diff options
author | Maurice Svay <maurice@svay.com> | 2012-03-06 18:16:00 +0100 |
---|---|---|
committer | Maurice Svay <maurice@svay.com> | 2012-03-07 22:18:57 +0100 |
commit | 5d21ae32ac5141cc824946b149f50a461db09597 (patch) | |
tree | 8918d6f9c424f87335d0b5243d1f288f1f7011e4 | |
parent | 95c72062ca5cfed6bea4cd17cb69003d5b651e62 (diff) | |
download | planet-5d21ae32ac5141cc824946b149f50a461db09597.tar planet-5d21ae32ac5141cc824946b149f50a461db09597.tar.gz planet-5d21ae32ac5141cc824946b149f50a461db09597.tar.bz2 planet-5d21ae32ac5141cc824946b149f50a461db09597.tar.xz planet-5d21ae32ac5141cc824946b149f50a461db09597.zip |
One file per class
-rw-r--r-- | app/app.php | 8 | ||||
-rw-r--r-- | app/classes/Planet.class.php | 166 | ||||
-rw-r--r-- | app/classes/PlanetConfig.php | 75 | ||||
-rw-r--r-- | app/classes/PlanetError.php | 20 | ||||
-rw-r--r-- | app/classes/PlanetFeed.php | 39 | ||||
-rw-r--r-- | app/classes/PlanetItem.php | 22 | ||||
-rw-r--r-- | custom/views/archive/sidebar.tpl.php | 2 | ||||
-rw-r--r-- | custom/views/default/sidebar.tpl.php | 2 | ||||
-rw-r--r-- | postload.php | 2 |
9 files changed, 172 insertions, 164 deletions
diff --git a/app/app.php b/app/app.php index cd24c51..1bb632c 100644 --- a/app/app.php +++ b/app/app.php @@ -8,6 +8,14 @@ if ($debug) { error_reporting(0); } +include(dirname(__FILE__).'/lib/lib.opml.php'); +include(dirname(__FILE__).'/lib/simplepie/simplepie.inc'); +include(dirname(__FILE__).'/lib/spyc-0.5/spyc.php'); + +include_once(dirname(__FILE__).'/classes/PlanetConfig.php'); +include_once(dirname(__FILE__).'/classes/PlanetFeed.php'); +include_once(dirname(__FILE__).'/classes/PlanetItem.php'); +include_once(dirname(__FILE__).'/classes/PlanetError.php'); include_once(dirname(__FILE__).'/classes/Planet.class.php'); if (is_file(dirname(__FILE__).'/../custom/config.yml')){ diff --git a/app/classes/Planet.class.php b/app/classes/Planet.class.php index ab741e9..f327fd9 100644 --- a/app/classes/Planet.class.php +++ b/app/classes/Planet.class.php @@ -29,162 +29,6 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-include(dirname(__FILE__).'/../lib/lib.opml.php');
-include(dirname(__FILE__).'/../lib/simplepie/simplepie.inc');
-include(dirname(__FILE__).'/../lib/spyc-0.5/spyc.php');
-
-/**
- * Planet configuration class
- */
-class PlanetConfig{
- var $conf;
-
- 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'
- );
-
- //User config
- $this->conf = $array;
-
- //Complete config with default config
- foreach ($defaultConfig as $key => $value){
- if (!isset($this->conf[$key])){
- $this->conf[$key] = $value;
- }
- }
- }
-
- function getUrl(){
- return $this->conf['url'];
- }
-
- function getName(){
- return $this->conf['name'];
- }
-
- function setName($name){
- $this->conf['name'] = $name;
- }
-
- function getCacheTimeout(){
- return $this->conf['refresh'];
- }
-
- function getOutputTimeout(){
- return $this->conf['cache'];
- }
-
- //@TODO: drop this pref
- function getShuffle(){
- return $this->conf['shuffle'];
- }
-
- function getMaxDisplay(){
- return $this->conf['items'];
- }
-
- //@TODO: drop this pref
- function getNoHTML(){
- return $this->conf['nohtml'];
- }
-
- //@TODO: drop this pref
- function getPostMaxLength(){
- return $this->conf['postmaxlength'];
- }
-
- function toYaml(){
- return Spyc::YAMLDump($this->conf,4);
- }
-}
-
-/**
- * Planet person
- */
-class PlanetPerson extends SimplePie{
- var $name;
- var $feed;
- var $website;
-
- function __construct($name, $feed, $website){
- $this->name = $name;
- $this->feed = $feed;
- $this->website = $website;
- parent::__construct();
- $this->set_item_class('PlanetItem');
- $this->set_cache_location(dirname(__FILE__).'/../../cache');
- $this->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
- $this->set_feed_url($this->getFeed());
- $this->set_timeout(5);
- $this->set_stupidly_fast(true);
- }
-
- function getFeed(){
- return $this->feed;
- }
-
- function getName(){
- return $this->name;
- }
-
- function getWebsite(){
- return $this->website;
- }
-
- function compare($person1, $person2){
- return strcasecmp($person1->name, $person2->name);
- }
-}
-
-/**
- * Planet item
- */
-class PlanetItem{
- function __construct($feed, $data){
- parent::SimplePie_Item($feed, $data);
- }
-
- function compare($item1, $item2){
- $item1_date = $item1->get_date('U');
- $item2_date = $item2->get_date('U');
- if ($item1_date == $item2_date){
- return 0;
- }
- else if ($item1_date < $item2_date){
- return 1;
- }
- return -1;
- }
-}
-
-class PlanetError {
- var $level;
- var $message;
-
- function __construct($level, $message) {
- $this->level = (int) $level;
- $this->message = $message;
- }
-
- function toString($format = '%1$s : %2$s') {
- $levels = array(
- 1 => "notice",
- 2 => "warning",
- 3 => "error"
- );
- return sprintf($format, $levels[$this->level], $this->message);
- }
-}
-
/**
* Planet, main app class
*/
@@ -218,11 +62,11 @@ class Planet{ }
/**
- * Adds a person to the planet
- * @param PlanetPerson person
+ * Adds a feed to the planet
+ * @param PlanetFeed feed
*/
- function addPerson(&$person) {
- $this->people[] = $person;
+ function addPerson(&$feed) {
+ $this->people[] = $feed;
}
/**
@@ -238,7 +82,7 @@ class Planet{ $opml_people = $opml->getPeople();
foreach ($opml_people as $opml_person){
$this->addPerson(
- new PlanetPerson(
+ new PlanetFeed(
$opml_person['name'],
$opml_person['feed'],
$opml_person['website']
diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php new file mode 100644 index 0000000..2509e00 --- /dev/null +++ b/app/classes/PlanetConfig.php @@ -0,0 +1,75 @@ +<?php + +/** + * Planet configuration class + */ +class PlanetConfig{ + var $conf; + + 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' + ); + + //User config + $this->conf = $array; + + //Complete config with default config + foreach ($defaultConfig as $key => $value){ + if (!isset($this->conf[$key])){ + $this->conf[$key] = $value; + } + } + } + + function getUrl(){ + return $this->conf['url']; + } + + function getName(){ + return $this->conf['name']; + } + + function setName($name){ + $this->conf['name'] = $name; + } + + function getCacheTimeout(){ + return $this->conf['refresh']; + } + + function getOutputTimeout(){ + return $this->conf['cache']; + } + + //@TODO: drop this pref + function getShuffle(){ + return $this->conf['shuffle']; + } + + function getMaxDisplay(){ + return $this->conf['items']; + } + + //@TODO: drop this pref + function getNoHTML(){ + return $this->conf['nohtml']; + } + + //@TODO: drop this pref + function getPostMaxLength(){ + return $this->conf['postmaxlength']; + } + + 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 new file mode 100644 index 0000000..503fe57 --- /dev/null +++ b/app/classes/PlanetError.php @@ -0,0 +1,20 @@ +<?php + +class PlanetError { + var $level; + var $message; + + function __construct($level, $message) { + $this->level = (int) $level; + $this->message = $message; + } + + function toString($format = '%1$s : %2$s') { + $levels = array( + 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 new file mode 100644 index 0000000..f91cf20 --- /dev/null +++ b/app/classes/PlanetFeed.php @@ -0,0 +1,39 @@ +<?php + +/** + * Planet person + */ +class PlanetFeed extends SimplePie{ + var $name; + var $feed; + var $website; + + function __construct($name, $feed, $website){ + $this->name = $name; + $this->feed = $feed; + $this->website = $website; + parent::__construct(); + $this->set_item_class('PlanetItem'); + $this->set_cache_location(dirname(__FILE__).'/../../cache'); + $this->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); + $this->set_feed_url($this->getFeed()); + $this->set_timeout(5); + $this->set_stupidly_fast(true); + } + + function getFeed(){ + return $this->feed; + } + + function getName(){ + return $this->name; + } + + function getWebsite(){ + return $this->website; + } + + 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 new file mode 100644 index 0000000..b3f1fb9 --- /dev/null +++ b/app/classes/PlanetItem.php @@ -0,0 +1,22 @@ +<?php + +/** + * Planet item + */ +class PlanetItem{ + function __construct($feed, $data){ + parent::SimplePie_Item($feed, $data); + } + + function compare($item1, $item2){ + $item1_date = $item1->get_date('U'); + $item2_date = $item2->get_date('U'); + if ($item1_date == $item2_date){ + return 0; + } + else if ($item1_date < $item2_date){ + return 1; + } + return -1; + } +}
\ No newline at end of file diff --git a/custom/views/archive/sidebar.tpl.php b/custom/views/archive/sidebar.tpl.php index 32b51a1..fc2c881 100644 --- a/custom/views/archive/sidebar.tpl.php +++ b/custom/views/archive/sidebar.tpl.php @@ -1,6 +1,6 @@ <?php $all_people = &$Planet->getPeople(); -usort($all_people, array('PlanetPerson', 'compare')); +usort($all_people, array('PlanetFeed', 'compare')); ?> <div id="sidebar"> <div id="sidebar-people"> diff --git a/custom/views/default/sidebar.tpl.php b/custom/views/default/sidebar.tpl.php index 07de920..9e7631c 100644 --- a/custom/views/default/sidebar.tpl.php +++ b/custom/views/default/sidebar.tpl.php @@ -1,6 +1,6 @@ <?php $all_people = &$Planet->getPeople(); -usort($all_people, array('PlanetPerson', 'compare')); +usort($all_people, array('PlanetFeed', 'compare')); ?> <div id="sidebar" class="aside"> <div id="sidebar-people" class="section"> diff --git a/postload.php b/postload.php index e1670d8..64fd42e 100644 --- a/postload.php +++ b/postload.php @@ -2,7 +2,7 @@ include_once(dirname(__FILE__).'/app/app.php');
$Planet->addPerson(
- new PlanetPerson(
+ new PlanetFeed(
'',
htmlspecialchars_decode($_GET['url'], ENT_QUOTES),
''
|