Note: this list is kept only as a demonstration for CVSNotice. For the latest CVS notices, see the Xaraya and Postnuke sites
View Statistics - Next Notice - Previous NoticeDirectory filter : [ all ] / postnuke_official / html / includes [ view in CVS ]
Date | Directory [filter] | File(s) [view] | Author [filter] |
17 Aug 2002 00:26:15 | postnuke_official/html/includes | pnEvt.php,NONE,1.1 pnLog.php,NONE,1.1 | Marco Canini |
Event Messanging System |
Update of /home/cvsroot/postnuke_official/html/includes In directory ns7.hostnuke.net:/tmp/cvs-serv11571 Added Files: pnEvt.php pnLog.php Log Message: Event Messanging System Log Facilities I won't commit my modified version of pnAPI.php since I don't get this new installer working for them. So they're here just to let you have an overview of how things will work. --- NEW FILE: pnEvt.php --- <?php // File: $Id: pnEvt.php,v 1.1 2002/08/17 00:26:13 marco Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2001 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Marco Canini // Purpose of file: Event Messanging System // ---------------------------------------------------------------------- function pnEvtInit() { global $pnEvt_Subscribed; if (!is_array($pnEvt_Subscribed)) { $pnEvt_Subscribed = array(); } return true; } function pnEvt_notify($modname, $modtype, $event, $value) { pnLogMessage("pnEvt_notify: notifying event $event to $modname:$modtype"); pnModFunc($modname, $modtype, '_On'.$event, array('value'=>$value)); if (pnExceptionMajor() != PN_NO_EXCEPTION) { if (pnExceptionId() == 'MODULE_FUNCTION_NOT_EXIST') { pnExceptionFree(); } else { return; // throw back } } pnModFunc($modname, $modtype, '_OnEvent', array('event'=>$event, 'value'=>$value)); if (pnExceptionMajor() != PN_NO_EXCEPTION) { if (pnExceptionId() == 'MODULE_FUNCTION_NOT_EXIST') { pnExceptionFree(); } else { return; // throw back } } } function pnEvtFire($event, $value = NULL) { global $pnEvt_Subscribed; if (!isset($pnEvt_Subscribed[$event])) return; for ($i = 0; $i < count($pnEvt_Subscribed[$event]); $i++) { $callback = $pnEvt_Subscribed[$event][$i]; if (is_array($callback)) { list($modname, $modtype) = $callback; pnLogMessage("pnEvtFire: firing event $event to $modname:$modtype"); pnModFunc($modname, $modtype, '_On'.$event, array('value'=>$value)); if (pnExceptionMajor() != PN_NO_EXCEPTION) { if (pnExceptionId() == 'MODULE_FUNCTION_NOT_EXIST') { pnExceptionFree(); } else { return; // throw back } } pnModFunc($modname, $modtype, '_OnEvent', array('event'=>$event, 'value'=>$value)); if (pnExceptionMajor() != PN_NO_EXCEPTION) { return; // throw back } } else { // Raw callback if (function_exists($callback)) { $callback($value); } } } } function pnEvt_subscribeRawCallback($event, $callback) { global $pnEvt_Subscribed; if (!pnEvt_checkEvent($event)) { $msg = pnML('Unknown event.'); pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNKNOWN', new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); return; } $pnEvt_Subscribed[$event][] = $callback; } function pnEvtSubscribe($event, $modname, $modtype) { global $pnEvt_Subscribed; if (!pnEvt_checkEvent($event)) { $msg = pnML('Unknown event.'); pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNKNOWN', new SystemException(__FILE__.'('.__LINE__.'): '.$msg)); return; } $pnEvt_Subscribed[$event][] = array($modname, $modtype); } function pnEvtUnsubscribe($event, $modname, $modtype) { global $pnEvt_Subscribed; if (!isset($pnEvt_Subscribed[$event])) return; for ($i = 0; $i < count($pnEvt_Subscribed[$event]); $i++) { list($mn, $mt) = $pnEvt_Subscribed[$event][$i]; if ($modname == $mn && $modtype == $mt) { unset($pnEvt_Subscribed[$event][$i]); break; } } } function pnEvt_checkEvent($event) { switch ($event) { case 'LoadModule': case 'PostBodyStart': case 'PreBodyEnd': case 'MissingTranslationString': case 'MissingTranslationKey': case 'MissingTranslationContext': return true; } return false; } ?> --- NEW FILE: pnLog.php --- <?php // File: $Id: pnLog.php,v 1.1 2002/08/17 00:26:13 marco Exp $ // ---------------------------------------------------------------------- // PostNuke Content Management System // Copyright (C) 2001 by the PostNuke Development Team. // http://www.postnuke.com/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of file: Marco Canini // Purpose of file: Logging Facilities // ---------------------------------------------------------------------- // TODO: <marco> // When calendar & pnLocaleFormatDate is done complete simple logger // and html logger // When pnMail is done do email logger define('PNLOG_LEVEL_DEBUG', 1); define('PNLOG_LEVEL_NOTICE', 2); define('PNLOG_LEVEL_WARNING', 4); define('PNLOG_LEVEL_ERROR', 8); function pnLogInit() { global $pnLog_Logger, $pnLog_Level; $loggerName = pnConfigGetVar('Site.Logger'); $args = pnConfigGetVar('Site.Logger.Args'); // Yet an array switch ($loggerName) { case 'dummy': $pnLog_Logger = new pnLog_Logger($args); break; case 'simple': $pnLog_Logger = new pnLog_SimpleLogger($args); break; case 'html': $pnLog_Logger = new pnLog_HTMLLogger($args); break; case 'javascript': $pnLog_Logger = new pnLog_JavaScriptLogger($args); break; case 'email': $pnLog_Logger = new pnLog_EmailLogger($args); break; default: die('Unknown logger: '.$loggerName); } $pnLog_Level = pnConfigGetVar('Site.Logger.Level'); return true; } function pnLogGetLevel() { global $pnLog_Level; return $pnLog_Level; } // TODO: <marco> Move to logger module /* function logger_adminapi_getLogLevelInfo($level) { switch ($level) { case PNLOG_LEVEL_DEBUG: $name = pnML('Debug level'); $description = pnML('Logs everuthing.'); break; case PNLOG_LEVEL_NOTICE: $name = pnML('Notice level'); $description = pnML('Logs all except debugging messages.'); break; case PNLOG_LEVEL_WARNING: $name = pnML('Warning level'); $description = pnML('Logs only warning and errors.'); break; case PNLOG_LEVEL_ERROR: $name = pnML('Error level'); $description = pnML('Logs only errors.'); break; } return array('name'=>$name, 'description'=>$description); } */ // TODO: <marco> Move to logger module /* function logger_adminapi_listLoggers() { $dummy = array('id' => 'dummy', 'name' => 'Dummy logger', 'description' => pnML('Doesn\'t log anything.')); $simple = array('id' => 'simple', 'name' => 'Simple logger', 'description' => pnML('Logs in a file in plain text.')); $html = array('id' => 'html', 'name' => 'Html logger', 'description' => pnML('Logs in a file in html.')); $javascript = array('id' => 'javascript', 'name' => 'JavaScript logger', 'description' => pnML('Logs into a browser window (useful for debug).')); $email = array('id' => 'email', 'name' => 'Email logger', 'description' => pnML('Logs as plain text and send it as an email message.')); return array($dummy, $simple, $html, $javascript, $email); } */ /** * Converts a string in the form key1=value1;key2=value2 to an * array in the form ('key1'=>'value1', 'key2'=>'value2') */ function pnLog_parseArgsString($string) { $args = array(); $tmp = explode(';', $string); foreach($tmp as $param) { list($k, $v) = explode('=', $param); $k = trim($k); $v = trim($v); $args[$k] = $v; } return $args; } function pnLogMessage($msg, $level = PNLOG_LEVEL_DEBUG) { global $pnLog_Logger, $pnLog_Level, $pnDebug; if ($pnLog_Level > $level || ($level == PNLOG_LEVEL_DEBUG && ($pnDebug & PNDBG_ACTIVE) == 0)) return; $pnLog_Logger->logMessage($msg); } function pnLogException($level = PNLOG_LEVEL_DEBUG) { global $pnLog_Logger, $pnLog_Level, $pnDebug; if ($pnLog_Level > $level || ($level == PNLOG_LEVEL_DEBUG && ($pnDebug & PNDBG_ACTIVE) == 0)) return; $pnLog_Logger->logException(); } function pnLogVariable($name, $var, $level = PNLOG_LEVEL_DEBUG) { global $pnLog_Logger, $pnLog_Level, $pnDebug; if ($pnLog_Level > $level || ($level == PNLOG_LEVEL_DEBUG && ($pnDebug & PNDBG_ACTIVE) == 0)) return; $pnLog_Logger->logVariable($name, $var); } class pnLog_Logger { // private var $depth = 0; var $format = 'text'; function pnLog_Logger($args) { /* nothing do do */ } function logMessage($msg, $callPrepForDisplay = true) { /* nothing do do */ } function logException() { $msg = pnExceptionRender($this->format); $this->logMessage($msg, false); } function logVariable($name, $var) { $msg = $this->dumpVariable($var, $name); $this->logMessage($msg); } /** * @access protected */ function setFormat($format) { $this->format = $format; } /** * @access protected */ function formatLevel() { global $pnLog_Level; switch ($pnLog_Level) { case PNLOG_LEVEL_DEBUG: return 'DEBUG'; case PNLOG_LEVEL_NOTICE: return 'NOTICE'; case PNLOG_LEVEL_WARNING: return 'WARNING'; case PNLOG_LEVEL_ERROR: return 'ERROR'; } } /** * @access protected */ function getTimestamp() { // TODO: <marco> Use formatDate here return date('Y-m-d H:i:s'); } /** * @access protected */ function dumpVariable($var, $name = NULL, $classname = NULL) { if ($this->depth > 32) { return pnML('Recursive Depth Exceeded'); } if ($this->depth == 0) { $blank = ''; } else { $blank = str_repeat(' ', $this->depth); } $this->depth += 1; $TYPE_COLOR = "red"; $NAME_COLOR = "blue"; $VALUE_COLOR = "purple"; $str = ''; if (isset($name)) { if ($this->format == 'html') { $str = "<font color=\"$NAME_COLOR\">".$blank.'Variable name: <b>'. htmlspecialchars($name).'</b></font><br/>'; } else { $str = $blank."Variable name: $name\n"; } } $type = gettype($var); if (is_object($var)) { $str = $this->dumpVariable(get_object_vars($var), $name, get_class($var)); } elseif (is_array($var)) { if (isset($classname)) { $type = 'class'; } else { $type = 'array'; } if ($this->format == 'html') { $str .= "<font color=\"$TYPE_COLOR\">".$blank."Variable type: $type</font><br/>"; } else { $str .= $blank."Variable type: $type\n"; } if ($this->format == 'html') { $str .= '{<br/><ul>'; } else { $str .= $blank."{\n"; } foreach($var as $key => $val) { $str .= $this->dumpVariable($val, $key); } if ($this->format == 'html') { $str .= '</ul>}<br/><br/>'; } else { $str .= $blank."}\n\n"; } } else { if ($var === NULL) { $var = 'NULL'; } else if ($var === false) { $var = 'false'; } else if ($var === true) { $var = 'true'; } if ($this->format == 'html') { $str .= "<font color=\"$TYPE_COLOR\">".$blank."Variable type: $type</font><br/>"; $str .= "<font color=\"$VALUE_COLOR\">".$blank.'Variable value: "'. htmlspecialchars($var).'"</font><br/><br/>'; } else { $str .= $blank."Variable type: $type\n"; $str .= $blank."Variable value: \"$var\"\n\n"; } } $this->depth -= 1; return $str; } } // Implements a concrete logger, the most simple text based file logger. class pnLog_SimpleLogger extends pnLog_Logger { var $filename; function pnLog_SimpleLogger($args) { // TODO: <marco> Base filename & one log file per month or per week $this->filename = $args['filename']; } function logMessage($msg, $callPrepForDisplay = true) { if (!($fd = @fopen($this->filename, 'a'))) return; $ts = $this->getTimestamp(); $str = $ts . ' - '; $blanklen = strlen($str); $str .= '('.$this->formatLevel().') '; $str .= $this->formatString($msg, $blanklen); $str .= "\n"; fwrite($fd, $str); fclose($fd); } /** * @access protected */ function formatString($string, $blanklen) { $break = "\n".str_repeat(' ', $blanklen); $rows = explode("\n", $string); foreach($rows as $row) { $newrows[] = wordwrap($row, 79 - $blanklen, $break, 1); } return join($break, $newrows); } } class pnLog_HTMLLogger extends pnLog_Logger { var $filename; function pnLog_HTMLLogger($args) { // TODO: <marco> Base filename & one log file per month or per week $this->filename = $args['filename']; if (file_exists($this->filename) || !($fd = @fopen($this->filename, 'a'))) return; $str = "<html><head><title>PostNuke HTML Logger</title></head><body>"; fwrite($fd, $str); fclose($fd); } function logMessage($msg, $callPrepForDisplay = true) { if (!($fd = @fopen($this->filename, 'a'))) return; $str = $this->getTimestamp().' - ('.$this->formatLevel().')<br/>'; if ($callPrepForDisplay) { $msg = pnVarPrepForDisplay($msg); } $str .= nl2br($msg).'<br/>'; fwrite($fd, $str); fclose($fd); } } function pnLog_JavaScriptLogger_OnPostBodyStart($value) { // This function is called whenever the <body> tag has being sent to the browser global $pnLog_Logger; echo $pnLog_Logger->getWindowLoaderScript(); } function pnLog_JavaScriptLogger_OnPreBodyEnd($value) { // This function is called whenever the </body> tag is going to be sent to the browser global $pnLog_Logger; echo $pnLog_Logger->getBuffer(); } class pnLog_JavaScriptLogger extends pnLog_Logger { var $buffer = ''; function pnLog_JavaScriptLogger($args) { // Register proper callback functions at EMS pnEvt_subscribeRawCallback('PostBodyStart', 'pnLog_JavaScriptLogger_OnPostBodyStart'); pnEvt_subscribeRawCallback('PreBodyEnd', 'pnLog_JavaScriptLogger_OnPreBodyEnd'); // Set the HTML format $this->setFormat('html'); } function getWindowLoaderScript() { $header = "<table size=\\\"100%\\\" cellspacing=\\\"0\\\" cellpadding=\\\"0\\\" border=\\\"0\\\"><tr><td>". "<hr size=\\\"1\\\">PostNuke Javascript Logger</hr></td><td width=\\\"1%\\\"><font face=\\\"Verdana,arial\\\" size=\\\"1\\\">". date("Y-m-d H:i:s"). "</font></td></tr></table>"; $str = "<script language=\"javascript\">\n". "debugWindow = window.open(\"PostNuke Javascript Logger\",\"PostNuke Javascript Logger\",\"width=450,height=500,scrollbars=yes,resizable=yes\");\n". "if (debugWindow) {\n". " debugWindow.focus();\n". " debugWindow.document.write(\"".$header."\"+'<p><b>'+window.location.href+'</b></p>');\n". "}\n". "</script>\n"; return $str; } function getBuffer() { $str = "<script language=\"javascript\">\n". "if (debugWindow) {\n". $this->buffer. " debugWindow.scrollBy(0,100000);\n". "}\n". "</script>\n"; return $str; } function logMessage($msg, $callPrepForDisplay = true) { $str = " debugWindow.document.write(\"".$this->getTimestamp(). ' - ('.$this->formatLevel().')<br/>'; if ($callPrepForDisplay) { $msg = pnVarPrepForDisplay($msg); } $str .= nl2br(addslashes($msg))."<br/>\");\n"; $this->buffer .= $str; } } class pnLog_EmailLogger extends pnLog_Logger { function pnLog_EmailLogger($args) { die('TODO'); } function logMessage($msg, $callPrepForDisplay = true) { die('TODO'); } function logException() { die('TODO'); } function logVariable($name, $var) { die('TODO'); } } ?>
View Statistics - Next Notice - Previous Notice
Visit Developer Site - Browse CVS Repository |
Syndicate via backend.rss (max. once per hour please) | Powered by CVSNotice 0.1.3 |