OSDN Git Service

ブックマークレットの不具合修正
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / globalfunctions.php
index 2ae695a..37f2114 100755 (executable)
@@ -2,7 +2,7 @@
 \r
 /*\r
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
- * Copyright (C) 2002-2007 The Nucleus Group\r
+ * Copyright (C) 2002-2009 The Nucleus Group\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
  */\r
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
- * @copyright Copyright (C) 2002-2007 The Nucleus Group\r
- * @version $Id: globalfunctions.php,v 1.24 2008-02-08 09:31:22 kimitake Exp $\r
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
+ * @version $Id$\r
  * $NucleusJP: globalfunctions.php,v 1.23.2.7 2008/02/05 08:30:08 kimitake Exp $\r
  */\r
 \r
 // needed if we include globalfunctions from install.php\r
 global $nucleus, $CONF, $DIR_LIBS, $DIR_LANG, $manager, $member;\r
 \r
-$nucleus['version'] = 'v3.4';\r
+$nucleus['version'] = 'v3.40RC';\r
 $nucleus['codename'] = '';\r
 \r
 checkVars(array('nucleus', 'CONF', 'DIR_LIBS', 'MYSQL_HOST', 'MYSQL_USER', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'DIR_LANG', '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
@@ -32,11 +32,6 @@ if ($CONF['debug']) {
        error_reporting(E_ERROR | E_WARNING | E_PARSE);\r
 }\r
 \r
-// Avoid notices\r
-if (!isset($CONF['Self'])) {\r
-       $CONF['Self'] = htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES);\r
-}\r
-\r
 /*\r
        Indicates when Nucleus should display startup errors. Set to 1 if you want\r
        the error enabled (default), false otherwise\r
@@ -51,15 +46,15 @@ if (!isset($CONF['Self'])) {
                more of the installation files (install.php, install.sql, upgrades/\r
                directory) are still on the server.\r
 */\r
-$CONF['alertOnHeadersSent'] = 1;\r
+$CONF['alertOnHeadersSent']  = 1;\r
 $CONF['alertOnSecurityRisk'] = 1;\r
-$CONF['ItemURL'] = $CONF['Self'];\r
-$CONF['ArchiveURL'] = $CONF['Self'];\r
-$CONF['ArchiveListURL'] = $CONF['Self'];\r
-$CONF['MemberURL'] = $CONF['Self'];\r
-$CONF['SearchURL'] = $CONF['Self'];\r
-$CONF['BlogURL'] = $CONF['Self'];\r
-$CONF['CategoryURL'] = $CONF['Self'];\r
+$CONF['ItemURL']             = $CONF['Self'];\r
+$CONF['ArchiveURL']          = $CONF['Self'];\r
+$CONF['ArchiveListURL']      = $CONF['Self'];\r
+$CONF['MemberURL']           = $CONF['Self'];\r
+$CONF['SearchURL']           = $CONF['Self'];\r
+$CONF['BlogURL']             = $CONF['Self'];\r
+$CONF['CategoryURL']         = $CONF['Self'];\r
 \r
 // switch URLMode back to normal when $CONF['Self'] ends in .php\r
 // this avoids urls like index.php/item/13/index.php/item/15\r
@@ -93,24 +88,24 @@ $orgRequestURI = serverVar('REQUEST_URI');
 sanitizeParams();\r
 \r
 // get all variables that can come from the request and put them in the global scope\r
-$blogid        = requestVar('blogid');\r
-$itemid        = intRequestVar('itemid');\r
-$catid = intRequestVar('catid');\r
-$skinid        = requestVar('skinid');\r
-$memberid = requestVar('memberid');\r
-$archivelist = requestVar('archivelist');\r
-$imagepopup = requestVar('imagepopup');\r
-$archive = requestVar('archive');\r
-$query = requestVar('query');\r
-$highlight = requestVar('highlight');\r
-$amount = requestVar('amount');\r
-$action = requestVar('action');\r
-$nextaction = requestVar('nextaction');\r
-$maxresults = requestVar('maxresults');\r
-$startpos = intRequestVar('startpos');\r
+$blogid       = requestVar('blogid');\r
+$itemid       = intRequestVar('itemid');\r
+$catid        = intRequestVar('catid');\r
+$skinid       = requestVar('skinid');\r
+$memberid     = requestVar('memberid');\r
+$archivelist  = requestVar('archivelist');\r
+$imagepopup   = requestVar('imagepopup');\r
+$archive      = requestVar('archive');\r
+$query        = requestVar('query');\r
+$highlight    = requestVar('highlight');\r
+$amount       = requestVar('amount');\r
+$action       = requestVar('action');\r
+$nextaction   = requestVar('nextaction');\r
+$maxresults   = requestVar('maxresults');\r
+$startpos     = intRequestVar('startpos');\r
 $errormessage = '';\r
-$error = '';\r
-$virtualpath = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
+$error        = '';\r
+$virtualpath  = ((getVar('virtualpath') != null) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
 \r
 if (!headers_sent() ) {\r
        header('Generator: Nucleus CMS ' . $nucleus['version']);\r
@@ -161,6 +156,23 @@ register_shutdown_function('sql_disconnect');
 // read config\r
 getConfig();\r
 \r
+// Properly set $CONF['Self'] and others if it's not set... usually when we are access from admin menu\r
+if (!isset($CONF['Self'])) {\r
+       $CONF['Self'] = $CONF['IndexURL'];\r
+       // strip trailing /\r
+       if ($CONF['Self'][strlen($CONF['Self']) -1] == "/") {\r
+               $CONF['Self'] = substr($CONF['Self'], 0, strlen($CONF['Self']) -1);\r
+       }\r
+\r
+       $CONF['ItemURL']        = $CONF['Self'];\r
+       $CONF['ArchiveURL']     = $CONF['Self'];\r
+       $CONF['ArchiveListURL'] = $CONF['Self'];\r
+       $CONF['MemberURL']      = $CONF['Self'];\r
+       $CONF['SearchURL']      = $CONF['Self'];\r
+       $CONF['BlogURL']        = $CONF['Self'];\r
+       $CONF['CategoryURL']    = $CONF['Self'];\r
+}\r
+\r
 // automatically use simpler toolbar for mozilla\r
 if (($CONF['DisableJsTools'] == 0) && strstr(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0') && strstr(serverVar('HTTP_USER_AGENT'), 'Gecko') ) {\r
        $CONF['DisableJsTools'] = 2;\r
@@ -308,7 +320,7 @@ $language = getLanguageName();
 include($DIR_LANG . ereg_replace( '[\\|/]', '', $language) . '.php');\r
 \r
 // check if valid charset\r
-if (!encoding_check(false,false,_CHARSET)) {\r
+if (!encoding_check(false, false, _CHARSET)) {\r
        foreach(array($_REQUEST, $_SERVER) as $input) {\r
                array_walk($input, 'encoding_check');\r
        }\r
@@ -338,27 +350,27 @@ if (!defined('_ARCHIVETYPE_MONTH') ) {
 // decode path_info\r
 if ($CONF['URLMode'] == 'pathinfo') {\r
        // initialize keywords if this hasn't been done before\r
-       if ($CONF['ItemKey'] == '') {\r
+       if (!isset($CONF['ItemKey']) || $CONF['ItemKey'] == '') {\r
                $CONF['ItemKey'] = 'item';\r
        }\r
 \r
-       if ($CONF['ArchiveKey'] == '') {\r
+       if (!isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '') {\r
                $CONF['ArchiveKey'] = 'archive';\r
        }\r
 \r
-       if ($CONF['ArchivesKey'] == '') {\r
+       if (!isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '') {\r
                $CONF['ArchivesKey'] = 'archives';\r
        }\r
 \r
-       if ($CONF['MemberKey'] == '') {\r
+       if (!isset($CONF['MemberKey']) || $CONF['MemberKey'] == '') {\r
                $CONF['MemberKey'] = 'member';\r
        }\r
 \r
-       if ($CONF['BlogKey'] == '') {\r
+       if (!isset($CONF['BlogKey']) || $CONF['BlogKey'] == '') {\r
                $CONF['BlogKey'] = 'blog';\r
        }\r
 \r
-       if ($CONF['CategoryKey'] == '') {\r
+       if (!isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '') {\r
                $CONF['CategoryKey'] = 'category';\r
        }\r
 \r
@@ -572,10 +584,10 @@ function sendContentType($contenttype, $pagetype = '', $charset = _CHARSET) {
  * Errors before the database connection has been made\r
  */\r
 function startUpError($msg, $title) {\r
-       if (!defined('_CHARSET')) define('_CHARSET','iso-8859-1');\r
+       if (!defined('_CHARSET')) define('_CHARSET', 'iso-8859-1');\r
        header('Content-Type: text/html; charset=' . _CHARSET);\r
        ?>\r
-       <html xmlns="http://www.w3.org/1999/xhtml">\r
+       <html <?php echo _HTML_XML_NAME_SPACE_AND_LANG_CODE; ?>>\r
                <head><meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET?>" />\r
                <title><?php echo htmlspecialchars($title)?></title></head>\r
                <body>\r
@@ -827,6 +839,8 @@ function selector() {
 \r
                if ($b->isValidCategory($catid) ) {\r
                        $catextra = ' and icat=' . $catid;\r
+               } else {\r
+                       $catextra = '';\r
                }\r
 \r
                // get previous itemid and title\r
@@ -929,11 +943,11 @@ function selector() {
                global $startpos;\r
                $type = 'search';\r
                $query = stripslashes($query);\r
-               if(preg_match("/^(\xA1{2}|\xe3\x80{2}|\x20)+$/",$query)){\r
+               if(preg_match("/^(\xA1{2}|\xe3\x80{2}|\x20)+$/", $query)){\r
                                        $type = 'index';\r
                }\r
                $order = (_CHARSET == 'EUC-JP') ? 'EUC-JP, UTF-8,' : 'UTF-8, EUC-JP,';\r
-               $query = mb_convert_encoding($query, _CHARSET, $order.' JIS, SJIS, ASCII');\r
+               $query = mb_convert_encoding($query, _CHARSET, $order . ' JIS, SJIS, ASCII');\r
                if (is_numeric($blogid)) {\r
                        $blogid = intVal($blogid);\r
                } else {\r
@@ -1085,7 +1099,7 @@ function shorten($text, $maxlength, $toadd) {
 //     $trans = get_html_translation_table(HTML_ENTITIES);\r
        $trans = get_html_translation_table(HTML_SPECIALCHARS); // for Japanese\r
        $trans = array_flip($trans);\r
-       $text = strtr($text, $trans);\r
+       $text  = strtr($text, $trans);\r
 \r
        // 2. the actual shortening\r
        if (strlen($text) > $maxlength)\r
@@ -1189,11 +1203,13 @@ function help($id) {
 }\r
 \r
 function helpHtml($id) {\r
-       return helplink($id) . '<img src="documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" /></a>';\r
+       global $CONF;\r
+       return helplink($id) . '<img src="' . $CONF['AdminURL'] . 'documentation/icon-help.gif" width="15" height="15" alt="' . _HELP_TT . '" /></a>';\r
 }\r
 \r
 function helplink($id) {\r
-       return '<a href="documentation/help.html#'. $id . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">';\r
+       global $CONF;\r
+       return '<a href="' . $CONF['AdminURL'] . 'documentation/help.html#'. $id . '" onclick="if (event &amp;&amp; event.preventDefault) event.preventDefault(); return help(this.href);">';\r
 }\r
 \r
 function getMailFooter() {\r
@@ -1922,7 +1938,7 @@ function revertArrayForSanitizing($array, &$dst)
  * - the URL will be stripped of illegal or dangerous characters\r
  */\r
 function redirect($url) {\r
-       $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $url);\r
+       $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%*]|i', '', $url);\r
        header('Location: ' . $url);\r
        exit;\r
 }\r
@@ -2024,10 +2040,10 @@ function encode_desc(&$data)
     {   //_$to_entities = get_html_translation_table(HTML_ENTITIES);\r
         $to_entities = get_html_translation_table(HTML_SPECIALCHARS);\r
         $from_entities = array_flip($to_entities);\r
-        $data = str_replace('<br />','\n',$data); //hack\r
+        $data = str_replace('<br />', '\n', $data); //hack\r
         $data = strtr($data,$from_entities);\r
         $data = strtr($data,$to_entities);\r
-        $data = str_replace('\n','<br />',$data); //hack\r
+        $data = str_replace('\n', '<br />', $data); //hack\r
         return $data;\r
     }\r
  \r
@@ -2043,7 +2059,7 @@ function getBookmarklet($blogid) {
        $document = 'document';\r
        $bookmarkletline = "javascript:Q='';x=".$document.";y=window;if(x.selection){Q=x.selection.createRange().text;}else if(y.getSelection){Q=y.getSelection();}else if(x.getSelection){Q=x.getSelection();}wingm=window.open('";\r
        $bookmarkletline .= $CONF['AdminURL'] . "bookmarklet.php?blogid=$blogid";\r
-       $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','scrollbars=yes,width=600,height=550,left=10,top=10,status=yes,resizable=yes');wingm.focus();";\r
+       $bookmarkletline .="&logtext='+escape(Q)+'&loglink='+escape(x.location.href)+'&loglinktitle='+escape(x.title),'nucleusbm','toolbar=no,scrollbars=no,width=600,height=550,left=10,top=10,status=no,resizable=yes');wingm.focus();";\r
 \r
        return $bookmarkletline;\r
 }\r
@@ -2076,4 +2092,4 @@ function numberOfEventSubscriber($event) {
        return $obj->count;\r
 }\r
 \r
-?>\r
+?>
\ No newline at end of file