Location: PHPKode > projects > Buzzword > buzzword-0.8.12/contrib/keywords.php
<?php

/*
 * buzzword
 * Copyright (c) 2003 Brad Taylor, Jon Tai
 *
 * $Id: keywords.php,v 1.9 2003/12/11 23:54:33 bradt Exp $
 * Flush and re-populate the keywords cache for the relevance engine
 *
 * This file is part of buzzword.
 *
 * buzzword is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * buzzword is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with buzzword; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

// comment out this line to run the rest of this script 
// (prevents DoS attacks... this script takes a LOT of resources to run)
die('permission denied');

$progress_dot = ".\n";
$progress_dot .= "<!--\n";
$progress_dot .= str_repeat(str_repeat('x', 70)."\n", 32);
$progress_dot .= "-->\n";

function print_progress_dot() {
    global $progress_dot;

    echo $progress_dot;
    flush();
    set_time_limit(30);
}

require_once '../includes/config.inc';
include_once '../includes/header.inc';

?>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td id="content">
<?php

// clear all cached keywords
echo 'flushing cache: ';
for ($i = 0; $i < 100; $i++)
    print_progress_dot();

$sql = 'TRUNCATE TABLE '.DB_PREFIX.'relevance_cache';
$result = mysql_query($sql);
echo mysql_error();

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();


// blog entries
echo 'caching keywords for entries: ';
print_progress_dot();

$sql = 'SELECT entry_key FROM '.DB_PREFIX.'blog_entries';
$result = mysql_query($sql);
echo mysql_error();

$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $entry = new blog_entry($row['entry_key']);
    cache_relevance_keywords('blog_entry', $entry->entry_key, get_relevance_keywords(strtoupper($entry->title).'.'.$entry->title.'.'.$entry->body));
    if (!($i++ % 10))
        print_progress_dot();
}

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();


// galleries
echo 'caching keywords for galleries: ';
print_progress_dot();

$sql = 'SELECT gallery_key FROM '.DB_PREFIX.'gallery_galleries';
$result = mysql_query($sql);
echo mysql_error();

$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $gallery = new gallery_gallery($row['gallery_key']);
    cache_relevance_keywords('gallery_gallery', $gallery->gallery_key, get_relevance_keywords(strtoupper($gallery->title).'.'.$gallery->title.'.'.$gallery->description));
    if (!($i++ % 10))
        print_progress_dot();
}

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();


// images
echo 'caching keywords for images: ';
print_progress_dot();

$sql = 'SELECT image_key FROM '.DB_PREFIX.'gallery_images';
$result = mysql_query($sql);
echo mysql_error();

$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $image = new gallery_image($row['image_key']);
    cache_relevance_keywords('gallery_image', $image->image_key, get_relevance_keywords(strtoupper($image->title).'.'.$image->title.'.'.$image->description));
    if (!($i++ % 10))
        print_progress_dot();
}

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();


// categories
echo 'caching keywords for categories: ';
print_progress_dot();

$sql = 'SELECT category_key FROM '.DB_PREFIX.'links_categories';
$result = mysql_query($sql);
echo mysql_error();

$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $category = new links_category($row['category_key']);
    cache_relevance_keywords('links_category', $category->category_key, get_relevance_keywords(strtoupper($category->title).'.'.$category->title.'.'.$category->description));
    if (!($i++ % 10))
        print_progress_dot();
}

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();
                                                                                                                             

// links
echo 'caching keywords for links: ';
print_progress_dot();

$sql = 'SELECT link_key FROM '.DB_PREFIX.'links_links';
$result = mysql_query($sql);
echo mysql_error();
                                                                                                                             
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $link = new links_link($row['link_key']);
    cache_relevance_keywords('links_link', $link->link_key, get_relevance_keywords(strtoupper($link->title).'.'.$link->title.'.'.$link->description));
    if (!($i++ % 10))
        print_progress_dot();
}

echo "done<br>\n";
echo "<table><tr><td></td></tr></table>\n";
flush();

?>
</td>
</tr>
</table>
<?php

include_once '../includes/footer.inc';

?>
Return current item: Buzzword