[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/inc/ -> lib.frontend.php (source)

   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 'full' 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   @proto doc
 812  
 813   !! The $last loop
 814  
 815   This loop is available in all the templates, you just have to initialize it
 816   before use:
 817  
 818  |<?php pxGetLastResources(); ?>
 819  |<?php while (!$last->EOF()): ?>
 820  |    <p><a href="<?php pxLastResPath(); ?>"><?php pxLastResTitle(); ?></a></p>
 821  |<?php
 822  |$last->moveNext();
 823  |endwhile; ?>
 824  
 825  */
 826  
 827  /**
 828   * Get the list of last resources and put them in $last
 829   * Must be run before using the $last loop
 830   *
 831   * @proto function pxGetLastResources
 832   * @param int limit Number of last resources (5)
 833   * @param string type Type of resources ('') for all, 'news' or 'articles'
 834   * @param int category Category id ('')
 835   * @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 836   */
 837  function pxGetLastResources($limit=5, $type='', $category='', $return=false) 
 838  {
 839      $result = $GLOBALS['_PX_render']['last'] = FrontEnd::getResources($category, 
 840                          $limit, $type, 1);
 841      if ($return) return $result;
 842  }
 843  
 844  /**
 845   Display the title of the resource.
 846  
 847   @proto function pxLastResTitle
 848   @param string s Substitution string ('%s')
 849   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 850  
 851  */
 852  function pxLastResTitle($s='%s', $return=false)
 853  {
 854      $remove_numbers = (config::f('remove_numbers')) ? true : false;
 855      $title = $GLOBALS['_PX_render']['last']->getTextContent('title');
 856      if ($remove_numbers) 
 857          $title = px_removeNumbers($title);
 858      $result = sprintf($s, $title);
 859      if ($return) return $result;
 860      echo $result;
 861  }
 862  
 863  /**
 864   Display the path to the resource.
 865  
 866   @proto function pxLastResPath
 867   @param string type If 'full' give path with http:// ('relative')
 868   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 869  
 870  */
 871  function pxLastResPath($type='relative', $return=false)
 872  {
 873      $result = $GLOBALS['_PX_render']['last']->getPath($type);
 874      
 875      if ($return) return $result;
 876      echo $result;
 877  }
 878  
 879  /**
 880   Display the description of the resource.
 881  
 882   @proto function pxLastResDescription
 883   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 884  
 885  */
 886  function pxLastResDescription($return=false)
 887  {
 888      $result = text::parseContent($GLOBALS['_PX_render']['last']->f('description'));
 889      
 890      if ($return) return $result;
 891      echo $result;
 892  }
 893  
 894  /**
 895   Display the name of the author
 896  
 897   @proto function pxLastResAuthor
 898   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 899  */
 900  function pxLastResAuthor($return=false)
 901  {
 902      $result = $GLOBALS['_PX_render']['last']->extf('authors', 'user_realname');
 903      
 904      if ($return) return $result;
 905      echo $result;
 906  }
 907  
 908  /**
 909   Display the author public email if available.
 910  
 911   @proto function pxLastResAuthorEmail
 912   @param string s Substitution string ('%s')
 913   @param string encoding Encoding for a mailto ('link') or for display 'text'
 914   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 915  */
 916  function pxLastResAuthorEmail($s='%s', $encoding='link', $return=false)
 917  {
 918      $result = '';
 919      $text = ($encoding == 'link') ? false : true;
 920      if (strlen($GLOBALS['_PX_render']['last']->extf('authors', 'user_pubemail')) > 0) {
 921          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['last']->extf('authors', 'user_pubemail'), $text));
 922      }
 923      
 924      if ($return) return $result;
 925      echo $result;
 926  }
 927  
 928  /**
 929   Display the modification date of the resource.
 930  
 931   @proto function pxLastResDateModification
 932   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 933   @param string s Substitution string ('%s')
 934   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
 935   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 936  */
 937  function pxLastResDateModification($dateformat='%Y-%m-%dT%H:%M:%S+00:00', 
 938                                     $s='%s', $ifmodified=false, $return=false)
 939  {
 940      $result = '';
 941      if ($ifmodified !== false) {
 942          $pd = date::unix($GLOBALS['_PX_render']['last']->f('publicationdate'));
 943          $md = date::unix($GLOBALS['_PX_render']['last']->f('modifdate'));
 944          $ifmodified = 60 * (int) $ifmodified;
 945          if ($md > ($pd + $ifmodified)) {
 946              $result = sprintf($s, strftime($dateformat, $md));
 947          }
 948      } else {
 949          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['last']->f('modifdate'))));
 950      }
 951      if ($return) return $result;
 952      echo $result;
 953  }
 954  
 955  /**
 956   Display the publication date of the last resource.
 957  
 958   @proto function pxLastResDatePublication
 959   @param string dateformat Format of the date ('%Y-%d-%mT%T+00:00')
 960   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 961  */
 962  function pxLastResDatePublication($dateformat='%Y-%m-%dT%H:%M:%S+00:00', $return=false)
 963  {
 964      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['last']->f('publicationdate')));
 965      
 966      if ($return) return $result;
 967      echo $result;
 968  }
 969  
 970  /**
 971   Display the associated link and title if available. When getting the last
 972   resources, if the 'news' type is chose as link can be associated to
 973   news, this is the way to get it back if available.
 974  
 975   @proto function pxLastResAssociatedLink
 976   @param string s Substitution string ('<a href="%1$s">%2$s</a>')
 977   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
 978  */
 979  function pxLastResAssociatedLink($s='<a href="%1$s">%2$s</a>', $return=false)
 980  {
 981      $result = '';
 982      if ($GLOBALS['_PX_render']['last']->f('type_id') == 'news') {
 983          $GLOBALS['_PX_render']['last']->cur->loadDetails();
 984          if (strlen($GLOBALS['_PX_render']['last']->cur->details->f('news_titlewebsite')) > 0) {
 985              $result = sprintf($s, $GLOBALS['_PX_render']['last']->cur->details->f('news_linkwebsite'), $GLOBALS['_PX_render']['last']->cur->details->f('news_titlewebsite'));
 986          }
 987      }
 988      if ($return) return $result;
 989      echo $result;
 990  }
 991  
 992  /**
 993   Display the list of categories in which the last ressource is.
 994  
 995   The list is not an HTML list, it is to be used as sentence like
 996   "Category one, category two and category tree" The category names
 997   are linked to the category pages.
 998  
 999   @proto function pxLastResCategories
1000   @param string s Substitution string ('%s')
1001   @param string p1 First delimiters (', ')
1002   @param string p2 Last delimiter (' and ')
1003   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1004  */
1005  function pxLastResCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1006  {
1007      $remove_numbers = config::fbool('remove_numbers');
1008      $cat = $GLOBALS['_PX_render']['last']->cur->cats;
1009      $nr = $cat->nbRow();
1010      $i = 1;
1011      $link = '<a href="%s">%s</a>';
1012      $res = '';
1013      while (!$cat->EOF()) {
1014          $title = $cat->f('category_name');
1015          if ($remove_numbers) $title = px_removeNumbers($title);
1016          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1017          if ($nr >= 2 && ($i < ($nr - 1))) {
1018              $res .= $p1;
1019          }
1020          if ($nr >= 2 && ($i == ($nr - 1))) {
1021              $res .= $p2;
1022          }
1023          $i++;
1024          $cat->moveNext();
1025      }
1026      $result = sprintf($s, $res);
1027      
1028      if ($return) return $result;
1029      echo $result;
1030  }
1031  
1032  
1033  /**
1034   @proto doc
1035  
1036   !!! The resource functions
1037  
1038   These are functions to display information about the current resource in the
1039   page. For the moment the resource can be either an __article__ or a __news__.
1040  
1041   !! The article functions
1042  
1043   These functions are to be used in the ''article'' templates.
1044  
1045  */
1046  
1047  
1048  /**
1049   Display the title of the article.
1050  
1051   @proto function pxArtTitle
1052   @param string s Substitution string ('%s')
1053   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1054  
1055  */
1056  function pxArtTitle($s='%s', $return=false)
1057  {
1058      $title = $GLOBALS['_PX_render']['art']->getTextContent('title');
1059      if (config::fbool('remove_numbers')) 
1060          $title = px_removeNumbers($title);
1061      $result = sprintf($s, $title);
1062      
1063      if ($return) return $result;
1064      echo $result;
1065  }
1066  
1067  /**
1068   Display the description of the article.
1069  
1070   @proto function pxArtDescription
1071   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1072  */
1073  function pxArtDescription($return=false)
1074  {
1075      $result = text::parseContent($GLOBALS['_PX_render']['art']->f('description'));
1076      
1077      if ($return) return $result;
1078      echo $result;
1079  }
1080  
1081  /**
1082   Display the name of the author
1083  
1084   @proto function pxArtAuthor
1085   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1086  */
1087  function pxArtAuthor($return=false)
1088  {
1089      $result = $GLOBALS['_PX_render']['art']->authors->f('user_realname');
1090      
1091      if ($return) return $result;
1092      echo $result;
1093  }
1094  
1095  /**
1096   Display the path to the article.
1097  
1098   @proto function pxArtPath
1099   @param string type 'full' give path with http:// ('relative')
1100   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1101  */
1102  function pxArtPath($type='relative', $return=false)
1103  {
1104      $result = $GLOBALS['_PX_render']['art']->getPath($type);
1105      
1106      if ($return) return $result;
1107      echo $result;
1108  }
1109  
1110  /**
1111   Display the author public email if available.
1112  
1113  @proto function pxArtAuthorEmail
1114  @param string s Substitution string ('%s')
1115  @param string encoding Encoding for a mailto ('link') or for display 'text'
1116  @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1117  */
1118  function pxArtAuthorEmail($s='%s', $encoding='link', $return=false)
1119  {
1120      $result = '';
1121      $text = ($encoding == 'link') ? false : true;
1122      if (strlen($GLOBALS['_PX_render']['art']->authors->f('user_pubemail')) > 0) {
1123          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['art']->authors->f('user_pubemail'), $text));
1124      }
1125      
1126      if ($return) return $result;
1127      echo $result;
1128  }
1129  
1130  /**
1131   Display the creation date of the article.
1132  
1133   The substitution string for the date is directly given to
1134   [strftime|http://www.php.net/strftime]
1135  
1136   @proto function pxArtDateCreation
1137   @param string dateformat Format of the date ('%A %e %B %Y')
1138   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1139  
1140  */
1141  function pxArtDateCreation($dateformat='%A %e %B %Y', $return=false)
1142  {
1143      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('creationdate')));
1144      
1145      if ($return) return $result;
1146      echo $result;
1147  }
1148  
1149  /**
1150   Display the publication date of the article.
1151  
1152   The substitution string for the date is directly given to
1153   [strftime|http://www.php.net/strftime]
1154  
1155   @proto function pxArtDatePublication
1156   @param string dateformat Format of the date ('%A %e %B %Y')
1157   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1158  
1159  */
1160  function pxArtDatePublication($dateformat='%A %e %B %Y', $return=false)
1161  {
1162      $result = strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('publicationdate')));
1163      
1164      if ($return) return $result;
1165      echo $result;
1166  }
1167  
1168  /**
1169   Display the modification date of the article. Only if newer than the
1170   publication date.
1171  
1172   The substitution string for the date is directly given to
1173   [strftime|http://www.php.net/strftime]
1174  
1175   @proto function pxArtDateModification
1176   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1177   @param string s Substitution ('Modified the %s.')
1178   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
1179   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1180  */
1181  function pxArtDateModification($dateformat='%A %e %B %Y', 
1182                                 $s='Modified the %s.', $ifmodified=false, $return=false)
1183  {
1184      $result = '';
1185      if (false !== $ifmodified) {
1186          $ifmodified = 60 * $ifmodified;
1187          $md = date::unix($GLOBALS['_PX_render']['art']->f('modifdate'));
1188          $pb = date::unix($GLOBALS['_PX_render']['art']->f('publicationdate'));
1189          if ($md > ($pb + $ifmodified)) {
1190              $result = sprintf($s, strftime($dateformat, $md));
1191          }
1192      } else {
1193          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['art']->f('modifdate'))));
1194      }
1195      
1196      if ($return) return $result;
1197      echo $result;
1198  }
1199  
1200  /**
1201   Display the date of end of availaibility of the article. Only if end date.
1202  
1203   The substitution string for the date is directly given to
1204   [strftime|http://www.php.net/strftime]
1205  
1206   @proto function pxArtDateEnd
1207   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1208   @param string s Substitution ('End the %s.')
1209   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1210  */
1211  function pxArtDateEnd($dateformat='%A %e %B %Y', $s='End the %s.', $return=false)
1212  {
1213      $result = '';
1214      $y = substr($GLOBALS['_PX_render']['art']->f('enddate'), 0, 4);
1215      if ((int)$y < 9999) {
1216          $result = sprintf($s, strftime($dateformat , date::unix($GLOBALS['_PX_render']['art']->f('enddate'))));
1217      }
1218      
1219      if ($return) return $result;
1220      echo $result;
1221  }
1222  
1223  /**
1224   Display the keywords or subject of the article
1225  
1226   @proto function pxArtKeywords
1227   @param string s Substitution string ('%s')
1228   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1229  */
1230  function pxArtKeywords($s='%s', $return=false)
1231  {
1232      $result = '';
1233      $keywords = trim($GLOBALS['_PX_render']['art']->f('subject'));
1234      if (strlen($keywords) > 0) {
1235          $result = sprintf($s, $keywords);
1236      }
1237      
1238      if ($return) return $result;
1239      echo $result;
1240  }
1241  
1242  /**
1243   Display the list of categories in which the article is.
1244  
1245   The list is not an HTML list, it is to be used as sentence like
1246   "Category one, category two and category tree" The category names
1247   are linked to the category pages.
1248  
1249   @proto function pxArtCategories
1250   @param string s Substitution string ('%s')
1251   @param string p1 First delimiters (', ')
1252   @param string p2 Last delimiter (' and ')
1253   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1254  */
1255  function pxArtCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1256  {
1257      $remove_numbers = config::fbool('remove_numbers');
1258      $cat = $GLOBALS['_PX_render']['art']->cats;
1259      $nr = $cat->nbRow();
1260      $i = 1;
1261      $link = '<a href="%s">%s</a>';
1262      $res = '';
1263      while (!$cat->EOF()) {
1264          $title = $cat->f('category_name');
1265          if ($remove_numbers) $title = px_removeNumbers($title);
1266          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1267          if ($nr >= 2 && ($i < ($nr - 1))) {
1268              $res .= $p1;
1269          }
1270          if ($nr >= 2 && ($i == ($nr - 1))) {
1271              $res .= $p2;
1272          }
1273          $i++;
1274          $cat->moveNext();
1275      }
1276      $result = sprintf($s, $res);
1277      
1278      if ($return) return $result;
1279      echo $result;
1280  }
1281  
1282  /**
1283   Return true if the current page is the first page of the article
1284  
1285   @proto function pxArtPageIsFirst
1286   @return bool __true__ if the current page is the first, else __false__
1287  */
1288  function pxArtPageIsFirst()
1289  {
1290      return ((int)$GLOBALS['_PX_render']['art']->pages->f('page_number') == 1);
1291  }
1292  
1293  /**
1294   Display the title of the current article page.
1295  
1296   @proto function pxArtPageTitle
1297   @param string s Substitution string ('%s')
1298   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1299  
1300  */
1301  function pxArtPageTitle($s='%s', $return=false)
1302  {
1303      $result = $GLOBALS['_PX_render']['art']->pages->f('page_title');
1304      $result = str_replace('&', '&amp;', $result);    
1305      $result = sprintf($s, $result);
1306      if ($return) return $result;
1307      echo $result;
1308  }
1309  
1310  /**
1311   Display the content of the current article page.
1312  
1313   @proto function pxArtPageContent
1314   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1315  
1316  */
1317  function pxArtPageContent($return=false)
1318  {
1319      $result = text::parseContent($GLOBALS['_PX_render']['art']->pages->f('page_content'));
1320      
1321      if ($return) return $result;
1322      echo $result;
1323  }
1324  
1325  /**
1326   Display an ordered list of pages in the article with link to the pages.
1327   The current page is set as ''active'' with the corresponding <li> element
1328   being from the __current__ class.
1329  
1330   An output example is:
1331  
1332  |<ol>
1333  |<li><a href="/cat/my-article">Page 1</a></li>
1334  |<li class="current"><a href="/cat/my-article2">Page 2</a></li>
1335  |<li><a href="/cat/my-article3">Page 3</a></li>
1336  |</ol>
1337  
1338   @proto function pxArtListPages
1339   @param string s Substitution string ('%s')
1340   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1341  
1342  */
1343  function pxArtListPages($s = '%s', $return=false)
1344  {
1345      $result = '';
1346      if ($GLOBALS['_PX_render']['art']->pages->nbRow() > 1) {
1347          $index = $GLOBALS['_PX_render']['art']->pages->getIndex();
1348          $GLOBALS['_PX_render']['art']->pages->moveStart();
1349          $lp = '<ol>'."\n";
1350          while (!$GLOBALS['_PX_render']['art']->pages->EOF()) {
1351              $active = ($index == $GLOBALS['_PX_render']['art']->pages->getIndex()) ? ' class="current"' : '';
1352              $page = ($GLOBALS['_PX_render']['art']->pages->f('page_number') == 1) ? '' : $GLOBALS['_PX_render']['art']->pages->f('page_number');
1353              $lp .= '<li'.$active.'><a href="'.$GLOBALS['_PX_render']['art']->getPath().$page.'">'.$GLOBALS['_PX_render']['art']->pages->getTextContent('page_title').'</a></li>'."\n";
1354              $GLOBALS['_PX_render']['art']->pages->moveNext();
1355          }
1356          $lp .= '</ol>'."\n";
1357          $GLOBALS['_PX_render']['art']->pages->move($index);
1358          $result = sprintf($s, $lp);
1359      }
1360      
1361      if ($return) return $result;
1362      echo $result;
1363  }
1364  
1365  /**
1366   @proto doc
1367  
1368   !! The comments functions
1369  
1370   These functions are to be used in the ''news'' and ''article'' templates.
1371  
1372  */
1373  
1374  /**
1375   Return true if one can post a comment to the current resource.
1376  
1377   @proto function pxCtEnabled
1378   @return bool True if possible to post a comment
1379  
1380  */
1381  function pxCtEnabled()
1382  {
1383      return $GLOBALS['_PX_render']['ct_enabled'];
1384  }
1385  
1386  
1387  /**
1388   Display the author of the comment.
1389  
1390   @proto function pxCtAuthor
1391   @param string s Substitution string ('%s')
1392   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1393  
1394  */
1395  function pxCtAuthor($s='%s', $return=false)
1396  {
1397      $result = sprintf($s, htmlspecialchars($GLOBALS['_PX_render']['ct']->f('comment_author')));
1398      if ($return) return $result;
1399      echo $result;
1400  }
1401  
1402  /**
1403   Display the email of the author of the comment.
1404  
1405   @proto function pxCtEmail
1406   @param string s Substitution string ('%s')
1407   @param string encoding Encoding for a mailto ('link') or for display 'text'
1408   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1409  
1410  */
1411  function pxCtEmail($s='%s', $encoding='link', $return=false)
1412  {
1413      $text = ($encoding == 'link') ? false : true;
1414      $result = '';
1415      if (strlen($GLOBALS['_PX_render']['ct']->f('comment_email'))) {
1416          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['ct']->f('comment_email'), $text));
1417      }
1418      if ($return) return $result;
1419      echo $result;
1420  }
1421  
1422  /**
1423   Display the web of the author of the comment.
1424  
1425   @proto function pxCtWeb
1426   @param string s Substitution string ('%s')
1427   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1428  
1429  */
1430  function pxCtWeb($s='%s', $return=false)
1431  {
1432      $result = '';
1433      if (strlen($GLOBALS['_PX_render']['ct']->f('comment_website'))) {
1434          $result = sprintf($s, htmlspecialchars($GLOBALS['_PX_render']['ct']->f('comment_website')));
1435      }
1436      if ($return) return $result;
1437      echo $result;
1438  }
1439  
1440  /**
1441   Display the content of the comment.
1442  
1443   @proto function pxCtContent
1444   @param string Substitution string ('<span class="px-comment">%s</span>')
1445   @param string Format of the content ('safe') or 'textarea'
1446   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1447  
1448  */
1449  function pxCtContent($s='<span class="px-comment">%s</span>', $format='safe',
1450                       $return=false)
1451  {
1452      $result = '';
1453      $content = $GLOBALS['_PX_render']['ct']->getContent($format);
1454      if (strlen($content) > 0) {
1455          $result = sprintf($s, $content);
1456      }
1457      if ($return) return $result;
1458      echo $result;
1459  }
1460  
1461  /**
1462   Display the comment errors if any.
1463  
1464   @proto function pxCtErrors
1465   @param string Substitution string ('%s')
1466   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1467  
1468  */
1469  function pxCtErrors($s='%s', $return=false)
1470  {
1471      if (false !== ($result = $GLOBALS['_PX_render']['ct']->error(true, false))) {
1472          $result = sprintf($s, $result);
1473          if ($return) return $result;
1474          echo $result;
1475      }
1476  }
1477  
1478  /**
1479   Display the action to post a comment.
1480  
1481   @proto function pxCtAction
1482  
1483  */
1484  function pxCtAction()
1485  {
1486      $url = pxInfo('url', true);
1487      $base = '';
1488      if (config::f('url_format') == 'simple') {
1489          $base .= '?/';
1490      }
1491      echo $url.$base.'comments/'.$GLOBALS['_PX_render']['res_id'].'/';
1492  }
1493  
1494  /**
1495   Display the redirection URL
1496  
1497   @proto function pxCtRedirect
1498  
1499  */
1500  function pxCtRedirect($return=false)
1501  {
1502      if (isset($GLOBALS['_PX_render']['ct_redirect'])) {
1503          echo $GLOBALS['_PX_render']['ct_redirect'];
1504      } else {
1505          echo www::getRequestUri();
1506      }
1507  }
1508  
1509  
1510  
1511  
1512  /**
1513   @proto doc
1514  
1515   !! The news functions
1516  
1517   These functions are to be used in the ''news'' templates.
1518  
1519  */
1520  
1521  /**
1522   Display the title of a news.
1523  
1524   @proto function pxNewsTitle
1525   @param string s Substitution string ('%s')
1526   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1527  
1528  */
1529  function pxNewsTitle($s='%s', $return=false)
1530  {
1531      $result = $GLOBALS['_PX_render']['news']->getTextContent('title');
1532      if (config::fbool('remove_numbers')) {
1533         $result = px_removeNumbers($result);
1534      }
1535      $result = sprintf($s, $result);
1536      if ($return) return $result;
1537      echo $result;
1538  }
1539  
1540  /**
1541   Display the content of a news.
1542  
1543   @proto function pxNewsContent
1544   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1545  */
1546  function pxNewsContent($return=false)
1547  {
1548      $result = text::parseContent($GLOBALS['_PX_render']['news']->f('description'));
1549      
1550      if ($return) return $result;
1551      echo $result;
1552  }
1553  
1554  /**
1555   Display the keywords or subject of the news.
1556  
1557   @proto function pxNewsKeywords
1558   @param string s Substitution string ('%s')
1559   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1560  */
1561  function pxNewsKeywords($s = '%s', $return=false)
1562  {
1563      $result = '';
1564      $keywords = trim($GLOBALS['_PX_render']['m']->news->f('subject'));
1565      if (strlen($keywords) > 0) {
1566          $result = sprintf($s, $keywords);
1567      }
1568      
1569      if ($return) return $result;
1570      echo $result;
1571  }
1572  
1573  /**
1574   Display the creation date of the news.
1575  
1576   The substitution string for the date is directly given to
1577   [strftime|http://www.php.net/strftime]
1578  
1579   @proto function pxNewsDateCreation
1580   @param string dateformat Format of the date ('%A %e %B %Y')
1581   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1582  
1583  */
1584  function pxNewsDateCreation($dateformat='%A %e %B %Y', $return=false)
1585  {
1586      $result = strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('creationdate')));
1587      
1588      if ($return) return $result;
1589      echo $result;
1590  }
1591  
1592  /**
1593   Display the publication date of the news.
1594  
1595   The substitution string for the date is directly given to
1596   [strftime|http://www.php.net/strftime]
1597  
1598   @proto function pxNewsDatePublication
1599   @param string dateformat Format of the date ('%A %e %B %Y')
1600   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1601  
1602  */
1603  function pxNewsDatePublication($dateformat='%A %e %B %Y', $return=false)
1604  {
1605      $result = strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('publicationdate')));
1606      
1607      if ($return) return $result;
1608      echo $result;
1609  }
1610  
1611  /**
1612   Display the modification date of the news. Only if newer than the
1613   publication date.
1614  
1615   The substitution string for the date is directly given to
1616   [strftime|http://www.php.net/strftime]
1617  
1618   @proto function pxNewsDateModification
1619   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1620   @param string s Substitution ('Modified the %s.')
1621   @param mixed ifmodified Time in minutes between publication date and modification to display, false to always display it (false)
1622   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1623  */
1624  function pxNewsDateModification($dateformat='%A %e %B %Y', $s='Modified the %s.',
1625                                      $ifmodified=false, $return=false)
1626  {
1627      $result = '';
1628      if (false !== $ifmodified) {
1629          $ifmodified = $ifmodified * 60;
1630          $md = date::unix($GLOBALS['_PX_render']['news']->f('modifdate'));
1631          $pd = date::unix($GLOBALS['_PX_render']['news']->f('publicationdate'));
1632          if ($md > ($ifmodified + $pd)) {
1633              $result = sprintf($s, strftime($dateformat, $md));
1634          }
1635      } else {
1636          $result = sprintf($s, strftime($dateformat, date::unix($GLOBALS['_PX_render']['news']->f('modifdate'))));
1637      }
1638      
1639      if ($return) return $result;
1640      echo $result;
1641  }
1642  
1643  /**
1644   Display the date of end of availaibility of the news. Only if end date.
1645  
1646   The substitution string for the date is directly given to
1647   [strftime|http://www.php.net/strftime]
1648  
1649   @proto function pxNewsDateEnd
1650   @param string dateformat Format of the date ('%A %e %B %Y - %T ')
1651   @param string s Substitution ('End the %s.')
1652   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1653  */
1654  function pxNewsDateEnd($dateformat='%A %e %B %Y', $s='End the %s.', $return=false)
1655  {
1656      $result = '';
1657      $y = substr($GLOBALS['_PX_render']['news']->f('enddate'),0,4);
1658      if ((int)$y < 9999) {
1659          $result = sprintf($s, strftime($dateformat , date::unix($GLOBALS['_PX_render']['news']->f('enddate'))));
1660      }
1661      
1662      if ($return) return $result;
1663      echo $result;
1664  }
1665  
1666  /**
1667   Display the name of the author
1668  
1669   @proto function pxNewsAuthor
1670   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1671  */
1672  function pxNewsAuthor($return=false)
1673  {
1674      $result = $GLOBALS['_PX_render']['news']->authors->f('user_realname');
1675      
1676      if ($return) return $result;
1677      echo $result;
1678  }
1679  
1680  /**
1681   Display the author public email if available.
1682  
1683   @proto function pxNewsAuthorEmail
1684   @param string s Substitution string ('%s')
1685   @param string encoding Encoding for a mailto ('link') or for display 'text'
1686   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1687  */
1688  function pxNewsAuthorEmail($s='%s', $encoding='link', $return=false)
1689  {
1690      $result = '';
1691      $text = ($encoding == 'link') ? false : true;
1692      if (strlen($GLOBALS['_PX_render']['news']->authors->f('user_pubemail')) > 0) {
1693          $result = sprintf($s, text::hexEncode($GLOBALS['_PX_render']['news']->authors->f('user_pubemail'), $text));
1694      }
1695      
1696      if ($return) return $result;
1697      echo $result;
1698  }
1699  
1700  /**
1701   Display the path to the news.
1702  
1703   @proto function pxNewsPath
1704   @param string type 'full' give path with http:// ('relative')
1705   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1706  */
1707  function pxNewsPath($type = 'relative', $return=false)
1708  {
1709      $result = $GLOBALS['_PX_render']['news']->getPath();
1710      
1711      if ($return) return $result;
1712      echo $result;
1713  }
1714  
1715  /**
1716   Display the list of categories in which the news is.
1717  
1718   The list is not an HTML list, it is to be used as sentence like
1719   "Category one, category two and category tree" The category names
1720   are linked to the category pages.
1721  
1722   @proto function pxNewsCategories
1723   @param string s Substitution string ('%s')
1724   @param string p1 First delimiters (', ')
1725   @param string p2 Last delimiter (' and ')
1726   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1727  */
1728  function pxNewsCategories($s='%s', $p1=', ', $p2=' and ', $return=false)
1729  {
1730      $cat = $GLOBALS['_PX_render']['news']->cats;
1731      $nr = $cat->nbRow();
1732      $i = 1;
1733      $link = '<a href="%s">%s</a>';
1734      $res = '';
1735      $remove_numbers = config::fbool('remove_numbers');
1736      while (!$cat->EOF()) {
1737          $title = $cat->f('category_name');
1738          if ($remove_numbers) $title = px_removeNumbers($title);
1739          $res .= sprintf($link, $cat->getPath(), htmlspecialchars($title));
1740          if ($nr >= 2 && ($i < ($nr - 1))) {
1741              $res .= $p1;
1742          }
1743          if ($nr >= 2 && ($i == ($nr - 1))) {
1744              $res .= $p2;
1745          }
1746          $i++;
1747          $cat->moveNext();
1748      }
1749      $result = sprintf($s, $res);
1750      
1751      if ($return) return $result;
1752      echo $result;
1753  }
1754  
1755  
1756  /**
1757   Display the associated link and title if available. 
1758  
1759   @proto function pxNewsAssociatedLink
1760   @param string s Substitution string ('<a href="%1$s">%2$s</a>')
1761   @param boolean return Type of return : true, return result as a string, false (default) print in stdout
1762  */
1763  function pxNewsAssociatedLink($s='<a href="%1$s">%2$s</a>', $return=false)
1764  {
1765      $result = '';
1766      if ($GLOBALS['_PX_render']['news']->f('type_id') == 'news') {
1767          $GLOBALS['_PX_render']['news']->loadDetails();
1768          if (strlen($GLOBALS['_PX_render']['news']->details->f('news_titlewebsite')) > 0) {
1769              $result = sprintf($s, $GLOBALS['_PX_render']['news']->details->f('news_linkwebsite'), $GLOBALS['_PX_render']['news']->details->f('news_titlewebsite'));
1770          }
1771      }
1772      if ($return) return $result;
1773      echo $result;
1774  }
1775  
1776  
1777  
1778  
1779  /**
1780   * Display the content of a category
1781   *
1782   * @credits Nicolas LASSALLE.
1783   *
1784   * @param String category the current category to display
1785   * @param int limit Number of last resources (10)
1786   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
1787   */
1788  function pxSitemapShowCatContent($vals, $type, $limit)
1789  {
1790      $cat = $vals['id'];
1791      $res = FrontEnd::getResources($cat, $limit, $type);
1792     
1793      if ($res->EOF()) {
1794          $path = $vals['path'];
1795          echo sprintf('<li><a href="%s">%s</a></li>'."\n", $path,
1796                       __('Show the category content'));
1797      } else {
1798          while (!$res->EOF()) {
1799              echo sprintf('<li><a href="%s">%s</a></li>'."\n", $res->getPath(), 
1800                           px_removeNumbers($res->getTextContent('title')));
1801           $res->moveNext();
1802          }
1803      }
1804  }
1805  
1806  /**
1807   * Returns subcategories of a Category
1808   * 
1809   * @credits Nicolas LASSALLE.
1810   *
1811   * @param string category the category we want the subdirectories
1812   *
1813   * @return array
1814   */
1815  function pxSitemapCategoriesList($categoryId)
1816  {
1817      $list = array();
1818      $ordermanual = config::fbool('order_cat_manual');
1819      $remove_numbers = config::fbool('remove_numbers');
1820      $order = 'ORDER BY category_path';
1821      if ($ordermanual) {
1822          $order = 'ORDER BY category_name';
1823      }
1824      $prim    = FrontEnd::getCategories($categoryId, $order);
1825  
1826      $cats = '';
1827      while (!$prim->EOF()) {
1828          if ($prim->f('category_path') != '/') {
1829              $path = $prim->getPath();
1830              $name = $prim->f('category_name');
1831              if ($remove_numbers) {
1832                  $name = px_removeNumbers($name);
1833              }
1834              $list[htmlspecialchars($name)] = array('path' => $path, 
1835                                                     'desc' => $prim->f('category_description'),
1836                                                     'parentid' => $prim->f('category_parentid'),
1837                                                     'id' => $prim->f('category_id'));
1838          }
1839          $prim->moveNext();
1840      }
1841      return $list;
1842  }
1843  
1844  
1845  /**
1846   * return the content of a category title without the html tag 
1847   * (no <hx> or <li>)
1848   *
1849   * @credits Nicolas LASSALLE.
1850   *
1851   * @return the title to display
1852   */
1853  function pxSitemapGetCatTitle($name, $vals) 
1854  {
1855      $rootcat = FrontEnd::getCategory('/');
1856      $rootcatid = $rootcat->f('category_id');
1857      if ($vals['parentid'] == $rootcatid) {
1858          return sprintf('<a href="%s">%s</a></h3>'."\n".'<p>%s</p>'."\n",
1859                         $vals['path'], $name,
1860                          strip_tags(trim(text::parseContent($vals['desc']))),$name);
1861      } else {
1862          return sprintf('<a href="%s">%s</a>'."\n".'<p>%s</p>'."\n",
1863                         $vals['path'], $name,
1864                          strip_tags(trim(text::parseContent($vals['desc']))),$name);
1865      }
1866  }
1867  
1868  /**
1869   * Display a sitemap for a category
1870   *
1871   * @credits Nicolas LASSALLE.
1872   *
1873   * @param String category the current category to display
1874   * @param int limit Number of last resources (10)
1875   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
1876   */
1877  function pxSitemapShowCategory ($category, $type, $limit) 
1878  {
1879      $list = pxSitemapCategoriesList($category); 
1880      while (list($name, $vals) = each ($list)) {
1881          echo sprintf('<li class="subcatlism">%s </li>'."\n",  pxSitemapGetCatTitle($name, $vals)); 
1882          echo '<li class="nodeco"><ul>'."\n";
1883          pxSitemapShowCatContent($vals, $type, $limit);
1884          pxSitemapShowCategory($vals['id'], $type, $limit);
1885          echo '</ul></li>'."\n";
1886      }
1887  }
1888  
1889  /**
1890   * Display a sitemap for a primary category
1891   *
1892   * @credits Nicolas LASSALLE.
1893   *
1894   * @param String category the current category to display
1895   * @param int limit Number of last resources (10)
1896   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
1897   */
1898  function pxSitemapShowPrimaryCategory ($category, $type, $limit) 
1899  {
1900      $list = pxSitemapCategoriesList($category);
1901      while (list($name, $vals) = each ($list)) {
1902          echo sprintf('<h3>%s'."\n",  pxSitemapGetCatTitle($name,
1903  $vals));
1904          echo '<ul>'."\n";
1905          pxSitemapShowCatContent($vals, $type, $limit);
1906          pxSitemapShowCategory($vals['id'], $type, $limit);
1907          echo '</ul>'."\n";
1908      }
1909  }
1910  
1911  
1912  /**
1913   * Display the sitemap
1914   *
1915   * @credits Nicolas LASSALLE.
1916   *
1917   * @param int limit Number of last resources (10)
1918   * @param string type Type of resources ('' or 'all') for all, 'news' or 'articles'
1919   */
1920  function pxShowSitemap($type='all', $limit='10') 
1921  {
1922      if ($type == 'all') {
1923          $type = '';
1924      }
1925      $rootcat = FrontEnd::getCategory('/');
1926      pxSitemapShowPrimaryCategory ($rootcat->f('category_id'), $type, $limit, 0);
1927  }
1928  
1929  
1930  /**
1931   Remove the numbers at the start of a string
1932  
1933   @param string string
1934   @return string
1935   @private
1936  */
1937  function px_removeNumbers($string)
1938  {
1939      return preg_replace('/^\s*\d+\.\s*/', '', $string);
1940  }
1941  
1942  
1943  
1944  
1945  /**
1946   * Initialisation of the template, it loads all the other librairies. 
1947   * Needed only if the page is not cached, else we try to load the minimum.
1948   *
1949   * @param string Parameters for the template
1950   */
1951  function pxTemplateInit($params='')
1952  {
1953      $aparams = explode('|', $params);
1954      foreach ($aparams as $param) {
1955          if (strpos($param, ':')) {
1956              list($key, $val) = explode(':', $param);
1957              config::setVar(trim($key), trim($val));
1958          } else {
1959              config::setVar(trim($param), true);
1960          }
1961      }
1962  
1963      setlocale(LC_ALL, strtolower(config::f('lang')));
1964      Hook::run('onInitTemplate');
1965  }
1966  
1967  /**
1968   * Set of methods useful for the action method of the resource classes.
1969   *
1970   * All the methods are 'standalone' methods.
1971   */
1972  class FrontEnd
1973  {
1974      /**
1975       * Get the resources for the category.
1976       *
1977       * Set the correct position with respect
1978       * to the number of resources in one page.
1979       *
1980       * @param int Category id ('') default is current category
1981       * @param int Number of resources per page (10)
1982       * @param string Type of resources to limit to ('')
1983       * @param int Page number for the pagination (1)
1984       * @param string Optional order ('ORDER BY %sresources.publicationdate DESC')
1985       * @return mixed false or ResourceSet
1986       */
1987      function getResources($category='', $limit=10, $type='', $page=1,
1988                            $order='ORDER BY %sresources.publicationdate DESC')
1989      {
1990          if ('' == $category) {
1991              $sql = SQL::getResources();
1992          } else {
1993              $sql = SQL::getResourcesInCat($category);
1994          }
1995          $con =& pxDBConnect();
1996          $order = sprintf($order, $con->pfx);
1997  
1998          $sql .= ' AND '.$con->pfx.'resources.website_id=\''
1999              .$con->esc(config::f('website_id')).'\''."\n";
2000          $sql .= ' AND '.$con->pfx.'resources.status=\''
2001              .PX_RESOURCE_STATUS_VALIDE.'\''."\n";
2002          if ('' != $type) {
2003              $sql .= ' AND '.$con->pfx.'resources.type_id=\''
2004                  .$con->esc($type).'\''."\n";
2005          }
2006          $sql .= ' AND '.$con->pfx.'resources.publicationdate <= '
2007              .date::stamp();
2008          $sql .= ' AND '.$con->pfx.'resources.enddate >= '.date::stamp();
2009          $sql .= ' '.$order;
2010  
2011          if (($rs = $con->select($sql, 'Paginator', $limit, $page)) === false) {
2012              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 
2013                                                        500);
2014              return false;
2015          }
2016          return $rs;
2017      }
2018  
2019  
2020      /** 
2021       * Get a category by id or path.
2022       *
2023       * @param mixed Id as int or path as string
2024       * @return mixed Category or false
2025       */
2026      function getCategory($cat)
2027      {
2028          if (preg_match('/^[0-9]+$/', $cat)) {
2029              $sql = SQL::getCategoryById($cat);
2030          } else {
2031              $sql = SQL::getCategoryByPath($cat, config::f('website_id'));
2032          }
2033  
2034          $con =& pxDBConnect();
2035          if (($rs = $con->select($sql, 'Category')) !== false) {
2036              return $rs;
2037          } else {
2038              $GLOBALS['_PX_render']['error']->setError('MySQL: '
2039                                                        .$this->con->error(), 
2040                                                        500);
2041              return false;
2042          }
2043      }
2044  
2045      /**
2046       * Get categories.
2047       *
2048       * Limit to ones have a given parent, order in a given order.
2049       *
2050       * @param int Parent id ('') no limit by default
2051       * @param string Order ('ORDER BY category_path')
2052       * @return Category or false
2053       */
2054      function getCategories($parentid='', $order='ORDER BY category_path')
2055      {
2056          $con =& pxDBConnect();
2057          $sql = 'SELECT * FROM '.$con->pfx.'categories '
2058              .'LEFT JOIN '.$con->pfx.'websites 
2059               ON '.$con->pfx.'websites.website_id='
2060              .$con->pfx.'categories.website_id '
2061              .'WHERE '.$con->pfx.'categories.website_id=\''
2062              .$con->esc(config::f('website_id')).'\'';
2063          if (!empty($parentid)) {
2064              $sql .= ' AND category_parentid=\''.$con->esc($parentid).'\'';
2065          }
2066          $sql .= ' AND category_path NOT LIKE \'%/\\_%\'';
2067          $sql .= ' '.$order;
2068          if (($rs = $con->select($sql, 'Category')) !== false) {
2069              return $rs;
2070          } else {
2071              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 
2072                                                        500);
2073              return false;
2074          }
2075  
2076      }
2077  
2078  
2079  
2080      /**
2081       * Get the website data.
2082       *
2083       * @param string Website id ('') current by default
2084       * @return mixed RecordSet or false in case of error
2085       */
2086      function getWebsite($website='')
2087      {
2088          if ('' == $website) {
2089              $website = config::f('website_id');
2090          }
2091          $sql = SQL::getWebsite($website);
2092          $con =& pxDBConnect();
2093          if (($rs = $con->select($sql)) !== false) {
2094              return $rs;
2095          } else {
2096              $GLOBALS['_PX_render']['error']->setError('MySQL: '.$con->error(), 500);
2097              return false;
2098          }
2099      }
2100  
2101      /**
2102       * Get extra header from the template extension.
2103       *
2104       * @param string Template file
2105       * @return string Extra header to send
2106       */
2107  	function getHeader($template)
2108      {
2109          $ext = strtolower(substr(strrchr($template, '.'), 1));
2110          $encoding = strtolower(config::f('encoding'));
2111          $headers = array(
2112            'htm'   => 'text/html; charset='.$encoding,
2113            'html'  => 'text/html; charset='.$encoding,
2114            'php'   => 'text/html; charset='.$encoding,
2115            'xhtml' => 'application/xhtml+xml; charset='.$encoding,
2116            'txt'   => 'text/plain; charset='.$encoding,
2117            'rss'   => 'text/xml; charset='.$encoding,
2118            'rdf'   => 'text/xml; charset='.$encoding,
2119            'xml'   => 'text/xml; charset='.$encoding,
2120            'atom'  => 'application/atom+xml; charset=utf-8',
2121          );
2122          if (!empty($headers[$ext])) {
2123              return sprintf('Content-Type: %s', $headers[$ext]);
2124          }
2125          return '';
2126      }
2127  }
2128  
2129  /**
2130   Display the description of the current category in the meta description.
2131  
2132   @proto function pxMetasDescription
2133   @param boolean return Type of return : true return result as a string, false (default) print in stdout
2134  */
2135  function pxMetasDescription($return='')
2136  {
2137      $result = strip_tags(text::parseContent($GLOBALS['_PX_render']['cat']->f('category_description')),"");
2138      $result = str_replace("\n","",$result);
2139      
2140      if ($return) return $result;
2141      echo $result;
2142  }
2143  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics