| 1 |
<?php |
<?php |
| 2 |
// $Id: node_blaster.module,v 1.2 2006/11/15 18:02:48 bpocanada Exp $ |
// $Id: node_blaster.module,v 1.1 2007/03/23 15:25:37 bpocanada Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 32 |
* Define the node type |
* Define the node type |
| 33 |
*/ |
*/ |
| 34 |
function node_blaster_node_info() { |
function node_blaster_node_info() { |
| 35 |
return array('node_blaster' => array('name' => t('Node blaster'), 'base' => 'node_blaster','description' => 'Node blaster for sending periodic content subscription.')); |
return array( |
| 36 |
|
'node_blaster' => array( |
| 37 |
|
'name' => t('Node blaster'), |
| 38 |
|
'module' => 'node_blaster', |
| 39 |
|
'description' => t("Node blaster for sending periodic content subscription."), |
| 40 |
|
) |
| 41 |
|
); |
| 42 |
|
|
| 43 |
} |
} |
|
|
|
|
|
|
| 44 |
|
|
| 45 |
/** |
/** |
| 46 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 90 |
if ($node->nid && $node->type == 'node_blaster') { |
if ($node->nid && $node->type == 'node_blaster') { |
| 91 |
|
|
| 92 |
$items[] = array('path' => 'node/'. arg(1) .'/subscriber', 'title' => t('subscriber'), |
$items[] = array('path' => 'node/'. arg(1) .'/subscriber', 'title' => t('subscriber'), |
| 93 |
'callback' => 'node_blaster_subscriber', |
'callback' => 'show_node_blaster_subscriber', |
| 94 |
'callback arguments' => array(arg(1)), |
'callback arguments' => array(arg(1)), |
| 95 |
'access' => user_access('create node blaster'), |
'access' => user_access('create node blaster'), |
| 96 |
'weight' => 1, |
'weight' => 1, |
| 142 |
if( $aid && user_access('create node blaster') ) { |
if( $aid && user_access('create node blaster') ) { |
| 143 |
db_query("delete from {node_blaster} WHERE aid ='%d'",$aid); |
db_query("delete from {node_blaster} WHERE aid ='%d'",$aid); |
| 144 |
// Clear the cache so an anonymous poster can see the node being deleted. |
// Clear the cache so an anonymous poster can see the node being deleted. |
| 145 |
cache_clear_all(); |
cache_clear_all(); |
| 146 |
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', 'node_blaster')))); |
drupal_set_message(t('%title has been deleted.', array('%title' => theme('placeholder', 'node_blaster')))); |
| 147 |
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t('node_blaster')), '%title' => theme('placeholder', 'node_blaster')))); |
watchdog('content', t('%type: deleted %title.', array('%type' => theme('placeholder', t('node_blaster')), '%title' => theme('placeholder', 'node_blaster')))); |
| 148 |
|
// delete all subscriber of this node_blaster TODO |
| 149 |
} |
} |
| 150 |
} |
} |
| 151 |
|
|
| 168 |
} |
} |
| 169 |
else |
else |
| 170 |
if( count($_GET) > 0) { |
if( count($_GET) > 0) { |
| 171 |
$aid = $_GET['aid']; |
$aid = $_GET['aid']; |
| 172 |
$name = $_GET['name']; |
$name = $_GET['name']; |
| 173 |
$email = $_GET['email']; |
$email = $_GET['email']; |
| 174 |
|
|
| 175 |
$submit = $_GET['subscribe']; |
$submit = $_GET['subscribe']; |
| 176 |
$redirect = $_GET['redirect']; |
$redirect = $_GET['redirect']; |
| 177 |
|
|
| 178 |
$subtime = time(); |
$subtime = time(); |
| 179 |
if ( $submit == 'Submit' ) { |
if ( $submit == 'Submit' ) { |
| 180 |
db_query("INSERT INTO {node_blaster_subscriber} (sid, aid, name, email, date ) VALUES ('', '%d', '%s','%s', '%d' )", $aid, $name, $email, $subtime ); |
db_query("INSERT INTO {node_blaster_subscriber} (sid, aid, name, email, date ) VALUES ('', '%d', '%s','%s', '%d' )", $aid, $name, $email, $subtime ); |
| 181 |
} |
} |
| 182 |
|
|
| 183 |
} else { |
} |
| 184 |
return "Sorry no input data subscription failed."; |
else { |
| 185 |
|
return "Sorry no input data subscription failed."; |
| 186 |
} |
} |
| 187 |
|
|
| 188 |
drupal_goto($redirect); |
drupal_goto($redirect); |
| 218 |
return $nodes; |
return $nodes; |
| 219 |
} |
} |
| 220 |
|
|
| 221 |
|
function show_node_blaster_subscriber($aid = ''){ |
| 222 |
|
$output = drupal_get_form('node_blaster_subscriber', $aid); |
| 223 |
|
|
| 224 |
|
return $output; |
| 225 |
|
} |
| 226 |
/** |
/** |
| 227 |
* Display all subscriber Details |
* Display all subscriber Details |
| 228 |
*/ |
*/ |
| 267 |
$form['subscriber'][] = array('#value'=>'</div>'); |
$form['subscriber'][] = array('#value'=>'</div>'); |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
$output = drupal_get_form('node_blaster_subscriber', $form); |
return $form; |
|
return $output; |
|
| 271 |
} |
} |
| 272 |
|
|
| 273 |
// theme node_blaster page |
// theme node_blaster page |
| 274 |
|
|
| 275 |
function theme_node_blaster_subscriber($form) { |
function theme_node_blaster_subscriber($form) { |
| 276 |
$output = form_render($form); |
$output = drupal_render($form); |
| 277 |
return $output; |
return $output; |
| 278 |
} |
} |
| 279 |
|
|
| 324 |
* every time a node is loaded, and allows us to do some loading of our own. |
* every time a node is loaded, and allows us to do some loading of our own. |
| 325 |
*/ |
*/ |
| 326 |
function node_blaster_load($node) { |
function node_blaster_load($node) { |
| 327 |
$additions = db_fetch_object(db_query('SELECT ar.mail_theme, ar.redirect_url, ar.public_url FROM {node_blaster} ar, {node_blaster_node} arn WHERE ar.vid = %d ', $node->vid)); |
$additions = db_fetch_object(db_query('SELECT mail_theme, redirect_url, public_url FROM {node_blaster} ar WHERE vid = %d ', $node->vid)); |
| 328 |
$additions_node1 = db_query('SELECT nid, series, day_sent FROM {node_blaster_node} WHERE aid = %d ', $node->nid); |
$additions_node1 = db_query('SELECT nid, series, day_sent FROM {node_blaster_node} WHERE aid = %d ', $node->nid); |
| 329 |
$additions_node = array(); |
$additions_node = array(); |
| 330 |
while( $additions_n = db_fetch_array($additions_node1) ) { |
while( $additions_n = db_fetch_array($additions_node1) ) { |
| 343 |
* a sub array containing information for each element in the form. |
* a sub array containing information for each element in the form. |
| 344 |
*/ |
*/ |
| 345 |
function node_blaster_form(&$node) { |
function node_blaster_form(&$node) { |
| 346 |
|
|
| 347 |
$node = (object) $node; |
$node = (object) $node; |
| 348 |
$layouts = node_blaster_layouts('page', TRUE); |
$layouts = node_blaster_layouts('page', TRUE); |
| 349 |
|
|
| 359 |
'#default_value' => $node->body, |
'#default_value' => $node->body, |
| 360 |
'#required' => FALSE |
'#required' => FALSE |
| 361 |
); |
); |
| 362 |
$form['mail_theme'] = array('#type' => 'select', // '#required' => TRUE |
|
| 363 |
|
$form['mail_theme'] = array('#type' => 'select', // '#required' => TRUE |
| 364 |
'#title' => t('Use theme to control email MIME/HTML output? '), |
'#title' => t('Use theme to control email MIME/HTML output? '), |
| 365 |
'#default_value' => $node->mail_theme, '#options' => $layouts); |
'#default_value' => $node->mail_theme, '#options' => $layouts); |
| 366 |
|
|
| 367 |
if ($node->nid) { // node section |
if ($node->nid) { // node section |
| 368 |
$form['node_blaster_nodes'] = array( |
$form['node_blaster_nodes'] = array( |
| 369 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 376 |
$form['node_blaster_nodes'][] = array('#value'=>'</div>'); |
$form['node_blaster_nodes'][] = array('#value'=>'</div>'); |
| 377 |
|
|
| 378 |
$resultm = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.changed, n.status, n.type, an.series, an.day_sent |
$resultm = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.changed, n.status, n.type, an.series, an.day_sent |
| 379 |
FROM {node_blaster_node} an LEFT JOIN {node} n ON n.nid = an.nid |
FROM {node} n LEFT JOIN {node_blaster_node} an ON n.nid = an.nid |
| 380 |
WHERE n.type != 'node_blaster' and n.title !='' ORDER BY n.changed DESC")); |
WHERE n.type != 'node_blaster' and n.title !='' ORDER BY n.changed DESC")); |
| 381 |
|
|
| 382 |
$node_lst = node_blaster_get_node(); |
$node_lst = node_blaster_get_node(); |
| 384 |
if (db_num_rows($resultm) > 0 ) { |
if (db_num_rows($resultm) > 0 ) { |
| 385 |
|
|
| 386 |
$rows = array(); |
$rows = array(); |
| 387 |
|
// TODO make it configurable |
| 388 |
$day_sent_option = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); |
$day_sent_option = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); |
| 389 |
|
|
| 390 |
$tot_toshow = count( $node->ar_node ); // priority |
$tot_toshow = count( $node->ar_node ); // priority |
| 410 |
break; // display only selected |
break; // display only selected |
| 411 |
else |
else |
| 412 |
$to_disp++; |
$to_disp++; |
| 413 |
|
|
| 414 |
|
|
| 415 |
|
$form1['series_' . $autn->nid]= array( |
| 416 |
|
'#type' => 'weight', // default_value not working ???? |
| 417 |
|
'#value' => ( !$autn->series ) ? $to_disp : $autn->series, |
| 418 |
|
'#delta' => 20, |
| 419 |
|
'#parents' => array('series_' . $autn->nid), |
| 420 |
|
'#tree' => FALSE, |
| 421 |
|
); // TODO '#attributes' => array('onchange'=>'onChangeTID(' . $autn->nid . ')') |
| 422 |
|
|
| 423 |
|
$form['name']['node_'.$autn->nid] = array( |
| 424 |
|
'#type'=>'select', |
| 425 |
|
'#name'=>'node_'.$autn->nid, |
| 426 |
|
'#parents' => array('series_' . $autn->nid), |
| 427 |
|
'#options' => $node_lst, |
| 428 |
|
'#value' => $autn->nid, |
| 429 |
|
'#tree' => FALSE, |
| 430 |
|
); |
| 431 |
|
|
| 432 |
|
$form['day_sent']['day_sent_' . $autn->nid] = array( |
| 433 |
|
'#type' => 'select', |
| 434 |
|
'#name'=>'day_sent_' . $autn->nid, |
| 435 |
|
'#value' => $autn->day_sent, |
| 436 |
|
'#weight' => 5, |
| 437 |
|
'#options' => $day_sent_option, |
| 438 |
|
'#parents' => array('series_' . $autn->nid), |
| 439 |
|
'#tree' => FALSE, |
| 440 |
|
'#attributes' => array('onchange'=>'onChangeWeight(' . $autn->nid . ')'), |
| 441 |
|
); |
| 442 |
|
|
| 443 |
$form['series']['series_' . $autn->nid] = array('#type' => 'weight', |
$row[] = drupal_render($form['name']['node_'.$autn->nid]); |
| 444 |
'#name'=>'series_' . $autn->nid, |
$row[] = drupal_render(process_weight($form1['series_' . $autn->nid])); // theme('weight', $form['series_' . $autn->nid]['weight']); not worked bad stuff |
| 445 |
'#value' => ($autn->series == '') ? 0 : $autn->series, |
$row[] = drupal_render($form['day_sent']['day_sent_' . $autn->nid]); |
| 446 |
'#delta' => 20, |
|
| 447 |
'#parents' => array('series_' . $autn->nid), |
$rows[] = $row; |
| 448 |
'#tree' => FALSE, |
|
| 449 |
'#attributes' => array('onchange'=>'onChangeTID(' . $autn->nid . ')')); |
} |
| 450 |
$form['name']['node_'.$autn->nid] = array('#type'=>'select', |
} // end while |
| 451 |
'#name'=>'node_'.$autn->nid, |
}else { |
|
'#parents' => array('series_' . $autn->nid), |
|
|
'#options' => $node_lst, |
|
|
'#value' => $autn->nid, |
|
|
'#tree' => FALSE, |
|
|
); |
|
|
$form['day_sent']['day_sent_' . $autn->nid] = array('#type' => 'select', |
|
|
'#name'=>'day_sent_' . $autn->nid, |
|
|
'#value' => $autn->day_sent, |
|
|
'#weight' => 5, |
|
|
'#options' => $day_sent_option, |
|
|
'#parents' => array('series_' . $autn->nid), |
|
|
'#tree' => FALSE, |
|
|
'#attributes' => array('onchange'=>'onChangeWeight(' . $autn->nid . ')')); |
|
|
|
|
|
$row[] = form_render($form['series']['series_' . $autn->nid]); |
|
|
$row[] = form_render($form['name']['node_'.$autn->nid]); |
|
|
$row[] = form_render($form['day_sent']['day_sent_' . $autn->nid]); |
|
|
$rows[] = $row; |
|
|
} |
|
|
} // end while |
|
|
}else { |
|
| 452 |
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6')); |
$rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6')); |
| 453 |
} |
} |
| 454 |
|
|
| 455 |
$header = array(t('# in Sequence'), t('Node Title'), t('Day')); |
$header = array(t('Node Title'), t('# in Sequence'), t('Day')); |
| 456 |
$table_content = theme('table', $header, $rows); |
$table_content = theme('table', $header, $rows); |
| 457 |
|
|
| 458 |
$form['node_blaster_nodes'][] = array('#value'=> $table_content.'<br>'); |
$form['node_blaster_nodes'][] = array('#value'=> $table_content.'<br>'); |
| 523 |
} else { |
} else { |
| 524 |
|
|
| 525 |
} |
} |
| 526 |
|
|
| 527 |
return $form; |
return $form; |
| 528 |
} |
} |
| 529 |
|
|
| 530 |
|
/** |
| 531 |
|
* hook_form_alter() |
| 532 |
|
* |
| 533 |
|
* @param unknown_type $form_id |
| 534 |
|
* @param unknown_type $form |
| 535 |
|
*/ |
| 536 |
function node_blaster_form_alter($form_id, &$form){ |
function node_blaster_form_alter($form_id, &$form){ |
| 537 |
// unset($form['comment_settings']); |
|
| 538 |
// print_r($form); |
// print_r($form); // debug code here |
| 539 |
|
|
| 540 |
// unset any variable for this node_blaster |
// unset any variable for this node_blaster |
| 541 |
|
if ( $form_id == 'node_type_form' && isset($form['identity']['type']) ) { |
| 542 |
|
|
| 543 |
|
$node_type = $form['#node_type']->type; |
| 544 |
|
|
| 545 |
|
$form['workflow']["node_blaster_notify"] = array( |
| 546 |
|
'#type' => 'checkbox', |
| 547 |
|
'#title' => t("Notify admin when new .".$node_type." is submitted."), |
| 548 |
|
'#description'=>t('Admin will be notified when new content will be created with type.'.$node_type), |
| 549 |
|
'#return_value' => 1, |
| 550 |
|
'#default_value' => variable_get("node_blaster_notify_$node_type", 0), |
| 551 |
|
); |
| 552 |
|
} |
| 553 |
|
|
| 554 |
} |
} |
| 555 |
|
|
| 556 |
/** |
/** |
| 557 |
|
* hook_nodeapi |
| 558 |
|
* |
| 559 |
|
* @param unknown_type $node |
| 560 |
|
* @param unknown_type $op |
| 561 |
|
* @param unknown_type $teaser |
| 562 |
|
* @param unknown_type $page |
| 563 |
|
*/ |
| 564 |
|
function node_blaster_nodeapi(&$node, $op, $teaser, $page) { |
| 565 |
|
switch ($op) { |
| 566 |
|
case 'insert': |
| 567 |
|
// check node type and send an email to suggest type |
| 568 |
|
if( variable_get("node_blaster_notify_$node->type", 0) ){ |
| 569 |
|
// send an email with title as subject & detail in body |
| 570 |
|
$to = variable_get("site_mail",""); // or user id 1 |
| 571 |
|
if($to !="" ) { |
| 572 |
|
$from = ini_get('sendmail_from'); |
| 573 |
|
$subject = t($node->title); |
| 574 |
|
$body = t('A new location suggestion has been made. |
| 575 |
|
Details below: |
| 576 |
|
'.$node->body); |
| 577 |
|
// debug code |
| 578 |
|
// echo "".$to.$subject.$body.$from."<br />"; |
| 579 |
|
drupal_mail('new_'.$node->type, $to, $subject, $body, $from); |
| 580 |
|
} |
| 581 |
|
} |
| 582 |
|
break; |
| 583 |
|
case 'update': |
| 584 |
|
// nothing for now |
| 585 |
|
break; |
| 586 |
|
} |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
/** |
| 590 |
* Implementation of hook_insert(). |
* Implementation of hook_insert(). |
| 591 |
* |
* |
| 592 |
* As a new node is being inserted into the database, we need to do our own |
* As a new node is being inserted into the database, we need to do our own |
| 593 |
* database inserts. |
* database inserts. |
| 594 |
*/ |
*/ |
| 595 |
function node_blaster_insert($node) { |
function node_blaster_insert($node) { |
| 596 |
|
|
| 597 |
if( !$edit['aid'] ) { |
if( !$edit['aid'] ) { |
| 598 |
$edit['eid'] = db_next_id('{node_blaster}_aid'); |
$edit['eid'] = db_next_id('{node_blaster}_aid'); |
| 599 |
db_query("INSERT INTO {node_blaster} (vid, nid, mail_theme) VALUES (%d, '%d', '%s')", $node->vid, $node->nid, $node->mail_theme ); |
db_query("INSERT INTO {node_blaster} (vid, nid, mail_theme) VALUES (%d, '%d', '%s')", $node->vid, $node->nid, $node->mail_theme ); |
| 616 |
|
|
| 617 |
db_query("UPDATE {node_blaster} set vid='%d', mail_theme = '%s', public_url = '%s' where nid='%d' ", $node->vid, $_POST['edit']['mail_theme'], $_POST['edit']['public_url'], $node->nid); |
db_query("UPDATE {node_blaster} set vid='%d', mail_theme = '%s', public_url = '%s' where nid='%d' ", $node->vid, $_POST['edit']['mail_theme'], $_POST['edit']['public_url'], $node->nid); |
| 618 |
db_query("DELETE from {node_blaster_node} where aid = %d ",$node->nid); |
db_query("DELETE from {node_blaster_node} where aid = %d ",$node->nid); |
| 619 |
|
|
| 620 |
|
print_r($_POST); |
| 621 |
|
exit; |
| 622 |
|
|
| 623 |
// update node order |
// update node order |
| 624 |
foreach ( $_POST as $key => $val ) { |
foreach ( $_POST as $key => $val ) { |
| 625 |
// echo "<br>". $key. $val; |
// echo "<br>". $key. $val; |
| 688 |
* This is a typical implementation that simply runs the node text through |
* This is a typical implementation that simply runs the node text through |
| 689 |
* the output filters. |
* the output filters. |
| 690 |
*/ |
*/ |
| 691 |
function node_blaster_view(&$node, $teaser = FALSE, $page = FALSE) { |
function node_blaster_view($node, $teaser = FALSE, $page = FALSE) { |
| 692 |
$node = node_prepare($node, $teaser); |
$node = node_prepare($node, $teaser); |
| 693 |
$arc_info = theme('node_blaster_info', $node); |
|
| 694 |
$node->body .= $arc_info; // no need here for node_blaster |
$node->content['nblaster'] = array( |
| 695 |
$node->teaser .= $arc_info; |
'#value' => theme('node_blaster_info', $node), |
| 696 |
|
'#weight' => 1, |
| 697 |
|
); |
| 698 |
|
|
| 699 |
|
// debug code |
| 700 |
// node_blaster_cron(); |
// node_blaster_cron(); |
| 701 |
|
|
| 702 |
|
return $node; |
| 703 |
} |
} |
| 704 |
|
|
| 705 |
|
|
| 749 |
$email = substr($email,0,-1); // remove last comma |
$email = substr($email,0,-1); // remove last comma |
| 750 |
$header =''; |
$header =''; |
| 751 |
if( $email !='' ) { |
if( $email !='' ) { |
| 752 |
user_mail($email, $autor->title, $message, ''); |
// TODO make ... |
| 753 |
|
drupal_mail('node_blaster',$email, $autor->title, $message); |
| 754 |
echo $email; |
echo $email; |
| 755 |
// drupal_set_message('Node blaster executed successfully. Mail sent to '.$email); |
// drupal_set_message('Node blaster executed successfully. Mail sent to '.$email); |
| 756 |
} |
} |
| 761 |
|
|
| 762 |
// cloud_update($site); |
// cloud_update($site); |
| 763 |
// user_mail($mail, $subject, $message, $header); this will send mail |
// user_mail($mail, $subject, $message, $header); this will send mail |
| 764 |
|
// drupal_mail($mailkey, $to, $subject, $body, $from, $headers); |
| 765 |
// db_query('DELETE FROM {history} WHERE timestamp < %d', NODE_NEW_LIMIT); |
// db_query('DELETE FROM {history} WHERE timestamp < %d', NODE_NEW_LIMIT); |
| 766 |
} |
} |
| 767 |
|
|