-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-shortcode.php
96 lines (89 loc) · 4.58 KB
/
class-shortcode.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
<?php
namespace Wp_dspace;
/*
function LoadShortcode($atts) {
$shortcode = new Shortcode ();
ob_start();
$shortcode->plugin_sedici ($atts);
$res =ob_get_contents();
ob_clean();
return $res;
}
function DspaceShortcode($atts) {
return LoadShortcode ( $atts );
}*/
require_once 'util/class-shortcodefilter.php';
require_once 'util/class-showshortcodevalidation.php';
class Shortcode {
protected $filter;
protected $validation;
protected $util;
protected $view;
protected $configuration;
public function __construct(){
$this->view = new \Wp_dspace\View\View();
$this->filter = new Util\ShortcodeFilter();
$this->validation = new Util\ShortcodeValidation();
}
/**
* Procesa un shortcode para obtener y mostrar publicaciones obtenidas de algun repositorio.
*
* Este método valida los parámetros del shortcode, configura las opciones del plugin,
* construye la consulta correspondiente y obtiene los resultados.
* Si se encuentran resultados, los renderiza; de lo contrario, muestra un mensaje de error.
*
* @param array $atts Atributos del shortcode proporcionados por el usuario.
* @return void
*/
function plugin_sedici($atts) {
$instance = shortcode_atts ($this->filter->default_shortcode (), $atts );
$handle = $instance ['handle'] ;
$author = $instance ['author'];
$keywords = $instance ['keywords'];
$subject = $instance ['subject'];
$degree = $instance ['degree'];
if ($this->validation->labelValidation($author,$handle,$keywords,$subject)){
$subtypes="";
$config = $instance ['config'];
$this->configuration = $this->validation->create_configuration($config);
$queryMethod = $this->configuration->get_query_method();
if ($queryMethod == "api"){
$this->util = new Util\Query\apiQuery();
}
else{
$this->util = new Util\Query\opensearchQuery();
}
if (!is_null($this->configuration)){
$description = ($instance ['description'] === 'true');
$description = $this->configuration->is_description($description);
$date = ($instance ['date'] === 'true');
$show_author = ($instance ['show_author'] === 'true');
$cache = $instance ['cache'];//default value from filter.php
$max_results = $this->validation->maxResults($instance ['max_results']);
$maxlenght = $this->validation->maxLenght($instance ['max_lenght']);
$all = $instance ['all'];
$all = $this->configuration->instance_all($all);
if ($this->configuration->all_documents()){
$all = $this->filter->selectedSubtypes($instance, $subtypes);
}
$show_videos= ($instance ['show_videos'] === 'true');
$show_subtypes = ($instance ['show_subtype'] === 'true');
$show_subtypes= $this->configuration->is_label_true($show_subtypes);
$share=($instance ['share'] === 'true');
$group_subtype = ($instance ['group_subtype'] === 'true');
$group_subtype = $this->configuration->is_label_true( $group_subtype);
$cmp=$this->validation->getOrder($group_subtype,$instance ['group_date']);
$this->util->setCmp($cmp);
$attributes = $this->util->group_attributes ( $description, $date, $show_author, $maxlenght, $show_subtypes,$share, $show_videos, $max_results);
$queryStandar = $this->util->buildQuery($handle, $author, $keywords, $subject,$degree,$max_results,$this->configuration);
$results= $this->util->getPublications($all, $queryStandar, $cache, $subtypes, $max_results );
if (!empty($results)){
echo $this->view->render ($results,$attributes,$cmp,$this->configuration);
}
else{
echo "<p> <strong>No se encontraron resultados.</strong></p>";
}
}
}
}
}