summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurice Svay <maurice@svay.com>2012-02-29 01:58:06 -0800
committerMaurice Svay <maurice@svay.com>2012-02-29 01:58:06 -0800
commit4122a59905d0ab123f7c867e339e46539f7b41a8 (patch)
tree43ad73a8c9487bda19d85d2ecabf653084b6c285
parent77d669315ed80947b23537284380e2b914c052b2 (diff)
parent93e7b8c890535549793f8206a584cbdf0df91950 (diff)
downloadplanet-4122a59905d0ab123f7c867e339e46539f7b41a8.tar
planet-4122a59905d0ab123f7c867e339e46539f7b41a8.tar.gz
planet-4122a59905d0ab123f7c867e339e46539f7b41a8.tar.bz2
planet-4122a59905d0ab123f7c867e339e46539f7b41a8.tar.xz
planet-4122a59905d0ab123f7c867e339e46539f7b41a8.zip
Merge pull request #12 from pascalchevrel/ConvertPHP4code
convert OpmlManager class to PHP5 syntax and make the load() function static
-rw-r--r--app/lib/lib.opml.php130
1 files changed, 65 insertions, 65 deletions
diff --git a/app/lib/lib.opml.php b/app/lib/lib.opml.php
index 8670f5e..21890d2 100644
--- a/app/lib/lib.opml.php
+++ b/app/lib/lib.opml.php
@@ -1,90 +1,91 @@
-<?php
-class opml
-{
+<?php
+class opml
+{
var $_xml = null;
var $_currentTag = '';
- var $title = '';
- var $entries = array();
- var $map =
- array(
- 'URL' => 'website',
- 'HTMLURL' => 'website',
- 'TEXT' => 'name',
- 'TITLE' => 'name',
- 'XMLURL' => 'feed',
- 'DESCRIPTION' => 'description'
- );
-
-
- function parse($data)
- {
- $this->_xml = xml_parser_create('UTF-8');
+ var $title = '';
+ var $entries = array();
+ var $map =
+ array(
+ 'URL' => 'website',
+ 'HTMLURL' => 'website',
+ 'TEXT' => 'name',
+ 'TITLE' => 'name',
+ 'XMLURL' => 'feed',
+ 'DESCRIPTION' => 'description'
+ );
+
+
+ function parse($data)
+ {
+ $this->_xml = xml_parser_create('UTF-8');
//xml_parser_set_option($this->_xml, XML_OPTION_CASE_FOLDING, false);
- //xml_parser_set_option($this->_xml, XML_OPTION_SKIP_WHITE, true);
- xml_set_object($this->_xml, $this);
+ //xml_parser_set_option($this->_xml, XML_OPTION_SKIP_WHITE, true);
+ xml_set_object($this->_xml, $this);
xml_set_element_handler($this->_xml,'_openTag','_closeTag');
- xml_set_character_data_handler ($this->_xml, '_cData');
-
- xml_parse($this->_xml,$data);
- xml_parser_free($this->_xml);
- return $this->entries;
- }
-
-
- function _openTag($p,$tag,$attrs)
+ xml_set_character_data_handler ($this->_xml, '_cData');
+
+ xml_parse($this->_xml,$data);
+ xml_parser_free($this->_xml);
+ return $this->entries;
+ }
+
+
+ function _openTag($p,$tag,$attrs)
{
$this->_currentTag = $tag;
-
- if ($tag == 'OUTLINE')
- {
- $i = count($this->entries);
- foreach (array_keys($this->map) as $key)
- {
- if (isset($attrs[$key])) {
- $this->entries[$i][$this->map[$key]] = $attrs[$key];
- }
- }
- }
+
+ if ($tag == 'OUTLINE')
+ {
+ $i = count($this->entries);
+ foreach (array_keys($this->map) as $key)
+ {
+ if (isset($attrs[$key])) {
+ $this->entries[$i][$this->map[$key]] = $attrs[$key];
+ }
+ }
+ }
}
-
+
function _closeTag($p, $tag){
$this->_currentTag = '';
}
-
+
function _cData($p, $cdata){
if ($this->_currentTag == 'TITLE'){
$this->title = $cdata;
}
}
-
+
function getTitle(){
return $this->title;
}
-
+
function getPeople(){
return $this->entries;
- }
-}
-
-class OpmlManager {
- function load($file) {
- if (@file_exists($file)) {
+ }
+}
+
+class OpmlManager
+{
+ public function load($file) {
+ if (@file_exists($file)) {
$opml = new opml();
-
+
//Remove BOM if needed
$BOM = '/^/';
$fileContent = file_get_contents($file);
$fileContent = preg_replace($BOM, '', $fileContent, 1);
-
+
//Parse
- $opml->parse($fileContent);
-
- return $opml;
- }
+ $opml->parse($fileContent);
+
+ return $opml;
+ }
}
-
- function save($opml, $file){
+
+ public function save($opml, $file){
$out = '<?xml version="1.0"?>'."\n";
$out.= '<opml version="1.1">'."\n";
$out.= '<head>'."\n";
@@ -98,12 +99,11 @@ class OpmlManager {
}
$out.= '</body>'."\n";
$out.= '</opml>';
-
+
file_put_contents($file, $out);
}
-
- function backup($file){
+
+ public function backup($file){
copy($file, $file.'.bak');
- }
-}
-?>
+ }
+}