Example #1
0
function refresh_index($pContentObject = null)
{
    global $gBitSystem;
    if (is_object($pContentObject)) {
        if (!isset($pContentObject->mInfo["index_data"]) and method_exists($pContentObject, 'setIndexData')) {
            $pContentObject->setIndexData();
        }
        if (isset($pContentObject->mInfo["index_data"]) and isset($pContentObject->mContentId)) {
            if (isset($pContentObject->mType["content_type_guid"])) {
                $contentTypeGuid = $pContentObject->mType["content_type_guid"];
            } elseif (isset($pContentObject->mContentTypeGuid)) {
                $contentTypeGuid = $pContentObject->mContentTypeGuid;
            }
            if (isset($contentTypeGuid)) {
                $words = prepare_words($pContentObject->mInfo["index_data"]);
                insert_index($words, $contentTypeGuid, $pContentObject->mContentId);
            }
        }
    }
}
Example #2
0
function random_refresh_filegal()
{
    global $feature_galleries;
    global $tikilib;
    $cant = $tikilib->getOne("select count(*) from `tiki_file_galleries`", array());
    if ($cant > 0) {
        $query = "select * from `tiki_file_galleries`";
        $result = $tikilib->query($query, array(), 1, rand(0, $cant - 1));
        $res = $result->fetchRow();
        $words =& search_index($res["name"] . " " . $res["description"]);
        insert_index($words, "filegal", $res["galleryId"]);
    }
}
function refresh_index($object_type, $object_id = null)
{
    if (empty($object_type)) {
        return false;
    }
    global $tikilib;
    $wiki_html = '';
    $query_from = " from `tiki_{$object_type}`";
    $query_limit = -1;
    $query_offset = 0;
    $query_vars = array();
    $query_where = '';
    $query_fields = '';
    $cant_query = 'select count(*)' . $query_from;
    $cant_vars = null;
    //$filtering_expr = array('$content = strip_tags($content);');
    // strip tags seems to be bugged (maybe due to UTF-8 content ?)
    $mb = function_exists('mb_ereg_replace') ? 'mb_' : '';
    $filtering_expr = array('$content = ' . $mb . 'ereg_replace("<\\s*/?\\s*([a-zA-Z]+)[^>]*>", " ", $content);');
    switch ($object_type) {
        case 'articles':
            //case 'art': case 'article':
            $index_type = 'article';
            $f_id = 'articleId';
            $f_content = array('title', 'authorName', 'heading', 'body', 'author', 'topline', 'subtitle');
            break;
        case 'blog_posts':
            //case 'blog': case 'blog_post':
            $index_type = 'blog_post';
            $f_id = 'postId';
            $f_content = array('title', 'user', 'data');
            break;
        case 'blogs':
            $index_type = 'blog';
            $f_id = 'blogId';
            $f_content = array('title', 'user', 'description');
            break;
        case 'directory_categories':
            //case 'dir_cat':
            $index_type = 'dir_cat';
            $f_id = 'categId';
            $f_content = array('name', 'description');
            break;
        case 'directory_sites':
            //case 'dir': case 'dir_site':
            $index_type = 'dir_site';
            $f_id = 'siteId';
            $f_content = array('name', 'description');
            break;
        case 'comments':
            //case 'wiki comment': case 'comment':
            $f_index_type = 'objectType';
            $filtering_expr[] = '$index_type .= "comment";';
            $f_id = 'threadId';
            $f_content = array('title', 'data', 'summary', 'objectType');
            break;
        case 'faq_questions':
            $index_type = 'faq_question';
            $f_id = 'questionId';
            $f_content = array('question', 'answer');
            break;
        case 'faqs':
            //case 'faq':
            $index_type = 'faq';
            $f_id = 'faqId';
            $f_content = array('title', 'description');
            break;
        case 'file_galleries':
            $index_type = 'filegal';
            $f_id = 'galleryId';
            $f_content = array('name', 'description');
            break;
        case 'files':
            //case 'fgal': case 'file':
            $index_type = 'file';
            $f_id = 'fileId';
            $f_content = array('data', 'description', 'name', 'search_data', 'filename', 'comment');
            $f_other = array('archiveId', 'filetype');
            $query_where = ' where archiveId = ?';
            $query_vars = array(0);
            $fulltext_mimetypes_pattern = '/^text\\//i';
            // Mimetypes that will be fulltext indexed
            unset($filtering_expr);
            break;
        case 'forums':
            //case 'forum':
            $index_type = 'forum';
            $f_id = 'forumId';
            $f_content = array('name', 'description', 'moderator');
            break;
        case 'images':
            //case 'gal': case 'img':
            $index_type = 'img';
            $f_id = 'imageId';
            $f_content = array('name', 'description');
            break;
        case 'pages':
            //case 'wiki page': case 'wiki':
            $index_type = 'wiki';
            $f_id = 'pageName';
            $f_content = array('data', 'description', 'pageName');
            array_unshift($filtering_expr, '$content = $tikilib->parse_data($content, $res["is_html"]);');
            $wiki_html = ', `is_html`';
            break;
        case 'tracker_items':
            //case 'track': case 'trackeritem':
            $cant_query = 'select count(*) from `tiki_tracker_item_fields` f, `tiki_tracker_fields` tf where tf.`type` in (?,?) and tf.`fieldId`=f.`fieldId`';
            $cant_vars = array('t', 'a');
            $index_type = 'trackeritem';
            $query_from = ' from `tiki_tracker_item_fields` f, `tiki_tracker_fields` tf';
            $query_where = ' where tf.`type` in (?,?) and tf.`fieldId`=f.`fieldId`';
            $query_vars = array('t', 'a');
            $f_id = array('id1' => 'f.`itemId`', 'id2' => 'f.`fieldId`');
            $f_content = array('content' => 'f.`value`');
            break;
        case 'trackers':
            //case 'tracker':
            $index_type = 'tracker';
            $f_id = 'trackerId';
            $f_content = array('name', 'description');
            break;
        case 'galleries':
            // case 'imggal':
            $index_type = 'imggal';
            $f_id = 'galleryId';
            $f_content = array('name', 'description');
            break;
    }
    if ($object_id == -1) {
        // Random indexation...
        $query_limit = 1;
        $cant = $tikilib->getOne($cant_query, $cant_vars);
        if ($cant > 0) {
            $query_offset = rand(0, $cant - 1);
        } else {
            return true;
        }
    } elseif (is_integer($object_id) && $object_id != 0 || is_string($object_id)) {
        // Index one object identified by its id
        $query_vars[] = $object_id;
        $query_where .= ($query_where == '' ? ' where ' : ' and ') . (is_array($f_id) ? $f_id['id1'] : $f_id) . ' = ?';
    }
    if (!empty($f_id) && !empty($f_content)) {
        if (!is_array($f_id)) {
            $f_id = array($f_id);
        }
        if (!is_array($f_content)) {
            $f_content = array($f_content);
        }
        foreach ($f_id as $k_id => $v_id) {
            $query_fields .= ($query_fields != '' ? ', ' : '') . $v_id . (is_string($k_id) ? ' as ' . $k_id : '');
        }
        foreach ($f_content as $k_content => $v_content) {
            $query_fields .= ', ' . $v_content . (is_string($k_content) ? ' as ' . $k_content : '');
        }
        if (!empty($f_other)) {
            $query_fields .= ', ' . (is_array($f_other) ? implode(', ', $f_other) : $f_other);
        }
        $result = $tikilib->query('select ' . $query_fields . $wiki_html . $query_from . $query_where, $query_vars, $query_limit, $query_offset);
        if ($result) {
            while ($res = $result->fetchRow()) {
                if (is_array($res)) {
                    $id = '';
                    $content = '';
                    // For performance reasons, do not index all files with fulltext (depending on their mimetypes)
                    if ($index_type == 'file' && !preg_match($fulltext_mimetypes_pattern, $res['filetype'])) {
                        $res['data'] = '';
                    }
                    foreach ($f_id as $k_id => $v_id) {
                        $id .= ($id != '' ? '#' : '') . $res[is_string($k_id) ? $k_id : $v_id];
                    }
                    foreach ($f_content as $k_content => $v_content) {
                        $content .= ' ' . $res[is_string($k_content) ? $k_content : $v_content];
                    }
                    if (isset($f_index_type) && $f_index_type != '') {
                        $index_type = $res[$f_index_type];
                    }
                    if (is_array($filtering_expr)) {
                        foreach ($filtering_expr as $expr) {
                            eval($expr);
                        }
                    }
                    if ($content != '' && $index_type != '' && $id != '') {
                        insert_index(search_index($content), $index_type, $id);
                    }
                }
            }
        }
    }
    return true;
}