[ Index ]

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

title

Body

[close]

/include/inc_module/mod_glossary/ -> frontend.render.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  // Module/Plug-in Glossary frontend_render script
  24  // use it as when it is located under "template/inc_script/frontend_render"
  25  
  26  if(!isset($content['glossary'])) {
  27      
  28      // used to store glossary keywords which has been found
  29      $content['glossary_cache'] = array();
  30  
  31  
  32  	function replace_glossary_tag($matches) {
  33          
  34          global $content;
  35          
  36          $inner = trim($matches[2]);
  37          
  38          // search keyword in glossary table
  39          $keyword = trim($matches[1]);
  40          if($keyword !== '') {
  41              $keyword = html_entity_decode($keyword, ENT_QUOTES, PHPWCMS_CHARSET);
  42              
  43              // check against cache
  44              if(!isset($content['glossary_cache'][$keyword])) {
  45              
  46                  $like = aporeplace($keyword);
  47              
  48                  $where  = 'glossary_status=1 AND glossary_highlight=1 AND (';
  49                  $where .= "glossary_keyword LIKE '".$like."' OR ";
  50                  $where .= "glossary_keyword LIKE '".$like.",%' OR ";
  51                  $where .= "glossary_keyword LIKE '%, ".$like.",%' OR ";
  52                  $where .= "glossary_keyword LIKE '%, ".$like."'";
  53                  $where .= ')';
  54              
  55                  // retrieve only single keyword that matches best
  56                  $entry  = _dbGet('phpwcms_glossary', 'glossary_title, glossary_keyword, glossary_text, COUNT(glossary_id) AS count_all', $where, 'glossary_id', 'count_all DESC', '1');
  57                  
  58                  if(isset($entry[0])) {
  59                      
  60                      // get keywords to store each in cache
  61                      $keywords    = convertStringToArray($entry[0]['glossary_keyword']);
  62                      $title        = empty($entry[0]['glossary_title']) ? $inner : html_specialchars($entry[0]['glossary_title']);
  63                      $text        = trim(clean_slweg($entry[0]['glossary_text']));
  64                  
  65                      // store glossary item in cache
  66                      foreach($keywords as $key) {
  67                          $content['glossary_cache'][$key] = array( 'title' => $title, 'text' => $text );
  68                      }
  69                  
  70                  }
  71              }
  72              
  73              // create ABBR
  74              if(isset($content['glossary_cache'][$keyword])) {
  75              
  76                  $inner =    '<abbr class="glossary" title="'.$content['glossary_cache'][$keyword]['title'].
  77                              ' :: '.
  78                              $content['glossary_cache'][$keyword]['text'].
  79                              '">'.$inner.'</abbr>';
  80              }
  81              
  82          }
  83          
  84          return $inner;
  85          
  86      }
  87      
  88      // Search for glossary tag
  89      $content['all'] = preg_replace_callback('/\[glossary (.*?)\](.*?)\[\/glossary\]/i', 'replace_glossary_tag', $content['all']);
  90      
  91      
  92  
  93  
  94      /*
  95      $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_glossary WHERE ';
  96      $sql .= 'glossary_status=1 AND glossary_highlight=1 AND glossary_keyword != ""';
  97      
  98      $glossary['keywords'] = _dbGet('phpwcms_glossary', );
  99      
 100      if($glossary['keywords'] !== false && is_array($glossary['keywords']) && count($glossary['keywords'])) {
 101      
 102          // OK - fine we have found all glossary words
 103          
 104          $glossary['tags'] = array();
 105          
 106          foreach($glossary['keywords'] as $value) {
 107              $value['glossary_tag'] = convertStringToArray(strtolower($value['glossary_tag']), ' ');
 108              foreach($value['glossary_tag'] as $value) {
 109                  $glossary['tags'][$value] = $value;
 110              }
 111          }
 112          
 113          // now lets search for glossary content parts
 114          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_articlecontent ac ';
 115          $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_article ar ON ac.acontent_aid = ar.article_id ';
 116          $sql .= 'WHERE ar.article_public=1 AND ar.article_aktiv=1 AND ';
 117          $sql .= 'ar.article_deleted=0 AND ar.article_begin<NOW() AND ';
 118          $sql .= 'ar.article_end>NOW() AND ac.acontent_visible = 1 AND ac.acontent_module = "glossary"';
 119          
 120          $glossary['cp'] = @_dbQuery($sql);
 121          
 122          if(is_array($glossary['cp']) && count($glossary['cp'])) {
 123          
 124              foreach($glossary['cp'] as $key => $value) {
 125                  
 126                  if(!isset($content['struct'][ $value['article_cid'] ])) {
 127                      unset($glossary['cp'][$key]);
 128                      continue;
 129                  }
 130                  $glossary['cp'][$key]['acontent_form'] = unserialize($value['acontent_form']);
 131                  $glossary['cp'][$key]['acontent_form']['acontent_id']  = $value['acontent_id'];
 132                  $glossary['cp'][$key]['acontent_form']['acontent_aid'] = $value['acontent_aid'];
 133                  $glossary['cp'][$key]['acontent_form']['article_cid'] = $value['article_cid'];
 134                  
 135                  $glossary['cp'][$key] = $glossary['cp'][$key]['acontent_form'];
 136          
 137              }
 138          
 139          }
 140      
 141      //dumpVar($glossary['tags']);
 142      //dumpVar($glossary['cp']);
 143      //dumpVar($glossary['keywords']);
 144          
 145      }
 146      
 147      */
 148  
 149  }
 150  
 151  ?>


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