This repository has been archived by the owner on Jan 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
125 lines (106 loc) · 3.9 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package repository_arix
* @copyright 2017, ANTARES PROJECT GmbH
* @author Rene Kaufmann <rene@antares.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once dirname(dirname(__FILE__)) . '/arix/arix.php';
class repository_arix extends repository
{
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array())
{
parent::__construct($repositoryid, $context, $options);
}
public static function get_instance_option_names()
{
return array_merge(parent::get_type_option_names(), array('arix_url', 'kontext'));
}
static function instance_config_form($mform)
{
parent::type_config_form($mform);
$arix_url = get_config('repository_arix', 'arix_url');
$mform->addElement('text', 'arix_url', get_string('arix_url', 'repository_arix'), array('size' => '40'));
$mform->setType('arix_url', PARAM_NOTAGS);
$mform->setDefault('arix_url', $arix_url);
$kontext = get_config('repository_arix', 'kontext');
$mform->addElement('text', 'kontext', get_string('kontext', 'repository_arix'), array('size' => '40'));
$mform->setType('kontext', PARAM_NOTAGS);
$mform->setDefault('kontext', $kontext);
}
public function print_login() {
$keyword = new stdClass();
$keyword->label = get_string('keyword', 'repository_wikimedia').': ';
$keyword->id = 'input_text_keyword';
$keyword->type = 'text';
$keyword->name = 'wikimedia_keyword';
$keyword->value = '';
if ($this->options['ajax']) {
$form = array();
$form['login'] = array($keyword);
$form['nologin'] = true;
$form['norefresh'] = true;
$form['nosearch'] = true;
return $form;
}
}
public function check_login() {
$this->keyword = optional_param('wikimedia_keyword', '', PARAM_RAW);
if (empty($this->keyword)) {
$this->keyword = optional_param('s', '', PARAM_RAW);
}
return !empty($this->keyword);
}
public function get_listing($path = '', $page = '')
{
$search_result = array();
$arix_cli = $this->getArixCli();
$search_result['list'] = $arix_cli->search($this->keyword, $this->id);
$search_result['issearchresult'] = true;
$search_result['norefresh'] = true;
$search_result['dynload'] = true;
return $search_result;
}
private function getArixCli()
{
$arix_url = $this->get_option('arix_url');
$kontext = $this->get_option('kontext');
return new ArixClient($arix_url, $kontext);
}
public function get_link($url)
{
return $url;
}
public function search($text, $page = 0)
{
$search_result = array();
$arix_cli = $this->getArixCli();
$search_result['list'] = $arix_cli->search($text, $this->id);
$search_result['issearchresult'] = true;
$search_result['norefresh'] = true;
$search_result['dynload'] = true;
return $search_result;
}
public function global_search()
{
return false;
}
public function supported_returntypes()
{
return FILE_EXTERNAL;
}
}