3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2011 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * This class is a collections of functions that produce links
\r
15 * All functions in this clss should only be called statically,
\r
16 * for example: LINK::create_item_link(...)
\r
18 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
19 * @copyright Copyright (C) 2002-2011 The Nucleus Group
\r
20 * @version $Id: LINK.php 1674 2012-02-26 05:25:02Z sakamocchi $
\r
26 * LINK::create_item_link()
\r
27 * Create a link to an item
\r
29 * @param $itemid item id
\r
30 * @param $extra extra parameter
\r
32 static public function create_item_link($itemid, $extra = '') {
\r
33 return self::create_link('item', array('itemid' => $itemid, 'extra' => $extra) );
\r
37 * LINK::create_member_link()
\r
38 * Create a link to a member
\r
41 * @param $memberid member id
\r
42 * @param $extra extra parameter
\r
44 static public function create_member_link($memberid, $extra = '') {
\r
45 return self::create_link('member', array('memberid' => $memberid, 'extra' => $extra) );
\r
49 * LINK::create_category_link()
\r
50 * Create a link to a category
\r
53 * @param $catid category id
\r
54 * @param $extra extra parameter
\r
56 static public function create_category_link($catid, $extra = '') {
\r
57 return self::create_link('category', array('catid' => $catid, 'extra' => $extra) );
\r
61 * LINK::cteate_archive_link()
\r
62 * Create a link to an archive
\r
65 * @param $blogid blog id
\r
66 * @param $archive archive identifier
\r
67 * @param $extra extra parameter
\r
69 static public function create_archive_link($blogid, $archive, $extra = '') {
\r
70 return self::create_link('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) );
\r
74 * LINK::create_archivelist_link()
\r
75 * Create a link to an archive list
\r
78 * @param $blogid blog id
\r
79 * @param $extra extra parameter
\r
81 static public function create_archivelist_link($blogid = '', $extra = '') {
\r
82 return self::create_link('archivelist', array('blogid' => $blogid, 'extra' => $extra) );
\r
86 * LINK::create_blogid_link()
\r
87 * Create a link to a blog
\r
90 * @param $blogid blog id
\r
91 * @param $extra extra parameter
\r
93 static public function create_blogid_link($blogid, $params = '') {
\r
94 return self::create_link('blog', array('blogid' => $blogid, 'extra' => $params) );
\r
98 * LINK::create_link()
\r
101 * Universell function that creates link of different types (like item, blog ...)
\r
102 * and with an array of parameters
\r
105 * @param $type type of the link
\r
106 * @param $params array with parameters
\r
108 static public function create_link($type, $params) {
\r
109 global $manager, $CONF;
\r
111 $generatedURL = '';
\r
112 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
\r
114 // ask plugins first
\r
123 'params' => $params,
\r
124 'completed' => &$created,
\r
130 // if a plugin created the URL, return it
\r
136 // default implementation
\r
139 if ($usePathInfo) {
\r
140 $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid'];
\r
142 $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid'];
\r
147 if ($usePathInfo) {
\r
148 $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid'];
\r
150 $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid'];
\r
155 if ($usePathInfo) {
\r
156 $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid'];
\r
158 $url = $CONF['CategoryURL'] . '?catid=' . $params['catid'];
\r
162 case 'archivelist':
\r
163 if (!$params['blogid']) {
\r
164 $params['blogid'] = $CONF['DefaultBlog'];
\r
167 if ($usePathInfo) {
\r
168 $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid'];
\r
170 $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid'];
\r
175 if ($usePathInfo) {
\r
176 $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive'];
\r
178 $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&archive=' . $params['archive'];
\r
183 if ($usePathInfo) {
\r
184 $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid'];
\r
186 $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid'];
\r
191 return LINK::add_link_params($url, (isset($params['extra'])? $params['extra'] : null));
\r
194 static private function add_link_params($link, $params)
\r
198 if (is_array($params) ) {
\r
200 if ($CONF['URLMode'] == 'pathinfo') {
\r
202 foreach ($params as $param => $value) {
\r
203 // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1
\r
204 // but they should use the URL keys like this: category/4/blog/1
\r
205 // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php
\r
206 if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1)
\r
208 $link .= '/' . $param . '/' . urlencode($value);
\r
212 $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value);
\r
215 $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value);
\r
218 $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value);
\r
220 case 'archivelist':
\r
221 $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value);
\r
224 $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value);
\r
227 $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value);
\r
230 $link .= '/' . $param . '/' . urlencode($value);
\r
238 foreach ($params as $param => $value) {
\r
239 $link .= '&' . $param . '=' . urlencode($value);
\r
249 * LINK::create_blog_link()
\r
250 * Create an link to a blog
\r
252 * This function considers the URLMode of the blog
\r
256 * @param $params parameters
\r
258 static public function create_blog_link($url, $params) {
\r
260 if ($CONF['URLMode'] == 'normal') {
\r
261 if (i18n::strpos($url, '?') === FALSE && is_array($params)) {
\r
262 $fParam = reset($params);
\r
263 $fKey = key($params);
\r
264 array_shift($params);
\r
265 $url .= '?' . $fKey . '=' . $fParam;
\r
267 } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') {
\r
268 $url = i18n::substr($url, 0, -1);
\r
270 return addLinkParams($url, $params);
\r