Exemplo n.º 1
0
 /**
  * Clean data method
  * 
  * @param array $data
  */
 public function _cleanData($data = null)
 {
     if (empty($data['WebpageMenu']['code']) && !empty($data['WebpageMenu']['name'])) {
         $data['WebpageMenu']['code'] = ZuhaInflector::asciify($data['WebpageMenu']['name']);
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * String to Url
  * Converts the given string to a no spaces, no special characters, no cases string, like a url.
  * Unlike the asciify function it changes + (plus signs) to / (slashes)
  *
  * Tänk efter nu – förr'n vi föser dig b+ort BECOMES tank-efter-nu-forrn-vi-foser-dig-b/ort
  *
  * Usage : ZuhaInflector::urlify('some string');
  *
  * @param string $str
  * @param array $replace
  * @param string $delimiter
  * @return string
  */
 public static function urlify($str, $delimiter = '-')
 {
     $strs = explode('+', $str);
     $string = '';
     for ($i = 0; $i < count($strs); $i++) {
         $parts[] = ZuhaInflector::asciify(trim($strs[$i]));
     }
     return implode('/', $parts);
 }
 /**
  * Upload method
  * 
  * @param object $Model
  * @param array $data
  */
 public function upload(Model $Model, $data)
 {
     $data = !empty($data) ? $data : $this->data;
     if (!empty($data['File'])) {
         ini_set('memory_limit', '750M');
         foreach ($data['File'] as $attachment) {
             if (!empty($attachment['file']['tmp_name'])) {
                 // make sure there is actually a file to upload
                 $data[$this->ImageStorage->alias]['adapter'] = 'S3Storage';
                 $model = $this->_detectModelByFileType($attachment['file']['type']);
                 if ($model) {
                     $data['File']['model'] = $model;
                     $data['File']['adapter'] = 'S3Storage';
                     App::uses('File', 'Utility');
                     $file = new File($attachment['file']['tmp_name']);
                     $info = $file->info();
                     // fill in empty data that should have something (if possible)
                     $attachment['user_id'] = !empty($attachment['user_id']) ? $attachment['user_id'] : CakeSession::read('Auth.User.id');
                     $attachment['title'] = !empty($attachment['title']) ? $attachment['title'] : $attachment['file']['name'];
                     $attachment['alt'] = !empty($attachment['alt']) ? $attachment['alt'] : ZuhaInflector::asciify($attachment['file']['name']);
                     $saveData = array($this->{$model}->alias => array_merge($attachment, array('filename' => uniqid('', true) . '.' . substr(strrchr($attachment['file']['name'], '.'), 1), 'filesize' => $info['filesize'], 'file' => $attachment['file'], 'mime_type' => $info['mime'], 'extension' => substr(strrchr($attachment['file']['name'], '.'), 1), 'adapter' => 'S3Storage')));
                     $saveData[$this->{$model}->alias]['file']['name'] = uniqid('', true) . '.' . substr(strrchr($attachment['file']['name'], '.'), 1);
                     $saveData['FileAttach'] = array_merge($attachment, array('model' => $Model->name, 'foreign_key' => $Model->id));
                     try {
                         $this->{$model}->create();
                         if ($this->{$model}->save($saveData)) {
                             $saveData['FileAttach']['file_storage_id'] = $this->{$model}->getLastInsertID();
                             $this->FileAttach->create();
                             $this->FileAttach->save($saveData);
                         }
                     } catch (Exception $e) {
                         debug('Please report this error, with the information below.');
                         debug($e->getMessage());
                         debug($this->{$model}->invalidFields());
                         exit;
                     }
                 }
             }
         }
     }
     return true;
 }