| Línea 48... |
Línea 48... |
| 48 |
if (empty($url)) {
|
48 |
if (empty($url)) {
|
| 49 |
$this->api = 'https://commons.wikimedia.org/w/api.php';
|
49 |
$this->api = 'https://commons.wikimedia.org/w/api.php';
|
| 50 |
} else {
|
50 |
} else {
|
| 51 |
$this->api = $url;
|
51 |
$this->api = $url;
|
| 52 |
}
|
52 |
}
|
| 53 |
$this->_param['format'] = 'php';
|
53 |
$this->_param['format'] = 'json';
|
| 54 |
$this->_param['redirects'] = true;
|
54 |
$this->_param['redirects'] = true;
|
| 55 |
$this->_conn = new curl(array('cache'=>true, 'debug'=>false));
|
55 |
$this->_conn = new curl(array('cache'=>true, 'debug'=>false));
|
| 56 |
}
|
56 |
}
|
| 57 |
public function login($user, $pass) {
|
57 |
public function login($user, $pass) {
|
| 58 |
$this->_param['action'] = 'login';
|
58 |
$this->_param['action'] = 'login';
|
| 59 |
$this->_param['lgname'] = $user;
|
59 |
$this->_param['lgname'] = $user;
|
| 60 |
$this->_param['lgpassword'] = $pass;
|
60 |
$this->_param['lgpassword'] = $pass;
|
| 61 |
$content = $this->_conn->post($this->api, $this->_param);
|
61 |
$content = $this->_conn->post($this->api, $this->_param);
|
| 62 |
$result = unserialize($content);
|
62 |
$result = json_decode($content, true);
|
| 63 |
if (!empty($result['result']['sessionid'])) {
|
63 |
if (!empty($result['result']['sessionid'])) {
|
| 64 |
$this->userid = $result['result']['lguserid'];
|
64 |
$this->userid = $result['result']['lguserid'];
|
| 65 |
$this->username = $result['result']['lgusername'];
|
65 |
$this->username = $result['result']['lgusername'];
|
| 66 |
$this->token = $result['result']['lgtoken'];
|
66 |
$this->token = $result['result']['lgtoken'];
|
| 67 |
return true;
|
67 |
return true;
|
| Línea 85... |
Línea 85... |
| 85 |
$this->_param['titles'] = urldecode($titles);
|
85 |
$this->_param['titles'] = urldecode($titles);
|
| 86 |
}
|
86 |
}
|
| 87 |
$this->_param['prop'] = 'imageinfo';
|
87 |
$this->_param['prop'] = 'imageinfo';
|
| 88 |
$this->_param['iiprop'] = 'url';
|
88 |
$this->_param['iiprop'] = 'url';
|
| 89 |
$content = $this->_conn->post($this->api, $this->_param);
|
89 |
$content = $this->_conn->post($this->api, $this->_param);
|
| 90 |
$result = unserialize($content);
|
90 |
$result = json_decode($content, true);
|
| 91 |
foreach ($result['query']['pages'] as $page) {
|
91 |
foreach ($result['query']['pages'] as $page) {
|
| 92 |
if (!empty($page['imageinfo'][0]['url'])) {
|
92 |
if (!empty($page['imageinfo'][0]['url'])) {
|
| 93 |
$image_urls[] = $page['imageinfo'][0]['url'];
|
93 |
$image_urls[] = $page['imageinfo'][0]['url'];
|
| 94 |
}
|
94 |
}
|
| 95 |
}
|
95 |
}
|
| Línea 101... |
Línea 101... |
| 101 |
$this->_param['generator'] = 'images';
|
101 |
$this->_param['generator'] = 'images';
|
| 102 |
$this->_param['titles'] = urldecode($title);
|
102 |
$this->_param['titles'] = urldecode($title);
|
| 103 |
$this->_param['prop'] = 'images|info|imageinfo';
|
103 |
$this->_param['prop'] = 'images|info|imageinfo';
|
| 104 |
$this->_param['iiprop'] = 'url';
|
104 |
$this->_param['iiprop'] = 'url';
|
| 105 |
$content = $this->_conn->post($this->api, $this->_param);
|
105 |
$content = $this->_conn->post($this->api, $this->_param);
|
| 106 |
$result = unserialize($content);
|
106 |
$result = json_decode($content, true);
|
| 107 |
if (!empty($result['query']['pages'])) {
|
107 |
if (!empty($result['query']['pages'])) {
|
| 108 |
foreach ($result['query']['pages'] as $page) {
|
108 |
foreach ($result['query']['pages'] as $page) {
|
| 109 |
$image_urls[$page['title']] = $page['imageinfo'][0]['url'];
|
109 |
$image_urls[$page['title']] = $page['imageinfo'][0]['url'];
|
| 110 |
}
|
110 |
}
|
| 111 |
}
|
111 |
}
|
| Línea 172... |
Línea 172... |
| 172 |
$this->_param += $params;
|
172 |
$this->_param += $params;
|
| 173 |
$this->_param += array('iiurlwidth' => WIKIMEDIA_IMAGE_SIDE_LENGTH,
|
173 |
$this->_param += array('iiurlwidth' => WIKIMEDIA_IMAGE_SIDE_LENGTH,
|
| 174 |
'iiurlheight' => WIKIMEDIA_IMAGE_SIDE_LENGTH);
|
174 |
'iiurlheight' => WIKIMEDIA_IMAGE_SIDE_LENGTH);
|
| 175 |
//didn't work with POST
|
175 |
//didn't work with POST
|
| 176 |
$content = $this->_conn->get($this->api, $this->_param);
|
176 |
$content = $this->_conn->get($this->api, $this->_param);
|
| 177 |
$result = unserialize($content);
|
177 |
$result = json_decode($content, true);
|
| 178 |
if (!empty($result['query']['pages'])) {
|
178 |
if (!empty($result['query']['pages'])) {
|
| 179 |
foreach ($result['query']['pages'] as $page) {
|
179 |
foreach ($result['query']['pages'] as $page) {
|
| 180 |
$title = $page['title'];
|
180 |
$title = $page['title'];
|
| 181 |
$file_type = $page['imageinfo'][0]['mime'];
|
181 |
$file_type = $page['imageinfo'][0]['mime'];
|
| 182 |
$image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/svg+xml');
|
182 |
$image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/svg+xml');
|