4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 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-2012 The Nucleus Group
\r
16 * @version $Id: globalfunctions.php 1727 2012-04-07 02:54:22Z 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 ( !isset($CONF) )
\r
33 if ( array_key_exists('debug', $CONF) && $CONF['debug'] )
\r
35 /* report all errors! */
\r
36 error_reporting(E_ALL);
\r
40 ini_set('display_errors','0');
\r
41 error_reporting(E_ERROR | E_WARNING | E_PARSE);
\r
45 * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
\r
47 if ( !isset($DIR_LOCALES) )
\r
49 $DIR_LOCALES = $DIR_NUCLEUS . 'locales/';
\r
52 if ( !isset($DIR_LANG) )
\r
54 $DIR_LANG = $DIR_LOCALES;
\r
58 * Errors before the database connection has been made
\r
60 function startUpError($msg, $title)
\r
62 header('Content-Type: text/xml; charset=' . i18n::get_current_charset());
\r
64 <html xmlns="http://www.w3.org/1999/xhtml">
\r
65 <head><title><?php echo htmlspecialchars($title, null, i18n::get_current_charset()) ?></title></head>
\r
67 <h1><?php echo htmlspecialchars($title, null, i18n::get_current_charset()) ?></h1>
\r
76 * load and initialize i18n class
\r
78 if (!class_exists('i18n', FALSE))
\r
80 include($DIR_LIBS . 'i18n.php');
\r
82 if ( !i18n::init('UTF-8', $DIR_LOCALES) )
\r
84 exit('Fail to initialize i18n class.');
\r
87 * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
\r
89 define('_CHARSET', i18n::get_current_charset());
\r
92 * Indicates when Nucleus should display startup errors. Set to 1 if you want
\r
93 * the error enabled (default), false otherwise
\r
95 * alertOnHeadersSent
\r
96 * Displays an error when visiting a public Nucleus page and headers have
\r
97 * been sent out to early. This usually indicates an error in either a
\r
98 * configuration file or a translation file, and could cause Nucleus to
\r
100 * alertOnSecurityRisk
\r
101 * Displays an error only when visiting the admin area, and when one or
\r
102 * more of the installation files (install.php, install.sql, upgrades/
\r
103 * directory) are still on the server.
\r
105 if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )
\r
107 $CONF['alertOnHeadersSent'] = 1;
\r
109 $CONF['alertOnSecurityRisk'] = 1;
\r
111 * NOTE: this should be removed when releasing 4.0
\r
112 $CONF['ItemURL'] = $CONF['Self'];
\r
113 $CONF['ArchiveURL'] = $CONF['Self'];
\r
114 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
115 $CONF['MemberURL'] = $CONF['Self'];
\r
116 $CONF['SearchURL'] = $CONF['Self'];
\r
117 $CONF['BlogURL'] = $CONF['Self'];
\r
118 $CONF['CategoryURL'] = $CONF['Self'];
\r
122 * Set these to 1 to allow viewing of future items or draft items
\r
123 * Should really never do this, but can be useful for some plugins that might need to
\r
124 * Could cause some other issues if you use future posts otr drafts
\r
127 $CONF['allowDrafts'] = 0;
\r
128 $CONF['allowFuture'] = 0;
\r
130 if ( getNucleusPatchLevel() > 0 )
\r
132 $nucleus['version'] .= '/' . getNucleusPatchLevel();
\r
135 /* Avoid notices */
\r
136 if ( !isset($CONF['installscript']) )
\r
138 $CONF['installscript'] = 0;
\r
141 /* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/
\r
142 if ( $CONF['installscript'] != 1 )
\r
144 /* vars were already included in install.php */
\r
145 include_once($DIR_LIBS . 'vars4.1.0.php');
\r
148 /* sanitize option */
\r
149 $bLoggingSanitizedResult=0;
\r
150 $bSanitizeAndContinue=0;
\r
152 $orgRequestURI = serverVar('REQUEST_URI');
\r
155 /* get all variables that can come from the request and put them in the global scope */
\r
156 $blogid = requestVar('blogid');
\r
157 $itemid = intRequestVar('itemid');
\r
158 $catid = intRequestVar('catid');
\r
159 $skinid = requestVar('skinid');
\r
160 $memberid = requestVar('memberid');
\r
161 $archivelist = requestVar('archivelist');
\r
162 $imagepopup = requestVar('imagepopup');
\r
163 $archive = requestVar('archive');
\r
164 $query = requestVar('query');
\r
165 $highlight = requestVar('highlight');
\r
166 $amount = requestVar('amount');
\r
167 $action = requestVar('action');
\r
168 $nextaction = requestVar('nextaction');
\r
169 $maxresults = requestVar('maxresults');
\r
170 $startpos = intRequestVar('startpos');
\r
171 $errormessage = '';
\r
173 $special = requestVar('special');
\r
174 $virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));
\r
176 if ( !headers_sent() )
\r
178 header('Generator: Nucleus CMS ' . $nucleus['version']);
\r
182 * NOTE: Since 4.0 release, Entity class becomes to be important class
\r
183 * with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function
\r
185 include($DIR_LIBS . 'ENTITY.php');
\r
187 /* include core classes that are needed for login & plugin handling */
\r
189 /* added for 3.5 sql_* wrapper */
\r
190 global $MYSQL_HANDLER;
\r
191 if ( !isset($MYSQL_HANDLER) )
\r
193 $MYSQL_HANDLER = array('mysql','');
\r
195 if ( $MYSQL_HANDLER[0] == '' )
\r
197 $MYSQL_HANDLER[0] = 'mysql';
\r
199 /* added for 4.0 DB::* wrapper and compatibility sql_* */
\r
200 include_once($DIR_LIBS . 'sql/sql.php');
\r
201 /* end new for 3.5 sql_* wrapper */
\r
203 include($DIR_LIBS . 'MEMBER.php');
\r
204 include($DIR_LIBS . 'ACTIONLOG.php');
\r
205 include($DIR_LIBS . 'MANAGER.php');
\r
206 include($DIR_LIBS . 'PLUGIN.php');
\r
208 $manager = new Manager();
\r
211 * make sure there's no unnecessary escaping:
\r
212 * set_magic_quotes_runtime(0);
\r
214 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
216 ini_set('magic_quotes_runtime', '0');
\r
219 /* Avoid notices */
\r
220 if ( !array_key_exists('UsingAdminArea', $CONF) )
\r
222 $CONF['UsingAdminArea'] = 0;
\r
225 /* only needed when updating logs */
\r
226 if ( $CONF['UsingAdminArea'] )
\r
228 /* XML-RPC client classes */
\r
229 include($DIR_LIBS . 'xmlrpc.inc.php');
\r
230 include_once($DIR_LIBS . 'ADMIN.php');
\r
233 /* connect to database */
\r
234 DB::setConnectionInfo($MYSQL_HANDLER[1], $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE);
\r
236 /* logs sanitized result if need */
\r
237 if ( $orgRequestURI!==serverVar('REQUEST_URI') )
\r
239 $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";
\r
240 $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');
\r
241 if ( $bLoggingSanitizedResult )
\r
243 addToLog(WARNING, $msg);
\r
245 if ( !$bSanitizeAndContinue )
\r
255 * FIXME: This is for backward compatibility, should be obsoleted near future.
\r
257 if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])
\r
258 && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )
\r
260 $CONF['Locale'] = 'en_Latn_US';
\r
262 if ( !array_key_exists('Language', $CONF) )
\r
264 $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);
\r
266 $locale = $CONF['Locale'];
\r
268 /* Properly set $CONF['Self'] and others if it's not set...
\r
269 * usually when we are access from admin menu
\r
271 if ( !array_key_exists('Self', $CONF) )
\r
273 $CONF['Self'] = $CONF['IndexURL'];
\r
274 /* strip trailing */
\r
275 if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )
\r
277 $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);
\r
281 $CONF['ItemURL'] = $CONF['Self'];
\r
282 $CONF['ArchiveURL'] = $CONF['Self'];
\r
283 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
284 $CONF['MemberURL'] = $CONF['Self'];
\r
285 $CONF['SearchURL'] = $CONF['Self'];
\r
286 $CONF['BlogURL'] = $CONF['Self'];
\r
287 $CONF['CategoryURL'] = $CONF['Self'];
\r
290 *switch URLMode back to normal when $CONF['Self'] ends in .php
\r
291 * this avoids urls like index.php/item/13/index.php/item/15
\r
293 if ( !array_key_exists('URLMode', $CONF)
\r
294 || (($CONF['URLMode'] == 'pathinfo')
\r
295 && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
\r
297 $CONF['URLMode'] = 'normal';
\r
300 /* automatically use simpler toolbar for mozilla */
\r
301 if ( ($CONF['DisableJsTools'] == 0)
\r
302 && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0') !== FALSE
\r
303 && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Gecko') !== FALSE )
\r
305 $CONF['DisableJsTools'] = 2;
\r
308 $member = new Member();
\r
310 if ( $action == 'login' )
\r
312 $login = postVar('login');
\r
313 $password = postVar('password');
\r
314 $shared = intPostVar('shared');
\r
315 $member->login($login, $password, $shared);
\r
317 elseif ( ($action == 'logout') )
\r
323 $member->cookielogin();
\r
326 /* NOTE: include translation file and set locale */
\r
327 if ( $member->isLoggedIn() && $member->getLocale())
\r
329 $locale = $member->getLocale();
\r
331 include_translation($locale);
\r
332 i18n::set_current_locale($locale);
\r
334 /* login completed */
\r
335 $manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );
\r
338 if ( $member->isLoggedIn() && $nextaction )
\r
340 $action = $nextaction;
\r
344 * Release ticket for plugin
\r
348 /* first, let's see if the site is disabled or not. always allow admin area access. */
\r
349 if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )
\r
351 redirect($CONF['DisableSiteURL']);
\r
355 /* load other classes */
\r
356 include($DIR_LIBS . 'PARSER.php');
\r
357 include($DIR_LIBS . 'SKIN.php');
\r
358 include($DIR_LIBS . 'TEMPLATE.php');
\r
359 include($DIR_LIBS . 'BLOG.php');
\r
360 include($DIR_LIBS . 'BODYACTIONS.php');
\r
361 include($DIR_LIBS . 'COMMENTS.php');
\r
362 include($DIR_LIBS . 'COMMENT.php');
\r
363 /* include($DIR_LIBS . 'ITEM.php'); */
\r
364 include($DIR_LIBS . 'NOTIFICATION.php');
\r
365 include($DIR_LIBS . 'BAN.php');
\r
366 include($DIR_LIBS . 'PAGEFACTORY.php');
\r
367 include($DIR_LIBS . 'SEARCH.php');
\r
368 include($DIR_LIBS . 'LINK.php');
\r
370 /* set lastVisit cookie (if allowed) */
\r
371 if ( !headers_sent() )
\r
373 if ( $CONF['LastVisit'] )
\r
375 setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
379 setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
383 if ( !defined('_ARCHIVETYPE_MONTH') )
\r
385 define('_ARCHIVETYPE_DAY', 'day');
\r
386 define('_ARCHIVETYPE_MONTH', 'month');
\r
387 define('_ARCHIVETYPE_YEAR', 'year');
\r
390 /* decode path_info */
\r
391 if ( $CONF['URLMode'] == 'pathinfo' )
\r
393 /* initialize keywords if this hasn't been done before */
\r
394 if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )
\r
396 $CONF['ItemKey'] = 'item';
\r
399 if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )
\r
401 $CONF['ArchiveKey'] = 'archive';
\r
404 if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )
\r
406 $CONF['ArchivesKey'] = 'archives';
\r
409 if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )
\r
411 $CONF['MemberKey'] = 'member';
\r
414 if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )
\r
416 $CONF['BlogKey'] = 'blog';
\r
419 if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )
\r
421 $CONF['CategoryKey'] = 'category';
\r
424 if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )
\r
426 $CONF['SpecialskinKey'] = 'special';
\r
433 /* e.g. item, blog, ... */
\r
434 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
435 'info' => $virtualpath,
\r
436 'complete' => &$parsed
\r
442 /* default implementation */
\r
443 $data = preg_split("#/#", $virtualpath );
\r
444 for ( $i = 0; $i < sizeof($data); $i++ )
\r
446 switch ( $data[$i] )
\r
448 /* item/1 (blogid) */
\r
449 case $CONF['ItemKey']:
\r
452 if ( $i < sizeof($data) )
\r
454 $itemid = intval($data[$i]);
\r
458 /* archives/1 (blogid) */
\r
459 case $CONF['ArchivesKey']:
\r
461 if ( $i < sizeof($data) )
\r
463 $archivelist = intval($data[$i]);
\r
467 /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
\r
468 case $CONF['ArchiveKey']:
\r
469 if ( (($i + 1) < sizeof($data) ) && (i18n::strpos($data[$i + 1], '-') === FALSE ) )
\r
471 $blogid = (integer) $data[++$i];
\r
474 if ( $i < sizeof($data) )
\r
476 $archive = $data[$i];
\r
483 case $CONF['BlogKey']:
\r
485 if ( $i < sizeof($data) )
\r
487 $blogid = intval($data[$i]);
\r
491 /* category/1 (catid) */
\r
492 case $CONF['CategoryKey']:
\r
495 if ( $i < sizeof($data) )
\r
497 $catid = intval($data[$i]);
\r
501 case $CONF['MemberKey']:
\r
503 if ( $i < sizeof($data) )
\r
505 $memberid = intval($data[$i]);
\r
509 case $CONF['SpecialskinKey']:
\r
511 if ( $i < sizeof($data) )
\r
513 $special = $data[$i];
\r
514 $_REQUEST['special'] = $special;
\r
526 * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.
\r
527 * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking
\r
528 * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on
\r
529 * the values of something like catid or itemid
\r
535 /* e.g. item, blog, ... */
\r
536 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
537 'info' => $virtualpath
\r
541 * NOTE: Here is the end of initialization
\r
545 * This function includes or requires the specified library file
\r
546 * @param string $file
\r
547 * @param bool $once use the _once() version
\r
548 * @param bool $require use require() instead of include()
\r
550 function include_libs($file, $once = TRUE, $require = TRUE)
\r
554 // begin if: $DIR_LIBS isn't a directory
\r
555 if ( !is_dir($DIR_LIBS) )
\r
560 $lib_path = $DIR_LIBS . $file;
\r
563 if ( $once && $require )
\r
565 require_once($lib_path);
\r
567 else if ( $once && !$require )
\r
569 include_once($lib_path);
\r
571 else if ( $require )
\r
573 require($lib_path);
\r
577 include($lib_path);
\r
584 * This function includes or requires the specified plugin file
\r
585 * @param string $file
\r
586 * @param bool $once use the _once() version
\r
587 * @param bool $require use require() instead of include()
\r
589 function include_plugins($file, $once = TRUE, $require = TRUE)
\r
591 global $DIR_PLUGINS;
\r
593 // begin if: $DIR_LIBS isn't a directory
\r
594 if ( !is_dir($DIR_PLUGINS) )
\r
599 $plugin_path = $DIR_PLUGINS . $file;
\r
602 if ( $once && $require )
\r
604 require_once($plugin_path);
\r
606 else if ( $once && !$require )
\r
608 include_once($plugin_path);
\r
610 elseif ( $require )
\r
612 require($plugin_path);
\r
616 include($plugin_path);
\r
621 * This function decide which locale is used and include translation
\r
622 * @param string $locale locale name referring to 'language tags' defined in RFC 5646
\r
625 function include_translation(&$locale)
\r
627 global $DIR_LOCALES;
\r
629 $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';
\r
630 if ( !file_exists($translation_file) )
\r
632 $locale = 'en_Latn_US';
\r
633 $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';
\r
635 include($translation_file);
\r
640 * This function returns the integer value of $_POST for the variable $name
\r
641 * @param string $name field to get the integer value of
\r
644 function intPostVar($name)
\r
646 return intval(postVar($name));
\r
651 * This function returns the integer value of $_GET for the variable $name
\r
652 * @param string $name field to get the integer value of
\r
655 function intGetVar($name)
\r
657 return intval(getVar($name));
\r
662 * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST
\r
663 * @param string $name field to get the integer value of
\r
666 function intRequestVar($name)
\r
668 return intval(requestVar($name));
\r
673 * This function returns the integer value of $_COOKIE for the variable $name
\r
674 * @param string $name field to get the integer value of
\r
677 function intCookieVar($name)
\r
679 return intval(cookieVar($name));
\r
684 * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)
\r
687 function getNucleusVersion()
\r
694 * TODO: Better description of this function.
\r
696 * Power users can install patches in between nucleus releases. These patches
\r
697 * usually add new functionality in the plugin API and allow those to
\r
698 * be tested without having to install CVS.
\r
702 function getNucleusPatchLevel()
\r
709 * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data
\r
710 * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02
\r
711 * @return string|bool
\r
713 function getLatestVersion()
\r
715 // begin if: cURL is not available in this PHP installation
\r
716 if ( !function_exists('curl_init') )
\r
721 $curl = curl_init();
\r
723 curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');
\r
724 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
\r
725 curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
\r
726 $return = curl_exec($curl);
\r
733 * This function returns a Nucleus table name with the appropriate prefix
\r
734 * @param string $name
\r
737 function sql_table($name)
\r
739 global $MYSQL_PREFIX;
\r
741 // begin if: no MySQL prefix
\r
742 if ( empty($MYSQL_PREFIX) )
\r
744 return 'nucleus_' . $name;
\r
746 // else: use MySQL prefix
\r
749 return $MYSQL_PREFIX . 'nucleus_' . $name;
\r
756 * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.
\r
758 * This function sends the Content-Type header if headers have not already been sent
\r
759 * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.
\r
760 * @param string $content_type
\r
761 * @param string $page_type
\r
762 * @param string $charset Deprecated. This has no meaning.
\r
764 function sendContentType($content_type, $page_type = '', $charset = _CHARSET)
\r
766 global $manager, $CONF;
\r
768 if ( !headers_sent() )
\r
770 // if content type is application/xhtml+xml, only send it to browsers
\r
771 // that can handle it (IE6 cannot). Otherwise, send text/html
\r
773 // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)
\r
774 // application/xhtml+xml still causes too much problems with the javascript implementations
\r
776 // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,
\r
777 // application/xhtml+xml seems to be working, so we're going to use it if we can.
\r
779 if ( ($content_type == 'application/xhtml+xml')
\r
780 && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )
\r
782 $content_type = 'text/html';
\r
786 'PreSendContentType',
\r
788 'contentType' => &$content_type,
\r
789 'charset' => i18n::get_current_charset(),
\r
790 'pageType' => $page_type
\r
794 // strip strange characters
\r
795 $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);
\r
796 header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());
\r
803 * This function parses a query into an array of expressions that can be passed on to the highlight method
\r
804 * @param string $query
\r
806 function parseHighlight($query)
\r
808 // TODO: add more intelligent splitting logic
\r
810 // get rid of quotes
\r
811 $query = preg_replace('/\'|"/', '', $query);
\r
818 $aHighlight = preg_split('# #', $query);
\r
820 for ( $i = 0; $i < count($aHighlight); $i++ )
\r
822 $aHighlight[$i] = trim($aHighlight[$i]);
\r
824 if ( i18n::strlen($aHighlight[$i]) < 3 )
\r
826 unset($aHighlight[$i]);
\r
830 if ( count($aHighlight) == 1 )
\r
832 return $aHighlight[0];
\r
836 return $aHighlight;
\r
842 * This function gets the blog ID from the blog name
\r
843 * @param string $name
\r
846 function getBlogIDFromName($name)
\r
848 $query = sprintf('SELECT bnumber AS result FROM %s WHERE bshortname=%s', sql_table('blog'), DB::quoteValue($name));
\r
849 return DB::getValue($query);
\r
854 * This function gets the blog name from the blog ID
\r
858 function getBlogNameFromID($id)
\r
860 $query = sprintf('SELECT bname AS result FROM %s WHERE bnumber=%d', sql_table('blog'), intval($id));
\r
861 return DB::getValue($query);
\r
866 * This function gets the blog ID from the item ID
\r
867 * @param int $item_id
\r
870 function getBlogIDFromItemID($item_id)
\r
872 $query = sprintf('SELECT iblog AS result FROM %s WHERE inumber=%d', sql_table('item'), intval($item_id));
\r
873 return DB::getValue($query);
\r
878 * This function gets the blog ID from the comment ID
\r
879 * @param int $comment_id
\r
882 function getBlogIDFromCommentID($comment_id)
\r
884 $query = sprintf('SELECT cblog AS result FROM %s WHERE cnumber=%d', sql_table('comment'), intval($comment_id));
\r
885 return DB::getValue($query);
\r
890 * This function gets the blog ID from the category ID
\r
891 * @param int $category_id
\r
894 function getBlogIDFromCatID($category_id)
\r
896 $query = sprintf('SELECT cblog AS result FROM %s WHERE catid=%d', sql_table('category'), intval($category_id));
\r
897 return DB::getValue($query);
\r
902 * This function gets the category ID from the category name
\r
906 function getCatIDFromName($name)
\r
908 $query = sprintf('SELECT catid AS result FROM %s WHERE cname=%s', sql_table('category'), DB::quoteValue($name));
\r
909 return DB::getValue($query);
\r
914 * This function performs a quick SQL query
\r
916 * @param string $query
\r
919 function quickQuery($query)
\r
921 $row = DB::getRow($query);
\r
922 return $row['result'];
\r
925 function getPluginNameFromPid($pid) {
\r
926 $query = sprintf('SELECT pfile FROM %s WHERE pid=%d', sql_table('plugin'), intval($pid));
\r
927 return DB::getValue($query);
\r
928 // return isset($obj->pfile) ? $obj->pfile : false;
\r
931 function selector()
\r
933 global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
\r
934 global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
\r
935 global $imagepopup, $catid, $special;
\r
938 $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');
\r
939 $action = requestVar('action');
\r
941 if ( in_array($action, $actionNames) )
\r
943 global $DIR_LIBS, $errormessage;
\r
944 include_once($DIR_LIBS . 'ACTION.php');
\r
946 $errorInfo = $a->doAction($action);
\r
950 $errormessage = $errorInfo['message'];
\r
954 // show error when headers already sent out
\r
955 if ( headers_sent() && $CONF['alertOnHeadersSent'] )
\r
957 // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)
\r
958 if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )
\r
960 headers_sent($hsFile, $hsLine);
\r
961 $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';
\r
969 '<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
970 'Page headers already sent'
\r
975 // make is so ?archivelist without blogname or blogid shows the archivelist
\r
976 // for the default weblog
\r
977 if ( serverVar('QUERY_STRING') == 'archivelist' )
\r
979 $archivelist = $CONF['DefaultBlog'];
\r
982 // now decide which type of skin we need
\r
985 // itemid given -> only show that item
\r
988 if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )
\r
990 doError(_ERROR_NOSUCHITEM);
\r
993 global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
\r
995 // 1. get timestamp, blogid and catid for item
\r
996 $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';
\r
997 $query = sprintf($query, sql_table('item'), intval($itemid));
\r
998 $row = DB::getRow($query);
\r
1000 // if a different blog id has been set through the request or selectBlog(),
\r
1003 if ( $blogid && (intval($blogid) != $row['iblog']) )
\r
1005 doError(_ERROR_NOSUCHITEM);
\r
1008 // if a category has been selected which doesn't match the item, ignore the
\r
1010 if ( ($catid != 0) && ($catid != $row['icat']) )
\r
1015 $blogid = $row['iblog'];
\r
1016 $timestamp = strtotime($row['itime']);
\r
1018 $b =& $manager->getBlog($blogid);
\r
1020 if ( !$b->isValidCategory($catid) )
\r
1022 $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";
\r
1023 $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid));
\r
1027 $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
1028 $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), intval($blogid), intval($catid));
\r
1030 $row = DB::getRow($query);
\r
1034 $itemidprev = $row['inumber'];
\r
1035 $itemtitleprev = $row['ititle'];
\r
1038 // get next itemid and title
\r
1039 if ( !$b->isValidCategory($catid) )
\r
1041 $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
1042 $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid));
\r
1046 $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
1047 $query = sprintf($query, sql_table('item'), DB::formatDateTime($timestamp), DB::formatDateTime($b->getCorrectTime()), intval($blogid), intval($catid));
\r
1049 $row = DB::getRow($query);
\r
1053 $itemidnext = $row['inumber'];
\r
1054 $itemtitlenext = $row['ititle'];
\r
1057 elseif ( $archive )
\r
1060 $type = 'archive';
\r
1062 // get next and prev month links ...
\r
1063 global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;
\r
1065 // sql queries for the timestamp of the first and the last published item
\r
1066 $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime ASC', sql_table('item'));
\r
1067 $first_timestamp = DB::getValue($query);
\r
1068 $query = sprintf('SELECT UNIX_TIMESTAMP(itime) as result FROM %s WHERE idraft=0 ORDER BY itime DESC', sql_table('item'));
\r
1069 $last_timestamp = DB::getValue($query);
\r
1071 sscanf($archive, '%d-%d-%d', $y, $m, $d);
\r
1075 $archivetype = _ARCHIVETYPE_DAY;
\r
1076 $t = mktime(0, 0, 0, $m, $d, $y);
\r
1077 // one day has 24 * 60 * 60 = 86400 seconds
\r
1078 $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 );
\r
1079 // check for published items
\r
1080 if ( $t > $first_timestamp )
\r
1082 $archiveprevexists = true;
\r
1086 $archiveprevexists = false;
\r
1091 $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t);
\r
1092 if ( $t < $last_timestamp )
\r
1094 $archivenextexists = true;
\r
1098 $archivenextexists = false;
\r
1101 elseif ( $m == 0 )
\r
1103 $archivetype = _ARCHIVETYPE_YEAR;
\r
1104 $t = mktime(0, 0, 0, 12, 31, $y - 1);
\r
1105 // one day before is in the previous year
\r
1106 $archiveprev = i18n::formatted_datetime('%Y', $t);
\r
1107 if ( $t > $first_timestamp )
\r
1109 $archiveprevexists = true;
\r
1113 $archiveprevexists = false;
\r
1116 // timestamp for the next year
\r
1117 $t = mktime(0, 0, 0, 1, 1, $y + 1);
\r
1118 $archivenext = i18n::formatted_datetime('%Y', $t);
\r
1119 if ( $t < $last_timestamp )
\r
1121 $archivenextexists = true;
\r
1125 $archivenextexists = false;
\r
1130 $archivetype = _ARCHIVETYPE_MONTH;
\r
1131 $t = mktime(0, 0, 0, $m, 1, $y);
\r
1132 // one day before is in the previous month
\r
1133 $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400);
\r
1134 if ( $t > $first_timestamp )
\r
1136 $archiveprevexists = true;
\r
1140 $archiveprevexists = false;
\r
1143 // timestamp for the next month
\r
1144 $t = mktime(0, 0, 0, $m+1, 1, $y);
\r
1145 $archivenext = i18n::formatted_datetime('%Y-%m', $t);
\r
1146 if ( $t < $last_timestamp )
\r
1148 $archivenextexists = true;
\r
1152 $archivenextexists = false;
\r
1156 elseif ( $archivelist )
\r
1158 $type = 'archivelist';
\r
1160 if ( is_numeric($archivelist) )
\r
1162 $blogid = intVal($archivelist);
\r
1166 $blogid = getBlogIDFromName($archivelist);
\r
1171 doError(_ERROR_NOSUCHBLOG);
\r
1178 $query = stripslashes($query);
\r
1180 if ( is_numeric($blogid) )
\r
1182 $blogid = intVal($blogid);
\r
1186 $blogid = getBlogIDFromName($blogid);
\r
1191 doError(_ERROR_NOSUCHBLOG);
\r
1194 elseif ( $memberid )
\r
1198 if ( !Member::existsID($memberid) )
\r
1200 doError(_ERROR_NOSUCHMEMBER);
\r
1202 $memberinfo = $manager->getMember($memberid);
\r
1204 elseif ( $imagepopup )
\r
1206 // media object (images etc.)
\r
1207 $type = 'imagepopup';
\r
1209 // TODO: check if media-object exists
\r
1210 // TODO: set some vars?
\r
1214 // show regular index page
\r
1219 // any type of skin with catid
\r
1220 if ( $catid && !$blogid )
\r
1222 $blogid = getBlogIDFromCatID($catid);
\r
1225 // decide which blog should be displayed
\r
1228 $blogid = $CONF['DefaultBlog'];
\r
1231 $b =& $manager->getBlog($blogid);
\r
1232 $blog = $b; // references can't be placed in global variables?
\r
1234 if ( !$blog->isValid )
\r
1236 doError(_ERROR_NOSUCHBLOG);
\r
1239 // set catid if necessary
\r
1242 // check if the category is valid
\r
1243 if ( !$blog->isValidCategory($catid) )
\r
1245 doError(_ERROR_NOSUCHCATEGORY);
\r
1249 $blog->setSelectedCategory($catid);
\r
1253 // decide which skin should be used
\r
1254 if ( $skinid != '' && ($skinid == 0) )
\r
1256 selectSkin($skinid);
\r
1261 $skinid = $blog->getDefaultSkin();
\r
1264 //$special = requestVar('special'); //get at top of file as global
\r
1265 if ( !empty($special) && isValidShortName($special) )
\r
1267 $type = strtolower($special);
\r
1270 $skin = new SKIN($skinid);
\r
1272 if ( !$skin->isValid() )
\r
1274 doError(_ERROR_NOSUCHSKIN);
\r
1277 // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude
\r
1279 $skinpart = $type;
\r
1282 $skin->parse($type);
\r
1284 // check to see we should throw JustPosted event
\r
1285 $blog->checkJustPosted();
\r
1290 * Show error skin with given message. An optional skin-object to use can be given
\r
1292 function doError($msg, $skin = '')
\r
1294 global $errormessage, $CONF, $skinid, $blogid, $manager;
\r
1296 if ( $skin == '' )
\r
1298 if ( Skin::existsID($skinid) )
\r
1302 elseif ( $manager->existsBlogID($blogid) )
\r
1304 $blog =& $manager->getBlog($blogid);
\r
1305 $id = $blog->getDefaultSkin();
\r
1307 elseif ($CONF['DefaultBlog'] )
\r
1309 $blog =& $manager->getBlog($CONF['DefaultBlog']);
\r
1310 $id = $blog->getDefaultSkin();
\r
1314 // this statement should actually never be executed
\r
1315 $id = $CONF['BaseSkin'];
\r
1317 $skin = new Skin($id);
\r
1320 $skinid = $skin->getID();
\r
1321 $errormessage = $msg;
\r
1322 $skin->parse('error');
\r
1326 function getConfig() {
\r
1329 $query = sprintf('SELECT * FROM %s', sql_table('config'));
\r
1330 $res = DB::getResult($query);
\r
1332 foreach ( $res as $row )
\r
1334 $CONF[$row['name']] = $row['value'];
\r
1338 // some checks for names of blogs, categories, templates, members, ...
\r
1339 function isValidShortName($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
1344 return preg_match('#^[a-z0-9]+$#i', $name);
\r
1348 function isValidDisplayName($name) {
\r
1350 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1351 # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)
\r
1353 return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);
\r
1357 function isValidCategoryName($name) {
\r
1361 function isValidTemplateName($name) {
\r
1363 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1364 # original eregi: eregi('^[a-z0-9/]+$', $name)
\r
1365 // added - and _ to valid characters as of 4.00
\r
1367 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1371 function isValidSkinName($name) {
\r
1373 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1374 # original eregi: eregi('^[a-z0-9/]+$', $name);
\r
1375 // added - and _ to valid characters as of 4.00
\r
1377 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1381 // add and remove linebreaks
\r
1382 function addBreaks($var) {
\r
1383 return nl2br($var);
\r
1386 function removeBreaks($var) {
\r
1387 return preg_replace("/<br \/>([\r\n])/", "$1", $var);
\r
1391 * functions for use in index.php
\r
1393 function selectBlog($shortname) {
\r
1394 global $blogid, $archivelist;
\r
1395 $blogid = getBlogIDFromName($shortname);
\r
1397 // also force archivelist variable, if it is set
\r
1398 if ($archivelist) {
\r
1399 $archivelist = $blogid;
\r
1403 function selectSkin($skinname) {
\r
1405 $skinid = SKIN::getIdFromName($skinname);
\r
1409 * Can take either a category ID or a category name (be aware that
\r
1410 * multiple categories can have the same name)
\r
1412 function selectCategory($cat) {
\r
1414 if (is_numeric($cat) ) {
\r
1415 $catid = intval($cat);
\r
1417 $catid = getCatIDFromName($cat);
\r
1421 function selectItem($id) {
\r
1423 $itemid = intval($id);
\r
1426 function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
1430 if ( !$skinid || !existsID($skinid) )
1432 $skin = new Skin($CONF['BaseSkin']);
1436 $skin = new Skin($skinid);
1439 $oldIncludeMode = Parser::getProperty('IncludeMode');
1440 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
1442 $skin->parse('fileparse', $filename);
1444 Parser::setProperty('IncludeMode', $oldIncludeMode);
1445 Parser::setProperty('IncludePrefix', $oldIncludePrefix);
1451 * Outputs a debug message
\r
1453 function debug($msg) {
\r
1454 echo '<p><b>' . $msg . "</b></p>\n";
\r
1458 function addToLog($level, $msg) {
\r
1459 ActionLog::add($level, $msg);
\r
1462 // shows a link to help file
\r
1463 function help($id) {
\r
1464 echo helpHtml($id);
\r
1467 function helpHtml($id) {
\r
1469 return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';
\r
1472 function helplink($id) {
\r
1474 return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';
\r
1478 * Includes a PHP file. This method can be called while parsing templates and skins
\r
1480 function includephp($filename) {
\r
1481 // make predefined variables global, so most simple scripts can be used here
\r
1483 // apache (names taken from PHP doc)
\r
1484 global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;
\r
1485 global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;
\r
1486 global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;
\r
1487 global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;
\r
1488 global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;
\r
1489 global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;
\r
1490 global $REQUEST_URI;
\r
1492 // php (taken from PHP doc)
\r
1493 global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1494 global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
\r
1497 global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;
\r
1499 if (@file_exists($filename) ) {
\r
1500 include($filename);
\r
1505 * Checks if a certain plugin exists
\r
1506 * @param string $plug
\r
1509 function checkPlugin($plug) {
\r
1511 global $DIR_PLUGINS;
\r
1513 # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
\r
1514 # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')
\r
1515 # important note that '\' must be matched with '\\\\' in preg* expressions
\r
1517 return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');
\r
1524 * @param string $querystr querystring to alter (e.g. foo=1&bar=2&x=y)
\r
1525 * @param string $param name of parameter to change (e.g. 'foo')
\r
1526 * @param string $value New value for that parameter (e.g. 3)
\r
1527 * @result string altered query string (for the examples above: foo=3&bar=2&x=y)
\r
1529 function alterQueryStr($querystr, $param, $value)
\r
1531 $vars = preg_split('#&#', $querystr);
\r
1534 for ( $i = 0; $i < count($vars); $i++ )
\r
1536 $v = preg_split('#=#', $vars[$i]);
\r
1538 if ( $v[0] == $param )
\r
1541 $vars[$i] = implode('=', $v);
\r
1548 $vars[] = "{$param}={$value}";
\r
1550 return ltrim(implode('&', $vars), '&');
\r
1553 // passes one variable as hidden input field (multiple fields for arrays)
\r
1554 // @see passRequestVars in varsx.x.x.php
\r
1555 function passVar($key, $value) {
\r
1557 if (is_array($value) ) {
\r
1558 for ($i = 0; $i < sizeof($value); $i++) {
\r
1559 passVar($key . '[' . $i . ']', $value[$i]);
\r
1565 // other values: do stripslashes if needed
\r
1566 ?><input type="hidden" name="<?php echo Entity::hsc($key)?>" value="<?php echo Entity::hsc(undoMagic($value) )?>" /><?php
\r
1569 function checkVars($aVars) {
\r
1570 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
\r
1572 foreach ($aVars as $varName) {
\r
1574 if (phpversion() >= '4.1.0') {
\r
1576 if ( isset($_GET[$varName])
\r
1577 || isset($_POST[$varName])
\r
1578 || isset($_COOKIE[$varName])
\r
1579 || isset($_ENV[$varName])
\r
1580 || isset($_SESSION[$varName])
\r
1581 || isset($_FILES[$varName])
\r
1583 die('Sorry. An error occurred.');
\r
1588 if ( isset($HTTP_GET_VARS[$varName])
\r
1589 || isset($HTTP_POST_VARS[$varName])
\r
1590 || isset($HTTP_COOKIE_VARS[$varName])
\r
1591 || isset($HTTP_ENV_VARS[$varName])
\r
1592 || isset($HTTP_SESSION_VARS[$varName])
\r
1593 || isset($HTTP_POST_FILES[$varName])
\r
1595 die('Sorry. An error occurred.');
\r
1604 * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.
\r
1607 function sanitizeParams()
\r
1609 global $HTTP_SERVER_VARS;
\r
1615 // REQUEST_URI of $HTTP_SERVER_VARS
\r
1616 $str =& $HTTP_SERVER_VARS["REQUEST_URI"];
\r
1617 serverStringToArray($str, $array, $frontParam);
\r
1618 sanitizeArray($array);
\r
1619 arrayToServerString($array, $frontParam, $str);
\r
1621 // QUERY_STRING of $HTTP_SERVER_VARS
\r
1622 $str =& $HTTP_SERVER_VARS["QUERY_STRING"];
\r
1623 serverStringToArray($str, $array, $frontParam);
\r
1624 sanitizeArray($array);
\r
1625 arrayToServerString($array, $frontParam, $str);
\r
1627 if (phpversion() >= '4.1.0') {
\r
1628 // REQUEST_URI of $_SERVER
\r
1629 $str =& $_SERVER["REQUEST_URI"];
\r
1630 serverStringToArray($str, $array, $frontParam);
\r
1631 sanitizeArray($array);
\r
1632 arrayToServerString($array, $frontParam, $str);
\r
1634 // QUERY_STRING of $_SERVER
\r
1635 $str =& $_SERVER["QUERY_STRING"];
\r
1636 serverStringToArray($str, $array, $frontParam);
\r
1637 sanitizeArray($array);
\r
1638 arrayToServerString($array, $frontParam, $str);
\r
1642 convArrayForSanitizing($_GET, $array);
\r
1643 sanitizeArray($array);
\r
1644 revertArrayForSanitizing($array, $_GET);
\r
1646 // $_REQUEST (only GET param)
\r
1647 convArrayForSanitizing($_REQUEST, $array);
\r
1648 sanitizeArray($array);
\r
1649 revertArrayForSanitizing($array, $_REQUEST);
\r
1653 * ticketForPlugin()
\r
1655 * Check ticket when not checked in plugin's admin page
\r
1657 * Also avoid the access to plugin/index.php by guest user.
\r
1659 function ticketForPlugin()
\r
1661 global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;
\r
1664 $ticketforplugin = array();
\r
1665 $ticketforplugin['ticket'] = FALSE;
\r
1667 /* $_SERVER['PATH_TRANSLATED']
\r
1668 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1669 * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
\r
1670 * under the Apache 2 SAPI in contrast to the situation in Apache 1,
\r
1671 * where it's set to the same value as the SCRIPT_FILENAME server variable
\r
1672 * when it's not populated by Apache.
\r
1673 * This change was made to comply with the CGI specification
\r
1674 * that PATH_TRANSLATED should only exist if PATH_INFO is defined.
\r
1675 * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
\r
1678 /* Check if using plugin's php file. */
\r
1679 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1681 if (!file_exists($p_translated) )
\r
1683 header("HTTP/1.0 404 Not Found");
\r
1687 $p_translated = str_replace('\\', '/', $p_translated);
\r
1688 $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);
\r
1690 // This isn't plugin php file.
\r
1691 if ( i18n::strpos($p_translated, $d_plugins) !== 0 )
\r
1696 // Solve the plugin php file or admin directory
\r
1697 $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );
\r
1698 // Remove the first "/" if exists.
\r
1699 $phppath = preg_replace('#^/#', '', $phppath);
\r
1700 // Remove the first "NP_" and the last ".php" if exists.
\r
1701 $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);
\r
1702 // Remove the "/" and beyond.
\r
1703 $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);
\r
1705 // Solve the plugin name.
\r
1706 $plugins = array();
\r
1707 $query = sprintf('SELECT pfile FROM %s', sql_table('plugin'));
\r
1708 $res = DB::getResult($query);
\r
1710 foreach ( $res as $row )
\r
1712 $name = i18n::substr($row['pfile'], 3);
\r
1713 $plugins[strtolower($name)] = $name;
\r
1716 $res->closeCursor();
\r
1718 if (array_key_exists($path, $plugins))
\r
1720 $plugin_name = $plugins[$path];
\r
1722 else if (in_array($path, $plugins))
\r
1724 $plugin_name = $path;
\r
1728 header("HTTP/1.0 404 Not Found");
\r
1732 /* Return if not index.php */
\r
1733 if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )
\r
1738 /* Exit if not logged in. */
\r
1739 if ( !$member->isLoggedIn() )
\r
1741 exit('You aren\'t logged in.');
\r
1744 global $manager, $DIR_LIBS, $DIR_LOCALES, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1746 /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */
\r
1747 if (!($p_translated = serverVar('PATH_TRANSLATED') ) )
\r
1749 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1752 if ($file = @file($p_translated) )
\r
1756 foreach($file as $line)
\r
1758 if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )
\r
1763 $prevline = $line;
\r
1767 /* Show a form if not valid ticket */
\r
1768 if ( ( i18n::strpos(serverVar('REQUEST_URI'), '?') !== FALSE || serverVar('QUERY_STRING')
\r
1769 || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')
\r
1770 && (!$manager->checkTicket() ) )
\r
1772 $oPluginAdmin = new PluginAdmin($plugin_name);
\r
1773 $oPluginAdmin->start();
\r
1774 echo '<p>' . _ERROR_BADTICKET . "</p>\n";
\r
1776 /* Show the form to confirm action */
\r
1777 // PHP 4.0.x support
\r
1778 $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;
\r
1779 $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;
\r
1781 // Resolve URI and QUERY_STRING
\r
1782 if ($uri = serverVar('REQUEST_URI') )
\r
1784 list($uri, $qstring) = preg_split('#\?#', $uri);
\r
1788 if ( !($uri = serverVar('PHP_SELF') ) )
\r
1790 $uri = serverVar('SCRIPT_NAME');
\r
1792 $qstring = serverVar('QUERY_STRING');
\r
1796 $qstring = '?' . $qstring;
\r
1799 echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . Entity::hsc($plugin_name) . "</span> ?</p>\n";
\r
1801 switch(strtoupper(serverVar('REQUEST_METHOD') ) )
\r
1804 echo '<form method="POST" action="'.Entity::hsc($uri.$qstring).'">';
\r
1805 $manager->addTicketHidden();
\r
1806 _addInputTags($post);
\r
1810 echo '<form method="GET" action="'.Entity::hsc($uri).'">';
\r
1811 $manager->addTicketHidden();
\r
1812 _addInputTags($get);
\r
1818 echo '<input type="submit" value="' . _YES . '" /> ';
\r
1819 echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';
\r
1822 $oPluginAdmin->end();
\r
1826 /* Create new ticket */
\r
1827 $ticket=$manager->addTicketToUrl('');
\r
1828 $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7);
\r
1832 function _addInputTags(&$keys,$prefix=''){
\r
1833 foreach($keys as $key=>$value){
\r
1834 if ($prefix) $key=$prefix.'['.$key.']';
\r
1835 if (is_array($value)) _addInputTags($value,$key);
\r
1837 if (get_magic_quotes_gpc()) $value=stripslashes($value);
\r
1838 if ($key=='ticket') continue;
\r
1839 echo '<input type="hidden" name="'.Entity::hsc($key).
\r
1840 '" value="'.Entity::hsc($value).'" />'."\n";
\r
1846 * serverStringToArray()
\r
1847 * Convert the server string such as $_SERVER['REQUEST_URI']
\r
1848 * to arry like arry['blogid']=1 and array['page']=2 etc.
\r
1850 * @param string $str string
\r
1851 * @param string $array
\r
1852 * @param string $frontParam
\r
1854 function serverStringToArray($str, &$array, &$frontParam)
\r
1860 // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2
\r
1861 if ( i18n::strpos($str, "?") > 0 )
\r
1863 list($frontParam, $args) = preg_split("#\?#", $str, 2);
\r
1871 // If there is no args like blogid=1&page=2, return
\r
1872 if ( i18n::strpos($str, "=") == FALSE && !i18n::strlen($frontParam) )
\r
1874 $frontParam = $str;
\r
1878 $array = preg_split("#&#", $args);
\r
1883 * Convert array like array['blogid'] to server string
\r
1884 * such as $_SERVER['REQUEST_URI']
\r
1886 function arrayToServerString($array, $frontParam, &$str)
\r
1888 if ( i18n::strpos($str, "?") !== FALSE )
\r
1890 $str = $frontParam . "?";
\r
1894 $str = $frontParam;
\r
1896 if ( count($array) )
\r
1898 $str .= implode("&", $array);
\r
1905 * Sanitize array parameters.
\r
1906 * This function checks both key and value.
\r
1907 * - check key if it inclues " (double quote), remove from array
\r
1908 * - check value if it includes \ (escape sequece), remove remaining string
\r
1910 * @param array &$array
\r
1913 function sanitizeArray(&$array)
\r
1915 $excludeListForSanitization = array('query');
\r
1917 foreach ( $array as $k => $v )
\r
1919 // split to key and value
\r
1920 list($key, $val) = preg_split("#=#", $v, 2);
\r
1921 if ( !isset($val) )
\r
1926 // when magic quotes is on, need to use stripslashes,
\r
1927 // and then addslashes
\r
1928 if ( get_magic_quotes_gpc() )
\r
1930 $val = stripslashes($val);
\r
1932 // note that we must use addslashes here because this function is called before the db connection is made
\r
1933 // and sql_real_escape_string needs a db connection
\r
1934 $val = addslashes($val);
\r
1936 // if $key is included in exclude list, skip this param
\r
1937 if ( !in_array($key, $excludeListForSanitization) )
\r
1940 if ( i18n::strpos($val, '\\') )
\r
1942 list($val, $tmp) = preg_split('#\\\\#', $val);
\r
1945 // remove control code etc.
\r
1946 $val = strtr($val, "\0\r\n<>'\"", " ");
\r
1949 if ( preg_match('#\"#', $key) )
\r
1951 unset($array[$k]);
\r
1955 // set sanitized info
\r
1956 $array[$k] = sprintf("%s=%s", $key, $val);
\r
1963 * Convert array for sanitizeArray function
\r
1965 function convArrayForSanitizing($src, &$array)
\r
1968 foreach ($src as $key => $val) {
\r
1969 if (key_exists($key, $_GET)) {
\r
1970 array_push($array, sprintf("%s=%s", $key, $val));
\r
1976 * Revert array after sanitizeArray function
\r
1978 function revertArrayForSanitizing($array, &$dst)
\r
1980 foreach ($array as $v) {
\r
1981 list($key, $val) = preg_split("/=/", $v, 2);
\r
1982 $dst[$key] = $val;
\r
1987 * Stops processing the request and redirects to the given URL.
\r
1988 * - no actual contents should have been sent to the output yet
\r
1989 * - the URL will be stripped of illegal or dangerous characters
\r
1991 function redirect($url) {
\r
1992 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);
\r
1993 header('Location: ' . $url);
\r
1998 * getBookmarklet()
\r
1999 * Returns the Javascript code for a bookmarklet that works on most modern browsers
\r
2001 * @param integer $blogid ID for weblog
\r
2002 * @return script to call Bookmarklet
\r
2004 function getBookmarklet($blogid, $width=600, $height=500)
\r
2011 . "if ( x.selection )"
\r
2013 . " Q=x.selection.createRange().text;"
\r
2015 . "else if ( y.getSelection )"
\r
2017 . " Q=y.getSelection();"
\r
2019 . "else if ( x.getSelection )"
\r
2021 . " Q=x.getSelection();"
\r
2023 . "wingm = window.open('{$CONF['AdminURL']}bookmarklet.php?blogid={$blogid}"
\r
2024 . " &logtext=' + encodeURIComponent(Q) +"
\r
2025 . " '&loglink=' + encodeURIComponent(x.location.href) +"
\r
2026 . " '&loglinktitle=' + encodeURIComponent(x.title),"
\r
2028 . " 'scrollbars=yes,width={$width},height={$height},left=10,top=10,status=yes,resizable=yes');"
\r
2029 . "wingm.focus();";
\r
2033 // END: functions from the end of file ADMIN.php
\r
2036 * Returns a variable or null if not set
\r
2038 * @param mixed Variable
\r
2039 * @return mixed Variable
\r
2041 function ifset(&$var) {
\r
2042 if (isset($var)) {
\r
2050 * Returns number of subscriber to an event
\r
2053 * @return number of subscriber(s)
\r
2055 function numberOfEventSubscriber($event) {
\r
2056 $query = sprintf('SELECT COUNT(*) as count FROM %s WHERE event=%s', sql_table('plugin_event'), DB::quoteValue($event));
\r
2057 $res = DB::getValue($query);
\r
2062 * sets $special global variable for use in index.php before selector()
\r
2064 * @param String id
\r
2067 function selectSpecialSkinType($id) {
\r
2069 $special = strtolower($id);
\r
2073 * cleans filename of uploaded file for writing to file system
\r
2075 * @param String str
\r
2076 * @return String cleaned filename ready for use
\r
2078 function cleanFileName($str) {
\r
2079 $str = strtolower($str);
\r
2080 $ext_point = i18n::strrpos($str,".");
\r
2081 if ($ext_point===false) return false;
\r
2082 $ext = i18n::substr($str,$ext_point,i18n::strlen($str));
\r
2083 $str = i18n::substr($str,0,$ext_point);
\r
2085 return preg_replace("/[^a-z0-9-]/","_",$str).$ext;
\r
2089 * Centralisation of the functions to send mail
\r
2090 * Deprecated since 4.0:
\r
2091 * Please use functions in NOTIFICATION class instead
\r
2093 function getMailFooter()
\r
2095 NOTIFICATION::get_mail_footer();
\r
2097 function isValidMailAddress($address)
\r
2099 return NOTIFICATION::address_validation($address);
\r
2102 * Centralisation of the functions that deals XML entities
\r
2103 * Deprecated since 4.0:
\r
2104 * Please use Entity::FunctionName(...) instead
\r
2106 function highlight($text, $expression, $highlight)
\r
2108 return Entity::highlight($text, $expression, $highlight);
\r
2110 function shorten($string, $maxlength, $suffix)
\r
2112 return Entity::shorten($string, $maxlength, $suffix);
\r
2114 function stringStripTags ($string)
\r
2116 return Entity::strip_tags($string);
\r
2118 function toAscii($string)
\r
2120 return Entity::anchor_footnoting($string);
\r
2122 function stringToAttribute ($string)
\r
2124 return Entity::hsc($string);
\r
2126 function stringToXML ($string)
\r
2128 return Entity::hen($string);
\r
2130 function encode_desc($data)
\r
2132 return Entity::hen($data);
\r
2135 * Centralisation of the functions that deals with locales
\r
2136 * This functions is based on the old way to deal with languages
\r
2137 * Deprecated since 4.0:
\r
2139 /* NOTE: use i18n::get_current_locale() directly instead of this */
\r
2140 function getLanguageName()
\r
2142 if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )
\r
2144 $language ='english';
\r
2148 /* NOTE: this is completely deprecated because generating much warnings */
\r
2149 function selectLanguage($language)
\r
2152 include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');
\r
2156 /* NOTE: use i18n::get_available_locales() directly instead of this */
\r
2157 function checkLanguage($lang)
\r
2159 return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)
\r
2160 || i18n::convert_old_language_file_name_to_locale($lang) );
\r
2162 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2163 function formatDate($format, $timestamp, $default_format, &$blog)
\r
2165 $offset = date('Z', $timestamp);
\r
2168 $offset += $blog->getTimeOffset() * 3600;
\r
2170 return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);
\r
2172 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2173 function mysqldate($timestamp)
\r
2175 return '"' . DB::formatDateTime($timestamp) . '"';
\r
2178 * Centralisation of the functions that generate links
\r
2179 * Deprecated since 4.0:
\r
2180 * Please use Link::FunctionName(...) instead
\r
2182 function createItemLink($itemid, $extra = '')
\r
2184 return Link::create_item_link($itemid, $extra);
\r
2186 function createMemberLink($memberid, $extra = '')
\r
2188 return Link::create_member_link($memberid, $extra);
\r
2190 function createCategoryLink($catid, $extra = '')
\r
2192 return Link::create_category_link($catid, $extra);
\r
2194 function createArchiveListLink($blogid = '', $extra = '')
\r
2196 return Link::create_archivelist_link($blogid, $extra);
\r
2198 function createArchiveLink($blogid, $archive, $extra = '')
\r
2200 return Link::create_archive_link($blogid, $archive, $extra);
\r
2202 function createBlogidLink($blogid, $params = '')
\r
2204 return Link::create_blogid_link($blogid, $params = '');
\r
2206 function createLink($type, $params)
\r
2208 return Link::create_link($type, $params);
\r
2210 function createBlogLink($url, $params)
\r
2212 return Link::create_blog_link($url, $params);
\r