[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/ -> function.cms_selflink.php (source)

   1  <?php
   2  #CMS - CMS Made Simple
   3  #(c)2004 by Ted Kulp (wishy@users.sf.net)
   4  #This project's homepage is: http://cmsmadesimple.sf.net
   5  #
   6  #This program is free software; you can redistribute it and/or modify
   7  #it under the terms of the GNU General Public License as published by
   8  #the Free Software Foundation; either version 2 of the License, or
   9  #(at your option) any later version.
  10  #
  11  #This program is distributed in the hope that it will be useful,
  12  #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #GNU General Public License for more details.
  15  #You should have received a copy of the GNU General Public License
  16  #along with this program; if not, write to the Free Software
  17  #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18  
  19  function smarty_cms_function_cms_selflink($params, &$smarty) {
  20  
  21      global $gCms;
  22  
  23      $rellink = (isset($params['rellink']) && $params['rellink'] == '1' ? true : false);
  24  
  25      $url = '';
  26  
  27  /* ugly hack by tsw for external links with wiki styling */
  28  if ( isset($params['ext']) ) {
  29     /* thanks elijah */
  30     $url = $params['ext'];
  31     $text = $params['ext'];
  32  
  33     if ( isset($params['text'] )) {
  34        $text = $params['text'];
  35     }
  36  
  37     $title= '';
  38     if ( isset($params['title']) ) {
  39        $title=' title="'.$params['title'].'" ';
  40     }
  41  
  42     $target = '';
  43     if ( isset($params['target']) && ( strlen($params['target']) > 0 ) )  {
  44        $target=' target="'.$params['target'].'" ';
  45     }
  46  
  47     $external_text = '(external link)';
  48     if ( isset($params['ext_info']) ) {
  49        $external_text ='( '.$ext_info.' )';
  50     }
  51  
  52  
  53  return '<a class="external" href="'.$url.'" '.$title.''.$target.'>'.$text.'<span>'.$external_text.'</span></a>';
  54  }
  55  
  56  $urlparams = '';
  57  if ( isset($params['urlparams']) && ( strlen($params['urlparams'] > 0 ) ) ) {
  58    $urlparams =$params['urlparams'];
  59  }
  60  
  61  
  62  
  63      /* LeisureLarry - Changed if statement */
  64      if (isset($params['page']) or isset($params['href']))
  65      {
  66          $page = $params['page'];
  67          $name = $params['page']; //mbv - 21-06-2005
  68  
  69          /* LeisureLarry - Begin */
  70          if (isset($params['href']))
  71          {
  72              $page = $params['href'];
  73          }
  74          /* LeisureLarry - End */
  75  
  76          # check if the page exists in the db
  77          $manager =& $gCms->GetHierarchyManager();
  78          $node =& $manager->sureGetNodeByAlias($page);
  79          if (!isset($node)) return;
  80          $content =& $node->GetContent();
  81          if ($content !== FALSE)
  82          {
  83              $pageid = $content->Id();
  84              $alias = $content->Alias();
  85              $name = $content->Name(); //mbv - 21-06-2005
  86              $url = $content->GetUrl();
  87              $menu_text = $content->MenuText();
  88              $titleattr = $content->TitleAttribute();
  89          }
  90  
  91          /* Mod by Nemesis */
  92          if (isset($params['anchorlink']))
  93          {
  94              $url .= '#' . ltrim($params['anchorlink'], '#');
  95          }
  96  
  97          if (isset($params['urlparam']))
  98          {
  99              $url .= trim($params['urlparam']);
 100          }
 101  
 102              /* End mod Nemesis */
 103          
 104          $Prev_label = "";
 105          $Next_label = "";
 106          $Anchor_label = ""; //*Russ
 107          $Parent_label = "Parent page: "; //uplink
 108      }
 109      elseif (isset($params['dir'])) // this part is by mbv built on a proposal by 100rk
 110      {
 111          /* Russ - Begin */
 112          if (isset($params['anchorlink']))
 113          {
 114              $anchorlink = ltrim($params['anchorlink'], '#');
 115              //Param to set anchor link
 116          }
 117          /* Russ - End */
 118  
 119          if (isset($params['lang']))
 120          {
 121              switch (strtolower($params['lang']))
 122              {
 123                  case 'dk':
 124                  case 'da':
 125                      $Prev_label = "Forrige side: ";
 126                      $Next_label = "N&aelig;ste side: ";
 127                      break;
 128                  case 'nl':
 129                      $Prev_label = "Vorige pagina: ";
 130                      $Next_label = "Volgende pagina: ";
 131                      $Parent_label = "Bovenliggende pagina: "; // uplink
 132                      break;
 133                  case 'en':
 134                      $Prev_label = "Previous page: ";
 135                      $Next_label = "Next page: ";
 136                      $Parent_label = "Parent page: "; //uplink
 137                      break;
 138                  case 'fr':
 139                      $Prev_label = "Page pr&eacute;c&eacute;dente&nbsp;: ";
 140                      $Next_label = "Page suivante&nbsp;: ";
 141                      $Parent_label = "Page ascendante&nbsp;: "; //uplink
 142                      break;
 143                  case 'no':
 144                      $Prev_label = "Forrige side : ";
 145                      $Next_label = "Neste side: ";
 146                      $Parent_label = "Side opp: "; //uplink
 147                      break;
 148                  case '0':
 149                      $Prev_label = "";
 150                      $Next_label = "";
 151                      break;
 152                  default:
 153                      $Prev_label = "Previous page: ";
 154                      $Next_label = "Next page: ";
 155                      $Parent_label = "Parent page: "; //uplink
 156                      break;
 157              }
 158          }
 159          else
 160          {
 161              $Prev_label = "Previous page: ";
 162              $Next_label = "Next page: ";
 163              $Parent_label = "Parent page: "; //uplink
 164          }
 165          $condition = $order_by = false;
 166          switch (strtolower($params['dir']))
 167          {
 168              case 'next':
 169                  $condition = '>';
 170                  $order_by = 'hierarchy';
 171                  $label=$Next_label;
 172                  break;
 173              case 'prev':
 174              case 'previous':
 175                  $condition = '<';
 176                  $order_by = 'hierarchy DESC';
 177                  $label=$Prev_label;
 178                  break;
 179              case 'anchor': //* Start Russ addition
 180                  $condition = '^';
 181                  $order_by = 'something';
 182                  $label=''; //No label needed
 183                  break;//* End Russ addition
 184              case 'start':
 185                  $condition = '-';
 186                  $order_by = 'something';
 187                  $label = '';
 188                  break;
 189              case 'up': //* Start uplink
 190                  $condition = '|';
 191                  $order_by = '-';
 192                  $label='';
 193                  break; //* End uplink
 194          }
 195          if ($condition && $order_by)
 196          {
 197              global $gCms;
 198              $hm =& $gCms->GetHierarchyManager();
 199              $flatcontent = array();
 200              if ($condition != '|') // uplink (we don't need the flatcontent for an uplink)
 201              {
 202                  #return '';
 203                  $flatcontent =& $hm->getFlatList();
 204                  $number = 0;
 205                  for ($i = 0; $i < count($flatcontent); $i++)
 206                  {
 207                      if ($condition == '-')
 208                      {
 209                          global $gCms;
 210                          $contentops =& $gCms->GetContentOperations();
 211                          $defaultid = $contentops->GetDefaultPageID();
 212                          if ($flatcontent[$i]->getTag() == $defaultid)
 213                          {
 214                              $number = $i;
 215                              break;
 216                          }
 217                      }
 218                      else if ($flatcontent[$i]->getTag() == $gCms->variables['content_id'])
 219                      {
 220                          $number = $i;
 221                          break;
 222                      }
 223                  }
 224              } //* uplink addition
 225              if ($condition == '<')
 226              {
 227                  if ($number > 0)
 228                  {
 229                      for ($i = $number - 1; $i >= 0; $i--)
 230                      {
 231                          $content =& $flatcontent[$i]->getContent();
 232                          if (isset($content) && $content != NULL)
 233                          {
 234                              if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
 235                              {
 236                                  $pageid = $content->Id();
 237                                  $alias = $content->Alias();
 238                                  $name = $content->Name();
 239                                  $menu_text = $content->MenuText();
 240                                  $url = $content->GetURL();
 241                                  $titleattr = $content->TitleAttribute();
 242                                  break;
 243                              }
 244                          }
 245                          else
 246                          {
 247                              break;
 248                          }
 249                      }
 250                  }
 251              }
 252              else if ($condition == '>')
 253              {
 254                  if ($number < count($flatcontent))
 255                  {
 256                      for ($i = $number + 1; $i < count($flatcontent); $i++)
 257                      {
 258                          $content =& $flatcontent[$i]->getContent();
 259                          if(isset($content) && $content != NULL)
 260                          {
 261                              if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
 262                              {
 263                                  $pageid = $content->Id();
 264                                  $alias = $content->Alias();
 265                                  $name = $content->Name();
 266                                  $menu_text = $content->MenuText();
 267                                  $url = $content->GetURL();
 268                                  $titleattr = $content->TitleAttribute();
 269                                  break;
 270                              }
 271                          }
 272                          else
 273                          {
 274                              break;
 275                          }
 276                      }
 277                  }
 278              }
 279              else if ($condition == '^') //* Start Russ addition
 280              {
 281                  if ($number < count($flatcontent))
 282                  {
 283                      for ($i = $number; $i < count($flatcontent); $i++)
 284                      {
 285                          $content =& $flatcontent[$i]->getContent();
 286                          if (isset($content))
 287                          {
 288                              if ($content->Active() && $content->ShowInMenu() && $content->HasUsableLink())
 289                              {
 290                                  $pageid = $content->Id();
 291                                  $alias = $content->Alias();
 292                                  $name = $content->Name();
 293                                  $menu_text = $content->MenuText();
 294                                  $url = $content->GetURL().'#'.$anchorlink; //set as Param
 295                                  $titleattr = $content->TitleAttribute();
 296                                  break;
 297                              }
 298                          }
 299                          else
 300                          {
 301                              break;
 302                          }
 303                      }
 304                  }
 305              } //* End Russ addition
 306              else if ($condition == '|') //* Start uplink
 307              {
 308                  $node =& $hm->getNodeById($gCms->variables['content_id']);
 309                  $node =& $node->getParentNode();
 310                  //                print_r($node);
 311                  if (!isset($node)) return;
 312                  $content =& $node->GetContent();
 313                  if ($content != FALSE)
 314                  {
 315                      if ($content->Active() && $content->HasUsableLink())
 316                      {
 317                          $pageid = $content->Id();
 318                          $alias = $content->Alias();
 319                          $name = $content->Name();
 320                          $menu_text = $content->MenuText();
 321                          $url = $content->GetURL();
 322                          $titleattr = $content->TitleAttribute();
 323                      }
 324                  }
 325              } //* End uplink
 326              else if ($condition == '-')
 327              {
 328                  $content =& $flatcontent[$number]->getContent();
 329                  if (isset($content))
 330                  {
 331                      $pageid = $content->Id();
 332                      $alias = $content->Alias();
 333                      $name = $content->Name();
 334                      $menu_text = $content->MenuText();
 335                      $url = $content->GetURL();
 336                      $titleattr = $content->TitleAttribute();
 337                  }
 338              }
 339          }
 340          unset($condition);
 341          unset($order_by);
 342      } // end of next-prev code
 343  
 344      if (isset($params['label']))
 345      {
 346          $label = $params['label'];
 347      }
 348      else
 349      {
 350        if (!isset($label))
 351          {
 352            $label = '';
 353          }
 354      }
 355      $result = "";
 356  
 357      /* LeisureLarry - Changes if statement */
 358      if (($url != "") and !isset($params['href']))
 359      {
 360          if ($rellink && isset($params['dir']))
 361          {
 362              $result .= '<link rel="';
 363              if ($params['dir'] == 'prev' || $params['dir'] == 'previous')
 364              {
 365                  $result .= 'prev';
 366              }
 367              else if ($params['dir'] == 'start')
 368              {
 369                  $result .= 'start';
 370              }
 371              else if ($params['dir'] == 'anchor')//* Start Russ addition
 372              {
 373                  $result .= 'anchor';
 374              }//* End Russ addition
 375              else if ($params['dir'] == 'next')
 376              {
 377                  $result .= 'next';
 378              }
 379              else if ($params['dir'] == 'up')//* Start uplink
 380              {
 381                  $result .= 'up';
 382              }//* End uplink
 383              $result .= '" title="' . (isset($params['title']) ? $params['title'] : ($titleattr != '' ? $titleattr : $name));
 384              $result .= '" href="' . $url . '" />';
 385          }
 386          else
 387          {
 388              if (! isset($params['label_side']) || $params['label_side'] == 'left')
 389                  {
 390                  $result .= $label;
 391                  }
 392              $result .= '<a href="'.$url.'"';
 393  
 394              $result .= ' title="'.(isset($params['title']) ? $params['title'] : ($titleattr != '' ? $titleattr : $name)).'"';
 395  
 396              if (isset($params['target']))
 397              {
 398                  $result .= ' target="'.$params['target'].'"';
 399              }
 400  
 401              if (isset($params['id']))
 402              {
 403                  $result .= ' id="'.$params['id'].'"';
 404              }
 405  
 406              if (isset($params['class']))
 407              {
 408                  $result .= ' class="'.$params['class'].'"';
 409              }
 410              //Start Russ for tabindex param
 411              if (isset($params['tabindex']))
 412              {
 413                  $result .= ' tabindex="'.$params['tabindex'].'"';
 414              }
 415              //End Russ
 416              if (isset($params['more']))
 417              {
 418                  $result .= ' '.$params['more'];
 419              }
 420  
 421              $result .= '>';
 422  
 423              //Marcus Bointon - add ability to use images for links
 424              if (isset($params['text'])){
 425                  $linktext = $params['text'];
 426              } elseif (isset($params['menu']) && $params['menu'] == "1")       { // mbv
 427                  $linktext = $menu_text;
 428              } else {
 429                  $linktext = $name; // mbv - 21-06-2005
 430              }
 431              if (isset($params['image']) && ! empty($params['image'])) {
 432                  $alt = (isset($params['alt']) && ! empty($params['alt'])) ? $params['alt'] : '';
 433                  $result .= "<img src=\"{$params['image']}\" alt=\"$alt\" />";
 434                  if (! (isset($params['imageonly']) && $params['imageonly'])) {
 435                      $result .= " $linktext";
 436                  }
 437              } else {
 438                  $result .= $linktext;
 439              }
 440  
 441              $result .= '</a>';
 442              if (isset($params['label_side']) && $params['label_side'] == 'right')
 443                  {
 444                  $result .= $label;
 445                  }
 446  
 447  
 448          }
 449  
 450          /* LeisureLarry - Begin */
 451      }
 452      elseif (isset($params['href'])) {
 453  
 454          $result .= $url;
 455  
 456          /* LeisureLarry - End */
 457  
 458      }
 459      else {
 460          /*
 461             $result .= "<!-- Not a valid cms_selflink -->";
 462             if (isset($params['text']))
 463             {
 464             $result .= $params['text'];
 465             }
 466           */
 467      }
 468  
 469      return $result;
 470  }
 471  
 472  function smarty_cms_help_function_cms_selflink() {
 473      ?>
 474          <h3>What does this do?</h3>
 475          <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>
 476          <h3>How do I use it?</h3>
 477          <p>Just insert the tag into your template/page like: <code>{cms_selflink page=&quot;1&quot;}</code> or  <code>{cms_selflink page=&quot;alias&quot;}</code></p>
 478          <h3>What parameters does it take?</h3>
 479          <p>
 480          <ul>
 481          <li><em>(optional)</em> <tt>page</tt> - Page ID or alias to link to.</li>
 482          <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 -->
 483          <li><em>(optional)</em> <tt>anchorlink</tt> - New paramater for an internal page link. If this is used then <tt>dir =&quot;anchor&quot;</tt> should also be set. No need to add the #, because it is added automatically.</li> <!-- Russ - 25-04-2006 -->
 484          <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>
 485          <li><em>(optional)</em> <tt>tabindex =&quot;a value&quot;</tt> - Set a tabindex for the link.</li> <!-- Russ - 22-06-2005 -->
 486          <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 -->
 487          <B>Note!</B> Only one of the above may be used in the same cms_selflink statement!!
 488          <li><em>(optional)</em> <tt>text</tt> - Text to show for the link.  If not given, the Page Name is used instead.</li>
 489          <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 -->
 490          <li><em>(optional)</em> <tt>target</tt> - Optional target for the a link to point to.  Useful for frame and javascript situations.</li>
 491          <li><em>(optional)</em> <tt>class</tt> - Class for the &lt;a&gt; link. Useful for styling the link.</li> <!-- mbv - 21-06-2005 -->
 492          <li><em>(optional)</em> <tt>lang</tt> - Display link-labels  (&quot;Next Page&quot;/&quot;Previous Page&quot;) in different languages (0 for no label.) Danish (dk), English (en) or French (fr), for now.</li> <!-- mbv - 21-06-2005 -->
 493          <li><em>(optional)</em> <tt>id</tt> - Optional css_id for the &lt;a&gt; link.</li> <!-- mbv - 29-06-2005 -->
 494          <li><em>(optional)</em> <tt>more</tt> - place additional options inside the &lt;a&gt; link.</li> <!-- mbv - 29-06-2005 -->
 495          <li><em>(optional)</em> <tt>label</tt> - Label to use in with the link if applicable.</li>
 496          <li><em>(optional)</em> <tt>label_side left/right</tt> - Side of link to place the label (defaults to "left").</li>
 497          <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>
 498          <li><em>(optional)</em> <tt>rellink 1/0</tt> - Make a relational link for accessible navigation.  Only works if the dir parameter is set and should only go in the head section of a template.</li>
 499          <li><em>(optional)</em> <tt>href</tt> - If href is used only the href value is generated (no other parameters possible). <strong>Example:</strong> &lt;a href=&quot;{cms_selflink href=&quot;alias&quot;}&quot;&gt;&lt;img src=&quot;&quot;&gt;&lt;/a&gt;</li>
 500          <li><em>(optional)</em> <tt>image</tt> - A url of an image to use in the link. <strong>Example:</strong> {cms_selflink dir=&quot;next&quot; image=&quot;next.png&quot; text=&quot;Next&quot;}</li>
 501          <li><em>(optional)</em> <tt>alt</tt> - Alternative text to be used with image (alt="" will be used if no alt parameter is given).</li>
 502          <li><em>(optional)</em> <tt>imageonly</tt> - If using an image, whether to suppress display of text links. If you want no text in the link at all, also set lang=0 to suppress the label. <B>Example:</B> {cms_selflink dir=&quot;next&quot; image=&quot;next.png&quot; text=&quot;Next&quot; imageonly=1}</li>
 503          <li><em>(optional)</em> <tt>ext</tt> - For external links, will add class=&quot;external and info text. <strong>warning:</strong> only text, target and title parameters are compatible with this parameter</li>
 504          <li><em>(optional)</em> <tt>ext_info</tt> - Used together with &quot;ext&quot; defaults to (external link)</li>
 505          </ul>
 506          </p>
 507  
 508          <?php
 509  }
 510  
 511  function smarty_cms_about_function_cms_selflink() {
 512      ?>
 513          <p>Author: Ted Kulp &lt;tedkulp@users.sf.net&gt;</p>
 514          <p>Version: 1.1</p>
 515          <p>Modified: Martin B. Vestergaard &lt;mbv@nospam.dk&gt;</p>
 516          <p>Version: 1.41</p>
 517          <p>Modified: Russ Baldwin</p>
 518          <p>Version: 1.42</p>
 519          <p>Modified: Marcus Bointon &lt;coolbru@users.sf.net&gt;</p>
 520          <p>Version: 1.43</p>
 521          <p>Modified: Tatu Wikman &lt;tsw@backspace.fi&gt;</p>
 522          <p>Version: 1.44</p>
 523          <p>Modified: Hans Mogren &lt;http://hans.bymarken.net/&gt;</p>
 524          <p>Version: 1.45</p>
 525  
 526          <p>
 527          Change History:<br/>
 528          1.45 - Added a new option for &quot;dir&quot;, &quot;up&quot;, for links to the parent page e.g. dir=&quot;up&quot; (Hans Mogren).<br />
 529          1.44 - Added new parameters &quot;ext&quot; and &quot;ext_info&quot; to allow external links with class=&quot;external&quot; and info text after the link, ugly hack but works thinking about rewriting this(Tatu Wikman)<br />
 530          1.43 - Added new parameters &quot;image&quot; and &quot;imageonly&quot; to allow attachment of images to be used for page links, either instead of or in addition to text links. (Marcus Bointon)<br />
 531          1.42 - Added new parameter &quot;anchorlink&quot; and a new option for &quot;dir&quot; namely, &quot;anchor&quot;, for internal page links. e.g. dir=&quot;anchor&quot; anchorlink=&quot;internal_link&quot;. (Russ)<br />
 532          1.41 - added new parameter &quot;href&quot; (LeisureLarry)<br />
 533          1.4 - fixed bug next/prev linking to non-content pages. (Thanks Teemu Koistinen for this fix)<br />
 534          1.3 - added option &quot;more&quot;<br />
 535          1.2 - by Martin B. Vestergaard
 536          <ul>
 537          <li>changed default text to Page Name (was Page Alias)</li>
 538          <li>added option dir=next/prev to display next or previous item in the hirachy - thanks to 100rk</li>
 539          <li>added option class to add a class= statement to the a-tag.</li>
 540          <li>added option menu to display menu-text in sted of Page Name</li>
 541          <li>added option lang to display link-labels in different languages</li>
 542          </ul>
 543          1.1 - Changed to new content system<br />
 544          1.0 - Initial release
 545          </p>
 546          <?php
 547  }
 548  
 549  # vim:ts=4 sw=4 noet
 550  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7