<?php
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#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.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function smarty_cms_function_cms_selflink($params, &$smarty) {
global $gCms;
$rellink = (isset($params['rellink']) && $params['rellink'] == '1' ? true : false);
$url = '';
/* ugly hack by tsw for external links with wiki styling */
if ( isset($params['ext']) )
{
/* thanks elijah */
$url = $params['ext'];
$text = $params['ext'];
/* thanks elijah */
$url = $params['ext'];
$text = $params['ext'];
if ( isset($params['text'] ))
{
$text = $params['text'];
}
$title= '';
if ( isset($params['title']) )
{
$title=' title="'.$params['title'].'" ';
}
$target = '';
if ( isset($params['target']) && ( strlen($params['target'] > 0 ) ) )
{
$target=' target="'.$params['taget'].'" ';
}
$external_text = '(external link)';
if ( isset($params['ext_info']) )
{
$external_text ='( '.$ext_info.' )';
}
return '<a class="external" href="'.$url.'" '.$title.''.$target.'>'.$text.'<span>'.$external_text.'</span></a>';
}
$urlparams = '';
if ( isset($params['urlparams']) && ( strlen($params['urlparams'] > 0 ) ) )
{
$urlparams =$params['urlparams'];
}
/* LeisureLarry - Changed if statement */
if (isset($params['page']) or isset($params['href']))
{
$page = $params['page'];
$name = $params['page']; //mbv - 21-06-2005
/* LeisureLarry - Begin */
if (isset($params['href']))
{
$page = $params['href'];
}
/* LeisureLarry - End */
# check if the page exists in the db
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($page);
if (!isset($node)) return;
$content =& $node->GetContent();
if ($content !== FALSE)
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name(); //mbv - 21-06-2005
$url = $content->GetUrl();
$menu_text = $content->MenuText();
$titleattr = $content->TitleAttribute();
}
/* Mod by Nemesis */
if (isset($params['anchorlink']))
{
$url .= '#' . ltrim($params['anchorlink'], '#');
}
if (isset($params['urlparam']))
{
$url .= trim($params['urlparam']);
}
/* End mod Nemesis */
$Prev_label = "";
$Next_label = "";
$Anchor_label = ""; //*Russ
$Parent_label = "Parent page: "; //uplink
}
elseif (isset($params['dir'])) // this part is by mbv built on a proposal by 100rk
{
/* Russ - Begin */
if (isset($params['anchorlink']))
{
$anchorlink = ltrim($params['anchorlink'], '#');
//Param to set anchor link
}
/* Russ - End */
if (isset($params['lang']))
{
switch (strtolower($params['lang']))
{
case 'dk':
case 'da':
$Prev_label = "Forrige side: ";
$Next_label = "Næste side: ";
break;
case 'nl':
$Prev_label = "Vorige pagina: ";
$Next_label = "Volgende pagina: ";
$Parent_label = "Bovenliggende pagina: "; // uplink
break;
case 'en':
$Prev_label = "Previous page: ";
$Next_label = "Next page: ";
$Parent_label = "Parent page: "; //uplink
break;
case 'fr':
$Prev_label = "Page précédente : ";
$Next_label = "Page suivante : ";
$Parent_label = "Page ascendante : "; //uplink
break;
case 'no':
$Prev_label = "Forrige side : ";
$Next_label = "Neste side: ";
$Parent_label = "Side opp: "; //uplink
break;
case '0':
$Prev_label = "";
$Next_label = "";
break;
default:
$Prev_label = "Previous page: ";
$Next_label = "Next page: ";
$Parent_label = "Parent page: "; //uplink
break;
}
}
else
{
$Prev_label = "Previous page: ";
$Next_label = "Next page: ";
$Parent_label = "Parent page: "; //uplink
}
$condition = $order_by = false;
switch (strtolower($params['dir']))
{
case 'next':
$condition = '>';
$order_by = 'hierarchy';
$label=$Next_label;
break;
case 'prev':
case 'previous':
$condition = '<';
$order_by = 'hierarchy DESC';
$label=$Prev_label;
break;
case 'anchor': //* Start Russ addition
$condition = '^';
$order_by = 'something';
$label=''; //No label needed
break;//* End Russ addition
case 'start':
$condition = '-';
$order_by = 'something';
$label = '';
break;
case 'up': //* Start uplink
$condition = '|';
$order_by = '-';
$label='';
break; //* End uplink
}
if ($condition && $order_by)
{
global $gCms;
$hm =& $gCms->GetHierarchyManager();
$flatcontent = array();
if ($condition != '|') // uplink (we don't need the flatcontent for an uplink)
{
#return '';
$flatcontent =& $hm->getFlatList();
$number = 0;
for ($i = 0; $i < count($flatcontent); $i++)
{
if ($condition == '-')
{
global $gCms;
$contentops =& $gCms->GetContentOperations();
$defaultid = $contentops->GetDefaultPageID();
if ($flatcontent[$i]->getTag() == $defaultid)
{
$number = $i;
break;
}
}
else if ($flatcontent[$i]->getTag() == $gCms->variables['content_id'])
{
$number = $i;
break;
}
}
} //* uplink addition
if ($condition == '<')
{
if ($number > 0)
{
for ($i = $number - 1; $i >= 0; $i--)
{
$content =& $flatcontent[$i]->getContent();
if (isset($content) && $content != NULL)
{
if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$menu_text = $content->MenuText();
$url = $content->GetURL();
$titleattr = $content->TitleAttribute();
break;
}
}
else
{
break;
}
}
}
}
else if ($condition == '>')
{
if ($number < count($flatcontent))
{
for ($i = $number + 1; $i < count($flatcontent); $i++)
{
$content =& $flatcontent[$i]->getContent();
if(isset($content) && $content != NULL)
{
if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$menu_text = $content->MenuText();
$url = $content->GetURL();
$titleattr = $content->TitleAttribute();
break;
}
}
else
{
break;
}
}
}
}
else if ($condition == '^') //* Start Russ addition
{
if ($number < count($flatcontent))
{
for ($i = $number; $i < count($flatcontent); $i++)
{
$content =& $flatcontent[$i]->getContent();
if (isset($content))
{
if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$menu_text = $content->MenuText();
$url = $content->GetURL().'#'.$anchorlink; //set as Param
$titleattr = $content->TitleAttribute();
break;
}
}
else
{
break;
}
}
}
} //* End Russ addition
else if ($condition == '|') //* Start uplink
{
$node =& $hm->getNodeById($gCms->variables['content_id']);
$node =& $node->getParentNode();
// print_r($node);
if (!isset($node)) return;
$content =& $node->GetContent();
if ($content != FALSE)
{
if ($content->Active() && $content->HasUsableLink())
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$menu_text = $content->MenuText();
$url = $content->GetURL();
$titleattr = $content->TitleAttribute();
}
}
} //* End uplink
else if ($condition == '-')
{
$content =& $flatcontent[$number]->getContent();
if (isset($content))
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name();
$menu_text = $content->MenuText();
$url = $content->GetURL();
$titleattr = $content->TitleAttribute();
}
}
}
unset($condition);
unset($order_by);
} // end of next-prev code
if (isset($params['label']))
{
$label = $params['label'];
}
else
{
if (!isset($label))
{
$label = '';
}
}
$result = "";
/* LeisureLarry - Changes if statement */
if (($url != "") and !isset($params['href']))
{
if ($rellink && isset($params['dir']))
{
$result .= '<link rel="';
if ($params['dir'] == 'prev' || $params['dir'] == 'previous')
{
$result .= 'prev';
}
else if ($params['dir'] == 'start')
{
$result .= 'start';
}
else if ($params['dir'] == 'anchor')//* Start Russ addition
{
$result .= 'anchor';
}//* End Russ addition
else if ($params['dir'] == 'next')
{
$result .= 'next';
}
else if ($params['dir'] == 'up')//* Start uplink
{
$result .= 'up';
}//* End uplink
$result .= '" title="' . (isset($params['title']) ? $params['title'] : ($titleattr != '' ? $titleattr : $name));
$result .= '" href="' . $url . '" />';
}
else
{
if (! isset($params['label_side']) || $params['label_side'] == 'left')
{
$result .= $label;
}
$result .= '<a href="'.$url.'"';
$result .= ' title="'.(isset($params['title']) ? $params['title'] : ($titleattr != '' ? $titleattr : $name)).'"';
if (isset($params['target']))
{
$result .= ' target="'.$params['target'].'"';
}
if (isset($params['id']))
{
$result .= ' id="'.$params['id'].'"';
}
if (isset($params['class']))
{
$result .= ' class="'.$params['class'].'"';
}
//Start Russ for tabindex param
if (isset($params['tabindex']))
{
$result .= ' tabindex="'.$params['tabindex'].'"';
}
//End Russ
if (isset($params['more']))
{
$result .= ' '.$params['more'];
}
$result .= '>';
//Marcus Bointon - add ability to use images for links
if (isset($params['text'])){
$linktext = $params['text'];
}
elseif (isset($params['menu']) && $params['menu'] == "1") { // mbv
$linktext = $menu_text;
}
else {
$linktext = $name; // mbv - 21-06-2005
}
if (isset($params['image']) && ! empty($params['image'])) {
$alt = (isset($params['alt']) && ! empty($params['alt'])) ? $params['alt'] : '';
$result .= "<img src=\"{$params['image']}\" alt=\"$alt\" />";
if (! (isset($params['imageonly']) && $params['imageonly'])) {
$result .= " $linktext";
}
}
else {
$result .= $linktext;
}
$result .= '</a>';
if (isset($params['label_side']) && $params['label_side'] == 'right')
{
$result .= $label;
}
}
/* LeisureLarry - Begin */
}
elseif (isset($params['href'])) {
$result .= $url;
/* LeisureLarry - End */
}
else {
/*
$result .= "<!-- Not a valid cms_selflink -->";
if (isset($params['text']))
{
$result .= $params['text'];
}
*/
}
return $result;
}
function smarty_cms_help_function_cms_selflink() {
?>
<h3>What does this do?</h3>
<p>Creates a link to another CMSMS content page inside your template or content. Can also be used for external links with the ext parameter.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like: <code>{cms_selflink page="1"}</code> or <code>{cms_selflink page="alias"}</code></p>
<h3>What parameters does it take?</h3>
<p>
<ul>
<li><em>(optional)</em> <tt>page</tt> - Page ID or alias to link to.</li>
<li><em>(optional)</em> <tt>dir anchor (internal links)</tt> - New option for an internal page link. If this is used then <tt>anchorlink</tt> should be set to your link. </li> <!-- Russ - 25-04-2006 -->
<li><em>(optional)</em> <tt>anchorlink</tt> - New paramater for an internal page link. If this is used then <tt>dir ="anchor"</tt> should also be set. No need to add the #, because it is added automatically.</li> <!-- Russ - 25-04-2006 -->
<li><em>(optional)</em> <tt>urlparam</tt> - Specify additional parameters to the URL. <strong>Do not use this in conjunction with the <em>anchorlink</em> parameter</em></strong>
<li><em>(optional)</em> <tt>tabindex ="a value"</tt> - Set a tabindex for the link.</li> <!-- Russ - 22-06-2005 -->
<li><em>(optional)</em> <tt>dir start/next/prev/up (previous)</tt> - Links to the default start page or the next or previous page, or the parent page (up). If this is used <tt>page</tt> should not be set.</li> <!-- mbv - 21-06-2005 -->
<B>Note!</B> Only one of the above may be used in the same cms_selflink statement!!
<li><em>(optional)</em> <tt>text</tt> - Text to show for the link. If not given, the Page Name is used instead.</li>
<li><em>(optional)</em> <tt>menu 1/0</tt> - If 1 the Menu Text is used for the link text instead of the Page Name</li> <!-- mbv - 21-06-2005 -->
<li><em>(optional)</em> <tt>target</tt> - Optional target for the a link to point to. Useful for frame and javascript situations.</li>
<li><em>(optional)</em> <tt>class</tt> - Class for the <a> link. Useful for styling the link.</li> <!-- mbv - 21-06-2005 -->
<li><em>(optional)</em> <tt>lang</tt> - Display link-labels ("Next Page"/"Previous Page") in different languages (0 for no label.) Danish (dk), English (en) or French (fr), for now.</li> <!-- mbv - 21-06-2005 -->
<li><em>(optional)</em> <tt>id</tt> - Optional css_id for the <a> link.</li> <!-- mbv - 29-06-2005 -->
<li><em>(optional)</em> <tt>more</tt> - place additional options inside the <a> link.</li> <!-- mbv - 29-06-2005 -->
<li><em>(optional)</em> <tt>label</tt> - Label to use in with the link if applicable.</li>
<li><em>(optional)</em> <tt>label_side left/right</tt> - Side of link to place the label (defaults to "left").</li>
<li><em>(optional)</em> <tt>title</tt> - Text to use in the title attribute. If none is given, then the title of the page will be used for the title.</li>
<li><em>(optional)</em> <tt>rellink 1/0</tt> - Make a relational link for accessible navigation. Only works