1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-04-09 19:15:42 +02:00

Merge branch 'newsapp' of git://gitorious.org/owncloud/apps into newsapp

This commit is contained in:
Bernhard Posselt 2012-08-12 12:27:10 +02:00
commit 1029b44255
20 changed files with 277 additions and 131 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ news.kdev4
*~
.kdev4
img/*
.*
!/.gitignore

127
ajax/exportopml.php Normal file
View File

@ -0,0 +1,127 @@
<?php
/**
* ownCloud - News app
*
* @author Alessandro Cosentino
* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
$l = OC_L10N::get('news');
function bailOut($msg) {
OCP\JSON::error(array('data' => array('message' => $msg)));
OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::ERROR);
exit();
}
if(!isset($_POST['path'])) {
bailOut($l->t('No file path was submitted.'));
}
require_once('news/opmlparser.php');
$raw = file_get_contents($_POST['path']);
try {
$parsed = OPMLParser::parse($raw);
} catch (Exception $e) {
bailOut($e->getMessage());
}
if ($parsed == null) {
bailOut($l->t('An error occurred while parsing the file.'));
}
$data = $parsed->getData();
function createFeed($feedurl, $folderid) {
$feedmapper = new OCA\News\FeedMapper();
$feedid = $feedmapper->findIdFromUrl($feedurl);
$l = OC_L10N::get('news');
if ($feedid === null) {
$feed = OCA\News\Utils::fetch($feedurl);
if ($feed !== null) {
$feedid = $feedmapper->save($feed, $folderid);
}
} else {
OCP\Util::writeLog('news','ajax/createfeed.php: Error adding feed: '. $feedurl, OCP\Util::ERROR);
return false;
}
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 Feed) {
$feedurl = $collection->getUrl();
$folderid = 0;
if (createFeed($feedurl, $folderid)) {
$countadded++;
}
}
}
// // $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)));

View File

@ -1,7 +1,8 @@
<?php
include("populateroot.php");
$foldermapper = new OCA\News\FolderMapper(OCP\USER::getUser());
$folderforest = $foldermapper->childrenOf(0); //retrieve all the folders
$output = new OCP\Template("news", "part.feeddialog");
$output->assign('allfeeds', $allfeeds);
$output->assign('folderforest', $folderforest);
$output->printpage();

View File

@ -1,7 +1,8 @@
<?php
include("populateroot.php");
$foldermapper = new OCA\News\FolderMapper(OCP\USER::getUser());
$folderforest = $foldermapper->childrenOf(0); //retrieve all the folders
$output = new OCP\Template("news", "part.folderdialog");
$output->assign('allfeeds', $allfeeds);
$output->assign('folderforest', $folderforest);
$output->printpage();

View File

@ -1,21 +0,0 @@
<?php
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
$foldermapper = new OCA\News\FolderMapper(OCP\USER::getUser());
$l = new OC_l10n('news');
$folder = new OCA\News\Folder($l->t('Everything'), 0);
$allfeeds = $foldermapper->populate($folder);
if ($allfeeds) {
$feedid = isset( $_GET['feedid'] ) ? $_GET['feedid'] : null;
if ($feedid == null) {
}
}
else {
$feedid = 0;
}

View File

@ -10,6 +10,7 @@
*
*/
OC::$CLASSPATH['OCA\News\StatusFlag'] = 'apps/news/lib/item.php';
OC::$CLASSPATH['OCA\News\Item'] = 'apps/news/lib/item.php';
OC::$CLASSPATH['OCA\News\Collection'] = 'apps/news/lib/collection.php';
OC::$CLASSPATH['OCA\News\Feed'] = 'apps/news/lib/feed.php';

View File

@ -34,6 +34,9 @@ div.collapsable:hover { background-color: rgb(221, 221, 221); }
.unreaditemcounter.nonzero { position: relative; background: #5E5E5E; border-radius: 5px; padding: 0 5px; color: white; text-align: center; margin: 0 0.3em 0 0.3em;}
.unreaditemcounter.zero { position: relative; margin: 0 0.3em 0 0; }
/* when there are no feeds in the db */
#firstrun { width: 100%; position: absolute; top: 5em; left: 0; text-align: center; font-weight:bold; font-size:1.5em; color:#777; }
#firstrun #selections { font-size:0.8em; margin: 2em auto auto auto; clear: both; }
/* feed controls */
#addfolder { background: url('%webroot%/core/img/places/folder.svg') no-repeat left center; padding-left: 20px !important; }

View File

@ -27,9 +27,8 @@ $userid = OCP\USER::getUser();
$foldermapper = new OCA\News\FolderMapper($userid);
$folder = new OCA\News\Folder($l->t('Everything'), 0);
$allfeeds = $foldermapper->populate($folder);
$allfeeds = $foldermapper->childrenOfWithFeeds(0); //$foldermapper->populate($folder);
$folderforest = $foldermapper->childrenOf(0); //retrieve all the folders
if ($allfeeds) {
$feedid = isset( $_GET['feedid'] ) ? $_GET['feedid'] : null;
@ -44,6 +43,7 @@ else {
$tmpl = new OCP\Template( 'news', 'main', 'user' );
$tmpl->assign('allfeeds', $allfeeds);
$tmpl->assign('folderforest', $folderforest);
$tmpl->assign('feedid', $feedid);
$tmpl->printPage();

View File

@ -80,13 +80,13 @@ class FeedMapper {
}
/**
* @brief Retrieve a feed from the database
* @param id The id of the feed in the database table.
* @returns an instance of OC_News_Feed
* @brief Retrieve all the feeds contained in the folder $folderid
* @param folderid The id of the folder in the database table.
* @returns a list of feeds
*/
public function findByFolderId($folderid){
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE folder_id = ?');
$result = $stmt->execute(array($folderid));
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE user_id = ? AND folder_id = ?');
$result = $stmt->execute(array($this->userid, $folderid));
$feeds = array();
while ($row = $result->fetchRow()) {
$url = $row['url'];

View File

@ -29,33 +29,54 @@ class FolderMapper {
}
/**
* @brief Create a folder and populate with children from the database
* @param folder The folder to be populated.
* @returns an instance of OC_News_Folder
* @brief Returns the forest (list of trees) of folders children of $parentid
* @param
* @returns
*/
public function populate($folder){
// first add child feeds
$feedmapper = new FeedMapper();
$feeds = $feedmapper->findByFolderId($folder->getId());
foreach ($feeds as $feed){
$folder->addChild($feed);
}
// and second child folders
$stmt = \OCP\DB::prepare('SELECT *
FROM ' . self::tableName .
public function childrenOf($parentid) {
$folderlist = array();
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName .
' WHERE user_id = ? AND parent_id = ?');
$result = $stmt->execute(array($this->userid, $folder->getId()));
$result = $stmt->execute(array($this->userid, $parentid));
while( $row = $result->fetchRow()){
$unpopfolder = new Folder($row['name'], $row['id']);
$popfolder = self::populate($unpopfolder);
$folder->addChild($popfolder);
$folderid = $row['id'];
$folder = new Folder($row['name'], $folderid);
$children = self::childrenOf($folderid);
$folder->addChildren($children);
$folderlist[] = $folder;
}
return $folder;
return $folderlist;
}
/**
* @brief Returns the forest (list of trees) of folders children of $parentid,
* including the feeds that they contain
* @param
* @returns
*/
public function childrenOfWithFeeds($parentid) {
$feedmapper = new FeedMapper();
$collectionlist = $feedmapper->findByFolderId($parentid);
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName .
' WHERE user_id = ? AND parent_id = ?');
$result = $stmt->execute(array($this->userid, $parentid));
while( $row = $result->fetchRow()){
$folderid = $row['id'];
$folder = new Folder($row['name'], $folderid);
$children = self::childrenOf($folderid);
$folder->addChildren($children);
$collectionlist[] = $folder;
}
return $collectionlist;
}
/**
* @brief Retrieve a folder from the database
* @param id The id of the folder in the database table.
@ -73,26 +94,6 @@ class FolderMapper {
return $folder;
}
/**
* @brief Retrieve a feed and all its items from the database
* @param id The id of the feed in the database table.
* @returns
*/
public function findWithItems($id){
$stmt = \OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?');
$result = $stmt->execute(array($id));
$row = $result->fetchRow();
$url = $row['url'];
$title = $row['title'];
$feed = new Feed($url, $title, null,$id);
$itemMapper = new ItemMapper($feed);
$items = $itemMapper->findAll();
$feed->setItems($items);
return $feed;
}
/**
* @brief Store the folder and all its feeds into the database
* @param folder the folder to be saved

35
opmlexporter.php Normal file
View File

@ -0,0 +1,35 @@
<?php
/**
* ownCloud - News app
*
* @author Alessandro Cosentino
* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/
class OPMLExporter {
public static function feedToXML(OCA\News\Feed $feed){
}
/**
* @brief
*/
public static function export(OCA\News\Collection $data){
foreach($children as $child) {
if ($child instanceOf OCA\News\Folder){
}
elseif ($child instanceOf OCA\News\Feed) { //onhover $(element).attr('id', 'newID');
}
else {
//TODO:handle error in this case
}
}
}
}

View File

@ -99,5 +99,4 @@ class OPMLParser {
return null;
}
}
}

View File

@ -1,3 +1,11 @@
<!-- Dialogs -->
<div id="dialog_holder"></div>
<!-- End of Dialogs -->
<?php
if ($_['feedid']){
?>
<div id="leftcontent" class="leftcontent">
<ul id="feeds">
<?php echo $this->inc("part.feeds"); ?>
@ -26,20 +34,16 @@
<div id="rightcontent" class="rightcontent" data-id="<?php echo $_['feedid']; ?>">
<?php
if ($_['feedid']){
echo $this->inc("part.items.header");
echo $this->inc("part.items");
}
else {
echo $this->inc("part.nofeeds");
}
?>
<div id="appsettings" class="popup bottomleft hidden"></div>
</div>
<!-- Dialogs -->
<div id="dialog_holder"></div>
<!-- End of Dialogs -->
<?php
} else {
echo $this->inc("part.nofeeds");
}
?>

View File

@ -6,7 +6,7 @@
<td>
<div class="add_parentfolder">
<button id="dropdownBtn" onclick="News.DropDownMenu.dropdown(this)">
<?php echo $l->t('Subscriptions'); ?>
<?php echo $l->t('Choose folder'); ?>
</button>
<input id="inputfolderid" type="hidden" name="folderid" value="0" />
<ul class="menu" id="dropdownmenu">

View File

@ -1,26 +1,26 @@
<?php
function print_folder(OCA\News\Folder $folder){
$tmpl_folder = new OCP\Template("news", "part.listfolder");
$tmpl_folder->assign('folder', $folder);
$tmpl_folder->printpage();
$children = $folder->getChildren();
foreach($children as $child) {
if ($child instanceOf OCA\News\Folder){
print_folder($child);
function print_collection_list($list) {
foreach($list as $collection) {
if ($collection instanceOf OCA\News\Folder){
$tmpl_folder = new OCP\Template("news", "part.listfolder");
$tmpl_folder->assign('folder', $collection);
$tmpl_folder->printpage();
print_collection_list($collection->getChildren());
echo '</ul></li>';
}
elseif ($child instanceOf OCA\News\Feed) { //onhover $(element).attr('id', 'newID');
elseif ($collection instanceOf OCA\News\Feed) { //onhover $(element).attr('id', 'newID');
$itemmapper = new OCA\News\ItemMapper();
$items = $itemmapper->findAll($child->getId());
$items = $itemmapper->findAll($collection->getId());
$counter = 0;
foreach($items as $item) {
if(!$item->isRead())
++$counter;
}
$tmpl_feed = new OCP\Template("news", "part.listfeed");
$tmpl_feed->assign('child', $child);
$tmpl_feed->assign('feed', $collection);
$tmpl_feed->assign('unreadItems',$counter);
$tmpl_feed->printpage();
}
@ -28,12 +28,9 @@
//TODO:handle error in this case
}
}
echo '</ul></li>';
}
$allfeeds = isset($_['allfeeds']) ? $_['allfeeds'] : '';
?>
<?php
print_folder($allfeeds);
?>
print_collection_list($allfeeds);

View File

@ -6,7 +6,7 @@
<td>
<div class="add_parentfolder">
<button id="dropdownBtn" onclick="News.DropDownMenu.dropdown(this)">
<?php echo $l->t('Subscriptions'); ?>
<?php echo $l->t('Choose folder'); ?>
</button>
<input id="inputfolderid" type="hidden" name="folderid" value="0" />
<ul class="menu" id="dropdownmenu">

View File

@ -1,13 +1,13 @@
<?php
function print_folder(OCA\News\Folder $folder, $depth){
echo '<li style="margin-left:' . 10*$depth . 'px;" class="menuItem" onclick="News.DropDownMenu.selectItem(this, ' . $folder->getId() . ')">' . $folder->getName() . '</li>';
$children = $folder->getChildren();
foreach($children as $child) {
if ($child instanceOf OCA\News\Folder){
print_folder($child, $depth+1);
}
function print_folder_list($folderlist, $depth) {
foreach($folderlist as $folder) {
echo '<li style="margin-left:' . 10*$depth . 'px;" class="menuItem" onclick="News.DropDownMenu.selectItem(this, ' . $folder->getId() . ')">' . $folder->getName() . '</li>';
$children = $folder->getChildren();
print_folder_list($children, $depth+1);
}
}
print_folder($_['allfeeds'], 0);
print_folder_list($_['folderforest'], 0);
?>

View File

@ -2,16 +2,16 @@
$l = new OC_l10n('news');
$child = isset($_['child']) ? $_['child'] : null;
$feed = isset($_['feed']) ? $_['feed'] : null;
$unreadItems = isset($_['unreadItems']) ? $_['unreadItems'] : null;
$favicon = $child->getFavicon();
$favicon = $feed->getFavicon();
if ($favicon == null) {
$favicon = OCP\Util::imagePath('news', 'rss.svg');
}
echo '<li class="feed" data-id="' . $child->getId() . '">';
echo '<li class="feed" data-id="' . $feed->getId() . '">';
echo '<a href="#" style="background: url(' . $favicon . ') left center no-repeat; background-size:16px 16px;" class="' .
(($unreadItems > 0) ? 'nonzero' : 'zero') . '">' . $child->getTitle() .'</a>';
(($unreadItems > 0) ? 'nonzero' : 'zero') . '">' . $feed->getTitle() .'</a>';
if ($unreadItems > 0) {
echo '<span class="unreaditemcounter nonzero">' . $unreadItems . '</span>';
}
@ -19,5 +19,5 @@ else {
echo '<span class="unreaditemcounter zero"></span>';
}
echo '<button class="svg action feeds_edit" title="' . $l->t('Edit feed') . '"></button>';
echo '<button class="svg action feeds_delete" onClick="(News.Feed.delete(' . $child->getId(). '))" title="' . $l->t('Delete feed') . '"></button>';
echo '<button class="svg action feeds_delete" onClick="(News.Feed.delete(' . $feed->getId(). '))" title="' . $l->t('Delete feed') . '"></button>';
echo '</li>';

View File

@ -1,3 +1,8 @@
<div id="appsettings" class="popup bottomleft hidden"></div>
<div id="firstrun">
<?php echo $l->t('You have no feeds in your reader.') ?>
<div id="selections">
<input type="button" id="addfeed" value="<?php echo $l->t('Add feed') ?>" />
<input type="button" value="<?php echo $l->t('Import OPML') ?>" />
</div>
</div>

View File

@ -1,18 +1,9 @@
<?php
$content = file_get_contents('/tmp/occOrigzvXqKO');
$itemmapper = new OCA\News\ItemMapper();
require_once('news/opmlparser.php');
$items = $itemmapper->findAllStatus(155, OCA\News\StatusFlag::Unread);
$parser = new OPMLParser($content);
$title = $parser->getTitle();
$data = $parser->parse();
foreach ($data as $collection) {
if ($collection instanceof OCA\News\Feed) {
echo $collection->getTitle() . '\n';
} else {
echo 'NO\n';
}
}
echo $title;
foreach ($items as $item) {
echo $item->getTitle();
}