| 1 |
<?php
|
| 2 |
// $Id: postcard.module,v 1.26 2007/09/12 22:25:24 add1sun Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Allows the creation of postcards (image + text) and sends a link by email.
|
| 7 |
*
|
| 8 |
* @todo
|
| 9 |
* - Allow multiselect for galleries
|
| 10 |
* - Allow admin to pick picture size for creation and display
|
| 11 |
* - Give admin/user a link to all postcards sent
|
| 12 |
* - Email to sender when recipient views
|
| 13 |
* - Allow recipient to respond
|
| 14 |
* - Random pic block to "send postcards"
|
| 15 |
*
|
| 16 |
*/
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of hook_perm().
|
| 20 |
*/
|
| 21 |
function postcard_perm() {
|
| 22 |
return array('view postcards', 'send postcards');
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implementation of hook_help().
|
| 27 |
*/
|
| 28 |
function postcard_help($section) {
|
| 29 |
switch ($section) {
|
| 30 |
case 'admin/help#postcard':
|
| 31 |
return t('Allows a user to create postcards and send them to friends by e-mail. Note: to have a separate postcard gallery requires image and image_gallery modules to be installed and enabled.');
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Implementation of hook_menu().
|
| 37 |
*/
|
| 38 |
function postcard_menu($may_cache) {
|
| 39 |
$items = array();
|
| 40 |
if ($may_cache) {
|
| 41 |
$items[] = array(
|
| 42 |
'path' => 'postcard',
|
| 43 |
'title' => t('Postcards'),
|
| 44 |
'callback' => 'postcard_page',
|
| 45 |
'access' => user_access('view postcards'),
|
| 46 |
'type' => MENU_SUGGESTED_ITEM,
|
| 47 |
);
|
| 48 |
}
|
| 49 |
$items[] = array(
|
| 50 |
'path' => 'admin/settings/postcard',
|
| 51 |
'title' => t('Postcard'),
|
| 52 |
'description' => t('Choose your postcard gallery and set default messages.'),
|
| 53 |
'callback' => 'drupal_get_form',
|
| 54 |
'callback arguments' => 'postcard_admin_settings',
|
| 55 |
'access' => user_access('administer site configuration'),
|
| 56 |
'type' => MENU_NORMAL_ITEM,
|
| 57 |
);
|
| 58 |
return $items;
|
| 59 |
}
|
| 60 |
|
| 61 |
/**
|
| 62 |
* Form for the settings page.
|
| 63 |
*
|
| 64 |
* @return
|
| 65 |
* form
|
| 66 |
*/
|
| 67 |
function postcard_admin_settings() {
|
| 68 |
|
| 69 |
$form['main'] = array(
|
| 70 |
'#type' => 'fieldset',
|
| 71 |
'#title' => t('Postcard details'),
|
| 72 |
);
|
| 73 |
if (module_exists('taxonomy')) {
|
| 74 |
$terms[] = '<'. t('none') .'>';
|
| 75 |
// TODO: we need to pick our vocab (taking into account the gallery stuff?)
|
| 76 |
foreach (taxonomy_get_tree(5) as $term) {
|
| 77 |
$terms[$term->tid] = str_repeat('--', $term->depth) . $term->name;
|
| 78 |
}
|
| 79 |
// TODO: allow multiselect
|
| 80 |
$form['main']['postcard_term'] = array(
|
| 81 |
'#type' => 'select',
|
| 82 |
'#multiple' => false,
|
| 83 |
'#title' => t('Image Galleries'),
|
| 84 |
'#default_value' => variable_get('postcard_term', array()),
|
| 85 |
'#options' => $terms,
|
| 86 |
'#description' => t('Select top term of postcard image gallery. Select none for including all terms of the vocabulary.'),
|
| 87 |
);
|
| 88 |
}
|
| 89 |
///////////////////////////////////////////////////////////////
|
| 90 |
// get all of the sizes and presets and then put them in one select
|
| 91 |
$image_sizes = array_keys(_image_get_sizes());
|
| 92 |
$imagecache_presets = _imagecache_get_presets();
|
| 93 |
$all_sizes = array_merge($image_sizes, $imagecache_presets);
|
| 94 |
$sizes = drupal_map_assoc($all_sizes);
|
| 95 |
|
| 96 |
if (module_exists('imagecache')) {
|
| 97 |
$form['main']['postcard_size'] = array(
|
| 98 |
'#type' => 'select',
|
| 99 |
'#multiple' => false,
|
| 100 |
'#title' => t('Postcard image size'),
|
| 101 |
'#default_value' => variable_get('postcard_size', ''),
|
| 102 |
'#options' => $sizes,
|
| 103 |
'#description' => t('Select which size you would like to use for your postcards.'),
|
| 104 |
);
|
| 105 |
}
|
| 106 |
//////////////////////////////////////////////////
|
| 107 |
$form['letter'] = array(
|
| 108 |
'#type' => 'fieldset',
|
| 109 |
'#title' => t('Letter customization'),
|
| 110 |
);
|
| 111 |
$form['letter']['postcard_subject'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Subject'),
|
| 114 |
'#default_value' => variable_get('postcard_subject', 'Postcard from %site'),
|
| 115 |
'#size' => 70,
|
| 116 |
'#maxlength' => 70,
|
| 117 |
'#description' => t('Custom subject for email which will be sent to the postcard recipient.'),
|
| 118 |
);
|
| 119 |
$form['letter']['postcard_letter'] = array(
|
| 120 |
'#type' => 'textarea',
|
| 121 |
'#title' => t('Body'),
|
| 122 |
'#default_value' => variable_get('postcard_letter', _postcard_letter()),
|
| 123 |
'#cols' => 70,
|
| 124 |
'#rows' => 5,
|
| 125 |
'#description' => t('This text is the body of the email that the card recipient will see. These are the variables you may use: %site = your site name, %site_url = your site URL, %site_mail = your site email address, %card_url = the URL for the postcard, %sender = sender name, %user = sender site username, %recipient = recipient name, %postcards = URL of postcards page, %card_text = postcard message'),
|
| 126 |
);
|
| 127 |
|
| 128 |
$form['misc'] = array(
|
| 129 |
'#type' => 'fieldset',
|
| 130 |
'#title' => t('Miscellaneous settings'),
|
| 131 |
);
|
| 132 |
$form['misc']['postcard_cron'] = array(
|
| 133 |
'#type' => 'textfield',
|
| 134 |
'#title' => t('Days to keep postcards'),
|
| 135 |
'#description' => t('Postcards that are aged more than the number of days entered above will automatically be deleted from the database. Use 0 to never delete. Note that this will only be checked when cron.php is run.'),
|
| 136 |
'#size' => '2',
|
| 137 |
'#default_value' => variable_get('postcard_cron', '0'),
|
| 138 |
);
|
| 139 |
$form['misc']['postcard_send'] = array(
|
| 140 |
'#type' => 'checkbox',
|
| 141 |
'#title' => '<strong>'. t('Show "Send this as a postcard" link') .'</strong>',
|
| 142 |
'#description' => t('Checking this box will make a "Send this as a postcard" link appear with the other links under the image for nodes that fall within the postcard gallery selected above.'),
|
| 143 |
'#default_value' => variable_get('postcard_send', 1),
|
| 144 |
);
|
| 145 |
$form['misc']['postcard_help'] = array(
|
| 146 |
'#type' => 'textarea',
|
| 147 |
'#title' => t('Explanation or submission guidelines'),
|
| 148 |
'#default_value' => variable_get('postcard_help', ''),
|
| 149 |
'#cols' => 70,
|
| 150 |
'#rows' => 5,
|
| 151 |
'#description' => t('This text will be displayed at the top of the postcard creation form. It is useful for helping or instructing your users.'),
|
| 152 |
);
|
| 153 |
|
| 154 |
return system_settings_form($form);
|
| 155 |
}
|
| 156 |
|
| 157 |
/**
|
| 158 |
* Display the postcard page
|
| 159 |
*
|
| 160 |
* @param $arg1, $arg2, $arg3
|
| 161 |
* URL arguments
|
| 162 |
*/
|
| 163 |
|
| 164 |
function postcard_page($arg1=0, $arg2=0, $arg3=0) {
|
| 165 |
global $user;
|
| 166 |
$breadcrumb[] = l(t('Home'), NULL);
|
| 167 |
$breadcrumb[] = l(t('Postcards'), 'postcard');
|
| 168 |
// check permissions
|
| 169 |
if (!user_access('view postcards') && !user_access('send postcards')) {
|
| 170 |
return drupal_access_denied();
|
| 171 |
}
|
| 172 |
// are we dealing with postcard stuff?
|
| 173 |
if (arg(0) == 'postcard' && is_numeric($arg1)) {
|
| 174 |
$nid = $arg1;
|
| 175 |
// do we have a postcard, if so, show it baby
|
| 176 |
if (!empty($arg2)) {
|
| 177 |
// check permissions
|
| 178 |
if (!user_access('view postcards') && !($user->uid && ($card->uid == $user->uid))) {
|
| 179 |
return drupal_access_denied();
|
| 180 |
}
|
| 181 |
// view a postcard
|
| 182 |
$card = db_fetch_object(db_query("SELECT p.pid, p.nid, p.uid, p.sender_name, p.sender_mail, p.recp_name, p.recp_mail, p.body, p.send_time, f.nid, f.filepath FROM {postcard} p INNER JOIN {files} f ON p.nid = f.nid INNER JOIN {node} n ON n.nid = p.nid WHERE p.pid = '%s'", $arg2));
|
| 183 |
$title = t('A Postcard for you');
|
| 184 |
$output = theme('postcard_image', $card);
|
| 185 |
if (isset($card)) {
|
| 186 |
// don't do this if the sender is reviewing the card
|
| 187 |
if (empty($arg3)) {
|
| 188 |
if (empty($card->recp_time)) {
|
| 189 |
$update[] = "recp_time = ". time();
|
| 190 |
}
|
| 191 |
$update[] = "count_view =". ($card->count_view + 1);
|
| 192 |
db_query("UPDATE {postcard} SET ". implode(', ', $update) ." WHERE pid = '". $card->pid ."'");
|
| 193 |
}
|
| 194 |
}
|
| 195 |
else {
|
| 196 |
$title = t('Postcard not found');
|
| 197 |
$output = t('Requested postcard not found. It was probably too old and was deleted from the site. Sorry.');
|
| 198 |
}
|
| 199 |
}
|
| 200 |
// create a postcard
|
| 201 |
else {
|
| 202 |
// check permissions to make postcards
|
| 203 |
if (!user_access('send postcards')) {
|
| 204 |
return drupal_access_denied();
|
| 205 |
}
|
| 206 |
$title = t('Create your postcard');
|
| 207 |
|
| 208 |
// find taxonomy and create breadcrumbs for page
|
| 209 |
// TODO: this can't be a hard-coded vocab :p
|
| 210 |
$terms = taxonomy_node_get_terms_by_vocabulary($nid, 5);
|
| 211 |
$term = array_pop($terms);
|
| 212 |
if (isset($term)) {
|
| 213 |
// TODO: same here (vocab)
|
| 214 |
$vocabulary = taxonomy_get_vocabulary(5);
|
| 215 |
// Breadcrumb navigation
|
| 216 |
if ($parents = taxonomy_get_parents_all($term->tid)) {
|
| 217 |
$parents = array_reverse($parents);
|
| 218 |
foreach ($parents as $parent) {
|
| 219 |
$breadcrumb[] = l($parent->name, 'postcard/tid/'. $parent->tid);
|
| 220 |
}
|
| 221 |
}
|
| 222 |
}
|
| 223 |
// display help text if we have any
|
| 224 |
$helptext = variable_get('postcard_help', '');
|
| 225 |
if (!empty($helptext)) {
|
| 226 |
$output .= '<div class="help">'. filter_xss_admin($helptext) .'</div>';
|
| 227 |
}
|
| 228 |
//////////////////////////////////////////////////
|
| 229 |
// display the image we are using for the postcard
|
| 230 |
// if the image is from image module use that
|
| 231 |
//if (module_exists('image')) {
|
| 232 |
// $node = node_load(array('nid' => $nid));
|
| 233 |
// $output .= image_display($node, variable_get('postcard_size', 'preview'));
|
| 234 |
//}
|
| 235 |
// otherwise see if they are using imagecache and use that
|
| 236 |
// get the image info we need
|
| 237 |
$image = db_fetch_object(db_query("SELECT nid, filepath FROM {files} WHERE nid = %d", $nid));
|
| 238 |
if (module_exists('imagecache')) {
|
| 239 |
$output .= theme('imagecache', variable_get('postcard_size', ''), $image->filepath);
|
| 240 |
}
|
| 241 |
//$output .= dsm($sizes);
|
| 242 |
//////////////////////////////////////////////////
|
| 243 |
// get our postcard creation form
|
| 244 |
$output .= drupal_get_form('postcard_create_form');
|
| 245 |
}
|
| 246 |
}
|
| 247 |
// if no postcard to display, then show us the postcard gallery
|
| 248 |
else {
|
| 249 |
// this will require image_gallery module
|
| 250 |
if (!module_exists('image_galley')) {
|
| 251 |
return 'There are no postcard galleries available.';
|
| 252 |
}
|
| 253 |
else {
|
| 254 |
// check permissions
|
| 255 |
if (!user_access('send postcards')) {
|
| 256 |
return drupal_access_denied();
|
| 257 |
}
|
| 258 |
|
| 259 |
$tid = $arg2 ? $arg2: variable_get('postcard_term', 0);
|
| 260 |
|
| 261 |
// show galleries
|
| 262 |
$galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 1);
|
| 263 |
for ($i=0; $i < count($galleries); $i++) {
|
| 264 |
$galleries[$i]->count = taxonomy_term_count_nodes($galleries[$i]->tid, 'image');
|
| 265 |
$tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
|
| 266 |
$descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
|
| 267 |
$last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
|
| 268 |
$galleries[$i]->latest = node_load(array('nid' => $last->nid));
|
| 269 |
}
|
| 270 |
// show images
|
| 271 |
$images = array();
|
| 272 |
if (isset($tid)) {
|
| 273 |
$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, NULL, $tid);
|
| 274 |
while ($node = db_fetch_object($result)) {
|
| 275 |
$images[] = node_load(array('nid' => $node->nid));
|
| 276 |
}
|
| 277 |
}
|
| 278 |
// set the page title to the gallery name
|
| 279 |
$gallery = taxonomy_get_term($tid);
|
| 280 |
$title = $gallery->name;
|
| 281 |
// set breadcrumbs
|
| 282 |
$parents = taxonomy_get_parents_all($tid);
|
| 283 |
array_shift($parents);
|
| 284 |
$parents = array_reverse($parents);
|
| 285 |
foreach ($parents as $parent) {
|
| 286 |
$breadcrumb[] = l($parent->name, 'postcard/tid/'. $parent->tid);
|
| 287 |
}
|
| 288 |
$output = theme('postcard_gallery', $galleries, $images);
|
| 289 |
}
|
| 290 |
}
|
| 291 |
|
| 292 |
|
| 293 |
// prepare the page for printing
|
| 294 |
drupal_set_title($title);
|
| 295 |
drupal_set_breadcrumb($breadcrumb);
|
| 296 |
|
| 297 |
// print the page
|
| 298 |
return $output;
|
| 299 |
}
|
| 300 |
|
| 301 |
/**
|
| 302 |
* Form to create a new postcard
|
| 303 |
*
|
| 304 |
* @return
|
| 305 |
* form to render
|
| 306 |
*/
|
| 307 |
function postcard_create_form() {
|
| 308 |
global $user;
|
| 309 |
$sndr_name = $user->name;
|
| 310 |
$sndr_mail = $user->mail;
|
| 311 |
$form['field_rcpt'] = array(
|
| 312 |
'#type' => 'textfield',
|
| 313 |
'#title' => t('Name of recipient'),
|
| 314 |
'#size' => 60,
|
| 315 |
'#maxlength' => 64,
|
| 316 |
'#required' => TRUE,
|
| 317 |
);
|
| 318 |
$form['field_to'] = array(
|
| 319 |
'#type' => 'textfield',
|
| 320 |
'#title' => t('E-mail(s) of recipient(s)'),
|
| 321 |
'#size' => 60,
|
| 322 |
'#maxlength' => 64,
|
| 323 |
'#required' => TRUE,
|
| 324 |
'#description' => t('You may enter multiple emails separated by a comma (,).'),
|
| 325 |
);
|
| 326 |
$form['field_sndr'] = array(
|
| 327 |
'#type' => 'textfield',
|
| 328 |
'#title' => t('Your full name'),
|
| 329 |
'#default_value' => $sndr_name,
|
| 330 |
'#size' => 60,
|
| 331 |
'#maxlength' => 64,
|
| 332 |
'#required' => TRUE,
|
| 333 |
);
|
| 334 |
$form['field_from'] = array(
|
| 335 |
'#type' => 'textfield',
|
| 336 |
'#title' => t('Your email'),
|
| 337 |
'#default_value' => $sndr_mail,
|
| 338 |
'#size' => 60,
|
| 339 |
'#maxlength' => 64,
|
| 340 |
'#required' => TRUE,
|
| 341 |
);
|
| 342 |
$form['field_nid'] = array(
|
| 343 |
'#type' => 'value',
|
| 344 |
'#value' => arg(1),
|
| 345 |
);
|
| 346 |
$form['field_body'] = array(
|
| 347 |
'#type' => 'textarea',
|
| 348 |
'#title' => t("Message"),
|
| 349 |
'#cols' => 64,
|
| 350 |
'#rows' => 15,
|
| 351 |
'#required' => TRUE,
|
| 352 |
);
|
| 353 |
// CC sender upon request.
|
| 354 |
$form['send_copy'] = array(
|
| 355 |
'#type' => 'checkbox',
|
| 356 |
'#title' => t('Send yourself a copy.'),
|
| 357 |
);
|
| 358 |
$form['submit'] = array(
|
| 359 |
'#type' => 'submit',
|
| 360 |
'#value' => t('Send Postcard'),
|
| 361 |
);
|
| 362 |
return $form;
|
| 363 |
}
|
| 364 |
|
| 365 |
/**
|
| 366 |
* Implementation of hook_validate().
|
| 367 |
*/
|
| 368 |
function postcard_create_form_validate($form_id, $form_values) {
|
| 369 |
// split it up if we have muliple emails
|
| 370 |
$emails = explode(',', $form_values['field_to']);
|
| 371 |
foreach ($emails as $email) {
|
| 372 |
if (!valid_email_address(trim($email))) {
|
| 373 |
form_set_error('', t('E-mail for recipient @email is invalid.', array('@email' => $email)));
|
| 374 |
}
|
| 375 |
}
|
| 376 |
if (!valid_email_address($form_values['field_from'])) {
|
| 377 |
form_set_error('', t('Your e-mail address is invalid'));
|
| 378 |
}
|
| 379 |
if ($form_values['field_nid'] == '' || !is_numeric($form_values['field_nid'])) {
|
| 380 |
form_set_error('', t('Image not selected. Select image again and refill form fields.'));
|
| 381 |
}
|
| 382 |
}
|
| 383 |
|
| 384 |
/**
|
| 385 |
* Send postcard link by email and insert data
|
| 386 |
*
|
| 387 |
* Implementation of hook_submit().
|
| 388 |
*/
|
| 389 |
function postcard_create_form_submit($form_id, $form_values) {
|
| 390 |
global $user, $base_url;
|
| 391 |
// the nid of the postcard
|
| 392 |
$arg = arg(1);
|
| 393 |
// set our email variables
|
| 394 |
$name = $form_values['field_sndr'];
|
| 395 |
$from = $form_values['field_from'];
|
| 396 |
$to = $form_values['field_to'];
|
| 397 |
unset($postid);
|
| 398 |
while (!$postid) {
|
| 399 |
$postid = strtr(substr(crypt(microtime(), $user->uid), 2), '/\|$^&.,;?+=!@#$%^&*()', '_-_-_-_-_-_-_-_-_-_-_-');
|
| 400 |
$result = db_fetch_object(db_query("SELECT nid FROM {postcard} WHERE pid = '%s'", $postid));
|
| 401 |
if ($result) unset($postid);
|
| 402 |
}
|
| 403 |
// set the base variable from the clean url value
|
| 404 |
if (variable_get('clean_url', 0)) {
|
| 405 |
$base = $base_url .'/';
|
| 406 |
}
|
| 407 |
else {
|
| 408 |
$base = $base_url .'/index.php?q=';
|
| 409 |
}
|
| 410 |
// set the variables
|
| 411 |
$variables = array('%site' => variable_get('site_name', 'drupal'), '%site_url' => $base_url, '%site_mail' => variable_get('site_mail', 'root@localhost'), '%card_url' => $base .'postcard/'. $form_values['field_nid'] .'/'. $postid, '%sender' => $name, '%user' => $user->name, '%recipient' => $form_values['field_rcpt'], '%postcards' => $base .'postcard', '%card_text' => $form_values['field_body']);
|
| 412 |
$body = strtr(variable_get('postcard_letter', _postcard_letter()), $variables);
|
| 413 |
$subject = strtr(variable_get('postcard_subject', 'Postcard from %site'), $variables);
|
| 414 |
$subject = mime_header_encode($subject, 'UTF-8');
|
| 415 |
$send_date = time();
|
| 416 |
// set headers to bcc: sender if selected
|
| 417 |
if ($form_values['send_copy']) {
|
| 418 |
$headers = array( 'bcc' => $from );
|
| 419 |
}
|
| 420 |
|
| 421 |
// insert our data into the db
|
| 422 |
db_query("INSERT INTO {postcard} (pid, nid, uid, sender_name, sender_mail, recp_name, recp_mail, body, send_time) VALUES ('%s', %d, %d, '%s', '%s', '%s', '%s', '%s', %d)", $postid, $form_values['field_nid'], $user->uid, $name, $from, $form_values['field_rcpt'], $to, $form_values['field_body'], $send_date);
|
| 423 |
|
| 424 |
// send the card and return a message for the user
|
| 425 |
if (isset($postid)) {
|
| 426 |
// email it out
|
| 427 |
if (!empty($headers)) {
|
| 428 |
drupal_mail('postcard', $to, $subject, $body, $from, $headers);
|
| 429 |
}
|
| 430 |
else {
|
| 431 |
drupal_mail('postcard', $to, $subject, $body, $from);
|
| 432 |
}
|
| 433 |
// log it
|
| 434 |
watchdog('postcard', t('User %name sent a postcard to %recipient.', array('%name' => $user->name, '%recipient' => $to)));
|
| 435 |
$output .= t('Your postcard was sent! %recipient will get a message by email with a link to your picture and message. ', array('%recipient' => $form_values['field_rcpt']));
|
| 436 |
$output .= l(t('View sent postcard.'), "postcard/$arg/$postid/review");
|
| 437 |
}
|
| 438 |
// there was a problem here, Houston
|
| 439 |
else {
|
| 440 |
watchdog('postcard', t('There was a problem creating a postcard. The $postid variable was not set.'));
|
| 441 |
$output .= t('There was a problem creating your card! Please contact the site administrator.');
|
| 442 |
}
|
| 443 |
drupal_set_message($output);
|
| 444 |
// TODO: dont always want to go back here....
|
| 445 |
drupal_goto('postcard');
|
| 446 |
}
|
| 447 |
|
| 448 |
/**
|
| 449 |
* Implementation of hook_link().
|
| 450 |
*
|
| 451 |
* This adds the "send this as a postcard" link to an Image node.
|
| 452 |
**/
|
| 453 |
function postcard_link($type) {
|
| 454 |
if (user_access('send postcards')) {
|
| 455 |
if (variable_get('postcard_send', 1) == 1) {
|
| 456 |
$links = array();
|
| 457 |
$terms = array();
|
| 458 |
|
| 459 |
if ($type = 'node' && is_numeric(arg(1))) {
|
| 460 |
// get the taxonomy info from the node object
|
| 461 |
$node = node_load(arg(1));
|
| 462 |
$taxonomy = array_keys($node->taxonomy);
|
| 463 |
foreach ($taxonomy as $tid) {
|
| 464 |
$terms[] = $tid;
|
| 465 |
// get the parent(s) as well
|
| 466 |
$parents = taxonomy_get_parents($tid);
|
| 467 |
foreach ($parents as $parent) {
|
| 468 |
$terms[] = $parent->tid;
|
| 469 |
}
|
| 470 |
}
|
| 471 |
|
| 472 |
// If the node term, a parent term or all terms are in
|
| 473 |
// the postcard variable, make a postcard link.
|
| 474 |
if (in_array(variable_get('postcard_term', 0), $terms) || (variable_get('postcard_term', 0) == 0)) {
|
| 475 |
$links['send_postcard'] = array(
|
| 476 |
'title' => t('Send this as a postcard'),
|
| 477 |
'href' => 'postcard/'. $node->nid,
|
| 478 |
);
|
| 479 |
|
| 480 |
return $links;
|
| 481 |
}
|
| 482 |
}
|
| 483 |
}
|
| 484 |
}
|
| 485 |
}
|
| 486 |
|
| 487 |
|
| 488 |
/**
|
| 489 |
* Implementation of hook_cron().
|
| 490 |
**/
|
| 491 |
function postcard_cron() {
|
| 492 |
// convert cron days into timestamp
|
| 493 |
$postcard_cron = variable_get('postcard_cron', '0') * 86400;
|
| 494 |
// delete postcards older than setting
|
| 495 |
if (!empty($postcard_cron)) {
|
| 496 |
db_query('DELETE FROM {postcard} WHERE send_time < %d', time() - $postcard_cron);
|
| 497 |
}
|
| 498 |
}
|
| 499 |
|
| 500 |
/**
|
| 501 |
* Set up the standard letter
|
| 502 |
*
|
| 503 |
* This is done so that there is a default reusable, translatable string
|
| 504 |
* for the letter even without visiting the settings page.
|
| 505 |
**/
|
| 506 |
function _postcard_letter() {
|
| 507 |
$output = t("Dear %recipient!\n\n%sender made an e-postcard for you.\nAt any time you may see your card by clicking this link:\n\n%card_url\n\n(if your email client doesn't allow you to click on the site link,\nthen just copy and paste the URL into your browser)\n\nAny complaints about this e-postcard service please send to %site_mail\n\n-- \nThis postcard was sent through %site");
|
| 508 |
return $output;
|
| 509 |
}
|
| 510 |
|
| 511 |
/**
|
| 512 |
* Theme a gallery page (taken from theme_image_gallery)
|
| 513 |
*
|
| 514 |
* @return
|
| 515 |
* HTML for postcard gallery
|
| 516 |
*/
|
| 517 |
function theme_postcard_gallery($galleries, $images) {
|
| 518 |
drupal_add_css(drupal_get_path('module', 'image_gallery') .'/image_gallery.css');
|
| 519 |
|
| 520 |
// This check is needed due to an api change in image module at 5.x-1.3.
|
| 521 |
if (function_exists('_image_get_sizes')) {
|
| 522 |
$size = _image_get_sizes('thumbnail');
|
| 523 |
}
|
| 524 |
else {
|
| 525 |
$size = _image_get_dimensions('thumbnail');
|
| 526 |
}
|
| 527 |
$width = $size['width'];
|
| 528 |
$height = $size['height'];
|
| 529 |
|
| 530 |
$content = '';
|
| 531 |
if (count($galleries)) {
|
| 532 |
$content .= '<ul class="galleries">';
|
| 533 |
foreach ($galleries as $gallery) {
|
| 534 |
$content .= '<li>';
|
| 535 |
if ($gallery->count)
|
| 536 |
$content .= l(image_display($gallery->latest, 'thumbnail'), 'postcard/tid/'. $gallery->tid, array(), NULL, NULL, FALSE, TRUE);
|
| 537 |
$content .= "<h3>". l($gallery->name, 'postcard/tid/'. $gallery->tid) ."</h3>\n";
|
| 538 |
$content .= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
|
| 539 |
$content .= '<p class="count">'. format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
|
| 540 |
if ($gallery->latest->changed) {
|
| 541 |
$content .= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) ."</p>\n";
|
| 542 |
}
|
| 543 |
$content .= "</li>\n";
|
| 544 |
}
|
| 545 |
$content .= "</ul>\n";
|
| 546 |
}
|
| 547 |
|
| 548 |
if (count($images)) {
|
| 549 |
$height += 75;
|
| 550 |
$content .= '<ul class="images">';
|
| 551 |
foreach ($images as $image) {
|
| 552 |
$content .= '<li';
|
| 553 |
if ($image->sticky) {
|
| 554 |
$content .= ' class="sticky"';
|
| 555 |
}
|
| 556 |
$content .= ' style="height : '. $height .'px; width : '. $width .'px;"';
|
| 557 |
$content .= ">\n";
|
| 558 |
$content .= l(image_display($image, 'thumbnail'), 'postcard/'. $image->nid, array(), NULL, NULL, FALSE, TRUE);
|
| 559 |
$content .= '<h3>'. l($image->title, 'postcard/'. $image->nid) ."</h3>";
|
| 560 |
if (variable_get('image_gallery_node_info', 0)) {
|
| 561 |
$content .= '<div class="author">'. t('Posted by: !name', array('!name' => theme('username', $image))) ."</div>\n";
|
| 562 |
if ($image->created > 0) {
|
| 563 |
$content .= '<div class="date">'. format_date($image->created) ."</div>\n";
|
| 564 |
}
|
| 565 |
}
|
| 566 |
$content .= "</li>\n";
|
| 567 |
}
|
| 568 |
$content .= "</ul>\n";
|
| 569 |
}
|
| 570 |
|
| 571 |
if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
|
| 572 |
$content .= $pager;
|
| 573 |
}
|
| 574 |
|
| 575 |
if (count($images) + count($galleries) == 0) {
|
| 576 |
$content .= '<p class="count">'. format_plural(0, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
|
| 577 |
}
|
| 578 |
|
| 579 |
return $content;
|
| 580 |
}
|
| 581 |
|
| 582 |
|
| 583 |
/**
|
| 584 |
* Theme function for a single postcard.
|
| 585 |
*
|
| 586 |
* To change the image size for all postcards, change 'preview' in the
|
| 587 |
* image_display function below to a size label that you have listed in your
|
| 588 |
* Image module image sizes setting at admin/settings/image
|
| 589 |
*
|
| 590 |
* @return
|
| 591 |
* HTML for postcard node
|
| 592 |
*/
|
| 593 |
function theme_postcard_image($card) {
|
| 594 |
// get the node and user info
|
| 595 |
$node = node_load(array('nid' => $card->nid));
|
| 596 |
$account = user_load(array('uid' => $card->uid));
|
| 597 |
// build the postcard page
|
| 598 |
//////////////////////////////////////////////////
|
| 599 |
// display the image we are using for the postcard
|
| 600 |
// if the image is from image module use that
|
| 601 |
//if (module_exists('image')) {
|
| 602 |
// $node = node_load(array('nid' => $nid));
|
| 603 |
// $output .= image_display($node, variable_get('postcard_size', 'preview'));
|
| 604 |
//}
|
| 605 |
// otherwise see if they are using imagecache and use that
|
| 606 |
// get the image info we need
|
| 607 |
$image = db_fetch_object(db_query("SELECT nid, filepath FROM {files} WHERE nid = %d", $card->nid));
|
| 608 |
if (module_exists('imagecache')) {
|
| 609 |
$output .= theme('imagecache', variable_get('postcard_size', ''), $image->filepath);
|
| 610 |
}
|
| 611 |
//$output .= dsm($sizes);
|
| 612 |
//////////////////////////////////////////////////
|
| 613 |
$output .= '<br />'. t('To: ') . check_plain($card->recp_name);
|
| 614 |
$output .= '<hr />'. check_plain($card->body) .'<hr />';
|
| 615 |
// this shows the user picture if the "display in node" setting is checked on the theme
|
| 616 |
if (theme_get_setting('toggle_node_user_picture')) {
|
| 617 |
$output .= theme('user_picture', $account);
|
| 618 |
}
|
| 619 |
$output .= t('Sent: ') . format_date($card->send_time);
|
| 620 |
$output .= '<br />'. t('From: ') . check_plain($card->sender_name);
|
| 621 |
$output .= '<br />'. t('Email: ') . check_plain($card->sender_mail);
|
| 622 |
return $output;
|
| 623 |
}
|