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