/[drupal]/contributions/modules/ShindigIntegrator/shindig_integrator/shindig_integrator.module
ViewVC logotype

Diff of /contributions/modules/ShindigIntegrator/shindig_integrator/shindig_integrator.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2.2.10, Thu Aug 13 08:27:37 2009 UTC revision 1.2.2.11, Thu Oct 22 07:54:28 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: shindig_integrator.module,v 1.2.2.9 2009/08/12 08:21:09 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
# Line 105  function shindig_integrator_menu() { Line 105  function shindig_integrator_menu() {
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'));
   
   $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);  
   
   $items['remove_application/%'] = array(  
     'title'            => t('Remove application'),  
     'description'      => t('Remove application from the system.'),  
     'page callback'    => 'shindig_integrator_remove_application',  
     'page arguments'   => array(1),  
     'access arguments' => array('delete applications'),  
     'type'             => MENU_CALLBACK);  
113    
114    $items['application_canvas/%/%'] = array(    $items['application_canvas/%/%'] = array(
115      'title'            => t('Application canvas page'),      'title'            => t('Application canvas page'),
# Line 237  function show_directory_page($msg="", $e Line 213  function show_directory_page($msg="", $e
213      return ;      return ;
214    }    }
215    
   if (!empty($msg)) {  
     if ($error) {  
       drupal_set_message($msg, 'error');  
     }  
     else {  
       drupal_set_message($msg);  
     }  
   }  
216    if ( user_access('delete applications')) {    if ( user_access('delete applications')) {
217      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.');
218    }    }
# Line 281  function show_directory_page($msg="", $e Line 249  function show_directory_page($msg="", $e
249      $app[]           = theme('image', check_plain($app_thumb), '', '', $attr, FALSE);      $app[]           = theme('image', check_plain($app_thumb), '', '', $attr, FALSE);
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);
     $app_id_64 = base64_encode($app_id);  
252      if (!in_array($app_id, $user_app_array)) {      if (!in_array($app_id, $user_app_array)) {
253                  $app[] = (l(t('Add'), "add_application/$app_id_64") . ' ' . (user_access('delete application') ?          $app[] = (drupal_get_form('add_app_form_'. $app_id, $app_id) . (user_access('delete application') ?
254                          (l(t('Remove'), "remove_application/$app_id_64")) :            drupal_get_form('remove_app_form_'. $app_id, $app_id) : ' '));
                         ''));  
255      }      }
256      else {      else {
257                  $app[] = ((user_access('delete application') ?        $app[] = ((user_access('delete application') ?
258                          (l(t('Remove'), "remove_application/$app_id_64")) :          drupal_get_form('remove_app_form_'. $app_id, $app_id) :
259                          ''));          ''));
260      }      }
261      $apps[] = $app;      $apps[] = $app;
262    }    }
# Line 302  function show_directory_page($msg="", $e Line 268  function show_directory_page($msg="", $e
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 create_app_page() {  function add_app_form($form_id, $app_id) {
343    if (!user_access('create application')) {    $form['app_id'] = array(
344      return;      '#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 add_app_form_submit($form, &$form_state) {
361      global $user;
362      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  /**  /**
# Line 361  function create_app_form_submit($form, & Line 400  function create_app_form_submit($form, &
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 {
# Line 497  function fetch_gadget_metadata($app_url) Line 536  function fetch_gadget_metadata($app_url)
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");  
 }  
   
 function shindig_integrator_remove_application($app_id) {  
         $res = db_query("DELETE FROM {user_applications} WHERE application_id=%d", base64_decode($app_id));  
         if (!$res) {  
                 return FALSE;  
         }  
         $res = db_query("DELETE FROM {applications} WHERE id=%d", base64_decode($app_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 = '') {
# Line 614  function theme_apps_on_profile($items) { Line 624  function theme_apps_on_profile($items) {
624    $attr = '';    $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 .= theme('add_gadget', $app_id, $mod_id, $view, $owner_id);        $output .= theme('add_gadget', $app_id, $mod_id, $view, check_plain($owner_id));
630        $output .= '<hr>';        $output .= '<hr>';
631      }      }
632    }    }
# Line 674  function theme_add_gadget($app_id, $mod_ Line 684  function theme_add_gadget($app_id, $mod_
684        if (isset($user_prefs[$key])) {        if (isset($user_prefs[$key])) {
685          unset($user_prefs[$key]);          unset($user_prefs[$key]);
686        }        }
687        $prefs .= '&up_' . urlencode($key) . '=' . urlencode($value);        $prefs .= '&up_' . urlencode(check_plain($key)) . '=' . urlencode(check_plain($value));
688      }      }
689    }    }
690    
# Line 703  function theme_add_gadget($app_id, $mod_ Line 713  function theme_add_gadget($app_id, $mod_
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='. base64_encode($gadget->id)      .'&aid='. base64_encode(check_plain($gadget->id))
720      .'&mid='. base64_encode($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_css($path ."/css/jquery.css");      drupal_add_css($path ."/css/jquery.css");
# Line 734  function theme_add_gadget($app_id, $mod_ Line 744  function theme_add_gadget($app_id, $mod_
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"></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"' .' id='. $iframe_id .'_title align="center" style="padding-top:30px;font-family: inherit;font-size: large;font-weight: bold;">'. $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;">'. check_plain($gadget->title) .'</div><br>';
748      $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";
749    }    }
750    return $output;    return $output;
# Line 759  function theme_application_canvas($app_i Line 769  function theme_application_canvas($app_i
769    $ret        = array();    $ret        = array();
770    $attr       = array();    $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     = "";
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() {  function set_user_preference() {
821    if (empty($_GET['st']) || empty($_GET['name']) || ! isset($_GET['value'])) {    if (empty($_POST['st']) || empty($_POST['name']) || ! isset($_POST['value'])) {
822      header("HTTP/1.0 400 Bad Request", true);      header("HTTP/1.0 400 Bad Request", true);
823      echo "<html><body><h1>400 - Bad Request</h1></body></html>";      echo "<html><body><h1>400 - Bad Request</h1></body></html>";
824    } else {    } else {
# Line 780  function set_user_preference() { Line 829  function set_user_preference() {
829      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicBlobCrypter');      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');      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/Crypto');
831      try {      try {
832        $st = urldecode(base64_decode($_GET['st']));        $st = urldecode(base64_decode($_POST['st']));
833        $key = urldecode($_GET['name']);        $key = urldecode($_POST['name']);
834        $value = urldecode($_GET['value']);        $value = urldecode($_POST['value']);
   
835        $token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age'));        $token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age'));
836        $app_id = $token->getAppId();        $app_id = $token->getAppId();
837        $viewer = $token->getViewerId();        $viewer = $token->getOwnerId();
838        $sql = "INSERT INTO application_settings (application_id, user_id, name, value) values (%d, %d, '%s', '%s') on duplicate key update value = '%s'";        $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);        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";        echo "success";

Legend:
Removed from v.1.2.2.10  
changed lines
  Added in v.1.2.2.11

  ViewVC Help
Powered by ViewVC 1.1.2