skeleton of updatefeeds feature

This commit is contained in:
Alessandro Cosentino 2012-07-16 18:46:59 -04:00
Родитель b87705aa94
Коммит f54ffd3ed7
3 изменённых файлов: 90 добавлений и 0 удалений

32
ajax/feedlist.php Normal file
Просмотреть файл

@ -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!'))));

37
ajax/updatefeed.php Normal file
Просмотреть файл

@ -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!'))));

Просмотреть файл

@ -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) {