Updated Simple_HTML_Dom and fixed module XML to work with KH 3.3
This commit is contained in:
101
modules/xml/classes/XML/Driver/Atom.php
Normal file
101
modules/xml/classes/XML/Driver/Atom.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
/**
|
||||
* Document : atom.php
|
||||
* Created on : 1 mai 2009, 13:03:03
|
||||
* @author Cedric de Saint Leger <c.desaintleger@gmail.com>
|
||||
*
|
||||
* Description:
|
||||
* Atom driver
|
||||
*/
|
||||
|
||||
class XML_Driver_Atom extends XML
|
||||
{
|
||||
public $root_node = 'feed';
|
||||
|
||||
|
||||
protected static function initialize(XML_Meta $meta)
|
||||
{
|
||||
$meta ->content_type("application/atom+xml")
|
||||
->nodes (
|
||||
array(
|
||||
"feed" => array("namespace" => "http://www.w3.org/2005/Atom"),
|
||||
// "entry" => array("namespace" => "http://www.w3.org/2005/Atom"),
|
||||
"href" => array("filter" => "normalize_uri"),
|
||||
"link" => array("filter" => "normalize_uri"),
|
||||
"logo" => array("filter" => "normalize_uri"),
|
||||
"icon" => array("filter" => "normalize_uri"),
|
||||
"id" => array("filter" => "normalize_uri"),
|
||||
"updated" => array("filter" => "normalize_datetime"),
|
||||
"published" => array("filter" => "normalize_datetime"),
|
||||
"startDate" => array("filter" => "normalize_date"),
|
||||
'endDate' => array("filter" => "normalize_date"),
|
||||
"summary" => array("filter" => "normalize_text"),
|
||||
"subtitle" => array("filter" => "normalize_text"),
|
||||
"title" => array("filter" => "normalize_text"),
|
||||
"content" => array("filter" => "normalize_text")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function add_person($type, $name, $email = NULL, $uri = NULL)
|
||||
{
|
||||
$author = $this->add_node($type);
|
||||
$author->add_node("name", $name);
|
||||
if ($email)
|
||||
{
|
||||
$author->add_node("email", $email);
|
||||
}
|
||||
if ($uri)
|
||||
{
|
||||
$author->add_node("uri", $uri);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function add_content(XML $xml_document)
|
||||
{
|
||||
$this->add_node("content", NULL, array("type" => $xml_document->meta()->content_type()))->import($xml_document);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function normalize_text($value, $node)
|
||||
{
|
||||
if (strpos($value, "<") >= 0 AND strpos($value, ">") > 0)
|
||||
{
|
||||
// Assume type = html
|
||||
$node->setAttribute("type", "html");
|
||||
}
|
||||
else
|
||||
{
|
||||
$node->setAttribute("type", "text");
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
public function normalize_datetime($value)
|
||||
{
|
||||
if ( ! is_numeric($value))
|
||||
{
|
||||
$value = strtotime($value);
|
||||
}
|
||||
|
||||
// Convert timestamps to RFC 3339 formatted datetime
|
||||
return date(DATE_RFC3339, $value);
|
||||
}
|
||||
|
||||
|
||||
public function normalize_date($value)
|
||||
{
|
||||
if ( ! is_numeric($value))
|
||||
{
|
||||
$value = strtotime($value);
|
||||
}
|
||||
|
||||
// Convert timestamps to RFC 3339 formatted dates
|
||||
return date("Y-m-d", $value);
|
||||
}
|
||||
}
|
57
modules/xml/classes/XML/Driver/Rss2.php
Normal file
57
modules/xml/classes/XML/Driver/Rss2.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
/**
|
||||
* Document : rss2.php
|
||||
* Created on : 1 mai 2009, 13:03:03
|
||||
* @author Cedric de Saint Leger <c.desaintleger@gmail.com>
|
||||
*
|
||||
* Description:
|
||||
* RSS2 driver
|
||||
*/
|
||||
|
||||
class XML_Driver_Rss2 extends XML
|
||||
{
|
||||
public $root_node = 'rss';
|
||||
|
||||
protected static function initialize(XML_Meta $meta)
|
||||
{
|
||||
$meta ->content_type("application/rss+xml")
|
||||
->nodes (
|
||||
array(
|
||||
"rss" => array("attributes" => array("version" => "2.0")),
|
||||
"title" => array("filter" => "normalize_text"),
|
||||
"description" => array("filter" => "normalize_text"),
|
||||
"link" => array("filter" => "normalize_uri"),
|
||||
"atom:link" => array("attributes" => array(
|
||||
"rel" => "self",
|
||||
"type" => "application/rss+xml",
|
||||
// "href" => URL::site(Request::initial()->uri(), TRUE)
|
||||
),
|
||||
"namespace" => "http://www.w3.org/2005/Atom"),
|
||||
"href" => array("filter" => "normalize_uri"),
|
||||
"docs" => array("filter" => "normalize_uri"),
|
||||
"guid" => array("filter" => "normalize_uri"),
|
||||
"pubDate" => array("filter" => "normalize_date"),
|
||||
"lastBuildDate" => array("filter" => "normalize_date")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function normalize_date($value)
|
||||
{
|
||||
if ( ! is_numeric($value))
|
||||
{
|
||||
$value = strtotime($value);
|
||||
}
|
||||
|
||||
// Convert timestamps to RFC 822 formatted dates, with 4 digits year
|
||||
return date(DATE_RSS, $value);
|
||||
}
|
||||
|
||||
|
||||
public function normalize_text($value)
|
||||
{
|
||||
// Strip HTML tags
|
||||
return strip_tags($value);
|
||||
}
|
||||
}
|
55
modules/xml/classes/XML/Driver/Xrds.php
Normal file
55
modules/xml/classes/XML/Driver/Xrds.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
/**
|
||||
* Document : xrds.php
|
||||
* Created on : 1 mai 2009, 13:03:03
|
||||
* @author Cedric de Saint Leger <c.desaintleger@gmail.com>
|
||||
*
|
||||
* Description:
|
||||
* XRDS driver. For Service Discovery.
|
||||
*/
|
||||
|
||||
class XML_Driver_XRDS extends XML
|
||||
{
|
||||
public $root_node = 'xrds:XRDS';
|
||||
|
||||
protected static function initialize(XML_Meta $meta)
|
||||
{
|
||||
$meta ->content_type("application/xrds+xml")
|
||||
->nodes (
|
||||
array(
|
||||
"xrds:XRDS" => array("namespace" => 'xri://$xrds', "attributes" => array("xmlns" => 'xri://$xrd*($v*2.0)')),
|
||||
"LocalID" => array("filter" => "normalize_uri"),
|
||||
"openid:Delegate" => array("filter" => "normalize_uri", "namespace" => "http://openid.net/xmlns/1.0"),
|
||||
"URI" => array("filter" => "normalize_uri"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function add_service($type, $uri, $priority = NULL)
|
||||
{
|
||||
if (! is_null($priority))
|
||||
{
|
||||
$priority = array("priority" => $priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
$priority = array();
|
||||
}
|
||||
|
||||
$service_node = $this->add_node("Service", NULL, $priority);
|
||||
|
||||
if (! is_array($type))
|
||||
{
|
||||
$type = array($type);
|
||||
}
|
||||
|
||||
foreach ($type as $t)
|
||||
{
|
||||
$service_node->add_node("Type", $t);
|
||||
}
|
||||
$service_node->add_node("URI", $uri);
|
||||
|
||||
return $service_node;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user