diff options
-rw-r--r-- | ajax/createfolder.php | 5 | ||||
-rw-r--r-- | ajax/importopml.php | 18 | ||||
-rw-r--r-- | js/news.js | 2 | ||||
-rw-r--r-- | lib/feed.php | 20 | ||||
-rw-r--r-- | lib/folder.php | 6 | ||||
-rw-r--r-- | lib/importopml.php | 0 | ||||
-rw-r--r-- | lib/utils.php | 12 | ||||
-rw-r--r-- | opmlparser.php | 36 | ||||
-rw-r--r-- | prova.opml | 46 | ||||
-rw-r--r-- | templates/test.php | 89 |
10 files changed, 120 insertions, 114 deletions
diff --git a/ajax/createfolder.php b/ajax/createfolder.php index b5f624604..6d3c62411 100644 --- a/ajax/createfolder.php +++ b/ajax/createfolder.php @@ -22,10 +22,11 @@ $parentid = trim($_POST['parentid']); $foldermapper = new OC_News_FolderMapper($userid); -if($parentid != 0) +if($parentid != 0) { $folder = new OC_News_Folder($name, NULL, $foldermapper->find($parentid)); -else +} else { $folder = new OC_News_Folder($name); +} $folderid = $foldermapper->save($folder); diff --git a/ajax/importopml.php b/ajax/importopml.php index 5a93567f9..89e2a52f0 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -27,30 +27,18 @@ function debug($msg) { OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::DEBUG); } -if(!isset($_GET['path'])) { +if(!isset($_POST['path'])) { bailOut($l->t('No file path was submitted.')); } require_once('news/opmlparser.php'); -$raw = file_get_contents($_GET['path']); +$raw = file_get_contents($_POST['path']); $parser = new OPMLParser($raw); $title = $parser->getTitle(); +$data = $parser->parse(); $count = 0; //number of feeds imported OCP\JSON::success(array('data' => array('title'=>$title, 'count'=>$count))); -/* -$localpath = OC_Filesystem::getLocalFile($_GET['path']); -$tmpfname = tempnam(get_temp_dir(), "occOrig"); - -if(!file_exists($localpath)) { - bailOut($l->t('File doesn\'t exist:').$localpath); -} - -if (file_put_contents($tmpfname, file_get_contents($localpath))) { - OCP\JSON::success(array('data' => array('tmp'=>$tmpfname, 'path'=>$localpath))); -} else { - bailOut(bailOut('Couldn\'t save temporary image: '.$tmpfname)); -}*/ diff --git a/js/news.js b/js/news.js index 0b5f792ff..4c71e2a90 100644 --- a/js/news.js +++ b/js/news.js @@ -99,7 +99,7 @@ News={ } - $.getJSON(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){ + $.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){ if (jsondata.status == 'success') { alert(jsondata.data.title); } diff --git a/lib/feed.php b/lib/feed.php index 59db6f7cc..6b1409440 100644 --- a/lib/feed.php +++ b/lib/feed.php @@ -20,36 +20,40 @@ class OC_News_Feed extends OC_News_Collection { private $items; //array that contains all the items of the feed private $favicon; - public function __construct($url, $title, $items, $id = null){ + public function __construct($url, $title, $items, $id = null) { $this->url = $url; $this->title = $title; $this->items = $items; - if ($id !== null){ + if ($id !== null) { parent::__construct($id); } } - public function getUrl(){ + public function getUrl() { return $this->url; } - public function getTitle(){ + public function getTitle() { return $this->title; } + + public function setTitle($title) { + $this->title = $title; + } - public function getFavicon(){ + public function getFavicon() { return $this->favicon; } - public function setFavicon($favicon){ + public function setFavicon($favicon) { $this->favicon = $favicon; } - public function setItems($items){ + public function setItems($items) { $this->items = $items; } - public function getItems(){ + public function getItems() { return $this->items; } diff --git a/lib/folder.php b/lib/folder.php index 6654b2f5e..14951d57c 100644 --- a/lib/folder.php +++ b/lib/folder.php @@ -48,7 +48,11 @@ class OC_News_Folder extends OC_News_Collection { public function addChild(OC_News_Collection $child){ $this->children[] = $child; } - + + public function addChildren($children){ + $this->children = $children; + } + public function getChildren(){ return $this->children; } diff --git a/lib/importopml.php b/lib/importopml.php deleted file mode 100644 index e69de29bb..000000000 --- a/lib/importopml.php +++ /dev/null diff --git a/lib/utils.php b/lib/utils.php index 6735c3f60..12a9506ec 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -22,12 +22,17 @@ class OC_News_Utils { * @returns */ public static function fetch($url){ - //TODO: handle the case where fetching of the feed fails $spfeed = new SimplePie_Core(); $spfeed->set_feed_url( $url ); $spfeed->enable_cache( false ); - $spfeed->init(); - $spfeed->handle_content_type(); + + if (!$spfeed->init()) { + return null; + } + + if (!$spfeed->handle_content_type()) { + return null; + } $title = $spfeed->get_title(); $spitems = $spfeed->get_items(); @@ -53,6 +58,7 @@ class OC_News_Utils { $feed->setFavicon($webFavicon); } return $feed; + } public static function checkFavicon($favicon) { diff --git a/opmlparser.php b/opmlparser.php index 4918b87b1..cde55e2dd 100644 --- a/opmlparser.php +++ b/opmlparser.php @@ -15,13 +15,11 @@ class OPMLParser { private $raw; private $body; - private $data; private $title; private $error; public function __construct($raw) { $this->raw = $raw; - $this->data = array(); try { $xml_parser = new SimpleXMLElement($this->raw, LIBXML_NOERROR); $this->title = (string)$xml_parser->head->title; @@ -34,12 +32,38 @@ class OPMLParser { } public function parse(){ - + return self::parseFolder($this->body); + } + + private function parseFolder($rawfolder) { + $list = array(); + foreach ($rawfolder->outline as $rawcollection) { + if ($rawcollection['type'] == 'rss') { + $collection = self::parseFeed($rawcollection); + } + else { + $name = (string)$rawcollection['text']; + $children = self::parseFolder($rawcollection); + $collection = new OC_News_Folder($name); + $collection->addChildren($children); + } + if ($collection !== null) { + $list[] = $collection; + } + } + return $list; } - //TODO: implement an iterator to get data in a fancier way - public function getData() { - return $this->data; + private function parseFeed($rawfeed) { + $url = (string)$rawfeed['xmlUrl']; + + $feed = OC_News_Utils::fetch($url); + if ($feed !== null) { + $title = $rawfeed['title']; + $feed->setTitle($title); + } + + return $feed; } public function getTitle() { diff --git a/prova.opml b/prova.opml new file mode 100644 index 000000000..014be0ae6 --- /dev/null +++ b/prova.opml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<opml version="1.0"> + <head> + <title>cosenal subscriptions in Google Reader</title> + </head> + <body> + <outline text="3" title="3" type="rss" xmlUrl="http://3ansis.wordpress.com/feed/" htmlUrl="http://3ansis.wordpress.com"/> + <outline text="Algorithms for the Kitchen » KDE" title="Algorithms for the Kitchen » KDE" type="rss" xmlUrl="http://algorithmsforthekitchen.com/blog/?tag=kde-2&feed=rss2" htmlUrl="http://algorithmsforthekitchen.com/blog"/> + <outline text="CBC Radio 3 Podcast with Grant Lawrence" title="CBC Radio 3 Podcast with Grant Lawrence" type="rss" xmlUrl="http://www.cbcradio3.com/podcast/radio3/ogg/" htmlUrl="http://radio3.cbc.ca/"/> + <outline text="Computational Complexity" title="Computational Complexity" type="rss" xmlUrl="http://blog.computationalcomplexity.org/feeds/posts/default" htmlUrl="http://blog.computationalcomplexity.org/"/> + <outline text="Delicious/nielsen/linklog" title="Delicious/nielsen/linklog" type="rss" xmlUrl="http://feeds.delicious.com/v2/rss/nielsen/linklog?count=15" htmlUrl="http://www.delicious.com/nielsen/linklog"/> + <outline text="Dr. Dobbs 'Quantum Computing'" title="Dr. Dobbs 'Quantum Computing'" type="rss" xmlUrl="http://dobbscodetalk.com/index.php?option=com_myblog&category=Quantum%20Computing&task=rss" htmlUrl="http://dobbscodetalk.com"/> + <outline text="ECCC - Reports" title="ECCC - Reports" type="rss" xmlUrl="http://eccc.hpi-web.de/feeds/reports/" htmlUrl="http://example.com/"/> + <outline text="Google Open Source Blog" title="Google Open Source Blog" type="rss" xmlUrl="http://google-opensource.blogspot.com/feeds/posts/default" htmlUrl="http://google-opensource.blogspot.com/"/> + <outline text="Gödel's Lost Letter and P=NP" title="Gödel's Lost Letter and P=NP" type="rss" xmlUrl="http://rjlipton.wordpress.com/feed/" htmlUrl="http://rjlipton.wordpress.com"/> + <outline text="in theory » The Cancun of Theoreticians" title="in theory » The Cancun of Theoreticians" type="rss" xmlUrl="http://lucatrevisan.wordpress.com/feed/" htmlUrl="http://lucatrevisan.wordpress.com"/> + <outline text="Kunal's Website" title="Kunal's Website" type="rss" xmlUrl="http://www.kunalghosh.net46.net/?q=rss.xml" htmlUrl="http://www.kunalghosh.net46.net"/> + <outline text="Little Big Details" title="Little Big Details" type="rss" xmlUrl="http://littlebigdetails.com/rss" htmlUrl="http://littlebigdetails.com/"/> + <outline text="Mamuta memuāri" title="Mamuta memuāri" type="rss" xmlUrl="http://marozols.wordpress.com/feed/" htmlUrl="http://marozols.wordpress.com"/> + <outline text="Marcus D. Hanwell's Blog" title="Marcus D. Hanwell's Blog" type="rss" xmlUrl="http://blog.cryos.net/feeds/index.rss2" htmlUrl="http://blog.cryos.net/"/> + <outline text="Martin's Blog" title="Martin's Blog" type="rss" xmlUrl="http://blog.martin-graesslin.com/blog/feed/" htmlUrl="http://blog.martin-graesslin.com/blog"/> + <outline text="Michael Nielsen" title="Michael Nielsen" type="rss" xmlUrl="http://michaelnielsen.org/blog/?feed=rss2" htmlUrl="http://michaelnielsen.org/blog"/> + <outline text="mytvrss" title="mytvrss" type="rss" xmlUrl="http://www.mytvrss.com/tvrss.xml?id=88413522554" htmlUrl="http://www.mytvrss.com/tvrss.xml?id=88413522554"/> + <outline text="mytvrss2" title="mytvrss2" type="rss" xmlUrl="http://www.mytvrss.com/tvrss.xml?id=46345705950" htmlUrl="http://www.mytvrss.com/tvrss.xml?id=46345705950"/> + <outline text="Notes on Gastronavigation" title="Notes on Gastronavigation" type="rss" xmlUrl="http://gastronavigation.blogspot.com/feeds/posts/default" htmlUrl="http://gastronavigation.blogspot.com/"/> + <outline text="online communities and free desktops" title="online communities and free desktops" type="rss" xmlUrl="http://blog.karlitschek.de/feeds/posts/default" htmlUrl="http://blog.karlitschek.de/"/> + <outline text="ownCloud" title="ownCloud" type="rss" xmlUrl="http://owncloud.com/feed" htmlUrl="https://owncloud.com"/> + <outline text="ownCloud Blog" title="ownCloud Blog" type="rss" xmlUrl="http://owncloudtest.blogspot.com/feeds/posts/default" htmlUrl="http://owncloudtest.blogspot.com/"/> + <outline text="ownCloud.org" title="ownCloud.org" type="rss" xmlUrl="http://owncloud.org/feed/" htmlUrl="http://owncloud.org"/> + <outline text="Pontiff++" title="Pontiff++" type="rss" xmlUrl="http://www.dabacon.org/newpontiff/?feed=rss2" htmlUrl="http://www.dabacon.org/newpontiff"/> + <outline text="quantumfactory" title="quantumfactory" type="rss" xmlUrl="http://quantumfactory.wordpress.com/feed/" htmlUrl="http://quantumfactory.wordpress.com"/> + <outline text="Raspberry Pi" title="Raspberry Pi" type="rss" xmlUrl="http://www.raspberrypi.org/feed" htmlUrl="http://www.raspberrypi.org"/> + <outline text="Shtetl-Optimized" title="Shtetl-Optimized" type="rss" xmlUrl="http://scottaaronson.com/blog/?feed=rss2" htmlUrl="http://www.scottaaronson.com/blog"/> + <outline text="Teo's blog" title="Teo's blog" type="rss" xmlUrl="http://teom.wordpress.com/feed/" htmlUrl="http://teom.org"/> + <outline text="The Quantum Pontiff" title="The Quantum Pontiff" type="rss" xmlUrl="http://scienceblogs.com/pontiff/index.xml" htmlUrl="http://scienceblogs.com/pontiff"/> + <outline text="Theory Matters" title="Theory Matters" type="rss" xmlUrl="http://thmatters.wordpress.com/feed/" htmlUrl="http://thmatters.wordpress.com"/> + <outline text="Theory of Quantum Information (course webpage)" title="Theory of Quantum Information (course webpage)" type="rss" xmlUrl="http://page2rss.com/rss/1a37007113e5693ccdcc9f1d2ad20631" htmlUrl="http://page2rss.com/1a37007113e5693ccdcc9f1d2ad20631"/> + <outline title="friends" text="friends"> + <outline text="<peppe>'s weblog" title="<peppe>'s weblog" type="rss" xmlUrl="http://dangelog.wordpress.com/feed/" htmlUrl="http://dangelog.wordpress.com"/> + <outline text="atdotde" title="atdotde" type="rss" xmlUrl="http://atdotde.blogspot.com/feeds/posts/default" htmlUrl="http://atdotde.blogspot.com/"/> + <outline text="Cult Bits" title="Cult Bits" type="rss" xmlUrl="http://cultbits.blogspot.com/feeds/posts/default" htmlUrl="http://cultbits.blogspot.com/"/> + <outline text="Stuff" title="Stuff" type="rss" xmlUrl="http://vinayakpathak.wordpress.com/feed/" htmlUrl="http://vinayakpathak.wordpress.com"/> + <outline text="The hole of it" title="The hole of it" type="rss" xmlUrl="http://theholeofit.blogspot.com/feeds/posts/default" htmlUrl="http://theholeofit.blogspot.com/"/> + </outline> + </body> +</opml>
\ No newline at end of file diff --git a/templates/test.php b/templates/test.php index d8e31e675..e8bb02c72 100644 --- a/templates/test.php +++ b/templates/test.php @@ -1,85 +1,18 @@ <?php -$feedmapper = new OC_News_FeedMapper(); -$foldermapper = new OC_News_FolderMapper(); -$itemmapper = new OC_News_ItemMapper(); +$content = file_get_contents('/var/www/apps/news/prova.opml'); -$folder = new OC_News_Folder( 'Friends' ); -$folderid = $foldermapper->save($folder); +require_once('news/opmlparser.php'); -$feed = OC_News_Utils::fetch( 'http://www.dabacon.org/newpontiff/?feed=rss2' ); +$parser = new OPMLParser($content); +$title = $parser->getTitle(); +$data = $parser->parse(); -$feedmapper->save($feed, $folder->getId()); - -$feed = $feedmapper->findWithItems($feed->getId()); -echo '<br>' . $feed->getTitle() . '<br>'; -$items = $feed->getItems(); - -foreach($items as $item) { - - echo $item->getTitle() . ' - '; - if ($item->isRead()) { - echo $l->t('Read'); - } - else { - echo $l->t('Unread'); - } - echo ' - '; - if ($item->isImportant()) { - echo $l->t('Important'); - } - else { - echo $l->t('Not important'); - } - echo '<br>'; - $item->setImportant(); -} - -echo '<br>...after changing status'; -echo '<br>' . $feed->getTitle() . '<br>'; - -foreach($items as $item) { - echo $item->getTitle() . ' - '; - if ($item->isRead()) { - echo $l->t('Read'); - } - else { - echo $l->t('Unread'); +foreach ($data as $collection) { + if ($collection instanceof OC_News_Feed) { + echo $collection->getTitle() . '\n'; + } else { + echo 'NO\n'; } - echo ' - '; - if ($item->isImportant()) { - echo $l->t('Important'); - } - else { - echo $l->t('Not important'); - } - echo '<br>'; - $item->setUnimportant(); } - -$feedmapper->save($feed, $folder->getId()); - -echo '<br>...after saving and reloading'; - -$feed = $feedmapper->findWithItems($feed->getId()); -echo '<br>' . $feed->getTitle() . '<br>'; -$items = $feed->getItems(); - -foreach($items as &$item) { - - echo $item->getTitle() . ' - '; - if ($item->isRead()) { - echo $l->t('Read'); - } - else { - echo $l->t('Unread'); - } - echo ' - '; - if ($item->isImportant()) { - echo $l->t('Important'); - } - else { - echo $l->t('Not important'); - } - echo '<br>'; -}
\ No newline at end of file +echo $title; |