/[drupal]/contributions/modules/posterous/posterous.module
ViewVC logotype

Diff of /contributions/modules/posterous/posterous.module

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

revision 1.5, Sat Dec 20 02:42:08 2008 UTC revision 1.5.2.1, Fri Apr 3 04:08:34 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: posterous.module,v 1.4 2008/12/19 17:43:31 sethfreach Exp $  // $Id: posterous.module,v 1.5 2008/12/20 02:42:08 sethfreach Exp $
3    
4  define("POSTEROUS_TO_EMAIL", "post@posterous.com");  define("POSTEROUS_TO_EMAIL", "post@posterous.com");
5    
# Line 16  function posterous_perm() { Line 16  function posterous_perm() {
16  /**  /**
17   * Implementation of hook_menu()   * Implementation of hook_menu()
18   */   */
19  function posterous_menu($may_cache) {  function posterous_menu() {
20    $items = array();    $items['admin/settings/posterous'] = array(
21    if ($may_cache) {      'title' => 'Posterous',
22      $items[] = array(      'description' => 'Denote which content types can be posted to Posterous',
23        'title' => t('Posterous'),      'page callback' => 'drupal_get_form',
24        'path' => 'admin/settings/posterous',      'page arguments' => array('posterous_admin_settings'),
25        'description' => t('Denote which content types can be posted to Posterous'),      'access arguments' => array('configure posterous'),
26        'callback' => 'drupal_get_form',    );
       'callback arguments' => array('posterous_admin_settings'),  
       'access' => user_access('configure posterous'),  
     );  
   }  
27    
28    return $items;    return $items;
29  }  }
# Line 35  function posterous_menu($may_cache) { Line 31  function posterous_menu($may_cache) {
31  function posterous_admin_settings() {  function posterous_admin_settings() {
32    $form['posterous_content_types'] = array(    $form['posterous_content_types'] = array(
33      '#title' => t('Select the content types that may be posted to Posterous'),      '#title' => t('Select the content types that may be posted to Posterous'),
34      '#description' => t('Individual users\' roles still need permission to post, but, even with appropriate roles, these are the only content types that may be posted to Posterous.'),      '#description' => t('Individual users\' roles still need permission to post, but, even with appropriate roles, these are
35    the only content types that may be posted to Posterous.'),
36      '#type' => 'checkboxes',      '#type' => 'checkboxes',
37      '#options' => node_get_types('names'),      '#options' => node_get_types('names'),
38      '#default_value' => variable_get('posterous_content_types', array('story')),      '#default_value' => variable_get('posterous_content_types', array('story')),
39    );    );
40    $form['posterous_allow_on_edit'] = array(    $form['posterous_allow_on_edit'] = array(
41      '#title' => t('Allow Posterous option on node edit?'),      '#title' => t('Allow Posterous option on node edit?'),
42      '#description' => t('Checking this will make the "Send to Posterous also?" option available when editing existing content (at node/$nid/edit).  This will not edit the content at Posterous, however, it will create a new (and presumably, similar, slightly edited) Posterous post.'),      '#description' => t('Checking this will make the "Send to Posterous also?" option available when editing existing
43    content (at node/$nid/edit).  This will not edit the content at Posterous, however, it will create a new (and presumably,
44    similar, slightly edited) Posterous post.'),
45      '#type' => 'checkbox',      '#type' => 'checkbox',
46      '#default_value' => variable_get('posterous_allow_on_edit', 0),      '#default_value' => variable_get('posterous_allow_on_edit', 0),
47    );    );
# Line 50  function posterous_admin_settings() { Line 49  function posterous_admin_settings() {
49    return system_settings_form($form);    return system_settings_form($form);
50  }  }
51    
52  function posterous_form_alter($form_id, &$form) {  function posterous_form_alter(&$form, &$form_state, $form_id) {
53    //is this a node form AND it's the add new one form AND this content type has been marked availible for posting?    // is this a node form
54    if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form' && in_array($form['#node']->type, variable_get('posterous_content_types', array())) ) {    if ( isset($form['#node']) ) {
55      //and this user has permission to post?      $type = $form['#node']->type;
56      if (user_access('post to posterous')) {      $post_types = variable_get('posterous_content_types', array());
57        global $user;  
58        $dis = variable_get('posterous_allow_on_edit', 0) ? FALSE : TRUE;      // AND this content type has been marked availible for posting?
59        $form['posterous'] = array(      if ( $post_types[$type] ) {
60          '#title' => t('Posterous'),  
61          '#description' => t('Selecting this option will also mail this content to post@posterous.com from your account email, '. $user->mail .'.'),        // AND this user has permission to post?
62          '#type' => 'checkboxes',        if (user_access('post to posterous')) {
63          '#options' => array( 'post_to_posterous' => t('Send to Posterous also?') ),          global $user;
64          '#weight' => 5,          $form['posterous'] = array(
65          '#disabled' => $dis,            '#title' => t('Posterous'),
66        );            '#description' => t('Selecting this option will also mail this content to post@posterous.com from your account
67    email, '. $user->mail .'.'),
68              '#type' => 'checkboxes',
69              '#options' => array( 'post_to_posterous' => t('Send to Posterous also?') ),
70              '#weight' => 5,
71            );
72          }
73    
74          // disable the checkbox, if needed.
75          // are we editing a previously submitted form AND have we been told to not allow submission here?
76          if ( !empty($form['changed']['#default_value']) && !variable_get('posterous_allow_on_edit', 0) ) {
77            $form['posterous']['#disabled'] = true;
78            $form['posterous']['#description'] = t('This option has been disabled by the site administrator on edits to
79    previously submitted content.');
80          }
81    
82      }      }
83    }    }
84  }  }
85    
86    
87  function posterous_nodeapi(&$node, $op, $a3, $a4) {  function posterous_nodeapi(&$node, $op, $a3, $a4) {
88    switch ($op) {    // actions to take when the 'post to posterous' box is checked.
89      case 'update':    if ($node->posterous['post_to_posterous']) {
90        // for now, just disallow edits to be posted to Posterous.  TODO: add admin setting to toggle this.      switch ($op) {
91        drupal_set_message("Only new content will be posted to Posterous.  Edits to Drupal content will not edit existing Posterous posts; it would create dupliates.", "error");        case 'update':
92        break;          drupal_set_message("Edits to Drupal content will not edit existing Posterous posts, it will create dupliates.  Your
93      case 'insert':  post has been sent as indicated, however, to Posterous.", "error");
94        if ($node->posterous['post_to_posterous']) {        case 'insert':
95          global $user;          global $user;
96          $mailkey = 'posterous_email';          $language = user_preferred_language($account);
97          $headers = array();          $params = array(
98          drupal_mail($mailkey, POSTEROUS_TO_EMAIL, $node->title, $node->body, $user->mail, $headers);            'node' => $node,
99        }            'user' => $user,
100        break;          );
101            drupal_mail('posterous', 'posterous_send_email', POSTEROUS_TO_EMAIL, $language, $params, $user->mail);
102            break;
103        }
104      }
105    
106    }
107    
108    function posterous_mail($key, &$message, $params) {
109      $language = $message['language'];
110      $variables = user_mail_tokens($params['user'], $language);
111    
112      switch ($key) {
113        case 'posterous_send_email':
114          $node = $params['node'];
115    
116          $message['subject'] = t($node->title, $variables, $language->language);
117          $message['body'] = t($node->body, $variables, $language->language);
118              break;
119    }    }
120  }  }
121    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

  ViewVC Help
Powered by ViewVC 1.1.2