Changeset 29629 for extensions


Ignore:
Timestamp:
Sep 18, 2014, 4:45:03 PM (10 years ago)
Author:
mistic100
Message:

update phpFlickr

Location:
extensions/flickr2piwigo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/flickr2piwigo/admin/import.php

    r27265 r29629  
    99if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']))
    1010{
    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');
    1313}
    1414else if (!test_remote_download())
  • extensions/flickr2piwigo/include/phpFlickr/phpFlickr.php

    r28824 r29629  
    9292                                        mysqli_query($db, "
    9393                                                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`)
    9898                                                )
    9999                                        ");
    100100
    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");
    105108                                                mysqli_query($db, 'OPTIMIZE TABLE ' . $this->cache_table);
    106109                                        }
     
    133136                        //If there is no cache result, it returns a value of false. If it finds one,
    134137                        //it returns the unparsed XML.
     138                        unset($request['api_sig']);
    135139                        foreach ( $request as $key => $value ) {
    136140                                if ( empty($value) ) unset($request[$key]);
     
    142146                        $this->cache_request = $request;
    143147                        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) ) {
    146150                                        $result = mysqli_fetch_assoc($result);
    147                                         return $result['response'];
     151                                        return urldecode($result['response']);
    148152                                } else {
    149153                                        return false;
     
    175179                        if ($this->cache == 'db') {
    176180                                //$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;
    186193                        } elseif ($this->cache == "fs") {
    187194                                $file = $this->cache_dir . "/" . $reqhash . ".cache";
     
    228235                                $data = implode('&', $data);
    229236
    230                                 $fp = @pfsockopen($matches[1], 80);
     237                                $fp = @pfsockopen('ssl://'.$matches[1], 443);
    231238                                if (!$fp) {
    232239                                        die('Could not connect to the web service');
     
    271278
    272279                        //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);
    274281                        if (!empty($this->token)) {
    275282                                $args = array_merge($args, array("auth_token" => $this->token));
     
    280287                        $auth_sig = "";
    281288                        $this->last_request = $args;
    282                         if (!($this->response = $this->getCached($args)) || $nocache) {
     289                        $this->response = $this->getCached($args);
     290                        if (!($this->response) || $nocache) {
    283291                                foreach ($args as $key => $data) {
    284292                                        if ( is_null($data) ) {
     
    296304                        }
    297305
     306
    298307                        /*
    299308                         * Uncomment this line (and comment out the next one) if you're doing large queries
     
    301310                         * the result, so be sure that you look at the results.
    302311                         */
    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)); */
    305314                        if ($this->parsed_response['stat'] == 'fail') {
    306315                                if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
     
    11351144
    11361145                        /* 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;
    11391148                }
    11401149
Note: See TracChangeset for help on using the changeset viewer.