Esempio n. 1
0
 function index()
 {
     $this->Plugin->recursive = 0;
     $dbPluginList = $this->Plugin->find('list');
     $dirPluginList = array();
     if ($handle = opendir(ROOT . DS . 'app' . DS . 'plugins')) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != ".." && $file != '.svn') {
                 $dirPluginList[] = $file;
             }
         }
         closedir($handle);
     }
     $notInstalled = array_diff($dirPluginList, $dbPluginList);
     $noFiles = array_diff($dbPluginList, $dirPluginList);
     $this->Plugin->deleteAll(array('Plugin.id' => array_keys($noFiles)));
     $plugins = $this->paginate();
     App::import('Xml');
     foreach ($plugins as &$plugin) {
         $xml = new Xml(file_get_contents(ROOT . DS . 'app' . DS . 'plugins' . DS . $plugin['Plugin']['name'] . DS . 'meta.xml'));
         $plugin['Plugin']['author'] = $xml->child('plugin')->child('author')->children[0]->value;
         $plugin['Plugin']['email'] = $xml->child('plugin')->child('email')->children[0]->value;
         $plugin['Plugin']['website'] = $xml->child('plugin')->child('website')->children[0]->value;
         $plugin['Plugin']['description'] = $xml->child('plugin')->child('description')->children[0]->value;
     }
     $this->set('plugins', $plugins);
     foreach ($notInstalled as $k => &$plugin) {
         $plugin_name = $plugin;
         $plugin = array();
         $meta = ROOT . DS . 'app' . DS . 'plugins' . DS . $plugin_name . DS . 'meta.xml';
         if (file_exists($meta)) {
             $xml = new Xml(file_get_contents($meta));
             $plugin['Plugin']['name'] = $plugin_name;
             $plugin['Plugin']['author'] = $xml->child('plugin')->child('author')->children[0]->value;
             $plugin['Plugin']['email'] = $xml->child('plugin')->child('email')->children[0]->value;
             $plugin['Plugin']['website'] = $xml->child('plugin')->child('website')->children[0]->value;
             $plugin['Plugin']['description'] = $xml->child('plugin')->child('description')->children[0]->value;
         } else {
             unset($notInstalled[$k]);
         }
     }
     $this->set('notInstalled', $notInstalled);
 }
    /**
     * testToArray method
     *
     * @access public
     * @return void
     */
    function testToArray()
    {
        App::import('Set');
        $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 = new Xml($string);
        $result = $xml->toArray();
        $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', 'value' => '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', 'value' => '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->assertEqual($result, $expected);
        $string = '<data><post title="Title of this post" description="cool"/></data>';
        $xml = new Xml($string);
        $result = $xml->toArray();
        $expected = array('Data' => array('Post' => array('title' => 'Title of this post', 'description' => 'cool')));
        $this->assertEqual($result, $expected);
        $xml = new Xml('<example><item><title>An example of a correctly reversed XMLNode</title><desc/></item></example>');
        $result = Set::reverse($xml);
        $expected = array('Example' => array('Item' => array('title' => 'An example of a correctly reversed XMLNode', 'desc' => array())));
        $this->assertIdentical($result, $expected);
        $xml = new Xml('<example><item attr="123"><titles><title>title1</title><title>title2</title></titles></item></example>');
        $result = $xml->toArray();
        $expected = array('Example' => array('Item' => array('attr' => '123', 'Titles' => array('Title' => array('title1', 'title2')))));
        $this->assertIdentical($result, $expected);
        $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
        $result = $xml->toArray();
        $expected = array('Example' => array('attr' => 'ex_attr', 'Item' => array('attr' => '123', 'titles' => 'list', 'value' => 'textforitems')));
        $this->assertIdentical($result, $expected);
        $xml = new Xml('<example attr="ex_attr"><item attr="123"><titles>list</titles>textforitems</item></example>');
        $example = $xml->child('example');
        $item = $example->child('item');
        $result = $item->toArray();
        $expected = array('attr' => '123', 'titles' => 'list', 'value' => 'textforitems');
        $this->assertIdentical($result, $expected);
        $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>
				<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 = new Xml($string);
        $result = $xml->toArray();
        $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(", 'creator' => 'cakephp', 'Category' => array('cakephp', 'model'), 'guid' => array('isPermaLink' => 'true', 'value' => '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', 'creator' => 'cakephp', 'Category' => array('cakephp', 'model'), 'guid' => array('isPermaLink' => 'true', 'value' => '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->assertEqual($result, $expected);
        $text = "<?xml version='1.0' encoding='utf-8'?>\n\t\t          <course>\n\t\t            <comps>\n\t\t              <comp>1</comp>\n\t\t              <comp>2</comp>\n\t\t              <comp>3</comp>\n\t\t              <comp>4</comp>\n\t\t            </comps>\n\t\t          </course>";
        $xml = new Xml($text);
        $result = $xml->toArray();
        $expected = array('Course' => array('Comps' => array('Comp' => array(1, 2, 3, 4))));
        $this->assertEqual($result, $expected);
        $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 = new Xml($text);
        $result = $xml->toArray();
        $expected = array('XRDS' => array('xmlns' => 'xri://$xrds', 'XRD' => array(array('xml:id' => 'oauth', 'xmlns' => 'xri://$XRD*($v*2.0)', '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('value' => 'https://ma.gnolia.com/oauth/authorize', 'priority' => '10'), array('value' => 'http://ma.gnolia.com/oauth/authorize', 'priority' => '20')))), array('xmlns' => 'xri://$XRD*($v*2.0)', 'version' => '2.0', 'Type' => 'xri://$xrds*simple', 'Service' => array('priority' => '10', 'Type' => 'http://oauth.net/discovery/1.0', 'URI' => '#oauth')))));
        $this->assertEqual($result, $expected);
        $text = '<?xml version="1.0" encoding="UTF-8"?>
		<root>
			<child id="1" other="1" />
			<child id="2" other="1" />
			<child id="3" other="1" />
			<child id="4" other="1" />
			<child id="5" other="1" />
		</root>';
        $xml = new Xml($text);
        $result = $xml->toArray();
        $expected = array('Root' => array('Child' => array(array('id' => 1, 'other' => 1), array('id' => 2, 'other' => 1), array('id' => 3, 'other' => 1), array('id' => 4, 'other' => 1), array('id' => 5, 'other' => 1))));
        $this->assertEqual($result, $expected);
    }
 /**
  * The startup method of the RequestHandler enables several automatic behaviors
  * related to the detection of certain properties of the HTTP request, including:
  *
  * - Disabling layout rendering for Ajax requests (based on the HTTP_X_REQUESTED_WITH header)
  * - If Router::parseExtensions() is enabled, the layout and template type are
  *   switched based on the parsed extension.  For example, if controller/action.xml
  *   is requested, the view path becomes <i>app/views/controller/xml/action.ctp</i>.
  * - If a helper with the same name as the extension exists, it is added to the controller.
  * - If the extension is of a type that RequestHandler understands, it will set that
  *   Content-type in the response header.
  * - If the XML data is POSTed, the data is parsed into an XML object, which is assigned
  *   to the $data property of the controller, which can then be saved to a model object.
  *
  * @param object $controller A reference to the controller
  * @return void
  * @access public
  */
 function startup(&$controller)
 {
     if (!$this->enabled) {
         return;
     }
     $this->__initializeTypes();
     $controller->params['isAjax'] = $this->isAjax();
     $isRecognized = !in_array($this->ext, array('html', 'htm')) && in_array($this->ext, array_keys($this->__requestContent));
     if (!empty($this->ext) && $isRecognized) {
         $this->renderAs($controller, $this->ext);
     } elseif ($this->isAjax()) {
         $this->renderAs($controller, 'ajax');
     }
     if ($this->requestedWith('xml')) {
         if (!class_exists('XmlNode')) {
             App::import('Core', 'Xml');
         }
         $xml = new Xml(trim(file_get_contents('php://input')));
         if (is_object($xml->child('data')) && count($xml->children) == 1) {
             $controller->data = $xml->child('data');
         } else {
             $controller->data = $xml;
         }
     }
 }