Ejemplo n.º 1
0
 /**
  *
  * Upload file to CDN
  * @param string $file
  * @param string $uploadName
  * @param string $content_type
  * @return boolean
  */
 public function uploadFile($file, $uploadName, $content_type = null)
 {
     Varien_Profiler::start('cdn_upload_file_' . $uploadName);
     if ($content_type == null) {
         $content_type = Mage::helper('mycdn')->detectFileMimeType($file);
     }
     $adapter = $this->getAdapter();
     if ($adapter) {
         $fileName = Mage::helper('mycdn')->getRelativeFile($uploadName);
         Mage::helper('mycdn')->addLog('[UPLOAD] ' . $fileName . ' as type ' . $content_type);
         $size = new Zend_Validate_File_Size(['min' => Mage::getStoreConfig('mycdn/general/min')]);
         if (!$size->isValid($file)) {
             return false;
         }
         $result = $adapter->uploadFile($file, $fileName, $content_type);
         if ($result) {
             Mage::helper('mycdn')->addLog('[UPLOADED] ' . $fileName);
             //saving to cache
             Mage::helper('mycdn')->savePathInCache($fileName, $this->getUrl($fileName));
             return true;
         }
         Mage::helper('mycdn')->addLog('[NOT UPLOADED] ' . $fileName);
         Varien_Profiler::stop('cdn_upload_file_' . $uploadName);
         return false;
     }
 }
Ejemplo n.º 2
0
 public function update()
 {
     $helper = Mage::helper('geoip');
     $ret = array('status' => 'error');
     if ($permissions_error = $this->checkFilePermissions()) {
         $ret['message'] = $permissions_error;
         return $ret;
     }
     $remote_file_size = $helper->getSize($this->remote_archive);
     if ($remote_file_size < 100000) {
         $ret['message'] = $helper->__('You are banned from downloading the file. Please try again in several hours.');
         return $ret;
     }
     /** @var $_session Mage_Core_Model_Session */
     $_session = Mage::getSingleton('core/session');
     $_session->setData('_geoip_file_size', $remote_file_size);
     $ch = curl_init($this->remote_archive);
     $fp = fopen($this->local_archive, 'wb');
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($httpCode != 200) {
         $ret['message'] = $helper->__('Failed to Download Zip');
         fclose($fp);
         return $ret;
     }
     curl_close($ch);
     fclose($fp);
     $arch_size = new Zend_Validate_File_Size(array('min' => 1000));
     if (!$arch_size->isValid($this->local_archive)) {
         $ret['message'] = $helper->__('Download failed.');
         return $ret;
     }
     if (!$helper->unGZip($this->local_archive, $this->local_dir)) {
         $ret['message'] = $helper->__('UnGzipping failed');
         return $ret;
     }
     $ret['status'] = 'success';
     $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
     $ret['date'] = Mage::app()->getLocale()->date(filemtime($this->local_file))->toString($format);
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * Sets validator options
  *
  * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
  * It also accepts an array with the keys 'min' and 'max'
  *
  * @param  integer|array|Zend_Config $options Options for this validator
  * @throws Zend_Validate_Exception
  */
 public function __construct($options)
 {
     $this->_files = array();
     $this->_setSize(0);
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } elseif (is_scalar($options)) {
         $options = array('max' => $options);
     } elseif (!is_array($options)) {
         throw new Zend_Validate_Exception('Invalid options to validator provided');
     }
     if (1 < func_num_args()) {
         $argv = func_get_args();
         array_shift($argv);
         $options['max'] = array_shift($argv);
         if (!empty($argv)) {
             $options['bytestring'] = array_shift($argv);
         }
     }
     parent::__construct($options);
 }
Ejemplo n.º 4
0
 /**
  * Sets validator options
  *
  * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
  * It also accepts an array with the keys 'min' and 'max'
  *
  * @param  integer|array $min        Minimum diskspace for all files
  * @param  integer       $max        Maximum diskspace for all files (deprecated)
  * @param  boolean       $bytestring Use bytestring or real size ? (deprecated)
  * @return void
  */
 public function __construct($options)
 {
     $this->_files = array();
     $this->_setSize(0);
     if (1 < func_num_args()) {
         trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
         if ($options instanceof Zend_Config) {
             $options = $options->toArray();
         } elseif (is_scalar($options)) {
             $options = array('min' => $options);
         } elseif (!is_array($options)) {
             #require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Invalid options to validator provided');
         }
         $argv = func_get_args();
         array_shift($argv);
         $options['max'] = array_shift($argv);
         if (!empty($argv)) {
             $options['bytestring'] = array_shift($argv);
         }
     }
     parent::__construct($options);
 }
 /**
  * Ensures that the validator returns size infos
  *
  * @return void
  */
 public function testFailureMessage()
 {
     $validator = new Zend_Validate_File_Size(array('min' => 9999, 'max' => 10000));
     $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/testsize.mo'));
     $this->assertContains('9.76kB', current($validator->getMessages()));
     $this->assertContains('794B', current($validator->getMessages()));
     $validator = new Zend_Validate_File_Size(array('min' => 9999, 'max' => 10000, 'bytestring' => false));
     $this->assertFalse($validator->isValid(dirname(__FILE__) . '/_files/testsize.mo'));
     $this->assertContains('9999', current($validator->getMessages()));
     $this->assertContains('794', current($validator->getMessages()));
 }
Ejemplo n.º 6
0
 /**
  * Sets validator options
  *
  * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
  * It also accepts an array with the keys 'min' and 'max'
  *
  * @param  integer|array $min Minimum diskspace for all files
  * @param  integer       $max Maximum diskspace for all files
  * @return void
  */
 public function __construct($min, $max = null)
 {
     $this->_files = array();
     $this->_size = 0;
     parent::__construct($min, $max);
 }
Ejemplo n.º 7
0
 /**
  *
  * @param type $min
  * @param type $max
  * @param type $messages_prefixed
  * @return \Zend_Validate_File_Size 
  */
 protected function _getValidatorFileSize($min = 0, $max = "200kB", $messages_prefixed = "")
 {
     $file = new Zend_Validate_File_Size(array('min' => $min, 'max' => $max));
     $file->setMessage(sprintf($this->_translate('ERROR_FILE_TO_BIG'), $this->_translate($messages_prefixed), $max), Zend_Validate_File_Size::TOO_BIG);
     $file->setMessage(sprintf($this->_translate('ERROR_FILE_TO_SMAILL'), $this->_translate($messages_prefixed), $min), Zend_Validate_File_Size::TOO_SMALL);
     return $file;
 }
Ejemplo n.º 8
0
 /**
  * Ensures that setMax() returns expected value
  *
  * @return void
  */
 public function testSetMax()
 {
     $validator = new Zend_Validate_File_Size(1000, 10000);
     $validator->setMax(1000000);
     $this->assertEquals('976.56kB', $validator->getMax());
     $validator->setMin(100);
     $this->assertEquals('976.56kB', $validator->getMax());
 }
Ejemplo n.º 9
0
 /**
  * Sets validator options
  *
  * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
  * It also accepts an array with the keys 'min' and 'max'
  *
  * @param  integer|array $min        Minimum diskspace for all files
  * @param  integer       $max        Maximum diskspace for all files
  * @param  boolean       $bytestring Use bytestring or real size ?
  * @return void
  */
 public function __construct($min, $max = null, $bytestring = true)
 {
     $this->_files = array();
     $this->_size = 0;
     parent::__construct($min, $max, $bytestring);
 }
Ejemplo n.º 10
0
 /**
  * Ensures that setMax() returns expected value
  *
  * @return void
  */
 public function testSetMax()
 {
     $validator = new Zend_Validate_File_Size(null, null);
     $validator->setMax(null);
     $this->assertEquals('0B', $validator->getMax());
     $validator->setMax(1000000);
     $this->assertEquals('976.56kB', $validator->getMax());
     $validator->setMin(100);
     $this->assertEquals('976.56kB', $validator->getMax());
     $validator->setMax('100 AB');
     $this->assertEquals('100B', $validator->getMax());
     $validator->setMax('100 kB');
     $this->assertEquals('100kB', $validator->getMax());
     $validator->setMax('100 MB');
     $this->assertEquals('100MB', $validator->getMax());
     $validator->setMax('1 GB');
     $this->assertEquals('1GB', $validator->getMax());
     $validator->setMax('0.001 TB');
     $this->assertEquals('1.02GB', $validator->getMax());
     $validator->setMax('0.000001 PB');
     $this->assertEquals('1.05GB', $validator->getMax());
     $validator->setMax('0.000000001 EB');
     $this->assertEquals('1.07GB', $validator->getMax());
     $validator->setMax('0.000000000001 ZB');
     $this->assertEquals('1.1GB', $validator->getMax());
     $validator->setMax('0.000000000000001 YB');
     $this->assertEquals('1.13GB', $validator->getMax());
 }