Author: Jonathan.Wage
Date: 2010-02-01 22:07:10 +0100 (Mon, 01 Feb 2010)
New Revision: 27401

Modified:
   plugins/sfSympalPlugin/trunk/data/bin/installer.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/manager/sfSympalPluginManagerDownload.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/sfSympalPluginInfo.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/toolkits/sfSympalPluginToolkit.class.php
   plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
   plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
   plugins/sfSympalPlugin/trunk/test/functional/SanityCheckTest.php
   plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php
Log:
[1.4][sfSympalPlugin][1.0] Fixing use of file_get_contents() for urls


Modified: plugins/sfSympalPlugin/trunk/data/bin/installer.php
===================================================================
--- plugins/sfSympalPlugin/trunk/data/bin/installer.php 2010-02-01 20:43:26 UTC 
(rev 27400)
+++ plugins/sfSympalPlugin/trunk/data/bin/installer.php 2010-02-01 21:07:10 UTC 
(rev 27401)
@@ -1,5 +1,16 @@
 <?php
 
+function fileGetContents($url)
+{
+  $ch = curl_init();
+       curl_setopt($ch, CURLOPT_HEADER, 0);
+       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+       curl_setopt($ch, CURLOPT_URL, $url);
+       $data = curl_exec($ch);
+       curl_close($ch);
+       return $data;
+}
+
 $classes = array(
   'sfSympalServerCheck',
   'sfSympalServerCheckRenderer',
@@ -8,7 +19,7 @@
 );
 foreach ($classes as $file)
 {
-  $code = 
file_get_contents('http://svn.symfony-project.org/plugins/sfSympalPlugin/trunk/lib/check/'.$file.'.class.php');
+  $code = 
fileGetContents('http://svn.symfony-project.org/plugins/sfSympalPlugin/trunk/lib/check/'.$file.'.class.php');
   file_put_contents(sys_get_temp_dir().'/'.$file.'.class.php', $code);
   require sys_get_temp_dir().'/'.$file.'.class.php';
 }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/manager/sfSympalPluginManagerDownload.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/manager/sfSympalPluginManagerDownload.class.php
    2010-02-01 20:43:26 UTC (rev 27400)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/manager/sfSympalPluginManagerDownload.class.php
    2010-02-01 21:07:10 UTC (rev 27401)
@@ -6,10 +6,11 @@
   {
     $this->logSection('sympal', sprintf('Downloading Sympal plugin "%s"', 
$this->_pluginName));
 
-    $success = true;
+    $success = false;
     try {
       $this->logSection('sympal', '...trying to download plugin via PEAR');
 
+      chdir(sfConfig::get('sf_root_dir'));
       $pluginInstall = new sfPluginInstallTask($this->_dispatcher, 
$this->_formatter);
       $ret = @$pluginInstall->run(array($this->_pluginName), array());
 
@@ -17,6 +18,8 @@
       {
         $this->logSection('sympal', '...could not download plugin via PEAR', 
null, 'ERROR');
         $success = false;
+      } else {
+        $success = true;
       }
     } catch (Exception $e) {
       $success = false;
@@ -26,7 +29,6 @@
     if (!$success)
     {
       $this->logSection('sympal', 'Could not download plugin via PEAR! Trying 
alternative sources.');
-
       $path = sfSympalPluginToolkit::getPluginDownloadPath($this->_pluginName);
       if (is_dir($path))
       {

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/sfSympalPluginInfo.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/sfSympalPluginInfo.class.php
       2010-02-01 20:43:26 UTC (rev 27400)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/sfSympalPluginInfo.class.php
       2010-02-01 21:07:10 UTC (rev 27401)
@@ -99,10 +99,10 @@
       $packageXmlPath = $downloadPath.'/package.xml';
       $readmePath = $downloadPath.'/README';
 
-      if (@file_get_contents($packageXmlPath))
+      if (sfSympalToolkit::fileGetContents($packageXmlPath))
       {
         $packageXml = simplexml_load_file($packageXmlPath);
-      } else if (@file_get_contents($packageXmlPath.'.tmpl')) {
+      } else if (sfSympalToolkit::fileGetContents($packageXmlPath.'.tmpl')) {
         $packageXml = simplexml_load_file($packageXmlPath.'.tmpl');
       }
 
@@ -112,7 +112,7 @@
         $this->_plugin = array_merge($package, $this->_plugin);
       }
 
-      if ($readme = @file_get_contents($readmePath))
+      if ($readme = sfSympalToolkit::fileGetContents($readmePath))
       {
         $this->_plugin['readme'] = $readme;
       }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/toolkits/sfSympalPluginToolkit.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/toolkits/sfSympalPluginToolkit.class.php
   2010-02-01 20:43:26 UTC (rev 27400)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPluginManagerPlugin/lib/toolkits/sfSympalPluginToolkit.class.php
   2010-02-01 21:07:10 UTC (rev 27401)
@@ -130,7 +130,7 @@
             }
           }
         } else {
-          $html = file_get_contents($path);
+          $html = sfSympalToolkit::fileGetContents($path);
           preg_match_all("/sfSympal(.*)Plugin/", strip_tags($html), $matches);
           foreach ($matches[0] as $plugin)
           {
@@ -181,11 +181,11 @@
       {
         $branchSvnPath = $path.'/'.$pluginName.'/branches/'.$version;
         $trunkSvnPath = $path.'/'.$pluginName.'/trunk';
-        if (@file_get_contents($branchSvnPath) !== false || 
is_dir($branchSvnPath))
+        if (sfSympalToolkit::fileGetContents($branchSvnPath) !== false || 
is_dir($branchSvnPath))
         {
           $path = $branchSvnPath;
           break;
-        } else if (@file_get_contents($trunkSvnPath) !== false || 
is_dir($trunkSvnPath)) {
+        } else if (sfSympalToolkit::fileGetContents($trunkSvnPath) !== false 
|| is_dir($trunkSvnPath)) {
           $path = $trunkSvnPath;
           break;
         } else if (is_dir($path)) {

Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php     
2010-02-01 20:43:26 UTC (rev 27400)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php     
2010-02-01 21:07:10 UTC (rev 27401)
@@ -2,6 +2,35 @@
 
 class sfSympalToolkit
 {
+  public static function fileGetContents($file)
+  {
+    if (substr($file, 0, 4) === 'http')
+    {
+      $ch = curl_init();
+       curl_setopt($ch, CURLOPT_HEADER, 0);
+       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+       curl_setopt($ch, CURLOPT_URL, $file);
+       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+       $data = curl_exec($ch);
+      $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+      if (curl_errno($ch) || !$data || $code == 404)
+       {
+         return false;
+       } else {
+       curl_close($ch);
+       return $data;
+      }
+    } else {
+      if (file_exists($file))
+      {
+        return file_get_contents($file);
+      } else {
+        return false;
+      }
+    }
+  }
+
   public static function loadHelpers($helpers)
   {
     sfApplicationConfiguration::getActive()->loadHelpers($helpers);

Modified: 
plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
===================================================================
(Binary files differ)

Modified: plugins/sfSympalPlugin/trunk/test/functional/SanityCheckTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/functional/SanityCheckTest.php    
2010-02-01 20:43:26 UTC (rev 27400)
+++ plugins/sfSympalPlugin/trunk/test/functional/SanityCheckTest.php    
2010-02-01 21:07:10 UTC (rev 27401)
@@ -3,7 +3,7 @@
 require_once(dirname(__FILE__).'/../bootstrap/functional.php');
 
 $browser = new sfSympalTestFunctional(new sfBrowser());
-
+$browser->signInAsAdmin();
 $browser->get('/');
 
 // Make sure we can click each menu item in the menu

Modified: plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php 2010-02-01 20:43:26 UTC 
(rev 27400)
+++ plugins/sfSympalPlugin/trunk/test/unit/MenuTest.php 2010-02-01 21:07:10 UTC 
(rev 27401)
@@ -110,6 +110,9 @@
   }
 }
 
+$user = Doctrine_Core::getTable('sfGuardUser')->findOneByIsSuperAdmin(true);
+sfContext::getInstance()->getUser()->signIn($user);
+
 $manager = sfSympalMenuSiteManager::getInstance();
 $primaryMenu = $manager->getMenu('primary', false, 'sfSympalMenuSiteTest');
 $t->is((string) $primaryMenu, '<ul id="primary-menu"><li id="primary-blog" 
class="first">Blog</li><li id="primary-signout">Signout</li><li 
id="primary-home">Home</li><li id="primary-sample-page">Sample Page</li><li 
id="primary-sample-content-list">Sample Content List</li><li 
id="primary-powered-by" class="last">Powered By</li></ul>', 'Test 
__toString()');

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to