/[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.2.1, Thu Oct 22 11:46:07 2009 UTC revision 1.2.2.10.2.2, Fri Oct 23 12:28:34 2009 UTC
# Line 1  Line 1 
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
# Line 56  function shindig_integrator_help($path, Line 56  function shindig_integrator_help($path,
56                                                          <td>Interested in</td>                                                          <td>Interested in</td>
57                                                          <td>profile_interest</td>                                                          <td>profile_interest</td>
58                                                          <td>multi-line textfield</td>                                                          <td>multi-line textfield</td>
59                                                  </tr>                                                  </tr>
60                                          </table><br/>                                          </table><br/>
61                                          <li>Currently above fields are supported in the module. More fields can be easily added as per the requirement in <b>/shindig/php/src/social/sample/ShindigIntegratorDbFetcher.php</b>.</li>                                          <li>Currently above fields are supported in the module. More fields can be easily added as per the requirement in <b>/shindig/php/src/social/sample/ShindigIntegratorDbFetcher.php</b>.</li>
62                                          <li> The above field names are mandatory for this module to run successfully. If you don\'t want to use profile fields as defined above, you need to modify the function <b>getPeople()</b> of <b>"/shindig/php/src/social/sample/ShindigIntegratorDbFetcher.php"</b>, in order to run any open social application.</li>                                          <li> The above field names are mandatory for this module to run successfully. If you don\'t want to use profile fields as defined above, you need to modify the function <b>getPeople()</b> of <b>"/shindig/php/src/social/sample/ShindigIntegratorDbFetcher.php"</b>, in order to run any open social application.</li>
# Line 69  function shindig_integrator_help($path, Line 69  function shindig_integrator_help($path,
69                                                          <li><a href="@name">Name Specifications</a></li>                                                          <li><a href="@name">Name Specifications</a></li>
70                                                  </ul>                                                  </ul>
71                                          </li>                                          </li>
72                                  </ul>',                                  </ul>',
73                  array('@profile_help' => url('/admin/help/profile'),                  array('@profile_help' => url('/admin/help/profile'),
74                        '@address' => url('http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.Address'),                        '@address' => url('http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.Address'),
75                        '@body_type' => url('http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.BodyType'),                        '@body_type' => url('http://code.google.com/apis/opensocial/docs/0.8/reference/#opensocial.BodyType'),
# Line 77  function shindig_integrator_help($path, Line 77  function shindig_integrator_help($path,
77                       ));                       ));
78      return $output;      return $output;
79    }    }
80  }  }
81    
82  /**  /**
83   * Implementation of hook_perm().   * Implementation of hook_perm().
84   */   */
85  function shindig_integrator_perm() {  function shindig_integrator_perm() {
86    return array(    return array(
87      'view application directory',      'view application directory',
88      'create application',      'create application',
89          'delete applications',      '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',
93    );    );
94  }  }
# Line 100  function shindig_integrator_menu() { Line 100  function shindig_integrator_menu() {
100    $items                   = array();    $items                   = array();
101    $items['show_directory'] = array(    $items['show_directory'] = array(
102      'title'            => t('Application gallery'),      'title'            => t('Application gallery'),
103      'description'      => t('Show all applications.'),      'description'      => t('Show all applications.'),
104      'page callback'    => 'show_directory_page',      'page callback'    => 'show_directory_page',
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['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' => 'drupal_get_form',      'page callback'    => 'drupal_get_form',
112      'page arguments' => array('create_app_form'));      'page arguments'   => array('create_app_form'),
113        'access arguments' => array('create application'),
114        'type'             => MENU_NORMAL_ITEM);
115    
116    $items['application_canvas/%/%'] = array(    $items['application_canvas/%/%'] = array(
117      'title'            => t('Application canvas page'),      'title'            => t('Application canvas page'),
118      'description'      => t('Show Application In Canvas View.'),      'description'      => t('Show Application In Canvas View.'),
119      'page callback'    => 'application_canvas_page',      'page callback'    => 'application_canvas_page',
120      'page arguments'   => array(1, 2),      'page arguments'   => array(1, 2),
121      'access arguments' => array('view application canvas'),      'access arguments' => array('view application canvas'),
122      'type'             => MENU_CALLBACK);      'type'             => MENU_CALLBACK);
123    
124    $items['setPrefs'] = array(    $items['setPrefs'] = array(
125      'title'            => t('Application canvas page'),      'title'            => t('Application canvas page'),
126      'description'      => t('Set User preference.'),      'description'      => t('Set User preference.'),
127      'page callback'    => 'set_user_preference',      'page callback'    => 'set_user_preference',
128      'access arguments' => array('view application canvas'),      'access arguments' => array('view application canvas'),
129      'type'             => MENU_CALLBACK);      'type'             => MENU_CALLBACK);
130    
131    return $items;    return $items;
# Line 133  function shindig_integrator_menu() { Line 135  function shindig_integrator_menu() {
135   * Implementation of hook_theme().   * Implementation of hook_theme().
136   */   */
137  function shindig_integrator_theme() {  function shindig_integrator_theme() {
138    return array(    return array(
139      'apps_on_profile' => array(      'apps_on_profile' => array(
140        'arguments' => array('items' => NULL),        'arguments' => array('items' => NULL),
141      ),      ),
142      'add_gadget' => array(      'add_gadget' => array(
143        'arguments' => array(        'arguments' => array(
144          'app_id' => NULL,          'app_id' => NULL,
145          'mod_id' => NULL,          'mod_id' => NULL,
146          'view' => NULL,          'view' => NULL,
147          'owner_id' => NULL),          'owner_id' => NULL),
148      ),      ),
149      'application_canvas' => array(      'application_canvas' => array(
150        'arguments' => array(        'arguments' => array(
151          'app_id' => NULL,          'app_id' => NULL,
152          'mod_id' => NULL),          'mod_id' => NULL),
153      ),      ),
154    );    );
# Line 174  function shindig_integrator_block($op = Line 176  function shindig_integrator_block($op =
176        $output    = "";        $output    = "";
177        $apps      = array();        $apps      = array();
178        $result    = db_query("SELECT * FROM {applications} WHERE id IN (SELECT application_id FROM {user_applications} WHERE user_id =%d)", $owner_id);        $result    = db_query("SELECT * FROM {applications} WHERE id IN (SELECT application_id FROM {user_applications} WHERE user_id =%d)", $owner_id);
179            if(!$result) {        if (!$result) {
180              return FALSE;          return FALSE;
181            }        }
182        while ($record = db_fetch_object($result)) {        while ($record = db_fetch_object($result)) {
183          $app               = array();          $app               = array();
184          $app_id            = $record->id;          $app_id            = $record->id;
185          $result_get_mod_id = db_query("SELECT id FROM {user_applications} WHERE user_id =%d AND application_id =%d", $owner_id, $app_id);          $result_get_mod_id = db_query("SELECT id FROM {user_applications} WHERE user_id =%d AND application_id =%d", $owner_id, $app_id);
186          if(!$result_get_mod_id) {          if (!$result_get_mod_id) {
187            return FALSE;            return FALSE;
188              }          }
189          $record_get_mod_id = db_fetch_object($result_get_mod_id);          $record_get_mod_id = db_fetch_object($result_get_mod_id);
190          $mod_id            = $record_get_mod_id->id;          $mod_id            = $record_get_mod_id->id;
191          $redirect_url      = "application_canvas/". base64_encode($app_id) ."/". base64_encode($mod_id);          $redirect_url      = "application_canvas/". base64_encode($app_id) ."/". base64_encode($mod_id);
# Line 199  function shindig_integrator_block($op = Line 201  function shindig_integrator_block($op =
201  /**  /**
202   * Page callback for 'show_directory'.   * Page callback for 'show_directory'.
203   *   *
204   * @param   * @param
205   * $msg   * $msg
206   *   A string shows message whether application added to user's account or not   *   A string shows message whether application added to user's account or not
207   * $error   * $error
# Line 212  function show_directory_page($msg="", $e Line 214  function show_directory_page($msg="", $e
214    if ( !user_access('view application directory')) {    if ( !user_access('view application directory')) {
215      return ;      return ;
216    }    }
217    
218    if ( user_access('delete applications')) {    if ( user_access('delete applications')) {
219      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.');
220    }    }
221    
222    $path                = drupal_get_path('module', 'shindig_integrator');    $path                = drupal_get_path('module', 'shindig_integrator');
223    $default_thumb       = "$path/images/noimage.gif";    $default_thumb       = "$path/images/noimage.gif";
224    $num_apps_on_page    = 10;    $num_apps_on_page    = 10;
225    $result_get_user_app = db_query("SELECT application_id FROM {user_applications} WHERE user_id = %d", $user->uid);    $result_get_user_app = db_query("SELECT application_id FROM {user_applications} WHERE user_id = %d", $user->uid);
226    if(!$result_get_user_app) {    if (!$result_get_user_app) {
227      return FALSE;      return FALSE;
228    }    }
229    $i                   = 0;    $i                   = 0;
# Line 232  function show_directory_page($msg="", $e Line 234  function show_directory_page($msg="", $e
234    }    }
235    $num = base64_decode(arg(2));    $num = base64_decode(arg(2));
236    $attr['width']       = "100";    $attr['width']       = "100";
237    $attr['height']      = "75";    $attr['height']      = "75";
238    $result_get_all_apps = pager_query(    $result_get_all_apps = pager_query(
239      "SELECT * FROM {applications}",      "SELECT * FROM {applications}",
240      $num_apps_on_page, 0, "SELECT COUNT(*) FROM {applications}");      $num_apps_on_page, 0, "SELECT COUNT(*) FROM {applications}");
# Line 240  function show_directory_page($msg="", $e Line 242  function show_directory_page($msg="", $e
242    $headers = array();    $headers = array();
243    while ($record_get_all_apps = db_fetch_object($result_get_all_apps)) {    while ($record_get_all_apps = db_fetch_object($result_get_all_apps)) {
244      $app_id          = $record_get_all_apps->id;      $app_id          = $record_get_all_apps->id;
245      $app_thumb       = ($record_get_all_apps->thumbnail) ?      $app_thumb       = ($record_get_all_apps->thumbnail) ?
246        $record_get_all_apps->thumbnail:(($record_get_all_apps->screenshot) ?        $record_get_all_apps->thumbnail:(($record_get_all_apps->screenshot) ?
247        $record_get_all_apps->screenshot:$default_thumb);        $record_get_all_apps->screenshot:$default_thumb);
248      $app_description = $record_get_all_apps->description;      $app_description = $record_get_all_apps->description;
249      $app_dir_title   = ($record_get_all_apps->directory_title) ? $record_get_all_apps->directory_title: $record_get_all_apps->title;      $app_dir_title   = ($record_get_all_apps->directory_title) ? $record_get_all_apps->directory_title: $record_get_all_apps->title;
# Line 250  function show_directory_page($msg="", $e Line 252  function show_directory_page($msg="", $e
252      $app[]           = check_plain($app_dir_title);      $app[]           = check_plain($app_dir_title);
253      $app[]           = ($app_description=="")?"No Description":check_plain($app_description);      $app[]           = ($app_description=="")?"No Description":check_plain($app_description);
254      if (!in_array($app_id, $user_app_array)) {      if (!in_array($app_id, $user_app_array)) {
255          $app[] = (drupal_get_form('add_app_form_'. $app_id, $app_id) . (user_access('delete application') ?          $app[] = (drupal_get_form('add_app_form_'. $app_id, $app_id) . (user_access('delete application') ?
256            drupal_get_form('remove_app_form_'. $app_id, $app_id) : ' '));            drupal_get_form('remove_app_form_'. $app_id, $app_id) : ' '));
257      }      }
258      else {      else {
259        $app[] = ((user_access('delete application') ?        $app[] = ((user_access('delete application') ?
260          drupal_get_form('remove_app_form_'. $app_id, $app_id) :          drupal_get_form('remove_app_form_'. $app_id, $app_id) :
261          ''));          ''));
262      }      }
263      $apps[] = $app;      $apps[] = $app;
# Line 263  function show_directory_page($msg="", $e Line 265  function show_directory_page($msg="", $e
265    $output        = "";    $output        = "";
266    $attr['width'] = "100%";    $attr['width'] = "100%";
267    $output        = theme('table', $headers, $apps, $attr);    $output        = theme('table', $headers, $apps, $attr);
268    $output       .=  theme('pager', NULL, $num_apps_on_page, 0);    $output       .=  theme('pager', NULL, $num_apps_on_page, 0);
269    return $output;    return $output;
270  }  }
271    
# Line 278  function shindig_integrator_forms($form_ Line 280  function shindig_integrator_forms($form_
280      $forms[$form_id] = array('callback' => 'add_app_form');      $forms[$form_id] = array('callback' => 'add_app_form');
281      return $forms;      return $forms;
282    }    }
283    
284    if (strpos($form_id, "remove_app_form_") === 0) {    if (strpos($form_id, "remove_app_form_") === 0) {
285      $forms[$form_id] = array('callback' => 'remove_app_form');      $forms[$form_id] = array('callback' => 'remove_app_form');
286      return $forms;      return $forms;
287    }    }
288    
289  }  }
290    
291  /**  /**
292   * Form to remove an application from application directory   * Form to remove an application from application directory
293   *   *
294   * @param   * @param
295   * $form_id   * $form_id
296   *   Form id   *   Form id
297   * $app_id   * $app_id
# Line 300  function remove_app_form($form_id, $app_ Line 302  function remove_app_form($form_id, $app_
302      '#type' => 'hidden',      '#type' => 'hidden',
303      '#value' => $app_id      '#value' => $app_id
304    );    );
305    
306    $form['submit'] = array(    $form['submit'] = array(
307      '#type'  => 'submit',      '#type'  => 'submit',
308      '#value' => t('Remove'),      '#value' => t('Remove'),
# Line 324  function remove_app_form_submit($form, & Line 326  function remove_app_form_submit($form, &
326    $res = db_query("DELETE FROM {applications} WHERE id=%d", $app_id);    $res = db_query("DELETE FROM {applications} WHERE id=%d", $app_id);
327    if (!$res) {    if (!$res) {
328      drupal_set_message(t('There is some problem to remove these application from directory. Please try again.'));      drupal_set_message(t('There is some problem to remove these application from directory. Please try again.'));
329    }    }
330    else {    else {
331      drupal_set_message(t('Application removed successfully from directory.'));      drupal_set_message(t('Application removed successfully from directory.'));
332    }    }
# Line 333  function remove_app_form_submit($form, & Line 335  function remove_app_form_submit($form, &
335  /**  /**
336   * Form to add an application to user's account   * Form to add an application to user's account
337   *   *
338   * @param   * @param
339   * $form_id   * $form_id
340   *   Form id   *   Form id
341   * $app_id   * $app_id
# Line 344  function add_app_form($form_id, $app_id) Line 346  function add_app_form($form_id, $app_id)
346      '#type' => 'hidden',      '#type' => 'hidden',
347      '#value' => $app_id      '#value' => $app_id
348    );    );
349     $form['add_app_submit'] = array(    $form['add_app_submit'] = array(
350      '#type'  => 'submit',      '#type'  => 'submit',
351      '#value' => t('Add'),      '#value' => t('Add'),
352    );    );
353    $form['#submit'] = array("add_app_form_submit");    $form['#submit'] = array("add_app_form_submit");
   
   
354    return $form;    return $form;
355  }  }
356    
# Line 368  function add_app_form_submit($form, &$fo Line 368  function add_app_form_submit($form, &$fo
368      drupal_set_message(t("There is some problem in adding application to your account. Please try again."), 'error');      drupal_set_message(t("There is some problem in adding application to your account. Please try again."), 'error');
369    }    }
370    else {    else {
371      $msg = t("Application added successfully to your account");      $msg = t("Application added successfully to your account");
372      drupal_set_message(t("Application added successfully to your account"));      drupal_set_message(t("Application added successfully to your account"));
373    }    }
374  }  }
# Line 402  function create_app_form_submit($form, & Line 402  function create_app_form_submit($form, &
402    if (!empty($response['error'])) {    if (!empty($response['error'])) {
403      $error = t('Cannot add the application. Error: %error', array('%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 {
407      drupal_set_message(t('Application successfully added to Application Gallery.'));      drupal_set_message(t('Application successfully added to Application Gallery.'));
408    }    }
# Line 457  function save_application($app_url) { Line 457  function save_application($app_url) {
457        $info['description']     = isset($gadget->description) ? $gadget->description:'';        $info['description']     = isset($gadget->description) ? $gadget->description:'';
458        $info['settings']        = isset($gadget->userPrefs) ? serialize($gadget->userPrefs):'';        $info['settings']        = isset($gadget->userPrefs) ? serialize($gadget->userPrefs):'';
459        $info['height']          = !empty($gadget->height) ? $gadget->height:'0';        $info['height']          = !empty($gadget->height) ? $gadget->height:'0';
460    
461        switch ($gadget->scrolling) {        switch ($gadget->scrolling) {
462          case TRUE :          case TRUE :
463          case 1:          case 1:
464            $info['scrolling'] = "1";            $info['scrolling'] = "1";
465            break;            break;
466          default : $info['scrolling'] = "0";          default : $info['scrolling'] = "0";
467        }        }
468        // Extract the version from the iframe url        // Extract the version from the iframe url
469        $iframe_url              = $gadget->iframeUrl;        $iframe_url              = $gadget->iframeUrl;
470        $iframe_params           = array();        $iframe_params           = array();
# Line 472  function save_application($app_url) { Line 472  function save_application($app_url) {
472        parse_str($iframe_url, $iframe_params);        parse_str($iframe_url, $iframe_params);
473        $info['version']         = isset($iframe_params['v']) ? $iframe_params['v']:'';        $info['version']         = isset($iframe_params['v']) ? $iframe_params['v']:'';
474        $info['modified']        = time();        $info['modified']        = time();
475    
476        // Insert new application into our db, or if it exists (but had expired info) update the meta data        // Insert new application into our db, or if it exists (but had expired info) update the meta data
477        db_query("INSERT INTO {applications}        db_query("INSERT INTO {applications}
478            (id, url, title, directory_title, screenshot, thumbnail, author, author_email, description, settings, version, height, scrolling, modified)            (id, url, title, directory_title, screenshot, thumbnail, author, author_email, description, settings, version, height, scrolling, modified)
479                    VALUES(0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')                    VALUES(0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
480                  ON DUPLICATE KEY UPDATE url = '%s', title = '%s', directory_title = '%s', screenshot = '%s', thumbnail = '%s', author = '%s',   author_email = '%s', description = '%s', settings = '%s', version = '%s', height = '%s', scrolling = '%s', modified = '%s'",                  ON DUPLICATE KEY UPDATE url = '%s', title = '%s', directory_title = '%s', screenshot = '%s', thumbnail = '%s', author = '%s',   author_email = '%s', description = '%s', settings = '%s', version = '%s', height = '%s', scrolling = '%s', modified = '%s'",
481          $info['url'], $info['title'], $info['directory_title'],          $info['url'], $info['title'], $info['directory_title'],
482          $info['screenshot'], $info['thumbnail'], $info['author'],          $info['screenshot'], $info['thumbnail'], $info['author'],
483          $info['author_email'], $info['description'], $info['settings'],          $info['author_email'], $info['description'], $info['settings'],
484          $info['version'], $info['height'], $info['scrolling'],          $info['version'], $info['height'], $info['scrolling'],
485          $info['modified'], $info['url'], $info['title'],          $info['modified'], $info['url'], $info['title'],
486          $info['directory_title'], $info['screenshot'], $info['screenshot'],          $info['directory_title'], $info['screenshot'], $info['screenshot'],
487          $info['thumbnail'], $info['author'], $info['author_email'],          $info['thumbnail'], $info['author'], $info['author_email'],
488          $info['description'], $info['settings'], $info['version'],          $info['description'], $info['settings'], $info['version'],
489          $info['height'], $info['scrolling'], $info['modified']);          $info['height'], $info['scrolling'], $info['modified']);
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 = '';        $error = '';
# Line 516  function fetch_gadget_metadata($app_url) Line 516  function fetch_gadget_metadata($app_url)
516    module_load_include('php', 'shindig_integrator', '/shindig/php/config/local');    module_load_include('php', 'shindig_integrator', '/shindig/php/config/local');
517    $request = json_encode(    $request = json_encode(
518      array(      array(
519        'context' => array('country' => 'US', 'language' => 'en', 'view' => 'default', 'container' => 'default'),        'context' => array('country' => 'US', 'language' => 'en', 'view' => 'default', 'container' => 'default'),
520        'gadgets' =>    array(        'gadgets' =>    array(
521          array('url' => $app_url, 'moduleId' => '1'))          array('url' => $app_url, 'moduleId' => '1'))
522      )      )
# Line 553  function shindig_integrator_user($op, &$ Line 553  function shindig_integrator_user($op, &$
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();        $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
560                                              )", $owner_id);                                              )", $owner_id);
561        if(!$result_get_app) {        if (!$result_get_app) {
562              return FALSE;          return FALSE;
563            }        }
564        $record_found = FALSE;        $record_found = FALSE;
565        while ($record_get_app    = db_fetch_object($result_get_app)) {        while ($record_get_app    = db_fetch_object($result_get_app)) {
566          $record_found      = TRUE;          $record_found      = TRUE;
567          $app_id            = $record_get_app->id;          $app_id            = $record_get_app->id;
568          $result_get_mod_id = db_query("SELECT id FROM {user_applications} WHERE user_id = %d AND application_id = %d", $owner_id, $app_id);          $result_get_mod_id = db_query("SELECT id FROM {user_applications} WHERE user_id = %d AND application_id = %d", $owner_id, $app_id);
569                  if(!$result_get_mod_id) {          if (!$result_get_mod_id) {
570                    return FALSE;            return FALSE;
571                  }          }
572          $record_get_mod_id = db_fetch_object($result_get_mod_id);          $record_get_mod_id = db_fetch_object($result_get_mod_id);
573          $mod_id            = $record_get_mod_id->id;          $mod_id            = $record_get_mod_id->id;
574          $apps[]            = array('app_id' => $app_id, 'mod_id' => $mod_id);          $apps[]            = array('app_id' => $app_id, 'mod_id' => $mod_id);
575        }        }
576        $output  =  theme('apps_on_profile', $apps);        $output  =  theme('apps_on_profile', $apps);
577        $items[] = array('title' => 'Applications', 'value' => $output, 'recordFound' => $record_found);        $items[] = array('title' => 'Applications', 'value' => $output, 'recordFound' => $record_found);
578    
579        $owner->content['Applications'] = array(        $owner->content['Applications'] = array(
580              '#type'       => 'user_profile_item',              '#type'       => 'user_profile_item',
581              '#title'      => t('Applications'),              '#title'      => t('Applications'),
# Line 590  function shindig_integrator_user($op, &$ Line 590  function shindig_integrator_user($op, &$
590  /**  /**
591   * Page callback for 'application_canvas'   * Page callback for 'application_canvas'
592   *   *
593   * @param   * @param
594   * $app_id   * $app_id
595   *   Application id   *   Application id
596   * $mod_id   * $mod_id
597   *   Module id - specific user's application id   *   Module id - specific user's application id
598   */   */
# Line 630  function theme_apps_on_profile($items) { Line 630  function theme_apps_on_profile($items) {
630        $output .= '<hr>';        $output .= '<hr>';
631      }      }
632    }    }
633    
634    return $output;    return $output;
635  }  }
636    
637  /**  /**
638   * Theme to add_gadget on any type of page   * Theme to add_gadget on any type of page
639   *   *
640   * @param   * @param
641   * $app_id   * $app_id
642   *   Application id   *   Application id
643   * $mod_id   * $mod_id
644   *   Module id - specific user's application id   *   Module id - specific user's application id
645   * $view   * $view
# Line 661  function theme_add_gadget($app_id, $mod_ Line 661  function theme_add_gadget($app_id, $mod_
661    $viewer_id   = $user->uid;    $viewer_id   = $user->uid;
662    $output      = '';    $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    while ($gadget = db_fetch_object($rs_Apps)) {    while ($gadget = db_fetch_object($rs_Apps)) {
668    $container   = "default";    $container   = "default";
669    
670    // get user preferences    // 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);    $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();    $user_prefs = array();
673    while ($row = db_fetch_array($result)) {    while ($row = db_fetch_array($result)) {
674      $user_prefs[$row['name']] = $row['value'];      $user_prefs[$row['name']] = $row['value'];
675    }    }
676    
   
677    $prefs       = "";    $prefs       = "";
678    
679    $settings = ! empty($gadget->settings) ? unserialize($gadget->settings) : array();    $settings = ! empty($gadget->settings) ? unserialize($gadget->settings) : array();
680    foreach ($settings as $key => $setting) {    foreach ($settings as $key => $setting) {
681      if (! empty($key)) {      if (! empty($key)) {
682        $value = isset($user_prefs[$key]) ? $user_prefs[$key] : (isset($setting->default) ? $setting->default : null);        $value = isset($user_prefs[$key]) ? $user_prefs[$key] : (isset($setting->default) ? $setting->default : NULL);
683        if (isset($user_prefs[$key])) {        if (isset($user_prefs[$key])) {
684          unset($user_prefs[$key]);          unset($user_prefs[$key]);
685        }        }
686        $prefs .= '&up_' . urlencode(check_plain($key)) . '=' . urlencode(check_plain($value));        $prefs .= '&up_'. urlencode(check_plain($key)) .'='. urlencode(check_plain($value));
687      }      }
688    }    }
689    
# Line 692  function theme_add_gadget($app_id, $mod_ Line 691  function theme_add_gadget($app_id, $mod_
691    foreach ($user_prefs as $name => $value) {    foreach ($user_prefs as $name => $value) {
692      // if some keys _are_ set in the db, but not in the gadget metadata, we still parse them on the url      // if some keys _are_ set in the db, but not in the gadget metadata, we still parse them on the url
693      // (the above loop unsets the entries that matched      // (the above loop unsets the entries that matched
694      if (! empty($value) && ! isset($appParams[$name])) {      if (! empty($value)) {
695        $prefs .= '&up_' . urlencode($name) . '=' . urlencode($value);        $prefs .= '&up_'. urlencode($name) .'='. urlencode($value);
696      }      }
697    }    }
698    $security_token = BasicSecurityToken::createFromValues(isset($owner_id) ? $owner_id:'0', // Owner    $security_token = BasicSecurityToken::createFromValues(isset($owner_id) ? $owner_id:'0', // Owner
# Line 710  function theme_add_gadget($app_id, $mod_ Line 709  function theme_add_gadget($app_id, $mod_
709    module_load_include('php', 'shindig_integrator', '/shindig/php/config/local');    module_load_include('php', 'shindig_integrator', '/shindig/php/config/local');
710    
711    $path = drupal_get_path('module', 'shindig_integrator');    $path = drupal_get_path('module', 'shindig_integrator');
712    
713    $iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'.    $iframe_url = ShindigConfig::get('gadget_server') .'/gadgets/ifr?'.
714      'synd='. $container      'synd='. $container
715      .'&container='. check_plain($container)      .'&container='. check_plain($container)
716      .'&viewer='. check_plain((isset($viewer_id) ? $viewer_id:'0'))      .'&viewer='. check_plain((isset($viewer_id) ? $viewer_id:'0'))
717      .'&owner='. check_plain((isset($owner_id) ? $owner_id:$viewer_id))      .'&owner='. check_plain((isset($owner_id) ? $owner_id:$viewer_id))
718      .'&aid='. base64_encode(check_plain($gadget->id))      .'&aid='. base64_encode(check_plain($gadget->id))
719      .'&mid='. base64_encode(check_plain($mod_id))      .'&mid='. base64_encode(check_plain($mod_id))
720      .'&nocache=1'      .'&nocache=1'
721      .'&country=US'      .'&country=US'
722      .'&lang=EN'      .'&lang=EN'
723      .'&view='. check_plain($view)      .'&view='. check_plain($view)
724      .'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST'])      .'&parent='. urlencode('http://'. $_SERVER['HTTP_HOST'])
725      . $prefs      . $prefs
726      . (isset($_REQUEST['appParams']) ? '&view-params='. urlencode(check_plain($_REQUEST['appParams'])):'')      . (isset($_REQUEST['appParams']) ? '&view-params='. urlencode(check_plain($_REQUEST['appParams'])):'')
727      .'&st='. base64_encode($security_token->toSerialForm())      .'&st='. base64_encode($security_token->toSerialForm())
728      .'&v='. check_plain($gadget->version)      .'&v='. check_plain($gadget->version)
729      .'&url='. urlencode(check_url($gadget->url))      .'&url='. urlencode(check_url($gadget->url))
730      .'#rpctoken='. rand(0, getrandmax());      .'#rpctoken='. rand(0, getrandmax());
731    
732      $height      = !empty($gadget->height) ? check_plain($gadget->height):'200';      $height      = !empty($gadget->height) ? check_plain($gadget->height):'200';
733      $iframe_name = "remote_iframe_" . check_plain($mod_id);      $iframe_name = "remote_iframe_" . check_plain($mod_id);
734      $iframe_id   = "remote_iframe_" . check_plain($mod_id);      $iframe_id   = "remote_iframe_" . check_plain($mod_id);
735      $scrolling   = $gadget->scrolling ? 'yes':'no';      $scrolling   = $gadget->scrolling ? 'yes':'no';
736    
737      drupal_add_css($path ."/css/jquery.css");      drupal_add_css($path ."/css/jquery.css");
738      drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/util.js?c=1");      drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/util.js?c=1");
739      drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/json.js?c=1");      drupal_add_js($path ."/shindig/features/src/main/javascript/features/core/json.js?c=1");
740      drupal_add_js($path ."/shindig/features/src/main/javascript/features/rpc/rpc.js?c=1");      drupal_add_js($path ."/shindig/features/src/main/javascript/features/rpc/rpc.js?c=1");
741      drupal_add_js($path ."/js/jquery.all.js");      drupal_add_js($path ."/js/jquery.all.js");
742      drupal_add_js($path ."/js/container.js");      drupal_add_js($path ."/js/container.js");
743    
744      $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>';
745    
746      $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;">'. check_plain($gadget->title) .'</div><br/>';
747      $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";
748    }    }
749    return $output;    return $output;
750  }  }
751    
752  /**  /**
753   * Theme to show application on canvas page   * Theme to show application on canvas page
754   *   *
755   * @param   * @param
756   * $app_id   * $app_id
757   *   Application id   *   Application id
758   * $mod_id   * $mod_id
759   *   Module id - specific user's application id   *   Module id - specific user's application id
760   * @return   * @return
# Line 782  function theme_application_canvas($app_i Line 781  function theme_application_canvas($app_i
781  /**  /**
782   * Form to delete an application from user's account   * Form to delete an application from user's account
783   *   *
784   * @param   * @param
785   * $form_id   * $form_id
786   *   Form id   *   Form id
787   * $app_id   * $app_id
# Line 793  function delete_app_form($form_id, $app_ Line 792  function delete_app_form($form_id, $app_
792      '#type' => 'hidden',      '#type' => 'hidden',
793      '#value' => $app_id      '#value' => $app_id
794    );    );
795    
796    $form['submit'] = array(    $form['submit'] = array(
797      '#type'  => 'submit',      '#type'  => 'submit',
798      '#value' => t('Delete application'),      '#value' => t('Delete application'),
# Line 819  function delete_app_form_submit($form, & Line 818  function delete_app_form_submit($form, &
818   */   */
819  function set_user_preference() {  function set_user_preference() {
820    if (empty($_POST['st']) || empty($_POST['name']) || ! isset($_POST['value'])) {    if (empty($_POST['st']) || empty($_POST['name']) || ! isset($_POST['value'])) {
821      header("HTTP/1.0 400 Bad Request", true);      header("HTTP/1.0 400 Bad Request", TRUE);
822      echo "<html><body><h1>400 - Bad Request</h1></body></html>";      echo "<html><body><h1>400 - Bad Request</h1></body></html>";
823    } else {    }
824          module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/Config');    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');      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/SecurityToken');
827      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter');      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/BlobCrypter');
828      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken');      module_load_include('php', 'shindig_integrator', '/shindig/php/src/common/sample/BasicSecurityToken');
# Line 832  function set_user_preference() { Line 832  function set_user_preference() {
832        $st = urldecode(base64_decode($_POST['st']));        $st = urldecode(base64_decode($_POST['st']));
833        $key = urldecode($_POST['name']);        $key = urldecode($_POST['name']);
834        $value = urldecode($_POST['value']);        $value = urldecode($_POST['value']);
835    
836        $token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age'));        $token = BasicSecurityToken::createFromToken($st, Config::get('token_max_age'));
837        $app_id = $token->getAppId();        $app_id = $token->getAppId();
838        $viewer = $token->getOwnerId();        $viewer = $token->getViewerId();
839        $sql = "INSERT INTO application_settings (application_id, user_id, name, value) values (%d, %d, '%s', '%s') on duplicate key update value = '%s'";        db_query("INSERT INTO {application_settings}
840        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);                (application_id, user_id, name, value)
841                  values (%d, %d, '%s', '%s')
842                  on duplicate key update value = '%s'", $app_id, $viewer, $key, $value, $value);
843        echo "success";        echo "success";
844      } catch (Exception $e) {      } catch (Exception $e) {
845        header("HTTP/1.0 400 Bad Request", true);        header("HTTP/1.0 400 Bad Request", TRUE);
846        echo "<html><body><h1>400 - Bad Request</h1>" . $e->getMessage() . "</body></html>";        echo "<html><body><h1>400 - Bad Request</h1>". $e->getMessage() ."</body></html>";
847      }      }
848    }    }
849    die();    die();

Legend:
Removed from v.1.2.2.10.2.1  
changed lines
  Added in v.1.2.2.10.2.2

  ViewVC Help
Powered by ViewVC 1.1.2