-<?php
-
-/*
- * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2009 The Nucleus Group
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- * (see nucleus/documentation/index.html#license for more info)
- */
-/**
- * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2009 The Nucleus Group
- * @version $Id: globalfunctions.php 1639 2012-01-29 08:10:11Z sakamocchi $
- */
-
-/* needed if we include globalfunctions from install.php */
-global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALE, $manager, $member;
-
-$nucleus['version'] = 'v4.00 SVN';
-$nucleus['codename'] = '';
-
-/* check and die if someone is trying to override internal globals (when register_globals turn on) */
-checkVars(array('nucleus', 'CONF', 'DIR_LIBS', 'MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', '$DIR_LOCALE', 'DIR_PLUGINS', 'HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS', 'HTTP_SESSION_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'GLOBALS', 'argv', 'argc', '_GET', '_POST', '_COOKIE', '_ENV', '_SESSION', '_SERVER', '_FILES'));
-
-$CONF['debug'] = 0;
-if ( $CONF['debug'] )
+<?php\r
+\r
+/*\r
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
+ * Copyright (C) 2002-2012 The Nucleus Group\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * (see nucleus/documentation/index.html#license for more info)\r
+ */\r
+/**\r
+ * @license http://nucleuscms.org/license.txt GNU General Public License\r
+ * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
+ * @version $Id: globalfunctions.php 1727 2012-04-07 02:54:22Z sakamocchi $\r
+ */\r
+\r
+/* needed if we include globalfunctions from install.php */\r
+global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALES, $manager, $member;\r
+\r
+$nucleus['version'] = 'v4.00 SVN';\r
+$nucleus['codename'] = '';\r
+\r
+/* check and die if someone is trying to override internal globals (when register_globals turn on) */\r
+checkVars(array('nucleus', 'CONF', 'DIR_LIBS', 'MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'DIR_LOCALES', 'DIR_PLUGINS', 'HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS', 'HTTP_SESSION_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'GLOBALS', 'argv', 'argc', '_GET', '_POST', '_COOKIE', '_ENV', '_SESSION', '_SERVER', '_FILES'));\r
+\r
+/* debug mode */\r
+if ( !isset($CONF) )\r
+{\r
+ $CONF = array();\r
+}\r
+if ( array_key_exists('debug', $CONF) && $CONF['debug'] )\r
+{\r
+ /* report all errors! */\r
+ error_reporting(E_ALL);\r
+}\r
+else\r
+{\r
+ ini_set('display_errors','0');\r
+ error_reporting(E_ERROR | E_WARNING | E_PARSE);\r
+}\r
+\r
+/*\r
+ * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.\r
+ */\r
+if ( !isset($DIR_LOCALES) )\r
+{\r
+ $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';\r
+}\r
+global $DIR_LANG;\r
+if ( !isset($DIR_LANG) )\r
+{\r
+ $DIR_LANG = $DIR_LOCALES;\r
+}\r
+\r
+/*\r
+ * load and initialize i18n class\r
+ */\r
+if (!class_exists('i18n', FALSE))\r
+{\r
+ include($DIR_LIBS . 'i18n.php');\r
+}\r
+if ( !i18n::init('UTF-8', $DIR_LOCALES) )\r
+{\r
+ exit('Fail to initialize i18n class.');\r
+}\r
+/*\r
+ * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.\r
+ */\r
+define('_CHARSET', i18n::get_current_charset());\r
+\r
+/*\r
+ * Indicates when Nucleus should display startup errors. Set to 1 if you want\r
+ * the error enabled (default), false otherwise\r
+ *\r
+ * alertOnHeadersSent\r
+ * Displays an error when visiting a public Nucleus page and headers have\r
+ * been sent out to early. This usually indicates an error in either a\r
+ * configuration file or a translation file, and could cause Nucleus to\r
+ * malfunction\r
+ * alertOnSecurityRisk\r
+ * Displays an error only when visiting the admin area, and when one or\r
+ * more of the installation files (install.php, install.sql, upgrades/\r
+ * directory) are still on the server.\r
+ */\r
+if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )\r
+{\r
+ $CONF['alertOnHeadersSent'] = 1;\r
+}\r
+$CONF['alertOnSecurityRisk'] = 1;\r
+/*\r
+ * NOTE: this should be removed when releasing 4.0\r
+$CONF['ItemURL'] = $CONF['Self'];\r
+$CONF['ArchiveURL'] = $CONF['Self'];\r
+$CONF['ArchiveListURL'] = $CONF['Self'];\r
+$CONF['MemberURL'] = $CONF['Self'];\r
+$CONF['SearchURL'] = $CONF['Self'];\r
+$CONF['BlogURL'] = $CONF['Self'];\r
+$CONF['CategoryURL'] = $CONF['Self'];\r
+*/\r
+\r
+/*\r
+ * Set these to 1 to allow viewing of future items or draft items\r
+ * Should really never do this, but can be useful for some plugins that might need to\r
+ * Could cause some other issues if you use future posts otr drafts\r
+ * So use with care\r
+ */\r
+$CONF['allowDrafts'] = 0;\r
+$CONF['allowFuture'] = 0;\r
+\r
+if ( getNucleusPatchLevel() > 0 )\r
+{\r
+ $nucleus['version'] .= '/' . getNucleusPatchLevel();\r
+}\r
+\r
+/* Avoid notices */\r
+if ( !isset($CONF['installscript']) )\r
+{\r
+ $CONF['installscript'] = 0;\r
+}\r
+\r
+/* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/\r
+if ( $CONF['installscript'] != 1 )\r
+{\r
+ /* vars were already included in install.php */\r
+ include_once($DIR_LIBS . 'vars4.1.0.php');\r
+}\r
+\r
+/* sanitize option */\r
+$bLoggingSanitizedResult=0;\r
+$bSanitizeAndContinue=0;\r
+\r
+$orgRequestURI = serverVar('REQUEST_URI');\r
+sanitizeParams();\r
+\r
+/* get all variables that can come from the request and put them in the global scope */\r
+$blogid = requestVar('blogid');\r
+$itemid = intRequestVar('itemid');\r
+$catid = intRequestVar('catid');\r
+$skinid = requestVar('skinid');\r
+$memberid = requestVar('memberid');\r
+$archivelist = requestVar('archivelist');\r
+$imagepopup = requestVar('imagepopup');\r
+$archive = requestVar('archive');\r
+$query = requestVar('query');\r
+$highlight = requestVar('highlight');\r
+$amount = requestVar('amount');\r
+$action = requestVar('action');\r
+$nextaction = requestVar('nextaction');\r
+$maxresults = requestVar('maxresults');\r
+$startpos = intRequestVar('startpos');\r
+$errormessage = '';\r
+$error = '';\r
+$special = requestVar('special');\r
+$virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
+\r
+if ( !headers_sent() )\r
+{\r
+ header('Generator: Nucleus CMS ' . $nucleus['version']);\r
+}\r
+\r
+/*\r
+ * NOTE: Since 4.0 release, Entity class becomes to be important class\r
+ * with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function\r
+*/\r
+include($DIR_LIBS . 'ENTITY.php');\r
+\r
+/* include core classes that are needed for login & plugin handling */\r
+include_once($DIR_LIBS . 'mysql.php');\r
+/* added for 3.5 sql_* wrapper */\r
+global $MYSQL_HANDLER;\r
+if ( !isset($MYSQL_HANDLER) )\r
+{\r
+ $MYSQL_HANDLER = array('mysql','');\r
+}\r
+if ( $MYSQL_HANDLER[0] == '' )\r
+{\r
+ $MYSQL_HANDLER[0] = 'mysql';\r
+}\r
+include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');\r
+/* end new for 3.5 sql_* wrapper */\r
+include($DIR_LIBS . 'MEMBER.php');\r
+include($DIR_LIBS . 'ACTIONLOG.php');\r
+include($DIR_LIBS . 'MANAGER.php');\r
+include($DIR_LIBS . 'PLUGIN.php');\r
+\r
+$manager =& Manager::instance();\r
+\r
+/*\r
+ * make sure there's no unnecessary escaping:\r
+ * set_magic_quotes_runtime(0);\r
+ */\r
+if ( version_compare(PHP_VERSION, '5.3.0', '<') )\r
+{\r
+ ini_set('magic_quotes_runtime', '0');\r
+}\r
+\r
+/* Avoid notices */\r
+if ( !array_key_exists('UsingAdminArea', $CONF) )\r
+{\r
+ $CONF['UsingAdminArea'] = 0;\r
+}\r
+\r
+/* only needed when updating logs */\r
+if ( $CONF['UsingAdminArea'] )\r
+{\r
+ /* XML-RPC client classes */\r
+ include($DIR_LIBS . 'xmlrpc.inc.php');\r
+ include_once($DIR_LIBS . 'ADMIN.php');\r
+}\r
+\r
+/* connect to database */\r
+sql_connect();\r
+$SQLCount = 0;\r
+\r
+/* logs sanitized result if need */\r
+if ( $orgRequestURI!==serverVar('REQUEST_URI') )\r
+{\r
+ $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";\r
+ $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');\r
+ if ( $bLoggingSanitizedResult )\r
+ {\r
+ addToLog(WARNING, $msg);\r
+ }\r
+ if ( !$bSanitizeAndContinue )\r
+ {\r
+ die("");\r
+ }\r
+}\r
+\r
+/* makes sure database connection gets closed on script termination */\r
+register_shutdown_function('sql_disconnect');\r
+\r
+/* read config */\r
+getConfig();\r
+\r
+/*\r
+ * FIXME: This is for backward compatibility, should be obsoleted near future.\r
+ */\r
+if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])\r
+ && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )\r
+{\r
+ $CONF['Locale'] = 'en_Latn_US';\r
+}\r
+if ( !array_key_exists('Language', $CONF) )\r
+{\r
+ $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);\r
+}\r
+$locale = $CONF['Locale'];\r
+\r
+/* Properly set $CONF['Self'] and others if it's not set...\r
+ * usually when we are access from admin menu\r
+ */\r
+if ( !array_key_exists('Self', $CONF) )\r
+{\r
+ $CONF['Self'] = $CONF['IndexURL'];\r
+ /* strip trailing */\r
+ if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )\r
+ {\r
+ $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);\r
+ }\r
+}\r
+\r
+$CONF['ItemURL'] = $CONF['Self'];\r
+$CONF['ArchiveURL'] = $CONF['Self'];\r
+$CONF['ArchiveListURL'] = $CONF['Self'];\r
+$CONF['MemberURL'] = $CONF['Self'];\r
+$CONF['SearchURL'] = $CONF['Self'];\r
+$CONF['BlogURL'] = $CONF['Self'];\r
+$CONF['CategoryURL'] = $CONF['Self'];\r
+\r
+/*\r
+ *switch URLMode back to normal when $CONF['Self'] ends in .php\r
+ * this avoids urls like index.php/item/13/index.php/item/15\r
+ */\r
+if ( !array_key_exists('URLMode', $CONF)\r
+ || (($CONF['URLMode'] == 'pathinfo')\r
+ && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )\r
+{\r
+ $CONF['URLMode'] = 'normal';\r
+}\r
+\r
+/* automatically use simpler toolbar for mozilla */\r
+if ( ($CONF['DisableJsTools'] == 0)\r
+ && strstr(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0')\r
+ && strstr(serverVar('HTTP_USER_AGENT'), 'Gecko') )\r
+{\r
+ $CONF['DisableJsTools'] = 2;\r
+}\r
+\r
+$member = new Member();\r
+\r
+if ( $action == 'login' )\r
+{\r
+ $login = postVar('login');\r
+ $password = postVar('password');\r
+ $shared = intPostVar('shared');\r
+ $member->login($login, $password, $shared);\r
+}\r
+elseif ( ($action == 'logout') )\r
+{\r
+ $member->logout();\r
+}\r
+else\r
+{\r
+ $member->cookielogin();\r
+}\r
+\r
+/* NOTE: include translation file and set locale */\r
+if ( $member->isLoggedIn() && $member->getLocale())\r
+{\r
+ $locale = $member->getLocale();\r
+}\r
+include_translation($locale);\r
+i18n::set_current_locale($locale);\r
+\r
+/* login completed */\r
+$manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );\r
+\r
+/* next action */\r
+if ( $member->isLoggedIn() && $nextaction )\r
+{\r
+ $action = $nextaction;\r
+}\r
+\r
+/*\r
+ * Release ticket for plugin\r
+ */\r
+ticketForPlugin();\r
+\r
+/* first, let's see if the site is disabled or not. always allow admin area access. */\r
+if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )\r
+{\r
+ redirect($CONF['DisableSiteURL']);\r
+ exit;\r
+}\r
+\r
+/* load other classes */\r
+include($DIR_LIBS . 'PARSER.php');\r
+include($DIR_LIBS . 'SKIN.php');\r
+include($DIR_LIBS . 'TEMPLATE.php');\r
+include($DIR_LIBS . 'BLOG.php');\r
+include($DIR_LIBS . 'BODYACTIONS.php');\r
+include($DIR_LIBS . 'COMMENTS.php');\r
+include($DIR_LIBS . 'COMMENT.php');\r
+/* include($DIR_LIBS . 'ITEM.php'); */\r
+include($DIR_LIBS . 'NOTIFICATION.php');\r
+include($DIR_LIBS . 'BAN.php');\r
+include($DIR_LIBS . 'PAGEFACTORY.php');\r
+include($DIR_LIBS . 'SEARCH.php');\r
+include($DIR_LIBS . 'LINK.php');\r
+\r
+/* set lastVisit cookie (if allowed) */\r
+if ( !headers_sent() )\r
+{\r
+ if ( $CONF['LastVisit'] )\r
+ {\r
+ setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);\r
+ }\r
+ else\r
+ {\r
+ setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);\r
+ }\r
+}\r
+\r
+if ( !defined('_ARCHIVETYPE_MONTH') )\r
+{\r
+ define('_ARCHIVETYPE_DAY', 'day');\r
+ define('_ARCHIVETYPE_MONTH', 'month');\r
+ define('_ARCHIVETYPE_YEAR', 'year');\r
+}\r
+\r
+/* decode path_info */\r
+if ( $CONF['URLMode'] == 'pathinfo' )\r
+{\r
+ /* initialize keywords if this hasn't been done before */\r
+ if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )\r
+ {\r
+ $CONF['ItemKey'] = 'item';\r
+ }\r
+ \r
+ if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )\r
+ {\r
+ $CONF['ArchiveKey'] = 'archive';\r
+ }\r
+ \r
+ if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )\r
+ {\r
+ $CONF['ArchivesKey'] = 'archives';\r
+ }\r
+ \r
+ if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )\r
+ {\r
+ $CONF['MemberKey'] = 'member';\r
+ }\r
+ \r
+ if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )\r
+ {\r
+ $CONF['BlogKey'] = 'blog';\r
+ }\r
+ \r
+ if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )\r
+ {\r
+ $CONF['CategoryKey'] = 'category';\r
+ }\r
+ \r
+ if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )\r
+ {\r
+ $CONF['SpecialskinKey'] = 'special';\r
+ }\r
+ \r
+ $parsed = false;\r
+ $manager->notify(\r
+ 'ParseURL',\r
+ array(\r
+ /* e.g. item, blog, ... */\r
+ 'type' => basename(serverVar('SCRIPT_NAME') ),\r
+ 'info' => $virtualpath,\r
+ 'complete' => &$parsed\r
+ )\r
+ );\r
+ \r
+ if ( !$parsed )\r
+ {\r
+ /* default implementation */\r
+ $data = preg_split("#/#", $virtualpath );\r
+ for ( $i = 0; $i < sizeof($data); $i++ )\r
+ {\r
+ switch ( $data[$i] )\r
+ {\r
+ /* item/1 (blogid) */\r
+ case $CONF['ItemKey']:\r
+ $i++;\r
+ \r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $itemid = intval($data[$i]);\r
+ }\r
+ break;\r
+ \r
+ /* archives/1 (blogid) */\r
+ case $CONF['ArchivesKey']:\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $archivelist = intval($data[$i]);\r
+ }\r
+ break;\r
+ \r
+ /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */\r
+ case $CONF['ArchiveKey']:\r
+ if ( (($i + 1) < sizeof($data) ) && (!strstr($data[$i + 1], '-') ) )\r
+ {\r
+ $blogid = intval($data[++$i]);\r
+ }\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $archive = $data[$i];\r
+ }\r
+ break;\r
+ \r
+ /* blogid/1 */\r
+ case 'blogid':\r
+ /* blog/1 */\r
+ case $CONF['BlogKey']:\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $blogid = intval($data[$i]);\r
+ }\r
+ break;\r
+ \r
+ /* category/1 (catid) */\r
+ case $CONF['CategoryKey']:\r
+ case 'catid':\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $catid = intval($data[$i]);\r
+ }\r
+ break;\r
+ \r
+ case $CONF['MemberKey']:\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $memberid = intval($data[$i]);\r
+ }\r
+ break;\r
+ \r
+ case $CONF['SpecialskinKey']:\r
+ $i++;\r
+ if ( $i < sizeof($data) )\r
+ {\r
+ $special = $data[$i];\r
+ $_REQUEST['special'] = $special;\r
+ }\r
+ break;\r
+ \r
+ default:\r
+ // skip...\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+/*\r
+ * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.\r
+ * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking\r
+ * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on\r
+ * the values of something like catid or itemid\r
+ * New in 3.60\r
+ */\r
+$manager->notify(\r
+ 'PostParseURL',\r
+ array(\r
+ /* e.g. item, blog, ... */\r
+ 'type' => basename(serverVar('SCRIPT_NAME') ),\r
+ 'info' => $virtualpath\r
+ )\r
+);\r
+\r
+/*\r
+ * NOTE: Here is the end of initialization\r
+ */\r
+\r
+ /**\r
+ * This function includes or requires the specified library file\r
+ * @param string $file\r
+ * @param bool $once use the _once() version\r
+ * @param bool $require use require() instead of include()\r
+ */\r
+ function include_libs($file, $once = TRUE, $require = TRUE)\r
+ {\r
+ global $DIR_LIBS;\r
+\r
+ // begin if: $DIR_LIBS isn't a directory\r
+ if ( !is_dir($DIR_LIBS) )\r
+ {\r
+ exit;\r
+ } // end if\r
+\r
+ $lib_path = $DIR_LIBS . $file;\r
+\r
+ // begin if: \r
+ if ( $once && $require )\r
+ {\r
+ require_once($lib_path);\r
+ }\r
+ else if ( $once && !$require )\r
+ {\r
+ include_once($lib_path);\r
+ }\r
+ else if ( $require )\r
+ {\r
+ require($lib_path);\r
+ }\r
+ else\r
+ {\r
+ include($lib_path);\r
+ } // end if\r
+\r
+ }\r
+\r
+\r
+ /**\r
+ * This function includes or requires the specified plugin file\r
+ * @param string $file\r
+ * @param bool $once use the _once() version\r
+ * @param bool $require use require() instead of include()\r
+ */\r
+ function include_plugins($file, $once = TRUE, $require = TRUE)\r
+ {\r
+ global $DIR_PLUGINS;\r
+\r
+ // begin if: $DIR_LIBS isn't a directory\r
+ if ( !is_dir($DIR_PLUGINS) )\r
+ {\r
+ exit;\r
+ } // end if\r
+\r
+ $plugin_path = $DIR_PLUGINS . $file;\r
+\r
+ // begin if: \r
+ if ( $once && $require )\r
+ {\r
+ require_once($plugin_path);\r
+ }\r
+ else if ( $once && !$require )\r
+ {\r
+ include_once($plugin_path);\r
+ }\r
+ elseif ( $require )\r
+ {\r
+ require($plugin_path);\r
+ }\r
+ else\r
+ {\r
+ include($plugin_path);\r
+ }\r
+ }\r
+ \r
+ /**\r
+ * This function decide which locale is used and include translation\r
+ * @param string $locale locale name referring to 'language tags' defined in RFC 5646\r
+ * @return Void\r
+ */\r
+ function include_translation($locale)\r
+ {\r
+ global $DIR_LOCALES;\r
+ \r
+ $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';\r
+ if ( !file_exists($translation_file) )\r
+ {\r
+ $locale = 'en_Latn_US';\r
+ $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';\r
+ }\r
+ include($translation_file);\r
+ return;\r
+ }\r
+ \r
+ /**\r
+ * This function returns the integer value of $_POST for the variable $name\r
+ * @param string $name field to get the integer value of\r
+ * @return int\r
+ */\r
+ function intPostVar($name)\r
+ {\r
+ return intval(postVar($name));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns the integer value of $_GET for the variable $name\r
+ * @param string $name field to get the integer value of\r
+ * @return int\r
+ */\r
+ function intGetVar($name)\r
+ {\r
+ return intval(getVar($name));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST\r
+ * @param string $name field to get the integer value of\r
+ * @return int\r
+ */\r
+ function intRequestVar($name)\r
+ {\r
+ return intval(requestVar($name));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns the integer value of $_COOKIE for the variable $name\r
+ * @param string $name field to get the integer value of\r
+ * @return int\r
+ */\r
+ function intCookieVar($name)\r
+ {\r
+ return intval(cookieVar($name));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)\r
+ * @return int\r
+ */\r
+ function getNucleusVersion()\r
+ {\r
+ return 400;\r
+ }\r
+\r
+\r
+ /**\r
+ * TODO: Better description of this function.\r
+ *\r
+ * Power users can install patches in between nucleus releases. These patches\r
+ * usually add new functionality in the plugin API and allow those to\r
+ * be tested without having to install CVS.\r
+ *\r
+ * @return int\r
+ */\r
+ function getNucleusPatchLevel()\r
+ {\r
+ return 0;\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data\r
+ * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02\r
+ * @return string|bool\r
+ */\r
+ function getLatestVersion()\r
+ {\r
+ // begin if: cURL is not available in this PHP installation\r
+ if ( !function_exists('curl_init') )\r
+ {\r
+ return FALSE;\r
+ } // end if\r
+\r
+ $curl = curl_init();\r
+ $timeout = 5;\r
+ curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');\r
+ curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);\r
+ curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);\r
+ $return = curl_exec($curl);\r
+ curl_close($curl);\r
+ return $return;\r
+ }\r
+\r
+\r
+ /**\r
+ * This function returns a Nucleus table name with the appropriate prefix\r
+ * @param string $name\r
+ * @return string\r
+ */\r
+ function sql_table($name)\r
+ {\r
+ global $MYSQL_PREFIX;\r
+\r
+ // begin if: no MySQL prefix\r
+ if ( empty($MYSQL_PREFIX) )\r
+ {\r
+ return 'nucleus_' . $name;\r
+ }\r
+ // else: use MySQL prefix\r
+ else\r
+ {\r
+ return $MYSQL_PREFIX . 'nucleus_' . $name;\r
+ } // end if\r
+\r
+ }\r
+\r
+\r
+ /**\r
+ * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.\r
+ *\r
+ * This function sends the Content-Type header if headers have not already been sent\r
+ * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.\r
+ * @param string $content_type\r
+ * @param string $page_type\r
+ * @param string $charset Deprecated. This has no meaning.\r
+ */\r
+ function sendContentType($content_type, $page_type = '', $charset = _CHARSET)\r
+ {\r
+ global $manager, $CONF;\r
+ \r
+ if ( !headers_sent() )\r
+ {\r
+ // if content type is application/xhtml+xml, only send it to browsers\r
+ // that can handle it (IE6 cannot). Otherwise, send text/html\r
+\r
+ // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)\r
+ // application/xhtml+xml still causes too much problems with the javascript implementations\r
+\r
+ // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,\r
+ // application/xhtml+xml seems to be working, so we're going to use it if we can.\r
+\r
+ if ( ($content_type == 'application/xhtml+xml')\r
+ && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )\r
+ {\r
+ $content_type = 'text/html';\r
+ } // end if\r
+\r
+ $manager->notify(\r
+ 'PreSendContentType',\r
+ array(\r
+ 'contentType' => &$content_type,\r
+ 'charset' => i18n::get_current_charset(),\r
+ 'pageType' => $page_type\r
+ )\r
+ );\r
+\r
+ // strip strange characters\r
+ $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);\r
+ header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());\r
+ } // end if\r
+\r
+ }\r
+\r
+\r
+ /**\r
+ * This function parses a query into an array of expressions that can be passed on to the highlight method\r
+ * @param string $query\r
+ */\r
+ function parseHighlight($query)\r
+ {\r
+ // TODO: add more intelligent splitting logic\r
+ \r
+ // get rid of quotes\r
+ $query = preg_replace('/\'|"/', '', $query);\r
+ \r
+ if ( !$query )\r
+ {\r
+ return array();\r
+ }\r
+ \r
+ $aHighlight = preg_split('# #', $query);\r
+ \r
+ for ( $i = 0; $i < count($aHighlight); $i++ )\r
+ {\r
+ $aHighlight[$i] = trim($aHighlight[$i]);\r
+ \r
+ if ( i18n::strlen($aHighlight[$i]) < 3 )\r
+ {\r
+ unset($aHighlight[$i]);\r
+ }\r
+ }\r
+ \r
+ if ( count($aHighlight) == 1 )\r
+ {\r
+ return $aHighlight[0];\r
+ }\r
+ else\r
+ {\r
+ return $aHighlight;\r
+ }\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the blog ID from the blog name\r
+ * @param string $name\r
+ * @return\r
+ */\r
+ function getBlogIDFromName($name)\r
+ {\r
+ return quickQuery('SELECT bnumber AS result FROM ' . sql_table('blog') . ' WHERE bshortname = "' . sql_real_escape_string($name) . '"');\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the blog name from the blog ID\r
+ * @param int $id\r
+ * @return object\r
+ */\r
+ function getBlogNameFromID($id)\r
+ {\r
+ return quickQuery('SELECT bname AS result FROM ' . sql_table('blog') . ' WHERE bnumber = ' . intval($id));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the blog ID from the item ID\r
+ * @param int $item_id\r
+ * @return object\r
+ */\r
+ function getBlogIDFromItemID($item_id)\r
+ {\r
+ return quickQuery('SELECT iblog AS result FROM ' . sql_table('item') . ' WHERE inumber = ' . intval($item_id));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the blog ID from the comment ID\r
+ * @param int $comment_id\r
+ * @return object\r
+ */\r
+ function getBlogIDFromCommentID($comment_id)\r
+ {\r
+ return quickQuery('SELECT cblog AS result FROM ' . sql_table('comment') . ' WHERE cnumber = ' . intval($comment_id));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the blog ID from the category ID\r
+ * @param int $category_id\r
+ * @return object\r
+ */\r
+ function getBlogIDFromCatID($category_id)\r
+ {\r
+ return quickQuery('SELECT cblog AS result FROM ' . sql_table('category') . ' WHERE catid = ' . intval($category_id));\r
+ }\r
+\r
+\r
+ /**\r
+ * This function gets the category ID from the category name\r
+ * @param int $name\r
+ * @return object\r
+ */\r
+ function getCatIDFromName($name)\r
+ {\r
+ return quickQuery('SELECT catid AS result FROM ' . sql_table('category') . ' WHERE cname = "' . sql_real_escape_string($name) . '"');\r
+ }\r
+\r
+\r
+ /**\r
+ * This function performs a quick SQL query\r
+ * @param string $query\r
+ * @return object\r
+ */\r
+ function quickQuery($query)\r
+ {\r
+ $res = sql_query($query);\r
+ $obj = sql_fetch_object($res);\r
+ return $obj->result;\r
+ }\r
+\r
+function getPluginNameFromPid($pid) {\r
+ $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );\r
+ $obj = sql_fetch_object($res);\r
+ return $obj->pfile;\r
+// return isset($obj->pfile) ? $obj->pfile : false;\r
+}\r
+\r
+function selector()\r
+{\r
+ global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;\r
+ global $archive, $skinid, $blog, $memberinfo, $CONF, $member;\r
+ global $imagepopup, $catid, $special;\r
+ global $manager;\r
+ \r
+ $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');\r
+ $action = requestVar('action');\r
+ \r
+ if ( in_array($action, $actionNames) )\r
+ {\r
+ global $DIR_LIBS, $errormessage;\r
+ include_once($DIR_LIBS . 'ACTION.php');\r
+ $a = new Action();\r
+ $errorInfo = $a->doAction($action);\r
+ \r
+ if ( $errorInfo )\r
+ {\r
+ $errormessage = $errorInfo['message'];\r
+ }\r
+ }\r
+ \r
+ // show error when headers already sent out\r
+ if ( headers_sent() && $CONF['alertOnHeadersSent'] )\r
+ {\r
+ // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)\r
+ if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )\r
+ {\r
+ headers_sent($hsFile, $hsLine);\r
+ $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';\r
+ }\r
+ else\r
+ {\r
+ $extraInfo = '';\r
+ }\r
+ \r
+ startUpError(\r
+ '<p>The page headers have already been sent out' . $extraInfo . '. This could cause Nucleus not to work in the expected way.</p><p>Usually, this is caused by spaces or newlines at the end of the <code>config.php</code> file, at the end of the translation file or at the end of a plugin file. Please check this and try again.</p><p>If you don\'t want to see this error message again, without solving the problem, set <code>$CONF[\'alertOnHeadersSent\']</code> in <code>globalfunctions.php</code> to <code>0</code></p>',\r
+ 'Page headers already sent'\r
+ );\r
+ exit;\r
+ }\r
+ \r
+ // make is so ?archivelist without blogname or blogid shows the archivelist\r
+ // for the default weblog\r
+ if ( serverVar('QUERY_STRING') == 'archivelist' )\r
+ {\r
+ $archivelist = $CONF['DefaultBlog'];\r
+ }\r
+ \r
+ // now decide which type of skin we need\r
+ if ( $itemid )\r
+ {\r
+ // itemid given -> only show that item\r
+ $type = 'item';\r
+ \r
+ if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )\r
+ {\r
+ doError(_ERROR_NOSUCHITEM);\r
+ }\r
+ \r
+ global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;\r
+ \r
+ // 1. get timestamp, blogid and catid for item\r
+ $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';\r
+ $query = sprintf($query, sql_table('item'), (integer) $itemid);\r
+ $res = sql_query($query);\r
+ $obj = sql_fetch_object($res);\r
+ \r
+ // if a different blog id has been set through the request or selectBlog(),\r
+ // deny access\r
+ \r
+ if ( $blogid && (intval($blogid) != $obj->iblog) )\r
+ {\r
+ doError(_ERROR_NOSUCHITEM);\r
+ }\r
+ \r
+ // if a category has been selected which doesn't match the item, ignore the\r
+ // category. #85\r
+ if ( ($catid != 0) && ($catid != $obj->icat) )\r
+ {\r
+ $catid = 0;\r
+ }\r
+ \r
+ $blogid = $obj->iblog;\r
+ $timestamp = strtotime($obj->itime);\r
+ \r
+ $b =& $manager->getBlog($blogid);\r
+ \r
+ if ( !$b->isValidCategory($catid) )\r
+ {\r
+ $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";\r
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);\r
+ }\r
+ else\r
+ {\r
+ $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime DESC LIMIT 1";\r
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);\r
+ }\r
+ \r
+ $res = sql_query($query);\r
+ $obj = sql_fetch_object($res);\r
+ \r
+ if ( $obj )\r
+ {\r
+ $itemidprev = $obj->inumber;\r
+ $itemtitleprev = $obj->ititle;\r
+ }\r
+ \r
+ // get next itemid and title\r
+ if ( !$b->isValidCategory($catid) )\r
+ {\r
+ $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d ORDER BY itime ASC LIMIT 1";\r
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);\r
+ }\r
+ else\r
+ {\r
+ $query = "SELECT inumber, ititle FROM %s WHERE itime>'%s' AND itime<='%s' AND idraft=0 AND iblog=%d AND icat=%d ORDER BY itime ASC LIMIT 1";\r
+ $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);\r
+ }\r
+ $res = sql_query($query);\r
+ \r
+ $obj = sql_fetch_object($res);\r
+ \r
+ if ( $obj )\r
+ {\r
+ $itemidnext = $obj->inumber;\r
+ $itemtitlenext = $obj->ititle;\r
+ }\r
+ }\r
+ elseif ( $archive )\r
+ {\r
+ // show archive\r
+ $type = 'archive';\r
+ \r
+ // get next and prev month links ...\r
+ global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;\r
+ \r
+ // sql queries for the timestamp of the first and the last published item\r
+ $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";\r
+ $first_timestamp=quickQuery ($query);\r
+ $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";\r
+ $last_timestamp=quickQuery ($query);\r
+ \r
+ sscanf($archive, '%d-%d-%d', $y, $m, $d);\r
+ \r
+ if ( $d != 0 )\r
+ {\r
+ $archivetype = _ARCHIVETYPE_DAY;\r
+ $t = mktime(0, 0, 0, $m, $d, $y);\r
+ // one day has 24 * 60 * 60 = 86400 seconds\r
+ $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 );\r
+ // check for published items\r
+ if ( $t > $first_timestamp )\r
+ {\r
+ $archiveprevexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archiveprevexists = false;\r
+ }\r
+ \r
+ // one day later\r
+ $t += 86400;\r
+ $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t);\r
+ if ( $t < $last_timestamp )\r
+ {\r
+ $archivenextexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archivenextexists = false;\r
+ }\r
+ }\r
+ elseif ( $m == 0 )\r
+ {\r
+ $archivetype = _ARCHIVETYPE_YEAR;\r
+ $t = mktime(0, 0, 0, 12, 31, $y - 1);\r
+ // one day before is in the previous year\r
+ $archiveprev = i18n::formatted_datetime('%Y', $t);\r
+ if ( $t > $first_timestamp )\r
+ {\r
+ $archiveprevexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archiveprevexists = false;\r
+ }\r
+\r
+ // timestamp for the next year\r
+ $t = mktime(0, 0, 0, 1, 1, $y + 1);\r
+ $archivenext = i18n::formatted_datetime('%Y', $t);\r
+ if ( $t < $last_timestamp )\r
+ {\r
+ $archivenextexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archivenextexists = false;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ $archivetype = _ARCHIVETYPE_MONTH;\r
+ $t = mktime(0, 0, 0, $m, 1, $y);\r
+ // one day before is in the previous month\r
+ $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400);\r
+ if ( $t > $first_timestamp )\r
+ {\r
+ $archiveprevexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archiveprevexists = false;\r
+ }\r
+ \r
+ // timestamp for the next month\r
+ $t = mktime(0, 0, 0, $m+1, 1, $y);\r
+ $archivenext = i18n::formatted_datetime('%Y-%m', $t);\r
+ if ( $t < $last_timestamp )\r
+ {\r
+ $archivenextexists = true;\r
+ }\r
+ else\r
+ {\r
+ $archivenextexists = false;\r
+ }\r
+ }\r
+ }\r
+ elseif ( $archivelist )\r
+ {\r
+ $type = 'archivelist';\r
+ \r
+ if ( is_numeric($archivelist) )\r
+ {\r
+ $blogid = intVal($archivelist);\r
+ }\r
+ else\r
+ {\r
+ $blogid = getBlogIDFromName($archivelist);\r
+ }\r
+ \r
+ if ( !$blogid )\r
+ {\r
+ doError(_ERROR_NOSUCHBLOG);\r
+ }\r
+ }\r
+ elseif ( $query )\r
+ {\r
+ global $startpos;\r
+ $type = 'search';\r
+ $query = stripslashes($query);\r
+ \r
+ if ( is_numeric($blogid) )\r
+ {\r
+ $blogid = intVal($blogid);\r
+ }\r
+ else\r
+ {\r
+ $blogid = getBlogIDFromName($blogid);\r
+ }\r
+ \r
+ if ( !$blogid )\r
+ {\r
+ doError(_ERROR_NOSUCHBLOG);\r
+ }\r
+ }\r
+ elseif ( $memberid )\r
+ {\r
+ $type = 'member';\r
+ \r
+ if ( !Member::existsID($memberid) )\r
+ {\r
+ doError(_ERROR_NOSUCHMEMBER);\r
+ }\r
+ $memberinfo = $manager->getMember($memberid);\r
+ }\r
+ elseif ( $imagepopup )\r
+ {\r
+ // media object (images etc.)\r
+ $type = 'imagepopup';\r
+ \r
+ // TODO: check if media-object exists\r
+ // TODO: set some vars?\r
+ }\r
+ else\r
+ {\r
+ // show regular index page\r
+ global $startpos;\r
+ $type = 'index';\r
+ }\r
+ \r
+ // any type of skin with catid\r
+ if ( $catid && !$blogid )\r
+ {\r
+ $blogid = getBlogIDFromCatID($catid);\r
+ }\r
+ \r
+ // decide which blog should be displayed\r
+ if ( !$blogid )\r
+ {\r
+ $blogid = $CONF['DefaultBlog'];\r
+ }\r
+ \r
+ $b =& $manager->getBlog($blogid);\r
+ $blog = $b; // references can't be placed in global variables?\r
+ \r
+ if ( !$blog->isValid )\r
+ {\r
+ doError(_ERROR_NOSUCHBLOG);\r
+ }\r
+ \r
+ // set catid if necessary\r
+ if ( $catid )\r
+ {\r
+ // check if the category is valid\r
+ if ( !$blog->isValidCategory($catid) )\r
+ {\r
+ doError(_ERROR_NOSUCHCATEGORY);\r
+ }\r
+ else\r
+ {\r
+ $blog->setSelectedCategory($catid);\r
+ }\r
+ }\r
+ \r
+ // decide which skin should be used\r
+ if ( $skinid != '' && ($skinid == 0) )\r
+ {\r
+ selectSkin($skinid);\r
+ }\r
+ \r
+ if ( !$skinid )\r
+ {\r
+ $skinid = $blog->getDefaultSkin();\r
+ }\r
+ \r
+ //$special = requestVar('special'); //get at top of file as global\r
+ if ( !empty($special) && isValidShortName($special) )\r
+ {\r
+ $type = strtolower($special);\r
+ }\r
+ \r
+ $skin = new SKIN($skinid);\r
+ \r
+ if ( !$skin->isValid() )\r
+ {\r
+ doError(_ERROR_NOSUCHSKIN);\r
+ }\r
+ \r
+ // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude\r
+ global $skinpart;\r
+ $skinpart = $type;\r
+ \r
+ // parse the skin\r
+ $skin->parse($type);\r
+ \r
+ // check to see we should throw JustPosted event\r
+ $blog->checkJustPosted();\r
+ return;\r
+}\r
+\r
+/**\r
+ * Show error skin with given message. An optional skin-object to use can be given\r
+ */\r
+function doError($msg, $skin = '')\r
+{\r
+ global $errormessage, $CONF, $skinid, $blogid, $manager;\r
+ \r
+ if ( $skin == '' )\r
+ {\r
+ if ( Skin::existsID($skinid) )\r
+ {\r
+ $id = $skinid;\r
+ }\r
+ elseif ( $manager->existsBlogID($blogid) )\r
+ {\r
+ $blog =& $manager->getBlog($blogid);\r
+ $id = $blog->getDefaultSkin();\r
+ }\r
+ elseif ($CONF['DefaultBlog'] )\r
+ {\r
+ $blog =& $manager->getBlog($CONF['DefaultBlog']);\r
+ $id = $blog->getDefaultSkin();\r
+ }\r
+ else\r
+ {\r
+ // this statement should actually never be executed\r
+ $id = $CONF['BaseSkin'];\r
+ }\r
+ $skin = new Skin($id);\r
+ }\r
+ \r
+ $skinid = $skin->getID();\r
+ $errormessage = $msg;\r
+ $skin->parse('error');\r
+ exit;\r
+}\r
+\r
+function getConfig() {\r
+ global $CONF;\r
+\r
+ $query = 'SELECT * FROM ' . sql_table('config');\r
+ $res = sql_query($query);\r
+\r
+ while ($obj = sql_fetch_object($res) ) {\r
+ $CONF[$obj->name] = $obj->value;\r
+ }\r
+}\r
+\r
+// some checks for names of blogs, categories, templates, members, ...\r
+function isValidShortName($name) {\r
+\r
+ # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+ # original eregi: eregi('^[a-z0-9]+$', $name)\r
+\r
+ return preg_match('#^[a-z0-9]+$#i', $name);\r
+\r
+}\r
+\r
+function isValidDisplayName($name) {\r
+\r
+ # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+ # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)\r
+\r
+ return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);\r
+\r
+}\r
+\r
+function isValidCategoryName($name) {\r
+ return 1;\r
+}\r
+\r
+function isValidTemplateName($name) {\r
+\r
+ # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+ # original eregi: eregi('^[a-z0-9/]+$', $name)\r
+ // added - and _ to valid characters as of 4.00\r
+\r
+ return preg_match('#^[a-z0-9/_\-]+$#i', $name);\r
+\r
+}\r
+\r
+function isValidSkinName($name) {\r
+\r
+ # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0\r
+ # original eregi: eregi('^[a-z0-9/]+$', $name);\r
+ // added - and _ to valid characters as of 4.00\r
+\r
+ return preg_match('#^[a-z0-9/_\-]+$#i', $name);\r
+\r
+}\r
+\r
+// add and remove linebreaks\r
+function addBreaks($var) {\r
+ return nl2br($var);\r
+}\r
+\r
+function removeBreaks($var) {\r
+ return preg_replace("/<br \/>([\r\n])/", "$1", $var);\r
+}\r
+\r
+/**\r
+ * functions for use in index.php\r
+ */\r
+function selectBlog($shortname) {\r
+ global $blogid, $archivelist;\r
+ $blogid = getBlogIDFromName($shortname);\r
+\r
+ // also force archivelist variable, if it is set\r
+ if ($archivelist) {\r
+ $archivelist = $blogid;\r
+ }\r
+}\r
+\r
+function selectSkin($skinname) {\r
+ global $skinid;\r
+ $skinid = SKIN::getIdFromName($skinname);\r
+}\r
+\r
+/**\r
+ * Can take either a category ID or a category name (be aware that\r
+ * multiple categories can have the same name)\r
+ */\r
+function selectCategory($cat) {\r
+ global $catid;\r
+ if (is_numeric($cat) ) {\r
+ $catid = intval($cat);\r
+ } else {\r
+ $catid = getCatIDFromName($cat);\r
+ }\r
+}\r
+\r
+function selectItem($id) {\r
+ global $itemid;\r
+ $itemid = intval($id);\r
+}\r
+\r
+function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
{
- /* report all errors! */
- error_reporting(E_ALL);
-}
-else
-{
- ini_set('display_errors','0');
- error_reporting(E_ERROR | E_WARNING | E_PARSE);
-}
-
-/*
- * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
- */
-if ( !isset($DIR_LOCALES) )
-{
- $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
-}
-global $DIR_LANG;
-if ( !isset($DIR_LANG) )
-{
- $DIR_LANG = $DIR_LOCALES;
-}
-
-/*
- * load and initialize i18n class
- */
-if (!class_exists('i18n', FALSE))
-{
- include($DIR_LIBS . 'i18n.php');
-}
-if ( !i18n::init('UTF-8', $DIR_LOCALES) )
-{
- exit('Fail to initialize i18n class.');
-}
-/*
- * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
- */
-define('_CHARSET', i18n::get_current_charset());
-
-/*
- * Indicates when Nucleus should display startup errors. Set to 1 if you want
- * the error enabled (default), false otherwise
- *
- * alertOnHeadersSent
- * Displays an error when visiting a public Nucleus page and headers have
- * been sent out to early. This usually indicates an error in either a
- * configuration file or a translation file, and could cause Nucleus to
- * malfunction
- * alertOnSecurityRisk
- * Displays an error only when visiting the admin area, and when one or
- * more of the installation files (install.php, install.sql, upgrades/
- * directory) are still on the server.
- */
-if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )
-{
- $CONF['alertOnHeadersSent'] = 1;
-}
-$CONF['alertOnSecurityRisk'] = 1;
-/*
- * NOTE: this should be removed when releasing 4.0
-$CONF['ItemURL'] = $CONF['Self'];
-$CONF['ArchiveURL'] = $CONF['Self'];
-$CONF['ArchiveListURL'] = $CONF['Self'];
-$CONF['MemberURL'] = $CONF['Self'];
-$CONF['SearchURL'] = $CONF['Self'];
-$CONF['BlogURL'] = $CONF['Self'];
-$CONF['CategoryURL'] = $CONF['Self'];
-*/
-
-/*
- * Set these to 1 to allow viewing of future items or draft items
- * Should really never do this, but can be useful for some plugins that might need to
- * Could cause some other issues if you use future posts otr drafts
- * So use with care
- */
-$CONF['allowDrafts'] = 0;
-$CONF['allowFuture'] = 0;
-
-if ( getNucleusPatchLevel() > 0 )
-{
- $nucleus['version'] .= '/' . getNucleusPatchLevel();
-}
-
-/* Avoid notices */
-if ( !isset($CONF['installscript']) )
-{
- $CONF['installscript'] = 0;
-}
-
-/* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/
-if ( $CONF['installscript'] != 1 )
-{
- /* vars were already included in install.php */
- include_once($DIR_LIBS . 'vars4.1.0.php');
-}
-
-/* sanitize option */
-$bLoggingSanitizedResult=0;
-$bSanitizeAndContinue=0;
-
-$orgRequestURI = serverVar('REQUEST_URI');
-sanitizeParams();
-
-/* get all variables that can come from the request and put them in the global scope */
-$blogid = requestVar('blogid');
-$itemid = intRequestVar('itemid');
-$catid = intRequestVar('catid');
-$skinid = requestVar('skinid');
-$memberid = requestVar('memberid');
-$archivelist = requestVar('archivelist');
-$imagepopup = requestVar('imagepopup');
-$archive = requestVar('archive');
-$query = requestVar('query');
-$highlight = requestVar('highlight');
-$amount = requestVar('amount');
-$action = requestVar('action');
-$nextaction = requestVar('nextaction');
-$maxresults = requestVar('maxresults');
-$startpos = intRequestVar('startpos');
-$errormessage = '';
-$error = '';
-$special = requestVar('special');
-$virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));
-
-if ( !headers_sent() )
-{
- header('Generator: Nucleus CMS ' . $nucleus['version']);
-}
-
-/* include core classes that are needed for login & plugin handling */
-include_once($DIR_LIBS . 'mysql.php');
-/* added for 3.5 sql_* wrapper */
-global $MYSQL_HANDLER;
-if ( !isset($MYSQL_HANDLER) )
-{
- $MYSQL_HANDLER = array('mysql','');
-}
-if ( $MYSQL_HANDLER[0] == '' )
-{
- $MYSQL_HANDLER[0] = 'mysql';
-}
-include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');
-/* end new for 3.5 sql_* wrapper */
-include($DIR_LIBS . 'MEMBER.php');
-include($DIR_LIBS . 'ACTIONLOG.php');
-include($DIR_LIBS . 'MANAGER.php');
-include($DIR_LIBS . 'PLUGIN.php');
-
-$manager =& MANAGER::instance();
-
-/*
- * make sure there's no unnecessary escaping:
- * set_magic_quotes_runtime(0);
- */
-if ( version_compare(PHP_VERSION, '5.3.0', '<') )
-{
- ini_set('magic_quotes_runtime', '0');
-}
-
-/* Avoid notices */
-if ( !array_key_exists('UsingAdminArea', $CONF) )
-{
- $CONF['UsingAdminArea'] = 0;
-}
-
-/* only needed when updating logs */
-if ( $CONF['UsingAdminArea'] )
-{
- /* XML-RPC client classes */
- include($DIR_LIBS . 'xmlrpc.inc.php');
- include_once($DIR_LIBS . 'ADMIN.php');
-}
-
-/* connect to database */
-sql_connect();
-$SQLCount = 0;
-
-/* logs sanitized result if need */
-if ( $orgRequestURI!==serverVar('REQUEST_URI') )
-{
- $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";
- $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');
- if ( $bLoggingSanitizedResult )
- {
- addToLog(WARNING, $msg);
- }
- if ( !$bSanitizeAndContinue )
- {
- die("");
- }
-}
-
-/* makes sure database connection gets closed on script termination */
-register_shutdown_function('sql_disconnect');
-
-/* read config */
-getConfig();
-
-/*
- * FIXME: This is for backward compatibility, should be obsoleted near future.
- */
-if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])
- && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )
-{
- $CONF['Locale'] = 'en_Latn_US';
-}
-if ( !array_key_exists('Language', $CONF) )
-{
- $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);
-}
-$locale = $CONF['Locale'];
-
-/* Properly set $CONF['Self'] and others if it's not set...
- * usually when we are access from admin menu
- */
-if ( !array_key_exists('Self', $CONF) )
-{
- $CONF['Self'] = $CONF['IndexURL'];
- /* strip trailing */
- if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )
- {
- $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);
- }
-}
-
-$CONF['ItemURL'] = $CONF['Self'];
-$CONF['ArchiveURL'] = $CONF['Self'];
-$CONF['ArchiveListURL'] = $CONF['Self'];
-$CONF['MemberURL'] = $CONF['Self'];
-$CONF['SearchURL'] = $CONF['Self'];
-$CONF['BlogURL'] = $CONF['Self'];
-$CONF['CategoryURL'] = $CONF['Self'];
-
-/*
- *switch URLMode back to normal when $CONF['Self'] ends in .php
- * this avoids urls like index.php/item/13/index.php/item/15
- */
-if ( !array_key_exists('URLMode', $CONF) || (($CONF['URLMode'] == 'pathinfo')
- && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
-{
- $CONF['URLMode'] = 'normal';
-}
-
-/* automatically use simpler toolbar for mozilla */
-if ( ($CONF['DisableJsTools'] == 0)
- && strstr(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0')
- && strstr(serverVar('HTTP_USER_AGENT'), 'Gecko') )
-{
- $CONF['DisableJsTools'] = 2;
-}
-
-$member = new MEMBER();
-
-if ( $action == 'login' )
-{
- $login = postVar('login');
- $password = postVar('password');
- $shared = intPostVar('shared');
- $member->login($login, $password, $shared);
-}
-elseif ( ($action == 'logout') )
-{
- $member->logout();
-}
-else
-{
- $member->cookielogin();
-}
-
-/* NOTE: include translation file and set locale */
-if ( $member->isLoggedIn() && !$member->getLocale())
-{
- $locale = $member->getLocale();
-}
-include_translation($locale);
-i18n::set_current_locale($locale);
-
-/* login completed */
-$manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );
-
-/* next action */
-if ( $member->isLoggedIn() && $nextaction )
-{
- $action = $nextaction;
-}
-
-/*
- * Release ticket for plugin
- */
-ticketForPlugin();
-
-/* first, let's see if the site is disabled or not. always allow admin area access. */
-if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )
-{
- redirect($CONF['DisableSiteURL']);
- exit;
-}
-
-/* load other classes */
-include($DIR_LIBS . 'PARSER.php');
-include($DIR_LIBS . 'SKIN.php');
-include($DIR_LIBS . 'TEMPLATE.php');
-include($DIR_LIBS . 'BLOG.php');
-include($DIR_LIBS . 'BODYACTIONS.php');
-include($DIR_LIBS . 'COMMENTS.php');
-include($DIR_LIBS . 'COMMENT.php');
-/* include($DIR_LIBS . 'ITEM.php'); */
-include($DIR_LIBS . 'NOTIFICATION.php');
-include($DIR_LIBS . 'BAN.php');
-include($DIR_LIBS . 'PAGEFACTORY.php');
-include($DIR_LIBS . 'SEARCH.php');
-include($DIR_LIBS . 'ENTITY.php');
-include($DIR_LIBS . 'LINK.php');
-
-/* set lastVisit cookie (if allowed) */
-if ( !headers_sent() )
-{
- if ( $CONF['LastVisit'] )
- {
- setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
- }
- else
- {
- setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
- }
-}
-
-if ( !defined('_ARCHIVETYPE_MONTH') )
-{
- define('_ARCHIVETYPE_DAY', 'day');
- define('_ARCHIVETYPE_MONTH', 'month');
- define('_ARCHIVETYPE_YEAR', 'year');
-}
-
-/* decode path_info */
-if ( $CONF['URLMode'] == 'pathinfo' )
-{
- /* initialize keywords if this hasn't been done before */
- if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )
- {
- $CONF['ItemKey'] = 'item';
- }
-
- if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )
- {
- $CONF['ArchiveKey'] = 'archive';
- }
-
- if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )
- {
- $CONF['ArchivesKey'] = 'archives';
- }
-
- if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )
- {
- $CONF['MemberKey'] = 'member';
- }
-
- if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )
- {
- $CONF['BlogKey'] = 'blog';
- }
-
- if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )
- {
- $CONF['CategoryKey'] = 'category';
- }
-
- if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )
- {
- $CONF['SpecialskinKey'] = 'special';
- }
-
- $parsed = false;
- $manager->notify(
- 'ParseURL',
- array(
- /* e.g. item, blog, ... */
- 'type' => basename(serverVar('SCRIPT_NAME') ),
- 'info' => $virtualpath,
- 'complete' => &$parsed
- )
- );
-
- if ( !$parsed )
- {
- /* default implementation */
- $data = i18n::explode("/", $virtualpath );
- for ( $i = 0; $i < sizeof($data); $i++ )
- {
- switch ( $data[$i] )
- {
- /* item/1 (blogid) */
- case $CONF['ItemKey']:
- $i++;
-
- if ( $i < sizeof($data) )
- {
- $itemid = intval($data[$i]);
- }
- break;
-
- /* archives/1 (blogid) */
- case $CONF['ArchivesKey']:
- $i++;
- if ( $i < sizeof($data) )
- {
- $archivelist = intval($data[$i]);
- }
- break;
-
- /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
- case $CONF['ArchiveKey']:
- if ( (($i + 1) < sizeof($data) ) && (!strstr($data[$i + 1], '-') ) )
- {
- $blogid = intval($data[++$i]);
- }
- $i++;
- if ( $i < sizeof($data) )
- {
- $archive = $data[$i];
- }
- break;
-
- /* blogid/1 */
- case 'blogid':
- /* blog/1 */
- case $CONF['BlogKey']:
- $i++;
- if ( $i < sizeof($data) )
- {
- $blogid = intval($data[$i]);
- }
- break;
-
- /* category/1 (catid) */
- case $CONF['CategoryKey']:
- case 'catid':
- $i++;
- if ( $i < sizeof($data) )
- {
- $catid = intval($data[$i]);
- }
- break;
-
- case $CONF['MemberKey']:
- $i++;
- if ( $i < sizeof($data) )
- {
- $memberid = intval($data[$i]);
- }
- break;
-
- case $CONF['SpecialskinKey']:
- $i++;
- if ( $i < sizeof($data) )
- {
- $special = $data[$i];
- $_REQUEST['special'] = $special;
- }
- break;
-
- default:
- // skip...
- }
- }
- }
-}
-
-/*
- * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.
- * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking
- * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on
- * the values of something like catid or itemid
- * New in 3.60
- */
-$manager->notify(
- 'PostParseURL',
- array(
- /* e.g. item, blog, ... */
- 'type' => basename(serverVar('SCRIPT_NAME') ),
- 'info' => $virtualpath
- )
-);
-
-/*
- * NOTE: Here is the end of initialization
- */
-
- /**
- * This function includes or requires the specified library file
- * @param string $file
- * @param bool $once use the _once() version
- * @param bool $require use require() instead of include()
- */
- function include_libs($file, $once = TRUE, $require = TRUE)
- {
- global $DIR_LIBS;
-
- // begin if: $DIR_LIBS isn't a directory
- if ( !is_dir($DIR_LIBS) )
- {
- exit;
- } // end if
-
- $lib_path = $DIR_LIBS . $file;
-
- // begin if:
- if ( $once && $require )
- {
- require_once($lib_path);
- }
- else if ( $once && !$require )
- {
- include_once($lib_path);
- }
- else if ( $require )
- {
- require($lib_path);
- }
- else
- {
- include($lib_path);
- } // end if
-
- }
-
-
- /**
- * This function includes or requires the specified plugin file
- * @param string $file
- * @param bool $once use the _once() version
- * @param bool $require use require() instead of include()
- */
- function include_plugins($file, $once = TRUE, $require = TRUE)
- {
- global $DIR_PLUGINS;
-
- // begin if: $DIR_LIBS isn't a directory
- if ( !is_dir($DIR_PLUGINS) )
- {
- exit;
- } // end if
-
- $plugin_path = $DIR_PLUGINS . $file;
-
- // begin if:
- if ( $once && $require )
- {
- require_once($plugin_path);
- }
- else if ( $once && !$require )
- {
- include_once($plugin_path);
- }
- elseif ( $require )
- {
- require($plugin_path);
- }
- else
- {
- include($plugin_path);
- }
- }
-
- /**
- * This function decide which locale is used and include translation
- * @param string $locale locale name referring to 'language tags' defined in RFC 5646
- * @return Void
- */
- function include_translation($locale)
- {
- global $DIR_LOCALES;
-
- $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';
- if ( !file_exists($translation_file) )
- {
- $locale = 'en_Latn_US';
- $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';
- }
- include($translation_file);
- return;
- }
-
- /**
- * This function returns the integer value of $_POST for the variable $name
- * @param string $name field to get the integer value of
- * @return int
- */
- function intPostVar($name)
- {
- return intval(postVar($name));
- }
-
-
- /**
- * This function returns the integer value of $_GET for the variable $name
- * @param string $name field to get the integer value of
- * @return int
- */
- function intGetVar($name)
- {
- return intval(getVar($name));
- }
-
-
- /**
- * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST
- * @param string $name field to get the integer value of
- * @return int
- */
- function intRequestVar($name)
- {
- return intval(requestVar($name));
- }
-
-
- /**
- * This function returns the integer value of $_COOKIE for the variable $name
- * @param string $name field to get the integer value of
- * @return int
- */
- function intCookieVar($name)
- {
- return intval(cookieVar($name));
- }
-
-
- /**
- * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)
- * @return int
- */
- function getNucleusVersion()
- {
- return 400;
- }
-
-
- /**
- * TODO: Better description of this function.
- *
- * Power users can install patches in between nucleus releases. These patches
- * usually add new functionality in the plugin API and allow those to
- * be tested without having to install CVS.
- *
- * @return int
- */
- function getNucleusPatchLevel()
- {
- return 0;
- }
-
-
- /**
- * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data
- * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02
- * @return string|bool
- */
- function getLatestVersion()
- {
- // begin if: cURL is not available in this PHP installation
- if ( !function_exists('curl_init') )
- {
- return FALSE;
- } // end if
-
- $curl = curl_init();
- $timeout = 5;
- curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');
- curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
- $return = curl_exec($curl);
- curl_close($curl);
- return $return;
- }
-
-
- /**
- * This function returns a Nucleus table name with the appropriate prefix
- * @param string $name
- * @return string
- */
- function sql_table($name)
- {
- global $MYSQL_PREFIX;
-
- // begin if: no MySQL prefix
- if ( empty($MYSQL_PREFIX) )
- {
- return 'nucleus_' . $name;
- }
- // else: use MySQL prefix
- else
- {
- return $MYSQL_PREFIX . 'nucleus_' . $name;
- } // end if
-
- }
-
-
- /**
- * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.
- *
- * This function sends the Content-Type header if headers have not already been sent
- * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.
- * @param string $content_type
- * @param string $page_type
- * @param string $charset Deprecated. This has no meaning.
- */
- function sendContentType($content_type, $page_type = '', $charset = _CHARSET)
- {
- global $manager, $CONF;
-
- if ( !headers_sent() )
- {
- // if content type is application/xhtml+xml, only send it to browsers
- // that can handle it (IE6 cannot). Otherwise, send text/html
-
- // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)
- // application/xhtml+xml still causes too much problems with the javascript implementations
-
- // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,
- // application/xhtml+xml seems to be working, so we're going to use it if we can.
-
- if ( ($content_type == 'application/xhtml+xml')
- && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )
- {
- $content_type = 'text/html';
- } // end if
-
- $manager->notify(
- 'PreSendContentType',
- array(
- 'contentType' => &$content_type,
- 'charset' => i18n::get_current_charset(),
- 'pageType' => $page_type
- )
- );
-
- // strip strange characters
- $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);
- header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());
- } // end if
-
- }
-
-
- /**
- * This function parses a query into an array of expressions that can be passed on to the highlight method
- * @param string $query
- */
- function parseHighlight($query)
- {
- // TODO: add more intelligent splitting logic
-
- // get rid of quotes
- $query = preg_replace('/\'|"/', '', $query);
-
- if ( !$query )
- {
- return array();
- }
-
- $aHighlight = i18n::explode(' ', $query);
-
- for ( $i = 0; $i < count($aHighlight); $i++ )
- {
- $aHighlight[$i] = trim($aHighlight[$i]);
-
- if ( i18n::strlen($aHighlight[$i]) < 3 )
- {
- unset($aHighlight[$i]);
- }
- }
-
- if ( count($aHighlight) == 1 )
- {
- return $aHighlight[0];
- }
- else
- {
- return $aHighlight;
- }
- }
-
-
- /**
- * This function gets the blog ID from the blog name
- * @param string $name
- * @return
- */
- function getBlogIDFromName($name)
- {
- return quickQuery('SELECT `bnumber` AS `result` FROM `' . sql_table('blog') . '` WHERE `bshortname` = "' . sql_real_escape_string($name) . '"');
- }
-
-
- /**
- * This function gets the blog name from the blog ID
- * @param int $id
- * @return object
- */
- function getBlogNameFromID($id)
- {
- return quickQuery('SELECT `bname` AS `result` FROM `' . sql_table('blog') . '` WHERE `bnumber` = ' . intval($id));
- }
-
-
- /**
- * This function gets the blog ID from the item ID
- * @param int $item_id
- * @return object
- */
- function getBlogIDFromItemID($item_id)
- {
- return quickQuery('SELECT `iblog` AS `result` FROM `' . sql_table('item') . '` WHERE `inumber` = ' . intval($item_id));
- }
-
-
- /**
- * This function gets the blog ID from the comment ID
- * @param int $comment_id
- * @return object
- */
- function getBlogIDFromCommentID($comment_id)
- {
- return quickQuery('SELECT `cblog` AS `result` FROM `' . sql_table('comment') . '` WHERE `cnumber` = ' . intval($comment_id));
- }
-
-
- /**
- * This function gets the blog ID from the category ID
- * @param int $category_id
- * @return object
- */
- function getBlogIDFromCatID($category_id)
- {
- return quickQuery('SELECT `cblog` AS `result` FROM `' . sql_table('category') . '` WHERE `catid` = ' . intval($category_id));
- }
-
-
- /**
- * This function gets the category ID from the category name
- * @param int $name
- * @return object
- */
- function getCatIDFromName($name)
- {
- return quickQuery('SELECT `catid` AS `result` FROM `' . sql_table('category') . '` WHERE `cname` = "' . sql_real_escape_string($name) . '"');
- }
-
-
- /**
- * This function performs a quick SQL query
- * @param string $query
- * @return object
- */
- function quickQuery($query)
- {
- $res = sql_query($query);
- $obj = sql_fetch_object($res);
- return $obj->result;
- }
-
-function getPluginNameFromPid($pid) {
- $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );
- $obj = sql_fetch_object($res);
- return $obj->pfile;
-// return isset($obj->pfile) ? $obj->pfile : false;
-}
-
-function selector() {
- global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
- global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
- global $imagepopup, $catid, $special;
- global $manager;
-
- $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');
- $action = requestVar('action');
-
- if ( in_array($action, $actionNames) )
- {
- global $DIR_LIBS, $errormessage;
- include_once($DIR_LIBS . 'ACTION.php');
- $a = new ACTION();
- $errorInfo = $a->doAction($action);
-
- if ( $errorInfo )
- {
- $errormessage = $errorInfo['message'];
- }
- }
-
- // show error when headers already sent out
- if ( headers_sent() && $CONF['alertOnHeadersSent'] )
- {
- // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)
- if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )
- {
- headers_sent($hsFile, $hsLine);
- $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';
- }
- else
- {
- $extraInfo = '';
- }
-
- startUpError(
- '<p>The page headers have already been sent out' . $extraInfo . '. This could cause Nucleus not to work in the expected way.</p><p>Usually, this is caused by spaces or newlines at the end of the <code>config.php</code> file, at the end of the translation file or at the end of a plugin file. Please check this and try again.</p><p>If you don\'t want to see this error message again, without solving the problem, set <code>$CONF[\'alertOnHeadersSent\']</code> in <code>globalfunctions.php</code> to <code>0</code></p>',
- 'Page headers already sent'
- );
- exit;
- }
-
- // make is so ?archivelist without blogname or blogid shows the archivelist
- // for the default weblog
- if ( serverVar('QUERY_STRING') == 'archivelist' )
+ global $skinid;
+\r
+ if ( !$skinid || !existsID($skinid) )
{
- $archivelist = $CONF['DefaultBlog'];
- }
-
- // now decide which type of skin we need
- if ( $itemid )
- {
- // itemid given -> only show that item
- $type = 'item';
-
- if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )
- {
- doError(_ERROR_NOSUCHITEM);
- }
-
- global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
-
- // 1. get timestamp, blogid and catid for item
- $query = 'SELECT itime, iblog, icat FROM ' . sql_table('item') . ' WHERE inumber=' . intval($itemid);
- $res = sql_query($query);
- $obj = sql_fetch_object($res);
-
- // if a different blog id has been set through the request or selectBlog(),
- // deny access
-
- if ( $blogid && (intval($blogid) != $obj->iblog) )
- {
- doError(_ERROR_NOSUCHITEM);
- }
-
- // if a category has been selected which doesn't match the item, ignore the
- // category. #85
- if ( ($catid != 0) && ($catid != $obj->icat) )
- {
- $catid = 0;
- }
-
- $blogid = $obj->iblog;
- $timestamp = strtotime($obj->itime);
-
- $b =& $manager->getBlog($blogid);
-
- if ( $b->isValidCategory($catid) )
- {
- $catextra = ' and icat=' . $catid;
- }
- else
- {
- $catextra = '';
- }
-
- // get previous itemid and title
- $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime<' . mysqldate($timestamp) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime DESC LIMIT 1';
- $res = sql_query($query);
-
- $obj = sql_fetch_object($res);
-
- if ( $obj )
- {
- $itemidprev = $obj->inumber;
- $itemtitleprev = $obj->ititle;
- }
-
- // get next itemid and title
- $query = 'SELECT inumber, ititle FROM ' . sql_table('item') . ' WHERE itime>' . mysqldate($timestamp) . ' and itime <= ' . mysqldate($b->getCorrectTime()) . ' and idraft=0 and iblog=' . $blogid . $catextra . ' ORDER BY itime ASC LIMIT 1';
- $res = sql_query($query);
-
- $obj = sql_fetch_object($res);
-
- if ( $obj )
- {
- $itemidnext = $obj->inumber;
- $itemtitlenext = $obj->ititle;
- }
- }
- elseif ($archive)
- {
- // show archive
- $type = 'archive';
-
- // get next and prev month links ...
- global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;
-
- // sql queries for the timestamp of the first and the last published item
- $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";
- $first_timestamp=quickQuery ($query);
- $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";
- $last_timestamp=quickQuery ($query);
-
- sscanf($archive, '%d-%d-%d', $y, $m, $d);
-
- if ( $d != 0 )
- {
- $archivetype = _ARCHIVETYPE_DAY;
- $t = mktime(0, 0, 0, $m, $d, $y);
- // one day has 24 * 60 * 60 = 86400 seconds
- $archiveprev = i18n::strftime('%Y-%m-%d', $t - 86400 );
- // check for published items
- if ( $t > $first_timestamp )
- {
- $archiveprevexists = true;
- }
- else
- {
- $archiveprevexists = false;
- }
-
- // one day later
- $t += 86400;
- $archivenext = i18n::strftime('%Y-%m-%d', $t);
- if ( $t < $last_timestamp )
- {
- $archivenextexists = true;
- }
- else
- {
- $archivenextexists = false;
- }
- }
- elseif ( $m == 0 )
- {
- $archivetype = _ARCHIVETYPE_YEAR;
- $t = mktime(0, 0, 0, 12, 31, $y - 1);
- // one day before is in the previous year
- $archiveprev = i18n::strftime('%Y', $t);
- if ( $t > $first_timestamp )
- {
- $archiveprevexists = true;
- }
- else
- {
- $archiveprevexists = false;
- }
-
- // timestamp for the next year
- $t = mktime(0, 0, 0, 1, 1, $y + 1);
- $archivenext = i18n::strftime('%Y', $t);
- if ( $t < $last_timestamp )
- {
- $archivenextexists = true;
- }
- else
- {
- $archivenextexists = false;
- }
- }
- else
- {
- $archivetype = _ARCHIVETYPE_MONTH;
- $t = mktime(0, 0, 0, $m, 1, $y);
- // one day before is in the previous month
- $archiveprev = i18n::strftime('%Y-%m', $t - 86400);
- if ( $t > $first_timestamp )
- {
- $archiveprevexists = true;
- }
- else
- {
- $archiveprevexists = false;
- }
-
- // timestamp for the next month
- $t = mktime(0, 0, 0, $m+1, 1, $y);
- $archivenext = i18n::strftime('%Y-%m', $t);
- if ( $t < $last_timestamp )
- {
- $archivenextexists = true;
- }
- else
- {
- $archivenextexists = false;
- }
- }
- }
- elseif ($archivelist)
- {
- $type = 'archivelist';
-
- if ( is_numeric($archivelist) )
- {
- $blogid = intVal($archivelist);
- }
- else
- {
- $blogid = getBlogIDFromName($archivelist);
- }
-
- if ( !$blogid )
- {
- doError(_ERROR_NOSUCHBLOG);
- }
- }
- elseif ( $query )
- {
- global $startpos;
- $type = 'search';
- $query = stripslashes($query);
-
- if ( is_numeric($blogid) )
- {
- $blogid = intVal($blogid);
- }
- else
- {
- $blogid = getBlogIDFromName($blogid);
- }
-
- if ( !$blogid )
- {
- doError(_ERROR_NOSUCHBLOG);
- }
- }
- elseif ( $memberid )
- {
- $type = 'member';
-
- if ( !MEMBER::existsID($memberid) )
- {
- doError(_ERROR_NOSUCHMEMBER);
- }
- $memberinfo = $manager->getMember($memberid);
- }
- elseif ( $imagepopup )
- {
- // media object (images etc.)
- $type = 'imagepopup';
-
- // TODO: check if media-object exists
- // TODO: set some vars?
+ $skin = new Skin($CONF['BaseSkin']);
}
else
{
- // show regular index page
- global $startpos;
- $type = 'index';
- }
-
- // any type of skin with catid
- if ( $catid && !$blogid )
- {
- $blogid = getBlogIDFromCatID($catid);
- }
-
- // decide which blog should be displayed
- if ( !$blogid )
- {
- $blogid = $CONF['DefaultBlog'];
- }
-
- $b =& $manager->getBlog($blogid);
- $blog = $b; // references can't be placed in global variables?
-
- if ( !$blog->isValid )
- {
- doError(_ERROR_NOSUCHBLOG);
- }
-
- // set catid if necessary
- if ( $catid )
- {
- // check if the category is valid
- if ( !$blog->isValidCategory($catid) )
- {
- doError(_ERROR_NOSUCHCATEGORY);
- }
- else
- {
- $blog->setSelectedCategory($catid);
- }
- }
-
- // decide which skin should be used
- if ( $skinid != '' && ($skinid == 0) )
- {
- selectSkin($skinid);
- }
-
- if ( !$skinid )
- {
- $skinid = $blog->getDefaultSkin();
- }
-
- //$special = requestVar('special'); //get at top of file as global
- if ( !empty($special) && isValidShortName($special) )
- {
- $type = strtolower($special);
- }
-
- $skin = new SKIN($skinid);
-
- if ( !$skin->isValid )
- {
- doError(_ERROR_NOSUCHSKIN);
- }
-
- // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude
- global $skinpart;
- $skinpart = $type;
-
- // parse the skin
- $skin->parse($type);
-
- // check to see we should throw JustPosted event
- $blog->checkJustPosted();
+ $skin = new Skin($skinid);
+ }\r
+\r
+ $oldIncludeMode = Parser::getProperty('IncludeMode');
+ $oldIncludePrefix = Parser::getProperty('IncludePrefix');
+\r
+ $skin->parse('fileparse', $filename);
+\r
+ Parser::setProperty('IncludeMode', $oldIncludeMode);
+ Parser::setProperty('IncludePrefix', $oldIncludePrefix);
+\r
return;
-}
-
-/**
- * Show error skin with given message. An optional skin-object to use can be given
- */
-function doError($msg, $skin = '') {
- global $errormessage, $CONF, $skinid, $blogid, $manager;
-
- if ($skin == '') {
-
- if (SKIN::existsID($skinid) ) {
- $skin = new SKIN($skinid);
- } elseif ($manager->existsBlogID($blogid) ) {
- $blog =& $manager->getBlog($blogid);
- $skin = new SKIN($blog->getDefaultSkin() );
- } elseif ($CONF['DefaultBlog']) {
- $blog =& $manager->getBlog($CONF['DefaultBlog']);
- $skin = new SKIN($blog->getDefaultSkin() );
- } else {
- // this statement should actually never be executed
- $skin = new SKIN($CONF['BaseSkin']);
- }
-
- }
-
- $skinid = $skin->id;
- $errormessage = $msg;
- $skin->parse('error');
- exit;
-}
-
-function getConfig() {
- global $CONF;
-
- $query = 'SELECT * FROM ' . sql_table('config');
- $res = sql_query($query);
-
- while ($obj = sql_fetch_object($res) ) {
- $CONF[$obj->name] = $obj->value;
- }
-}
-
-// some checks for names of blogs, categories, templates, members, ...
-function isValidShortName($name) {
-
- # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
- # original eregi: eregi('^[a-z0-9]+$', $name)
-
- return preg_match('#^[a-z0-9]+$#i', $name);
-
-}
-
-function isValidDisplayName($name) {
-
- # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
- # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)
-
- return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);
-
-}
-
-function isValidCategoryName($name) {
- return 1;
-}
-
-function isValidTemplateName($name) {
-
- # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
- # original eregi: eregi('^[a-z0-9/]+$', $name)
- // added - and _ to valid characters as of 4.00
-
- return preg_match('#^[a-z0-9/_\-]+$#i', $name);
-
-}
-
-function isValidSkinName($name) {
-
- # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
- # original eregi: eregi('^[a-z0-9/]+$', $name);
- // added - and _ to valid characters as of 4.00
-
- return preg_match('#^[a-z0-9/_\-]+$#i', $name);
-
-}
-
-// add and remove linebreaks
-function addBreaks($var) {
- return nl2br($var);
-}
-
-function removeBreaks($var) {
- return preg_replace("/<br \/>([\r\n])/", "$1", $var);
-}
-
-/**
- * Converts a unix timestamp to a mysql DATETIME format, and places
- * quotes around it.
- */
-function mysqldate($timestamp) {
- return '"' . date('Y-m-d H:i:s', $timestamp) . '"';
-}
-
-/**
- * functions for use in index.php
- */
-function selectBlog($shortname) {
- global $blogid, $archivelist;
- $blogid = getBlogIDFromName($shortname);
-
- // also force archivelist variable, if it is set
- if ($archivelist) {
- $archivelist = $blogid;
- }
-}
-
-function selectSkin($skinname) {
- global $skinid;
- $skinid = SKIN::getIdFromName($skinname);
-}
-
-/**
- * Can take either a category ID or a category name (be aware that
- * multiple categories can have the same name)
- */
-function selectCategory($cat) {
- global $catid;
- if (is_numeric($cat) ) {
- $catid = intval($cat);
- } else {
- $catid = getCatIDFromName($cat);
- }
-}
-
-function selectItem($id) {
- global $itemid;
- $itemid = intval($id);
-}
-
-// force the use of a translation file (warning: can cause warnings)
-function selectLanguage($language) {
-
- global $DIR_LANG;
-
- # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
- # original ereg_replace: preg_replace( '@\\|/@', '', $language) . '.php')
- # important note that '\' must be matched with '\\\\' in preg* expressions
-
- include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');
-
-}
-
-function parseFile($filename, $includeMode = 'normal', $includePrefix = '') {
- $handler = new ACTIONS('fileparser');
- $parser = new PARSER(SKIN::getAllowedActionsForType('fileparser'), $handler);
- $handler->parser =& $parser;
-
- // set IncludeMode properties of parser
- PARSER::setProperty('IncludeMode', $includeMode);
- PARSER::setProperty('IncludePrefix', $includePrefix);
-
- if (!file_exists($filename) ) {
- doError('A file is missing');
- }
-
- $fsize = filesize($filename);
-
- if ($fsize <= 0) {
- return;
- }
-
- // read file
- $fd = fopen ($filename, 'r');
- $contents = fread ($fd, $fsize);
- fclose ($fd);
-
- // parse file contents
- $parser->parse($contents);
-}
-
-/**
- * Outputs a debug message
- */
-function debug($msg) {
- echo '<p><b>' . $msg . "</b></p>\n";
-}
-
-// shortcut
-function addToLog($level, $msg) {
- ACTIONLOG::add($level, $msg);
-}
-
-// shows a link to help file
-function help($id) {
- echo helpHtml($id);
-}
-
-function helpHtml($id) {
- global $CONF;
- return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';
-}
-
-function helplink($id) {
- global $CONF;
- return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';
-}
-
-/**
- * Includes a PHP file. This method can be called while parsing templates and skins
- */
-function includephp($filename) {
- // make predefined variables global, so most simple scripts can be used here
-
- // apache (names taken from PHP doc)
- global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;
- global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;
- global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;
- global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;
- global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;
- global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;
- global $REQUEST_URI;
-
- // php (taken from PHP doc)
- global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
- global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
-
- // other
- global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;
-
- if (@file_exists($filename) ) {
- include($filename);
- }
-}
-
-/**
- * Checks if a certain plugin exists
- * @param string $plug
- * @return bool
- **/
-function checkPlugin($plug) {
-
- global $DIR_PLUGINS;
-
- # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
- # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')
- # important note that '\' must be matched with '\\\\' in preg* expressions
-
- return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');
-
-}
-
-/**
- * @param $querystr
- * querystring to alter (e.g. foo=1&bar=2&x=y)
- * @param $param
- * name of parameter to change (e.g. 'foo')
- * @param $value
- * New value for that parameter (e.g. 3)
- * @result
- * altered query string (for the examples above: foo=3&bar=2&x=y)
- */
-function alterQueryStr($querystr, $param, $value) {
- $vars = i18n::explode('&', $querystr);
- $set = false;
-
- for ($i = 0; $i < count($vars); $i++) {
- $v = i18n::explode('=', $vars[$i]);
-
- if ($v[0] == $param) {
- $v[1] = $value;
- $vars[$i] = implode('=', $v);
- $set = true;
- break;
- }
- }
-
- if (!$set) {
- $vars[] = $param . '=' . $value;
- }
-
- return ltrim(implode('&', $vars), '&');
-}
-
-// passes one variable as hidden input field (multiple fields for arrays)
-// @see passRequestVars in varsx.x.x.php
-function passVar($key, $value) {
- // array ?
- if (is_array($value) ) {
- for ($i = 0; $i < sizeof($value); $i++) {
- passVar($key . '[' . $i . ']', $value[$i]);
- }
-
- return;
- }
-
- // other values: do stripslashes if needed
- ?><input type="hidden" name="<?php echo ENTITY::hsc($key)?>" value="<?php echo ENTITY::hsc(undoMagic($value) )?>" /><?php
-}
-
-function checkVars($aVars) {
- global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
-
- foreach ($aVars as $varName) {
-
- if (phpversion() >= '4.1.0') {
-
- if ( isset($_GET[$varName])
- || isset($_POST[$varName])
- || isset($_COOKIE[$varName])
- || isset($_ENV[$varName])
- || isset($_SESSION[$varName])
- || isset($_FILES[$varName])
- ) {
- die('Sorry. An error occurred.');
- }
-
- } else {
-
- if ( isset($HTTP_GET_VARS[$varName])
- || isset($HTTP_POST_VARS[$varName])
- || isset($HTTP_COOKIE_VARS[$varName])
- || isset($HTTP_ENV_VARS[$varName])
- || isset($HTTP_SESSION_VARS[$varName])
- || isset($HTTP_POST_FILES[$varName])
- ) {
- die('Sorry. An error occurred.');
- }
-
- }
- }
-}
-
-
-/**
- * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.
- * to avoid XSS
- */
-function sanitizeParams()
-{
- global $HTTP_SERVER_VARS;
-
- $array = array();
- $str = '';
- $frontParam = '';
-
- // REQUEST_URI of $HTTP_SERVER_VARS
- $str =& $HTTP_SERVER_VARS["REQUEST_URI"];
- serverStringToArray($str, $array, $frontParam);
- sanitizeArray($array);
- arrayToServerString($array, $frontParam, $str);
-
- // QUERY_STRING of $HTTP_SERVER_VARS
- $str =& $HTTP_SERVER_VARS["QUERY_STRING"];
- serverStringToArray($str, $array, $frontParam);
- sanitizeArray($array);
- arrayToServerString($array, $frontParam, $str);
-
- if (phpversion() >= '4.1.0') {
- // REQUEST_URI of $_SERVER
- $str =& $_SERVER["REQUEST_URI"];
- serverStringToArray($str, $array, $frontParam);
- sanitizeArray($array);
- arrayToServerString($array, $frontParam, $str);
-
- // QUERY_STRING of $_SERVER
- $str =& $_SERVER["QUERY_STRING"];
- serverStringToArray($str, $array, $frontParam);
- sanitizeArray($array);
- arrayToServerString($array, $frontParam, $str);
- }
-
- // $_GET
- convArrayForSanitizing($_GET, $array);
- sanitizeArray($array);
- revertArrayForSanitizing($array, $_GET);
-
- // $_REQUEST (only GET param)
- convArrayForSanitizing($_REQUEST, $array);
- sanitizeArray($array);
- revertArrayForSanitizing($array, $_REQUEST);
-}
-
-/**
- * Check ticket when not checked in plugin's admin page
- * to avoid CSRF.
- * Also avoid the access to plugin/index.php by guest user.
- */
-function ticketForPlugin()
-{
- global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;
-
- /* initialize */
- $ticketforplugin = array();
- $ticketforplugin['ticket'] = FALSE;
-
- /* $_SERVER['PATH_TRANSLATED']
- * http://www.php.net/manual/en/reserved.variables.server.php
- * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
- * under the Apache 2 SAPI in contrast to the situation in Apache 1,
- * where it's set to the same value as the SCRIPT_FILENAME server variable
- * when it's not populated by Apache.
- * This change was made to comply with the CGI specification
- * that PATH_TRANSLATED should only exist if PATH_INFO is defined.
- * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
- */
-
- /* Check if using plugin's php file. */
- $p_translated = serverVar('SCRIPT_FILENAME');
-
- if (!file_exists($p_translated) )
- {
- header("HTTP/1.0 404 Not Found");
- exit('');
- }
-
- $p_translated = str_replace('\\', '/', $p_translated);
- $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);
-
- // This isn't plugin php file.
- if ( i18n::strpos($p_translated, $d_plugins) !== 0 )
- {
- return;
- }
-
- // Solve the plugin php file or admin directory
- $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );
- // Remove the first "/" if exists.
- $phppath = preg_replace('#^/#', '', $phppath);
- // Remove the first "NP_" and the last ".php" if exists.
- $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);
- // Remove the "/" and beyond.
- $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);
-
- // Solve the plugin name.
- $plugins = array();
- $query = 'SELECT `pfile` FROM '.sql_table('plugin');
- $res = sql_query($query);
-
- while($row = sql_fetch_row($res) )
- {
- $name = i18n::substr($row[0], 3);
- $plugins[strtolower($name)] = $name;
- }
-
- sql_free_result($res);
-
- if (array_key_exists($path, $plugins))
- {
- $plugin_name = $plugins[$path];
- }
- else if (in_array($path, $plugins))
- {
- $plugin_name = $path;
- }
- else
- {
- header("HTTP/1.0 404 Not Found");
- exit('');
- }
-
- /* Return if not index.php */
- if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )
- {
- return;
- }
-
- /* Exit if not logged in. */
- if ( !$member->isLoggedIn() )
- {
- exit('You aren\'t logged in.');
- }
-
- global $manager, $DIR_LIBS, $DIR_LOCALE, $HTTP_GET_VARS, $HTTP_POST_VARS;
-
- /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */
- if (!($p_translated = serverVar('PATH_TRANSLATED') ) )
- {
- $p_translated = serverVar('SCRIPT_FILENAME');
- }
-
- if ($file = @file($p_translated) )
- {
- $prevline = '';
-
- foreach($file as $line)
- {
- if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )
- {
- return;
- }
-
- $prevline = $line;
- }
- }
-
- /* Show a form if not valid ticket */
- if ( ( strstr(serverVar('REQUEST_URI'), '?') || serverVar('QUERY_STRING')
- || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')
- && (!$manager->checkTicket() ) )
- {
- $oPluginAdmin = new PluginAdmin($plugin_name);
- $oPluginAdmin->start();
- echo '<p>' . _ERROR_BADTICKET . "</p>\n";
-
- /* Show the form to confirm action */
- // PHP 4.0.x support
- $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;
- $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;
-
- // Resolve URI and QUERY_STRING
- if ($uri = serverVar('REQUEST_URI') )
- {
- list($uri, $qstring) = i18n::explode('?', $uri);
- }
- else
- {
- if ( !($uri = serverVar('PHP_SELF') ) )
- {
- $uri = serverVar('SCRIPT_NAME');
- }
- $qstring = serverVar('QUERY_STRING');
- }
- if ($qstring)
- {
- $qstring = '?' . $qstring;
- }
-
- echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . ENTITY::hsc($plugin_name) . "</span> ?</p>\n";
-
- switch(strtoupper(serverVar('REQUEST_METHOD') ) )
- {
- case 'POST':
- echo '<form method="POST" action="'.ENTITY::hsc($uri.$qstring).'">';
- $manager->addTicketHidden();
- _addInputTags($post);
- break;
-
- case 'GET':
- echo '<form method="GET" action="'.ENTITY::hsc($uri).'">';
- $manager->addTicketHidden();
- _addInputTags($get);
-
- default:
- break;
- }
-
- echo '<input type="submit" value="' . _YES . '" /> ';
- echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';
- echo "</form>\n";
-
- $oPluginAdmin->end();
- exit;
- }
-
- /* Create new ticket */
- $ticket=$manager->addTicketToUrl('');
- $ticketforplugin['ticket']=i18n::substr($ticket,i18n::strpos($ticket,'ticket=')+7);
-}
-
-function _addInputTags(&$keys,$prefix=''){
- foreach($keys as $key=>$value){
- if ($prefix) $key=$prefix.'['.$key.']';
- if (is_array($value)) _addInputTags($value,$key);
- else {
- if (get_magic_quotes_gpc()) $value=stripslashes($value);
- if ($key=='ticket') continue;
- echo '<input type="hidden" name="'.ENTITY::hsc($key).
- '" value="'.ENTITY::hsc($value).'" />'."\n";
- }
- }
-}
-
-/**
- * Convert the server string such as $_SERVER['REQUEST_URI']
- * to arry like arry['blogid']=1 and array['page']=2 etc.
- */
-function serverStringToArray($str, &$array, &$frontParam)
-{
- // init param
- $array = array();
- $frontParam = "";
-
- // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2
- if (strstr($str, "?")){
- list($frontParam, $args) = preg_split("/\?/", $str, 2);
- }
- else {
- $args = $str;
- $frontParam = "";
- }
-
- // If there is no args like blogid=1&page=2, return
- if (!strstr($str, "=") && !i18n::strlen($frontParam)) {
- $frontParam = $str;
- return;
- }
-
- $array = i18n::explode("&", $args);
-}
-
-/**
- * Convert array like array['blogid'] to server string
- * such as $_SERVER['REQUEST_URI']
- */
-function arrayToServerString($array, $frontParam, &$str)
-{
- if (strstr($str, "?")) {
- $str = $frontParam . "?";
- } else {
- $str = $frontParam;
- }
- if (count($array)) {
- $str .= implode("&", $array);
- }
-}
-
-/**
- * Sanitize array parameters.
- * This function checks both key and value.
- * - check key if it inclues " (double quote), remove from array
- * - check value if it includes \ (escape sequece), remove remaining string
- */
-function sanitizeArray(&$array)
-{
- $excludeListForSanitization = array('query');
-// $excludeListForSanitization = array();
-
- foreach ($array as $k => $v) {
-
- // split to key and value
- list($key, $val) = preg_split("/=/", $v, 2);
- if (!isset($val)) {
- continue;
- }
-
- // when magic quotes is on, need to use stripslashes,
- // and then addslashes
- if (get_magic_quotes_gpc()) {
- $val = stripslashes($val);
- }
- // note that we must use addslashes here because this function is called before the db connection is made
- // and sql_real_escape_string needs a db connection
- $val = addslashes($val);
-
- // if $key is included in exclude list, skip this param
- if (!in_array($key, $excludeListForSanitization)) {
-
- // check value
- if (i18n::strpos($val, '\\')) {
- list($val, $tmp) = i18n::explode('\\', $val);
- }
-
- // remove control code etc.
- $val = strtr($val, "\0\r\n<>'\"", " ");
-
- // check key
- if (preg_match('/\"/i', $key)) {
- unset($array[$k]);
- continue;
- }
-
- // set sanitized info
- $array[$k] = sprintf("%s=%s", $key, $val);
- }
- }
-}
-
-/**
- * Convert array for sanitizeArray function
- */
-function convArrayForSanitizing($src, &$array)
-{
- $array = array();
- foreach ($src as $key => $val) {
- if (key_exists($key, $_GET)) {
- array_push($array, sprintf("%s=%s", $key, $val));
- }
- }
-}
-
-/**
- * Revert array after sanitizeArray function
- */
-function revertArrayForSanitizing($array, &$dst)
-{
- foreach ($array as $v) {
- list($key, $val) = preg_split("/=/", $v, 2);
- $dst[$key] = $val;
- }
-}
-
-/**
- * Stops processing the request and redirects to the given URL.
- * - no actual contents should have been sent to the output yet
- * - the URL will be stripped of illegal or dangerous characters
- */
-function redirect($url) {
- $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);
- header('Location: ' . $url);
- exit;
-}
-
-/*
- * Returns the Javascript code for a bookmarklet that works on most modern browsers
- * @param blogid
- */
-function getBookmarklet($blogid) {
- global $CONF;
-
- // normal
- $document = 'document';
- $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";
- $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";
- $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";
-
- return $bookmarkletline;
-}
-// END: functions from the end of file ADMIN.php
-
-/**
- * Returns a variable or null if not set
- *
- * @param mixed Variable
- * @return mixed Variable
- */
-function ifset(&$var) {
- if (isset($var)) {
- return $var;
- }
-
- return null;
-}
-
-/**
- * Returns number of subscriber to an event
- *
- * @param event
- * @return number of subscriber(s)
- */
-function numberOfEventSubscriber($event) {
- $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';
- $res = sql_query($query);
- $obj = sql_fetch_object($res);
- return $obj->count;
-}
-
-/**
- * sets $special global variable for use in index.php before selector()
- *
- * @param String id
- * @return nothing
- */
-function selectSpecialSkinType($id) {
- global $special;
- $special = strtolower($id);
-}
-
-/**
- * cleans filename of uploaded file for writing to file system
- *
- * @param String str
- * @return String cleaned filename ready for use
- */
-function cleanFileName($str) {
- $str = strtolower($str);
- $ext_point = i18n::strrpos($str,".");
- if ($ext_point===false) return false;
- $ext = i18n::substr($str,$ext_point,i18n::strlen($str));
- $str = i18n::substr($str,0,$ext_point);
-
- return preg_replace("/[^a-z0-9-]/","_",$str).$ext;
-}
-
-/**
- * Centralisation of the functions to send mail
- * Deprecated since 4.0:
- * Please use functions in NOTIFICATION class instead
- */
-function getMailFooter()
-{
- NOTIFICATION::get_mail_footer();
-}
-function isValidMailAddress($address)
-{
- return NOTIFICATION::address_validation($address);
-}
-/**
- * Centralisation of the functions that deals XML entities
- * Deprecated since 4.0:
- * Please use ENTITY::FunctionName(...) instead
- */
-function highlight($text, $expression, $highlight)
-{
- return ENTITY::highlight($text, $expression, $highlight);
-}
-function shorten($string, $maxlength, $suffix)
-{
- return ENTITY::shorten($string, $maxlength, $suffix);
-}
-function stringStripTags ($string)
-{
- return ENTITY::strip_tags($string);
-}
-function toAscii($string)
-{
- return ENTITY::anchor_footnoting($string);
-}
-function stringToAttribute ($string)
-{
- return ENTITY::hsc($string);
-}
-function stringToXML ($string)
-{
- return ENTITY::hen($string);
-}
-function encode_desc($data)
-{
- return ENTITY::hen($data);
-}
-/**
- * Centralisation of the functions that deals with locales
- * This functions is based on the old way to deal with languages
- * Deprecated since 4.0:
- */
-/* NOTE: use i18n::get_current_locale() directly instead of this */
-function getLanguageName()
-{
- if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )
- {
- $language ='english';
- }
- return $language;
-}
-
-/* NOTE: use i18n::get_available_locales() directly instead of this */
-function checkLanguage($lang)
-{
- return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)
- || i18n::convert_old_language_file_name_to_locale($lang) );
-}
-/* NOTE: use i18n::formatted_datetime() directly instead of this */
-function formatDate($format, $timestamp, $default_format, &$blog)
-{
- $offset = date('Z', $timestamp);
- if ( $blog )
- {
- $offset += $blog->getTimeOffset() * 3600;
- }
- return i18n::formatted_datetime($format, $timestamp, $default_format, $offset);
-}
-/**
- * Centralisation of the functions that generate links
- * Deprecated since 4.0:
- * Please use LINK::FunctionName(...) instead
- */
-function createItemLink($itemid, $extra = '')
-{
- return LINK::create_item_link($itemid, $extra);
-}
-function createMemberLink($memberid, $extra = '')
-{
- return LINK::create_member_link($memberid, $extra);
-}
-function createCategoryLink($catid, $extra = '')
-{
- return LINK::create_category_link($catid, $extra);
-}
-function createArchiveListLink($blogid = '', $extra = '')
-{
- return LINK::create_archivelist_link($blogid, $extra);
-}
-function createArchiveLink($blogid, $archive, $extra = '')
-{
- return LINK::create_archive_link($blogid, $archive, $extra);
-}
-function createBlogidLink($blogid, $params = '')
-{
- return LINK::create_blogid_link($blogid, $params = '');
-}
-function createLink($type, $params)
-{
- return LINK::create_link($type, $params);
-}
-function createBlogLink($url, $params)
-{
- return LINK::create_blog_link($url, $params);
-}
+}\r
+\r
+/**\r
+ * Outputs a debug message\r
+ */\r
+function debug($msg) {\r
+ echo '<p><b>' . $msg . "</b></p>\n";\r
+}\r
+\r
+// shortcut\r
+function addToLog($level, $msg) {\r
+ ActionLog::add($level, $msg);\r
+}\r
+\r
+// shows a link to help file\r
+function help($id) {\r
+ echo helpHtml($id);\r
+}\r
+\r
+function helpHtml($id) {\r
+ global $CONF;\r
+ return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';\r
+}\r
+\r
+function helplink($id) {\r
+ global $CONF;\r
+ return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';\r
+}\r
+\r
+/**\r
+ * Includes a PHP file. This method can be called while parsing templates and skins\r
+ */\r
+function includephp($filename) {\r
+ // make predefined variables global, so most simple scripts can be used here\r
+\r
+ // apache (names taken from PHP doc)\r
+ global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;\r
+ global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;\r
+ global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;\r
+ global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;\r
+ global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;\r
+ global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;\r
+ global $REQUEST_URI;\r
+\r
+ // php (taken from PHP doc)\r
+ global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;\r
+ global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;\r
+\r
+ // other\r
+ global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;\r
+\r
+ if (@file_exists($filename) ) {\r
+ include($filename);\r
+ }\r
+}\r
+\r
+/**\r
+ * Checks if a certain plugin exists\r
+ * @param string $plug\r
+ * @return bool\r
+ **/\r
+function checkPlugin($plug) {\r
+\r
+ global $DIR_PLUGINS;\r
+\r
+ # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0\r
+ # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')\r
+ # important note that '\' must be matched with '\\\\' in preg* expressions\r
+\r
+ return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');\r
+\r
+}\r
+\r
+/**\r
+ * alterQueryStr()\r
+ * \r
+ * @param string $querystr querystring to alter (e.g. foo=1&bar=2&x=y)\r
+ * @param string $param name of parameter to change (e.g. 'foo')\r
+ * @param string $value New value for that parameter (e.g. 3)\r
+ * @result string altered query string (for the examples above: foo=3&bar=2&x=y)\r
+ */\r
+function alterQueryStr($querystr, $param, $value)\r
+{\r
+ $vars = preg_split('#&#', $querystr);\r
+ $set = FALSE;\r
+ \r
+ for ( $i = 0; $i < count($vars); $i++ )\r
+ {\r
+ $v = preg_split('#=#', $vars[$i]);\r
+ \r
+ if ( $v[0] == $param )\r
+ {\r
+ $v[1] = $value;\r
+ $vars[$i] = implode('=', $v);\r
+ $set = true;\r
+ break;\r
+ }\r
+ }\r
+ if ( !$set )\r
+ {\r
+ $vars[] = "{$param}={$value}";\r
+ }\r
+ return ltrim(implode('&', $vars), '&');\r
+}\r
+\r
+// passes one variable as hidden input field (multiple fields for arrays)\r
+// @see passRequestVars in varsx.x.x.php\r
+function passVar($key, $value) {\r
+ // array ?\r
+ if (is_array($value) ) {\r
+ for ($i = 0; $i < sizeof($value); $i++) {\r
+ passVar($key . '[' . $i . ']', $value[$i]);\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ // other values: do stripslashes if needed\r
+ ?><input type="hidden" name="<?php echo Entity::hsc($key)?>" value="<?php echo Entity::hsc(undoMagic($value) )?>" /><?php\r
+}\r
+\r
+function checkVars($aVars) {\r
+ global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;\r
+\r
+ foreach ($aVars as $varName) {\r
+\r
+ if (phpversion() >= '4.1.0') {\r
+\r
+ if ( isset($_GET[$varName])\r
+ || isset($_POST[$varName])\r
+ || isset($_COOKIE[$varName])\r
+ || isset($_ENV[$varName])\r
+ || isset($_SESSION[$varName])\r
+ || isset($_FILES[$varName])\r
+ ) {\r
+ die('Sorry. An error occurred.');\r
+ }\r
+\r
+ } else {\r
+\r
+ if ( isset($HTTP_GET_VARS[$varName])\r
+ || isset($HTTP_POST_VARS[$varName])\r
+ || isset($HTTP_COOKIE_VARS[$varName])\r
+ || isset($HTTP_ENV_VARS[$varName])\r
+ || isset($HTTP_SESSION_VARS[$varName])\r
+ || isset($HTTP_POST_FILES[$varName])\r
+ ) {\r
+ die('Sorry. An error occurred.');\r
+ }\r
+\r
+ }\r
+ }\r
+}\r
+\r
+\r
+/**\r
+ * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.\r
+ * to avoid XSS\r
+ */\r
+function sanitizeParams()\r
+{\r
+ global $HTTP_SERVER_VARS;\r
+\r
+ $array = array();\r
+ $str = '';\r
+ $frontParam = '';\r
+\r
+ // REQUEST_URI of $HTTP_SERVER_VARS\r
+ $str =& $HTTP_SERVER_VARS["REQUEST_URI"];\r
+ serverStringToArray($str, $array, $frontParam);\r
+ sanitizeArray($array);\r
+ arrayToServerString($array, $frontParam, $str);\r
+\r
+ // QUERY_STRING of $HTTP_SERVER_VARS\r
+ $str =& $HTTP_SERVER_VARS["QUERY_STRING"];\r
+ serverStringToArray($str, $array, $frontParam);\r
+ sanitizeArray($array);\r
+ arrayToServerString($array, $frontParam, $str);\r
+\r
+ if (phpversion() >= '4.1.0') {\r
+ // REQUEST_URI of $_SERVER\r
+ $str =& $_SERVER["REQUEST_URI"];\r
+ serverStringToArray($str, $array, $frontParam);\r
+ sanitizeArray($array);\r
+ arrayToServerString($array, $frontParam, $str);\r
+\r
+ // QUERY_STRING of $_SERVER\r
+ $str =& $_SERVER["QUERY_STRING"];\r
+ serverStringToArray($str, $array, $frontParam);\r
+ sanitizeArray($array);\r
+ arrayToServerString($array, $frontParam, $str);\r
+ }\r
+\r
+ // $_GET\r
+ convArrayForSanitizing($_GET, $array);\r
+ sanitizeArray($array);\r
+ revertArrayForSanitizing($array, $_GET);\r
+\r
+ // $_REQUEST (only GET param)\r
+ convArrayForSanitizing($_REQUEST, $array);\r
+ sanitizeArray($array);\r
+ revertArrayForSanitizing($array, $_REQUEST);\r
+}\r
+\r
+/**\r
+ * ticketForPlugin()\r
+ * \r
+ * Check ticket when not checked in plugin's admin page\r
+ * to avoid CSRF.\r
+ * Also avoid the access to plugin/index.php by guest user.\r
+ */\r
+function ticketForPlugin()\r
+{\r
+ global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;\r
+ \r
+ /* initialize */\r
+ $ticketforplugin = array();\r
+ $ticketforplugin['ticket'] = FALSE;\r
+ \r
+ /* $_SERVER['PATH_TRANSLATED']\r
+ * http://www.php.net/manual/en/reserved.variables.server.php\r
+ * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly\r
+ * under the Apache 2 SAPI in contrast to the situation in Apache 1,\r
+ * where it's set to the same value as the SCRIPT_FILENAME server variable\r
+ * when it's not populated by Apache.\r
+ * This change was made to comply with the CGI specification\r
+ * that PATH_TRANSLATED should only exist if PATH_INFO is defined.\r
+ * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO. \r
+ */\r
+ \r
+ /* Check if using plugin's php file. */\r
+ $p_translated = serverVar('SCRIPT_FILENAME');\r
+ \r
+ if (!file_exists($p_translated) )\r
+ {\r
+ header("HTTP/1.0 404 Not Found");\r
+ exit('');\r
+ }\r
+ \r
+ $p_translated = str_replace('\\', '/', $p_translated);\r
+ $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);\r
+ \r
+ // This isn't plugin php file.\r
+ if ( i18n::strpos($p_translated, $d_plugins) !== 0 )\r
+ {\r
+ return;\r
+ }\r
+\r
+ // Solve the plugin php file or admin directory\r
+ $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );\r
+ // Remove the first "/" if exists.\r
+ $phppath = preg_replace('#^/#', '', $phppath);\r
+ // Remove the first "NP_" and the last ".php" if exists.\r
+ $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);\r
+ // Remove the "/" and beyond.\r
+ $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);\r
+ \r
+ // Solve the plugin name.\r
+ $plugins = array();\r
+ $query = 'SELECT pfile FROM '.sql_table('plugin');\r
+ $res = sql_query($query);\r
+ \r
+ while($row = sql_fetch_row($res) )\r
+ {\r
+ $name = i18n::substr($row[0], 3);\r
+ $plugins[strtolower($name)] = $name;\r
+ }\r
+ \r
+ sql_free_result($res);\r
+ \r
+ if (array_key_exists($path, $plugins))\r
+ {\r
+ $plugin_name = $plugins[$path];\r
+ }\r
+ else if (in_array($path, $plugins))\r
+ {\r
+ $plugin_name = $path;\r
+ }\r
+ else\r
+ {\r
+ header("HTTP/1.0 404 Not Found");\r
+ exit('');\r
+ }\r
+ \r
+ /* Return if not index.php */\r
+ if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )\r
+ {\r
+ return;\r
+ }\r
+ \r
+ /* Exit if not logged in. */\r
+ if ( !$member->isLoggedIn() )\r
+ {\r
+ exit('You aren\'t logged in.');\r
+ }\r
+ \r
+ global $manager, $DIR_LIBS, $DIR_LOCALES, $HTTP_GET_VARS, $HTTP_POST_VARS;\r
+ \r
+ /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */\r
+ if (!($p_translated = serverVar('PATH_TRANSLATED') ) )\r
+ {\r
+ $p_translated = serverVar('SCRIPT_FILENAME');\r
+ }\r
+ \r
+ if ($file = @file($p_translated) )\r
+ {\r
+ $prevline = '';\r
+ \r
+ foreach($file as $line)\r
+ {\r
+ if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )\r
+ {\r
+ return;\r
+ }\r
+ \r
+ $prevline = $line;\r
+ }\r
+ }\r
+ \r
+ /* Show a form if not valid ticket */\r
+ if ( ( strstr(serverVar('REQUEST_URI'), '?') || serverVar('QUERY_STRING')\r
+ || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')\r
+ && (!$manager->checkTicket() ) )\r
+ {\r
+ $oPluginAdmin = new PluginAdmin($plugin_name);\r
+ $oPluginAdmin->start();\r
+ echo '<p>' . _ERROR_BADTICKET . "</p>\n";\r
+ \r
+ /* Show the form to confirm action */\r
+ // PHP 4.0.x support\r
+ $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;\r
+ $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;\r
+ \r
+ // Resolve URI and QUERY_STRING\r
+ if ($uri = serverVar('REQUEST_URI') )\r
+ {\r
+ list($uri, $qstring) = preg_split('#\?#', $uri);\r
+ }\r
+ else\r
+ {\r
+ if ( !($uri = serverVar('PHP_SELF') ) )\r
+ {\r
+ $uri = serverVar('SCRIPT_NAME');\r
+ }\r
+ $qstring = serverVar('QUERY_STRING');\r
+ }\r
+ if ($qstring)\r
+ {\r
+ $qstring = '?' . $qstring;\r
+ }\r
+ \r
+ echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . Entity::hsc($plugin_name) . "</span> ?</p>\n";\r
+ \r
+ switch(strtoupper(serverVar('REQUEST_METHOD') ) )\r
+ {\r
+ case 'POST':\r
+ echo '<form method="POST" action="'.Entity::hsc($uri.$qstring).'">';\r
+ $manager->addTicketHidden();\r
+ _addInputTags($post);\r
+ break;\r
+ \r
+ case 'GET':\r
+ echo '<form method="GET" action="'.Entity::hsc($uri).'">';\r
+ $manager->addTicketHidden();\r
+ _addInputTags($get);\r
+ \r
+ default:\r
+ break;\r
+ }\r
+ \r
+ echo '<input type="submit" value="' . _YES . '" /> ';\r
+ echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';\r
+ echo "</form>\n";\r
+ \r
+ $oPluginAdmin->end();\r
+ exit;\r
+ }\r
+ \r
+ /* Create new ticket */\r
+ $ticket=$manager->addTicketToUrl('');\r
+ $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7);\r
+ return;\r
+}\r
+\r
+function _addInputTags(&$keys,$prefix=''){\r
+ foreach($keys as $key=>$value){\r
+ if ($prefix) $key=$prefix.'['.$key.']';\r
+ if (is_array($value)) _addInputTags($value,$key);\r
+ else {\r
+ if (get_magic_quotes_gpc()) $value=stripslashes($value);\r
+ if ($key=='ticket') continue;\r
+ echo '<input type="hidden" name="'.Entity::hsc($key).\r
+ '" value="'.Entity::hsc($value).'" />'."\n";\r
+ }\r
+ }\r
+}\r
+\r
+/**\r
+ * serverStringToArray()\r
+ * Convert the server string such as $_SERVER['REQUEST_URI']\r
+ * to arry like arry['blogid']=1 and array['page']=2 etc.\r
+ * \r
+ * @param string $str string\r
+ * @param string $array \r
+ * @param string $frontParam \r
+ */\r
+function serverStringToArray($str, &$array, &$frontParam)\r
+{\r
+ // init param\r
+ $array = array();\r
+ $frontParam = "";\r
+ \r
+ // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2\r
+ if ( i18n::strpos($str, "?") > 0 )\r
+ {\r
+ list($frontParam, $args) = preg_split("#\?#", $str, 2);\r
+ }\r
+ else\r
+ {\r
+ $args = $str;\r
+ $frontParam = "";\r
+ }\r
+ \r
+ // If there is no args like blogid=1&page=2, return\r
+ if ( i18n::strpos($str, "=") == FALSE && !i18n::strlen($frontParam) )\r
+ {\r
+ $frontParam = $str;\r
+ return;\r
+ }\r
+ \r
+ $array = preg_split("#&#", $args);\r
+ return;\r
+}\r
+\r
+/**\r
+ * Convert array like array['blogid'] to server string\r
+ * such as $_SERVER['REQUEST_URI']\r
+ */\r
+function arrayToServerString($array, $frontParam, &$str)\r
+{\r
+ if (strstr($str, "?")) {\r
+ $str = $frontParam . "?";\r
+ } else {\r
+ $str = $frontParam;\r
+ }\r
+ if (count($array)) {\r
+ $str .= implode("&", $array);\r
+ }\r
+}\r
+\r
+/**\r
+ * sanitizeArray()\r
+ * Sanitize array parameters.\r
+ * This function checks both key and value.\r
+ * - check key if it inclues " (double quote), remove from array\r
+ * - check value if it includes \ (escape sequece), remove remaining string\r
+ * \r
+ * @param array &$array \r
+ * @return void\r
+ */\r
+function sanitizeArray(&$array)\r
+{\r
+ $excludeListForSanitization = array('query');\r
+ \r
+ foreach ( $array as $k => $v )\r
+ {\r
+ // split to key and value\r
+ list($key, $val) = preg_split("#=#", $v, 2);\r
+ if ( !isset($val) )\r
+ {\r
+ continue;\r
+ }\r
+ \r
+ // when magic quotes is on, need to use stripslashes,\r
+ // and then addslashes\r
+ if ( get_magic_quotes_gpc() )\r
+ {\r
+ $val = stripslashes($val);\r
+ }\r
+ // note that we must use addslashes here because this function is called before the db connection is made\r
+ // and sql_real_escape_string needs a db connection\r
+ $val = addslashes($val);\r
+ \r
+ // if $key is included in exclude list, skip this param\r
+ if ( !in_array($key, $excludeListForSanitization) )\r
+ {\r
+ // check value\r
+ if ( i18n::strpos($val, '\\') )\r
+ {\r
+ list($val, $tmp) = preg_split('#\\\\#', $val);\r
+ }\r
+ \r
+ // remove control code etc.\r
+ $val = strtr($val, "\0\r\n<>'\"", " ");\r
+ \r
+ // check key\r
+ if ( preg_match('#\"#', $key) )\r
+ {\r
+ unset($array[$k]);\r
+ continue;\r
+ }\r
+ \r
+ // set sanitized info\r
+ $array[$k] = sprintf("%s=%s", $key, $val);\r
+ }\r
+ }\r
+ return;\r
+}\r
+\r
+/**\r
+ * Convert array for sanitizeArray function\r
+ */\r
+function convArrayForSanitizing($src, &$array)\r
+{\r
+ $array = array();\r
+ foreach ($src as $key => $val) {\r
+ if (key_exists($key, $_GET)) {\r
+ array_push($array, sprintf("%s=%s", $key, $val));\r
+ }\r
+ }\r
+}\r
+\r
+/**\r
+ * Revert array after sanitizeArray function\r
+ */\r
+function revertArrayForSanitizing($array, &$dst)\r
+{\r
+ foreach ($array as $v) {\r
+ list($key, $val) = preg_split("/=/", $v, 2);\r
+ $dst[$key] = $val;\r
+ }\r
+}\r
+\r
+/**\r
+ * Stops processing the request and redirects to the given URL.\r
+ * - no actual contents should have been sent to the output yet\r
+ * - the URL will be stripped of illegal or dangerous characters\r
+ */\r
+function redirect($url) {\r
+ $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);\r
+ header('Location: ' . $url);\r
+ exit;\r
+}\r
+\r
+/*\r
+ * Returns the Javascript code for a bookmarklet that works on most modern browsers\r
+ * @param blogid\r
+ */\r
+function getBookmarklet($blogid) {\r
+ global $CONF;\r
+\r
+ // normal\r
+ $document = 'document';\r
+ $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";\r
+ $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";\r
+ $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";\r
+\r
+ return $bookmarkletline;\r
+}\r
+// END: functions from the end of file ADMIN.php\r
+\r
+/**\r
+ * Returns a variable or null if not set\r
+ *\r
+ * @param mixed Variable\r
+ * @return mixed Variable\r
+ */\r
+function ifset(&$var) {\r
+ if (isset($var)) {\r
+ return $var;\r
+ }\r
+\r
+ return null;\r
+}\r
+\r
+/**\r
+ * Returns number of subscriber to an event\r
+ *\r
+ * @param event\r
+ * @return number of subscriber(s)\r
+ */\r
+function numberOfEventSubscriber($event) {\r
+ $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';\r
+ $res = sql_query($query);\r
+ $obj = sql_fetch_object($res);\r
+ return $obj->count;\r
+}\r
+\r
+/**\r
+ * sets $special global variable for use in index.php before selector()\r
+ *\r
+ * @param String id\r
+ * @return nothing\r
+ */\r
+function selectSpecialSkinType($id) {\r
+ global $special;\r
+ $special = strtolower($id);\r
+}\r
+\r
+/**\r
+ * cleans filename of uploaded file for writing to file system\r
+ *\r
+ * @param String str\r
+ * @return String cleaned filename ready for use\r
+ */\r
+function cleanFileName($str) {\r
+ $str = strtolower($str);\r
+ $ext_point = i18n::strrpos($str,".");\r
+ if ($ext_point===false) return false;\r
+ $ext = i18n::substr($str,$ext_point,i18n::strlen($str));\r
+ $str = i18n::substr($str,0,$ext_point);\r
+\r
+ return preg_replace("/[^a-z0-9-]/","_",$str).$ext;\r
+}\r
+\r
+/**\r
+ * Centralisation of the functions to send mail\r
+ * Deprecated since 4.0:\r
+ * Please use functions in NOTIFICATION class instead\r
+ */\r
+function getMailFooter()\r
+{\r
+ NOTIFICATION::get_mail_footer();\r
+}\r
+function isValidMailAddress($address)\r
+{\r
+ return NOTIFICATION::address_validation($address);\r
+}\r
+/**\r
+ * Centralisation of the functions that deals XML entities\r
+ * Deprecated since 4.0:\r
+ * Please use Entity::FunctionName(...) instead\r
+ */\r
+function highlight($text, $expression, $highlight)\r
+{\r
+ return Entity::highlight($text, $expression, $highlight);\r
+}\r
+function shorten($string, $maxlength, $suffix)\r
+{\r
+ return Entity::shorten($string, $maxlength, $suffix);\r
+}\r
+function stringStripTags ($string)\r
+{\r
+ return Entity::strip_tags($string);\r
+}\r
+function toAscii($string)\r
+{\r
+ return Entity::anchor_footnoting($string);\r
+}\r
+function stringToAttribute ($string)\r
+{\r
+ return Entity::hsc($string);\r
+}\r
+function stringToXML ($string)\r
+{\r
+ return Entity::hen($string);\r
+}\r
+function encode_desc($data)\r
+{\r
+ return Entity::hen($data);\r
+}\r
+/**\r
+ * Centralisation of the functions that deals with locales\r
+ * This functions is based on the old way to deal with languages\r
+ * Deprecated since 4.0:\r
+ */\r
+/* NOTE: use i18n::get_current_locale() directly instead of this */\r
+function getLanguageName()\r
+{\r
+ if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )\r
+ {\r
+ $language ='english';\r
+ }\r
+ return $language;\r
+}\r
+/* NOTE: this is completely deprecated because generating much warnings */\r
+function selectLanguage($language)\r
+{\r
+ global $DIR_LANG;\r
+ include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');\r
+ return;\r
+}\r
+\r
+/* NOTE: use i18n::get_available_locales() directly instead of this */\r
+function checkLanguage($lang)\r
+{\r
+ return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)\r
+ || i18n::convert_old_language_file_name_to_locale($lang) );\r
+}\r
+/* NOTE: use i18n::formatted_datetime() directly instead of this */\r
+function formatDate($format, $timestamp, $default_format, &$blog)\r
+{\r
+ $offset = date('Z', $timestamp);\r
+ if ( $blog )\r
+ {\r
+ $offset += $blog->getTimeOffset() * 3600;\r
+ }\r
+ return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);\r
+}\r
+/* NOTE: use i18n::formatted_datetime() directly instead of this */\r
+function mysqldate($timestamp)\r
+{\r
+ return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';\r
+ }\r
+/**\r
+ * Centralisation of the functions that generate links\r
+ * Deprecated since 4.0:\r
+ * Please use Link::FunctionName(...) instead\r
+ */\r
+function createItemLink($itemid, $extra = '')\r
+{\r
+ return Link::create_item_link($itemid, $extra);\r
+}\r
+function createMemberLink($memberid, $extra = '')\r
+{\r
+ return Link::create_member_link($memberid, $extra);\r
+}\r
+function createCategoryLink($catid, $extra = '')\r
+{\r
+ return Link::create_category_link($catid, $extra);\r
+}\r
+function createArchiveListLink($blogid = '', $extra = '')\r
+{\r
+ return Link::create_archivelist_link($blogid, $extra);\r
+}\r
+function createArchiveLink($blogid, $archive, $extra = '')\r
+{\r
+ return Link::create_archive_link($blogid, $archive, $extra);\r
+}\r
+function createBlogidLink($blogid, $params = '')\r
+{\r
+ return Link::create_blogid_link($blogid, $params = '');\r
+}\r
+function createLink($type, $params)\r
+{\r
+ return Link::create_link($type, $params);\r
+}\r
+function createBlogLink($url, $params)\r
+{\r
+ return Link::create_blog_link($url, $params);\r
+}\r