--- /home/tmckeown/CVS/contributions/modules/listhandler/listhandler.module 2006-06-28 15:27:51.000000000 -0400 +++ /mnt/webserver/sandbox/modules/listhandler/listhandler.module 2006-06-30 15:08:14.000000000 -0400 @@ -180,8 +180,13 @@ function listhandler_nodeapi(&$node, $op * $edit["mid"]: id of mailbox * $edit["tid"]: taxo id of the forum */ -function listhandler_comment($type, $edit = array()) { - if($type == "insert") { // only accept calls by the comment insert hook. +function listhandler_comment($comment, $op){ + + //Added for compatability for with 4.7 + $edit = (array) $comment; + + if($op == "insert") { // only accept calls by the comment insert hook. + if($edit["sentbylisthandler"]) { // avoid running an infinite loop. // save comment ids in listhandler table. db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $edit["message_id"], $edit["nid"], $edit["cid"], $edit["pid"], $edit["uid"], $edit["mid"], $edit["tid"]); @@ -210,7 +215,7 @@ function listhandler_comment($type, $edi } function listhandler_send_mail($edit) { - global $user, $base_url; + global $user, $base_url, $db_type; if(!$user->uid) { $edit["name"] = variable_get("anonymous", "Anonymous"); @@ -223,28 +228,63 @@ function listhandler_send_mail($edit) { // Find the list to send to. $mboxen = array(); +/*SQL in this function uses regular expressions to find taxonomy term associated with forum */ + // taxo terms of the node. if (count($edit['taxonomy'])) { + + watchdog("listhandler", "Count edit tax true", WATCHDOG_NOTICE); + foreach ($edit['taxonomy'] as $taxoterm) { // Now for the mailbox. - $result2 = db_query("SELECT * FROM {mailhandler} m WHERE m.commands REGEXP '%s'", 'tid:[[:blank:]]*'. $taxoterm .'[[:>:]]'); - while ($mbox = db_fetch_object($result2)) { - $mboxen[] = array($mbox->mid, $mbox->mailto, $taxoarr->tid); + $sql_regex=''; + + switch($db_type){ + case "mysql": + $sql_regex = " REGEXP " . ' tid:[[:blank:]]*'. $taxoterm .'[[:>: +]]'; + break; + case "pgsql": + $sql_regex = " ~ " . "'tid:[[:blank:]]*" . $taxoterm ."[[:>:]]'"; + break; + } + + $result2 = db_query("SELECT * FROM {mailhandler} m WHERE m.commands " . $sql_regex); + + while ($mbox = db_fetch_object($result2)) { + $mboxen[] = array($mbox->mid, $mbox->mailto, $taxoterm); } } } else { $result = db_query("SELECT t.tid FROM {term_node} t WHERE t.nid = %d", $edit["nid"]); while ($taxoarr = db_fetch_object($result)) { + // Now for the mailbox. - $result2 = db_query("SELECT * FROM {mailhandler} m WHERE m.commands REGEXP '%s'", 'tid:[[:blank:]]*'. $taxoarr->tid .'[[:>:]]'); + + $sql_regex=''; + + switch($db_type){ + case "mysql": + $sql_regex = " REGEXP " . ' tid:[[:blank:]]*'. $taxoarr->tid .'[[:>: +]]'; + break; + case "pgsql": + $sql_regex = " ~ " . "'tid:[[:blank:]]*" . $taxoarr->tid ."[[:>:]]'"; + break; + } + $result2 = db_query("SELECT * FROM {mailhandler} m WHERE m.commands " . $sql_regex); + while ($mbox = db_fetch_object($result2)) { + + $mboxen[] = array($mbox->mid, $mbox->mailto, $taxoarr->tid); + } } } // Find parent's MsgID if received by listhandler. - if ($edit["pid"]){ + if ($edit["pid"] != 0){ // We should get only one or no result. $result = db_fetch_object(db_query("SELECT * FROM {listhandler} WHERE cid = %d", $edit['pid'])); } @@ -281,7 +321,8 @@ function listhandler_send_mail($edit) { $err = user_mail($address, $subject, $body, "From: ". $edit["name"] ." <". $edit["mail"] .">\n". $mid); // save comment ids in listhandler table. // Not strictly needed, the same info is stored in the msgid. - db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $msgid, $edit["nid"], $edit["cid"], $edit["pid"], $user->uid, $edit["mid"], $edit["tid"]); + + db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s',%d,%d,%d,%d,%d,%d)", $msgid, $edit["nid"], $edit["cid"], $edit["pid"], $user->uid, $edit["mid"], $edit["tid"]); // call watchdog watchdog('listhandler', t("'%s' sent to '%a'.", array("%s" => $edit["subject"], "%a" => $address))); } @@ -386,7 +427,7 @@ function listhandler_create_author($node // create account else { $empty_account = new StdClass(); - $from_user = user_save($empty_account, array('name' => $from_name, 'pass' => user_password(), 'init' => $from_address, 'mail' => $from_address, 'roles' => array(_user_authenticated_id()), 'status' => variable_get('listhandler_accountstatus', 0)), 'account'); + $from_user = user_save($empty_account, array('name' => $from_name, 'pass' => user_password(), 'init' => $from_address, 'mail' => $from_address, 'roles' => array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID), 'status' => variable_get('listhandler_accountstatus', 0)), 'account'); watchdog('listhandler', t('Created account for %fa, with roles %rid', array ('%fa' => $from_address, '%rid' => implode(', ', $from_user->roles)))); mailhandler_switch_user($from_user->uid); } @@ -445,4 +486,4 @@ function listhandler_new_thread($node) { return $node; } -?> \ No newline at end of file +?>