Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

223 lines (167 sloc) 4.61 kB
<?php
/**
* This module contains custom functionality for sites that I run.
*
* @author Douglas Muth <http://www.dmuth.org/>
*/
require_once("abuse.inc.php");
require_once("about.inc.php");
require_once("comment.inc.php");
require_once("cron.inc.php");
require_once("flag.inc.php");
require_once("menu.inc.php");
require_once("nodeapi.inc.php");
require_once("privatemsg.inc.php");
require_once("settings.inc.php");
require_once("spam.inc.php");
require_once("user.inc.php");
require_once("vars.inc.php");
//
// Our number of messages to keep.
// (Yeah, I know this shouldn't be a global variable.
// I'll make that be a setting I can configure in a future release...)
//
//$GLOBALS["ddt_num_messages"] = 5000;
$GLOBALS["ddt_num_messages"] = 10000;
/**
* Our boot hook, executed even on cached pages.
*/
function ddt_boot() {
$search_google = variable_get("ddt_search_google", false);
if ($search_google) {
$uri = request_uri();
if ($uri == "/search") {
ddt_goto("/search/google");
}
$regexp = "|^/search/node/(.*)|";
if (preg_match($regexp, $uri, $results)) {
$url = "/search/google/" . $results[1];
ddt_goto($url);
}
}
} // End of ddt_boot()
/**
* Our init hook.
*/
function ddt_init() {
//
// Various debugging statements for testing.
//
//print "In ddt_init()"; // Debugging
//ddt_log("test: !time", array("!time" => time()));
//ddt_log("test: !time", array("!time" => time()), WATCHDOG_WARNING);
//ddt_log("test: !time", array("!time" => time()), WATCHDOG_ERROR, l("test link", "http://test"));
//ddt_uninstall(); // Debugging
//ddt_install(); // Debugging
//ddt_cron(); // Debugging
} // End of ddt_init()
/**
* Our main settings page.
*
* @param string $arg, $arg2, $arg3 Optional page arguments
*
* @return string HTML code of the page
*/
function ddt_main($arg = "", $arg2 = "", $arg3 = "") {
$retval = "";
if ($arg == "abuse") {
$retval .= drupal_get_form("ddt_abuse_form");
} else if ($arg == "about") {
$retval .= ddt_about();
} else {
$retval .= drupal_get_form("ddt_settings_form");
}
return($retval);
} // End of ddt_settings()
/**
* Our own verison of drupal_goto(), since it's not available in hook_boot().
*
* @param string $url The URL/URI to go to.
*/
function ddt_goto($url) {
$url = "http://" . $_SERVER["HTTP_HOST"] . $url;
$header = "Location: $url";
$message = "Redirecting to '" . $url . "' ";
//ddt_debug($message); // Debugging
//ddt_log($message); // Doesn't seem to work in hook_boot()
header($header);
exit();
} // End of ddt_goto()
/**
* Log when this module is enabled.
*/
function ddt_enable() {
ddt_log("DDT Module enabled");
}
/**
* Log when this module is disabled.
*/
function ddt_disable() {
ddt_log("DDT Module disabled");
}
/**
* Our exit hook. It is called at the end of the page load.
*/
function ddt_exit() {
//
// No Message IDs? Stop here.
//
if (empty($GLOBALS["ddt"]["mid"])) {
return(null);
}
$mids = &$GLOBALS["ddt"]["mid"];
$var = array();
//
// At this point, log evidence of reading private messages.
// We do this here, since we'll have "read" all of the messages
// any given thread, and can log just the low and high MIDs,
// instead of writing a separate log entry for each MID.
//
if ($mids["high"] == $mids["low"]) {
//
// There was only a single message in the thread.
//
$message = t("Read private message. MID: %mid");
$var["%mid"] = $mids["low"];
} else {
//
// There were multiple messages in the thread.
//
$message = t("Read private messages. MIDS: %low-%high");
$var["%low"] = $mids["low"];
$var["%high"] = $mids["high"];
}
ddt_log($message, $var);
} // End of ddt_exit()
/**
* Our wrapper for watchdog()
*
* @param string $message The message, which will be passed to t().
* For substitution, using !string is probably the way to go.
*
* @param array $variables Array of variable substituions for t().
*
* @param string $severity Valid values are WATCHDOG_NOTICE,
* WATCHDOG_WARNING, and WATCHDOG_ERROR.
*
* @return void
*
*/
function ddt_log($message, $variables = array(),
$severity = WATCHDOG_NOTICE, $url = "") {
if ($severity == "") {
$severity = WATCHDOG_NOTICE;
}
watchdog("ddt", $message, $variables, $severity, $url);
} // End of ddt_log()
/**
* Our debugging function.
*
* @param mixed $message Can be a string or an array to print out.
*/
function ddt_debug($message) {
if (is_array($message) || gettype($message) == "object") {
$message = "<pre>" . print_r($message, true) . "</pre>";
}
drupal_set_message("DDT Debug: " . $message);
} // End of ddt_debug()
Jump to Line
Something went wrong with that request. Please try again.