Source for file md_phpdig.php
Documentation is available at md_phpdig.php
<?php /* <!-- Dokeos metadata/md_phpdig.php -->
<!-- Copyright (C) 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
==============================================================================
* Dokeos Metadata: PhpDig connection
* If PhpDig 1.8.3 is installed in a Dokeos course site, then MD items
* can be indexed for search (via PhpDig's search screen search.php).
* The functions below inject the words of metadata/indexabletext directly
* into PhpDig's tables. Affected tables:
* keywords: key_id, twoletters, keyword (lowercase, accents removed)
* sites: site_id, site_url (e.g. http://xx.yy.zz/), upddate, ...
* spider: spider_id, site_id, upddate, num_words, first_words,
* path (e.g. uu/vv/ww/), file (e.g. index.php?sid=xxx), ...
* engine: spider_id, key_id, weight
* Most of the function code is a simplified version of real PhpDig code
* released under the GNU GPL V2, see www.phpdig.net.
* @package dokeos.metadata
==============================================================================
// PHPDIG CONNECTION ---------------------------------------------------------->
$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...
while (list ($id,$word) = each($lines))
$common_words[trim($word)] = 1;
define('SUMMARY_DISPLAY_LENGTH', 700);
define('PHPDIG_ENCODING', 'iso-8859-1');
define('SMALL_WORDS_SIZE', 2);
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)
if ($with) // because last one will be empty!
$letterswithout .= $without; $letterswith .= $with;
define('LETTERS_WITH_ACCENTS', $letterswith);
define('SAME_WITHOUT_ACCENTS', $letterswithout);
or give_up('LETTERS_WITH_ACCENTS problem in md_phpdig.php');
$site_url = "site_url = '" . addslashes($url) . "'";
$result = api_sql_query("SELECT site_id FROM " . PHPDIG_DB_PREFIX .
"sites WHERE " . $site_url, __FILE__ , __LINE__ ); // find site
"sites SET " . $site_url, __FILE__ , __LINE__ ); // new site
"site_page (site_id,num_page) VALUES ('$site_id', '0')");
$and_path = " AND path = '" . addslashes($path) . "'";
if ($file) $and_path .= " AND file LIKE '" . addslashes(
str_replace(array('_', '%'), array('\_', '\%'), $file)) . "%'";
$result = api_sql_query("SELECT spider_id FROM " . PHPDIG_DB_PREFIX .
"spider WHERE site_id=" . ($site_id = find_site($url)) . $and_path,
__FILE__ , __LINE__ ); // find page(s)
"engine WHERE spider_id=" . (int) $row['spider_id'],
__FILE__ , __LINE__ ); // delete all references to keywords
"spider WHERE site_id=" . $site_id . $and_path,
__FILE__ , __LINE__ ); // delete page
' pages + word references removed from index.<br>';
function index_words($site_id, $path, $file, $first_words, $keywords)
$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
api_sql_query("INSERT INTO " . PHPDIG_DB_PREFIX . $spider_set_path_etc,
foreach ($keywords as $key => $w)
!isset ($common_words[$key]) and
$result = api_sql_query("SELECT key_id FROM " . PHPDIG_DB_PREFIX .
"keywords WHERE keyword = '" . addslashes($key) . "'",
"keywords (keyword,twoletters) VALUES ('" . addslashes($key) .
"engine (spider_id,key_id,weight) VALUES ($spider_id,$key_id,$w)",
$spider_id, '):</td><td align="right">', count($keywords), ' kwds, ',
$new , ' new</td></tr>', "\n";
$db_some_text = preg_replace("/([ ]{2}|\n|\r|\r\n)/" ," ", $text);
$titre_resume = $path . $file;
if (($psc = strpos($titre_resume, 'scorm/')) !== FALSE)
$titre_resume = substr($titre_resume, $psc + 6);
if (($pth = strpos($titre_resume, '&thumb')) !== FALSE)
$titre_resume = substr($titre_resume, 0, $pth);
return $titre_resume. "\n". $db_some_text;
while (($token = strtok(' ')))
$nbre_mots[$token] = ($nm = $nbre_mots[$token]) ? $nm + 1 : 1;
// the next two repeated lines needed
//$text = ereg_replace('\.+[[:space:]]|\.+$|\.{2,}',' ',$text);
|