function search(&$fromform, &$result) { global $CFG, $USER; $terms = array('keyword', 'title', 'description'); // Initialize with the target URL $search = trim($fromform->search); $lang = strtolower(preg_replace('/\\_\\w+$/', '', $USER->lang)); foreach ($terms as $term) { $search = preg_replace('/' . $term . ':\\s*/', $term . '_' . $lang . ':', $search); } $url = 'http://localhost:7574/solr/select?q=' . $search . '&wt=php'; // is this a complete browse request? if ($fromform->search == '*') { $url = 'http://localhost:7574/solr/select?q=' . urlencode('keyword_' . $lang . ':[0 TO zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz]') . '&wt=php'; } $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, TAORESOURCE_PLUGIN_CURL_TIMEOUT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Moodle'); $code = curl_exec($ch); if ($code === false) { $this->error[] = curl_errno($ch) . ':' . curl_error($ch); return false; } curl_close($ch); $qr = false; if ($code) { $code = "\$qr = " . $code . ";"; eval($code); } if ($qr && isset($qr['response']) && $qr['response']['numFound'] > 0) { $docs = $qr['response']['docs']; foreach ($docs as $doc) { if ($taoresource_entry = taoresource_entry::get_by_id((int) $doc['entry'])) { $result[] = $taoresource_entry; } } } return false; }
/** * Hydrate a taoresource_entry object reading by identifier * * @param identifier hash, sha1 hash identifier * @return taoresource_entry object */ static function get_by_identifier($identifier) { return $taoresource_entry = taoresource_entry::read($identifier); }
/** * * @author Piers Harding piers@catalyst.net.nz * @version 0.0.1 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License, mod/taoresource is a work derived from Moodle mod/resoruce * @package taoresource * */ require '../../../../config.php'; require_once "../../lib.php"; if ($entries = get_records("taoresource_entry")) { print "<?xml version='1.0'?>\n"; print "<add>\n"; foreach ($entries as $e) { $entry = new taoresource_entry($e); $issuedate = '0000-00-00T00:00:00.000Z'; if ($entry->element('IssueDate')) { // $issuedate = date("Y-m-d\TH:i:s.000\Z", $entry->element('IssueDate')); $issuedate = $entry->element('IssueDate'); } print " <doc>\n"; print ' <field name="catalogentry">' . $entry->identifier . '</field>' . "\n"; print ' <field name="catalog">' . $entry->remoteid . '</field>' . "\n"; print ' <field name="entry">' . $entry->id . '</field>' . "\n"; print ' <field name="title_en">' . preg_replace('/\\>/', '>', preg_replace('/\\</', '<', preg_replace('/\\&/', '&', $entry->title))) . '</field>' . "\n"; print ' <field name="language">' . $entry->lang . '</field>' . "\n"; print ' <field name="description_en">' . preg_replace('/\\>/', '>', preg_replace('/\\</', '<', preg_replace('/\\&/', '&', $entry->description))) . '</field>' . "\n"; print ' <field name="keyword_en">' . $entry->keywords . '</field>' . "\n"; print ' <field name="contributor">' . ($entry->element('Contributor') || '') . '</field>' . "\n"; print ' <field name="issuedate">' . $issuedate . '</field>' . "\n";
$file = $o[1]; break; } } } $elements = array("title_{$lang}" => 'title', 'catalogentry' => 'identifier', 'catalog' => 'remoteid', 'language' => 'lang', "description_{$lang}" => 'description', "keyword_{$lang}" => 'keywords', 'contributor' => 'Contributor', 'issuedate' => 'IssueDate', 'agefrom' => 'AgeFrom', 'ageto' => 'AgeTo', 'format' => 'mimetype', 'location' => 'url', 'file' => 'file', 'learningresourcetype' => 'LearningResourceType', 'rights' => 'Rights', 'rightsdescription' => 'RightsDescription', 'classificationpurpose' => 'ClassificationPurpose', 'classificationtaxonpath' => 'ClassificationTaxonPath'); $xml = simplexml_load_file($file); if ($result = $xml->xpath("doc")) { foreach ($result as $doc) { // check if the entry exists $exists = false; if ($el = $doc->xpath("field[@name='catalogentry']/text()")) { $identifier = $el[0]; } if (!($entry = taoresource_entry::get_by_identifier($identifier))) { $entry = new taoresource_entry(); } else { $entry->metadata_elements = array(); $exists = true; } $entry->add_element('type', 'file'); foreach ($elements as $key => $element) { if ($el = $doc->xpath("field[@name='{$key}']/text()")) { $entry->add_element($element, $el[0]); } } if ($exists) { $entry->update_instance(); } else { $entry->add_instance(); }
function taoresource_restore_mods_one_index($tredata) { // restore the entry $taoresource_entry = new object(); $taoresource_entry->id = $tredata['#']['ID']['0']['#']; $taoresource_entry->title = $tredata['#']['TITLE']['0']['#']; $taoresource_entry->type = $tredata['#']['TYPE']['0']['#']; $taoresource_entry->mimetype = $tredata['#']['MIMETYPE']['0']['#']; $taoresource_entry->identifier = $tredata['#']['IDENTIFIER']['0']['#']; $taoresource_entry->remoteid = $tredata['#']['REMOTEID']['0']['#']; if ($taoresource_entry->remoteid == '$@NULL@$') { $taoresource_entry->remoteid = ''; } $taoresource_entry->file = $tredata['#']['FILE']['0']['#']; $taoresource_entry->url = $tredata['#']['URL']['0']['#']; $taoresource_entry->lang = $tredata['#']['LANG']['0']['#']; $taoresource_entry->description = $tredata['#']['DESCRIPTION']['0']['#']; $taoresource_entry->keywords = $tredata['#']['KEYWORDS']['0']['#']; $taoresource_entry->timemodified = $tredata['#']['TIMEMODIFIED']['0']['#']; $taoresource_entry = new taoresource_entry($taoresource_entry); // restore the metadata $metadata = $tredata['#']['METADATA']['0']['#']['ELEMENT']; foreach ($metadata as $element) { $entryid = $element['#']['ENTRY_ID']['0']['#']; $el = $element['#']['ELEMENT']['0']['#']; $namespace = $element['#']['NAMESPACE']['0']['#']; $value = $element['#']['VALUE']['0']['#']; $taoresource_entry->add_element($el, $value, $namespace); } $taoresource_entry->add_instance(); }
/** * This constructs the course module information the gets used * in the course module list. */ function taoresource_get_coursemodule_info($coursemodule) { /// Given a course_module object, this function returns any /// "extra" information that may be needed when printing /// this activity in a course listing. /// /// See get_array_of_activities() in course/lib.php /// global $CFG; $info = NULL; if ($taoresource = get_record("taoresource", "id", $coursemodule->instance, '', '', '', '', 'id, popup, identifier, type, name')) { $taoresource_entry = taoresource_entry::read($taoresource->identifier); $info = new object(); $info->name = $taoresource->name; if (!empty($taoresource->popup)) { $info->extra = urlencode("onclick=\"this.target='taoresource{$taoresource->id}'; return " . "openpopup('/mod/taoresource/view.php?inpopup=true&id=" . $coursemodule->id . "','taoresource{$taoresource->id}','{$taoresource->popup}');\""); } require_once $CFG->libdir . '/filelib.php'; if ($taoresource->type == 'file') { if (!$taoresource_entry) { $icon = 'unknown.gif'; } else { $icon = mimeinfo("icon", $taoresource_entry->url); } if ($icon != 'unknown.gif') { $info->icon = "f/{$icon}"; } else { $info->icon = "f/web.gif"; } } else { if ($taoresource->type == 'directory') { $info->icon = "f/folder.gif"; } } } return $info; }
$type = optional_param('type', '', PARAM_ALPHANUM); $section = optional_param('section', 0, PARAM_INT); $mode = required_param('mode', PARAM_ALPHA); $course = required_param('course', PARAM_INT); $pagestep = optional_param('pagestep', 1, PARAM_INT); if (!($course = get_record("course", "id", $course))) { error("This course doesn't exist"); } require_login($course); $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); $pagetitle = strip_tags($course->shortname); // sort out how we should look depending on add or update if ($mode == 'update') { $entry_id = required_param('entry_id', PARAM_INT); $taoresource_entry = taoresource_entry::get_by_id($entry_id); $strpreview = get_string('preview', 'taoresource'); $taoresource_entry->url_display = "<a href=\"{$CFG->wwwroot}/mod/taoresource/view.php?identifier={$taoresource_entry->identifier}&inpopup=true\" " . "onclick=\"this.target='resource{$taoresource_entry->id}'; return openpopup('/mod/taoresource/view.php?inpopup=true&identifier={$taoresource_entry->identifier}', " . "'resource{$taoresource_entry->id}','resizable=1,scrollbars=1,directories=1,location=0,menubar=0,toolbar=0,status=1,width=800,height=600');\">(" . $strpreview . ")</a>"; $taoresource_entry->taoresourcefile = $taoresource_entry->file; } else { $mode = 'add'; $taoresource_entry = new taoresource_entry(); } // which form phase are we in - step 1 or step 2 $mform = false; if ($pagestep == 1) { $mform = new mod_taoresource_taoresource_entry_form($mode); $mform->set_data($taoresource_entry); } else { $mform = new mod_taoresource_taoresource_entry_extra_form($mode); $mform->set_data($taoresource_entry);
} } } $mform->set_data($fromform); $mform->display(); $fromform->search = isset($fromform->search) ? clean_param($fromform->search, PARAM_CLEAN) : clean_param(optional_param('search', '', PARAM_RAW), PARAM_CLEAN); $fromform->section = $section; $resources = array(); // if we have an id then we must have come here from the add page if (!empty($fromform->id)) { $resources[] = taoresource_entry::get_by_id($fromform->id); } else { if ($id) { $resources[] = taoresource_entry::get_by_id($id); } else { $resources = taoresource_entry::search($fromform); } } //output results in same format as ims finder.php if ($resources) { $totalcount = count($resources); $baseurl = $CFG->wwwroot . "/mod/taoresource/search.php?course={$course->id}§ion={$section}&type={$type}&add=taoresource&return={$return}&"; // serialise the search query and append to the paging URI $search_parameters = ''; foreach ($fromform as $fld => $val) { if (!in_array($fld, $exclude_inputs)) { if ($val === true) { $val = 'true'; } else { if ($val === false) { $val = 'false';
/** * TODO document */ function setup_elements(&$mform) { global $CFG, $USER, $TAORESOURCE_WINDOW_OPTIONS; $taoresource_entry; $add = optional_param('add', 0, PARAM_ALPHA); $update = optional_param('update', 0, PARAM_INT); $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true $type = optional_param('type', '', PARAM_ALPHANUM); $section = optional_param('section', PARAM_INT); $course = optional_param('course', PARAM_INT); if (!empty($add)) { $entry_id = optional_param('entry_id', false, PARAM_INT); // Have we selected a resource yet ? if (empty($entry_id)) { redirect($CFG->wwwroot . "/mod/taoresource/search.php?course={$course}§ion={$section}&type={$type}&add={$add}&return={$return}"); } else { if (!($taoresource_entry = taoresource_entry::read_by_id($entry_id))) { error('Invalid taoresource_entry::id supplied: ' . $entry_id); } } } else { if (!empty($update)) { if (!($cm = get_coursemodule_from_id('taoresource', $update))) { error('Course Module ID was incorrect'); } if (!($resource = get_record('taoresource', 'id', $cm->instance))) { error('Resource ID was incorrect'); } if (!($taoresource_entry = taoresource_entry::read($resource->identifier))) { error('Invalid taoresource_entry::identifier supplied: ' . $resource->identifier); } } } $this->set_parameters(); // set the parameter array for the form $mform->addElement('hidden', 'entry_id', $taoresource_entry->id); $mform->addElement('hidden', 'identifier', $taoresource_entry->identifier); $mform->setDefault('name', stripslashes_safe($taoresource_entry->title)); $mform->setDefault('description', stripslashes_safe($taoresource_entry->description)); $location = $mform->addElement('static', 'origtitle', get_string('title', 'taoresource') . ': ', stripslashes_safe($taoresource_entry->title)); $strpreview = get_string('preview', 'taoresource'); $link = "<a href=\"{$CFG->wwwroot}/mod/taoresource/view.php?identifier={$taoresource_entry->identifier}&inpopup=true\" " . "onclick=\"this.target='resource{$taoresource_entry->id}'; return openpopup('/mod/taoresource/view.php?inpopup=true&identifier={$taoresource_entry->identifier}', " . "'resource{$taoresource_entry->id}','resizable=1,scrollbars=1,directories=1,location=0,menubar=0,toolbar=0,status=1,width=800,height=600');\">(" . $strpreview . ")</a>"; $location = $mform->addElement('static', 'url', get_string('location', 'taoresource') . ': ', $link); $searchbutton = $mform->addElement('submit', 'searchtaoresource', get_string('searchtaoresource', 'taoresource')); $buttonattributes = array('title' => get_string('searchtaoresource', 'taoresource'), 'onclick' => " window.location.href ='" . $CFG->wwwroot . "/mod/taoresource/search.php?course={$this->course->id}§ion={$section}&type={$type}&add={$add}&return={$return}" . "'; return false;"); $searchbutton->updateAttributes($buttonattributes); $mform->addElement('header', 'displaysettings', get_string('display', 'resource')); $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource')); $mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource')); $mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1); $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource')); $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions); $mform->setDefault('windowpopup', empty($CFG->taoresource_popup) ? 1 : 0); $mform->disabledIf('windowpopup', 'forcedownload', 'checked'); $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource')); $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource')); $mform->setDefault('framepage', 0); $mform->disabledIf('framepage', 'windowpopup', 'eq', 1); $mform->disabledIf('framepage', 'forcedownload', 'checked'); $mform->setAdvanced('framepage'); foreach ($TAORESOURCE_WINDOW_OPTIONS as $option) { if ($option == 'height' or $option == 'width') { $mform->addElement('text', $option, get_string('new' . $option, 'resource'), array('size' => '4')); $mform->setDefault($option, $CFG->{'taoresource_popup' . $option}); $mform->disabledIf($option, 'windowpopup', 'eq', 0); } else { $mform->addElement('checkbox', $option, get_string('new' . $option, 'resource')); $mform->setDefault($option, $CFG->{'taoresource_popup' . $option}); $mform->disabledIf($option, 'windowpopup', 'eq', 0); } $mform->setAdvanced($option); } $mform->addElement('header', 'parameters', get_string('parameters', 'resource')); $options = array(); $options['-'] = get_string('chooseparameter', 'resource') . '...'; $optgroup = ''; foreach ($this->parameters as $pname => $param) { if ($param['value'] == '/optgroup') { $optgroup = ''; continue; } if ($param['value'] == 'optgroup') { $optgroup = $param['langstr']; continue; } $options[$pname] = $optgroup . ' - ' . $param['langstr']; } for ($i = 0; $i < $this->maxparameters; $i++) { $parametername = "parameter{$i}"; $parsename = "parse{$i}"; $group = array(); $group[] =& $mform->createElement('text', $parsename, '', array('size' => '12')); //TODO: accessiblity $group[] =& $mform->createElement('select', $parametername, '', $options); //TODO: accessiblity $mform->addGroup($group, 'pargroup' . $i, get_string('variablename', 'resource') . '=' . get_string('parameter', 'resource'), ' ', false); $mform->setAdvanced('pargroup' . $i); $mform->setDefault($parametername, '-'); } }