Permalink
Browse files

General syncback from HEAD branch (2.0)

  • Loading branch information...
1 parent 386aed2 commit 603042b740a3c1a539c3a4070b100111a0938a43 diml committed Nov 8, 2007
View
@@ -0,0 +1,15 @@
+This block is a revamping of the Google Summer Of Code Project (2006) on Global Search engine
+for Moodle. New block version is completed and internationalized according to Moodle multilengual support.
+
+This block instanciates a startup database model for the search engine.
+
+## Installing
+
+You need installing the following elements in order the global search to be available :
+
+1. The global search bloc (this block)
+2. update the /search root package from CVS
+3. The antiword libraries
+4. The xpdf libraries
+
+Both last libraries are provided as a patch called "global_search_libraries" in the contrib section.
@@ -14,8 +14,9 @@
class block_search extends block_base {
function init() {
- $this->title = "Global Search"; //get_string()
- $this->version = 2006062500;
+ $this->title = get_string('blockname', 'block_search');
+ $this->cron = 1;
+ $this->version = 2007081100;
} //init
// only one instance of this block is required
@@ -45,8 +46,8 @@ function get_content() {
//lazy check for the moment
if (check_php_version("5.0.0")) {
//fetch values if defined in admin, otherwise use defaults
- $label = (isset($CFG->block_search_text)) ? $CFG->block_search_text : "Search Moodle";
- $button = (isset($CFG->block_search_button)) ? $CFG->block_search_button : "Go";
+ $label = (!empty($CFG->block_search_text)) ? $CFG->block_search_text : get_string('searchmoodle', 'block_search');
+ $button = (!empty($CFG->block_search_button)) ? $CFG->block_search_button : get_string('go', 'block_search');
//basic search form
$this->content->text =
@@ -68,7 +69,17 @@ function get_content() {
function specialisation() {
//empty!
} //specialisation
+
+ /**
+ * wraps up to search engine cron
+ *
+ */
+ function cron(){
+ global $CFG;
+
+ include($CFG->dirroot.'/search/cron.php');
+ }
} //block_search
-?>
+?>
@@ -1,19 +1,132 @@
<div style="text-align:center;">
- <label for="block_search_text">Search label</label>
- <input id="block_search_text" type="text" name="block_search_text" value="<?php
- if(isset($CFG->block_search_text)) {
- p($CFG->block_search_text);
- } else {
- p("Search Moodle");
- } ?>"/><br/>
-
- <label for="block_search_button">Button label</label>
- <input id="block_search_button" type="text" name="block_search_button" value="<?php
- if(isset($CFG->block_search_button)) {
- p($CFG->block_search_button);
- } else {
- p("Go");
- } ?>"/><br/><br/>
-
- <input type="submit" value="<?php print_string('savechanges'); ?>" />
+<table cellspacing="5">
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configsearchtext', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_text" type="text" name="block_search_text" value="<?php
+ if(isset($CFG->block_search_text)) {
+ p($CFG->block_search_text);
+ } else {
+ p(get_string('searchmoodle', 'block_search'));
+ } ?>"/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configbuttonlabel', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_button" type="text" name="block_search_button" value="<?php
+ if(isset($CFG->block_search_button)) {
+ p($CFG->block_search_button);
+ } else {
+ p(get_string('go', 'block_search'));
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configenablefileindexing', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_enable_file_indexing" type="radio" name="block_search_enable_file_indexing" value="1" <?php
+ if(isset($CFG->block_search_enable_file_indexing) && $CFG->block_search_enable_file_indexing) {
+ echo " checked=\"checked\" ";
+ } ?> /> <?php print_string('yes') ?> -
+ <input id="block_search_enable_file_indexing" type="radio" name="block_search_enable_file_indexing" value="0" <?php
+ if(!isset($CFG->block_search_enable_file_indexing) || !$CFG->block_search_enable_file_indexing) {
+ echo " checked=\"checked\" ";
+ } ?> /> <?php print_string('no') ?>
+ <br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configfiletypes', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_filetypes" type="text" name="block_search_filetypes" value="<?php
+ if(isset($CFG->block_search_filetypes)) {
+ p($CFG->block_search_filetypes);
+ } else {
+ p("PDF,TXT,HTML,PPT,XML,DOC,HTM");
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_pdf_to_text_cmd" type="text" size="60" name="block_search_pdf_to_text_cmd" value="<?php
+ if(isset($CFG->block_search_pdf_to_text_cmd)) {
+ p($CFG->block_search_pdf_to_text_cmd);
+ } else {
+ $encoding = ($CFG->unicodedb) ? "-enc UTF-8" : "-enc ISO-8859-1" ;
+ if ($CFG->ostype == 'WINDOWS'){
+ p("lib/xpdf/win32/pdftotext.exe -eol dos $encoding -q");
+ }
+ else{
+ p("lib/xpdf/linux/pdftotext $encoding -eol unix -q");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configwordtotextcmd', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_word_to_text_cmd" type="text" size="60" name="block_search_word_to_text_cmd" value="<?php
+ if(isset($CFG->block_search_word_to_text_cmd)) {
+ p($CFG->block_search_word_to_text_cmd);
+ } else {
+ if ($CFG->ostype == 'WINDOWS'){
+ p("lib/antiword/win32/antiword/antiword.exe ");
+ }
+ else{
+ p("lib/antiword/linux/usr/bin/antiword");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configwordtotextenv', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_word_to_text_env" type="text" size="60" name="block_search_word_to_text_env" value="<?php
+ if(isset($CFG->block_search_word_to_text_env)) {
+ echo stripslashes($CFG->block_search_word_to_text_env);
+ } else {
+ if ($CFG->ostype == 'WINDOWS'){
+ p("HOME={$CFG->dirroot}\\lib\\antiword\\win32");
+ }
+ else{
+ p("ANTIWORDHOME={$CFG->dirroot}/lib/antiword/linux/usr/share/antiword");
+ }
+ } ?>"/><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right">
+ <b><?php print_string('configlimitindexbody', 'block_search') ?>:</b>
+ </td>
+ <td valign="top" align="left">
+ <input id="block_search_limit_index_body" type="text" size="8" name="block_search_limit_index_body" value="<?php
+ if(isset($CFG->block_search_limit_index_body)) {
+ p($CFG->block_search_limit_index_body);
+ } else {
+ p('');
+ } ?>"/> <?php print_string('bytes', 'block_search') ?><br/><br/>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top" align="right" colspan="2">
+ <input type="submit" value="<?php print_string('savechanges'); ?>" />
+ </td>
+ </tr>
+</table>
</div>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="blocks/search/db" VERSION="20070811" COMMENT="XMLDB file for Moodle search engine"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
+>
+ <TABLES>
+ <TABLE NAME="block_search_documents" COMMENT="table to store search index backups">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="docid"/>
+ <FIELD NAME="docid" TYPE="char" LENGTH="32" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="doctype"/>
+ <FIELD NAME="doctype" TYPE="char" LENGTH="32" NOTNULL="true" DEFAULT="none" SEQUENCE="false" ENUM="false" PREVIOUS="docid" NEXT="itemtype"/>
+ <FIELD NAME="itemtype" TYPE="char" LENGTH="32" NOTNULL="true" DEFAULT="standard" SEQUENCE="false" ENUM="false" PREVIOUS="doctype" NEXT="title"/>
+ <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="itemtype" NEXT="url"/>
+ <FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="title" NEXT="docdate"/>
+ <FIELD NAME="docdate" TYPE="datetime" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="url" NEXT="updated"/>
+ <FIELD NAME="updated" TYPE="datetime" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="docdate" NEXT="courseid"/>
+ <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="updated" NEXT="groupid"/>
+ <FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="mdl_search_docid" UNIQUE="false" FIELDS="docid" NEXT="mdl_search_doctype"/>
+ <INDEX NAME="mdl_search_doctype" UNIQUE="false" FIELDS="doctype" PREVIOUS="mdl_search_docid" NEXT="mdl_search_itemtype"/>
+ <INDEX NAME="mdl_search_itemtype" UNIQUE="false" FIELDS="itemtype" PREVIOUS="mdl_search_doctype"/>
+ </INDEXES>
+ </TABLE>
+ </TABLES>
+</XMLDB>
View
@@ -1,24 +0,0 @@
-<?php
-
-// THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
-//
-// IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
-// LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
-//
-// This file is tailored to MySQL
-
-function search_upgrade($oldversion=0) {
-
- global $CFG;
-
- $result = true;
-
- if ($oldversion < 2006062500 and $result) {
- $result = true; //Nothing to do
- }
-
- ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
-
- //Finally, return result
- return $result;
-}
@@ -1,24 +0,0 @@
-<?php
-
-// THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
-//
-// IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
-// LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
-//
-// This file is tailored to pgsql
-
-function search_upgrade($oldversion=0) {
-
- global $CFG;
-
- $result = true;
-
- if ($oldversion < 2006062500 and $result) {
- $result = true; //Nothing to do
- }
-
- ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
-
- //Finally, return result
- return $result;
-}
@@ -31,6 +31,81 @@ function xmldb_block_search_upgrade($oldversion=0) {
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
+ if ($result && $oldversion < 2007071302) {
+
+ /// Define table search_documents to be created
+ $table = new XMLDBTable('search_documents');
+
+ /// Drop it if it existed before
+
+ drop_table($table, true, false);
+
+ /// Adding fields to table search_documents
+ $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
+ $table->addFieldInfo('docid', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, null);
+ $table->addFieldInfo('doctype', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, 'none');
+ $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, 'standard');
+ $table->addFieldInfo('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
+ $table->addFieldInfo('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null);
+ $table->addFieldInfo('docdate', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null, null);
+ $table->addFieldInfo('updated', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL, null, null, null);
+ $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+ $table->addFieldInfo('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
+
+ /// Adding keys to table search_documents
+ $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
+
+ /// Adding indexes to table search_documents
+ $table->addIndexInfo('mdl_search_docid', XMLDB_INDEX_NOTUNIQUE, array('docid'));
+ $table->addIndexInfo('mdl_search_doctype', XMLDB_INDEX_NOTUNIQUE, array('doctype'));
+ $table->addIndexInfo('mdl_search_itemtype', XMLDB_INDEX_NOTUNIQUE, array('itemtype'));
+
+ /// Launch create table for search_documents
+ $result = $result && create_table($table);
+ }
+
+/// Rename table search_documents to block_search_documents and
+/// fix some defaults (MDL-10572)
+ if ($result && $oldversion < 2007081100) {
+
+ /// Define table search_documents to be renamed to block_search_documents
+ $table = new XMLDBTable('search_documents');
+
+ /// Launch rename table for block_search_documents
+ $result = $result && rename_table($table, 'block_search_documents');
+
+ /// Changing the default of field doctype on table block_search_documents to none
+ $table = new XMLDBTable('block_search_documents');
+ $field = new XMLDBField('doctype');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, 'none', 'docid');
+
+ /// Launch change of default for field doctype
+ $result = $result && change_field_default($table, $field);
+
+ /// Changing the default of field itemtype on table block_search_documents to standard
+ $table = new XMLDBTable('block_search_documents');
+ $field = new XMLDBField('itemtype');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '32', null, XMLDB_NOTNULL, null, null, null, 'standard', 'doctype');
+
+ /// Launch change of default for field itemtype
+ $result = $result && change_field_default($table, $field);
+
+ /// Changing the default of field title on table block_search_documents to drop it
+ $table = new XMLDBTable('block_search_documents');
+ $field = new XMLDBField('title');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'itemtype');
+
+ /// Launch change of default for field title
+ $result = $result && change_field_default($table, $field);
+
+ /// Changing the default of field url on table block_search_documents to drop it
+ $table = new XMLDBTable('block_search_documents');
+ $field = new XMLDBField('url');
+ $field->setAttributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'title');
+
+ /// Launch change of default for field url
+ $result = $result && change_field_default($table, $field);
+ }
return $result;
}

0 comments on commit 603042b

Please sign in to comment.