forked from sedici/wp-dspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDspace.php
More file actions
executable file
·340 lines (321 loc) · 14.7 KB
/
Dspace.php
File metadata and controls
executable file
·340 lines (321 loc) · 14.7 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
/**
* Plugin Name: Dspace-Plugin
* Plugin URI: http://sedici.unlp.edu.ar/
* Description: This plugin connects the repository SEDICI in wordpress, with the purpose of showing the publications of authors or institutions
* Version: 1.0
* Author: SEDICI - Paula Salamone Lacunza
* Author URI: http://sedici.unlp.edu.ar/
* Copyright (c) 2015 SEDICI UNLP, http://sedici.unlp.edu.ar
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*/
?>
<?php
require_once 'Shortcode.php';
require_once 'Dspace-config.php';
require_once 'configuration/config.php';
require_once 'util/WidgetFilter.php';
require_once 'util/WidgetValidation.php';
require_once 'util/Query.php';
require_once 'util/XmlOrder.php';
require_once 'view/ShowShortcode.php';
require_once 'model/SimplepieModel.php';
require_once 'configuration/Configuration.php';
foreach ( glob ( "configuration/*_config.php" ) as $app ) {
require_once $app;
}
function dspace_styles() {
//include the style
wp_register_style ( 'Dspace', plugins_url ( 'media/css/styles.css', __FILE__ ));
wp_enqueue_style ( 'Dspace' );
}
function dspace_scripts_method() {
// include js archives
wp_enqueue_script ( 'jquery' );
wp_register_script ( 'Dspace', plugins_url ( 'media/js/scrips.js', __FILE__ ), array ("jquery"), null, true );
wp_enqueue_script ( 'Dspace' );
}
class Dspace extends WP_Widget {
protected $filter;
protected $util;
protected $validation;
protected $showShortcode;
protected $configuration;
function Dspace() {
$this->filter = new WidgetFilter();
$this->util = new Query();
$this->validation = new WidgetValidation();
$this->showShortcode = new ShowShortcode();
$option = array ('description' => 'This plugin connects the repository SEDICI in wordpress');
parent::WP_Widget ( 'Dspace', 'Dspace Plugin', $option );
}
function widget($args, $instance) {
extract ( $args );
$handle = apply_filters ( 'handle', $instance ['handle'] );
$author = apply_filters ( 'author', $instance ['author'] );
$keywords = apply_filters ( 'keywords', $instance ['keywords'] );
if($this->validation->labelValidation($author,$handle,$keywords)){
$config = $instance ['config'];
$this->configuration = $this->validation->create_configuration($config);
$description = ('on' == $instance ['description']);
$description = $this->configuration->is_description($description);
$description = $this->validation->description($description, $instance ['summary']);
$maxlenght = $this->validation->limit_text($instance ['limit'],$instance ['maxlenght']);
$share = ('on' == $instance ['share']);
$show_author = ('on' == $instance ['show_author']); // $show_author: if ON, then $show_author = true
$date = ('on' == $instance ['date']); // $date: if checkbox date is ON, $date=true
$max_results = apply_filters ( 'max_results', $instance ['max_results'] ); //$max_results: total results of subtype
$cache = apply_filters ( 'cache', $instance ['cache'] ); //$cache: duration in seconds of cache
$show_subtypes = ('on' == $instance ['show_subtype']); //$show_subtypes: if checkbox show_subtype is ON, $show_subtypes=true
$show_subtypes= $this->configuration->is_label_true($show_subtypes);
$all = ('on' == $instance ['all']); //$all: all publications without subtype filter
$all = $this->configuration->instance_all($all);
if ($this->configuration->all_documents()){
$subtypes_selected = $this->filter->selectedSubtypes($instance,$all); //$subtypes: all selected documents subtypes
}
$attributes = $this->util->group_attributes ( $description, $date, $show_author, $maxlenght, $show_subtypes,$share);
$queryStandar = $this->util->standarQuery($handle, $author, $keywords,$max_results, $this->configuration);
$group_subtype = ($instance ['group_subtype'] === 'on');
$group_subtype = $this->configuration->is_label_true( $group_subtype);
$cmp=$this->validation->getOrder($group_subtype,$instance ['group_year']);
$this->util->setCmp($cmp);
$results= $this->util->getPublications($all, $queryStandar, $cache, $subtypes_selected );
echo $this->util->render ($results,$attributes, $cmp, $this->configuration);
}
}
/**
* @see WP_Widget::update
*/
function update($new_instance, $old_instance) {
$subtypes = $this->filter->subtypes();
$instance = $old_instance;
$instance ['config'] = sanitize_text_field ( $new_instance ['config'] );
$instance ['handle'] = sanitize_text_field ( $new_instance ['handle'] );
$instance ['author'] = sanitize_text_field ( $new_instance ['author'] );
$instance ['keywords'] = sanitize_text_field ( $new_instance ['keywords'] );
$instance ['share'] = sanitize_text_field ( $new_instance ['share'] );
$instance ['maxlenght'] = sanitize_text_field ( $new_instance ['maxlenght'] );
$instance ['description'] = sanitize_text_field ( $new_instance ['description'] );
$instance ['summary'] = sanitize_text_field ( $new_instance ['summary'] );
$instance ['date'] = sanitize_text_field ( $new_instance ['date'] );
$instance ['show_author'] = sanitize_text_field ( $new_instance ['show_author'] );
$instance ['max_results'] = sanitize_text_field ( $new_instance ['max_results'] );
$instance ['cache'] = sanitize_text_field ( $new_instance ['cache'] );
$instance ['all'] = sanitize_text_field ( $new_instance ['all'] );
$instance ['limit'] = sanitize_text_field ( $new_instance ['limit'] );
$instance ['group_subtype'] = sanitize_text_field ( $new_instance ['group_subtype'] );
$instance ['group_year'] = sanitize_text_field ( $new_instance ['group_year'] );
$instance ['show_subtype'] = sanitize_text_field ( $new_instance ['show_subtype'] );
foreach ( $subtypes as $s) {
$instance [$s] = sanitize_text_field ( $new_instance [$s] );
}
return $instance;
}
function show_input ($type,$text,$id,$placeholder=""){
?>
<p>
<label for="<?php echo $this->get_field_id($id); ?>"><?php _e($text); ?>
<input class="widefat"
placeholder="<?php echo $placeholder; ?>"
id="<?php echo $this->get_field_id($id); ?>"
name="<?php echo $this->get_field_name($id); ?>" type="text"
value="<?php echo $type; ?>" /></label>
</p>
<?php
}
function show_checkbox($instance,$text,$id){
?>
<input class="checkbox" type="checkbox"
<?php
echo checked($instance, 'on');
?>
id="<?php echo $this->get_field_id($id); ?>"
name="<?php echo $this->get_field_name($id); ?>" <?php ?> />
<label for="<?php echo $this->get_field_id($id); ?>"><?php _e($text); ?></label>
<?php
}
public function show_cache($duration){
if (empty($duration)) { $duration = defaultCache();}
?>
<p>
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Duración de la cache:'); ?>
<select class='widefat'
id="<?php echo $this->get_field_id('cache'); ?>"
name="<?php echo $this->get_field_name('cache'); ?>">
<?php
$one_day= one_day();
$all_days = cache_days();
foreach ($all_days as $day){
?>
<option value=<?php echo $day * $one_day;?>
<?php echo ($duration==($day * $one_day))?'selected':''; ?>>
<?php echo $day;?> <?php _e('días'); ?></option>
<?php } //end foreach?>
</select>
</label>
</p>
<?php
return;
}
public function show_options($instance){
$handle = esc_attr ( $instance ['handle'] );
$author = esc_attr ( $instance ['author'] );
$keywords = esc_attr ( $instance ['keywords'] );
$this->show_input($handle, 'Handle:', 'handle', 'Ejemplo: 10915/25293');
$this->show_input($author, 'Autores:', 'author','Apellidos, Nombres como en SEDICI');
$this->show_input($keywords, 'Palabras claves:', 'keywords','Palabra1; Palabra2; etc');
?>
<p>
<?php $this->show_checkbox($instance['group_year'], 'Agrupar por fecha', 'group_year'); ?>
</p>
<div class="conditional_config"
<?php echo selected($instance['config'], 'conicet') ? 'style="display: none;"' : ''; ?> >
<p>
<?php $this->show_checkbox($instance['group_subtype'], 'Agrupar por subtipos de documentos', 'group_subtype'); ?>
</p>
</div>
<p>
<?php $this->show_checkbox($instance['show_author'], 'Mostrar Autores', 'show_author')?>
</p>
<p>
<?php $this->show_checkbox($instance['share'], 'Compartir', 'share')?>
</p>
<p>
<?php $this->show_checkbox($instance['date'], 'Mostrar Fecha', 'date') ?>
</p>
<div class="conditional_config"
<?php echo selected($instance['config'], 'conicet') ? 'style="display: none;"' : ''; ?>>
<p>
<?php $this->show_checkbox($instance['show_subtype'], 'Mostrar el tipo de documento', 'show_subtype'); ?>
</p>
</div>
<?php
return;
}
public function show_description($instance){
$maxlenght = esc_attr($instance['maxlenght']);
?>
<div class="description-ds">
<p class="description-ds">
<?php $this->show_checkbox($instance['description'], 'Mostrar Resumen', 'description') ?>
</p>
</div>
<div class="conditional_config"
<?php echo selected($instance['config'], 'conicet') ? 'style="display: none;"' : ''; ?>>
<p class="conditionally-description"
<?php echo checked($instance['description'], 'on') === '' ? 'style="display: none;"' : ''; ?>>
<?php $this->show_checkbox($instance['summary'], 'Mostrar Sumario', 'summary') ?>
</p>
</div>
<div class="conditionally-description"
<?php echo checked($instance['description'], 'on') === '' ? 'style="display: none;"' : ''; ?>>
<p class="limit">
<?php $this->show_checkbox($instance['limit'], 'Limitar longitud del texto', 'limit') ?>
</p>
<p class="conditionally-limit"
<?php echo checked($instance['limit'], 'on') === '' ? 'style="display: none;"' : ''; ?>>
<label for="<?php echo $this->get_field_id('maxlenght'); ?>"><?php _e('Longitud del texto en caracteres:'); ?>
<input class="widefat" type="number" onKeyPress="return justNumbers(event);"
min="10"
id="<?php echo $this->get_field_id('maxlenght'); ?>"
name="<?php echo $this->get_field_name('maxlenght'); ?>"
value="<?php echo $maxlenght; ?>" /></label>
</p>
</div>
<?php
return;
}
public function show_totalResults($max_results){ ?>
<p>
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Cantidad de Resultados a mostrar'); ?>
<select class='widefat'
id="<?php echo $this->get_field_id('max_results'); ?>"
name="<?php echo $this->get_field_name('max_results'); ?>" type="text">
<?php
$results = total_results();
foreach ( $results as $result ) {
?>
<option value=<?php echo $result;?>
<?php echo ($max_results==$result)?'selected':''; ?>>
<?php echo $result; ?>
</option>
<?php
}// end for
?>
</select>
</label>
</p>
<?php
return;
}
public function show_subtypes($instance){?>
<div class="conditional_config"
<?php echo selected($instance['config'], 'conicet') ? 'style="display: none;"' : ''; ?>>
<p class="show-filter">
<?php $this->show_checkbox($instance['all'], 'Todas las publicaciones sin filtros', 'all'); ?>
</p>
<hr>
<hr>
<p class="conditionally-filter"
<?php echo checked($instance['all'], 'on') !== '' ? 'style="display: none;"' : ''; ?>>
<?php
$subtypes = $this->filter->subtypes();
foreach ( $subtypes as $subtype ) {
$this->show_checkbox($instance[$subtype], $subtype, $subtype);
?>
<br />
<?php
}//end foreach subtypes
?></p>
</div>
<?php
return;
}
function show_configs($config){
if (empty($config)) { $config = default_repository();}
?>
<div class="config">
<label id="origen" for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Configuración'); ?>
<select autocomplete="off" class='widefat'
id="<?php echo $this->get_field_id('config'); ?>"
name="<?php echo $this->get_field_name('config'); ?>" type="text">
<?php
$directorio = get_configuration_directory();
foreach (glob($directorio."*.ini") as $value) {
$ini_array = parse_ini_file($value);
?>
<option value=<?php echo $ini_array['name'];?>
<?php echo (strcmp($ini_array['name'], $config) == 0)?'selected':''; ?>>
<?php echo $ini_array['name']; ?>
</option>
<?php
}// end for
?>
</select>
</label>
</div>
<?php
return;
}
/**
* @see WP_Widget::form
*/
function form($instance) {
if (empty($instance))
{
$instance = array('all'=>'on');
}
$this->showShortcode->show_shortcode($instance);
$this->show_configs($instance['config']);
$this->show_options($instance);
$this->show_description($instance);
$this->show_cache(esc_attr ( $instance ['cache'] ));
$this->show_totalResults(esc_attr ( $instance ['max_results'] ));
$this->show_subtypes($instance);
}
}//end class
add_action ( 'admin_enqueue_scripts', 'dspace_scripts_method' );
add_action ( 'admin_enqueue_scripts', 'dspace_styles' );
add_action ( 'widgets_init', create_function ( '', 'return register_widget("Dspace");' ) );
add_action( 'admin_menu', 'dspace_config' );
print_r( add_shortcode ( 'get_publications', 'DspaceShortcode' ));