本文整理汇总了PHP中XmlParser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP XmlParser::parse方法的具体用法?PHP XmlParser::parse怎么用?PHP XmlParser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlParser
的用法示例。
在下文中一共展示了XmlParser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
示例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: 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']));
}
示例4: 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();
}
示例5: fetchArmory
/**
* General armory fetch class
* Returns XML, HTML or an array of the parsed XML page
*
* @param int $type
* @param string $character
* @param string $guild
* @param string $realm
* @param int $item_id
* @param string $fetch_type
* @return array
*/
function fetchArmory($type = false, $character = false, $guild = false, $realm = false, $item_id = false, $fetch_type = 'array')
{
global $roster;
$url = $this->_makeUrl($type, false, $item_id, $character, $realm, $guild);
if ($fetch_type == 'html') {
$this->setUserAgent('Opera/9.22 (X11; Linux i686; U; en)');
}
if ($this->_requestXml($url)) {
if ($fetch_type == 'array') {
// parse and return array
$this->_initXmlParser();
$this->xmlParser->Parse($this->xml);
$data = $this->xmlParser->getParsedData();
} elseif ($fetch_type == 'simpleClass') {
// parse and return SimpleClass object
$this->_initSimpleParser();
$data = $this->simpleParser->parse($this->xml);
} else {
// unparsed fetches
return $this->xml;
}
return $data;
} else {
trigger_error('RosterArmory:: Failed to fetch ' . $url);
return false;
}
}
示例6: 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;
}
示例7: 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);
}
示例8: trim
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;
}
}
示例9: 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;
}
示例10: 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;
}
示例11: Object
/**
* @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));
}
示例12: getModel
/**
* Update easy install information
*
* @return void
*/
function _updateinfo()
{
$oModel =& getModel('autoinstall');
$item = $oModel->getLatestPackage();
if ($item) {
$params["updatedate"] = $item->updatedate;
}
$params["act"] = "getResourceapiUpdate";
$body = XmlGenerater::generate($params);
$buff = FileHandler::getRemoteResource(_XE_DOWNLOAD_SERVER_, $body, 3, "POST", "application/xml");
$xml = new XmlParser();
$xmlDoc = $xml->parse($buff);
$this->updateCategory($xmlDoc);
$this->updatePackages($xmlDoc);
$this->checkInstalled();
}
示例13: getTableInfo
/**
* Returns table information
*
* Used for finding column type info (string/numeric) <br />
* Obtains the table info from XE's XML schema files
*
* @param object $query_id
* @param bool $table_name
* @return array
*/
function getTableInfo($query_id, $table_name)
{
$column_type = array();
$module = '';
$id_args = explode('.', $query_id);
if (count($id_args) == 2) {
$target = 'modules';
$module = $id_args[0];
$id = $id_args[1];
} else {
if (count($id_args) == 3) {
$target = $id_args[0];
$targetList = array('modules' => 1, 'addons' => 1, 'widgets' => 1);
if (!isset($targetList[$target])) {
return;
}
$module = $id_args[1];
$id = $id_args[2];
}
}
// get column properties from the table
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $module, $table_name);
if (!file_exists($table_file)) {
$searched_list = FileHandler::readDir(_XE_PATH_ . 'modules');
$searched_count = count($searched_list);
for ($i = 0; $i < $searched_count; $i++) {
$table_file = sprintf('%s%s/%s/schemas/%s.xml', _XE_PATH_, 'modules', $searched_list[$i], $table_name);
if (file_exists($table_file)) {
break;
}
}
}
if (file_exists($table_file)) {
$table_xml = FileHandler::readFile($table_file);
$xml_parser = new XmlParser();
$table_obj = $xml_parser->parse($table_xml);
if ($table_obj->table) {
if (isset($table_obj->table->column) && !is_array($table_obj->table->column)) {
$table_obj->table->column = array($table_obj->table->column);
}
foreach ($table_obj->table->column as $k => $v) {
$column_type[$v->attrs->name] = $v->attrs->type;
}
}
}
return $column_type;
}
示例14: parse
/**
* Converts XML into an array, respecting namespaces, attributes, and text values.
*
* @return array
*/
public function parse()
{
$namespaces = $this->xml->getDocNamespaces();
$namespaces[''] = null;
//add base (empty) namespace
$attributes = $this->getAttributes($namespaces);
//get child nodes from all namespaces
$tags = array();
foreach ($namespaces as $prefix => $namespace) {
foreach ($this->xml->children($namespace) as $childXml) {
$new_parser = new XmlParser($childXml, $this->options);
$child = $new_parser->parse();
list($childTag, $childProperties) = each($child);
//add namespace prefix, if any
if ($prefix) {
$childTag = $prefix . $this->namespaceSeparator . $childTag;
}
if (!isset($tags[$childTag])) {
$alwaysArray = $this->options['alwaysArray'];
$autoArray = $this->options['autoArray'];
$tags[$childTag] = $childProperties;
if (in_array($childTag, $alwaysArray) || !$autoArray) {
$tags[$childTag] = [$childProperties];
}
} elseif ($this->isIntegerIndexedArray($tags[$childTag])) {
$tags[$childTag][] = $childProperties;
} else {
//key exists so convert to integer indexed array with previous value in position 0
$tags[$childTag] = array($tags[$childTag], $childProperties);
}
}
}
//get text content of node
$textContent = array();
$plainText = trim((string) $this->xml);
if ($plainText !== '') {
$textContent[$this->options['textContent']] = $plainText;
}
//stick it all together
$properties = $plainText;
if (!$this->options['autoText'] || $attributes || $tags || $plainText === '') {
$properties = array_merge($attributes, $tags, $textContent);
}
//return node as array
return array($this->xml->getName() => $properties);
}
示例15: getModel
/**
* Update easy install information
*
* @return void
*/
function _updateinfo()
{
$oModel = getModel('autoinstall');
$item = $oModel->getLatestPackage();
if ($item) {
$params["updatedate"] = $item->updatedate;
}
$params["act"] = "getResourceapiUpdate";
$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);
$xml = new XmlParser();
$xmlDoc = $xml->parse($buff);
$this->updateCategory($xmlDoc);
$this->updatePackages($xmlDoc);
$this->checkInstalled();
$oAdminController = getAdminController('admin');
$output = $oAdminController->cleanFavorite();
}