本文整理汇总了PHP中XmlParser类的典型用法代码示例。如果您正苦于以下问题:PHP XmlParser类的具体用法?PHP XmlParser怎么用?PHP XmlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testParseWithIntegerIndexedArray
public function testParseWithIntegerIndexedArray()
{
$testXml = simplexml_load_file('./tests/raw/test_feed.xml');
$parser = new XmlParser($testXml);
$results = $parser->parse();
$this->assertTrue(isset($results['rss']['channel']));
}
示例2: proc
/**
* @brief 위젯의 실행 부분
*
* ./widgets/위젯/conf/info.xml 에 선언한 extra_vars를 args로 받는다
* 결과를 만든후 print가 아니라 return 해주어야 한다
**/
function proc($args)
{
// 위젯 자체적으로 설정한 변수들을 체크
$title = $args->title;
$PAGE_LIMIT = $args->page_limit ? $args->page_limit : 10;
// 날짜 형태
$DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s";
$buff = $this->rss_request($args->rss_url);
if (!is_string($buff) or !$buff) {
return Context::getLang('msg_fail_to_request_open');
}
$encoding = preg_match("/<\\?xml.*encoding=\"(.+)\".*\\?>/i", $buff, $matches);
if ($encoding && !preg_match("/UTF-8/i", $matches[1])) {
$buff = trim(iconv($matches[1] == "ks_c_5601-1987" ? "EUC-KR" : $matches[1], "UTF-8", $buff));
}
$buff = preg_replace("/<\\?xml.*\\?>/i", "", $buff);
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse($buff);
$rss->title = $xml_doc->rss->channel->title->body;
$rss->link = $xml_doc->rss->channel->link->body;
$items = $xml_doc->rss->channel->item;
if (!$items) {
return Context::getLang('msg_invalid_format');
}
if ($items && !is_array($items)) {
$items = array($items);
}
$rss_list = array();
foreach ($items as $key => $value) {
if ($key >= $PAGE_LIMIT) {
break;
}
unset($item);
foreach ($value as $key2 => $value2) {
if (is_array($value2)) {
$value2 = array_shift($value2);
}
$item->{$key2} = $value2->body;
}
$date = $item->pubdate;
$item->date = $date ? date($DATE_FORMAT, strtotime($date)) : '';
$array_date[$key] = strtotime($date);
$item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
$rss_list[$key] = $item;
}
array_multisort($array_date, SORT_DESC, $rss_list);
$widget_info->rss = $rss;
$widget_info->rss_list = $rss_list;
$widget_info->title = $title;
$widget_info->rss_height = $args->rss_height ? $args->rss_height : 200;
$widget_info->subject_cut_size = $args->subject_cut_size;
Context::set('widget_info', $widget_info);
// 템플릿의 스킨 경로를 지정 (skin, colorset에 따른 값을 설정)
$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);
Context::set('colorset', $args->colorset);
// 템플릿 컴파일
$oTemplate =& TemplateHandler::getInstance();
$output = $oTemplate->compile($tpl_path, 'list');
return $output;
}
示例3: send_order
/**
* Block Send XML order to Moulton
* @author Oleg D.
*/
function send_order()
{
$result = array();
$xml_order = $this->build_order_xml();
$xml_order = preg_replace("/(\\s+)?(\\<.+\\>)(\\s+)?/", "\$2", $xml_order);
$xml_order = str_replace('&', '&', $xml_order);
echo $xml_order;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_order);
if ($this->testing) {
curl_setopt($ch, CURLOPT_URL, $this->send_order_url_test);
} else {
curl_setopt($ch, CURLOPT_URL, $this->send_order_url);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$moulton_answer = curl_exec($ch);
curl_close($ch);
include 'xmlparser.class.php';
$Parser = new XmlParser();
$result = $Parser->xml2array($moulton_answer);
return $result;
}
示例4: init
function init()
{
// forbit access if the user is not an administrator
if (!$this->grant->manager && !$this->grant->is_admin) {
return $this->stop("msg_is_not_administrator");
}
// change into administration layout
//$this->setTemplatePath('./modules/cympusadmin/tpl');
$this->setLayoutPath('./modules/cympusadmin/tpl');
$this->setLayoutFile(_CYMPUSADMIN_LAYOUT_);
Context::loadLang(_XE_PATH_ . 'modules/cympusadmin/lang/');
if ($this->grant->is_admin) {
// parse admin menu
$oXmlParser = new XmlParser();
$xml_obj = $oXmlParser->loadXmlFile('./modules/cympusadmin/conf/' . _CYMPUSADMIN_MENU_);
$admin_menu = cympusadmin::getMenu($xml_obj->menu->item);
Context::set('cympusadmin_menu', $admin_menu);
} else {
$output = ModuleHandler::triggerCall('cympusadmin.getManagerMenu', 'before', $manager_menu);
if (!$output->toBool()) {
return $output;
}
Context::set('cympusadmin_menu', $manager_menu);
}
$news = getNewsFromAgency();
Context::set('news', $news);
Context::set('admin_bar', 'false');
$oModuleModel =& getModel('module');
$module_info = $oModuleModel->getModuleInfoXml('cympusadmin');
Context::set('cympus_modinfo', $module_info);
return new Object();
}
示例5: checkEasyinstall
/**
* check easy install
* @return void
*/
function checkEasyinstall()
{
$lastTime = (int) FileHandler::readFile($this->easyinstallCheckFile);
if ($lastTime > $_SERVER['REQUEST_TIME'] - 60 * 60 * 24 * 30) {
return;
}
$oAutoinstallModel = getModel('autoinstall');
$params = array();
$params["act"] = "getResourceapiLastupdate";
$body = XmlGenerater::generate($params);
$buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
$xml_lUpdate = new XmlParser();
$lUpdateDoc = $xml_lUpdate->parse($buff);
$updateDate = $lUpdateDoc->response->updatedate->body;
if (!$updateDate) {
$this->_markingCheckEasyinstall();
return;
}
$item = $oAutoinstallModel->getLatestPackage();
if (!$item || $item->updatedate < $updateDate) {
$oController = getAdminController('autoinstall');
$oController->_updateinfo();
}
$this->_markingCheckEasyinstall();
}
示例6: getNewsFromAgency
function getNewsFromAgency()
{
//Retrieve recent news and set them into context
$newest_news_url = sprintf("http://www.xeshoppingmall.com/?module=newsagency&act=getNewsagencyArticle&inst=notice&top=6&loc=%s", _XE_LOCATION_);
$cache_file = sprintf("%sfiles/cache/nstore_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_);
if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) {
// Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing textmessageistration page
// Ensure to access the textmessageistration page even though news cannot be displayed
FileHandler::writeFile($cache_file, '');
FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl('')));
}
if (file_exists($cache_file)) {
$oXml = new XmlParser();
$buff = $oXml->parse(FileHandler::readFile($cache_file));
$item = $buff->zbxe_news->item;
if ($item) {
if (!is_array($item)) {
$item = array($item);
}
foreach ($item as $key => $val) {
$obj = null;
$obj->title = $val->body;
$obj->date = $val->attrs->date;
$obj->url = $val->attrs->url;
$news[] = $obj;
}
return $news;
}
}
}
示例7: init
function init()
{
// forbit access if the user is not an administrator
$oMemberModel =& getModel('member');
$logged_info = $oMemberModel->getLoggedInfo();
if ($logged_info->is_admin != 'Y') {
return $this->stop("msg_is_not_administrator");
}
// change into administration layout
//$this->setTemplatePath('./modules/cympusadmin/tpl');
$this->setLayoutPath('./modules/cympusadmin/tpl');
$this->setLayoutFile(_CYMPUSADMIN_LAYOUT_);
// parse admin menu
$act = Context::get('act');
$oXmlParser = new XmlParser();
$xml_obj = $oXmlParser->loadXmlFile('./modules/cympusadmin/conf/' . _CYMPUSADMIN_MENU_);
$admin_menu = array();
$admin_menu = cympusadmin::getMenu($xml_obj->menu->item);
Context::set('cympusadmin_menu', $admin_menu);
$oModuleModel =& getModel('module');
$module_info = $oModuleModel->getModuleInfoXml('cympusadmin');
Context::set('cympus_modinfo', $module_info);
$news = getNewsFromAgency();
Context::set('news', $news);
Context::set('admin_bar', 'false');
}
示例8: getLogs
/**
* get logs of the log file
* @param $type string of log direcroty, like store
* @param $logFile - log files name like 12.27.2009.xml
* @param $userID
* @author Oleg D.
*/
function getLogs($type, $logFile, $userID = null)
{
$logFile .= '.xml';
$date = explode('.', $logFile);
$year = $date[2];
$month = $date[0];
App::import('Vendor', 'XmlParser', array('file' => 'xmlparser.class.php'));
$XmlParser = new XmlParser();
$file = file_get_contents(ROOT . DS . 'app' . DS . 'logs' . DS . $type . DS . $year . DS . $month . DS . $logFile);
$file = str_replace('&', 'and', $file);
if (!$file) {
echo 'file error';
exit;
}
$file = '<All>' . $file . '</All>';
$logsParse = $XmlParser->xml2array($file);
$logs = array();
if (isset($logsParse['All']['Log'])) {
$logs = $logsParse['All']['Log'];
}
if ($userID) {
$myLogs = array();
foreach ($logs as $log) {
if ($log['Uid'] == $userID) {
$myLogs[] = $log;
}
}
} else {
$myLogs = $logs;
}
$myLogs = array_reverse($myLogs);
//echo "<pre>";
//print_r($myLogs);
return $myLogs;
}
示例9: getLicenseFromAgency
function getLicenseFromAgency($prodid, &$has_license = TRUE, &$expiration = NULL)
{
$has_license = TRUE;
$oLicenseModel =& getModel('license');
$config = $oLicenseModel->getModuleConfig();
if ($prodid == 'nstore') {
$user_id = $config->user_id;
$serial_number = $config->serial_number;
} else {
if ($prodid == 'nstore_digital') {
$user_id = $config->d_user_id;
$serial_number = $config->d_serial_number;
} else {
$user_id = $config->e_user_id;
$serial_number = $config->e_serial_number;
}
}
$cache_file = $this->checkLicense($prodid, $user_id, $serial_number);
if (file_exists($cache_file)) {
$oXml = new XmlParser();
$buff = $oXml->parse(FileHandler::readFile($cache_file));
// user
$userObj = $buff->drm->user;
if ($userObj) {
$user = $userObj->body;
if ($user != $user_id) {
$this->checkLicense($prodid, $user_id, $serial_number, TRUE);
return TRUE;
}
}
// serial
$serialObj = $buff->drm->serial;
if ($serialObj) {
$serial = $serialObj->body;
if ($serial != $serial_number) {
$this->checkLicense($prodid, $user_id, $serial_number, TRUE);
return TRUE;
}
}
// license
$licenseObj = $buff->drm->license;
if ($licenseObj) {
$license = $licenseObj->body;
if ($license == 'none') {
$url = getUrl('act', 'dispLicenseAdminConfig');
Context::set(sprintf('%s_MESSAGE_TYPE', strtoupper($prodid)), 'error');
Context::set(sprintf('%s_MESSAGE', strtoupper($prodid)), Context::getLang('not_registered'));
$has_license = FALSE;
}
}
// expiration
$expirationObj = $buff->drm->expiration;
if ($expirationObj) {
$expiration = $expirationObj->body;
}
}
return FALSE;
}
示例10: loadXmlFile
/**
* Load a xml file specified by a filename and parse it to Return the resultant data object
* @param string $filename a file path of file
* @return array Returns a data object containing data extracted from a xml file or NULL if a specified file does not exist
*/
function loadXmlFile($filename)
{
if (!file_exists($filename)) {
return;
}
$buff = FileHandler::readFile($filename);
$oXmlParser = new XmlParser();
return $oXmlParser->parse($buff);
}
示例11: decompressFile
public static function decompressFile($file, $destination = NULL)
{
if (!is_file($file)) {
throw new Exception("{$file} is not a regular file");
}
$parser = new XmlParser(new Stream(fopen($file, 'rd')));
//TODO : write a method in this class, ->saveToFile();
file_put_contents($destination === NULL ? $file : $destination, $parser->getXmlString());
}
示例12: _setGrantByWidgetSequence
function _setGrantByWidgetSequence($matches)
{
$buff = trim($matches[0]);
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse(trim($buff));
$widget_sequence = $vars->widget_sequence;
if ($widget_sequence) {
$_SESSION['magic_content_grant'][$widget_sequence] = true;
}
}
示例13: getXmlDoc
/**
* Request data to server and returns result
*
* @param array $params Request data
* @return object
*/
function getXmlDoc(&$params)
{
$body = XmlGenerater::generate($params);
$buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
if (!$buff) {
return;
}
$xml = new XmlParser();
$xmlDoc = $xml->parse($buff);
return $xmlDoc;
}
示例14: getXmlDoc
/**
* Request data to server and returns result
*
* @param array $params Request data
* @return object
*/
function getXmlDoc(&$params)
{
$body = XmlGenerater::generate($params);
$request_config = array('ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE);
$buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml", array(), array(), array(), $request_config);
if (!$buff) {
return;
}
$xml = new XmlParser();
$xmlDoc = $xml->parse($buff);
return $xmlDoc;
}
示例15: search_address
/**
* @brief naver map open api에서 주소를 찾는 함수
**/
function search_address()
{
$address = Context::get('address');
if (!$address) {
return new Object(-1, 'msg_not_exists_addr');
}
Context::loadLang($this->component_path . "lang");
// 지정된 서버에 요청을 시도한다
$address = urlencode(iconv("UTF-8", "EUC-KR", $address));
$query_string = sprintf('/api/geocode.php?key=%s&query=%s', $this->api_key, $address);
$fp = fsockopen('maps.naver.com', 80, $errno, $errstr);
if (!$fp) {
return new Object(-1, 'msg_fail_to_socket_open');
}
fputs($fp, "GET {$query_string} HTTP/1.0\r\n");
fputs($fp, "Host: maps.naver.com\r\n\r\n");
$buff = '';
while (!feof($fp)) {
$str = fgets($fp, 1024);
if (trim($str) == '') {
$start = true;
}
if ($start) {
$buff .= trim($str);
}
}
fclose($fp);
$buff = trim(iconv("EUC-KR", "UTF-8", $buff));
$buff = str_replace('<?xml version="1.0" encoding="euc-kr" ?>', '', $buff);
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse($buff);
//If a Naver OpenApi Error message exists.
if ($xml_doc->error->error_code->body || $xml_doc->error->message->body) {
return new Object(-1, 'NAVER OpenAPI Error' . "\n" . 'Code : ' . $xml_doc->error->error_code->body . "\n" . 'Message : ' . $xml_doc->error->message->body);
}
if ($xml_doc->geocode->total->body == 0) {
return new Object(-1, 'msg_no_result');
}
$addrs = $xml_doc->geocode->item;
if (!is_array($addrs)) {
$addrs = array($addrs);
}
$addrs_count = count($addrs);
$address_list = array();
for ($i = 0; $i < $addrs_count; $i++) {
$item = $addrs[$i];
$address_list[] = sprintf("%s,%s,%s", $item->point->x->body, $item->point->y->body, $item->address->body);
}
$this->add("address_list", implode("\n", $address_list));
}