Changeset 29629 for extensions
- Timestamp:
- Sep 18, 2014, 4:45:03 PM (10 years ago)
- Location:
- extensions/flickr2piwigo
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/flickr2piwigo/admin/import.php
r27265 r29629 9 9 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) 10 10 { 11 $ page['warnings'][] = l10n('Please fill your API keys on the configuration tab');12 $_GET['action'] = 'error';11 $_SESSION['page_warnings'][] = l10n('Please fill your API keys on the configuration tab'); 12 redirect(FLICKR_ADMIN . '-config'); 13 13 } 14 14 else if (!test_remote_download()) -
extensions/flickr2piwigo/include/phpFlickr/phpFlickr.php
r28824 r29629 92 92 mysqli_query($db, " 93 93 CREATE TABLE IF NOT EXISTS `$table` ( 94 `request` CHAR( 35 ) NOT NULL,95 `response` MEDIUMTEXT NOT NULL,96 `expiration` DATETIME NOT NULL,97 INDEX ( `request`)94 `request` varchar(128) NOT NULL, 95 `response` mediumtext NOT NULL, 96 `expiration` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 97 UNIQUE KEY `request` (`request`) 98 98 ) 99 99 "); 100 100 101 $result = mysqli_query($db, "SELECT COUNT(*) FROM $table"); 102 $result = mysqli_fetch_row($result); 103 if ( $result[0] > $this->max_cache_rows ) { 104 mysqli_query($db, "DELETE FROM $table WHERE expiration < DATE_SUB(NOW(), INTERVAL $cache_expire second)"); 101 $result = mysqli_query($db, "SELECT COUNT(*) 'count' FROM $table"); 102 if( $result ) { 103 $result = mysqli_fetch_assoc($result); 104 } 105 106 if ( $result && $result['count'] > $this->max_cache_rows ) { 107 mysqli_query($db, "DELETE FROM $table WHERE CURRENT_TIMESTAMP > expiration"); 105 108 mysqli_query($db, 'OPTIMIZE TABLE ' . $this->cache_table); 106 109 } … … 133 136 //If there is no cache result, it returns a value of false. If it finds one, 134 137 //it returns the unparsed XML. 138 unset($request['api_sig']); 135 139 foreach ( $request as $key => $value ) { 136 140 if ( empty($value) ) unset($request[$key]); … … 142 146 $this->cache_request = $request; 143 147 if ($this->cache == 'db') { 144 $result = mysqli_query($this->cache_db, "SELECT response FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "' AND DATE_SUB(NOW(), INTERVAL " . (int) $this->cache_expire . " SECOND)< expiration");145 if ( mysqli_num_rows($result) ) {148 $result = mysqli_query($this->cache_db, "SELECT response FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "' AND CURRENT_TIMESTAMP < expiration"); 149 if ( $result && mysqli_num_rows($result) ) { 146 150 $result = mysqli_fetch_assoc($result); 147 return $result['response'];151 return urldecode($result['response']); 148 152 } else { 149 153 return false; … … 175 179 if ($this->cache == 'db') { 176 180 //$this->cache_db->query("DELETE FROM $this->cache_table WHERE request = '$reqhash'"); 177 $result = mysqli_query($this->cache_db, "SELECT COUNT(*) FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "'"); 178 $result = mysqli_fetch_row($result); 179 if ( $result[0] ) { 180 $sql = "UPDATE " . $this->cache_table . " SET response = '" . str_replace("'", "''", $response) . "', expiration = '" . strftime("%Y-%m-%d %H:%M:%S") . "' WHERE request = '" . $reqhash . "'"; 181 mysqli_query($this->cache_db, $sql); 182 } else { 183 $sql = "INSERT INTO " . $this->cache_table . " (request, response, expiration) VALUES ('$reqhash', '" . str_replace("'", "''", $response) . "', '" . strftime("%Y-%m-%d %H:%M:%S") . "')"; 184 mysqli_query($this->cache_db, $sql); 185 } 181 $response = urlencode($response); 182 $sql = 'INSERT INTO '.$this->cache_table.' (request, response, expiration) 183 VALUES (\''.$reqhash.'\', \''.$response.'\', TIMESTAMPADD(SECOND,'.$this->cache_expire.',CURRENT_TIMESTAMP)) 184 ON DUPLICATE KEY UPDATE response=\''.$response.'\', 185 expiration=TIMESTAMPADD(SECOND,'.$this->cache_expire.',CURRENT_TIMESTAMP) '; 186 187 $result = mysqli_query($this->cache_db, $sql); 188 if(!$result) { 189 echo mysqli_error($this->cache_db); 190 } 191 192 return $result; 186 193 } elseif ($this->cache == "fs") { 187 194 $file = $this->cache_dir . "/" . $reqhash . ".cache"; … … 228 235 $data = implode('&', $data); 229 236 230 $fp = @pfsockopen( $matches[1], 80);237 $fp = @pfsockopen('ssl://'.$matches[1], 443); 231 238 if (!$fp) { 232 239 die('Could not connect to the web service'); … … 271 278 272 279 //Process arguments, including method and login data. 273 $args = array_merge(array("method" => $command, "format" => " php_serial", "api_key" => $this->api_key), $args);280 $args = array_merge(array("method" => $command, "format" => "json", "nojsoncallback" => "1", "api_key" => $this->api_key), $args); 274 281 if (!empty($this->token)) { 275 282 $args = array_merge($args, array("auth_token" => $this->token)); … … 280 287 $auth_sig = ""; 281 288 $this->last_request = $args; 282 if (!($this->response = $this->getCached($args)) || $nocache) { 289 $this->response = $this->getCached($args); 290 if (!($this->response) || $nocache) { 283 291 foreach ($args as $key => $data) { 284 292 if ( is_null($data) ) { … … 296 304 } 297 305 306 298 307 /* 299 308 * Uncomment this line (and comment out the next one) if you're doing large queries … … 301 310 * the result, so be sure that you look at the results. 302 311 */ 303 //$this->parsed_response = unserialize($this->response);304 $this->parsed_response = $this->clean_text_nodes(unserialize($this->response)); 312 $this->parsed_response = json_decode($this->response, TRUE); 313 /* $this->parsed_response = $this->clean_text_nodes(json_decode($this->response, TRUE)); */ 305 314 if ($this->parsed_response['stat'] == 'fail') { 306 315 if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}"); … … 1135 1144 1136 1145 /* https://www.flickr.com/services/api/flickr.photos.search.html */ 1137 $ this->request("flickr.photos.search", $args);1138 return $this->parsed_response? $this->parsed_response['photos'] : false;1146 $result = $this->request("flickr.photos.search", $args); 1147 return ($this->parsed_response) ? $this->parsed_response['photos'] : false; 1139 1148 } 1140 1149
Note: See TracChangeset
for help on using the changeset viewer.