| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: shindig_integrator.module,v 1.2.2.11 2009/10/22 07:54:28 impetus Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Module to integrate shindig framework |
* Module to integrate shindig framework |
| 86 |
return array( |
return array( |
| 87 |
'view application directory', |
'view application directory', |
| 88 |
'create application', |
'create application', |
| 89 |
|
'delete applications', |
| 90 |
'view application canvas', |
'view application canvas', |
| 91 |
'view list of user applications', |
'view list of user applications', |
| 92 |
'view user applications on profile', |
'view user applications on profile', |
| 105 |
'access arguments' => array('view application directory'), |
'access arguments' => array('view application directory'), |
| 106 |
'type' => MENU_NORMAL_ITEM); |
'type' => MENU_NORMAL_ITEM); |
| 107 |
|
|
|
$items['add_application/%'] = array( |
|
|
'title' => t('Add application'), |
|
|
'description' => t('Add application to user account.'), |
|
|
'page callback' => 'shindig_integrator_add_application', |
|
|
'page arguments' => array(1), |
|
|
'access arguments' => array('view application directory'), |
|
|
'type' => MENU_CALLBACK); |
|
|
|
|
| 108 |
$items['create_app'] = array( |
$items['create_app'] = array( |
| 109 |
'title' => t('Add new application'), |
'title' => t('Add new application'), |
| 110 |
'description' => 'Add new application to database through xml URL.', |
'description' => 'Add new application to database through xml URL.', |
| 111 |
'page callback' => 'create_app_page', |
'page callback' => 'drupal_get_form', |
| 112 |
'access arguments' => array('create application'), ); |
'page arguments' => array('create_app_form')); |
| 113 |
|
|
|
$items['delete_application/%'] = array( |
|
|
'title' => t('Delete application'), |
|
|
'description' => t('Delete application from user account.'), |
|
|
'page callback' => 'shindig_integrator_delete_application', |
|
|
'page arguments' => array(1), |
|
|
'access arguments' => array('view application canvas'), |
|
|
'type' => MENU_CALLBACK); |
|
|
|
|
| 114 |
$items['application_canvas/%/%'] = array( |
$items['application_canvas/%/%'] = array( |
| 115 |
'title' => t('Application canvas page'), |
'title' => t('Application canvas page'), |
| 116 |
'description' => t('Show Application In Canvas View.'), |
'description' => t('Show Application In Canvas View.'), |
| 118 |
'page arguments' => array(1, 2), |
'page arguments' => array(1, 2), |
| 119 |
'access arguments' => array('view application canvas'), |
'access arguments' => array('view application canvas'), |
| 120 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 121 |
|
|
| 122 |
|
$items['setPrefs'] = array( |
| 123 |
|
'title' => t('Application canvas page'), |
| 124 |
|
'description' => t('Set User preference.'), |
| 125 |
|
'page callback' => 'set_user_preference', |
| 126 |
|
'access arguments' => array('view application canvas'), |
| 127 |
|
'type' => MENU_CALLBACK); |
| 128 |
|
|
| 129 |
return $items; |
return $items; |
| 130 |
} |
} |
| 208 |
*/ |
*/ |
| 209 |
function show_directory_page($msg="", $error="") { |
function show_directory_page($msg="", $error="") { |
| 210 |
global $user; |
global $user; |
| 211 |
|
|
| 212 |
if ( !user_access('view application directory')) { |
if ( !user_access('view application directory')) { |
| 213 |
return ; |
return ; |
| 214 |
} |
} |
| 215 |
|
|
| 216 |
if (!empty($msg)) { |
if ( user_access('delete applications')) { |
| 217 |
if ($error) { |
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($msg, 'error'); |
|
|
} |
|
|
else { |
|
|
drupal_set_message($msg); |
|
|
} |
|
| 218 |
} |
} |
| 219 |
|
|
| 220 |
$path = drupal_get_path('module', 'shindig_integrator'); |
$path = drupal_get_path('module', 'shindig_integrator'); |
| 221 |
$default_thumb = "$path/images/noimage.gif"; |
$default_thumb = "$path/images/noimage.gif"; |
| 222 |
$num_apps_on_page = 10; |
$num_apps_on_page = 10; |
| 236 |
$result_get_all_apps = pager_query( |
$result_get_all_apps = pager_query( |
| 237 |
"SELECT * FROM {applications}", |
"SELECT * FROM {applications}", |
| 238 |
$num_apps_on_page, 0, "SELECT COUNT(*) FROM {applications}"); |
$num_apps_on_page, 0, "SELECT COUNT(*) FROM {applications}"); |
| 239 |
|
$apps = array(); |
| 240 |
|
$headers = array(); |
| 241 |
while ($record_get_all_apps = db_fetch_object($result_get_all_apps)) { |
while ($record_get_all_apps = db_fetch_object($result_get_all_apps)) { |
| 242 |
$app_id = $record_get_all_apps->id; |
$app_id = $record_get_all_apps->id; |
| 243 |
$app_thumb = ($record_get_all_apps->thumbnail) ? |
$app_thumb = ($record_get_all_apps->thumbnail) ? |
| 250 |
$app[] = check_plain($app_dir_title); |
$app[] = check_plain($app_dir_title); |
| 251 |
$app[] = ($app_description=="")?"No Description":check_plain($app_description); |
$app[] = ($app_description=="")?"No Description":check_plain($app_description); |
| 252 |
if (!in_array($app_id, $user_app_array)) { |
if (!in_array($app_id, $user_app_array)) { |
| 253 |
$app_id = base64_encode($app_id); |
$app[] = (drupal_get_form('add_app_form_'. $app_id, $app_id) . (user_access('delete application') ? |
| 254 |
$app[] = l(t('Add'), "add_application/$app_id"); |
drupal_get_form('remove_app_form_'. $app_id, $app_id) : ' ')); |
| 255 |
} |
} |
| 256 |
else { |
else { |
| 257 |
$app[] = " "; |
$app[] = ((user_access('delete application') ? |
| 258 |
|
drupal_get_form('remove_app_form_'. $app_id, $app_id) : |
| 259 |
|
'')); |
| 260 |
} |
} |
| 261 |
$apps[] = $app; |
$apps[] = $app; |
| 262 |
} |
} |
| 263 |
$output = ""; |
$output = ""; |
| 264 |
$attr['width'] = "100%"; |
$attr['width'] = "100%"; |
| 265 |
$output = theme('table', $headers, $apps, $attr); |
$output = theme('table', $headers, $apps, $attr); |
| 266 |
$output .= theme('pager', NULL, $limit, 0); |
$output .= theme('pager', NULL, $num_apps_on_page, 0); |
| 267 |
return $output; |
return $output; |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
/** |
/** |
| 271 |
* Page callback for 'addApplication'. |
* Implementation of hook_forms(). |
| 272 |
* |
* |
| 273 |
* @param $app_id |
* This is necessary when multiple forms appear on the same page, each |
| 274 |
* Application id which will be added to user's account |
* requiring a separate form_id, but all using the same underlying callbacks. |
| 275 |
*/ |
*/ |
| 276 |
function shindig_integrator_add_application($app_id=0) { |
function shindig_integrator_forms($form_id, $args) { |
| 277 |
global $user; |
if (strpos($form_id, "add_app_form_") === 0) { |
| 278 |
$app_id = base64_decode($app_id); |
$forms[$form_id] = array('callback' => 'add_app_form'); |
| 279 |
$u_id = $user->uid; |
return $forms; |
| 280 |
$is_error = ""; |
} |
| 281 |
if (is_null(db_query("INSERT INTO {user_applications} (user_id,application_id) VALUES(%d,%d)", $u_id, $app_id))) { |
|
| 282 |
$msg = t("There is some problem in adding application to your account. Please try again."); |
if (strpos($form_id, "remove_app_form_") === 0) { |
| 283 |
$is_error = "error"; |
$forms[$form_id] = array('callback' => 'remove_app_form'); |
| 284 |
|
return $forms; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
/** |
| 290 |
|
* Form to remove an application from application directory |
| 291 |
|
* |
| 292 |
|
* @param |
| 293 |
|
* $form_id |
| 294 |
|
* Form id |
| 295 |
|
* $app_id |
| 296 |
|
* Id of application which user wants to delete from his account |
| 297 |
|
*/ |
| 298 |
|
function remove_app_form($form_id, $app_id) { |
| 299 |
|
$form['app_id'] = array( |
| 300 |
|
'#type' => 'hidden', |
| 301 |
|
'#value' => $app_id |
| 302 |
|
); |
| 303 |
|
|
| 304 |
|
$form['submit'] = array( |
| 305 |
|
'#type' => 'submit', |
| 306 |
|
'#value' => t('Remove'), |
| 307 |
|
); |
| 308 |
|
$form['#submit'] = array("remove_app_form_submit"); |
| 309 |
|
return $form; |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
/** |
| 313 |
|
* Submit function for remove_app_form |
| 314 |
|
*/ |
| 315 |
|
function remove_app_form_submit($form, &$form_state) { |
| 316 |
|
drupal_get_messages('error'); |
| 317 |
|
drupal_get_messages('status'); |
| 318 |
|
$app_id = $form_state['values']['app_id']; |
| 319 |
|
|
| 320 |
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d", $app_id); |
| 321 |
|
if (!$res) { |
| 322 |
|
return FALSE; |
| 323 |
} |
} |
| 324 |
|
$res = db_query("DELETE FROM {applications} WHERE id=%d", $app_id); |
| 325 |
|
if (!$res) { |
| 326 |
|
drupal_set_message(t('There is some problem to remove these application from directory. Please try again.')); |
| 327 |
|
} |
| 328 |
else { |
else { |
| 329 |
$msg = t("Application added successfully to your account"); |
drupal_set_message(t('Application removed successfully from directory.')); |
| 330 |
} |
} |
|
drupal_goto("show_directory/$msg/$is_error"); |
|
| 331 |
} |
} |
| 332 |
|
|
| 333 |
/** |
/** |
| 334 |
* Page callback for 'create_app'. |
* Form to add an application to user's account |
| 335 |
|
* |
| 336 |
|
* @param |
| 337 |
|
* $form_id |
| 338 |
|
* Form id |
| 339 |
|
* $app_id |
| 340 |
|
* Id of application which user wants to delete from his account |
| 341 |
|
*/ |
| 342 |
|
function add_app_form($form_id, $app_id) { |
| 343 |
|
$form['app_id'] = array( |
| 344 |
|
'#type' => 'hidden', |
| 345 |
|
'#value' => $app_id |
| 346 |
|
); |
| 347 |
|
$form['add_app_submit'] = array( |
| 348 |
|
'#type' => 'submit', |
| 349 |
|
'#value' => t('Add'), |
| 350 |
|
); |
| 351 |
|
$form['#submit'] = array("add_app_form_submit"); |
| 352 |
|
|
| 353 |
|
|
| 354 |
|
return $form; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
/** |
| 358 |
|
* Submit function for remove_app_form |
| 359 |
*/ |
*/ |
| 360 |
function create_app_page() { |
function add_app_form_submit($form, &$form_state) { |
| 361 |
if (!user_access('create application')) { |
global $user; |
| 362 |
return; |
drupal_get_messages('error'); |
| 363 |
|
drupal_get_messages('status'); |
| 364 |
|
$app_id = $form_state['values']['app_id']; |
| 365 |
|
$u_id = $user->uid; |
| 366 |
|
if (is_null(db_query("INSERT INTO {user_applications} (user_id,application_id) VALUES(%d,%d)", $u_id, $app_id))) { |
| 367 |
|
$msg = t("There is some problem in adding application to your account. Please try again."); |
| 368 |
|
drupal_set_message(t("There is some problem in adding application to your account. Please try again."), 'error'); |
| 369 |
|
} |
| 370 |
|
else { |
| 371 |
|
$msg = t("Application added successfully to your account"); |
| 372 |
|
drupal_set_message(t("Application added successfully to your account")); |
| 373 |
} |
} |
|
$output = ""; |
|
|
$output .= drupal_get_form('create_app_form'); |
|
|
return $output; |
|
| 374 |
} |
} |
| 375 |
|
|
| 376 |
/** |
/** |
| 400 |
$app_url = trim($form_state['values']['gadget_url']); |
$app_url = trim($form_state['values']['gadget_url']); |
| 401 |
$response = save_application($app_url); |
$response = save_application($app_url); |
| 402 |
if (!empty($response['error'])) { |
if (!empty($response['error'])) { |
| 403 |
$error = t('Cannot add the application. Error: ') . $response['error']; |
$error = t('Cannot add the application. Error: %error', array('%error' => $response['error'])); |
| 404 |
drupal_set_message($error, 'error'); |
drupal_set_message($error, 'error'); |
| 405 |
} |
} |
| 406 |
else { |
else { |
| 490 |
|
|
| 491 |
$res = db_query("SELECT id FROM {applications} WHERE url = '%s'" , $info['url']); |
$res = db_query("SELECT id FROM {applications} WHERE url = '%s'" , $info['url']); |
| 492 |
$record = db_fetch_object($res); |
$record = db_fetch_object($res); |
| 493 |
|
$error = ''; |
| 494 |
if (is_null($record)) { |
if (is_null($record)) { |
| 495 |
$error = t("Could not store application in registry"); |
$error = t("Could not store application in registry"); |
| 496 |
} |
} |
| 536 |
} |
} |
| 537 |
|
|
| 538 |
/** |
/** |
|
* Page callback for 'delete_application'. |
|
|
* |
|
|
* @param $app_id |
|
|
* Id of application which user wants to delete from his account |
|
|
*/ |
|
|
function shindig_integrator_delete_application($app_id) { |
|
|
global $user; |
|
|
$user_id = $user->uid; |
|
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d AND user_id", base64_decode($app_id), $user_id); |
|
|
if(!res) { |
|
|
return FALSE; |
|
|
} |
|
|
drupal_goto("user"); |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
| 539 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 540 |
*/ |
*/ |
| 541 |
function shindig_integrator_user($op, &$edit, &$owner, $category = '') { |
function shindig_integrator_user($op, &$edit, &$owner, $category = '') { |
| 553 |
$owner_id = isset($owner->uid) ? $owner->uid:$user->uid; |
$owner_id = isset($owner->uid) ? $owner->uid:$user->uid; |
| 554 |
$viewer_id = $user->uid; |
$viewer_id = $user->uid; |
| 555 |
$output = ""; |
$output = ""; |
| 556 |
|
$apps = array(); |
| 557 |
$result_get_app = db_query("SELECT id, title FROM {applications} WHERE id IN |
$result_get_app = db_query("SELECT id, title FROM {applications} WHERE id IN |
| 558 |
( |
( |
| 559 |
SELECT application_id FROM {user_applications} WHERE user_id =%d |
SELECT application_id FROM {user_applications} WHERE user_id =%d |
| 621 |
$view = "profile"; |
$view = "profile"; |
| 622 |
$owner_id = isset($owner->uid) ? $owner->uid:$user->uid; |
$owner_id = isset($owner->uid) ? $owner->uid:$user->uid; |
| 623 |
$output = ""; |
$output = ""; |
| 624 |
|
$attr = ''; |
| 625 |
if (!empty($items)) { |
if (!empty($items)) { |
| 626 |
foreach ($items as $item) { |
foreach ($items as $item) { |
| 627 |
$app_id = $item['app_id']; |
$app_id = check_plain($item['app_id']); |
| 628 |
$mod_id = $item['mod_id']; |
$mod_id = check_plain($item['mod_id']); |
| 629 |
$output .= '<div id='. $mod_id .' align="center">'; |
$output .= theme('add_gadget', $app_id, $mod_id, $view, check_plain($owner_id)); |
|
$output .= theme('image', check_plain($image_path ."loading.gif"), '', '', $attr, FALSE); |
|
|
$output .= '</div>'; |
|
|
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
|
| 630 |
$output .= '<hr>'; |
$output .= '<hr>'; |
| 631 |
} |
} |
| 632 |
} |
} |
| 650 |
* HTML in string format |
* HTML in string format |
| 651 |
*/ |
*/ |
| 652 |
function theme_add_gadget($app_id, $mod_id, $view, $owner_id) { |
function theme_add_gadget($app_id, $mod_id, $view, $owner_id) { |
| 653 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/Config'); |
| 654 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/SecurityToken'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/SecurityToken'); |
| 655 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter'); |
| 656 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken'); |
| 657 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter'); |
| 658 |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto'); |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/config'); |
|
| 659 |
|
|
| 660 |
global $user; |
global $user; |
| 661 |
$viewer_id = $user->uid; |
$viewer_id = $user->uid; |
| 662 |
|
$output = ''; |
| 663 |
$rs_Apps = db_query("SELECT * FROM {applications} WHERE id = %d", $app_id); |
$rs_Apps = db_query("SELECT * FROM {applications} WHERE id = %d", $app_id); |
| 664 |
if(!$rs_Apps) { |
if(!$rs_Apps) { |
| 665 |
return FALSE; |
return FALSE; |
| 666 |
} |
} |
| 667 |
$row_rs_Apps = db_fetch_object($rs_Apps); |
while ($gadget = db_fetch_object($rs_Apps)) { |
|
$gadget = $row_rs_Apps; |
|
| 668 |
$container = "default"; |
$container = "default"; |
| 669 |
|
|
| 670 |
|
// get user preferences |
| 671 |
|
$result = db_query('SELECT name, value FROM application_settings WHERE application_id = %d and user_id = %d', $app_id, $viewer_id); |
| 672 |
|
$user_prefs = array(); |
| 673 |
|
while ($row = db_fetch_array($result)) { |
| 674 |
|
$user_prefs[$row['name']] = $row['value']; |
| 675 |
|
} |
| 676 |
|
|
| 677 |
|
|
| 678 |
$prefs = ""; |
$prefs = ""; |
| 679 |
|
|
| 680 |
|
$settings = ! empty($gadget->settings) ? unserialize($gadget->settings) : array(); |
| 681 |
|
foreach ($settings as $key => $setting) { |
| 682 |
|
if (! empty($key)) { |
| 683 |
|
$value = isset($user_prefs[$key]) ? $user_prefs[$key] : (isset($setting->default) ? $setting->default : null); |
| 684 |
|
if (isset($user_prefs[$key])) { |
| 685 |
|
unset($user_prefs[$key]); |
| 686 |
|
} |
| 687 |
|
$prefs .= '&up_' . urlencode(check_plain($key)) . '=' . urlencode(check_plain($value)); |
| 688 |
|
} |
| 689 |
|
} |
| 690 |
|
|
| 691 |
|
// Prepare the user preferences for inclusion in the iframe url |
| 692 |
|
foreach ($user_prefs as $name => $value) { |
| 693 |
|
// if some keys _are_ set in the db, but not in the gadget metadata, we still parse them on the url |
| 694 |
|
// (the above loop unsets the entries that matched |
| 695 |
|
if (! empty($value) && ! isset($appParams[$name])) { |
| 696 |
|
$prefs .= '&up_' . urlencode($name) . '=' . urlencode($value); |
| 697 |
|
} |
| 698 |
|
} |
| 699 |
$security_token = BasicSecurityToken::createFromValues(isset($owner_id) ? $owner_id:'0', // Owner |
$security_token = BasicSecurityToken::createFromValues(isset($owner_id) ? $owner_id:'0', // Owner |
| 700 |
(isset($viewer_id) ? $viewer_id:'0'), // Viewer |
(isset($viewer_id) ? $viewer_id:'0'), // Viewer |
| 701 |
$gadget->id, // App id |
$gadget->id, // App id |
| 710 |
module_load_include('php', 'shindig_integrator', '/shindig/php/config/local'); |
module_load_include('php', 'shindig_integrator', '/shindig/php/config/local'); |
| 711 |
|
|
| 712 |
$path = drupal_get_path('module', 'shindig_integrator'); |
$path = drupal_get_path('module', 'shindig_integrator'); |
|
$js_path = strstr(ShindigConfig::get('web_prefix'), 'sites'); |
|
| 713 |
|
|
|
|
|
| 714 |
$iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'. |
$iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'. |
| 715 |
'synd='. $container |
'synd='. $container |
| 716 |
.'&container='. $container |
.'&container='. check_plain($container) |
| 717 |
.'&viewer='. (isset($viewer_id) ? $viewer_id:'0') |
.'&viewer='. check_plain((isset($viewer_id) ? $viewer_id:'0')) |
| 718 |
.'&owner='. (isset($owner_id) ? $owner_id:$viewer_id) |
.'&owner='. check_plain((isset($owner_id) ? $owner_id:$viewer_id)) |
| 719 |
.'&aid='. $gadget->id |
.'&aid='. base64_encode(check_plain($gadget->id)) |
| 720 |
.'&mid='. $mod_id |
.'&mid='. base64_encode(check_plain($mod_id)) |
| 721 |
.'&nocache=1' |
.'&nocache=1' |
| 722 |
.'&country=US' |
.'&country=US' |
| 723 |
.'&lang=EN' |
.'&lang=EN' |
| 724 |
.'&view='. $view |
.'&view='. check_plain($view) |
| 725 |
.'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST']) |
.'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST']) |
| 726 |
. $prefs |
. $prefs |
| 727 |
. (isset($_REQUEST['appParams']) ? '&view-params='. urlencode($_REQUEST['appParams']):'') |
. (isset($_REQUEST['appParams']) ? '&view-params='. urlencode(check_plain($_REQUEST['appParams'])):'') |
| 728 |
.'&st='. base64_encode($security_token->toSerialForm()) |
.'&st='. base64_encode($security_token->toSerialForm()) |
| 729 |
.'&v='. $gadget->version |
.'&v='. check_plain($gadget->version) |
| 730 |
.'&url='. urlencode(check_url($gadget->url)) |
.'&url='. urlencode(check_url($gadget->url)) |
| 731 |
.'#rpctoken='. rand(0, getrandmax()); |
.'#rpctoken='. rand(0, getrandmax()); |
| 732 |
|
|
| 733 |
$height = !empty($gadget->height) ? check_plain($gadget->height):'200'; |
$height = !empty($gadget->height) ? check_plain($gadget->height):'200'; |
| 734 |
$iframe_name = "remote_iframe_" . $mod_id; |
$iframe_name = "remote_iframe_" . check_plain($mod_id); |
| 735 |
$iframe_id = "remote_iframe_" . $mod_id; |
$iframe_id = "remote_iframe_" . check_plain($mod_id); |
| 736 |
$scrolling = $gadget->scrolling ? 'yes':'no'; |
$scrolling = $gadget->scrolling ? 'yes':'no'; |
| 737 |
|
|
| 738 |
drupal_add_js($js_path .'/gadgets/js/rpc.js?c=1'); |
drupal_add_css($path ."/css/jquery.css"); |
| 739 |
drupal_add_js($path ."/prototype-1.6.0.2-min.js"); |
drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/util.js?c=1"); |
| 740 |
drupal_add_js($path ."/container.js"); |
drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/json.js?c=1"); |
| 741 |
|
drupal_add_js($path ."/shindig/features/src/main/javascript/features/rpc/rpc.js?c=1"); |
| 742 |
|
drupal_add_js($path ."/js/jquery.all.js"); |
| 743 |
|
drupal_add_js($path ."/js/container.js"); |
| 744 |
|
|
| 745 |
$iframe_str = '<iframe width="100%" height='. $height .' name='. $iframe_name .' id='. $iframe_id .' scrolling ='. $scrolling .' frameborder="no" src= "'. $iframe_url .'" class="gadgets-gadget" style="display:none;" onLoad="showIframe(\''. $iframe_id .'\',\''. $mod_id .'\');"></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>'; |
| 746 |
|
|
| 747 |
$output .= '<div class="iframe_div" align="center">'. $iframe_str .'</div>'; |
$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>'; |
| 748 |
|
$output .= '<div class="iframe_div" align="center" style="padding-top:30px;">'. $iframe_str ."</div>\n"; |
| 749 |
|
} |
| 750 |
return $output; |
return $output; |
| 751 |
} |
} |
| 752 |
|
|
| 767 |
$image_path = "$path/images/"; |
$image_path = "$path/images/"; |
| 768 |
$view = "canvas"; |
$view = "canvas"; |
| 769 |
$ret = array(); |
$ret = array(); |
| 770 |
|
$attr = array(); |
| 771 |
$owner_id = $user->uid; |
$owner_id = $user->uid; |
| 772 |
$app_id = base64_decode($app_id); |
$app_id = base64_decode(check_plain($app_id)); |
| 773 |
$mod_id = base64_decode($mod_id); |
$mod_id = base64_decode(check_plain($mod_id)); |
| 774 |
$output = ""; |
$output = ""; |
|
$output .= '<div id="'. $mod_id .'" align="center" width="100%">'; |
|
|
$output .= theme('image', $image_path ."/loading.gif", '', '', $attr, FALSE); |
|
|
$output .= '</div>'; |
|
| 775 |
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
$output .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id); |
| 776 |
$delete_url = "delete_application/". base64_encode($app_id); |
$output .= '<div align="right">'; |
| 777 |
$output .= '<div align="right">'. l(t("Delete application"), $delete_url) .'</div>'; |
$output .= drupal_get_form('delete_app_form', $app_id); |
| 778 |
|
$output .= '</div>'; |
| 779 |
return $output; |
return $output; |
| 780 |
} |
} |
| 781 |
|
|
| 782 |
|
/** |
| 783 |
|
* Form to delete an application from user's account |
| 784 |
|
* |
| 785 |
|
* @param |
| 786 |
|
* $form_id |
| 787 |
|
* Form id |
| 788 |
|
* $app_id |
| 789 |
|
* Id of application which user wants to delete from his account |
| 790 |
|
*/ |
| 791 |
|
function delete_app_form($form_id, $app_id) { |
| 792 |
|
$form['app_id'] = array( |
| 793 |
|
'#type' => 'hidden', |
| 794 |
|
'#value' => $app_id |
| 795 |
|
); |
| 796 |
|
|
| 797 |
|
$form['submit'] = array( |
| 798 |
|
'#type' => 'submit', |
| 799 |
|
'#value' => t('Delete application'), |
| 800 |
|
); |
| 801 |
|
return $form; |
| 802 |
|
} |
| 803 |
|
|
| 804 |
|
/** |
| 805 |
|
* Submit function for delete_app_form |
| 806 |
|
*/ |
| 807 |
|
function delete_app_form_submit($form, &$form_state) { |
| 808 |
|
$app_id = trim($form_state['values']['app_id']); |
| 809 |
|
$user_id = $user->uid; |
| 810 |
|
$res = db_query("DELETE FROM {user_applications} WHERE application_id=%d AND user_id", $app_id, $user_id); |
| 811 |
|
if (!$res) { |
| 812 |
|
drupal_set_message(t('There is some problem to delete these application from your account. Please try again.')); |
| 813 |
|
} |
| 814 |
|
drupal_goto("user"); |
| 815 |
|
} |
| 816 |
|
|
| 817 |
|
/** |
| 818 |
|
* Function to set user preferences through gadgets |
| 819 |
|
*/ |
| 820 |
|
function set_user_preference() { |
| 821 |
|
if (empty($_POST['st']) || empty($_POST['name']) || ! isset($_POST['value'])) { |
| 822 |
|
header("HTTP/1.0 400 Bad Request", true); |
| 823 |
|
echo "<html><body><h1>400 - Bad Request</h1></body></html>"; |
| 824 |
|
} else { |
| 825 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/Config'); |
| 826 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/SecurityToken'); |
| 827 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter'); |
| 828 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken'); |
| 829 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter'); |
| 830 |
|
module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto'); |
| 831 |
|
try { |
| 832 |
|
$st = urldecode(base64_decode($_POST['st'])); |
| 833 |
|
$key = urldecode($_POST['name']); |
| 834 |
|
$value = urldecode($_POST['value']); |
| 835 |
|
$token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age')); |
| 836 |
|
$app_id = $token->getAppId(); |
| 837 |
|
$viewer = $token->getViewerId(); |
| 838 |
|
$sql = "INSERT INTO application_settings (application_id, user_id, name, value) values (%d, %d, '%s', '%s') on duplicate key update value = '%s'"; |
| 839 |
|
db_query("INSERT INTO application_settings (application_id, user_id, name, value) values (%d, %d, '%s', '%s') on duplicate key update value = '%s'", $app_id, $viewer, $key, $value, $value); |
| 840 |
|
echo "success"; |
| 841 |
|
} catch (Exception $e) { |
| 842 |
|
header("HTTP/1.0 400 Bad Request", true); |
| 843 |
|
echo "<html><body><h1>400 - Bad Request</h1>" . $e->getMessage() . "</body></html>"; |
| 844 |
|
} |
| 845 |
|
} |
| 846 |
|
die(); |
| 847 |
|
} |