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>'));
 }
Esempio n. 2
0
 /**
  * @param string $feedID
  * @return array|bool|null
  */
 public function view_development($feedID = '')
 {
     if ($feedID != '') {
         if (Configure::read('globals.developmentfeed.' . $feedID) != null) {
             $feedDetails = Configure::read('globals.developmentfeed.' . $feedID);
             $this->feedURL = $feedDetails[0];
         } else {
             return false;
         }
     }
     $parsedXML = Xml::build($this->feedURL);
     // xml to array conversion
     $this->rssItem = Xml::toArray($parsedXML);
     //pr($this->rssItem);
     $feedInfo = $this->rssItem['feed'];
     $data = $this->rssItem['feed']['entry'];
     //pr($feedInfo);
     //pr($data);
     if ($this->request->is('requested')) {
         return array($feedInfo, $data);
     } else {
         $this->set('feedInfo', $feedInfo);
         $this->set('data', $data);
     }
     return null;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
    /**
     * 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);
            }
            
        }
        
    }
 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'));
 }
 function admin_add()
 {
     $Http = new HttpSocket();
     $response = $Http->get('https://www.google.com/accounts/o8/site-xrds?hd=' . $this->__getDomain());
     $response = Set::reverse(Xml::build($response->body));
     $endpoint = $response['XRDS']['XRD']['Service'][0]['URI'];
     $query = array('openid.mode' => 'checkid_setup', 'openid.ns' => 'http://specs.openid.net/auth/2.0', 'openid.return_to' => Router::url(array('plugin' => 'google_session', 'controller' => 'google_session', 'action' => 'callback', 'admin' => true), true), 'openid.ui.mode' => 'popup', 'openid.ns.ax' => 'http://openid.net/srv/ax/1.0', 'openid.ax.mode' => 'fetch_request', 'openid.ax.required' => 'email,firstname,lastname', 'openid.ax.type.email' => 'http://schema.openid.net/contact/email', 'openid.ax.type.firstname' => 'http://axschema.org/namePerson/first', 'openid.ax.type.lastname' => 'http://axschema.org/namePerson/last', 'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select', 'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select', 'hq' => $this->__getDomain());
     $this->redirect($endpoint . (strpos($endpoint, '?') ? '&' : '?') . http_build_query($query));
 }
Esempio n. 7
0
 /**
  * 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 [];
 }
 /**
  * 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);
 }
 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;
 }
Esempio n. 10
0
 public function genericDataExtractor($data)
 {
     $output = array();
     $method = $data['method'];
     $result = $this->http->{$method}($data['url'], $data['data'], $data['request']);
     if ($result->body != "") {
         $xmlArray = Xml::toArray(Xml::build($result->body));
         $output['result'] = Hash::extract($xmlArray, $data['path']);
         $output['array'] = $xmlArray;
     }
     return $output;
 }
 /**
  * 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);
 }
Esempio n. 12
0
 public function getTweets($q)
 {
     App::uses('Xml', 'Utility');
     $output = array();
     $this->searchURL = 'http://search.twitter.com/search.atom?page=' . $this->settings['page'] . '&lang=' . $this->settings['lang'] . '&rpp=' . $this->settings['rpp'] . '&q=';
     $ch = curl_init($this->searchURL . urlencode($q));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
     $response = curl_exec($ch);
     $xmlResult = Xml::toArray(Xml::build($response));
     curl_close($ch);
     return $xmlResult;
 }
Esempio n. 13
0
 /**
  * Test render with an array in _serialize
  *
  * @return void
  */
 public function testRenderWithoutViewMultiple()
 {
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $data = array('no' => 'nope', 'user' => 'fake', 'list' => array('item1', 'item2'));
     $Controller->set($data);
     $Controller->set('_serialize', array('no', 'user'));
     $View = new XmlView($Controller);
     $output = $View->render(false);
     $expected = array('response' => array('no' => $data['no'], 'user' => $data['user']));
     $this->assertIdentical(Xml::build($expected)->asXML(), $output);
     $this->assertIdentical('application/xml', $Response->type());
 }
 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $datasource = ConnectionManager::getDataSource($this->useDbConfig);
     //$datasource = ConnectionManager::loadDataSource('SalesforceSource');
     if ($datasource->_baseConfig['dynamic_mode']) {
         $this->_schema = $datasource->getSchema($this->name);
     } else {
         if (!empty($datasource->_baseConfig['my_wsdl'])) {
             $wsdl = APP . "Config" . DS . $datasource->_baseConfig['my_wsdl'];
         } else {
             $wsdl = App::Path('Vendor')[0] . 'salesforce/soapclient/' . $datasource->_baseConfig['standard_wsdl'];
         }
         $database_fields = Xml::toArray(Xml::build($wsdl));
         $schemas = $database_fields['definitions']['types']['schema'][0]['complexType'];
         $this_wsdl_schema = array();
         foreach ($schemas as $schema) {
             if ($schema['@name'] == $this->name) {
                 $this_wsdl_schema = $schema['complexContent']['extension']['sequence']['element'];
                 break;
             }
         }
         $names = Hash::extract($this_wsdl_schema, '{n}.@name');
         $types = Hash::extract($this_wsdl_schema, '{n}.@type');
         $new_array = array('Id' => array('type' => 'string', 'length' => 16));
         $n = 0;
         $type_name = "";
         foreach ($names as $name) {
             if (substr($types[$n], 0, 3) != "ens") {
                 //we dont want type of ens
                 if (substr($types[$n], 4) != "QueryResult") {
                     //Or this
                     if (substr($types[$n], 4) == "int") {
                         $type_name = "integer";
                     } elseif (substr($types[$n], 4) == "boolean") {
                         $type_name = "boolean";
                     } elseif (substr($types[$n], 4) == "dateTime" || substr($types[$n], 4) == "date") {
                         $type_name = "datetime";
                     } else {
                         $type_name = "string";
                     }
                     $new_array[$name] = array('type' => $type_name, 'length' => 255);
                 }
             }
             $n++;
         }
         $this->_schema = $new_array;
     }
     return true;
 }
Esempio n. 15
0
 /**
  * Get plugin information
  *
  * @return array
  */
 public static function getPluginData()
 {
     $dir = new Folder(APP . 'Plugin');
     $files = $dir->read(true, ['empty']);
     $plugins = [];
     foreach ($files[0] as $folder) {
         $file = new File(APP . 'Plugin' . DS . $folder . DS . 'Config' . DS . 'info.xml');
         if ($file->exists()) {
             $fileContent = $file->read();
             $plugin = Xml::toArray(Xml::build($fileContent));
             $plugins[$folder] = $plugin['plugin'];
         }
     }
     return $plugins;
 }
Esempio n. 16
0
 /**
  * Sobrescreve exceção do Cake para incluir informação
  * do erro que poderá ser logada.
  *
  * @param string  $message Mensagem da Exceção
  * @param integer $code    Código do erro
  * @param string  $error   O erro retornado pelo PagSeguro (possivelmente um XML)
  */
 public function __construct($message, $code = 1, $error = null)
 {
     if (!empty($error)) {
         try {
             $decoded = Xml::toArray(Xml::build($error));
             $error = $this->_parseXmlError($decoded);
         } catch (XmlException $e) {
             // apenas uma string... não faz conversão
         }
         $error .= $this->getTraceAsString();
         $msg = $message . " (Problema relacionado ao PagSeguro)\n" . $error;
         CakeLog::write('error', $msg);
     }
     parent::__construct($message, $code);
 }
Esempio n. 17
0
 /**
  * Reads an (external) RSS feed and returns it's items.
  *
  * @param $feed - The URL to the feed.
  * @param int $items - The amount of items to read.
  * @return array
  * @throws InternalErrorException
  */
 public function read($feed, $items = 5)
 {
     try {
         // RSSフィードをリード
         $xmlObject = Xml::build($feed);
     } catch (XmlException $e) {
         // Reading XML failed, throw InternalErrorException
         throw new InternalErrorException();
     }
     $output = array();
     for ($i = 0; $i < $items; $i++) {
         if (is_object($xmlObject->channel->item->{$i})) {
             $output[] = $xmlObject->channel->item->{$i};
         }
     }
     return $output;
 }
Esempio n. 18
0
 public static function getThemeData()
 {
     $defaults = array('name' => '', 'description' => '', 'theme_url' => '', 'author' => '', 'author_url' => '', 'version' => '', 'tags' => '');
     App::import('Utility', 'Xml');
     $viewPath = App::path('View');
     $dir = new Folder($viewPath[0] . 'Themed');
     $files = $dir->read(true, array('empty'));
     foreach ($files[0] as $i => $folder) {
         $file = new File($viewPath[0] . 'Themed' . DS . $folder . DS . 'Config' . DS . 'info.xml');
         if ($file->exists()) {
             $fileContent = $file->read();
             $theme = Xml::toArray(Xml::build($fileContent));
             $themes[Inflector::camelize($folder)] = Hash::merge($defaults, $theme['theme']);
         }
     }
     return $themes;
 }
Esempio n. 19
0
 public function geoLocation($data)
 {
     if (!empty($data)) {
         // API URL 作成
         $url = 'http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder?';
         $url .= 'appid=';
         $url .= 'tgDrTn6xg67ij9u5DwoG3JtStTLaWB4rSk5k5nCE.UMEEP7ub_bR0Ei4A8TsOtJfzhcpx08-';
         $url .= '&query=';
         $url .= urlencode($data);
         $url .= '&recursive=true&results=1';
         //debug($url);
         // Socket通信
         App::uses('HttpSocket', 'Network/Http');
         $http = new HttpSocket();
         $response = $http->get($url);
         // レスポンス200以外はエラー
         if ($http->response['status']['code'] != 200) {
             debug('not200');
             return false;
         }
         //debug($http->response['status']['code']);
         //debug($response);
         //debug($response['code']);
         //debug($response['body']);
         // XMLパース
         App::uses('Xml', 'Utility');
         $xml = Xml::build($response['body']);
         //debug($xml);
         //$tmp = (string)$xml->Feature->Geometry->Coordinates;
         //debug($xml->Feature->Geometry->Coordinates);
         //debug($tmp);
         // 候補があるかどうか
         if ((int) $xml->ResultInfo->Count == 0) {
             debug('count0');
             return false;
         }
         // Latitude, Longitude 取得
         $coordinates = array();
         list($coordinates['Latitude'], $coordinates['Longitude']) = explode(',', (string) $xml->Feature->Geometry->Coordinates);
         return $coordinates;
     } else {
         debug('noData');
         return false;
     }
 }
Esempio n. 20
0
 public function beforeSave($options = array())
 {
     if (!empty($this->data['Post']['post_dt'])) {
         $this->data['Post']['post_dt'] = $this->dateFormatBeforeSave($this->data['Post']['post_dt']);
     }
     App::uses('Xml', 'Utility');
     App::uses('HttpSocket', 'Network/Http');
     $http = new HttpSocket();
     $response = $http->get('http://www.earthtools.org/timezone/' . $this->data['Post']['latitude'] . '/' . $this->data['Post']['longitude']);
     if ($response->code == '200') {
         $response = Xml::toArray(Xml::build($response->body()));
         $response = 'GMT' . $response['timezone']['offset'];
     } else {
         $response = '';
     }
     $this->data[$this->alias]['post_dt_offset'] = $response;
     return true;
 }
Esempio n. 21
0
 protected function request($data = null)
 {
     App::uses('Xml', 'Utility');
     $xml = $this->buildRequest($data);
     //print_r($xml);
     $ch = curl_init($this->url);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
     $res = curl_exec($ch);
     $res = strstr($res, '<?');
     $response = Xml::toArray(Xml::build($res));
     //print_r($response);
     return $response;
 }
 public function getRate($data = null)
 {
     if ($data['Weight'] < 0.1) {
         $data['Weight'] = 0.1;
     }
     if ($data['Weight'] > 70) {
         $data['Weight'] = 70;
     }
     $xml = $this->buildRequest($data);
     App::uses('HttpSocket', 'Network/Http');
     $httpSocket = new HttpSocket();
     $res = $httpSocket->post($this->url, $xml);
     App::uses('Xml', 'Utility');
     $response = Xml::toArray(Xml::build($res['body']));
     $formattedResponse = $this->formatResponse($response);
     if (!empty($formattedResponse)) {
         return $formattedResponse;
     }
     return false;
 }
Esempio n. 23
0
 /**
  * Creates a formatted list element
  *
  * ### Usage
  * Note: For CakePHP 2.x before 2.2, replace Hash::merge with Set::merge
  * `echo $this->Menu->item($html->link('Example Link', array('controller' => 'example', 'action' => 'view', 3)), array('class' => 'myListClass'));`
  *
  * @param string $link Link in the form <a href="" [...]>.
  * @param array $attributes Options to use for the list element.
  * @return string The passed link with list tags containing the applicable attributes.
  */
 function item($link, $attributes = array())
 {
     // class to apply to the list element if the link routes to the current controller
     $activeClass = 'active';
     // pull href attribute from the <a> element, remove any base URL for proper controller and action mapping from Router::parse()
     $linkRoutes = Xml::toArray(Xml::build($link));
     $linkRoutes = str_replace($this->base, '', $linkRoutes['a']['@href']);
     $linkRoutes = Router::parse($linkRoutes);
     // if the current controller matches the one the link routes to, it is active
     if ($this->params['controller'] == $linkRoutes['controller'] && $this->params['action'] == $linkRoutes['action']) {
         if (isset($attributes['class'])) {
             $classes = explode(' ', $attributes['class']);
             $classes[] = $activeClass;
             $attributes['class'] = $classes;
         } else {
             $attributes['class'] = $activeClass;
         }
     }
     return $this->Html->tag('li', $link, $attributes);
 }
Esempio n. 24
0
 /**
  * Convert XML file to DOMDocument and validate against Edexml XSD
  *
  * @param string $filename Filename of XML file
  * @return mixed A DOMDocument (DOMDocument), or false (boolean) on validation errors
  */
 protected function _parse($filename)
 {
     $dom = false;
     if (file_exists($filename)) {
         // Enable user error handling
         libxml_use_internal_errors(true);
         libxml_clear_errors();
         $dom = Xml::build($filename, ['return' => 'domdocument']);
         if ($dom) {
             $schemaFile = CakePlugin::path('Edexml') . 'File' . DS . 'EDEXML-2.0' . DS . 'EDEXML.structuur.xsd';
             if (!$dom->schemaValidate($schemaFile)) {
                 $dom = false;
                 foreach (libxml_get_errors() as $error) {
                     CakeLog::error($this->_displayXmlError($error), 'debug');
                 }
                 libxml_clear_errors();
             }
         }
     }
     return $dom;
 }
Esempio n. 25
0
 /**
  * index method
  *
  * @return void
  */
 public function index()
 {
     $this->loadModel('User');
     $this->loadModel('Beer');
     $this->helpers[] = 'RssParser';
     $user = $this->User->findByFacebookId(self::$fbUser);
     $astFive = $this->User->Pageviews->getLast($user['User']['id'], 5);
     $this->set('localUser', $user);
     $lastFive = array();
     foreach ($astFive as $index => $date) {
         $lastFive[$date] = $this->Beer->findById($index);
     }
     $this->set(compact('lastFive'));
     //$favorites = $this->User->Favorite->find('all', array('Favorite.user_id'=>$user['User']['id']));
     ////$this->set(compact($favorites));
     //$this->Favorite->recursive = 0;
     $this->set('favorites', $this->paginate(array('Favorite.user_id' => $user['User']['id'], 'Favorite.beer_id !=' => '0', 'Favorite.active' => '1')));
     $this->set('favoriteBreweries', $this->paginate(array('Favorite.user_id' => $user['User']['id'], 'Favorite.brewery_id !=' => '0', 'Favorite.active' => '1')));
     $xml = Xml::build('https://allaboutbeer.com/rss');
     $this->set('rss', Xml::toArray($xml));
 }
 public function send($path, $data, $type = 'json')
 {
     switch ($type) {
         case 'json':
             $contentType = 'application/json';
             if (!is_string($data)) {
                 $data = json_encode($data);
             }
             break;
         case 'xml':
             $contentType = 'text/xml';
             break;
         default:
             throw new InternalErrorException('LinkedIn: Type "' . $type . '" not supported');
     }
     $accessToken = $this->Controller->Session->read(self::SESSION_ACCESS);
     $responseText = $this->createConsumer()->postRaw($accessToken->key, $accessToken->secret, self::API_URL . $path, $data, $contentType);
     $response = Xml::toArray(Xml::build($result->body));
     if (isset($response['error'])) {
         throw new InternalErrorException('LinkedIn: ' . $response['error']['message']);
     }
     return $response;
 }
 public function main()
 {
     App::uses('Sanitize', 'Utility');
     App::uses('Xml', 'Utility');
     $filename = TMP . 'Products117_20121220.xml';
     $itemsTemp = Xml::toArray(Xml::build($filename));
     echo count($itemsTemp['maestro']['product']);
     $changed = '';
     $tmrow = '';
     foreach ($itemsTemp['maestro']['product'] as $maestro) {
         //print_r($maestro);
         $product = $this->Product->find('first', array('recursive' => -1, 'fields' => array('Product.id', 'Product.vendor_sku', 'Product.name', 'Product.price', 'Product.price_wholesale', 'Product.price_list'), 'conditions' => array('Product.user_id' => 11, 'Product.vendor_sku' => $maestro['productid'])));
         if (!empty($product)) {
             if (number_format($maestro['cost'], 2) != $product['Product']['price_wholesale']) {
                 // echo "\n\n";
                 // echo '####################################################################';
                 // echo "\n\n";
                 // echo $maestro['productname'] . "\n";
                 // echo $maestro['cost'] . "\n";
                 // echo "\n\n";
                 // print_r($product);
                 // echo '####################################################################';
                 // echo "\n\n";
                 $row = "\n\nMAESTRO NAME: " . urldecode($maestro['productname']) . ' - MAESTRO COST: ' . number_format($maestro['cost'], 2) . " \n GB ID: " . $product['Product']['id'] . ' GB NAME: ' . $product['Product']['name'] . ' GB PRICE: ' . $product['Product']['price'] . 'GB WHOLESALE: ' . $product['Product']['price_wholesale'];
                 if ($row != $tmrow) {
                     $changed .= $row;
                     echo $row;
                 }
                 $tmrow = $row;
             }
         }
     }
     //mail('*****@*****.**', 'Maestro price changes script', $changed);
     echo "\n\n\n";
     echo $changed;
 }
Esempio n. 28
0
 public function json()
 {
     $this->autoRender = false;
     //var_dump(WWW_ROOT);
     //var_dump(WEBROOT_DIR);
     //var_dump($this->params->query);
     if (empty($this->params->query['coords'])) {
         return json_encode(array('error' => 'No coordinates provided'));
     }
     $values = explode(',', $this->params->query['coords']);
     $coords = array_map('doubleval', $values);
     $distances = array();
     $xml = Xml::build('http://api.irishrail.ie/realtime/realtime.asmx/getAllStationsXML');
     foreach ($xml->objStation as $f) {
         //echo json_encode($f);
         //echo $f->StationLatitude;
         //echo $f->StationLongitude;
         $distances[] = array('station' => (string) $f->StationDesc, 'code' => (string) $f->StationCode, 'distance' => $this->haversGCD($coords[0], $coords[1], (double) $f->StationLatitude, (double) $f->StationLongitude));
     }
     usort($distances, array($this, 'distance_compare'));
     //echo $distances[0]['code'];
     $trains = Xml::build('http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByCodeXML?StationCode=' . $distances[0]['code']);
     return json_encode($trains);
 }
 /**
  * testSaveFromXml method
  *
  * @return void
  */
 public function testSaveFromXml()
 {
     $this->markTestSkipped('This feature needs to be fixed or dropped');
     $this->loadFixtures('Article');
     App::uses('Xml', 'Utility');
     $Article = new Article();
     $result = $Article->save(Xml::build('<article title="test xml" user_id="5" />'));
     $this->assertFalse(empty($result));
     $results = $Article->find('first', array('conditions' => array('Article.title' => 'test xml')));
     $this->assertFalse(empty($results));
     $result = $Article->save(Xml::build('<article><title>testing</title><user_id>6</user_id></article>'));
     $this->assertFalse(empty($result));
     $results = $Article->find('first', array('conditions' => array('Article.title' => 'testing')));
     $this->assertFalse(empty($results));
     $result = $Article->save(Xml::build('<article><title>testing with DOMDocument</title><user_id>7</user_id></article>', array('return' => 'domdocument')));
     $this->assertFalse(empty($result));
     $results = $Article->find('first', array('conditions' => array('Article.title' => 'testing with DOMDocument')));
     $this->assertFalse(empty($results));
 }
Esempio n. 30
0
    /**
     * testXmlSetReverse method
     *
     * @return void
     */
    public function testXmlSetReverse()
    {
        App::uses('Xml', 'Utility');
        $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
		<rss version="2.0">
			<channel>
			<title>Cake PHP Google Group</title>
			<link>http://groups.google.com/group/cake-php</link>
			<description>Search this group before posting anything. There are over 20,000 posts and it&amp;#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
			<language>en</language>
				<item>
				<title>constructng result array when using findall</title>
				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
				<description>i&#39;m using cakephp to construct a logical data model array that will be &lt;br&gt; passed to a flex app. I have the following model association: &lt;br&gt; ServiceDay-&amp;gt;(hasMany)ServiceTi me-&amp;gt;(hasMany)ServiceTimePrice. So what &lt;br&gt; the current output from my findall is something like this example: &lt;br&gt; &lt;p&gt;Array( &lt;br&gt; [0] =&amp;gt; Array(</description>
				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
				<author>bmil...@gmail.com(bpscrugs)</author>
				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
				</item>
				<item>
				<title>Re: share views between actions?</title>
				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
				<description>Then perhaps you might do us all a favour and refrain from replying to &lt;br&gt; things you do not understand. That goes especially for asinine comments. &lt;br&gt; Indeed. &lt;br&gt; To sum up: &lt;br&gt; No comment. &lt;br&gt; In my day, a simple &amp;quot;RTFM&amp;quot; would suffice. I&#39;ll keep in mind to ignore any &lt;br&gt; further responses from you. &lt;br&gt; You (and I) were referring to the *online documentation*, not other</description>
				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
			 </item>
		</channel>
		</rss>';
        $xml = Xml::build($string);
        $result = Set::reverse($xml);
        $expected = array('rss' => array('@version' => '2.0', 'channel' => array('title' => 'Cake PHP Google Group', 'link' => 'http://groups.google.com/group/cake-php', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'language' => 'en', 'item' => array(array('title' => 'constructng result array when using findall', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(", 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'author' => 'bmil...@gmail.com(bpscrugs)', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT'), array('title' => 'Re: share views between actions?', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8', 'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other', 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT')))));
        $this->assertEquals($expected, $result);
        $string = '<data><post title="Title of this post" description="cool"/></data>';
        $xml = Xml::build($string);
        $result = Set::reverse($xml);
        $expected = array('data' => array('post' => array('@title' => 'Title of this post', '@description' => 'cool')));
        $this->assertEquals($expected, $result);
        $xml = Xml::build('<example><item><title>An example of a correctly reversed SimpleXMLElement</title><desc/></item></example>');
        $result = Set::reverse($xml);
        $expected = array('example' => array('item' => array('title' => 'An example of a correctly reversed SimpleXMLElement', 'desc' => '')));
        $this->assertEquals($expected, $result);
        $xml = Xml::build('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
        $result = Set::reverse($xml);
        $expected = array('example' => array('item' => array('@attr' => '123', 'titles' => array('title' => array('title1', 'title2')))));
        $this->assertEquals($expected, $result);
        $xml = Xml::build('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
        $result = Set::reverse($xml);
        $expected = array('example' => array('@attr' => 'ex_attr', 'item' => array('@attr' => '123', 'titles' => 'list', '@' => 'textforitems')));
        $this->assertEquals($expected, $result);
        $string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
		<rss version="2.0" xmlns:dc="http://www.cakephp.org/">
			<channel>
			<title>Cake PHP Google Group</title>
			<link>http://groups.google.com/group/cake-php</link>
			<description>Search this group before posting anything. There are over 20,000 posts and it&amp;#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.</description>
			<language>en</language>
				<item>
				<title>constructng result array when using findall</title>
				<link>http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</link>
				<description>i&#39;m using cakephp to construct a logical data model array that will be &lt;br&gt; passed to a flex app. I have the following model association: &lt;br&gt; ServiceDay-&amp;gt;(hasMany)ServiceTi me-&amp;gt;(hasMany)ServiceTimePrice. So what &lt;br&gt; the current output from my findall is something like this example: &lt;br&gt; &lt;p&gt;Array( &lt;br&gt; [0] =&amp;gt; Array(</description>
					<dc:creator>cakephp</dc:creator>
				<category><![CDATA[cakephp]]></category>
				<category><![CDATA[model]]></category>
				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f</guid>
				<author>bmil...@gmail.com(bpscrugs)</author>
				<pubDate>Fri, 28 Dec 2007 00:44:14 UT</pubDate>
				</item>
				<item>
				<title>Re: share views between actions?</title>
				<link>http://groups.google.com/group/cake-php/msg/8b350d898707dad8</link>
				<description>Then perhaps you might do us all a favour and refrain from replying to &lt;br&gt; things you do not understand. That goes especially for asinine comments. &lt;br&gt; Indeed. &lt;br&gt; To sum up: &lt;br&gt; No comment. &lt;br&gt; In my day, a simple &amp;quot;RTFM&amp;quot; would suffice. I&#39;ll keep in mind to ignore any &lt;br&gt; further responses from you. &lt;br&gt; You (and I) were referring to the *online documentation*, not other</description>
					<dc:creator>cakephp</dc:creator>
				<category><![CDATA[cakephp]]></category>
				<category><![CDATA[model]]></category>
				<guid isPermaLink="true">http://groups.google.com/group/cake-php/msg/8b350d898707dad8</guid>
				<author>subtropolis.z...@gmail.com(subtropolis zijn)</author>
				<pubDate>Fri, 28 Dec 2007 00:45:01 UT</pubDate>
			 </item>
		</channel>
		</rss>';
        $xml = Xml::build($string);
        $result = Set::reverse($xml);
        $expected = array('rss' => array('@version' => '2.0', 'channel' => array('title' => 'Cake PHP Google Group', 'link' => 'http://groups.google.com/group/cake-php', 'description' => 'Search this group before posting anything. There are over 20,000 posts and it&#39;s very likely your question was answered before. Visit the IRC channel #cakephp at irc.freenode.net for live chat with users and developers of Cake. If you post, tell us the version of Cake, PHP, and database.', 'language' => 'en', 'item' => array(array('title' => 'constructng result array when using findall', 'link' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f', 'description' => "i'm using cakephp to construct a logical data model array that will be <br> passed to a flex app. I have the following model association: <br> ServiceDay-&gt;(hasMany)ServiceTi me-&gt;(hasMany)ServiceTimePrice. So what <br> the current output from my findall is something like this example: <br> <p>Array( <br> [0] =&gt; Array(", 'dc:creator' => 'cakephp', 'category' => array('cakephp', 'model'), 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/49bc00f3bc651b4f'), 'author' => 'bmil...@gmail.com(bpscrugs)', 'pubDate' => 'Fri, 28 Dec 2007 00:44:14 UT'), array('title' => 'Re: share views between actions?', 'link' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8', 'description' => 'Then perhaps you might do us all a favour and refrain from replying to <br> things you do not understand. That goes especially for asinine comments. <br> Indeed. <br> To sum up: <br> No comment. <br> In my day, a simple &quot;RTFM&quot; would suffice. I\'ll keep in mind to ignore any <br> further responses from you. <br> You (and I) were referring to the *online documentation*, not other', 'dc:creator' => 'cakephp', 'category' => array('cakephp', 'model'), 'guid' => array('@isPermaLink' => 'true', '@' => 'http://groups.google.com/group/cake-php/msg/8b350d898707dad8'), 'author' => 'subtropolis.z...@gmail.com(subtropolis zijn)', 'pubDate' => 'Fri, 28 Dec 2007 00:45:01 UT')))));
        $this->assertEquals($expected, $result);
        $text = '<?xml version="1.0" encoding="UTF-8"?>
		<XRDS xmlns="xri://$xrds">
		<XRD xml:id="oauth" xmlns="xri://$XRD*($v*2.0)" version="2.0">
			<Type>xri://$xrds*simple</Type>
			<Expires>2008-04-13T07:34:58Z</Expires>
			<Service>
				<Type>http://oauth.net/core/1.0/endpoint/authorize</Type>
				<Type>http://oauth.net/core/1.0/parameters/auth-header</Type>
				<Type>http://oauth.net/core/1.0/parameters/uri-query</Type>
				<URI priority="10">https://ma.gnolia.com/oauth/authorize</URI>
				<URI priority="20">http://ma.gnolia.com/oauth/authorize</URI>
			</Service>
		</XRD>
		<XRD xmlns="xri://$XRD*($v*2.0)" version="2.0">
			<Type>xri://$xrds*simple</Type>
				<Service priority="10">
					<Type>http://oauth.net/discovery/1.0</Type>
					<URI>#oauth</URI>
				</Service>
		</XRD>
		</XRDS>';
        $xml = Xml::build($text);
        $result = Set::reverse($xml);
        $expected = array('XRDS' => array('XRD' => array(array('@xml:id' => 'oauth', '@version' => '2.0', 'Type' => 'xri://$xrds*simple', 'Expires' => '2008-04-13T07:34:58Z', 'Service' => array('Type' => array('http://oauth.net/core/1.0/endpoint/authorize', 'http://oauth.net/core/1.0/parameters/auth-header', 'http://oauth.net/core/1.0/parameters/uri-query'), 'URI' => array(array('@' => 'https://ma.gnolia.com/oauth/authorize', '@priority' => '10'), array('@' => 'http://ma.gnolia.com/oauth/authorize', '@priority' => '20')))), array('@version' => '2.0', 'Type' => 'xri://$xrds*simple', 'Service' => array('@priority' => '10', 'Type' => 'http://oauth.net/discovery/1.0', 'URI' => '#oauth')))));
        $this->assertEquals($expected, $result);
    }