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 1825 2012-05-04 16:56:35Z 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
26 * make sure there's no unnecessary escaping:
\r
27 * set_magic_quotes_runtime(0);
\r
29 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
31 ini_set('magic_quotes_runtime', '0');
\r
34 /* check and die if someone is trying to override internal globals (when register_globals turn on) */
\r
35 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
37 if ( !isset($CONF) )
\r
43 if ( array_key_exists('debug', $CONF) && $CONF['debug'] )
\r
45 /* report all errors! */
\r
46 error_reporting(E_ALL);
\r
50 ini_set('display_errors','0');
\r
51 error_reporting(E_ERROR | E_WARNING | E_PARSE);
\r
55 * alertOnHeadersSent
\r
56 * Displays an error when visiting a public Nucleus page and headers have
\r
57 * been sent out to early. This usually indicates an error in either a
\r
58 * configuration file or a translation file, and could cause Nucleus to
\r
61 if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )
\r
63 $CONF['alertOnHeadersSent'] = 1;
\r
66 * alertOnSecurityRisk
\r
67 * Displays an error only when visiting the admin area, and when one or
\r
68 * more of the installation files (install.php, install.sql, upgrades/
\r
69 * directory) are still on the server.
\r
71 $CONF['alertOnSecurityRisk'] = 1;
\r
74 * Set these to 1 to allow viewing of future items or draft items
\r
75 * Should really never do this, but can be useful for some plugins that might need to
\r
76 * Could cause some other issues if you use future posts otr drafts
\r
79 $CONF['allowDrafts'] = 0;
\r
80 $CONF['allowFuture'] = 0;
\r
82 if ( getNucleusPatchLevel() > 0 )
\r
84 $nucleus['version'] .= '/' . getNucleusPatchLevel();
\r
88 if ( !array_key_exists('installscript', $CONF) || empty($CONF['installscript']) )
\r
90 $CONF['installscript'] = 0;
\r
92 if ( !array_key_exists('UsingAdminArea', $CONF) )
\r
94 $CONF['UsingAdminArea'] = 0;
\r
97 if ( !headers_sent() )
\r
99 header('Generator: Nucleus CMS ' . $nucleus['version']);
\r
103 /* TODO: This is for compatibility since 4.0, should be obsoleted at future release. */
\r
104 if ( !isset($DIR_LOCALES) )
\r
106 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
109 if ( !isset($DIR_LANG) )
\r
111 $DIR_LANG = $DIR_LOCALES;
\r
114 /* load and initialize i18n class */
\r
115 if (!class_exists('i18n', FALSE))
\r
117 include($DIR_LIBS . 'i18n.php');
\r
119 if ( !i18n::init('UTF-8', $DIR_LOCALES) )
\r
121 exit('Fail to initialize i18n class.');
\r
124 /* TODO: This is just for compatibility since 4.0, should be obsoleted at future release. */
\r
125 define('_CHARSET', i18n::get_current_charset());
\r
129 * NOTE: Since 4.0 release, Entity class becomes to be important class
\r
130 * with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function
\r
132 include($DIR_LIBS . 'ENTITY.php');
\r
134 /* we will use postVar, getVar, ... methods instead of $_GET, $_POST ... */
\r
135 if ( $CONF['installscript'] != 1 )
\r
137 /* vars were already included in install.php */
\r
138 include_once($DIR_LIBS . 'vars4.1.0.php');
\r
140 /* added for 4.0 DB::* wrapper and compatibility sql_* */
\r
141 include_once($DIR_LIBS . 'sql/sql.php');
\r
144 /* include core classes that are needed for login & plugin handling */
\r
145 include($DIR_LIBS . 'MEMBER.php');
\r
146 include($DIR_LIBS . 'ACTIONLOG.php');
\r
147 include($DIR_LIBS . 'MANAGER.php');
\r
148 include($DIR_LIBS . 'PLUGIN.php');
\r
150 $manager =& MANAGER::instance();
\r
152 /* only needed when updating logs */
\r
153 if ( $CONF['UsingAdminArea'] )
\r
155 /* XML-RPC client classes */
\r
156 include($DIR_LIBS . 'xmlrpc.inc.php');
\r
157 include($DIR_LIBS . 'ADMIN.php');
\r
160 /* connect to database */
\r
161 global $MYSQL_HANDLER;
\r
162 if ( !isset($MYSQL_HANDLER) )
\r
164 $MYSQL_HANDLER = array('mysql','');
\r
166 if ( $MYSQL_HANDLER[0] == '' )
\r
168 $MYSQL_HANDLER[0] = 'mysql';
\r
170 include_once($DIR_LIBS . 'mysql.php');
\r
171 include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');
\r
175 /* force locale or charset */
\r
177 $charset = i18n::get_current_charset();
\r
180 'locale' => &$locale,
\r
181 'charset' => &$charset
\r
183 $manager->notify('ForceLocale', $data);
\r
185 if ( $data['locale'] !== '' )
\r
187 i18n::set_forced_locale($data['locale']);
\r
189 if ( $data['charset'] !== '' )
\r
191 i18n::set_forced_charset($data['charset']);
\r
197 /* convert forced charset to current charset */
\r
198 if ( i18n::get_forced_charset() != i18n::get_current_charset() )
\r
200 $_POST = i18n::convert_array($_POST, i18n::get_forced_charset());
\r
201 $_GET = i18n::convert_array($_GET, i18n::get_forced_charset());
\r
202 $_REQUEST = i18n::convert_array($_REQUEST, i18n::get_forced_charset());
\r
203 $_COOKIE = i18n::convert_array($_COOKIE, i18n::get_forced_charset());
\r
204 $_FILES = i18n::convert_array($_FILES, i18n::get_forced_charset());
\r
206 if ( session_id() !== '' )
\r
208 $_SESSION = i18n::convert_array($_SESSION, i18n::get_forced_charset());
\r
213 /* sanitize option */
\r
214 $bLoggingSanitizedResult = 0;
\r
215 $bSanitizeAndContinue = 0;
\r
216 $orgRequestURI = serverVar('REQUEST_URI');
\r
219 /* logs sanitized result if need */
\r
220 if ( $orgRequestURI !== serverVar('REQUEST_URI') )
\r
222 $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";
\r
223 $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');
\r
224 if ( $bLoggingSanitizedResult )
\r
226 addToLog(WARNING, $msg);
\r
228 if ( !$bSanitizeAndContinue )
\r
234 /* makes sure database connection gets closed on script termination */
\r
235 register_shutdown_function('sql_disconnect');
\r
237 /* get all variables that can come from the request and put them in the global scope */
\r
238 $blogid = requestVar('blogid');
\r
239 $itemid = intRequestVar('itemid');
\r
240 $catid = intRequestVar('catid');
\r
241 $skinid = requestVar('skinid');
\r
242 $memberid = requestVar('memberid');
\r
243 $archivelist = requestVar('archivelist');
\r
244 $imagepopup = requestVar('imagepopup');
\r
245 $archive = requestVar('archive');
\r
246 $query = requestVar('query');
\r
247 $highlight = requestVar('highlight');
\r
248 $amount = requestVar('amount');
\r
249 $action = requestVar('action');
\r
250 $nextaction = requestVar('nextaction');
\r
251 $maxresults = requestVar('maxresults');
\r
252 $startpos = intRequestVar('startpos');
\r
253 $errormessage = '';
\r
255 $special = requestVar('special');
\r
256 $virtualpath = ((getVar('virtualpath') != NULL) ? getVar('virtualpath') : serverVar('PATH_INFO'));
\r
263 /* Properly set $CONF['Self'] and others if it's not set...
\r
264 * usually when we are access from admin menu
\r
266 if ( !array_key_exists('Self', $CONF) )
\r
268 $CONF['Self'] = $CONF['IndexURL'];
\r
269 /* strip trailing */
\r
270 if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )
\r
272 $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);
\r
276 $CONF['ItemURL'] = $CONF['Self'];
\r
277 $CONF['ArchiveURL'] = $CONF['Self'];
\r
278 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
279 $CONF['MemberURL'] = $CONF['Self'];
\r
280 $CONF['SearchURL'] = $CONF['Self'];
\r
281 $CONF['BlogURL'] = $CONF['Self'];
\r
282 $CONF['CategoryURL'] = $CONF['Self'];
\r
285 *switch URLMode back to normal when $CONF['Self'] ends in .php
\r
286 * this avoids urls like index.php/item/13/index.php/item/15
\r
288 if ( !array_key_exists('URLMode', $CONF)
\r
289 || (($CONF['URLMode'] == 'pathinfo')
\r
290 && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
\r
292 $CONF['URLMode'] = 'normal';
\r
295 /* automatically use simpler toolbar for mozilla */
\r
296 if ( ($CONF['DisableJsTools'] == 0)
\r
297 && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0') !== FALSE
\r
298 && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Gecko') !== FALSE )
\r
300 $CONF['DisableJsTools'] = 2;
\r
303 $member = new Member();
\r
305 if ( $action == 'login' )
\r
307 $login = postVar('login');
\r
308 $password = postVar('password');
\r
309 $shared = intPostVar('shared');
\r
310 $member->login($login, $password, $shared);
\r
312 elseif ( ($action == 'logout') )
\r
318 $member->cookielogin();
\r
322 /* TODO: This is for backward compatibility, should be obsoleted near future. */
\r
323 if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])
\r
324 && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )
\r
326 $CONF['Locale'] = 'en_Latn_US';
\r
328 if ( !array_key_exists('Language', $CONF) )
\r
330 $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);
\r
332 $locale = $CONF['Locale'];
\r
335 /* NOTE: include translation file and set locale */
\r
336 if ( $member->isLoggedIn() )
\r
338 if ( $member->getLocale() )
\r
340 $locale = $member->getLocale();
\r
345 if ( i18n::get_forced_locale() !== '' )
\r
347 $locale = i18n::get_forced_locale();
\r
350 include_translation($locale);
\r
351 i18n::set_current_locale($locale);
\r
354 /* login completed */
\r
355 $manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );
\r
358 if ( $member->isLoggedIn() && $nextaction )
\r
360 $action = $nextaction;
\r
364 * Release ticket for plugin
\r
368 /* first, let's see if the site is disabled or not. always allow admin area access. */
\r
369 if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )
\r
371 redirect($CONF['DisableSiteURL']);
\r
375 /* load other classes */
\r
376 include($DIR_LIBS . 'PARSER.php');
\r
377 include($DIR_LIBS . 'SKIN.php');
\r
378 include($DIR_LIBS . 'TEMPLATE.php');
\r
379 include($DIR_LIBS . 'BLOG.php');
\r
380 include($DIR_LIBS . 'BODYACTIONS.php');
\r
381 include($DIR_LIBS . 'COMMENTS.php');
\r
382 include($DIR_LIBS . 'COMMENT.php');
\r
383 include($DIR_LIBS . 'NOTIFICATION.php');
\r
384 include($DIR_LIBS . 'BAN.php');
\r
385 include($DIR_LIBS . 'PAGEFACTORY.php');
\r
386 include($DIR_LIBS . 'SEARCH.php');
\r
387 include($DIR_LIBS . 'LINK.php');
\r
389 /* set lastVisit cookie (if allowed) */
\r
390 if ( !headers_sent() )
\r
392 if ( $CONF['LastVisit'] )
\r
394 setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
398 setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
402 if ( !defined('_ARCHIVETYPE_MONTH') )
\r
404 define('_ARCHIVETYPE_DAY', 'day');
\r
405 define('_ARCHIVETYPE_MONTH', 'month');
\r
406 define('_ARCHIVETYPE_YEAR', 'year');
\r
409 /* decode path_info */
\r
410 if ( $CONF['URLMode'] == 'pathinfo' )
\r
412 /* initialize keywords if this hasn't been done before */
\r
413 if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )
\r
415 $CONF['ItemKey'] = 'item';
\r
418 if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )
\r
420 $CONF['ArchiveKey'] = 'archive';
\r
423 if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )
\r
425 $CONF['ArchivesKey'] = 'archives';
\r
428 if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )
\r
430 $CONF['MemberKey'] = 'member';
\r
433 if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )
\r
435 $CONF['BlogKey'] = 'blog';
\r
438 if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )
\r
440 $CONF['CategoryKey'] = 'category';
\r
443 if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )
\r
445 $CONF['SpecialskinKey'] = 'special';
\r
452 /* e.g. item, blog, ... */
\r
453 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
454 'info' => $virtualpath,
\r
455 'complete' => &$parsed
\r
461 /* default implementation */
\r
462 $data = preg_split("#/#", $virtualpath );
\r
463 for ( $i = 0; $i < sizeof($data); $i++ )
\r
465 switch ( $data[$i] )
\r
467 /* item/1 (blogid) */
\r
468 case $CONF['ItemKey']:
\r
471 if ( $i < sizeof($data) )
\r
473 $itemid = intval($data[$i]);
\r
477 /* archives/1 (blogid) */
\r
478 case $CONF['ArchivesKey']:
\r
480 if ( $i < sizeof($data) )
\r
482 $archivelist = intval($data[$i]);
\r
486 /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
\r
487 case $CONF['ArchiveKey']:
\r
488 if ( (($i + 1) < sizeof($data) ) && (i18n::strpos($data[$i + 1], '-') === FALSE ) )
\r
490 $blogid = (integer) $data[++$i];
\r
493 if ( $i < sizeof($data) )
\r
495 $archive = $data[$i];
\r
502 case $CONF['BlogKey']:
\r
504 if ( $i < sizeof($data) )
\r
506 $blogid = intval($data[$i]);
\r
510 /* category/1 (catid) */
\r
511 case $CONF['CategoryKey']:
\r
514 if ( $i < sizeof($data) )
\r
516 $catid = intval($data[$i]);
\r
520 case $CONF['MemberKey']:
\r
522 if ( $i < sizeof($data) )
\r
524 $memberid = intval($data[$i]);
\r
528 case $CONF['SpecialskinKey']:
\r
530 if ( $i < sizeof($data) )
\r
532 $special = $data[$i];
\r
533 $_REQUEST['special'] = $special;
\r
545 * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.
\r
546 * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking
\r
547 * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on
\r
548 * the values of something like catid or itemid
\r
552 'type' => basename(serverVar('SCRIPT_NAME')),
\r
553 'info' => $virtualpath
\r
555 $manager->notify('PostParseURL', $data);
\r
558 * NOTE: Here is the end of initialization
\r
562 * This function includes or requires the specified library file
\r
563 * @param string $file
\r
564 * @param bool $once use the _once() version
\r
565 * @param bool $require use require() instead of include()
\r
567 function include_libs($file, $once = TRUE, $require = TRUE)
\r
571 // begin if: $DIR_LIBS isn't a directory
\r
572 if ( !is_dir($DIR_LIBS) )
\r
577 $lib_path = $DIR_LIBS . $file;
\r
580 if ( $once && $require )
\r
582 require_once($lib_path);
\r
584 else if ( $once && !$require )
\r
586 include_once($lib_path);
\r
588 else if ( $require )
\r
590 require($lib_path);
\r
594 include($lib_path);
\r
601 * This function includes or requires the specified plugin file
\r
602 * @param string $file
\r
603 * @param bool $once use the _once() version
\r
604 * @param bool $require use require() instead of include()
\r
606 function include_plugins($file, $once = TRUE, $require = TRUE)
\r
608 global $DIR_PLUGINS;
\r
610 // begin if: $DIR_LIBS isn't a directory
\r
611 if ( !is_dir($DIR_PLUGINS) )
\r
616 $plugin_path = $DIR_PLUGINS . $file;
\r
619 if ( $once && $require )
\r
621 require_once($plugin_path);
\r
623 else if ( $once && !$require )
\r
625 include_once($plugin_path);
\r
627 elseif ( $require )
\r
629 require($plugin_path);
\r
633 include($plugin_path);
\r
638 * This function decide which locale is used and include translation
\r
639 * @param string $locale locale name referring to 'language tags' defined in RFC 5646
\r
642 function include_translation(&$locale)
\r
644 global $DIR_LOCALES;
\r
646 $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';
\r
647 if ( !file_exists($translation_file) )
\r
649 $locale = 'en_Latn_US';
\r
650 $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';
\r
652 include($translation_file);
\r
657 * This function returns the integer value of $_POST for the variable $name
\r
658 * @param string $name field to get the integer value of
\r
661 function intPostVar($name)
\r
663 return intval(postVar($name));
\r
668 * This function returns the integer value of $_GET for the variable $name
\r
669 * @param string $name field to get the integer value of
\r
672 function intGetVar($name)
\r
674 return intval(getVar($name));
\r
679 * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST
\r
680 * @param string $name field to get the integer value of
\r
683 function intRequestVar($name)
\r
685 return intval(requestVar($name));
\r
690 * This function returns the integer value of $_COOKIE for the variable $name
\r
691 * @param string $name field to get the integer value of
\r
694 function intCookieVar($name)
\r
696 return intval(cookieVar($name));
\r
701 * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)
\r
704 function getNucleusVersion()
\r
711 * TODO: Better description of this function.
\r
713 * Power users can install patches in between nucleus releases. These patches
\r
714 * usually add new functionality in the plugin API and allow those to
\r
715 * be tested without having to install CVS.
\r
719 function getNucleusPatchLevel()
\r
726 * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data
\r
727 * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02
\r
728 * @return string|bool
\r
730 function getLatestVersion()
\r
732 // begin if: cURL is not available in this PHP installation
\r
733 if ( !function_exists('curl_init') )
\r
738 $curl = curl_init();
\r
740 curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');
\r
741 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
\r
742 curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
\r
743 $return = curl_exec($curl);
\r
750 * This function returns a Nucleus table name with the appropriate prefix
\r
751 * @param string $name
\r
754 function sql_table($name)
\r
756 global $MYSQL_PREFIX;
\r
758 // begin if: no MySQL prefix
\r
759 if ( empty($MYSQL_PREFIX) )
\r
761 return 'nucleus_' . $name;
\r
763 // else: use MySQL prefix
\r
766 return $MYSQL_PREFIX . 'nucleus_' . $name;
\r
773 * sendContentType()
\r
774 * This function sends the Content-Type header if headers have not already been sent
\r
775 * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.
\r
777 * if content type is application/xhtml+xml, only send it to browsers
\r
778 * that can handle it (IE6 cannot). Otherwise, send text/html
\r
781 * For admin area pages, keep sending text/html (unless it's a debug version)
\r
782 * application/xhtml+xml still causes too much problems with the javascript implementations
\r
785 * ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,
\r
786 * application/xhtml+xml seems to be working, so we're going to use it if we can.
\r
788 * @param string $content_type MIME media type registered to IANA, http://www.iana.org/assignments/media-types/index.html
\r
789 * @param string $page_type
\r
790 * @param string $charset Deprecated. This has no meaning.
\r
794 function sendContentType($content_type, $page_type = '', $charset = '')
\r
796 global $manager, $CONF;
\r
798 if ( headers_sent() )
\r
803 /* NOTE: MIME Media Type */
\r
804 if ( ($content_type == 'application/xhtml+xml')
\r
805 && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )
\r
807 $content_type = 'text/html';
\r
810 /* NOTE: generate event */
\r
812 'pageType' => $page_type,
\r
813 'contentType' => &$content_type
\r
815 $manager->notify('PreSendContentType', $data);
\r
817 /* NOTE: confirm MIME Media Type */
\r
818 $content_type = preg_replace('#[^a-zA-Z0-9-+./]#', '', $content_type);
\r
820 /* NOTE: confirm character set */
\r
821 $charset = i18n::get_current_charset();
\r
822 if ( i18n::get_forced_charset() !== '' )
\r
824 $charset = i18n::get_forced_charset();
\r
827 /* NOTE: send HTTP 1.1 header */
\r
828 header("Content-Type: {$content_type}; charset={$charset}");
\r
830 /* NOTE: set handler for translating character set */
\r
831 if ( $charset != i18n::get_current_charset() )
\r
833 ob_start(array('i18n', 'convert_handler'));
\r
841 * This function parses a query into an array of expressions that can be passed on to the highlight method
\r
842 * @param string $query
\r
844 function parseHighlight($query)
\r
846 // TODO: add more intelligent splitting logic
\r
848 // get rid of quotes
\r
849 $query = preg_replace('/\'|"/', '', $query);
\r
856 $aHighlight = preg_split('# #', $query);
\r
858 for ( $i = 0; $i < count($aHighlight); $i++ )
\r
860 $aHighlight[$i] = trim($aHighlight[$i]);
\r
862 if ( i18n::strlen($aHighlight[$i]) < 3 )
\r
864 unset($aHighlight[$i]);
\r
868 if ( count($aHighlight) == 1 )
\r
870 return $aHighlight[0];
\r
874 return $aHighlight;
\r
880 * This function gets the blog ID from the blog name
\r
881 * @param string $name
\r
884 function getBlogIDFromName($name)
\r
886 return quickQuery('SELECT bnumber AS result FROM ' . sql_table('blog') . ' WHERE bshortname = "' . sql_real_escape_string($name) . '"');
\r
891 * This function gets the blog name from the blog ID
\r
895 function getBlogNameFromID($id)
\r
897 return quickQuery('SELECT bname AS result FROM ' . sql_table('blog') . ' WHERE bnumber = ' . intval($id));
\r
902 * This function gets the blog ID from the item ID
\r
903 * @param int $item_id
\r
906 function getBlogIDFromItemID($item_id)
\r
908 return quickQuery('SELECT iblog AS result FROM ' . sql_table('item') . ' WHERE inumber = ' . intval($item_id));
\r
913 * This function gets the blog ID from the comment ID
\r
914 * @param int $comment_id
\r
917 function getBlogIDFromCommentID($comment_id)
\r
919 return quickQuery('SELECT cblog AS result FROM ' . sql_table('comment') . ' WHERE cnumber = ' . intval($comment_id));
\r
924 * This function gets the blog ID from the category ID
\r
925 * @param int $category_id
\r
928 function getBlogIDFromCatID($category_id)
\r
930 return quickQuery('SELECT cblog AS result FROM ' . sql_table('category') . ' WHERE catid = ' . intval($category_id));
\r
935 * This function gets the category ID from the category name
\r
939 function getCatIDFromName($name)
\r
941 return quickQuery('SELECT catid AS result FROM ' . sql_table('category') . ' WHERE cname = "' . sql_real_escape_string($name) . '"');
\r
946 * This function performs a quick SQL query
\r
947 * @param string $query
\r
950 function quickQuery($query)
\r
952 $res = sql_query($query);
\r
953 $obj = sql_fetch_object($res);
\r
954 return (is_object($obj)) ? $obj->result : FALSE;
\r
957 function getPluginNameFromPid($pid) {
\r
958 $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );
\r
959 $obj = sql_fetch_object($res);
\r
960 return $obj->pfile;
\r
961 // return isset($obj->pfile) ? $obj->pfile : false;
\r
964 function selector()
\r
966 global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
\r
967 global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
\r
968 global $imagepopup, $catid, $special;
\r
971 $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');
\r
972 $action = requestVar('action');
\r
974 if ( in_array($action, $actionNames) )
\r
976 global $DIR_LIBS, $errormessage;
\r
977 include_once($DIR_LIBS . 'ACTION.php');
\r
979 $errorInfo = $a->doAction($action);
\r
983 $errormessage = $errorInfo['message'];
\r
987 // show error when headers already sent out
\r
988 if ( headers_sent() && $CONF['alertOnHeadersSent'] )
\r
990 // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)
\r
991 if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )
\r
993 headers_sent($hsFile, $hsLine);
\r
994 $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';
\r
1002 '<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
1003 'Page headers already sent'
\r
1008 // make is so ?archivelist without blogname or blogid shows the archivelist
\r
1009 // for the default weblog
\r
1010 if ( serverVar('QUERY_STRING') == 'archivelist' )
\r
1012 $archivelist = $CONF['DefaultBlog'];
\r
1015 // now decide which type of skin we need
\r
1018 // itemid given -> only show that item
\r
1021 if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )
\r
1023 doError(_ERROR_NOSUCHITEM);
\r
1026 global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
\r
1028 // 1. get timestamp, blogid and catid for item
\r
1029 $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';
\r
1030 $query = sprintf($query, sql_table('item'), (integer) $itemid);
\r
1031 $res = sql_query($query);
\r
1032 $obj = sql_fetch_object($res);
\r
1034 // if a different blog id has been set through the request or selectBlog(),
\r
1037 if ( $blogid && (intval($blogid) != $obj->iblog) )
\r
1039 doError(_ERROR_NOSUCHITEM);
\r
1042 // if a category has been selected which doesn't match the item, ignore the
\r
1044 if ( ($catid != 0) && ($catid != $obj->icat) )
\r
1049 $blogid = $obj->iblog;
\r
1050 $timestamp = strtotime($obj->itime);
\r
1052 $b =& $manager->getBlog($blogid);
\r
1054 if ( !$b->isValidCategory($catid) )
\r
1056 $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";
\r
1057 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);
\r
1061 $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
1062 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);
\r
1065 $res = sql_query($query);
\r
1066 $obj = sql_fetch_object($res);
\r
1070 $itemidprev = $obj->inumber;
\r
1071 $itemtitleprev = $obj->ititle;
\r
1074 // get next itemid and title
\r
1075 if ( !$b->isValidCategory($catid) )
\r
1077 $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
1078 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);
\r
1082 $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
1083 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);
\r
1085 $res = sql_query($query);
\r
1087 $obj = sql_fetch_object($res);
\r
1091 $itemidnext = $obj->inumber;
\r
1092 $itemtitlenext = $obj->ititle;
\r
1095 elseif ( $archive )
\r
1098 $type = 'archive';
\r
1100 // get next and prev month links ...
\r
1101 global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;
\r
1103 // sql queries for the timestamp of the first and the last published item
\r
1104 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";
\r
1105 $first_timestamp=quickQuery ($query);
\r
1106 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";
\r
1107 $last_timestamp=quickQuery ($query);
\r
1109 sscanf($archive, '%d-%d-%d', $y, $m, $d);
\r
1113 $archivetype = _ARCHIVETYPE_DAY;
\r
1114 $t = mktime(0, 0, 0, $m, $d, $y);
\r
1115 // one day has 24 * 60 * 60 = 86400 seconds
\r
1116 $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 );
\r
1117 // check for published items
\r
1118 if ( $t > $first_timestamp )
\r
1120 $archiveprevexists = true;
\r
1124 $archiveprevexists = false;
\r
1129 $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t);
\r
1130 if ( $t < $last_timestamp )
\r
1132 $archivenextexists = true;
\r
1136 $archivenextexists = false;
\r
1139 elseif ( $m == 0 )
\r
1141 $archivetype = _ARCHIVETYPE_YEAR;
\r
1142 $t = mktime(0, 0, 0, 12, 31, $y - 1);
\r
1143 // one day before is in the previous year
\r
1144 $archiveprev = i18n::formatted_datetime('%Y', $t);
\r
1145 if ( $t > $first_timestamp )
\r
1147 $archiveprevexists = true;
\r
1151 $archiveprevexists = false;
\r
1154 // timestamp for the next year
\r
1155 $t = mktime(0, 0, 0, 1, 1, $y + 1);
\r
1156 $archivenext = i18n::formatted_datetime('%Y', $t);
\r
1157 if ( $t < $last_timestamp )
\r
1159 $archivenextexists = true;
\r
1163 $archivenextexists = false;
\r
1168 $archivetype = _ARCHIVETYPE_MONTH;
\r
1169 $t = mktime(0, 0, 0, $m, 1, $y);
\r
1170 // one day before is in the previous month
\r
1171 $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400);
\r
1172 if ( $t > $first_timestamp )
\r
1174 $archiveprevexists = true;
\r
1178 $archiveprevexists = false;
\r
1181 // timestamp for the next month
\r
1182 $t = mktime(0, 0, 0, $m+1, 1, $y);
\r
1183 $archivenext = i18n::formatted_datetime('%Y-%m', $t);
\r
1184 if ( $t < $last_timestamp )
\r
1186 $archivenextexists = true;
\r
1190 $archivenextexists = false;
\r
1194 elseif ( $archivelist )
\r
1196 $type = 'archivelist';
\r
1198 if ( is_numeric($archivelist) )
\r
1200 $blogid = intVal($archivelist);
\r
1204 $blogid = getBlogIDFromName($archivelist);
\r
1209 doError(_ERROR_NOSUCHBLOG);
\r
1216 $query = stripslashes($query);
\r
1218 if ( is_numeric($blogid) )
\r
1220 $blogid = intVal($blogid);
\r
1224 $blogid = getBlogIDFromName($blogid);
\r
1229 doError(_ERROR_NOSUCHBLOG);
\r
1232 elseif ( $memberid )
\r
1236 if ( !Member::existsID($memberid) )
\r
1238 doError(_ERROR_NOSUCHMEMBER);
\r
1240 $memberinfo = $manager->getMember($memberid);
\r
1242 elseif ( $imagepopup )
\r
1244 // media object (images etc.)
\r
1245 $type = 'imagepopup';
\r
1247 // TODO: check if media-object exists
\r
1248 // TODO: set some vars?
\r
1252 // show regular index page
\r
1257 // any type of skin with catid
\r
1258 if ( $catid && !$blogid )
\r
1260 $blogid = getBlogIDFromCatID($catid);
\r
1263 // decide which blog should be displayed
\r
1266 $blogid = $CONF['DefaultBlog'];
\r
1269 $b =& $manager->getBlog($blogid);
\r
1270 $blog = $b; // references can't be placed in global variables?
\r
1272 if ( !$blog->isValid )
\r
1274 doError(_ERROR_NOSUCHBLOG);
\r
1277 // set catid if necessary
\r
1280 // check if the category is valid
\r
1281 if ( !$blog->isValidCategory($catid) )
\r
1283 doError(_ERROR_NOSUCHCATEGORY);
\r
1287 $blog->setSelectedCategory($catid);
\r
1291 // decide which skin should be used
\r
1292 if ( $skinid != '' && ($skinid == 0) )
\r
1294 selectSkin($skinid);
\r
1299 $skinid = $blog->getDefaultSkin();
\r
1302 //$special = requestVar('special'); //get at top of file as global
\r
1303 if ( !empty($special) && isValidShortName($special) )
\r
1305 $type = strtolower($special);
\r
1308 $skin = new SKIN($skinid);
\r
1310 if ( !$skin->isValid() )
\r
1312 doError(_ERROR_NOSUCHSKIN);
\r
1315 // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude
\r
1317 $skinpart = $type;
\r
1320 $skin->parse($type);
\r
1322 // check to see we should throw JustPosted event
\r
1323 $blog->checkJustPosted();
\r
1328 * Show error skin with given message. An optional skin-object to use can be given
\r
1330 function doError($msg, $skin = '')
\r
1332 global $errormessage, $CONF, $skinid, $blogid, $manager;
\r
1334 if ( $skin == '' )
\r
1336 if ( Skin::existsID($skinid) )
\r
1340 elseif ( $manager->existsBlogID($blogid) )
\r
1342 $blog =& $manager->getBlog($blogid);
\r
1343 $id = $blog->getDefaultSkin();
\r
1345 elseif ($CONF['DefaultBlog'] )
\r
1347 $blog =& $manager->getBlog($CONF['DefaultBlog']);
\r
1348 $id = $blog->getDefaultSkin();
\r
1352 // this statement should actually never be executed
\r
1353 $id = $CONF['BaseSkin'];
\r
1355 $skin = new Skin($id);
\r
1358 $skinid = $skin->getID();
\r
1359 $errormessage = $msg;
\r
1360 $skin->parse('error');
\r
1364 function getConfig() {
\r
1367 $query = 'SELECT * FROM ' . sql_table('config');
\r
1368 $res = sql_query($query);
\r
1370 while ($obj = sql_fetch_object($res) ) {
\r
1371 $CONF[$obj->name] = $obj->value;
\r
1375 // some checks for names of blogs, categories, templates, members, ...
\r
1376 function isValidShortName($name) {
\r
1378 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1379 # original eregi: eregi('^[a-z0-9]+$', $name)
\r
1381 return preg_match('#^[a-z0-9]+$#i', $name);
\r
1385 function isValidDisplayName($name) {
\r
1387 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1388 # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)
\r
1390 return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);
\r
1394 function isValidCategoryName($name) {
\r
1398 function isValidTemplateName($name) {
\r
1400 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1401 # original eregi: eregi('^[a-z0-9/]+$', $name)
\r
1402 // added - and _ to valid characters as of 4.00
\r
1404 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1408 function isValidSkinName($name) {
\r
1410 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1411 # original eregi: eregi('^[a-z0-9/]+$', $name);
\r
1412 // added - and _ to valid characters as of 4.00
\r
1414 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1418 // add and remove linebreaks
\r
1419 function addBreaks($var) {
\r
1420 return nl2br($var);
\r
1423 function removeBreaks($var) {
\r
1424 return preg_replace("/<br \/>([\r\n])/", "$1", $var);
\r
1428 * functions for use in index.php
\r
1430 function selectBlog($shortname) {
\r
1431 global $blogid, $archivelist;
\r
1432 $blogid = getBlogIDFromName($shortname);
\r
1434 // also force archivelist variable, if it is set
\r
1435 if ($archivelist) {
\r
1436 $archivelist = $blogid;
\r
1440 function selectSkin($skinname) {
\r
1442 $skinid = SKIN::getIdFromName($skinname);
\r
1446 * Can take either a category ID or a category name (be aware that
\r
1447 * multiple categories can have the same name)
\r
1449 function selectCategory($cat) {
\r
1451 if (is_numeric($cat) ) {
\r
1452 $catid = intval($cat);
\r
1454 $catid = getCatIDFromName($cat);
\r
1458 function selectItem($id) {
\r
1460 $itemid = intval($id);
\r
1463 function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
\r
1467 if ( !$skinid || !existsID($skinid) )
\r
1469 $skin = new Skin($CONF['BaseSkin']);
\r
1473 $skin = new Skin($skinid);
\r
1476 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
1477 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
1479 $skin->parse('fileparse', $filename);
\r
1481 Parser::setProperty('IncludeMode', $oldIncludeMode);
\r
1482 Parser::setProperty('IncludePrefix', $oldIncludePrefix);
\r
1488 * Outputs a debug message
\r
1490 function debug($msg) {
\r
1491 echo '<p><b>' . $msg . "</b></p>\n";
\r
1495 function addToLog($level, $msg) {
\r
1496 ActionLog::add($level, $msg);
\r
1499 // shows a link to help file
\r
1500 function help($id) {
\r
1501 echo helpHtml($id);
\r
1504 function helpHtml($id) {
\r
1506 return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';
\r
1509 function helplink($id) {
\r
1511 return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';
\r
1515 * Includes a PHP file. This method can be called while parsing templates and skins
\r
1517 function includephp($filename) {
\r
1518 // make predefined variables global, so most simple scripts can be used here
\r
1520 // apache (names taken from PHP doc)
\r
1521 global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;
\r
1522 global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;
\r
1523 global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;
\r
1524 global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;
\r
1525 global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;
\r
1526 global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;
\r
1527 global $REQUEST_URI;
\r
1529 // php (taken from PHP doc)
\r
1530 global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1531 global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
\r
1534 global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;
\r
1536 if (@file_exists($filename) ) {
\r
1537 include($filename);
\r
1542 * Checks if a certain plugin exists
\r
1543 * @param string $plug
\r
1546 function checkPlugin($plug) {
\r
1548 global $DIR_PLUGINS;
\r
1550 # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
\r
1551 # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')
\r
1552 # important note that '\' must be matched with '\\\\' in preg* expressions
\r
1554 return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');
\r
1561 * @param string $querystr querystring to alter (e.g. foo=1&bar=2&x=y)
\r
1562 * @param string $param name of parameter to change (e.g. 'foo')
\r
1563 * @param string $value New value for that parameter (e.g. 3)
\r
1564 * @result string altered query string (for the examples above: foo=3&bar=2&x=y)
\r
1566 function alterQueryStr($querystr, $param, $value)
\r
1568 $vars = preg_split('#&#', $querystr);
\r
1571 for ( $i = 0; $i < count($vars); $i++ )
\r
1573 $v = preg_split('#=#', $vars[$i]);
\r
1575 if ( $v[0] == $param )
\r
1578 $vars[$i] = implode('=', $v);
\r
1585 $vars[] = "{$param}={$value}";
\r
1587 return ltrim(implode('&', $vars), '&');
\r
1590 // passes one variable as hidden input field (multiple fields for arrays)
\r
1591 // @see passRequestVars in varsx.x.x.php
\r
1592 function passVar($key, $value) {
\r
1594 if (is_array($value) ) {
\r
1595 for ($i = 0; $i < sizeof($value); $i++) {
\r
1596 passVar($key . '[' . $i . ']', $value[$i]);
\r
1602 // other values: do stripslashes if needed
\r
1603 ?><input type="hidden" name="<?php echo Entity::hsc($key)?>" value="<?php echo Entity::hsc(undoMagic($value) )?>" /><?php
\r
1606 function checkVars($aVars) {
\r
1607 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
\r
1609 foreach ($aVars as $varName) {
\r
1611 if (phpversion() >= '4.1.0') {
\r
1613 if ( isset($_GET[$varName])
\r
1614 || isset($_POST[$varName])
\r
1615 || isset($_COOKIE[$varName])
\r
1616 || isset($_ENV[$varName])
\r
1617 || isset($_SESSION[$varName])
\r
1618 || isset($_FILES[$varName])
\r
1620 die('Sorry. An error occurred.');
\r
1625 if ( isset($HTTP_GET_VARS[$varName])
\r
1626 || isset($HTTP_POST_VARS[$varName])
\r
1627 || isset($HTTP_COOKIE_VARS[$varName])
\r
1628 || isset($HTTP_ENV_VARS[$varName])
\r
1629 || isset($HTTP_SESSION_VARS[$varName])
\r
1630 || isset($HTTP_POST_FILES[$varName])
\r
1632 die('Sorry. An error occurred.');
\r
1641 * sanitizeParams()
\r
1642 * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.
\r
1648 function sanitizeParams()
\r
1654 // REQUEST_URI of $_SERVER
\r
1655 $str =& $_SERVER["REQUEST_URI"];
\r
1656 serverStringToArray($str, $array, $frontParam);
\r
1657 sanitizeArray($array);
\r
1658 arrayToServerString($array, $frontParam, $str);
\r
1660 // QUERY_STRING of $_SERVER
\r
1661 $str =& $_SERVER["QUERY_STRING"];
\r
1662 serverStringToArray($str, $array, $frontParam);
\r
1663 sanitizeArray($array);
\r
1664 arrayToServerString($array, $frontParam, $str);
\r
1667 convArrayForSanitizing($_GET, $array);
\r
1668 sanitizeArray($array);
\r
1669 revertArrayForSanitizing($array, $_GET);
\r
1671 // $_REQUEST (only GET param)
\r
1672 convArrayForSanitizing($_REQUEST, $array);
\r
1673 sanitizeArray($array);
\r
1674 revertArrayForSanitizing($array, $_REQUEST);
\r
1680 * ticketForPlugin()
\r
1682 * Check ticket when not checked in plugin's admin page
\r
1684 * Also avoid the access to plugin/index.php by guest user.
\r
1686 function ticketForPlugin()
\r
1688 global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;
\r
1691 $ticketforplugin = array();
\r
1692 $ticketforplugin['ticket'] = FALSE;
\r
1694 /* $_SERVER['PATH_TRANSLATED']
\r
1695 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1696 * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
\r
1697 * under the Apache 2 SAPI in contrast to the situation in Apache 1,
\r
1698 * where it's set to the same value as the SCRIPT_FILENAME server variable
\r
1699 * when it's not populated by Apache.
\r
1700 * This change was made to comply with the CGI specification
\r
1701 * that PATH_TRANSLATED should only exist if PATH_INFO is defined.
\r
1702 * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
\r
1705 /* Check if using plugin's php file. */
\r
1706 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1708 if (!file_exists($p_translated) )
\r
1710 header("HTTP/1.0 404 Not Found");
\r
1714 $p_translated = str_replace('\\', '/', $p_translated);
\r
1715 $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);
\r
1717 // This isn't plugin php file.
\r
1718 if ( i18n::strpos($p_translated, $d_plugins) !== 0 )
\r
1723 // Solve the plugin php file or admin directory
\r
1724 $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );
\r
1725 // Remove the first "/" if exists.
\r
1726 $phppath = preg_replace('#^/#', '', $phppath);
\r
1727 // Remove the first "NP_" and the last ".php" if exists.
\r
1728 $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);
\r
1729 // Remove the "/" and beyond.
\r
1730 $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);
\r
1732 // Solve the plugin name.
\r
1733 $plugins = array();
\r
1734 $query = 'SELECT pfile FROM '.sql_table('plugin');
\r
1735 $res = sql_query($query);
\r
1737 while($row = sql_fetch_row($res) )
\r
1739 $name = i18n::substr($row[0], 3);
\r
1740 $plugins[strtolower($name)] = $name;
\r
1743 sql_free_result($res);
\r
1745 if (array_key_exists($path, $plugins))
\r
1747 $plugin_name = $plugins[$path];
\r
1749 else if (in_array($path, $plugins))
\r
1751 $plugin_name = $path;
\r
1755 header("HTTP/1.0 404 Not Found");
\r
1759 /* Return if not index.php */
\r
1760 if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )
\r
1765 /* Exit if not logged in. */
\r
1766 if ( !$member->isLoggedIn() )
\r
1768 exit('You aren\'t logged in.');
\r
1771 global $manager, $DIR_LIBS, $DIR_LOCALES, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1773 /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */
\r
1774 if (!($p_translated = serverVar('PATH_TRANSLATED') ) )
\r
1776 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1779 if ($file = @file($p_translated) )
\r
1783 foreach($file as $line)
\r
1785 if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )
\r
1790 $prevline = $line;
\r
1794 /* Show a form if not valid ticket */
\r
1795 if ( ( i18n::strpos(serverVar('REQUEST_URI'), '?') !== FALSE || serverVar('QUERY_STRING')
\r
1796 || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')
\r
1797 && (!$manager->checkTicket() ) )
\r
1799 $oPluginAdmin = new PluginAdmin($plugin_name);
\r
1800 $oPluginAdmin->start();
\r
1801 echo '<p>' . _ERROR_BADTICKET . "</p>\n";
\r
1803 /* Show the form to confirm action */
\r
1804 // PHP 4.0.x support
\r
1805 $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;
\r
1806 $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;
\r
1808 // Resolve URI and QUERY_STRING
\r
1809 if ($uri = serverVar('REQUEST_URI') )
\r
1811 list($uri, $qstring) = preg_split('#\?#', $uri);
\r
1815 if ( !($uri = serverVar('PHP_SELF') ) )
\r
1817 $uri = serverVar('SCRIPT_NAME');
\r
1819 $qstring = serverVar('QUERY_STRING');
\r
1823 $qstring = '?' . $qstring;
\r
1826 echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . Entity::hsc($plugin_name) . "</span> ?</p>\n";
\r
1828 switch(strtoupper(serverVar('REQUEST_METHOD') ) )
\r
1831 echo '<form method="POST" action="'.Entity::hsc($uri.$qstring).'">';
\r
1832 $manager->addTicketHidden();
\r
1833 _addInputTags($post);
\r
1837 echo '<form method="GET" action="'.Entity::hsc($uri).'">';
\r
1838 $manager->addTicketHidden();
\r
1839 _addInputTags($get);
\r
1845 echo '<input type="submit" value="' . _YES . '" /> ';
\r
1846 echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';
\r
1849 $oPluginAdmin->end();
\r
1853 /* Create new ticket */
\r
1854 $ticket=$manager->addTicketToUrl('');
\r
1855 $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7);
\r
1859 function _addInputTags(&$keys,$prefix=''){
\r
1860 foreach($keys as $key=>$value){
\r
1861 if ($prefix) $key=$prefix.'['.$key.']';
\r
1862 if (is_array($value)) _addInputTags($value,$key);
\r
1864 if (get_magic_quotes_gpc()) $value=stripslashes($value);
\r
1865 if ($key=='ticket') continue;
\r
1866 echo '<input type="hidden" name="'.Entity::hsc($key).
\r
1867 '" value="'.Entity::hsc($value).'" />'."\n";
\r
1873 * serverStringToArray()
\r
1874 * Convert the server string such as $_SERVER['REQUEST_URI']
\r
1875 * to arry like arry['blogid']=1 and array['page']=2 etc.
\r
1877 * @param string $uri string
\r
1878 * @param string &$query_elements elements of query according to application/x-www-form-urlencoded
\r
1879 * @param string &$hier_part hierarchical part includes path
\r
1882 * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax
\r
1883 * 3. Syntax Components
\r
1884 * http://www.ietf.org/rfc/rfc3986.txt
\r
1886 * Hypertext Markup Language - 2.0
\r
1887 * 8.2.1. The form-urlencoded Media Type
\r
1888 * http://tools.ietf.org/html/rfc1866#section-8.2.1
\r
1890 * $_SERVER > Language Reference > Predefined Variables > PHP Manual
\r
1891 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1893 function serverStringToArray($uri, &$query_elements, &$hier_part)
\r
1896 $query_elements = array();
\r
1899 // split hierarchical part, e.g. /index.php, query and fragment, e.g. blogid=1&page=2#section1
\r
1900 if ( i18n::strpos($uri, "?") > 0 )
\r
1902 list($hier_part, $query_and_fragment) = preg_split("#\?#", $uri, 2);
\r
1906 $query_and_fragment = $uri;
\r
1910 // If there is no query like blogid=1&page=2, return
\r
1911 if ( i18n::strpos($uri, "=") == FALSE && !i18n::strlen($hier_part) )
\r
1913 $hier_part = $uri;
\r
1917 $query_elements = preg_split("#&#", $query_and_fragment);
\r
1922 * arrayToServerString()
\r
1923 * Convert array like array['blogid'] to server string
\r
1924 * such as $_SERVER['REQUEST_URI']
\r
1926 * @param array $query_elements elements of query according to application/x-www-form-urlencoded
\r
1927 * @param string $hier_part hier-part defined in RFC3986
\r
1928 * @param string &$uri return value
\r
1932 * RFC 3986: Uniform Resource Identifiers (URI): Generic Syntax
\r
1933 * 3. Syntax Components
\r
1934 * http://www.ietf.org/rfc/rfc3986.txt
\r
1936 * Hypertext Markup Language - 2.0
\r
1937 * 8.2.1. The form-urlencoded Media Type
\r
1938 * http://tools.ietf.org/html/rfc1866#section-8.2.1
\r
1940 * $_SERVER > Language Reference > Predefined Variables > PHP Manual
\r
1941 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1943 function arrayToServerString($query_elements, $hier_part, &$uri)
\r
1945 if ( i18n::strpos($uri, "?") !== FALSE )
\r
1947 $uri = $hier_part . "?";
\r
1951 $uri = $hier_part;
\r
1953 if ( count($query_elements) > 0 )
\r
1955 $uri .= implode("&", $query_elements);
\r
1962 * Sanitize array parameters.
\r
1963 * This function checks both key and value.
\r
1964 * - check key if it inclues " (double quote), remove from array
\r
1965 * - check value if it includes \ (escape sequece), remove remaining string
\r
1967 * @param array &$array elements of query according to application/x-www-form-urlencoded
\r
1970 function sanitizeArray(&$array)
\r
1972 $excludeListForSanitization = array('query');
\r
1974 foreach ( $array as $k => $v )
\r
1976 // split to key and value
\r
1977 list($key, $val) = preg_split("#=#", $v, 2);
\r
1978 if ( !isset($val) )
\r
1983 // when magic quotes is on, need to use stripslashes,
\r
1984 // and then addslashes
\r
1985 if ( get_magic_quotes_gpc() )
\r
1987 $val = stripslashes($val);
\r
1990 // note that we must use addslashes here because this function is called before the db connection is made
\r
1991 // and sql_real_escape_string needs a db connection
\r
1992 $val = addslashes($val);
\r
1994 // if $key is included in exclude list, skip this param
\r
1995 if ( !in_array($key, $excludeListForSanitization) )
\r
1998 if ( i18n::strpos($val, '\\') > 0 )
\r
2000 list($val, $tmp) = preg_split('#\\\\#', $val);
\r
2003 // remove control code etc.
\r
2004 $val = strtr($val, "\0\r\n<>'\"", " ");
\r
2007 if ( preg_match('#\"#', $key) > 0 )
\r
2009 unset($array[$k]);
\r
2013 // set sanitized info
\r
2014 $array[$k] = sprintf("%s=%s", $key, $val);
\r
2021 * convArrayForSanitizing()
\r
2022 * Convert array for sanitizeArray function
\r
2024 * @param string $src array to be sanitized
\r
2025 * @param array &$array array to be temporarily stored
\r
2028 function convArrayForSanitizing($src, &$array)
\r
2031 foreach ( $src as $key => $val )
\r
2033 if ( !key_exists($key, $_GET) )
\r
2037 $array[] = sprintf("%s=%s", $key, $val);
\r
2044 * revertArrayForSanitizing()
\r
2045 * Revert array after sanitizeArray function
\r
2047 * @param array $array element of query according to application/x-www-form-urlencoded
\r
2048 * @param array &$dst combination of key and value
\r
2051 function revertArrayForSanitizing($array, &$dst)
\r
2053 foreach ( $array as $v )
\r
2055 list($key, $val) = preg_split("#=#", $v, 2);
\r
2056 $dst[$key] = $val;
\r
2063 * Stops processing the request and redirects to the given URL.
\r
2064 * - no actual contents should have been sent to the output yet
\r
2065 * - the URL will be stripped of illegal or dangerous characters
\r
2067 function redirect($url) {
\r
2068 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);
\r
2069 header('Location: ' . $url);
\r
2074 * getBookmarklet()
\r
2075 * Returns the Javascript code for a bookmarklet that works on most modern browsers
\r
2077 * @param integer $blogid ID for weblog
\r
2078 * @return script to call Bookmarklet
\r
2080 function getBookmarklet($blogid, $width=600, $height=500)
\r
2087 . "if ( x.selection )"
\r
2089 . " Q=x.selection.createRange().text;"
\r
2091 . "else if ( y.getSelection )"
\r
2093 . " Q=y.getSelection();"
\r
2095 . "else if ( x.getSelection )"
\r
2097 . " Q=x.getSelection();"
\r
2099 . "wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}"
\r
2100 . " &logtext=' + encodeURIComponent(Q) +"
\r
2101 . " '&loglink=' + encodeURIComponent(x.location.href) +"
\r
2102 . " '&loglinktitle=' + encodeURIComponent(x.title),"
\r
2104 . " 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes');"
\r
2105 . "wingm.focus();";
\r
2109 // END: functions from the end of file ADMIN.php
\r
2112 * Returns a variable or null if not set
\r
2114 * @param mixed Variable
\r
2115 * @return mixed Variable
\r
2117 function ifset(&$var) {
\r
2118 if (isset($var)) {
\r
2126 * Returns number of subscriber to an event
\r
2129 * @return number of subscriber(s)
\r
2131 function numberOfEventSubscriber($event) {
\r
2132 $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';
\r
2133 $res = sql_query($query);
\r
2134 $obj = sql_fetch_object($res);
\r
2135 return $obj->count;
\r
2139 * sets $special global variable for use in index.php before selector()
\r
2141 * @param String id
\r
2144 function selectSpecialSkinType($id) {
\r
2146 $special = strtolower($id);
\r
2150 * cleans filename of uploaded file for writing to file system
\r
2152 * @param String str
\r
2153 * @return String cleaned filename ready for use
\r
2155 function cleanFileName($str) {
\r
2156 $str = strtolower($str);
\r
2157 $ext_point = i18n::strrpos($str,".");
\r
2158 if ($ext_point===false) return false;
\r
2159 $ext = i18n::substr($str,$ext_point,i18n::strlen($str));
\r
2160 $str = i18n::substr($str,0,$ext_point);
\r
2162 return preg_replace("/[^a-z0-9-]/","_",$str).$ext;
\r
2166 * Centralisation of the functions to send mail
\r
2167 * Deprecated since 4.0:
\r
2168 * Please use functions in NOTIFICATION class instead
\r
2170 function getMailFooter()
\r
2172 NOTIFICATION::get_mail_footer();
\r
2174 function isValidMailAddress($address)
\r
2176 return NOTIFICATION::address_validation($address);
\r
2179 * Centralisation of the functions that deals XML entities
\r
2180 * Deprecated since 4.0:
\r
2181 * Please use Entity::FunctionName(...) instead
\r
2183 function highlight($text, $expression, $highlight)
\r
2185 return Entity::highlight($text, $expression, $highlight);
\r
2187 function shorten($string, $maxlength, $suffix)
\r
2189 return Entity::shorten($string, $maxlength, $suffix);
\r
2191 function stringStripTags ($string)
\r
2193 return Entity::strip_tags($string);
\r
2195 function toAscii($string)
\r
2197 return Entity::anchor_footnoting($string);
\r
2199 function stringToAttribute ($string)
\r
2201 return Entity::hsc($string);
\r
2203 function stringToXML ($string)
\r
2205 return Entity::hen($string);
\r
2207 function encode_desc($data)
\r
2209 return Entity::hen($data);
\r
2212 * Centralisation of the functions that deals with locales
\r
2213 * This functions is based on the old way to deal with languages
\r
2214 * Deprecated since 4.0:
\r
2216 /* NOTE: use i18n::get_current_locale() directly instead of this */
\r
2217 function getLanguageName()
\r
2219 if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )
\r
2221 $language ='english';
\r
2225 /* NOTE: this is completely deprecated because generating much warnings */
\r
2226 function selectLanguage($language)
\r
2229 include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');
\r
2233 /* NOTE: use i18n::get_available_locales() directly instead of this */
\r
2234 function checkLanguage($lang)
\r
2236 return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)
\r
2237 || i18n::convert_old_language_file_name_to_locale($lang) );
\r
2239 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2240 function formatDate($format, $timestamp, $default_format, &$blog)
\r
2242 $offset = date('Z', $timestamp);
\r
2245 $offset += $blog->getTimeOffset() * 3600;
\r
2247 return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);
\r
2249 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2250 function mysqldate($timestamp)
\r
2252 return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';
\r
2255 * Centralisation of the functions that generate links
\r
2256 * Deprecated since 4.0:
\r
2257 * Please use Link::FunctionName(...) instead
\r
2259 function createItemLink($itemid, $extra = '')
\r
2261 return Link::create_item_link($itemid, $extra);
\r
2263 function createMemberLink($memberid, $extra = '')
\r
2265 return Link::create_member_link($memberid, $extra);
\r
2267 function createCategoryLink($catid, $extra = '')
\r
2269 return Link::create_category_link($catid, $extra);
\r
2271 function createArchiveListLink($blogid = '', $extra = '')
\r
2273 return Link::create_archivelist_link($blogid, $extra);
\r
2275 function createArchiveLink($blogid, $archive, $extra = '')
\r
2277 return Link::create_archive_link($blogid, $archive, $extra);
\r
2279 function createBlogidLink($blogid, $params = '')
\r
2281 return Link::create_blogid_link($blogid, $params = '');
\r
2283 function createLink($type, $params)
\r
2285 return Link::create_link($type, $params);
\r
2287 function createBlogLink($url, $params)
\r
2289 return Link::create_blog_link($url, $params);
\r