array( 'title' => 'Send', 'page callback' => '_send_page', 'access arguments' => array('send nodes'), 'type' => MENU_CALLBACK, 'file' => 'send.inc', ), 'admin/content/send' => array( 'title' => 'Send modules', 'description' => 'Default settings for "Send to Friend" and other modules that send content via e-mail', 'page callback' => 'drupal_get_form', 'page arguments' => array('_send_module_form'), 'access arguments' => array('administer send'), 'type' => MENU_NORMAL_ITEM, 'file' => 'send.inc', ), 'admin/content/send/default' => array( 'title' => 'Defaults', 'page callback' => 'drupal_get_form', 'page arguments' => array('_send_module_form'), 'access arguments' => array('administer send'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, 'file' => 'send.inc', ), 'node/%node/send' => array( //TODO this isn't done yet. ), ); foreach (send_modules() as $module => $name) { $items['admin/content/send/'. $module] = array( 'title' => module_invoke($module, 'send', 'name', $module), 'page callback' => 'drupal_get_form', 'page arguments' => array('_send_module_form', $module), 'access arguments' => array('administer send'), 'type' => MENU_LOCAL_TASK, 'file' => 'send.inc', ); } return $items; } /** * Implementation of hook_nodeapi(). */ function send_nodeapi(&$node, $op) { switch ($op) { case 'insert': case 'update': if (_send_node_enabled($node)) { return _send('settings_submit', $op, (array)$node); } return; case 'delete': return db_query("DELETE FROM {send_setting} WHERE nid = %d", $node->nid); } } /** * Implementation of hook_user(). */ function send_user($op, &$edit, &$user) { switch ($op) { case 'insert' : //if user has been a recipient before, note their uid if (!$user->mail) return; db_query("UPDATE {send} SET uid = %d WHERE mail = '%s'", $user->uid, $user->mail); db_query("UPDATE {send_recipient} SET rid = %d WHERE mail = '%s' AND rtype='user'", $user->uid, $user->mail); return; case 'delete': // no orphan uids db_query("UPDATE {send} SET uid = 0 WHERE uid = %d", $user->uid); db_query("UPDATE {send_recipient} SET rid = 0 WHERE rid = %d AND rtype='user'", $user->uid); return; } } /** * Implementation of hook_form_alter(). */ function send_form_alter(&$form, &$form_state, $form_id) { switch ($form['#id']) { case 'node-type-form': $form = _send('nodetype_form', $form); return; case 'node-form': if (_send_node_enabled($form['#node'])) { $form = _send('node_form', $form); } return; } return; } /** * Implementation of hook_link(). */ function send_link($type, $node = NULL) { if (!$node) return; foreach (send_modules() as $m => $name) { if (variable_get("{$m}_{$node->type}", 0) && module_invoke($m, 'send', 'access', $m)) { if (variable_get("{$m}_{$node->type}_pernode", 0)) { $linktext = _send('value', 'linktext', $m, $node->type, $node); } else { $linktext = variable_get("{$m}_{$node->type}_linktext", ''); } if ($linktext != '') { $links[$m] = array( 'title' => t($linktext), 'href' => "send/{$m}/{$node->nid}", 'attributes' => array("class" => 'send-link send-'. $m) ); } } } return $links; } /** * Helper function to determine if send settings are enabled for a node. */ function _send_node_enabled($node, $module = 'send') { $type = $node->type; // Not enabled at all. if (!variable_get('send_'. $type, 0)) return FALSE; // Enabled for all nodes of this type. if (variable_get('send_'. $type .'_pernode', FALSE)) return TRUE; // TODO not returning enabled/pernode setting // TODO not valid for other send modules? } /** * Implementation of our own send hook */ function send_send($op, $module = 'send', $nodetype = '', $node = NULL ) { if ($node) { $nodetype = $node->type; } if ($nodetype) { $nodename = node_get_types('name', $nodetype); } switch ($op) { case 'name': // human readable name of the module return t('Send to Friend'); case 'features': // features that this module uses return array('send', 'block'); case 'access': // access control for this module return user_access('send nodes'); case 'settings': // settings form return; case 'subject': // default setting for subject line if ($module == 'send' && $nodename) { return t('@name from '. variable_get('site_name', 'Drupal'), array('@name' => $nodename)); } if ($name = module_invoke($module, 'send', 'name', $module)) { return t('@name from '. variable_get('site_name', 'Drupal'), array('@name' => $name)); } return; case 'message': // default message text return; case 'template': // template/layout return theme('send_template'); case 'linktext': // default setting for link text if ($module == 'send') return t('send to friend'); if ($name = module_invoke($module, 'send', 'name', $module)) { return strtolower(t('send @name', array('@name' => $name))); } return; case 'threshold': // default setting for send threshold return 10; case 'default action': // if no nodes are included in message drupal_set_message(t('You have not selected any items to send'), 'error'); echo theme('page', ''); return; case 'node': // callback that modifies appearance of each rendered node return; case 'body': // callback that modifies appearance of rendered body return; case 'querystring': // callback that will return name=>value array for return links return; case 'deliver': // callback to send the message return '_send_deliver'; case 'confirm': // callback action when complete return '_send_confirm'; case 'recipient type': // node or user return 'user'; } return; } function send_modules() { static $modules = array(); if (!$modules) { foreach (module_implements('send') as $m) { $modules[$m] = module_invoke($m, 'send', 'name', $m); } } return $modules; } function _send($func) { require_once dirname(__FILE__) .'/send.inc'; if (function_exists($func = '_send_'. $func)) { $args = func_get_args(); unset($args[0]); return call_user_func_array($func, $args); } } function send_theme() { return array( 'send_form' => array( 'arguments' => array( 'form' => NULL ), 'file' => 'send.inc', ), 'send_template' => array( 'arguments' => array(), 'file' => 'send.inc', ), 'send_body' => array( 'arguments' => array( 'values' => array() ), 'file' => 'send.inc', ), ); } function send_views_api() { return array( 'api' => 2, 'path' => drupal_get_path('module', 'send') .'/includes', ); }