OSDN Git Service

Add: decode_path_info()を追加。globalfunctions.phpのコードを合わせて整理。
authorsakamocchi <o-takashi@sakamocchi.jp>
Fri, 18 May 2012 15:20:54 +0000 (00:20 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Fri, 18 May 2012 15:20:54 +0000 (00:20 +0900)
nucleus/libs/globalfunctions.php

index 389bd77..a367b4d 100644 (file)
 /**\r
  * @license http://nucleuscms.org/license.txt GNU General Public License\r
  * @copyright Copyright (C) 2002-2009 The Nucleus Group\r
- * @version $Id: globalfunctions.php 1825 2012-05-04 16:56:35Z sakamocchi $\r
+ * @version $Id: globalfunctions.php 1851 2012-05-17 14:22:56Z sakamocchi $
  */\r
 \r
 /* needed if we include globalfunctions from install.php */\r
-global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALES, $manager, $member;\r
+global $nucleus, $CONF, $DIR_LIBS, $DIR_LOCALES, $manager, $member, $MYSQL_HANDLER;
 \r
 $nucleus['version'] = 'v4.00 SVN';\r
 $nucleus['codename'] = '';\r
@@ -32,7 +32,12 @@ if ( version_compare(PHP_VERSION, '5.3.0', '<') )
 }\r
 \r
 /* check and die if someone is trying to override internal globals (when register_globals turn on) */\r
-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
+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
 if ( !isset($CONF) )\r
 {\r
@@ -163,7 +168,6 @@ if ( $CONF['UsingAdminArea'] )
 \r
 \r
 /* connect to database */\r
-global $MYSQL_HANDLER;\r
 if ( !isset($MYSQL_HANDLER) )\r
 {\r
        $MYSQL_HANDLER = array('mysql','');\r
@@ -253,7 +257,6 @@ $startpos   = intRequestVar('startpos');
 $errormessage = '';\r
 $error         = '';\r
 $special       = requestVar('special');\r
-$virtualpath = ((getVar('virtualpath') != NULL) ? getVar('virtualpath') : serverVar('PATH_INFO'));\r
 \r
 \r
 /* read config */\r
@@ -281,17 +284,6 @@ $CONF['SearchURL']         = $CONF['Self'];
 $CONF['BlogURL']               = $CONF['Self'];\r
 $CONF['CategoryURL']   = $CONF['Self'];\r
 \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
- */\r
-if ( !array_key_exists('URLMode', $CONF)\r
- || (($CONF['URLMode'] == 'pathinfo')\r
-  && (i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) == '.php')) )\r
-{\r
-       $CONF['URLMode'] = 'normal';\r
-}\r
-\r
 /* automatically use simpler toolbar for mozilla */\r
 if ( ($CONF['DisableJsTools'] == 0)\r
    && i18n::strpos(serverVar('HTTP_USER_AGENT'), 'Mozilla/5.0') !== FALSE\r
@@ -300,6 +292,7 @@ if ( ($CONF['DisableJsTools'] == 0)
        $CONF['DisableJsTools'] = 2;\r
 }\r
 \r
+/* login processing */
 $member = new Member();\r
 \r
 if ( $action == 'login' )\r
@@ -401,138 +394,26 @@ if ( !defined('_ARCHIVETYPE_MONTH') )
        define('_ARCHIVETYPE_YEAR', 'year');\r
 }\r
 \r
-/* decode path_info */\r
-if ( $CONF['URLMode'] == 'pathinfo' )\r
-{\r
-       /* initialize keywords if this hasn't been done before */\r
-       if ( !isset($CONF['ItemKey']) || $CONF['ItemKey'] == '' )\r
-       {\r
-               $CONF['ItemKey'] = 'item';\r
-       }\r
-       \r
-       if ( !isset($CONF['ArchiveKey']) || $CONF['ArchiveKey'] == '' )\r
-       {\r
-               $CONF['ArchiveKey'] = 'archive';\r
-       }\r
-       \r
-       if ( !isset($CONF['ArchivesKey']) || $CONF['ArchivesKey'] == '' )\r
-       {\r
-               $CONF['ArchivesKey'] = 'archives';\r
-       }\r
-       \r
-       if ( !isset($CONF['MemberKey']) || $CONF['MemberKey'] == '' )\r
-       {\r
-               $CONF['MemberKey'] = 'member';\r
-       }\r
-       \r
-       if ( !isset($CONF['BlogKey']) || $CONF['BlogKey'] == '' )\r
-       {\r
-               $CONF['BlogKey'] = 'blog';\r
-       }\r
-       \r
-       if ( !isset($CONF['CategoryKey']) || $CONF['CategoryKey'] == '' )\r
-       {\r
-               $CONF['CategoryKey'] = 'category';\r
-       }\r
-       \r
-       if ( !isset($CONF['SpecialskinKey']) || $CONF['SpecialskinKey'] == '' )\r
-       {\r
-               $CONF['SpecialskinKey'] = 'special';\r
-       }\r
-       \r
-       $parsed = false;\r
-       $manager->notify(\r
-               'ParseURL',\r
-               array(\r
-                       /* e.g. item, blog, ... */\r
-                       'type' => basename(serverVar('SCRIPT_NAME') ),\r
-                       'info' => $virtualpath,\r
-                       'complete' => &$parsed\r
-               )\r
-       );\r
-       \r
-       if ( !$parsed )\r
-       {\r
-               /* default implementation */\r
-               $data = preg_split("#/#", $virtualpath );\r
-               for ( $i = 0; $i < sizeof($data); $i++ )\r
-               {\r
-                       switch ( $data[$i] )\r
-                       {\r
-                               /* item/1 (blogid) */\r
-                               case $CONF['ItemKey']:\r
-                                       $i++;\r
-                                       \r
-                                       if ( $i < sizeof($data) )\r
+/* for path resolving */
+$virtualpath = getVar('virtualpath');
+if ( getVar('virtualpath') == '' )
                                        {\r
-                                               $itemid = intval($data[$i]);\r
+       $virtualpath = serverVar('PATH_INFO');
                                        }\r
-                                       break;\r
                                \r
-                               /* archives/1 (blogid) */\r
-                               case $CONF['ArchivesKey']:\r
-                                               $i++;\r
-                                               if ( $i < sizeof($data) )\r
-                                               {\r
-                                                       $archivelist = intval($data[$i]);\r
-                                               }\r
-                                               break;\r
-                                       \r
-                               /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */\r
-                               case $CONF['ArchiveKey']:\r
-                                       if ( (($i + 1) < sizeof($data) ) && (i18n::strpos($data[$i + 1], '-') === FALSE ) )\r
-                                       {\r
-                                               $blogid = (integer) $data[++$i];\r
-                                       }\r
-                                       $i++;\r
-                                       if ( $i < sizeof($data) )\r
+/*
+ * switch URLMode back to normal when $CONF['Self'] ends in .php
+ * this avoids urls like index.php/item/13/index.php/item/15
+ */
+if ( !array_key_exists('URLMode', $CONF) || ($CONF['URLMode'] != 'pathinfo') )
                                        {\r
-                                               $archive = $data[$i];\r
+       $CONF['URLMode'] = 'normal';
                                        }\r
-                                       break;\r
-                                       \r
-                               /* blogid/1 */\r
-                               case 'blogid':\r
-                               /* blog/1 */\r
-                               case $CONF['BlogKey']:\r
-                                       $i++;\r
-                                       if ( $i < sizeof($data) )\r
+else
                                        {\r
-                                               $blogid = intval($data[$i]);\r
-                                       }\r
-                                       break;\r
-                               \r
-                               /* category/1 (catid) */\r
-                               case $CONF['CategoryKey']:\r
-                               case 'catid':\r
-                                       $i++;\r
-                                       if ( $i < sizeof($data) )\r
+       if ( i18n::substr($CONF['Self'], i18n::strlen($CONF['Self']) - 4) != '.php' )
                                        {\r
-                                               $catid = intval($data[$i]);\r
-                                       }\r
-                                       break;\r
-                               \r
-                               case $CONF['MemberKey']:\r
-                                       $i++;\r
-                                       if ( $i < sizeof($data) )\r
-                                       {\r
-                                               $memberid = intval($data[$i]);\r
-                                       }\r
-                                       break;\r
-                               \r
-                               case $CONF['SpecialskinKey']:\r
-                                       $i++;\r
-                                       if ( $i < sizeof($data) )\r
-                                       {\r
-                                               $special = $data[$i];\r
-                                               $_REQUEST['special'] = $special;\r
-                                       }\r
-                                       break;\r
-                               \r
-                               default:\r
-                                       // skip...\r
-                       }\r
-               }\r
+               decode_path_info($virtualpath);
        }\r
 }\r
 \r
@@ -1358,7 +1239,6 @@ function selector()
                $skinid = $blog->getDefaultSkin();\r
        }\r
        \r
-       //$special = requestVar('special'); //get at top of file as global\r
        if ( !empty($special) && isValidShortName($special) )\r
        {\r
                $type = strtolower($special);\r
@@ -1418,10 +1298,9 @@ function doError($msg, $skin = '')
                $skin = new Skin($id);\r
        }\r
        \r
-       $skinid = $skin->getID();\r
        $errormessage = $msg;\r
        $skin->parse('error');\r
-       exit;\r
+       return;
 }\r
 \r
 /**\r
@@ -1922,6 +1801,150 @@ function revertArrayForSanitizing($array, &$dst)
 }\r
 \r
 /**\r
+ * decode_path_info()
+ * 
+ * @param      string  $virtualpath
+ * @return     void
+ */
+function decode_path_info($virtualpath)
+{
+       global $CONF, $manager, $archive, $blog, $catid, $memberid, $special;
+       
+       /* initialize keywords if this hasn't been done before */
+       if ( !isset($CONF['ItemKey']) || empty($CONF['ItemKey']) )
+       {
+               $CONF['ItemKey'] = 'item';
+       }
+       
+       if ( !isset($CONF['ArchiveKey']) || empty($CONF['ArchiveKey']) )
+       {
+               $CONF['ArchiveKey'] = 'archive';
+       }
+       
+       if ( !isset($CONF['ArchivesKey']) || empty($CONF['ArchivesKey']) )
+       {
+               $CONF['ArchivesKey'] = 'archives';
+       }
+       
+       if ( !isset($CONF['MemberKey']) || empty($CONF['MemberKey']) )
+       {
+               $CONF['MemberKey'] = 'member';
+       }
+       
+       if ( !isset($CONF['BlogKey']) || empty($CONF['BlogKey']) )
+       {
+               $CONF['BlogKey'] = 'blog';
+       }
+       
+       if ( !isset($CONF['CategoryKey']) || empty($CONF['CategoryKey']) )
+       {
+               $CONF['CategoryKey'] = 'category';
+       }
+       
+       if ( !isset($CONF['SpecialskinKey']) || empty($CONF['SpecialskinKey']) )
+       {
+               $CONF['SpecialskinKey'] = 'special';
+       }
+       
+       $parsed = FALSE;
+       $data = array(
+               'type'          =>  basename(serverVar('SCRIPT_NAME') ),
+               'info'          =>  $virtualpath,
+               'complete'      => &$parsed
+       );
+       $manager->notify('ParseURL', $data);
+       
+       /* already parsed by the other subsystem */
+       if ( $parsed )
+       {
+               return;
+       }
+       /* default implementation */
+       $data = preg_split("#/#", $virtualpath);
+       for ( $i = 0; $i < sizeof($data); $i++ )
+       {
+               switch ( $data[$i] )
+               {
+                       /* item/1 (blogid) */
+                       case $CONF['ItemKey']:
+                               $i++;
+                               
+                               if ( $i < sizeof($data) )
+                               {
+                                       $itemid = (integer) $data[$i];
+                               }
+                               break;
+                       
+                       /* archives/1 (blogid) */
+                       case $CONF['ArchivesKey']:
+                                       $i++;
+                                       if ( $i < sizeof($data) )
+                                       {
+                                               $archivelist = (integer) $data[$i];
+                                       }
+                                       break;
+                               
+                       /* two possibilities: archive/yyyy-mm or archive/1/yyyy-mm (with blogid) */
+                       case $CONF['ArchiveKey']:
+                               if ( (($i + 1) < sizeof($data) ) && (i18n::strpos($data[$i + 1], '-') === FALSE ) )
+                               {
+                                       $blogid = (integer) $data[++$i];
+                               }
+                               $i++;
+                               if ( $i < sizeof($data) )
+                               {
+                                       $archive = $data[$i];
+                               }
+                               break;
+                               
+                       /* blogid/1 */
+                       case 'blogid':
+                       /* blog/1 */
+                       case $CONF['BlogKey']:
+                               $i++;
+                               if ( $i < sizeof($data) )
+                               {
+                                       $blogid = intval($data[$i]);
+                               }
+                               break;
+                       
+                       /* category/1 (catid) */
+                       case $CONF['CategoryKey']:
+                       case 'catid':
+                               $i++;
+                               if ( $i < sizeof($data) )
+                               {
+                                       $catid = intval($data[$i]);
+                               }
+                               break;
+                       
+                       case $CONF['MemberKey']:
+                               $i++;
+                               if ( $i < sizeof($data) )
+                               {
+                                       $memberid = intval($data[$i]);
+                               }
+                               break;
+                       
+                       case $CONF['SpecialskinKey']:
+                               $i++;
+                               if ( $i < sizeof($data) )
+                               {
+                                       $special = $data[$i];
+                               }
+                               break;
+                       
+                       default:
+                               /* do nothing */
+                               break;
+               }
+       }
+       
+       return;
+}
+
+
+/**
  * redirect()\r
  * Stops processing the request and redirects to the given URL.\r
  * - no actual contents should have been sent to the output yet\r