зеркало из https://github.com/nextcloud/news.git
opml parser completed; still needs testing
This commit is contained in:
Родитель
a5438863a4
Коммит
fd5b815e58
|
@ -22,10 +22,11 @@ $parentid = trim($_POST['parentid']);
|
||||||
|
|
||||||
$foldermapper = new OC_News_FolderMapper($userid);
|
$foldermapper = new OC_News_FolderMapper($userid);
|
||||||
|
|
||||||
if($parentid != 0)
|
if($parentid != 0) {
|
||||||
$folder = new OC_News_Folder($name, NULL, $foldermapper->find($parentid));
|
$folder = new OC_News_Folder($name, NULL, $foldermapper->find($parentid));
|
||||||
else
|
} else {
|
||||||
$folder = new OC_News_Folder($name);
|
$folder = new OC_News_Folder($name);
|
||||||
|
}
|
||||||
|
|
||||||
$folderid = $foldermapper->save($folder);
|
$folderid = $foldermapper->save($folder);
|
||||||
|
|
||||||
|
|
|
@ -27,30 +27,18 @@ function debug($msg) {
|
||||||
OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::DEBUG);
|
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.'));
|
bailOut($l->t('No file path was submitted.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once('news/opmlparser.php');
|
require_once('news/opmlparser.php');
|
||||||
|
|
||||||
$raw = file_get_contents($_GET['path']);
|
$raw = file_get_contents($_POST['path']);
|
||||||
|
|
||||||
$parser = new OPMLParser($raw);
|
$parser = new OPMLParser($raw);
|
||||||
$title = $parser->getTitle();
|
$title = $parser->getTitle();
|
||||||
|
$data = $parser->parse();
|
||||||
$count = 0; //number of feeds imported
|
$count = 0; //number of feeds imported
|
||||||
|
|
||||||
OCP\JSON::success(array('data' => array('title'=>$title, 'count'=>$count)));
|
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));
|
|
||||||
}*/
|
|
||||||
|
|
|
@ -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') {
|
if (jsondata.status == 'success') {
|
||||||
alert(jsondata.data.title);
|
alert(jsondata.data.title);
|
||||||
}
|
}
|
||||||
|
|
20
lib/feed.php
20
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 $items; //array that contains all the items of the feed
|
||||||
private $favicon;
|
private $favicon;
|
||||||
|
|
||||||
public function __construct($url, $title, $items, $id = null){
|
public function __construct($url, $title, $items, $id = null) {
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
$this->items = $items;
|
$this->items = $items;
|
||||||
if ($id !== null){
|
if ($id !== null) {
|
||||||
parent::__construct($id);
|
parent::__construct($id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrl(){
|
public function getUrl() {
|
||||||
return $this->url;
|
return $this->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(){
|
public function getTitle() {
|
||||||
return $this->title;
|
return $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTitle($title) {
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFavicon(){
|
public function getFavicon() {
|
||||||
return $this->favicon;
|
return $this->favicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFavicon($favicon){
|
public function setFavicon($favicon) {
|
||||||
$this->favicon = $favicon;
|
$this->favicon = $favicon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setItems($items){
|
public function setItems($items) {
|
||||||
$this->items = $items;
|
$this->items = $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getItems(){
|
public function getItems() {
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,11 @@ class OC_News_Folder extends OC_News_Collection {
|
||||||
public function addChild(OC_News_Collection $child){
|
public function addChild(OC_News_Collection $child){
|
||||||
$this->children[] = $child;
|
$this->children[] = $child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addChildren($children){
|
||||||
|
$this->children = $children;
|
||||||
|
}
|
||||||
|
|
||||||
public function getChildren(){
|
public function getChildren(){
|
||||||
return $this->children;
|
return $this->children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,17 @@ class OC_News_Utils {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public static function fetch($url){
|
public static function fetch($url){
|
||||||
//TODO: handle the case where fetching of the feed fails
|
|
||||||
$spfeed = new SimplePie_Core();
|
$spfeed = new SimplePie_Core();
|
||||||
$spfeed->set_feed_url( $url );
|
$spfeed->set_feed_url( $url );
|
||||||
$spfeed->enable_cache( false );
|
$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();
|
$title = $spfeed->get_title();
|
||||||
|
|
||||||
$spitems = $spfeed->get_items();
|
$spitems = $spfeed->get_items();
|
||||||
|
@ -53,6 +58,7 @@ class OC_News_Utils {
|
||||||
$feed->setFavicon($webFavicon);
|
$feed->setFavicon($webFavicon);
|
||||||
}
|
}
|
||||||
return $feed;
|
return $feed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkFavicon($favicon) {
|
public static function checkFavicon($favicon) {
|
||||||
|
|
|
@ -15,13 +15,11 @@ class OPMLParser {
|
||||||
|
|
||||||
private $raw;
|
private $raw;
|
||||||
private $body;
|
private $body;
|
||||||
private $data;
|
|
||||||
private $title;
|
private $title;
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
public function __construct($raw) {
|
public function __construct($raw) {
|
||||||
$this->raw = $raw;
|
$this->raw = $raw;
|
||||||
$this->data = array();
|
|
||||||
try {
|
try {
|
||||||
$xml_parser = new SimpleXMLElement($this->raw, LIBXML_NOERROR);
|
$xml_parser = new SimpleXMLElement($this->raw, LIBXML_NOERROR);
|
||||||
$this->title = (string)$xml_parser->head->title;
|
$this->title = (string)$xml_parser->head->title;
|
||||||
|
@ -34,12 +32,38 @@ class OPMLParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(){
|
public function parse(){
|
||||||
|
return self::parseFolder($this->body);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: implement an iterator to get data in a fancier way
|
private function parseFolder($rawfolder) {
|
||||||
public function getData() {
|
$list = array();
|
||||||
return $this->data;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
public function getTitle() {
|
||||||
|
|
|
@ -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>
|
|
@ -1,85 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$feedmapper = new OC_News_FeedMapper();
|
$content = file_get_contents('/var/www/apps/news/prova.opml');
|
||||||
$foldermapper = new OC_News_FolderMapper();
|
|
||||||
$itemmapper = new OC_News_ItemMapper();
|
|
||||||
|
|
||||||
$folder = new OC_News_Folder( 'Friends' );
|
require_once('news/opmlparser.php');
|
||||||
$folderid = $foldermapper->save($folder);
|
|
||||||
|
|
||||||
$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());
|
foreach ($data as $collection) {
|
||||||
|
if ($collection instanceof OC_News_Feed) {
|
||||||
$feed = $feedmapper->findWithItems($feed->getId());
|
echo $collection->getTitle() . '\n';
|
||||||
echo '<br>' . $feed->getTitle() . '<br>';
|
} else {
|
||||||
$items = $feed->getItems();
|
echo 'NO\n';
|
||||||
|
|
||||||
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 $title;
|
||||||
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');
|
|
||||||
}
|
|
||||||
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>';
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче