/** * create - use this function to create a new entry in the database. * * @param string The filename of this document. Can be a URL. * @param string The filetype of this document. If filename is URL, this should be 'URL'; * @param string The contents of this document (should be addslashes()'d before entry). * @param int The doc_group id of the doc_groups table. * @param string The title of this document. * @param int The language id of the supported_languages table. * @param string The description of this document. * @return boolean success. */ function create($filename, $filetype, $data, $doc_group, $title, $language_id, $description) { if (strlen($title) < 5) { $this->setError(_('Title Must Be At Least 5 Characters')); return false; } if (strlen($description) < 10) { $this->setError(_('Document Description Must Be At Least 10 Characters')); return false; } /* $perm =& $this->Group->getPermission( session_get_user() ); if (!$perm || !is_object($perm) || !$perm->isDocEditor()) { $this->setPermissionDeniedError(); return false; } */ $user_id = session_loggedin() ? user_getid() : 100; $doc_initstatus = '3'; // If Editor - uploaded Documents are ACTIVE if (session_loggedin()) { $perm =& $this->Group->getPermission(session_get_user()); if ($perm && is_object($perm) && $perm->isDocEditor()) { $doc_initstatus = '1'; } } // If $filetype is "text/plain", $body convert UTF-8 encoding. if (strcasecmp($filetype, "text/plain") === 0 && function_exists('mb_convert_encoding') && function_exists('mb_detect_encoding')) { $data = mb_convert_encoding($data, 'UTF-8', mb_detect_encoding($data)); } $data1 = $data; // key words for in-document search $kw = new Parsedata($this->engine_path); $kwords = $kw->get_parse_data(stripslashes($data1), htmlspecialchars($title1), htmlspecialchars($description), $filetype); // $kwords = ""; $filesize = strlen($data); $sql = "INSERT INTO doc_data (group_id,title,description,createdate,doc_group,\n\t\t\tstateid,language_id,filename,filetype,filesize,data,data_words,created_by)\n\t\t\tVALUES ('" . $this->Group->getId() . "',\n\t\t\t'" . htmlspecialchars($title) . "',\n\t\t\t'" . htmlspecialchars($description) . "',\n\t\t\t'" . time() . "',\n\t\t\t'{$doc_group}',\n\t\t\t'{$doc_initstatus}',\n\t\t\t'{$language_id}',\n\t\t\t'{$filename}',\n\t\t\t'{$filetype}',\n\t\t\t'{$filesize}',\n\t\t\t'" . base64_encode(stripslashes($data)) . "',\n\t\t\t'{$kwords}',\n\t\t\t'{$user_id}')"; db_begin(); $result = db_query($sql); if (!$result) { $this->setError('Error Adding Document: ' . db_error()); db_rollback(); return false; } $docid = db_insertid($result, 'doc_data', 'docid'); if (!$this->fetchData($docid)) { db_rollback(); return false; } $this->sendNotice(true); db_commit(); return true; }
$sql = "SELECT docid, group_id, filename, title, createdate, filename, description, filetype, data FROM doc_data \n"; $resarr = array(); $result = db_query($sql); if ($result) { while ($arr = db_fetch_array($result)) { $resarr[] = $arr; } } $compt = 0; $rapp = ""; foreach ($resarr as $item) { $compt++; $timestart = microtime_float(); $data1 = base64_decode($item["data"]); $lenin = strlen($data1); $res = $p->get_parse_data($data1, $item["title"], $item["description"], $item["filetype"]); $len = strlen($res); $sql = "UPDATE doc_data SET data_words = '{$res}' WHERE docid = {$item['docid']} "; db_query($sql); $timeend = microtime_float(); $timetrait = $timeend - $timestart; print_debug("analyze {$item['filename']} type={$item['filetype']} octets in={$lenin} octets out={$len} time={$timetrait} sec"); } $timeendtrait = microtime_float(); $timetot = $timeendtrait - $timestarttrait; print_debug("End analyze : {$compt} files, {$timetot} secs."); function print_debug($text) { echo "{$text}\n"; } function microtime_float()