当前位置: 首页>>代码示例>>PHP>>正文


PHP Xml::toArray方法代码示例

本文整理汇总了PHP中Xml::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Xml::toArray方法的具体用法?PHP Xml::toArray怎么用?PHP Xml::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Xml的用法示例。


在下文中一共展示了Xml::toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: import

 /**
  * undocumented function
  *
  * @param string $file 
  * @return void
  * @access public
  */
 function import($file)
 {
     $source = file_get_contents($file);
     $xml = new Xml($source);
     $result = $xml->toArray();
     $result = $result['Xmlarchive']['Fileset']['File'];
     if (empty($result)) {
         return false;
     }
     $count = 0;
     foreach ($result as $smiley) {
         $name = $smiley['filename'];
         $content = $smiley['content'];
         $content = preg_replace('/\\s/', '', $content);
         $content = base64_decode($content);
         $filePath = SMILEY_PATH . $name;
         if (file_exists($filePath)) {
             continue;
         }
         $this->create(array('code' => ':' . r('.gif', '', $name) . ':', 'filename' => $name));
         $this->save();
         $f = fopen($filePath, 'w+');
         fwrite($f, $content);
         fclose($f);
         $count++;
     }
     return $count;
 }
开发者ID:stripthis,项目名称:donate,代码行数:35,代码来源:smiley.php

示例2: xml2Config

    /**
     * Parses XML files into config files
     * @access public 
     * @static
     * @param string $path 
     *
     */
    public static function xml2Config($path){
        
        foreach(scandir($path) as $file){
            $ext = pathinfo($file, PATHINFO_EXTENSION);

            //Skip file if it's not XML
            if(strtolower($ext) !== 'xml') {
                continue;
            }
            
            if(is_file($path . DS . $file)){
                
                $xmlData = Xml::toArray(Xml::build($path . DS . $file));
                
                $outFile = 
                    ROOT . DS . APP_DIR . DS . 'Config' . DS . 'Includes' . DS . str_replace('.xml', '.php', $file);
                
                $configureString = "<?php\n";

                foreach($xmlData['root'] as $key => $value){
                    $val = empty($value['value'])?$value['default']:$value['value'];
                    $decoded = htmlspecialchars_decode($val, ENT_QUOTES);
                    $configureString .= "Configure::write('{$value['name']}', {$decoded});\n";
                }
                
                file_put_contents ($outFile , $configureString);
            }
            
        }
        
    }
开发者ID:42northgroup,项目名称:42Viral,代码行数:38,代码来源:Parser.php

示例3: styleList

 public function styleList()
 {
     $style = array();
     $dirs = Dir::tree('template');
     foreach ($dirs as $tpl) {
         $xml = $tpl['path'] . '/config.xml';
         if (!is_file($xml)) {
             continue;
         }
         if (!($config = Xml::toArray(file_get_contents($xml)))) {
             continue;
         }
         $tpl['name'] = isset($config['name']) ? $config['name'][0] : '';
         //模型名
         $tpl['author'] = isset($config['author']) ? $config['author'][0] : '';
         //作者
         $tpl['image'] = isset($config['image']) ? __ROOT__ . '/template/' . $tpl['filename'] . '/' . $config['image'][0] : __CONTROLLER_TPL__ . '/img/preview.jpg';
         //预览图
         $tpl['email'] = isset($config['email']) ? $config['email'][0] : '';
         //邮箱
         $tpl['current'] = C("WEB_STYLE") == $tpl['filename'] ? 1 : 0;
         //正在使用的模板
         $style[] = $tpl;
     }
     $this->assign('style', $style);
     $this->display();
 }
开发者ID:lililishuang,项目名称:hdcms,代码行数:27,代码来源:TemplateStyleController.class.php

示例4: parseRss

 public function parseRss()
 {
     $channel = Xml::toArray(Xml::build($this->args[0])->channel);
     $items = $channel['channel']['item'];
     $list = $this->PinterestPin->find('list', array('fields' => array('id', 'guid')));
     $data = array();
     foreach ($items as $item) {
         if (!in_array($item['guid'], $list)) {
             $html = file_get_html($item['guid']);
             $image = $html->find('img.pinImage', 0);
             if (is_object($image)) {
                 $data[] = array('guid' => $item['guid'], 'title' => $item['title'], 'image' => $image->attr['src'], 'description' => strip_tags($item['description']), 'created' => date('Y-m-d H:i:s', strtotime($item['pubDate'])));
             }
         }
     }
     if (!empty($data)) {
         if ($this->PinterestPin->saveAll($data)) {
             $this->out(__d('pinterest', '<success>All records saved sucesfully.</success>'));
             return true;
         } else {
             $this->err(__d('pinterest', 'Cannot save records.'));
             return false;
         }
     }
     $this->out(__d('pinterest', '<warning>No records saved.</warning>'));
 }
开发者ID:adderall,项目名称:CakePHP-Pinterest-Plugin,代码行数:26,代码来源:PinterestShell.php

示例5: get

 public function get(&$accessToken, &$oauthConsumer)
 {
     // we need the GUID of the user for Yahoo
     $guid = $oauthConsumer->get($accessToken->key, $accessToken->secret, 'http://social.yahooapis.com/v1/me/guid');
     // Yahoo returns XML, so break it apart and make it an array
     $xml = new Xml($guid);
     // Or you can convert simply by calling toArray();
     $guid = $xml->toArray();
     // get them contacts
     $contacts = $oauthConsumer->get($accessToken->key, $accessToken->secret, 'http://social.yahooapis.com/v1/user/' . $guid['Guid']['value'] . '/contacts', array('count' => 'max', 'format' => 'xml'));
     // return array
     $c = array();
     // counter
     $i = 0;
     // new xml object
     $xml = new Xml($contacts);
     $contacts = $xml->toArray();
     // let's break apart Yahoo's contact format and make it our own, extracting what we want
     foreach ($contacts['Contacts']['Contact'] as $contact) {
         foreach ($contact['Fields'] as $field) {
             if ($field['type'] == 'email') {
                 $c[$i]['Contact']['email'][] = $field['value'];
             }
             if ($field['type'] == 'name' && isset($c[$i]['Contact']['email'])) {
                 $firstName = isset($field['Value']['givenName']) ? $field['Value']['givenName'] : '';
                 $lastName = isset($field['Value']['familyName']) ? $field['Value']['familyName'] : '';
                 $c[$i]['Contact']['fullName'] = $firstName . ' ' . $lastName;
             }
         }
         $i++;
     }
     return $c;
 }
开发者ID:RobertWHurst,项目名称:Telame,代码行数:33,代码来源:yahoo_consumer.php

示例6: serializeXmlToArray

 /**
  * Serialize to array data from xml
  *
  * @param array $url url
  * @return array Xml serialize array data
  */
 public function serializeXmlToArray($url)
 {
     $xmlData = Xml::toArray(Xml::build($url));
     // rssの種類によってタグ名が異なる
     if (isset($xmlData['feed'])) {
         $items = Hash::get($xmlData, 'feed.entry');
         $dateKey = 'published';
         $linkKey = 'link.@href';
         $summaryKey = 'summary';
     } elseif (Hash::get($xmlData, 'rss.@version') === '2.0') {
         $items = Hash::get($xmlData, 'rss.channel.item');
         $dateKey = 'pubDate';
         $linkKey = 'link';
         $summaryKey = 'description';
     } else {
         $items = Hash::get($xmlData, 'RDF.item');
         $dateKey = 'dc:date';
         $linkKey = 'link';
         $summaryKey = 'description';
     }
     if (!isset($items[0]) && is_array($items)) {
         $items = array($items);
     }
     $data = array();
     foreach ($items as $item) {
         $date = new DateTime($item[$dateKey]);
         $summary = Hash::get($item, $summaryKey);
         $data[] = array('title' => $item['title'], 'link' => Hash::get($item, $linkKey), 'summary' => $summary ? strip_tags($summary) : '', 'last_updated' => $date->format('Y-m-d H:i:s'), 'serialize_value' => serialize($item));
     }
     return $data;
 }
开发者ID:Onasusweb,项目名称:RssReaders,代码行数:37,代码来源:RssReaderItem.php

示例7: isUpToDate

 /**
  * Verifica se os menus do banco estão atualizados com os do arquivo
  * @param $aDados- array de menus do banco
  * @return boolean
  */
 public function isUpToDate($aDados)
 {
     $aDados = Set::combine($aDados, "/Menu/id", "/Menu");
     App::import("Xml");
     App::import("Folder");
     App::import("File");
     $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus");
     $oFolder = new Folder($sCaminhosArquivos);
     $aConteudo = $oFolder->read();
     $aArquivos = Set::sort($aConteudo[1], "{n}", "desc");
     if (empty($aArquivos)) {
         return false;
     }
     $oFile = new File($sCaminhosArquivos . $aArquivos[0]);
     $oXml = new Xml($oFile->read());
     $aAntigo = $oXml->toArray();
     foreach ($aDados as &$aMenu) {
         $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']);
     }
     if (isset($aAntigo["menus"])) {
         $aAntigo["Menus"] = $aAntigo["menus"];
         unset($aAntigo["menus"]);
     }
     if (isset($aAntigo["Menus"])) {
         $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu");
         $aRetorno = Set::diff($aDados, $aAntigo);
     }
     return empty($aRetorno);
 }
开发者ID:niltonfelipe,项目名称:e-cidade_transparencia,代码行数:34,代码来源:check_point.php

示例8: wordpress

 public function wordpress()
 {
     if ($this->request->is('post')) {
         /*
          * validate file upload
          */
         $this->CloggyValidation->set($this->request->data['CloggyBlogImport']);
         $this->CloggyValidation->validate = array('wordpress_xml' => array('ext' => array('rule' => array('extension', array('xml')), 'message' => __d('cloggy', 'You must upload xml file'))));
         if ($this->CloggyValidation->validates()) {
             /*
              * setup import files
              */
             $this->__CloggyFileUpload->settings(array('allowed_types' => array('xml'), 'field' => 'wordpress_xml', 'data_model' => 'CloggyBlogImport', 'folder_dest_path' => APP . 'Plugin' . DS . 'Cloggy' . DS . 'webroot' . DS . 'uploads' . DS . 'CloggyBlog' . DS . 'import' . DS));
             //upload xml
             $this->__CloggyFileUpload->proceedUpload();
             //check error upload
             $checkUploadError = $this->__CloggyFileUpload->isError();
             /*
              * if error then back to original view
              * if not then render new view, continue with download and import
              * data and files
              */
             if ($checkUploadError) {
                 $this->set('error', $this->__CloggyFileUpload->getErrorMsg());
             } else {
                 $xmlUploadedData = $this->__CloggyFileUpload->getUploadedData();
                 $xmlFile = $xmlUploadedData['dirname'] . DS . $xmlUploadedData['basename'];
                 //read wordpress xml data
                 $xml = Xml::toArray(Xml::build($xmlFile));
                 /*
                  * if option enabled
                  */
                 if (isset($this->request->data['CloggyBlogImport']['wordpress_import_options'])) {
                     $this->__CloggyBlogImport->setupOptions($this->request->data['CloggyBlogImport']['wordpress_import_options']);
                 }
                 //setup imported data
                 $this->__CloggyBlogImport->setupData($xml);
                 //genereate adapter
                 $this->__CloggyBlogImport->generate();
                 /*
                  * check if given data is valid based on adapter
                  */
                 $checkValidData = $this->__CloggyBlogImport->isValidImportedData();
                 if ($checkValidData) {
                     $checkImport = $this->__CloggyBlogImport->import();
                     if ($checkImport) {
                         $this->Session->setFlash(__d('cloggy', 'Data imported'), 'default', array(), 'success');
                     }
                 } else {
                     $this->set('error', __d('cloggy', 'Given data is not valid.'));
                 }
             }
         } else {
             $this->set('errors', $this->CloggyValidation->validationErrors);
         }
     }
     $this->set('title_for_layout', __d('cloggy', 'Import Post From Wordpress'));
 }
开发者ID:simaostephanie,项目名称:Cloggy,代码行数:58,代码来源:CloggyBlogImportController.php

示例9: __construct

 /**
  * Constructor
  * 
  * @param array $config
  * @param HttpSourceConnection $Connection
  * @throws RuntimeException
  */
 public function __construct($config = array(), HttpSourceConnection $Connection = null)
 {
     parent::__construct($config, $Connection);
     $this->setDecoder('text/html', function (HttpSocketResponse $HttpSocketResponse) {
         $Xml = Xml::build((string) $HttpSocketResponse);
         $response = Xml::toArray($Xml);
         return $response;
     }, true);
 }
开发者ID:imsamurai,项目名称:cakephp-sms-fly-datasource,代码行数:16,代码来源:SMSFlySource.php

示例10: _parseXml

 /**
  * Parse xml
  *
  * @return array
  */
 protected static function _parseXml($file)
 {
     $xml = Xml::build($file);
     $res = Xml::toArray($xml);
     if (!empty($res['xss']['attack'])) {
         return (array) $res['xss']['attack'];
     }
     return [];
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:14,代码来源:HazardLib.php

示例11: getPrototypes

 public function getPrototypes()
 {
     $searchdirs['App'] = APP . 'View';
     $searchdirs['Basic'] = CakePlugin::path('Muffin');
     foreach (CakePlugin::loaded() as $plugin) {
         if ($plugin != 'Muffin') {
             $searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
         }
     }
     $configs = array();
     foreach ($searchdirs as $plugin => $searchdir) {
         $dir = new Folder($searchdir, false);
         if ($files = $dir->findRecursive('config.xml')) {
             $configs = Hash::merge($configs, array($plugin => $files));
         }
     }
     $prototypes = array();
     foreach ($configs as $plugin => $configFiles) {
         $i = 0;
         foreach ($configFiles as $configFile) {
             $xml = Xml::build($configFile);
             $items = $xml->xpath('menu/item');
             if (!is_array($items) || empty($items)) {
                 continue;
             }
             foreach ($items as $item) {
                 $item = Xml::toArray($item);
                 if (empty($item['item']['@label'])) {
                     continue;
                 }
                 if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
                     $id = ucfirst(Inflector::variable($item['item']['@label']));
                 } else {
                     $id = $item['item']['@id'];
                 }
                 $fields = array();
                 foreach ($item['item']['field'] as $key => $field) {
                     foreach ($field as $name => $value) {
                         $name = str_replace('@', '', $name);
                         $fields[$key][$name] = $value;
                     }
                 }
                 $prototypes[$plugin][$i]['Link']['id'] = $id;
                 $prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
                 $prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
                 $prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
                 $prototypes[$plugin][$i]['Field'] = $fields;
                 $i++;
             }
         }
     }
     foreach ($prototypes as $plugin => $section) {
         $prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
     }
     return $prototypes;
 }
开发者ID:mindforce,项目名称:cakephp-front-engine,代码行数:56,代码来源:LinksComponent.php

示例12: parse

 /**
  * parse xml
  * 2010-02-07 ms
  */
 function parse($file)
 {
     App::import('Core', 'Xml');
     $xml = new Xml($file);
     $res = $xml->toArray();
     if (!empty($res['Xss']['Attack'])) {
         return (array) $res['Xss']['Attack'];
     }
     return array();
 }
开发者ID:robksawyer,项目名称:tools,代码行数:14,代码来源:security_lib.php

示例13: remove

 /**
  * 删除模块
  *
  * @param string $module 模块名称
  * @param int $removeData 删除模块数据
  *
  * @return bool
  */
 public function remove($module, $removeData = 0)
 {
     //删除封面关键词数据
     if ($removeData) {
         //本地安装的模块删除处理
         $xmlFile = 'addons/' . $module . '/manifest.xml';
         if (is_file($xmlFile)) {
             $manifest = Xml::toArray(file_get_contents($xmlFile));
             //卸载数据
             $installSql = trim($manifest['manifest']['uninstall']['@cdata']);
             if (!empty($installSql)) {
                 if (preg_match('/.php$/', $installSql)) {
                     $file = 'addons/' . $module . '/' . $installSql;
                     if (!is_file($file)) {
                         $this->error = '卸载文件:' . $file . '不存在';
                         return;
                     }
                     require $file;
                 } else {
                     \Schema::sql($installSql);
                 }
             }
         }
         //删除模块回复规则列表
         $rids = Db::table('rule')->where('module', $module)->lists('rid') ?: [];
         foreach ($rids as $rid) {
             service('WeChat')->removeRule($rid);
         }
         //删除站点模块
         Db::table('site_modules')->where('module', $module)->delete();
         //模块设置
         Db::table('module_setting')->where('module', $module)->delete();
         //代金券使用的模块
         Db::table('ticket_module')->where('module', $module)->delete();
     }
     //删除模块数据
     $this->where('name', $module)->delete();
     //删除模块动作数据
     Db::table('modules_bindings')->where('module', $module)->delete();
     //更新套餐数据
     $package = Db::table('package')->get();
     if ($package) {
         foreach ($package as $p) {
             $p['modules'] = unserialize($p['modules']) ?: [];
             if ($k = array_search($_GET['module'], $p['modules'])) {
                 unset($p['modules'][$k]);
             }
             $p['modules'] = serialize($p['modules']);
             Db::table('package')->where('id', $p['id'])->update($p);
         }
     }
     //更新所有站点缓存
     service('site')->updateAllCache();
     return TRUE;
 }
开发者ID:houdunwang,项目名称:hdcms,代码行数:63,代码来源:Modules.php

示例14: paginate

 /**
  * paginate
  *
  * @param  mixed $conditions
  * @param  mixed $fields
  * @param  mixed $order
  * @param  integer $limit
  * @param  integer $page
  * @param  integer $recursive
  * @param  array $extract
  * @return array
  */
 public function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra)
 {
     $HttpSocket = new HttpSocket();
     $query = array('q' => Set::extract('q', $conditions), 'page' => $page, 'rpp' => $limit, 'lang' => Set::extract('lang', $conditions));
     $ret = $HttpSocket->get(self::API_SEARCH, $query);
     if ($ret) {
         $Xml = new Xml($ret);
         return $Xml->toArray();
     }
     return array();
 }
开发者ID:shin1x1,项目名称:findTwitter,代码行数:23,代码来源:twitter.php

示例15: testByAtom

 /**
  * Expect RssReaderItem->serializeXmlToArray() by atom format
  *
  * @return void
  */
 public function testByAtom()
 {
     $url = APP . 'Plugin' . DS . 'RssReaders' . DS . 'Test' . DS . 'Fixture' . DS . 'rss_atom.xml';
     //テスト実施
     $result = $this->RssReaderItem->serializeXmlToArray($url);
     //期待値
     $xmlData = Xml::toArray(Xml::build($url));
     $items = Hash::get($xmlData, 'feed.entry');
     $serializeValue = isset($items[0]) && is_array($items[0]) ? $items[0] : $items;
     $expected = array(array('title' => 'content title', 'link' => 'http://example.com/1.html', 'summary' => 'content description', 'last_updated' => '2015-03-13 17:07:41', 'serialize_value' => serialize($serializeValue)));
     $this->assertEquals($result, $expected);
 }
开发者ID:Onasusweb,项目名称:RssReaders,代码行数:17,代码来源:RssReaderItemSerializeXmlToArrayTest.php


注:本文中的Xml::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。