diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-08-10 00:12:38 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-08-10 00:12:38 -0400 |
commit | a077e4ea2f34d3406373b7d3705162a44f527ace (patch) | |
tree | 7bdcfeeb6463e6e553ed072fe5353a65a47925b9 | |
parent | 98614791fb9cc79920405d2e07030a2411dc6f4a (diff) |
importing opml becomes simple for debugging reasons (ignore SimplePie issues for now)
-rw-r--r-- | ajax/.createfeed.php.kate-swp | bin | 0 -> 160 bytes | |||
-rw-r--r-- | ajax/createfeed.php | 8 | ||||
-rw-r--r-- | ajax/importopml.php | 89 | ||||
-rw-r--r-- | appinfo/database.xml | 6 | ||||
-rw-r--r-- | appinfo/version | 2 | ||||
-rw-r--r-- | js/news.js | 2 | ||||
-rw-r--r-- | js/settings.js | 94 | ||||
-rw-r--r-- | lib/feedmapper.php | 8 | ||||
-rw-r--r-- | lib/itemmapper.php | 2 | ||||
-rw-r--r-- | lib/utils.php | 2 | ||||
-rw-r--r-- | templates/part.feeds.php | 5 |
11 files changed, 135 insertions, 83 deletions
diff --git a/ajax/.createfeed.php.kate-swp b/ajax/.createfeed.php.kate-swp Binary files differnew file mode 100644 index 000000000..f3c2a36a4 --- /dev/null +++ b/ajax/.createfeed.php.kate-swp diff --git a/ajax/createfeed.php b/ajax/createfeed.php index 627b0e36b..728cf4844 100644 --- a/ajax/createfeed.php +++ b/ajax/createfeed.php @@ -10,7 +10,7 @@ * */ -register_shutdown_function("shutdown"); +//register_shutdown_function("shutdown"); /* handle the case of fatal error */ function shutdown() { @@ -40,10 +40,10 @@ $feedid = $feedmapper->findIdFromUrl($feedurl); $l = OC_L10N::get('news'); -if ($feedid == null) { +if ($feedid === null) { $feed = OC_News_Utils::fetch($feedurl); - if ($feed != null) { + if ($feed !== null) { $feedid = $feedmapper->save($feed, $folderid); } } else { @@ -52,7 +52,7 @@ if ($feedid == null) { exit(); } -if($feed == null || !$feedid) { +if($feed === null || !$feedid) { OCP\JSON::error(array('data' => array('message' => $l->t('Error adding feed.')))); OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '.$_POST['feedurl'], OCP\Util::ERROR); exit(); diff --git a/ajax/importopml.php b/ajax/importopml.php index 3aaccd840..04b745db6 100644 --- a/ajax/importopml.php +++ b/ajax/importopml.php @@ -41,38 +41,87 @@ 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); +$data = $parsed->getData(); + +function createFeed($feedurl, $folderid) { + $feedmapper = new OC_News_FeedMapper(); + $feedid = $feedmapper->findIdFromUrl($feedurl); + + $l = OC_L10N::get('news'); - if($result === false) { - bailOut(curl_error($ch)); + if ($feedid === null) { + $feed = OC_News_Utils::fetch($feedurl); + + if ($feed !== null) { + $feedid = $feedmapper->save($feed, $folderid); + } } else { - bailOut($result); + OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); + return false; } -} -$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); + if($feed === null || !$feedid) { + OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '. $feedurl, OCP\Util::ERROR); + return false; + } + + return true; +} +$countadded = 0; foreach($data as $collection) { if ($collection instanceOf OC_News_Feed) { $feedurl = $collection->getUrl(); $folderid = 0; - addFeed($feedurl, $folderid, $ch); + if (createFeed($feedurl, $folderid)) { + $countadded++; + } } } -addFeed(null, null, $ch); -$result = curl_exec($ch); -curl_close($ch); - -OCP\JSON::success(array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount()))); +// // $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); +// $status = curl_getinfo($ch); +// +// if($result === false) { +// bailOut(curl_error($ch)); +// } else { +// bailOut($status['http_code'] . $status['url']); +// } +// } + +// $url = OCP\Util::linkToAbsolute('news', 'ajax/createfeed.php'); +// $ch = curl_init($url); +// if ($ch != false) { +// curl_setopt($ch, CURLOPT_POST, TRUE); +// curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); +// curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); +// curl_setopt($ch, CURLOPT_USERPWD, 'acosenti:nopass'); +// +// +// 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); +// } else { +// bailOut($l->t('An error occurred while adding the feeds.')); +// } + +OCP\JSON::success(array('data' => array('title'=>$parsed->getTitle(), 'count'=>$parsed->getCount(), + 'countsuccess'=>$countadded))); diff --git a/appinfo/database.xml b/appinfo/database.xml index cbb8baf1e..1fbfe29a4 100644 --- a/appinfo/database.xml +++ b/appinfo/database.xml @@ -147,17 +147,17 @@ <name>guid</name> <type>text</type> <notnull>true</notnull> - <length>100</length> + <length>300</length> </field> <field> <name>url</name> <type>text</type> - <length>100</length> + <length>300</length> </field> <field> <name>title</name> <type>text</type> - <length>100</length> + <length>300</length> </field> <field> <name>feed_id</name> diff --git a/appinfo/version b/appinfo/version index 913671cdf..1f2be2a26 100644 --- a/appinfo/version +++ b/appinfo/version @@ -1 +1 @@ -6.2
\ No newline at end of file +6.3
\ No newline at end of file diff --git a/js/news.js b/js/news.js index e485e4a4b..2d38ec930 100644 --- a/js/news.js +++ b/js/news.js @@ -348,7 +348,7 @@ $(document).ready(function(){ $('#settingsbtn').on('click keydown', function() { try { - OC.appSettings({appid:'news', loadJS:true}); + OC.appSettings({appid:'news', loadJS:true, cache:false}); } catch(e) { alert(e); } diff --git a/js/settings.js b/js/settings.js index 95fb14b6a..7bc1c80db 100644 --- a/js/settings.js +++ b/js/settings.js @@ -1,57 +1,57 @@ News = News || {} News.Settings={ - importkind: '', - importpath: '', - IMPORTCLOUD:'cloud', - IMPORTLOCAL:'local', - cloudFileSelected:function(path){ - $.getJSON(OC.filePath('news', 'ajax', 'selectfromcloud.php'),{'path':path},function(jsondata){ - if(jsondata.status == 'success'){ - $('#browsebtn, #cloudbtn, #importbtn').show(); - $('#opml_file').text(t('news', 'File ') + path + t('news', ' loaded from cloud.')); - News.Settings.importkind = News.Settings.IMPORTCLOUD; - News.Settings.importpath = jsondata.data.tmp; - } - else{ - OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); - } - }); - }, - browseFile:function(filelist){ - if(!filelist) { - OC.dialogs.alert(t('news','No files selected.'), t('news', 'Error')); - return; + importkind: '', + importpath: '', + IMPORTCLOUD:'cloud', + IMPORTLOCAL:'local', + cloudFileSelected:function(path){ + $.getJSON(OC.filePath('news', 'ajax', 'selectfromcloud.php'),{'path':path},function(jsondata){ + if(jsondata.status == 'success'){ + $('#browsebtn, #cloudbtn, #importbtn').show(); + $('#opml_file').text(t('news', 'File ') + path + t('news', ' loaded from cloud.')); + News.Settings.importkind = News.Settings.IMPORTCLOUD; + News.Settings.importpath = jsondata.data.tmp; } - var file = filelist[0]; - $('#browsebtn, #cloudbtn, #importbtn').show(); - $('#opml_file').text(t('news', 'File ') + file.name + t('news', ' loaded from local filesystem.')); - $('#opml_file').prop('value', file.name); - }, - import:function(button){ - $(button).attr("disabled", true); - $(button).prop('value', t('news', 'Importing...')); - - var path = ''; - if (News.Settings.importkind == News.Settings.IMPORTCLOUD) { - path = News.Settings.importpath; - } else if (this.importkind == this.IMPORTLOCAL) { - } - else { - OC.dialogs.alert(t('news','Import kind not specified'), t('news', 'Error')); + else{ + OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); } + }); + }, + browseFile:function(filelist){ + if(!filelist) { + OC.dialogs.alert(t('news','No files selected.'), t('news', 'Error')); + return; + } + var file = filelist[0]; + $('#browsebtn, #cloudbtn, #importbtn').show(); + $('#opml_file').text(t('news', 'File ') + file.name + t('news', ' loaded from local filesystem.')); + $('#opml_file').prop('value', file.name); + }, + import:function(button){ + $(button).attr("disabled", true); + $(button).prop('value', t('news', 'Importing...')); - $.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){ - if (jsondata.status == 'success') { - alert(jsondata.data.title); - } else { - OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); - } - }); - + var path = ''; + if (News.Settings.importkind == News.Settings.IMPORTCLOUD) { + path = News.Settings.importpath; + } else if (this.importkind == this.IMPORTLOCAL) { + } + else { + OC.dialogs.alert(t('news','Import kind not specified'), t('news', 'Error')); + } + + $.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){ + if (jsondata.status == 'success') { + var message = jsondata.data.countsuccess + t('news', ' out of ') + jsondata.data.count + + t('news', ' feeds imported successfully from ') + jsondata.data.title; + OC.dialogs.alert(message, t('news', 'Success')); + } else { + OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); + } $(button).prop('value', t('news', 'Import')); $(button).attr("disabled", false); - - } + }); + } } $('#browsebtn, #cloudbtn, #importbtn').hide(); diff --git a/lib/feedmapper.php b/lib/feedmapper.php index a533691cb..c5f01f8d2 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -63,7 +63,7 @@ class OC_News_FeedMapper { return null; $url = $row['url']; - $title = $row['title']; + $title = htmlspecialchars_decode($row['title']); $feed = new OC_News_Feed($url, $title, null, $id); return $feed; } @@ -79,7 +79,7 @@ class OC_News_FeedMapper { $feeds = array(); while ($row = $result->fetchRow()) { $url = $row['url']; - $title = $row['title']; + $title = htmlspecialchars_decode($row['title']); $id = $row['id']; $feed = new OC_News_Feed($url, $title, null, $id); $favicon = $row['favicon_link']; @@ -100,7 +100,7 @@ class OC_News_FeedMapper { $result = $stmt->execute(array($id)); $row = $result->fetchRow(); $url = $row['url']; - $title = $row['title']; + $title = htmlspecialchars_decode($row['title']); $feed = new OC_News_Feed($url, $title, null,$id); $favicon = $row['favicon_link']; $feed->setFavicon($favicon); @@ -175,7 +175,7 @@ class OC_News_FeedMapper { $params=array( $url, - htmlspecialchars_decode($title), + $title, $feed->getFavicon(), $folderid, $this->userid diff --git a/lib/itemmapper.php b/lib/itemmapper.php index b20387192..27f56eb3f 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -126,7 +126,7 @@ class OC_News_ItemMapper { htmlspecialchars_decode($item->getUrl()), htmlspecialchars_decode($title), $body, - $guid, + htmlspecialchars_decode($guid), $feedid, $status ); diff --git a/lib/utils.php b/lib/utils.php index b7750e71a..f98608cd4 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -37,7 +37,7 @@ class OC_News_Utils { $items = array(); if ($spitems = $spfeed->get_items()) { - foreach($spitems as $spitem) { //FIXME: maybe we can avoid this loop + foreach($spitems as $spitem) { $itemUrl = $spitem->get_permalink(); $itemTitle = $spitem->get_title(); $itemGUID = $spitem->get_id(); diff --git a/templates/part.feeds.php b/templates/part.feeds.php index faa58f323..68ef70451 100644 --- a/templates/part.feeds.php +++ b/templates/part.feeds.php @@ -32,5 +32,8 @@ } $allfeeds = isset($_['allfeeds']) ? $_['allfeeds'] : ''; - print_folder($allfeeds); +?> + +<?php +print_folder($allfeeds); ?>
\ No newline at end of file |