コード例 #1
0
ファイル: class.page.php プロジェクト: hungnv0789/vhtm
		/**
		*	Load up an RSS feed, parse its contents and return it.
		*/
		public function _LoadFeed($FeedURL, $NumEntries=0, $CacheTime=0, $FeedId="", $RSSFeedSnippet="", $helpLinks = false)
		{
			$reload = true;
			if($CacheTime > 0) {
				if($FeedId != "") {
					$FeedID = md5($FeedURL);
				}
				$reload = false;
				if(!is_dir(ISC_BASE_PATH."/cache/feeds")) {
					isc_mkdir(ISC_BASE_PATH."/cache/feeds/");
				}
				// Using a cached version that hasn't expired yet
				if(file_exists(ISC_BASE_PATH."/cache/feeds/".$FeedId) && filemtime(ISC_BASE_PATH."/cache/feeds/".$FeedId) > time()-$CacheTime) {
					$contents = file_get_contents(ISC_BASE_PATH."/cache/feeds/".$FeedId);
					// Cache was bad, recreate
					if(!$contents) {
						$reload = true;
					}
				}
				else {
					$reload = true;
				}
			}

			if ($reload === true) {
				$contents = PostToRemoteFileAndGetResponse($FeedURL);
				// Do we need to cache this version?
				if ($CacheTime > 0 && $contents != "") {
					@file_put_contents(ISC_BASE_PATH."/cache/feeds/".$FeedId, $contents);
				}
			}

			$output = "";
			$count = 0;

			// Could not load the feed, return an error
			if(!$contents) {
				return false;
			}


			// Silence errors to not polute out logs with peoples invalid XML feeds
			if($xml = @simplexml_load_string($contents)) {
				require_once(ISC_BASE_PATH . "/lib/xml.php");

				$rss = new ISC_XML();
				$entries = $rss->ParseRSS($xml);

				foreach($entries as $entry) {
					$GLOBALS['RSSTitle'] = $entry['title'];
					$GLOBALS['RSSDescription'] = $entry['description'];
					$GLOBALS['RSSLink'] = $entry['link'];

					if ($RSSFeedSnippet != "") {
						if ($helpLinks) {
							preg_match('#/questions/([0-9]+)/#si', $entry['link'], $matches);
							if (!empty($matches)) {
								$GLOBALS['RSSLink'] = $matches[1];
							}
						}
						if(defined('ISC_ADMIN_CP')) {
							$output .= Interspire_Template::getInstance('admin')->render('Snippets/'.$RSSFeedSnippet.'.html');
						}
						else {
							$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet($RSSFeedSnippet);
						}
					} else {
						if(defined('ISC_ADMIN_CP')) {
							$output .= Interspire_Template::getInstance('admin')->render('Snippets/PageRSSItem.html');
						}
						else {
							$output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("PageRSSItem");
						}
					}

					if($NumEntries > 0 && ++$count >= $NumEntries) {
						break;
					}
				}

				return $output;
			}
			else {
				return false;
			}
		}
コード例 #2
0
ファイル: class.page.php プロジェクト: nirvana-info/old_bak
 /**
  *	Load up an RSS feed, parse its contents and return it.
  */
 public function _LoadFeed($FeedURL, $NumEntries = 0, $CacheTime = 0, $FeedId = "", $RSSFeedSnippet = "", $helpLinks = false)
 {
     $reload = true;
     if ($CacheTime > 0) {
         if ($FeedId != "") {
             $FeedID = md5($FeedURL);
         }
         $reload = false;
         if (!is_dir(ISC_BASE_PATH . "/cache/feeds")) {
             @mkdir(ISC_BASE_PATH . "/cache/feeds/", 0777);
         }
         // Using a cached version that hasn't expired yet
         if (file_exists(ISC_BASE_PATH . "/cache/feeds/" . $FeedId) && filemtime(ISC_BASE_PATH . "/cache/feeds/" . $FeedId) > time() - $CacheTime) {
             $contents = file_get_contents(ISC_BASE_PATH . "/cache/feeds/" . $FeedId);
             // Cache was bad, recreate
             if (!$contents) {
                 $reload = true;
             }
         } else {
             $reload = true;
         }
     }
     if ($reload === true) {
         $contents = PostToRemoteFileAndGetResponse($FeedURL);
         // Do we need to cache this version?
         if ($CacheTime > 0 && $contents != "") {
             @file_put_contents(ISC_BASE_PATH . "/cache/feeds/" . $FeedId, $contents);
         }
     }
     $output = "";
     $count = 0;
     // Could not load the feed, return an error
     if (!$contents) {
         return false;
     }
     if ($xml = SimpleXML_Load_String($contents)) {
         $rss = new ISC_XML();
         $entries = $rss->ParseRSS($xml);
         foreach ($entries as $entry) {
             $GLOBALS['RSSTitle'] = $entry['title'];
             $GLOBALS['RSSDescription'] = $entry['description'];
             $GLOBALS['RSSLink'] = $entry['link'];
             if ($RSSFeedSnippet != "") {
                 if ($helpLinks) {
                     preg_match('#/questions/([0-9]+)/#si', $entry['link'], $matches);
                     if (!empty($matches)) {
                         $GLOBALS['RSSLink'] = $matches[1];
                     }
                 }
                 $output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet($RSSFeedSnippet);
             } else {
                 $output .= $GLOBALS['ISC_CLASS_TEMPLATE']->GetSnippet("PageRSSItem");
             }
             if ($NumEntries > 0 && ++$count >= $NumEntries) {
                 break;
             }
         }
         return $output;
     } else {
         return false;
     }
 }