Permalink
Browse files

Converted to Cake 2.0

  • Loading branch information...
1 parent 21cef2a commit dc54fc3f81f8b335be3e536f443f2aeb22b9c4b3 Dean Sofer committed Nov 21, 2011
@@ -21,7 +21,7 @@ class UploadBehavior extends ModelBehavior {
var $maxWidthSize = false;
- function setup(&$model, $settings = array()) {
+ function setup($model, $settings = array()) {
$defaults = array(
'path' => ':webroot/upload/:model/:id/:style-:basename.:extension',
'styles' => array(),
@@ -34,7 +34,7 @@ function setup(&$model, $settings = array()) {
}
}
- function beforeSave(&$model) {
+ function beforeSave($model) {
$this->_reset();
foreach (self::$__settings[$model->name] as $field => $settings) {
if (!empty($model->data[$model->name][$field]) && is_array($model->data[$model->name][$field]) && file_exists($model->data[$model->name][$field]['tmp_name'])) {
@@ -51,24 +51,24 @@ function beforeSave(&$model) {
return true;
}
- function afterSave(&$model, $create) {
+ function afterSave($model, $create) {
if (!$create) {
$this->_deleteFiles($model);
}
$this->_writeFiles($model);
}
- function beforeDelete(&$model) {
+ function beforeDelete($model) {
$this->_reset();
$this->_prepareToDeleteFiles($model);
return true;
}
- function afterDelete(&$model) {
+ function afterDelete($model) {
$this->_deleteFiles($model);
}
- function beforeValidate(&$model) {
+ function beforeValidate($model) {
foreach (self::$__settings[$model->name] as $field => $settings) {
$data = $model->data[$model->name][$field];
@@ -93,7 +93,7 @@ function _fetchFromUrl($url) {
$data['name'] = end(explode('/', $url));
$data['tmp_name'] = tempnam(sys_get_temp_dir(), $data['name']) . '.' . end(explode('.', $url));
- App::import('Core', 'HttpSocket');
+ App::uses('HttpSocket', 'Network/Http');
$httpSocket = new HttpSocket();
$raw = $httpSocket->get($url);
@@ -106,15 +106,15 @@ function _fetchFromUrl($url) {
return $data;
}
- function _prepareToWriteFiles(&$model, $field) {
+ function _prepareToWriteFiles($model, $field) {
$this->toWrite[$field] = $model->data[$model->name][$field];
// make filename URL friendly by using Cake's Inflector
$this->toWrite[$field]['name'] =
Inflector::slug(substr($this->toWrite[$field]['name'], 0, strrpos($this->toWrite[$field]['name'], '.'))). // filename
substr($this->toWrite[$field]['name'], strrpos($this->toWrite[$field]['name'], '.')); // extension
}
- function _writeFiles(&$model) {
+ function _writeFiles($model) {
if (!empty($this->toWrite)) {
foreach ($this->toWrite as $field => $toWrite) {
$settings = $this->_interpolate($model, $field, $toWrite['name'], 'original');
@@ -143,11 +143,11 @@ function _writeFiles(&$model) {
}
}
- function _prepareToDeleteFiles(&$model, $field = null, $forceRead = false) {
+ function _prepareToDeleteFiles($model, $field = null, $forceRead = false) {
$needToRead = true;
if ($field === null) {
$fields = array_keys(self::$__settings[$model->name]);
- foreach ($fields as &$field) {
+ foreach ($fields as $field) {
$field .= '_file_name';
}
} else {
@@ -177,7 +177,7 @@ function _prepareToDeleteFiles(&$model, $field = null, $forceRead = false) {
$this->toDelete['id'] = $model->id;
}
- function _deleteFiles(&$model) {
+ function _deleteFiles($model) {
foreach (self::$__settings[$model->name] as $field => $settings) {
if (!empty($this->toDelete[$field.'_file_name'])) {
$styles = array_keys($settings['styles']);
@@ -192,7 +192,7 @@ function _deleteFiles(&$model) {
}
}
- function _interpolate(&$model, $field, $filename, $style) {
+ function _interpolate($model, $field, $filename, $style) {
return self::interpolate($model->name, $model->id, $field, $filename, $style);
}
@@ -238,7 +238,7 @@ function _resize($srcFile, $destFile, $geometry, $quality = 75) {
$src = null;
$createHandler = null;
$outputHandler = null;
- switch (low($pathinfo['extension'])) {
+ switch (strtolower($pathinfo['extension'])) {
case 'gif':
$createHandler = 'imagecreatefromgif';
$outputHandler = 'imagegif';
@@ -321,23 +321,23 @@ function _resize($srcFile, $destFile, $geometry, $quality = 75) {
return false;
}
- function attachmentMinSize(&$model, $value, $min) {
+ function attachmentMinSize($model, $value, $min) {
$value = array_shift($value);
if (!empty($value['tmp_name'])) {
return (int)$min <= (int)$value['size'];
}
return true;
}
- function attachmentMaxSize(&$model, $value, $max) {
+ function attachmentMaxSize($model, $value, $max) {
$value = array_shift($value);
if (!empty($value['tmp_name'])) {
return (int)$value['size'] <= (int)$max;
}
return true;
}
- function attachmentContentType(&$model, $value, $contentTypes) {
+ function attachmentContentType($model, $value, $contentTypes) {
$value = array_shift($value);
if (!is_array($contentTypes)) {
$contentTypes = array($contentTypes);
@@ -357,7 +357,7 @@ function attachmentContentType(&$model, $value, $contentTypes) {
return true;
}
- function attachmentPresence(&$model, $value) {
+ function attachmentPresence($model, $value) {
$keys = array_keys($value);
$field = $keys[0];
$value = array_shift($value);
@@ -378,15 +378,15 @@ function attachmentPresence(&$model, $value) {
}
return false;
}
- function minWidth(&$model, $value, $minWidth) {
+ function minWidth($model, $value, $minWidth) {
return $this->_validateDimension($value, 'min', 'x', $minWidth);
}
- function minHeight(&$model, $value, $minHeight) {
+ function minHeight($model, $value, $minHeight) {
return $this->_validateDimension($value, 'min', 'y', $minHeight);
}
- function maxWidth(&$model, $value, $maxWidth) {
+ function maxWidth($model, $value, $maxWidth) {
$keys = array_keys($value);
$field = $keys[0];
$settings = self::$__settings[$model->name][$field];
@@ -398,7 +398,7 @@ function maxWidth(&$model, $value, $maxWidth) {
}
}
- function maxHeight(&$model, $value, $maxHeight) {
+ function maxHeight($model, $value, $maxHeight) {
return $this->_validateDimension($value, 'max', 'y', $maxHeight);
}
File renamed without changes.

0 comments on commit dc54fc3

Please sign in to comment.