OSDN Git Service

MERGE: リビジョン1672から1680にかけて行われた修正のうち、反映されてないものを追加。
[nucleus-jp/nucleus-next.git] / nucleus / libs / LINK.php
similarity index 91%
rename from nucleus/libs/Link.php
rename to nucleus/libs/LINK.php
index aefed84..2d1ba11 100644 (file)
-<?php \r
-/*\r
- * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
- * Copyright (C) 2002-2011 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
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- * (see nucleus/documentation/index.html#license for more info)\r
- */\r
-/**\r
- * This class is a collections of functions that produce links\r
- * \r
- * All functions in this clss should only be called statically,\r
- * for example: Link::create_item_link(...)\r
- * \r
- * @license http://nucleuscms.org/license.txt GNU General Public License\r
- * @copyright Copyright (C) 2002-2011 The Nucleus Group\r
- * @version $Id: $\r
- */\r
-class Link\r
-{\r
-\r
-       /**\r
-        * Link::create_item_link()\r
-        * Create a link to an item\r
-        * @static\r
-        * @param $itemid       item id\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_item_link($itemid, $extra = '') {\r
-               return self::create_link('item', array('itemid' => $itemid, 'extra' => $extra) );\r
-       }\r
-\r
-       /**\r
-        * Link::create_member_link()\r
-        * Create a link to a member\r
-        * \r
-        * @static\r
-        * @param $memberid     member id\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_member_link($memberid, $extra = '') {\r
-               return self::create_link('member', array('memberid' => $memberid, 'extra' => $extra) );\r
-       }\r
-       \r
-       /**\r
-        * Link::create_category_link()\r
-        * Create a link to a category\r
-        * \r
-        * @static\r
-        * @param $catid        category id\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_category_link($catid, $extra = '') {\r
-               return self::create_link('category', array('catid' => $catid, 'extra' => $extra) );\r
-       }\r
-\r
-       /**\r
-        * Link::cteate_archive_link()\r
-        * Create a link to an archive\r
-        * \r
-        * @static\r
-        * @param $blogid       blog id\r
-        * @param $archive      archive identifier\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_archive_link($blogid, $archive, $extra = '') {\r
-               return self::create_link('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) );\r
-       }\r
-\r
-       /**\r
-        * Link::create_archivelist_link()\r
-        * Create a link to an archive list\r
-        * \r
-        * @static\r
-        * @param $blogid       blog id\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_archivelist_link($blogid = '', $extra = '') {\r
-               return self::create_link('archivelist', array('blogid' => $blogid, 'extra' => $extra) );\r
-       }\r
-\r
-       /**\r
-        * Link::create_blogid_link()\r
-        * Create a link to a blog\r
-        * \r
-        * @static\r
-        * @param $blogid       blog id\r
-        * @param $extra        extra parameter\r
-        */\r
-       static public function create_blogid_link($blogid, $params = '') {\r
-               return self::create_link('blog', array('blogid' => $blogid, 'extra' => $params) );\r
-       }\r
-\r
-       /**\r
-        * Link::create_link()\r
-        * Create a link\r
-        * \r
-        * Universell function that creates link of different types (like item, blog ...)\r
-        * and with an array of parameters\r
-        * \r
-        * @static\r
-        * @param $type         type of the link\r
-        * @param $params       array with parameters\r
-        */\r
-       static public function create_link($type, $params) {\r
-               global $manager, $CONF;\r
-       \r
-               $generatedURL = '';\r
-               $usePathInfo = ($CONF['URLMode'] == 'pathinfo');\r
-       \r
-               // ask plugins first\r
-               $created = false;\r
-       \r
-               if ($usePathInfo)\r
-               {\r
-                       $manager->notify(\r
-                               'GenerateURL',\r
-                               array(\r
-                                       'type' => $type,\r
-                                       'params' => $params,\r
-                                       'completed' => &$created,\r
-                                       'url' => &$url\r
-                               )\r
-                       );\r
-               }\r
-       \r
-               // if a plugin created the URL, return it\r
-               if ($created)\r
-               {\r
-                       return $url;\r
-               }\r
-       \r
-               // default implementation\r
-               switch ($type) {\r
-                       case 'item':\r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid'];\r
-                               } else {\r
-                                       $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid'];\r
-                               }\r
-                               break;\r
-       \r
-                       case 'member':\r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid'];\r
-                               } else {\r
-                                       $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid'];\r
-                               }\r
-                               break;\r
-       \r
-                       case 'category':\r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid'];\r
-                               } else {\r
-                                       $url = $CONF['CategoryURL'] . '?catid=' . $params['catid'];\r
-                               }\r
-                               break;\r
-       \r
-                       case 'archivelist':\r
-                               if (!$params['blogid']) {\r
-                                       $params['blogid'] = $CONF['DefaultBlog'];\r
-                               }\r
-       \r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid'];\r
-                               } else {\r
-                                       $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid'];\r
-                               }\r
-                               break;\r
-       \r
-                       case 'archive':\r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive'];\r
-                               } else {\r
-                                       $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&amp;archive=' . $params['archive'];\r
-                               }\r
-                               break;\r
-       \r
-                       case 'blog':\r
-                               if ($usePathInfo) {\r
-                                       $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid'];\r
-                               } else {\r
-                                       $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid'];\r
-                               }\r
-                               break;\r
-               }\r
-       \r
-               return Link::add_link_params($url, (isset($params['extra'])? $params['extra'] : null));\r
-       }\r
-       \r
-       static private function add_link_params($link, $params)\r
-       {\r
-               global $CONF;\r
-       \r
-               if (is_array($params) ) {\r
-       \r
-                       if ($CONF['URLMode'] == 'pathinfo') {\r
-       \r
-                               foreach ($params as $param => $value) {\r
-                                       // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1\r
-                                       // but they should use the URL keys like this: category/4/blog/1\r
-                                       // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php\r
-                                       if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1) \r
-                                       {\r
-                                               $link .= '/' . $param . '/' . urlencode($value);\r
-                                       } else {\r
-                                               switch ($param) {\r
-                                                       case 'itemid':\r
-                                                               $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       case 'memberid':\r
-                                                               $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       case 'catid':\r
-                                                               $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       case 'archivelist':\r
-                                                               $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       case 'archive':\r
-                                                               $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       case 'blogid':\r
-                                                               $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value);\r
-                                                       break;\r
-                                                       default:\r
-                                                               $link .= '/' . $param . '/' . urlencode($value);\r
-                                                       break;\r
-                                               }\r
-                                       }\r
-                               }\r
-       \r
-                       } else {\r
-       \r
-                               foreach ($params as $param => $value) {\r
-                                       $link .= '&amp;' . $param . '=' . urlencode($value);\r
-                               }\r
-       \r
-                       }\r
-               }\r
-       \r
-               return $link;\r
-       }\r
-\r
-       /**\r
-        * Link::create_blog_link()\r
-        * Create an link to a blog\r
-        * \r
-        * This function considers the URLMode of the blog\r
-        * \r
-        * @static\r
-        * @param $url          url\r
-        * @param $params       parameters\r
-        */\r
-       static public function create_blog_link($url, $params) {\r
-               global $CONF;\r
-               if ($CONF['URLMode'] == 'normal') {\r
-                       if (i18n::strpos($url, '?') === FALSE && is_array($params)) {\r
-                               $fParam = reset($params);\r
-                               $fKey   = key($params);\r
-                               array_shift($params);\r
-                               $url .= '?' . $fKey . '=' . $fParam;\r
-                       }\r
-               } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') {\r
-                       $url = i18n::substr($url, 0, -1);\r
-               }\r
-               return addLinkParams($url, $params);\r
-       }\r
-\r
-}\r
+<?php 
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2011 The Nucleus Group
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
+/**
+ * This class is a collections of functions that produce links
+ * 
+ * All functions in this clss should only be called statically,
+ * for example: LINK::create_item_link(...)
+ * 
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2011 The Nucleus Group
+ * @version $Id: LINK.php 1674 2012-02-26 05:25:02Z sakamocchi $
+ */
+class LINK
+{
+
+       /**
+        * LINK::create_item_link()
+        * Create a link to an item
+        * @static
+        * @param $itemid       item id
+        * @param $extra        extra parameter
+        */
+       static public function create_item_link($itemid, $extra = '') {
+               return self::create_link('item', array('itemid' => $itemid, 'extra' => $extra) );
+       }
+
+       /**
+        * LINK::create_member_link()
+        * Create a link to a member
+        * 
+        * @static
+        * @param $memberid     member id
+        * @param $extra        extra parameter
+        */
+       static public function create_member_link($memberid, $extra = '') {
+               return self::create_link('member', array('memberid' => $memberid, 'extra' => $extra) );
+       }
+       
+       /**
+        * LINK::create_category_link()
+        * Create a link to a category
+        * 
+        * @static
+        * @param $catid        category id
+        * @param $extra        extra parameter
+        */
+       static public function create_category_link($catid, $extra = '') {
+               return self::create_link('category', array('catid' => $catid, 'extra' => $extra) );
+       }
+
+       /**
+        * LINK::cteate_archive_link()
+        * Create a link to an archive
+        * 
+        * @static
+        * @param $blogid       blog id
+        * @param $archive      archive identifier
+        * @param $extra        extra parameter
+        */
+       static public function create_archive_link($blogid, $archive, $extra = '') {
+               return self::create_link('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) );
+       }
+
+       /**
+        * LINK::create_archivelist_link()
+        * Create a link to an archive list
+        * 
+        * @static
+        * @param $blogid       blog id
+        * @param $extra        extra parameter
+        */
+       static public function create_archivelist_link($blogid = '', $extra = '') {
+               return self::create_link('archivelist', array('blogid' => $blogid, 'extra' => $extra) );
+       }
+
+       /**
+        * LINK::create_blogid_link()
+        * Create a link to a blog
+        * 
+        * @static
+        * @param $blogid       blog id
+        * @param $extra        extra parameter
+        */
+       static public function create_blogid_link($blogid, $params = '') {
+               return self::create_link('blog', array('blogid' => $blogid, 'extra' => $params) );
+       }
+
+       /**
+        * LINK::create_link()
+        * Create a link
+        * 
+        * Universell function that creates link of different types (like item, blog ...)
+        * and with an array of parameters
+        * 
+        * @static
+        * @param $type         type of the link
+        * @param $params       array with parameters
+        */
+       static public function create_link($type, $params) {
+               global $manager, $CONF;
+       
+               $generatedURL = '';
+               $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
+       
+               // ask plugins first
+               $created = false;
+       
+               if ($usePathInfo)
+               {
+                       $manager->notify(
+                               'GenerateURL',
+                               array(
+                                       'type' => $type,
+                                       'params' => $params,
+                                       'completed' => &$created,
+                                       'url' => &$url
+                               )
+                       );
+               }
+       
+               // if a plugin created the URL, return it
+               if ($created)
+               {
+                       return $url;
+               }
+       
+               // default implementation
+               switch ($type) {
+                       case 'item':
+                               if ($usePathInfo) {
+                                       $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid'];
+                               } else {
+                                       $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid'];
+                               }
+                               break;
+       
+                       case 'member':
+                               if ($usePathInfo) {
+                                       $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid'];
+                               } else {
+                                       $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid'];
+                               }
+                               break;
+       
+                       case 'category':
+                               if ($usePathInfo) {
+                                       $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid'];
+                               } else {
+                                       $url = $CONF['CategoryURL'] . '?catid=' . $params['catid'];
+                               }
+                               break;
+       
+                       case 'archivelist':
+                               if (!$params['blogid']) {
+                                       $params['blogid'] = $CONF['DefaultBlog'];
+                               }
+       
+                               if ($usePathInfo) {
+                                       $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid'];
+                               } else {
+                                       $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid'];
+                               }
+                               break;
+       
+                       case 'archive':
+                               if ($usePathInfo) {
+                                       $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive'];
+                               } else {
+                                       $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&amp;archive=' . $params['archive'];
+                               }
+                               break;
+       
+                       case 'blog':
+                               if ($usePathInfo) {
+                                       $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid'];
+                               } else {
+                                       $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid'];
+                               }
+                               break;
+               }
+       
+               return LINK::add_link_params($url, (isset($params['extra'])? $params['extra'] : null));
+       }
+       
+       static private function add_link_params($link, $params)
+       {
+               global $CONF;
+       
+               if (is_array($params) ) {
+       
+                       if ($CONF['URLMode'] == 'pathinfo') {
+       
+                               foreach ($params as $param => $value) {
+                                       // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1
+                                       // but they should use the URL keys like this: category/4/blog/1
+                                       // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php
+                                       if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1) 
+                                       {
+                                               $link .= '/' . $param . '/' . urlencode($value);
+                                       } else {
+                                               switch ($param) {
+                                                       case 'itemid':
+                                                               $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       case 'memberid':
+                                                               $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       case 'catid':
+                                                               $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       case 'archivelist':
+                                                               $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       case 'archive':
+                                                               $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       case 'blogid':
+                                                               $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value);
+                                                       break;
+                                                       default:
+                                                               $link .= '/' . $param . '/' . urlencode($value);
+                                                       break;
+                                               }
+                                       }
+                               }
+       
+                       } else {
+       
+                               foreach ($params as $param => $value) {
+                                       $link .= '&amp;' . $param . '=' . urlencode($value);
+                               }
+       
+                       }
+               }
+       
+               return $link;
+       }
+
+       /**
+        * LINK::create_blog_link()
+        * Create an link to a blog
+        * 
+        * This function considers the URLMode of the blog
+        * 
+        * @static
+        * @param $url          url
+        * @param $params       parameters
+        */
+       static public function create_blog_link($url, $params) {
+               global $CONF;
+               if ($CONF['URLMode'] == 'normal') {
+                       if (i18n::strpos($url, '?') === FALSE && is_array($params)) {
+                               $fParam = reset($params);
+                               $fKey   = key($params);
+                               array_shift($params);
+                               $url .= '?' . $fKey . '=' . $fParam;
+                       }
+               } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') {
+                       $url = i18n::substr($url, 0, -1);
+               }
+               return addLinkParams($url, $params);
+       }
+
+}