/[drupal]/contributions/modules/fb/fb_actions.module
ViewVC logotype

Diff of /contributions/modules/fb/fb_actions.module

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

revision 1.6, Tue Jun 17 22:47:24 2008 UTC revision 1.7, Fri Aug 1 07:25:26 2008 UTC
# Line 431  function fb_actions_cron_per_user($obj, Line 431  function fb_actions_cron_per_user($obj,
431  }  }
432    
433    
   
   ///////////////////////////////////////////////////////////////////  
   // Below this line is obsolete code.  Actions have changed considerably, and the following is deprecated.  Recommended that you get the very latest actions module and start using it.  
   
   /**  
    * Implementation of an Action.  See Actions module.  
    *  
    * This action publishes to a user's mini-feed.  
    */  
 function action_fb_write_minifeed($op, $edit = array(), $node) {  
   if ($op == 'metadata') {  
     return array('description' => t('Post to Facebook mini-feed'),  
                  'type' => t('Facebook'),  
                  'batchable' => FALSE,  
                  'configurable' => TRUE,  
     );  
   }  
   else if ($op == 'form') {  
     $options = fb_get_app_options(TRUE);  
     $form['description'] = array('#value' => t('Note that this action will only succeed when executed from a Facebook canvas page when the user is logged in, or on non-canvas pages when the logged in user has an infinite session key.  These are privacy restrictions enforced by the Facebook API.'));  
     $form['fb_app_nid'] =  
       array('#type' => 'select',  
             '#title' => t('Application'),  
             '#default_value' => $edit['fb_app_nid'],  
             '#options' => $options,  
             '#description' => t('Log into Facebook as which action?  If %current, action will only be performed only on canvas pages.',  
                                 array('%current' => $options[FB_APP_CURRENT])),  
       );  
     $form['title'] = array('#type' => 'textfield',  
                            '#title' => t('Title'),  
                            '#default_value' => $edit['title'],  
                            '#description' => t('Title line of mini-feed item.  (Most Facebook mini-feed items have only a title, and no message body).'),  
                            '#required' => TRUE,  
     );  
     $form['body'] = array('#type' => 'textarea',  
                           '#title' => t('Body'),  
                           '#default_value' => $edit['body'],  
                           '#description' => t('Text to publish on mini-feed.  In many cases, only the title is required and this may be left blank.<br />The following token will be replaced: !token_help',  
                                               array('!token_help' => theme('token_help', 'node') . theme('token_help', 'fb_app'))),  
     );  
     return $form;  
   }  
   else if ($op == 'submit') {  
     return array('fb_app_nid' => $edit['fb_app_nid'],  
                  'body' => $edit['body'],  
                  'title' => $edit['title'],  
     );  
   }  
   else if ($op == 'do') {  
     // Log into facebook as the current user.  
     if ($fb_app = $GLOBALS['fb_app'])  
       if ($edit['fb_app_nid'] == FB_APP_CURRENT || $fb_app->nid == $edit['fb_app_nid'])  
         // We're in a canvas page for the desired app.  We're already logged in.  
         $fb = $GLOBALS['fb'];  
     if (!$fb && $edit['fb_app_nid'] != FB_APP_CURRENT) {  
       global $user;  
       // Need to log into this app.  
       $fb_app = fb_get_app(array('nid' => $edit['fb_app_nid']));  
       $fbu = fb_get_fbu($user->uid, $fb_app);  
       if ($fbu) {  
         $fb = fb_api_init($fb_app, $fbu);  
       }  
     }  
     // Even if we have an $fb now, it may not have permission to do all things  
     // we ask of it.  
     if ($fb) {  
       // Replace both node and fb_app related tokens  
       $title = token_replace($edit['title'], 'node', $node);  
       $title = token_replace($title, 'fb_app', $fb_app);  
       $body = token_replace($edit['body'], 'node', $node);  
       $body = token_replace($body, 'fb_app', $fb_app);  
       $fb->api_client->feed_publishActionOfUser($title, $body);  
       fb_report_errors($fb);  
     }  
   }  
 }  
   
   
 /**  
  * Implementation of an Action.  See Actions module.  
  *  
  * This action updates a user's profile FBML.  
  */  
 function action_fb_set_profile_fbml($op, $edit = array(), $obj) {  
   if ($op == 'metadata') {  
     return array('description' => t('Facebook set profile FBML'),  
                  'type' => t('Facebook'),  
                  'batchable' => FALSE,  
                  'configurable' => TRUE,  
     );  
   }  
   else if ($op == 'form') {  
     $options = fb_get_app_options(TRUE);  
     $form['description'] = array('#value' => t('This action will update the current user\'s Facebook profile.  Suitable for canvas pages and cron jobs (if infinite session is configured).'));  
     $form['fb_app_nid'] =  
       array('#type' => 'select',  
             '#title' => t('Application'),  
             '#default_value' => $edit['fb_app_nid'],  
             '#options' => $options,  
             '#description' => t('Log into Facebook as which application?  %current is OK when invoked from canvas pages or cron jobs.',  
                                 array('%current' => $options[FB_APP_CURRENT])),  
       );  
   
     $form['body'] = array('#type' => 'textarea',  
                           '#title' => t('Profile FBML'),  
                           '#default_value' => $edit['body'],  
                           '#description' => t('FBML to write to user\'s profile.<br />The following token will be replaced: !token_help',  
                                               array('!token_help' => theme('token_help', 'fb_app'))),  
     );  
     return $form;  
   }  
   else if ($op == 'submit') {  
     return array('fb_app_nid' => $edit['fb_app_nid'],  
                  'body' => $edit['body'],  
     );  
   }  
   else if ($op == 'do') {  
     // Log into facebook as the current user.  
     if ($fb_app = $GLOBALS['fb_app'])  
       if ($edit['fb_app_nid'] == FB_APP_CURRENT || $fb_app->nid == $edit['fb_app_nid'])  
         // We're in a canvas page for the desired app.  We're already logged in.  
         $fb = $GLOBALS['fb'];  
     if (!$fb && $edit['fb_app_nid'] != FB_APP_CURRENT) {  
       // Need to log into this app.  
       $fb_app = fb_get_app(array('nid' => $edit['fb_app_nid']));  
       $fb = fb_api_init($fb_app, FB_FBU_INFINITE_SESSION);  
     }  
   
     if ($fb) {  
       global $user;  
       $fbu = fb_get_fbu($user->uid, $fb_app);  
       // Replace fb_app related tokens  
       $body = token_replace($edit['body'], 'fb_app', $fb_app);  
       // TODO: enable filters for body.  
   
       // print("Setting facebook profile markup for $user->name to " . dpr($body, 1));  
   
       $fb->api_client->profile_setFBML($body, $fbu);  
       fb_report_errors($fb);  
     }  
   }  
 }  
 /**  
  * Implementation of an Action.  
  *  
  * This action updates reference FBML.  
  * http://developer.facebook.com/documentation.php?v=1.0&method=fbml.setRefHandle  
  */  
 function action_fb_set_ref_fbml($op, $edit = array(), $fb_app) {  
   if ($op == 'metadata') {  
     return array('description' => t('Facebook set reference FBML'),  
                  'type' => t('Facebook App'),  
                  'batchable' => FALSE,  
                  'configurable' => TRUE,  
     );  
   }  
   else if ($op == 'form') {  
     $options = fb_get_app_options(TRUE);  
     $form['description'] = array('#value' => t('This action will update reference FBML.  See Facebook\'s documentation of the &lt;fb:ref&gt; tag.  Suitable for canvas pages and cron jobs (if infinite session is configured).'));  
     $form['fb_app_nid'] =  
       array('#type' => 'select',  
             '#title' => t('Application'),  
             '#default_value' => $edit['fb_app_nid'],  
             '#options' => $options,  
             '#description' => t('Log into Facebook as which application?  %current is OK when invoked from canvas pages or cron jobs.',  
                                 array('%current' => $options[FB_APP_CURRENT])),  
       );  
   
     $form['handle'] = array('#type' => 'textfield',  
                             '#title' => t('Handle'),  
                             '#default_value' => $edit['handle'],  
     );  
     $form['body'] = array('#type' => 'textarea',  
                           '#title' => t('Profile FBML'),  
                           '#default_value' => $edit['body'],  
                           '#description' => t('FBML to write to user\'s profile.<br />The following token will be replaced: !token_help',  
                                               array('!token_help' => theme('token_help', 'fb_app'))),  
     );  
     $form['body_filter'] = filter_form($edit['body_filter'],  
                                        NULL,  
                                        array('body_filter'));  
     return $form;  
   }  
   else if ($op == 'submit') {  
     return array('handle' => $edit['handle'],  
                  'body' => $edit['body'],  
                  'body_filter' => $edit['body_filter'],  
     );  
   }  
   else if ($op == 'do') {  
     if ($GLOBALS['fb_app']->apikey == $fb_app->apikey)  
       // Use global FB api, if set up.  
       $fb = $GLOBALS['fb'];  
     else  
       $fb = fb_api_init($fb_app, FB_FBU_INFINITE_SESSION);  
   
     // This will be set on canvas pages and Facebook App cron actions.  
     if ($fb) {  
       // Replace fb_app related tokens  
       $body = token_replace($edit['body'], 'fb_app', $fb_app);  
       $body = check_markup($body, $edit['body_filter'], FALSE);  
       $fb->api_client->fbml_setRefHandle($edit['handle'], $body);  
       // TODO: enable filters for body.  
       $fb->api_client->profile_setFBML($body, $fbu);  
       fb_report_errors($fb);  
     }  
   }  
 }  
   
   
   
434  ?>  ?>

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.2