diff options
-rw-r--r-- | ajax/feedlist.php | 32 | ||||
-rw-r--r-- | ajax/updatefeed.php | 37 | ||||
-rw-r--r-- | js/news.js | 21 |
3 files changed, 90 insertions, 0 deletions
diff --git a/ajax/feedlist.php b/ajax/feedlist.php new file mode 100644 index 000000000..e5a37ef2b --- /dev/null +++ b/ajax/feedlist.php @@ -0,0 +1,32 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +// Check if we are a user +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('news'); +OCP\JSON::callCheck(); + +$userid = OCP\USER::getUser(); + +$feedmapper = new OC_News_FeedMapper(); + +$l = OC_L10N::get('news'); + +if(!$feedid) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.')))); + OCP\Util::writeLog('news','ajax/feedlist.php: Error adding feed: '.$_POST['feedurl'], OCP\Util::ERROR); + exit(); +} + +//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations +OCP\JSON::success(array('data' => array('message' => $l->t('Feed added!')))); + diff --git a/ajax/updatefeed.php b/ajax/updatefeed.php new file mode 100644 index 000000000..754d87495 --- /dev/null +++ b/ajax/updatefeed.php @@ -0,0 +1,37 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +// Check if we are a user +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('news'); +OCP\JSON::callCheck(); + +$userid = OCP\USER::getUser(); + +$feedurl = trim($_POST['feedurl']); +$folderid = trim($_POST['folderid']); + +$feed = OC_News_Utils::fetch($feedurl); +$feedmapper = new OC_News_FeedMapper(); +$feedid = $feedmapper->save($feed, $folderid); + +$l = OC_L10N::get('news'); + +if(!$feedid) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.')))); + OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '.$_POST['feedurl'], OCP\Util::ERROR); + exit(); +} + +//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations +OCP\JSON::success(array('data' => array('message' => $l->t('Feed added!')))); + diff --git a/js/news.js b/js/news.js index 0ed437ca7..77ee6d1fc 100644 --- a/js/news.js +++ b/js/news.js @@ -149,6 +149,24 @@ News={ OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); } }); + }, + updateAll:function() { + $.post(OC.filePath('news', 'ajax', 'feedlist.php'),function(jsondata){ + if(jsondata.status == 'success'){ + + } + else{ + OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); + } + }); + }, + updateFeed:function(feedid) { + $.post(OC.filePath('news', 'ajax', 'updatefeed.php'),{'feedid':feedid},function(jsondata){ + if(jsondata.status == 'success'){ + } + else{ + } + }); } } } @@ -193,6 +211,9 @@ $(document).ready(function(){ event.stopPropagation(); }); + var updateInterval = 20000; //how often the feeds should update (in msec) + setInterval('News.Feed.updateAll()', updateInterval); + }); $(document).click(function(event) { |