/[drupal]/contributions/modules/node_blaster/node_blaster.module
ViewVC logotype

Contents of /contributions/modules/node_blaster/node_blaster.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sat May 19 17:31:02 2007 UTC (2 years, 6 months ago) by gloscon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +153 -63 lines
File MIME type: text/x-php
#Updated for Drupal 5.0
1 <?php
2 // $Id: node_blaster.module,v 1.1 2007/03/23 15:25:37 bpocanada Exp $
3
4 /**
5 * @file
6 * Enables users to create node_blaster that will be subscribed by user for periodic subscription.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function node_blaster_help($section = 'admin/help#node_blaster') {
13 switch ($section) {
14 case 'admin/help#node_blaster':
15 $output = '<p>'. t('The node blaster module is used to create a newsletter like called <em>node blaster.</em>') .'</p>';
16 $output .= '<p>'. t('The node blaster administration interface allows for complex configuration. It provides a submission form, workflow, default view permission, default edit permission, permissions for permission, and attachments. Trackbacks can also be enabled.') .'</p>';
17 $output .= t('<p>You can</p>
18 <ul>
19 <li>post a node blaster at <a href="%node-add-node_blaster">create content &gt;&gt; node_blaster</a>.</li>
20 </ul>
21 ', array('%node-add-node_blaster' => url('node/add/node_blaster') ));
22 return $output;
23 case 'admin/modules#description':
24 return t('Allows users to create node blaster containing series of node to be sent out to subscriber.');
25 case 'node/add#node_blaster':
26 return t('Node blaster is for sending periodic content to user who will subscribe for this.');
27 }
28 }
29
30 /**
31 * Implementation of hook_node_info().
32 * Define the node type
33 */
34 function node_blaster_node_info() {
35 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().
47 * define all access for node blaster
48 */
49 function node_blaster_perm() {
50 return array('create node blaster', 'edit own node blaster', 'administer node blaster');
51 }
52
53 /**
54 * Implementation of hook_access().
55 *
56 * Node modules may implement node_access() to determine the operations
57 * users may perform on nodes. This example uses a very common access pattern.
58 */
59 function node_blaster_access($op, $node) {
60 global $user;
61
62 if ($op == 'create') {
63 return user_access('create node blaster');
64 }
65
66 if ($op == 'update' || $op == 'delete') {
67 if (user_access('edit own node blaster') && ($user->uid == $node->uid)) {
68 return TRUE;
69 }
70 }
71 }
72
73 /**
74 * Implementation of hook_menu().
75 */
76 function node_blaster_menu($may_cache) {
77 $items = array();
78
79 if ($may_cache) {
80
81 $items[] = array('path' => 'node/add/node_blaster',
82 'title' => t('Node blaster'),
83 'access' => user_access('create node blaster')
84 );
85 }
86 else {
87
88 if (arg(0) == 'node' && is_numeric(arg(1))) {
89 $node = node_load(arg(1));
90 if ($node->nid && $node->type == 'node_blaster') {
91
92 $items[] = array('path' => 'node/'. arg(1) .'/subscriber', 'title' => t('subscriber'),
93 'callback' => 'show_node_blaster_subscriber',
94 'callback arguments' => array(arg(1)),
95 'access' => user_access('create node blaster'),
96 'weight' => 1,
97 'type' => MENU_LOCAL_TASK);
98
99
100
101 }
102
103 }
104 if ( is_numeric(arg(2) )) {
105 $items[] = array('path' => 'node_blaster/subscribe/'.arg(2),
106 'title' => t('Subscribe to Node blaster'),
107 'callback' => 'node_blaster_subscribe', // with all posted data
108 'callback arguments' => array(arg(2)),
109 'access' => true, // put new access system here to control whether to control subscription
110 'type' => MENU_CALLBACK);
111 }
112 }
113 return $items;
114 }
115
116 /**
117 * Implementation of hook_validate().
118 *
119 * Our "quantity" field requires a number to be entered. This hook lets
120 * us ensure that the user entered an appropriate value before we try
121 * inserting anything into the database.
122 *
123 * Errors should be signaled with form_set_error().
124 */
125 function node_blaster_validate(&$node) {
126 if ($node->quantity) {
127 if (!is_numeric($node->quantity)) {
128 form_set_error('quantity', t('The quantity must be a number.'));
129 }
130 }
131 else {
132 // Let an empty field mean "zero."
133 $node->quantity = 0;
134 }
135 }
136
137 /**
138 * Delete an node_blaster.
139 */
140 function node_blaster_delete($aid) {
141
142 if( $aid && user_access('create node blaster') ) {
143 db_query("delete from {node_blaster} WHERE aid ='%d'",$aid);
144 // Clear the cache so an anonymous poster can see the node being deleted.
145 cache_clear_all();
146 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'))));
148 // delete all subscriber of this node_blaster TODO
149 }
150 }
151
152 /**
153 * display subscriber list
154 */
155 function node_blaster_subscribe($aid) {
156 if( count($_POST) > 0) {
157 $aid = $_POST['aid'];
158 $name = $_POST['name'];
159 $email = $_POST['email'];
160
161 $submit = $_POST['subscribe'];
162 $redirect = $_POST['redirect'];
163
164 $subtime = time();
165 if ( $submit == 'Submit' ) {
166 db_query("INSERT INTO {node_blaster_subscriber} (sid, aid, name, email, date ) VALUES ('', '%d', '%s','%s', '%d' )", $aid, $name, $email, $subtime );
167 }
168 }
169 else
170 if( count($_GET) > 0) {
171 $aid = $_GET['aid'];
172 $name = $_GET['name'];
173 $email = $_GET['email'];
174
175 $submit = $_GET['subscribe'];
176 $redirect = $_GET['redirect'];
177
178 $subtime = time();
179 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 );
181 }
182
183 }
184 else {
185 return "Sorry no input data subscription failed.";
186 }
187
188 drupal_goto($redirect);
189 }
190
191 function node_blaster_list() {
192
193 $node_blasters = db_query("SELECT * FROM {node_blaster}");
194 $header = array(t('Node blaster Name'), array("data" => t("operations"), "colspan" => 2));
195
196 while ($node_blaster = db_fetch_object($node_blasters)) {
197
198 $rows[] = array(l('<b>' . t($node_blaster->name) . '</b>', "node_blaster/$node_blaster->aid", array(), NULL, NULL, FALSE, TRUE),
199 l(t("edit"), "node_blaster/edit/$node_blaster->aid"),
200 l(t("delete"), "node_blaster/delete/$node_blaster->aid")
201 );
202
203
204 }
205 $output = theme("table", $header, $rows);
206 return $output;
207 }
208
209 /**
210 * Get node_blaster detail
211 */
212 function get_node_blaster($aid) {
213
214 $result = db_query(db_rewrite_sql("SELECT * FROM {node_blaster} at WHERE at.aid ='%d' "), $aid);
215 while ($node = db_fetch_object($result)) {
216 $nodes = $node; // send all
217 }
218 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
228 */
229 function node_blaster_subscriber($aid = '') {
230
231 if( $aid == '' ) {
232 $output = "Subscriber list" ;
233 }
234 else {
235 $node = node_load($aid);
236 drupal_set_title($node->title);
237 // display all node_blaster subscriber
238 $output = "<br>Hi here goes all subscriber list. coming soon.. any suggestion?";
239 $form['subscriber'][] = array('#value'=>'<b>Subscriber List<br><br></b>');
240 $form['subscriber'][] = array('#value'=>'<div class="container-inline">');
241
242 $form['subscriber'][] = array('#value'=>'<table width=100% border=1>');
243
244 $form['subscriber'][] = array('#value'=>'<tr>');
245 $form['subscriber'][] = array('#value'=>'<b>Name</b>','#prefix'=>'<td>','#suffix'=>'</td>');
246 $form['subscriber'][] = array('#value'=>'<b>Email</b>','#prefix'=>'<td>','#suffix'=>'</td>');
247 // $form['subscriber'][] = array('#value'=>'<b></b>','#prefix'=>'<td>','#suffix'=>'</td>'); // Message TODO
248 $form['subscriber'][] = array('#value'=>'</tr>');
249
250 // loop to display all subscriber record
251 $result = db_query("select * from {node_blaster_subscriber} where aid = '%d' ORDER BY sid desc ",$aid);
252
253 if( db_num_rows( $result) > 0 ) {
254 while ($asubscriber = db_fetch_object($result)) {
255
256 $form['subscriber'][] = array('#value'=>'<tr>');
257 $form['subscriber'][] = array('#value'=>$asubscriber->name.'&nbsp;','#prefix'=>'<td>','#suffix'=>'</td>');
258 $form['subscriber'][] = array('#value'=>$asubscriber->email.'&nbsp;','#prefix'=>'<td>','#suffix'=>'</td>');
259 // $form['subscriber'][] = array('#value'=>'','#prefix'=>'<td>','#suffix'=>'</td>'); // l('View','#') TODO
260 $form['subscriber'][] = array('#value'=>'</tr>');
261 }
262 }else {
263 $form['subscriber'][] = array('#value'=>'<tr><td colspan="2"> No subscriber found.</td><tr>');
264
265 }
266 $form['subscriber'][] = array('#value'=>'</table>');
267 $form['subscriber'][] = array('#value'=>'</div>');
268 }
269
270 return $form;
271 }
272
273 // theme node_blaster page
274
275 function theme_node_blaster_subscriber($form) {
276 $output = drupal_render($form);
277 return $output;
278 }
279
280 /**
281 * Get all nodes to add for node_blaster
282 * @param = NULL
283 * return all nodes array
284 */
285
286 // node_blaster node display
287
288 function node_blaster_get_node() {
289
290 $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, n.changed, n.status, n.type, an.series, an.day_sent
291 FROM {node} n LEFT JOIN {node_blaster_node} an ON n.nid = an.nid
292 ORDER BY n.changed DESC"));
293
294 while ($node = db_fetch_object($result)) {
295 if ($node->type != 'node_blaster') {
296 $nodes[$node->nid] = $node->title;
297 }
298 }
299
300 return $nodes;
301 }
302
303 /**
304 * Function to print array for debugging
305 * BY -- dsingh
306 */
307
308 function echo_pre($arr,$head = '',$debug = false) {
309 if( $debug ) {
310 echo "<pre>";
311 if($head !='') {
312 echo "$head<br>";
313 }
314 print_r($arr);
315 echo "</pre>";
316 }
317 }
318
319 /**
320 * Implementation of hook_load().
321 *
322 * Now that we've defined how to manage the node data in the database, we
323 * need to tell Drupal how to get the node back out. This hook is called
324 * every time a node is loaded, and allows us to do some loading of our own.
325 */
326 function node_blaster_load($node) {
327 $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);
329 $additions_node = array();
330 while( $additions_n = db_fetch_array($additions_node1) ) {
331 $additions_node[] = $additions_n;
332 }
333 $additions->ar_node = $additions_node;
334 // echo_pre($additions,'node',true);
335 return $additions;
336 }
337
338 /**
339 * Implementation of hook_form().
340 *
341 * Now it's time to describe the form for collecting the information
342 * specific to this node type. This hook requires us to return an array with
343 * a sub array containing information for each element in the form.
344 */
345 function node_blaster_form(&$node) {
346
347 $node = (object) $node;
348 $layouts = node_blaster_layouts('page', TRUE);
349
350 $form['title'] = array('#type' => 'textfield',
351 '#title' => t('Name'),
352 '#required' => TRUE,
353 '#default_value' => $node->title,
354 '#weight' => -5
355 );
356
357 $form['body_filter']['body'] = array('#type' => 'textarea',
358 '#title' => t('Enter brief description'),
359 '#default_value' => $node->body,
360 '#required' => FALSE
361 );
362
363 $form['mail_theme'] = array('#type' => 'select', // '#required' => TRUE
364 '#title' => t('Use theme to control email MIME/HTML output? '),
365 '#default_value' => $node->mail_theme, '#options' => $layouts);
366
367 if ($node->nid) { // node section
368 $form['node_blaster_nodes'] = array(
369 '#type' => 'fieldset',
370 '#title' => t('Manage node blaster content'), // Manage node_blaster nodes
371 '#collapsible' => TRUE,
372 '#collapsed' => TRUE,
373 );
374
375 $form['node_blaster_nodes'][] = array('#value'=>'<div class="container-inline">');
376 $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
379 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"));
381
382 $node_lst = node_blaster_get_node();
383
384 if (db_num_rows($resultm) > 0 ) {
385
386 $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);
389
390 $tot_toshow = count( $node->ar_node ); // priority
391 if( $tot_toshow < 5 ) {
392 $tot_toshow = 5; // // default 5 and minimum 5
393 }
394
395 if($_POST['add_row'] == t('Add Row?') ) {
396 // increase by one
397 if( db_num_rows($resultm) > $tot_toshow ) { // check database has much or not
398 $tot_toshow++;
399 }
400 }
401
402 $to_disp = 0;
403
404 while ( $autn = db_fetch_object($resultm) ) {
405
406 if( $autn->nid && $autn->type != 'node_blaster' && $autn->title!='' ) {
407 $row = array();
408
409 if( $to_disp == $tot_toshow )
410 break; // display only selected
411 else
412 $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 $row[] = drupal_render($form['name']['node_'.$autn->nid]);
444 $row[] = drupal_render(process_weight($form1['series_' . $autn->nid])); // theme('weight', $form['series_' . $autn->nid]['weight']); not worked bad stuff
445 $row[] = drupal_render($form['day_sent']['day_sent_' . $autn->nid]);
446
447 $rows[] = $row;
448
449 }
450 } // end while
451 }else {
452 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
453 }
454
455 $header = array(t('Node Title'), t('# in Sequence'), t('Day'));
456 $table_content = theme('table', $header, $rows);
457
458 $form['node_blaster_nodes'][] = array('#value'=> $table_content.'<br>');
459
460
461 $form['node_blaster_nodes']['add_row'][] = array(
462 '#type' => 'button',
463 '#name'=> 'add_row',
464 '#value' => t("Add Row?"),
465 );
466
467 $form['node_blaster_nodes']['add_row'][] = array('#value'=> t('<b><i>Hitting this button will add a new row to the form.</i></b>') );
468
469 $form[] = array('#value'=>'<a name="managenodes"></a>');
470
471 // with input hiddeb for node_blaster id
472 $embed_code_to_paste = '<center><form method="post" action="[SUBMIT_URL]" name="subscribe_form" target="_self"><input type="hidden" name="aid" value="'.$node->nid.'"> <input type="hidden" name="redirect" value="[REDIRECT_URL]"> <table> <tr><td colspan=2><center></center></td></tr>
473 <tr><td>Name:</td><td><input type="text" name="name" value="" size="20"></td></tr>
474 <tr><td>Email:</td><td><input type="text" name="email" value="" size="20"></td></tr> <tr><td align="center" colspan="2"><input type="submit" name="subscribe" value="Submit"></td></tr></table></form></center>';
475
476
477 global $base_url;
478 $submit_url = $base_url.'/?q=node_blaster/subscribe/'.$node->nid; // node_blaster/subscribe/2
479 $pub_url = $base_url.'/?q=node/'.$node->nid;
480 if( $node->public_url == '') {
481 $node->public_url = $pub_url;
482 }
483 if( $node->redirect_url == '') {
484 $node->redirect_url = $base_url;
485 }
486
487 $embed_code_to_paste = str_replace("[SUBMIT_URL]", $submit_url, $embed_code_to_paste);
488 $embed_code_to_paste = str_replace("[REDIRECT_URL]", $node->redirect_url, $embed_code_to_paste);
489
490 // embed code section
491 $form['embed_code'] = array('#type' => 'fieldset', '#title' => t('<b>Create Embed Code</b>'));
492 //$form['embed_code'][] = array('#value'=>'<b>Create Embed Code</b><br><br>');
493 $form['embed_code'][] = array('#value'=>'What Page would you like subscribers to be redirected to?<br>');
494
495 $form['embed_code']['redirect_url'] = array('#type' => 'textfield',
496 '#value' => $node->redirect_url,
497 '#title' => t('Insert fully qualified URL here '),
498 '#default_value' => '',
499 );
500 $form['embed_code']['embed_code_update'] = array(
501 '#type' => 'submit', // button needed if not wanted to redirect
502 '#value' => t("Update Code"),
503 );
504
505 $form['embed_code']['embed_code_to_paste'] = array('#type' => 'textarea',
506 '#value' => $embed_code_to_paste,
507 // '#size' => 50,
508 '#title' => t('Copy code and place in your page'),
509 '#default_value'=> $embed_code_to_paste
510 );
511
512 // $form['embed_code'][] = array('#value'=>'</div>');
513
514 // URL of this list for public
515 $form['public_url'] = array('#type' => 'textfield',
516 '#value' => $node->public_url,
517 '#default_value'=> $pub_url,
518 '#title' => t('URL of this list for the public'),
519 );
520
521 $form['embed_code'][] = array('#value'=>'</div>');
522
523 } else {
524
525 }
526
527 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){
537
538 // print_r($form); // debug code here
539
540 // 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().
591 *
592 * As a new node is being inserted into the database, we need to do our own
593 * database inserts.
594 */
595 function node_blaster_insert($node) {
596
597 if( !$edit['aid'] ) {
598 $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 );
600 }
601 }
602
603 /**
604 * Implementation of hook_update().
605 *
606 * As an existing node is being updated in the database, we need to do our own
607 * database updates.
608 */
609 function node_blaster_update($node) {
610
611 // if this is a new node or we're adding a new revision,
612 if ($node->revision) {
613 node_blaster_insert($node);
614 }
615 else {
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);
618 db_query("DELETE from {node_blaster_node} where aid = %d ",$node->nid);
619
620 print_r($_POST);
621 exit;
622
623 // update node order
624 foreach ( $_POST as $key => $val ) {
625 // echo "<br>". $key. $val;
626 $nid = substr($key,5);
627 if( substr($key,0,4) == 'node' ) {
628 if( $_POST['series_'.$nid] != 0 || $_POST['day_sent_'.$nid] != 0 ) {
629 // check if seletced condition match for aid and nid --------- alternate delete all existing node and insert again
630 // db_query("select aid, nid from {node_blaster_node} where aid = '%d', nid = '%d' ", $edit['aid'], $nid );
631 //if ( is_Alreadyina() ) {
632 db_query("INSERT INTO {node_blaster_node} (aid, nid, series, day_sent) VALUES ('%d', '%d', '%d', '%d')", $node->nid, $_POST['node_'.$nid], $_POST['series_'.$nid], $_POST['day_sent_'.$nid] );
633 //}
634 }
635 }
636 }
637
638
639 if( isset($_POST['edit']['redirect_url']) ) {
640 db_query("update {node_blaster} set redirect_url = '%s' where nid = '%d'", $_POST['edit']['redirect_url'], $node->nid );
641 //drupal_set_message(t('Node blaster updated successfully'));
642 //drupal_set_message(t('The "%title" node blaster has been updated.', array('%title' => theme('placeholder', $edit['name']))));
643 } // end if
644 }// end else
645
646 }
647
648 /**
649 * Node_blaster layout selector
650 */
651 function node_blaster_layouts($context_selection=NULL, $include_default=FALSE) { // page, TRUE for form
652 static $layouts, $contexts;
653 if (!isset($layouts)) {
654 $layouts = array();
655 $files = file_scan_directory(drupal_get_path('module', 'node_blaster'), '^layout_.*\.inc$');
656 foreach ($files as $filename => $file) {
657 include_once($filename);
658 $layouts[drupal_substr($file->name, 7)] = $description;
659 if ($context) {
660 $contexts[$context][drupal_substr($file->name, 7)] = $description;
661 }
662 }
663 }
664 if ($context_selection) {
665 if ($include_default) {
666 if( is_array($contexts[$context_selection]) )
667 return array_merge(array(0 => t('<default>')), $contexts[$context_selection]);
668 else
669 return array(0 => t('<default>'));
670 } else {
671 return $contexts[$context_selection];
672 }
673 } else {
674 if ($include_default) {
675 if( is_array($layouts) )
676 return array_merge(array(0 => t('<default>')), $layouts);
677 else
678 return array(0 => t('<default>'));
679 } else {
680 return $layouts;
681 }
682 }
683 }
684
685 /**
686 * Implementation of hook_view().
687 *
688 * This is a typical implementation that simply runs the node text through
689 * the output filters.
690 */
691 function node_blaster_view($node, $teaser = FALSE, $page = FALSE) {
692 $node = node_prepare($node, $teaser);
693
694 $node->content['nblaster'] = array(
695 '#value' => theme('node_blaster_info', $node),
696 '#weight' => 1,
697 );
698
699 // debug code
700 // node_blaster_cron();
701
702 return $node;
703 }
704
705
706 /**
707 * Implementation of hook_cron().
708 * Send mail to all node_blaster subscriber
709 *
710 */
711 function node_blaster_cron() {
712 /* Algo to be used
713 for all node_blaster
714 get all node_blaster node order by day_sent -- distinct then for all distinct try
715 for all day find subscriber to whom send
716 send mail with that formt to selected subscriber */
717
718 $res = db_query("SELECT * FROM {node} WHERE type = 'node_blaster'");
719 while ($result = db_fetch_array($res)) {
720 $autor = node_load($result['nid']);
721 // echo_pre($autor,'node_blaster'); // debug code // $autor->ar_node
722
723 // get all distict date
724 $query1 = db_query('SELECT DISTINCT day_sent FROM {node_blaster_node} WHERE aid = %d order by day_sent asc ', $autor->nid);
725 while( $result1 = db_fetch_array($query1) ) {
726 $email = '';
727 // 1. prepare message to send this day
728 $message = get_node_blaster_node_to_send($autor->nid, $result1['day_sent'], $autor->mail_theme);
729
730 // 2. find all subscriber email
731 // add this day to subscriber created : today = subsc craeted + day sent
732 // --- find all subscriber for today-day sent and send mail
733
734 $today = time(); // day based make it not time based
735 $nextWeek = time() + (7 * 24 * 60 * 60); // date("m") date("d") date("Y")
736 $timets = $today - ( (int)$result1[day_sent] * 24 * 60 * 60 );
737 // echo $result1[day_sent];
738
739 $timets = date('Y-m-d', mktime(0, 0, 0, date("m") , (date("d")+1)-(int)$result1[day_sent], date("Y")));
740 // echo $timets."<br>";
741 $email = '';
742 $query2 = db_query("SELECT email, name FROM {node_blaster_subscriber} WHERE aid = %d and TO_DAYS(FROM_UNIXTIME(date)) = TO_DAYS('%s') order by date asc ", $autor->nid, $timets);
743 while( $result2 = db_fetch_array($query2) ) {
744
745 $name = $result2['name'];
746 $mail = $result2['email'];
747 $email .= "$mail,"; // append name html ************* "$name <$mail>,";
748 }
749 $email = substr($email,0,-1); // remove last comma
750 $header ='';
751 if( $email !='' ) {
752 // TODO make ...
753 drupal_mail('node_blaster',$email, $autor->title, $message);
754 echo $email;
755 // drupal_set_message('Node blaster executed successfully. Mail sent to '.$email);
756 }
757
758 } // end while for daysent 1, 2 ..
759
760 } // end while for each node_blaster
761
762 // cloud_update($site);
763 // 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);
766 }
767
768 /**
769 * Prepare theme to send node_blaster
770 */
771 function get_node_blaster_node_to_send($aid, $dayst, $mimeoutput='' ) {
772 // $result1['day_sent'] select all node of this day , arrange according to layout and send
773 $additions_node1 = db_query('SELECT nid, series, day_sent FROM {node_blaster_node} WHERE aid = %d and day_sent=%d order by series asc', $aid, $dayst);
774
775 $additions_node = array();
776 $output = '';
777 while( $additions_n = db_fetch_array($additions_node1) ) {
778 // $additions_node[] = $additions_n;
779 $to_send_node = node_load($additions_n['nid']);
780 $additions_node[] = $to_send_node;
781 $output .= $to_send_node->body;
782 }
783
784 // echo_pre($additions_node, 'All responder',true);
785
786 foreach( $additions_node as $detail) {
787 // $output .= $detail->body."<br><hr><br>";
788 }
789
790 return $output;
791 }
792
793
794 /**
795 * A custom theme function.
796 *
797 * By using this function to format our node-specific information, themes
798 * can override this presentation if they wish. We also wrap the default
799 * presentation in a CSS class that is prefixed by the module name. This
800 * way, style sheets can modify the output without requiring theme code.
801 */
802 function theme_node_blaster_info($node) {
803
804 $output = '<div class="node_blaster_info">';
805 $output .= t($node->title.' Subscription');
806 $output .= t('<br><br>Enter name and email to subscribe to this node blaster.');
807 // with input hiddeb for node_blaster id
808 $embed_code_to_paste = '<center><form method="post" action="[SUBMIT_URL]" name="subscribe_form" target="_self"><input type="hidden" name="aid" value="'.$node->nid.'"> <input type="hidden" name="redirect" value="[REDIRECT_URL]"> <table> <tr><td colspan=2><center></center></td></tr>
809 <tr><td>Name:</td><td><input type="text" name="name" value="" size="20"></td></tr>
810 <tr><td>Email:</td><td><input type="text" name="email" value="" size="20"></td></tr> <tr><td align="center" colspan="2"><input type="submit" name="subscribe" value="Submit"></td></tr></table></form></center>';
811
812
813 global $base_url;
814 $submit_url = $base_url.'/?q=node_blaster/subscribe/'.$node->nid; // node_blaster/subscribe/2
815
816 $embed_code_to_paste = str_replace("[SUBMIT_URL]", $submit_url, $embed_code_to_paste);
817 $embed_code_to_paste = str_replace("[REDIRECT_URL]", $node->redirect_url, $embed_code_to_paste);
818
819 $output .= $embed_code_to_paste;
820 $output .= '</div>';
821 return $output;
822 }
823
824 // Load all layouts.
825 node_blaster_layouts();

  ViewVC Help
Powered by ViewVC 1.1.2