[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

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

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


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7