Esempio n. 1
0
 /**
  * Load the comments from an xml file
  *
  * @method loadFromXML
  * 
  * @param {string} $file The source file path
  */
 function loadFromXML($file)
 {
     if (!file_exists($file)) {
         $this->comments = array();
         return;
     }
     $xmlstring = @file_get_contents($file);
     if (strpos($xmlstring, "<?xml") !== false) {
         $xml = new imXML();
         $id = 0;
         // Remove the garbage (needed to avoid loosing comments when the xml string is malformed)
         $xmlstring = preg_replace('/<([0-9]+)>.*<\\/\\1>/i', '', $xmlstring);
         $xmlstring = preg_replace('/<comment>\\s*<\\/comment>/i', '', $xmlstring);
         $comments = $xml->parse_string($xmlstring);
         if ($comments !== false && is_array($comments)) {
             $tc = array();
             if (!isset($comments['comment'][0]) || !is_array($comments['comment'][0])) {
                 $comments['comment'] = array($comments['comment']);
             }
             for ($i = 0; $i < count($comments['comment']); $i++) {
                 foreach ($comments['comment'][$i] as $key => $value) {
                     if ($key == "timestamp" && strpos($value, "-") == 2) {
                         // The v8 and v9 timestamp was inverted. For compatibility, let's convert it to the correct format.
                         // The v10 format is yyyy-mm-dd hh:ii:ss
                         // The v8 and v9 format is dd-mm-yyyy hh:ii:ss
                         $value = preg_replace("/([0-9]{2})\\-([0-9]{2})\\-([0-9]{4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2})/", "\$3-\$2-\$1 \$4:\$5:\$6", $value);
                     }
                     $tc[$i][$key] = str_replace(array("\\'", '\\"'), array("'", '"'), htmlspecialchars_decode($value));
                     if ($key == "rating" && is_numeric($value) && intval($value) > 5) {
                         $tc[$i][$key] = "5";
                     }
                 }
                 $tc[$i]['id'] = $id++;
             }
             $this->comments = $tc;
         } else {
             // The comments cannot be retrieved. The XML is jammed.
             // Do a backup copy of the file and then reset the xml.
             // Hashed names ensure that a file is not copied more than once
             $n = $file . "_version_" . md5($xmlstring);
             if (!@file_exists($n)) {
                 @copy($file, $n);
             }
             $this->comments = array();
         }
     } else {
         $this->loadFromOldFile($file);
     }
 }
Esempio n. 2
0
 /**
  * Get an array with the data results from Google
  * @param site The site url
  * @param operation the operation id
  */
 function readServiceData($site, $operation)
 {
     if ($this->auth === FALSE) {
         return FALSE;
     }
     if (strlen($site) > 0) {
         $request = $this->urlencoding($site) . "/" . $operation . "/";
     } else {
         $request = $operation . "/";
     }
     $url = "https://www.google.com/webmasters/tools/feeds/" . $request;
     $curl = curl_init();
     $head = array("Authorization: GoogleLogin auth=" . $this->auth, "GData-Version: 2");
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $head);
     $result = curl_exec($curl);
     $info = curl_getinfo($curl);
     curl_close($curl);
     if ($info['http_code'] != 200) {
         return FALSE;
     }
     $xml = new imXML();
     $xml_output = $xml->parse_string($result);
     return $xml_output;
 }