Beispiel #1
0
 function xml()
 {
     // import XML class
     App::import('Xml');
     // your XML file's location
     $file = TMP . 'uploads' . DS . "product.xml";
     // now parse it
     $parsed_xml =& new XML($file);
     $parsed_xml = Set::reverse($parsed_xml);
     // this is what i call magic
     // see the returned array
     // debug($parsed_xml);
     //$i = 0;
     foreach ($parsed_xml['Doct']['Product'] as $for_img) {
         //$newImage[$i]['old_id'] = $for_img['product_id'];
         if (isset($for_img['BigImage']['src'])) {
             //$newImage[$for_img['product_id']] = $for_img['BigImage']['src'];
             $this->Gift->recursive = -1;
             $giftId = $this->Gift->find('first', array('conditions' => array('Gift.old_id' => $for_img['product_id'])));
             $this->data['Image']['gift_id'] = $giftId['Gift']['id'];
             $this->data['Image']['img'] = $for_img['BigImage']['src'];
             debug($this->data['Image']);
             $this->Image->create();
             $this->Image->save($this->data['Image']);
             $this->Image->id = null;
             //$newImage[$i]['SmallImage'] = $for_img['SmallImage']['src'];
         }
         //$i++;
     }
     debug($newImage);
 }
Beispiel #2
0
 /**
  * Process the request from MN Digital
  * @param $options an array of the function and search request
  * @return $data a formated array converting the xml response to an object to an array
  */
 public function request($options = array())
 {
     // fetch respponse
     $this->HttpSocket = new HttpSocket();
     $response = $this->HttpSocket->get($this->url, array_merge($options, $this->defaults));
     // convert xml to object
     $xml = new Xml($response);
     // convert object to array
     $this->results = Set::reverse($xml);
     // format the results
     foreach ($this->results['AlbumSearchResults']['Albums'] as $key => $value) {
         $data[$key]['mnid'] = $value['MnetId'];
         $data[$key]['artist'] = $value['Artist']['Name'];
         $data[$key]['genre'] = $value['Genre'];
         $data[$key]['explicit'] = $value['ExplicitLyrics'];
         $data[$key]['date'] = $value['ReleaseDate'];
         $data[$key]['tracks'] = $value['NumberOfTracks'];
         $data[$key]['length'] = $value['Duration'];
         $data[$key]['name'] = $value['Title'];
         $data[$key]['media'] = $value['Images'];
         foreach ($value['Tracks']['Track'] as $key2 => $value2) {
             $data[$key]['track'][$key2]['name'] = $value2['Title'];
             $data[$key]['track'][$key2]['artist'] = $value2['Artist']['Name'];
             $data[$key]['track'][$key2]['length'] = $value2['Duration'];
             $data[$key]['track'][$key2]['mnid'] = $value2['MnetId'];
             $data[$key]['track'][$key2]['track'] = $value2['TrackNumber'];
             $data[$key]['track'][$key2]['sample'] = $value2['SampleLocations']['MediaLocation'];
         }
     }
     return $data;
 }
Beispiel #3
0
 /**
  * [AJAX] Twitterのステータスを更新する(ツイート)
  * @return	mixid	TwitterユーザープロフィールへのURL / false
  * @access	public
  */
 function admin_update()
 {
     if (!$this->data) {
         $this->notFound();
     } else {
         $result = false;
         if (!empty($this->data['Twitter']['status'])) {
             if ($this->Twitter->setupTwitterBehavior()) {
                 $result = $this->Twitter->update($this->data['Twitter']['status']);
                 if ($result) {
                     App::import('Core', 'Xml');
                     $xml = new Xml($result);
                     $array = Set::reverse($xml);
                     if (!empty($array['Status']['User']['screen_name'])) {
                         $result = 'http://twitter.com/' . $array['Status']['User']['screen_name'];
                     } else {
                         $result = false;
                     }
                 }
             }
         }
         $this->set('result', $result);
     }
     $this->render('ajax_result');
 }
 function add($dashboard_id, $template = null)
 {
     if (!empty($template) && !empty($dashboard_id)) {
         $this->Dbview->create();
         $this->data['Dbview']['name'] = $template;
         $this->data['Dbview']['code'] = file_get_contents(APP . 'templates' . DS . 'views' . DS . $template . DS . $template . '.js');
         $this->data['Dbview']['dashboard_id'] = $dashboard_id;
         $this->data['Dbview']['left'] = 100;
         $this->data['Dbview']['top'] = 100;
         $this->data['Dbview']['width'] = 300;
         $this->data['Dbview']['height'] = 300;
         if ($this->Dbview->save($this->data)) {
             $this->Session->setFlash(__('The dbview has been saved', true));
             $this->redirect(array('controller' => 'dashboards', 'action' => 'view', $dashboard_id));
         } else {
             $this->Session->setFlash(__('The dbview could not be saved. Please, try again.', true));
         }
     }
     $files = scandir(APP . 'templates' . DS . 'views');
     App::import('Xml');
     foreach ($files as $f) {
         if ($f == '.' || $f == '..' || $f == '.svn') {
             continue;
         }
         $templates[] = Set::reverse(new Xml(APP . 'templates' . DS . 'views' . DS . $f . DS . $f . '.xml'));
         $templates[count($templates) - 1]['Template']['code'] = file_get_contents(APP . 'templates' . DS . 'views' . DS . $f . DS . $f . '.js');
     }
     $this->set(compact('templates', 'dashboard_id'));
 }
 function find($type, $query = array())
 {
     if (is_array($type)) {
         $query = $type;
     } else {
         $query['type'] = $type;
     }
     if (!is_array($query)) {
         $query = array('Title' => $query);
     }
     $map = array('info' => 'ResponseGroup', 'type' => 'SearchIndex');
     foreach ($map as $old => $new) {
         $query[$new] = $query[$old];
         unset($query[$old]);
     }
     foreach ($query as $key => $val) {
         if (preg_match('/^[a-z]/', $key)) {
             $query[Inflector::camelize($key)] = $val;
             unset($query[$key]);
         }
     }
     $query = am(array('Service' => 'AWSECommerceService', 'AWSAccessKeyId' => $this->config['key'], 'Operation' => 'ItemSearch', 'Version' => '2008-06-28'), $query);
     $r = $this->Http->get('http://ecs.amazonaws.com/onca/xml', $query);
     $r = Set::reverse(new Xml($r));
     return $r;
 }
 function add()
 {
     if ($this->isAPIKeyCorrect) {
         if (!empty($this->data)) {
             $data = array();
             //If the posted data is in XML format
             if ($this->params['url']['ext'] == 'xml') {
                 //Parse the XML Object into an array
                 $data = Set::reverse($this->data);
             } else {
                 $data = json_decode($this->data);
             }
             //Create a fountain model to use the save method
             $this->Fountain->create();
             //If it's possible to save the data
             if ($this->Fountain->save($data)) {
                 $this->set('status', '201 Created');
             } else {
                 $this->set('status', '500 Internal Server Error');
             }
         } else {
             $this->set('status', '401 Unauthorized');
         }
     }
 }
 function set($one, $two = null, $protectFields = true)
 {
     if ($protectFields) {
         if (!$one) {
             return;
         }
         if (is_object($one)) {
             $one = Set::reverse($one);
         }
         if (is_array($one)) {
             if (empty($one[$this->alias])) {
                 if ($this->getAssociated(key($one)) === null) {
                     $one = array($this->alias => $one);
                 }
             }
             foreach ($one as $alias => $data) {
                 if ($alias == $this->alias) {
                     $one[$alias] = $this->filterProtectedFields($data);
                 } else {
                     $associated = $this->getAssociated($alias);
                     if (!empty($associated)) {
                         $model = $associated['className'];
                         $one[$alias] = $this->{$model}->filterProtectedFields($data);
                     }
                 }
             }
         }
     }
     parent::set($one, $two);
 }
 protected function _parseResponse($response)
 {
     $results = json_decode($response->body);
     if (is_object($results)) {
         $results = Set::reverse($results);
     }
     return $results;
 }
Beispiel #9
0
 function importXml()
 {
     $file = dirname(dirname(__FILE__)) . '/vendors/emoji4unicode.xml';
     $xml = new Xml($file);
     $this->data = Set::reverse($xml);
     Cache::write('MobileKitEmoji', serialize($this->data));
     return;
 }
 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));
 }
Beispiel #11
0
 public function getFontsVendor($fontFamily)
 {
     $vendor = 'browser';
     $browserFonts = Set::flatten(Set::reverse($this->getBrowserFontsList()->items));
     if (!in_array($fontFamily, $browserFonts)) {
         $vendor = 'google';
     }
     return $vendor;
 }
 public function isFeriado(Model $model, DateTime $data, $regioes = array())
 {
     $this->feriados = array_reduce(array_merge($regioes, ['GERAL']), function ($red, $val) {
         $feriados = Set::reverse($this->getFeriadosFixos($val));
         return !isset($red) ? $feriados : array_merge($red, $feriados);
     });
     $this->calculaFeriadosMoveis($data->format('Y'));
     return in_array($data->format('d/m'), $this->feriados);
 }
Beispiel #13
0
 /**
  * Get the content of theme.xml file
  *
  * @param string $alias theme folder name
  * @return array
  */
 function getData($alias = null)
 {
     if ($alias == null) {
         $themeXml =& new XML(WWW_ROOT . 'theme.xml');
     } else {
         $themeXml =& new XML(WWW_ROOT . 'themed' . DS . $alias . DS . 'theme.xml');
     }
     $themeData = Set::reverse($themeXml);
     return $themeData;
 }
 public function getAllTweets($q, $limit = 1)
 {
     /*$results[$this->settings['page']] = $this->getTweets($q);
       
       while (array_key_exists('feed', $results[$this->settings['page']]) && $this->checkNext($results[$this->settings['page']]['feed']['link']) && $this->settings['page'] <=$limit){
           $this->settings['page'] +=1;
           $results[$this->settings['page']] = $this->getTweets($q); 		
       }*/
     $results = Set::reverse($this->Twitter->OAuth->get('search/tweets', array('q' => $q, 'lang' => $this->settings['lang'], 'count' => $this->settings['rpp'])));
     return $results;
 }
 /**
  * List all the plugins in the github plugin account
  *
  * @return array
  * @author Jose Diaz-Gonzalez
  */
 function __listServerPlugins($maintainer = null)
 {
     $githubServer = "http://github.com/api/v2/xml/";
     $maintainer = $maintainer == null ? 'cakephp-plugin-provider' : $maintainer;
     $pluginList = array();
     Cache::set(array('duration' => '+7 days'));
     if (($pluginList = Cache::read('Plugins.server.list.' . date('W-Y'))) === false) {
         $xmlResponse = new Xml($this->Socket->get("{$githubServer}repos/show/{$maintainer}"));
         $pluginList = Set::reverse($xmlResponse);
         Cache::set(array('duration' => '+7 days'));
         Cache::write('Plugins.server.list.' . date('W-Y'), $pluginList);
     }
     return $pluginList['Repositories']['Repository'];
 }
 /**
  * Recursively goes through an array and makes neat HTML out of it.
  *
  * @param mixed $values Array to make pretty.
  * @param int $openDepth Depth to add open class
  * @param int $currentDepth current depth.
  * @return string
  **/
 public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubleEncode = false)
 {
     $className = "neat-array depth-{$currentDepth}";
     if ($openDepth > $currentDepth) {
         $className .= ' expanded';
     }
     $nextDepth = $currentDepth + 1;
     $out = "<ul class=\"{$className}\">";
     if (!is_array($values)) {
         if (is_bool($values)) {
             $values = array($values);
         }
         if (is_null($values)) {
             $values = array(null);
         }
     }
     if (empty($values)) {
         $values[] = '(empty)';
     }
     foreach ($values as $key => $value) {
         $out .= '<li><strong>' . $key . '</strong>';
         if ($value === null) {
             $value = '(null)';
         }
         if ($value === false) {
             $value = '(false)';
         }
         if ($value === true) {
             $value = '(true)';
         }
         if (empty($value) && $value != 0) {
             $value = '(empty)';
         }
         if ($value instanceof Closure) {
             $value = 'function';
         }
         if (is_object($value)) {
             $value = Set::reverse($value, true);
         }
         if (is_array($value) && !empty($value)) {
             $out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode);
         } else {
             $out .= h($value, $doubleEncode);
         }
         $out .= '</li>';
     }
     $out .= '</ul>';
     return $out;
 }
Beispiel #17
0
 function __readData()
 {
     $config = $this->config;
     $feedUrl = $config['feedUrl'];
     $cacheTime = $config['cacheTime'];
     $cachePath = 'rss_' . md5($feedUrl);
     $data = cache($cachePath, null, $cacheTime);
     if (!$data) {
         $data = Set::reverse(new XML($this->config['feedUrl'], array('version' => $this->config['version'], 'encoding' => $this->config['encoding'])));
         cache($cachePath, serialize($data));
     } else {
         $data = unserialize($data);
     }
     return $data;
 }
Beispiel #18
0
 function parse_xml($file)
 {
     App::import('Xml');
     $parsed_xml = new XML($file);
     // Conversie din obiect in array. E mai simplu de extras datele si parcurs.
     $parsed_xml = Set::reverse($parsed_xml);
     //debug($parsed_xml);
     // Scapam de namespace-urile RSS-ului, pastram doar continutul interesant
     foreach ($parsed_xml as &$data) {
         foreach ($data as $feed) {
             continue;
         }
     }
     return $feed;
 }
Beispiel #19
0
 function requisicao($envio_maximo = null)
 {
     /**
      * Trata possiveis erros como . ao invés de ,
      */
     $this->pre();
     App::import("Xml");
     $this->entrada['StrRetorno'] = 'xml';
     $target = html_entity_decode($this->api_url . '?' . http_build_query($this->entrada));
     $xml = new XML($target);
     //print_r( $this->api_url .'?'. http_build_query( $this->entrada ) ."<br>" );
     $arrFrete = Set::reverse($xml);
     $arrFrete['Servicos']['CServico']['envio_maximo'] = $envio_maximo;
     //debug( $arrFrete );
     return $this->processa($arrFrete);
 }
 function __readData()
 {
     $config = $this->config;
     $feedUrl = $config['feedUrl'];
     $cacheTime = $config['cacheTime'];
     $cachePath = 'rss_' . md5($feedUrl);
     Cache::set(array('duration' => $cacheTime));
     $data = Cache::read($cachePath);
     if ($data === false) {
         $data = Set::reverse(new XML($this->config['feedUrl'], array('version' => $this->config['version'], 'encoding' => $this->config['encoding'])));
         Cache::set(array('duration' => $cacheTime));
         Cache::write($cachePath, serialize($data));
     } else {
         $data = unserialize($data);
     }
     return $data;
 }
Beispiel #21
0
 function _parse($data)
 {
     $xml = new Xml($data);
     $xml = Set::reverse($xml);
     // RSS1.0
     if (isset($xml['RDF'])) {
         $title = $xml['RDF']['Channel']['title'];
         $link = $xml['RDF']['Channel']['link'];
         $items = array();
         foreach ($xml['RDF']['Item'] as $key => $item) {
             $items[$key]['pubDate'] = date('Y-m-d H:i:s', strtotime($item['date']));
             $items[$key]['title'] = $item['title'];
             $items[$key]['link'] = $item['link'];
             if (isset($item['encoded'])) {
                 $items[$key]['description'] = $item['encoded'];
             } else {
                 $items[$key]['description'] = $item['description'];
             }
         }
     } elseif (isset($xml['Rss'])) {
         $title = $xml['Rss']['Channel']['title'];
         $link = $xml['Rss']['Channel']['link'];
         $items = array();
         foreach ($xml['Rss']['Channel']['Item'] as $key => $item) {
             $items[$key]['pubDate'] = date('Y-m-d H:i:s', strtotime($item['pubDate']));
             $items[$key]['title'] = $item['title'];
             $items[$key]['link'] = $item['link'];
             $items[$key]['description'] = $item['description'];
         }
     } elseif (isset($xml['Feed'])) {
         $title = $xml['Feed']['title'];
         $link = $xml['Feed']['Link'][0]['href'];
         $items = array();
         foreach ($xml['Feed']['Entry'] as $key => $item) {
             $items[$key]['pubDate'] = date('Y-m-d H:i:s', strtotime($item['issued']));
             $items[$key]['title'] = $item['title'];
             $items[$key]['link'] = $item['Link']['href'];
             $items[$key]['description'] = $item['content']['value'];
         }
     } else {
         return false;
     }
     return compact('title', 'link', 'items');
 }
Beispiel #22
0
 /**
  * Startup
  *
  * @param object $controller
  * @return void
  */
 function initialize(&$controller)
 {
     $controller->isAmf = false;
     if (class_exists('amfdispatcher') && AmfDispatcher::active()) {
         $controller->isAmf = true;
         $controller->disableCache();
         $controller->view = 'Amf.Amf';
         $data = AmfDispatcher::data();
         if (!empty($data)) {
             if (is_object($data)) {
                 $controller->data = Set::reverse($data);
             } elseif (Set::countDim($data) == 1) {
                 $controller->data = array_pop($data);
             } else {
                 $controller->data = $data;
             }
         }
     }
 }
Beispiel #23
0
 /**
  * undocumented function
  *
  * @param string 
  * @param string 
  * @return void
  * @access public
  */
 function find($type, $query = array())
 {
     $args = func_get_args();
     switch ($type) {
         case 'twitter':
             $cacheKey = 'posts_index_twitter';
             $posts = Cache::read($cacheKey);
             if (!$posts) {
                 App::import('Core', 'Xml');
                 $feed = Configure::read("App.rss.news");
                 $rss = Set::reverse(new XML($feed['url']));
                 $posts = array();
                 if (isset($rss["Rss"]["Channel"]["Item"]) && !empty($rss["Rss"]["Channel"]["Item"])) {
                     $posts = $rss["Rss"]["Channel"]["Item"];
                     $posts['feed'] = $feed;
                     Cache::write($cacheKey, $posts);
                 }
             }
             return $posts;
     }
     return call_user_func_array(array('parent', 'find'), $args);
 }
 /**
  *
  * @param string $plugin Name of the plugin to generate the release for.
  * @return Nothing
  */
 public function generate($plugin)
 {
     $this->__plugin = $plugin;
     $this->__configPath = CakePlugin::path($this->__plugin) . 'Config' . DS;
     $this->__info = $this->__models = array();
     if (file_exists($this->__configPath . 'config.json')) {
         $configFile = new File($this->__configPath . 'config.json');
         $this->__info = Set::reverse(json_decode($configFile->read()));
         $this->__update();
     } else {
         App::import('core', 'String');
         $this->__info = array('id' => String::uuid(), 'name' => $this->__plugin, 'update_url' => 'infinitas-cms.org/plugins/version/plugin:' . Inflector::underscore($this->__plugin), 'version' => '1.0', 'dependancies' => array());
         $this->__initializeDependancies();
         $this->__initializeModels();
         $this->out("Initial release for " . $this->__plugin);
         $this->out("It looks like this is the first time you are generating\nan Infinitas release for this plugin.");
         do {
             $this->hr();
             $this->__initialInfo();
             $hasDependancies = !empty($this->__info['dependancies']) ? 'Y' : 'N';
             $dependancies = $this->in('Does this plugin have any non-core dependancies?', array('Y', 'N'), $hasDependancies);
             if (strtoupper($dependancies) == 'Y') {
                 $this->__configureDependancies();
             }
             $this->hr();
             $this->out($this->__info['name'] . ' (Version ' . $this->__info['version'] . ')');
             $this->__configureModels();
             $correct = $this->__reviewInformation();
         } while (strtoupper($correct) == 'N');
         if (strtoupper($correct) == 'Q') {
             return;
         } else {
             $this->__writeOut();
         }
     }
 }
 /**
  * Parse the response from ElasticSearch, throwing errors if necessary
  *
  * @param CakeResponse $response
  * @return mixed boolean true or false, or body of request as array
  * @author David Kullmann
  */
 protected function _parseResponse($response)
 {
     if (empty($response->body)) {
         throw new Exception('Missing response');
     }
     $body = json_decode($response->body);
     if (!empty($body->items)) {
         foreach ($body->items as $item) {
             if (!empty($item->index->error)) {
                 throw new Exception('ElasticSearch Indexing Error ' . $item->index->error);
             }
         }
     }
     if (!empty($body->error)) {
         return $this->_throwError($body);
     }
     if (!empty($body->ok) && $body->ok == true) {
         return true;
     }
     return Set::reverse($body);
 }
Beispiel #26
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);
    }
Beispiel #27
0
 /**
  * This function does two things:
  *
  * 1. it scans the array $one for the primary key,
  * and if that's found, it sets the current id to the value of $one[id].
  * For all other keys than 'id' the keys and values of $one are copied to the 'data' property of this object.
  * 2. Returns an array with all of $one's keys and values.
  * (Alternative indata: two strings, which are mangled to
  * a one-item, two-dimensional array using $one for a key and $two as its value.)
  *
  * @param mixed $one Array or string of data
  * @param string $two Value string for the alternative indata method
  * @return array Data with all of $one's keys and values
  * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html
  */
 public function set($one, $two = null)
 {
     if (!$one) {
         return;
     }
     if (is_object($one)) {
         if ($one instanceof SimpleXMLElement || $one instanceof DOMNode) {
             $one = $this->_normalizeXmlData(Xml::toArray($one));
         } else {
             $one = Set::reverse($one);
         }
     }
     if (is_array($one)) {
         $data = $one;
         if (empty($one[$this->alias])) {
             if ($this->getAssociated(key($one)) === null) {
                 $data = array($this->alias => $one);
             }
         }
     } else {
         $data = array($this->alias => array($one => $two));
     }
     foreach ($data as $modelName => $fieldSet) {
         if (is_array($fieldSet)) {
             foreach ($fieldSet as $fieldName => $fieldValue) {
                 if (isset($this->validationErrors[$fieldName])) {
                     unset($this->validationErrors[$fieldName]);
                 }
                 if ($modelName === $this->alias) {
                     if ($fieldName === $this->primaryKey) {
                         $this->id = $fieldValue;
                     }
                 }
                 if (is_array($fieldValue) || is_object($fieldValue)) {
                     $fieldValue = $this->deconstruct($fieldName, $fieldValue);
                 }
                 $this->data[$modelName][$fieldName] = $fieldValue;
             }
         }
     }
     return $data;
 }
Beispiel #28
0
 /**
  * Converts an object into an array
  *
  * @param object $object
  * @return array
  */
 function reverse($object)
 {
     if (is_object($object)) {
         $merge = array();
         if (is_a($object, 'xmlnode') || is_a($object, 'XMLNode')) {
             if ($object->name != Inflector::underscore($this->name)) {
                 if (is_object($object->child(Inflector::underscore($this->name)))) {
                     $object = $object->child(Inflector::underscore($this->name));
                     $object = $object->attributes;
                 } else {
                     return null;
                 }
             }
         } elseif (is_a($object, 'stdclass') || is_a($object, 'stdClass')) {
             $object = get_object_vars($object);
             $keys = array_keys($object);
             $count = count($keys);
             for ($i = 0; $i < $count; $i++) {
                 if ($keys[$i] == '__identity__') {
                     $key = $object[$keys[$i]];
                     unset($object[$keys[$i]]);
                     $object[$key] = $object;
                 } elseif (is_array($object[$keys[$i]])) {
                     $keys1 = array_keys($object[$keys[$i]]);
                     $count1 = count($keys1);
                     for ($ii = 0; $ii < $count1; $ii++) {
                         if (is_object($object[$keys[$i]][$keys1[$ii]])) {
                             $merge[$keys[$i]][$keys1[$ii]] = Set::reverse($object[$keys[$i]][$keys1[$ii]]);
                         } else {
                             $merge[$keys[$i]][$keys1[$ii]] = $object[$keys[$i]][$keys1[$ii]];
                         }
                     }
                     unset($object[$keys[$i]]);
                 } elseif (is_object($object[$keys[$i]])) {
                     $merge[$keys[$i]] = Set::reverse($object[$keys[$i]]);
                     unset($object[$keys[$i]]);
                 }
             }
         }
         $return = $object;
         if (!empty($merge)) {
             $mergeKeys = array_keys($merge);
             $objectKeys = array_keys($object);
             $count = count($mergeKeys);
             $change = $object;
             $count1 = count($objectKeys);
             for ($i = 0; $i < $count; $i++) {
                 $loop = $count1;
                 for ($ii = 0; $ii < $loop; $ii++) {
                     if (is_array($object[$objectKeys[$ii]])) {
                         if (array_key_exists($objectKeys[$ii], $object[$objectKeys[$ii]])) {
                             unset($change[$objectKeys[$ii]][$objectKeys[$ii]]);
                         }
                     } else {
                         unset($change[$objectKeys[$ii]]);
                     }
                 }
                 foreach ($objectKeys as $key => $value) {
                     if (is_array($object[$value])) {
                         if (array_key_exists($mergeKeys[$i], $object[$value])) {
                             unset($change[$value][$mergeKeys[$i]]);
                         }
                     } else {
                         unset($change[$value]);
                     }
                 }
             }
             $object = Set::pushDiff($change, $merge);
         }
         return $object;
     }
 }
Beispiel #29
0
 /**
  * Converts an object into an array
  *
  * @param object $object
  * @return array
  */
 function reverse($object)
 {
     if (is_a($object, 'xmlnode') || is_a($object, 'XMLNode')) {
         if ($object->name != Inflector::underscore($this->name)) {
             if (is_object($object->child(Inflector::underscore($this->name)))) {
                 $object = $object->child(Inflector::underscore($this->name));
                 $object = $object->attributes;
             } else {
                 return null;
             }
         }
     } else {
         $out = array();
         if (is_object($object)) {
             $keys = get_object_vars($object);
             if (isset($keys['_name_'])) {
                 $identity = $keys['_name_'];
                 unset($keys['_name_']);
             }
             $new = array();
             foreach ($keys as $key => $value) {
                 if (is_array($value)) {
                     $new[$key] = (array) Set::reverse($value);
                 } else {
                     $new[$key] = Set::reverse($value);
                 }
             }
             if (isset($identity)) {
                 $out[$identity] = $new;
             } else {
                 $out = $new;
             }
         } elseif (is_array($object)) {
             foreach ($object as $key => $value) {
                 $out[$key] = Set::reverse($value);
             }
         } else {
             $out = $object;
         }
         return $out;
     }
     return $object;
 }
Beispiel #30
0
 /**
  * @brief load up the details from the plugins config file
  *
  * This will attempt to get the plugins details so that they can be saved
  * to the database.
  * 
  * If the plugin has not had a release created then it will return false
  * and will not be able to be saved.
  *
  * @param string $pluginName the name of the plugin to load
  *
  * @return array the details found or false if not found
  */
 private function __loadPluginDetails($pluginName)
 {
     $configFile = CakePlugin::path($pluginName) . 'Config' . DS . 'config.json';
     return file_exists($configFile) ? Set::reverse(json_decode(file_get_contents($configFile))) : false;
 }