$schema) { if (substr($table, 0, 13) == 'send_contact_') { if (!db_table_exists($table)) db_create_table($ret, $table, $schema); } } // Load the menu items from our send.menu.inc file. module_load_include('inc', 'send', 'includes/send.menu'); return send_menu_menu(); } /** * Load callback for send_profiles. */ function send_profile_load($name) { if (is_object($name)) $name = $name->name; $profiles = send_profiles(); return $profiles[$name]; } /** * Load callback for send_recipients, using a unique hash. */ function send_hash_load($hash) { // There's a small possibility of collision here, use the most recent hash. $res = db_query("SELECT * FROM {send_recipient} WHERE hash = '%s' ORDER BY srid LIMIT 1", $hash); return db_fetch_object($res); } /** * Load callback for send_recipients, using an id. */ function send_recipient_load($srid) { $res = db_query("SELECT * FROM {send_recipient} WHERE srid = %d", $srid); return db_fetch_object($res); } /** * Access callback for send forms. */ function send_access($profile = NULL, $nodes = array()) { if (!$profile) return FALSE; if (!user_access('send nodes')) return FALSE; // Check against threshold. $limit = variable_get('send_limit_'. $profile, 10); if ($limit && !flood_is_allowed("send $profile", $limit)) return FALSE; // Check whether we're sending valid nodes that are enabled for this profile. if ($nodes) { if (!is_array($nodes)) $nodes = explode(' ', $nodes); foreach ($nodes as $nid) { if (!$node = node_load($nid)) return FALSE; // TODO disabled for testing // if (!variable_get("{$profile}_{$node->type}", 0)) return FALSE; } } return TRUE; } /** * Implementation of hook_perm(). */ function send_perm() { return array('administer send', 'view send statistics'); } /** * Implementation of hook_elements(). * Add elements for the send form, its contact items, and a message format. * This permits us to build, validate and render a variety of send forms. */ function send_elements() { return array( 'send' => array( '#input' => TRUE, '#tree' => TRUE, '#process' => array('send_process'), ), 'send_contact' => send_element_defaults(), 'send_user' => send_element_defaults(), 'send_multiple' => send_element_defaults(), 'send_message_edit' => send_element_defaults(), 'send_message_compose' => send_element_defaults(), ); } /** * API Function: Common defaults for any element that appears on a send form. */ function send_element_defaults() { return array( '#input' => TRUE, '#process' => array('send_process'), '#theme' => 'send_element', '#tree' => TRUE, ); } /** * A #process callback for send_form elements. * Responsible for loading the required files and building out the form. */ function send_process($element, $edit, &$form_state, $complete_form) { module_load_include('inc', 'send', 'includes/send.form'); if (function_exists($func = $element['#type'] .'_element_process')) { $element = $func($element, $edit, $form_state, $complete_form); } unset($element['#required']); return $element; } /** * Implementation of hook_user(). */ function send_user($op, &$edit, &$user) { switch ($op) { case 'insert' : // If user has been a sender or recipient, update their uid. if (!$user->mail) return; db_query("UPDATE {send_contact} SET uid = %d WHERE mail = '%s'", $user->uid, $user->mail); return; case 'delete': // Set send_contact entries to anonymous. db_query("UPDATE {send_contact} SET uid = 0 WHERE uid = %d", $user->uid); return; } } function send_profiles($list_only = TRUE) { static $profiles; if (!$profiles) { $profiles = module_invoke_all('send_profile_info'); foreach ($profiles as $name => $info) $profiles[$name]['name'] = $name; } return $profiles; } function send_profile_names() { static $list; if (!isset($list)) { $list = array(); foreach (send_profiles() as $name => $info) { $list[$name] = $info['title']; } } return $list; } /** * Implementation of hook_theme(). */ function send_theme() { module_load_include('theme.inc', 'send', 'theme/send'); return send_theme_theme(); } /** * Implementation of Send module's hook_send_mode_info(). */ function send_send_mode_info() { return array( 'mail' => array( 'callback' => 'send_deliver_mail', 'database columns' => array( 'mail' => array('type' => 'varchar', 'length' => 64), 'name' => array('type' => 'varchar', 'length' => 100), ), 'unique keys' => array('mail' => array('mail')), 'user only' => FALSE, ), ); } /** * The Send API function. */ function send($profile, $recipients, $nids = array(), $message = array()) { module_load_include('inc', 'send', 'includes/send'); return _send($profile, $recipients, $nids, $message); } /** * An API function to return a send_contact entry. */ function send_contact($mode, $contact) { module_load_include('inc', 'send', 'includes/send'); return _send_contact($mode, $contact); } /** * An API function to return a send_value. */ function send_value($name, $module='', $nodetype = '', $node = NULL, $value = NULL) { module_load_include('inc', 'send', 'includes/send'); return _send_value($name, $module, $nodetype, $node, $value); } /** * An API function to list any message templates that exist. */ function send_templates($profile = NULL, $active_only = TRUE) { module_load_include('inc', 'send.template', 'includes/send'); return send_template_list($profile, $active_only); } /** * Implementation of hook_views_api(). */ function send_views_api() { return array( 'api' => 2, 'path' => drupal_get_path('module', 'send') .'/includes/views', ); }