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

Source for file refresh_functions.php

Documentation is available at refresh_functions.php

  1. <?php
  2. /**
  3.  * $Header$
  4.  *
  5.  * @copyright (c) 2004 bitweaver.org
  6.  *  Copyright (c) 2003 tikwiki.org
  7.  *  Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  8.  *  All Rights Reserved. See below for details and a complete list of authors.
  9.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  10.  *
  11.  *  $Id$
  12.  * @author  Luis Argerich (lrargerich@yahoo.com)
  13.  * @package search
  14.  * @subpackage functions
  15.  */
  16.  
  17. // to do - move blogs into tiki content.
  18.  
  19. /**
  20.  * random_refresh_index_comments
  21.  * I believe these functiions are from tiki. They are called every x refreshes of a browser.
  22.  * They appear to pick a random wiki page, comment, blog or article and index it.
  23.  * With the exception of blogs (blog headers not blog posts) they pick the content_id
  24.  * and pass it to refresh_index() to do the work.
  25.  */
  26.  
  27. function random_refresh_index($pContentType ""{
  28.     global $gBitSystem;
  29.     switch ($pContentType{
  30.         case "articles" :
  31.             $table "articles";
  32.             break;
  33.         case "wiki" :
  34.             $table "wiki_pages";
  35.             break;
  36.         case "blogs" :
  37.             $table "blogs";
  38.             break;
  39.         case "blog_posts" :
  40.             $table "blog_posts";
  41.             break;
  42.         case "comments" :
  43.             $table "liberty_comments";
  44.             break;
  45.         default :
  46.             $table "";
  47.     }
  48.     if (!empty($table)) {
  49.         $cant $gBitSystem->mDb->getOne("SELECT COUNT(*) FROM `" BIT_DB_PREFIX $table "`"array());
  50.         if($cant 0{
  51.             $query     "SELECT `content_id` FROM `" BIT_DB_PREFIX $table "`";
  52.             $contentId $gBitSystem->mDb->getOne($queryarray()1rand(0$cant 1));
  53.             refresh_index($contentId);
  54.         }
  55.     }
  56. }
  57.  
  58. /*
  59.  * Index Refresh Function for Liberty Content
  60.  * This can be called directly to force a refresh for a particular piece of tiki content.
  61.  * This is also called by the Random_Refresh_* indexing functions from tiki.
  62.  * This currently works for wiki pages, blog posts and articles.
  63.  */
  64.  
  65. function refresh_index$pContentObject null {
  66.     global $gBitSystem;
  67.     if (is_object($pContentObject)) {
  68.         if ( (!isset($pContentObject->mInfo["index_data"])) and method_exists($pContentObject'setIndexData')) {
  69.             $pContentObject->setIndexData(;
  70.         }
  71.         if (isset($pContentObject->mInfo["index_data"]and isset($pContentObject->mContentId)) {
  72.             if (isset($pContentObject->mType["content_type_guid"])) {
  73.                 $contentTypeGuid $pContentObject->mType["content_type_guid"];
  74.             elseif (isset($pContentObject->mContentTypeGuid)) {
  75.                 $contentTypeGuid $pContentObject->mContentTypeGuid;
  76.             }
  77.             if (isset($contentTypeGuid)) {
  78.                 $words prepare_words($pContentObject->mInfo["index_data"]);
  79.                 insert_index($words$contentTypeGuid$pContentObject->mContentId);
  80.             }
  81.         }
  82.     }
  83. }
  84.  
  85.     global $gBitSystem;
  86.     $contentId $gBitSystem->mDb->getOne("SELECT `content_id` FROM `" BIT_DB_PREFIX .
  87.                 "search_index` ORDER BY `last_update`"array());
  88.     if isset($contentId) ) {
  89.         refresh_index($contentId);
  90.     }
  91. }
  92.  
  93. function prepare_words($data{
  94.     $data strip_tags($data);
  95.     // split into words
  96.     $sstrings preg_split("/[\W]+/"$data-1PREG_SPLIT_NO_EMPTY);
  97.     // count words
  98.     $words array();
  99.     foreach ($sstrings as $key=>$value{
  100.         if(!isset($words[strtolower($value)])) {
  101.             $words[strtolower($value)0;
  102.         }
  103.         $words[strtolower($value)]++;
  104.     }
  105.     return($words);
  106. }
  107.  
  108. function delete_index ($pContentId{
  109.     global $gBitSystem;
  110.     if!empty$pContentId ) ) {
  111.         $sql "DELETE FROM `".BIT_DB_PREFIX."search_index` WHERE `content_id`=?";
  112.         $gBitSystem->mDb->query($sqlarray($pContentId));
  113.     }
  114. }
  115.  
  116. function insert_index&$words$location$pContentId {
  117.     global $gBitSystem;
  118.     if!empty$pContentId ) ) {
  119.         delete_index($pContentId);
  120.         $now $gBitSystem->getUTCTime();
  121.         foreach ($words as $key=>$value{
  122.             if (strlen($key>= $gBitSystem->getConfig'search_min_wordlength') ) {
  123.                 // todo: stopwords + common words.
  124.                 $query "INSERT INTO `" BIT_DB_PREFIX "search_index`
  125.                     (`content_id`,`searchword`,`i_count`,`last_update`) values (?,?,?,?)";
  126.                 $gBitSystem->mDb->query($queryarray($pContentId$key(int) $value$now));
  127.             // What happened to location?
  128.         }
  129.     }
  130. }
  131.  
  132.     global $gBitSystem;
  133.     $gBitSystem->mDb->query"DELETE FROM `" BIT_DB_PREFIX "search_words`"array() );
  134.     $gBitSystem->mDb->query"DELETE FROM `" BIT_DB_PREFIX "search_syllable`"array() );
  135. }
  136.  
  137. function delete_index_content_type($pContentType{
  138.     global $gBitSystem;
  139.     $sql   "DELETE FROM `" BIT_DB_PREFIX "search_index`";
  140.     $array array();
  141.     if $pContentType <> "pages" {
  142.         $sql  .= " WHERE `content_id` IN (SELECT `content_id` FROM `" BIT_DB_PREFIX .
  143.                  "liberty_content` where `content_type_guid` = ?)";
  144.         $array array($pContentType);
  145.     }
  146.     $gBitSystem->mDb->query$sql$array );
  147. }
  148.  
  149. function rebuild_index($pContentType$pUnindexedOnly false{
  150.     global $gBitSystem$gLibertySystem;
  151.     $arguments   array();
  152.     $whereClause "";
  153.     ini_set("max_execution_time""3000");
  154.     if (!$pUnindexedOnly{
  155.         delete_index_content_type($pContentType);
  156.     }
  157.     $query  "SELECT `content_id`, `content_type_guid` FROM `" BIT_DB_PREFIX "liberty_content`";
  158.     if!empty$pContentType && $pContentType != "pages" {
  159.         $whereClause " WHERE `content_type_guid` = ?";
  160.         $arguments[$pContentType;
  161.     }
  162.  
  163.     if$pUnindexedOnly {
  164.         if (empty($whereClause)) {
  165.             $whereClause " WHERE ";
  166.         else {
  167.             $whereClause .= " AND ";
  168.         }
  169.         $whereClause .= "`content_id` NOT IN (SELECT DISTINCT `content_id` FROM `" BIT_DB_PREFIX "search_index`)" ;
  170.     }
  171.  
  172.     $orderBy " ORDER BY `content_type_guid` ";
  173.     $result $gBitSystem->mDb->query$query.$whereClause.$orderBy$arguments );
  174.     $count  0;
  175.     if$result {
  176.         $count  $result->RecordCount();
  177.         while ($res $result->fetchRow()) {
  178.             ifisset$gLibertySystem->mContentTypes[$res["content_type_guid"]] ) ) {
  179.                 $type $gLibertySystem->mContentTypes[$res["content_type_guid"]];
  180.                 require_onceconstantstrtoupper$type['handler_package').'_PKG_PATH' ).$type['handler_file');
  181.                 $obj new $type['handler_class']NULL$res["content_id");
  182.                 refresh_index($obj);
  183.                 unset($obj);
  184.             }
  185.         }
  186.     }
  187.     return $count;
  188. }
  189. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:19 +0000 by phpDocumentor 1.5.0-lsces