comment; return TRUE; } return FALSE; } /** * Implementation of hook_help(). */ function petition_help($section) { switch ($section) { case 'admin/modules#description': return t('Enables users to create online petitions and for other users to sign it.'); case 'node/add#petition': return t('Creates a new petition for users to sign and support.'); case 'node/add/petition': return '
'.petition_help('node/add#petition').'
'; case 'admin/petition': return ''.t('You can view statistics about your petitions below.').'
'; case 'admin/petition/comments/'.arg(3): return ''.t('The following comments have been left about this petition:').'
'; case 'admin/petition/signatories/'.arg(3): return ''.t('The following people have signed this petition:').'
'; case 'admin/petition/trending/'.arg(3): return ''.t('The following is the number of people who signed this petition for each week:').'
'; } } /** * Implementation of hook_perm(). */ function petition_perm() { return array('create petition', 'respond to petition', 'access petition stats'); } /** * Implementation of hook_menu(). */ function petition_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('title' => t('petition'), 'path' => 'node/add/petition', 'access' => user_access('create petition'), ); $items[] = array('title' => t('petitions'), 'path' => 'petition', 'callback' => 'petition_overview', 'access' => user_access('respond to petition'), ); $items[] = array('title' => t('petition statistics'), 'path' => 'admin/petition', 'callback' => 'petition_results_overview', 'access' => user_access('access petition stats'), ); $items[] = array('title' => t('comments'), 'path' => 'admin/petition/comments', 'callback' => 'petition_results_comments', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('signatories'), 'path' => 'admin/petition/signatories', 'callback' => 'petition_results_signatories', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('signatories (csv)'), 'path' => 'admin/petition/signatories/csv', 'callback' => 'petition_results_signatories_csv', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); $items[] = array('title' => t('trending'), 'path' => 'admin/petition/trending', 'callback' => 'petition_results_trending', 'access' => user_access('access petition stats'), 'type' => MENU_CALLBACK, ); } return $items; } /** * Implementation of hook_node_info(). */ function petition_node_info() { return array('petition' => array('name' => t('petition'), 'base' => 'petition')); } /** * Implementation of hook_access(). */ function petition_access($op, $node) { global $user; if ($op == 'create') { return user_access('create petition'); } if ($op == 'update' || $op == 'delete') { if (user_access('edit petition') && ($user->uid == $node->uid)) { return TRUE; } } } /** * Implementation of hook_form(). */ function petition_form(&$node) { $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, ); $form['target'] = array( '#type' => 'textfield', '#title' => t('Target'), '#default_value' => $node->target, '#description' => t('The number of responses you are looking for from this petition.'), '#required' => TRUE, ); $form['body'] = array( '#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#description' => t('The petition itself: what it is users are going to be supporting.'), '#required' => TRUE, '#rows' => 10, ); $form['appeal'] = array( '#type' => 'textarea', '#title' => t('Appeal'), '#default_value' => $node->appeal, '#description' => t('Explain why the petition is important and appeal to the users on why they should sign.'), '#required' => TRUE, '#rows' => 10, ); $form['personal'] = array( '#type' => 'textarea', '#title' => t('Personal Message'), '#default_value' => $node->personal, '#description' => t('An optional personal message, usually from the petition creators themselves.'), '#rows' => 10, ); $form['statistics'] = array( '#type' => 'radios', '#title' => 'Display Signee Statistics', '#default_value' => ($node->statistics ? $node->statistics : 0), '#options' => array('No', 'Yes'), '#description' => t('Controls whether or not public users can see the number of people who have signed this petition.'), '#required' => TRUE, ); $form['defaultibles'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#title' => t('Default Petition Settings'), '#description' => t('If these settings are unchanged, they will use the defaults set by the administrator.'), ); $form['defaultibles']['thank_you_page'] = array( '#type' => 'textfield', '#title' => t('"Thank You" Page'), '#default_value' => $node->thank_you_page, '#description' => t('The path in your site to which users will be taken after completing a petition.'), ); // emails enabled, so allow message customization. if (variable_get('petition_default_autorespond', 1)) { $wildcards = _petition_get_wildcards(); $form['defaultibles']['autorespond_from'] = array( '#type' => 'textfield', '#title' => t('Email Auto-Respond From'), '#default_value' => $node->autorespond_from, '#description' => t('Enter the email address that will appear in the "From: " header of sent messages.'), ); $form['defaultibles']['autorespond_subject'] = array( '#type' => 'textfield', '#title' => t('Email Auto-Respond Subject'), '#default_value' => $node->autorespond_subject, '#description' => t('Subject of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); $form['defaultibles']['autorespond_message'] = array( '#type' => 'textarea', '#title' => t('Email Auto-Respond Message'), '#default_value' => $node->autorespond_message, '#description' => t('Body of auto-response email message to be sent. You may include the following wildcards: %wild.', array('%wild' => $wildcards)), ); } // the same format applies to all our boxes. $form['filter'] = filter_form($node->format); return $form; } /** * Implementation of hook_insert(). */ function petition_insert($node) { db_query("INSERT INTO {petition} (nid, appeal, personal, target, statistics, thank_you_page, autorespond_from, autorespond_subject, autorespond_message) VALUES (%d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s')", $node->nid, $node->appeal, $node->personal, $node->target, $node->statistics, $node->thank_you_page, $node->autorespond_from, $node->autorespond_subject, $node->autorespond_message); } /** * Implementation of hook_update(). */ function petition_update($node) { db_query("UPDATE {petition} SET appeal = '%s', personal = '%s', target = %d, statistics = %d, thank_you_page = '%s', autorespond_from = '%s', autorespond_subject = '%s', autorespond_message = '%s' WHERE nid = %d", $node->appeal, $node->personal, $node->target, $node->statistics, $node->thank_you_page, $node->autorespond_from, $node->autorespond_subject, $node->autorespond_message, $node->nid); } /** * Implementation of hook_delete(). */ function petition_delete($node) { db_query('DELETE FROM {petition} WHERE nid = %d', $node->nid); } /** * Implementation of hook_load(). */ function petition_load($node) { $content = db_fetch_object(db_query('SELECT * FROM {petition} WHERE nid = %d', $node->nid)); if ($node->nid) { $content->signatures = petition_count_signatures($node->nid); } return $content; } /** * Implementation of hook_view(). */ function petition_view(&$node, $teaser = FALSE, $page = FALSE) { // if ($page) { $form = array(); petition_build_signup_form(&$node, &$form); $node->petition_signup_form = drupal_get_form('petition_signup_form_data', $form); // @@@ Move to theme if ($page) { $node->petition_signup_form = str_replace ('