From: <be...@us...> - 2013-02-27 04:31:27
|
Revision: 11112 http://sourceforge.net/p/xoops/svn/11112 Author: beckmi Date: 2013-02-27 04:31:18 +0000 (Wed, 27 Feb 2013) Log Message: ----------- Adding Userlog from Irmtfan Added Paths: ----------- XoopsModules/userlog/ XoopsModules/userlog/branches/ XoopsModules/userlog/releases/ XoopsModules/userlog/trunk/ XoopsModules/userlog/trunk/userlog/ XoopsModules/userlog/trunk/userlog/admin/ XoopsModules/userlog/trunk/userlog/admin/about.php XoopsModules/userlog/trunk/userlog/admin/admin_header.php XoopsModules/userlog/trunk/userlog/admin/index.html XoopsModules/userlog/trunk/userlog/admin/index.php XoopsModules/userlog/trunk/userlog/admin/logs.php XoopsModules/userlog/trunk/userlog/admin/menu.php XoopsModules/userlog/trunk/userlog/admin/setting.php XoopsModules/userlog/trunk/userlog/blocks/ XoopsModules/userlog/trunk/userlog/blocks/index.html XoopsModules/userlog/trunk/userlog/blocks/views.php XoopsModules/userlog/trunk/userlog/class/ XoopsModules/userlog/trunk/userlog/class/index.html XoopsModules/userlog/trunk/userlog/class/log.php XoopsModules/userlog/trunk/userlog/class/request.php XoopsModules/userlog/trunk/userlog/class/setting.php XoopsModules/userlog/trunk/userlog/class/stats.php XoopsModules/userlog/trunk/userlog/class/userlog.php XoopsModules/userlog/trunk/userlog/docs/ XoopsModules/userlog/trunk/userlog/docs/changelog.txt XoopsModules/userlog/trunk/userlog/docs/index.html XoopsModules/userlog/trunk/userlog/docs/readme.txt XoopsModules/userlog/trunk/userlog/images/ XoopsModules/userlog/trunk/userlog/images/index.html XoopsModules/userlog/trunk/userlog/images/userlog_logo.png XoopsModules/userlog/trunk/userlog/include/ XoopsModules/userlog/trunk/userlog/include/common.php XoopsModules/userlog/trunk/userlog/include/index.html XoopsModules/userlog/trunk/userlog/include/log.php XoopsModules/userlog/trunk/userlog/include/module.php XoopsModules/userlog/trunk/userlog/index.html XoopsModules/userlog/trunk/userlog/language/ XoopsModules/userlog/trunk/userlog/language/english/ XoopsModules/userlog/trunk/userlog/language/english/admin.php XoopsModules/userlog/trunk/userlog/language/english/blocks.php XoopsModules/userlog/trunk/userlog/language/english/help/ XoopsModules/userlog/trunk/userlog/language/english/help/help.html XoopsModules/userlog/trunk/userlog/language/english/help/index.html XoopsModules/userlog/trunk/userlog/language/english/index.html XoopsModules/userlog/trunk/userlog/language/english/modinfo.php XoopsModules/userlog/trunk/userlog/language/index.html XoopsModules/userlog/trunk/userlog/preloads/ XoopsModules/userlog/trunk/userlog/preloads/core.php XoopsModules/userlog/trunk/userlog/preloads/index.html XoopsModules/userlog/trunk/userlog/sql/ XoopsModules/userlog/trunk/userlog/sql/index.html XoopsModules/userlog/trunk/userlog/sql/mysql.sql XoopsModules/userlog/trunk/userlog/templates/ XoopsModules/userlog/trunk/userlog/templates/blocks/ XoopsModules/userlog/trunk/userlog/templates/blocks/index.html XoopsModules/userlog/trunk/userlog/templates/blocks/userlog_views.html XoopsModules/userlog/trunk/userlog/templates/index.html XoopsModules/userlog/trunk/userlog/templates/userlog_admin_logs.html XoopsModules/userlog/trunk/userlog/templates/userlog_admin_sets.html XoopsModules/userlog/trunk/userlog/xoops_version.php Added: XoopsModules/userlog/trunk/userlog/admin/about.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/about.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/about.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,32 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: about.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +include_once dirname(__FILE__) . '/admin_header.php'; + +xoops_cp_header(); + +$aboutAdmin = new ModuleAdmin(); + +echo $aboutAdmin->addNavigation('about.php'); +echo $aboutAdmin->renderabout('6KJ7RW5DR3VTJ', false); + +xoops_cp_footer(); \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/admin_header.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/admin_header.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/admin_header.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,32 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: admin_header.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +include_once dirname(dirname(dirname(dirname(__FILE__)))) . '/mainfile.php'; +include_once dirname(dirname(__FILE__)) . '/include/common.php'; +include_once XOOPS_ROOT_PATH . '/include/cp_header.php'; +xoops_load('XoopsFormLoader'); +xoops_loadLanguage('modinfo', USERLOG_DIRNAME); +if ( file_exists($GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'))){ + include_once $GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'); +}else{ + echo xoops_error('/Frameworks/moduleclasses/moduleadmin/ is required!!!'); +} \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/index.html =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/index.html (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/index.html 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/index.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/index.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/index.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,64 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: index.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +include_once dirname(__FILE__) . '/admin_header.php'; + +xoops_cp_header(); + +$indexAdmin = new ModuleAdmin(); + +$Userlog = Userlog::getInstance(false); + +// update all time stats +$statsObj = UserlogStats::getInstance(); +$statsObj->updateAll("log", 100); // prob = 100 +$statsObj->updateAll("set", 100); // prob = 100 +$statsObj->updateAll("file", 100); // prob = 100 + +$stats = $statsObj->getAll(); +// if nothing in database - start with a setting! +if (empty($stats)) { + $indexAdmin->addItemButton(_AM_USERLOG_SET_ADD,"setting.php"); +} else { + $indexAdmin->addInfoBox(_AM_USERLOG_STATS_ABSTRACT); + $periods = array_flip($statsObj->_period); + $types = $statsObj->_type; + foreach($stats as $type=>$arr) { + if(strlen($type) > 10) continue; + foreach($arr as $period=>$arr2) { + // use sprintf in moduleadmin: sprintf($text, "<span style='color : " . $color . "; font-weight : bold;'>" . $value . "</span>") + $indexAdmin->addInfoBoxLine(_AM_USERLOG_STATS_ABSTRACT, + sprintf(_AM_USERLOG_STATS_TYPE_PERIOD, "%s\1", $types[$type], constant("_AM_USERLOG_" . strtoupper($periods[$period]))), + $arr2["value"] ); + } + } + $indexAdmin->addInfoBox(_AM_USERLOG_SUMMARY); + $indexAdmin->addInfoBoxLine(_AM_USERLOG_SUMMARY,'<a href="logs.php?options[referer]=del&options[request_method]=POST">' . _AM_USERLOG_SUMMARY_DELETED . '</a>'); + $indexAdmin->addInfoBoxLine(_AM_USERLOG_SUMMARY,'<a href="logs.php?options[admin]=1">' . _AM_USERLOG_SUMMARY_ADMIN . '</a>'); + $indexAdmin->addInfoBoxLine(_AM_USERLOG_SUMMARY,'<a href="logs.php?options[referer]=google.com">' . _AM_USERLOG_SUMMARY_GOOGLE . '</a>'); +} +$indexAdmin->addConfigBoxLine($Userlog->getConfig('logfilepath') .'/'. USERLOG_DIRNAME , 'folder'); +echo $indexAdmin->addNavigation('index.php'); +echo $indexAdmin->renderButton(); +echo $indexAdmin->renderIndex(); + +xoops_cp_footer(); \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/logs.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/logs.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/logs.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,163 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: logs.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +include_once dirname(__FILE__) . '/admin_header.php'; +include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; +xoops_cp_header(); + +$Userlog = Userlog::getInstance(false); +// Where do we start ? +$startentry = UserlogRequest::getInt('startentry',0); +$limitentry = UserlogRequest::getInt('limitentry',$Userlog->getConfig("logs_perpage")); +$sortentry = UserlogRequest::getString('sortentry','log_id'); +$orderentry = UserlogRequest::getString('orderentry','DESC'); + +$options = UserlogRequest::getArray("options"); +$logsetObj = UserlogSetting::getInstance(); +// get var types int, text, bool , ... +$type_vars = $logsetObj->getOptions("", "type"); +//$query_types = array("="=>"",">"=>"GT", "<"=>"LT"); +$criteria = new CriteriaCompo(); +//$criteria->add(new Criteria(1, 1)); +foreach($options as $key=>$val) { + // if user input an empty variable unset it + if (empty($val)) { + unset($options[$key]); + continue; + } + // deal with greater than and lower than + $tt = substr($key, -2); + switch ($tt) { + case "GT": + $op = substr($key,0, -2); + $t = ">"; + break; + case "LT": + $op = substr($key,0, -2); + $t = "<"; + break; + default: + $op = $key; + $t = "="; + break; + } + $criteria_q[$key] = new CriteriaCompo(); + $val_arr = explode(",", $val); + $query_array[$key] = "options[{$key}]={$val}"; + // if type is text + if ($type_vars[$op] == "text") { + foreach($val_arr as $qry) { + // if !QUERY eg: !logs.php,views.php + if (substr($qry,0,1) == "!") { + $criteria_q[$key]->add(new Criteria($op, "%" . substr($qry,1) . "%", "NOT LIKE"), "OR"); + } else { + $criteria_q[$key]->add(new Criteria($op, "%" . $qry . "%", "LIKE"), "OR"); + } + } + } else { + // if there is one value - deal with =, > ,< + if (count($val_arr) == 1) { + $val_int = $val_arr[0]; + if($op == "log_time" || $op == "last_login") $val_int = time() - $Userlog->getSinceTime($val_int); + // query is one int $t (=, < , >) + $criteria_q[$key]->add(new Criteria($op, $val_int, $t)); + } else { + // query is an array of int separate with comma. use OR ??? + $criteria_q[$key]->add(new Criteria($op, "(" . $val . ")", "IN")); + } + } + // save vars + $vars[$key] = $val; + // add criteria + $criteria->add($criteria_q[$key]); +} +$logs = $Userlog->getHandler('log')->getLogs($limitentry,$startentry,$criteria,$sortentry,$orderentry ,null, false); +$totalLogs = $Userlog->getHandler('log')->getLogsCount($criteria); + +// pagenav +$pagenav = new XoopsPageNav($totalLogs, $limitentry, $startentry, 'startentry'); +if ( !empty($pagenav) ) { + $GLOBALS['xoopsTpl']->assign("pagenav",$pagenav->renderNav()); +} + +$GLOBALS['xoopsTpl']->assign('options', $options); +$GLOBALS['xoopsTpl']->assign('totalLogs', $totalLogs); +$GLOBALS['xoopsTpl']->assign('pages', ceil($totalLogs/$limitentry)); +$GLOBALS['xoopsTpl']->assign('status', sprintf(_AM_USERLOG_LOG_STATUS,$totalLogs)); + +$GLOBALS['xoopsTpl']->assign('startentry', $startentry); +$GLOBALS['xoopsTpl']->assign('limitentry', $limitentry); +$GLOBALS['xoopsTpl']->assign('sortentry', $sortentry); +$GLOBALS['xoopsTpl']->assign('orderentry', $orderentry); + +$skips = array("get", "post", "request", "files", "env"); +// only times should be changed before assign to template +foreach($logs as $log_id=>$log) { + $logs[$log_id]["log_time"] = $Userlog->formatTime($logs[$log_id]["log_time"]); + $logs[$log_id]["last_login"] = $Userlog->formatTime($logs[$log_id]["last_login"]); + // merge all request_method to one column + if (!empty($logs[$log_id]["request_method"])) { + $logs[$log_id]["request_method"] = $logs[$log_id]["request_method"] . $logs[$log_id][strtolower($logs[$log_id]["request_method"])]; + } + foreach($skips as $option) { + unset($logs[$log_id][$option]); + } +} +// assign logs +$GLOBALS['xoopsTpl']->assign('logs', $logs); +if ( !empty($query_array) ) { + $GLOBALS['xoopsTpl']->assign('query_page', implode("&", array_values($query_array))); +} +$GLOBALS['xoopsTpl']->assign('types', $type_vars); + +// form +list($form, $headers) =$logsetObj->logForm($options); + +$limitEl = new XoopsFormText(_AM_USERLOG_LOGS_PERPAGE, "limitentry", 10, 255, $limitentry); +$limitEl->setDescription(sprintf(_AM_USERLOG_LOGS_PERPAGE_DSC, $Userlog->getConfig("logs_perpage"))); +$sortEl = new XoopsFormSelect(_AM_USERLOG_SORT,"sortentry", $sortentry); +$sortEl->addOptionArray($headers); +$sortEl->setDescription(_AM_USERLOG_SORT_DSC); +$orderEl = new XoopsFormSelect(_AM_USERLOG_ORDER,"orderentry", $orderentry); +$orderEl->addOption("DESC", _DESCENDING); +$orderEl->addOption("ASC", _ASCENDING); +$orderEl->setDescription(_AM_USERLOG_ORDER_DSC); + +$submitEl = new XoopsFormButton(_SUBMIT, 'submit', _SUBMIT, 'submit'); + +$form->addElement($limitEl); +$form->addElement($sortEl); +$form->addElement($orderEl); +$form->addElement($submitEl); +$GLOBALS['xoopsTpl']->assign('form', $form->render()); + +//headers +foreach($skips as $option) { + unset($headers[$option]); +} +$GLOBALS['xoopsTpl']->assign('headers', $headers); +$template_main = "userlog_admin_logs.html"; +if ( !empty($template_main) ) { + $GLOBALS['xoopsTpl']->display("db:{$template_main}"); +} + +xoops_cp_footer(); \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/menu.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/menu.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/menu.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,52 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: menu.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined"); + +$dirname = basename(dirname(dirname(__FILE__))); +$module_handler = xoops_gethandler('module'); +$module = $module_handler->getByDirname($dirname); +$pathIcon32 = $module->getInfo('icons32'); + +xoops_loadLanguage('admin', $dirname); + +$i = 0; + +// Index +$adminmenu[$i]['title'] = _AM_USERLOG_ADMENU_INDEX; +$adminmenu[$i]['link'] = "admin/index.php"; +$adminmenu[$i]["icon"] = '../../' . $pathIcon32 . '/home.png'; +$i++; + +$adminmenu[$i]['title'] = _AM_USERLOG_ADMENU_SETTING; +$adminmenu[$i]['link'] = "admin/setting.php"; +$adminmenu[$i]["icon"] = '../../' . $pathIcon32 . '/compfile.png'; + +$i++; +$adminmenu[$i]['title'] = _AM_USERLOG_ADMENU_LOGS; +$adminmenu[$i]['link'] = "admin/logs.php"; +$adminmenu[$i]["icon"] = '../../' . $pathIcon32 . '/content.png'; + +$i++; +$adminmenu[$i]['title'] = _AM_USERLOG_ABOUT; +$adminmenu[$i]['link'] = "admin/about.php"; +$adminmenu[$i]["icon"] = '../../' . $pathIcon32 . '/about.png'; \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/admin/setting.php =================================================================== --- XoopsModules/userlog/trunk/userlog/admin/setting.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/admin/setting.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,218 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog admin + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: setting.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +include_once dirname(__FILE__) . '/admin_header.php'; +include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; + +xoops_cp_header(); + +$Userlog = Userlog::getInstance(false); +$op = UserlogRequest::getString('op'); +// Where do we start ? +$set_id = UserlogRequest::getInt('set_id',0); +$logsetObj = $set_id ? $Userlog->getHandler('setting')->get($set_id) : UserlogSetting::getInstance(); +if ($set_id && !is_object($logsetObj)) { + redirect_header("setting.php", 1, _AM_USERLOG_SET_ERROR); +} +$name = UserlogRequest::getString('name',"","post"); +$logby = UserlogRequest::getString('logby',"","post"); +if ($logby == "ip") { + $unique_id = UserlogRequest::getString('unique_id',-1,"post"); + $unique_id = ip2long($unique_id); +} else { + $unique_id = UserlogRequest::getInt('unique_id',-1,"post"); +} +$option = UserlogRequest::getArray('option',"","post"); + +$scope = UserlogRequest::getArray('scope',"","post"); + +$startentry = UserlogRequest::getInt('startentry',0); + +switch ($op) { + case "del": + if (empty($set_id)) { + redirect_header("setting.php", 1, _AM_USERLOG_SET_ERROR); + } + $confirm = UserlogRequest::getString('confirm',0,"post"); + if ($confirm) { + if (!$Userlog->getHandler('setting')->delete($logsetObj)) { + redirect_header("setting.php", 1, sprintf(_AM_USERLOG_SET_DELETE_ERROR, $logsetObj->name())); + exit(); + } + redirect_header("setting.php", 1, sprintf(_AM_USERLOG_SET_DELETE_SUCCESS, $logsetObj->name())); + exit(); + } else { + xoops_confirm(array('op' => 'del', 'set_id' => $logsetObj->set_id(), 'confirm' => 1), 'setting.php', sprintf(_AM_USERLOG_SET_DELETE_CONFIRM, $logsetObj->name()), _DELETE); + xoops_cp_footer(); + } + break; + + case "addsetting": + $message = _AM_USERLOG_SET_EDIT; + // check to insure only one (logby and unique_id) added to database + if(!$set_id) { + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('logby', $logby)); + $criteria->add(new Criteria('unique_id', $unique_id)); + $logsetObj = $Userlog->getHandler('setting')->getObjects($criteria); + if ($logsetObj) { + $logsetObj = $logsetObj[0]; + $message = _AM_USERLOG_SET_UPDATE; + } elseif ($logby != "") { + $logsetObj = $Userlog->getHandler('setting')->create(); + $message = _AM_USERLOG_SET_CREATE; + } else { + redirect_header("setting.php", 1, _AM_USERLOG_SET_ERROR); + } + } + $logsetObj->setVar("name",$name); + $logsetObj->setVar("logby",$logby); + $logsetObj->setVar("unique_id",$unique_id); + // select views means store uid, groups, script name, pagetitle, module, item name, item id in Database + if (in_array("views",$option)) { + $option = array_merge(array("uid", "groups", "script","pagetitle","module","item_name","item_id"),$option); + } + // always log id and time + if(!empty($option[0])) { + $option = array_merge(array("log_id", "log_time"),$option); + } + $options_arr = $logsetObj->getOptions($option,"key");// empty means all. sanitize options + $logsetObj->setVar("options",implode(",",$options_arr)); + $logsetObj->setVar("scope",implode(",",$scope)); + $logsetObj->cleanCache(); // delete all settings caches + $logsetObj->set(true); + redirect_header("setting.php", 1, sprintf($message, $logsetObj->name())); + break; + case "cancel": + redirect_header("setting.php", 1, _AM_USERLOG_SET_CANCEL); + exit(); + + case "default": + default: + // get all dirnames for scope + $module_handler =& xoops_gethandler('module'); + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('isactive', 1)); + $modules = $module_handler->getObjects($criteria, true); // id_as_key = true, asobject = false + foreach($modules as $module) { + $dirNames[$module->dirname()] = $module->name(); + } + // unset userlog + //unset($dirNames[USERLOG_DIRNAME]); + // get all settings as array + $sets = $Userlog->getHandler('setting')->getSets($Userlog->getConfig("sets_perpage"),$startentry,null,'set_id', 'DESC', null, false); + $totalSets = $Userlog->getHandler('setting')->getCount(); + $pagenav = new XoopsPageNav($totalSets, $Userlog->getConfig("sets_perpage"), $startentry, 'startentry'); + // check set arrays + foreach($sets as $id=>$set) { + // ip to string + if ($set["logby"] == "ip") { + $sets[$id]["unique_id"]= long2ip($set["unique_id"]); + } + // logby to title + $sets[$id]["logby"] = $logsetObj->all_logby[$set["logby"]]; + + // options to title + $options = $logsetObj->getOptions($set["options"],"title"); + $sets[$id]["options"]= implode(",", $options); + + // modules to name + if (empty($set["scope"])) { + $sets[$id]["scope"] = _ALL; // no scope means all + continue; + } + $scope = explode(",", $set["scope"]); + $dir_str =""; + foreach($scope as $sc) { + $dir_str .= "," . $dirNames[$sc]; + } + $sets[$id]["scope"] = $dir_str; + } + $template_main = "userlog_admin_sets.html"; + // form + $form = new XoopsThemeForm($set_id ? _EDIT . " " . $logsetObj->name() : _AM_USERLOG_SET_ADD,'setting','setting.php?op=addsetting', 'post'); + if ($set_id) { // if in edit mode add a button + $indexAdmin = new ModuleAdmin(); + $indexAdmin->addItemButton(_AM_USERLOG_SET_ADD,"setting.php"); + } + $nameEle = new XoopsFormText(_AM_USERLOG_SET_NAME,"name",10,20, $logsetObj->name()); + $nameEle->setDescription(_AM_USERLOG_SET_NAME_DSC); + + $logbyEle = new XoopsFormSelect(_AM_USERLOG_SET_LOGBY,"logby", $logsetObj->logby()); + $logbyEle->addOptionArray($logsetObj->all_logby); + $logbyEle->setDescription(_AM_USERLOG_SET_LOGBY_DSC); + + $unique_idEle = new XoopsFormText(_AM_USERLOG_SET_UNIQUE_ID,"unique_id",10,20, $logsetObj->unique_id()); + $unique_idEle->setDescription(_AM_USERLOG_SET_UNIQUE_ID_DSC); + + $options_arr = explode(",",$logsetObj->options()); + $optionEle = new XoopsFormCheckBox(_AM_USERLOG_SET_OPTIONS,"option[]",$options_arr); + $optionEle->columns = 4; + $headers = $logsetObj->getOptions("","title"); + // always log id and time + unset($headers["log_id"], $headers["log_time"]); + $optionEle->addOptionArray($headers); + //$optionEle->isRequired(); + //$optionEle->renderValidationJS(); + $check_all = _ALL . ": <input type=\"checkbox\" name=\"option_check\" id=\"option_check\" value=\"0\" onclick=\"xoopsCheckGroup('setting', 'option_check','option[]');\" />"; + //$optiontrayEle = new XoopsFormElementTray(_AM_USERLOG_SET_OPTIONS, "<br\>", 'tray'); + $optionEle = new XoopsFormLabel(_AM_USERLOG_SET_OPTIONS, $check_all ."<br\>". $optionEle->render()); + $optionEle->setDescription(_AM_USERLOG_SET_OPTIONS_DSC); + + $scope_arr = explode(",",$logsetObj->scope()); + $scopeEle = new XoopsFormCheckBox(_AM_USERLOG_SET_SCOPE,"scope[]",$scope_arr); + $scopeEle->columns = 4; + $scopeEle->addOptionArray($dirNames); + $check_all = _ALL . ": <input type=\"checkbox\" name=\"scope_check\" id=\"scope_check\" value=\"1\" onclick=\"xoopsCheckGroup('setting', 'scope_check','scope[]');\" />"; + $scopeEle = new XoopsFormLabel(_AM_USERLOG_SET_SCOPE, $check_all ."<br\>". $scopeEle->render()); + $scopeEle->setDescription(_AM_USERLOG_SET_SCOPE_DSC); + + $submitEle = new XoopsFormButton('', 'post', _SUBMIT, 'submit'); + $set_idEle = new XoopsFormHidden('set_id',$set_id); + + $form->addElement($nameEle, true); + $form->addElement($logbyEle); + $form->addElement($unique_idEle, true); + $form->addElement($optionEle); + $form->addElement($scopeEle); + $form->addElement($set_idEle); + $form->addElement($submitEle); + + break; +} +if ( !empty($form) ) { + $GLOBALS['xoopsTpl']->assign("form",$form->render()); +} +if ( !empty($sets) ) { + //add set arrays to template + $GLOBALS['xoopsTpl']->assign('sets', $sets); +} +if ( !empty($pagenav) ) { + $GLOBALS['xoopsTpl']->assign("pagenav",$pagenav->renderNav()); +} +if ( !empty($indexAdmin) ) { + $GLOBALS['xoopsTpl']->assign("addset",$indexAdmin->renderButton("left")); +} +if ( !empty($template_main) ) { + $GLOBALS['xoopsTpl']->display("db:{$template_main}"); +} +xoops_cp_footer(); \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/blocks/index.html =================================================================== --- XoopsModules/userlog/trunk/userlog/blocks/index.html (rev 0) +++ XoopsModules/userlog/trunk/userlog/blocks/index.html 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/blocks/views.php =================================================================== --- XoopsModules/userlog/trunk/userlog/blocks/views.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/blocks/views.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,257 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog blocks + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: views.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +defined('XOOPS_ROOT_PATH') or die('Restricted access'); +include_once dirname(dirname(__FILE__)) . '/include/common.php'; + +if (defined('USERLOG_BLOCK_VIEWS_DEFINED')) return; +define('USERLOG_BLOCK_VIEWS_DEFINED',true); +xoops_loadLanguage("admin",USERLOG_DIRNAME); + +// options[0] - number of logs to proceed. use a high number. 0 = no limit and get all. default 2000 +// options[1] - items to select in Where claus +// options[2] - Time period - default 1 day +// options[3] - Uid in WHERE claus: select some users to only count views by them 0-all (by default) +// options[4] - Gid in WHERE claus: select some groups to only count views by them 0-all (by default) +// options[5] - Sort - module, views + +function userlog_views_show($options) +{ + $Userlog = Userlog::getInstance(); + + if (!empty($options[1])) { + $options_views = explode(',', $options[1]); // item views in where claus eg: news-storyid, newbb-topic_id, news-storytopic + $module=array(); + foreach ($options_views as $key=>$item) { + $module_item = explode('-', $item); // news-storyid news-storytopic => $module["news"]=array("storyid","storytopic"); + if (!isset($module[$module_item[0]])) { + $module[$module_item[0]] = array(); + } + $module[$module_item[0]][] = $module_item[1]; + } + $criteriaModule = new CriteriaCompo(); + foreach ($module as $module_dir=>$items) { + $criteriaItem = new CriteriaCompo(); + $criteriaItem->add(new Criteria('module', $module_dir)); + $criteriaItemName = new CriteriaCompo(); + foreach($items as $item_name) { + // why we cannot use this $criteriaItemName->add(new Criteria('item_name', $items, "IN")); + $criteriaItemName->add(new Criteria('item_name', $item_name), "OR"); + } + $criteriaItem->add($criteriaItemName); + $criteriaModule->add($criteriaItem, "OR"); + unset($criteriaItem,$criteriaItemName); + } + } + + if (!empty($options[2])) { + $starttime = time() - $Userlog->getSinceTime($options[2]); + $criteriaSince = new CriteriaCompo(); + $criteriaSince->add(new Criteria('log_time', $starttime ,'>')); + } + + if (!empty($options[3])) { + $criteriaUser = new CriteriaCompo(); + $criteriaUser->add(new Criteria('uid', '(' . $options[3] . ')', 'IN')); + } + if (!empty($options[4])) { + $criteriaGroup = new CriteriaCompo(); + $options_groups = explode(',', $options[4]); // groups to select + foreach($options_groups as $group) { + $criteriaGroup->add(new Criteria("groups", "%g" . $group . "%", "LIKE"), "OR"); + } + } + + // add all criterias + $criteria = new CriteriaCompo(); + if ( !empty($criteriaModule) ) { + $criteria->add($criteriaModule); + } + if ( !empty($criteriaSince) ) { + $criteria->add($criteriaSince); + } + if ( !empty($criteriaUser) ) { + $criteria->add($criteriaUser); + } + if ( !empty($criteriaGroup) ) { + $criteria->add($criteriaGroup); + } + + $loglogsObj = $Userlog->getHandler('log')->getLogs($options[0], 0, $criteria); + // initializing + $items = array(); // very important!!! + $items["views"] = 0; + $sort_views = array(); + foreach($loglogsObj as $loglogObj) { + // assign needed vars + $module_dirname = $loglogObj->module(); + $script_name = $loglogObj->script(); + $item_name = $loglogObj->item_name(); + $item_id = $loglogObj->item_id(); + // increment total, module, script, item_name, item views + // $items = array("newbb"=> array("viewtopic.php"=>array("topic_id"=>array([1]=>array("views"=> 23, + // "title"=>"topic title" + // ), + // [23]=>array("views"=> 234, + // "title"=>"my test topic" + // ), + // "views"=> 51, // topic_id views + // ),// end of topic_id + // "post_id"=>array([234512]=>array("views"=> 4, + // "title"=>"Re: topic title" + // ), + // [123] =>array("views"=> 121, + // "title"=>"post title" + // ), + // "views"=> 23, // post_id views + // ),// end of post_id + // "views"=> 124, // viewtopic.php views + // ), // end of viewtopic.php + // "index.php" =>array("forum"=>array([3]=>array("views"=> 5, + // "title"=>"Forum test" + // ), + // ), //end of forum + // "views"=> 14, // index.php views + // ), // end of index.php + // "views"=> 123, // newbb views + // ), // end of newbb + // "news"=>array("article.php"=>array("storyid"=>array([234]=>array("views"=> 12, + // "title"=>"news title" + // ), + // ),// end of storyid + // ), // end of article.php + // "views"=> 43, // news views + // ), // end of news + // "views"=>2424, // total views + // ); // end of array + $items["views"]++; + if (!isset($items[$module_dirname])) { + $items[$module_dirname] = array(); + $items[$module_dirname]["views"] = 0; + } + $items[$module_dirname]["views"]++; + if (!isset($items[$module_dirname][$script_name])) { + $items[$module_dirname][$script_name] = array(); + $items[$module_dirname][$script_name]["views"] = 0; + } + $items[$module_dirname][$script_name]["views"]++; + if (!isset($items[$module_dirname][$script_name][$item_name])) { + $items[$module_dirname][$script_name][$item_name] = array(); + $items[$module_dirname][$script_name][$item_name]["views"] = 0; + } + $items[$module_dirname][$script_name][$item_name]["views"]++; + if (!isset($items[$module_dirname][$script_name][$item_name][$item_id])) { + $items[$module_dirname][$script_name][$item_name][$item_id] = array(); + $items[$module_dirname][$script_name][$item_name][$item_id]["views"] = 0; + } + $items[$module_dirname][$script_name][$item_name][$item_id]["views"]++; + $link = $module_dirname."/".$script_name."?".$item_name."=".$item_id; + if (!isset($sort_views[$link])) { + $sort_views[$link] = array(); + $sort_views[$link]["views"] = 0; + } + $sort_views[$link]["views"]++; + // get the title of the item only once if the pagetitle is not empty. + if (empty($items[$module_dirname][$script_name][$item_name][$item_id]["title"]) && $loglogObj->pagetitle() != '') { + $items[$module_dirname][$script_name][$item_name][$item_id]["title"] = $loglogObj->pagetitle(); + $sort_views[$link]["title"] = $loglogObj->pagetitle(); + } + } + $block = array(); + arsort($sort_views); + $block["items"]= $items; + $block["sort_views"] = $sort_views; + $block["sort_type"] = $options[5]; + + return $block; +} + +function userlog_views_edit($options) +{ + // include_once XOOPS_ROOT_PATH . "/class/blockform.php"; //reserve for 2.6 + xoops_load('XoopsFormLoader'); + // $form = new XoopsBlockForm(); //reserve for 2.6 + $form = new XoopsThemeForm(_AM_USERLOG_VIEW,'views',''); + + $module_handler =& xoops_gethandler('module'); + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('hasnotification', 1)); + $criteria->add(new Criteria('isactive', 1)); + $modules = $module_handler->getObjects($criteria, true); + foreach ($modules as $module) { + $not_config = $module->getInfo('notification'); + foreach ($not_config['category'] as $category) { + if (!empty($category['item_name'])) { + $script = is_array($category["subscribe_from"]) ? implode("|", $category["subscribe_from"]) : $category["subscribe_from"]; + $hasviews[$module->dirname()."-".$category['item_name']] = $module->dirname()."/" . $script ."?".$category['item_name']."=ITEM_ID"; + } + } + } + $i=0; + // number of logs to display element + $numdispEle = new XoopsFormText(_MB_USERLOG_BLOCK_LOG_LIMIT, "options[{$i}]", 10, 255, intval($options[$i])); + + $i++; + // views element + $options_views = explode(',', $options[$i]); + $viewsEle = new XoopsFormCheckBox(_MB_USERLOG_BLOCK_ITEMS, "options[{$i}][]", $options_views); + $viewsEle->columns = 3; + $viewsEle->addOptionArray($hasviews); + $viewsEle->setDescription(_MB_USERLOG_BLOCK_ITEMS_DSC); + + $i++; + $timeEle = new XoopsFormText(_MB_USERLOG_BLOCK_TIME, "options[{$i}]", 10, 255, $options[$i]); + $timeEle->setDescription(_MB_USERLOG_BLOCK_TIME_DSC); + + $i++; + // topic_poster element + $userRadioEle = new XoopsFormRadio(_AM_USERLOG_UID, "options[{$i}]", !empty($options[$i])); + $userRadioEle->addOption(0,_ALL); + $userRadioEle->addOption(!empty($options[$i]) ? $options[$i] : 1,_SELECT); // if no user in selection box it select uid=1 + $userRadioEle->setExtra("onchange=\"var el=document.getElementById('options[{$i}]'); el.disabled=(this.id == 'options[{$i}]1'); if (!el.value) {el.value= this.value}\""); // if user dont select any option it select "all" + $userSelectEle = new XoopsFormSelectUser(_AM_USERLOG_UID, "options[{$i}]", false, explode(',', $options[$i]), 3, true); + $userEle = new XoopsFormLabel(_AM_USERLOG_UID, $userRadioEle->render().$userSelectEle->render()); + + $i++; + // topic_poster element + $groupRadioEle = new XoopsFormRadio(_AM_USERLOG_GROUPS, "options[{$i}]", !empty($options[$i])); + $groupRadioEle->addOption(0,_ALL); + $groupRadioEle->addOption(!empty($options[$i]) ? $options[$i] : 1,_SELECT); // if no group in selection box it select uid=1 + $groupRadioEle->setExtra("onchange=\"var el=document.getElementById('options[{$i}]'); el.disabled=(this.id == 'options[{$i}]1'); if (!el.value) {el.value= this.value}\""); // if group dont select any option it select "all" + $groupSelectEle = new XoopsFormSelectGroup(_AM_USERLOG_GROUPS, "options[{$i}]", true, explode(',', $options[$i]), 3, true); + $groupEle = new XoopsFormLabel(_AM_USERLOG_GROUPS, $groupRadioEle->render().$groupSelectEle->render()); + + $i++; + $sortEle = new XoopsFormSelect(_AM_USERLOG_SORT, "options[{$i}]", $options[$i]); + $sortEle->addOptionArray(array("module"=>_AM_USERLOG_MODULE,"views"=>_AM_USERLOG_VIEW)); + $sortEle->setDescription(_AM_USERLOG_SORT_DSC); + + // add all elements to form + $form->addElement($numdispEle); + $form->addElement($viewsEle); + $form->addElement($timeEle); + $form->addElement($userEle); + $form->addElement($groupEle); + $form->addElement($sortEle); + + return $form->render(); +} \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/class/index.html =================================================================== --- XoopsModules/userlog/trunk/userlog/class/index.html (rev 0) +++ XoopsModules/userlog/trunk/userlog/class/index.html 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1 @@ + <script>history.go(-1);</script> \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/class/log.php =================================================================== --- XoopsModules/userlog/trunk/userlog/class/log.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/class/log.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,282 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. +*/ +/** + * userlog module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package userlog class + * @since 1 + * @author irmtfan (ir...@ya...) + * @author The XOOPS Project <www.xoops.org> <www.xoops.ir> + * @version $Id: log.php 1 2013-02-26 16:25:04Z irmtfan $ + */ + +defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined"); +include_once dirname(dirname(__FILE__)) . '/include/common.php'; + +class UserlogLog extends XoopsObject +{ + /** + * @var string + */ + public $userlog = null; + + var $_store = 0; // store: 0,1->db 2->file 3->both + + /** + * constructor + */ + public function __construct() + { + $this->userlog = Userlog::getInstance(); + $this->initVar("log_id", XOBJ_DTYPE_INT, null, false); + $this->initVar("log_time", XOBJ_DTYPE_INT, null, true); + $this->initVar("uid", XOBJ_DTYPE_INT, null, false); + $this->initVar("uname", XOBJ_DTYPE_TXTBOX, null, false, 50); + $this->initVar("admin", XOBJ_DTYPE_INT, null, false); + $this->initVar("groups", XOBJ_DTYPE_TXTBOX, null, false, 100); + $this->initVar("last_login", XOBJ_DTYPE_INT, null, true); + $this->initVar("user_ip", XOBJ_DTYPE_TXTBOX, null, true, 15); + $this->initVar("user_agent", XOBJ_DTYPE_TXTBOX, null, true, 255); + $this->initVar("url", XOBJ_DTYPE_TXTBOX, null, true, 255); + $this->initVar("script", XOBJ_DTYPE_TXTBOX, null, true, 50); + $this->initVar("referer", XOBJ_DTYPE_TXTBOX, null, true, 255); + $this->initVar("pagetitle", XOBJ_DTYPE_TXTBOX, null, false, 255); + $this->initVar("module", XOBJ_DTYPE_TXTBOX, null, true, 10); + $this->initVar("item_name", XOBJ_DTYPE_TXTBOX, null, false, 10); + $this->initVar("item_id", XOBJ_DTYPE_INT, null, false); + $this->initVar("request_method", XOBJ_DTYPE_TXTBOX, null, false, 20); + $this->initVar("get", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("post", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("request", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("files", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("env", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("session", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("cookie", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("header", XOBJ_DTYPE_TXTAREA, '', false); + $this->initVar("logger", XOBJ_DTYPE_TXTAREA, '', false); + } + /** + * @param string $method + * @param array $args + * + * @return mixed + */ + public function __call($method, $args) + { + $arg = isset($args[0]) ? $args[0] : null; + return $this->getVar($method, $arg); + } + + static function &getInstance() + { + static $instance = false; + if (!$instance) { + $instance = new UserlogLog(); + } + return $instance; + } + public function log_time() + { + return $this->userlog->formatTime($this->getVar('log_time')); + } + + public function last_login() + { + return $this->userlog->formatTime($this->getVar('last_login')); + } + + public function getViews($criteria = null) + { + } + + public function store($tolog, $force = true) + { + if ($this->_store > 1) $this->storeFile($tolog); // store file + if ($this->_store == 2) return true; // do not store db + $this->storeDb($tolog, $force); + } + + public function storeDb($tolog, $force = true) + { + // set vars + foreach ($tolog as $option=>$logvalue) { + // value array to string + if (is_array($logvalue)) $logvalue = $this->logString($logvalue); + if(!empty($logvalue)) { + $this->setVar($option, $logvalue); + } + } + $ret = $this->userlog->getHandler('Log')->insert($this, $force); + $this->unsetNew(); + return $ret; + } + + public function storeFile($tolog) + { + $logext = "log"; + $log_file_name = $this->userlog->getConfig('logfilepath') .'/'. USERLOG_DIRNAME . '/' . $this->userlog->getConfig('logfilename'); + $log_file = $log_file_name.".".$logext; + + if (filesize($log_file) > $this->userlog->getConfig('maxlogfilesize')) { + $old_file = $log_file_name."_".date('Y-m-d_H-i-s').".".$logext; + if(!$result=rename($log_file, $old_file)) { + $this->setErrors('ERROR renaming ({$log_file_name})'); + return false; + } + } + $data = "\nlog_id|" . /*$this->log_id()*/ "0" .$this->logString($tolog); + if ($this->item_name() !== null ) { + $data .= "\$item_name|" . $this->item_name() . "\$item_id|". $this->item_id(); // views save to file; + } + // file create/open/write + $fileHandler = XoopsFile::getHandler(); + // force to create file if not exist + if ($fileHandler->XoopsFileHandler($log_file, false) == false) { + if(!$fileHandler->exists()) { + $fileHandler->XoopsFileHandler($log_file, true); // create file + $this->setErrors('File was not exist create file ({$log_file_name})'); + // update the new file in database + $statsObj = UserlogStats::getInstance(); + $statsObj->update("file", 0, 0, false, $log_file); // value = 0 to not auto increment + // update old file if exist + if(!empty($old_file)) { + $statsObj->update("file", 0, 0, false, $old_file); // value = 0 to not auto increment + } + $statsObj->updateAll("file", 100); // prob = 100 + } + } + if ($fileHandler->open("a") == false) { + $this->setErrors('Cannot open file ({$log_file_name})'); + return false; + } + if ($fileHandler->write($data) == false) { + $this->setErrors('Cannot write to file ({$log_file_name})'); + return false; + } + $fileHandler->close(); + return true; + } + public function getFromFile($log_file = null) + { + if (!$log_file) { + $logext = "log"; + $log_file_name = $this->userlog->getConfig('logfilepath') .'/'. USERLOG_DIRNAME . '/' . $this->userlog->getConfig('logfilename'); + $log_file = $log_file_name.".".$logext; + } + // file create/open/write + $fileHandler = XoopsFile::getHandler(); + // not create file if not exist + if ($fileHandler->XoopsFileHandler($log_file, false) == false) { + $this->setErrors('Cannot create file ({$log_file_name})'); + return false; + } + if (($data = $fileHandler->read()) == false) { + $this->setErrors('Cannot read file ({$log_file_name})'); + return false; + } + return $data; + } + + // use ; because it will never used in other methods + public function logString($data, $startDelimiter="\$" , $endDelimiter="" ) + { + static $depth = 0; + $delimiters = array("<", ">","{","}","[[","]]"); + $ret = ""; + foreach ($data as $method=>$value) + { + if(!empty($value)) { + $ret .= $startDelimiter . "{$method}"; + if (!$depth) { // if it is the first level + $ret .= "|"; + } else { + $ret .= ":"; + } + if (is_array($value)) { + $depth = $depth+2; + $ret .= self::logString($value,$delimiters[$depth],$delimiters[$depth+1]); + } else { + $depth = 0; + $ret .="{$value}"; + } + $ret .= $endDelimiter; + } + } + return $ret; + } + + public function setItem() + { + $not_config =& $this->userlog->getLogModule()->getInfo('notification'); + if (!empty($not_config)) { + foreach ($not_config['category'] as $category) { + // if $item_id != 0 ---> return true + if (!empty($category['item_name']) && $item_id = UserlogRequest::getInt($category['item_name'], 0)){ + $this->setVar('item_name', $category['item_name']); + $this->setVar('item_id', $item_id); + return true; + } + } + } + return false; + } + +} + +class UserlogLogHandler extends XoopsPersistableObjectHandler +{ + public $userlog = null; + + /** + * @param null|object $db + */ + public function __construct(&$db) + { + $this->userlog = Userlog::getInstance(); + parent::__construct($db, "mod_userlog_log", 'UserlogLog', "log_id", "log_time"); + } + + public function getLogs($limit = 0, $start = 0, $otherCriteria = null, $sort = 'log_id', $order = 'DESC', $fields = null, $asObject = true, $id_as_key = true) + { + $criteria = new CriteriaCompo(); + if (!empty($otherCriteria)) { + $criteria->add($otherCriteria); + } + $criteria->setLimit($limit); + $criteria->setStart($start); + $criteria->setSort($sort); + $criteria->setOrder($order); + $ret = $this->getAll($criteria, $fields, $asObject, $id_as_key); + return $ret; + } + + public function getLogsCount($otherCriteria = null,$notNullFields = '') + { + $criteria = new CriteriaCompo(); + if (!empty($otherCriteria)) { + $criteria->add($otherCriteria); + } + return $this->getCount($criteria, $notNullFields); + } + + public function &get($id) + { + static $logs; + if (isset($logs[$id])) { + return $logs[$id]; + } + $obj = parent::get($id); + $logs[$id] = $obj; + return $obj; + } +} \ No newline at end of file Added: XoopsModules/userlog/trunk/userlog/class/request.php =================================================================== --- XoopsModules/userlog/trunk/userlog/class/request.php (rev 0) +++ XoopsModules/userlog/trunk/userlog/class/request.php 2013-02-27 04:31:18 UTC (rev 11112) @@ -0,0 +1,940 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + 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. + */ +/** + * Userlog class + * + * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. + * @license GNU/GPL, see LICENSE.php + * Joomla! is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * See COPYRIGHT.php for copyright notices and details. + * @package Userlog + * @since 1.0 + * @author trabis <lus...@gm...> + * @version $Id: request.php 10374 2012-12-12 23:39:48Z trabis $ + */ + +/** + * Set the available masks for cleaning variables + */ +define('Userlog_REQUEST_NOTRIM', 1); +define('Userlog_REQUEST_ALLOWRAW', 2); +define('Userlog_REQUEST_ALLOWHTML', 4); + +/** + * UserlogRequest Class + * This class serves to provide a common interface to access + * request variables. This includes $_POST, $_GET, and naturally $_REQUEST. Variables + * can be passed through an input filter to avoid injection or returned raw. + */ +class UserlogRequest +{ + + /** + * Gets the request method + * + * @return string + */ + static function getOptions() + { + $method = strtoupper($_SERVER['REQUEST_METHOD']); + return $method; + } + + /** + * Fetches and returns a given variable. + * The default behaviour is fetching variables depending on the + * current request method: GET and HEAD will result in returning + * an entry from $_GET, POST and PUT will result in returning an + * entry from $_POST. + * You can force the source by setting the $hash parameter: + * post $_POST + * get $_GET + * files $_FILES + * cookie $_COOKIE + * env $_ENV + * server $_SERVER + * method via current $_SERVER['REQUEST_METHOD'] + * default $_REQUEST + * + * @static + * + * @param string $name Variable name + * @param string $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * @param string $type Return type for the variable, for valid values see {@link JFilterInput::clean()} + * @param int $mask Filter mask for the variable + * + * @return mixed Requested variable + */ + static function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0) + { + // Ensure hash and type are uppercase + $hash = strtoupper($hash); + if ($hash === 'METHOD') { + $hash = strtoupper($_SERVER['REQUEST_METHOD']); + } + $type = strtoupper($type); + // Get the input hash + switch ($hash) { + case 'GET' : + $input = & $_GET; + break; + case 'POST' : + $input = & $_POST; + break; + case 'FILES' : + $input = & $_FILES; + break; + case 'COOKIE' : + $input = & $_COOKIE; + break; + case 'ENV' : + $input = & $_ENV; + break; + case 'SERVER' : + $input = & $_SERVER; + break; + default: + $input = & $_REQUEST; + $hash = 'REQUEST'; + break; + } + if (isset($input[$name]) && $input[$name] !== null) { + // Get the variable from the input hash and clean it + $var = UserlogRequest::_cleanVar($input[$name], $mask, $type); + // Handle magic quotes compatability + if (get_magic_quotes_gpc() && ($var != $default) && ($hash != 'FILES')) { + $var = UserlogRequest::_stripSlashesRecursive($var); + } + } else if ($default !== null) { + // Clean the default value + $var = UserlogRequest::_cleanVar($default, $mask, $type); + } else { + $var = $default; + } + return $var; + } + + /** + * Fetches and returns a given filtered variable. The integer + * filter will allow only digits to be returned. This is currently + * only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param int $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * + * @return integer Requested variable + */ + static function getInt($name, $default = 0, $hash = 'default') + { + return UserlogRequest::getVar($name, $default, $hash, 'int'); + } + + /** + * Fetches and returns a given filtered variable. The float + * filter only allows digits and periods. This is currently + * only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param float $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * + * @return float Requested variable + */ + static function getFloat($name, $default = 0.0, $hash = 'default') + { + return UserlogRequest::getVar($name, $default, $hash, 'float'); + } + + /** + * Fetches and returns a given filtered variable. The bool + * filter will only return true/false bool values. This is + * currently only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param bool $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * + * @return bool Requested variable + */ + static function getBool($name, $default = false, $hash = 'default') + { + return UserlogRequest::getVar($name, $default, $hash, 'bool'); + } + + /** + * Fetches and returns a given filtered variable. The word + * filter only allows the characters [A-Za-z_]. This is currently + * only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param string $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * + * @return string Requested variable + */ + static function getWord($name, $default = '', $hash = 'default') + { + return UserlogRequest::getVar($name, $default, $hash, 'word'); + } + + /** + * Fetches and returns a given filtered variable. The cmd + * filter only allows the characters [A-Za-z0-9.-_]. This is + * currently only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param string $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * + * @return string Requested variable + */ + static function getCmd($name, $default = '', $hash = 'default') + { + return UserlogRequest::getVar($name, $default, $hash, 'cmd'); + } + + /** + * Fetches and returns a given filtered variable. The string + * filter deletes 'bad' HTML code, if not overridden by the mask. + * This is currently only a proxy function for getVar(). + * See getVar() for more in-depth documentation on the parameters. + * + * @static + * + * @param string $name Variable name + * @param string $default Default value if the variable does not exist + * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) + * @param int $mask Filter mask for the variable + * + * @return string Requested variable + */ + static function getString($name, $default = '', $hash = 'default', $mask = 0) + { + // Cast to string, in case JREQUEST_ALLOWRAW was specified for mask + return (string)UserlogRequest::getVar($name, $default, $hash, 'string', $mask); + } + + static function getArray($name, $defaul... [truncated message content] |