Skip to content

Commit

Permalink
* new opml import
Browse files Browse the repository at this point in the history
* prepare version 2.2
  • Loading branch information
SSilence committed Mar 14, 2013
1 parent 8a84ced commit bf28da8
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 126 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ UPDATE
7. insert your current database connection and your individual configuration in config.ini. Important: we change the config.ini and add new options in newer versions. You have to update the config.ini too.


OPML Import
-----------

Visit the page http://<selfoss url>/opml for importing your OPML File. If you are a user of the google reader then use https://www.google.com/takeout/ to get all your feeds in an opml file.


CHANGELOG
---------

Version 2.2-SNAPSHOT
Version 2.2
* update fat free php Framework to 3.0.5
* new opml import page (thanks a lot to Michael Moore)

Version 2.1
* security bugfix
Expand Down
11 changes: 9 additions & 2 deletions _docs/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 id="header-name"><span>selfoss</span></h1>
<li class="screenshots">screenshots</li>
<li class="documentation">documentation</li>
<li class="about">about</li>
<li class="download"><a href="selfoss-2.1.zip">download</a></li>
<li class="download"><a href="selfoss-2.2.zip">download</a></li>
</ul>

<a id="header-fork" href="https://github.com/SSilence/selfoss"></a>
Expand All @@ -34,7 +34,7 @@ <h1 id="header-name"><span>selfoss</span></h1>

<div id="header-just-updated"></div>

<a id="header-download" href="selfoss-2.1.zip"><span>download selfoss 2.1</span></a>
<a id="header-download" href="selfoss-2.2.zip"><span>download selfoss 2.2</span></a>

<a id="header-donate" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LR67F3T9DMSC8"><span>donate</span></a>

Expand All @@ -54,6 +54,7 @@ <h2>Features</h2>
<li>use selfoss to live stream and collect all your posts, tweets, feeds in one place</li>
<li>lightweight PHP application with less than 2 MB</li>
<li>supports MySQL and Sqlite Databases</li>
<li>OPML Import</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -117,6 +118,12 @@ <h2>Update</h2>
</ol>
</div>

<h2>Import your feeds from Google Reader (OPML File)</h2>
<div class="documentation-entry">
Visit the page http://<selfoss url>/opml for importing your OPML File.
If you are a user of the google reader then use https://www.google.com/takeout/ to get all your feeds in an opml file.
</div>

<h2>Configuration</h2>
<div class="documentation-entry">
<p>selfoss offers the following configuration parameters. You can set the config parameters in the <code>config.ini</code> file.</p>
Expand Down
207 changes: 121 additions & 86 deletions controllers/Opml.php
Original file line number Diff line number Diff line change
@@ -1,116 +1,151 @@
<?php
/**
* @author Michael Moore <[email protected]>
* @license GPLv3
* Simple Opml loading controller
*
* @package controllers
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
* @author Michael Moore <[email protected]>
*/

namespace controllers;

class Opml extends BaseController{
/**
* @classA simple Opml loading controller
*/

var $msgclass = 'error'; // Passed to opml.phtml
var $msg; // Passed to opml.phtml
class Opml extends BaseController {

/**
* Passed to opml.phtml
* @var String
*/
var $msgclass = 'error';

/**
* Passed to opml.phtml
* @var String
*/
var $msg;


/**
* @brief Shows a simple html form
* Shows a simple html form
*/
function show(){
$this->view = new \helpers\View();
$this->view->msg = $this->msg;
$this->view->msgclass = $this->msgclass;
echo $this->view->render('templates/opml.phtml');
$this->view = new \helpers\View();
$this->view->msg = $this->msg;
$this->view->msgclass = $this->msgclass;
echo $this->view->render('templates/opml.phtml');
}



/**
* @brief Add an Opml to the user's subscriptions
* Add an Opml to the user's subscriptions
* @note Borrows from controllers/Sources.php:write
*/
function add(){
try {
if(!array_key_exists('opml',$_FILES)){
throw new Exception("No file uploaded!");
}
$opml = $_FILES['opml'];
if(!$opml['type'] == 'text/xml'){
throw new Exception("Unsupported file type!: " . $opml['type']);
}
try {
if(!array_key_exists('opml',$_FILES)){
throw new Exception("No file uploaded!");
}
$opml = $_FILES['opml'];
if(!$opml['type'] == 'text/xml'){
throw new Exception("Unsupported file type!: " . $opml['type']);
}

$this->sourcesDao = new \daos\Sources();
$this->tagsDao = new \daos\Tags();
$this->sourcesDao = new \daos\Sources();
$this->tagsDao = new \daos\Tags();

$subs = simplexml_load_file($opml['tmp_name']);
$subs = $subs->body;
$errors = $this->processGroup($subs);
if(count($errors) > 1){
$this->msg = "The following feeds were not added:<br>";
$this->msg .= implode("<br>",$errors);
$this->show();
}else{
// On success bring them back to their subscription list
$this->msg = "Success! You might want to <a href='update'>Update now</a> or <a href='./'>view your feeds</a>.";
$this->msgclass = 'success';
$this->show();
}
}catch (Exception $e){
$this->msg = "</p>There was a problem importing your OPML file: <p>";
$this->msg .= $e->getMessage();
$this->show();
}
\F3::get('logger')->log('start opml import ', \DEBUG);
$subs = simplexml_load_file($opml['tmp_name']);
$subs = $subs->body;
$errors = $this->processGroup($subs);

// show errors
if(count($errors) > 1){
$this->msg = "The following feeds were not added:<br>";
$this->msg .= implode("<br>",$errors);
$this->show();

// On success bring them back to their subscription list
} else {
$this->msg = "Success! You might want to <a href='update'>Update now</a> or <a href='./'>view your feeds</a>.";
$this->msgclass = 'success';
$this->show();
}
} catch (Exception $e){
$this->msg = "</p>There was a problem importing your OPML file: <p>";
$this->msg .= $e->getMessage();
$this->show();
}
}



/**
* @brief Process a group of outlines
* Process a group of outlines
* @param $xml (SimpleXML) A SimpleXML object with <outline> children
* @param $tags (Array) An array of tags for the current <outline>
* @note Recursive
* @note We use non-rss outline's text as tags
*/
function processGroup($xml,$tags = Array()){
$errors = Array();
if((string)$xml['title']){
$tags[] = (string)$xml['title'];
}
foreach($xml->outline as $outline){
if((string)$outline['type']){
$ret = $this->addSubscription($outline,$tags);
if($ret!==TRUE)
$errors[] = $ret;
}else{
$ret = $this->processGroup($outline,$tags);
$errors = array_merge($errors,$ret);
}
}
return $errors;
$errors = Array();

// tags are the words of the outline parent
if((string)$xml['title']){
$tags[] = (string)$xml['title'];
}

// parse every outline item
foreach($xml->outline as $outline){
if((string)$outline['type']) {
$ret = $this->addSubscription($outline,$tags);
if($ret!==true) {
$errors[] = $ret;
}
} else {
$ret = $this->processGroup($outline,$tags);
$errors = array_merge($errors,$ret);
}
}
return $errors;
}


/**
* Add new feed subscription
* @return true on success or item title on error
* @param $xml xml feed entry for item
* @param $tags of the entry
*/
function addSubscription($xml, $tags){
// OPML Required attributes: text,xmlUrl,type
// Optional attributes: title, htmlUrl, language, title, version

// description
$title = (string)$xml['text'];

// RSS URL
$data['url'] = (string)$xml['xmlUrl'];

function addSubscription($xml,$tags){
// OPML Required attributes: text,xmlUrl,type
// Optional attributes: title, htmlUrl, language, title, version
$title = (string)$xml['text']; // description
$data['url'] = (string)$xml['xmlUrl']; // RSS URL

if($xml['type'] == 'rss'){
$spout = 'spouts\rss\feed';
}

$validation = $this->sourcesDao->validate($title, $spout, $data);

if($validation!==true)
return $title;

$tags = implode(',',$tags);
error_log("Tags are: $tags");
$id = $this->sourcesDao->add($title, $tags, $spout, $data);
$tags = explode(",",$tags);
foreach($tags as $tag)
$this->tagsDao->autocolorTag(trim($tag));
if($xml['type'] == 'rss')
$spout = 'spouts\rss\feed';

// validate new item
$validation = $this->sourcesDao->validate($title, 'spouts\rss\feed', $data);
if($validation!==true) {
\F3::get('logger')->log('opml import: invalid item ' . $title, \DEBUG);
return $title;
}

// cleanup tags
$this->tagsDao->cleanup($this->sourcesDao->getAllTags());
// import tags
$tags = implode(',',$tags);
$id = $this->sourcesDao->add($title, $tags, $spout, $data);
$tags = explode(",",$tags);
foreach($tags as $tag)
$this->tagsDao->autocolorTag(trim($tag));

// cleanup tags
$this->tagsDao->cleanup($this->sourcesDao->getAllTags());

return TRUE;
// success
\F3::get('logger')->log('opml import: item successfully imported: ' . $title, \DEBUG);
return true;
}
}
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$f3 = require(__DIR__.'/libs/f3/base.php');

$f3->set('DEBUG',0);
$f3->set('version','2.2-SNAPSHOT');
$f3->set('version','2.2');
$f3->set('AUTOLOAD',__dir__.'/;libs/f3/;libs/;libs/WideImage/;daos/;libs/twitteroauth/;libs/FeedWriter/');
$f3->set('cache',__dir__.'/data/cache');
$f3->set('BASEDIR',__dir__);
Expand Down
7 changes: 6 additions & 1 deletion public/css/opml.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#opmlbody {
height:auto;
}

#opml {
margin-left: auto;
margin-right: auto;
Expand Down Expand Up @@ -34,7 +38,7 @@

#opml .button input {
margin-left:7px;
padding:5px;
padding:9px;
margin-top: 30px;
font-size:1.2em;
}
Expand All @@ -46,4 +50,5 @@

#opml input {
margin-top: 30px;
background:white;
}
2 changes: 1 addition & 1 deletion templates/login.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<li><h1>hash generator</h1></li>
<li><label>Password:</label> <input type="password" name="password" /></li>
<?PHP if(isset($this->hash)) : ?>
<li class="error"><label>&nbsp;</label>Generated Passwort (insert this in config.ini): <input type="text" id="hash" value="<?PHP echo $this->hash; ?>" /></li>
<li class="error"><label>&nbsp;</label>Generated Password (insert this in config.ini): <input type="text" id="hash" value="<?PHP echo $this->hash; ?>" /></li>
<?PHP endif; ?>
<li><label>&nbsp;</label><input class="button" type="submit" value="generate password" /></li>
</ul>
Expand Down
Loading

0 comments on commit bf28da8

Please sign in to comment.