| 1 |
<?php |
<?php |
| 2 |
// $Id: shindig_integrator.module,v 1.2.2.11 2009/10/22 07:54:28 impetus Exp $ |
// $Id: shindig_integrator.module,v 1.2.2.10 2009/08/13 08:27:37 impetus Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Module to integrate shindig framework |
* Module to integrate shindig framework |
| 105 |
'access arguments' => array('view application directory'), |
'access arguments' => array('view application directory'), |
| 106 |
'type' => MENU_NORMAL_ITEM); |
'type' => MENU_NORMAL_ITEM); |
| 107 |
|
|
| 108 |
|
$items['add_application/%'] = array( |
| 109 |
|
'title' => t('Add application'), |
| 110 |
|
'description' => t('Add application to user account.'), |
| 111 |
|
'page callback' => 'shindig_integrator_add_application', |
| 112 |
|
'page arguments' => array(1), |
| 113 |
|
'access arguments' => array('view application directory'), |
| 114 |
|
'type' => MENU_CALLBACK); |
| 115 |
|
|
| 116 |
$items['create_app'] = array( |
$items['create_app'] = array( |
| 117 |
'title' => t('Add new application'), |
'title' => t('Add new application'), |
| 118 |
'description' => 'Add new application to database through xml URL.', |
'description' => 'Add new application to database through xml URL.', |
| 119 |
'page callback' => 'drupal_get_form', |
'page callback' => 'create_app_page', |
| 120 |
'page arguments' => array('create_app_form')); |
'access arguments' => array('create application'), ); |
| 121 |
|
|
| 122 |
|
$items['delete_application/%'] = array( |
| 123 |
|
'title' => t('Delete application'), |
| 124 |
|
'description' => t('Delete application from user account.'), |
| 125 |
|
'page callback' => 'shindig_integrator_delete_application', |
| 126 |
|
'page arguments' => array(1), |
| 127 |
|
'access arguments' => array('view application canvas'), |
| 128 |
|
'type' => MENU_CALLBACK); |
| 129 |
|
|
| 130 |
|
$items['remove_application/%'] = array( |
| 131 |
|
'title' => t('Remove application'), |
| 132 |
|
'description' => t('Remove application from the system.'), |
| 133 |
|
'page callback' => 'shindig_integrator_remove_application', |
| 134 |
|
'page arguments' => array(1), |
| 135 |
|
'access arguments' => array('delete applications'), |
| 136 |
|
'type' => MENU_CALLBACK); |
| 137 |
|
|
| 138 |
$items['application_canvas/%/%'] = array( |
$items['application_canvas/%/%'] = array( |
| 139 |
'title' => t('Application canvas page'), |
'title' => t('Application canvas page'), |
| 237 |
return ; |
return ; |
| 238 |
} |
} |
| 239 |
|
|
| 240 |
|
if (!empty($msg)) { |
| 241 |
|
if ($error) { |
| 242 |
|
drupal_set_message($msg, 'error'); |
| 243 |
|
} |
| 244 |
|
else { |
| 245 |
|
drupal_set_message($msg); |
| 246 |
|
} |
| 247 |
|
} |
| 248 |
if ( user_access('delete applications')) { |
if ( user_access('delete applications')) { |
| 249 |
drupal_set_message('Please note, the "Remove" link is NOT the opposite of "Add". "Add" will add an application to your account, where as remove will delete the appication from the system completely. To remove an application from your account, please use the links provided on the "Application canvas" page.'); |
drupal_set_message('Please note, the "Remove" link is NOT the opposite of "Add". "Add" will add an application to your account, where as remove will delete the appication from the system completely. To remove an application from your account, please use the links provided on the "Application canvas" page.'); |
| 250 |
} |
} |
| 281 |
$app[] = theme('image', check_plain($app_thumb), '', '', $attr, FALSE); |
$app[] = theme('image', check_plain($app_thumb), '', '', $attr, FALSE); |
| 282 |
$app[] = check_plain($app_dir_title); |
$app[] = check_plain($app_dir_title); |
| 283 |
$app[] = ($app_description=="")?"No Description":check_plain($app_description); |
$app[] = ($app_description=="")?"No Description":check_plain($app_description); |
| 284 |
|
$app_id_64 = base64_encode($app_id); |
| 285 |
if (!in_array($app_id, $user_app_array)) { |
if (!in_array($app_id, $user_app_array)) { |
| 286 |
$app[] = (drupal_get_form('add_app_form_'. $app_id, $app_id) . (user_access('delete application') ? |
$app[] = (l(t('Add'), "add_application/$app_id_64") . ' ' . (user_access('delete application') ? |
| 287 |
drupal_get_form('remove_app_form_'. $app_id, $app_id) : ' ')); |
(l(t('Remove'), "remove_application/$app_id_64")) : |
| 288 |
|
'')); |
| 289 |
} |
} |
| 290 |
else { |
else { |
| 291 |
$app[] = ((user_access('delete application') ? |
$app[] = ((user_access('delete application') ? |
| 292 |
drupal_get_form('remove_app_form_'. $app_id, $app_id) : |
(l(t('Remove'), "remove_application/$app_id_64")) : |
| 293 |
'')); |
'')); |
| 294 |
} |
} |
| 295 |
$apps[] = $app; |
$apps[] = $app; |
| 296 |
} |
} |
| 302 |
} |
} |
| 303 |
|
|
| 304 |
/** |
/** |
| 305 |
* Implementation of hook_forms(). |
* Page callback for 'addApplication'. |
| 306 |
* |
* |
| 307 |
* This is necessary when multiple forms appear on the same page, each |
* @param $app_id |
| 308 |
* requiring a separate form_id, but all using the same underlying callbacks. |
* Application id which will be added to user's account |
| 309 |
*/ |
*/ |
| 310 |
function shindig_integrator_forms($form_id, $args) { |
function shindig_integrator_add_application($app_id=0) { |
|
if (strpos($form_id, "add_app_form_") === 0) { |
|
|
$forms[$form_id] = array('callback' => 'add_app_form'); |
|
|
return $forms; |
|
|
} |
|
|
|
|
|
if (strpos($form_id, "remove_app_form_") === 0) { |
|
|
$forms[$form_id] = array('callback' => 'remove_app_form'); |
|
|
return $forms; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* Form to remove an application from application directory |
|
|
* |
|
|
* @param |
|
|
* $form_id |
|
|
* Form id |
|
|
* $app_id |
|
|
* Id of application which user wants to delete from his account |
|
|
*/ |
|
|
function remove_app_form($form_id, $app_id) { |
|
|
$form['app_id'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#value' => $app_id |
|
|
); |
|
|
|
|
|
$form['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Remove'), |
|
|
); |
|
|
$form['#submit'] = array("remove_app_form_submit"); |
|
|
return $form; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit function for remove_app_form |
|
|
*/ |
|
|
function remove_app_form_submit($form, &$form_state) { |
|
|
drupal_get_messages('error'); |
|
|
drupal_get_messages('status'); |
|
|
$app_id = $form_state['values']['app_id']; |
|
|
|
|
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d", $app_id); |
|
|
if (!$res) { |
|
|
return FALSE; |
|
|
} |
|
|
$res = db_query("DELETE FROM {applications} WHERE id=%d", $app_id); |
|
|
if (!$res) { |
|
|
drupal_set_message(t('There is some problem to remove these application from directory. Please try again.')); |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Application removed successfully from directory.')); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Form to add an application to user's account |
|
|
* |
|
|
* @param |
|
|
* $form_id |
|
|
* Form id |
|
|
* $app_id |
|
|
* Id of application which user wants to delete from his account |
|
|
*/ |
|
|
function add_app_form($form_id, $app_id) { |
|
|
$form['app_id'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#value' => $app_id |
|
|
); |
|
|
$form['add_app_submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Add'), |
|
|
); |
|
|
$form['#submit'] = array("add_app_form_submit"); |
|
|
|
|
|
|
|
|
return $form; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit function for remove_app_form |
|
|
*/ |
|
|
function add_app_form_submit($form, &$form_state) { |
|
| 311 |
global $user; |
global $user; |
| 312 |
drupal_get_messages('error'); |
$app_id = base64_decode($app_id); |
|
drupal_get_messages('status'); |
|
|
$app_id = $form_state['values']['app_id']; |
|
| 313 |
$u_id = $user->uid; |
$u_id = $user->uid; |
| 314 |
|
$is_error = ""; |
| 315 |
if (is_null(db_query("INSERT INTO {user_applications} (user_id,application_id) VALUES(%d,%d)", $u_id, $app_id))) { |
if (is_null(db_query("INSERT INTO {user_applications} (user_id,application_id) VALUES(%d,%d)", $u_id, $app_id))) { |
| 316 |
$msg = t("There is some problem in adding application to your account. Please try again."); |
$msg = t("There is some problem in adding application to your account. Please try again."); |
| 317 |
drupal_set_message(t("There is some problem in adding application to your account. Please try again."), 'error'); |
$is_error = "error"; |
| 318 |
} |
} |
| 319 |
else { |
else { |
| 320 |
$msg = t("Application added successfully to your account"); |
$msg = t("Application added successfully to your account"); |
|
drupal_set_message(t("Application added successfully to your account")); |
|
| 321 |
} |
} |
| 322 |
|
drupal_goto("show_directory/$msg/$is_error"); |
| 323 |
|
} |
| 324 |
|
|
| 325 |
|
/** |
| 326 |
|
* Page callback for 'create_app'. |
| 327 |
|
*/ |
| 328 |
|
function create_app_page() { |
| 329 |
|
if (!user_access('create application')) { |
| 330 |
|
return; |
| 331 |
|
} |
| 332 |
|
$output = ""; |
| 333 |
|
$output .= drupal_get_form('create_app_form'); |
| 334 |
|
return $output; |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
/** |
/** |
| 361 |
$app_url = trim($form_state['values']['gadget_url']); |
$app_url = trim($form_state['values']['gadget_url']); |
| 362 |
$response = save_application($app_url); |
$response = save_application($app_url); |
| 363 |
if (!empty($response['error'])) { |
if (!empty($response['error'])) { |
| 364 |
$error = t('Cannot add the application. Error: %error', array('%error' => $response['error'])); |
$error = t('Cannot add the application. Error: ') . $response['error']; |
| 365 |
drupal_set_message($error, 'error'); |
drupal_set_message($error, 'error'); |
| 366 |
} |
} |
| 367 |
else { |
else { |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
/** |
/** |
| 500 |
|
* Page callback for 'delete_application'. |
| 501 |
|
* |
| 502 |
|
* @param $app_id |
| 503 |
|
* Id of application which user wants to delete from his account |
| 504 |
|
*/ |
| 505 |
|
function shindig_integrator_delete_application($app_id) { |
| 506 |
|
global $user; |
| 507 |
|
$user_id = $user->uid; |
| 508 |
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d AND user_id", base64_decode($app_id), $user_id); |
| 509 |
|
if(!$res) { |
| 510 |
|
return FALSE; |
| 511 |
|
} |
| 512 |
|
drupal_goto("user"); |
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
function shindig_integrator_remove_application($app_id) { |
| 516 |
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d", base64_decode($app_id)); |
| 517 |
|
if (!$res) { |
| 518 |
|
return FALSE; |
| 519 |
|
} |
| 520 |
|
$res = db_query("DELETE FROM {applications} WHERE id=%d", base64_decode($app_id)); |
| 521 |
|
if (!$res) { |
| 522 |
|
return FALSE; |
| 523 |
|
} |
| 524 |
|
drupal_goto("user"); |
| 525 |
|
} |
| 526 |
|
|
| 527 |
|
|
| 528 |
|
/** |
| 529 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 530 |
*/ |
*/ |
| 531 |
function shindig_integrator_user($op, &$edit, &$owner, $category = '') { |
function shindig_integrator_user($op, &$edit, &$owner, $category = '') { |
| 614 |
$attr = ''; |
$attr = ''; |
| 615 |
if (!empty($items)) { |
if (!empty($items)) { |
| 616 |
foreach ($items as $item) { |
foreach ($items as $item) { |
| 617 |
$app_id = check_plain($item['app_id']); |
$app_id = $item['app_id']; |
| 618 |
$mod_id = check_plain($item['mod_id']); |
$mod_id = $item['mod_id']; |
| 619 |
$output .= theme('add_gadget', $app_id, $mod_id, $view, check_plain($owner_id)); |
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
| 620 |
$output .= '<hr>'; |
$output .= '<hr>'; |
| 621 |
} |
} |
| 622 |
} |
} |
| 674 |
if (isset($user_prefs[$key])) { |
if (isset($user_prefs[$key])) { |
| 675 |
unset($user_prefs[$key]); |
unset($user_prefs[$key]); |
| 676 |
} |
} |
| 677 |
$prefs .= '&up_' . urlencode(check_plain($key)) . '=' . urlencode(check_plain($value)); |
$prefs .= '&up_' . urlencode($key) . '=' . urlencode($value); |
| 678 |
} |
} |
| 679 |
} |
} |
| 680 |
|
|
| 703 |
|
|
| 704 |
$iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'. |
$iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'. |
| 705 |
'synd='. $container |
'synd='. $container |
| 706 |
.'&container='. check_plain($container) |
.'&container='. $container |
| 707 |
.'&viewer='. check_plain((isset($viewer_id) ? $viewer_id:'0')) |
.'&viewer='. (isset($viewer_id) ? $viewer_id:'0') |
| 708 |
.'&owner='. check_plain((isset($owner_id) ? $owner_id:$viewer_id)) |
.'&owner='. (isset($owner_id) ? $owner_id:$viewer_id) |
| 709 |
.'&aid='. base64_encode(check_plain($gadget->id)) |
.'&aid='. base64_encode($gadget->id) |
| 710 |
.'&mid='. base64_encode(check_plain($mod_id)) |
.'&mid='. base64_encode($mod_id ) |
| 711 |
.'&nocache=1' |
.'&nocache=1' |
| 712 |
.'&country=US' |
.'&country=US' |
| 713 |
.'&lang=EN' |
.'&lang=EN' |
| 714 |
.'&view='. check_plain($view) |
.'&view='. $view |
| 715 |
.'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST']) |
.'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST']) |
| 716 |
. $prefs |
. $prefs |
| 717 |
. (isset($_REQUEST['appParams']) ? '&view-params='. urlencode(check_plain($_REQUEST['appParams'])):'') |
. (isset($_REQUEST['appParams']) ? '&view-params='. urlencode($_REQUEST['appParams']):'') |
| 718 |
.'&st='. base64_encode($security_token->toSerialForm()) |
.'&st='. base64_encode($security_token->toSerialForm()) |
| 719 |
.'&v='. check_plain($gadget->version) |
.'&v='. $gadget->version |
| 720 |
.'&url='. urlencode(check_url($gadget->url)) |
.'&url='. urlencode(check_url($gadget->url)) |
| 721 |
.'#rpctoken='. rand(0, getrandmax()); |
.'#rpctoken='. rand(0, getrandmax()); |
| 722 |
|
|
| 723 |
$height = !empty($gadget->height) ? check_plain($gadget->height):'200'; |
$height = !empty($gadget->height) ? check_plain($gadget->height):'200'; |
| 724 |
$iframe_name = "remote_iframe_" . check_plain($mod_id); |
$iframe_name = "remote_iframe_" . $mod_id; |
| 725 |
$iframe_id = "remote_iframe_" . check_plain($mod_id); |
$iframe_id = "remote_iframe_" . $mod_id; |
| 726 |
$scrolling = $gadget->scrolling ? 'yes':'no'; |
$scrolling = $gadget->scrolling ? 'yes':'no'; |
| 727 |
|
|
| 728 |
drupal_add_css($path ."/css/jquery.css"); |
drupal_add_css($path ."/css/jquery.css"); |
| 734 |
|
|
| 735 |
$iframe_str = '<iframe width="100%" height='. $height .' name='. $iframe_name .' id='. $iframe_id .' scrolling ='. $scrolling .' frameborder="no" src= "'. $iframe_url .'" class="gadgets-gadget"></iframe>'; |
$iframe_str = '<iframe width="100%" height='. $height .' name='. $iframe_name .' id='. $iframe_id .' scrolling ='. $scrolling .' frameborder="no" src= "'. $iframe_url .'" class="gadgets-gadget"></iframe>'; |
| 736 |
|
|
| 737 |
$output .= '<div class="iframe_div"' .' id='. $iframe_id .'_title align="center" style="padding-top:30px;font-family: inherit;font-size: large;font-weight: bold;">'. check_plain($gadget->title) .'</div><br>'; |
$output .= '<div class="iframe_div"' .' id='. $iframe_id .'_title align="center" style="padding-top:30px;font-family: inherit;font-size: large;font-weight: bold;">'. $gadget->title .'</div><br>'; |
| 738 |
$output .= '<div class="iframe_div" align="center" style="padding-top:30px;">'. $iframe_str ."</div>\n"; |
$output .= '<div class="iframe_div" align="center" style="padding-top:30px;">'. $iframe_str ."</div>\n"; |
| 739 |
} |
} |
| 740 |
return $output; |
return $output; |
| 759 |
$ret = array(); |
$ret = array(); |
| 760 |
$attr = array(); |
$attr = array(); |
| 761 |
$owner_id = $user->uid; |
$owner_id = $user->uid; |
| 762 |
$app_id = base64_decode(check_plain($app_id)); |
$app_id = base64_decode($app_id); |
| 763 |
$mod_id = base64_decode(check_plain($mod_id)); |
$mod_id = base64_decode($mod_id); |
| 764 |
$output = ""; |
$output = ""; |
| 765 |
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
| 766 |
$output .= '<div align="right">'; |
$delete_url = "delete_application/". base64_encode($app_id); |
| 767 |
$output .= drupal_get_form('delete_app_form', $app_id); |
$output .= '<div align="right">'. l(t("Delete application"), $delete_url) .'</div>'; |
|
$output .= '</div>'; |
|
| 768 |
return $output; |
return $output; |
| 769 |
} |
} |
| 770 |
|
|
|
/** |
|
|
* Form to delete an application from user's account |
|
|
* |
|
|
* @param |
|
|
* $form_id |
|
|
* Form id |
|
|
* $app_id |
|
|
* Id of application which user wants to delete from his account |
|
|
*/ |
|
|
function delete_app_form($form_id, $app_id) { |
|
|
$form['app_id'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#value' => $app_id |
|
|
); |
|
|
|
|
|
$form['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Delete application'), |
|
|
); |
|
|
return $form; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit function for delete_app_form |
|
|
*/ |
|
|
function delete_app_form_submit($form, &$form_state) { |
|
|
$app_id = trim($form_state['values']['app_id']); |
|
|
$user_id = $user->uid; |
|
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d AND user_id", $app_id, $user_id); |
|
|
if (!$res) { |
|
|
drupal_set_message(t('There is some problem to delete these application from your account. Please try again.')); |
|
|
} |
|
|
drupal_goto("user"); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Function to set user preferences through gadgets |
|
|
*/ |
|
| 771 |
function set_user_preference() { |
function set_user_preference() { |
| 772 |
if (empty($_POST['st']) || empty($_POST['name']) || ! isset($_POST['value'])) { |
if (empty($_GET['st']) || empty($_GET['name']) || ! isset($_GET['value'])) { |
| 773 |
header("HTTP/1.0 400 Bad Request", true); |
header("HTTP/1.0 400 Bad Request", true); |
| 774 |
echo "<html><body><h1>400 - Bad Request</h1></body></html>"; |
echo "<html><body><h1>400 - Bad Request</h1></body></html>"; |
| 775 |
} else { |
} else { |
| 780 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter'); |
| 781 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto'); |
| 782 |
try { |
try { |
| 783 |
$st = urldecode(base64_decode($_POST['st'])); |
$st = urldecode(base64_decode($_GET['st'])); |
| 784 |
$key = urldecode($_POST['name']); |
$key = urldecode($_GET['name']); |
| 785 |
$value = urldecode($_POST['value']); |
$value = urldecode($_GET['value']); |
| 786 |
|
|
| 787 |
$token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age')); |
$token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age')); |
| 788 |
$app_id = $token->getAppId(); |
$app_id = $token->getAppId(); |
| 789 |
$viewer = $token->getViewerId(); |
$viewer = $token->getViewerId(); |