From: Andrey Kutejko Date: Fri, 19 Apr 2013 19:32:14 +0000 (+0300) Subject: add uploadTo parameter to file/image field X-Git-Tag: 0.5~302 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=bb16420b05c8a70a422b3136036cc4351cc204d0;p=ipf.git add uploadTo parameter to file/image field --- diff --git a/ipf.php b/ipf.php index b36f32a..af45fb5 100644 --- a/ipf.php +++ b/ipf.php @@ -1,28 +1,22 @@ $val){ + private static function applySettings($settings) + { + foreach($settings as $key=>$val) IPF::$settings[strtolower($key)] = $val; - } } - private static function loadSettings(){ + private static function loadSettings() + { $settings_file = IPF::$settings['project_path'].DIRECTORY_SEPARATOR.'settings.php'; IPF::$settings['settings_file'] = $settings_file; @@ -110,28 +104,28 @@ final class IPF{ { IPF::$settings['ipf_path']=$ipf_path; IPF::$settings['project_path']=$project_path; - try{ + try { IPF::loadSettings(); - date_default_timezone_set(IPF::$settings['time_zone']); - }catch(IPF_Exception_Settings $e){ + date_default_timezone_set(IPF::$settings['time_zone']); + } catch(IPF_Exception_Settings $e) { die('Setting Error: '.$e->getMessage()."\n"); } } - private function __construct(){} - private function __clone(){} + private function __construct() {} + private function __clone() {} - public static function get($name,$default=null){ - if (isset(IPF::$settings[$name])) - return IPF::$settings[$name]; - return $default; - } + public static function get($name, $default=null) + { + if (isset(IPF::$settings[$name])) + return IPF::$settings[$name]; + return $default; + } public static function loadFunction($function) { - if (function_exists($function)) { + if (function_exists($function)) return; - } $elts = explode('_', $function); array_pop($elts); $file = strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php'; @@ -147,20 +141,14 @@ final class IPF{ return new $model(); } - public static function getUploadPath($params=array()){ - $upload_path = IPF::get('upload_path', '/tmp'); - if (isset($params['upload_path'])) { - $upload_path = $params['upload_path']; - } - return $upload_path; + public static function getUploadPath() + { + return IPF::get('upload_path', '/tmp'); } - public static function getUploadUrl($params=array()){ - $upload_url = IPF::get('upload_url', '/media/upload'); - if (isset($params['upload_url'])) { - $upload_url = $params['upload_url']; - } - return $upload_url; + public static function getUploadUrl() + { + return IPF::get('upload_url', '/media/upload'); } } @@ -170,4 +158,3 @@ function __($str) return $t; } - diff --git a/ipf/admin/modelinline.php b/ipf/admin/modelinline.php index 54f59de..87a5a31 100644 --- a/ipf/admin/modelinline.php +++ b/ipf/admin/modelinline.php @@ -123,8 +123,9 @@ abstract class IPF_Admin_ModelInline{ } } - function save($parent_obj){ - if ($this->parentModel->exists()){ + function save($parent_obj) + { + if ($this->parentModel->exists()) { $objects = IPF_ORM_Query::create() ->from(get_class($this->model)) ->orderby('id') @@ -136,13 +137,13 @@ abstract class IPF_Admin_ModelInline{ continue; @list($x1,$x2,$id,$x3) = @explode('_',$form->prefix); - if ($id==$obj->id){ - if ($form->cleaned_data[0]==true) + if ($id == $obj->id) { + if ($form->cleaned_data[0]==true) { $obj->delete(); - else{ + } else { unset($form->cleaned_data[0]); - foreach($form->fields as $fname=>$f){ - if (is_a($f,'IPF_Form_Field_File')){ + foreach($form->fields as $fname=>$f) { + if (is_a($f,'IPF_Form_Field_File')) { if($form->cleaned_data[$fname]===null) continue; if($form->cleaned_data[$fname]=='') @@ -160,8 +161,8 @@ abstract class IPF_Admin_ModelInline{ } $fk_local = $this->getFkLocal(); - foreach($this->formset as $form){ - if ($form->isValid()){ + foreach ($this->formset as $form) { + if ($form->isValid()) { if ($form->isAdd){ unset($form->cleaned_data[0]); $form->cleaned_data[$fk_local] = $parent_obj->id; @@ -170,4 +171,4 @@ abstract class IPF_Admin_ModelInline{ } } } -} \ No newline at end of file +} diff --git a/ipf/context.php b/ipf/context.php index 370cfb9..d9acae3 100644 --- a/ipf/context.php +++ b/ipf/context.php @@ -22,7 +22,7 @@ function IPF_Context_Version($request) function IPF_Context_Upload($request) { - return array('UPLOAD_URL' => IPF::get('upload_url')); + return array('UPLOAD_URL' => IPF::getUploadUrl()); } function IPF_Context_Current($request) diff --git a/ipf/form/db/email.php b/ipf/form/db/email.php index 09af091..73f030d 100644 --- a/ipf/form/db/email.php +++ b/ipf/form/db/email.php @@ -1,10 +1,13 @@ 200); - function formField($def, $form_field='IPF_Form_Field_Email'){ + function formField($def, $form_field='IPF_Form_Field_Email') + { return parent::formField($def, $form_field); } } + diff --git a/ipf/form/db/file.php b/ipf/form/db/file.php index 2f78f0c..520344a 100644 --- a/ipf/form/db/file.php +++ b/ipf/form/db/file.php @@ -1,7 +1,12 @@ uploadTo = @$this->extra['uploadTo']; + return $field; } } + diff --git a/ipf/form/db/image.php b/ipf/form/db/image.php index c97ac87..fb741bf 100644 --- a/ipf/form/db/image.php +++ b/ipf/form/db/image.php @@ -1,7 +1,10 @@ widget = $widget; } - function clean($value) + public function clean($value) { if ($this->required and in_array($value, $this->empty_values)) { throw new IPF_Exception_Form(__('This field is required.')); diff --git a/ipf/form/field/file.php b/ipf/form/field/file.php index 306a88f..2d131d1 100644 --- a/ipf/form/field/file.php +++ b/ipf/form/field/file.php @@ -3,87 +3,89 @@ class IPF_Form_Field_File extends IPF_Form_Field { public $widget = 'IPF_Form_Widget_FileInput'; - public $move_function = 'IPF_Form_Field_moveToUploadFolder'; - public $remove_function = 'IPF_Form_Field_removeFile'; - public $rename_function = 'IPF_Form_Field_renameFile'; public $max_size = 20971520; // 20MB - public $move_function_params = array(); + public $uploadTo = ''; - function clean($value) + protected function removeFile($data) { - if (@$value['remove']===true){ - IPF::loadFunction($this->remove_function); - return call_user_func($this->remove_function, $value['data']); - } - if (@$value['name']!=@$value['rename']){ - IPF::loadFunction($this->rename_function); - return call_user_func($this->rename_function, $value); - } + return null; + } + + protected function getRelativePath($filename) + { + if ($this->uploadTo) + return $this->uploadTo . DIRECTORY_SEPARATOR . $filename; + else + return $filename; + } + + protected function getAbsolutePath($filename) + { + $upload_root = IPF::getUploadPath() . DIRECTORY_SEPARATOR; + if ($this->uploadTo) + return $upload_root . $this->uploadTo . DIRECTORY_SEPARATOR . $filename; + else + return $upload_root . $filename; + } + + protected function renameFile($old_name, $new_name) + { + @rename(getAbsolutePath($old_name), getAbsolutePath($new_name)); + return getRelativePath($new_name); + } + + public function clean($value) + { + IPF_Utils::makeDirectories($this->getAbsolutePath('')); + + if (@$value['remove'] === true) + return $this->removeFile($value['data']); + + if (@$value['name'] != @$value['rename']) + return $this->renameFile(@$value['name'], @$value['rename']); + $value = @$value['data']; - - if (@$value['name']=='') + + if (@$value['name'] == '') return ''; parent::clean($value); - $errors = array(); - $no_files = false; switch ($value['error']) { - case UPLOAD_ERR_OK: - break; - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - throw new IPF_Exception_Form(__('The uploaded file is too large. Reduce the size of the file and send it again.')); - break; - case UPLOAD_ERR_PARTIAL: - throw new IPF_Exception_Form(__('The upload did not complete. Please try to send the file again.')); - break; - case UPLOAD_ERR_NO_FILE: - throw new IPF_Exception_Form(__('No files were uploaded. Please try to send the file again.')); - break; - case UPLOAD_ERR_NO_TMP_DIR: - case UPLOAD_ERR_CANT_WRITE: - throw new IPF_Exception_Form(__('The server has no temporary folder correctly configured to store the uploaded file.')); - break; - case UPLOAD_ERR_EXTENSION: - throw new IPF_Exception_Form(__('The uploaded file has been stopped by an extension.')); - break; - default: - throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); + case UPLOAD_ERR_OK: + break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + throw new IPF_Exception_Form(__('The uploaded file is too large. Reduce the size of the file and send it again.')); + break; + case UPLOAD_ERR_PARTIAL: + throw new IPF_Exception_Form(__('The upload did not complete. Please try to send the file again.')); + break; + case UPLOAD_ERR_NO_FILE: + throw new IPF_Exception_Form(__('No files were uploaded. Please try to send the file again.')); + break; + case UPLOAD_ERR_NO_TMP_DIR: + case UPLOAD_ERR_CANT_WRITE: + throw new IPF_Exception_Form(__('The server has no temporary folder correctly configured to store the uploaded file.')); + break; + case UPLOAD_ERR_EXTENSION: + throw new IPF_Exception_Form(__('The uploaded file has been stopped by an extension.')); + break; + default: + throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); } if ($value['size'] > $this->max_size) { throw new IPF_Exception_Form(sprintf(__('The uploaded file is to big (%1$s). Reduce the size to less than %2$s and try again.'), IPF_Utils::prettySize($value['size']), IPF_Utils::prettySize($this->max_size))); } - IPF::loadFunction($this->move_function); - return call_user_func($this->move_function, $value, $this->move_function_params); - } -} - -function IPF_Form_Field_moveToUploadFolder($value, $params=array()) -{ - $upload_path = IPF::getUploadPath($params); - $name = IPF_Utils::cleanFileName($value['name'], $upload_path); - $dest = $upload_path.DIRECTORY_SEPARATOR.$name; - if (!move_uploaded_file($value['tmp_name'], $dest)) { - throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); + $name = IPF_Utils::cleanFileName($value['name'], $this->getAbsolutePath('')); + $dest = $this->getAbsolutePath($name); + if (!move_uploaded_file($value['tmp_name'], $dest)) + throw new IPF_Exception_Form(__('An error occured when upload the file. Please try to send the file again.')); + @chmod($dest, IPF::get('file_permission')); + return $this->getRelativePath($name); } - @chmod($dest, IPF::get('file_permission')); - return $name; -} - - -function IPF_Form_Field_removeFile($value, $params=array()){ - return null; -} - -function IPF_Form_Field_renameFile($value, $params=array()){ - $upload_path = IPF::getUploadPath($params); - $old_name = @$upload_path.DIRECTORY_SEPARATOR.$value['name']; - $new_name = @$upload_path.DIRECTORY_SEPARATOR.$value['rename']; - @rename($old_name, $new_name); - return @$value['rename']; } diff --git a/ipf/form/field/image.php b/ipf/form/field/image.php index d9a4018..b8efd19 100644 --- a/ipf/form/field/image.php +++ b/ipf/form/field/image.php @@ -1,18 +1,18 @@ model->getTable()->getColumns(); $db_relations = $this->model->getTable()->getRelations(); - if ($user_fields===null){ - + if ($user_fields === null) { if (isset($extra['exclude'])) $exclude = $extra['exclude']; else $exclude = array(); - foreach($db_columns as $name=>$col){ + foreach($db_columns as $name=>$col) { if (array_search($name,$exclude)!==false) continue; $this->addDBField($name,$col); } - foreach($db_relations as $name => $relation){ + foreach($db_relations as $name => $relation) { if (array_search($name,$exclude)!==false) continue; $this->addDBRelation($name,$relation,$col); - } - } - else{ - foreach($user_fields as $uname){ + } + } else { + foreach($user_fields as $uname) { $add_method = 'add__'.$uname.'__field'; - if (method_exists($this,$add_method)){ + if (method_exists($this,$add_method)) { $this->$add_method(); continue; } - if (array_key_exists($uname,$db_columns)) + if (array_key_exists($uname,$db_columns)) { $this->addDBField($uname,$db_columns[$uname]); - elseif (array_key_exists($uname,$db_relations)){ - $lfn = $db_relations[$uname]->getLocalFieldName(); - if (isset($db_columns[$lfn])) - $col = $db_columns[$lfn]; - else - $col = array(); + } elseif (array_key_exists($uname,$db_relations)) { + $lfn = $db_relations[$uname]->getLocalFieldName(); + if (isset($db_columns[$lfn])) + $col = $db_columns[$lfn]; + else + $col = array(); $this->addDBRelation($uname,$db_relations[$uname],$col); } } } } - function addDBField($name,$col){ + function addDBField($name, $col) + { if ($name==$this->model->getTable()->getIdentifier()) return; $defaults = array('blank' => true, 'verbose' => $name, 'help_text' => '', 'editable' => true); $type = $col['type']; - if (isset($col['notblank'])) + if (isset($col['notblank'])) { if ($col['notblank']) $defaults['blank'] = false; else $defaults['blank'] = true; + } if (isset($col['length'])) $defaults['max_length'] = (int)($col['length']); + if (isset($col['email'])) $type = 'email'; @@ -86,21 +87,21 @@ class IPF_Form_Model extends IPF_Form $cn = 'IPF_Form_DB_'.$type; - $db_field = new $cn('', $name); + $db_field = new $cn('', $name, $col); - if (null !== ($form_field=$db_field->formField($defaults))) { + $form_field = $db_field->formField($defaults); + if ($form_field !== null) $this->fields[$name] = $form_field; - } } - function addDBRelation($name,$relation,$col){ - - if (isset($col['notblank'])) - $blank = false; - else - $blank = true; + function addDBRelation($name, $relation, $col) + { + if (isset($col['notblank'])) + $blank = false; + else + $blank = true; - if ($relation->getType()==IPF_ORM_Relation::ONE_AGGREGATE){ + if ($relation->getType()==IPF_ORM_Relation::ONE_AGGREGATE) { $name .= "_id"; $db_field = new IPF_Form_DB_Foreignkey('',$name); $defaults = array('blank' => $blank, 'verbose' => $name, 'help_text' => '', 'editable' => true, 'model'=>$relation->getClass()); @@ -108,7 +109,7 @@ class IPF_Form_Model extends IPF_Form $this->fields[$name] = $form_field; return; } - if ($relation->getType()==IPF_ORM_Relation::MANY_AGGREGATE){ + if ($relation->getType()==IPF_ORM_Relation::MANY_AGGREGATE) { $db_field = new IPF_Form_DB_ManyToMany('',$name); $defaults = array('blank' => $blank, 'verbose' => $name, 'help_text' => '', 'editable' => true, 'model'=>$relation->getClass()); $form_field = $db_field->formField($defaults); @@ -117,7 +118,10 @@ class IPF_Form_Model extends IPF_Form } } - function fields(){ return $this->user_fields; } + function fields() + { + return $this->user_fields; + } function save($commit=true) { @@ -147,3 +151,4 @@ class IPF_Form_Model extends IPF_Form //throw new IPF_Exception_Form(__('Cannot save the model from an invalid form.')); } } + diff --git a/ipf/form/widget/fileinput.php b/ipf/form/widget/fileinput.php index f3e54de..ea86baa 100644 --- a/ipf/form/widget/fileinput.php +++ b/ipf/form/widget/fileinput.php @@ -7,53 +7,45 @@ class IPF_Form_Widget_FileInput extends IPF_Form_Widget_Input public $allow_extended = true; public $allow_delete = true; - public $additional_params = array(); - public function render($name, $value, $extra_attrs=array()) { $sim = ''; - if (isset($value['data'])){ + if (isset($value['data'])) { $value = $value['data']; - if (is_string($value) && $value!=''){ - if ($this->allow_extended){ - $sim = 'Currently: view'; - if ($this->allow_delete) - $sim .= ' |  '; - $sim .= ' Change:'; - } - else - $sim = 'Currently: '.$value.'
Change: '; + if (is_string($value) && $value != '') { + if ($this->allow_extended) { + $sim = '
Currently: view'; + if ($this->allow_delete) + $sim .= ' |  '; + $sim .= ' Change:'; + } else { + $sim = 'Currently: '.$value.'
Change: '; + } } } $value = ''; return $sim.parent::render($name, $value, $extra_attrs); } - public function valueFromFormData($name, &$data){ - if (isset($data[$name])) { - $remove = false; - if (isset($data[$name.'_remove'])) - if ($data[$name.'_remove']==1) - $remove = true; - $res = array('data'=>$data[$name], 'remove'=>$remove); - if (isset($data[$name.'_rename'])) - $res['rename'] = $data[$name.'_rename']; - if (isset($data[$name.'_name'])) - $res['name'] = $data[$name.'_name']; - return $res; - } - return null; + public function valueFromFormData($name, &$data) + { + if (!isset($data[$name])) + return null; + $remove = isset($data[$name.'_remove']) && $data[$name.'_remove'] == 1; + $res = array('data'=>$data[$name], 'remove'=>$remove); + if (isset($data[$name.'_rename'])) + $res['rename'] = $data[$name.'_rename']; + if (isset($data[$name.'_name'])) + $res['name'] = $data[$name.'_name']; + return $res; } - public function valueToFormData($name, $data){ - if (isset($data[$name])) { - $remove = false; - if (isset($data[$name.'_remove'])) - if ($data[$name.'_remove']==1) - $remove = true; - $res = array('data'=>$data[$name], 'remove'=>$remove); - return $res; - } - return null; + public function valueToFormData($name, $data) + { + if (!isset($data[$name])) + return null; + $remove = isset($data[$name.'_remove']) && $data[$name.'_remove'] == 1; + return array('data'=>$data[$name], 'remove'=>$remove); } } + diff --git a/ipf/orm/import/schema.php b/ipf/orm/import/schema.php index 76a9ab3..a4c67c2 100644 --- a/ipf/orm/import/schema.php +++ b/ipf/orm/import/schema.php @@ -543,3 +543,4 @@ class IPF_ORM_Import_Schema } } } + diff --git a/ipf/orm/utils.php b/ipf/orm/utils.php index 72c2a1a..0fa8f93 100644 --- a/ipf/orm/utils.php +++ b/ipf/orm/utils.php @@ -57,6 +57,7 @@ class IPF_ORM_Utils { 'file', 'image', 'html', + 'uploadTo', ); } diff --git a/ipf/orm/validator/uploadto.php b/ipf/orm/validator/uploadto.php new file mode 100644 index 0000000..2a99a68 --- /dev/null +++ b/ipf/orm/validator/uploadto.php @@ -0,0 +1,10 @@ +$max_length) ) @@ -14,7 +15,8 @@ class IPF_Utils { return true; } - public static function isEmail($value){ + public static function isEmail($value) + { $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; @@ -48,25 +50,25 @@ class IPF_Utils { $name = mb_strtolower($name, 'UTF-8'); $name = mb_ereg_replace("/\015\012|\015|\012|\s|[^A-Za-z0-9\.\-\_]/", '_', $name); - while(file_exists($path.$name)){ + while (file_exists($path . $name)) { $pathinfo = pathinfo($name); $filename = $pathinfo['filename']; $split = explode('_', $filename); $n = count($split); - if ($n<2){ + if ($n < 2) { $filename .= '_2'; - } - else{ + } else { $x = $split[$n-1]; - if (is_numeric($x)){ + if (is_numeric($x)) { $split[$n-1] = ((int)$x)+1; - } - else + } else { $split[] = '2'; + } $filename = ''; - foreach($split as $sp){ - if ($filename!='') $filename.='_'; + foreach ($split as $sp) { + if ($filename != '') + $filename .= '_'; $filename .= $sp; } } @@ -83,18 +85,20 @@ class IPF_Utils { return (preg_match('!^(http|https|ftp|gopher)\://('.$ip.'|'.$dom.')!i', $url)) ? true : false; } - static function humanTitle($s){ + static function humanTitle($s) + { $s = ucfirst(str_replace('_',' ',str_replace('_id','',$s))); - $ns = ''; - for ($i=0; $i0) && (ucfirst($s[$i-1])!=$s[$i-1]) && (ucfirst($s[$i])==$s[$i]) ) - $ns .= ' '; - if ($s[$i]=='_') - $ns .= ' '; - else - $ns .= $s[$i]; - } - return $ns; + $ns = ''; + for ($i = 0; $i < strlen($s); ++$i) { + if ( ($i>0) && (ucfirst($s[$i-1])!=$s[$i-1]) && (ucfirst($s[$i])==$s[$i]) ) + $ns .= ' '; + + if ($s[$i] == '_') + $ns .= ' '; + else + $ns .= $s[$i]; + } + return $ns; } static function randomString($len=35) @@ -103,7 +107,7 @@ class IPF_Utils { $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $lchars = strlen($chars); $i = 0; - while ($i<$len) { + while ($i < $len) { $string .= substr($chars, mt_rand(0, $lchars-1), 1); $i++; } @@ -112,7 +116,7 @@ class IPF_Utils { static function dateCompare($date1, $date2=null) { - if (strlen($date1) == 10){ + if (strlen($date1) == 10) { $date1 .= ' 23:59:59'; } if (is_null($date2)) { @@ -127,9 +131,10 @@ class IPF_Utils { return $date2 - $date1; } - static function appLabelByModel($model){ - foreach (IPF_Project::getInstance()->appList() as $app){ - foreach($app->modelList() as $m){ + static function appLabelByModel($model) + { + foreach (IPF_Project::getInstance()->appList() as $app) { + foreach($app->modelList() as $m) { if ($model==$m) return strtolower($app->getLabel()); } @@ -137,20 +142,22 @@ class IPF_Utils { return ''; } - public static function makeDirectories($path, $mode = 0777){ - if ( ! $path) { + public static function makeDirectories($path, $mode=0777) + { + if (!$path) return false; - } - if (is_dir($path) || is_file($path)) { + + if (is_dir($path) || is_file($path)) return true; - } + return mkdir(trim($path), $mode, true); } - public static function removeDirectories($folderPath){ - if (is_dir($folderPath)){ - foreach (scandir($folderPath) as $value){ - if ($value != '.' && $value != '..'){ + public static function removeDirectories($folderPath) + { + if (is_dir($folderPath)) { + foreach (scandir($folderPath) as $value) { + if ($value != '.' && $value != '..') { $value = $folderPath . "/" . $value; if (is_dir($value)) { self::removeDirectories($value); @@ -165,7 +172,8 @@ class IPF_Utils { } } - public static function copyDirectory($source, $dest){ + public static function copyDirectory($source, $dest) + { // Simple copy for a file if (is_file($source)) { return copy($source, $dest); @@ -176,7 +184,7 @@ class IPF_Utils { } // Loop through the folder $dir = dir($source); - while (false !== $entry = $dir->read()){ + while (false !== $entry = $dir->read()) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; @@ -229,12 +237,14 @@ class IPF_Utils { return $s; } - public static function timestamp(){ - list($f,$i) = explode(' ',microtime()); - return $i.substr((string)$f,2,6); + public static function timestamp() + { + list($f,$i) = explode(' ',microtime()); + return $i.substr((string)$f,2,6); } - static function TrimP($html){ + static function TrimP($html) + { $strL = "

"; $lenL = 3; $strR = "

"; $lenR = 4; if (0 == strcasecmp(substr($html, 0, $lenL), $strL) @@ -244,17 +254,16 @@ class IPF_Utils { return $html; } - static function moneyFormat($val){ + static function moneyFormat($val) + { return number_format((float)$val,2); } - static function toSlug($slug){ - if ($slug){ + static function toSlug($slug) + { + if ($slug) return strtolower(preg_replace('/[^A-Z^a-z^0-9^\/\_]+/', '-', $slug)); - } return $slug; } - - }