Plume CMS PHP Cross Reference Content Management Systems

Source: /manager/inc/lib.frontend.php - 2299 lines - 72299 bytes - Summary - Text - Print

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # This file is part of Plume CMS, a website management application.
   6  # Copyright (C) 2001-2005 Loic d'Anterroches and contributors.
   7  #
   8  # Plume CMS is free software; you can redistribute it and/or modify
   9  # it under the terms of the GNU General Public License as published by
  10  # the Free Software Foundation; either version 2 of the License, or
  11  # (at your option) any later version.
  12  #
  13  # Plume CMS is distributed in the hope that it will be useful,
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  # GNU General Public License for more details.
  17  #
  18  # You should have received a copy of the GNU General Public License
  19  # along with this program; if not, write to the Free Software
  20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21  #
  22  # ***** END LICENSE BLOCK ***** */
  23  /*
  24  $art, $res, $news etc...
  25  -> points to $GLOBALS['_PX_render']['art']
  26                                     ['res']
  27                                     ['news']
  28                                     ['cat']
  29  */
  30  /**
  31   @proto doc
  32   
  33   !!! Introduction
  34   
  35   The PLUME CMS template system is not the simplest, but if read the 
  36   documenation and study a little the current templates, you will quickly 
  37   figure out how to use it.
  38   
  39   The system simply use PHP functions to display the data. Sometimes the use of
  40   the [PHP|http://www.php.net] [sprintf|http://www.php.net/sprintf] function to
  41   format data.
  42  
  43  */ 
  44  
  45  /**
  46   @proto doc
  47   
  48   !!! Informative functions
  49   
  50   These are functions to display information like the name of the website
  51   but not within a loop.
  52  */ 
  53    
  54   
  55  /**
  56   Display some information about the website.
  57   The __name__ parameter can take the following values:
  58   
  59   * name : name of the website
  60   * url : relative url of the website
  61   * fullurl : full url of the website
  62   * filesurl : relative url to the files and images of the website  
  63   * lang : the lang of the website
  64   * namexml : name utf-8 encoded
  65  
  66  Example:
  67  
  68  |<a href="<?php pxInfo('url'); ?>"><?php pxInfo('name'); ?></a>
  69   
  70   @proto function pxInfo 
  71   @param string name Property to display ('name')
  72   @param boolean return Type of return : true return result as a string, false (default) print in stdout
  73  */
  74  function pxInfo($name='name', $return=false)
  75  {
  76      switch ($name) {
  77      case 'fullurl':
  78          $result = 'http://'.config::f('domain').config::f('rel_url').'/'; 
  79          break;
  80      case 'url':
  81          $result = config::f('rel_url').'/'; 
  82          break;
  83      case 'filesurl':
  84          $result = config::f('rel_url_files').'/'; 
  85          break;
  86      case 'lang':
  87          $result = str_replace('_', '-', config::f('lang')); 
  88          break;
  89      case 'description':
  90          $result = $GLOBALS['_PX_render']['website']->f('website_description'); 
  91          break;
  92      case 'namexml':
  93          $result = text::toXML($GLOBALS['_PX_render']['website']->f('website_name'));
  94          break;
  95      case 'encoding':
  96          $result = strtolower(config::f('encoding')); 
  97          break;
  98      default:
  99          $result = $GLOBALS['_PX_render']['website']->f('website_name');
 100      }
 101      
 102      if ($return) return $result;
 103      echo $result;
 104  }
 105  
 106  /**
 107   Generate the 'link' links just need to put it in the head of the
 108   template.
 109  
 110  |<head>
 111  |<?php pxHeadLinks(); ?>
 112  |</head>
 113  
 114   @proto function pxHeadLinks
 115   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 116  */
 117  function pxHeadLinks($return=false)
 118  {
 119      $remove_numbers = (config::f('remove_numbers')) ? true : false;
 120      if ((int) config::f('res_per_page') > 0) {
 121          $res_per_page = (int) config::f('res_per_page');
 122      } else {
 123          $res_per_page = 0;
 124      }
 125      $result = '';
 126      if (config::f('action') == 'Category') {
 127          // Navigation links to the resources in the current page
 128          $GLOBALS['_PX_render']['res']->move((config::f('category_page') - 1) * $res_per_page);
 129          while (!$GLOBALS['_PX_render']['res']->EOF()) {
 130              $title = $GLOBALS['_PX_render']['res']->getTextContent('title');
 131              if ($remove_numbers) $title = px_removeNumbers($title);
 132              $result.= '<link rel="section" href="'
 133                  .$GLOBALS['_PX_render']['res']->getPath()
 134                  .'" title="'.$title.'" />'."\n";
 135              $GLOBALS['_PX_render']['res']->moveNext();
 136          }
 137          $GLOBALS['_PX_render']['res']->move((config::f('category_page') - 1) * $res_per_page);
 138  
 139          // Keywords
 140          $result.= '<meta name="keywords" content="'.htmlspecialchars($GLOBALS['_PX_render']['cat']->f('category_keywords')).'" />'."\n";
 141  
 142      } elseif (config::f('action') == 'Article') {
 143          $result = '<meta name="keywords" content="'
 144              .htmlspecialchars($GLOBALS['_PX_render']['art']->f('subject')
 145                                .', '.$GLOBALS['_PX_render']['art']->f('category_keywords')).'" />'."\n";
 146      } elseif (config::f('action') == 'News') {
 147          $result = '<meta name="keywords" content="'
 148              .htmlspecialchars($GLOBALS['_PX_render']['news']->f('subject')
 149                                .', '.$GLOBALS['_PX_render']['news']->f('category_keywords')).'" />'."\n";
 150      }
 151      
 152      if ($return) return $result;
 153      echo $result;
 154  }
 155  
 156  
 157  
 158  /**
 159   Generate the RSS sequence description
 160  
 161   @proto function pxRssSeq
 162   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 163  */
 164  function pxRssSeq($return=false)
 165  {
 166      $result = '';
 167      $index = $GLOBALS['_PX_render']['last']->getIndex();
 168      while (!$GLOBALS['_PX_render']['last']->EOF()) {
 169          $result.= '<rdf:li rdf:resource="'
 170              .$GLOBALS['_PX_render']['last']->getPath('fullurl').'" />'."\n";
 171          $GLOBALS['_PX_render']['last']->moveNext();
 172      }
 173      $GLOBALS['_PX_render']['last']->move($index);
 174      
 175      if ($return) return $result;
 176      echo $result;
 177  }
 178  
 179  /**
 180   Generate the RSS item sequence
 181  
 182   @proto function pxRssItems
 183   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 184  */
 185  function pxRssItems($return=false)
 186  {
 187      $result = '';    //global $_PX_website_config, $_PX_config;
 188      $index = $GLOBALS['_PX_render']['last']->getIndex();
 189      $remove_numbers = config::fbool('remove_numbers');
 190      while (!$GLOBALS['_PX_render']['last']->EOF()) {
 191          $content = htmlspecialchars(text::removeEntities(text::parseContent($GLOBALS['_PX_render']['last']->f('description'))));
 192          $title = htmlspecialchars(text::removeEntities($GLOBALS['_PX_render']['last']->f('title')));
 193          if ($remove_numbers) {
 194              $title = px_removeNumbers($title);
 195          }
 196          $result.= '<item rdf:about="'.$GLOBALS['_PX_render']['last']->getPath('fullurl')
 197              .'">'."\n".'  <title>'.$title."</title>\n".'  <link>'; 
 198          $result.= pxLastResPath('fullurl', true);  
 199          $result.= "</link>\n".'  <dc:date>'; 
 200          $result.= pxLastResDateModification('%Y-%m-%dT%H:%M:%S+00:00', 
 201                                              '%s', false, true); 
 202          $result.= "</dc:date>\n";
 203          $result.= '<description>'.$content.'</description>'."\n";
 204          $result.= '</item>'."\n";
 205          $GLOBALS['_PX_render']['last']->moveNext();
 206      }
 207      $GLOBALS['_PX_render']['last']->move($index);
 208      
 209      if ($return) return $result;
 210      echo $result;
 211  }
 212  
 213  /**
 214   Display the title of the current category.
 215  
 216   @proto function pxSingleCatTitle
 217   @param string s Substitution string ('%s - ')
 218   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 219  */
 220  function pxSingleCatTitle($s='%s - ', $return=false)
 221  {
 222      $title = $GLOBALS['_PX_render']['cat']->f('category_name');
 223      if (config::fbool('remove_numbers')) 
 224          $title = px_removeNumbers($title);
 225      $result = sprintf($s, htmlspecialchars($title));
 226      
 227      if ($return) return $result;
 228      echo $result;
 229  }
 230  
 231  /**
 232   Display the description of the current category.
 233  
 234   @proto function pxSingleCatDescription
 235   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 236  */
 237  function pxSingleCatDescription($return=false)
 238  {
 239      $result = text::parseContent($GLOBALS['_PX_render']['cat']->f('category_description'));
 240      
 241      if ($return) return $result;
 242      echo $result;
 243  }
 244  
 245  /**
 246   Display the category path
 247  
 248   @proto function pxSingleCatPath
 249   @param string s Substitution string ('%s')
 250   @param bool Get the feed path (false)
 251   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 252  */
 253  function pxSingleCatPath($s='%s', $feed=false, $return=false)
 254  {
 255      $path = $GLOBALS['_PX_render']['cat']->getPath('', $feed);
 256      $result = sprintf($s, $path);
 257      
 258      if ($return) return $result;
 259      echo $result;
 260  }
 261  
 262  /**
 263   Give the number of resources in the current category, 
 264   when displaying a category page
 265   
 266   @proto function pxSingleCatNbResources
 267   @param string no String for no resources ('no resources')
 268   @param string one String for 1 resource ('1 resource')
 269   @param string more Substitution string for 2 or more resources ('%s resources')
 270   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 271  */
 272  function pxSingleCatNbResources($no='no resources', $one='1 resource', 
 273                                  $more='%s resources', $return=false)
 274  {
 275      switch ($GLOBALS['_PX_render']['res']->NbRow()) {
 276      case 0: 
 277          $result = $no; 
 278          break;
 279      case 1: 
 280          $result = $one; 
 281          break;
 282      default: 
 283          $result = sprintf($more, $GLOBALS['_PX_render']['res']->nbRow()); 
 284          break;
 285      }
 286      if ($return) return $result;
 287      echo $result;
 288  }
 289  
 290  /**
 291   Get the number of resources in the current category, when displaying a 
 292   category page. If displaying a resource page, give the number of resources 
 293   in the current category of the resource. Usefull in __if__ statements.
 294  
 295   @proto function pxSingleCatGetNbResources
 296   @return integer Number of resources
 297  */
 298  function pxSingleCatGetNbResources()
 299  {
 300      return $GLOBALS['_PX_render']['res']->NbRowTotal();
 301  }
 302  
 303  /**
 304   Give a link to the previous/next page if available
 305    
 306   @proto function pxSingleCatNextPage
 307   @param int dir Direction -1 previous, (1) next
 308   @param string s substitution string ('%s')
 309   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 310  */
 311  function pxSingleCatNextPage($dir=1, $s='%s', $return=false)
 312  {
 313      $total = $GLOBALS['_PX_render']['res']->NbRowTotal();
 314      $path = $GLOBALS['_PX_render']['cat']->getPath();
 315      $page = config::f('category_page');
 316      $nbres = config::f('res_per_page');
 317      $result = '';
 318      if ($dir == -1 && $page > 1) {
 319          $page--;
 320          if (1 == $page) {
 321              $result = sprintf($s, $path);
 322          } else {
 323              $result = sprintf($s, $path.'index'.$page);
 324          }
 325      } elseif ($dir == 1 && ($total > ($page * $nbres))) {
 326          $page++;
 327          $result = sprintf($s, $path.'index'.$page);
 328      }
 329      
 330      if ($return) return $result;
 331      echo $result;
 332  }
 333  
 334  /**
 335   Give the list of pages of a category with links like
 336   search engines. Looks like ''Pages: Prev 1, 2, 3, 4, 5 Next''.
 337  
 338   @proto function pxSingleCatListPages
 339   @param string s Substitution string ('<p>Pages: %s</p>')
 340   @param string prev Previous page string ('Prev')
 341   @param string next Next page string ('Next')
 342   @param string sep Separator between page numbers (', ')
 343   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 344  */
 345  function pxSingleCatListPages($s='<p>Pages: %s</p>', $prev='Prev', 
 346                                $next='Next', $sep=', ', $return=false)
 347  {
 348      $result = '';
 349      $total = $GLOBALS['_PX_render']['res']->NbRowTotal();
 350      $activepage  = config::f('category_page');
 351      $nbres = config::fint('res_per_page');
 352      $path = $GLOBALS['_PX_render']['cat']->getPath();
 353      $pages = array();
 354      $list = '';
 355      $previouspage = '';
 356      $nextpage = '';
 357      $nbpages = (int) ceil($total/$nbres);
 358      if ($nbpages > 1) {
 359          for ($i=1;$i<=$nbpages;$i++) {
 360              $class = '';
 361              if ($i == $activepage) $class = 'class="current" ';
 362              $url = $path;
 363              if ($i > 1) $url .= 'index'.$i;
 364              $pages[]='<a '.$class.'href="'.$url.'">'.$i.'</a>';
 365          }
 366          $list = join($sep, $pages);
 367          //Previous page
 368          if ($activepage > 1) {
 369              if (2 == $activepage) {
 370                  $previouspage = '<a href="'.$path.'">'.$prev.'</a>';
 371              } else {
 372                  $temp = $activepage - 1;
 373                  $previouspage = '<a href="'.$path.'index'.$temp.'">'
 374                      .$prev.'</a>';
 375              }
 376          }
 377          //Next page
 378          if ($total > ($activepage * $nbres)) {
 379              $temp = $activepage + 1;
 380              $nextpage = '<a href="'.$path.'index'.$temp.'">'.$next.'</a>';
 381          }
 382          $result = sprintf($s, $previouspage.' '.$list.' '.$nextpage);
 383      }
 384      
 385      if ($return) return $result;
 386      echo $result;
 387  }
 388  
 389  
 390  /**
 391   Display the list of categories for a breadcrumb. Like
 392   Home >> Subcategory >> Subsubcategory
 393  
 394   @proto function pxSingleCatTree
 395   @param string s substitution string ('<ol>%s</ol>')
 396   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 397  */
 398  function pxSingleCatTree($s='<ol>%s</ol>', $return=false)
 399  {
 400      $result = '';
 401      $remove_numbers = config::fbool('remove_numbers');
 402      $res = '';
 403      $categories = array();
 404      $i=0;
 405      $categories[$i] = $GLOBALS['_PX_render']['cat'];
 406      $parentcat    = $GLOBALS['_PX_render']['cat']->f('category_parentid');
 407      $currentcatid = $GLOBALS['_PX_render']['cat']->f('category_id');
 408      $i++;
 409      while ($parentcat !=  $currentcatid) {
 410          $categories[$i] = FrontEnd::getCategory($parentcat);
 411          $parentcat    = $categories[$i]->f('category_parentid');
 412          $currentcatid = $categories[$i]->f('category_id');
 413          $i++;
 414      }
 415      reset($categories);
 416      foreach ($categories as $cat) {
 417          $title = $cat->f('category_name');
 418          if ($remove_numbers) $title = px_removeNumbers($title);
 419          $res = '<li><a href="'.$cat->getPath().'">'.htmlspecialchars($title)
 420              .'</a></li>'."\n".$res;
 421      }
 422      $result = sprintf($s, $res);
 423      
 424      if ($return) return $result;
 425      echo $result;
 426  }
 427  
 428  /**
 429   Display the parent name cat, only if not in homepage
 430  
 431   @proto function pxParentCatTitle
 432   @param string s Substitution string ('%s - ')
 433   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 434  */
 435  function pxParentCatTitle($s='%s - ', $return=false)
 436  {
 437      $title = $GLOBALS['_PX_render']['pcat']->f('category_name');
 438      if (config::fbool('remove_numbers')) {
 439          $title = px_removeNumbers($title);
 440      }
 441      $result = sprintf($s, htmlspecialchars($title));
 442      
 443      if ($return) return $result;
 444      echo $result;
 445  }
 446  
 447  /**
 448   Display the parent description cat, only if not in homepage
 449  
 450   @proto function pxParentCatDescription
 451   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 452  */
 453  function pxParentCatDescription($return=false)
 454  {
 455      $result = text::parseContent($GLOBALS['_PX_render']['pcat']->f('category_description'));
 456      
 457      if ($return) return $result;
 458      echo $result;
 459  }
 460  
 461  /**
 462   Display the parent category path, only if not in homepage
 463  
 464   @proto function pxParentCatPath
 465   @param string s Substitution string ('%s')
 466   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 467  */
 468  function pxParentCatPath($s='%s', $return=false)
 469  {
 470      $result = sprintf($s, $GLOBALS['_PX_render']['pcat']->getPath());
 471      
 472      if ($return) return $result;
 473      echo $result;
 474  }
 475  
 476  /**
 477   Display the list of primary categories
 478  
 479   @proto function pxPrimaryCategories
 480   @param string s Substitution string ('<ul>%s</ul>')
 481   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 482  */
 483  function pxPrimaryCategories($s='<ul>%s</ul>', $return=false)
 484  {
 485      $ordermanual = config::fbool('order_cat_manual');
 486      $remove_numbers = config::fbool('remove_numbers');
 487      $order = 'ORDER BY category_path';
 488      if ($ordermanual) {
 489          $order = 'ORDER BY category_name';
 490      }
 491      $rootcat = FrontEnd::getCategory('/');
 492      $prim    = FrontEnd::getCategories($rootcat->f('category_id'), $order);
 493  
 494      $cats = '';
 495      while (!$prim->EOF()) {
 496          if ($prim->f('category_path') != '/') {
 497              $path = $prim->getPath();
 498              $name = $prim->f('category_name');
 499              if ($remove_numbers) {
 500                  $name = px_removeNumbers($name);
 501              }
 502              $cats .= '<li><a href="'.$path.'">'.htmlspecialchars($name)
 503                  .'</a></li>'."\n";
 504          }
 505          $prim->moveNext();
 506      }
 507      $result = sprintf($s, $cats);
 508      
 509      if ($return) return $result;
 510      echo $result;
 511  }
 512  
 513  /**
 514   Display the list of subcategories in the form of an unordered list.
 515   
 516   @proto function pxSubCategories
 517   @param string s Substitution string ('%s')
 518   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 519  */ 
 520  function pxSubCategories($s='%s', $return=false)
 521  {
 522      $remove_numbers = config::fbool('remove_numbers');
 523      $order = 'ORDER BY category_path';
 524      if (config::fbool('order_cat_manual')) {
 525          $order = 'ORDER BY category_name';
 526      }
 527      $subcat = FrontEnd::getCategories($GLOBALS['_PX_render']['cat']->f('category_id'), $order);
 528      $result = '';
 529      if ($subcat->NbRow() > 0) {
 530          $ls = "<ul>\n";
 531          while (!$subcat->EOF()) {
 532              $name = $subcat->f('category_name');
 533              if ($remove_numbers) {
 534                  $name = px_removeNumbers($name);
 535              }
 536              $ls .= '<li><a href="'.$subcat->getPath().'">'
 537                  .htmlspecialchars($name).'</a></li>'."\n";
 538              $subcat->moveNext();
 539          }
 540          $ls .= "</ul>\n";
 541          $result = sprintf($s, $ls);
 542      }
 543      if ($return) return $result;
 544      echo $result;
 545  }
 546  
 547  /**
 548   Display the query string.
 549   
 550   To be used only in the search template.
 551  
 552   @proto function pxSearchQuery
 553   @param string s Substitution string ('%s')
 554   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 555  */
 556  function pxSearchQuery($s= '%s', $return=false)
 557  {
 558      $result = sprintf($s, htmlspecialchars(config::f('query_string')));
 559      
 560      if ($return) return $result;
 561      echo $result;
 562  }
 563  
 564  
 565  /**
 566   @proto doc
 567   
 568   !!! Functions in loops
 569   
 570   It is possible to run functions within loops to get access to specific data from
 571   the elements in the loops. 
 572   
 573   !! The $res loop
 574  
 575   This loop is available in the categories. It is used to display the last 
 576   resources of a category. For example:
 577  
 578  |<?php while (!$res->EOF()): ?>
 579  |   <div class="resource">
 580  |   <h2><a href="<?php pxResPath(); ?>"><?php pxResTitle(); ?></a></h2>
 581  |   <?php pxResDescription(); ?>
 582  |   </div>
 583  |<?php 
 584  |$res->moveNext(); 
 585  |endwhile; ?>
 586   
 587  */ 
 588  
 589  
 590  /**
 591   Display the title of the resource. 
 592  
 593   @proto function pxResTitle
 594   @param string s Substitution string ('%s')
 595   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 596  */
 597  function pxResTitle($s='%s', $return=false)
 598  {
 599      $title = $GLOBALS['_PX_render']['res']->getTextContent('title');
 600      if (config::fbool('remove_numbers')) {
 601          $title = px_removeNumbers($title);
 602      }
 603      $result = sprintf($s, $title);
 604      
 605      if ($return) return $result;
 606      echo $result;
 607  }
 608  
 609  /**
 610   Display the path to the resource.
 611  
 612   @proto function pxResPath
 613   @param string type 'fullurl' give path with http:// ('relative')
 614   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 615  */
 616  function pxResPath($type='relative', $return=false)
 617  {
 618      $result = $GLOBALS['_PX_render']['res']->getPath($type);
 619      
 620      if ($return) return $result;
 621      echo $result;
 622  }
 623  
 624  /**
 625   Display the description of the resource.
 626  
 627   If a limit is given, the description is converted into raw text and then the limit is applied.
 628  
 629   @proto function pxResDescription
 630   @param string s Substitution string ('%s')
 631   @param int limit Number of words (characters for the moment) to limit the description
 632   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 633  */
 634  function pxResDescription($s='%s', $limit=0, $return=false)
 635  {
 636      $result = '';
 637      if ($limit) {
 638          $text = text::truncate(text::parseContent($GLOBALS['_PX_render']['res']->f('description'), 'text'), $limit);
 639          $result = sprintf($s, $text);
 640      } else {
 641          $result = text::parseContent($GLOBALS['_PX_render']['res']->f('description'));
 642      }
 643      
 644      if ($return) return $result;
 645      echo $result;
 646  }
 647  
 648  /**
 649   Display the list of categories in which the ressource is.
 650  
 651   The list is not an HTML list, it is to be used as sentence like
 652   "Category one, category two and category tree" The category names
 653   are linked to the category pages.
 654  
 655   @proto function pxResCategories
 656   @param string s Substitution string ('%s')
 657   @param string p1 First delimiters (', ')
 658   @param string p2 Last delimiter (' and ')
 659   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 660  */
 661  function pxResCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
 662  {
 663      $remove_numbers = config::fbool('remove_numbers');
 664      $cat = $GLOBALS['_PX_render']['res']->cur->cats;
 665      $nr = $cat->nbRow();
 666      $i = 1;
 667      $link = '<a href="%s">%s</a>';
 668      $res = '';
 669      while (!$cat->EOF()) {
 670          $title = $cat->f('category_name');
 671          if ($remove_numbers) $title = px_removeNumbers($title);
 672          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
 673          if ($nr >= 2 && ($i < ($nr - 1))) {
 674              $res .= $p1;
 675          }
 676          if ($nr >= 2 && ($i == ($nr - 1))) {
 677              $res .= $p2;
 678          }
 679          $i++;
 680          $cat->moveNext();
 681      }
 682      $result = sprintf($s, $res);
 683      
 684      if ($return) return $result;
 685      echo $result;
 686  }
 687  
 688  
 689  /**
 690   Display the name of the author
 691  
 692   @proto function pxResAuthor
 693   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 694  */
 695  function pxResAuthor($return=false)
 696  {
 697      $result = $GLOBALS['_PX_render']['res']->extf('authors', 'user_realname');
 698      
 699      if ($return) return $result;
 700      echo $result;
 701  }
 702  
 703  /**
 704   Display the author public email if available.
 705  
 706   @proto function pxResAuthorEmail
 707   @param string s Substitution string ('%s')
 708   @param string encoding Encoding for a mailto ('link') or for display 'text'
 709   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 710  */
 711  function pxResAuthorEmail($s = '%s', $encoding = 'link', $return=false)
 712  {
 713      $result = '';
 714      $text = ($encoding == 'link') ? false : true;
 715      if (strlen($GLOBALS['_PX_render']['res']->extf('authors', 'user_pubemail')) > 0) {
 716          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['res']->extf('authors', 'user_pubemail'), $text));
 717      }
 718      
 719      if ($return) return $result;
 720      echo $result;
 721  }
 722  
 723  /**
 724   Display the modification date of the resource. Only if newer than the publication date.
 725  
 726   @proto function pxResDateModification
 727   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 728   @param string s Substitution string ('%s')
 729   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
 730   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 731  */
 732  function pxResDateModification($dateformat='%Y-%m-%dT%H:%M:%S+00:00', $s='%s', 
 733                                 $ifmodified=false, $return=false)
 734  {
 735      $result = '';
 736      if (false !== $ifmodified) {
 737          $ifmodified = $ifmodified * 60;
 738          $md = date::unix($GLOBALS['_PX_render']['res']->f('modifdate'));
 739          $pd = date::unix($GLOBALS['_PX_render']['res']->f('publicationdate'));
 740          if ($md >  ($pd + $ifmodified))
 741              $result = sprintf($s, strftime($dateformat, $md));
 742      } else {
 743          $result = sprintf($s, strftime($dateformat , 
 744                                    date::unix($GLOBALS['_PX_render']['res']->f('modifdate'))));
 745      }
 746      
 747      if ($return) return $result;
 748      echo $result;
 749  }
 750  
 751  /**
 752   Display the publication date of the resource.
 753  
 754   @proto function pxResDatePublication
 755   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 756   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 757  */
 758  function pxResDatePublication($dateformat = '%Y-%m-%dT%H:%M:%S+00:00', $return=false)
 759  {
 760      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['res']->f('publicationdate')));
 761      
 762      if ($return) return $result;
 763      echo $result;
 764  }
 765  
 766  /**
 767   Display the score of the resource for this research.
 768  
 769   To be used only in the search template.
 770  
 771   @proto function pxResSearchScore
 772   @param string s Substitution string ('%01.2f%%')
 773   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 774  */
 775  function pxResSearchScore($s= '%01.2f%%', $return=false)
 776  {
 777      if (!isset($GLOBALS['_PX_render']['search_max_occ'])) {
 778          $GLOBALS['_PX_render']['search_max_occ'] = (float) $GLOBALS['_PX_render']['res']->f('score');
 779      }
 780      $score = (float) $GLOBALS['_PX_render']['res']->f('score') / $GLOBALS['_PX_render']['search_max_occ'] * 100.0;
 781      $result = sprintf($s, $score);
 782      
 783      if ($return) return $result;
 784      echo $result;
 785  }
 786  
 787  
 788  /**
 789   Display the associated link and title if available. When getting the 
 790   resources, if the 'news' type is chose as link can be associated to
 791   news, this is the way to get it back if available.
 792  
 793   @proto function pxResAssociatedLink
 794   @param string s Substitution string ('<a href="%1$s">%2$s</a>')
 795   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 796  */
 797  function pxResAssociatedLink($s='<a href="%1$s">%2$s</a>', $return=false)
 798  {
 799      $result = '';
 800      if ($GLOBALS['_PX_render']['res']->f('type_id') == 'news') {
 801          $GLOBALS['_PX_render']['res']->cur->loadDetails();
 802          if (strlen($GLOBALS['_PX_render']['res']->cur->details->f('news_titlewebsite')) > 0) {
 803              $result = sprintf($s, $GLOBALS['_PX_render']['res']->cur->details->f('news_linkwebsite'), $GLOBALS['_PX_render']['res']->cur->details->f('news_titlewebsite'));
 804          }
 805      }
 806      if ($return) return $result;
 807      echo $result;
 808  }
 809  
 810  /**
 811   Display the number of comments of the resources.
 812  
 813   @proto function pxResCountComments
 814   @param boolean return Type of return : true return result as a string, false (default) print in stdout
 815  */
 816  function pxResCountComments($return=false)
 817  {
 818      $result = $GLOBALS['_PX_render']['res']->cur->countComments();
 819      if ($return) return $result;
 820      echo $result;
 821  }
 822  
 823  
 824  /**
 825   @proto doc
 826  
 827   !! The $last loop
 828  
 829   This loop is available in all the templates, you just have to initialize it
 830   before use:
 831  
 832  |<?php pxGetLastResources(); ?>
 833  |<?php while (!$last->EOF()): ?>
 834  |    <p><a href="<?php pxLastResPath(); ?>"><?php pxLastResTitle(); ?></a></p>
 835  |<?php
 836  |$last->moveNext();
 837  |endwhile; ?>
 838  
 839  */
 840  
 841  /**
 842   * Get the list of last resources and put them in $last
 843   * Must be run before using the $last loop
 844   *
 845   * @proto function pxGetLastResources
 846   * @param int limit Number of last resources (5)
 847   * @param string type Type of resources ('') for all, 'news' or 'articles'
 848   * @param int category Category id ('')
 849   * @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 850   */
 851  function pxGetLastResources($limit=5, $type='', $category='', $return=false) 
 852  {
 853      $result = $GLOBALS['_PX_render']['last'] = FrontEnd::getResources($category, 
 854                          $limit, $type, 1);
 855      if ($return) return $result;
 856  }
 857  
 858  /**
 859   Display the title of the resource.
 860  
 861   @proto function pxLastResTitle
 862   @param string s Substitution string ('%s')
 863   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 864  
 865  */
 866  function pxLastResTitle($s='%s', $return=false)
 867  {
 868      $remove_numbers = (config::f('remove_numbers')) ? true : false;
 869      $title = $GLOBALS['_PX_render']['last']->getTextContent('title');
 870      if ($remove_numbers) 
 871          $title = px_removeNumbers($title);
 872      $result = sprintf($s, $title);
 873      if ($return) return $result;
 874      echo $result;
 875  }
 876  
 877  /**
 878   Display the path to the resource.
 879  
 880   @proto function pxLastResPath
 881   @param string type If 'fullurl' give path with http:// ('relative')
 882   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 883  
 884  */
 885  function pxLastResPath($type='relative', $return=false)
 886  {
 887      $result = $GLOBALS['_PX_render']['last']->getPath($type);
 888      
 889      if ($return) return $result;
 890      echo $result;
 891  }
 892  
 893  /**
 894   Display the description of the resource.
 895  
 896   @proto function pxLastResDescription
 897   @param string s Substitution string ('%s')
 898   @param int limit Number of words (characters for the moment) to limit the description
 899   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 900  
 901  */
 902  function pxLastResDescription($s='%s', $limit=0, $return=false)
 903  {
 904      $result = '';
 905      if ($limit) {
 906          $text = text::truncate(text::parseContent($GLOBALS['_PX_render']['last']->f('description'), 'text'), $limit);
 907          $result = sprintf($s, $text);
 908      } else {
 909          $result = text::parseContent($GLOBALS['_PX_render']['last']->f('description'));
 910      }
 911      
 912      if ($return) return $result;
 913      echo $result;
 914  }
 915  
 916  /**
 917   Display the name of the author
 918  
 919   @proto function pxLastResAuthor
 920   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 921  */
 922  function pxLastResAuthor($return=false)
 923  {
 924      $result = $GLOBALS['_PX_render']['last']->extf('authors', 'user_realname');
 925      
 926      if ($return) return $result;
 927      echo $result;
 928  }
 929  
 930  /**
 931   Display the author public email if available.
 932  
 933   @proto function pxLastResAuthorEmail
 934   @param string s Substitution string ('%s')
 935   @param string encoding Encoding for a mailto ('link') or for display 'text'
 936   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 937  */
 938  function pxLastResAuthorEmail($s='%s', $encoding='link', $return=false)
 939  {
 940      $result = '';
 941      $text = ($encoding == 'link') ? false : true;
 942      if (strlen($GLOBALS['_PX_render']['last']->extf('authors', 'user_pubemail')) > 0) {
 943          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['last']->extf('authors', 'user_pubemail'), $text));
 944      }
 945      
 946      if ($return) return $result;
 947      echo $result;
 948  }
 949  
 950  /**
 951   Display the modification date of the resource.
 952  
 953   @proto function pxLastResDateModification
 954   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 955   @param string s Substitution string ('%s')
 956   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
 957   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 958  */
 959  function pxLastResDateModification($dateformat='%Y-%m-%dT%H:%M:%S+00:00', 
 960                                     $s='%s', $ifmodified=false, $return=false)
 961  {
 962      $result = '';
 963      if ($ifmodified !== false) {
 964          $pd = date::unix($GLOBALS['_PX_render']['last']->f('publicationdate'));
 965          $md = date::unix($GLOBALS['_PX_render']['last']->f('modifdate'));
 966          $ifmodified = 60 * (int) $ifmodified;
 967          if ($md > ($pd + $ifmodified)) {
 968              $result = sprintf($s, strftime($dateformat, $md));
 969          }
 970      } else {
 971          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['last']->f('modifdate'))));
 972      }
 973      if ($return) return $result;
 974      echo $result;
 975  }
 976  
 977  /**
 978   Display the publication date of the last resource.
 979  
 980   @proto function pxLastResDatePublication
 981   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 982   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 983  */
 984  function pxLastResDatePublication($dateformat='%Y-%m-%dT%H:%M:%S+00:00', $return=false)
 985  {
 986      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['last']->f('publicationdate')));
 987      
 988      if ($return) return $result;
 989      echo $result;
 990  }
 991  
 992  /**
 993   Display the associated link and title if available. When getting the last
 994   resources, if the 'news' type is chose as link can be associated to
 995   news, this is the way to get it back if available.
 996  
 997   @proto function pxLastResAssociatedLink
 998   @param string s Substitution string ('<a href="%1$s">%2$s</a>')
 999   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1000  */
1001  function pxLastResAssociatedLink($s='<a href="%1$s">%2$s</a>', $return=false)
1002  {
1003      $result = '';
1004      if ($GLOBALS['_PX_render']['last']->f('type_id') == 'news') {
1005          $GLOBALS['_PX_render']['last']->cur->loadDetails();
1006          if (strlen($GLOBALS['_PX_render']['last']->cur->details->f('news_titlewebsite')) > 0) {
1007              $result = sprintf($s, $GLOBALS['_PX_render']['last']->cur->details->f('news_linkwebsite'), $GLOBALS['_PX_render']['last']->cur->details->f('news_titlewebsite'));
1008          }
1009      }
1010      if ($return) return $result;
1011      echo $result;
1012  }
1013  
1014  /**
1015   Display the list of categories in which the last ressource is.
1016  
1017   The list is not an HTML list, it is to be used as sentence like
1018   "Category one, category two and category tree" The category names
1019   are linked to the category pages.
1020  
1021   @proto function pxLastResCategories
1022   @param string s Substitution string ('%s')
1023   @param string p1 First delimiters (', ')
1024   @param string p2 Last delimiter (' and ')
1025   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1026  */
1027  function pxLastResCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1028  {
1029      $remove_numbers = config::fbool('remove_numbers');
1030      $cat = $GLOBALS['_PX_render']['last']->cur->cats;
1031      $nr = $cat->nbRow();
1032      $i = 1;
1033      $link = '<a href="%s">%s</a>';
1034      $res = '';
1035      while (!$cat->EOF()) {
1036          $title = $cat->f('category_name');
1037          if ($remove_numbers) $title = px_removeNumbers($title);
1038          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1039          if ($nr >= 2 && ($i < ($nr - 1))) {
1040              $res .= $p1;
1041          }
1042          if ($nr >= 2 && ($i == ($nr - 1))) {
1043              $res .= $p2;
1044          }
1045          $i++;
1046          $cat->moveNext();
1047      }
1048      $result = sprintf($s, $res);
1049      
1050      if ($return) return $result;
1051      echo $result;
1052  }
1053  
1054  /**
1055   Display the number of comments of the resources.
1056  
1057   @proto function pxLastResCountComments
1058   @param boolean return Type of return : true return result as a string, false (default) print in stdout
1059  */
1060  function pxLastResCountComments($return=false)
1061  {
1062      $result = $GLOBALS['_PX_render']['last']->cur->countComments();
1063      if ($return) return $result;
1064      echo $result;
1065  }
1066  
1067  
1068  
1069  /**
1070   @proto doc
1071  
1072   !!! The resource functions
1073  
1074   These are functions to display information about the current resource in the
1075   page. For the moment the resource can be either an __article__ or a __news__.
1076  
1077   !! The article functions
1078  
1079   These functions are to be used in the ''article'' templates.
1080  
1081  */
1082  
1083  
1084  /**
1085   Display the title of the article.
1086  
1087   @proto function pxArtTitle
1088   @param string s Substitution string ('%s')
1089   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1090  
1091  */
1092  function pxArtTitle($s='%s', $return=false)
1093  {
1094      $title = $GLOBALS['_PX_render']['art']->getTextContent('title');
1095      if (config::fbool('remove_numbers')) 
1096          $title = px_removeNumbers($title);
1097      $result = sprintf($s, $title);
1098      
1099      if ($return) return $result;
1100      echo $result;
1101  }
1102  
1103  /**
1104   Display the description of the article.
1105  
1106   @proto function pxArtDescription
1107   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1108  */
1109  function pxArtDescription($return=false)
1110  {
1111      $result = text::parseContent($GLOBALS['_PX_render']['art']->f('description'));
1112      
1113      if ($return) return $result;
1114      echo $result;
1115  }
1116  
1117  /**
1118   Display the name of the author
1119  
1120   @proto function pxArtAuthor
1121   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1122  */
1123  function pxArtAuthor($return=false)
1124  {
1125      $result = $GLOBALS['_PX_render']['art']->authors->f('user_realname');
1126      
1127      if ($return) return $result;
1128      echo $result;
1129  }
1130  
1131  /**
1132   Display the path to the article.
1133  
1134   @proto function pxArtPath
1135   @param string type 'fullurl' give path with http:// ('relative')
1136   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1137  */
1138  function pxArtPath($type='relative', $return=false)
1139  {
1140      $result = $GLOBALS['_PX_render']['art']->getPath($type);
1141      
1142      if ($return) return $result;
1143      echo $result;
1144  }
1145  
1146  /**
1147   Display the author public email if available.
1148  
1149  @proto function pxArtAuthorEmail
1150  @param string s Substitution string ('%s')
1151  @param string encoding Encoding for a mailto ('link') or for display 'text'
1152  @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1153  */
1154  function pxArtAuthorEmail($s='%s', $encoding='link', $return=false)
1155  {
1156      $result = '';
1157      $text = ($encoding == 'link') ? false : true;
1158      if (strlen($GLOBALS['_PX_render']['art']->authors->f('user_pubemail')) > 0) {
1159          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['art']->authors->f('user_pubemail'), $text));
1160      }
1161      
1162      if ($return) return $result;
1163      echo $result;
1164  }
1165  
1166  /**
1167   Display the creation date of the article.
1168  
1169   The substitution string for the date is directly given to
1170   [strftime|http://www.php.net/strftime]
1171  
1172   @proto function pxArtDateCreation
1173   @param string dateformat Format of the date ('%A %e %B %Y')
1174   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1175  
1176  */
1177  function pxArtDateCreation($dateformat='%A %e %B %Y', $return=false)
1178  {
1179      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('creationdate')));
1180      
1181      if ($return) return $result;
1182      echo $result;
1183  }
1184  
1185  /**
1186   Display the publication date of the article.
1187  
1188   The substitution string for the date is directly given to
1189   [strftime|http://www.php.net/strftime]
1190  
1191   @proto function pxArtDatePublication
1192   @param string dateformat Format of the date ('%A %e %B %Y')
1193   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1194  
1195  */
1196  function pxArtDatePublication($dateformat='%A %e %B %Y', $return=false)
1197  {
1198      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('publicationdate')));
1199      
1200      if ($return) return $result;
1201      echo $result;
1202  }
1203  
1204  /**
1205   Display the modification date of the article. Only if newer than the
1206   publication date.
1207  
1208   The substitution string for the date is directly given to
1209   [strftime|http://www.php.net/strftime]
1210  
1211   @proto function pxArtDateModification
1212   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1213   @param string s Substitution ('Modified the %s.')
1214   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
1215   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1216  */
1217  function pxArtDateModification($dateformat='%A %e %B %Y', 
1218                                 $s='Modified the %s.', $ifmodified=false, $return=false)
1219  {
1220      $result = '';
1221      if (false !== $ifmodified) {
1222          $ifmodified = 60 * $ifmodified;
1223          $md = date::unix($GLOBALS['_PX_render']['art']->f('modifdate'));
1224          $pb = date::unix($GLOBALS['_PX_render']['art']->f('publicationdate'));
1225          if ($md > ($pb + $ifmodified)) {
1226              $result = sprintf($s, strftime($dateformat, $md));
1227          }
1228      } else {
1229          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['art']->f('modifdate'))));
1230      }
1231      
1232      if ($return) return $result;
1233      echo $result;
1234  }
1235  
1236  /**
1237   Display the date of end of availaibility of the article. Only if end date.
1238  
1239   The substitution string for the date is directly given to
1240   [strftime|http://www.php.net/strftime]
1241  
1242   @proto function pxArtDateEnd
1243   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1244   @param string s Substitution ('End the %s.')
1245   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1246  */
1247  function pxArtDateEnd($dateformat='%A %e %B %Y', $s='End the %s.', $return=false)
1248  {
1249      $result = '';
1250      $y = substr($GLOBALS['_PX_render']['art']->f('enddate'), 0, 4);
1251      if ((int)$y < 9999) {
1252          $result = sprintf($s, strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('enddate'))));
1253      }
1254      
1255      if ($return) return $result;
1256      echo $result;
1257  }
1258  
1259  /**
1260   Display the keywords or subject of the article
1261  
1262   @proto function pxArtKeywords
1263   @param string s Substitution string ('%s')
1264   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1265  */
1266  function pxArtKeywords($s='%s', $return=false)
1267  {
1268      $result = '';
1269      $keywords = trim($GLOBALS['_PX_render']['art']->f('subject'));
1270      if (strlen($keywords) > 0) {
1271          $result = sprintf($s, $keywords);
1272      }
1273      
1274      if ($return) return $result;
1275      echo $result;
1276  }
1277  
1278  /**
1279   Display the list of categories in which the article is.
1280  
1281   The list is not an HTML list, it is to be used as sentence like
1282   "Category one, category two and category tree" The category names
1283   are linked to the category pages.
1284  
1285   @proto function pxArtCategories
1286   @param string s Substitution string ('%s')
1287   @param string p1 First delimiters (', ')
1288   @param string p2 Last delimiter (' and ')
1289   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1290  */
1291  function pxArtCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1292  {
1293      $remove_numbers = config::fbool('remove_numbers');
1294      $cat = $GLOBALS['_PX_render']['art']->cats;
1295      $nr = $cat->nbRow();
1296      $i = 1;
1297      $link = '<a href="%s">%s</a>';
1298      $res = '';
1299      while (!$cat->EOF()) {
1300          $title = $cat->f('category_name');
1301          if ($remove_numbers) $title = px_removeNumbers($title);
1302          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1303          if ($nr >= 2 && ($i < ($nr - 1))) {
1304              $res .= $p1;
1305          }
1306          if ($nr >= 2 && ($i == ($nr - 1))) {
1307              $res .= $p2;
1308          }
1309          $i++;
1310          $cat->moveNext();
1311      }
1312      $result = sprintf($s, $res);
1313      
1314      if ($return) return $result;
1315      echo $result;
1316  }
1317  
1318  /**
1319   Return true if the current page is the first page of the article
1320  
1321   @proto function pxArtPageIsFirst
1322   @return bool __true__ if the current page is the first, else __false__
1323  */
1324  function pxArtPageIsFirst()
1325  {
1326      return ((int)$GLOBALS['_PX_render']['art']->pages->f('page_number') == 1);
1327  }
1328  
1329  /**
1330   Display the title of the current article page.
1331  
1332   @proto function pxArtPageTitle
1333   @param string s Substitution string ('%s')
1334   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1335  
1336  */
1337  function pxArtPageTitle($s='%s', $return=false)
1338  {
1339      $result = $GLOBALS['_PX_render']['art']->pages->f('page_title');
1340      $result = str_replace('&', '&amp;', $result);    
1341      $result = sprintf($s, $result);
1342      if ($return) return $result;
1343      echo $result;
1344  }
1345  
1346  /**
1347   Display the number of comments of the article.
1348  
1349   @proto function pxArtCountComments
1350   @param boolean return Type of return : true return result as a string, false (default) print in stdout
1351  */
1352  function pxArtCountComments($return=false)
1353  {
1354      $result = $GLOBALS['_PX_render']['art']->countComments();
1355      if ($return) return $result;
1356      echo $result;
1357  }
1358  
1359  /**
1360   Display an address link to edit the current resource.
1361  
1362  @proto function pxResEditLink
1363  @param string s Substitution string ('%s')
1364  @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1365  */
1366  
1367  function pxGetResType()
1368  {
1369      return $GLOBALS['_PX_render']['res']->f('type_id');
1370  }
1371  
1372  function pxResEditLink($s='%s', $return=false)
1373  {
1374      require_once dirname(__FILE__).'/lib.auth.php';
1375      require_once dirname(__FILE__).'/class.user.php';
1376      if (auth::getFromCookie())
1377      {
1378          $result = "";
1379  
1380          $type = $GLOBALS['_PX_render']['res']->f('type_id');
1381          if ($type == "articles")
1382      {$result = "articles";
1383      $res = 'art';}
1384          else if ($type == "news")
1385      {$res = 'news';
1386      $result = "news";}
1387  
1388          $id = $GLOBALS['_PX_render'][$res]->f('resource_id');
1389          $url = pxInfo('fullurl', true)."manager";
1390          $result = "$url/$result.php?resource_id=$id";
1391          $result = sprintf($s, $result);
1392  
1393          if ($return) return $result;
1394          echo $result;
1395      }
1396  }
1397  
1398  /**
1399   Display the content of the current article page.
1400  
1401   @proto function pxArtPageContent
1402   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1403  
1404  */
1405  function pxArtPageContent($return=false)
1406  {
1407      $result = text::parseContent($GLOBALS['_PX_render']['art']->pages->f('page_content'));
1408      
1409      if ($return) return $result;
1410      echo $result;
1411  }
1412  
1413  /**
1414   Display an ordered list of pages in the article with link to the pages.
1415   The current page is set as ''active'' with the corresponding <li> element
1416   being from the __current__ class.
1417  
1418   An output example is:
1419  
1420  |<ol>
1421  |<li><a href="/cat/my-article">Page 1</a></li>
1422  |<li class="current"><a href="/cat/my-article2">Page 2</a></li>
1423  |<li><a href="/cat/my-article3">Page 3</a></li>
1424  |</ol>
1425  
1426   @proto function pxArtListPages
1427   @param string s Substitution string ('%s')
1428   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1429  
1430  */
1431  function pxArtListPages($s = '%s', $return=false)
1432  {
1433      $result = '';
1434      if ($GLOBALS['_PX_render']['art']->pages->nbRow() > 1) {
1435          $index = $GLOBALS['_PX_render']['art']->pages->getIndex();
1436          $GLOBALS['_PX_render']['art']->pages->moveStart();
1437          $lp = '<ol>'."\n";
1438          while (!$GLOBALS['_PX_render']['art']->pages->EOF()) {
1439              $active = ($index == $GLOBALS['_PX_render']['art']->pages->getIndex()) ? ' class="current"' : '';
1440              $page = ($GLOBALS['_PX_render']['art']->pages->f('page_number') == 1) ? '' : $GLOBALS['_PX_render']['art']->pages->f('page_number');
1441              $lp .= '<li'.$active.'><a href="'.$GLOBALS['_PX_render']['art']->getPath().$page.'">'.$GLOBALS['_PX_render']['art']->pages->getTextContent('page_title').'</a></li>'."\n";
1442              $GLOBALS['_PX_render']['art']->pages->moveNext();
1443          }
1444          $lp .= '</ol>'."\n";
1445          $GLOBALS['_PX_render']['art']->pages->move($index);
1446          $result = sprintf($s, $lp);
1447      }
1448      
1449      if ($return) return $result;
1450      echo $result;
1451  }
1452  
1453  /**
1454   Give a link to the previous/next page of an article if available
1455    
1456   @proto function pxArtNextPage
1457   @param int dir Direction -1 previous, (1) next
1458   @param string s substitution string ('%s')
1459   @param boolean return Type of return : true return result as a string, false (default) print in stdout
1460  */
1461  function pxArtNextPage($dir=1, $s='%s', $return=false)
1462  {
1463      $total = $GLOBALS['_PX_render']['art']->pages->nbRow();
1464      $path = $GLOBALS['_PX_render']['art']->getPath();
1465      $page = $GLOBALS['_PX_render']['art']->pages->f('page_number');
1466      $result = '';
1467      if ($dir == -1 && $page > 1) {
1468          $page--;
1469          if (1 == $page) {
1470              $result = sprintf($s, $path);
1471          } else {
1472              $result = sprintf($s, $path.$page);
1473          }
1474      } elseif ($dir == 1 && ($total > $page)) {
1475          $page++;
1476          $result = sprintf($s, $path.$page);
1477      }
1478      
1479      if ($return) return $result;
1480      echo $result;
1481  }
1482  
1483  /**
1484   @proto doc
1485  
1486   !! The comments functions
1487  
1488   These functions are to be used in the ''news'' and ''article'' templates.
1489  
1490  */
1491  
1492  /**
1493   Return true if one can post a comment to the current resource.
1494  
1495   @proto function pxCtEnabled
1496   @return bool True if possible to post a comment
1497  
1498  */
1499  function pxCtEnabled()
1500  {
1501      return $GLOBALS['_PX_render']['ct_enabled'];
1502  }
1503  
1504  
1505  /**
1506   Display the author of the comment.
1507  
1508   @proto function pxCtAuthor
1509   @param string s Substitution string ('%s')
1510   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1511  
1512  */
1513  function pxCtAuthor($s='%s', $return=false)
1514  {
1515      $result = sprintf($s, htmlspecialchars($GLOBALS['_PX_render']['ct']->f('comment_author')));
1516      if ($return) return $result;
1517      echo $result;
1518  }
1519  
1520  /**
1521   Display the email of the author of the comment.
1522  
1523   @proto function pxCtEmail
1524   @param string s Substitution string ('%s')
1525   @param string encoding Encoding for a mailto ('link') or for display 'text'
1526   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1527  
1528  */
1529  function pxCtEmail($s='%s', $encoding='link', $return=false)
1530  {
1531      $text = ($encoding == 'link') ? false : true;
1532      $result = '';
1533      if (strlen($GLOBALS['_PX_render']['ct']->f('comment_email'))) {
1534          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['ct']->f('comment_email'), $text));
1535      }
1536      if ($return) return $result;
1537      echo $result;
1538  }
1539  
1540  /**
1541   Display the web of the author of the comment.
1542  
1543   @proto function pxCtWeb
1544   @param string s Substitution string ('%s')
1545   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1546  
1547  */
1548  function pxCtWeb($s='%s', $return=false)
1549  {
1550      $result = '';
1551      if (strlen($GLOBALS['_PX_render']['ct']->f('comment_website'))) {
1552          $result = sprintf($s, htmlspecialchars($GLOBALS['_PX_render']['ct']->f('comment_website')));
1553      }
1554      if ($return) return $result;
1555      echo $result;
1556  }
1557  
1558  /**
1559   Display the content of the comment.
1560  
1561   @proto function pxCtContent
1562   @param string Substitution string ('<span class="px-comment">%s</span>')
1563   @param string Format of the content ('safe') or 'textarea'
1564   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1565  
1566  */
1567  function pxCtContent($s='<span class="px-comment">%s</span>', $format='safe',
1568                       $return=false)
1569  {
1570      $result = '';
1571      $content = $GLOBALS['_PX_render']['ct']->getContent($format);
1572      if (strlen($content) > 0) {
1573          $result = sprintf($s, $content);
1574      }
1575      if ($return) return $result;
1576      echo $result;
1577  }
1578  
1579  /**
1580   Display the comment errors if any.
1581  
1582   @proto function pxCtErrors
1583   @param string Substitution string ('%s')
1584   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1585  
1586  */
1587  function pxCtErrors($s='%s', $return=false)
1588  {
1589      if (false !== ($result = $GLOBALS['_PX_render']['ct']->error(true, false))) {
1590          $result = sprintf($s, $result);
1591          if ($return) return $result;
1592          echo $result;
1593      }
1594  }
1595  
1596  /**
1597   Display the action to post a comment.
1598  
1599   @proto function pxCtAction
1600  
1601  */
1602  function pxCtAction()
1603  {
1604      $url = pxInfo('url', true);
1605      $base = '';
1606      if (config::f('url_format') == 'simple') {
1607          $base .= '?/';
1608      }
1609      echo $url.$base.'comments/'.$GLOBALS['_PX_render']['res_id'].'/';
1610  }
1611  
1612  /**
1613   Display the redirection URL
1614  
1615   @proto function pxCtRedirect
1616  
1617  */
1618  function pxCtRedirect($return=false)
1619  {
1620      if (isset($GLOBALS['_PX_render']['ct_redirect'])) {
1621          echo $GLOBALS['_PX_render']['ct_redirect'];
1622      } else {
1623          echo www::getRequestUri();
1624      }
1625  }
1626  
1627  /**
1628   Display some special fields to kill a little more spam.
1629  
1630   @proto function pxCtSpamControl
1631  */
1632  function pxCtSpamControl()
1633  {
1634      $twister = md5($_SERVER["REMOTE_ADDR"].time().config::f('secret_key').$GLOBALS['_PX_render']['res_id']);
1635      echo '<input type=\'hidden\' name=\'twister\' value=\''.$twister.'\' />';
1636      $fieldname = md5(config::f('secret_key').$twister);
1637      echo '<input type=\'hidden\' name=\''.$fieldname.'\' value=\''.time().'\' />';    
1638  }
1639  
1640  
1641  /**
1642   @proto doc
1643  
1644   !! The news functions
1645  
1646   These functions are to be used in the ''news'' templates.
1647  
1648  */
1649  
1650  /**
1651   Display the title of a news.
1652  
1653   @proto function pxNewsTitle
1654   @param string s Substitution string ('%s')
1655   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1656  
1657  */
1658  function pxNewsTitle($s='%s', $return=false)
1659  {
1660      $result = $GLOBALS['_PX_render']['news']->getTextContent('title');
1661      if (config::fbool('remove_numbers')) {
1662         $result = px_removeNumbers($result);
1663      }
1664      $result = sprintf($s, $result);
1665      if ($return) return $result;
1666      echo $result;
1667  }
1668  
1669  /**
1670   Display the content of a news.
1671  
1672   @proto function pxNewsContent
1673   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1674  */
1675  function pxNewsContent($return=false)
1676  {
1677      $result = text::parseContent($GLOBALS['_PX_render']['news']->f('description'));
1678      
1679      if ($return) return $result;
1680      echo $result;
1681  }
1682  
1683  /**
1684   Display the keywords or subject of the news.
1685  
1686   @proto function pxNewsKeywords
1687   @param string s Substitution string ('%s')
1688   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1689  */
1690  function pxNewsKeywords($s = '%s', $return=false)
1691  {
1692      $result = '';
1693      $keywords = trim($GLOBALS['_PX_render']['news']->f('subject'));
1694      if (strlen($keywords) > 0) {
1695          $result = sprintf($s, $keywords);
1696      }
1697      
1698      if ($return) return $result;
1699      echo $result;
1700  }
1701  
1702  /**
1703   Display the creation date of the news.
1704  
1705   The substitution string for the date is directly given to
1706   [strftime|http://www.php.net/strftime]
1707  
1708   @proto function pxNewsDateCreation
1709   @param string dateformat Format of the date ('%A %e %B %Y')
1710   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1711  
1712  */
1713  function pxNewsDateCreation($dateformat='%A %e %B %Y', $return=false)
1714  {
1715      $result = strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('creationdate')));
1716      
1717      if ($return) return $result;
1718      echo $result;
1719  }
1720  
1721  /**
1722   Display the publication date of the news.
1723  
1724   The substitution string for the date is directly given to
1725   [strftime|http://www.php.net/strftime]
1726  
1727   @proto function pxNewsDatePublication
1728   @param string dateformat Format of the date ('%A %e %B %Y')
1729   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1730  
1731  */
1732  function pxNewsDatePublication($dateformat='%A %e %B %Y', $return=false)
1733  {
1734      $result = strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('publicationdate')));
1735      
1736      if ($return) return $result;
1737      echo $result;
1738  }
1739  
1740  /**
1741   Display the modification date of the news. Only if newer than the
1742   publication date.
1743  
1744   The substitution string for the date is directly given to
1745   [strftime|http://www.php.net/strftime]
1746  
1747   @proto function pxNewsDateModification
1748   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1749   @param string s Substitution ('Modified the %s.')
1750   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
1751   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1752  */
1753  function pxNewsDateModification($dateformat='%A %e %B %Y', $s='Modified the %s.',
1754                                      $ifmodified=false, $return=false)
1755  {
1756      $result = '';
1757      if (false !== $ifmodified) {
1758          $ifmodified = $ifmodified * 60;
1759          $md = date::unix($GLOBALS['_PX_render']['news']->f('modifdate'));
1760          $pd = date::unix($GLOBALS['_PX_render']['news']->f('publicationdate'));
1761          if ($md > ($ifmodified + $pd)) {
1762              $result = sprintf($s, strftime($dateformat, $md));
1763          }
1764      } else {
1765          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('modifdate'))));
1766      }
1767      
1768      if ($return) return $result;
1769      echo $result;
1770  }
1771  
1772  /**
1773   Display the date of end of availaibility of the news. Only if end date.
1774  
1775   The substitution string for the date is directly given to
1776   [strftime|http://www.php.net/strftime]
1777  
1778   @proto function pxNewsDateEnd
1779   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1780   @param string s Substitution ('End the %s.')
1781   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1782  */
1783  function pxNewsDateEnd($dateformat='%A %e %B %Y', $s='End the %s.', $return=false)
1784  {
1785      $result = '';
1786      $y = substr($GLOBALS['_PX_render']['news']->f('enddate'),0,4);
1787      if ((int)$y < 9999) {
1788          $result = sprintf($s, strftime($dateformat , date::unix($GLOBALS['_PX_render']['news']->f('enddate'))));
1789      }
1790      
1791      if ($return) return $result;
1792      echo $result;
1793  }
1794  
1795  /**
1796   Display the name of the author
1797  
1798   @proto function pxNewsAuthor
1799   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1800  */
1801  function pxNewsAuthor($return=false)
1802  {
1803      $result = $GLOBALS['_PX_render']['news']->authors->f('user_realname');
1804      
1805      if ($return) return $result;
1806      echo $result;
1807  }
1808  
1809  /**
1810   Display the author public email if available.
1811  
1812   @proto function pxNewsAuthorEmail
1813   @param string s Substitution string ('%s')
1814   @param string encoding Encoding for a mailto ('link') or for display 'text'
1815   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1816  */
1817  function pxNewsAuthorEmail($s='%s', $encoding='link', $return=false)
1818  {
1819      $result = '';
1820      $text = ($encoding == 'link') ? false : true;
1821      if (strlen($GLOBALS['_PX_render']['news']->authors->f('user_pubemail')) > 0) {
1822          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['news']->authors->f('user_pubemail'), $text));
1823      }
1824      
1825      if ($return) return $result;
1826      echo $result;
1827  }
1828  
1829  /**
1830   Display the path to the news.
1831  
1832   @proto function pxNewsPath
1833   @param string type 'fullurl' give path with http:// ('relative')
1834   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1835  */
1836  function pxNewsPath($type='relative', $return=false)
1837  {
1838      $result = $GLOBALS['_PX_render']['news']->getPath($type);
1839      
1840      if ($return) return $result;
1841      echo $result;
1842  }
1843  
1844  /**
1845   Display the list of categories in which the news is.
1846  
1847   The list is not an HTML list, it is to be used as sentence like
1848   "Category one, category two and category tree" The category names
1849   are linked to the category pages.
1850  
1851   @proto function pxNewsCategories
1852   @param string s Substitution string ('%s')
1853   @param string p1 First delimiters (', ')
1854   @param string p2 Last delimiter (' and ')
1855   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1856  */
1857  function pxNewsCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1858  {
1859      $cat = $GLOBALS['_PX_render']['news']->cats;
1860      $nr = $cat->nbRow();
1861      $i = 1;
1862      $link = '<a href="%s">%s</a>';
1863      $res = '';
1864      $remove_numbers = config::fbool('remove_numbers');
1865      while (!$cat->EOF()) {
1866          $title = $cat->f('category_name');
1867          if ($remove_numbers) $title = px_removeNumbers($title);
1868          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1869          if ($nr >= 2 && ($i < ($nr - 1))) {
1870              $res .= $p1;
1871          }
1872          if ($nr >= 2 && ($i == ($nr - 1))) {
1873              $res .= $p2;
1874          }
1875          $i++;
1876          $cat->moveNext();
1877      }
1878      $result = sprintf($s, $res);
1879      
1880      if ($return) return $result;
1881      echo $result;
1882  }
1883  
1884  
1885  /**
1886   Display the associated link and title if available. 
1887  
1888   @proto function pxNewsAssociatedLink
1889   @param string s Substitution string ('<a href="%1$s">%2$s</a>')
1890   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1891  */
1892  function pxNewsAssociatedLink($s='<a href="%1$s">%2$s</a>', $return=false)
1893  {
1894      $result = '';
1895      if ($GLOBALS['_PX_render']['news']->f('type_id') == 'news') {
1896          $GLOBALS['_PX_render']['news']->loadDetails();
1897          if (strlen($GLOBALS['_PX_render']['news']->details->f('news_titlewebsite')) > 0) {
1898              $result = sprintf($s, $GLOBALS['_PX_render']['news']->details->f('news_linkwebsite'), $GLOBALS['_PX_render']['news']->details->f('news_titlewebsite'));
1899          }
1900      }
1901      if ($return) return $result;
1902      echo $result;
1903  }
1904  
1905  /**
1906   Display the number of comments of the news.
1907  
1908   @proto function pxArtCountComments
1909   @param boolean return Type of return : true return result as a string, false (default) print in stdout
1910  */
1911  function pxNewsCountComments($return=false)
1912  {
1913      $result = $GLOBALS['_PX_render']['news']->countComments();
1914      if ($return) return $result;
1915      echo $result;
1916  }
1917  
1918  
1919  
1920  /**
1921   * Display the content of a category
1922   *
1923   * @credits Nicolas LASSALLE.
1924   *
1925   * @param String category the current category to display
1926   * @param int limit Number of last resources (10)
1927   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
1928   */
1929  function pxSitemapShowCatContent($vals, $type, $limit)
1930  {
1931      $cat = $vals['id'];
1932      $res = FrontEnd::getResources($cat, $limit, $type);
1933     
1934      if ($res->EOF()) {
1935          $path = $vals['path'];
1936          echo sprintf('<li><a href="%s">%s</a></li>'."\n", $path,
1937                       __('Show the category content'));
1938      } else {
1939          while (!$res->EOF()) {
1940              echo sprintf('<li><a href="%s">%s</a></li>'."\n", $res->getPath(), 
1941                           px_removeNumbers($res->getTextContent('title')));
1942           $res->moveNext();
1943          }
1944      }
1945  }
1946  
1947  /**
1948   * Returns subcategories of a Category
1949   * 
1950   * @credits Nicolas LASSALLE.
1951   *
1952   * @param string category the category we want the subdirectories
1953   *
1954   * @return array
1955   */
1956  function pxSitemapCategoriesList($categoryId)
1957  {
1958      $list = array();
1959      $ordermanual = config::fbool('order_cat_manual');
1960      $remove_numbers = config::fbool('remove_numbers');
1961      $order = 'ORDER BY category_path';
1962      if ($ordermanual) {
1963          $order = 'ORDER BY category_name';
1964      }
1965      $prim    = FrontEnd::getCategories($categoryId, $order);
1966  
1967      $cats = '';
1968      while (!$prim->EOF()) {
1969          if ($prim->f('category_path') != '/') {
1970              $path = $prim->getPath();
1971              $name = $prim->f('category_name');
1972              if ($remove_numbers) {
1973                  $name = px_removeNumbers($name);
1974              }
1975              $list[htmlspecialchars($name)] = array('path' => $path, 
1976                                                     'desc' => $prim->f('category_description'),
1977                                                     'parentid' => $prim->f('category_parentid'),
1978                                                     'id' => $prim->f('category_id'));
1979          }
1980          $prim->moveNext();
1981      }
1982      return $list;
1983  }
1984  
1985  
1986  /**
1987   * return the content of a category title without the html tag 
1988   * (no <hx> or <li>)
1989   *
1990   * @credits Nicolas LASSALLE.
1991   *
1992   * @return the title to display
1993   */
1994  function pxSitemapGetCatTitle($name, $vals) 
1995  {
1996      $rootcat = FrontEnd::getCategory('/');
1997      $rootcatid = $rootcat->f('category_id');
1998      if ($vals['parentid'] == $rootcatid) {
1999          return sprintf('<a href="%s">%s</a></h3>'."\n".'<p>%s</p>'."\n",
2000                         $vals['path'], $name,
2001                          strip_tags(trim(text::parseContent($vals['desc']))),$name);
2002      } else {
2003          return sprintf('<a href="%s">%s</a>'."\n".'<p>%s</p>'."\n",
2004                         $vals['path'], $name,
2005                          strip_tags(trim(text::parseContent($vals['desc']))),$name);
2006      }
2007  }
2008  
2009  /**
2010   * Display a sitemap for a category
2011   *
2012   * @credits Nicolas LASSALLE.
2013   *
2014   * @param String category the current category to display
2015   * @param int limit Number of last resources (10)
2016   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
2017   */
2018  function pxSitemapShowCategory ($category, $type, $limit) 
2019  {
2020      $list = pxSitemapCategoriesList($category); 
2021      while (list($name, $vals) = each ($list)) {
2022          echo sprintf('<li class="subcatlism">%s </li>'."\n",  pxSitemapGetCatTitle($name, $vals)); 
2023          echo '<li class="nodeco"><ul>'."\n";
2024          pxSitemapShowCatContent($vals, $type, $limit);
2025          pxSitemapShowCategory($vals['id'], $type, $limit);
2026          echo '</ul></li>'."\n";
2027      }
2028  }
2029  
2030  /**
2031   * Display a sitemap for a primary category
2032   *
2033   * @credits Nicolas LASSALLE.
2034   *
2035   * @param String category the current category to display
2036   * @param int limit Number of last resources (10)
2037   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
2038   */
2039  function pxSitemapShowPrimaryCategory ($category, $type, $limit) 
2040  {
2041      $list = pxSitemapCategoriesList($category);
2042      while (list($name, $vals) = each ($list)) {
2043          echo sprintf('<h3>%s'."\n",  pxSitemapGetCatTitle($name,
2044  $vals));
2045          echo '<ul>'."\n";
2046          pxSitemapShowCatContent($vals, $type, $limit);
2047          pxSitemapShowCategory($vals['id'], $type, $limit);
2048          echo '</ul>'."\n";
2049      }
2050  }
2051  
2052  
2053  /**
2054   * Display the sitemap
2055   *
2056   * @credits Nicolas LASSALLE.
2057   *
2058   * @param int limit Number of last resources (10)
2059   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
2060   */
2061  function pxShowSitemap($type='all', $limit='10') 
2062  {
2063      if ($type == 'all') {
2064          $type = '';
2065      }
2066      $rootcat = FrontEnd::getCategory('/');
2067      pxSitemapShowPrimaryCategory ($rootcat->f('category_id'), $type, $limit, 0);
2068  }
2069  
2070  
2071  /**
2072   Remove the numbers at the start of a string
2073  
2074   @param string string
2075   @return string
2076   @private
2077  */
2078  function px_removeNumbers($string)
2079  {
2080      return preg_replace('/^\s*\d+\.\s*/', '', $string);
2081  }
2082  
2083  
2084  
2085  
2086  /**
2087   * Initialisation of the template, it loads all the other librairies. 
2088   * Needed only if the page is not cached, else we try to load the minimum.
2089   *
2090   * @param string Parameters for the template
2091   */
2092  function pxTemplateInit($params='')
2093  {
2094      $aparams = explode('|', $params);
2095      foreach ($aparams as $param) {
2096          if (strpos($param, ':')) {
2097              list($key, $val) = explode(':', $param);
2098              config::setVar(trim($key), trim($val));
2099          } else {
2100              config::setVar(trim($param), true);
2101          }
2102      }
2103  
2104      setlocale(LC_ALL, strtolower(config::f('lang')));
2105      Hook::run('onInitTemplate');
2106  }
2107  
2108  /**
2109   * Set of methods useful for the action method of the resource classes.
2110   *
2111   * All the methods are 'standalone' methods.
2112   */
2113  class FrontEnd
2114  {
2115      /**
2116       * Get the resources for the category.
2117       *
2118       * Set the correct position with respect
2119       * to the number of resources in one page.
2120       *
2121       * @param int Category id ('') default is current category
2122       * @param int Number of resources per page (10)
2123       * @param string Type of resources to limit to ('')
2124       * @param int Page number for the pagination (1)
2125       * @param string Optional order ('ORDER BY %sresources.publicationdate DESC')
2126       * @return mixed false or ResourceSet
2127       */
2128      function getResources($category='', $limit=10, $type='', $page=1,
2129                            $order='ORDER BY %sresources.publicationdate DESC')
2130      {
2131          if ('' == $category) {
2132              $sql = SQL::getResources();
2133          } else {
2134              $sql = SQL::getResourcesInCat($category);
2135          }
2136          $con =& pxDBConnect();
2137          $order = sprintf($order, $con->pfx);
2138  
2139          $sql .= ' AND '.$con->pfx.'resources.website_id=\''
2140              .$con->esc(config::f('website_id')).'\''."\n";
2141          $sql .= ' AND '.$con->pfx.'resources.status=\''
2142              .PX_RESOURCE_STATUS_VALIDE.'\''."\n";
2143          if ('' != $type) {
2144              $sql .= ' AND '.$con->pfx.'resources.type_id=\''
2145                  .$con->esc($type).'\''."\n";
2146          }
2147          $sql .= ' AND '.$con->pfx.'resources.publicationdate <= '
2148              .date::stamp();
2149          $sql .= ' AND '.$con->pfx.'resources.enddate >= '.date::stamp();
2150          $sql .= ' '.$order;
2151  
2152          if (($rs = $con->select($sql, 'Paginator', $limit, $page)) === false) {
2153              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 
2154                                                        500);
2155              return false;
2156          }
2157          return $rs;
2158      }
2159  
2160  
2161      /** 
2162       * Get a category by id or path.
2163       *
2164       * @param mixed Id as int or path as string
2165       * @return mixed Category or false
2166       */
2167      function getCategory($cat)
2168      {
2169          if (preg_match('/^[0-9]+$/', $cat)) {
2170              $sql = SQL::getCategoryById($cat);
2171          } else {
2172              $sql = SQL::getCategoryByPath($cat, config::f('website_id'));
2173          }
2174  
2175          $con =& pxDBConnect();
2176          if (($rs = $con->select($sql, 'Category')) !== false) {
2177              return $rs;
2178          } else {
2179              $GLOBALS['_PX_render']['error']->setError('MySQL: '
2180                                                        .$this->con->error(), 
2181                                                        500);
2182              return false;
2183          }
2184      }
2185  
2186      /**
2187       * Get categories.
2188       *
2189       * Limit to ones have a given parent, order in a given order.
2190       *
2191       * @param int Parent id ('') no limit by default
2192       * @param string Order ('ORDER BY category_path')
2193       * @return Category or false
2194       */
2195      function getCategories($parentid='', $order='ORDER BY category_path')
2196      {
2197          $con =& pxDBConnect();
2198          $sql = 'SELECT * FROM '.$con->pfx.'categories '
2199              .'LEFT JOIN '.$con->pfx.'websites 
2200               ON '.$con->pfx.'websites.website_id='
2201              .$con->pfx.'categories.website_id '
2202              .'WHERE '.$con->pfx.'categories.website_id=\''
2203              .$con->esc(config::f('website_id')).'\'';
2204          if (!empty($parentid)) {
2205              $sql .= ' AND category_parentid=\''.$con->esc($parentid).'\'';
2206          }
2207          $sql .= ' AND category_path NOT LIKE \'%/\\_%\'';
2208          $sql .= ' '.$order;
2209          if (($rs = $con->select($sql, 'Category')) !== false) {
2210              return $rs;
2211          } else {
2212              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 
2213                                                        500);
2214              return false;
2215          }
2216  
2217      }
2218  
2219  
2220  
2221      /**
2222       * Get the website data.
2223       *
2224       * @param string Website id ('') current by default
2225       * @return mixed RecordSet or false in case of error
2226       */
2227      function getWebsite($website='')
2228      {
2229          if ('' == $website) {
2230              $website = config::f('website_id');
2231          }
2232          $sql = SQL::getWebsite($website);
2233          $con =& pxDBConnect();
2234          if (($rs = $con->select($sql)) !== false) {
2235              return $rs;
2236          } else {
2237              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 500);
2238              return false;
2239          }
2240      }
2241  
2242      /**
2243       * Get extra header from the template extension.
2244       *
2245       * @param string Template file
2246       * @return string Extra header to send
2247       */
2248  	function getHeader($template)
2249      {
2250          $ext = strtolower(substr(strrchr($template, '.'), 1));
2251          $encoding = strtolower(config::f('encoding'));
2252          $headers = array(
2253            'htm'   => 'text/html; charset='.$encoding,
2254            'html'  => 'text/html; charset='.$encoding,
2255            'php'   => 'text/html; charset='.$encoding,
2256            'xhtml' => 'application/xhtml+xml; charset='.$encoding,
2257            'txt'   => 'text/plain; charset='.$encoding,
2258            'rss'   => 'text/xml; charset='.$encoding,
2259            'rdf'   => 'text/xml; charset='.$encoding,
2260            'xml'   => 'text/xml; charset='.$encoding,
2261            'atom'  => 'application/atom+xml; charset=utf-8',
2262          );
2263          if (!empty($headers[$ext])) {
2264              return sprintf('Content-Type: %s', $headers[$ext]);
2265          }
2266          return '';
2267      }
2268  }
2269  
2270  /**
2271   Display the description of the current category in the meta description.
2272  
2273   @proto function pxMetasDescription
2274   @param boolean return Type of return : true return result as a string, false (default) print in stdout
2275  */
2276  function pxMetasDescription($return='')
2277  {
2278      $result = strip_tags(text::parseContent($GLOBALS['_PX_render']['cat']->f('category_description')),"");
2279      $result = str_replace("\n","",$result);
2280      
2281      if ($return) return $result;
2282      echo $result;
2283  }
2284  
2285  /**
2286   Display the translated string according to the langague set up in manager.
2287   If no translation founds, return the string parameter.
2288  
2289   @proto function pxTrans
2290   @param boolean return Type of return : true return result as a string, false (default) print in stdout
2291  */
2292  function pxTrans($str, $return=false)
2293  {
2294      $result = __($str);
2295      
2296      if ($return) return $result;
2297      echo $result;
2298  }
2299  ?>

title

Description

title

Description

title

Description

title

title

Body