Beispiel #1
0
 public static function get_items_feed($url, $params)
 {
     $cache_path = self::getPath($url);
     if (!self::need_update($cache_path)) {
         $rows = self::get_cache($cache_path);
         return $rows;
     }
     //		jimport('simplepie.simplepie');
     $feed = new SimplePie();
     $mode = isset($params->mode) ? $params->mode : 0;
     if ($mode == 0) {
         $feed->set_feed_url($url);
     } else {
         $html = ogbFile::get_curl($url);
         $feed->set_raw_data($html);
     }
     $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
     $feed->set_timeout(20);
     $feed->enable_cache(false);
     $feed->set_stupidly_fast(true);
     $feed->enable_order_by_date($params->order_by_date);
     // we don't want to do anything to the feed
     $feed->set_url_replacements(array());
     $result = $feed->init();
     if (isset($_GET['x'])) {
         echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
         echo "<p>URL: [{$url}]</p>";
         echo "<p>Error: [{$feed->error}]</p>";
     }
     $items = $feed->get_items();
     $c_items = count($items);
     if ($c_items == 0) {
         echo "<p>Error: [{$feed->error}]</p>";
         return array();
     }
     for ($i = 0; $i < count($items); $i++) {
         $row = new stdclass();
         $row->title = html_entity_decode($items[$i]->get_title(), ENT_QUOTES, 'UTF-8');
         # the title for the post
         $row->link = $items[$i]->get_link();
         # a single link for the post
         $row->description = $items[$i]->get_description();
         # the content of the post (prefers summaries)
         $row->author = $items[$i]->get_author();
         # a single author for the post
         $row->date = $items[$i]->get_date('Y-m-d H:i:s');
         $row->enclosures = $items[$i]->get_enclosures();
         $rows[] = $row;
     }
     //		var_dump($rows);
     if ($params->order_by_date && $params->order_by_date_follow) {
         $newrows = array();
         if (count(array_filter($rows)) > 0) {
             for ($i = count($rows) - 1; $i >= 0; $i--) {
                 $newrows[] = $rows[$i];
             }
             $rows = $newrows;
         }
     }
     self::update_cache($cache_path, $rows);
     return $rows;
 }
 public static function copyImage($contents = '', $itemLink = '', $params)
 {
     $matches = array();
     $upload_dir = wp_upload_dir();
     preg_match_all("#<img*[^\\>]*>#i", $contents, $matches);
     if (!isset($matches[0][0])) {
         return $contents;
     }
     $searches = $matches[0];
     $local_dir = $params->image_local;
     if (substr($local_dir, 0, 1) == '/') {
         $local_dir = substr($local_dir, 1);
     }
     $upload_path = $upload_dir['basedir'];
     $url_path = $upload_dir['baseurl'] . DS . $local_dir;
     $to = array('host' => str_replace("\\", "/", $url_path), 'path' => $local_dir);
     if (isset($params->origin_url) && $params->origin_url != '') {
         $origin_url = $params->origin_url;
     } else {
         $url_parts = parse_url($itemLink);
         $origin_url = @$url_parts['scheme'] . "://" . @$url_parts['host'];
     }
     $dest_host = isset($to['host']) ? $to['host'] : '';
     $more_path = date('Y-m');
     $dest_path = isset($to['path']) ? $upload_path . DS . $to['path'] . DS . $more_path : '';
     /*if ( ! preg_match( '!^https?://.+!i', $dest_host ) ) {
     			$dest_host = str_replace( "administrator/", "", JURI :: base() ) . $dest_host;
     		}*/
     $dest_parts = parse_url($dest_host);
     $source_urls = array();
     $replaces = $searches;
     $b = explode("'", $searches[0]);
     $repl = isset($b[1]);
     $iMin = array(64, 64);
     if (isset($params->clear_tiny)) {
         $clear_tiny = explode('x', $params->clear_tiny);
         $iMin[0] = (int) $clear_tiny[0];
         if (isset($clear_tiny[1])) {
             $iMin[1] = (int) $clear_tiny[1];
         }
     }
     for ($i = 0; $i < count($searches); $i++) {
         $remove = false;
         $img = $searches[$i];
         if ($repl) {
             $img = str_replace("'", '"', $searches[$i]);
             $contents = str_replace($searches[$i], $img, $contents);
             $searches[$i] = $replaces[$i] = $img;
         }
         preg_match_all('#\\ssrc=\\"*[^\\"]*\\"#', $img, $src);
         $src = preg_replace("#src\\s*=\\s*\"|\"#", "", @$src[0][0]);
         if (!preg_match('!https?://.+!i', $src)) {
             $source_urls[$i] = $origin_url . trim($src);
         } else {
             $source_urls[$i] = $src;
         }
         if (@$params->special_img_url) {
             $source_urls[$i] = self::img_url_encode($source_urls[$i]);
         }
         $info_file = @get_headers(trim($source_urls[$i]), 1);
         if (!$info_file) {
             $curl = self::get_web_page(trim($source_urls[$i]));
             $info_file['Content-Type'] = $curl['content_type'];
             $mime = $info_file['Content-Type'];
         } else {
             $mime = $info_file['Content-Type'];
         }
         if (count($mime) > 1) {
             $mime = implode("/", $mime);
         }
         $temp_arr = explode("/", $mime);
         if (!in_array('image', $temp_arr)) {
             //check is image or not
             continue;
         }
         $filename = substr(md5($source_urls[$i]), -10) . '.' . end($temp_arr);
         $success = false;
         if ($dest_host && $dest_path) {
             $s = $source_urls[$i];
             $d = $dest_path . DS . $filename;
             $success = file_exists($d);
             $unlink = true;
             //$remove		= true;
             // Debug
             if (isset($_GET['i'])) {
                 $img_info = array();
                 echo '<hr /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n";
                 echo '[ url_path ]: ';
                 var_dump($url_path);
                 echo '<br />[ <a href="' . $s . '" target="_blank">source_urls</a> ]: ' . $s;
                 echo '<br />[ <a href="' . $url_path . '/' . $filename . '" target="_blank">dest_path</a> ]: ' . $d;
                 if (isset($_GET['y'])) {
                     echo '<br /><br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n";
                     if ($success) {
                         $success = false;
                         $k = unlink($d);
                         echo 'Unlink: ';
                         var_dump($k);
                     } else {
                         echo 'File not exist';
                     }
                     echo 'dest_path:';
                     var_dump($k);
                 }
             }
             if (!$success) {
                 $aa = ogbFolder::create($dest_path);
                 if ($aa) {
                     $img_c = ogbFile::get_curl(trim($s));
                     $a = ogbFile::write($d, $img_c);
                     //$a = copy($s, $d);
                     if (is_file($d)) {
                         $size = filesize($d);
                         if ($size > 0) {
                             $img_info = getimagesize(trim($source_urls[$i]));
                             $width = isset($img_info[0]) ? $img_info[0] : 0;
                             $height = isset($img_info[1]) ? $img_info[1] : 0;
                             $remove = $iMin[0] > 0 && $width > 0 && $width < $iMin[0];
                             if (!$remove) {
                                 $remove = $iMin[1] > 0 && $height > 0 && $height < $iMin[1];
                             }
                             if (!$remove) {
                                 $success = true;
                                 $unlink = false;
                             }
                         }
                         if ($unlink && !isset($_GET['nodel'])) {
                             unlink($d);
                         }
                     } else {
                         $size = 0;
                     }
                     // Debug
                     if (isset($_GET['i'])) {
                         echo '<br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n";
                         echo 'copy image Success: ';
                         var_dump($a);
                         echo '<br />file image exist: ';
                         var_dump($success);
                         echo '<br />Size: ';
                         var_dump($size);
                         echo '<br />Unlink:';
                         var_dump($unlink);
                         echo '<pre>';
                         print_r($iMin);
                         print_r($img_info);
                         echo '</pre>';
                     }
                 }
             }
         }
         if ($remove) {
             $replaces[$i] = '';
         } else {
             if ($success) {
                 $replace = "src=\"" . ($dest_host . '/' . $more_path . '/' . $filename) . "\"";
             } else {
                 if (!preg_match('!^https?://.+!i', $src)) {
                     // if src is not contain host=>add host to src
                     $source_path = $origin_url . '/' . $src;
                 } else {
                     $source_path = $src;
                 }
                 $replace = "src=\"" . $source_urls[$i] . "\"";
             }
             $replaces[$i] = preg_replace("#src\\s*=\\s*\"*[^\"]*\"#", $replace, $replaces[$i]);
         }
     }
     $contents = str_replace($searches, $replaces, $contents);
     // Debug
     if (isset($_GET['i2'])) {
         echo '<br /><i><b>File:</b>' . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br /> \n";
         echo '$itemLink: ';
         var_dump($itemLink);
         echo '<pre>';
         echo 'searches:';
         print_r($searches);
         echo 'replaces:';
         print_r($replaces);
         echo '</pre>';
         echo '<hr />' . $contents;
         exit;
     }
     return $contents;
 }
Beispiel #3
0
 public static function get_items_feed($url, $params = null)
 {
     $feed = new SimplePie();
     $mode = isset($params->mode) ? $params->mode : 0;
     if ($mode == 0) {
         $feed->set_feed_url($url);
     } else {
         $html = ogbFile::get_curl($url);
         $feed->set_raw_data($html);
     }
     $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
     $feed->set_timeout(20);
     $feed->enable_cache(false);
     $feed->set_stupidly_fast(true);
     $feed->enable_order_by_date(false);
     // we don't want to do anything to the feed
     $feed->set_url_replacements(array());
     $feed->force_feed(true);
     $result = $feed->init();
     if (isset($_GET['x'])) {
         echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n";
         echo "<p>URL: [{$url}]</p>";
         echo "<p>Error: [{$feed->error}]</p>";
     }
     $items = $feed->get_items();
     $c_items = count($items);
     if ($c_items == 0) {
         echo "<p>Error: [{$feed->error}]</p>";
         return array();
     }
     for ($i = 0; $i < count($items); $i++) {
         $row = new stdclass();
         $row->title = $items[$i]->get_title();
         # the title for the post
         $row->link = $items[$i]->get_link();
         # a single link for the post
         $row->description = $items[$i]->get_description();
         # the content of the post (prefers summaries)
         $row->author = $items[$i]->get_author();
         # a single author for the post
         $row->date = $items[$i]->get_date('Y-m-d H:i:s');
         $row->enclosures = $items[$i]->get_enclosures();
         $rows[] = $row;
     }
     return $rows;
 }