| 1 |
<?php
|
| 2 |
// $Id: posterous.module,v 1.4 2008/12/19 17:43:31 sethfreach Exp $
|
| 3 |
|
| 4 |
define("POSTEROUS_TO_EMAIL", "post@posterous.com");
|
| 5 |
|
| 6 |
/**
|
| 7 |
* Implementation of hook_perm()
|
| 8 |
*/
|
| 9 |
function posterous_perm() {
|
| 10 |
return array(
|
| 11 |
'configure posterous',
|
| 12 |
'post to posterous',
|
| 13 |
);
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_menu()
|
| 18 |
*/
|
| 19 |
function posterous_menu($may_cache) {
|
| 20 |
$items = array();
|
| 21 |
if ($may_cache) {
|
| 22 |
$items[] = array(
|
| 23 |
'title' => t('Posterous'),
|
| 24 |
'path' => 'admin/settings/posterous',
|
| 25 |
'description' => t('Denote which content types can be posted to Posterous'),
|
| 26 |
'callback' => 'drupal_get_form',
|
| 27 |
'callback arguments' => array('posterous_admin_settings'),
|
| 28 |
'access' => user_access('configure posterous'),
|
| 29 |
);
|
| 30 |
}
|
| 31 |
|
| 32 |
return $items;
|
| 33 |
}
|
| 34 |
|
| 35 |
function posterous_admin_settings() {
|
| 36 |
$form['posterous_content_types'] = array(
|
| 37 |
'#title' => t('Select the content types that may be posted to Posterous'),
|
| 38 |
'#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.'),
|
| 39 |
'#type' => 'checkboxes',
|
| 40 |
'#options' => node_get_types('names'),
|
| 41 |
'#default_value' => variable_get('posterous_content_types', array('story')),
|
| 42 |
);
|
| 43 |
$form['posterous_allow_on_edit'] = array(
|
| 44 |
'#title' => t('Allow Posterous option on node edit?'),
|
| 45 |
'#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.'),
|
| 46 |
'#type' => 'checkbox',
|
| 47 |
'#default_value' => variable_get('posterous_allow_on_edit', 0),
|
| 48 |
);
|
| 49 |
|
| 50 |
return system_settings_form($form);
|
| 51 |
}
|
| 52 |
|
| 53 |
function posterous_form_alter($form_id, &$form) {
|
| 54 |
//is this a node form AND it's the add new one form AND this content type has been marked availible for posting?
|
| 55 |
if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form' && in_array($form['#node']->type, variable_get('posterous_content_types', array())) ) {
|
| 56 |
//and this user has permission to post?
|
| 57 |
if (user_access('post to posterous')) {
|
| 58 |
global $user;
|
| 59 |
$dis = variable_get('posterous_allow_on_edit', 0) ? FALSE : TRUE;
|
| 60 |
$form['posterous'] = array(
|
| 61 |
'#title' => t('Posterous'),
|
| 62 |
'#description' => t('Selecting this option will also mail this content to post@posterous.com from your account email, '. $user->mail .'.'),
|
| 63 |
'#type' => 'checkboxes',
|
| 64 |
'#options' => array( 'post_to_posterous' => t('Send to Posterous also?') ),
|
| 65 |
'#weight' => 5,
|
| 66 |
'#disabled' => $dis,
|
| 67 |
);
|
| 68 |
}
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
| 72 |
function posterous_nodeapi(&$node, $op, $a3, $a4) {
|
| 73 |
switch ($op) {
|
| 74 |
case 'update':
|
| 75 |
// for now, just disallow edits to be posted to Posterous. TODO: add admin setting to toggle this.
|
| 76 |
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");
|
| 77 |
break;
|
| 78 |
case 'insert':
|
| 79 |
if ($node->posterous['post_to_posterous']) {
|
| 80 |
global $user;
|
| 81 |
$mailkey = 'posterous_email';
|
| 82 |
$headers = array();
|
| 83 |
drupal_mail($mailkey, POSTEROUS_TO_EMAIL, $node->title, $node->body, $user->mail, $headers);
|
| 84 |
}
|
| 85 |
break;
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|