summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/classes/Planet.class.php49
-rw-r--r--app/classes/PlanetConfig.php66
-rw-r--r--app/classes/PlanetError.php23
-rw-r--r--app/classes/PlanetFeed.php31
-rw-r--r--app/classes/PlanetItem.php19
5 files changed, 113 insertions, 75 deletions
diff --git a/app/classes/Planet.class.php b/app/classes/Planet.class.php
index f327fd9..4344abc 100644
--- a/app/classes/Planet.class.php
+++ b/app/classes/Planet.class.php
@@ -32,21 +32,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* Planet, main app class
*/
-class Planet{
- var $config;
- var $items;
- var $people;
+class Planet
+{
+ public $config;
+ public $items;
+ public $people;
+ public $errors;
- var $errors;
+ public function __construct($config=null)
+ {
- function Planet($config=null) {
- if ($config == null){
+ if ($config == null) {
$this->config = new PlanetConfig(array());
- }
- else{
+ } else {
$this->config = $config;
}
- $this->items = array();
+
+ $this->items = array();
$this->people = array();
$this->errors = array();
}
@@ -54,10 +56,13 @@ class Planet{
/**
* Getters
*/
- function getItems() {
+ public function getItems()
+ {
return $this->items;
}
- function getPeople() {
+
+ public function getPeople()
+ {
return $this->people;
}
@@ -65,7 +70,8 @@ class Planet{
* Adds a feed to the planet
* @param PlanetFeed feed
*/
- function addPerson(&$feed) {
+ public function addPerson(&$feed)
+ {
$this->people[] = $feed;
}
@@ -73,11 +79,13 @@ class Planet{
* Load people from an OPML
* @return integer Number of people loaded
*/
- function loadOpml($file) {
- if (!is_file($file)){
+ public function loadOpml($file)
+ {
+ if (!is_file($file)) {
$this->errors[] = new PlanetError(3, $file.' is missing.');
return 0;
}
+
$opml = OpmlManager::load($file);
$opml_people = $opml->getPeople();
foreach ($opml_people as $opml_person){
@@ -95,12 +103,14 @@ class Planet{
/**
* Load feeds
*/
- function loadFeeds() {
+ public function loadFeeds()
+ {
foreach ($this->people as $person) {
$person->set_timeout(-1);
$person->init();
$this->items = array_merge($this->items, $person->get_items());
}
+
$this->sort();
}
@@ -108,7 +118,8 @@ class Planet{
* Download
* @var $max_load percentage of feeds to load
*/
- function download($max_load=0.1){
+ public function download($max_load=0.1)
+ {
$max_load_feeds = ceil(count($this->people) * $max_load);
@@ -137,8 +148,8 @@ class Planet{
}
}
- function sort() {
+ public function sort()
+ {
usort($this->items, array('PlanetItem','compare'));
}
}
-?>
diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php
index 2509e00..13e1cc6 100644
--- a/app/classes/PlanetConfig.php
+++ b/app/classes/PlanetConfig.php
@@ -3,73 +3,85 @@
/**
* Planet configuration class
*/
-class PlanetConfig{
- var $conf;
+class PlanetConfig
+{
- function __construct($array){
- $defaultConfig = Array(
- 'url' => 'http://www.example.com/',
- 'name' => '',
- 'items' => 10,
- 'shuffle' => 0,
- 'refresh' => 240,
- 'cache' => 10,
- 'nohtml' => 0,
+ public $conf;
+
+ public function __construct($array)
+ {
+ $defaultConfig = array(
+ 'url' => 'http://www.example.com/',
+ 'name' => '',
+ 'items' => 10,
+ 'shuffle' => 0,
+ 'refresh' => 240,
+ 'cache' => 10,
+ 'nohtml' => 0,
'postmaxlength' => 0,
- 'cachedir' => './cache'
+ 'cachedir' => './cache',
);
- //User config
+ // User config
$this->conf = $array;
- //Complete config with default config
- foreach ($defaultConfig as $key => $value){
- if (!isset($this->conf[$key])){
+ // Complete config with default config
+ foreach ($defaultConfig as $key => $value) {
+ if (!isset($this->conf[$key])) {
$this->conf[$key] = $value;
}
}
}
- function getUrl(){
+ public function getUrl()
+ {
return $this->conf['url'];
}
- function getName(){
+ public function getName(){
return $this->conf['name'];
}
- function setName($name){
+ public function setName($name)
+ {
$this->conf['name'] = $name;
}
- function getCacheTimeout(){
+ public function getCacheTimeout()
+ {
return $this->conf['refresh'];
}
- function getOutputTimeout(){
+ public function getOutputTimeout()
+ {
return $this->conf['cache'];
}
//@TODO: drop this pref
- function getShuffle(){
+ public function getShuffle()
+ {
return $this->conf['shuffle'];
}
- function getMaxDisplay(){
+ public function getMaxDisplay()
+ {
return $this->conf['items'];
}
//@TODO: drop this pref
- function getNoHTML(){
+ public function getNoHTML()
+ {
return $this->conf['nohtml'];
}
//@TODO: drop this pref
- function getPostMaxLength(){
+ public function getPostMaxLength()
+ {
return $this->conf['postmaxlength'];
}
- function toYaml(){
+ public function toYaml()
+ {
return Spyc::YAMLDump($this->conf,4);
}
-} \ No newline at end of file
+}
diff --git a/app/classes/PlanetError.php b/app/classes/PlanetError.php
index 503fe57..31923a3 100644
--- a/app/classes/PlanetError.php
+++ b/app/classes/PlanetError.php
@@ -1,20 +1,23 @@
-<?php
+<?php
-class PlanetError {
- var $level;
- var $message;
+class PlanetError
+{
+ public $level;
+ public $message;
- function __construct($level, $message) {
+ public function __construct($level, $message)
+ {
$this->level = (int) $level;
$this->message = $message;
}
- function toString($format = '%1$s : %2$s') {
+ public function toString($format = '%1$s : %2$s')
+ {
$levels = array(
- 1 => "notice",
- 2 => "warning",
- 3 => "error"
+ 1 => 'notice',
+ 2 => 'warning',
+ 3 => 'error',
);
return sprintf($format, $levels[$this->level], $this->message);
}
-} \ No newline at end of file
+}
diff --git a/app/classes/PlanetFeed.php b/app/classes/PlanetFeed.php
index f91cf20..a6c7aab 100644
--- a/app/classes/PlanetFeed.php
+++ b/app/classes/PlanetFeed.php
@@ -3,14 +3,17 @@
/**
* Planet person
*/
-class PlanetFeed extends SimplePie{
- var $name;
- var $feed;
- var $website;
- function __construct($name, $feed, $website){
- $this->name = $name;
- $this->feed = $feed;
+class PlanetFeed extends SimplePie
+{
+ public $name;
+ public $feed;
+ public $website;
+
+ public function __construct($name, $feed, $website)
+ {
+ $this->name = $name;
+ $this->feed = $feed;
$this->website = $website;
parent::__construct();
$this->set_item_class('PlanetItem');
@@ -21,19 +24,23 @@ class PlanetFeed extends SimplePie{
$this->set_stupidly_fast(true);
}
- function getFeed(){
+ public function getFeed()
+ {
return $this->feed;
}
- function getName(){
+ public function getName()
+ {
return $this->name;
}
- function getWebsite(){
+ public function getWebsite()
+ {
return $this->website;
}
- function compare($person1, $person2){
+ public function compare($person1, $person2)
+ {
return strcasecmp($person1->name, $person2->name);
}
-} \ No newline at end of file
+}
diff --git a/app/classes/PlanetItem.php b/app/classes/PlanetItem.php
index b3f1fb9..039d0ca 100644
--- a/app/classes/PlanetItem.php
+++ b/app/classes/PlanetItem.php
@@ -3,20 +3,25 @@
/**
* Planet item
*/
-class PlanetItem{
- function __construct($feed, $data){
+
+class PlanetItem
+{
+ public function __construct($feed, $data)
+ {
parent::SimplePie_Item($feed, $data);
}
- function compare($item1, $item2){
+ public function compare($item1, $item2)
+ {
$item1_date = $item1->get_date('U');
$item2_date = $item2->get_date('U');
- if ($item1_date == $item2_date){
+
+ if ($item1_date == $item2_date) {
return 0;
- }
- else if ($item1_date < $item2_date){
+ } elseif ($item1_date < $item2_date) {
return 1;
}
+
return -1;
}
-} \ No newline at end of file
+}