$phpDigInc = get_course_path() . $_course['path'] . '/phpdig-1.8.6/includes/';
$phpDigIncCn = $phpDigInc. 'connect.php'; // to connect to PhpDig's database
$phpDigIncCw = $phpDigInc. 'common_words.txt'; // stopwords
// if (!file_exists($phpDigIncCn)) return(); doesn't seem to work properly...
if (file_exists($phpDigIncCw))
if (is_array($lines = @file($phpDigIncCw)))
while (list($id,$word) = each($lines))
$common_words[trim($word)] = 1;
define('SUMMARY_DISPLAY_LENGTH', 700);
//define('PHPDIG_ENCODING', 'iso-8859-1');
define('PHPDIG_ENCODING', strtolower($charset));
define('SMALL_WORDS_SIZE', 2);
define('MAX_WORDS_SIZE',50);
define('WORDS_CHARS_LATIN1', '[:alnum:]��ߵ');
foreach (array( 'A'=>'������', 'a'=>'������', 'O'=>'������', 'o'=>'������',
'E'=>'����', 'e'=>'����', 'C'=>'�', 'c'=>'�', 'I'=>'����',
'i'=>'����', 'U'=>'����', 'u'=>'����', 'Y'=>'�', 'y'=>'��',
'N'=>'�', 'n'=>'�') as $without => $allwith)
foreach (explode('!', chunk_split($allwith, 1, '!')) as $with)
if ($with) // because last one will be empty!
{
$letterswithout .= $without; $letterswith .= $with;
}
define('LETTERS_WITH_ACCENTS', $letterswith);
define('SAME_WITHOUT_ACCENTS', $letterswithout);
(strlen(LETTERS_WITH_ACCENTS) == strlen(SAME_WITHOUT_ACCENTS))
or give_up('LETTERS_WITH_ACCENTS problem in md_phpdig.php');
function find_site($url)
{
$site_url = "site_url = '" . addslashes($url) . "'";
$result = Database::query("SELECT site_id FROM " . PHPDIG_DB_PREFIX .
"sites WHERE " . $site_url); // find site
if (Database::num_rows($result) == 1)
{
$row = Database::fetch_array($result); return (int) $row['site_id'];
}
else
{
$result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
"sites SET " . $site_url); // new site
$site_id = Database::insert_id();
$result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
"site_page (site_id,num_page) VALUES ('$site_id', '0')");
return $site_id;
}
}
function remove_engine_entries($url, $path, $file = '')
{
global $charset;
$and_path = " AND path = '" . addslashes($path) . "'";
if ($file) $and_path .= " AND file LIKE '" . addslashes(
str_replace(array('_', '%'), array('\_', '\%'), $file)) . "%'";
$result = Database::query("SELECT spider_id FROM " . PHPDIG_DB_PREFIX .
"spider WHERE site_id=" . ($site_id = find_site($url)) . $and_path); // find page(s)
while ($row = Database::fetch_array($result))
{
$result = Database::query("DELETE FROM " . PHPDIG_DB_PREFIX .
"engine WHERE spider_id=" . (int)$row['spider_id']); // delete all references to keywords
$aff .= ' +' . Database::affected_rows($result);
}
Database::query("DELETE FROM " . PHPDIG_DB_PREFIX ."spider WHERE site_id=" . $site_id . $and_path); // delete page
echo htmlspecialchars($url . $path . $file, ENT_QUOTES, $charset), ' (site_id ',
$site_id, '): ', Database::affected_rows(), $aff,
' pages + word references removed from index.
';
return $site_id;
}
function index_words($site_id, $path, $file, $first_words, $keywords)
{
global $common_words;
$spider_set_path_etc = "spider SET path='" . addslashes($path) .
"',file='" . addslashes($file) . "',first_words='" .
addslashes($first_words) . "',site_id='$site_id'";
// do not set upddate,md5,num_words,last_modified,filesize
Database::query("INSERT INTO " . PHPDIG_DB_PREFIX . $spider_set_path_etc);
$spider_id = Database::insert_id(); $new = 0;
foreach ($keywords as $key => $w)
if (strlen($key) > SMALL_WORDS_SIZE and strlen($key) <= MAX_WORDS_SIZE and
!isset($common_words[$key]) and
ereg('^['.WORDS_CHARS_LATIN1.'#$]', $key))
{
$result = Database::query("SELECT key_id FROM " . PHPDIG_DB_PREFIX .
"keywords WHERE keyword = '" . addslashes($key) . "'");
if (Database::num_rows($result) == 0)
{
Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
"keywords (keyword,twoletters) VALUES ('" . addslashes($key) .
"','" .addslashes(substr(str_replace('\\','',$key),0,2)) ."')");
$key_id = Database::insert_id(); $new++;
}
else
{
$keyid = Database::fetch_row($result); $key_id = $keyid[0];
}
Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
"engine (spider_id,key_id,weight) VALUES ($spider_id,$key_id,$w)");
}
global $charset;
echo '