parses opml file to get the title

This commit is contained in:
Alessandro Cosentino 2012-07-30 02:24:38 -04:00
Родитель 0812aadc7b
Коммит a5438863a4
3 изменённых файлов: 47 добавлений и 7 удалений

Просмотреть файл

@ -22,17 +22,25 @@ function bailOut($msg) {
OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::ERROR);
exit();
}
function debug($msg) {
OCP\Util::writeLog('news','ajax/importopml.php: '.$msg, OCP\Util::DEBUG);
}
if(!isset($_GET['path'])) {
bailOut($l->t('No file path was submitted.'));
}
}
require_once('news/opmlparser.php');
$parser = new OPMLParser();
$raw = file_get_contents($_GET['path']);
$parser = new OPMLParser($raw);
$title = $parser->getTitle();
$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");

Просмотреть файл

@ -98,9 +98,11 @@ News={
} else {
}
$.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path}, function(jsondata){
OC.dialogs.alert(jsondata.data.message, t('news', 'Success!'));
$.getJSON(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){
if (jsondata.status == 'success') {
alert(jsondata.data.title);
}
});
}

Просмотреть файл

@ -1,13 +1,36 @@
<?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 OPMLParser {
public $raw;
public $data;
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;
$this->body = $xml_parser->body;
}
catch (Exception $e) {
$this->error = $e->getMessage();
return;
}
}
public function parse(){
@ -19,4 +42,11 @@ class OPMLParser {
return $this->data;
}
public function getTitle() {
return $this->title;
}
public function getError() {
return $this->error;
}
}