| 1 |
<?php
|
| 2 |
// $Id: citizenspeak.node.php,v 1.11 2005/11/16 16:32:33 georgehotelling Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Node module functions for the CitizenSpeak module
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_access().
|
| 11 |
*/
|
| 12 |
function citizenspeak_access($op, $node) {
|
| 13 |
global $user;
|
| 14 |
|
| 15 |
if ($op == 'create') {
|
| 16 |
// Only users with permission to do so may create this node type.
|
| 17 |
return user_access('create campaigns');
|
| 18 |
}
|
| 19 |
|
| 20 |
// Users who create a node may edit or delete it later, assuming they have the
|
| 21 |
// necessary permissions.
|
| 22 |
if ($op == 'update' || $op == 'delete') {
|
| 23 |
if (user_access('edit own campaigns') && ($user->uid == $node->uid)) {
|
| 24 |
return true;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
if ($op == "collect contact information") {
|
| 29 |
if (user_access('collect contact information') && ($user->uid == $node->uid)) {
|
| 30 |
return true;
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
return null;
|
| 35 |
} // function citizenspeak_access
|
| 36 |
|
| 37 |
/**
|
| 38 |
* Implementation of hook_delete().
|
| 39 |
*/
|
| 40 |
function citizenspeak_delete($node) {
|
| 41 |
db_query("DELETE FROM {citizenspeak_campaigns} WHERE nid = %d", $node->nid);
|
| 42 |
} // function citizenspeak_delete
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Implementation of hook_form().
|
| 46 |
*/
|
| 47 |
function citizenspeak_form(&$node, &$error) {
|
| 48 |
$output = '';
|
| 49 |
|
| 50 |
// In order to be able to attach taxonomy terms to this node, we need
|
| 51 |
// to display the appropriate form elements.
|
| 52 |
if (function_exists('taxonomy_node_form')) {
|
| 53 |
$output .= implode('', taxonomy_node_form('citizenspeak', $node));
|
| 54 |
}
|
| 55 |
|
| 56 |
// Now we define the form elements specific to our node type.
|
| 57 |
$email_group = '';
|
| 58 |
$email_group .= form_textarea(t('Email Message'), 'email_message', $node->email_message, 60, 20, t("Note: This text will be followed by the participant's contact information."), array(), true);
|
| 59 |
$email_group .= form_textarea(t('Send Message To'), 'email_recipients', $node->email_recipients, 60, 6, t("Use a comma or space to separate addresses. Make sure the above email addresses are valid to avoid campaign suspension."), array(), true);
|
| 60 |
$email_group .= form_checkbox(t('Put personal statements at top of letter'), 'campaign_format', 1, $node->campaign_format);
|
| 61 |
|
| 62 |
$output .= form_group(t('Campaign Information'), $email_group);
|
| 63 |
|
| 64 |
return $output;
|
| 65 |
} // function citizenspeak_form
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Implementation of hook_insert().
|
| 69 |
*/
|
| 70 |
function citizenspeak_insert($node) {
|
| 71 |
db_query("INSERT INTO {citizenspeak_campaigns} (nid, email_message, email_recipients, campaign_format) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->email_message, $node->email_recipients, $node->campaign_format);
|
| 72 |
drupal_set_message(t('<p>The campaign "%title" has been saved and the following web address has been activated: %url</p><p>Pass the web address along to people you wish to join your campaign.</p><p>To monitor your campaign, please go to <a href="%url/report">%url/report</a></p><p>Good Luck!<br />%site_name</p>', array("%title" => $node->title, "%url" => url("node/". $node->nid, null, null, true), "%site_name" => variable_get("site_name", ""))));
|
| 73 |
} // function citizenspeak_insert
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Implementation of hook_load().
|
| 77 |
*/
|
| 78 |
function citizenspeak_load($node) {
|
| 79 |
return db_fetch_array(db_query('SELECT * FROM {citizenspeak_campaigns} WHERE nid = %d', $node->nid));
|
| 80 |
} // function citizenspeak_load
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Implementation of hook_node_name().
|
| 84 |
*
|
| 85 |
* @return name of the module
|
| 86 |
*/
|
| 87 |
function citizenspeak_node_name($node) {
|
| 88 |
return t('citizenspeak');
|
| 89 |
} // function citizenspeak_node_name
|
| 90 |
|
| 91 |
/**
|
| 92 |
* Implementation of hook_update().
|
| 93 |
*/
|
| 94 |
function citizenspeak_update($node) {
|
| 95 |
db_query("UPDATE {citizenspeak_campaigns} SET email_message = '%s', email_recipients = '%s', campaign_format = %d WHERE nid = %d", $node->email_message, $node->email_recipients, $node->campaign_format, $node->nid);
|
| 96 |
} // function citizenspeak_update
|
| 97 |
|
| 98 |
/**
|
| 99 |
* Implementation of hook_validate().
|
| 100 |
*
|
| 101 |
* @param &$node The node to be validated.
|
| 102 |
*/
|
| 103 |
function citizenspeak_validate(&$node) {
|
| 104 |
if (isset($node->email_message) && $node->email_message == '') {
|
| 105 |
form_set_error('email_message', 'You must provide an email message');
|
| 106 |
}
|
| 107 |
|
| 108 |
if (isset($node->email_recipients)) {
|
| 109 |
if ($node->email_recipients == '') {
|
| 110 |
form_set_error('email_recipients', 'You must provide at least one email address.');
|
| 111 |
}
|
| 112 |
|
| 113 |
$recipients = _citizenspeak_split_emails($node->email_recipients);
|
| 114 |
|
| 115 |
if (count($recipients) > 25) {
|
| 116 |
form_set_error('email_recipients', 'You may not have more than 25 email addresses.');
|
| 117 |
}
|
| 118 |
|
| 119 |
foreach ($recipients as $email) {
|
| 120 |
if (!valid_email_address($email)) {
|
| 121 |
form_set_error('email_recipients', 'You must provide valid email addresses.');
|
| 122 |
break;
|
| 123 |
}
|
| 124 |
}
|
| 125 |
} // if (isset($node->email_recipients))
|
| 126 |
} // function citizenspeak_validate
|
| 127 |
|
| 128 |
|
| 129 |
/**
|
| 130 |
* Implementation of hook_view().
|
| 131 |
*
|
| 132 |
* @param &$node The node to be displayed.
|
| 133 |
* @param $teaser Whether we are to generate a "teaser" or summary of the node,
|
| 134 |
* rather than display the whole thing.
|
| 135 |
* @param $page Whether the node is being displayed as a standalone page. If
|
| 136 |
* this is TRUE, the node title should not be displayed, as it will be printed
|
| 137 |
* automatically by the theme system. Also, the module may choose to alter the
|
| 138 |
* default breadcrumb trail in this case.
|
| 139 |
* @return None. The passed-by-reference $node parameter should be modified as
|
| 140 |
* necessary so it can be properly presented by theme('node', $node).
|
| 141 |
*/
|
| 142 |
function citizenspeak_view(&$node, $teaser = false, $page = false) {
|
| 143 |
if ($_POST['op'] == 'send') {
|
| 144 |
_citizenspeak_validate_participation($_POST['edit']);
|
| 145 |
}
|
| 146 |
$node->body .= theme('citizenspeak_participate_display', $node);
|
| 147 |
$node->teaser .= $node->email_message;
|
| 148 |
} // function citizenspeak_view
|
| 149 |
|
| 150 |
?>
|