-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmywikidata.php
145 lines (117 loc) · 4.24 KB
/
mywikidata.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/*
Plugin Name: Buscador de sondas espaciales
Plugin URI: https://www.ua.es/wikidata
Description: Plugin creado en base a "University of Alicante Wikidata Plugin" adaptado para buscar sondas espaciales filtrando por decadas
Version: 1.0
Author: Marcos Checa Pérez
Author URI: https://quieroserseo.com
*/
/**
* Funcion que instancia el Widget
*/
//function mywikidata_create_widget(){
//include_once(plugin_dir_path( __FILE__ ).'/includes/widget.php');
//register_widget('mywikidata_widget');
//}
//add_action('widgets_init', 'mywikidata_create_widget');
require_once 'easyrdf/vendor/autoload.php';
if (!function_exists('write_log')) {
function write_log ( $log ) {
if ( true === WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
}
register_activation_hook(__FILE__,'mywikidata_install');
function mywikidata_install() {
global $wp_version;
If (version_compare($wp_version, "2.9", "<"))
{
deactivate_plugins(basename(__FILE__)); // Deactivate plugin
wp_die("This plugin requires WordPress version 2.9 or higher.");
}
// create page
check_pages_live();
}
add_filter( 'template_include', 'wikidata_page_template');
function wikidata_page_template( $template ) {
if ( is_page( 'sondas-espaciales' ) ) {
$new_template = plugin_dir_path( __FILE__ ) . 'templates/wikidata-page-template.php';
return $new_template;
}
return $template;
}
function check_pages_live(){
if(get_page_by_title( 'sondas-espaciales') == NULL) {
create_pages_fly('sondas-espaciales');
}
}
function create_pages_fly($pageName) {
$createPage = array(
'post_title' => $pageName,
'post_content' => 'Wikidata Search Example',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'post_name' => $pageName
);
// Insert the post into the database
wp_insert_post( $createPage );
}
function my_enqueued_assets() {
wp_enqueue_style('my-css-file', plugin_dir_url(__FILE__) . '/css/style.css', '', time());
}
add_action('wp_enqueue_scripts', 'my_enqueued_assets');
function movement_wikidata_call($decada){
$sparql = new EasyRdf_Sparql_Client('http://query.wikidata.org/sparql');
echo "<h2>Listado de lanzamiento de sondas espaciales en la decada de los ".$decada."</h2>";
$decadaux = $decada+10;
$result = $sparql->query(
'SELECT ?item ?itemLabel ?launchdate ?operator ?operatorLabel (SAMPLE(?image) AS ?image)'.
'WHERE'.
'{'.
'?item wdt:P31 wd:Q26529 .'.
'?item wdt:P619 ?launchdate .'.
'?item wdt:P137 ?operator .'.
'FILTER (?launchdate > "'.$decada.'-01-01T00:00:00+05:30"^^xsd:dateTime && ?launchdate < "'.$decadaux.'-01-01T00:00:00+05:30"^^xsd:dateTime)'.
'SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }'.
'OPTIONAL { ?item wdt:P18 ?image }'.
'}'.
'GROUP BY ?item ?itemLabel ?launchdate ?operator ?operatorLabel'
);
/* $result = $sparql->query(
'SELECT ?barba ?barbaLabel ?imagen WHERE {'.
'SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }'.
'?barba wdt:P180 wd:Q42804.'.
'OPTIONAL { ?barba wdt:P18 ?imagen. }'.
'}'.
'LIMIT '.$numresults
);*/
/*SELECT ?barbaLabel ?imagen WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?barba wdt:P180 wd:Q42804.
OPTIONAL { ?barba wdt:P18 ?imagen. }
}
LIMIT 100*/
echo " <div class='lista'> ";
foreach ($result as $row) {
// echo "Se han econtrado: ";
echo "<div class='display'><header class=''><h3 class=''><a href='".$row->item."'><span>".$row->itemLabel."</span></a></h3></header>";
echo "<p>Lanzado el: ".$row->launchdate."</p>";
echo "<p>Lanzado por: <a href='".$row->operator."'>".$row->operatorLabel."</a></p>";
if(isset($row->image)){
echo "<img src='".$row->image."' class='imgwiki'>";
}
else{
echo "<img max-width='390' max-height='200' src='https://via.placeholder.com/300?text=No-hay-imagen' class=''></header>";
}
echo "</div>";
}
echo "</div> ";
}
?>