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 * load and initialize i18n class
\r
60 if (!class_exists('i18n', FALSE))
\r
62 include($DIR_LIBS . 'i18n.php');
\r
64 if ( !i18n::init('UTF-8', $DIR_LOCALES) )
\r
66 exit('Fail to initialize i18n class.');
\r
69 * FIXME: This is for compatibility since 4.0, should be obsoleted at future release.
\r
71 define('_CHARSET', i18n::get_current_charset());
\r
74 * Indicates when Nucleus should display startup errors. Set to 1 if you want
\r
75 * the error enabled (default), false otherwise
\r
77 * alertOnHeadersSent
\r
78 * Displays an error when visiting a public Nucleus page and headers have
\r
79 * been sent out to early. This usually indicates an error in either a
\r
80 * configuration file or a translation file, and could cause Nucleus to
\r
82 * alertOnSecurityRisk
\r
83 * Displays an error only when visiting the admin area, and when one or
\r
84 * more of the installation files (install.php, install.sql, upgrades/
\r
85 * directory) are still on the server.
\r
87 if ( !array_key_exists('alertOnHeadersSent', $CONF) || $CONF['alertOnHeadersSent'] !== 0 )
\r
89 $CONF['alertOnHeadersSent'] = 1;
\r
91 $CONF['alertOnSecurityRisk'] = 1;
\r
93 * NOTE: this should be removed when releasing 4.0
\r
94 $CONF['ItemURL'] = $CONF['Self'];
\r
95 $CONF['ArchiveURL'] = $CONF['Self'];
\r
96 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
97 $CONF['MemberURL'] = $CONF['Self'];
\r
98 $CONF['SearchURL'] = $CONF['Self'];
\r
99 $CONF['BlogURL'] = $CONF['Self'];
\r
100 $CONF['CategoryURL'] = $CONF['Self'];
\r
104 * Set these to 1 to allow viewing of future items or draft items
\r
105 * Should really never do this, but can be useful for some plugins that might need to
\r
106 * Could cause some other issues if you use future posts otr drafts
\r
109 $CONF['allowDrafts'] = 0;
\r
110 $CONF['allowFuture'] = 0;
\r
112 if ( getNucleusPatchLevel() > 0 )
\r
114 $nucleus['version'] .= '/' . getNucleusPatchLevel();
\r
117 /* Avoid notices */
\r
118 if ( !isset($CONF['installscript']) )
\r
120 $CONF['installscript'] = 0;
\r
123 /* we will use postVar, getVar, ... methods instead of $_GET, $_POST ...*/
\r
124 if ( $CONF['installscript'] != 1 )
\r
126 /* vars were already included in install.php */
\r
127 include_once($DIR_LIBS . 'vars4.1.0.php');
\r
130 /* sanitize option */
\r
131 $bLoggingSanitizedResult=0;
\r
132 $bSanitizeAndContinue=0;
\r
134 $orgRequestURI = serverVar('REQUEST_URI');
\r
137 /* get all variables that can come from the request and put them in the global scope */
\r
138 $blogid = requestVar('blogid');
\r
139 $itemid = intRequestVar('itemid');
\r
140 $catid = intRequestVar('catid');
\r
141 $skinid = requestVar('skinid');
\r
142 $memberid = requestVar('memberid');
\r
143 $archivelist = requestVar('archivelist');
\r
144 $imagepopup = requestVar('imagepopup');
\r
145 $archive = requestVar('archive');
\r
146 $query = requestVar('query');
\r
147 $highlight = requestVar('highlight');
\r
148 $amount = requestVar('amount');
\r
149 $action = requestVar('action');
\r
150 $nextaction = requestVar('nextaction');
\r
151 $maxresults = requestVar('maxresults');
\r
152 $startpos = intRequestVar('startpos');
\r
153 $errormessage = '';
\r
155 $special = requestVar('special');
\r
156 $virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));
\r
158 if ( !headers_sent() )
\r
160 header('Generator: Nucleus CMS ' . $nucleus['version']);
\r
164 * NOTE: Since 4.0 release, Entity class becomes to be important class
\r
165 * with some wrapper functions for htmlspechalchars/htmlentity PHP's built-in function
\r
167 include($DIR_LIBS . 'ENTITY.php');
\r
169 /* include core classes that are needed for login & plugin handling */
\r
170 include_once($DIR_LIBS . 'mysql.php');
\r
171 /* added for 3.5 sql_* wrapper */
\r
172 global $MYSQL_HANDLER;
\r
173 if ( !isset($MYSQL_HANDLER) )
\r
175 $MYSQL_HANDLER = array('mysql','');
\r
177 if ( $MYSQL_HANDLER[0] == '' )
\r
179 $MYSQL_HANDLER[0] = 'mysql';
\r
181 include_once($DIR_LIBS . 'sql/'.$MYSQL_HANDLER[0].'.php');
\r
182 /* end new for 3.5 sql_* wrapper */
\r
183 include($DIR_LIBS . 'MEMBER.php');
\r
184 include($DIR_LIBS . 'ACTIONLOG.php');
\r
185 include($DIR_LIBS . 'MANAGER.php');
\r
186 include($DIR_LIBS . 'PLUGIN.php');
\r
188 $manager =& Manager::instance();
\r
191 * make sure there's no unnecessary escaping:
\r
192 * set_magic_quotes_runtime(0);
\r
194 if ( version_compare(PHP_VERSION, '5.3.0', '<') )
\r
196 ini_set('magic_quotes_runtime', '0');
\r
199 /* Avoid notices */
\r
200 if ( !array_key_exists('UsingAdminArea', $CONF) )
\r
202 $CONF['UsingAdminArea'] = 0;
\r
205 /* only needed when updating logs */
\r
206 if ( $CONF['UsingAdminArea'] )
\r
208 /* XML-RPC client classes */
\r
209 include($DIR_LIBS . 'xmlrpc.inc.php');
\r
210 include_once($DIR_LIBS . 'ADMIN.php');
\r
213 /* connect to database */
\r
217 /* logs sanitized result if need */
\r
218 if ( $orgRequestURI!==serverVar('REQUEST_URI') )
\r
220 $msg = "Sanitized [" . serverVar('REMOTE_ADDR') . "] ";
\r
221 $msg .= $orgRequestURI . " -> " . serverVar('REQUEST_URI');
\r
222 if ( $bLoggingSanitizedResult )
\r
224 addToLog(WARNING, $msg);
\r
226 if ( !$bSanitizeAndContinue )
\r
232 /* makes sure database connection gets closed on script termination */
\r
233 register_shutdown_function('sql_disconnect');
\r
239 * FIXME: This is for backward compatibility, should be obsoleted near future.
\r
241 if ( !preg_match('#^(.+)_(.+)_(.+)$#', $CONF['Locale'])
\r
242 && ($CONF['Locale'] = i18n::convert_old_language_file_name_to_locale($CONF['Locale'])) === FALSE )
\r
244 $CONF['Locale'] = 'en_Latn_US';
\r
246 if ( !array_key_exists('Language', $CONF) )
\r
248 $CONF['Language'] = i18n::convert_locale_to_old_language_file_name($CONF['Locale']);
\r
250 $locale = $CONF['Locale'];
\r
252 /* Properly set $CONF['Self'] and others if it's not set...
\r
253 * usually when we are access from admin menu
\r
255 if ( !array_key_exists('Self', $CONF) )
\r
257 $CONF['Self'] = $CONF['IndexURL'];
\r
258 /* strip trailing */
\r
259 if ( $CONF['Self'][i18n::strlen($CONF['Self']) -1] == "/" )
\r
261 $CONF['Self'] = i18n::substr($CONF['Self'], 0, i18n::strlen($CONF['Self']) -1);
\r
265 $CONF['ItemURL'] = $CONF['Self'];
\r
266 $CONF['ArchiveURL'] = $CONF['Self'];
\r
267 $CONF['ArchiveListURL'] = $CONF['Self'];
\r
268 $CONF['MemberURL'] = $CONF['Self'];
\r
269 $CONF['SearchURL'] = $CONF['Self'];
\r
270 $CONF['BlogURL'] = $CONF['Self'];
\r
271 $CONF['CategoryURL'] = $CONF['Self'];
\r
274 *switch URLMode back to normal when $CONF['Self'] ends in .php
\r
275 * this avoids urls like index.php/item/13/index.php/item/15
\r
277 if ( !array_key_exists('URLMode', $CONF)
\r
278 || (($CONF['URLMode'] == 'pathinfo')
\r
279 && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )
\r
281 $CONF['URLMode'] = 'normal';
\r
284 /* automatically use simpler toolbar for mozilla */
\r
285 if ( ($CONF['DisableJsTools'] == 0)
\r
286 && strstr(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0')
\r
287 && strstr(serverVar('HTTP_USER_AGENT'), 'Gecko') )
\r
289 $CONF['DisableJsTools'] = 2;
\r
292 $member = new Member();
\r
294 if ( $action == 'login' )
\r
296 $login = postVar('login');
\r
297 $password = postVar('password');
\r
298 $shared = intPostVar('shared');
\r
299 $member->login($login, $password, $shared);
\r
301 elseif ( ($action == 'logout') )
\r
307 $member->cookielogin();
\r
310 /* NOTE: include translation file and set locale */
\r
311 if ( $member->isLoggedIn() && $member->getLocale())
\r
313 $locale = $member->getLocale();
\r
315 include_translation($locale);
\r
316 i18n::set_current_locale($locale);
\r
318 /* login completed */
\r
319 $manager->notify('PostAuthentication', array('loggedIn' => $member->isLoggedIn() ) );
\r
322 if ( $member->isLoggedIn() && $nextaction )
\r
324 $action = $nextaction;
\r
328 * Release ticket for plugin
\r
332 /* first, let's see if the site is disabled or not. always allow admin area access. */
\r
333 if ( $CONF['DisableSite'] && !$member->isAdmin() && !$CONF['UsingAdminArea'] )
\r
335 redirect($CONF['DisableSiteURL']);
\r
339 /* load other classes */
\r
340 include($DIR_LIBS . 'PARSER.php');
\r
341 include($DIR_LIBS . 'SKIN.php');
\r
342 include($DIR_LIBS . 'TEMPLATE.php');
\r
343 include($DIR_LIBS . 'BLOG.php');
\r
344 include($DIR_LIBS . 'BODYACTIONS.php');
\r
345 include($DIR_LIBS . 'COMMENTS.php');
\r
346 include($DIR_LIBS . 'COMMENT.php');
\r
347 /* include($DIR_LIBS . 'ITEM.php'); */
\r
348 include($DIR_LIBS . 'NOTIFICATION.php');
\r
349 include($DIR_LIBS . 'BAN.php');
\r
350 include($DIR_LIBS . 'PAGEFACTORY.php');
\r
351 include($DIR_LIBS . 'SEARCH.php');
\r
352 include($DIR_LIBS . 'LINK.php');
\r
354 /* set lastVisit cookie (if allowed) */
\r
355 if ( !headers_sent() )
\r
357 if ( $CONF['LastVisit'] )
\r
359 setcookie($CONF['CookiePrefix'] . 'lastVisit', time(), time() + 2592000, $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
363 setcookie($CONF['CookiePrefix'] . 'lastVisit', '', (time() - 2592000), $CONF['CookiePath'], $CONF['CookieDomain'], $CONF['CookieSecure']);
\r
367 if ( !defined('_ARCHIVETYPE_MONTH') )
\r
369 define('_ARCHIVETYPE_DAY', 'day');
\r
370 define('_ARCHIVETYPE_MONTH', 'month');
\r
371 define('_ARCHIVETYPE_YEAR', 'year');
\r
374 /* decode path_info */
\r
375 if ( $CONF['URLMode'] == 'pathinfo' )
\r
377 /* initialize keywords if this hasn't been done before */
\r
378 if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )
\r
380 $CONF['ItemKey'] = 'item';
\r
383 if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )
\r
385 $CONF['ArchiveKey'] = 'archive';
\r
388 if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )
\r
390 $CONF['ArchivesKey'] = 'archives';
\r
393 if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )
\r
395 $CONF['MemberKey'] = 'member';
\r
398 if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )
\r
400 $CONF['BlogKey'] = 'blog';
\r
403 if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )
\r
405 $CONF['CategoryKey'] = 'category';
\r
408 if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )
\r
410 $CONF['SpecialskinKey'] = 'special';
\r
417 /* e.g. item, blog, ... */
\r
418 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
419 'info' => $virtualpath,
\r
420 'complete' => &$parsed
\r
426 /* default implementation */
\r
427 $data = preg_split("#/#", $virtualpath );
\r
428 for ( $i = 0; $i < sizeof($data); $i++ )
\r
430 switch ( $data[$i] )
\r
432 /* item/1 (blogid) */
\r
433 case $CONF['ItemKey']:
\r
436 if ( $i < sizeof($data) )
\r
438 $itemid = intval($data[$i]);
\r
442 /* archives/1 (blogid) */
\r
443 case $CONF['ArchivesKey']:
\r
445 if ( $i < sizeof($data) )
\r
447 $archivelist = intval($data[$i]);
\r
451 /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
\r
452 case $CONF['ArchiveKey']:
\r
453 if ( (($i + 1) < sizeof($data) ) && (!strstr($data[$i + 1], '-') ) )
\r
455 $blogid = intval($data[++$i]);
\r
458 if ( $i < sizeof($data) )
\r
460 $archive = $data[$i];
\r
467 case $CONF['BlogKey']:
\r
469 if ( $i < sizeof($data) )
\r
471 $blogid = intval($data[$i]);
\r
475 /* category/1 (catid) */
\r
476 case $CONF['CategoryKey']:
\r
479 if ( $i < sizeof($data) )
\r
481 $catid = intval($data[$i]);
\r
485 case $CONF['MemberKey']:
\r
487 if ( $i < sizeof($data) )
\r
489 $memberid = intval($data[$i]);
\r
493 case $CONF['SpecialskinKey']:
\r
495 if ( $i < sizeof($data) )
\r
497 $special = $data[$i];
\r
498 $_REQUEST['special'] = $special;
\r
510 * PostParseURL is a place to cleanup any of the path-related global variables before the selector function is run.
\r
511 * It has 2 values in the data in case the original virtualpath is needed, but most the use will be in tweaking
\r
512 * global variables to clean up (scrub out catid or add catid) or to set someother global variable based on
\r
513 * the values of something like catid or itemid
\r
519 /* e.g. item, blog, ... */
\r
520 'type' => basename(serverVar('SCRIPT_NAME') ),
\r
521 'info' => $virtualpath
\r
526 * NOTE: Here is the end of initialization
\r
530 * This function includes or requires the specified library file
\r
531 * @param string $file
\r
532 * @param bool $once use the _once() version
\r
533 * @param bool $require use require() instead of include()
\r
535 function include_libs($file, $once = TRUE, $require = TRUE)
\r
539 // begin if: $DIR_LIBS isn't a directory
\r
540 if ( !is_dir($DIR_LIBS) )
\r
545 $lib_path = $DIR_LIBS . $file;
\r
548 if ( $once && $require )
\r
550 require_once($lib_path);
\r
552 else if ( $once && !$require )
\r
554 include_once($lib_path);
\r
556 else if ( $require )
\r
558 require($lib_path);
\r
562 include($lib_path);
\r
569 * This function includes or requires the specified plugin file
\r
570 * @param string $file
\r
571 * @param bool $once use the _once() version
\r
572 * @param bool $require use require() instead of include()
\r
574 function include_plugins($file, $once = TRUE, $require = TRUE)
\r
576 global $DIR_PLUGINS;
\r
578 // begin if: $DIR_LIBS isn't a directory
\r
579 if ( !is_dir($DIR_PLUGINS) )
\r
584 $plugin_path = $DIR_PLUGINS . $file;
\r
587 if ( $once && $require )
\r
589 require_once($plugin_path);
\r
591 else if ( $once && !$require )
\r
593 include_once($plugin_path);
\r
595 elseif ( $require )
\r
597 require($plugin_path);
\r
601 include($plugin_path);
\r
606 * This function decide which locale is used and include translation
\r
607 * @param string $locale locale name referring to 'language tags' defined in RFC 5646
\r
610 function include_translation($locale)
\r
612 global $DIR_LOCALES;
\r
614 $translation_file = $DIR_LOCALES . $locale . '.' . i18n::get_current_charset() . '.php';
\r
615 if ( !file_exists($translation_file) )
\r
617 $locale = 'en_Latn_US';
\r
618 $translation_file = $DIR_LOCALES . 'en_Latn_US.ISO-8859-1.php';
\r
620 include($translation_file);
\r
625 * This function returns the integer value of $_POST for the variable $name
\r
626 * @param string $name field to get the integer value of
\r
629 function intPostVar($name)
\r
631 return intval(postVar($name));
\r
636 * This function returns the integer value of $_GET for the variable $name
\r
637 * @param string $name field to get the integer value of
\r
640 function intGetVar($name)
\r
642 return intval(getVar($name));
\r
647 * This function returns the integer value of $_REQUEST for the variable $name. Also checks $_GET and $_POST if not found in $_REQUEST
\r
648 * @param string $name field to get the integer value of
\r
651 function intRequestVar($name)
\r
653 return intval(requestVar($name));
\r
658 * This function returns the integer value of $_COOKIE for the variable $name
\r
659 * @param string $name field to get the integer value of
\r
662 function intCookieVar($name)
\r
664 return intval(cookieVar($name));
\r
669 * This function returns the current Nucleus version (100 = 1.00, 101 = 1.01, etc...)
\r
672 function getNucleusVersion()
\r
679 * TODO: Better description of this function.
\r
681 * Power users can install patches in between nucleus releases. These patches
\r
682 * usually add new functionality in the plugin API and allow those to
\r
683 * be tested without having to install CVS.
\r
687 function getNucleusPatchLevel()
\r
694 * This function returns the latest Nucleus version available for download from nucleuscms.org or FALSE if unable to attain data
\r
695 * Format will be major.minor/patachlevel e.g. 3.41 or 3.41/02
\r
696 * @return string|bool
\r
698 function getLatestVersion()
\r
700 // begin if: cURL is not available in this PHP installation
\r
701 if ( !function_exists('curl_init') )
\r
706 $curl = curl_init();
\r
708 curl_setopt ($curl, CURLOPT_URL, 'http://nucleuscms.org/version_check.php');
\r
709 curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
\r
710 curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
\r
711 $return = curl_exec($curl);
\r
718 * This function returns a Nucleus table name with the appropriate prefix
\r
719 * @param string $name
\r
722 function sql_table($name)
\r
724 global $MYSQL_PREFIX;
\r
726 // begin if: no MySQL prefix
\r
727 if ( empty($MYSQL_PREFIX) )
\r
729 return 'nucleus_' . $name;
\r
731 // else: use MySQL prefix
\r
734 return $MYSQL_PREFIX . 'nucleus_' . $name;
\r
741 * TODO: This function should be changed to send_content_type() per the Coding Guidelines. Ensure this change is compatible with rest of core.
\r
743 * This function sends the Content-Type header if headers have not already been sent
\r
744 * It also determines if the browser can accept application/xhtml+xml and sends it only to those that can.
\r
745 * @param string $content_type
\r
746 * @param string $page_type
\r
747 * @param string $charset Deprecated. This has no meaning.
\r
749 function sendContentType($content_type, $page_type = '', $charset = _CHARSET)
\r
751 global $manager, $CONF;
\r
753 if ( !headers_sent() )
\r
755 // if content type is application/xhtml+xml, only send it to browsers
\r
756 // that can handle it (IE6 cannot). Otherwise, send text/html
\r
758 // v2.5: For admin area pages, keep sending text/html (unless it's a debug version)
\r
759 // application/xhtml+xml still causes too much problems with the javascript implementations
\r
761 // v3.3: ($CONF['UsingAdminArea'] && !$CONF['debug']) gets removed,
\r
762 // application/xhtml+xml seems to be working, so we're going to use it if we can.
\r
764 if ( ($content_type == 'application/xhtml+xml')
\r
765 && (!stristr(serverVar('HTTP_ACCEPT'), 'application/xhtml+xml') ) )
\r
767 $content_type = 'text/html';
\r
771 'PreSendContentType',
\r
773 'contentType' => &$content_type,
\r
774 'charset' => i18n::get_current_charset(),
\r
775 'pageType' => $page_type
\r
779 // strip strange characters
\r
780 $content_type = preg_replace('|[^a-z0-9-+./]|i', '', $content_type);
\r
781 header('Content-Type: ' . $content_type . '; charset=' . i18n::get_current_charset());
\r
788 * This function parses a query into an array of expressions that can be passed on to the highlight method
\r
789 * @param string $query
\r
791 function parseHighlight($query)
\r
793 // TODO: add more intelligent splitting logic
\r
795 // get rid of quotes
\r
796 $query = preg_replace('/\'|"/', '', $query);
\r
803 $aHighlight = preg_split('# #', $query);
\r
805 for ( $i = 0; $i < count($aHighlight); $i++ )
\r
807 $aHighlight[$i] = trim($aHighlight[$i]);
\r
809 if ( i18n::strlen($aHighlight[$i]) < 3 )
\r
811 unset($aHighlight[$i]);
\r
815 if ( count($aHighlight) == 1 )
\r
817 return $aHighlight[0];
\r
821 return $aHighlight;
\r
827 * This function gets the blog ID from the blog name
\r
828 * @param string $name
\r
831 function getBlogIDFromName($name)
\r
833 return quickQuery('SELECT bnumber AS result FROM ' . sql_table('blog') . ' WHERE bshortname = "' . sql_real_escape_string($name) . '"');
\r
838 * This function gets the blog name from the blog ID
\r
842 function getBlogNameFromID($id)
\r
844 return quickQuery('SELECT bname AS result FROM ' . sql_table('blog') . ' WHERE bnumber = ' . intval($id));
\r
849 * This function gets the blog ID from the item ID
\r
850 * @param int $item_id
\r
853 function getBlogIDFromItemID($item_id)
\r
855 return quickQuery('SELECT iblog AS result FROM ' . sql_table('item') . ' WHERE inumber = ' . intval($item_id));
\r
860 * This function gets the blog ID from the comment ID
\r
861 * @param int $comment_id
\r
864 function getBlogIDFromCommentID($comment_id)
\r
866 return quickQuery('SELECT cblog AS result FROM ' . sql_table('comment') . ' WHERE cnumber = ' . intval($comment_id));
\r
871 * This function gets the blog ID from the category ID
\r
872 * @param int $category_id
\r
875 function getBlogIDFromCatID($category_id)
\r
877 return quickQuery('SELECT cblog AS result FROM ' . sql_table('category') . ' WHERE catid = ' . intval($category_id));
\r
882 * This function gets the category ID from the category name
\r
886 function getCatIDFromName($name)
\r
888 return quickQuery('SELECT catid AS result FROM ' . sql_table('category') . ' WHERE cname = "' . sql_real_escape_string($name) . '"');
\r
893 * This function performs a quick SQL query
\r
894 * @param string $query
\r
897 function quickQuery($query)
\r
899 $res = sql_query($query);
\r
900 $obj = sql_fetch_object($res);
\r
901 return $obj->result;
\r
904 function getPluginNameFromPid($pid) {
\r
905 $res = sql_query('SELECT pfile FROM ' . sql_table('plugin') . ' WHERE pid=' . intval($pid) );
\r
906 $obj = sql_fetch_object($res);
\r
907 return $obj->pfile;
\r
908 // return isset($obj->pfile) ? $obj->pfile : false;
\r
911 function selector()
\r
913 global $itemid, $blogid, $memberid, $query, $amount, $archivelist, $maxresults;
\r
914 global $archive, $skinid, $blog, $memberinfo, $CONF, $member;
\r
915 global $imagepopup, $catid, $special;
\r
918 $actionNames = array('addcomment', 'sendmessage', 'createaccount', 'forgotpassword', 'votepositive', 'votenegative', 'plugin');
\r
919 $action = requestVar('action');
\r
921 if ( in_array($action, $actionNames) )
\r
923 global $DIR_LIBS, $errormessage;
\r
924 include_once($DIR_LIBS . 'ACTION.php');
\r
926 $errorInfo = $a->doAction($action);
\r
930 $errormessage = $errorInfo['message'];
\r
934 // show error when headers already sent out
\r
935 if ( headers_sent() && $CONF['alertOnHeadersSent'] )
\r
937 // try to get line number/filename (extra headers_sent params only exists in PHP 4.3+)
\r
938 if ( function_exists('version_compare') && version_compare('4.3.0', phpversion(), '<=') )
\r
940 headers_sent($hsFile, $hsLine);
\r
941 $extraInfo = ' in <code>' . $hsFile . '</code> line <code>' . $hsLine . '</code>';
\r
949 '<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
950 'Page headers already sent'
\r
955 // make is so ?archivelist without blogname or blogid shows the archivelist
\r
956 // for the default weblog
\r
957 if ( serverVar('QUERY_STRING') == 'archivelist' )
\r
959 $archivelist = $CONF['DefaultBlog'];
\r
962 // now decide which type of skin we need
\r
965 // itemid given -> only show that item
\r
968 if ( !$manager->existsItem($itemid,intval($CONF['allowFuture']),intval($CONF['allowDrafts'])) )
\r
970 doError(_ERROR_NOSUCHITEM);
\r
973 global $itemidprev, $itemidnext, $catid, $itemtitlenext, $itemtitleprev;
\r
975 // 1. get timestamp, blogid and catid for item
\r
976 $query = 'SELECT itime, iblog, icat FROM %s WHERE inumber=%d';
\r
977 $query = sprintf($query, sql_table('item'), (integer) $itemid);
\r
978 $res = sql_query($query);
\r
979 $obj = sql_fetch_object($res);
\r
981 // if a different blog id has been set through the request or selectBlog(),
\r
984 if ( $blogid && (intval($blogid) != $obj->iblog) )
\r
986 doError(_ERROR_NOSUCHITEM);
\r
989 // if a category has been selected which doesn't match the item, ignore the
\r
991 if ( ($catid != 0) && ($catid != $obj->icat) )
\r
996 $blogid = $obj->iblog;
\r
997 $timestamp = strtotime($obj->itime);
\r
999 $b =& $manager->getBlog($blogid);
\r
1001 if ( !$b->isValidCategory($catid) )
\r
1003 $query = "SELECT inumber, ititle FROM %s WHERE itime<'%s' AND idraft=0 AND iblog=%d ORDER BY itime DESC LIMIT 1";
\r
1004 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid);
\r
1008 $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
1009 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), $blogid, $catid);
\r
1012 $res = sql_query($query);
\r
1013 $obj = sql_fetch_object($res);
\r
1017 $itemidprev = $obj->inumber;
\r
1018 $itemtitleprev = $obj->ititle;
\r
1021 // get next itemid and title
\r
1022 if ( !$b->isValidCategory($catid) )
\r
1024 $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
1025 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid);
\r
1029 $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
1030 $query = sprintf($query, sql_table('item'), i18n::formatted_datetime('mysql', $timestamp), i18n::formatted_datetime('mysql', $b->getCorrectTime()), $blogid, $catid);
\r
1032 $res = sql_query($query);
\r
1034 $obj = sql_fetch_object($res);
\r
1038 $itemidnext = $obj->inumber;
\r
1039 $itemtitlenext = $obj->ititle;
\r
1042 elseif ( $archive )
\r
1045 $type = 'archive';
\r
1047 // get next and prev month links ...
\r
1048 global $archivenext, $archiveprev, $archivetype, $archivenextexists, $archiveprevexists;
\r
1050 // sql queries for the timestamp of the first and the last published item
\r
1051 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime ASC";
\r
1052 $first_timestamp=quickQuery ($query);
\r
1053 $query = "SELECT UNIX_TIMESTAMP(itime) as result FROM ".sql_table('item')." WHERE idraft=0 ORDER BY itime DESC";
\r
1054 $last_timestamp=quickQuery ($query);
\r
1056 sscanf($archive, '%d-%d-%d', $y, $m, $d);
\r
1060 $archivetype = _ARCHIVETYPE_DAY;
\r
1061 $t = mktime(0, 0, 0, $m, $d, $y);
\r
1062 // one day has 24 * 60 * 60 = 86400 seconds
\r
1063 $archiveprev = i18n::formatted_datetime('%Y-%m-%d', $t - 86400 );
\r
1064 // check for published items
\r
1065 if ( $t > $first_timestamp )
\r
1067 $archiveprevexists = true;
\r
1071 $archiveprevexists = false;
\r
1076 $archivenext = i18n::formatted_datetime('%Y-%m-%d', $t);
\r
1077 if ( $t < $last_timestamp )
\r
1079 $archivenextexists = true;
\r
1083 $archivenextexists = false;
\r
1086 elseif ( $m == 0 )
\r
1088 $archivetype = _ARCHIVETYPE_YEAR;
\r
1089 $t = mktime(0, 0, 0, 12, 31, $y - 1);
\r
1090 // one day before is in the previous year
\r
1091 $archiveprev = i18n::formatted_datetime('%Y', $t);
\r
1092 if ( $t > $first_timestamp )
\r
1094 $archiveprevexists = true;
\r
1098 $archiveprevexists = false;
\r
1101 // timestamp for the next year
\r
1102 $t = mktime(0, 0, 0, 1, 1, $y + 1);
\r
1103 $archivenext = i18n::formatted_datetime('%Y', $t);
\r
1104 if ( $t < $last_timestamp )
\r
1106 $archivenextexists = true;
\r
1110 $archivenextexists = false;
\r
1115 $archivetype = _ARCHIVETYPE_MONTH;
\r
1116 $t = mktime(0, 0, 0, $m, 1, $y);
\r
1117 // one day before is in the previous month
\r
1118 $archiveprev = i18n::formatted_datetime('%Y-%m', $t - 86400);
\r
1119 if ( $t > $first_timestamp )
\r
1121 $archiveprevexists = true;
\r
1125 $archiveprevexists = false;
\r
1128 // timestamp for the next month
\r
1129 $t = mktime(0, 0, 0, $m+1, 1, $y);
\r
1130 $archivenext = i18n::formatted_datetime('%Y-%m', $t);
\r
1131 if ( $t < $last_timestamp )
\r
1133 $archivenextexists = true;
\r
1137 $archivenextexists = false;
\r
1141 elseif ( $archivelist )
\r
1143 $type = 'archivelist';
\r
1145 if ( is_numeric($archivelist) )
\r
1147 $blogid = intVal($archivelist);
\r
1151 $blogid = getBlogIDFromName($archivelist);
\r
1156 doError(_ERROR_NOSUCHBLOG);
\r
1163 $query = stripslashes($query);
\r
1165 if ( is_numeric($blogid) )
\r
1167 $blogid = intVal($blogid);
\r
1171 $blogid = getBlogIDFromName($blogid);
\r
1176 doError(_ERROR_NOSUCHBLOG);
\r
1179 elseif ( $memberid )
\r
1183 if ( !Member::existsID($memberid) )
\r
1185 doError(_ERROR_NOSUCHMEMBER);
\r
1187 $memberinfo = $manager->getMember($memberid);
\r
1189 elseif ( $imagepopup )
\r
1191 // media object (images etc.)
\r
1192 $type = 'imagepopup';
\r
1194 // TODO: check if media-object exists
\r
1195 // TODO: set some vars?
\r
1199 // show regular index page
\r
1204 // any type of skin with catid
\r
1205 if ( $catid && !$blogid )
\r
1207 $blogid = getBlogIDFromCatID($catid);
\r
1210 // decide which blog should be displayed
\r
1213 $blogid = $CONF['DefaultBlog'];
\r
1216 $b =& $manager->getBlog($blogid);
\r
1217 $blog = $b; // references can't be placed in global variables?
\r
1219 if ( !$blog->isValid )
\r
1221 doError(_ERROR_NOSUCHBLOG);
\r
1224 // set catid if necessary
\r
1227 // check if the category is valid
\r
1228 if ( !$blog->isValidCategory($catid) )
\r
1230 doError(_ERROR_NOSUCHCATEGORY);
\r
1234 $blog->setSelectedCategory($catid);
\r
1238 // decide which skin should be used
\r
1239 if ( $skinid != '' && ($skinid == 0) )
\r
1241 selectSkin($skinid);
\r
1246 $skinid = $blog->getDefaultSkin();
\r
1249 //$special = requestVar('special'); //get at top of file as global
\r
1250 if ( !empty($special) && isValidShortName($special) )
\r
1252 $type = strtolower($special);
\r
1255 $skin = new SKIN($skinid);
\r
1257 if ( !$skin->isValid() )
\r
1259 doError(_ERROR_NOSUCHSKIN);
\r
1262 // set global skinpart variable so can determine quickly what is being parsed from any plugin or phpinclude
\r
1264 $skinpart = $type;
\r
1267 $skin->parse($type);
\r
1269 // check to see we should throw JustPosted event
\r
1270 $blog->checkJustPosted();
\r
1275 * Show error skin with given message. An optional skin-object to use can be given
\r
1277 function doError($msg, $skin = '')
\r
1279 global $errormessage, $CONF, $skinid, $blogid, $manager;
\r
1281 if ( $skin == '' )
\r
1283 if ( Skin::existsID($skinid) )
\r
1287 elseif ( $manager->existsBlogID($blogid) )
\r
1289 $blog =& $manager->getBlog($blogid);
\r
1290 $id = $blog->getDefaultSkin();
\r
1292 elseif ($CONF['DefaultBlog'] )
\r
1294 $blog =& $manager->getBlog($CONF['DefaultBlog']);
\r
1295 $id = $blog->getDefaultSkin();
\r
1299 // this statement should actually never be executed
\r
1300 $id = $CONF['BaseSkin'];
\r
1302 $skin = new Skin($id);
\r
1305 $skinid = $skin->getID();
\r
1306 $errormessage = $msg;
\r
1307 $skin->parse('error');
\r
1311 function getConfig() {
\r
1314 $query = 'SELECT * FROM ' . sql_table('config');
\r
1315 $res = sql_query($query);
\r
1317 while ($obj = sql_fetch_object($res) ) {
\r
1318 $CONF[$obj->name] = $obj->value;
\r
1322 // some checks for names of blogs, categories, templates, members, ...
\r
1323 function isValidShortName($name) {
\r
1325 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1326 # original eregi: eregi('^[a-z0-9]+$', $name)
\r
1328 return preg_match('#^[a-z0-9]+$#i', $name);
\r
1332 function isValidDisplayName($name) {
\r
1334 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1335 # original eregi: eregi('^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$', $name)
\r
1337 return preg_match('#^[a-z0-9]+[a-z0-9 ]*[a-z0-9]+$#i', $name);
\r
1341 function isValidCategoryName($name) {
\r
1345 function isValidTemplateName($name) {
\r
1347 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1348 # original eregi: eregi('^[a-z0-9/]+$', $name)
\r
1349 // added - and _ to valid characters as of 4.00
\r
1351 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1355 function isValidSkinName($name) {
\r
1357 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
\r
1358 # original eregi: eregi('^[a-z0-9/]+$', $name);
\r
1359 // added - and _ to valid characters as of 4.00
\r
1361 return preg_match('#^[a-z0-9/_\-]+$#i', $name);
\r
1365 // add and remove linebreaks
\r
1366 function addBreaks($var) {
\r
1367 return nl2br($var);
\r
1370 function removeBreaks($var) {
\r
1371 return preg_replace("/<br \/>([\r\n])/", "$1", $var);
\r
1375 * functions for use in index.php
\r
1377 function selectBlog($shortname) {
\r
1378 global $blogid, $archivelist;
\r
1379 $blogid = getBlogIDFromName($shortname);
\r
1381 // also force archivelist variable, if it is set
\r
1382 if ($archivelist) {
\r
1383 $archivelist = $blogid;
\r
1387 function selectSkin($skinname) {
\r
1389 $skinid = SKIN::getIdFromName($skinname);
\r
1393 * Can take either a category ID or a category name (be aware that
\r
1394 * multiple categories can have the same name)
\r
1396 function selectCategory($cat) {
\r
1398 if (is_numeric($cat) ) {
\r
1399 $catid = intval($cat);
\r
1401 $catid = getCatIDFromName($cat);
\r
1405 function selectItem($id) {
\r
1407 $itemid = intval($id);
\r
1410 function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
\r
1414 if ( !$skinid || !existsID($skinid) )
\r
1416 $skin = new Skin($CONF['BaseSkin']);
\r
1420 $skin = new Skin($skinid);
\r
1423 $oldIncludeMode = Parser::getProperty('IncludeMode');
\r
1424 $oldIncludePrefix = Parser::getProperty('IncludePrefix');
\r
1426 $skin->parse('fileparse', $filename);
\r
1428 Parser::setProperty('IncludeMode', $oldIncludeMode);
\r
1429 Parser::setProperty('IncludePrefix', $oldIncludePrefix);
\r
1435 * Outputs a debug message
\r
1437 function debug($msg) {
\r
1438 echo '<p><b>' . $msg . "</b></p>\n";
\r
1442 function addToLog($level, $msg) {
\r
1443 ActionLog::add($level, $msg);
\r
1446 // shows a link to help file
\r
1447 function help($id) {
\r
1448 echo helpHtml($id);
\r
1451 function helpHtml($id) {
\r
1453 return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" title="' . _HELP_TT . '" /></a>';
\r
1456 function helplink($id) {
\r
1458 return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event && event.preventDefault) event.preventDefault(); return help(this.href);">';
\r
1462 * Includes a PHP file. This method can be called while parsing templates and skins
\r
1464 function includephp($filename) {
\r
1465 // make predefined variables global, so most simple scripts can be used here
\r
1467 // apache (names taken from PHP doc)
\r
1468 global $GATEWAY_INTERFACE, $SERVER_NAME, $SERVER_SOFTWARE, $SERVER_PROTOCOL;
\r
1469 global $REQUEST_METHOD, $QUERY_STRING, $DOCUMENT_ROOT, $HTTP_ACCEPT;
\r
1470 global $HTTP_ACCEPT_CHARSET, $HTTP_ACCEPT_ENCODING, $HTTP_ACCEPT_LANGUAGE;
\r
1471 global $HTTP_CONNECTION, $HTTP_HOST, $HTTP_REFERER, $HTTP_USER_AGENT;
\r
1472 global $REMOTE_ADDR, $REMOTE_PORT, $SCRIPT_FILENAME, $SERVER_ADMIN;
\r
1473 global $SERVER_PORT, $SERVER_SIGNATURE, $PATH_TRANSLATED, $SCRIPT_NAME;
\r
1474 global $REQUEST_URI;
\r
1476 // php (taken from PHP doc)
\r
1477 global $argv, $argc, $PHP_SELF, $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1478 global $HTTP_POST_FILES, $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS;
\r
1481 global $PATH_INFO, $HTTPS, $HTTP_RAW_POST_DATA, $HTTP_X_FORWARDED_FOR;
\r
1483 if (@file_exists($filename) ) {
\r
1484 include($filename);
\r
1489 * Checks if a certain plugin exists
\r
1490 * @param string $plug
\r
1493 function checkPlugin($plug) {
\r
1495 global $DIR_PLUGINS;
\r
1497 # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
\r
1498 # original ereg_replace: ereg_replace( '[\\|/]', '', $plug) . '.php')
\r
1499 # important note that '\' must be matched with '\\\\' in preg* expressions
\r
1501 return file_exists($DIR_PLUGINS . preg_replace('#[\\\\|/]#', '', $plug) . '.php');
\r
1508 * @param string $querystr querystring to alter (e.g. foo=1&bar=2&x=y)
\r
1509 * @param string $param name of parameter to change (e.g. 'foo')
\r
1510 * @param string $value New value for that parameter (e.g. 3)
\r
1511 * @result string altered query string (for the examples above: foo=3&bar=2&x=y)
\r
1513 function alterQueryStr($querystr, $param, $value)
\r
1515 $vars = preg_split('#&#', $querystr);
\r
1518 for ( $i = 0; $i < count($vars); $i++ )
\r
1520 $v = preg_split('#=#', $vars[$i]);
\r
1522 if ( $v[0] == $param )
\r
1525 $vars[$i] = implode('=', $v);
\r
1532 $vars[] = "{$param}={$value}";
\r
1534 return ltrim(implode('&', $vars), '&');
\r
1537 // passes one variable as hidden input field (multiple fields for arrays)
\r
1538 // @see passRequestVars in varsx.x.x.php
\r
1539 function passVar($key, $value) {
\r
1541 if (is_array($value) ) {
\r
1542 for ($i = 0; $i < sizeof($value); $i++) {
\r
1543 passVar($key . '[' . $i . ']', $value[$i]);
\r
1549 // other values: do stripslashes if needed
\r
1550 ?><input type="hidden" name="<?php echo Entity::hsc($key)?>" value="<?php echo Entity::hsc(undoMagic($value) )?>" /><?php
\r
1553 function checkVars($aVars) {
\r
1554 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
\r
1556 foreach ($aVars as $varName) {
\r
1558 if (phpversion() >= '4.1.0') {
\r
1560 if ( isset($_GET[$varName])
\r
1561 || isset($_POST[$varName])
\r
1562 || isset($_COOKIE[$varName])
\r
1563 || isset($_ENV[$varName])
\r
1564 || isset($_SESSION[$varName])
\r
1565 || isset($_FILES[$varName])
\r
1567 die('Sorry. An error occurred.');
\r
1572 if ( isset($HTTP_GET_VARS[$varName])
\r
1573 || isset($HTTP_POST_VARS[$varName])
\r
1574 || isset($HTTP_COOKIE_VARS[$varName])
\r
1575 || isset($HTTP_ENV_VARS[$varName])
\r
1576 || isset($HTTP_SESSION_VARS[$varName])
\r
1577 || isset($HTTP_POST_FILES[$varName])
\r
1579 die('Sorry. An error occurred.');
\r
1588 * Sanitize parameters such as $_GET and $_SERVER['REQUEST_URI'] etc.
\r
1591 function sanitizeParams()
\r
1593 global $HTTP_SERVER_VARS;
\r
1599 // REQUEST_URI of $HTTP_SERVER_VARS
\r
1600 $str =& $HTTP_SERVER_VARS["REQUEST_URI"];
\r
1601 serverStringToArray($str, $array, $frontParam);
\r
1602 sanitizeArray($array);
\r
1603 arrayToServerString($array, $frontParam, $str);
\r
1605 // QUERY_STRING of $HTTP_SERVER_VARS
\r
1606 $str =& $HTTP_SERVER_VARS["QUERY_STRING"];
\r
1607 serverStringToArray($str, $array, $frontParam);
\r
1608 sanitizeArray($array);
\r
1609 arrayToServerString($array, $frontParam, $str);
\r
1611 if (phpversion() >= '4.1.0') {
\r
1612 // REQUEST_URI of $_SERVER
\r
1613 $str =& $_SERVER["REQUEST_URI"];
\r
1614 serverStringToArray($str, $array, $frontParam);
\r
1615 sanitizeArray($array);
\r
1616 arrayToServerString($array, $frontParam, $str);
\r
1618 // QUERY_STRING of $_SERVER
\r
1619 $str =& $_SERVER["QUERY_STRING"];
\r
1620 serverStringToArray($str, $array, $frontParam);
\r
1621 sanitizeArray($array);
\r
1622 arrayToServerString($array, $frontParam, $str);
\r
1626 convArrayForSanitizing($_GET, $array);
\r
1627 sanitizeArray($array);
\r
1628 revertArrayForSanitizing($array, $_GET);
\r
1630 // $_REQUEST (only GET param)
\r
1631 convArrayForSanitizing($_REQUEST, $array);
\r
1632 sanitizeArray($array);
\r
1633 revertArrayForSanitizing($array, $_REQUEST);
\r
1637 * ticketForPlugin()
\r
1639 * Check ticket when not checked in plugin's admin page
\r
1641 * Also avoid the access to plugin/index.php by guest user.
\r
1643 function ticketForPlugin()
\r
1645 global $CONF, $DIR_PLUGINS, $member, $ticketforplugin;
\r
1648 $ticketforplugin = array();
\r
1649 $ticketforplugin['ticket'] = FALSE;
\r
1651 /* $_SERVER['PATH_TRANSLATED']
\r
1652 * http://www.php.net/manual/en/reserved.variables.server.php
\r
1653 * Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
\r
1654 * under the Apache 2 SAPI in contrast to the situation in Apache 1,
\r
1655 * where it's set to the same value as the SCRIPT_FILENAME server variable
\r
1656 * when it's not populated by Apache.
\r
1657 * This change was made to comply with the CGI specification
\r
1658 * that PATH_TRANSLATED should only exist if PATH_INFO is defined.
\r
1659 * Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.
\r
1662 /* Check if using plugin's php file. */
\r
1663 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1665 if (!file_exists($p_translated) )
\r
1667 header("HTTP/1.0 404 Not Found");
\r
1671 $p_translated = str_replace('\\', '/', $p_translated);
\r
1672 $d_plugins = str_replace('\\', '/', $DIR_PLUGINS);
\r
1674 // This isn't plugin php file.
\r
1675 if ( i18n::strpos($p_translated, $d_plugins) !== 0 )
\r
1680 // Solve the plugin php file or admin directory
\r
1681 $phppath = i18n::substr($p_translated, i18n::strlen($d_plugins) );
\r
1682 // Remove the first "/" if exists.
\r
1683 $phppath = preg_replace('#^/#', '', $phppath);
\r
1684 // Remove the first "NP_" and the last ".php" if exists.
\r
1685 $path = preg_replace('#^NP_(.*)\.php$#', '$1', $phppath);
\r
1686 // Remove the "/" and beyond.
\r
1687 $path = preg_replace('#^([^/]*)/(.*)$#', '$1', $path);
\r
1689 // Solve the plugin name.
\r
1690 $plugins = array();
\r
1691 $query = 'SELECT pfile FROM '.sql_table('plugin');
\r
1692 $res = sql_query($query);
\r
1694 while($row = sql_fetch_row($res) )
\r
1696 $name = i18n::substr($row[0], 3);
\r
1697 $plugins[strtolower($name)] = $name;
\r
1700 sql_free_result($res);
\r
1702 if (array_key_exists($path, $plugins))
\r
1704 $plugin_name = $plugins[$path];
\r
1706 else if (in_array($path, $plugins))
\r
1708 $plugin_name = $path;
\r
1712 header("HTTP/1.0 404 Not Found");
\r
1716 /* Return if not index.php */
\r
1717 if ( ($phppath != strtolower($plugin_name) . '/') && ($phppath != strtolower($plugin_name) . '/index.php') )
\r
1722 /* Exit if not logged in. */
\r
1723 if ( !$member->isLoggedIn() )
\r
1725 exit('You aren\'t logged in.');
\r
1728 global $manager, $DIR_LIBS, $DIR_LOCALES, $HTTP_GET_VARS, $HTTP_POST_VARS;
\r
1730 /* Check if this feature is needed (ie, if "$manager->checkTicket()" is not included in the script). */
\r
1731 if (!($p_translated = serverVar('PATH_TRANSLATED') ) )
\r
1733 $p_translated = serverVar('SCRIPT_FILENAME');
\r
1736 if ($file = @file($p_translated) )
\r
1740 foreach($file as $line)
\r
1742 if (preg_match('/[\$]manager([\s]*)[\-]>([\s]*)checkTicket([\s]*)[\(]/i', $prevline . $line) )
\r
1747 $prevline = $line;
\r
1751 /* Show a form if not valid ticket */
\r
1752 if ( ( strstr(serverVar('REQUEST_URI'), '?') || serverVar('QUERY_STRING')
\r
1753 || strtoupper(serverVar('REQUEST_METHOD') ) == 'POST')
\r
1754 && (!$manager->checkTicket() ) )
\r
1756 $oPluginAdmin = new PluginAdmin($plugin_name);
\r
1757 $oPluginAdmin->start();
\r
1758 echo '<p>' . _ERROR_BADTICKET . "</p>\n";
\r
1760 /* Show the form to confirm action */
\r
1761 // PHP 4.0.x support
\r
1762 $get = (isset($_GET) ) ? $_GET : $HTTP_GET_VARS;
\r
1763 $post = (isset($_POST) ) ? $_POST : $HTTP_POST_VARS;
\r
1765 // Resolve URI and QUERY_STRING
\r
1766 if ($uri = serverVar('REQUEST_URI') )
\r
1768 list($uri, $qstring) = preg_split('#\?#', $uri);
\r
1772 if ( !($uri = serverVar('PHP_SELF') ) )
\r
1774 $uri = serverVar('SCRIPT_NAME');
\r
1776 $qstring = serverVar('QUERY_STRING');
\r
1780 $qstring = '?' . $qstring;
\r
1783 echo '<p>' . _SETTINGS_UPDATE . ' : ' . _QMENU_PLUGINS . ' <span style="color:red;">' . Entity::hsc($plugin_name) . "</span> ?</p>\n";
\r
1785 switch(strtoupper(serverVar('REQUEST_METHOD') ) )
\r
1788 echo '<form method="POST" action="'.Entity::hsc($uri.$qstring).'">';
\r
1789 $manager->addTicketHidden();
\r
1790 _addInputTags($post);
\r
1794 echo '<form method="GET" action="'.Entity::hsc($uri).'">';
\r
1795 $manager->addTicketHidden();
\r
1796 _addInputTags($get);
\r
1802 echo '<input type="submit" value="' . _YES . '" /> ';
\r
1803 echo '<input type="button" value="' . _NO . '" onclick="history.back(); return false;" />';
\r
1806 $oPluginAdmin->end();
\r
1810 /* Create new ticket */
\r
1811 $ticket=$manager->addTicketToUrl('');
\r
1812 $ticketforplugin['ticket'] = preg_split($ticket, i18n::strpos($ticket, 'ticket=') + 7);
\r
1816 function _addInputTags(&$keys,$prefix=''){
\r
1817 foreach($keys as $key=>$value){
\r
1818 if ($prefix) $key=$prefix.'['.$key.']';
\r
1819 if (is_array($value)) _addInputTags($value,$key);
\r
1821 if (get_magic_quotes_gpc()) $value=stripslashes($value);
\r
1822 if ($key=='ticket') continue;
\r
1823 echo '<input type="hidden" name="'.Entity::hsc($key).
\r
1824 '" value="'.Entity::hsc($value).'" />'."\n";
\r
1830 * serverStringToArray()
\r
1831 * Convert the server string such as $_SERVER['REQUEST_URI']
\r
1832 * to arry like arry['blogid']=1 and array['page']=2 etc.
\r
1834 * @param string $str string
\r
1835 * @param string $array
\r
1836 * @param string $frontParam
\r
1838 function serverStringToArray($str, &$array, &$frontParam)
\r
1844 // split front param, e.g. /index.php, and others, e.g. blogid=1&page=2
\r
1845 if ( i18n::strpos($str, "?") > 0 )
\r
1847 list($frontParam, $args) = preg_split("#\?#", $str, 2);
\r
1855 // If there is no args like blogid=1&page=2, return
\r
1856 if ( i18n::strpos($str, "=") == FALSE && !i18n::strlen($frontParam) )
\r
1858 $frontParam = $str;
\r
1862 $array = preg_split("#&#", $args);
\r
1867 * Convert array like array['blogid'] to server string
\r
1868 * such as $_SERVER['REQUEST_URI']
\r
1870 function arrayToServerString($array, $frontParam, &$str)
\r
1872 if (strstr($str, "?")) {
\r
1873 $str = $frontParam . "?";
\r
1875 $str = $frontParam;
\r
1877 if (count($array)) {
\r
1878 $str .= implode("&", $array);
\r
1884 * Sanitize array parameters.
\r
1885 * This function checks both key and value.
\r
1886 * - check key if it inclues " (double quote), remove from array
\r
1887 * - check value if it includes \ (escape sequece), remove remaining string
\r
1889 * @param array &$array
\r
1892 function sanitizeArray(&$array)
\r
1894 $excludeListForSanitization = array('query');
\r
1896 foreach ( $array as $k => $v )
\r
1898 // split to key and value
\r
1899 list($key, $val) = preg_split("#=#", $v, 2);
\r
1900 if ( !isset($val) )
\r
1905 // when magic quotes is on, need to use stripslashes,
\r
1906 // and then addslashes
\r
1907 if ( get_magic_quotes_gpc() )
\r
1909 $val = stripslashes($val);
\r
1911 // note that we must use addslashes here because this function is called before the db connection is made
\r
1912 // and sql_real_escape_string needs a db connection
\r
1913 $val = addslashes($val);
\r
1915 // if $key is included in exclude list, skip this param
\r
1916 if ( !in_array($key, $excludeListForSanitization) )
\r
1919 if ( i18n::strpos($val, '\\') )
\r
1921 list($val, $tmp) = preg_split('#\\\\#', $val);
\r
1924 // remove control code etc.
\r
1925 $val = strtr($val, "\0\r\n<>'\"", " ");
\r
1928 if ( preg_match('#\"#', $key) )
\r
1930 unset($array[$k]);
\r
1934 // set sanitized info
\r
1935 $array[$k] = sprintf("%s=%s", $key, $val);
\r
1942 * Convert array for sanitizeArray function
\r
1944 function convArrayForSanitizing($src, &$array)
\r
1947 foreach ($src as $key => $val) {
\r
1948 if (key_exists($key, $_GET)) {
\r
1949 array_push($array, sprintf("%s=%s", $key, $val));
\r
1955 * Revert array after sanitizeArray function
\r
1957 function revertArrayForSanitizing($array, &$dst)
\r
1959 foreach ($array as $v) {
\r
1960 list($key, $val) = preg_split("/=/", $v, 2);
\r
1961 $dst[$key] = $val;
\r
1966 * Stops processing the request and redirects to the given URL.
\r
1967 * - no actual contents should have been sent to the output yet
\r
1968 * - the URL will be stripped of illegal or dangerous characters
\r
1970 function redirect($url) {
\r
1971 $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);
\r
1972 header('Location: ' . $url);
\r
1977 * Returns the Javascript code for a bookmarklet that works on most modern browsers
\r
1980 function getBookmarklet($blogid) {
\r
1984 $document = 'document';
\r
1985 $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";
\r
1986 $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";
\r
1987 $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";
\r
1989 return $bookmarkletline;
\r
1991 // END: functions from the end of file ADMIN.php
\r
1994 * Returns a variable or null if not set
\r
1996 * @param mixed Variable
\r
1997 * @return mixed Variable
\r
1999 function ifset(&$var) {
\r
2000 if (isset($var)) {
\r
2008 * Returns number of subscriber to an event
\r
2011 * @return number of subscriber(s)
\r
2013 function numberOfEventSubscriber($event) {
\r
2014 $query = 'SELECT COUNT(*) as count FROM ' . sql_table('plugin_event') . ' WHERE event=\'' . $event . '\'';
\r
2015 $res = sql_query($query);
\r
2016 $obj = sql_fetch_object($res);
\r
2017 return $obj->count;
\r
2021 * sets $special global variable for use in index.php before selector()
\r
2023 * @param String id
\r
2026 function selectSpecialSkinType($id) {
\r
2028 $special = strtolower($id);
\r
2032 * cleans filename of uploaded file for writing to file system
\r
2034 * @param String str
\r
2035 * @return String cleaned filename ready for use
\r
2037 function cleanFileName($str) {
\r
2038 $str = strtolower($str);
\r
2039 $ext_point = i18n::strrpos($str,".");
\r
2040 if ($ext_point===false) return false;
\r
2041 $ext = i18n::substr($str,$ext_point,i18n::strlen($str));
\r
2042 $str = i18n::substr($str,0,$ext_point);
\r
2044 return preg_replace("/[^a-z0-9-]/","_",$str).$ext;
\r
2048 * Centralisation of the functions to send mail
\r
2049 * Deprecated since 4.0:
\r
2050 * Please use functions in NOTIFICATION class instead
\r
2052 function getMailFooter()
\r
2054 NOTIFICATION::get_mail_footer();
\r
2056 function isValidMailAddress($address)
\r
2058 return NOTIFICATION::address_validation($address);
\r
2061 * Centralisation of the functions that deals XML entities
\r
2062 * Deprecated since 4.0:
\r
2063 * Please use Entity::FunctionName(...) instead
\r
2065 function highlight($text, $expression, $highlight)
\r
2067 return Entity::highlight($text, $expression, $highlight);
\r
2069 function shorten($string, $maxlength, $suffix)
\r
2071 return Entity::shorten($string, $maxlength, $suffix);
\r
2073 function stringStripTags ($string)
\r
2075 return Entity::strip_tags($string);
\r
2077 function toAscii($string)
\r
2079 return Entity::anchor_footnoting($string);
\r
2081 function stringToAttribute ($string)
\r
2083 return Entity::hsc($string);
\r
2085 function stringToXML ($string)
\r
2087 return Entity::hen($string);
\r
2089 function encode_desc($data)
\r
2091 return Entity::hen($data);
\r
2094 * Centralisation of the functions that deals with locales
\r
2095 * This functions is based on the old way to deal with languages
\r
2096 * Deprecated since 4.0:
\r
2098 /* NOTE: use i18n::get_current_locale() directly instead of this */
\r
2099 function getLanguageName()
\r
2101 if( ($language = i18n::convert_locale_to_old_language_file_name(i18n::get_current_locale())) === FALSE )
\r
2103 $language ='english';
\r
2107 /* NOTE: this is completely deprecated because generating much warnings */
\r
2108 function selectLanguage($language)
\r
2111 include($DIR_LANG . preg_replace('#[\\\\|/]#', '', $language) . '.php');
\r
2115 /* NOTE: use i18n::get_available_locales() directly instead of this */
\r
2116 function checkLanguage($lang)
\r
2118 return ( preg_match('#^(.+)_(.+)_(.+)$#', $lang)
\r
2119 || i18n::convert_old_language_file_name_to_locale($lang) );
\r
2121 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2122 function formatDate($format, $timestamp, $default_format, &$blog)
\r
2124 $offset = date('Z', $timestamp);
\r
2127 $offset += $blog->getTimeOffset() * 3600;
\r
2129 return i18n::formatted_datetime($format, $timestamp, $offset, $default_format);
\r
2131 /* NOTE: use i18n::formatted_datetime() directly instead of this */
\r
2132 function mysqldate($timestamp)
\r
2134 return '"' . i18n::formatted_datetime('mysql', $timestamp) . '"';
\r
2137 * Centralisation of the functions that generate links
\r
2138 * Deprecated since 4.0:
\r
2139 * Please use Link::FunctionName(...) instead
\r
2141 function createItemLink($itemid, $extra = '')
\r
2143 return Link::create_item_link($itemid, $extra);
\r
2145 function createMemberLink($memberid, $extra = '')
\r
2147 return Link::create_member_link($memberid, $extra);
\r
2149 function createCategoryLink($catid, $extra = '')
\r
2151 return Link::create_category_link($catid, $extra);
\r
2153 function createArchiveListLink($blogid = '', $extra = '')
\r
2155 return Link::create_archivelist_link($blogid, $extra);
\r
2157 function createArchiveLink($blogid, $archive, $extra = '')
\r
2159 return Link::create_archive_link($blogid, $archive, $extra);
\r
2161 function createBlogidLink($blogid, $params = '')
\r
2163 return Link::create_blogid_link($blogid, $params = '');
\r
2165 function createLink($type, $params)
\r
2167 return Link::create_link($type, $params);
\r
2169 function createBlogLink($url, $params)
\r
2171 return Link::create_blog_link($url, $params);
\r