hotwords
[ class tree: hotwords ] [ index: hotwords ] [ all elements ]

Source for file hotword_lib.php

Documentation is available at hotword_lib.php

  1. <?php
  2. /**
  3.  * @version $Header: /cvsroot/bitweaver/_bit_hotwords/hotword_lib.php,v 1.8 2007/01/06 09:46:15 squareing Exp $
  4.  * @package hotwords
  5.  */
  6.  
  7. /**
  8.  * @version $Header: /cvsroot/bitweaver/_bit_hotwords/hotword_lib.php,v 1.8 2007/01/06 09:46:15 squareing Exp $
  9.  * @package hotwords
  10.  */
  11. class HotwordsLib extends BitBase {
  12.     function HotwordsLib({                
  13.     BitBase::BitBase();
  14.     }
  15.     /**
  16.      * List hotwords
  17.      * @return Data array of hotwords
  18.      *  [data] is the actual array of words
  19.      *  [cant] is a count of the number of entries in [data]
  20.      */
  21.     function list_hotwords($offset 0$max_records = -1$sort_mode 'word_desc'$find ''{
  22.  
  23.         if ($find{
  24.             $findesc $this->mDb->qstr('%' strtoupper$find '%');
  25.             $mid " where UPPER(`word`) like ?";
  26.             $bindvars array($findesc);
  27.         else {
  28.             $mid '';
  29.             $bindvars array();
  30.         }
  31.  
  32.         $query "select * from `".BIT_DB_PREFIX."hotwords$mid order by ".$this->mDb->convertSortmode($sort_mode);
  33.         $query_cant "select count(*) from `".BIT_DB_PREFIX."hotwords$mid";
  34.         $result $this->mDb->query($query,$bindvars,$max_records,$offset);
  35.         $cant $this->mDb->getOne($query_cant,$bindvars);
  36.         $ret array();
  37.  
  38.         while ($res $result->fetchRow()) {
  39.             $ret[$res;
  40.         }
  41.  
  42.         $retval array();
  43.         $retval["data"$ret;
  44.         $retval["cant"$cant;
  45.         return $retval;
  46.     }
  47.  
  48.     /**
  49.      * Add hotword
  50.      * 
  51.      * @param word        Word to be replaced by link
  52.      * @param url        Url to be used with that word
  53.      */
  54.     function add_hotword($word$url{
  55.         $word addslashes($word);
  56.  
  57.         $url addslashes($url);
  58.         $query "delete from `".BIT_DB_PREFIX."hotwords` where `word`=?";
  59.         $result $this->mDb->query($query,array($word));
  60.         $query "insert into `".BIT_DB_PREFIX."hotwords`(`word`,`url`) values(?,?)";
  61.         $result $this->mDb->query($query,array($word,$url));
  62.         return true;
  63.     }
  64.  
  65.     /**
  66.      * Remove hotword
  67.      * 
  68.      * @param word        Word to be removed
  69.      */
  70.     function remove_hotword($word{
  71.         $query "delete from `".BIT_DB_PREFIX."hotwords` where `word`=?";
  72.         $result $this->mDb->query($query,array($word));
  73.     }
  74.  
  75.     /**
  76.      * Replace hotword
  77.      *
  78.      * @param line        Text to be modified by adding links
  79.      * @param words        Words to be replaced by links
  80.      * @return String with hotword link
  81.      */
  82.     function replace_hotwords($line$words{
  83.         global $gBitSystem;
  84.         $hotw_nw ($gBitSystem->isFeatureActive'hotwords_new_window' )) "onkeypress='popUpWin(this.href,'fullScreen',0,0);' onclick='popUpWin(this.href,'fullScreen',0,0);return false;'" '';
  85.  
  86.         // Replace Hotwords
  87.         foreach ($words as $word => $url{
  88.             // \b is a word boundary, \s is a space char
  89.             $line preg_replace("/^$word(\b)/i","<a href=\"$url\" $hotw_nw>$word</a>$1",$line);
  90.             $line preg_replace("/\s$word(\b)/i"," <a href=\"$url\" $hotw_nw>$word</a>$1",$line);
  91.         }
  92.  
  93.         return $line;
  94.     }
  95.  
  96.     /**
  97.      * Get hotwords
  98.      *
  99.      * @return Array of hotwords
  100.      */
  101.     function get_hotwords({
  102.         static $retHotwords NULL;
  103.         if!isset$retHotwords ) ) {
  104.             $query "select * from `".BIT_DB_PREFIX."hotwords`";
  105.             $result $this->mDb->query($queryarray());
  106.             $retHotwords array();
  107.             while ($res $result->fetchRow()) {
  108.                 $retHotwords[$res["word"]] $res["url"];
  109.             }
  110.         }
  111.         return $retHotwords;
  112.     }
  113.  
  114. }
  115.  
  116. /**
  117.  * @global HotwordsLib Hotwords library
  118.  */
  119. global $hotwordlib;
  120. $hotwordlib new HotwordsLib();
  121.  
  122. ?>

Documentation generated on Thu, 15 Feb 2007 20:41:11 +0000 by phpDocumentor 1.3.0