mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-24 16:25:00 -04:00
API add feed
This commit is contained in:
@@ -26,7 +26,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public static function addFeed($url, $cat_id = 0, $new_cat_name = '', $http_auth = '') {
|
||||
public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') {
|
||||
@set_time_limit(300);
|
||||
|
||||
$catDAO = new FreshRSS_CategoryDAO();
|
||||
@@ -40,9 +40,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
}
|
||||
if ($cat == null) {
|
||||
$catDAO->checkDefault();
|
||||
$def_cat = $catDAO->getDefault();
|
||||
$cat = $def_cat->id();
|
||||
$cat = $catDAO->getDefault();
|
||||
}
|
||||
$cat_id = $cat->id();
|
||||
|
||||
$feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception
|
||||
$feed->_httpAuth($http_auth);
|
||||
@@ -63,7 +63,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
$values = array(
|
||||
'url' => $feed->url(),
|
||||
'category' => $feed->category(),
|
||||
'name' => $feed->name(),
|
||||
'name' => $title != '' ? $title : $feed->name(),
|
||||
'website' => $feed->website(),
|
||||
'description' => $feed->description(),
|
||||
'lastUpdate' => time(),
|
||||
@@ -149,7 +149,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
}
|
||||
|
||||
try {
|
||||
$feed = self::addFeed($url, $cat, $new_cat_name, $http_auth);
|
||||
$feed = self::addFeed($url, '', $cat, $new_cat_name, $http_auth);
|
||||
} catch (FreshRSS_BadUrl_Exception $e) {
|
||||
// Given url was not a valid url!
|
||||
Minz_Log::warning($e->getMessage());
|
||||
|
||||
@@ -298,18 +298,22 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '
|
||||
if ($add != '' || $remove != '') {
|
||||
$categoryDAO = new FreshRSS_CategoryDAO();
|
||||
}
|
||||
$c_name = '';
|
||||
if ($add != '' && strpos($add, 'user/-/label/') === 0) { //user/-/label/Example
|
||||
$c_name = basename($add);
|
||||
$c_name = substr($add, 13);
|
||||
$cat = $categoryDAO->searchByName($c_name);
|
||||
$addCatId = $cat == null ? -1 : $cat->id();
|
||||
} else if ($remove != '' && strpos($remove, 'user/-/label/')) {
|
||||
$addCatId = 1; //Default category
|
||||
}
|
||||
if ($addCatId <= 0 && $c_name = '') {
|
||||
$addCatId = 1; //Default category
|
||||
}
|
||||
$feedDAO = FreshRSS_Factory::createFeedDao();
|
||||
for ($i = count($streamNames) - 1; $i >= 0; $i--) {
|
||||
$streamName = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338
|
||||
if (strpos($streamName, 'feed/') === 0) {
|
||||
$streamName = basename($streamName);
|
||||
$streamName = substr($streamName, 5);
|
||||
$feedId = 0;
|
||||
if (ctype_digit($streamName)) {
|
||||
if ($action === 'subscribe') {
|
||||
@@ -324,11 +328,15 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '
|
||||
switch ($action) {
|
||||
case 'subscribe':
|
||||
if ($feedId <= 0) {
|
||||
//TODO
|
||||
notImplemented();
|
||||
} else {
|
||||
badRequest();
|
||||
$http_auth = ''; //TODO
|
||||
try {
|
||||
$feed = FreshRSS_feed_Controller::addFeed($streamName, $title, $addCatId, $c_name, $http_auth);
|
||||
continue;
|
||||
} catch (Exception $e) {
|
||||
logMe("subscriptionEdit error subscribe: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
badRequest();
|
||||
break;
|
||||
case 'unsubscribe':
|
||||
if (!($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId))) {
|
||||
|
||||
Reference in New Issue
Block a user