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::createItemLink(...)
\r
18 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
19 * @copyright Copyright (C) 2002-2011 The Nucleus Group
\r
25 * Create a link to an item
\r
26 * @param $itemid item id
\r
27 * @param $extra extra parameter
\r
29 function createItemLink($itemid, $extra = '') {
\r
30 return Link::createLink('item', array('itemid' => $itemid, 'extra' => $extra) );
\r
34 * Create a link to a member
\r
36 * @param $memberid member id
\r
37 * @param $extra extra parameter
\r
39 function createMemberLink($memberid, $extra = '') {
\r
40 return Link::createLink('member', array('memberid' => $memberid, 'extra' => $extra) );
\r
44 * Create a link to a category
\r
46 * @param $catid category id
\r
47 * @param $extra extra parameter
\r
49 function createCategoryLink($catid, $extra = '') {
\r
50 return Link::createLink('category', array('catid' => $catid, 'extra' => $extra) );
\r
54 * Create a link to an archive
\r
56 * @param $blogid blog id
\r
57 * @param $archive archive identifier
\r
58 * @param $extra extra parameter
\r
60 function createArchiveLink($blogid, $archive, $extra = '') {
\r
61 return Link::createLink('archive', array('blogid' => $blogid, 'archive' => $archive, 'extra' => $extra) );
\r
65 * Create a link to an archive list
\r
67 * @param $blogid blog id
\r
68 * @param $extra extra parameter
\r
70 function createArchiveListLink($blogid = '', $extra = '') {
\r
71 return Link::createLink('archivelist', array('blogid' => $blogid, 'extra' => $extra) );
\r
75 * Create a link to a blog
\r
77 * @param $blogid blog id
\r
78 * @param $extra extra parameter
\r
80 function createBlogidLink($blogid, $params = '') {
\r
81 return Link::createLink('blog', array('blogid' => $blogid, 'extra' => $params) );
\r
87 * Universell function that creates link of different types (like item, blog ...)
\r
88 * and with an array of parameters
\r
90 * @param $type type of the link
\r
91 * @param $params array with parameters
\r
93 function createLink($type, $params) {
\r
94 global $manager, $CONF;
\r
97 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
\r
99 // ask plugins first
\r
102 if ($usePathInfo) {
\r
107 'params' => $params,
\r
108 'completed' => &$created,
\r
114 // if a plugin created the URL, return it
\r
119 // default implementation
\r
122 if ($usePathInfo) {
\r
123 $url = $CONF['ItemURL'] . '/' . $CONF['ItemKey'] . '/' . $params['itemid'];
\r
125 $url = $CONF['ItemURL'] . '?itemid=' . $params['itemid'];
\r
130 if ($usePathInfo) {
\r
131 $url = $CONF['MemberURL'] . '/' . $CONF['MemberKey'] . '/' . $params['memberid'];
\r
133 $url = $CONF['MemberURL'] . '?memberid=' . $params['memberid'];
\r
138 if ($usePathInfo) {
\r
139 $url = $CONF['CategoryURL'] . '/' . $CONF['CategoryKey'] . '/' . $params['catid'];
\r
141 $url = $CONF['CategoryURL'] . '?catid=' . $params['catid'];
\r
145 case 'archivelist':
\r
146 if (!$params['blogid']) {
\r
147 $params['blogid'] = $CONF['DefaultBlog'];
\r
150 if ($usePathInfo) {
\r
151 $url = $CONF['ArchiveListURL'] . '/' . $CONF['ArchivesKey'] . '/' . $params['blogid'];
\r
153 $url = $CONF['ArchiveListURL'] . '?archivelist=' . $params['blogid'];
\r
158 if ($usePathInfo) {
\r
159 $url = $CONF['ArchiveURL'] . '/' . $CONF['ArchiveKey'] . '/'.$params['blogid'].'/' . $params['archive'];
\r
161 $url = $CONF['ArchiveURL'] . '?blogid='.$params['blogid'].'&archive=' . $params['archive'];
\r
166 if ($usePathInfo) {
\r
167 $url = $CONF['BlogURL'] . '/' . $CONF['BlogKey'] . '/' . $params['blogid'];
\r
169 $url = $CONF['BlogURL'] . '?blogid=' . $params['blogid'];
\r
174 return Link::addLinkParams($url, (isset($params['extra'])? $params['extra'] : null));
\r
177 function addLinkParams($link, $params) {
\r
180 if (is_array($params) ) {
\r
182 if ($CONF['URLMode'] == 'pathinfo') {
\r
184 foreach ($params as $param => $value) {
\r
185 // change in 3.63 to fix problem where URL generated with extra params mike look like category/4/blogid/1
\r
186 // but they should use the URL keys like this: category/4/blog/1
\r
187 // if user wants old urls back, set $CONF['NoURLKeysInExtraParams'] = 1; in config.php
\r
188 if (isset($CONF['NoURLKeysInExtraParams']) && $CONF['NoURLKeysInExtraParams'] == 1)
\r
190 $link .= '/' . $param . '/' . urlencode($value);
\r
194 $link .= '/' . $CONF['ItemKey'] . '/' . urlencode($value);
\r
197 $link .= '/' . $CONF['MemberKey'] . '/' . urlencode($value);
\r
200 $link .= '/' . $CONF['CategoryKey'] . '/' . urlencode($value);
\r
202 case 'archivelist':
\r
203 $link .= '/' . $CONF['ArchivesKey'] . '/' . urlencode($value);
\r
206 $link .= '/' . $CONF['ArchiveKey'] . '/' . urlencode($value);
\r
209 $link .= '/' . $CONF['BlogKey'] . '/' . urlencode($value);
\r
212 $link .= '/' . $param . '/' . urlencode($value);
\r
220 foreach ($params as $param => $value) {
\r
221 $link .= '&' . $param . '=' . urlencode($value);
\r
231 * Create an link to a blog
\r
233 * This function considers the URLMode of the blog
\r
236 * @param $params parameters
\r
238 function createBlogLink($url, $params) {
\r
240 if ($CONF['URLMode'] == 'normal') {
\r
241 if (i18n::strpos($url, '?') === FALSE && is_array($params)) {
\r
242 $fParam = reset($params);
\r
243 $fKey = key($params);
\r
244 array_shift($params);
\r
245 $url .= '?' . $fKey . '=' . $fParam;
\r
247 } elseif ($CONF['URLMode'] == 'pathinfo' && i18n::substr($url, -1) == '/') {
\r
248 $url = i18n::substr($url, 0, -1);
\r
250 return addLinkParams($url, $params);
\r