Atomlib
Atomlib
php Page 1 of 7
<?php
/**
* Atom Syndication Format PHP Library
*
* @package AtomLib
* @link http://code.google.com/p/phpatomlib/
*
* @author Elias Torres <[email protected]>
* @version 0.4
* @since 2.3.0
*/
/**
* Structure that store common Atom Feed Properties
*
* @package AtomLib
*/
class AtomFeed {
/**
* Stores Links
* @var array
* @access public
*/
var $links = array();
/**
* Stores Categories
* @var array
* @access public
*/
var $categories = array();
/**
* Stores Entries
*
* @var array
* @access public
*/
var $entries = array();
}
/**
* Structure that store Atom Entry Properties
*
* @package AtomLib
*/
class AtomEntry {
/**
* Stores Links
* @var array
* @access public
*/
var $links = array();
/**
* Stores Categories
* @var array
* @access public
*/
var $categories = array();
}
/**
* AtomLib Atom Parser API
*
* @package AtomLib
*/
class AtomParser {
File: /home/fran/WordPress/wp-includes/atomlib.php Page 2 of 7
var $depth = 0;
var $indent = 2;
var $in_content;
var $ns_contexts = array();
var $ns_decls = array();
var $content_ns_decls = array();
var $content_ns_contexts = array();
var $is_xhtml = false;
var $is_html = false;
var $is_text = true;
var $skipped_div = false;
var $feed;
var $current;
/**
* PHP5 constructor.
*/
function __construct() {
/**
* PHP4 constructor.
*/
public function AtomParser() {
self::__construct();
}
/**
* Map attributes to key="val"
*
* @param string $k Key
* @param string $v Value
* @return string
*/
public static function map_attrs($k, $v) {
return "$k=\"$v\"";
}
/**
* Map XML namespace to string.
*
* @param indexish $p XML Namespace element index
* @param array $n Two-element array pair. [ 0 => {namespace}, 1 => {url} ]
* @return string 'xmlns="{url}"' or 'xmlns:{namespace}="{url}"'
*/
public static function map_xmlns($p, $n) {
$xd = "xmlns";
if( 0 < strlen($n[0]) ) {
$xd .= ":{$n[0]}";
}
return "{$xd}=\"{$n[1]}\"";
}
File: /home/fran/WordPress/wp-includes/atomlib.php Page 3 of 7
function _p($msg) {
if($this->debug) {
print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n";
}
}
function parse() {
set_error_handler(array(&$this, 'error_handler'));
array_unshift($this->ns_contexts, array());
if ( ! function_exists( 'xml_parser_create_ns' ) ) {
trigger_error( __( "PHP's XML extension is not available. Please contact
your hosting provider to enable PHP's XML extension." ) );
return false;
}
$parser = xml_parser_create_ns();
xml_set_object($parser, $this);
xml_set_element_handler($parser, "start_element", "end_element");
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_set_character_data_handler($parser, "cdata");
xml_set_default_handler($parser, "_default");
xml_set_start_namespace_decl_handler($parser, "start_ns");
xml_set_end_namespace_decl_handler($parser, "end_ns");
$this->content = '';
$ret = true;
xml_parser_free($parser);
unset($parser);
restore_error_handler();
return $ret;
}
switch($name) {
File: /home/fran/WordPress/wp-includes/atomlib.php Page 4 of 7
$this->_p("start_element('$name')");
#$this->_p(print_r($this->ns_contexts,true));
#$this->_p('current(' . $this->current . ')');
array_unshift($this->ns_contexts, $this->ns_decls);
$this->depth++;
if(!empty($this->in_content)) {
$this->content_ns_decls = array();
if($this->is_html || $this->is_text)
trigger_error("Invalid content in element found. Content must not be of
type text or html if it contains markup.");
$attrs_prefix = array();
$with_prefix = $this->ns_to_prefix($name);
if(!$this->is_declared_content_ns($with_prefix[0])) {
array_push($this->content_ns_decls, $with_prefix[0]);
}
$xmlns_str = '';
if(count($this->content_ns_decls) > 0) {
array_unshift($this->content_ns_contexts, $this->content_ns_decls);
$xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this-
>content_ns_contexts[0]), array_values($this->content_ns_contexts[0])));
if(strlen($xmlns_str) > 0) {
$xmlns_str = " " . $xmlns_str;
}
}
if(in_array('src',array_keys($attrs))) {
$this->current->$tag = $attrs;
} else {
array_push($this->in_content, array($tag,$this->depth, $type));
}
} else if($tag == 'link') {
array_push($this->current->links, $attrs);
} else if($tag == 'category') {
array_push($this->current->categories, $attrs);
}
$this->ns_decls = array();
}
$ccount = count($this->in_content);
array_shift($this->ns_contexts);
$this->depth--;
$this->_p("end_element('$name')");
}
if(!empty($components)) {
# re-join back the namespace component
$ns = join(":",$components);
foreach($this->ns_contexts as $context) {
foreach($context as $mapping) {
if($mapping[1] == $ns && strlen($mapping[0]) > 0) {
return array($mapping, "$mapping[0]:$name");
}
}
}
}
if($attr) {
return array(null, $name);
} else {
foreach($this->ns_contexts as $context) {
foreach($context as $mapping) {
if(strlen($mapping[0]) == 0) {
return array($mapping, $name);
}
}
}
}
}
function is_declared_content_ns($new_mapping) {
foreach($this->content_ns_contexts as $context) {
foreach($context as $mapping) {
if($new_mapping == $mapping) {
return true;
}
}
File: /home/fran/WordPress/wp-includes/atomlib.php Page 7 of 7
}
return false;
}
function xml_escape($content)
{
return str_replace(array('&','"',"'",'<','>'),
array('&','"',''','<','>'),
$content );
}
}