diff options
-rw-r--r-- | ajax/.importopml.php.kate-swp | bin | 0 -> 150 bytes | |||
-rw-r--r-- | ajax/importopml.php | 33 | ||||
-rw-r--r-- | js/news.js | 26 | ||||
-rw-r--r-- | opmlparser.php | 16 |
4 files changed, 49 insertions, 26 deletions
diff --git a/ajax/.importopml.php.kate-swp b/ajax/.importopml.php.kate-swp Binary files differnew file mode 100644 index 000000000..9447b6429 --- /dev/null +++ b/ajax/.importopml.php.kate-swp diff --git a/ajax/importopml.php b/ajax/importopml.php index c2230c8b8..3aaccd840 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -41,5 +41,38 @@ if ($parsed == null) { bailOut($l->t('An error occurred while parsing the file.')); } +// $ch is the handler for the curl connection +function addFeed($feedurl, $folderid, $ch) { + + $data = array('feedurl' => $feedurl, 'folderid' => $folderid); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + $result = curl_exec($ch); + + if($result === false) { + bailOut(curl_error($ch)); + } else { + bailOut($result); + } +} + +$data = $parsed->getData(); +$url = OCP\Util::linkToAbsolute('news', 'ajax/createfeed.php'); +$ch = curl_init($url); +curl_setopt($ch, CURLOPT_POST, TRUE); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + +foreach($data as $collection) { + if ($collection instanceOf OC_News_Feed) { + $feedurl = $collection->getUrl(); + $folderid = 0; + addFeed($feedurl, $folderid, $ch); + } +} + +addFeed(null, null, $ch); +$result = curl_exec($ch); + +curl_close($ch); + OCP\JSON::success(array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount()))); diff --git a/js/news.js b/js/news.js index 7f27a8486..6e2407e4e 100644 --- a/js/news.js +++ b/js/news.js @@ -150,32 +150,6 @@ News={ $(button).prop('value', t('news', 'Add feed')); } }); - -// $.post(OC.filePath('news', 'ajax', 'createfeed.php'), { feedurl: feedurl, folderid: folderid }, -// function(jsondata){ -// if(jsondata.status == 'success'){ -// $('div[data-id="' + folderid + '"] > ul').append(jsondata.data.listfeed); -// setupFeedList(); -// OC.dialogs.confirm(t('news', 'Do you want to add another feed?'), t('news', 'Feed added!'), function(answer) { -// if(!answer) { -// $('#addfeed_dialog').dialog('destroy').remove(); -// var rightcontent = $('div.rightcontent'); -// rightcontent.empty(); -// rightcontent.attr('data-id', jsondata.data.feedid); -// rightcontent.html(jsondata.data.part_items); -// rightcontent.find('ul.accordion').before(jsondata.data.part_newfeed); -// setupRightContent(); -// transformCollapsableTrigger(); -// } -// }); -// } else { -// OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); -// } -// $("#feed_add_url").val(''); -// $(button).attr("disabled", false); -// $(button).prop('value', t('news', 'Add feed')); -// }); - }, 'delete':function(feedid) { $('#feeds_delete').tipsy('hide'); diff --git a/opmlparser.php b/opmlparser.php index 3a07383cb..280a07a83 100644 --- a/opmlparser.php +++ b/opmlparser.php @@ -23,18 +23,33 @@ class OPMLParser { $this->count = 0; } + /** + * @brief + * @returns the title element from the head section of the OPML file + */ public function getTitle() { return $this->title; } + /** + * @brief + * @returns the number of feeds found in the OPML file + */ public function getData() { return $this->data; } + /** + * @brief + * @returns the number of feeds found in the file + */ public function getCount() { return $this->count; } + /** + * @brief This is used as a utility private function by the method OPMLParser::parse + */ private static function parseFolder($rawfolder, &$count) { $list = array(); foreach ($rawfolder->outline as $rawcollection) { @@ -64,6 +79,7 @@ class OPMLParser { } /** + * @brief * @param $raw the XML string to be parsed * @return an object of the OPMLParser class itself * or null if the parsing failed |