diff options
-rw-r--r-- | appinfo/app.php | 1 | ||||
-rw-r--r-- | appinfo/database.xml | 48 | ||||
-rw-r--r-- | lib/feed.php | 79 | ||||
-rw-r--r-- | templates/main.php | 29 |
4 files changed, 128 insertions, 29 deletions
diff --git a/appinfo/app.php b/appinfo/app.php index 43db69fee..303b601b1 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -22,6 +22,7 @@ */ OC::$CLASSPATH['OC_News_Item'] = 'apps/news/lib/item.php'; +OC::$CLASSPATH['OC_News_Feed'] = 'apps/news/lib/feed.php'; $l = new OC_l10n('news'); diff --git a/appinfo/database.xml b/appinfo/database.xml index 562fac158..e2aeb7ee2 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -1,14 +1,14 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <database> - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - <charset>latin1</charset> - <table> + <name>*dbname*</name> + <create>true</create> + <overwrite>false</overwrite> + <charset>latin1</charset> + <table> <name>*dbprefix*news_feeds</name> <declaration> <field> - <name>feed_id</name> + <name>id</name> <type>integer</type> <default>0</default> <notnull>true</notnull> @@ -16,17 +16,49 @@ <length>4</length> </field> <field> - <name>feed_name</name> + <name>url</name> <type>text</type> <notnull>true</notnull> <length>100</length> </field> <field> - <name>feed_url</name> + <name>title</name> <type>text</type> <notnull>true</notnull> <length>100</length> </field> + <field> + <name>user_id</name> + <type>text</type> + <default></default> + <notnull>true</notnull> + <length>64</length> + </field> + <field> + <name>added</name> + <type>integer</type> + <default></default> + <notnull>false</notnull> + <unsigned>true</unsigned> + <length>4</length> + </field> + <field> + <name>lastmodified</name> + <type>integer</type> + <default></default> + <notnull>false</notnull> + <unsigned>true</unsigned> + <length>4</length> + </field> + + <index> + <name>id</name> + <unique>true</unique> + <field> + <name>id</name> + <sorting>descending</sorting> + </field> + </index> </declaration> </table> </database> diff --git a/lib/feed.php b/lib/feed.php new file mode 100644 index 000000000..91380c6b1 --- /dev/null +++ b/lib/feed.php @@ -0,0 +1,79 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + + +/** + * This class models a feed. + */ +class OC_News_Feed extends SimplePie_Core{ + + private $url; + private $feed_id; + + public function __construct($url){ + parent::__construct(); + $this->url = $url; + $this->set_item_class('OC_News_Item'); + $this->set_feed_url( $url ); + $this->enable_cache( false ); + + //FIXME: figure out if constructor is the right place for these + $this->init(); + $this->handle_content_type(); + } + + public function saveToDB() { + $CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" ); + if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ + $_ut = "strftime('%s','now')"; + } elseif($CONFIG_DBTYPE == 'pgsql') { + $_ut = 'date_part(\'epoch\',now())::integer'; + } else { + $_ut = "UNIX_TIMESTAMP()"; + } + + //FIXME: Detect when user adds a known feed + $query = OCP\DB::prepare(" + INSERT INTO *PREFIX*news_feeds + (url, title, userid, added, lastmodified) + VALUES (?, ?, ?, $_ut, $_ut) + "); + + $title = $this->sp->get_title(); + + if(empty($title)) { + $l = OC_L10N::get('news'); + $title = $l->t('no title'); + } + + $params=array( + htmlspecialchars_decode($this->url), + htmlspecialchars_decode($title), + OCP\USER::getUser() + ); + $query->execute($params); + + $feed_id = OCP\DB::insertid('*PREFIX*news_feeds'); + + return $feed_id; + } +}
\ No newline at end of file diff --git a/templates/main.php b/templates/main.php index 499483875..771d83b3e 100644 --- a/templates/main.php +++ b/templates/main.php @@ -1,18 +1,16 @@ <?php -$feed = new SimplePie_Core(); -$feed->set_item_class('OC_News_Item'); -$feed->set_feed_url( 'http://algorithmsforthekitchen.com/blog/?feed=rss2' ); -$feed->enable_cache( false ); -$feed->init(); -$feed->handle_content_type(); +$feed = new OC_News_Feed( 'http://algorithmsforthekitchen.com/blog/?feed=rss2' ); +$feed->saveToDB(); $item = $feed->get_item(1); -if ($item->isRead()) +if ($item->isRead()) { echo $l->t('Read'); -else +} +else { echo $l->t('Unread'); +} $item->setRead(); $item->setUnread(); @@ -23,17 +21,6 @@ echo "<br>" . $item->get_title() . "<br>"; if ($item->isRead()) { echo $l->t('Read'); } -else +else { echo $l->t('Unread'); - -?> - -<?php /* this is from apptemplate - -<h1>This is an example app template</h1> - -<?php echo $l->t('Some Setting');?> -:" -<?php echo $_['somesetting']; ?> -" -*/ ?>
\ No newline at end of file +} |