2009-11-10 19:13:07 +00:00
|
|
|
<?php
|
2010-05-28 22:10:20 +00:00
|
|
|
/*
|
|
|
|
* e107 website system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
* e107 requires PHP >= 5 - implement functions only supported in later versions
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2009-11-10 19:13:07 +00:00
|
|
|
if (!defined('e107_INIT'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-05-28 22:10:20 +00:00
|
|
|
/**
|
|
|
|
* Handle system messages
|
|
|
|
*
|
|
|
|
* @package e107
|
|
|
|
* @subpackage e107_handlers
|
|
|
|
* @version $Id$
|
|
|
|
* @copyright Copyright (C) 2008-2010 e107 Inc (e107.org)
|
|
|
|
*/
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-05-28 22:10:20 +00:00
|
|
|
/*
|
2008-01-06 20:59:48 +00:00
|
|
|
// file_put_contents - introduced in PHP5
|
2008-01-20 04:46:35 +00:00
|
|
|
if (!function_exists('file_put_contents'))
|
2008-01-06 20:59:48 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
2009-11-10 19:13:07 +00:00
|
|
|
* @return int
|
|
|
|
* @param string $filename
|
|
|
|
* @param mixed $data
|
|
|
|
* @desc Write a string to a file
|
2010-05-28 22:10:20 +00:00
|
|
|
* /
|
2007-06-11 21:50:15 +00:00
|
|
|
define('FILE_APPEND', 1);
|
2008-01-20 04:46:35 +00:00
|
|
|
function file_put_contents($filename, $data, $flag = false)
|
2007-06-11 21:50:15 +00:00
|
|
|
{
|
2008-01-20 04:46:35 +00:00
|
|
|
$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
|
|
|
|
if (($h = @fopen($filename, $mode)) === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
if (is_array($data))
|
|
|
|
$data = implode($data);
|
2008-01-20 04:46:35 +00:00
|
|
|
if (($bytes = @fwrite($h, $data)) === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fclose($h);
|
|
|
|
return $bytes;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-28 22:10:20 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-05-28 22:10:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
// stripos - introduced in PHP5
|
2008-01-20 04:46:35 +00:00
|
|
|
if (!function_exists('stripos'))
|
2008-01-06 20:59:48 +00:00
|
|
|
{
|
2009-11-10 19:13:07 +00:00
|
|
|
function stripos($str, $needle, $offset = 0)
|
2007-11-16 01:28:54 +00:00
|
|
|
{
|
|
|
|
return strpos(strtolower($str), strtolower($needle), $offset);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-28 22:10:20 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-05-28 22:10:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
// simplexml_load_string - introduced in PHP5
|
2009-11-10 19:13:07 +00:00
|
|
|
if (!function_exists('simplexml_load_string'))
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
//CXml class code found on php.net
|
|
|
|
class CXml
|
|
|
|
{
|
|
|
|
var $xml_data;
|
|
|
|
var $obj_data;
|
|
|
|
var $pointer;
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
function CXml()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
function Set_xml_data(&$xml_data)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
|
|
|
$this->index = 0;
|
|
|
|
$this->pointer[] = &$this->obj_data;
|
2009-11-10 19:13:07 +00:00
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
//strip white space between tags
|
|
|
|
$this->xml_data = preg_replace("/>[[:space:]]+</i", "><", $xml_data);
|
2009-11-10 19:13:07 +00:00
|
|
|
$this->xml_parser = xml_parser_create("UTF-8");
|
|
|
|
|
|
|
|
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
xml_set_object($this->xml_parser, $this);
|
|
|
|
xml_set_element_handler($this->xml_parser, "_startElement", "_endElement");
|
|
|
|
xml_set_character_data_handler($this->xml_parser, "_cData");
|
|
|
|
|
|
|
|
xml_parse($this->xml_parser, $this->xml_data, true);
|
|
|
|
xml_parser_free($this->xml_parser);
|
2008-01-20 04:46:35 +00:00
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
function _startElement($parser, $tag, $attributeList)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
|
|
|
$attributes = '@attributes';
|
2009-11-10 19:13:07 +00:00
|
|
|
foreach ($attributeList as $name=>$value)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
2009-11-10 19:13:07 +00:00
|
|
|
$value = $this->_cleanString($value);
|
|
|
|
$object-> {$attributes} [$name] = $value;
|
2008-01-20 04:46:35 +00:00
|
|
|
// $object->$name = $value;
|
|
|
|
}
|
|
|
|
//replaces the special characters with the underscore (_) in tag name
|
|
|
|
$tag = preg_replace("/[:\-\. ]/", "_", $tag);
|
2009-11-10 19:13:07 +00:00
|
|
|
eval("\$this->pointer[\$this->index]->".$tag."[] = \$object;");
|
|
|
|
eval("\$size = sizeof( \$this->pointer[\$this->index]->".$tag." );");
|
|
|
|
eval("\$this->pointer[] = &\$this->pointer[\$this->index]->".$tag."[\$size-1];");
|
|
|
|
|
2008-01-20 04:46:35 +00:00
|
|
|
$this->index++;
|
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
function _endElement($parser, $tag)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
2009-11-10 19:13:07 +00:00
|
|
|
array_pop($this->pointer);
|
2008-01-20 04:46:35 +00:00
|
|
|
$this->index--;
|
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
function _cData($parser, $data)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
2009-11-10 19:13:07 +00:00
|
|
|
if ( empty($this->pointer[$this->index]))
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
|
|
|
if (rtrim($data, "\n"))
|
|
|
|
{
|
|
|
|
$this->pointer[$this->index] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->pointer[$this->index] .= $data;
|
|
|
|
}
|
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
function _cleanString($string)
|
2008-01-20 04:46:35 +00:00
|
|
|
{
|
2009-11-10 19:13:07 +00:00
|
|
|
return utf8_decode(trim($string));
|
2008-01-20 04:46:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function simplexml_load_string($xml)
|
|
|
|
{
|
|
|
|
$xmlClass = new CXml;
|
|
|
|
$xmlClass->Set_xml_data($xml);
|
2009-11-10 19:13:07 +00:00
|
|
|
$data = (array) $xmlClass->obj_data;
|
2008-01-20 04:46:35 +00:00
|
|
|
$tmp = array_keys($data);
|
|
|
|
$data = $data[$tmp[0]][0];
|
|
|
|
return $data;
|
|
|
|
}
|
2009-11-10 19:13:07 +00:00
|
|
|
|
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
2010-05-28 22:10:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-11-10 19:13:07 +00:00
|
|
|
if (!function_exists('strptime'))
|
|
|
|
{
|
2012-05-26 12:21:39 +00:00
|
|
|
|
2009-11-10 19:13:07 +00:00
|
|
|
define('STRPTIME_COMPAT', true);
|
|
|
|
function strptime($str, $format)
|
|
|
|
{
|
2012-05-26 12:21:39 +00:00
|
|
|
return e107::getDate()->strptime($str,$format);
|
2009-11-10 19:13:07 +00:00
|
|
|
}
|
2008-01-20 04:46:35 +00:00
|
|
|
|
|
|
|
}
|
2010-12-10 14:20:15 +00:00
|
|
|
|
|
|
|
//PHP < 5.2 compatibility
|
|
|
|
if (!function_exists('json_encode'))
|
|
|
|
{
|
|
|
|
require_once(e_HANDLER.'json_compat_handler.php');
|
|
|
|
function json_encode($array)
|
|
|
|
{
|
|
|
|
$json = new Services_JSON();
|
|
|
|
return $json->encode($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
function json_decode($json_obj)
|
|
|
|
{
|
|
|
|
$json = new Services_JSON();
|
|
|
|
return $json->decode($json_obj);
|
|
|
|
}
|
|
|
|
}
|