Last active
April 7, 2017 21:38
-
-
Save mcanvar/8f47964b7013671c2ec7bfaef2673573 to your computer and use it in GitHub Desktop.
YaSimpleFeed yii extension fixed minor bugs: lines 57 and 87-90.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* FileDoc: | |
* Widget for YaSimpleWidget. | |
* !!! ATTENTION !!! this widget only supports XML format | |
* | |
* Usage: | |
* | |
* 1. Copy ya-simple-feed directory into the extensions directory | |
* | |
* 2. Use the widget in a view specifying | |
* a. the url of the feed to grab and | |
* b. the speed of slideshow (OPTIONAL, default is 5) | |
* c. the direction of feed (OPTIONAL, default is 'left') | |
* | |
* eg. | |
* <?php | |
* $this->widget( | |
* 'ext.ya-simple-feed.YaSimpleFeed', | |
* array( | |
* 'feedUrl'=>'http://yourfeedsite.com/page.xml, | |
* ) | |
* ); | |
* ?> | |
* | |
* PHP version 5.3 | |
* | |
* @category Extensions | |
* @package YaSimpleFeed | |
* @author Biagio Tagliaferro <[email protected]> | |
* | |
*/ | |
//Yii::import('ext.ya-simple-feed.*'); | |
class YaSimpleFeed extends CWidget | |
{ | |
/** | |
* @var string $feedUrl - The url of the feed | |
*/ | |
public $feedUrl; | |
/** | |
* @var int $speed - The spped of the feed | |
*/ | |
public $feedSpeed; | |
/** | |
* @var string $feedDirection - The direction of the feed | |
* (left, right, up, down) | |
*/ | |
public $feedDirection; | |
private function getFeeds() | |
{ | |
$rawFeed = @file_get_contents($this->feedUrl); | |
if ($rawFeed === false) return FALSE; | |
// give an XML object to be iterate | |
$xml = new SimpleXMLElement($rawFeed); | |
// check if 'feedSpeed' is set OR is int | |
if(!isset($this->feedSpeed) || !is_int($this->feedSpeed)) | |
$this->feedSpeed = 5; | |
// check if is a valid direction; else set 'left' as default | |
if( ($this->feedDirection != 'left') && ($this->feedDirection != 'right') && ($this->feedDirection != 'up') && ($this->feedDirection != 'down') ) | |
$this->feedDirection = 'left'; | |
$news = ""; | |
foreach($xml->channel->item as $item) | |
{ | |
$news .= $item->description; | |
$news .= " - "; | |
} | |
$scrolling_news = '<marquee behavior="scroll" direction="'.$this->feedDirection.'" scrollamount="'.$this->feedSpeed.'">'.$news.'</marquee>'; | |
return $scrolling_news; | |
} | |
public function run() | |
{ | |
if($this->checkConnection()) | |
{ | |
$feeds = $this->getFeeds(); | |
if($feeds !== FALSE) | |
echo $feeds; | |
else | |
echo '500 internal server error!'; | |
} | |
} | |
/** check if the pc is connected to internet | |
* @return TRUE if there is a connection | |
*/ | |
private function checkConnection() | |
{ | |
// Initiates a socket connection to www.google.com at port 80 | |
$conn = @fsockopen("www.google.com", 80); | |
if($conn) | |
{ | |
// there is a connection | |
fclose($conn); | |
return TRUE; | |
} | |
return FALSE; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment