4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2009 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
15 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
16 * @version $Id: globalfunctions.php 1697 2012-03-10 13:15:47Z sakamocchi $
\r
19 /* needed if we include globalfunctions from install.php */
\r
20 global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALES, $manager, $member;
\r
22 $nucleus['version'] = 'v4.00 SVN';
\r
23 $nucleus['codename'] = '';
\r
25 /* check and die if someone is trying to override internal globals (when register_globals turn on) */
\r
26 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
29 if ( array_key_exists('debug', $CONF) && $CONF['debug'] )
\r
31 /* report all errors! */
\r
32 error_reporting(E_ALL);
\r
36 ini_set('display_errors','0');
\r
37 error_reporting(E_ERROR | E_WARNING | E_PARSE);
\r
41 * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
\r
43 if ( !isset($DIR_LOCALES) )
\r
45 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
48 if ( !isset($DIR_LANG) )
\r
50 $DIR_LANG = $DIR_LOCALES;
\r
54 * load and initialize i18n class
\r
56 if (!class_exists('i18n', FALSE))
\r
58 include($DIR_LIBS . 'i18n.php');
\r
60 if ( !i18n::init('UTF-8', $DIR_LOCALES) )
\r
62 exit('Fail to initialize i18n class.');
\r
65 * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
\r
67 define('_CHARSET', i18n::get_current_charset());
\r
70 * Indicates when Nucleus should display startup errors. Set to 1 if you want
\r
71 * the error enabled (default), false otherwise
\r
73 * alertOnHeadersSent
\r
74 * Displays an error when visiting a public Nucleus page and headers have
\r
75 * been sent out to early. This usually indicates an error in either a
\r
76 * configuration file or a translation file, and could cause Nucleus to
\r
78 * alertOnSecurityRisk
\r
79 * Displays an error only when visiting the admin area, and when one or
\r
80 * more of the installation files (install.php, install.sql, upgrades/
\r
81 * directory) are still on the server.
\r
83 if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )
\r
85 $CONF['alertOnHeadersSent'] = 1;
\r
87 $CONF['alertOnSecurityRisk'] = 1;
\r
89 * NOTE: this should be removed when releasing 4.0
\r
90 $CONF['ItemURL'] = $CONF['Self'];
\r
91 $CONF['ArchiveURL'] = $CONF['Self'];
\r
92 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
93 $CONF['MemberURL'] = $CONF['Self'];
\r
94 $CONF['SearchURL'] = $CONF['Self'];
\r
95 $CONF['BlogURL'] = $CONF['Self'];
\r
96 $CONF['CategoryURL'] = $CONF['Self'];
\r
100 * Set these to 1 to allow viewing of future items or draft items
\r
101 * Should really never do this, but can be useful for some plugins that might need to
\r
102 * Could cause some other issues if you use future posts otr drafts
\r
105 $CONF['allowDrafts'] = 0;
\r
106 $CONF['allowFuture'] = 0;
\r
108 if ( getNucleusPatchLevel() > 0 )
\r
110 $nucleus['version'] .= '/' . getNucleusPatchLevel();
\r
113 /* Avoid notices */
\r
114 if ( !isset($CONF['installscript']) )
\r
116 $CONF['installscript'] = 0;
\r
119 /* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/
\r
120 if ( $CONF['installscript'] != 1 )
\r
122 /* vars were already included in install.php */
\r
123 include_once($DIR_LIBS . 'vars4.1.0.php');
\r
126 /* sanitize option */
\r
127 $bLoggingSanitizedResult=0;
\r
128 $bSanitizeAndContinue=0;
\r
130 $orgRequestURI = serverVar('REQUEST_URI');
\r
133 /* get all variables that can come from the request and put them in the global scope */
\r
134 $blogid = requestVar('blogid');
\r
135 $itemid = intRequestVar('itemid');
\r
136 $catid = intRequestVar('catid');
\r
137 $skinid = requestVar('skinid');
\r
138 $memberid = requestVar('memberid');
\r
139 $archivelist = requestVar('archivelist');
\r
140 $imagepopup = requestVar('imagepopup');
\r
141 $archive = requestVar('archive');
\r
142 $query = requestVar('query');
\r
143 $highlight = requestVar('highlight');
\r
144 $amount = requestVar('amount');
\r
145 $action = requestVar('action');
\r
146 $nextaction = requestVar('nextaction');
\r
147 $maxresults = requestVar('maxresults');
\r
148 $startpos = intRequestVar('startpos');
\r
149 $errormessage = '';
\r
151 $special = requestVar('special');
\r
152 $virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));
\r
154 if ( !headers_sent() )
\r
156 header('Generator: Nucleus CMS ' . $nucleus['version']);
\r
159 /* include core classes that are needed for login & plugin handling */
\r
160 include_once($DIR_LIBS . 'mysql.php');
\r
161 /* added for 3.5 sql_* wrapper */
\r
162 global $MYSQL_HANDLER;
\r
163 if ( !isset($MYSQL_HANDLER) )
\r
165 $MYSQL_HANDLER = array('mysql','');
\r
167 if ( $MYSQL_HANDLER[0] == '' )
\r
169 $MYSQL_HANDLER[0] = 'mysql';
\r
171 include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');
\r
172 /* end new for 3.5 sql_* wrapper */
\r
173 include($DIR_LIBS . 'MEMBER.php');
\r
174 include($DIR_LIBS . 'ACTIONLOG.php');
\r
175 include($DIR_LIBS . 'MANAGER.php');
\r
176 include($DIR_LIBS . 'PLUGIN.php');
\r
178 $manager =& MANAGER::instance();
\r
181 * make sure there's no unnecessary escaping:
\r
182 * set_magic_quotes_runtime(0);
\r
184 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
186 ini_set('magic_quotes_runtime', '0');
\r
189 /* Avoid notices */
\r
190 if ( !array_key_exists('UsingAdminArea', $CONF) )
\r
192 $CONF['UsingAdminArea'] = 0;
\r
195 /* only needed when updating logs */
\r
196 if ( $CONF['UsingAdminArea'] )
\r
198 /* XML-RPC client classes */
\r
199 include($DIR_LIBS . 'xmlrpc.inc.php');
\r
200 include_once($DIR_LIBS . 'ADMIN.php');
\r
203 /* connect to database */
\r
207 /* logs sanitized result if need */
\r
208 if ( $orgRequestURI!==serverVar('REQUEST_URI') )
\r
210 $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";
\r
211 $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');
\r
212 if ( $bLoggingSanitizedResult )
\r
214 addToLog(WARNING, $msg);
\r
216 if ( !$bSanitizeAndContinue )
\r
222 /* makes sure database connection gets closed on script termination */
\r
223 register_shutdown_function('sql_disconnect');
\r
229 * FIXME: This is for backward compatibility, should be obsoleted near future.
\r
231 if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])
\r
232 && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )
\r
234 $CONF['Locale'] = 'en_Latn_US';
\r
236 if ( !array_key_exists('Language', $CONF) )
\r
238 $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);
\r
240 $locale = $CONF['Locale'];
\r
242 /* Properly set $CONF['Self'] and others if it's not set...
\r
243 * usually when we are access from admin menu
\r
245 if ( !array_key_exists('Self', $CONF) )
\r
247 $CONF['Self'] = $CONF['IndexURL'];
\r
248 /* strip trailing */
\r
249 if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )
\r
251 $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);
\r
255 $CONF['ItemURL'] = $CONF['Self'];
\r
256 $CONF['ArchiveURL'] = $CONF['Self'];
\r
257 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
258 $CONF['MemberURL'] = $CONF['Self'];
\r
259 $CONF['SearchURL'] = $CONF['Self'];
\r
260 $CONF['BlogURL'] = $CONF['Self'];
\r
261 $CONF['CategoryURL'] = $CONF['Self'];
\r
264 *switch URLMode back to normal when $CONF['Self'] ends in .php
\r
265 * this avoids urls like index.php/item/13/index.php/item/15
\r
267 if ( !array_key_exists('URLMode', $CONF)
\r
268 || (($CONF['URLMode'] == 'pathinfo')
\r
269 && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
\r
271 $CONF['URLMode'] = 'normal';
\r
274 /* automatically use simpler toolbar for mozilla */
\r
275 if ( ($CONF['DisableJsTools'] == 0)
\r
276 && strstr(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0')
\r
277 && strstr(serverVar('HTTP_USER_AGENT'), 'Gecko') )
\r
279 $CONF['DisableJsTools'] = 2;
\r
282 $member = new MEMBER();
\r
284 if ( $action == 'login' )
\r
286 $login = postVar('login');
\r
287 $password = postVar('password');
\r
288 $shared = intPostVar('shared');
\r
289 $member->login($login, $password, $shared);
\r
291 elseif ( ($action == 'logout') )
\r
297 $member->cookielogin();
\r
300 /* NOTE: include translation file and set locale */
\r
301 if ( $member->isLoggedIn() && $member->getLocale())
\r
303 $locale = $member->getLocale();
\r
305 include_translation($locale);
\r
306 i18n::set_current_locale($locale);
\r
308 /* login completed */
\r
309 $manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );
\r
312 if ( $member->isLoggedIn() && $nextaction )
\r
314 $action = $nextaction;
\r
318 * Release ticket for plugin
\r
322 /* first, let's see if the site is disabled or not. always allow admin area access. */
\r
323 if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )
\r
325 redirect($CONF['DisableSiteURL']);
\r
329 /* load other classes */
\r
330 include($DIR_LIBS . 'PARSER.php');
\r
331 include($DIR_LIBS . 'SKIN.php');
\r
332 include($DIR_LIBS . 'TEMPLATE.php');
\r
333 include($DIR_LIBS . 'BLOG.php');
\r
334 include($DIR_LIBS . 'BODYACTIONS.php');
\r
335 include($DIR_LIBS . 'COMMENTS.php');
\r
336 include($DIR_LIBS . 'COMMENT.php');
\r
337 /* include($DIR_LIBS . 'ITEM.php'); */
\r
338 include($DIR_LIBS . 'NOTIFICATION.php');
\r
339 include($DIR_LIBS . 'BAN.php');
\r
340 include($DIR_LIBS . 'PAGEFACTORY.php');
\r
341 include($DIR_LIBS . 'SEARCH.php');
\r
342 include($DIR_LIBS . 'ENTITY.php');
\r
343 include($DIR_LIBS . 'LINK.php');
\r
345 /* set lastVisit cookie (if allowed) */
\r
346 if ( !headers_sent() )
\r
348 if ( $CONF['LastVisit'] )
\r
350 setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
354 setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
358 if ( !defined('_ARCHIVETYPE_MONTH') )
\r
360 define('_ARCHIVETYPE_DAY', 'day');
\r
361 define('_ARCHIVETYPE_MONTH', 'month');
\r
362 define('_ARCHIVETYPE_YEAR', 'year');
\r
365 /* decode path_info */
\r
366 if ( $CONF['URLMode'] == 'pathinfo' )
\r
368 /* initialize keywords if this hasn't been done before */
\r
369 if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )
\r
371 $CONF['ItemKey'] = 'item';
\r
374 if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )
\r
376 $CONF['ArchiveKey'] = 'archive';
\r
379 if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )
\r
381 $CONF['ArchivesKey'] = 'archives';
\r
384 if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )
\r
386 $CONF['MemberKey'] = 'member';
\r
389 if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )
\r
391 $CONF['BlogKey'] = 'blog';
\r
394 if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )
\r
396 $CONF['CategoryKey'] = 'category';
\r
399 if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )
\r
401 $CONF['SpecialskinKey'] = 'special';
\r
408 /* e.g. item, blog, ... */
\r
409 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
410 'info' => $virtualpath,
\r
411 'complete' => &$parsed
\r
417 /* default implementation */
\r
418 $data = i18n::explode("/", $virtualpath );
\r
419 for ( $i = 0; $i < sizeof($data); $i++ )
\r
421 switch ( $data[$i] )
\r
423 /* item/1 (blogid) */
\r
424 case $CONF['ItemKey']:
\r
427 if ( $i < sizeof($data) )
\r
429 $itemid = intval($data[$i]);
\r
433 /* archives/1 (blogid) */
\r
434 case $CONF['ArchivesKey']:
\r
436 if ( $i < sizeof($data) )
\r
438 $archivelist = intval($data[$i]);
\r
442 /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
\r
443 case $CONF['ArchiveKey']:
\r
444 if ( (($i + 1) < sizeof($data) ) && (!strstr($data[$i + 1], '-') ) )
\r
446 $blogid = intval($data[++$i]);
\r
449 if ( $i < sizeof($data) )
\r
451 $archive = $data[$i];
\r
458 case $CONF['BlogKey']:
\r
460 if ( $i < sizeof($data) )
\r
462 $blogid = intval($data[$i]);
\r
466 /* category/1 (catid) */
\r
467 case $CONF['CategoryKey']:
\r
470 if ( $i < sizeof($data) )
\r
472 $catid = intval($data[$i]);
\r
476 case $CONF['MemberKey']:
\r
478 if ( $i < sizeof($data) )
\r
480 $memberid = intval($data[$i]);
\r
484 case $CONF['SpecialskinKey']:
\r
486 if ( $i < sizeof($data) )
\r
488 $special = $data[$i];
\r
489 $_REQUEST['special'] = $special;
\r
501 * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.
\r
502 * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking
\r
503 * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on
\r
504 * the values of something like catid or itemid
\r
510 /* e.g. item, blog, ... */
\r
511 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
512 'info' => $virtualpath
\r
517 * NOTE: Here is the end of initialization
\r
521 * This function includes or requires the specified library file
\r
522 * @param string $file
\r
523 * @param bool $once use the _once() version
\r
524 * @param bool $require use require() instead of include()
\r
526 function include_libs($file, $once = TRUE, $require = TRUE)
\r
530 // begin if: $DIR_LIBS isn't a directory
\r
531 if ( !is_dir($DIR_LIBS) )
\r
536 $lib_path = $DIR_LIBS . $file;
\r
539 if ( $once && $require )
\r
541 require_once($lib_path);
\r
543 else if ( $once && !$require )
\r
545 include_once($lib_path);
\r
547 else if ( $require )
\r
549 require($lib_path);
\r
553 include($lib_path);
\r
560 * This function includes or requires the specified plugin file
\r
561 * @param string $file
\r
562 * @param bool $once use the _once() version
\r
563 * @param bool $require use require() instead of include()
\r
565 function include_plugins($file, $once = TRUE, $require = TRUE)
\r
567 global $DIR_PLUGINS;
\r
569 // begin if: $DIR_LIBS isn't a directory
\r
570 if ( !is_dir($DIR_PLUGINS) )
\r
575 $plugin_path = $DIR_PLUGINS . $file;
\r
578 if ( $once && $require )
\r
580 require_once($plugin_path);
\r
582 else if ( $once && !$require )
\r
584 include_once($plugin_path);
\r
586 elseif ( $require )
\r
588 require($plugin_path);
\r
592 include($plugin_path);
\r
597 * This function decide which locale is used and include translation
\r
598 * @param string $locale locale name referring to 'language tags' defined in RFC 5646
\r
601 function include_translation($locale)
\r
603 global $DIR_LOCALES;
\r
605 $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';
\r
606 if ( !file_exists($translation_file) )
\r
608 $locale = 'en_Latn_US';
\r
609 $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';
\r
611 include($translation_file);
\r
616 * This function returns the integer value of $_POST for the variable $name
\r
617 * @param string $name field to get the integer value of
\r
620 function intPostVar($name)
\r
622 return intval(postVar($name));
\r
627 * This function returns the integer value of $_GET for the variable $name
\r
628 * @param string $name field to get the integer value of
\r
631 function intGetVar($name)
\r
633 return intval(getVar($name));
\r
638 * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST
\r
639 * @param string $name field to get the integer value of
\r
642 function intRequestVar($name)
\r
644 return intval(requestVar($name));
\r
649 * This function returns the integer value of $_COOKIE for the variable $name
\r
650 * @param string $name field to get the integer value of
\r
653 function intCookieVar($name)
\r
655 return intval(cookieVar($name));
\r
660 * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)
\r
663 function getNucleusVersion()
\r
670 * TODO: Better description of this function.
\r
672 * Power users can install patches in between nucleus releases. These patches
\r
673 * usually add new functionality in the plugin API and allow those to
\r
674 * be tested without having to install CVS.
\r
678 function getNucleusPatchLevel()
\r
685 * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data
\r
686 * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02
\r
687 * @return string|bool
\r
689 function getLatestVersion()
\r
691 // begin if: cURL is not available in this PHP installation
\r
692 if ( !function_exists('curl_init') )
\r
697 $curl = curl_init();
\r
699 curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');
\r
700 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
\r
701 curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
\r
702 $return = curl_exec($curl);
\r
709 * This function returns a Nucleus table name with the appropriate prefix
\r
710 * @param string $name
\r
713 function sql_table($name)
\r
715 global $MYSQL_PREFIX;
\r
717 // begin if: no MySQL prefix
\r
718 if ( empty($MYSQL_PREFIX) )
\r
720 return 'nucleus_' . $name;
\r
722 // else: use MySQL prefix
\r
725 return $MYSQL_PREFIX . 'nucleus_' . $name;
\r
732 * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.
\r
734 * This function sends the Content-Type header if headers have not already been sent
\r
735 * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.
\r
736 * @param string $content_type
\r
737 * @param string $page_type
\r
738 * @param string $charset Deprecated. This has no meaning.
\r
740 function sendContentType($content_type, $page_type = '', $charset = _CHARSET)
\r
742 global $manager, $CONF;
\r
744 if ( !headers_sent() )
\r
746 // if content type is application/xhtml+xml, only send it to browsers
\r
747 // that can handle it (IE6 cannot). Otherwise, send text/html
\r
749 // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)
\r
750 // application/xhtml+xml still causes too much problems with the javascript implementations
\r
752 // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,
\r
753 // application/xhtml+xml seems to be working, so we're going to use it if we can.
\r
755 if ( ($content_type == 'application/xhtml+xml')
\r
756 && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )
\r
758 $content_type = 'text/html';
\r
762 'PreSendContentType',
\r
764 'contentType' => &$content_type,
\r
765 'charset' => i18n::get_current_charset(),
\r
766 'pageType' => $page_type
\r
770 // strip strange characters
\r
771 $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);
\r
772 header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());
\r
779 * This function parses a query into an array of expressions that can be passed on to the highlight method
\r
780 * @param string $query
\r
782 function parseHighlight($query)
\r
784 // TODO: add more intelligent splitting logic
\r
786 // get rid of quotes
\r
787 $query = preg_replace('/\'|"/', '', $query);
\r
794 $aHighlight = i18n::explode(' ', $query);
\r
796 for ( $i = 0; $i < count($aHighlight); $i++ )
\r
798 $aHighlight[$i] = trim($aHighlight[$i]);
\r
800 if ( i18n::strlen($aHighlight[$i]) < 3 )
\r
802 unset($aHighlight[$i]);
\r
806 if ( count($aHighlight) == 1 )
\r
808 return $aHighlight[0];
\r
812 return $aHighlight;
\r
818 * This function gets the blog ID from the blog name
\r
819 * @param string $name
\r
822 function getBlogIDFromName($name)
\r
824 return quickQuery('SELECT `bnumber` AS `result` FROM `' . sql_table('blog') . '` WHERE `bshortname` = "' . sql_real_escape_string($name) . '"');
\r
829 * This function gets the blog name from the blog ID
\r
833 function getBlogNameFromID($id)
\r
835 return quickQuery('SELECT `bname` AS `result` FROM `' . sql_table('blog') . '` WHERE `bnumber` = ' . intval($id));
\r
840 * This function gets the blog ID from the item ID
\r
841 * @param int $item_id
\r
844 function getBlogIDFromItemID($item_id)
\r
846 return quickQuery('SELECT `iblog` AS `result` FROM `' . sql_table('item') . '` WHERE `inumber` = ' . intval($item_id));
\r
851 * This function gets the blog ID from the comment ID
\r
852 * @param int $comment_id
\r
855 function getBlogIDFromCommentID($comment_id)
\r
857 return quickQuery('SELECT `cblog` AS `result` FROM `' . sql_table('comment') . '` WHERE `cnumber` = ' . intval($comment_id));
\r
862 * This function gets the blog ID from the category ID
\r
863 * @param int $category_id
\r
866 function getBlogIDFromCatID($category_id)
\r
868 return quickQuery('SELECT `cblog` AS `result` FROM `' . sql_table('category') . '` WHERE `catid` = ' . intval($category_id));
\r
873 * This function gets the category ID from the category name
\r
877 function getCatIDFromName($name)
\r
879 return quickQuery('SELECT `catid` AS `result` FROM `' . sql_table('category') . '` WHERE `cname` = "' . sql_real_escape_string($name) . '"');
\r
884 * This function performs a quick SQL query
\r
885 * @param string $query
\r
888 function quickQuery($query)
\r
890 $res = sql_query($query);
\r
891 $obj = sql_fetch_object($res);
\r
892 return $obj->result;
\r
895 function getPluginNameFromPid($pid) {
\r
896 $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );
\r
897 $obj = sql_fetch_object($res);
\r
898 return $obj->pfile;
\r
899 // return isset($obj->pfile) ? $obj->pfile : false;
\r
902 function selector()
\r
904 global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
\r
905 global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
\r
906 global $imagepopup, $catid, $special;
\r
909 $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');
\r
910 $action = requestVar('action');
\r
912 if ( in_array($action, $actionNames) )
\r
914 global $DIR_LIBS, $errormessage;
\r
915 include_once($DIR_LIBS . 'ACTION.php');
\r
917 $errorInfo = $a->doAction($action);
\r
921 $errormessage = $errorInfo['message'];
\r
925 // show error when headers already sent out
\r
926 if ( headers_sent() && $CONF['alertOnHeadersSent'] )
\r
928 // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)
\r
929 if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )
\r
931 headers_sent($hsFile, $hsLine);
\r
932 $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';
\r
940 '<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
941 'Page headers already sent'
\r
946 // make is so ?archivelist without blogname or blogid shows the archivelist
\r
947 // for the default weblog
\r
948 if ( serverVar('QUERY_STRING') == 'archivelist' )
\r
950 $archivelist = $CONF['DefaultBlog'];
\r
953 // now decide which type of skin we need
\r
956 // itemid given -> only show that item
\r
959 if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )
\r
961 doError(_ERROR_NOSUCHITEM);
\r
964 global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
\r
966 // 1. get timestamp, blogid and catid for item
\r
967 $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';
\r
968 $query = sprintf($query, sql_table('item'), (integer) $itemid);
\r
969 $res = sql_query($query);
\r
970 $obj = sql_fetch_object($res);
\r
972 // if a different blog id has been set through the request or selectBlog(),
\r
975 if ( $blogid && (intval($blogid) != $obj->iblog) )
\r
977 doError(_ERROR_NOSUCHITEM);
\r
980 // if a category has been selected which doesn't match the item, ignore the
\r
982 if ( ($catid != 0) && ($catid != $obj->icat) )
\r
987 $blogid = $obj->iblog;
\r
988 $timestamp = strtotime($obj->itime);
\r
990 $b =& $manager->getBlog($blogid);
\r
992 if ( !$b->isValidCategory($catid) )
\r
994 $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";
\r
995 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);
\r
999 $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
1000 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);
\r
1003 $res = sql_query($query);
\r
1004 $obj = sql_fetch_object($res);
\r
1008 $itemidprev = $obj->inumber;
\r
1009 $itemtitleprev = $obj->ititle;
\r
1012 // get next itemid and title
\r
1013 if ( !$b->isValidCategory($catid) )
\r
1015 $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
1016 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);
\r
1020 $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
1021 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);
\r
1024 $res = sql_query($query);
\r
1026 $obj = sql_fetch_object($res);
\r
1030 $itemidnext = $obj->inumber;
\r
1031 $itemtitlenext = $obj->ititle;
\r
1034 elseif ( $archive )
\r
1037 $type = 'archive';
\r
1039 // get next and prev month links ...
\r
1040 global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;
\r
1042 // sql queries for the timestamp of the first and the last published item
\r
1043 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";
\r
1044 $first_timestamp=quickQuery ($query);
\r
1045 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";
\r
1046 $last_timestamp=quickQuery ($query);
\r
1048 sscanf($archive, '%d-%d-%d', $y, $m, $d);
\r
1052 $archivetype = _ARCHIVETYPE_DAY;
\r
1053 $t = mktime(0, 0, 0, $m, $d, $y);
\r
1054 // one day has 24 * 60 * 60 = 86400 seconds
\r
1055 $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 );
\r
1056 // check for published items
\r
1057 if ( $t > $first_timestamp )
\r
1059 $archiveprevexists = true;
\r
1063 $archiveprevexists = false;
\r
1068 $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t);
\r
1069 if ( $t < $last_timestamp )
\r
1071 $archivenextexists = true;
\r
1075 $archivenextexists = false;
\r
1078 elseif ( $m == 0 )
\r
1080 $archivetype = _ARCHIVETYPE_YEAR;
\r
1081 $t = mktime(0, 0, 0, 12, 31, $y - 1);
\r
1082 // one day before is in the previous year
\r
1083 $archiveprev = i18n::formatted_datetime('%Y', $t);
\r
1084 if ( $t > $first_timestamp )
\r
1086 $archiveprevexists = true;
\r
1090 $archiveprevexists = false;
\r
1093 // timestamp for the next year
\r
1094 $t = mktime(0, 0, 0, 1, 1, $y + 1);
\r
1095 $archivenext = i18n::formatted_datetime('%Y', $t);
\r
1096 if ( $t < $last_timestamp )
\r
1098 $archivenextexists = true;
\r
1102 $archivenextexists = false;
\r
1107 $archivetype = _ARCHIVETYPE_MONTH;
\r
1108 $t = mktime(0, 0, 0, $m, 1, $y);
\r
1109 // one day before is in the previous month
\r
1110 $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400);
\r
1111 if ( $t > $first_timestamp )
\r
1113 $archiveprevexists = true;
\r
1117 $archiveprevexists = false;
\r
1120 // timestamp for the next month
\r
1121 $t = mktime(0, 0, 0, $m+1, 1, $y);
\r
1122 $archivenext = i18n::formatted_datetime('%Y-%m', $t);
\r
1123 if ( $t < $last_timestamp )
\r
1125 $archivenextexists = true;
\r
1129 $archivenextexists = false;
\r
1133 elseif ( $archivelist )
\r
1135 $type = 'archivelist';
\r
1137 if ( is_numeric($archivelist) )
\r
1139 $blogid = intVal($archivelist);
\r
1143 $blogid = getBlogIDFromName($archivelist);
\r
1148 doError(_ERROR_NOSUCHBLOG);
\r
1155 $query = stripslashes($query);
\r
1157 if ( is_numeric($blogid) )
\r
1159 $blogid = intVal($blogid);
\r
1163 $blogid = getBlogIDFromName($blogid);
\r
1168 doError(_ERROR_NOSUCHBLOG);
\r
1171 elseif ( $memberid )
\r
1175 if ( !MEMBER::existsID($memberid) )
\r
1177 doError(_ERROR_NOSUCHMEMBER);
\r
1179 $memberinfo = $manager->getMember($memberid);
\r
1181 elseif ( $imagepopup )
\r
1183 // media object (images etc.)
\r
1184 $type = 'imagepopup';
\r
1186 // TODO: check if media-object exists
\r
1187 // TODO: set some vars?
\r
1191 // show regular index page
\r
1196 // any type of skin with catid
\r
1197 if ( $catid && !$blogid )
\r
1199 $blogid = getBlogIDFromCatID($catid);
\r
1202 // decide which blog should be displayed
\r
1205 $blogid = $CONF['DefaultBlog'];
\r
1208 $b =& $manager->getBlog($blogid);
\r
1209 $blog = $b; // references can't be placed in global variables?
\r
1211 if ( !$blog->isValid )
\r
1213 doError(_ERROR_NOSUCHBLOG);
\r
1216 // set catid if necessary
\r
1219 // check if the category is valid
\r
1220 if ( !$blog->isValidCategory($catid) )
\r
1222 doError(_ERROR_NOSUCHCATEGORY);
\r
1226 $blog->setSelectedCategory($catid);
\r
1230 // decide which skin should be used
\r
1231 if ( $skinid != '' && ($skinid == 0) )
\r
1233 selectSkin($skinid);
\r
1238 $skinid = $blog->getDefaultSkin();
\r
1241 //$special = requestVar('special'); //get at top of file as global
\r
1242 if ( !empty($special) && isValidShortName($special) )
\r
1244 $type = strtolower($special);
\r
1247 $skin = new SKIN($skinid);
\r
1249 if ( !$skin->isValid )
\r
1251 doError(_ERROR_NOSUCHSKIN);
\r
1254 // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude
\r
1256 $skinpart = $type;
\r
1259 $skin->parse($type);
\r
1261 // check to see we should throw JustPosted event
\r
1262 $blog->checkJustPosted();
\r
1267 * Show error skin with given message. An optional skin-object to use can be given
\r
1269 function doError($msg, $skin = '') {
\r
1270 global $errormessage, $CONF, $skinid, $blogid, $manager;
\r
1272 if ($skin == '') {
\r
1274 if (SKIN::existsID($skinid) ) {
\r
1275 $skin = new SKIN($skinid);
\r
1276 } elseif ($manager->existsBlogID($blogid) ) {
\r
1277 $blog =& $manager->getBlog($blogid);
\r
1278 $skin = new SKIN($blog->getDefaultSkin() );
\r
1279 } elseif ($CONF['DefaultBlog']) {
\r
1280 $blog =& $manager->getBlog($CONF['DefaultBlog']);
\r
1281 $skin = new SKIN($blog->getDefaultSkin() );
\r
1283 // this statement should actually never be executed
\r
1284 $skin = new SKIN($CONF['BaseSkin']);
\r
1289 $skinid = $skin->id;
\r
1290 $errormessage = $msg;
\r
1291 $skin->parse('error');
\r
1295 function getConfig() {
\r
1298 $query = 'SELECT * FROM ' . sql_table('config');
\r
1299 $res = sql_query($query);
\r
1301 while ($obj = sql_fetch_object($res) ) {
\r
1302 $CONF[$obj->name] = $obj->value;
\r
1306 // some checks for names of blogs, categories, templates, members, ...
\r
1307 function isValidShortName($name) {
\r
1309 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1310 # original eregi: eregi('^[a-z0-9]+$', $name)
\r
1312 return preg_match('#^[a-z0-9]+$#i', $name);
\r
1316 function isValidDisplayName($name) {
\r
1318 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1319 # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)
\r
1321 return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);
\r
1325 function isValidCategoryName($name) {
\r
1329 function isValidTemplateName($name) {
\r
1331 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1332 # original eregi: eregi('^[a-z0-9/]+$', $name)
\r
1333 // added - and _ to valid characters as of 4.00
\r
1335 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1339 function isValidSkinName($name) {
\r
1341 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1342 # original eregi: eregi('^[a-z0-9/]+$', $name);
\r
1343 // added - and _ to valid characters as of 4.00
\r
1345 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1349 // add and remove linebreaks
\r
1350 function addBreaks($var) {
\r
1351 return nl2br($var);
\r
1354 function removeBreaks($var) {
\r
1355 return preg_replace("/<br \/>([\r\n])/", "$1", $var);
\r
1359 * functions for use in index.php
\r
1361 function selectBlog($shortname) {
\r
1362 global $blogid, $archivelist;
\r
1363 $blogid = getBlogIDFromName($shortname);
\r
1365 // also force archivelist variable, if it is set
\r
1366 if ($archivelist) {
\r
1367 $archivelist = $blogid;
\r
1371 function selectSkin($skinname) {
\r
1373 $skinid = SKIN::getIdFromName($skinname);
\r
1377 * Can take either a category ID or a category name (be aware that
\r
1378 * multiple categories can have the same name)
\r
1380 function selectCategory($cat) {
\r
1382 if (is_numeric($cat) ) {
\r
1383 $catid = intval($cat);
\r
1385 $catid = getCatIDFromName($cat);
\r
1389 function selectItem($id) {
\r
1391 $itemid = intval($id);
\r
1394 // force the use of a translation file (warning: can cause warnings)
\r
1395 function selectLanguage($language) {
\r
1399 # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
\r
1400 # original ereg_replace: preg_replace( '@\\|/@', '', $language) . '.php')
\r
1401 # important note that '\' must be matched with '\\\\' in preg* expressions
\r
1403 include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');
\r
1407 function parseFile($filename, $includeMode = 'normal', $includePrefix = '') {
\r
1408 $handler = new ACTIONS('fileparser');
\r
1409 $parser = new PARSER(SKIN::getAllowedActionsForType('fileparser'), $handler);
\r
1410 $handler->parser =& $parser;
\r
1412 // set IncludeMode properties of parser
\r
1413 PARSER::setProperty('IncludeMode', $includeMode);
\r
1414 PARSER::setProperty('IncludePrefix', $includePrefix);
\r
1416 if (!file_exists($filename) ) {
\r
1417 doError('A file is missing');
\r
1420 $fsize = filesize($filename);
\r
1422 if ($fsize <= 0) {
\r
1427 $fd = fopen ($filename, 'r');
\r
1428 $contents = fread ($fd, $fsize);
\r
1431 // parse file contents
\r
1432 $parser->parse($contents);
\r
1436 * Outputs a debug message
\r
1438 function debug($msg) {
\r
1439 echo '<p><b>' . $msg . "</b></p>\n";
\r
1443 function addToLog($level, $msg) {
\r
1444 ACTIONLOG::add($level, $msg);
\r
1447 // shows a link to help file
\r
1448 function help($id) {
\r
1449 echo helpHtml($id);
\r
1452 function helpHtml($id) {
\r
1454 return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';
\r
1457 function helplink($id) {
\r
1459 return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';
\r
1463 * Includes a PHP file. This method can be called while parsing templates and skins
\r
1465 function includephp($filename) {
\r
1466 // make predefined variables global, so most simple scripts can be used here
\r
1468 // apache (names taken from PHP doc)
\r
1469 global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;
\r
1470 global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;
\r
1471 global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;
\r
1472 global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;
\r
1473 global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;
\r
1474 global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;
\r
1475 global $REQUEST_URI;
\r
1477 // php (taken from PHP doc)
\r
1478 global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1479 global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
\r
1482 global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;
\r
1484 if (@file_exists($filename) ) {
\r
1485 include($filename);
\r
1490 * Checks if a certain plugin exists
\r
1491 * @param string $plug
\r
1494 function checkPlugin($plug) {
\r
1496 global $DIR_PLUGINS;
\r
1498 # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
\r
1499 # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')
\r
1500 # important note that '\' must be matched with '\\\\' in preg* expressions
\r
1502 return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');
\r
1507 * @param $querystr
\r
1508 * querystring to alter (e.g. foo=1&bar=2&x=y)
\r
1510 * name of parameter to change (e.g. 'foo')
\r
1512 * New value for that parameter (e.g. 3)
\r
1514 * altered query string (for the examples above: foo=3&bar=2&x=y)
\r
1516 function alterQueryStr($querystr, $param, $value) {
\r
1517 $vars = i18n::explode('&', $querystr);
\r
1520 for ($i = 0; $i < count($vars); $i++) {
\r
1521 $v = i18n::explode('=', $vars[$i]);
\r
1523 if ($v[0] == $param) {
\r
1525 $vars[$i] = implode('=', $v);
\r
1532 $vars[] = $param . '=' . $value;
\r
1535 return ltrim(implode('&', $vars), '&');
\r
1538 // passes one variable as hidden input field (multiple fields for arrays)
\r
1539 // @see passRequestVars in varsx.x.x.php
\r
1540 function passVar($key, $value) {
\r
1542 if (is_array($value) ) {
\r
1543 for ($i = 0; $i < sizeof($value); $i++) {
\r
1544 passVar($key . '[' . $i . ']', $value[$i]);
\r
1550 // other values: do stripslashes if needed
\r
1551 ?><input type="hidden" name="<?php echo ENTITY::hsc($key)?>" value="<?php echo ENTITY::hsc(undoMagic($value) )?>" /><?php
\r
1554 function checkVars($aVars) {
\r
1555 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
\r
1557 foreach ($aVars as $varName) {
\r
1559 if (phpversion() >= '4.1.0') {
\r
1561 if ( isset($_GET[$varName])
\r
1562 || isset($_POST[$varName])
\r
1563 || isset($_COOKIE[$varName])
\r
1564 || isset($_ENV[$varName])
\r
1565 || isset($_SESSION[$varName])
\r
1566 || isset($_FILES[$varName])
\r
1568 die('Sorry. An error occurred.');
\r
1573 if ( isset($HTTP_GET_VARS[$varName])
\r
1574 || isset($HTTP_POST_VARS[$varName])
\r
1575 || isset($HTTP_COOKIE_VARS[$varName])
\r
1576 || isset($HTTP_ENV_VARS[$varName])
\r
1577 || isset($HTTP_SESSION_VARS[$varName])
\r
1578 || isset($HTTP_POST_FILES[$varName])
\r
1580 die('Sorry. An error occurred.');
\r
1589 * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.
\r
1592 function sanitizeParams()
\r
1594 global $HTTP_SERVER_VARS;
\r
1600 // REQUEST_URI of $HTTP_SERVER_VARS
\r
1601 $str =& $HTTP_SERVER_VARS["REQUEST_URI"];
\r
1602 serverStringToArray($str, $array, $frontParam);
\r
1603 sanitizeArray($array);
\r
1604 arrayToServerString($array, $frontParam, $str);
\r
1606 // QUERY_STRING of $HTTP_SERVER_VARS
\r
1607 $str =& $HTTP_SERVER_VARS["QUERY_STRING"];
\r
1608 serverStringToArray($str, $array, $frontParam);
\r
1609 sanitizeArray($array);
\r
1610 arrayToServerString($array, $frontParam, $str);
\r
1612 if (phpversion() >= '4.1.0') {
\r
1613 // REQUEST_URI of $_SERVER
\r
1614 $str =& $_SERVER["REQUEST_URI"];
\r
1615 serverStringToArray($str, $array, $frontParam);
\r
1616 sanitizeArray($array);
\r
1617 arrayToServerString($array, $frontParam, $str);
\r
1619 // QUERY_STRING of $_SERVER
\r
1620 $str =& $_SERVER["QUERY_STRING"];
\r
1621 serverStringToArray($str, $array, $frontParam);
\r
1622 sanitizeArray($array);
\r
1623 arrayToServerString($array, $frontParam, $str);
\r
1627 convArrayForSanitizing($_GET, $array);
\r
1628 sanitizeArray($array);
\r
1629 revertArrayForSanitizing($array, $_GET);
\r
1631 // $_REQUEST (only GET param)
\r
1632 convArrayForSanitizing($_REQUEST, $array);
\r
1633 sanitizeArray($array);
\r
1634 revertArrayForSanitizing($array, $_REQUEST);
\r
1638 * Check ticket when not checked in plugin's admin page
\r
1640 * Also avoid the access to plugin/index.php by guest user.
\r
1642 function ticketForPlugin()
\r
1644 global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;
\r
1647 $ticketforplugin = array();
\r
1648 $ticketforplugin['ticket'] = FALSE;
\r
1650 /* $_SERVER['PATH_TRANSLATED']
\r
1651 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1652 * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
\r
1653 * under the Apache 2 SAPI in contrast to the situation in Apache 1,
\r
1654 * where it's set to the same value as the SCRIPT_FILENAME server variable
\r
1655 * when it's not populated by Apache.
\r
1656 * This change was made to comply with the CGI specification
\r
1657 * that PATH_TRANSLATED should only exist if PATH_INFO is defined.
\r
1658 * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
\r
1661 /* Check if using plugin's php file. */
\r
1662 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1664 if (!file_exists($p_translated) )
\r
1666 header("HTTP/1.0 404 Not Found");
\r
1670 $p_translated = str_replace('\\', '/', $p_translated);
\r
1671 $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);
\r
1673 // This isn't plugin php file.
\r
1674 if ( i18n::strpos($p_translated, $d_plugins) !== 0 )
\r
1679 // Solve the plugin php file or admin directory
\r
1680 $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );
\r
1681 // Remove the first "/" if exists.
\r
1682 $phppath = preg_replace('#^/#', '', $phppath);
\r
1683 // Remove the first "NP_" and the last ".php" if exists.
\r
1684 $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);
\r
1685 // Remove the "/" and beyond.
\r
1686 $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);
\r
1688 // Solve the plugin name.
\r
1689 $plugins = array();
\r
1690 $query = 'SELECT `pfile` FROM '.sql_table('plugin');
\r
1691 $res = sql_query($query);
\r
1693 while($row = sql_fetch_row($res) )
\r
1695 $name = i18n::substr($row[0], 3);
\r
1696 $plugins[strtolower($name)] = $name;
\r
1699 sql_free_result($res);
\r
1701 if (array_key_exists($path, $plugins))
\r
1703 $plugin_name = $plugins[$path];
\r
1705 else if (in_array($path, $plugins))
\r
1707 $plugin_name = $path;
\r
1711 header("HTTP/1.0 404 Not Found");
\r
1715 /* Return if not index.php */
\r
1716 if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )
\r
1721 /* Exit if not logged in. */
\r
1722 if ( !$member->isLoggedIn() )
\r
1724 exit('You aren\'t logged in.');
\r
1727 global $manager, $DIR_LIBS, $DIR_LOCALES, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1729 /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */
\r
1730 if (!($p_translated = serverVar('PATH_TRANSLATED') ) )
\r
1732 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1735 if ($file = @file($p_translated) )
\r
1739 foreach($file as $line)
\r
1741 if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )
\r
1746 $prevline = $line;
\r
1750 /* Show a form if not valid ticket */
\r
1751 if ( ( strstr(serverVar('REQUEST_URI'), '?') || serverVar('QUERY_STRING')
\r
1752 || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')
\r
1753 && (!$manager->checkTicket() ) )
\r
1755 $oPluginAdmin = new PluginAdmin($plugin_name);
\r
1756 $oPluginAdmin->start();
\r
1757 echo '<p>' . _ERROR_BADTICKET . "</p>\n";
\r
1759 /* Show the form to confirm action */
\r
1760 // PHP 4.0.x support
\r
1761 $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;
\r
1762 $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;
\r
1764 // Resolve URI and QUERY_STRING
\r
1765 if ($uri = serverVar('REQUEST_URI') )
\r
1767 list($uri, $qstring) = i18n::explode('?', $uri);
\r
1771 if ( !($uri = serverVar('PHP_SELF') ) )
\r
1773 $uri = serverVar('SCRIPT_NAME');
\r
1775 $qstring = serverVar('QUERY_STRING');
\r
1779 $qstring = '?' . $qstring;
\r
1782 echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . ENTITY::hsc($plugin_name) . "</span> ?</p>\n";
\r
1784 switch(strtoupper(serverVar('REQUEST_METHOD') ) )
\r
1787 echo '<form method="POST" action="'.ENTITY::hsc($uri.$qstring).'">';
\r
1788 $manager->addTicketHidden();
\r
1789 _addInputTags($post);
\r
1793 echo '<form method="GET" action="'.ENTITY::hsc($uri).'">';
\r
1794 $manager->addTicketHidden();
\r
1795 _addInputTags($get);
\r
1801 echo '<input type="submit" value="' . _YES . '" /> ';
\r
1802 echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';
\r
1805 $oPluginAdmin->end();
\r
1809 /* Create new ticket */
\r
1810 $ticket=$manager->addTicketToUrl('');
\r
1811 $ticketforplugin['ticket']=i18n::substr($ticket,i18n::strpos($ticket,'ticket=')+7);
\r
1814 function _addInputTags(&$keys,$prefix=''){
\r
1815 foreach($keys as $key=>$value){
\r
1816 if ($prefix) $key=$prefix.'['.$key.']';
\r
1817 if (is_array($value)) _addInputTags($value,$key);
\r
1819 if (get_magic_quotes_gpc()) $value=stripslashes($value);
\r
1820 if ($key=='ticket') continue;
\r
1821 echo '<input type="hidden" name="'.ENTITY::hsc($key).
\r
1822 '" value="'.ENTITY::hsc($value).'" />'."\n";
\r
1828 * Convert the server string such as $_SERVER['REQUEST_URI']
\r
1829 * to arry like arry['blogid']=1 and array['page']=2 etc.
\r
1831 function serverStringToArray($str, &$array, &$frontParam)
\r
1837 // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2
\r
1838 if (strstr($str, "?")){
\r
1839 list($frontParam, $args) = preg_split("/\?/", $str, 2);
\r
1846 // If there is no args like blogid=1&page=2, return
\r
1847 if (!strstr($str, "=") && !i18n::strlen($frontParam)) {
\r
1848 $frontParam = $str;
\r
1852 $array = i18n::explode("&", $args);
\r
1856 * Convert array like array['blogid'] to server string
\r
1857 * such as $_SERVER['REQUEST_URI']
\r
1859 function arrayToServerString($array, $frontParam, &$str)
\r
1861 if (strstr($str, "?")) {
\r
1862 $str = $frontParam . "?";
\r
1864 $str = $frontParam;
\r
1866 if (count($array)) {
\r
1867 $str .= implode("&", $array);
\r
1872 * Sanitize array parameters.
\r
1873 * This function checks both key and value.
\r
1874 * - check key if it inclues " (double quote), remove from array
\r
1875 * - check value if it includes \ (escape sequece), remove remaining string
\r
1877 function sanitizeArray(&$array)
\r
1879 $excludeListForSanitization = array('query');
\r
1880 // $excludeListForSanitization = array();
\r
1882 foreach ($array as $k => $v) {
\r
1884 // split to key and value
\r
1885 list($key, $val) = preg_split("/=/", $v, 2);
\r
1886 if (!isset($val)) {
\r
1890 // when magic quotes is on, need to use stripslashes,
\r
1891 // and then addslashes
\r
1892 if (get_magic_quotes_gpc()) {
\r
1893 $val = stripslashes($val);
\r
1895 // note that we must use addslashes here because this function is called before the db connection is made
\r
1896 // and sql_real_escape_string needs a db connection
\r
1897 $val = addslashes($val);
\r
1899 // if $key is included in exclude list, skip this param
\r
1900 if (!in_array($key, $excludeListForSanitization)) {
\r
1903 if (i18n::strpos($val, '\\')) {
\r
1904 list($val, $tmp) = i18n::explode('\\', $val);
\r
1907 // remove control code etc.
\r
1908 $val = strtr($val, "\0\r\n<>'\"", " ");
\r
1911 if (preg_match('/\"/i', $key)) {
\r
1912 unset($array[$k]);
\r
1916 // set sanitized info
\r
1917 $array[$k] = sprintf("%s=%s", $key, $val);
\r
1923 * Convert array for sanitizeArray function
\r
1925 function convArrayForSanitizing($src, &$array)
\r
1928 foreach ($src as $key => $val) {
\r
1929 if (key_exists($key, $_GET)) {
\r
1930 array_push($array, sprintf("%s=%s", $key, $val));
\r
1936 * Revert array after sanitizeArray function
\r
1938 function revertArrayForSanitizing($array, &$dst)
\r
1940 foreach ($array as $v) {
\r
1941 list($key, $val) = preg_split("/=/", $v, 2);
\r
1942 $dst[$key] = $val;
\r
1947 * Stops processing the request and redirects to the given URL.
\r
1948 * - no actual contents should have been sent to the output yet
\r
1949 * - the URL will be stripped of illegal or dangerous characters
\r
1951 function redirect($url) {
\r
1952 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);
\r
1953 header('Location: ' . $url);
\r
1958 * Returns the Javascript code for a bookmarklet that works on most modern browsers
\r
1961 function getBookmarklet($blogid) {
\r
1965 $document = 'document';
\r
1966 $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
1967 $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";
\r
1968 $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
1970 return $bookmarkletline;
\r
1972 // END: functions from the end of file ADMIN.php
\r
1975 * Returns a variable or null if not set
\r
1977 * @param mixed Variable
\r
1978 * @return mixed Variable
\r
1980 function ifset(&$var) {
\r
1981 if (isset($var)) {
\r
1989 * Returns number of subscriber to an event
\r
1992 * @return number of subscriber(s)
\r
1994 function numberOfEventSubscriber($event) {
\r
1995 $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';
\r
1996 $res = sql_query($query);
\r
1997 $obj = sql_fetch_object($res);
\r
1998 return $obj->count;
\r
2002 * sets $special global variable for use in index.php before selector()
\r
2004 * @param String id
\r
2007 function selectSpecialSkinType($id) {
\r
2009 $special = strtolower($id);
\r
2013 * cleans filename of uploaded file for writing to file system
\r
2015 * @param String str
\r
2016 * @return String cleaned filename ready for use
\r
2018 function cleanFileName($str) {
\r
2019 $str = strtolower($str);
\r
2020 $ext_point = i18n::strrpos($str,".");
\r
2021 if ($ext_point===false) return false;
\r
2022 $ext = i18n::substr($str,$ext_point,i18n::strlen($str));
\r
2023 $str = i18n::substr($str,0,$ext_point);
\r
2025 return preg_replace("/[^a-z0-9-]/","_",$str).$ext;
\r
2029 * Centralisation of the functions to send mail
\r
2030 * Deprecated since 4.0:
\r
2031 * Please use functions in NOTIFICATION class instead
\r
2033 function getMailFooter()
\r
2035 NOTIFICATION::get_mail_footer();
\r
2037 function isValidMailAddress($address)
\r
2039 return NOTIFICATION::address_validation($address);
\r
2042 * Centralisation of the functions that deals XML entities
\r
2043 * Deprecated since 4.0:
\r
2044 * Please use ENTITY::FunctionName(...) instead
\r
2046 function highlight($text, $expression, $highlight)
\r
2048 return ENTITY::highlight($text, $expression, $highlight);
\r
2050 function shorten($string, $maxlength, $suffix)
\r
2052 return ENTITY::shorten($string, $maxlength, $suffix);
\r
2054 function stringStripTags ($string)
\r
2056 return ENTITY::strip_tags($string);
\r
2058 function toAscii($string)
\r
2060 return ENTITY::anchor_footnoting($string);
\r
2062 function stringToAttribute ($string)
\r
2064 return ENTITY::hsc($string);
\r
2066 function stringToXML ($string)
\r
2068 return ENTITY::hen($string);
\r
2070 function encode_desc($data)
\r
2072 return ENTITY::hen($data);
\r
2075 * Centralisation of the functions that deals with locales
\r
2076 * This functions is based on the old way to deal with languages
\r
2077 * Deprecated since 4.0:
\r
2079 /* NOTE: use i18n::get_current_locale() directly instead of this */
\r
2080 function getLanguageName()
\r
2082 if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )
\r
2084 $language ='english';
\r
2089 /* NOTE: use i18n::get_available_locales() directly instead of this */
\r
2090 function checkLanguage($lang)
\r
2092 return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)
\r
2093 || i18n::convert_old_language_file_name_to_locale($lang) );
\r
2095 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2096 function formatDate($format, $timestamp, $default_format, &$blog)
\r
2098 $offset = date('Z', $timestamp);
\r
2101 $offset += $blog->getTimeOffset() * 3600;
\r
2103 return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);
\r
2105 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2106 function mysqldate($timestamp)
\r
2108 return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';
\r
2111 * Centralisation of the functions that generate links
\r
2112 * Deprecated since 4.0:
\r
2113 * Please use LINK::FunctionName(...) instead
\r
2115 function createItemLink($itemid, $extra = '')
\r
2117 return LINK::create_item_link($itemid, $extra);
\r
2119 function createMemberLink($memberid, $extra = '')
\r
2121 return LINK::create_member_link($memberid, $extra);
\r
2123 function createCategoryLink($catid, $extra = '')
\r
2125 return LINK::create_category_link($catid, $extra);
\r
2127 function createArchiveListLink($blogid = '', $extra = '')
\r
2129 return LINK::create_archivelist_link($blogid, $extra);
\r
2131 function createArchiveLink($blogid, $archive, $extra = '')
\r
2133 return LINK::create_archive_link($blogid, $archive, $extra);
\r
2135 function createBlogidLink($blogid, $params = '')
\r
2137 return LINK::create_blogid_link($blogid, $params = '');
\r
2139 function createLink($type, $params)
\r
2141 return LINK::create_link($type, $params);
\r
2143 function createBlogLink($url, $params)
\r
2145 return LINK::create_blog_link($url, $params);
\r