*************** *** 1,14 **** "user/$user->uid/subscriptions", - 'title' => t('my subscriptions'), - 'callback' => 'subscriptions_page', - 'access' => user_access('maintain subscriptions'), - 'type' => MENU_LOCAL_TASK); - // My Subscriptios submenus if(module_exist('blog')){ $items[] = array('path' => "user/$user->uid/subscriptions/blogs", 'title' => t('blogs'), --- 226,237 ---- */ function subscriptions_menu($may_cache) { $items = array(); if ($may_cache) { if (variable_get('subscriptions_usersmenu', 0)){ + global $user; + $items[] = array('path' => "user/$user->uid/subscriptions", 'title' => t('my subscriptions'), + 'callback' => 'subscriptions_page', 'access' => user_access('maintain subscriptions'), + 'type' => MENU_LOCAL_TASK); // My Subscriptios submenus if(module_exist('blog')){ $items[] = array('path' => "user/$user->uid/subscriptions/blogs", 'title' => t('blogs'), *************** *** 387,393 **** /* * Get e-mail vars */ - function subscriptions_mailvars($sid, $ssid, $uid, $stype, $strsent, $cid = null) { global $base_url; global $locale; $initial_locale = $locale; --- 400,406 ---- /* * Get e-mail vars */ + function subscriptions_mailvars($sid, $ssid, $uid, $stype, $strsent) { global $base_url; global $locale; $initial_locale = $locale; *************** *** 403,420 **** $result = db_query('SELECT u.uid, u.name, u.mail, u.language FROM {users} u INNER JOIN {subscriptions} s ON u.uid = s.uid WHERE u.status= 1 AND s.sid = %d AND s.stype = \'node\'', $sid); $strtype = 'thread'; $nid = $sid; - $cid = $ssid; - $page = subscriptions_comment_page($ssid, $nid); - if ($page) { - $page = "&page=$page"; - } } // if content type, get vars - if ($stype == 'type') { $typestr = 'type'.$sid; $result = db_query('SELECT u.mail, u.name, u.uid, u.language FROM {users} u INNER JOIN {subscriptions} s ON u.uid = s.uid WHERE u.status= 1 AND s.stype =\''.$typestr.'\''); $strtype = 'content type'; $nid = $ssid; } // if node insert, test if node has a taxonomy else skip if ($stype == 'taxa' && !is_null($sid)) { --- 416,430 ---- $result = db_query('SELECT u.uid, u.name, u.mail, u.language FROM {users} u INNER JOIN {subscriptions} s ON u.uid = s.uid WHERE u.status= 1 AND s.sid = %d AND s.stype = \'node\'', $sid); $strtype = 'thread'; $nid = $sid; + $cid = "comment-$ssid"; } // if content type, get vars + if ($stype == 'type') { $typestr = 'type'.$sid; $result = db_query('SELECT u.mail, u.name, u.uid, u.language FROM {users} u INNER JOIN {subscriptions} s ON u.uid = s.uid WHERE u.status= 1 AND s.stype =\''.$typestr.'\''); $strtype = 'content type'; $nid = $ssid; + $cid = NULL; } // if node insert, test if node has a taxonomy else skip if ($stype == 'taxa' && !is_null($sid)) { *************** *** 554,560 **** // set teaser variable if($subuser->subscriptions_teaser){ // and set send filter appropriately - $teaser = (is_null($cid) ? $nobj->teaser : db_result(db_query('SELECT comment FROM {comments} WHERE cid = ' . $cid))); }else{ $teaser = ''; } --- 566,572 ---- // set teaser variable if($subuser->subscriptions_teaser){ // and set send filter appropriately + $teaser = $nobj->teaser; }else{ $teaser = ''; } *************** *** 566,581 **** $locale = $subscriptions->language; } $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; - $subject = t('[!site] !type subscription update for !name : !subject', array('!site' => variable_get('site_name', 'drupal'), '!type' => t($strtype), '!name' => $subscriptions->name, '!subject' => $subj)); - $body = t("Greetings, !name.\n\nA !type to which you have subscribed has been updated.\n!title\n!teaser\nTo view the thread, navigate to !url \n\n--\nThis is an automatic message from !site.\nTo manage your subscriptions, browse to !manage-url", - array('!name' => $subscriptions->name, - '!type' => t($strtype), - '!url' => url('node/'. $nid, $page? $page: null, (is_null($cid) ? NULL : "comment-$cid"), 1), - '!site' => t(variable_get('site_name', 'drupal')), - '!manage-url' => variable_get('subscriptions_usersmenu', 0) ? url("user/$subuid/subscriptions", NULL, NULL, 1) : url('subscriptions', NULL, NULL, 1), - '!title' => (is_null($cid) ? $nobj->title : $nobj->title . "\n\n" . db_result(db_query('SELECT subject FROM {comments} WHERE cid = ' . $cid)) ), - '!teaser'=> $teaser) - ); // revert to original locale $locale = $initial_locale; subscriptions_sendmail($subscriptions->name, $subscriptions->mail, $subject, $body, $headers); --- 578,609 ---- $locale = $subscriptions->language; } $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; + $setting_subject = variable_get('subscriptions_email_subject', ""); + $setting_body = variable_get('subscriptions_email_body', ""); + + // if a CCK type then get real name (i.e. "label") other wise just use the node->type + if (substr($nobj->type,0,8) == "content_") + $content_type = db_result(db_query("SELECT label FROM {node_type_content} WHERE type_name = '$nobj->type'")); + else $content_type = $nobj->type; + + $subject = t($setting_subject, array( + '%site' => variable_get('site_name', 'drupal'), + '%type' => $strtype, + '%content_type' => $content_type, + '%name' => $subscriptions->name, + '%title' => $nobj->title, + '%subject' => $subj)); + $body = t($setting_body, array( + '%name' => $subscriptions->name, + '%type' => t($strtype), + '%content_type' => $content_type, + '%url' => url('node/'. $nid, NULL, $cid, 1), + '%site' => t(variable_get('site_name', 'drupal')), + '%manage-url' => url('subscriptions', NULL, NULL, 1), + '%title' => $nobj->title, + '%teaser'=> $teaser, + '%full_node' => node_view(node_load($nobj->nid),false,true,false), + '%comment' => comment_render($sid, $ssid))); // revert to original locale $locale = $initial_locale; subscriptions_sendmail($subscriptions->name, $subscriptions->mail, $subject, $body, $headers); *************** *** 583,589 **** } return $strsent; } - /* * Subscribes users to nodes in which they post, if not already subscribed */ --- 611,616 ---- } return $strsent; } /* * Subscribes users to nodes in which they post, if not already subscribed */ *************** *** 610,651 **** $strsent = '!'; $onode = unserialize($heldnode); if ($onode->status) { - if (!empty($onode->taxonomy)) { - - // this handles free taging - if ($onode->taxonomy['tags']){ - $freetags = explode(", ", $onode->taxonomy['tags'][1]); - foreach($freetags as $tag) { - $tag_id = taxonomy_get_term_by_name($tag); - $thetags[$tag_id[0]->tid] = $tag_id[0]->tid; - } - unset($onode->taxonomy['tags']); - $onode->taxonomy[] = $thetags; - } - foreach ($onode->taxonomy as $terms){ - foreach ($terms as $tid){ - $strsent = $strsent . subscriptions_mailvars($tid, $onode->nid, $poster, 'taxa', $strsent); - } - } } - $strsent = $strsent . subscriptions_mailvars($onode->nid, 0, $poster, 'node', $strsent); - if ($node->type == 'blog') { $strsent = $strsent . subscriptions_mailvars($onode->uid, $onode->nid, $poster, 'blog', $strsent); } - } } - /** * handling for held comments */ function subscriptions_heldcomments($heldcomment, $poster){ $strsent = '!'; - $ocom = unserialize($heldcomment); subscriptions_mailvars($ocom['nid'], $ocom['cid'], $poster, 'node', $strsent); } - /** * store node changes for later handling */ --- 636,660 ---- $strsent = '!'; $onode = unserialize($heldnode); if ($onode->status) { + if (!empty($onode->taxonomy)) { + foreach ($onode->taxonomy as $tid){ + $strsent = $strsent . subscriptions_mailvars($tid, $onode->nid, $poster, 'taxa', $strsent); + } } $strsent = $strsent . subscriptions_mailvars($onode->nid, 0, $poster, 'node', $strsent); if ($node->type == 'blog') { $strsent = $strsent . subscriptions_mailvars($onode->uid, $onode->nid, $poster, 'blog', $strsent); } + } } /** * handling for held comments */ function subscriptions_heldcomments($heldcomment, $poster){ $strsent = '!'; + $ocom = unserialize($heldcomment); subscriptions_mailvars($ocom['nid'], $ocom['cid'], $poster, 'node', $strsent); } /** * store node changes for later handling */ *************** *** 694,719 **** if($proceed){ // do send if($row->ptype == 'comment'){ - $content = unserialize($row->content); - // we check the comment status and don't send or delete it - // if it hasn't been approved - $comment = db_fetch_array(db_query("SELECT * FROM comments WHERE cid = %d", $content['cid'])); - if ($comment['status'] != 1){ - subscriptions_heldcomments($row->content, $row->pid); - // delete processed row - db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); - } - } // row type == 'comment' - if($row->ptype == 'node'){ - subscriptions_heldnodes($row->content, $row->pid); - // delete processed row - db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); - } // row type == 'node' - }else{ - // do delete - db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); - } - } // for each row in results set } // if using cron to send notifications } --- 701,720 ---- if($proceed){ // do send if($row->ptype == 'comment'){ + subscriptions_heldcomments($row->content, $row->pid); + // delete processed row + db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); + } // row type == 'comment' + if($row->ptype == 'node'){ + subscriptions_heldnodes($row->content, $row->pid); + // delete processed row + db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); + } // row type == 'node' + }else{ + // do delete + db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid); + } + } // for each row in results set } // if using cron to send notifications } *************** *** 738,748 **** if ($op == 'insert' || ($op == 'update' && $comment->status == 1)) { // ignore deactivated comments // if use_cron is set, insert node actions into holding table if(variable_get('subscriptions_usecron', 0)){ - subscriptions_hold($comment, 'comment' , $op, $user->uid ); } else { // if cron is not used $cid = is_null($comment->cid) ? $comment['cid'] : $comment->cid; $nobj = node_load($nid); - if(!$nobj->status) return; // node is unpublished // send node subscriptions $strsent = $strsent . subscriptions_mailvars($nid, $cid, $user->uid, 'node', $strsent); // get subscription->node->taxonomy --- 739,748 ---- if ($op == 'insert' || ($op == 'update' && $comment->status == 1)) { // ignore deactivated comments // if use_cron is set, insert node actions into holding table if(variable_get('subscriptions_usecron', 0)){ + subscriptions_hold( $comment, 'comment' , $op, $user->uid ); } else { // if cron is not used $cid = is_null($comment->cid) ? $comment['cid'] : $comment->cid; $nobj = node_load($nid); // send node subscriptions $strsent = $strsent . subscriptions_mailvars($nid, $cid, $user->uid, 'node', $strsent); // get subscription->node->taxonomy *************** *** 750,830 **** // send to taxonomy subscribers if (!empty($taxa)) { foreach ($taxa as $tid){ - $strsent = $strsent . subscriptions_mailvars($tid, $nid, $user->uid, 'taxa', $strsent, $cid); } } // send content type subscriptions - $strsent = $strsent . subscriptions_mailvars($nobj->type, $nobj->nid, $user->uid, 'type', $strsent, $cid); } // end cron test subscriptions_autosubscribe($user->uid, $nid); } } - /** - * Return the page a comment is on - */ - function subscriptions_comment_page($cid, $nid) { - - $comments_per_page = _comment_get_display_setting('comments_per_page'); - - // load the comment - $comment = _comment_load($cid); - - if (user_access('administer comments')) { - // For users with 'administer comments' permission - // we have to count published and unpublished comments. - $comments_num = comment_num_all($nid, TRUE); - } - else { - $comments_num = isset($comment->comment_count) ? $comment->comment_count : comment_num_all($nid); - } - - if ($comments_num <= $comments_per_page) { - // one page of comments only - return 0; - } - else { - // Build the database query that retrieves the comment's position - // This follows the same sheme as in comment_render(). - // See comments there for an explanation. - $query = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d'; - $query_args = array($nid); - - if (!user_access('administer comments')) { - $query .= ' AND status = %d'; - $query_args[] = COMMENT_PUBLISHED; - } - - $mode = _comment_get_display_setting('mode'); - $order = _comment_get_display_setting('sort'); - if ($order == COMMENT_ORDER_NEWEST_FIRST) { - if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { - $query .= ' AND timestamp > %d'; - $query_args[] = $comment->timestamp; - } - else { - $query .= " AND thread > '%s'"; - $query_args[] = $comment->thread; - } - } - else if ($order == COMMENT_ORDER_OLDEST_FIRST) { - if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) { - $query .= ' AND timestamp < %d'; - $query_args[] = $comment->timestamp; - } - else { - $query .= " AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '%s'"; - $query_args[] = substr($comment->thread, 0, -1); - } - } - - $count = db_result(db_query($query, $query_args)); - return floor($count / $comments_per_page); - } - } - - - /** * Implementation of hook_nodeapi(). */ function subscriptions_nodeapi(&$node, $op, $arg = 0) { --- 750,765 ---- // send to taxonomy subscribers if (!empty($taxa)) { foreach ($taxa as $tid){ + $strsent = $strsent . subscriptions_mailvars($tid, $nid, $user->uid, 'taxa', $strsent); } } // send content type subscriptions + $strsent = $strsent . subscriptions_mailvars($nobj->type, $nobj->nid, $user->uid, 'type', $strsent); } // end cron test subscriptions_autosubscribe($user->uid, $nid); } } /** * Implementation of hook_nodeapi(). */ function subscriptions_nodeapi(&$node, $op, $arg = 0) { *************** *** 837,877 **** if($node->status == '1' && $node->subscriptions_currentstatus == '1'){break;} // else, fall through case 'insert': - if (variable_get('subscriptions_usecron', 0)) { - // using cron to send notifications - subscriptions_hold( $node, 'node' , $op, $user->uid ); - } - else { // sending notification on submission - if ($node->status) { - if (!empty($node->taxonomy)) { - $omitted_taxa = variable_get('subscriptions_omitted_taxa', array()); - foreach ($node->taxonomy as $tid){ - // send taxonomy subscriptions - if (!in_array($tid->vid, $omitted_taxa)) { - // send taxonomy subscriptions - $strsent = $strsent . subscriptions_mailvars($tid, $node->nid, $user->uid, 'taxa', $strsent); - } - } } - // send content type subscriptions - $strsent = $strsent . subscriptions_mailvars($node->type, $node->nid, $user->uid, 'type', $strsent); - // send node subscriptions - $strsent = $strsent . subscriptions_mailvars($node->nid, 0, $user->uid, 'node', $strsent); - if ($node->type == 'blog') { - // send blog subscriptions - $strsent = $strsent . subscriptions_mailvars($node->uid, $node->nid, $user->uid, 'blog', $strsent); - } } - } // cron test - subscriptions_autosubscribe($user->uid, $node->nid); - if (isset($node->subscriptions_subscribe)) { - if ($node->subscriptions_subscribe) { - subscriptions_add($node->nid, $user->uid, 'node'); } - $user = user_load(array("uid" => $user->uid)); - user_save($user, array('subscriptions_subscribe' => $node->subscriptions_subscribe)); } - break; } } /** --- 772,807 ---- if($node->status == '1' && $node->subscriptions_currentstatus == '1'){break;} // else, fall through case 'insert': + if (variable_get('subscriptions_usecron', 0)) { + // using cron to send notifications + subscriptions_hold( $node, 'node' , $op, $user->uid ); + } + else { // sending notification on submission + if ($node->status) { + if (!empty($node->taxonomy)) { + foreach ($node->taxonomy as $tid){ + // send taxonomy subscriptions + $strsent = $strsent . subscriptions_mailvars($tid, $node->nid, $user->uid, 'taxa', $strsent); } } + // send content type subscriptions + $strsent = $strsent . subscriptions_mailvars($node->type, $node->nid, $user->uid, 'type', $strsent); + // send node subscriptions + $strsent = $strsent . subscriptions_mailvars($node->nid, 0, $user->uid, 'node', $strsent); + if ($node->type == 'blog') { + // send blog subscriptions + $strsent = $strsent . subscriptions_mailvars($node->uid, $node->nid, $user->uid, 'blog', $strsent); } + subscriptions_autosubscribe($user->uid, $node->nid); } + } // cron test + if (isset($node->subscriptions_subscribe)) { + if ($node->subscriptions_subscribe) { + subscriptions_add($node->nid, $user->uid, 'node'); + } + user_save($user, array('subscriptions_subscribe' => $node->subscriptions_subscribe)); + } + break; } } /** *************** *** 887,893 **** '#type' => 'fieldset', '#title' => t('Subscriptions'), '#collapsible' => TRUE, - '#collapsed' => FALSE, '#weight' => 1, ); $allsubs = subscriptions_get_user(); --- 817,822 ---- '#type' => 'fieldset', '#title' => t('Subscriptions'), '#collapsible' => TRUE, '#weight' => 1, ); $allsubs = subscriptions_get_user(); *************** *** 1181,1190 **** /* * Pages where users add and delete their subscriptions to nodes */ - function subscriptions_page($uid = null) { - global $user; - - $subscribed = false; $uid = $user->uid; if (!arg(2)) { --- 1110,1117 ---- /* * Pages where users add and delete their subscriptions to nodes */ + function subscriptions_page() { + global $user; $subscribed = false; $uid = $user->uid; if (!arg(2)) { *************** *** 1339,1345 **** $message .= theme('xml_icon', url("subscriptions/feed")); drupal_add_link(array('rel' => 'alternate', 'type' => 'application/rss+xml', - 'title' => t("!name Subscriptions", array('!name' => $user->name)), 'href' => url('subscriptions/feed'))); return $message; break; --- 1266,1272 ---- $message .= theme('xml_icon', url("subscriptions/feed")); drupal_add_link(array('rel' => 'alternate', 'type' => 'application/rss+xml', + 'title' => t("%name Subscriptions", array('%name' => $user->name)), 'href' => url('subscriptions/feed'))); return $message; break; *************** *** 1366,1378 **** $cond[] = "tn.tid IN ($tids)"; } // content types link differently and will be excluded from this list - $sql = "SELECT n.nid, max( n.created ) AS nc FROM {node} n LEFT JOIN {term_node} tn ON n.nid=tn.nid WHERE n.status=1"; if ($cond) { - $sql.= " AND ( ". implode(' OR ', $cond). " )"; } $sql .= " GROUP BY n.nid ORDER BY nc DESC"; $result = db_query_range(db_rewrite_sql($sql), 0, variable_get('feed_default_items', 10)); - $channel['title'] = t("!name Subscriptions", array('!name' => $account->name)); $channel['link'] = url("subscriptions/feed", NULL, NULL, TRUE); // $channel['description'] = ; node_feed($result, $channel); --- 1293,1305 ---- $cond[] = "tn.tid IN ($tids)"; } // content types link differently and will be excluded from this list + $sql = "SELECT n.nid, max( n.created ) AS nc FROM {node} n LEFT JOIN {term_node} tn ON n.nid=tn.nid"; if ($cond) { + $sql.= " WHERE ". implode(' OR ', $cond); } $sql .= " GROUP BY n.nid ORDER BY nc DESC"; $result = db_query_range(db_rewrite_sql($sql), 0, variable_get('feed_default_items', 10)); + $channel['title'] = t("%name Subscriptions", array('%name' => $account->name)); $channel['link'] = url("subscriptions/feed", NULL, NULL, TRUE); // $channel['description'] = ; node_feed($result, $channel);