From: <tr...@us...> - 2011-10-27 00:12:56
|
Revision: 7983 http://xoops.svn.sourceforge.net/xoops/?rev=7983&view=rev Author: trabis Date: 2011-10-27 00:12:48 +0000 (Thu, 27 Oct 2011) Log Message: ----------- Moving functions to xoops class and mark them as deprecated. Notice that functions are required on every page and there is no difference in having them inside the main class. Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoops.php XoopsCore/branches/2.6.x/2.6.0/htdocs/include/common.php XoopsCore/branches/2.6.x/2.6.0/htdocs/include/functions.php Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoops.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoops.php 2011-10-26 20:47:18 UTC (rev 7982) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/class/xoops.php 2011-10-27 00:12:48 UTC (rev 7983) @@ -71,9 +71,9 @@ public $userIsAdmin = false; /** - * @var string + * @var array */ - public $option = ''; + public $option = array(); /** * @var XoopsTpl|null @@ -99,6 +99,32 @@ public $tpl_file = ''; /** + * @var array + */ + private $_kernelHandlers = array(); + + /** + * @var array + */ + private $_moduleHandlers = array(); + + /** + * @var null|array + */ + private $_activeModules = null; + + /** + * @var array + */ + private $_systemConfigs = array(); + + /** + * @var array + */ + private $_moduleConfigs = array(); + + + /** * Actual Xoops OS */ private function __construct() @@ -117,7 +143,7 @@ * @staticvar Xoops * @return Xoops */ - static function getInstance() + static public function getInstance() { static $instance; if (!isset($instance)) { @@ -212,10 +238,10 @@ * Disable gzip compression if PHP is run under CLI mode and needs refactored to work correctly */ if (empty($_SERVER['SERVER_NAME']) || substr(PHP_SAPI, 0, 3) == 'cli') { - xoops_setConfigOption('gzip_compression', 0); + $this->setConfig('gzip_compression', 0); } - if (xoops_getConfigOption('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) { + if ($this->getConfig('gzip_compression') == 1 && extension_loaded('zlib') && !ini_get('zlib.output_compression')) { if (@ini_get('zlib.output_compression_level') < 0) { ini_set('zlib.output_compression_level', 6); } @@ -409,6 +435,1069 @@ { return $this->userIsAdmin; } + + + /** + * @param mixed $name + * @param mixed $optional + * @return XoopsObjectHandler|XoopsPersistableObjectHandler|null + */ + public function getHandler($name, $optional = false) + { + $name = strtolower(trim($name)); + $class = ''; + if (!isset($this->_kernelHandlers[$name])) { + if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { + require_once $hnd_file; + } + $class = 'Xoops' . ucfirst($name) . 'Handler'; + if (class_exists($class)) { + $this->_kernelHandlers[$name] = new $class($this->db); + } + } + if (!isset($this->_kernelHandlers[$name])) { + trigger_error('Class <strong>' . $class . '</strong> does not exist<br />Handler Name: ' . $name, $optional + ? E_USER_WARNING : E_USER_ERROR); + } + if (isset($this->_kernelHandlers[$name])) { + return $this->_kernelHandlers[$name]; + } + return false; + } + + /** + * @param string|null $name + * @param string|null $module_dir + * @param bool $optional + * @return bool + */ + public function getModuleHandler($name = null, $module_dir = null, $optional = false) + { + // if $module_dir is not specified + if (!isset($module_dir)) { + // if a module is loaded + if ($this->module instanceof XoopsModule) { + $module_dir = $this->module->getVar('dirname', 'n'); + } else { + trigger_error('No Module is loaded', E_USER_ERROR); + } + } else { + $module_dir = trim($module_dir); + } + $name = (!isset($name)) ? $module_dir : trim($name); + if (!isset($this->_moduleHandlers[$module_dir][$name])) { + if (file_exists($hnd_file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php")) { + include_once $hnd_file; + } + $class = ucfirst(strtolower($module_dir)) . ucfirst($name) . 'Handler'; + if (class_exists($class)) { + $this->_moduleHandlers[$module_dir][$name] = new $class($this->db); + } + } + if (!isset($this->_moduleHandlers[$module_dir][$name])) { + trigger_error('Handler does not exist<br />Module: ' . $module_dir . '<br />Name: ' . $name, $optional + ? E_USER_WARNING : E_USER_ERROR); + } + if (isset($this->_moduleHandlers[$module_dir][$name])) { + return $this->_moduleHandlers[$module_dir][$name]; + } + return false; + } + + /** + * XOOPS class loader wrapper + * + * Temporay solution for XOOPS 2.3 + * + * @param string $name Name of class to be loaded + * @param string $type domain of the class, potential values: core - locaded in /class/; framework - located in /Frameworks/; other - module class, located in /modules/[$type]/class/ + * @return boolean + */ + public function load($name, $type = 'core') + { + if (!class_exists('XoopsLoad')) { + require_once XOOPS_ROOT_PATH . '/class/xoopsload.php'; + } + return XoopsLoad::load($name, $type); + } + + /** + * XOOPS language loader wrapper + * + * Temporay solution, not encouraged to use + * + * @param string $name Name of language file to be loaded, without extension + * @param string $domain Module dirname; global language file will be loaded if $domain is set to 'global' or not specified + * @param string $language Language to be loaded, current language content will be loaded if not specified + * @return boolean + * @todo expand domain to multiple categories, e.g. module:system, framework:filter, etc. + * + */ + public function loadLanguage($name, $domain = '', $language = null) + { + /** + * We must check later for an empty value. As xoops_getOption could be empty + */ + if (empty($name)) { + return false; + } + $language = empty($language) ? $this->config['language'] : $language; + $path = ((empty($domain) || 'global' == $domain) ? '' : "modules/{$domain}/") . 'language'; + if (!file_exists($file = $this->path("{$path}/{$language}/{$name}.php"))) { + if (!file_exists($file = $this->path("{$path}/english/{$name}.php"))) { + return false; + } + } + $ret = include_once $file; + return $ret; + } + + /** + * YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED + */ + /** + * Get active modules from cache file + * + * @return array + */ + public function getActiveModules() + { + if (is_array($this->_activeModules)) { + return $this->_activeModules; + } + + if (!$this->_activeModules = XoopsCache::read('system_modules_active')) { + $this->_activeModules = $this->_setActiveModules(); + } + return $this->_activeModules; + } + + /** + * YOU SHOULD BE CAREFUL WITH USING THIS METHOD SINCE IT WILL BE DEPRECATED + */ + /** + * Write active modules to cache file + * + * @return array + */ + private function _setActiveModules() + { + /* @var $module_handler XoopsModuleHandler */ + $module_handler = xoops_gethandler('module'); + $modules_active = $module_handler->getAll(new Criteria('isactive', 1), array('dirname'), false, false); + XoopsCache::write('system_modules_active', $modules_active); + return $modules_active; + } + + /** + * Checks is module is installed and active + * + * @param $dirname + * @return bool + */ + public function isActiveModule($dirname) + { + if (isset($dirname) && in_array($dirname, $this->getActiveModules())) { + return true; + } + return false; + } + + /** + * @param bool $closehead + * @return void + */ + public function simpleHeader($closehead = true) + { + /* @var $config_handler XoopsConfigHandler */ + $config_handler = xoops_gethandler('config'); + $xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); + + if (!headers_sent()) { + header('Content-Type:text/html; charset=' . _CHARSET); + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0'); + header("Pragma: no-cache"); + } + + echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n"; + echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '"> + <head> + <meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" /> + <meta http-equiv="content-language" content="' . _LANGCODE . '" /> + <meta name="robots" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_robots']) . '" /> + <meta name="keywords" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']) . '" /> + <meta name="description" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_desc']) . '" /> + <meta name="rating" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_rating']) . '" /> + <meta name="author" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_author']) . '" /> + <meta name="copyright" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']) . '" /> + <meta name="generator" content="XOOPS" /> + <title>' . htmlspecialchars($this->config['sitename']) . '</title> + <script type="text/javascript" src="' . XOOPS_URL . '/include/xoops.js"></script>'; + $themecss = $this->getcss($this->config['theme_set']); + echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css" />'; + $language = $this->getConfig('language'); + if (file_exists($this->path('language/' . $language . '/style.css'))) { + echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/language/' . $language . '/style.css" />'; + } + if ($themecss) { + echo '<link rel="stylesheet" type="text/css" media="all" href="' . $themecss . '" />'; + } + if ($closehead) { + echo '</head><body>'; + } + } + + /** + * @return void + */ + public function simpleFooter() + { + echo '</body></html>'; + ob_end_flush(); + } + + /** + * @param mixed $msg + * @param string $title + * @return void + */ + public function error($msg, $title = '') + { + echo '<div class="errorMsg">'; + if ($title != '') { + echo '<strong>' . $title . '</strong><br /><br />'; + } + if (is_object($msg)) { + $msg = (array)$msg; + } + if (is_array($msg)) { + foreach ($msg as $key => $value) { + if (is_numeric($key)) { + $key = ''; + } + $this->error($value, $key); + } + } else { + echo "<div>{$msg}</div>"; + } + echo '</div>'; + } + + /** + * @param mixed $msg + * @param string $title + * @return void + */ + public function result($msg, $title = '') + { + echo '<div class="resultMsg">'; + if ($title != '') { + echo '<strong>' . $title . '</strong><br /><br />'; + } + if (is_object($msg)) { + $msg = (array)$msg; + } + if (is_array($msg)) { + foreach ($msg as $key => $value) { + if (is_numeric($key)) { + $key = ''; + } + $this->result($value, $key); + } + } else { + echo "<div>{$msg}</div>"; + } + echo '</div>'; + } + + /** + * @param mixed $hiddens + * @param mixed $action + * @param mixed $msg + * @param string $submit + * @param bool $addtoken + * @return void + */ + public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true) + { + $submit = ($submit != '') ? trim($submit) : _SUBMIT; + echo '<div class="confirmMsg">' . $msg . '<br /> + <form method="post" action="' . $action . '">'; + foreach ($hiddens as $name => $value) { + if (is_array($value)) { + foreach ($value as $caption => $newvalue) { + echo '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption; + } + echo '<br />'; + } else { + echo '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />'; + } + } + if ($addtoken != false) { + echo $this->security->getTokenHTML(); + } + echo '<input type="submit" name="confirm_submit" value="' . $submit . '" title="' . $submit . '"/> + <input type="button" name="confirm_back" value="' . _CANCEL . '" onclick="javascript:history.go(-1);" title="' . _CANCEL . '" /> + </form> + </div>'; + } + + /** + * @param mixed$time + * @param string $timeoffset + * @return int + */ + public function getUserTimestamp($time, $timeoffset = '') + { + if ($timeoffset == '') { + if ($this->isUser()) { + $timeoffset = $this->user->getVar('timezone_offset'); + } else { + $timeoffset = $this->config['default_TZ']; + } + } + $usertimestamp = intval($time) + (floatval($timeoffset) - $this->config['server_TZ']) * 3600; + return $usertimestamp; + } + + /** + * Function to display formatted times in user timezone + * + * @param int $time + * @param string $format + * @param string $timeoffset + * @return string + */ + public function formatTimestamp($time, $format = 'l', $timeoffset = '') + { + return XoopsLocal::formatTimestamp($time, $format, $timeoffset); + } + + /** + * Function to calculate server timestamp from user entered time (timestamp) + * + * @param int $timestamp + * @param null $userTZ + * @return int + */ + public function userTimeToServerTime($timestamp, $userTZ = null) + { + if (!isset($userTZ)) { + $userTZ = $this->config['default_TZ']; + } + $timestamp = $timestamp - (($userTZ - $this->config['server_TZ']) * 3600); + return $timestamp; + } + + /** + * @return string + */ + public function makePass() + { + $makepass = ''; + $syllables = array( + 'er', 'in', 'tia', 'wol', 'fe', 'pre', 'vet', 'jo', 'nes', 'al', 'len', 'son', 'cha', 'ir', 'ler', 'bo', 'ok', + 'tio', 'nar', 'sim', 'ple', 'bla', 'ten', 'toe', 'cho', 'co', 'lat', 'spe', 'ak', 'er', 'po', 'co', 'lor', + 'pen', 'cil', 'li', 'ght', 'wh', 'at', 'the', 'he', 'ck', 'is', 'mam', 'bo', 'no', 'fi', 've', 'any', 'way', + 'pol', 'iti', 'cs', 'ra', 'dio', 'sou', 'rce', 'sea', 'rch', 'pa', 'per', 'com', 'bo', 'sp', 'eak', 'st', 'fi', + 'rst', 'gr', 'oup', 'boy', 'ea', 'gle', 'tr', 'ail', 'bi', 'ble', 'brb', 'pri', 'dee', 'kay', 'en', 'be', 'se' + ); + srand((double)microtime() * 1000000); + for ($count = 1; $count <= 4; $count++) { + if (rand() % 10 == 1) { + $makepass .= sprintf('%0.0f', (rand() % 50) + 1); + } else { + $makepass .= sprintf('%s', $syllables[rand() % 62]); + } + } + return $makepass; + } + + /** + * @param string $email + * @param bool $antispam + * @return bool|mixed + */ + public function checkEmail($email, $antispam = false) + { + if (!$email || !preg_match('/^[^@]{1,64}@[^@]{1,255}$/', $email)) { + return false; + } + $email_array = explode("@", $email); + $local_array = explode(".", $email_array[0]); + for ($i = 0; $i < sizeof($local_array); $i++) { + if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/\=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/\=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i]) + ) { + return false; + } + } + if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { + $domain_array = explode(".", $email_array[1]); + if (sizeof($domain_array) < 2) { + return false; // Not enough parts to domain + } + for ($i = 0; $i < sizeof($domain_array); $i++) { + if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) { + return false; + } + } + } + if ($antispam) { + $email = str_replace("@", " at ", $email); + $email = str_replace(".", " dot ", $email); + } + return $email; + } + + /** + * @param string $url + * @return string + */ + public function formatURL($url) + { + $url = trim($url); + if ($url != '') { + if ((!preg_match('/^http[s]*:\/\//i', $url)) && (!preg_match('/^ftp*:\/\//i', $url)) && (!preg_match('/^ed2k*:\/\//i', $url)) + ) { + $url = 'http://' . $url; + } + } + return $url; + } + + /** + * Function to get banner html tags for use in templates + * + * @return string + */ + public function getBanner() + { + $bresult = $this->db->query('SELECT COUNT(*) FROM ' . $this->db->prefix('banner')); + list ($numrows) = $this->db->fetchRow($bresult); + if ($numrows > 1) { + $numrows = $numrows - 1; + mt_srand((double)microtime() * 1000000); + $bannum = mt_rand(0, $numrows); + } else { + $bannum = 0; + } + if ($numrows > 0) { + $bresult = $this->db->query('SELECT * FROM ' . $this->db->prefix('banner'), 1, $bannum); + list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $this->db->fetchRow($bresult); + if ($this->config['my_ip'] == $this->getEnv('REMOTE_ADDR')) { + // EMPTY + } else { + $impmade = $impmade + 1; + $this->db->queryF(sprintf('UPDATE %s SET impmade = %u WHERE bid = %u', $this->db->prefix('banner'), $impmade, $bid)); + /** + * Check if this impression is the last one + */ + if ($imptotal > 0 && $impmade >= $imptotal) { + $newid = $this->db->genId($this->db->prefix('bannerfinish') . '_bid_seq'); + $sql = sprintf('INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)', $this->db->prefix('bannerfinish'), $newid, $cid, $impmade, $clicks, $date, time()); + $this->db->queryF($sql); + $this->db->queryF(sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('banner'), $bid)); + } + } + /** + * Print the banner + */ + if ($htmlbanner) { + $bannerobject = $htmlcode; + } else { + $bannerobject = '<div id="xo-bannerfix">'; + if (stristr($imageurl, '.swf')) { + $bannerobject = $bannerobject . '<div id ="xo-fixbanner">' . '<a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"></a></div>' . '<object type="application/x-shockwave-flash" width="468" height="60" data="' . $imageurl . '" style="z-index:100;">' . '<param name="movie" value="' . $imageurl . '" />' . '<param name="wmode" value="opaque" />' . '</object>'; + + } else { + $bannerobject = $bannerobject . '<a href="' . XOOPS_URL . '/banners.php?op=click&bid=' . $bid . '" rel="external" title="' . $clickurl . '"><img src="' . $imageurl . '" alt="' . $clickurl . '" /></a>'; + } + + $bannerobject = $bannerobject . '</div>'; + } + return $bannerobject; + } + return ''; + } + + /** + * Function to redirect a user to certain pages + * + * @param $url + * @param int $time + * @param string $message + * @param bool $addredirect + * @param bool $allowExternalLink + * @return void + */ + public function redirect($url, $time = 3, $message = '', $addredirect = true, $allowExternalLink = false) + { + $this->preload->triggerEvent('core.include.functions.redirectheader', + array($url, $time, $message, $addredirect, $allowExternalLink)); + + if (preg_match("/[\\0-\\31]|about:|script:/i", $url)) { + if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-[0-9]*\)([\s]*[;]*[\s]*)$/si', $url)) { + $url = XOOPS_URL; + } + } + if (!$allowExternalLink && $pos = strpos($url, '://')) { + $xoopsLocation = substr(XOOPS_URL, strpos(XOOPS_URL, '://') + 3); + if (strcasecmp(substr($url, $pos + 3, strlen($xoopsLocation)), $xoopsLocation)) { + $url = XOOPS_URL; + } + } + if (defined('XOOPS_CPFUNC_LOADED')) { + $theme = 'default'; + } else { + $theme = $this->config['theme_set']; + } + + $xoopsThemeFactory = null; + $xoopsThemeFactory = new xos_opal_ThemeFactory(); + $xoopsThemeFactory->allowedThemes = $this->config['theme_set_allowed']; + $xoopsThemeFactory->defaultTheme = $theme; + $this->theme = $xoopsThemeFactory->createInstance(array("plugins" => array(), "renderBanner" => false)); + $this->tpl = $this->theme->template; + $this->tpl->assign(array( + 'xoops_theme' => $theme, 'xoops_imageurl' => XOOPS_THEME_URL . '/' . $theme . '/', + 'xoops_themecss' => xoops_getcss($theme), + 'xoops_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES), + 'xoops_sitename' => htmlspecialchars($this->config['sitename'], ENT_QUOTES), + 'xoops_slogan' => htmlspecialchars($this->config['slogan'], ENT_QUOTES), + 'xoops_dirname' => $this->isModule() ? $this->module->getVar('dirname') : 'system', + 'xoops_pagetitle' => $this->isModule() ? $this->module->getVar('name') : htmlspecialchars($this->config['slogan'], ENT_QUOTES) + )); + if ($this->config['debug_mode'] == 2 && $this->userIsAdmin) { + $this->tpl->assign('time', 300); + $this->tpl->assign('xoops_logdump', $this->logger->dump()); + } else { + $this->tpl->assign('time', intval($time)); + } + if (!empty($_SERVER['REQUEST_URI']) && $addredirect && strstr($url, 'user.php')) { + if (!strstr($url, '?')) { + $url .= '?xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']); + } else { + $url .= '&xoops_redirect=' . urlencode($_SERVER['REQUEST_URI']); + } + } + if (defined('SID') && SID && (!isset($_COOKIE[session_name()]) || ($this->config['use_mysession'] && $this->config['session_name'] != '' && !isset($_COOKIE[$this->config['session_name']]))) + ) { + if (!strstr($url, '?')) { + $url .= '?' . SID; + } else { + $url .= '&' . SID; + } + } + $url = preg_replace("/&/i", '&', htmlspecialchars($url, ENT_QUOTES)); + $this->tpl->assign('url', $url); + $message = trim($message) != '' ? $message : _TAKINGBACK; + $this->tpl->assign('message', $message); + $this->tpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url)); + $this->tpl->display('db:system_redirect.html'); + exit(); + } + + /** + * @param $key + * @return string + */ + public function getEnv($key) + { + $ret = ''; + if (array_key_exists($key, $_SERVER) && isset($_SERVER[$key])) { + $ret = $_SERVER[$key]; + return $ret; + } + if (array_key_exists($key, $_ENV) && isset($_ENV[$key])) { + $ret = $_ENV[$key]; + return $ret; + } + return $ret; + } + + /** + * Function to get css file for a certain themeset + * + * @param string $theme + * @return string + */ + public function getCss($theme = '') + { + if ($theme == '') { + $theme = $this->config['theme_set']; + } + $uagent = xoops_getenv('HTTP_USER_AGENT'); + if (stristr($uagent, 'mac')) { + $str_css = 'styleMAC.css'; + } elseif (preg_match("/MSIE ([0-9]\.[0-9]{1,2})/i", $uagent)) { + $str_css = 'style.css'; + } else { + $str_css = 'styleNN.css'; + } + if (is_dir(XOOPS_THEME_PATH . '/' . $theme)) { + if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/' . $str_css)) { + return XOOPS_THEME_URL . '/' . $theme . '/' . $str_css; + } elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/style.css')) { + return XOOPS_THEME_URL . '/' . $theme . '/style.css'; + } + } + if (is_dir(XOOPS_THEME_PATH . '/' . $theme . '/css')) { + if (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/' . $str_css)) { + return XOOPS_THEME_URL . '/' . $theme . '/css/' . $str_css; + } elseif (file_exists(XOOPS_THEME_PATH . '/' . $theme . '/css/style.css')) { + return XOOPS_THEME_URL . '/' . $theme . '/css/style.css'; + } + } + return ''; + } + + /** + * @return XoopsMailer|XoopsMailerLocal + */ + public function getMailer() + { + static $mailer; + if (is_object($mailer)) { + return $mailer; + } + + include_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; + if (file_exists($file = XOOPS_ROOT_PATH . '/language/' . Xoops::getInstance()->config['language'] . '/xoopsmailerlocal.php')) { + include_once $file; + } else { + if (file_exists($file = XOOPS_ROOT_PATH . '/language/english/xoopsmailerlocal.php')) { + include_once $file; + } + } + unset($mailer); + if (class_exists('XoopsMailerLocal')) { + $mailer = new XoopsMailerLocal(); + } else { + $mailer = new XoopsMailer(); + } + return $mailer; + } + + /** + * @param integer $rank_id + * @param int $posts + * @return array + */ + public function getRank($rank_id = 0, $posts = 0) + { + $myts = MyTextSanitizer::getInstance(); + $rank_id = intval($rank_id); + $posts = intval($posts); + if ($rank_id != 0) { + $sql = "SELECT rank_title AS title, rank_image AS image FROM " . $this->db->prefix('ranks') . " WHERE rank_id = " . $rank_id; + } else { + $sql = "SELECT rank_title AS title, rank_image AS image FROM " . $this->db->prefix('ranks') . " WHERE rank_min <= " . $posts . " AND rank_max >= " . $posts . " AND rank_special = 0"; + } + $rank = $this->db->fetchArray($this->db->query($sql)); + $rank['title'] = $myts->htmlspecialchars($rank['title']); + $rank['id'] = $rank_id; + return $rank; + } + + /** + * Returns the portion of string specified by the start and length parameters. If $trimmarker is supplied, it is appended to the return string. This function works fine with multi-byte characters if mb_* functions exist on the server. + * + * @param string $str + * @param int $start + * @param int $length + * @param string $trimmarker + * @return string + */ + public function substr($str, $start, $length, $trimmarker = '...') + { + return XoopsLocal::substr($str, $start, $length, $trimmarker); + } + + /** + * @param string $text + * @return string + */ + public function utf8_encode(&$text) + { + return XoopsLocal::utf8_encode($text); + } + + /** + * @param string $text + * @return string + */ + function convertEncoding(&$text) + { + return XoopsLocal::utf8_encode($text); + } + + /** + * @param string $text + * @return string + */ + public function trim($text) + { + return XoopsLocal::trim($text); + } + + public function getOption($option) + { + $ret = ''; + if (isset($this->option[$option])) { + $ret = $this->option[$option]; + } + return $ret; + } + + /** + * @param string $key + * @param string $type + * @return mixed + */ + function getConfig($key, $type = 'XOOPS_CONF') + { + if (isset($this->_systemConfigs[$key])) { + return $this->_systemConfigs[$key]; + } + $this->getConfigs($type); + $this->_systemConfigs[$key] = array(); + if (!isset($this->_systemConfigs[$key])) { + $this->_systemConfigs[$key] = null; + } + return $this->_systemConfigs[$key]; + } + + function getConfigs($type = 'XOOPS_CONF') { + /* @var $config_handler XoopsConfigHandler */ + $config_handler = xoops_gethandler('config'); + $configs = $config_handler->getConfigsByCat((is_array($type)) ? $type : constant($type)); + $this->_systemConfigs = array_merge($this->_systemConfigs, $configs); + $this->config =& $this->_systemConfigs;//for compatibilty + return $this->_systemConfigs; + } + + /** + * @param $configs + * @return void + */ + function addConfigs($configs) { + $this->_systemConfigs = array_merge($this->_systemConfigs, (array) $configs); + } + + /** + * @param string $key + * @param mixed $value + * @return void + */ + public function setConfig($key, $value = null) + { + if (isset($this->_systemConfigs[$key]) && !is_null($value)) { + $this->_systemConfigs[$key] = $value; + } + } + + /** + * @param string $key + * @param string $dirname + * @return null + */ + public function getModuleConfig($key, $dirname = '') + { + $dirname = trim($dirname); + if (empty($dirname)) { + $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system'; + } + if (!isset($this->_moduleConfigs[$dirname])) { + $this->getModuleConfigs($dirname); + } + if (isset($this->_moduleConfigs[$dirname][$key])) { + return $this->_moduleConfigs[$dirname][$key]; + } + return null; + } + + /** + * @param string $dirname + * @return + */ + public function getModuleConfigs($dirname = '') + { + $dirname = trim($dirname); + if (empty($dirname)) { + $dirname = $this->isModule() ? $this->module->getVar('dirname') : 'system'; + } + if (isset($this->_moduleConfigs[$dirname])) { + return $this->_moduleConfigs[$dirname]; + } + $this->_moduleConfigs[$dirname] = array(); + + /* @var $module_handler XoopsModuleHandler */ + $module_handler = xoops_gethandler('module'); + $module = $module_handler->getByDirname($dirname); + /* @var $config_handler XoopsConfigHandler */ + $config_handler = xoops_gethandler('config'); + if (is_object($module)) { + $this->_moduleConfigs[$dirname] = $config_handler->getConfigsByCat(0, $module->getVar('mid')); + } + if ($this->isModule()) { + $this->moduleConfig =& $this->_moduleConfigs[$module->getVar('dirname')]; + } + return $this->_moduleConfigs[$dirname]; + } + + /** + * @param string $url + * @param int $debug + * @return string + * @deprecated + */ + public function getBaseDomain($url, $debug = 0) + { + $base_domain = ''; + $url = strtolower($url); + + // generic tlds (source: http://en.wikipedia.org/wiki/Generic_top-level_domain) + $G_TLD = array( + 'biz', 'com', 'edu', 'gov', 'info', 'int', 'mil', 'name', 'net', 'org', 'aero', 'asia', 'cat', 'coop', 'jobs', + 'mobi', 'museum', 'pro', 'tel', 'travel', 'arpa', 'root', 'berlin', 'bzh', 'cym', 'gal', 'geo', 'kid', 'kids', + 'lat', 'mail', 'nyc', 'post', 'sco', 'web', 'xxx', 'nato', 'example', 'invalid', 'localhost', 'test', 'bitnet', + 'csnet', 'ip', 'local', 'onion', 'uucp', 'co' + ); + + // country tlds (source: http://en.wikipedia.org/wiki/Country_code_top-level_domain) + $C_TLD = array( // active + 'ac', 'ad', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'ax', 'az', + 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bw', 'by', 'bz', + 'ca', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', + 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', + 'fr', 'ga', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', + 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'io', 'iq', 'ir', 'is', 'it', 'je', + 'jm', 'jo', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', + 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'mg', 'mh', 'mk', 'ml', 'mm', 'mn', 'mo', 'mp', 'mq', + 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', + 'nr', 'nu', 'nz', 'om', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pn', 'pr', 'ps', 'pt', 'pw', 'py', 'qa', + 're', 'ro', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sk', 'sl', 'sm', 'sn', 'sr', 'st', + 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tr', 'tt', 'tv', 'tw', + 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yu', + 'za', 'zm', 'zw', // inactive + 'eh', 'kp', 'me', 'rs', 'um', 'bv', 'gb', 'pm', 'sj', 'so', 'yt', 'su', 'tp', 'bu', 'cs', 'dd', 'zr' + ); + + // get domain + if (!$full_domain = $this->getUrlDomain($url)) { + return $base_domain; + } + + // break up domain, reverse + $DOMAIN = explode('.', $full_domain); + if ($debug) { + print_r($DOMAIN); + } + $DOMAIN = array_reverse($DOMAIN); + if ($debug) { + print_r($DOMAIN); + } + // first check for ip address + if (count($DOMAIN) == 4 && is_numeric($DOMAIN[0]) && is_numeric($DOMAIN[3])) { + return $full_domain; + } + + // if only 2 domain parts, that must be our domain + if (count($DOMAIN) <= 2) { + return $full_domain; + } + + /* + finally, with 3+ domain parts: obviously D0 is tld now, + if D0 = ctld and D1 = gtld, we might have something like com.uk so, + if D0 = ctld && D1 = gtld && D2 != 'www', domain = D2.D1.D0 else if D0 = ctld && D1 = gtld && D2 == 'www', + domain = D1.D0 else domain = D1.D0 - these rules are simplified below. + */ + if (in_array($DOMAIN[0], $C_TLD) && in_array($DOMAIN[1], $G_TLD) && $DOMAIN[2] != 'www') { + $full_domain = $DOMAIN[2] . '.' . $DOMAIN[1] . '.' . $DOMAIN[0]; + } else { + $full_domain = $DOMAIN[1] . '.' . $DOMAIN[0]; + } + // did we succeed? + return $full_domain; + } + + /** + * Function to get the domain from a URL. + * + * @param string $url the URL to be stripped. + * @return string + * @deprecated + */ + public function getUrlDomain($url) + { + $domain = ''; + $_URL = parse_url($url); + + if (!empty($_URL) || !empty($_URL['host'])) { + $domain = $_URL['host']; + } + return $domain; + } + + /** + * function to update compiled template file in templates_c folder + * + * @param string $tpl_id + * @param boolean $clear_old + * @return boolean + */ + public function templateTouch($tpl_id, $clear_old = true) + { + $tplfile_handler = xoops_gethandler('tplfile'); + $tplfile = $tplfile_handler->get($tpl_id); + + if (is_object($tplfile)) { + $file = $tplfile->getVar('tpl_file', 'n'); + $tpl = new XoopsTpl(); + return $tpl->touch('db:' . $file); + } + return false; + } + + /** + * Clear the module cache + * + * @param int $mid Module ID + * @return void + */ + public function templateClearModuleCache($mid) + { + /* @var $block_handler XoopsBlockHandler */ + $block_handler = xoops_getHandler('block'); + $block_arr = $block_handler->getByModule($mid); + $count = count($block_arr); + if ($count > 0) { + $xoopsTpl = new XoopsTpl(); + $xoopsTpl->caching = 2; + for ($i = 0; $i < $count; $i++) { + if ($block_arr[$i]->getVar('template') != '') { + $xoopsTpl->clear_cache(XOOPS_ROOT_PATH . "/modules/" . $block_arr[$i]->getVar('dirname') . "/templates/blocks/" . $block_arr[$i]->getVar('template'), 'blk_' . $block_arr[$i]->getVar('bid')); + } + } + } + } + + /** + * Notification Helper Functions + * + * We want to be able to delete by module, by user, or by item. + * How do we specify this?? + * + * @param $module_id + * @return bool + */ + public function notificationDeleteByModule($module_id) + { + /* @var $notification_handler XoopsNotificationHandler */ + $notification_handler = xoops_gethandler('notification'); + return $notification_handler->unsubscribeByModule($module_id); + } + + /** + * @param int $user_id + * @return bool + */ + public function notificationDeleteByUser($user_id) + { + /* @var $notification_handler XoopsNotificationHandler */ + $notification_handler = xoops_gethandler('notification'); + return $notification_handler->unsubscribeByUser($user_id); + } + + /** + * @param int $module_id + * @param string $category + * @param int $item_id + * @return bool + */ + function notificationDeleteByItem($module_id, $category, $item_id) + { + /* @var $notification_handler XoopsNotificationHandler */ + $notification_handler = xoops_gethandler('notification'); + return $notification_handler->unsubscribeByItem($module_id, $category, $item_id); + } + + /** + * @param int $module_id + * @param int|null $item_id + * @return int + */ + public function commentCount($module_id, $item_id = null) + { + $comment_handler = xoops_gethandler('comment'); + $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); + if (isset($item_id)) { + $criteria->add(new Criteria('com_itemid', intval($item_id))); + } + return $comment_handler->getCount($criteria); + } + + /** + * @param int $module_id + * @param int $item_id + * @return bool + */ + function commentDelete($module_id, $item_id) + { + if (intval($module_id) > 0 && intval($item_id) > 0) { + /* @var $comment_handler XoopsCommentHandler */ + $comment_handler = xoops_gethandler('comment'); + $comments = $comment_handler->getByItemId($module_id, $item_id); + if (is_array($comments)) { + $count = count($comments); + $deleted_num = array(); + for ($i = 0; $i < $count; $i++) { + if (false != $comment_handler->delete($comments[$i])) { + // store poster ID and deleted post number into array for later use + $poster_id = $comments[$i]->getVar('com_uid'); + if ($poster_id != 0) { + $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 + : ($deleted_num[$poster_id] + 1); + } + } + } + + $member_handler = xoops_gethandler('member'); + foreach ($deleted_num as $user_id => $post_num) { + // update user posts + /* @var $member_handler XoopsMemberHandler */ + $com_poster = $member_handler->getUser($user_id); + if (is_object($com_poster)) { + $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num); + } + } + return true; + } + } + return false; + } + + /** + * Group Permission Helper Functions + * + * @param int $module_id + * @param string $perm_name + * @param null|int $item_id + * @return bool + */ + public function grouppermDeleteByModItem($module_id, $perm_name, $item_id = null) + { + // do not allow system permissions to be deleted + if (intval($module_id) <= 1) { + return false; + } + /* @var $gperm_handler XoopsGrouppermHandler */ + $gperm_handler = xoops_gethandler('groupperm'); + return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id); + } } ?> \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/include/common.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/include/common.php 2011-10-26 20:47:18 UTC (rev 7982) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/include/common.php 2011-10-27 00:12:48 UTC (rev 7983) @@ -67,7 +67,7 @@ */ $xoops->security = new XoopsSecurity(); $xoops->security->checkSuperglobals(); -$xoopsSecurity = $xoops->security; +$xoopsSecurity =& $xoops->security; /** * Create Instance XoopsLogger Object @@ -90,7 +90,7 @@ * Set cookie dope for multiple subdomains remove the '.'. to use top level dope for session cookie; * Requires functions */ -define('XOOPS_COOKIE_DOMAIN', ($domain = xoops_getBaseDomain(XOOPS_URL)) == 'localhost' ? '' : '.' . $domain); +define('XOOPS_COOKIE_DOMAIN', ($domain = $xoops->getBaseDomain(XOOPS_URL)) == 'localhost' ? '' : '.' . $domain); /** * Check Proxy; @@ -111,18 +111,15 @@ * Get xoops configs * Requires functions and database loaded */ -/* @var $config_handler XoopsConfigHandler */ -$config_handler = xoops_gethandler('config'); -$xoops->config =& $config_handler->getConfigsByCat(XOOPS_CONF); +$xoops->getConfigs(); $xoopsConfig =& $xoops->config; /** * Merge file and db configs. */ if (file_exists($file = $xoops->path('var/configs/xoopsconfig.php'))) { - $fileConfigs = include $file; - $xoops->config = array_merge($xoops->config, (array) $fileConfigs); - unset($fileConfigs, $file); + $xoops->addConfigs(include $file); + unset($file); } else { trigger_error('File Path Error: ' . 'var/configs/xoopsconfig.php' . ' does not exist.'); } @@ -136,10 +133,10 @@ /** * Start of Error Reportings. */ -if ($xoops->config['debug_mode'] == 1 || $xoops->config['debug_mode'] == 2) { +if ($xoops->getConfig('debug_mode') == 1 || $xoops->getConfig('debug_mode') == 2) { xoops_loadLanguage('logger'); $xoops->logger->enable(); - $xoops->logger->usePopup = ($xoops->config['debug_mode'] == 2); + $xoops->logger->usePopup = ($xoops->getConfig('debug_mode') == 2); } else { $xoops->logger->disable(); } @@ -160,24 +157,24 @@ * User Sessions */ /* @var $member_handler XoopsMemberHandler */ -$member_handler = xoops_gethandler('member'); +$member_handler = $xoops->gethandler('member'); /* @var $sess_handler XoopsSessionHandler */ -$xoops->sess_handler = xoops_gethandler('session'); +$xoops->sess_handler = $xoops->gethandler('session'); $sess_handler =& $xoops->sess_handler; -if ($xoops->config['use_ssl'] - && isset($_POST[$xoops->config['sslpost_name']]) - && $_POST[$xoops->config['sslpost_name']] != '' +if ($xoops->getConfig('use_ssl') + && isset($_POST[$xoops->getConfig('sslpost_name')]) + && $_POST[$xoops->getConfig('sslpost_name')] != '' ) { - session_id($_POST[$xoops->config['sslpost_name']]); -} else if ($xoops->config['use_mysession'] && $xoops->config['session_name'] != '' && $xoops->config['session_expire'] > 0) { - if (isset($_COOKIE[$xoops->config['session_name']])) { - session_id($_COOKIE[$xoops->config['session_name']]); + session_id($_POST[$xoops->getConfig('sslpost_name')]); +} else if ($xoops->getConfig('use_mysession') && $xoops->getConfig('session_name') != '' && $xoops->getConfig('session_expire') > 0) { + if (isset($_COOKIE[$xoops->getConfig('session_name')])) { + session_id($_COOKIE[$xoops->getConfig('session_name')]); } if (function_exists('session_cache_expire')) { - session_cache_expire($xoops->config['session_expire']); + session_cache_expire($xoops->getConfig('session_expire')); } - @ini_set('session.gc_maxlifetime', $xoops->config['session_expire'] * 60); + @ini_set('session.gc_maxlifetime', $xoops->getConfig('session_expire') * 60); } session_set_save_handler(array(&$xoops->sess_handler, 'open'), array(&$xoops->sess_handler, 'close'), @@ -190,9 +187,9 @@ /** * Remove expired session for xoopsUserId */ -if ($xoops->config['use_mysession'] - && $xoops->config['session_name'] != '' - && !isset($_COOKIE[$xoops->config['session_name']]) +if ($xoops->getConfig('use_mysession') + && $xoops->getConfig('session_name') != '' + && !isset($_COOKIE[$xoops->getConfig('session_name')]) && !empty($_SESSION['xoopsUserId']) ) { unset($_SESSION['xoopsUserId']); @@ -202,10 +199,10 @@ * Load xoopsUserId from cookie if "Remember me" is enabled. */ if (empty($_SESSION['xoopsUserId']) - && !empty($xoops->config['usercookie']) - && !empty($_COOKIE[$xoops->config['usercookie']]) + && $xoops->getConfig('usercookie') != '' + && !empty($_COOKIE[$xoops->getConfig('usercookie')]) ) { - $hash_data = @explode("-", $_COOKIE[$xoops->config['usercookie']], 2); + $hash_data = @explode("-", $_COOKIE[$xoops->getConfig('usercookie')], 2); list($_SESSION['xoopsUserId'], $hash_login) = array($hash_data[0], strval(@$hash_data[1])); unset($hash_data); } @@ -219,11 +216,11 @@ $xoops->user = ''; $_SESSION = array(); session_destroy(); - setcookie($xoops->config['usercookie'], 0, - 1, '/'); + setcookie($xoops->getConfig('usercookie'), 0, - 1, '/'); } else { if ((intval($xoops->user->getVar('last_login')) + 60 * 5) < time()) { /* @var $user_handler XoopsUserHandler */ - $user_handler = xoops_gethandler('user'); + $user_handler = $xoops->gethandler('user'); $criteria = new Criteria('uid', $_SESSION['xoopsUserId']); $user_handler->updateAll('last_login', time(), $criteria, true); unset($criteria); @@ -246,7 +243,7 @@ * Note: temporary solution only. Will be re-designed in XOOPS 3.0 */ if ($xoops->logger->isEnable()) { - $level = isset($xoops->config['debugLevel']) ? intval($xoops->config['debugLevel']) : 0; + $level = $xoops->getConfig('debugLevel') ? $xoops->getConfig('debugLevel') : 0; if (($level == 2 && empty($xoops->userIsAdmin)) || ($level == 1 && !$xoops->isUser())) { $xoops->logger->disable(); } @@ -264,7 +261,7 @@ /** * Closed Site */ -if ($xoops->config['closesite'] == 1) { +if ($xoops->getConfig('closesite') == 1) { include_once $xoops->path('include/site-closed.php'); } @@ -274,7 +271,7 @@ if (file_exists('./xoops_version.php')) { $url_arr = explode('/', strstr($_SERVER['PHP_SELF'], '/modules/')); /* @var $module_handler XoopsModuleHandler */ - $module_handler = xoops_gethandler( 'module' ); + $module_handler = $xoops->gethandler( 'module' ); $xoops->module = $module_handler->getByDirname($url_arr[2]); unset($url_arr); @@ -284,17 +281,15 @@ $xoops->footer(); } /* @var $moduleperm_handler XoopsGrouppermHandler */ - $moduleperm_handler = xoops_gethandler('groupperm'); + $moduleperm_handler = $xoops->gethandler('groupperm'); if ($xoops->isUser()) { if (!$moduleperm_handler->checkRight('module_read', $xoops->module->getVar('mid'), $xoops->user->getGroups())) { - redirect_header(XOOPS_URL, 1, _NOPERM, false); - exit(); + $xoops->redirect(XOOPS_URL, 1, _NOPERM, false); } $xoops->userIsAdmin = $xoops->user->isAdmin($xoops->module->getVar('mid')); } else { if (!$moduleperm_handler->checkRight('module_read', $xoops->module->getVar('mid'), XOOPS_GROUP_ANONYMOUS)) { - redirect_header(XOOPS_URL . '/user.php?from=' . $xoops->module->getVar('dirname', 'n'), 1, _NOPERM); - exit(); + $xoops->redirect(XOOPS_URL . '/user.php?from=' . $xoops->module->getVar('dirname', 'n'), 1, _NOPERM); } } @@ -308,7 +303,7 @@ } if ($xoops->module->getVar('hasconfig') == 1 || $xoops->module->getVar('hascomments') == 1 || $xoops->module->getVar('hasnotification') == 1 ) { - $xoops->moduleConfig = $config_handler->getConfigsByCat(0, $xoops->module->getVar('mid')); + $xoops->getModuleConfigs(); } } else if ($xoops->isUser()) { $xoops->userIsAdmin = $xoops->user->isAdmin(1); @@ -325,9 +320,8 @@ * YOU SHOULD AVOID USING THE FOLLOWING FUNCTION, IT WILL BE REMOVED */ //Creates 'system_modules_active' cache file if it has been deleted. -xoops_getActiveModules(); +$xoops->getActiveModules(); $xoops->logger->stopTime('XOOPS Boot'); $xoops->logger->startTime('Module init'); -$xoops->preload->triggerEvent('core.include.common.end'); -?> \ No newline at end of file +$xoops->preload->triggerEvent('core.include.common.end'); \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/include/functions.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/include/functions.php 2011-10-26 20:47:18 UTC (rev 7982) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/include/functions.php 2011-10-27 00:12:48 UTC (rev 7983) @@ -25,28 +25,9 @@ */ function xoops_getHandler($name, $optional = false) { - static $handlers; - $name = strtolower(trim($name)); - $class = ''; - if (!isset($handlers[$name])) { - if (file_exists($hnd_file = XOOPS_ROOT_PATH . '/kernel/' . $name . '.php')) { - require_once $hnd_file; - } - $class = 'Xoops' . ucfirst($name) . 'Handler'; - if (class_exists($class)) { - $db = XoopsDatabaseFactory::getDatabaseConnection(); - $handlers[$name] = new $class($db); - } - } - if (!isset($handlers[$name])) { - trigger_error('Class <strong>' . $class . '</strong> does not exist<br />Handler Name: ' . $name, $optional - ? E_USER_WARNING : E_USER_ERROR); - } - if (isset($handlers[$name])) { - return $handlers[$name]; - } - $inst = false; - return $inst; + $xoops = Xoops::getInstance(); + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->getHandler($name, $optional); } /** @@ -58,38 +39,8 @@ function xoops_getModuleHandler($name = null, $module_dir = null, $optional = false) { $xoops = Xoops::getInstance(); - static $handlers; - // if $module_dir is not specified - if (!isset($module_dir)) { - // if a module is loaded - if ($xoops->module instanceof XoopsModule) { - $module_dir = $xoops->module->getVar('dirname', 'n'); - } else { - trigger_error('No Module is loaded', E_USER_ERROR); - } - } else { - $module_dir = trim($module_dir); - } - $name = (!isset($name)) ? $module_dir : trim($name); - if (!isset($handlers[$module_dir][$name])) { - if (file_exists($hnd_file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php")) { - include_once $hnd_file; - } - $class = ucfirst(strtolower($module_dir)) . ucfirst($name) . 'Handler'; - if (class_exists($class)) { - $db = XoopsDatabaseFactory::getDatabaseConnection(); - $handlers[$module_dir][$name] = new $class($db); - } - } - if (!isset($handlers[$module_dir][$name])) { - trigger_error('Handler does not exist<br />Module: ' . $module_dir . '<br />Name: ' . $name, $optional - ? E_USER_WARNING : E_USER_ERROR); - } - if (isset($handlers[$module_dir][$name])) { - return $handlers[$module_dir][$name]; - } - $inst = false; - return $inst; + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->getModuleHandler($name, $module_dir, $optional); } /** @@ -103,10 +54,9 @@ */ function xoops_load($name, $type = 'core') { - if (!class_exists('XoopsLoad')) { - require_once XOOPS_ROOT_PATH . '/class/xoopsload.php'; - } - return XoopsLoad::load($name, $type); + $xoops = Xoops::getInstance(); + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->load($name, $type); } /** @@ -124,22 +74,8 @@ function xoops_loadLanguage($name, $domain = '', $language = null) { $xoops = Xoops::getInstance(); - - /** - * We must check later for an empty value. As xoops_getOption could be empty - */ - if (empty($name)) { - return false; - } - $language = empty($language) ? $xoops->config['language'] : $language; - $path = ((empty($domain) || 'global' == $domain) ? '' : "modules/{$domain}/") . 'language'; - if (!file_exists($fileinc = $xoops->path("{$path}/{$language}/{$name}.php"))) { - if (!file_exists($fileinc = $xoops->path("{$path}/english/{$name}.php"))) { - return false; - } - } - $ret = include_once $fileinc; - return $ret; + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated since XOOPS 2.6.0. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->loadLanguage($name, $domain, $language); } /** @@ -152,15 +88,9 @@ */ function xoops_getActiveModules() { - static $modules_active; - if (is_array($modules_active)) { - return $modules_active; - } - - if (!$modules_active = XoopsCache::read('system_modules_active')) { - $modules_active = xoops_setActiveModules(); - } - return $modules_active; + $xoops = Xoops::getInstance(); + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated since XOOPS 2.6.0. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->getActiveModules(); } /** @@ -173,16 +103,7 @@ */ function xoops_setActiveModules() { - /* @var $module_handler XoopsModuleHandler */ - $module_handler = xoops_gethandler('module'); - $modules_obj = $module_handler->getObjectsArray(new Criteria('isactive', 1)); - $modules_active = array(); - foreach (array_keys($modules_obj) as $key) { - $modules_active[] = $modules_obj[$key]->getVar('dirname'); - } - unset($modules_obj); - XoopsCache::write('system_modules_active', $modules_active); - return $modules_active; + exit('xoops_setActiveModules is deprecated'); } /** @@ -196,10 +117,9 @@ */ function xoops_isActiveModule($dirname) { - if (isset($dirname) && in_array($dirname, xoops_getActiveModules())) { - return true; - } - return false; + $xoops = Xoops::getInstance(); + $xoops->logger->addDeprecated(__FUNCTION__ . ' is deprecated since XOOPS 2.6.0. See how to replace in file ' . __FILE__ . ' line ' . __LINE__); + return $xoops->isActiveModule($dirname); } /** @@ -209,45 +129,8 @@ function xoops_header($closehead = true) { $xoops = Xoops::getInstance(); - - /* @var $config_handler XoopsConfigHandler */ - $config_handler = xoops_gethandler('config'); - $xoopsConfigMetaFooter = $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); - - if (!headers_sent()) { - header('Content-Type:text/html; charset=' . _CHARSET); - header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0'); - header("Pragma: no-cache"); - } - - echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n"; - echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '"> - <head> - <meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" /> - <meta http-equiv="content-language" content="' . _LANGCODE . '" /> - <meta name="robots" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_robots']) . '" /> - <meta name="keywords" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']) . '" /> - <meta name="description" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_desc']) . '" /> - <meta name="rating" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_rating']) . '" /> - <meta name="author" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_author']) . '" /> - <meta name="copyright" content="' . htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']) . '" /> - <meta name="generator" content="XOOPS" /> - <title>' . htmlspecialchars($xoops->config['sitename']) . '</title> - <script type="text/javascript" src="' . XOOPS_URL . '/include/xoops.js"></script>'; - $themecss = xoops_getcss($xoops->config['theme_set']); - echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/xoops.css" />'; - $language = xoops_getConfigOption('language'); - if (file_exists($xoops->path('language/' . $language . '/style.css'))) { - echo '<link rel="stylesheet" type="text/css" media="all" href="' . XOOPS_URL . '/language/' . $language . '/style.css" />'; - } - if ($themecss) { - echo '<link rel="stylesheet" type="text/css" media... [truncated message content] |