[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/include/inc_front/ -> front.func.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4  
   5     (c) 2002-2010 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6  
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11  
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15  
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19  
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  
  24  //specific functions for the frontend
  25  
  26  function spacer($width=1, $height=1) {
  27      //creates a placeholder image (transparent gif)
  28      return '<img src="img/leer.gif" width="'.intval($width).'" height="'.intval($height).'" border="0" alt="" />';
  29  }
  30  
  31  function headline(& $head, & $subhead, & $layout) {
  32      $c = '';
  33      if($head) {
  34          $c .= $layout["content_head_before"];
  35          $c .= html_specialchars($head);
  36          $c .= $layout["content_head_after"];
  37      }
  38      if($subhead) {
  39          $c .= $layout["content_subhead_before"];
  40          $c .= html_specialchars($subhead);
  41          $c .= $layout["content_subhead_after"];
  42      }
  43      return $c;
  44  }
  45  
  46  //defines multimedia plugin specific values for width or height
  47  function plugin_size($mediatype, $player, $width, $height) {
  48  
  49      switch($mediatype) {
  50          case 0: //Video
  51                  switch($player) {
  52                      case 0:    //Quicktime
  53                              $width = ($width) ? $width : "";
  54                              $height = ($height) ? $height+16 : "";
  55                              break;
  56  
  57                      case 1:    //RealPlayer
  58                              $width = ($width) ? $width : "";
  59                              $width = ($height) ? $height+36 : "";
  60                              break;
  61  
  62                      case 2:    //MediaPlayer
  63                              $width = ($width) ? $width : "";
  64                              $width = ($height) ? $height : "";
  65                              break;
  66  
  67                      case 3:    //Flash
  68                              $width = ($width) ? $width : "";
  69                              $width = ($height) ? $height : "";
  70                              break;
  71                  }
  72                  break;
  73  
  74          case 1:    //Audio
  75                  break;
  76  
  77          case 2:    //Flash
  78                  break;
  79  
  80      }
  81  }
  82  
  83  function must_filled($c) {
  84      //spaceholder for form fields that have to be filled
  85      //with some content or has to be marked or like that
  86      return intval($c) ? '<img src="img/article/fill_in_here.gif" border="0" alt="" />' : '';
  87  }
  88  
  89  function add_attribute($baseval, $attribute, $val, $space=" ") {
  90      //to add all relevant attributes that contains
  91      //values to a string maybe a html tag
  92      $attribute = isEmpty(strval($val)) ? '' : $attribute.'="'.$val.'"';
  93      $attribute = ($baseval && !isEmpty($val)) ? $space.$attribute : $attribute;
  94      return $attribute;
  95  }
  96  
  97  function add_style_attribute($attribute='', $val='') {
  98      //to add all relevant attributes that contains
  99      //values to a string maybe a html tag
 100      $attribute = isEmpty(strval($val)) ? '' : $attribute.': '.$val.';';
 101      return $attribute;
 102  }
 103  
 104  function html_attribute($attribute='', $val='') {
 105      //to return only 1 well formatted attributes and values
 106      return isEmpty(strval($val)) ? '' : $attribute.'="'.$val.'"';
 107  }
 108  
 109  function html_height_attribute($val=0) {
 110      //to return only 1 well formatted attributes and values
 111      return (intval($val)) ? ' style="height:'.$val.'px;" ' : '';
 112  }
 113  
 114  function get_body_attributes(& $values) {
 115      //return a standard list of standard html body attributes
 116      //based on the pagelayout definitions
 117      $body_class    = '';
 118      $link_class    = '';
 119      if(is_array($values)) {
 120          if(empty($values["layout_noborder"])) {
 121              $body_class .= add_style_attribute('        margin', '0').LF;
 122              $body_class .= add_style_attribute('        padding-top',        empty($values["layout_border_top"])        ? '0' : intval($values["layout_border_top"])   .'px').LF;
 123              $body_class .= add_style_attribute('        padding-bottom',    empty($values["layout_border_bottom"])    ? '0' : intval($values["layout_border_bottom"]).'px').LF;
 124              $body_class .= add_style_attribute('        padding-left',    empty($values["layout_border_left"])     ? '0' : intval($values["layout_border_left"])  .'px').LF;
 125              $body_class .= add_style_attribute('        padding-right',     empty($values["layout_border_right"])     ? '0' : intval($values["layout_border_right"]) .'px').LF;
 126              $body_class .= LF;
 127          }
 128          if(!empty($values["layout_bgcolor"])) {
 129              $body_class .= add_style_attribute('        background-color', $values["layout_bgcolor"]);
 130              $body_class .= LF;
 131          }
 132          if(!empty($values["layout_bgimage"])) {
 133              $body_class .= add_style_attribute('        background-image', 'url('.$values["layout_bgimage"].')');
 134              $body_class .= LF;
 135          }
 136          if(!empty($values["layout_textcolor"])) {
 137              $body_class .= add_style_attribute('        color', $values["layout_textcolor"]);
 138              $body_class .= LF;
 139          }
 140          if(!empty($body_class)) {
 141              $body_class  = '    body {'.LF.$body_class.'    }'.LF;
 142          }
 143          if(!empty($values["layout_linkcolor"])) {
 144              $link_class .= '    a, a:link, a:active, a:visited, a:hover { color: '.$values["layout_linkcolor"].'; }';
 145              $link_class .= LF;
 146          }
 147          if(!empty($values["layout_vcolor"])) {
 148              $link_class .= '    a:visited { color: '.$values["layout_vcolor"].'; }';
 149              $link_class .= LF;
 150          }
 151          if(!empty($values["layout_acolor"])) {
 152              $link_class .= '    a:active { color: '.$values["layout_acolor"].'; }';
 153              $link_class .= LF;
 154          }
 155          if(!empty($body_class) || !empty($link_class)) {
 156              $body_class  = '  <style type="text/css">'.LF.SCRIPT_CDATA_START.LF;
 157              $body_class .= $body_class . $link_class;
 158              $body_class .= SCRIPT_CDATA_END.LF.'  </style>'.LF;
 159          }
 160          return $body_class;
 161      }
 162  }
 163  
 164  function align_base_layout($value) {
 165      //to get the alignment of the base layout table
 166      switch($value) {
 167          case  1: $align = "center"; break;
 168          case  2: $align = "right"; break;
 169          default: $align = 0;
 170      }
 171      return ($align) ? ' align="'.$align.'"' : '';
 172  }
 173  
 174  function get_colspan($value) {
 175      //returns colspan value back to table row
 176      if(!isset($value["layout_type"]))                $value["layout_type"] = 0;
 177      switch($value["layout_type"]) {
 178          case  0:    $col=3; break;
 179          case  1:    $col=2; break;
 180          case  2:    $col=2; break;
 181          case  3:    $col=0; break;
 182          default:    $col=3;
 183      }
 184      if(!empty($value["layout_leftspace_width"]))  $col++;
 185      if(!empty($value["layout_rightspace_width"])) $col++;
 186      return ($col) ? (' colspan="'.$col.'"') : '';
 187  }
 188  
 189  function colspan_table_row($val, $block, $colspan="", $rowcontent="&nbsp;") {
 190      //creates a new table row for header or footer or such rows
 191      return ($rowcontent) ? "<tr>\n<td".$colspan.td_attributes($val, $block, 0).">".$rowcontent."</td>\n</tr>\n" : '';
 192  }
 193  
 194  function get_table_block($val, $content="", $leftblock="", $rightblock="") {
 195      //creates the string with all relevant main block data
 196      //$val = $pagelayout array values
 197      $mainblock  = "<tr>\n"; //start row
 198  
 199      //if 3column or 2column (with left block)
 200      if($val["layout_type"]==0 || $val["layout_type"]==1) {
 201          $mainblock .= "<td".td_attributes($val, "left").">".$leftblock."</td>\n";
 202      }
 203  
 204      //if there is a spacer column between left and main block
 205      if($val["layout_leftspace_width"]) {
 206          $mainblock .= "<td".td_attributes($val, "leftspace").">";
 207          $mainblock .= spacer($val["layout_leftspace_width"]);
 208          $mainblock .= "</td>\n";
 209      }
 210  
 211      $mainblock .= "<td".td_attributes($val, "content").">".$content."</td>\n";
 212  
 213      //if there is a spacer column between main block and right column
 214      if($val["layout_rightspace_width"]) {
 215          $mainblock .= "<td".td_attributes($val, "rightspace").">";
 216          $mainblock .= spacer($val["layout_rightspace_width"]);
 217          $mainblock .= "</td>\n";
 218      }
 219  
 220      //if 3column or 2column (with right block)
 221      if($val["layout_type"]==0 || $val["layout_type"]==2) {
 222          $mainblock .= "<td".td_attributes($val, "right").">".$rightblock."</td>\n";
 223      }
 224  
 225      $mainblock .= "</tr>\n"; //end row
 226      return $mainblock;
 227  }
 228  
 229  function td_attributes($val, $block, $top=1) {
 230      //creates a string with all relevant cell attributes like nackground color/image, class
 231      $td_attrib  = ($top) ? ' valign="top"' : "";
 232      if(!empty($val["layout_".$block."_height"])) {
 233          $td_attrib .= html_height_attribute($val["layout_".$block."_height"]);
 234      }
 235      if(!empty($val["layout_".$block."_width"])) {
 236          $td_attrib .= html_attribute(" width", $val["layout_".$block."_width"]);
 237      }
 238      if(!empty($val["layout_".$block."_bgcolor"])) {
 239          $td_attrib .= html_attribute(" bgcolor", $val["layout_".$block."_bgcolor"]);
 240      }
 241      if(!empty($val["layout_".$block."_bgimage"])) {
 242          $td_attrib .= html_attribute(" style", 'background-image:url('.$val["layout_".$block."_bgimage"].')');
 243      }
 244      if(!empty($val["layout_".$block."_class"])) {
 245          $td_attrib .= html_attribute(" class", $val["layout_".$block."_class"]);
 246      }
 247      return $td_attrib;
 248  }
 249  
 250  function table_attributes($val, $var_part, $top=1, $tr=false) {
 251      //creates a string with all relevant cell attributes like background color/image, class
 252      //P.S. it is nearly the same as td_attributes - but it was boring to rewrite code ;-)
 253      $td_attrib = '';
 254      if($top) {
 255          $td_attrib = ' valign="top"';
 256      }
 257  
 258      if(!$tr) {
 259          $td_attrib .= html_attribute(" border", (!empty($val[$var_part."_border"])) ? $val[$var_part."_border"] : '0');
 260          $td_attrib .= html_attribute(" cellspacing", (!empty($val[$var_part."_cspace"])) ? $val[$var_part."_cspace"] : '0');
 261          $td_attrib .= html_attribute(" cellpadding", (!empty($val[$var_part."_cpad"])) ? $val[$var_part."_cpad"] : '0');
 262      }
 263  
 264      if(!empty($val[$var_part."_height"])) {
 265          $td_attrib .= html_height_attribute($val[$var_part."_height"]);
 266      }
 267      if(!empty($val[$var_part."_width"])) {
 268          $td_attrib .= html_attribute(" width", $val[$var_part."_width"]);
 269      }
 270      if(!empty($val[$var_part."_bgcolor"])) {
 271          $td_attrib .= html_attribute(" bgcolor", $val[$var_part."_bgcolor"]);
 272      }
 273      if(!empty($val[$var_part."_bgimage"])) {
 274          $td_attrib .= html_attribute(" background", $val[$var_part."_bgimage"]);
 275      }
 276      if(!empty($val[$var_part."_class"])) {
 277          $td_attrib .= html_attribute(" class", $val[$var_part."_class"]);
 278      }
 279  
 280      return $td_attrib;
 281  }
 282  
 283  function get_breadcrumb ($start_id, &$struct_array) {
 284      //returns the breadcrumb path starting with given start_id
 285  
 286      $data = array();
 287      while ($start_id && isset($struct_array[$start_id])) {
 288          $data[$start_id] = $struct_array[$start_id]["acat_name"];
 289          $start_id         = $struct_array[$start_id]["acat_struct"];
 290      }
 291      if(!empty($struct_array[$start_id]["acat_name"])) {
 292          $data[$start_id] = $struct_array[$start_id]["acat_name"];
 293      }
 294      return array_reverse($data, 1);
 295  }
 296  
 297  function breadcrumb ($start_id, &$struct_array, $end_id, $spacer=' &gt; ') {
 298      //builds the breadcrumb menu based on given values
 299      //$link_to = the page on which the breadcrum part links
 300      //$root_name = name of the breadcrumb part if empty/false/0 $start_id
 301      //$spacer = how should breadcrumb parts be divided
 302  
 303      $start_id     = intval($start_id);
 304      $end_id     = intval($end_id);
 305      $act_id     = $start_id; //store actual ID for later comparing
 306      $breadcrumb = '';
 307      global $template_default;
 308  
 309      while ($start_id) { //get the breadcrumb path starting with given start_id
 310          if($end_id && $start_id == $end_id) break;
 311          $data[$start_id] = $struct_array[$start_id]["acat_name"];
 312          $start_id         = $struct_array[$start_id]["acat_struct"];
 313      }
 314      $data[$start_id] = $struct_array[$start_id]["acat_name"];
 315      $crumbs_part = array_reverse($data, 1);
 316      if(is_array($crumbs_part)) {
 317          foreach($crumbs_part as $key => $value) {
 318              $alias = '';
 319              if($struct_array[$key]["acat_hidden"] != 1) { // check if the structure should be unvisible when active
 320                  if ($act_id != $key) {
 321                      if($breadcrumb) $breadcrumb .= $spacer;
 322                      if(!$struct_array[$key]["acat_redirect"]) {
 323                          $breadcrumb .= '<a href="index.php?';
 324                          $alias          = $struct_array[$key]["acat_alias"];
 325                          $breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key; //',0,0,1,0,0';
 326                          $breadcrumb .= '">';
 327                      } else {
 328                          $redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
 329                          $breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
 330                      }
 331                      $breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
 332                  } else {
 333                      if($breadcrumb) $breadcrumb .= $spacer;
 334                      if(!empty($template_default['breadcrumb_active_prefix'])) {
 335                          $breadcrumb .= $template_default['breadcrumb_active_prefix'];
 336                      }
 337                      $breadcrumb .= html_specialchars($crumbs_part[$key]);
 338                      if(!empty($template_default['breadcrumb_active_suffix'])) {
 339                          $breadcrumb .= $template_default['breadcrumb_active_suffix'];
 340                      }
 341                  }
 342              }
 343          }
 344      }
 345      return $breadcrumb;
 346  }
 347  
 348  function get_redirect_link($link='#', $pre='', $after=' ') {
 349      // returns the link var and target var if available
 350      $link             = explode(' ', $link);
 351      $l['link']        = empty($link[0]) ? '#' : $link[0];
 352      $l['target']    = empty($link[1]) ? ''  : $pre.'target="'.$link[1].'"'.$after;
 353      return $l;
 354  }
 355  
 356  function get_struct_data($root_name='', $root_info='') {
 357      //returns the complete active and public struct data as array
 358      //so it is reusable by many menu functions -> lower db access
 359      
 360      // first check pre-rendered structure for current user mode
 361      $sysvalue_key    = 'structure_array_vmode_'.get_user_vmode();
 362      $data            = _getConfig($sysvalue_key);
 363      
 364      if(is_array($data)) {
 365          return $data;    
 366      }
 367  
 368      global $db;
 369      global $indexpage;
 370      $data = array();
 371  
 372      $data[0] = array(    "acat_id"        => 0,
 373                      "acat_name"        => $indexpage['acat_name'],
 374                      "acat_info"        => $indexpage['acat_info'],
 375                      "acat_struct"    => 0,
 376                      "acat_sort"        => 0,
 377                      "acat_hidden"    => intval($indexpage['acat_hidden']),
 378                      "acat_regonly"    => intval($indexpage['acat_regonly']),
 379                      "acat_ssl"        => intval($indexpage['acat_ssl']),
 380                      "acat_template"    => intval($indexpage['acat_template']),
 381                      "acat_alias"    => $indexpage['acat_alias'],
 382                      "acat_topcount"    => intval($indexpage['acat_topcount']),
 383                      "acat_maxlist"    => intval($indexpage['acat_maxlist']),
 384                      "acat_redirect"    => $indexpage['acat_redirect'],
 385                      "acat_order"    => intval($indexpage['acat_order']),
 386                      "acat_timeout"    => $indexpage['acat_timeout'],
 387                      "acat_nosearch"    => $indexpage['acat_nosearch'],
 388                      "acat_nositemap"=> $indexpage['acat_nositemap'],
 389                      "acat_permit"    => !empty($indexpage['acat_permit']) && is_array($indexpage['acat_permit']) ? $indexpage['acat_permit'] : array(),
 390                      "acat_pagetitle"=> empty($indexpage['acat_pagetitle']) ? '' : $indexpage['acat_pagetitle'],
 391                      "acat_paginate"    => empty($indexpage['acat_paginate']) ? 0 : 1,
 392                      "acat_overwrite"=> empty($indexpage['acat_overwrite']) ? '' : $indexpage['acat_overwrite'],
 393                      "acat_archive"    => empty($indexpage['acat_archive']) ? 0 : 1,
 394                      "acat_class"    => empty($indexpage['acat_class']) ? '' : $indexpage['acat_class'],
 395                      "acat_keywords"    => empty($indexpage['acat_keywords']) ? '' : $indexpage['acat_keywords']
 396                  );
 397      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE ";
 398      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 399      if(VISIBLE_MODE != 2) {
 400          // for 0 AND 1
 401          $sql .= "acat_aktiv=1 AND acat_public=1 AND ";
 402      }
 403      $sql .= "acat_trash=0 ORDER BY acat_struct, acat_sort";
 404  
 405      if($result = mysql_query($sql, $db)) {
 406          while($row = mysql_fetch_assoc($result)) {
 407              $data[$row["acat_id"]] = array(    "acat_id"        => $row["acat_id"],
 408                                          "acat_name"        => $row["acat_name"],
 409                                          "acat_info"        => $row["acat_info"],
 410                                          "acat_struct"    => $row["acat_struct"],
 411                                          "acat_sort"        => $row["acat_sort"],
 412                                          "acat_hidden"    => $row["acat_hidden"],
 413                                          "acat_regonly"    => $row["acat_regonly"],
 414                                          "acat_ssl"        => $row["acat_ssl"],
 415                                          "acat_template"    => $row["acat_template"],
 416                                          "acat_alias"    => $row["acat_alias"],
 417                                          "acat_topcount"    => $row["acat_topcount"],
 418                                          "acat_maxlist"    => $row["acat_maxlist"],
 419                                          "acat_redirect"    => $row["acat_redirect"],
 420                                          "acat_order"    => $row["acat_order"],
 421                                          "acat_timeout"    => $row["acat_cache"],
 422                                          "acat_nosearch"    => $row["acat_nosearch"],
 423                                          "acat_nositemap"=> $row["acat_nositemap"],
 424                                          "acat_permit"    => empty($row["acat_permit"]) ? array() : explode(',', $row["acat_permit"]),
 425                                          "acat_pagetitle"=> $row["acat_pagetitle"],
 426                                          "acat_paginate"    => $row["acat_paginate"],
 427                                          "acat_overwrite"=> $row["acat_overwrite"],
 428                                          "acat_archive"    => $row["acat_archive"],
 429                                          "acat_class"    => $row["acat_class"],
 430                                          "acat_keywords"    => $row["acat_keywords"]
 431                                        );
 432          }
 433          mysql_free_result($result);
 434      }
 435      
 436      // store pre-rendered serialized array in database
 437      _setConfig($sysvalue_key, $data, 'frontend_render', 1);
 438      
 439      return $data;
 440  }
 441  
 442  function get_actcat_articles_data($act_cat_id) {
 443      //returns the complete active and public article data as array (basic infos only)
 444      //so it is reusable by many functions -> lower db access
 445  
 446      global $content;
 447      global $db;
 448  
 449      $data                 = array();
 450      if(isset($content['struct'][ $act_cat_id ])) {
 451          $ao = get_order_sort($content['struct'][ $act_cat_id ]['acat_order']);
 452      } else {
 453          return $data;
 454      }
 455      $as                    = $content['struct'][ $act_cat_id ];
 456      $as['acat_maxlist']    = intval($as['acat_maxlist']);
 457  
 458      $sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date, ";
 459      $sql .= "UNIX_TIMESTAMP(article_begin) AS article_livedate, ";
 460      $sql .= "UNIX_TIMESTAMP(article_end) AS article_killdate ";
 461      $sql .= "FROM ".DB_PREPEND."phpwcms_article ";
 462      $sql .= "WHERE article_cid=".$act_cat_id;
 463      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 464      switch(VISIBLE_MODE) {
 465          case 0: $sql .= " AND article_public=1 AND article_aktiv=1";
 466                  break;
 467          case 1: $sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
 468                  break;
 469          //case 2: admin mode no additional neccessary
 470      }
 471      $sql .= ' AND article_deleted=0 AND article_begin < NOW() ';
 472      
 473      if($content['struct'][ $act_cat_id ]['acat_archive'] == 0) {
 474          $sql .= 'AND article_end > NOW() ';
 475      } else {
 476          $sql .= 'AND IF( article_archive_status=1 , 1 , article_end > NOW() ) ';    
 477      }
 478      
 479      $sql .= "ORDER BY ".$ao[2];
 480  
 481      if(empty($as['acat_paginate']) && $as['acat_maxlist'] && $as['acat_topcount'] >= $as['acat_maxlist']) {
 482          $sql .= ' LIMIT '.$as['acat_maxlist'];
 483      }
 484  
 485      if($result = mysql_query($sql, $db)) {
 486          while($row = mysql_fetch_assoc($result)) {
 487              $data[$row["article_id"]] = array(
 488                                      "article_id"        => $row["article_id"],
 489                                      "article_cid"        => $row["article_cid"],
 490                                      "article_title"        => $row["article_title"],
 491                                      "article_subtitle"    => $row["article_subtitle"],
 492                                      "article_menutitle"    => $row["article_menutitle"],
 493                                      "article_keyword"    => $row["article_keyword"],
 494                                      "article_summary"    => $row["article_summary"],
 495                                      "article_redirect"    => $row["article_redirect"],
 496                                      "article_date"        => $row["article_date"],
 497                                      "article_username"    => $row["article_username"],
 498                                      "article_sort"        => $row["article_sort"],
 499                                      "article_notitle"    => $row["article_notitle"],
 500                                      "article_created"    => $row["article_created"],
 501                                      "article_image"        => @unserialize($row["article_image"]),
 502                                      "article_timeout"    => $row["article_cache"],
 503                                      "article_nosearch"    => $row["article_nosearch"],
 504                                      "article_nositemap"    => $row["article_nositemap"],
 505                                      "article_aliasid"    => $row["article_aliasid"],
 506                                      "article_headerdata"=> $row["article_headerdata"],
 507                                      "article_morelink"    => $row["article_morelink"],
 508                                      "article_begin"        => $row["article_begin"],
 509                                      "article_end"        => $row["article_end"],
 510                                      "article_alias"        => $row["article_alias"],
 511                                      'article_livedate'    => $row["article_livedate"],
 512                                      'article_killdate'    => $row["article_killdate"]
 513                                              );
 514              // now check for article alias ID
 515              if($row["article_aliasid"]) {
 516                  $aid = $row["article_id"];
 517                  $alias_sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date, ";
 518                  $alias_sql .= "UNIX_TIMESTAMP(article_begin) AS article_livedate, ";
 519                  $alias_sql .= "UNIX_TIMESTAMP(article_end) AS article_killdate "; 
 520                  $alias_sql .= "FROM ".DB_PREPEND."phpwcms_article ";
 521                  $alias_sql .= "WHERE article_deleted=0 AND article_id=".intval($row["article_aliasid"]);
 522                  if(!$row["article_headerdata"]) {
 523                      switch(VISIBLE_MODE) {
 524                          case 0: $alias_sql .= " AND article_public=1 AND article_aktiv=1";
 525                                  break;
 526                          case 1: $alias_sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
 527                                  break;
 528                      }
 529                      $alias_sql .= " AND article_begin < NOW() AND article_end > NOW()";
 530                  }
 531                  $alias_sql .= " AND article_deleted=0 LIMIT 1";
 532                  if($alias_result = mysql_query($alias_sql, $db)) {
 533                      if($alias_row = mysql_fetch_assoc($alias_result)) {
 534                          $data[$aid]["article_id"] = $alias_row["article_id"];
 535                          $data[$aid]["article_alias"] = $alias_row["article_alias"];
 536                          // use alias article header data
 537                          if(!$row["article_headerdata"]) {
 538                              $data[$aid]["article_title"]        = $alias_row["article_title"];
 539                              $data[$aid]["article_subtitle"]        = $alias_row["article_subtitle"];
 540                              $data[$aid]["article_keyword"]        = $alias_row["article_keyword"];
 541                              $data[$aid]["article_summary"]        = $alias_row["article_summary"];
 542                              $data[$aid]["article_redirect"]        = $alias_row["article_redirect"];
 543                              $data[$aid]["article_date"]            = $alias_row["article_date"];
 544                              $data[$aid]["article_image"]        = @unserialize($alias_row["article_image"]);
 545                              $data[$aid]["article_begin"]        = $alias_row["article_begin"];
 546                              $data[$aid]["article_end"]            = $alias_row["article_end"];
 547                              $data[$aid]['article_livedate']        = $alias_row["article_livedate"];
 548                              $data[$aid]['article_killdate']        = $alias_row["article_killdate"];
 549                              $data[$aid]['article_menutitle']    = $alias_row["article_menutitle"];
 550                          }
 551                      }
 552                      mysql_free_result($alias_result);
 553                  }
 554              }
 555          }
 556          mysql_free_result($result);
 557      }
 558      return $data;
 559  }
 560  
 561  function setArticleSummaryImageData($img) {
 562      // used to set correct list image values based on given data
 563  
 564      //first check if lis_image data is set - will not for all old articles
 565      if(!isset($img['list_usesummary'])) {
 566          $img['list_usesummary'] = 1;
 567      }
 568      if($img['list_usesummary'] && !empty($img['hash'])) {
 569          $img['list_name']        = $img['name'];
 570          $img['list_hash']        = $img['hash'];
 571          $img['list_ext']        = $img['ext'];
 572          $img['list_id']            = $img['id'];
 573          $img['list_caption']    = $img['caption'];
 574          $img['list_zoom']        = empty($img['list_zoom']) ? $img['zoom'] : $img['list_zoom'];
 575          $img['list_width']        = empty($img['list_width']) ? $img['width'] : $img['list_width'];
 576          $img['list_height']        = empty($img['list_height']) ? $img['height'] : $img['list_height'];
 577      }
 578      return $img;
 579  }
 580  
 581  //menu creating
 582  function nav_table_simple_struct(&$struct, $act_cat_id, $link_to="index.php") {
 583      //returns a simple table based navigation menu of possible
 584      //structure levels based on current structure level
 585      $nav_table  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" summary=\"\">\n<tr>\n";
 586      $nav_table .= "<td width=\"10\"><img src=\"img/leer.gif\" width=\"10\" height=\"1\" alt=\"\" /></td>\n";
 587      $nav_table .= '<td width="100%"'.(empty($struct[$act_cat_id]["acat_class"]) ? '' : ' class="'.$struct[$act_cat_id]["acat_class"].'"').'><strong>';
 588      $nav_table .= html_specialchars($struct[$act_cat_id]["acat_name"]);
 589      $nav_table .= "</strong></td>\n<tr>";
 590      foreach($struct as $key => $value) {
 591  
 592          if($key != $act_cat_id && _getStructureLevelDisplayStatus($key, $act_cat_id) ) {
 593              
 594              $nav_table .= "<tr>\n";
 595              $nav_table .= "<td width=\"10\"><img src=\"img/leer.gif\" width=\"10\" height=\"1\" alt=\"\" /></td>\n";
 596              $nav_table .= '<td width="100%"'.(empty($struct[$key]["acat_class"]) ? '' : ' class="'.$struct[$key]["acat_class"].'"').'>';
 597  
 598              if(!$struct[$key]["acat_redirect"]) {
 599                  $nav_table .= '<a href="index.php?';
 600                  if($struct[$key]["acat_alias"]) {
 601                      $nav_table .= html_specialchars($struct[$key]["acat_alias"]);
 602                  } else {
 603                      $nav_table .= 'id='.$key; //',0,0,1,0,0';
 604                  }
 605                  $nav_table .= '">';
 606              } else {
 607                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
 608                  $nav_table .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
 609              }
 610  
 611              $nav_table .= html_specialchars($struct[$key]["acat_name"])."</a></td>\n<tr>";
 612          }
 613      }
 614      $nav_table .= '</table>';
 615      return $nav_table;
 616  }
 617  
 618  function nav_level_row($show_id, $show_home=1) {
 619      //returns a simple row based navigation
 620  
 621      if(strtoupper($show_id) == 'CURRENT') {
 622          $act_cat_id = $GLOBALS['content']["cat_id"];
 623      } else {
 624          $act_cat_id = intval($show_id);
 625      }
 626  
 627      $nav = '';
 628  
 629      if($show_home && $GLOBALS['content']['struct'][$act_cat_id]['acat_hidden'] != 1) {
 630          if($GLOBALS['content']["cat_id"] == $act_cat_id) {
 631              $before = $GLOBALS['template_default']["nav_row"]["link_before_active"];
 632              $after  = $GLOBALS['template_default']["nav_row"]["link_after_active"];
 633              $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before_active"];
 634              $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after_active"];
 635          } else {
 636              $before = $GLOBALS['template_default']["nav_row"]["link_before"];
 637              $after  = $GLOBALS['template_default']["nav_row"]["link_after"];
 638              $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before"];
 639              $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after"];
 640          }
 641          $nav .= $before;
 642          $nav .= '<a href="index.php?';
 643          $nav .= ($GLOBALS['content']['struct'][$act_cat_id]['acat_alias']) ? html_specialchars($GLOBALS['content']['struct'][$act_cat_id]['acat_alias']) : 'id='.$act_cat_id; //',0,0,1,0,0';
 644          $nav .= '"'.(empty($GLOBALS['content']['struct'][$act_cat_id]["acat_class"]) ? '' : ' class="'.$GLOBALS['content']['struct'][$act_cat_id]["acat_class"].'"').'>'.$direct_before;
 645          $nav .= html_specialchars($GLOBALS['content']['struct'][$act_cat_id]['acat_name']);
 646          $nav .= $direct_after.'</a>'.$after;
 647      }
 648  
 649      // check against breadcrumb - active site tree
 650      if($GLOBALS['content']['struct'][$GLOBALS['content']["cat_id"]]['acat_struct'] != 0) {
 651          $breadcrumb = get_breadcrumb($GLOBALS['content']["cat_id"], $GLOBALS['content']['struct']);
 652      }
 653  
 654      foreach($GLOBALS['content']['struct'] as $key => $value) {
 655      
 656          if($key != $act_cat_id && _getStructureLevelDisplayStatus($key, $act_cat_id) ) {
 657              
 658              $class = empty($GLOBALS['content']['struct'][$key]["acat_class"]) ? '' : ' class="'.$GLOBALS['content']['struct'][$key]["acat_class"].'"';
 659  
 660              if($nav) {
 661                  $nav .= $GLOBALS['template_default']["nav_row"]["between"];
 662              }
 663  
 664              if($GLOBALS['content']["cat_id"] == $key || isset($breadcrumb[$key])) {
 665                  $before = $GLOBALS['template_default']["nav_row"]["link_before_active"];
 666                  $after  = $GLOBALS['template_default']["nav_row"]["link_after_active"];
 667                  $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before_active"];
 668                  $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after_active"];
 669              } else {
 670                  $before = $GLOBALS['template_default']["nav_row"]["link_before"];
 671                  $after  = $GLOBALS['template_default']["nav_row"]["link_after"];
 672                  $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before"];
 673                  $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after"];
 674              }
 675  
 676              $nav .= $before;
 677  
 678              if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
 679                  $nav .= '<a href="index.php?';
 680                  if($GLOBALS['content']['struct'][$key]["acat_alias"]) {
 681                      $nav .= html_specialchars($GLOBALS['content']['struct'][$key]["acat_alias"]);
 682                  } else {
 683                      $nav .= 'id='.$key; //',0,0,1,0,0';
 684                  }
 685                  $nav .= '"'.$class.'>';
 686              } else {
 687                  $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
 688                  $nav .= '<a href="'.$redirect['link'].'"'.$redirect['target'].$class.'>';
 689              }
 690              $nav .= $direct_before;
 691              $nav .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);;
 692              $nav .= $direct_after.'</a>'.$after;
 693          }
 694      }
 695      if($nav) {
 696          $nav  = $GLOBALS['template_default']["nav_row"]["before"].$nav;
 697          $nav .= $GLOBALS['template_default']["nav_row"]["after"];
 698      }
 699      return $nav;
 700  }
 701  
 702  function nav_table_struct (&$struct, $act_cat_id, $level, $nav_table_struct, $link_to="index.php") {
 703      // start with home directory for the listing = top nav structure
 704      // 1. Build the recursive tree for given actual article category ID
 705  
 706      // return the tree starting with given start_id (like breadcrumb)
 707      // if the $start_id = 0 then this stops because 0 = top level
 708  
 709      $level             = intval($level);
 710      $start_id         = $act_cat_id;
 711      $data             = array();
 712      $c                 = 0;
 713      $total_levels     = 0;
 714      $level_depth     = 0;
 715      //$start_level     = $level;
 716      while ($start_id) {
 717          $data[$start_id]    = 1;
 718          $start_id            = $struct[$start_id]["acat_struct"];
 719          $total_levels++;
 720      }
 721  
 722      if(is_array($data) && count($data)) {
 723          $temp_tree = array_reverse($data, 1);
 724      } else {
 725          $temp_tree = false;
 726      }
 727  
 728      foreach($struct as $key => $value) {
 729          if($struct[$key]["acat_struct"] == $act_cat_id && $key && (!$struct[$key]["acat_hidden"] || isset($GLOBALS['LEVEL_KEY'][$key]))) {
 730              $c++;
 731          }
 732      }
 733      $c = (!$c) ? 1 : 0;
 734  
 735      //build image src path and real image tag
 736      $nav_table_struct["linkimage_over_js"]  = get_real_imgsrc($nav_table_struct["linkimage_over"]);
 737  
 738      $nav_table_struct["linkimage_norm"]        = add_linkid($nav_table_struct["linkimage_norm"],   '#');
 739      $nav_table_struct["linkimage_over"]        = add_linkid($nav_table_struct["linkimage_over"],   '#');
 740      $nav_table_struct["linkimage_active"]    = add_linkid($nav_table_struct["linkimage_active"], '#');
 741  
 742      $lc = count($temp_tree);
 743      $ld = false;
 744      for($l = 0; $l <= $lc; $l++) {
 745  
 746          if(isset($GLOBALS['LEVEL_ID'][$l])) {
 747  
 748              $curStructID = $GLOBALS['LEVEL_ID'][$l];
 749              // now all deeper levels can be deleted
 750              if($ld) {
 751                  unset($temp_tree[$curStructID]);
 752              }
 753  
 754              if(!isset($nav_table_struct['array_struct'][$l])) {
 755  
 756                  $nav_table_struct['array_struct'][$l]["linkimage_over_js"]    = $nav_table_struct["linkimage_over_js"];
 757                  $nav_table_struct['array_struct'][$l]["linkimage_norm"]        = $nav_table_struct["linkimage_norm"];
 758                  $nav_table_struct['array_struct'][$l]["linkimage_over"]        = $nav_table_struct["linkimage_over"];
 759                  $nav_table_struct['array_struct'][$l]["linkimage_active"]    = $nav_table_struct["linkimage_active"];
 760  
 761                  $nav_table_struct['array_struct'][$l]["link_before"]        = $nav_table_struct["link_before"];
 762                  $nav_table_struct['array_struct'][$l]["link_after"]            = $nav_table_struct["link_after"];
 763                  $nav_table_struct['array_struct'][$l]["link_active_before"]    = $nav_table_struct["link_active_before"];
 764                  $nav_table_struct['array_struct'][$l]["link_active_after"]    = $nav_table_struct["link_active_after"];
 765  
 766                  $nav_table_struct['array_struct'][$l]["row_norm_bgcolor"]    = $nav_table_struct["row_norm_bgcolor"];
 767                  $nav_table_struct['array_struct'][$l]["row_norm_class"]        = $nav_table_struct["row_norm_class"];
 768                  $nav_table_struct['array_struct'][$l]["row_over_bgcolor"]    = $nav_table_struct["row_over_bgcolor"];
 769                  $nav_table_struct['array_struct'][$l]["row_active_bgcolor"]    = $nav_table_struct["row_active_bgcolor"];
 770                  $nav_table_struct['array_struct'][$l]["row_active_class"]    = $nav_table_struct["row_active_class"];
 771  
 772                  $nav_table_struct['array_struct'][$l]["space_celltop"]        = $nav_table_struct["space_celltop"];
 773                  $nav_table_struct['array_struct'][$l]["space_cellbottom"]    = $nav_table_struct["space_cellbottom"];
 774  
 775                  $nav_table_struct['array_struct'][$l]["cell_height"]        = $nav_table_struct["cell_height"];
 776                  $nav_table_struct['array_struct'][$l]["cell_class"]            = $nav_table_struct["cell_class"];
 777                  $nav_table_struct['array_struct'][$l]["cell_active_height"]    = $nav_table_struct["cell_active_height"];
 778                  $nav_table_struct['array_struct'][$l]["cell_active_class"]    = $nav_table_struct["cell_active_class"];
 779  
 780              } else {
 781  
 782                  $nav_table_struct['array_struct'][$l]["linkimage_over_js"]    = get_real_imgsrc($nav_table_struct['array_struct'][$l]["linkimage_over"]);
 783                  $nav_table_struct['array_struct'][$l]["linkimage_norm"]        = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_norm"],   '#');
 784                  $nav_table_struct['array_struct'][$l]["linkimage_over"]        = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_over"],   '#');
 785                  $nav_table_struct['array_struct'][$l]["linkimage_active"]    = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_active"], '#');
 786  
 787              }
 788  
 789              if($struct[$curStructID]['acat_hidden'] == 1) {
 790                  unset($temp_tree[$curStructID]);
 791                  $ld = true;
 792              }
 793  
 794          }
 795  
 796      }
 797  
 798      $temp_menu = build_levels ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //starts at root level
 799      if($temp_menu) {
 800          initFrontendJS();
 801          return "<table".table_attributes($nav_table_struct, "table", 0)." summary=\"\">\n".$temp_menu."</table>";
 802      }
 803      return '';
 804  }
 805  
 806  function get_real_imgsrc($img='') {
 807      // strips real src attribute from image tag
 808      if($img) {
 809          $img = preg_replace('/.*src=["|\'](.*?)["|\'].*/i', "$1", $img);
 810      }
 811      return $img;
 812  }
 813  
 814  function add_linkid($img='', $linkid='') {
 815      //used to add the link ID for js over functions
 816      $img = preg_replace('/( \/>|>)$/', $linkid."$1", $img);
 817      return $img;
 818  }
 819  
 820  function build_levels ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
 821  
 822      // this returns the level structure based on given arrays
 823      // it is special for browsing from root levels
 824  
 825      $nav_table_struct["linkimage_over_js"]    = $nav_table_struct['array_struct'][$count]["linkimage_over_js"];
 826      $nav_table_struct["linkimage_norm"]        = $nav_table_struct['array_struct'][$count]["linkimage_norm"];
 827      $nav_table_struct["linkimage_over"]        = $nav_table_struct['array_struct'][$count]["linkimage_over"];
 828      $nav_table_struct["linkimage_active"]    = $nav_table_struct['array_struct'][$count]["linkimage_active"];
 829      $nav_table_struct["row_norm_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_norm_bgcolor"];
 830      $nav_table_struct["row_norm_class"]        = $nav_table_struct['array_struct'][$count]["row_norm_class"];
 831      $nav_table_struct["row_over_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_over_bgcolor"];
 832      $nav_table_struct["row_active_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_active_bgcolor"];
 833      $nav_table_struct["row_active_class"]    = $nav_table_struct['array_struct'][$count]["row_active_class"];
 834      $nav_table_struct["space_celltop"]        = $nav_table_struct['array_struct'][$count]["space_celltop"];
 835      $nav_table_struct["space_cellbottom"]    = $nav_table_struct['array_struct'][$count]["space_cellbottom"];
 836      $nav_table_struct["cell_height"]        = $nav_table_struct['array_struct'][$count]["cell_height"];
 837      $nav_table_struct["cell_class"]            = $nav_table_struct['array_struct'][$count]["cell_class"];
 838      $nav_table_struct["cell_active_height"]    = $nav_table_struct['array_struct'][$count]["cell_active_height"];
 839      $nav_table_struct["cell_active_class"]    = $nav_table_struct['array_struct'][$count]["cell_active_class"];
 840      $nav_table_struct["link_before"]        = $nav_table_struct['array_struct'][$count]["link_before"];
 841      $nav_table_struct["link_after"]            = $nav_table_struct['array_struct'][$count]["link_after"];
 842      $nav_table_struct["link_active_before"]    = $nav_table_struct['array_struct'][$count]["link_active_before"];
 843      $nav_table_struct["link_active_after"]    = $nav_table_struct['array_struct'][$count]["link_active_after"];
 844  
 845      $temp_menu        = '';
 846      $js             = '';
 847      $depth             = count($temp_tree)-$div;
 848      $current_level    = $count;
 849      $count++;
 850      $depth2         = $depth-$count+2;
 851      $right_cell     = '';
 852      $left_cell         = '';
 853      $cell_top         = '';
 854      $cell_bottom     = '';
 855      $space_right    = '';
 856      $space_cell     = '';
 857      $space_row         = '';
 858      $cell_height     = $nav_table_struct["cell_height"] ? $nav_table_struct["cell_height"] : 1;
 859  
 860      if($nav_table_struct["space_right"]) {
 861          $right_cell  = "<td width=\"".$nav_table_struct["space_left"]."\">";
 862          $right_cell .= spacer($nav_table_struct["space_right"], $cell_height)."</td>\n";
 863          $space_right = "<td>".spacer(1, 1)."</td>";
 864      }
 865      if($nav_table_struct["space_left"]) {
 866          $colspan    = ($count > 1) ? " colspan=\"".$count."\"" : "";
 867          $left_cell    = "<td width=\"".$nav_table_struct["space_left"]."\"".$colspan.">";
 868          $left_cell .= spacer($nav_table_struct["space_left"], $cell_height)."</td>\n";
 869          $space_cell = "<td".$colspan.">".spacer(1, 1)."</td><td>".spacer(1, 1)."</td>";
 870      } else {
 871          if($count > 1) {
 872              $colspan    = ($count > 2) ? " colspan=\"".($count-1)."\"" : "";
 873              $left_cell    = "<td ".$colspan.">".spacer(1, 1)."</td>\n";
 874              $space_cell = "<td".$colspan.">".spacer(1, 1)."</td><td>".spacer(1, 1)."</td>";
 875          }
 876      }
 877      if($nav_table_struct["space_celltop"]) $cell_top = spacer(1, $nav_table_struct["space_celltop"])."<br />";
 878      if($nav_table_struct["space_cellbottom"]) $cell_bottom = "<br />".spacer(1, $nav_table_struct["space_cellbottom"]);
 879  
 880      $colspan    = ($depth2 > 1) ? ' colspan="'.($depth2).'"' : '';
 881  
 882      foreach($struct as $key => $value) {
 883  
 884          if( _getStructureLevelDisplayStatus($key, $level) ) {
 885              
 886              $link_image_id    = "linkid".randpassword(6);
 887              $link_name_id     = ' name="'.$link_image_id.'" id="'.$link_image_id.'"';
 888  
 889              if(!$struct[$key]["acat_redirect"]) {
 890                  $link = 'index.php?';
 891                  if($struct[$key]["acat_alias"]) {
 892                      $link .= html_specialchars($struct[$key]["acat_alias"]);
 893                  } else {
 894                      $link .= 'id='.$key; //',0,0,1,0,0';
 895                  }
 896                  $redirect['target'] = '';
 897              } else {
 898                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
 899                  $link = $redirect['link'];
 900              }
 901  
 902              $js        = ' style="cursor:pointer;cursor:hand;"'; //display:block;
 903              $js_act = $js;
 904              if($nav_table_struct["js_over_effects"]) {
 905  
 906                  if($redirect['target'] != ' target="_blank"') {
 907                      $js .= " onclick=\"location.href='".js_singlequote($link)."';return false;\"";
 908                  } else {
 909                      $js .= " onclick=\"window.open('".js_singlequote($link)."', 'phpwcmnewwin');return false;\"";
 910                  }
 911  
 912                  $js_act = $js;
 913                  $js .= ' onmouseover="';
 914                  if($nav_table_struct["linkimage_over_js"]) {
 915                      $js .= "MM_swapImage('".$link_image_id."','','".$nav_table_struct["linkimage_over_js"]."',1);";
 916                  }
 917                  if($nav_table_struct["row_over_bgcolor"]) $js .= "this.bgColor='".$nav_table_struct["row_over_bgcolor"]."';";
 918                  $js .= '" onmouseout="';
 919                  if($nav_table_struct["linkimage_over_js"]) $js .= "MM_swapImgRestore();";
 920                  if($nav_table_struct["row_norm_bgcolor"]) $js .= "this.bgColor='".$nav_table_struct["row_norm_bgcolor"]."';";
 921                  $js .= '"';
 922              } else {
 923                  $js = '';
 924              }
 925              
 926              // add structure level based classes
 927              if(!empty($struct[$key]["acat_class"])) {
 928                  $nav_table_struct_temp = $nav_table_struct;
 929                  $nav_table_struct["row_norm_class"]        = trim($nav_table_struct["row_norm_class"].' '.$struct[$key]["acat_class"]);
 930                  $nav_table_struct["row_active_class"]    = trim($nav_table_struct["row_active_class"].' '.$struct[$key]["acat_class"]);
 931                  $nav_table_struct["row_space_class"]    = 'row_space '.$struct[$key]["acat_class"];
 932              } else {
 933                  $nav_table_struct_temp = NULL;
 934              }
 935  
 936              //spacer row
 937              if($nav_table_struct["row_space"]) {
 938                  $space_row  = "<tr".table_attributes($nav_table_struct, "row_space", 0, true).">\n".$space_cell;
 939                  $space_row .= "<td".$colspan.">".spacer(1, $nav_table_struct["row_space"])."</td>";
 940                  $space_row .= $space_right."\n</tr>\n";
 941                  $temp_menu .= $space_row;
 942              }
 943  
 944              if(!empty($temp_tree[$key])) {
 945                  //if($act_cat_id == $key) {
 946                  //check if inside active tree structure
 947                  if($act_cat_id == $key || (!empty($nav_table_struct["all_nodes_active"]) && isset($GLOBALS['LEVEL_KEY'][$key]))) {
 948                      $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_active", 0, true).$js_act.">\n".$left_cell;
 949                      $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_active"])."</td>\n";
 950                      $temp_menu .= "<td".table_attributes($nav_table_struct, "cell_active", 1, true).$colspan.">".$cell_top;
 951                      $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
 952                      $temp_menu .= $nav_table_struct["link_active_before"];
 953                      $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
 954                      $temp_menu .= $nav_table_struct["link_active_after"].'</a>';
 955                  } else {
 956                      $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_norm", 0, true).$js.">\n".$left_cell;
 957                      $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_norm"])."</td>\n";
 958                      $temp_menu .= "<td".table_attributes($nav_table_struct, "cell", 1, true).$colspan.">".$cell_top;
 959                      $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
 960                      $temp_menu .= $nav_table_struct["link_before"];
 961                      $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
 962                      $temp_menu .= $nav_table_struct["link_after"].'</a>';
 963                  }
 964  
 965                  $temp_menu .= $cell_bottom."</td>\n".$right_cell."</tr>\n";
 966                  $temp_menu .= build_levels ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
 967              } else {
 968                  $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_norm", 0, true).$js.">\n".$left_cell;
 969                  $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_norm"])."</td>\n";
 970                  $temp_menu .= "<td".table_attributes($nav_table_struct, "cell", 1, true).$colspan.">".$cell_top;
 971                  $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
 972                  $temp_menu .= $nav_table_struct["link_before"];
 973                  $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
 974                  $temp_menu .= $nav_table_struct["link_after"].'</a>';
 975                  $temp_menu .= $cell_bottom."</td>\n".$right_cell."</tr>\n";
 976              }
 977              
 978              // reset table structure attributes
 979              if($nav_table_struct_temp !== NULL) {
 980                  $nav_table_struct = $nav_table_struct_temp;
 981              }
 982          }
 983      }
 984  
 985      if($nav_table_struct["row_space"] && $count == 1) {
 986          $temp_menu .= $space_row;
 987      }
 988  
 989      return $temp_menu;
 990  }
 991  
 992  function list_articles_summary($alt=NULL, $topcount=99999, $template='') {
 993      // returns an article listing only with headline and summary text
 994      // and with an listing of all other available articles of this category
 995  
 996      global $content;
 997      global $template_default;
 998      global $_getVar;
 999  
1000      // alternative way to send article listings
1001      if(is_array($alt)) {
1002          // first save default value of $content["articles"]
1003          $_old_articles            = $content["articles"];
1004          $content["articles"]    = $alt;
1005          $temp_topcount            = intval($topcount);
1006          if($temp_topcount == 0) {
1007              $temp_topcount        = $content['struct'][ $content['cat_id'] ]['acat_topcount'];
1008          }
1009          $template                = trim($template);
1010      } else {
1011          $temp_topcount = $content['struct'][ $content['cat_id'] ]['acat_topcount'];
1012      }
1013  
1014      $max_articles = count($content["articles"]);
1015  
1016      if(empty($template_default['article_paginate_show'])) {
1017          $paginate_show = array('bottom'=>1);
1018      } else {
1019          $paginate_show = array();
1020          foreach((explode(' ', $template_default['article_paginate_show'])) as $value) {
1021              if($value == 'top') {
1022                  $paginate_show['top'] = 1;
1023              } elseif($value == 'bottom') {
1024                  $paginate_show['bottom'] = 1;
1025              } elseif(strpos($value, 'rt') !== false) {
1026                  $paginate_show['rt'] = str_replace('rt', '', $value);
1027              }
1028          }
1029          if(!count($paginate_show)) {
1030              $paginate_show = array('bottom'=>1);
1031          }
1032      }
1033  
1034      if($content['struct'][ $content['cat_id'] ]['acat_paginate'] && $content['struct'][ $content['cat_id'] ]['acat_maxlist'] && $max_articles > $content['struct'][ $content['cat_id'] ]['acat_maxlist']) {
1035  
1036          $paginate         = true;
1037          $paginate_navi    = empty($template_default['article_paginate_navi']) ? '<div class="phpwcmsArticleListNavi">{PREV:&laquo;} {NEXT:&raquo;}</div>' : $template_default['article_paginate_navi'];
1038          $max_pages        = ceil($max_articles / $content['struct'][ $content['cat_id'] ]['acat_maxlist']);
1039  
1040          // always do full top article listing because of paginating
1041          $temp_topcount    = $max_articles+1;
1042  
1043          if(isset($_getVar['listpage'])) {
1044              $page_current = intval($_getVar['listpage']);
1045              if($page_current < 1) {
1046                  $page_current = 1;
1047              } elseif($page_current > $max_pages) {
1048                  $page_current = $max_pages;
1049              }
1050          } else {
1051              $page_current = 1;
1052          }
1053  
1054          $page_next = $page_current;
1055          $page_prev = $page_current;
1056          if($page_current < $max_pages) {
1057              $page_next = $page_current + 1;
1058          }
1059          if($page_current > 1) {
1060              $page_prev = $page_current - 1;
1061          }
1062  
1063          // setting pagination navi
1064  
1065          $page_article_max = $content['struct'][ $content['cat_id'] ]['acat_maxlist'] * $page_current;
1066          $page_article_at  = $content['struct'][ $content['cat_id'] ]['acat_maxlist'] * ($page_current - 1);
1067          $page_article_at  = $page_article_at + 1;
1068          if($page_article_max > $max_articles) $page_article_max = $max_articles;
1069  
1070          $paginate_navi = str_replace('#####',    $max_articles,             $paginate_navi);
1071          $paginate_navi = str_replace('####',    $page_article_max,         $paginate_navi);
1072          $paginate_navi = str_replace('###',     $page_article_at,        $paginate_navi);
1073          $paginate_navi = str_replace('##',         $max_pages,             $paginate_navi);
1074          $paginate_navi = str_replace('#',         $page_current,             $paginate_navi);
1075  
1076          $GLOBALS['paginate_temp'] = array('next' => '', 'prev' => '', 'navi' => '');
1077  
1078          $paginate_navi = preg_replace_callback('/\{NEXT:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["next"]=$matches[1]; return "{NEXT}";'), $paginate_navi);
1079          $paginate_navi = preg_replace_callback('/\{PREV:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["prev"]=$matches[1]; return "{PREV}";'), $paginate_navi);
1080          $paginate_navi = preg_replace_callback('/\{NAVI:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["navi"]=$matches[1]; return "{NAVI}";'), $paginate_navi);
1081  
1082          // next page link
1083          if($GLOBALS['paginate_temp']['next'] && $page_current < $max_pages) {
1084              $_getVar['listpage'] = $page_next;
1085              $page_next_link = '<a href="index.php' . returnGlobalGET_QueryString('htmlentities') . '">' . $GLOBALS['paginate_temp']['next'] . '</a>';
1086          } else {
1087              $page_next_link = $GLOBALS['paginate_temp']['next'];
1088          }
1089  
1090          // previous page link
1091          if($GLOBALS['paginate_temp']['prev'] && $page_current > 1) {
1092              $_getVar['listpage'] = $page_prev;
1093              $page_prev_link = '<a href="index.php' . returnGlobalGET_QueryString('htmlentities') . '">' . $GLOBALS['paginate_temp']['prev'] . '</a>';
1094          } else {
1095              $page_prev_link = $GLOBALS['paginate_temp']['prev'];
1096          }
1097  
1098          // set listpage value to current page
1099  
1100          $paginate_navi = str_replace('{NEXT}', $page_next_link, $paginate_navi);
1101          $paginate_navi = str_replace('{PREV}', $page_prev_link, $paginate_navi);
1102  
1103          // temporary unset GET listpage setting
1104          unset($_getVar['listpage']);
1105  
1106          if($GLOBALS['paginate_temp']['navi']) {
1107  
1108              $navi = explode(',', $GLOBALS['paginate_temp']['navi'], 2);
1109              $navi[0] = trim($navi[0]);
1110  
1111              $navi[1]         = empty($navi[1])    ? array(0 => ' ') : explode('|', $navi[1]);
1112              $navi['spacer']    = empty($navi[1][0]) ? ' ' : $navi[1][0]; //spacer
1113              $navi['prefix']    = empty($navi[1][1]) ? ''  : $navi[1][1]; //prefix
1114              $navi['suffix']    = empty($navi[1][2]) ? ''  : $navi[1][2]; //suffix
1115  
1116              $navi['navi']     = $navi['prefix'];
1117  
1118              if($navi[0] == '123') {
1119  
1120                  for($i = 1; $i <= $max_pages; $i++) {
1121  
1122                      if($i > 1) $navi['navi'] .= $navi['spacer'];
1123                      $navi['navi'] .= ($i == $page_current) ? $i : '<a href="' . rel_url( array('listpage'=>$i) ) . '">'.$i.'</a>';
1124  
1125                  }
1126  
1127              } elseif($navi[0] == '1-3') {
1128  
1129                  for($i = 0; $i < $max_pages; $i++) {
1130  
1131                      $i_start    = $i * $content['struct'][ $content['cat_id'] ]['acat_maxlist'] + 1;
1132                      $i_end        = $i_start - 1 + $content['struct'][ $content['cat_id'] ]['acat_maxlist'];
1133                      if($i_end > $max_articles) $i_end = $max_articles;
1134  
1135                      if($i > 0) $navi['navi'] .= $navi['spacer'];
1136                      $i_entry     = $i_start.'&ndash;'.$i_end;
1137                      $i_page     = $i+1;
1138                      $navi['navi'] .= ($i_page == $page_current) ? $i_entry : '<a href="' . rel_url( array('listpage'=>$i_page) ) . '">'.$i_entry.'</a>';
1139  
1140                  }
1141  
1142              }
1143  
1144              $navi['navi'] .= $navi['suffix'];
1145  
1146              // replace navi
1147              $paginate_navi = str_replace('{NAVI}', $navi['navi'], $paginate_navi);
1148  
1149          }
1150  
1151          // reset GET listpage setting
1152          $_getVar['listpage'] = $page_current;
1153  
1154          unset($GLOBALS['paginate_temp']);
1155  
1156      } else {
1157          $paginate         = false;
1158          $paginate_navi    = '';
1159      }
1160  
1161  
1162      $tmpllist         = array(); //temporary array for storing templates to minimize load
1163      $temp_counter     = 0;
1164      $space_counter    = 0;
1165  
1166      $listing         = $template_default["space_top"]; //start with space at top
1167  
1168      if(isset($paginate_show['top'])) {
1169          $listing        .= str_replace('{POS}', 'top', $paginate_navi);
1170      }
1171  
1172      foreach($content["articles"] as $article) {
1173  
1174          if($paginate && $content['struct'][ $content['cat_id'] ]['acat_maxlist']) {
1175              // get page number based on current article counter
1176              $page_article = ceil( ($temp_counter + 1) / $content['struct'][ $content['cat_id'] ]['acat_maxlist']);
1177              if($page_article > $page_current) {
1178                  //stop listing
1179                  break;
1180              } elseif($page_article != $page_current) {
1181                  //no listing - goto next article
1182                  $temp_counter++;
1183                  continue;
1184              }
1185          }
1186  
1187          $link_data        = get_article_morelink($article);
1188          $article_link     = $link_data[0];
1189  
1190          //add available keywords to page wide keyword field
1191          $content['all_keywords'] .= $article["article_keyword"].',';
1192  
1193          if($temp_counter < $temp_topcount) {
1194              // as long as the counter is lower than the default "top_count" value
1195              // show the complete article summary listing
1196  
1197              $article["article_image"] = setArticleSummaryImageData($article["article_image"]);
1198              
1199              if($template) {
1200                  $article["article_image"]['tmpllist'] = $template;
1201              }
1202  
1203              // build image/image link
1204              $article["article_image"]["poplink"]    = '';
1205              $thumb_image                             = false;
1206              $thumb_img                                 = '';
1207              
1208              $img_thumb_name        = '';
1209              $img_thumb_rel        = '';
1210              $img_thumb_abs        = '';
1211              $img_thumb_width    = 0;
1212              $img_thumb_height    = 0;
1213              
1214              $img_zoom_name        = '';
1215              $img_zoom_rel        = '';
1216              $img_zoom_abs        = '';
1217              $img_zoom_width        = 0;
1218              $img_zoom_height    = 0;
1219              
1220              if(empty($article["article_image"]["list_caption"])) {
1221                  $article["article_image"]["list_caption"] = '';
1222              }
1223              $caption = getImageCaption($article["article_image"]["list_caption"]);
1224  
1225              $article["article_image"]["list_caption"]    = $caption[0]; // caption text
1226              $article["article_image"]["copyright"]        = $caption[4]; // copyright information
1227              
1228              if(!empty($article["article_image"]["list_hash"])) {
1229  
1230                  $thumb_image = get_cached_image(
1231                                      array(    "target_ext"    =>    $article["article_image"]['list_ext'],
1232                                              "image_name"    =>    $article["article_image"]['list_hash'] . '.' . $article["article_image"]['list_ext'],
1233                                              "max_width"        =>    $article["article_image"]['list_width'],
1234                                              "max_height"    =>    $article["article_image"]['list_height'],
1235                                              "thumb_name"    =>    md5($article["article_image"]['list_hash'].$article["article_image"]['list_width'].$article["article_image"]['list_height'].$GLOBALS['phpwcms']["sharpen_level"])
1236                                        ));
1237  
1238                  if($thumb_image != false) {
1239                  
1240                      $img_thumb_name        = $thumb_image[0];
1241                      $img_thumb_rel        = PHPWCMS_IMAGES.$thumb_image[0];
1242                      $img_thumb_abs        = PHPWCMS_URL.PHPWCMS_IMAGES.$thumb_image[0];
1243                      $img_thumb_width    = $thumb_image[1];
1244                      $img_thumb_height    = $thumb_image[2];
1245  
1246                      $caption[3] = empty($caption[3]) ? '' : ' title="'.html_specialchars($caption[3]).'"';
1247                      $caption[1] = html_specialchars($caption[1]);
1248  
1249                      $thumb_img = '<img src="'.PHPWCMS_IMAGES . $thumb_image[0] .'" border="0" '.$thumb_image[3].' alt="'.$caption[1].'"'.$caption[3].' />';
1250  
1251                      if($article["article_image"]["list_zoom"]) {
1252  
1253                          $zoominfo = get_cached_image(
1254                                              array(    "target_ext"    =>    $article["article_image"]['list_ext'],
1255                                                      "image_name"    =>    $article["article_image"]['list_hash'] . '.' . $article["article_image"]['list_ext'],
1256                                                      "max_width"        =>    $GLOBALS['phpwcms']["img_prev_width"],
1257                                                      "max_height"    =>    $GLOBALS['phpwcms']["img_prev_height"],
1258                                                      "thumb_name"    =>    md5($article["article_image"]['list_hash'].$GLOBALS['phpwcms']["img_prev_width"].$GLOBALS['phpwcms']["img_prev_height"].$GLOBALS['phpwcms']["sharpen_level"])
1259                                                        )
1260                                                  );
1261  
1262                          if($zoominfo != false) {
1263                          
1264                              $img_zoom_name        = $zoominfo[0];
1265                              $img_zoom_rel        = PHPWCMS_IMAGES.$zoominfo[0];
1266                              $img_zoom_abs        = PHPWCMS_URL.PHPWCMS_IMAGES.$zoominfo[0];
1267                              $img_zoom_width        = $zoominfo[1];
1268                              $img_zoom_height    = $zoominfo[2];
1269  
1270                              $article["article_image"]["poplink"] = 'image_zoom.php?'.getClickZoomImageParameter($zoominfo[0].'?'.$zoominfo[3]);
1271  
1272                              if(!empty($caption[2][0])) {
1273                                  $open_link = $caption[2][0];
1274                                  $return_false = '';
1275                              } else {
1276                                  $open_link = $article["article_image"]["poplink"];
1277                                  $return_false = 'return false;';
1278                              }
1279  
1280                              if(empty($article["article_image"]["list_lightbox"]) && !empty($caption[2][0])) {
1281                                  
1282                                  initFrontendJS();
1283                                  
1284                                  $article["article_image"]["poplink"]  = '<a href="'.$article["article_image"]["poplink"].'" ';
1285                                  $article["article_image"]["poplink"] .= 'onclick="checkClickZoom();clickZoom(\''.$open_link;
1286                                  $article["article_image"]["poplink"] .= "','previewpic','width=".$zoominfo[1];
1287                                  $article["article_image"]["poplink"] .= ",height=".$zoominfo[2]."');".$return_false;
1288                                  $article["article_image"]["poplink"] .= '"'.$caption[2][1].'>';
1289                              } else {
1290                                  // lightbox
1291                                  initSlimbox();
1292                                  
1293                                  $article["article_image"]["poplink"]  = '<a href="'.PHPWCMS_IMAGES.$zoominfo[0].'" rel="lightbox" ';
1294                                  if($article["article_image"]["list_caption"]) {
1295                                      $article["article_image"]["poplink"] .= 'title="'.parseLightboxCaption($article["article_image"]["list_caption"]).'" ';
1296                                  }
1297                                  $article["article_image"]["poplink"] .= 'target="_blank">';
1298                              }
1299                                                                     
1300                              $article["article_image"]["poplink"] .= $thumb_img.'</a>';
1301                          }
1302                      }
1303  
1304                      unset($caption);
1305                  }
1306              } else {
1307              
1308                  $article["article_image"]["list_id"]    = 0;
1309                  $article["article_image"]["list_hash"]    = '';
1310      
1311              }
1312  
1313  
1314              // set default template
1315              if(empty($article["article_image"]['tmpllist']) || $article["article_image"]['tmpllist'] == 'default') {
1316  
1317                  $article["article_image"]['tmpllist'] = 'default';
1318  
1319                  if(empty($tmpllist['default'])) {
1320  
1321                      $tmpllist['default'] = file_get_contents(PHPWCMS_TEMPLATE.'inc_default/article_summary_list.tmpl');
1322  
1323                  }
1324  
1325              }
1326  
1327              // try to read the template files
1328              // 1. try to check if template was read
1329              if(!isset($tmpllist[ $article["article_image"]['tmpllist'] ])) {
1330                  $tmpllist[ $article["article_image"]['tmpllist'] ] = @file_get_contents(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/list/'.$article["article_image"]['tmpllist']);
1331              }
1332              if($tmpllist[ $article["article_image"]['tmpllist'] ]) {
1333              
1334                  // set frontend edit link
1335                  $tmpl  = getFrontendEditLink('summary', $article['article_id']);
1336              
1337                  //rendering
1338                  $tmpl .= $tmpllist[ $article["article_image"]['tmpllist'] ];
1339                  
1340                  $tmpl = render_cnt_template($tmpl, 'TITLE', empty($article['article_notitle']) ? html_specialchars($article["article_title"]) : '' );
1341                  $tmpl = render_cnt_template($tmpl, 'SUB', html_specialchars($article["article_subtitle"]));
1342                  
1343                  // replace thumbnail and zoom image information
1344                  $tmpl = str_replace( array(    '{THUMB_NAME}', '{THUMB_REL}', '{THUMB_ABS}', '{THUMB_WIDTH}', '{THUMB_HEIGHT}',
1345                                              '{IMAGE_NAME}', '{IMAGE_REL}', '{IMAGE_ABS}', '{IMAGE_WIDTH}', '{IMAGE_HEIGHT}',
1346                                              '{IMAGE_ID}',     '{IMAGE_HASH}' ),
1347                                       array(    $img_thumb_name, $img_thumb_rel, $img_thumb_abs, $img_thumb_width, $img_thumb_height,
1348                                              $img_zoom_name, $img_zoom_rel, $img_zoom_abs, $img_zoom_width, $img_zoom_height,
1349                                              $article["article_image"]["list_id"], $article["article_image"]["list_hash"] ),
1350                                       $tmpl );
1351                  
1352                  if( preg_match('/\{SUMMARY:(\d+)\}/', $tmpl, $matches) ) {
1353                      if(empty($article['article_image']['list_maxwords'])) {
1354                          $article['article_image']['list_maxwords'] = intval($matches[1]);
1355                      }                    
1356                      $tmpl = preg_replace('/\{SUMMARY:\d+\}/', '{SUMMARY}', $tmpl);
1357                  }
1358                  
1359                  $tmpl = render_cnt_template($tmpl, 'SUMMARY', empty($article['article_image']['list_maxwords']) ? $article["article_summary"] : getCleanSubString($article["article_summary"], $article['article_image']['list_maxwords'], $template_default['ellipse_sign'], 'word'));
1360                  $tmpl = render_cnt_template($tmpl, 'IMAGE', $thumb_img);
1361                  $tmpl = render_cnt_template($tmpl, 'ZOOMIMAGE', $article["article_image"]["poplink"]);
1362                  $tmpl = render_cnt_template($tmpl, 'CAPTION', nl2br(html_specialchars($article["article_image"]["list_caption"])));
1363                  $tmpl = render_cnt_template($tmpl, 'COPYRIGHT', html_specialchars($article["article_image"]["copyright"]));
1364                  $tmpl = render_cnt_template($tmpl, 'ARTICLELINK', $article["article_morelink"] ? $article_link : '');
1365                  $tmpl = render_cnt_template($tmpl, 'EDITOR', html_specialchars($article["article_username"]));
1366                  $tmpl = render_cnt_template($tmpl, 'ARTICLEID', $article["article_id"]);
1367                  $tmpl = render_cnt_template($tmpl, 'MORE', $article["article_morelink"] ? $template_default["top_readmore_link"] : '');
1368                  $tmpl = render_cnt_template($tmpl, 'TARGET', ($article["article_morelink"] && $link_data[1]) ? ' target="'.$link_data[1].'"' : '');
1369                  $tmpl = render_cnt_template($tmpl, 'BEFORE', '<!--before//-->');
1370                  $tmpl = render_cnt_template($tmpl, 'AFTER', '<!--after//-->');
1371                  $tmpl = render_cnt_date($tmpl, $article["article_date"], $article["article_livedate"], $article["article_killdate"] );
1372                  if($space_counter) {
1373                      $tmpl = render_cnt_template($tmpl, 'SPACE', '<!--space//-->');
1374                  } else {
1375                      $tmpl = render_cnt_template($tmpl, 'SPACE', '');
1376                  }
1377                  $listing .= $tmpl;
1378                  $article["article_image"]['tmpllist'] = 1;
1379              } else {
1380                  $article["article_image"]['tmpllist'] = 0;
1381              }
1382  
1383          } else {
1384              // if "top_count" value is equal or larger
1385              // show only the article headline listing
1386              if($temp_counter && $temp_counter == $temp_topcount) {
1387                  $listing .= $template_default["space_aftertop_text"];
1388              } elseif ($temp_counter) {
1389                  $listing .= $template_default["space_between_list"];
1390              }
1391              
1392              $listing .= $template_default["list_headline_before"];
1393              
1394              // set frontend edit link
1395              $listing .= getFrontendEditLink('article', $article['article_id']);
1396              $listing .= getFrontendEditLink('summary', $article['article_id']);            
1397              
1398              $listing .= '<a href="'.$article_link.'">';
1399              $listing .= $template_default["list_startimage"];
1400              $listing .= html_specialchars($article["article_title"]);
1401              $listing .= '</a>'.$template_default["list_headline_after"];
1402  
1403          }
1404          $temp_counter++;
1405          $space_counter++;
1406      }
1407  
1408      if(isset($paginate_show['bottom'])) {
1409          $listing .= str_replace('{POS}', 'bottom', $paginate_navi);
1410      }
1411      if(!empty($paginate_show['rt'])) {
1412          $content['globalRT'][ $paginate_show['rt'] ] = $paginate_navi;
1413      }
1414  
1415      // restore original articles
1416      if(isset($_old_articles)) {
1417          $content["articles"]    = $_old_articles;
1418      }
1419  
1420      $listing .= $template_default["space_bottom"]; //ends with space at bottom
1421      return $listing;
1422  }
1423  
1424  function get_html_part($value, $class="", $link="", $span_or_div=1) {
1425      // returns a content part for html output like
1426      // <span class="xxx">html</span>
1427      if($value) {
1428          $html_tag  = ($span_or_div) ? 'span' : 'div';
1429          $html_part = ($link) ? '<a href="'.$link.'">'.html_specialchars($value).'</a>' : html_specialchars($value);
1430          if($class) {
1431              $html_part = '<'.$html_tag.' class="'.$class.'">'.$html_part;
1432          } else {
1433              $html_part = '<'.$html_tag.'>'.$html_part;
1434          }
1435          return $html_part.'</'.$html_tag.'>';
1436      } else {
1437          return '';
1438      }
1439  }
1440  
1441  function span_class($value, $class) {
1442      return !empty($class) ? '<span class="'.$class.'">'.$value.'</span>' : $value;
1443  }
1444  
1445  function div_class($value, $class, $tag='div') {
1446      return !empty($class) ? '<'.$tag.' class="'.$class.'">'.$value.'</'.$tag.'>' : $value;
1447  }
1448  
1449  function get_class_attrib($class) {
1450      return !empty($class) ? ' class="'.$class.'"' : '';
1451  }
1452  
1453  function html_parser($string) {
1454      // parse the $string and replace all possible
1455      // values with $replace
1456      
1457      if(trim($string) == '') {
1458          return $string;    
1459      }
1460      
1461      $string = render_bbcode_basics($string, '');
1462  
1463      // page TOP link
1464      $search[0]        = '/\[TOP\](.*?)\[\/TOP\]/is';
1465      $replace[0]        = '<a href="#top" class="phpwcmsTopLink">$1</a>';
1466  
1467      // internal Link to article ID
1468      $search[1]        = '/\[ID (\d+)\](.*?)\[\/ID\]/s';
1469      $replace[1]        = '<a href="index.php?aid=$1" class="phpwcmsIntLink">$2</a>';
1470  
1471      // external Link (string)
1472      $search[2]        = '/\[EXT (.*?)\](.*?)\[\/EXT\]/s';
1473      $replace[2]        = '<a href="$1" target="_blank" class="phpwcmsExtLink">$2</a>';
1474  
1475      // internal Link (string)
1476      $search[3]        = '/\[INT (.*?)\](.*?)\[\/INT\]/s';
1477      $replace[3]        = '<a href="$1" class="phpwcmsIntLink">$2</a>';
1478  
1479      // random GIF Image
1480      $search[4]        = '/\{RANDOM_GIF:(.*?)\}/';
1481      $replace[4]        = '<img src="img/random_image.php?type=0&imgdir=$1" border="0" alt="" />';
1482  
1483      // random JPEG Image
1484      $search[5]        = '/\{RANDOM_JPEG:(.*?)\}/';
1485      $replace[5]        = '<img src="img/random_image.php?type=1&amp;imgdir=$1" border="0" alt="" />';
1486  
1487      // random PNG Image
1488      $search[6]        = '/\{RANDOM_PNG:(.*?)\}/';
1489      $replace[6]        = '<img src="img/random_image.php?type=2&amp;imgdir=$1" border="0" alt="" />';
1490  
1491      // insert non db image standard
1492      $search[7]        = '/\{IMAGE:(.*?)\}/';
1493      $replace[7]        = '<img src="picture/$1" border="0" alt="" />';
1494  
1495      // insert non db image left
1496      $search[8]        = '/\{IMAGE_LEFT:(.*?)\}/';
1497      $replace[8]        = '<img src="picture/$1" border="0" align="left" alt="" />';
1498  
1499      // insert non db image right
1500      $search[9]        = '/\{IMAGE_RIGHT:(.*?)\}/';
1501      $replace[9]        = '<img src="picture/$1" border="0" align="right" alt="" />';
1502  
1503      // insert non db image center
1504      $search[10]        = '/\{IMAGE_CENTER:(.*?)\}/';
1505      $replace[10]        = '<div align="center"><img src="picture/$1" border="0" alt="" /></div>';
1506  
1507      // insert non db image right
1508      $search[11]         = '/\{SPACER:(\d+)x(\d+)\}/';
1509      $replace[11]     = '<img src="img/leer.gif" border="0" width="$1" height="$2" alt="" />';
1510  
1511      // RSS feed link 
1512      $search[13]        = '/\[RSS (.*?)\](.*?)\[\/RSS\]/s';
1513      $replace[13]    = '<a href="feeds.php?feed=$1" target="_blank" class="phpwcmsRSSLink">$2</a>';
1514  
1515      // back Link (string)
1516      $search[14]        = '/\[BACK\](.*?)\[\/BACK\]/i';
1517      $replace[14]     = '<a href="#" target="_top" title="go back" onclick="history.back();return false;" class="phpwcmsBackLink">$1</a>';
1518  
1519      // random Image Tag
1520      $search[15]        = '/\{RANDOM:(.*?)\}/e';
1521      $replace[15]    = 'get_random_image_tag("$1");';
1522  
1523      // span or div style
1524      $search[16]        = '/\[(span|div)_style:(.*?)\](.*?)\[\/style\]/s';
1525      $replace[16]    = '<$1 style="$2">$3</$1>';
1526  
1527      // span or div class
1528      $search[17]        = '/\[(span|div)_class:(.*?)\](.*?)\[\/class\]/s';
1529      $replace[17]    = '<$1 class="$2">$3</$1>';
1530  
1531      // anchor link
1532      $search[22]        = '/\{A:(.*?)\}/is';
1533      $replace[22]    = '<a name="$1" class="phpwcmsAnchorLink"></a>';
1534  
1535      // this parses an E-Mail Link without subject (by Florian, 21-11-2003)
1536      $search[23]     = '/\[E{0,1}MAIL (.*?)\](.*?)\[\/E{0,1}MAIL\]/is';
1537      $replace[23]    = '<a href="mailto:$1" class="phpwcmsMailtoLink">$2</a>';
1538  
1539      // this tags out a Mailaddress with an predifined subject (by Florian, 21-11-2003)
1540      $search[24]     = '/\[MAILSUB (.*?) (.*?)\](.*?)\[\/MAILSUB\]/is';
1541      $replace[24]    = '<a href="mailto:$1?subject=$2" class="phpwcmsMailtoLink">$3</a>';
1542  
1543      $search[26]     = '/\<br>/i';
1544      $replace[26]    = '<br />';
1545  
1546      // create "make bookmark" javascript code
1547      $search[27]     = '/\[BOOKMARK\s{0,}(.*)\](.*?)\[\/BOOKMARK\]/is';
1548      $replace[27]    = '<a href="#" onclick="return BookMark_Page(\'$1\');" title="$1" class="phpwcmsBookmarkLink">$2</a>';
1549  
1550      // ABBreviation
1551      $search[28]        = '/\[abbr (.*?)\](.*?)\[\/abbr\]/is';
1552      $replace[28]    = '<abbr title="$1">$2</abbr>';
1553  
1554      $search[29]        = '/\[dfn (.*?)\](.*?)\[\/dfn\]/is';
1555      $replace[29]    = '<dfn title="$1">$2</dfn>';
1556  
1557      $search[34]        = '/\[blockquote (.*?)\](.*?)\[\/blockquote\]/is';
1558      $replace[34]    = '<blockquote cite="$1">$2</blockquote>';
1559  
1560      $search[35]        = '/\[acronym (.*?)\](.*?)\[\/acronym\]/is';
1561      $replace[35]    = '<acronym title="$1">$2</acronym>';
1562  
1563      $search[36]        = '/\[ID (.*?)\](.*?)\[\/ID\]/s';
1564      $replace[36]    = '<a href="index.php?$1" class="phpwcmsIntLink">$2</a>';
1565  
1566      $search[49]     = '/\[E{0,1}MAIL\](.*?)\[\/E{0,1}MAIL\]/is';
1567      $replace[49]    = '<a href="mailto:$1" class="phpwcmsMailtoLink">$1</a>';
1568  
1569      $string = preg_replace($search, $replace, $string);
1570      $string = str_replace('&#92;&#039;', '&#039;', $string);
1571      $string = str_replace('&amp;quot;', '&quot;', $string);
1572      return $string;
1573  }
1574  
1575  function include_ext_php($inc_file, $t=0) {
1576      // includes an external PHP script file and returns
1577      // the result as string from buffered include content
1578      $ext_php_content = '';
1579  
1580      //check if this is a local file
1581      if(is_file($inc_file) && !$t) {
1582  
1583          $this_path = str_replace("\\", '/', dirname(realpath($inc_file)));
1584          $this_path = preg_replace('/\/$/', '', $this_path);
1585  
1586          $root_path = str_replace("\\", '/', realpath(PHPWCMS_ROOT));
1587          $root_path = preg_replace('/\/$/', '', $root_path);
1588  
1589          if(strpos($this_path, $root_path) === 0) $t = 1;
1590  
1591      } elseif(!$t && !empty($GLOBALS['phpwcms']['allow_remote_URL'])) {
1592          //if remote URL is allowed in conf.inc.php
1593          $t = 1;
1594      }
1595  
1596      if($t) {
1597          ob_start();
1598          @include($inc_file);
1599          $ext_php_content = ob_get_contents();
1600          ob_end_clean();
1601      }
1602  
1603      return $ext_php_content;
1604  }
1605  
1606  function international_date_format($language="EN", $format="Y/m/d", $date_now=0) {
1607      // formats the given date
1608      // for the specific language
1609      // use the normal date format options
1610  
1611      if(!$format) {
1612          $format = "Y/m/d";
1613      }
1614      if(!intval($date_now)) {
1615          $date_now = time();
1616      }
1617      if($language == "EN" || !$language) {
1618          return date($format, $date_now);
1619      } else {
1620          $lang_include = PHPWCMS_ROOT.'/include/inc_lang/date/'.substr(strtolower($language), 0, 2).'.date.lang.php';
1621          if(is_file($lang_include)) {
1622  
1623              include($lang_include);
1624              $date_format_function = array (    "a" => 1, "A" => 1, "B" => 1, "d" => 1, "g" => 1, "G" => 1,
1625                                      "h" => 1, "H" => 1, "i" => 1, "I" => 1, "j" => 1, "m" => 1,
1626                                      "n" => 1, "s" => 1, "t" => 1, "T" => 1, "U" => 1, "w" => 1,
1627                                      "Y" => 1, "y" => 1, "z" => 1, "Z" => 1,
1628                                      "D" => 0, "F" => 0, "l" => 0, "M" => 0, "S" => 0
1629                                     );
1630  
1631              $str_length = strlen($format); $date = "";
1632              for($i = 0; $i < $str_length; $i++) $date_format[$i] = substr($format, $i, 1);
1633              foreach($date_format as $key => $value) {
1634                  if(isset($date_format_function[$value])) {
1635                      if($date_format_function[$value]) {
1636                          $date .= date($value, $date_now);
1637                      } else{
1638                          switch($value) {
1639                              case "D":    $date .= $weekday_short[ intval(date("w", $date_now)) ]; break; //short weekday name
1640                              case "l":    $date .= $weekday_long[ intval(date("w", $date_now)) ]; break; //long weekday name
1641                              case "F":    $date .= $month_long[ intval(date("n", $date_now)) ]; break; //long month name
1642                              case "M":    $date .= $month_short[ intval(date("n", $date_now)) ]; break; //long month name
1643                              case "S":    $date .= ""; break;
1644                          }
1645                      }
1646                  } else {
1647                      $date .= $value;
1648                  }
1649              }
1650  
1651          } else {
1652              $date = date($format, $date_now);
1653          }
1654      }
1655      return $date;
1656  }
1657  
1658  function get_random_image_tag($path) {
1659      // returns an random image from the give path
1660      // it looks for image of following type: gif, jpg, jpeg, png
1661      // {RANDOM:path} willl return <img src="path/rand_image" />
1662      // {RANDOM:SRC:path} willl return absolute URI PHPWCMS_URL/path/rand_image
1663  
1664      $imgArray    = array();
1665      $path        = trim($path);
1666      if(strtoupper(substr($path, 0, 4)) == 'SRC:') {
1667          $tag    = false;
1668          $path    = trim(substr($path, 4));
1669      } else {
1670          $tag    = true;
1671      }
1672      
1673      $path        = trim($path, '/');
1674      $imgpath    = PHPWCMS_ROOT . '/' . $path . '/';
1675      $imageinfo    = false;
1676  
1677      if(is_dir($imgpath)) {
1678          $handle = opendir( $imgpath );
1679          while($file = readdir( $handle )) {
1680                 if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) {
1681                  $imgArray[] = $file;
1682              }
1683          }
1684          closedir( $handle );
1685      }
1686  
1687      if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) {
1688          if($tag) {
1689              return '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
1690          } else {
1691              return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']);
1692          }
1693      }
1694  
1695      return '';
1696  }
1697  
1698  function is_random_image($imgArray, $imagepath, $count=0) {
1699      // tests if the random choosed image is really an image
1700      $count++;
1701      $randval = mt_rand( 0, count( $imgArray ) - 1 );
1702      $file = $imagepath.$imgArray[ $randval ];
1703      $imageinfo = @getimagesize($file);
1704      //if $imageinfo is not true repeat function and count smaller count all images
1705      if(!$imageinfo && $count < count($imgArray)) {
1706          $imageinfo = is_random_image($imgArray, $imagepath, $count);
1707      } else {
1708          $imageinfo["imagename"] = $imgArray[ $randval ];
1709      }
1710      return $imageinfo;
1711  }
1712  
1713  function return_struct_level(&$struct, $struct_id) {
1714      // walk through the given struct level and returns an array with available levels
1715      $level_entry = array();
1716      if(is_array($struct)) {
1717          foreach($struct as $key => $value) {
1718              if( _getStructureLevelDisplayStatus($key, $struct_id) ) {
1719                  $level_entry[$key] = $value;
1720              }
1721          }
1722      }
1723      return $level_entry;
1724  }
1725  
1726  function get_active_categories($struct, $act_struct_id) {
1727      // returns an array with all active categories/structure levels
1728  
1729      $which_cat_array = array();
1730      $which_category = $act_struct_id;
1731      while($which_category) {
1732          $which_cat_array[$which_category] = 1;
1733          $which_category = $GLOBALS['content']["struct"][$which_category]["acat_struct"];
1734      }
1735      return $which_cat_array;
1736  }
1737  
1738  function css_level_list(&$struct, $struct_path, $level, $parent_level_name='', $parent_level=1, $class='') {
1739      // returns list <div><ul><li></li></ul></div> of the current structure level
1740      // if $parent_level=1 the first list entry will be the parent level
1741      // $parent_level=0 - only the list of all levels in this structure
1742      // if $parent_leve_name != "" then it uses the given string
1743      // predefined class for this menu is "list_level"
1744      // PAtched version: http://code.google.com/p/phpwcms/issues/detail?id=256#c6
1745      if(!trim($class)) {
1746          $class = 'list_level';
1747      }
1748      $parent_level_name    = trim($parent_level_name);
1749      $level                 = intval($level);
1750      $parent_level         = intval($parent_level);
1751      $activated            = 0;
1752      $css_list            = '';
1753  
1754      //returns the complete level of NON hidden categories
1755      $level_struct         = return_struct_level($struct, $level);
1756      $breadcrumb         = get_breadcrumb(key($struct_path), $struct);
1757  
1758      foreach($level_struct as $key => $value) {
1759  
1760          if(!$level_struct[$key]["acat_redirect"]) {
1761              $link = 'index.php?';
1762              if($level_struct[$key]["acat_alias"]) {
1763                  $link .= html_specialchars($level_struct[$key]["acat_alias"]);
1764              } else {
1765                  $link .= 'id='.$key; //',0,0,1,0,0';
1766              }
1767              $redirect['target'] = '';
1768          } else {
1769              $redirect = get_redirect_link($level_struct[$key]["acat_redirect"], ' ', '');
1770              $link = $redirect['link'];
1771          }
1772          $css_list .= '    <li';
1773          $liclass   = trim( (empty($breadcrumb[$key]) ? '' : 'active ') . $level_struct[$key]["acat_class"] );
1774          $css_list .= empty($liclass) ? '' : ' class="'.$liclass.'"';
1775          $css_list .= '><a href="'.$link.'"'.$redirect['target'].'>';
1776          $css_list .= html_specialchars($level_struct[$key]["acat_name"]);
1777          $css_list .= '</a></li>'.LF;
1778  
1779      }
1780  
1781      if($parent_level) {
1782          if(!$struct[$level]["acat_redirect"]) {
1783              $link = 'index.php?';
1784              if($struct[$level]["acat_alias"]) {
1785                  $link .= html_specialchars($struct[$level]["acat_alias"]);
1786              } else {
1787                  $link .= 'id='.$level; //',0,0,1,0,0';
1788              }
1789              $redirect['target'] = '';
1790          } else {
1791              $redirect = get_redirect_link($struct[$level]["acat_redirect"], ' ', '');
1792              $link = $redirect['link'];
1793          }
1794  
1795          $css_list_home  = '    <li class="' . trim( ($GLOBALS['aktion'][0] == $level ? 'active' : 'parent') . ' ' . $struct[$level]["acat_class"] ) .'">';
1796          $css_list_home .= '<a href="'.$link.'"'.$redirect['target'].'>';
1797          $css_list_home .= html_specialchars((!$parent_level_name) ? $struct[$level]["acat_name"] : $parent_level_name);
1798          $css_list_home .= '</a></li>'.LF;
1799          $css_list = $css_list_home . $css_list;
1800      }
1801      if($css_list) {
1802          $css_list = LF.'<ul class="'.$class.'">'.LF . $css_list .'</ul>'.LF;
1803      }
1804      return $css_list;
1805  }
1806  
1807  // REWRITE - PATCHED FOR 04/04 // jan212
1808  function url_search($query) {
1809      if ( substr($query,0,4) == '?id=') {
1810          $noid = substr($query, 4);
1811          $file = str_replace(',', '.', $noid).'.'.PHPWCMS_REWRITE_EXT;
1812      } else {
1813          $noid = substr($query,1);
1814          $file = str_replace(',', '.', $noid).'.'.PHPWCMS_REWRITE_EXT;
1815      }
1816      $link = ' href="'.$file.'"';
1817      return($link);
1818  }
1819  
1820  function js_url_search($query) {
1821      if ( substr($query,0,4) == '?id=') {
1822          $noid = substr($query, 4);
1823          $file = str_replace(',', '.', $noid).'.'.PHPWCMS_REWRITE_EXT;
1824          $file = $noid.'.'.PHPWCMS_REWRITE_EXT;
1825      } else {
1826          $noid = substr($query,1);
1827          $file = str_replace(',', '.', $noid).'.'.PHPWCMS_REWRITE_EXT;
1828          $file = $noid.'.'.PHPWCMS_REWRITE_EXT;
1829      }
1830      $link = "onclick=\"location.href='".$file."'";
1831      return($link);
1832  }
1833  
1834  function get_related_articles($keywords, $current_article_id, $template_default, $max_cnt_links=0, $dbcon) {
1835      // find keyword for current article used for RELATED replacementtag
1836      // prepared and inspired by Magnar Stav Johanssen
1837  
1838      $keyword_links = '';
1839      $max_cnt_links = intval($max_cnt_links);
1840  
1841      $keywords = str_replace("ALLKEYWORDS", $GLOBALS['content']['all_keywords'].',', $keywords);
1842  
1843      // replace unwanted chars and convert to wanted
1844      $keywords = str_replace(";", ",", $keywords);
1845      $keywords = str_replace("'", "", $keywords);
1846      $keywords = str_replace(" ", ",", $keywords);
1847      $keywords = str_replace(",,", ",", $keywords);
1848  
1849      // choose comma separated keywords
1850      $keywordarray = explode (",", $keywords);
1851      $keywordarray = array_map('trim', $keywordarray);
1852      $keywordarray = array_diff($keywordarray, array(''));
1853      $keywordarray = array_unique($keywordarray);
1854      $keywordarray = array_map('strtoupper', $keywordarray);
1855      // check for empty keywords or keywords smaller than 3 chars
1856      if(is_array($keywordarray) && count($keywordarray)) {
1857          foreach($keywordarray as $key => $value) {
1858  
1859              if(substr($keywordarray[$key], 0, 1) == '-') {
1860                  $doNotUse = substr($keywordarray[$key], 1);
1861                  foreach($keywordarray as $key2 => $value2) {
1862                      if($doNotUse == $value2) {
1863                          unset($keywordarray[$key2]);
1864                          unset($keywordarray[$key]);
1865                      }
1866                  }
1867              }
1868  
1869              if(isset($keywordarray[$key]) && (strlen($keywordarray[$key]) < 3 || empty($keywordarray[$key]))) {
1870                  unset($keywordarray[$key]);
1871              }
1872          }
1873      }
1874  
1875      if(is_array($keywordarray) && count($keywordarray)) {
1876          $where = "";
1877          foreach($keywordarray as $value) {
1878                  //build where keyword = blabla
1879                  $where .= ($where) ? " OR " : "";
1880                  //replace every "'" to "''" for security reasons with aporeplace()
1881                  $where .= "article_keyword LIKE '%".aporeplace($value)."%'";
1882          }
1883          $limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
1884          $sql  =    "SELECT article_id, article_title, article_cid, article_subtitle, article_summary, article_alias, article_redirect, article_morelink ";
1885          $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND ";
1886          $sql .=    "article_id<>".intval($current_article_id)." AND ";
1887          // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
1888          switch(VISIBLE_MODE) {
1889              case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
1890                      break;
1891              case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
1892                      break;
1893              //case 2: admin mode no additional neccessary
1894          }
1895          $sql .=    "article_begin < NOW() AND article_end > NOW() AND (".$where.") ";
1896          
1897          if(empty($template_default['sort_by'])) $template_default['sort_by'] = '';
1898          
1899          switch($template_default['sort_by']) {
1900          
1901              case 'title_asc': 
1902                          $sql .=    "ORDER BY article_title";
1903                          break;
1904                          
1905              case 'title_desc': 
1906                          $sql .=    "ORDER BY article_title DESC";
1907                          break;
1908                          
1909              case 'ldate_asc': 
1910                          $sql .=    "ORDER BY article_begin";
1911                          break;
1912                          
1913              case 'ldate_desc': 
1914                          $sql .=    "ORDER BY article_begin DESC";
1915                          break;
1916                          
1917              case 'kdate_asc': 
1918                          $sql .=    "ORDER BY article_end";
1919                          break;
1920                          
1921              case 'kdate_desc': 
1922                          $sql .=    "ORDER BY article_end DESC";
1923                          break;
1924                          
1925              case 'cdate_asc': 
1926                          $sql .=    "ORDER BY article_created";
1927                          break;
1928                          
1929              case 'cdate_desc': 
1930                          $sql .=    "ORDER BY article_created DESC";
1931                          break;
1932          
1933              default:
1934                          $sql .=    "ORDER BY article_tstamp DESC";
1935          }
1936          
1937          $sql .= $limit;
1938  
1939          // related things
1940          $target = $template_default["link_target"] ? ' target="'.$template_default["link_target"].'"' : '';
1941          $result = _dbQuery($sql);
1942          if(isset($result[0])) {
1943              foreach($result as $row) {
1944                  
1945                  if(empty($row['article_redirect'])) {
1946                      if(empty($row['article_morelink'])) {
1947                          continue;
1948                      }
1949                      $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
1950                  } else {
1951                      $redirect = get_redirect_link($row['article_redirect'], ' ', '');
1952                      $article_link = $redirect['link'].'"'.$redirect['target'];
1953                  }
1954                  
1955                  if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
1956                      $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
1957                  } else {
1958                      $article_title = $row['article_title'];
1959                  }
1960                  $keyword_links .= $template_default["link_before"];
1961                  $keyword_links .= $template_default["link_symbol"];
1962                  $keyword_links .= '<a href="' . $article_link . '>';
1963                  $keyword_links .= html_specialchars($article_title);
1964                  $keyword_links .= '</a>' . $template_default["link_after"];
1965              }
1966          }
1967      }
1968  
1969      //enclose whole
1970      return empty($keyword_links) ? '' : $template_default["before"].$keyword_links.$template_default["after"];
1971  }
1972  
1973  function get_new_articles(&$template_default, $max_cnt_links=0, $cat, $dbcon) {
1974      // find all new articles
1975  
1976      $max_cnt_links = intval($max_cnt_links);
1977      $limit = empty($max_cnt_links) ?  '' : ' LIMIT '.$max_cnt_links;
1978      $cat = trim($cat);
1979      $cat = (intval($cat) || $cat == '0') ? 'article_cid='.intval($cat).' AND ' : '';
1980      
1981      $sql = 'SELECT article_id, article_title, article_cid, article_alias, article_redirect, article_morelink, ';
1982  
1983      switch( (empty($template_default["sort_by"]) ? '' : strtolower($template_default["sort_by"])) ) {
1984  
1985          case 'cdate':     //use real creation date
1986                          $sql .=    "article_created AS article_date ";
1987                          $sorting = 'article_created';
1988                          break;
1989  
1990          case 'ldate':     //use live/start date
1991                          $sql .=    "UNIX_TIMESTAMP(article_begin) AS article_date ";
1992                          $sorting = 'article_begin';
1993                          break;
1994  
1995          case 'kdate':     //use kill/end date
1996                          $sql .=    "UNIX_TIMESTAMP(article_end) AS article_date ";
1997                          $sorting = 'article_end';
1998                          break;
1999  
2000          default:        $sql .=    "UNIX_TIMESTAMP(article_tstamp) AS article_date ";
2001                          $sorting = 'article_tstamp';
2002      }
2003  
2004      $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat;
2005      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2006      switch(VISIBLE_MODE) {
2007          case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2008                  break;
2009          case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2010                  break;
2011          //case 2: admin mode no additional neccessary
2012      }
2013      $sql .= "article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
2014      $sql .= "ORDER BY ".$sorting." DESC".$limit;
2015  
2016      // new articles list
2017      $new_links = "";
2018      $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : '';
2019      
2020      $result = _dbQuery($sql);
2021      $count  = 0;
2022      
2023      foreach($result as $row) {
2024          
2025              if(empty($row['article_redirect'])) {
2026                  if(empty($row['article_morelink'])) {
2027                      continue;
2028                  }
2029                  $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
2030              } else {
2031                  $redirect = get_redirect_link($row['article_redirect'], ' ', '');
2032                  $article_link = $redirect['link'].'"'.$redirect['target'];
2033              }
2034          
2035              $count++;
2036              if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
2037                  $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
2038              } else {
2039                  $article_title = $row['article_title'];
2040              }
2041              $article_title = html_specialchars($article_title);
2042              if(trim($template_default["date_format"])) {
2043                  $article_title =     $template_default["date_before"] .
2044                                      html_specialchars(international_date_format(
2045                                      $template_default["date_language"],
2046                                      $template_default["date_format"],
2047                                      $row['article_date'])) .
2048                                      $template_default["date_after"] .
2049                                      $article_title;
2050              }
2051              $new_links .= $template_default["link_before"];
2052              $new_links .= $template_default["link_symbol"];
2053              $new_links .= '<a href="' . $article_link . '>' . $article_title . '</a>';
2054              $new_links .= $template_default["link_after"];
2055      }
2056  
2057      //enclose whole
2058      if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
2059  
2060      return $new_links;
2061  }
2062  
2063  function get_article_idlink($article_id=0, $link_text="", $db) {
2064      // returns the internal article link to given article ID/category
2065      $article_id        = intval($article_id);
2066      $article_cid    = 0;
2067      $link_text        = decode_entities($link_text);
2068      $link_text        = html_specialchars($link_text);
2069      $article_title    = $link_text;
2070  
2071      if($article_id) {
2072          $sql =    "SELECT article_id, article_title, article_cid, article_alias ".
2073                  "FROM ".DB_PREPEND."phpwcms_article ".
2074                  "WHERE article_id=".$article_id." AND ".
2075                  "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
2076                  "article_begin < NOW() AND article_end > NOW() LIMIT 1";
2077          $data = _dbQuery($sql);
2078          
2079          if(isset($data[0])) {
2080              return '<a href="index.php?'.setGetArticleAid($data[0]).'" title="'.$article_title.'">'.$link_text.'</a>';
2081          }
2082      }
2083      return '<a href="index.php?aid='.$article_id.'" title="'.$article_title.'">'.$link_text.'</a>';
2084  }
2085  
2086  function get_keyword_link($keywords="", $db) {
2087      // returns a link or linklist for special article keywords
2088      // used for replacement tag {KEYWORD:Charlie}
2089  
2090      $keywords = explode(",", $keywords);
2091      $where = "";
2092      $keyword_list = "";
2093      $link = "";
2094  
2095      if(count($keywords)) {
2096          foreach($keywords as $value) {
2097              $value = trim($value);
2098              if($value) {
2099                  if($where) {
2100                      $where .= " AND ";
2101                      $keyword_list .= ", ";
2102                  }
2103                  $where .= "article_keyword LIKE '%*".aporeplace($value)."*%'";
2104                  $keyword_list .= html_specialchars($value);
2105              }
2106          }
2107      } else {
2108          $keyword_list = $keywords;
2109      }
2110  
2111      if($where) {
2112  
2113          $x = 0;
2114          $sql  = "SELECT article_id, article_cid, article_title, article_alias FROM ".DB_PREPEND."phpwcms_article WHERE ";
2115          // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2116          switch(VISIBLE_MODE) {
2117              case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2118                      break;
2119              case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2120                      break;
2121              //case 2: admin mode no additional neccessary
2122          }
2123          $sql .= "article_deleted=0 AND article_begin < NOW() ";
2124          $sql .=    "AND article_end > NOW() AND (".$where.")";
2125  
2126          if($result = mysql_query($sql, $db)) {
2127              $article_list = array();
2128              while($row = mysql_fetch_row($result)) {
2129                  $article_list[$x][0] = $row[0]; //article ID
2130                  $article_list[$x][1] = $row[1]; //article catID
2131                  $article_list[$x][2] = html_specialchars($row[2]); //article title
2132                  $article_list[$x]['article_alias'] = $row[3];
2133                  $article_list[$x]['article_id'] = $row[0];
2134                  $x++;
2135              }
2136              mysql_free_result($result);
2137          }
2138  
2139          if($x) {
2140              // if keyword(s) found
2141              if($x == 1) {
2142                  // if only 1 article found
2143                  $link .= '<a href="index.php?'.setGetArticleAid($article_list[0]).'" title="'.$article_list[0][2].'">'.$keyword_list.'</a>';
2144              } else {
2145                  // if more than one article found
2146                  foreach($article_list as $key => $value) {
2147                      if($link) $link .= '|';
2148                      $link .= '<a href="index.php?'.setGetArticleAid($value).'" title="'.$article_list[$key][2].'">'.($key+1).'</a>';
2149                  }
2150                  $link = $keyword_list.' ['.$link.']';
2151              }
2152          }
2153      }
2154      if(!$link) $link = $keyword_list;
2155      $link  = $GLOBALS['template_default']["article"]["keyword_before"] . $link;
2156      $link .= $GLOBALS['template_default']["article"]["keyword_after"];
2157      return $link;
2158  
2159  }
2160  
2161  function clean_replacement_tags($text = '', $allowed_tags='<a><b><i><strong>') {
2162      // strip out special replacement tags
2163      $text = render_PHPcode($text);
2164      $text = str_replace('<td>', '<td> ', $text);
2165      $text = strip_tags($text, $allowed_tags);
2166      $text = str_replace('|', ' ', $text);
2167      
2168      $search = array(
2169                  '/\{.*?\}/si',
2170                  '/\[ID.*?\/ID\]/si',
2171                  '/(\s+)/i',
2172                  '/\[img=(\d+)(.*?){0,1}\](.*?)\[\/img\]/i',
2173                  '/\[img=(\d+)(.*?){0,1}\]/i',
2174                  '/\[download=(.*?)\/\]/i',
2175                  '/\[download=(.*?)\](.*?)\[\/download\]/is'
2176                      );
2177                      
2178      $replace = array(
2179                  '',
2180                  '',
2181                  ' ',
2182                  '$3',
2183                  '',
2184                  '',
2185                  '$2'
2186                      );
2187      
2188      $text = preg_replace($search, $replace, $text);
2189  
2190      return trim($text);
2191  }
2192  
2193  function get_search_action($id, $dbcon) {
2194      // return the search form action
2195      $id = intval($id); $cid = 0;
2196      if($id) {
2197          $sql  = "SELECT article_cid, article_alias FROM ".DB_PREPEND."phpwcms_article WHERE ";
2198          $sql .=    "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND article_begin < NOW() ";
2199          $sql .=    "AND article_end > NOW() AND article_id=".$id." LIMIT 1";
2200          if($result = mysql_query($sql, $dbcon)) {
2201              if($row = mysql_fetch_row($result)) {
2202                  $cid = $row[0];
2203                  $data = array('article_id'=>$id, 'article_alias'=>$row[1]);
2204              }
2205              mysql_free_result($result);
2206          }
2207      }
2208      return ($cid) ? 'index.php?'.setGetArticleAid($data) : '';
2209  }
2210  
2211  function get_index_link_up($linktext) {
2212      // return the link to parent category of current category
2213      $cat_id = $GLOBALS['content']['cat_id'];
2214      $linktext = trim($linktext);
2215      $link = '';
2216      if(!$linktext) $linktext = 'UP';
2217      if($cat_id && !$GLOBALS['content']['struct'][$cat_id]['acat_hidden']) {
2218          $upid = $GLOBALS['content']['struct'][$cat_id]['acat_struct'];
2219          $link = '<a href="index.php?' . ( empty($GLOBALS['content']['struct'][$upid]['acat_alias']) ? 'id='.$upid : $GLOBALS['content']['struct'][$upid]['acat_alias'] ) .'">';
2220      }
2221      return ($link) ? $link.$linktext.'</a>' : $linktext;
2222  }
2223  
2224  function get_index_link_next($linktext, $cat_down=0) {
2225  
2226      global $content;
2227  
2228      // return the link to next article in current ctageory
2229      $a_id = isset($content['article_id']) ? $content['article_id'] : $GLOBALS['aktion'][1];
2230      $linktext = trim($linktext);
2231      if(!$linktext) $linktext = 'NEXT';
2232      $link = '';
2233  
2234      if(count($content['articles']) > 1) {
2235  
2236          $c = 0; //temp counter
2237          foreach($content['articles'] as $key => $value) {
2238              if($c || !$a_id) {
2239                  $link  = '<a href="index.php?aid='.$key.'">';
2240                  break;
2241              }
2242              if($key == $a_id) $c++;
2243          }
2244      }
2245  
2246      if($cat_down && !$link) {
2247          // go cat down or to next cat above
2248  
2249          if($content['cat_id']) {
2250              foreach($content['struct'] as $key => $value) {
2251                  if($content['struct'][$key]['acat_struct'] == $content['cat_id']) {
2252                      $link  = '<a href="index.php?';
2253                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2254                      $link .= '">';
2255                      break;
2256                  }
2257              }
2258          } else {
2259              $c = 0;
2260              foreach($content['struct'] as $key => $value) {
2261                  if($c) {
2262                      $link  = '<a href="index.php?';
2263                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2264                      $link .= '">';
2265                      break;
2266                  }
2267                  $c++;
2268              }
2269          }
2270  
2271          if(!$link && $content['cat_id']) {
2272              $c=0;
2273              $temp_key = array();
2274              foreach($content['struct'] as $key => $value) {
2275                  if($content['struct'][$key]['acat_struct'] == $content['struct'][ $content['cat_id'] ]['acat_struct']) {
2276                      $temp_key[] = $key;
2277                  }
2278              }
2279              $count_temp = count($temp_key);
2280              if($count_temp) {
2281                  $c=0;
2282                  foreach($temp_key as $value) {
2283                      if($value == $content['cat_id'] && $c+1 < $count_temp) {
2284                          //$link = '<a href="index.php?id='.$temp_key[$c+1].',0,0,1,0,0">';
2285                          
2286                          $key = $temp_key[$c+1];
2287                          
2288                          $link  = '<a href="index.php?';
2289                          $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2290                          $link .= '">';
2291                          break;
2292                      }
2293                      $c++;
2294                  }
2295                  if($c == $count_temp && !$link) {
2296                      // back reverese to higher next structure level
2297                      $current_id = $content['cat_id'];
2298  
2299                      while($c=1) {
2300                          $parent_id = $content['struct'][ $current_id ]['acat_struct'];
2301                          $parent_struct_id = $content['struct'][ $parent_id ]['acat_struct'];
2302  
2303                          $c=0;
2304                          foreach($content['struct'] as $key => $value) {
2305                              if($content['struct'][$key]['acat_struct'] == $parent_struct_id) {
2306                                  if($c) {
2307                                      $link  = '<a href="index.php?';
2308                                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2309                                      $link .= '">';
2310                                      break;
2311                                  }
2312                                  if($key == $parent_id) $c=1;
2313                              }
2314                          }
2315  
2316                          if(!$parent_struct_id) {
2317                              if(!$parent_id) $link = '';
2318                              break;
2319                          } else {
2320                              $current_id = $parent_id;
2321                          }
2322  
2323                      }
2324  
2325  
2326                  }
2327              }
2328          }
2329  
2330      }
2331  
2332      return ($link) ? $link.$linktext.'</a>' : $linktext;
2333  }
2334  
2335  function get_index_link_prev($linktext, $cat_up=0) {
2336      // return the link to next article in current ctageory
2337      $a_id = isset($GLOBALS['content']['article_id']) ? $GLOBALS['content']['article_id'] : $GLOBALS['aktion'][1];
2338      $linktext = trim($linktext);
2339      if(!$linktext) $linktext = 'PREV';
2340      $link = '';
2341      $c = 0; //temp counter
2342  
2343      if(count($GLOBALS['content']['articles']) > 1 && $a_id) {
2344  
2345          foreach($GLOBALS['content']['articles'] as $key => $value) {
2346              if($key == $a_id && $c) {
2347                  $link  = '<a href="index.php?aid='.$prev_art_id.'">';
2348                  break;
2349              }
2350              $c++;
2351              $prev_cat_id = $GLOBALS['content']['articles'][$key]['article_cid'];
2352              $prev_art_id = $key;
2353          }
2354      }
2355      if($cat_up && $a_id && $c && !$link) {
2356          $link = '<a href="index.php?id='.$GLOBALS['content']['cat_id'].',0,0,1,0,0">';
2357      }
2358  
2359      if($cat_up && !$link) {
2360          // go cat down or to next cat above
2361          $temp_key = array();
2362          foreach($GLOBALS['content']['struct'] as $key => $value) {
2363              if($GLOBALS['content']['struct'][$key]['acat_struct'] == $GLOBALS['content']['struct'][ $GLOBALS['content']['cat_id'] ]['acat_struct']) {
2364                  $temp_key[] = $key;
2365              }
2366          }
2367          if(count($temp_key) && $GLOBALS['content']['cat_id']) {
2368              $c = 0;
2369              foreach($temp_key as $value) {
2370                  if($value == $GLOBALS['content']['cat_id']) {
2371                      $prev_cat_id = (!$c) ? $GLOBALS['content']['struct'][$value]['acat_struct'] : $temp_key[$c-1];
2372                      $link = '<a href="index.php?id='.$prev_cat_id.',0,0,1,0,0">';
2373                      break;
2374                  }
2375                  $c++;
2376              }
2377          }
2378      }
2379  
2380      return ($link) ? $link.$linktext.'</a>' : $linktext;
2381  }
2382  
2383  function include_int_php($string) {
2384      // return the PHP var value
2385      $s = html_despecialchars($string[1]);
2386      if((strpos($s,'$GLOBALS') || strpos($s,'$_'))===false) {
2387          $s = preg_replace('/^\$(.*?)\[(.*?)/si', '$GLOBALS["$1"][$2', $s);
2388          if(substr($s,strlen($s)-1) != ']') {
2389              $s = str_replace('$', '', $s);
2390              $s = '$GLOBALS["'.$s.'"]';
2391          }
2392      }
2393      $s = str_replace('$phpwcms', '$notavailable', $s);
2394      $s = str_replace('["phpwcms"]', '["notavailable"]', $s);
2395      $s = str_replace("['phpwcms']", '["notavailable"]', $s);
2396      ob_start();
2397      eval('echo '.$s.';');
2398      $return = ob_get_contents();
2399      ob_end_clean();
2400      return $return;
2401  }
2402  
2403  function include_int_phpcode($string) {
2404      // return the PHP code
2405      $s = html_despecialchars($string[1]);
2406      $s = str_replace('<br>', "\n", $s);
2407      $s = str_replace('<br />', "\n", $s);
2408      ob_start();
2409      eval($s.";");
2410      $return = ob_get_contents();
2411      ob_end_clean();
2412      return $return;
2413  }
2414  
2415  function build_sitemap($start=0, $counter=0) {
2416      // create sitemap
2417  
2418      $s = '';
2419      $c = '';
2420      $counter++;
2421  
2422  
2423      if($GLOBALS['sitemap']['classcount']) {
2424          if($GLOBALS['sitemap']['catclass']) $c = ' class="'.$GLOBALS['sitemap']['catclass'].$counter.'"';
2425      } else {
2426          if($GLOBALS['sitemap']['catclass']) $c = ' class="'.$GLOBALS['sitemap']['catclass'].'"';
2427      }
2428  
2429      foreach($GLOBALS['content']['struct'] as $key => $value) {
2430  
2431          //if ($key && $GLOBALS['content']['struct'][$key]['acat_nositemap'] && $start == $GLOBALS['content']['struct'][$key]['acat_struct'])
2432          if( $GLOBALS['content']['struct'][$key]['acat_nositemap'] && _getStructureLevelDisplayStatus($key, $start) ) {
2433  
2434              $s .= '<li'.$GLOBALS['sitemap']['cat_style'].'>';    //$c.
2435  
2436              if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
2437                  $s .= '<a href="index.php?';
2438                  if($GLOBALS['content']['struct'][$key]['acat_alias']) {
2439                      $s .= $GLOBALS['content']['struct'][$key]['acat_alias'];
2440                  } else {
2441                      $s .= 'id='.$key;
2442                  }
2443                  $s .= '"';
2444              } else {
2445                  $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
2446                  $s .= '<a href="'.$redirect['link'].'"'.$redirect['target'];
2447              }
2448  
2449              $s .= '>';
2450              $s .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
2451              $s .= '</a>';
2452              if($GLOBALS['sitemap']["display"]) $s .= build_sitemap_articlelist($key, $counter);
2453  
2454              $s .= build_sitemap($key, $counter);
2455  
2456              $s .= "</li>\n";
2457          }
2458      }
2459  
2460  
2461      if($s) $s = "\n<ul".$c.">\n".$s.'</ul>';
2462  
2463      return $s;
2464  }
2465  
2466  function build_sitemap_articlelist($cat, $counter=0) {
2467      // create list of articles for given category
2468  
2469      $ao = get_order_sort($GLOBALS['content']['struct'][ $cat ]['acat_order']);
2470  
2471      $sql  = "SELECT article_id, article_title FROM ".DB_PREPEND."phpwcms_article ";
2472      $sql .= "WHERE article_cid=".intval($cat)." AND article_nositemap=1 AND ";
2473      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2474      switch(VISIBLE_MODE) {
2475          case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2476                  break;
2477          case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2478                  break;
2479          //case 2: admin mode no additional neccessary
2480      }
2481      $sql .= "article_deleted=0 AND article_begin<NOW() AND article_end>NOW() ";
2482      $sql .= "ORDER BY ".$ao[2];
2483  
2484      $s = '';
2485      $c = '';
2486      if($GLOBALS['sitemap']['classcount']) {
2487          if($GLOBALS['sitemap']['articleclass']) $c = ' class="'.$GLOBALS['sitemap']['articleclass'].$counter.'"';
2488      } else {
2489          if($GLOBALS['sitemap']['articleclass']) $c = ' class="'.$GLOBALS['sitemap']['articleclass'].'"';
2490      }
2491  
2492      if($result = mysql_query($sql, $GLOBALS['db'])) {
2493          while($row = mysql_fetch_row($result)) {
2494  
2495              $s .= '<li'.$GLOBALS['sitemap']['article_style'].'>';    //.$c
2496              $s .= '<a href="index.php?aid='.$row[0].'">';
2497              $s .= html_specialchars($row[1]);
2498              $s .= "</a></li>\n";
2499  
2500          }
2501          mysql_free_result($result);
2502      }
2503  
2504      if($s) $s = "\n<ul".$c.">\n".$s.'</ul>';
2505  
2506      return $s;
2507  
2508  }
2509  
2510  function render_cnt_template($text='', $tag='', $value='') {
2511      // render content part by replacing placeholder tags by value
2512      $value = strval($value);
2513      if($value) {
2514          $text = preg_replace('/\['.$tag.'\](.*?)\[\/'.$tag.'\]/is', '$1', $text);
2515          $text = preg_replace('/\['.$tag.'_ELSE\](.*?)\[\/'.$tag.'_ELSE\]/is', '', $text);
2516      } else {
2517          $text = preg_replace('/\['.$tag.'_ELSE\](.*?)\[\/'.$tag.'_ELSE\]/is', '$1', $text);
2518          $text = preg_replace('/\['.$tag.'\](.*?)\[\/'.$tag.'\]/is', '', $text);
2519      }
2520      return str_replace('{'.$tag.'}', $value, $text);
2521  }
2522  
2523  function replace_cnt_template($text='', $tag='', $value='') {
2524      // replace tag by value
2525      return preg_replace('/\['.$tag.'\].*?\[\/'.$tag.'\]/is', strval($value), $text);
2526  }
2527  
2528  function render_cnt_date($text='', $date, $livedate=NULL, $killdate=NULL) {
2529      // render date by replacing placeholder tags by value
2530      $date = is_numeric($date) ? intval($date) : now();
2531      $text = preg_replace('/\{DATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$date.'")', $text);
2532      $text = preg_replace('/\{DATE:(.*?)\}/e', 'date("$1",'.$date.')', $text);
2533      if(intval($livedate)) {
2534          $text = preg_replace('/\{LIVEDATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$livedate.'")', $text);
2535          $text = preg_replace('/\{LIVEDATE:(.*?)\}/e', 'date("$1",'.$livedate.')', $text);
2536      }
2537      if(intval($killdate)) {
2538          $text = preg_replace('/\{KILLDATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$killdate.'")', $text);
2539          $text = preg_replace('/\{KILLDATE:(.*?)\}/e', 'date("$1",'.$killdate.')', $text);
2540      }
2541      return preg_replace('/\{NOW:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.now().'")', $text);
2542  }
2543  
2544  function render_date($text='', $date, $rt='DATE') {
2545      // render date by replacing placeholder tags by value
2546      $rt = preg_quote($rt);
2547      $text = preg_replace('/\{'.$rt.':(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$date.'")', $text);
2548      return preg_replace('/\{'.$rt.':(.*?)\}/e', 'date("$1",'.$date.')', $text);
2549  }
2550  
2551  function returnTagContent($string='', $tag='', $findall=false, $tagOpen='[', $tagClose=']') {
2552      // used to exclude a special string sequence from string
2553      // enclosed by [tag][/tag] or also <tag></tag>
2554      $data                 = array();
2555      $data['original']    = $string;
2556      $tag_open            = preg_quote($tagOpen.$tag.$tagClose, '/');
2557      $tag_close            = preg_quote($tagOpen.'/'.$tag.$tagClose, '/');
2558      $data['new']        = trim(preg_replace('/'.$tag_open.'(.*?)'.$tag_close.'/is', '', $string));
2559      if($findall) {
2560          preg_match_all('/'.$tag_open.'(.*?)'.$tag_close.'/is', $string, $matches);
2561      } else {
2562          preg_match('/'.$tag_open.'(.*?)'.$tag_close.'/is', $string, $matches);
2563      }
2564      $data['tag']        = isset($matches[1]) ? $matches[1] : '';
2565      return $data;
2566  }
2567  
2568  function include_url($url) {
2569      // include given URL but only take content between <body></body>
2570  
2571      global $include_urlparts;
2572      
2573      if( is_string($url) ) {
2574          $url = array( 1 => $url );
2575      } elseif( ! isset($url[1]) ) {
2576          return '';
2577      }
2578      
2579      $k                = '';
2580      $url            = trim($url[1]);
2581      $url            = explode(' ', $url);
2582      $cache            = isset($url[1]) ? intval(str_replace('CACHE=', '', strtoupper($url[1]))) : 0;
2583      $url            = $url[0];
2584      $cache_status    = 'MISSING';
2585      
2586      if($url && $cache) {
2587      
2588          $cache_filename    = md5($url).'-url';    // set cache file name
2589          $cache_file        = PHPWCMS_CONTENT.'tmp/'.$cache_filename;    // set caching file
2590          $cache_status    = check_cache($cache_file, $cache);    // ceck existence
2591          
2592          if($cache_status == 'VALID') {    // read cache
2593              
2594              $k    = read_textfile($cache_file);
2595              $k    = trim($k);
2596          
2597              if(empty($k)) {
2598                  $cache_status == 'EXPIRED';    // check if cache content is available
2599              }
2600          
2601          }
2602  
2603      }
2604      
2605      if($cache_status != 'VALID' && $url) {    // cache file is missing or outdated
2606  
2607          $include_urlparts = parse_url($url);
2608          if(!empty($include_urlparts['path'])) {
2609              $include_urlparts['path'] = dirname($include_urlparts['path']);
2610              $include_urlparts['path'] = str_replace('\\', '/', $include_urlparts['path']);
2611          }
2612          $k = @file_get_contents($url);
2613  
2614          if($k) {
2615              // now check against charset
2616              if(preg_match('/charset=(.*?)"/i', $k, $match)) {
2617                  $charset = $match[1];
2618                  $charset = str_replace(array('"', "'", '/'), '', $charset);
2619                  $charset = strtolower(trim($charset));
2620              } elseif(preg_match('/http-equiv="{0,1}Content-Type"{0,1}\s{1,}(content="{0,1}.*?"{0,1}.{0,3}>)/i', $k, $match)) {
2621                  $charset = '';
2622                  if(!empty($match[1])) {
2623                      $charset = strtolower($match[1]);
2624                      $charset = trim(str_replace(array('"', "'", '/', 'content=', ' ', '>'), '', $charset));
2625                  }
2626              } else {
2627                  $charset = false;
2628              }
2629  
2630              if(preg_match('/<body[^>]*?'.'>(.*)<\/body>/is', $k, $match)) {
2631                  $k = $match[1];
2632              }
2633              $k = str_replace(array('<?', '?>', '<%', '%>'), array('&lt;?', '?&gt;', '&lt;&#37;', '&#37;&gt;'), $k);
2634              $k = preg_replace_callback('/(href|src|action)=[\'|"]{0,1}(.*?)[\'|"]{0,1}( .*?){0,1}>/i', 'make_absoluteURL', $k);
2635              $k = sanitize( trim($k) , array(false, 'link', 'meta'), array(), array('img', 'br', 'hr', 'input'), true);
2636  
2637              if($charset != false) {
2638                  $k = makeCharsetConversion($k, $charset, PHPWCMS_CHARSET, 1);
2639              }
2640              
2641              // now write or update cache file in case there is timeout or content
2642              if($cache && $k) {
2643                  @write_textfile($cache_file, $k);
2644              }
2645  
2646          }
2647          $include_urlparts = '';
2648  
2649      }
2650      return $k;
2651  }
2652  
2653  function make_absoluteURL($matches) {
2654      // replaces all relative URLs in href=/src= to absolute paths based on called URI
2655      $parts = $GLOBALS['include_urlparts'];
2656      $path  = $matches[2];
2657      $k = '';
2658      if(preg_match('/^(http|mailto|ftp|https|skype|itms)/i', $path)) {
2659          $k = $path;
2660      } else {
2661          if(empty($parts['path'])) $parts['path'] = '';
2662          $k = $parts['host'].$parts['path'].'/'.$path;
2663          $k = str_replace('///', '/', $k);
2664          $k = str_replace('//', '/', $k);
2665          $k = $parts['scheme'].'://'.$k;
2666      }
2667      if(empty($matches[3])) $matches[3] = '';
2668      return $matches[1].'="'.$k.'"'.$matches[3].'>';
2669  
2670  }
2671  
2672  function render_PHPcode($string='') {
2673      // combined PHP replace renderer
2674      // includes external PHP script and returns the content
2675      $string = preg_replace('/\{PHP:(.*?)\}/e', 'include_ext_php("$1");', $string);
2676      // do complete PHP code
2677      $string = preg_replace_callback("/\[PHP\](.*?)\[\/PHP\]/s", 'include_int_phpcode', $string);
2678      // includes external PHP script and returns the content
2679      $string = preg_replace_callback("/\{PHPVAR:(.*?)\}/s", 'include_int_php', $string);
2680      return $string;
2681  }
2682  
2683  function nav_list_struct (&$struct, $act_cat_id, $level, $class='') {
2684      // start with home directory for the listing = top nav structure
2685      // 1. Build the recursive tree for given actual article category ID
2686  
2687      // return the tree starting with given start_id (like breadcrumb)
2688      // if the $start_id = 0 then this stops because 0 = top level
2689  
2690      $level        = intval($level);
2691      $data        = array();
2692      $start_id     = $act_cat_id;
2693      $class         = trim($class);
2694      $depth        = 0;
2695  
2696      while ($start_id) {
2697          $data[$start_id] = 1;
2698          $start_id         = $struct[$start_id]["acat_struct"];
2699      }
2700      $temp_tree = sizeof($data) ? array_reverse($data, 1) : false;
2701  
2702      $temp_menu = build_list ($struct, $level, $temp_tree, $act_cat_id, $class, $depth);
2703      $temp_menu = str_replace("\n\n", LF, $temp_menu);
2704      return $temp_menu ? $temp_menu : '';
2705  }
2706  
2707  function build_list ($struct, $level, $temp_tree, $act_cat_id, $class='', $depth=0) {
2708      // this returns the level structure based on given arrays
2709      // it is special for browsing from root levels
2710  
2711      if($class != '') {
2712          $curClass = ' class="'.$class.$depth.'"';
2713          $curClassNext = ' class="'.$class.($depth+1).'"';
2714          $curClassActive = ' class="'.$class.'Active'.$depth.'"';
2715      } else {
2716          $curClass = '';
2717          $curClassNext = '';
2718          $curClassActive = ' class="listActive"';
2719      }
2720  
2721      $depth++;
2722  
2723      $temp_menu = "\n<ul".$curClass.">\n";
2724      foreach($struct as $key => $value) {
2725  
2726          if( _getStructureLevelDisplayStatus($key, $level) ) {
2727  
2728              if(!$struct[$key]["acat_redirect"]) {
2729                  $link = 'index.php?';
2730                  if($struct[$key]["acat_alias"]) {
2731                      $link .= html_specialchars($struct[$key]["acat_alias"]);
2732                  } else {
2733                      $link .= 'id='.$key; //',0,0,1,0,0';
2734                  }
2735                  $redirect['target'] = '';
2736              } else {
2737                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
2738                  $link = $redirect['link'];
2739              }
2740  
2741              if(!empty($temp_tree[$key])) {
2742  
2743                  if($act_cat_id == $key) {
2744                      $temp_menu .= "\n<li".$curClassActive.">";
2745                  } else {
2746                      $temp_menu .= "\n<li>";
2747                  }
2748  
2749                  $temp_menu .= '<a href="'.$link.'">'.html_specialchars($struct[$key]["acat_name"]).'</a>';
2750  
2751                  $temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $class, $depth);
2752                  $temp_menu .= '</li>';
2753  
2754              } else {
2755                  $temp_menu .= "\n<li>".'<a href="'.$link.'"'.$redirect['target'].'>';
2756                  $temp_menu .= html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
2757              }
2758          }
2759      }
2760  
2761      $temp_menu = trim($temp_menu);
2762      return $temp_menu != "<ul".$curClassNext.">" ? $temp_menu."\n</ul>" : '';
2763  }
2764  
2765  function combined_POST_cleaning($val) {
2766      $val = clean_slweg($val);
2767      $val = remove_unsecure_rptags($val);
2768      return $val;
2769  }
2770  
2771  function get_fe_userinfo($forum_userID) {
2772      // get frontend userinformation
2773      $forum_userID = intval($forum_userID);
2774      $got_the_info = false;
2775      if($forum_userID != 0 && (!isset($GLOBALS['FE_USER']) || !isset($GLOBALS['FE_USER'][$forum_userID]))) {
2776          //connect to user db and get information
2777          $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_user WHERE usr_id=".$forum_userID." LIMIT 1";
2778          if($result = mysql_query($sql, $GLOBALS['db'])) {
2779              if($row = mysql_fetch_assoc($result)) {
2780                  $GLOBALS['FE_USER'][$forum_userID] = array(
2781                      'FE_ID'        => $forum_userID,        'login'    => $row['usr_login'],
2782                      'pass'        => $row['usr_pass'],    'email'    => $row['usr_email'],
2783                      'admin'        => $row['usr_admin'],    'fe'    => $row['usr_fe'],
2784                      'aktiv'        => $row['usr_aktiv'],    'name'    => $row['usr_name'],
2785                      'lang'        => empty($row['usr_lang']) ? $GLOBALS['phpwcms']['default_lang'] : $row['usr_lang'],
2786                      'wysiwyg'    => $row['usr_wysiwyg']
2787                  );
2788                  $got_the_info = true;
2789              }
2790              mysql_free_result($result);
2791          }
2792      } else {
2793          $got_the_info = true;
2794      }
2795      if(($forum_userID === 0 && !isset($GLOBALS['FE_USER'][$forum_userID])) || !$got_the_info) {
2796          $forum_userID = 0;
2797          $GLOBALS['FE_USER'][$forum_userID] = array(
2798                      'FE_ID'        => $forum_userID,        'login'    => 'guest',
2799                      'pass'        => '',                    'email'    => 'noreply@localhost',
2800                      'admin'        => 0,                    'fe'    => 0,
2801                      'aktiv'        => 1,                    'name'    => 'Guest',
2802                      'lang'        => $GLOBALS['phpwcms']['default_lang'],
2803                      'wysiwyg'    => $GLOBALS['phpwcms']['wysiwyg_editor']
2804                  );
2805      }
2806  }
2807  
2808  function highlightSearchResult($string='', $search, $wrap='<em class="highlight">|</em>') {
2809      // string will be highlighted by $search - can be string or array
2810      if(!empty($string) && !empty($search)) {
2811  
2812          // make $wrap[0] prefix and $wrap[1] suffix
2813          $wrap = explode('|', $wrap);
2814          if(empty($wrap[1])) $wrap[1] = '';
2815          $highlight_match = '';
2816  
2817          // make all search values array fields
2818          if(is_array($search)) {
2819              // make unique
2820              $search = array_unique($search);
2821          } else {
2822              $search = array(strval($search));
2823          }
2824          foreach($search as $key => $value) {
2825              if($highlight_match != '') $highlight_match .= '|';
2826              $highlight_match .= preg_quote($value, '/');
2827          }
2828          $highlight_match = str_replace("\\?", '.?', $highlight_match);
2829          $highlight_match = str_replace("\\*", '.*', $highlight_match);
2830          $highlight_match = trim($highlight_match);
2831  
2832          if(false == preg_match('/<.+>/', $string)) {
2833              $string = preg_replace('/('.$highlight_match.')/i', $wrap[0].'$1'.$wrap[1], $string);
2834          } else {
2835              $string = preg_replace('/(?<=>)([^<]+)?('.$highlight_match.')/i', '$1'.$wrap[0].'$2'.$wrap[1], $string);
2836          }
2837      }
2838      return $string;
2839  }
2840  function pregReplaceHighlightWrapper($matches) {
2841      // just a wrapper for frontend sectional highlighting
2842      global $highlight_words;
2843      return highlightSearchResult($matches[1], $highlight_words, '<em class="highlight">|</em>');
2844  }
2845  
2846  function buildCascadingMenu($parameter='', $counter=0, $param='string') {
2847  
2848      // @string $parameter = "menu_type, start_id, max_level_depth, class_path, class_active,
2849      // ul_id_name, wrap_ul_div(0 = off, 1 = <div>, 2 = <div id="">, 3 = <div class="navLevel-0">),
2850      // wrap_link_text(<em>|</em>, articlemenu_start_level)"
2851  
2852      if($param == 'string') {
2853  
2854          $parameter         = explode(',', $parameter);
2855          $menu_type        = empty($parameter[0]) ? '' : strtoupper(trim($parameter[0]));
2856  
2857          $unfold         = 'all';
2858          $ie_patch        = false; // unused at the moment
2859          $create_css     = false;
2860          $parent            = false; // do not show parent link
2861          $articlemenu    = false; // do not show category's article titles as menu entry
2862  
2863          switch($menu_type) {
2864  
2865                              // show parent level too
2866              case 'PA':        $articlemenu    = true;
2867              case 'P':        $parent            = true;
2868                              break;
2869  
2870                              // vertical, active path unfolded
2871              case 'FPA':        $articlemenu    = true;
2872              case 'FP':        $parent            = true;
2873              case 'F':        $unfold            = 'active_path';
2874                              break;
2875                              
2876              case 'FA':        $articlemenu    = true;
2877                              $unfold            = 'active_path';
2878                              break;
2879                              
2880                              // horizontal, all levels unfolded, add special code for horizontal flyout menu
2881              case 'HCSSP':    $parent        = true;
2882              case 'HCSS':    $create_css    = true;
2883                              break;
2884  
2885                              // horizontal, all levels unfolded, add special code for vertical flyout menu
2886              case 'VCSSP':    $parent        = true;
2887              case 'VCSS':    $create_css = true;
2888                              break;
2889  
2890          }
2891  
2892          $start_id        = empty($parameter[1]) ? 0  : intval($parameter[1]);
2893          $max_depth        = empty($parameter[2]) ? 0  : intval($parameter[2]);
2894          $path_class     = empty($parameter[3]) ? '' : trim($parameter[3]);
2895          $active_class    = empty($parameter[4]) ? '' : trim($parameter[4]);
2896          $level_id_name    = empty($parameter[5]) ? '' : trim($parameter[5]);
2897          $wrap_ul_div    = empty($parameter[6]) ? 0  : intval($parameter[6]);
2898          if($wrap_ul_div > 3) {
2899              $wrap_ul_div = 2;
2900          } elseif($wrap_ul_div < 0) {
2901              $wrap_ul_div = 0;
2902          }
2903          $wrap_link_text    = empty($parameter[7]) ? array(0 => '', 1 => '') : explode('|', trim($parameter[7]), 2);
2904          if(empty($wrap_link_text[1])) {
2905              $wrap_link_text[1] = '';
2906          }
2907          $amenu_level    = empty($parameter[8]) ? 0 : intval($parameter[8]);
2908  
2909          $parameter        = array(     0 => $menu_type,          1 => $start_id,          2 => $max_depth,
2910                                       3 => $path_class,         4 => $active_class,      5 => $level_id_name,
2911                                       6 => $wrap_ul_div,         7 => $wrap_link_text,     8 => $unfold,
2912                                       9 => $ie_patch,        10 => $create_css,        11 => $amenu_level,
2913                                      12 => array('articlemenu' => $articlemenu, 'level_id' => $start_id)
2914                              );
2915          
2916          if($articlemenu) {
2917              $parameter[12]['class_active']            = $active_class;
2918              $parameter[12]['wrap_title_prefix']        = $wrap_link_text[0];
2919              $parameter[12]['wrap_title_suffix']        = $wrap_link_text[1];
2920              $parameter[12]['item_prefix']            = "\t";
2921              $parameter[12]['item_suffix']            = '';
2922              $parameter[12]['sort']                    = 'level';
2923              $parameter[12]['item_tag']                = 'li';
2924              $parameter[12]['wrap_tag']                = '';
2925              $parameter[12]['attribute_wrap_tag']    = '';
2926              $parameter[12]['class_item_tag']        = 'asub_no';
2927              $parameter[12]['class_first_item_tag']    = 'asub_first';
2928              $parameter[12]['class_last_item_tag']    = 'asub_last';
2929              $parameter[12]['return_format']            = 'array';
2930          }
2931      
2932      } else {
2933  
2934          $menu_type        = $parameter[0];
2935          $start_id        = $parameter[1];
2936          $max_depth        = $parameter[2];
2937          $path_class     = $parameter[3];
2938          $active_class    = $parameter[4];
2939          $level_id_name    = $parameter[5];
2940          $wrap_ul_div    = $parameter[6];
2941          $wrap_link_text    = $parameter[7];
2942          $unfold            = $parameter[8];
2943          $ie_patch        = $parameter[9];
2944          $create_css     = $parameter[10];
2945          $amenu_level    = $parameter[11];
2946          
2947          $parent            = false;        // do not show parent link
2948  
2949      }
2950  
2951      $li                = '';
2952      $ul                = '';
2953      $TAB            = str_repeat('    ', $counter);
2954      $_menu_type        = strtolower($menu_type);
2955      $max_depth        = ($max_depth == 0 || $max_depth-1 > $counter) ? true : false;
2956      $x                = 0;
2957  
2958      foreach($GLOBALS['content']['struct'] as $key => $value) {
2959  
2960          if( _getStructureLevelDisplayStatus($key, $start_id) ) {
2961  
2962              $li_ul         = '';
2963              $li_ie        = '';
2964              $li_a_title    = html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
2965              
2966              $li_a  = get_level_ahref($key, ' title="'.$li_a_title.'"');
2967              $li_a .= $wrap_link_text[0] . $li_a_title . $wrap_link_text[1];
2968  
2969              if($max_depth && ($unfold == 'all' || ($unfold == 'active_path' && isset($GLOBALS['LEVEL_KEY'][$key]))) ) {
2970                  $parameter[1]    = $key;
2971                  $li_ul            = buildCascadingMenu($parameter, $counter+1, 'param_is_array');
2972              }
2973  
2974              $li .= $TAB.'    <li';
2975  
2976              if($level_id_name) {
2977                  $li .= ' id="li_'.$level_id_name.'_'.$key.'"';
2978              }
2979              $li_class = ($li_ul) ? 'sub_ul' : (getHasSubStructureStatus($key) ? 'sub_no sub_ul_true' : 'sub_no');
2980              if($path_class != '' && isset($GLOBALS['LEVEL_KEY'][$key])) {
2981                  $li_class = trim($li_class.' '.$path_class);
2982              }
2983              if($active_class != '' && $key == $GLOBALS['aktion'][0]) {
2984                  $li_class = trim($li_class.' '.$active_class);
2985              }
2986              if($x==0) {
2987                  $li_class .= ' sub_first';
2988              }
2989  
2990              $li .= ' class="' . trim($li_class . ' ' . $GLOBALS['content']['struct'][$key]['acat_class']) .'"';
2991  
2992              $li .= '>' . $li_a . '</a>';
2993  
2994              $li .= $li_ul.'</li>'.LF; // remove $li_ul from this line of code if $ie_patch is used
2995              
2996              $x++;
2997          }
2998      }
2999      
3000      // show article menu
3001      if($parameter[12]['articlemenu'] && $amenu_level <= $counter) {
3002          
3003          $parameter[12]['level_id']        = $start_id;
3004          $parameter[12]['item_prefix']    = $TAB;
3005  
3006          $ali = getArticleMenu( $parameter[12] );
3007          
3008          if(count($ali) > 1) {
3009          
3010              $li .= implode(LF, $ali) . LF;
3011              
3012          }
3013          
3014      }    
3015      
3016      // also check if $parent
3017      if($li || ($parent && isset($GLOBALS['content']['struct'][$start_id]))) {
3018  
3019          switch($wrap_ul_div) {
3020              case 1:        $ul = LF.$TAB.'<div>';
3021                          $close_wrap_ul = '</div>'.LF.$TAB;
3022                          break;
3023              case 2:        $ul = LF.$TAB.'<div id="ul_div_'.$start_id.'">';
3024                          $close_wrap_ul = '</div>'.LF.$TAB;
3025                          break;
3026              case 3:        $ul = LF.$TAB.'<div class="navLevel-'.$counter.'">';
3027                          $close_wrap_ul = '</div>'.LF.$TAB;
3028                          break;
3029              default:    $ul = '';
3030                          $close_wrap_ul = '';
3031          }
3032          $ul .= LF.$TAB.'<ul';
3033          if($level_id_name) {
3034              $ul .= ' id="'.$level_id_name.'_'.$start_id.'"';
3035          }
3036          if(isset($GLOBALS['LEVEL_KEY'][$start_id]) && $path_class) {
3037              $ul .= ' class="'.$path_class.'"';
3038          }
3039          $ul .= '>'.LF;
3040          
3041          if($parent && isset($GLOBALS['content']['struct'][$start_id])) {
3042          
3043              $ul .= LF;
3044              $ul .= $TAB.'    <li';
3045              if($level_id_name) {
3046                  $ul .= ' id="li_'.$level_id_name.'_'.$start_id.'"';
3047              }
3048              $li_class = 'sub_parent';
3049              if($active_class != '' && $start_id == $GLOBALS['aktion'][0]) {
3050                  $li_class = trim($li_class.' '.$active_class);
3051              }
3052              $ul .= ' class="'.trim($li_class.' '.$GLOBALS['content']['struct'][$start_id]['acat_class']).'">';
3053              
3054              $link_text = html_specialchars($GLOBALS['content']['struct'][$start_id]['acat_name']);
3055              
3056              $ul .= get_level_ahref($start_id, ' title="'.$link_text.'"');
3057              $ul .= $wrap_link_text[0] . $link_text . $wrap_link_text[1];
3058              $ul .= '</a></li>'.LF;
3059                      
3060          }
3061          
3062          $ul .= $li;
3063          $ul .= $TAB . '</ul>' . LF . $TAB . $close_wrap_ul;
3064  
3065          if($create_css && empty($GLOBALS['block']['custom_htmlhead'][$menu_type][$counter])) {
3066  
3067              if($counter) {
3068  
3069                  $tmp_css  = '    .'.$_menu_type.'_menu ul li:hover '.str_repeat('ul ', $counter) .'ul { display: none; }'.LF;
3070                  $tmp_css .= '    .'.$_menu_type.'_menu ul '.str_repeat('ul ', $counter) .'li:hover ul { display: block; }';
3071                  $GLOBALS['block']['custom_htmlhead'][$menu_type][$counter] = $tmp_css;
3072  
3073              } else {  //if($counter == 0) {
3074  
3075                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-9]  = LF.'  <style type="text/css">'.LF.SCRIPT_CDATA_START;
3076                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-8]  = '    @import url("'.TEMPLATE_PATH.'inc_css/specific/nav_list_ul_'.$_menu_type.'.css");';
3077  
3078                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-5]  = '    .'.$_menu_type.'_menu ul ul { display: none; }';
3079                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-4]  = '    .'.$_menu_type.'_menu ul li:hover ul { display: block; }';
3080  
3081                  ksort($GLOBALS['block']['custom_htmlhead'][$menu_type]);
3082                  $GLOBALS['block']['custom_htmlhead'][$menu_type][]   = SCRIPT_CDATA_END.LF.'  </style>';
3083                  $GLOBALS['block']['custom_htmlhead'][$menu_type]   = implode(LF, $GLOBALS['block']['custom_htmlhead'][$menu_type]);
3084  
3085                  $ul = '<div class="'.$_menu_type.'_menu">'.$ul.'</div>';
3086  
3087              }
3088  
3089          }
3090  
3091      }
3092  
3093      return $ul;
3094  }
3095  
3096  function get_level_ahref($key=0, $custom_link_add='') {
3097      $link = '<a href="';
3098      if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
3099          $link .= 'index.php?';
3100          if($GLOBALS['content']['struct'][$key]['acat_alias']) {
3101              $link .= $GLOBALS['content']['struct'][$key]['acat_alias'];
3102          } else {
3103              $link .= 'id='.$key.',0,0,1,0,0';
3104          }
3105          $link .= '"';
3106      } else {
3107          $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
3108          $link .= html_specialchars($redirect['link']).'"'.$redirect['target'];
3109      }
3110      return $link.$custom_link_add.'>';
3111  }
3112  
3113  function getHasSubStructureStatus($level_id=0) {
3114      if( !isset($GLOBALS['content']['struct'][$level_id]) ) {
3115          return false;
3116      }
3117      foreach($GLOBALS['content']['struct'] as $key => $value) {
3118          if( _getStructureLevelDisplayStatus($key, $level_id) ) {
3119              return true;
3120          }
3121      }
3122      return false;
3123  }
3124  
3125  function getStructureChildData($level_id=0) {
3126      if( !isset($GLOBALS['content']['struct'][$level_id]) ) return array();
3127      $struct_data = array();
3128      foreach($GLOBALS['content']['struct'] as $key => $value) {
3129          if( _getStructureLevelDisplayStatus($key, $level_id) ) {
3130              $struct_data[$key]    = $value;
3131          }
3132      }
3133      return $struct_data;
3134  }
3135  
3136  function getStructureChildEntryHref($childData) {
3137  
3138      $a = array('link'=>'', 'target'=>'');
3139      if(!$childData["acat_redirect"]) {
3140          $a['link'] .= 'index.php?';
3141          $a['link'] .= $childData['acat_alias'] ? $childData['acat_alias'] : 'id='.$childData['acat_id'].',0,0,1,0,0';
3142      } else {
3143          $redirect = get_redirect_link($childData["acat_redirect"], ' ', '');
3144          $a['link']   .= $redirect['link'];
3145          $a['target'] .= $redirect['target'];
3146      }
3147      return $a;
3148  
3149  }
3150  
3151  function getImageCaption($caption='', $array_index='NUM', $short=false) {
3152      // splits given image caption and returns an array
3153      $caption    = explode('|', $caption);
3154  
3155      // following is default for the exploded $caption
3156      // [0] caption text
3157      // [1] alt text for image
3158      // [2] link -> array(0 => link, 1 => target)
3159      // [3] title text -> if empty alt text will be used
3160      // [4] copyright information
3161      $caption[0]            = trim($caption[0]);
3162      $caption[1]            = isset($caption[1]) ? trim($caption[1]) : '';
3163      $caption[3]            = isset($caption[3]) ? trim($caption[3]) : $caption[1];
3164      
3165      // cut here – just return caption and alt text
3166      if($short) {
3167          return array('caption' => $caption[0], 'alt' => $caption[1], 'title' => $caption[3]);
3168      }
3169      
3170      $caption[2]            = isset($caption[2]) ? explode(' ', trim($caption[2])) : array(0 => '', 1 => '');
3171      $caption[2][0]        = trim($caption[2][0]);
3172      if(empty($caption[2][0]) || empty($caption[2][1])) {
3173          $caption[2][1]    = '';
3174      } else {
3175          $caption[2][1]    = trim($caption[2][1]);
3176          $caption[2][1]    = empty($caption[2][1]) ? '' : ' target="'.$caption[2][1].'"';
3177      }
3178      $caption[4]            = isset($caption[4]) ? trim($caption[4]) : '';
3179      
3180      if($caption[4] == '') {
3181          $copyright        = returnTagContent($caption[3], 'copyright');
3182          $caption[3]        = $copyright['new'];
3183          $caption[4]        = $copyright['tag'];
3184      } else {
3185          $caption[3]        = replace_cnt_template($caption[3], 'copyright', '');
3186      }
3187      
3188      if($array_index == 'NUM') {
3189          return $caption;
3190      } else {
3191          return array(    'caption_text'        => $caption[0],        'caption_alt'        => $caption[1],
3192                          'caption_link'        => $caption[2][0],    'caption_target'    => $caption[2][1],
3193                          'caption_title'        => $caption[3]        );
3194      }
3195  
3196  }
3197  
3198  function getClickZoomImageParameter($string='', $getvar='show') {
3199      $string = base64_encode($string);
3200      $string = rawurlencode($string);
3201      return $getvar.'='.$string;
3202  }
3203  
3204  function getPageInfoGetValue($type='string') {
3205      // type can be
3206      // 'string' -> 'pageinfo=/...';
3207      // 'array' -> array('pageinfo'=>'/...')
3208      return ($type == 'string') ? 'pageinfo=' : array('pageinfo'=>'');
3209  }
3210  
3211  function _getFeUserLoginStatus() {
3212      $login_key = session_id();
3213      if(empty($login_key)) {
3214          return false;    // user is not logged in
3215      } elseif(empty($_SESSION[$login_key])) {
3216          return false;    // this is the false session and/or false user
3217      } elseif(isset($_GET[$login_key])) {
3218          return false;    // hm, somebody is trying to inject by GET in case register_globals ON
3219      } elseif(isset($_POST[$login_key])) {
3220          return false;    // hm, somebody is trying to inject by POST in case register_globals ON
3221      }
3222      return true;
3223  }
3224  
3225  function _checkFrontendUserLogin($user='', $pass='', $validate_db=array('userdetail'=>1, 'backenduser'=>1)) {
3226      if(empty($user) || empty($pass)) return false;
3227      // check against database
3228      if(!empty($validate_db['userdetail'])) {
3229          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_userdetail WHERE ';
3230          $sql .= "detail_login='".aporeplace($user)."' AND ";
3231          $sql .= "detail_password='".aporeplace($pass)."' AND ";
3232          $sql .= "detail_aktiv=1 LIMIT 1";
3233          $result = _dbQuery($sql);
3234      }
3235      // hm, seems no user found - OK test against cms users
3236      if(!empty($validate_db['backenduser']) && !isset($result[0])) {
3237          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_user ';
3238          $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_userdetail ON ';
3239          $sql .= 'usr_id = detail_pid WHERE ';
3240          $sql .= "usr_login='".aporeplace($user)."' AND ";
3241          $sql .= "usr_pass='".aporeplace($pass)."' AND ";
3242          $sql .= "usr_aktiv=1 AND usr_fe IN (0,2) LIMIT 1";
3243          $result = _dbQuery($sql);
3244      }
3245      return (isset($result[0]) && is_array($result)) ? $result[0] : false;
3246  }
3247  
3248  function _getFrontendUserBaseData(& $data) {
3249      // use vaid user data to set some base fe user data
3250      // like name, login, email
3251      $userdata = array('login'=>'', 'name'=>'', 'email'=>'', 'url'=>'', 'source'=>'', 'id'=>0);
3252  
3253      if(isset($data['usr_login'])) {
3254          $userdata['login']    = $data['usr_login'];
3255          $userdata['name']    = $data['usr_name'];
3256          $userdata['email']    = $data['usr_email'];
3257          $userdata['source']    = 'BACKEND';
3258          $userdata['id']        = $data['usr_id'];
3259          if(trim($data['detail_firstname'].$data['detail_lastname'].$data['detail_company'])) {
3260              $t                            = trim($data['detail_firstname'].' '.$data['detail_lastname']);
3261              if(empty($t))    $t            = trim($data['detail_company']);
3262              if($t) $userdata['name']    = $t;
3263              $userdata['url']            = trim($data['detail_website']);
3264          }        
3265      } elseif($data['detail_login']) {
3266          $t                    = trim($data['detail_firstname'].' '.$data['detail_lastname']);
3267          if(empty($t)) $t    = $data['detail_company'];
3268          $userdata['login']    = $data['detail_login'];
3269          $userdata['name']    = $t;
3270          $userdata['email']    = $data['detail_email'];
3271          $userdata['url']    = $data['detail_website'];
3272          $userdata['source']    = 'PROFILE';
3273          $userdata['id']        = $data['detail_id'];
3274      }
3275      return $userdata;
3276  }
3277  
3278  function _checkFrontendUserAutoLogin() {
3279      if(!_getFeUserLoginStatus() && session_id() && !empty($_COOKIE['phpwcmsFeLoginRemember']) && !isset($_POST['phpwcmsFeLoginRemember']) && !isset($_GET['phpwcmsFeLoginRemember'])) {
3280          $_loginData = explode('##-|-##', $_COOKIE['phpwcmsFeLoginRemember']);
3281          if(!empty($_loginData[0]) && !empty($_loginData[1])) {
3282              $_loginData['validate_db']['userdetail']    = empty($_loginData[2]) ? 0 : 1;
3283              $_loginData['validate_db']['backenduser']    = empty($_loginData[3]) ? 0 : 1;
3284              $_loginData['query_result'] = _checkFrontendUserLogin($_loginData[0], $_loginData[1], $_loginData['validate_db']);
3285              if($_loginData['query_result'] !== false && is_array($_loginData['query_result']) && count($_loginData['query_result'])) {
3286                  if(isset($_loginData['query_result']['usr_login'])) {
3287                      $_SESSION[ session_id() ] = $_loginData['query_result']['usr_login'];
3288                  } elseif($_loginData['query_result']['detail_login']) {
3289                      $_SESSION[ session_id() ] = $_loginData['query_result']['detail_login'];
3290                  }
3291                  $_SESSION[ session_id().'_userdata'] = _getFrontendUserBaseData($_loginData['query_result']);
3292              } else {
3293                  unset($_COOKIE['phpwcmsFeLoginRemember']);
3294              }
3295          }
3296      }
3297      // logout
3298      if(session_id() && (isset($_POST['feLogout']) || isset($_GET['feLogout']))) {
3299          unset($_SESSION[ session_id() ]); 
3300          setcookie('phpwcmsFeLoginRemember', '', time()-3600, '/',  getCookieDomain() );
3301      }
3302      define('FEUSER_LOGIN_STATUS', _getFeUserLoginStatus() );
3303  }
3304  
3305  function _getStructureLevelDisplayStatus(&$level_ID, &$current_ID) {
3306      if($GLOBALS['content']['struct'][$level_ID]['acat_struct'] == $current_ID && $level_ID) {
3307          if($GLOBALS['content']['struct'][$level_ID]['acat_regonly'] && !FEUSER_LOGIN_STATUS) {
3308              return false;
3309          }
3310          if(empty($GLOBALS['content']['struct'][$level_ID]['acat_hidden'])) {
3311              return true;
3312          } elseif($GLOBALS['content']['struct'][$level_ID]["acat_hidden"] == 2 && isset($GLOBALS['LEVEL_KEY'][$level_ID])) {
3313              return true;
3314          }
3315          return false;
3316      }
3317      return false;
3318  }
3319  
3320  function setPageTitle($pagetitle, $cattitle, $articletitle, $title_order=NULL) {
3321      // get default pagetitle order value;
3322      if($title_order === NULL) {
3323          $title_order = empty($GLOBALS['pagelayout']['layout_title_order']) ? 0 : intval($GLOBALS['pagelayout']['layout_title_order']);
3324      }    
3325      if(empty($GLOBALS['pagelayout']['layout_title_spacer'])) {
3326          $title_spacer = ' | ';
3327          $GLOBALS['pagelayout']['layout_title_spacer'] = $title_spacer;
3328      } else {
3329          $title_spacer = $GLOBALS['pagelayout']['layout_title_spacer'];
3330      }
3331      switch($title_order) {
3332      
3333          case 1:        $title = array($pagetitle, $articletitle, $cattitle); break;
3334          case 2:        $title = array($cattitle, $articletitle, $pagetitle); break;
3335          case 3:        $title = array($cattitle, $pagetitle, $articletitle); break;
3336          case 4:        $title = array($articletitle, $cattitle, $pagetitle); break;
3337          case 5:        $title = array($articletitle, $pagetitle, $cattitle); break;
3338  
3339          case 6:        $title = array($pagetitle, $cattitle);         break;
3340          case 7:        $title = array($pagetitle, $articletitle);     break;
3341          case 8:        $title = array($cattitle, $articletitle);     break;
3342          case 9:        $title = array($cattitle, $pagetitle);         break;
3343          case 10:    $title = array($articletitle, $cattitle);     break;
3344          case 11:    $title = array($articletitle, $pagetitle);     break;
3345  
3346          case 12:    $title = array($pagetitle);     break;
3347          case 13:    $title = array($cattitle);         break;
3348          case 14:    $title = array($articletitle);     break;
3349          
3350          default:    $title = array($pagetitle, $cattitle, $articletitle);
3351      
3352      }
3353      $title = array_diff($title, array('', NULL, false));
3354      $title = array_unique($title);
3355      $title = trim(implode($title_spacer, $title));
3356      return ($title === '') ? $pagetitle : $title;
3357  }
3358  
3359  function sanitize_replacement_tags( $string, $rt='', $bracket=array('{}', '[]') ) {
3360      if( $string === '' ) return '';
3361      if( is_string($bracket) ) {
3362          $bracket = array($bracket);
3363      }
3364      $tag = array();
3365      if($rt === '') {
3366          $tag[] = array('.*?', '.*?');
3367      } elseif( is_array($rt) ) {
3368          foreach($rt as $value) {
3369              $value = trim($value);
3370              if($value === '') continue;
3371              $tag[] = array($value . '.*?', $value);
3372          }
3373      } elseif( is_string($rt) ) {
3374          $rt = trim($rt);
3375          if($rt) {
3376              $tag[] = array($rt . '.*?', $rt);
3377          }
3378      }
3379      if( is_array($bracket) && count($bracket) && count($tag) ) {
3380          foreach($bracket as $value) {
3381              if(strlen($value) < 2) continue;
3382              $prefix = preg_quote($value{0});
3383              $suffix = preg_quote($value{1});
3384              foreach($tag as $row) {
3385                  $string = preg_replace('/' . $prefix . $row[0] . $suffix . '(.*?)' . $prefix . '\/' . $row[1] . $suffix . '/si', '$1', $string);
3386              }
3387          }
3388      }
3389      return $string;
3390  }
3391  
3392  function parseLightboxCaption($caption='') {
3393      if(empty($caption)) return '';
3394      $caption = html_parser($caption);
3395      return html_specialchars($caption);
3396  }
3397  
3398  function get_article_morelink(& $article) {
3399      if($article['article_redirect'] && strpos($article['article_redirect'], ' ')) {
3400          $link = explode(' ', $article['article_redirect']);
3401          if($link[0]) {
3402              $link[0] = str_replace('{SITE}', PHPWCMS_URL, $link[0]);
3403          }
3404          if(empty($link[1])) $link[1] = '';
3405      } else {
3406          $link[0] = 'index.php?'.setGetArticleAid($article);
3407          $link[1] = '';
3408      }
3409      return $link;
3410  }
3411  
3412  function set_css_link($css='', $add_template_path=true) {
3413      $css_var = basename($css);
3414      $GLOBALS['block']['custom_htmlhead'][$css_var] = '  <link href="';
3415      if($add_template_path) {
3416          $GLOBALS['block']['custom_htmlhead'][$css_var] .= TEMPLATE_PATH;
3417      }
3418      $GLOBALS['block']['custom_htmlhead'][$css_var] .= $css.'" rel="stylesheet" type="text/css" />';
3419  }
3420  
3421  function getFrontendEditLink($type='', $id_1=0, $id_2=0) {
3422  
3423      // check if frontend edit link allowed
3424      if(!FE_EDIT_LINK) return '';
3425      
3426      // init Mootools
3427      initJSLib();
3428      
3429      // set specific frontend editing link
3430      set_css_link('inc_css/specific/frontend_edit.css');
3431      
3432      $link  = '';
3433      $href  = '';
3434      $title = '';
3435      
3436      switch($type) {
3437  
3438          case 'article':        $href  = 'do=articles&amp;p=2&amp;s=1&amp;id='.$id_1;
3439                              $title = 'backend: goto Article';
3440                              break;
3441                              
3442          case 'summary':        $href = 'do=articles&amp;p=2&amp;s=1&amp;aktion=1&amp;id='.$id_1;
3443                              $title = 'backend: edit Article Summary';
3444                              break;
3445  
3446          case 'structure':    break;
3447                              
3448          case 'CP':            $href = 'do=articles&amp;p=2&amp;s=1&amp;aktion=2&amp;id='.$id_1.'&amp;acid='.$id_2;
3449                              $title = 'backend: edit Content Part';
3450                              break;
3451                              
3452          case 'module':        $href = 'do=modules&amp;module='.$id_1;
3453                              $title = 'backend: goto Module';
3454                              break;
3455      }
3456      
3457      if($href) {
3458      
3459          $link  = '<a href="'.PHPWCMS_URL.'phpwcms.php?'.$href.'" target="_blank" ';
3460          $link .= 'class="fe-link fe-'.$type.'" title="'.$title.'">';
3461          $link .= '<span>'.$title.'</span></a> ';
3462      
3463      }
3464      
3465      return $link;
3466  }
3467  
3468  function setGetArticleAid(&$data) {
3469  
3470      if(!empty($data['article_alias'])) {
3471          return $data['article_alias'];
3472      } elseif(isset($data['article_id'])) {
3473          return 'aid='.$data['article_id'];
3474      }
3475      return '';
3476  }
3477  
3478  /**
3479   * Return Link based on given structure level data
3480   *
3481   * @param mixed - structure level [integer] ID or Array(acat_redirect,acat_alias,acat_id,acat_name) 
3482   * @param string - additional link attributes
3483   * @param string - link prefix
3484   * @param string - link suffix
3485   */
3486  function getStructureLevelLink($acat, $attributes='', $prefix='', $suffix='') {
3487      
3488      if( !is_array($acat) ) {
3489          
3490          $id = is_int($acat) ? intval($acat) : -1;
3491          
3492          if($id >= 0 && isset($GLOBALS['content']['struct'][$id])) {
3493          
3494              $acat =& $GLOBALS['content']['struct'][$id];
3495          
3496          } else {
3497              
3498              $acat = trim($acat);
3499              
3500              if(empty($acat)) {
3501                  return '';
3502              }
3503              
3504              return $prefix . html_specialchars( $acat ) . $suffix;
3505          
3506          }
3507          
3508      }
3509      
3510      if($acat['acat_redirect'] == false) {
3511          
3512          $target        = '';
3513          $link        = rel_url( array(), array(), empty($acat['acat_alias']) ? 'id='.$acat['acat_id'] : $acat['acat_alias'] );
3514          
3515      } else {
3516          
3517          $redirect    = get_redirect_link($acat['acat_redirect'], ' ', '');
3518          $target        = $redirect['target'];
3519          $link        = $redirect['link'];
3520          
3521      }
3522      
3523      return trim( '<a href="' . $link . '"' . $target . ' ' . $attributes ) . '>' . $prefix . html_specialchars( $acat['acat_name'] ) . $suffix . '</a>';
3524      
3525  }
3526  
3527  /**
3528   * Return menu or menu elements based on article menu title information 
3529   * starting at given structure level ID, limited to single level (non-nested)
3530   *
3531   * @return mixed (array/string)
3532   * @param array
3533   **/
3534  function getArticleMenu($data=array()) {
3535      
3536      global $content;
3537      global $aktion;
3538      
3539      $defaults = array(
3540          
3541          'level_id'                => 0,
3542          'class_active'            => 'active',
3543          'wrap_title_prefix'        => '',
3544          'wrap_title_suffix'        => '',
3545          'item_prefix'            => "\t",
3546          'item_suffix'            => '',
3547          'sort'                    => 'level',
3548          'item_tag'                => 'li',
3549          'wrap_tag'                => 'ul',
3550          'attribute_wrap_tag'    => '',
3551          'class_item_tag'        => '',
3552          'class_first_item_tag'    => '',
3553          'class_last_item_tag'    => '',
3554          'return_format'            => 'string' // string or array
3555  
3556                        );    
3557      
3558      $data    = is_array($data) && count($data) ? array_merge($defaults, $data) : $defaults;
3559      $li        = array();
3560      
3561      $articles = get_actcat_articles_data( $data['level_id'] );
3562      
3563      $key    = 0;
3564      $total    = count($articles) - 1;
3565      foreach($articles as $item) {
3566          
3567          $class = '';
3568          if($data['class_item_tag']) {
3569              $class .= $data['class_item_tag'].' ';
3570          }
3571          if($key === 0 && $data['class_first_item_tag']) {
3572              $class .= $data['class_first_item_tag'].' ';
3573          } elseif($key === $total && $data['class_last_item_tag']) {
3574              $class .= $data['class_last_item_tag'].' ';
3575          }
3576          if($data['class_active'] && $item['article_id'] == $aktion[1]) {
3577              $class .= $data['class_active'].' ';
3578          }
3579          $class = trim($class);
3580          
3581          $li[$key]  = $data['item_prefix'] . '<'. $data['item_tag'] . ($class != '' ? ' class="' . $class . '"' : '' ) . '>';
3582  
3583          $li[$key] .= '<a href="'.rel_url( array(), array(), setGetArticleAid($item) ).'">';
3584          
3585          $li[$key] .= $data['wrap_title_prefix'];
3586          $li[$key] .= html_entities( getArticleMenuTitle($item) );
3587          $li[$key] .= $data['wrap_title_suffix'];
3588          
3589          $li[$key] .= '</a>';
3590  
3591          $li[$key] .= '</'.$data['item_tag'].'>' . $data['item_suffix'];
3592      
3593          $key++;
3594      
3595      }
3596      
3597      if($data['wrap_tag'] && count($li)) {
3598          
3599          array_unshift($li, '<'.trim($data['wrap_tag'].' '.trim($data['attribute_wrap_tag'])).'>');
3600          array_push($li, '</'.$data['wrap_tag'].'>');
3601          
3602      }
3603      
3604      return $data['return_format'] == 'string' ? implode(LF, $li) : $li;
3605  
3606  }
3607  
3608  /**
3609   * Return article menu title text
3610   *
3611   * @return string
3612   * @param array article data
3613   **/
3614  function getArticleMenuTitle(& $data) {
3615      return empty($data['article_menutitle']) ? $data['article_title'] : $data['article_menutitle'];
3616  }
3617  
3618  /**
3619   * Add HTML Head meta tag
3620   */
3621  function set_meta($name='', $content='', $http_equiv=FALSE) {
3622      if(empty($name) || empty($content)) {
3623          return NULL;
3624      }
3625      $GLOBALS['block']['custom_htmlhead']['meta.'.$name]  = '  <meta ';
3626      $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= $http_equiv ? 'http-equiv' : 'name';
3627      $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= '="' . $name . '" content="'.html_specialchars($content).'" />';
3628  }
3629  
3630  /**
3631   * Search for replacement tag {LEVELX_ID} while X is integer like {LEVEL3_ID}
3632   * and return ID of the level or 0 if level is not set
3633   */
3634  function replace_level_id($match) {
3635      $level_id = intval($match[1]);
3636      if(isset($GLOBALS['LEVEL_ID'][ $level_id ])) {
3637          return $GLOBALS['LEVEL_ID'][ $level_id ];
3638      }
3639      return 0;
3640  }
3641  
3642  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7