@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $picture_directory = $this->build_path_to_directory(); |
| 31 | 31 | $thumbnail_directory = $picture_directory; |
| 32 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | - throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 32 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) { |
|
| 33 | + throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | 36 | $filenames = self::preg_scandir($picture_directory, self::FILENAME_REGEX); |
| 36 | 37 | |
@@ -42,8 +43,9 @@ discard block |
||
| 42 | 43 | { |
| 43 | 44 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 44 | 45 | $filepathes = []; |
| 45 | - foreach($filenames as $filename) |
|
| 46 | - $filepathes[] = $this->locate_thumbnail($filename); |
|
| 46 | + foreach($filenames as $filename) { |
|
| 47 | + $filepathes[] = $this->locate_thumbnail($filename); |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | return $filepathes; |
| 49 | 51 | } |
@@ -52,8 +54,10 @@ discard block |
||
| 52 | 54 | { |
| 53 | 55 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 54 | 56 | $uris = []; |
| 55 | - foreach($filenames as $filename) |
|
| 56 | - $uris[] = hopper::file_uri($this->locate_file($filename)); ; |
|
| 57 | + foreach($filenames as $filename) { |
|
| 58 | + $uris[] = hopper::file_uri($this->locate_file($filename)); |
|
| 59 | + } |
|
| 60 | + ; |
|
| 57 | 61 | |
| 58 | 62 | return $uris; |
| 59 | 63 | } |
@@ -67,31 +71,37 @@ discard block |
||
| 67 | 71 | 'image/gif' => 'imagecreatefromgif', |
| 68 | 72 | ); |
| 69 | 73 | $mime = mime_content_type($filepath); |
| 70 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 71 | - return true; |
|
| 74 | + if(array_key_exists($mime, $picture_mime_to_gd_create_function)) { |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 72 | 77 | return $mime; |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | 80 | |
| 76 | 81 | public function upload() |
| 77 | 82 | { |
| 78 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 79 | - throw new PictureManagerException($this->get_type()." not found in _FILES"); |
|
| 83 | + if(!array_key_exists($this->get_type(), $_FILES)) { |
|
| 84 | + throw new PictureManagerException($this->get_type()." not found in _FILES"); |
|
| 85 | + } |
|
| 80 | 86 | |
| 81 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 82 | - throw new PictureManagerException('uploaded file has no size'); |
|
| 87 | + if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) { |
|
| 88 | + throw new PictureManagerException('uploaded file has no size'); |
|
| 89 | + } |
|
| 83 | 90 | |
| 84 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 85 | - throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
|
| 91 | + if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) { |
|
| 92 | + throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
|
| 93 | + } |
|
| 86 | 94 | |
| 87 | 95 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 88 | 96 | $filepath = $this->locate_file($filepath); |
| 89 | 97 | |
| 90 | - if(file_exists($filepath)) |
|
| 91 | - throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
|
| 98 | + if(file_exists($filepath)) { |
|
| 99 | + throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
|
| 100 | + } |
|
| 92 | 101 | |
| 93 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | - throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 102 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) { |
|
| 103 | + throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 104 | + } |
|
| 95 | 105 | |
| 96 | 106 | $this->make_thumbnail($filepath); |
| 97 | 107 | } |
@@ -154,19 +164,23 @@ discard block |
||
| 154 | 164 | { |
| 155 | 165 | $filenames = $this->filenames(); |
| 156 | 166 | |
| 157 | - foreach($filenames as $filename) |
|
| 158 | - $this->remove($filename); |
|
| 167 | + foreach($filenames as $filename) { |
|
| 168 | + $this->remove($filename); |
|
| 169 | + } |
|
| 159 | 170 | |
| 160 | 171 | $directory = $this->build_path_to_directory(); |
| 161 | 172 | if(file_exists($directory) === true) |
| 162 | 173 | { |
| 163 | - if(is_dir($directory) === false) |
|
| 164 | - throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
|
| 174 | + if(is_dir($directory) === false) { |
|
| 175 | + throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
|
| 176 | + } |
|
| 165 | 177 | |
| 166 | - if(rmdir($directory) === false) |
|
| 167 | - throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 178 | + if(rmdir($directory) === false) { |
|
| 179 | + throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 180 | + } |
|
| 181 | + } else { |
|
| 182 | + trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 168 | 183 | } |
| 169 | - else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 170 | 184 | } |
| 171 | 185 | |
| 172 | 186 | public function remove($picture_filename) |
@@ -181,14 +195,15 @@ discard block |
||
| 181 | 195 | foreach($pathes as $what => $path) |
| 182 | 196 | { |
| 183 | 197 | $error = null; |
| 184 | - if(!file_exists($path)) |
|
| 185 | - $error = 'file does not exist'; |
|
| 186 | - elseif(unlink($path)===false) |
|
| 187 | - $error = 'unlink() failed'; |
|
| 188 | - |
|
| 189 | - if(is_null($error)) |
|
| 190 | - $deleted[]= $what; |
|
| 191 | - else |
|
| 198 | + if(!file_exists($path)) { |
|
| 199 | + $error = 'file does not exist'; |
|
| 200 | + } elseif(unlink($path)===false) { |
|
| 201 | + $error = 'unlink() failed'; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if(is_null($error)) { |
|
| 205 | + $deleted[]= $what; |
|
| 206 | + } else |
|
| 192 | 207 | { |
| 193 | 208 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 194 | 209 | $still_walking[]=$what; |
@@ -238,13 +253,15 @@ discard block |
||
| 238 | 253 | $pictures = $pi_manager->filenames(); |
| 239 | 254 | |
| 240 | 255 | $item_model_type = get_class($item)::model_type(); |
| 241 | - if(count($pictures)===0) |
|
| 242 | - return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
|
| 256 | + if(count($pictures)===0) { |
|
| 257 | + return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
|
| 258 | + } |
|
| 243 | 259 | |
| 244 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 246 | - else |
|
| 247 | - $filename = array_shift($pictures); |
|
| 260 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) { |
|
| 261 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 262 | + } else { |
|
| 263 | + $filename = array_shift($pictures); |
|
| 264 | + } |
|
| 248 | 265 | |
| 249 | 266 | return hopper::file_uri( $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
| 250 | 267 | } |
@@ -255,8 +272,9 @@ discard block |
||
| 255 | 272 | if(count($filenames = $this->filenames()) > 0) |
| 256 | 273 | { |
| 257 | 274 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 258 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 259 | - throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 275 | + if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) { |
|
| 276 | + throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 277 | + } |
|
| 260 | 278 | |
| 261 | 279 | $last_index = $last_index[1]; |
| 262 | 280 | } |
@@ -271,8 +289,9 @@ discard block |
||
| 271 | 289 | |
| 272 | 290 | public function build_filename($index=null) |
| 273 | 291 | { |
| 274 | - if(is_null($index)) |
|
| 275 | - $index = $this->last_index()+1; |
|
| 292 | + if(is_null($index)) { |
|
| 293 | + $index = $this->last_index()+1; |
|
| 294 | + } |
|
| 276 | 295 | |
| 277 | 296 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
| 278 | 297 | } |
@@ -34,27 +34,31 @@ |
||
| 34 | 34 | |
| 35 | 35 | public function filters($filter_name=null, $value=null) |
| 36 | 36 | { |
| 37 | - if(is_null($filter_name)) |
|
| 38 | - return $_SESSION[$this->index_filter]; |
|
| 37 | + if(is_null($filter_name)) { |
|
| 38 | + return $_SESSION[$this->index_filter]; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | - if(!is_null($value)) |
|
| 41 | - $_SESSION[$this->index_filter][$filter_name] = $value; |
|
| 41 | + if(!is_null($value)) { |
|
| 42 | + $_SESSION[$this->index_filter][$filter_name] = $value; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | public function reset_filters($filter_name=null) |
| 47 | 49 | { |
| 48 | - if(is_null($filter_name)) |
|
| 49 | - $_SESSION[$this->index_filter]=[]; |
|
| 50 | - else |
|
| 51 | - unset($_SESSION[$this->index_filter][$filter_name]); |
|
| 50 | + if(is_null($filter_name)) { |
|
| 51 | + $_SESSION[$this->index_filter]=[]; |
|
| 52 | + } else { |
|
| 53 | + unset($_SESSION[$this->index_filter][$filter_name]); |
|
| 54 | + } |
|
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | public function operator_id($setter = null) |
| 55 | 58 | { |
| 56 | - if(!is_null($setter)) |
|
| 57 | - $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
| 59 | + if(!is_null($setter)) { |
|
| 60 | + $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | 63 | return $_SESSION[$this->index_operator]['id'] ?? null; |
| 60 | 64 | } |
@@ -37,8 +37,9 @@ discard block |
||
| 37 | 37 | $res = self::any(['operator_id'=>$op->get_id()]); |
| 38 | 38 | |
| 39 | 39 | $permission_ids = []; |
| 40 | - foreach($res as $r) |
|
| 41 | - $permission_ids[]=$r->get('permission_id'); |
|
| 40 | + foreach($res as $r) { |
|
| 41 | + $permission_ids[]=$r->get('permission_id'); |
|
| 42 | + } |
|
| 42 | 43 | |
| 43 | 44 | $ret = Permission::filter(['ids'=>$permission_ids]); |
| 44 | 45 | return $ret; |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $operator_with_perms = get_class($op)::exists($op->operator_id()); |
| 49 | 50 | // $operator_with_perms = get_class($op)::retrieve($operator_with_perms); |
| 50 | - if(is_null($operator_with_perms)) |
|
| 51 | - return []; |
|
| 51 | + if(is_null($operator_with_perms)) { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | return explode(',',$operator_with_perms->get('permission_names')); |
| 54 | 56 | } |
@@ -17,8 +17,10 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function load_operator($id = null) |
| 19 | 19 | { |
| 20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
| 20 | + if(!is_null($operator_id = $id ?? $this->get('operator_id'))) { |
|
| 21 | + // extraction failed but we have an fk |
|
| 21 | 22 | $this->operator = Operator::exists($operator_id); |
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | |
| 24 | 26 | public function operator() : ?OperatorInterface |
@@ -28,9 +30,10 @@ discard block |
||
| 28 | 30 | $extract_attempt = $this->extract(new Operator(), true); |
| 29 | 31 | if(!is_null($extract_attempt)) |
| 30 | 32 | { |
| 31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | - if(property_exists($this, $permission_marker)) |
|
| 33 | + foreach(['permission_names', 'permission_ids'] as $permission_marker) { |
|
| 34 | + if(property_exists($this, $permission_marker)) |
|
| 33 | 35 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
| 36 | + } |
|
| 34 | 37 | |
| 35 | 38 | $this->operator = $extract_attempt; |
| 36 | 39 | } |
@@ -55,14 +58,17 @@ discard block |
||
| 55 | 58 | |
| 56 | 59 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
| 57 | 60 | |
| 58 | - if(isset($filters['username'])) |
|
| 59 | - $Query->aw_eq('username', $filters['username'], 'operator'); |
|
| 61 | + if(isset($filters['username'])) { |
|
| 62 | + $Query->aw_eq('username', $filters['username'], 'operator'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | - if(isset($filters['email'])) |
|
| 62 | - $Query->aw_eq('email', $filters['email'], 'operator'); |
|
| 65 | + if(isset($filters['email'])) { |
|
| 66 | + $Query->aw_eq('email', $filters['email'], 'operator'); |
|
| 67 | + } |
|
| 63 | 68 | |
| 64 | - if(isset($filters['active'])) |
|
| 65 | - $Query->aw_eq('active', $filters['active'], 'operator'); |
|
| 69 | + if(isset($filters['active'])) { |
|
| 70 | + $Query->aw_eq('active', $filters['active'], 'operator'); |
|
| 71 | + } |
|
| 66 | 72 | |
| 67 | 73 | return $Query; |
| 68 | 74 | } |
@@ -193,7 +193,9 @@ discard block |
||
| 193 | 193 | $method_match = (stripos($methods, $requestMethod) !== false); |
| 194 | 194 | |
| 195 | 195 | // Method did not match, continue to next route. |
| 196 | - if (!$method_match) continue; |
|
| 196 | + if (!$method_match) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 197 | 199 | |
| 198 | 200 | if ($route === '*') { |
| 199 | 201 | // * wildcard (matches all) |
@@ -218,7 +220,9 @@ discard block |
||
| 218 | 220 | |
| 219 | 221 | if ($params) { |
| 220 | 222 | foreach($params as $key => $value) { |
| 221 | - if(is_numeric($key)) unset($params[$key]); |
|
| 223 | + if(is_numeric($key)) { |
|
| 224 | + unset($params[$key]); |
|
| 225 | + } |
|
| 222 | 226 | } |
| 223 | 227 | } |
| 224 | 228 | |
@@ -15,25 +15,31 @@ |
||
| 15 | 15 | |
| 16 | 16 | // are we paginating ? |
| 17 | 17 | |
| 18 | - if(is_null($this->box('StateAgent')->filters('results_per_page'))) |
|
| 19 | - return; |
|
| 18 | + if(is_null($this->box('StateAgent')->filters('results_per_page'))) { |
|
| 19 | + return; |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $pages_range = intval($this->box('StateAgent')->filters('results_per_page')); |
| 22 | 23 | $pages_total = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1; |
| 23 | 24 | $pages_current = intval($this->box('StateAgent')->filters('page')); |
| 24 | 25 | |
| 25 | - if($pages_current >= $pages_total) |
|
| 26 | - $pages_current = $pages_total; |
|
| 26 | + if($pages_current >= $pages_total) { |
|
| 27 | + $pages_current = $pages_total; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side; |
| 29 | 31 | |
| 30 | 32 | $pages_last = $pages_current + $pages_max_on_each_side; |
| 31 | 33 | |
| 32 | - if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed |
|
| 34 | + if($pages_last < $pages_max_displayed) { |
|
| 35 | + // add the missing pages to fullfill $pages_max_displayed |
|
| 33 | 36 | $pages_last += $pages_max_displayed-$pages_last; |
| 37 | + } |
|
| 34 | 38 | |
| 35 | - if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages |
|
| 39 | + if($pages_last > $pages_total) { |
|
| 40 | + // $pages_max_displayed greater than the total of pages |
|
| 36 | 41 | $pages_last = $pages_total; |
| 42 | + } |
|
| 37 | 43 | |
| 38 | 44 | $this->viewport("pages_total", $pages_total); |
| 39 | 45 | $this->viewport("pages_first", $pages_first); |
@@ -31,8 +31,9 @@ discard block |
||
| 31 | 31 | // shortcut for (un)boxing |
| 32 | 32 | public function box($key, $instance=null) |
| 33 | 33 | { |
| 34 | - if(!is_null($instance)) |
|
| 35 | - $this->container->register($key, $instance); |
|
| 34 | + if(!is_null($instance)) { |
|
| 35 | + $this->container->register($key, $instance); |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | // dd($this->container->get($key)); |
| 38 | 39 | return $this->container->get($key); |
@@ -64,15 +65,18 @@ discard block |
||
| 64 | 65 | public function authorize($permission=null) |
| 65 | 66 | { |
| 66 | 67 | // if(!$this->requires_operator() || is_null($permission)) |
| 67 | - if(!$this->requires_operator()) |
|
| 68 | - return true; |
|
| 68 | + if(!$this->requires_operator()) { |
|
| 69 | + return true; |
|
| 70 | + } |
|
| 69 | 71 | |
| 70 | 72 | $operator = $this->operator(); |
| 71 | - if(is_null($operator) || $operator->is_new() || !$operator->is_active()) |
|
| 72 | - throw new AccessRefusedException(); |
|
| 73 | + if(is_null($operator) || $operator->is_new() || !$operator->is_active()) { |
|
| 74 | + throw new AccessRefusedException(); |
|
| 75 | + } |
|
| 73 | 76 | |
| 74 | - if(!is_null($permission) && !$operator->has_permission($permission)) |
|
| 75 | - throw new AccessRefusedException(); |
|
| 77 | + if(!is_null($permission) && !$operator->has_permission($permission)) { |
|
| 78 | + throw new AccessRefusedException(); |
|
| 79 | + } |
|
| 76 | 80 | |
| 77 | 81 | return true; |
| 78 | 82 | } |
@@ -80,22 +84,26 @@ discard block |
||
| 80 | 84 | public function viewport($key=null, $value=null, $coercion=false) |
| 81 | 85 | { |
| 82 | 86 | // no key, returns all |
| 83 | - if(is_null($key)) |
|
| 84 | - return $this->template_variables; |
|
| 87 | + if(is_null($key)) { |
|
| 88 | + return $this->template_variables; |
|
| 89 | + } |
|
| 85 | 90 | |
| 86 | 91 | // got key, got null value, returns $[$key] |
| 87 | 92 | if(is_null($value)) |
| 88 | 93 | { |
| 89 | - if($coercion === true) // break rule 1 ? |
|
| 94 | + if($coercion === true) { |
|
| 95 | + // break rule 1 ? |
|
| 90 | 96 | $this->template_variables[$key] = null; |
| 97 | + } |
|
| 91 | 98 | |
| 92 | 99 | return $this->template_variables[$key] ?? null; |
| 93 | 100 | } |
| 94 | 101 | |
| 95 | 102 | // got key, got value |
| 96 | 103 | // sets or coerces $[$key]=$value and returns $[$key] |
| 97 | - if(!isset($this->template_variables[$key]) || $coercion === true) |
|
| 98 | - $this->template_variables[$key] = $value; |
|
| 104 | + if(!isset($this->template_variables[$key]) || $coercion === true) { |
|
| 105 | + $this->template_variables[$key] = $value; |
|
| 106 | + } |
|
| 99 | 107 | |
| 100 | 108 | return $this->template_variables[$key] ?? null; |
| 101 | 109 | } |
@@ -106,19 +114,22 @@ discard block |
||
| 106 | 114 | |
| 107 | 115 | $custom_template = null; |
| 108 | 116 | |
| 109 | - if(method_exists($this, 'prepare')) |
|
| 110 | - $this->prepare(); |
|
| 117 | + if(method_exists($this, 'prepare')) { |
|
| 118 | + $this->prepare(); |
|
| 119 | + } |
|
| 111 | 120 | |
| 112 | 121 | if(method_exists($this, $method = $this->router()->target_method())) |
| 113 | 122 | { |
| 114 | 123 | $custom_template = $this->$method(); |
| 115 | 124 | } |
| 116 | 125 | |
| 117 | - if(method_exists($this, 'conclude')) |
|
| 118 | - $this->conclude(); |
|
| 126 | + if(method_exists($this, 'conclude')) { |
|
| 127 | + $this->conclude(); |
|
| 128 | + } |
|
| 119 | 129 | |
| 120 | - if(method_exists($this, 'display')) |
|
| 121 | - $template = $this->display($custom_template); |
|
| 130 | + if(method_exists($this, 'display')) { |
|
| 131 | + $template = $this->display($custom_template); |
|
| 132 | + } |
|
| 122 | 133 | } |
| 123 | 134 | |
| 124 | 135 | public function conclude(){} |
@@ -133,8 +144,10 @@ discard block |
||
| 133 | 144 | array_walk_recursive($_GET, function(&$value){$value = trim($value);}); |
| 134 | 145 | array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);}); |
| 135 | 146 | |
| 136 | - if($this->router()->submits()) |
|
| 137 | - array_walk_recursive($_POST, function(&$value){$value = trim($value);}); |
|
| 147 | + if($this->router()->submits()) { |
|
| 148 | + array_walk_recursive($_POST, function(&$value){$value = trim($value); |
|
| 149 | + } |
|
| 150 | + }); |
|
| 138 | 151 | } |
| 139 | 152 | |
| 140 | 153 | public function display($custom_template = null, $standalone=false) |
@@ -154,14 +167,14 @@ discard block |
||
| 154 | 167 | $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path')); |
| 155 | 168 | $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/'); |
| 156 | 169 | |
| 157 | - foreach($this->viewport() as $template_var_name => $value) |
|
| 158 | - $smarty->assign($template_var_name, $value); |
|
| 170 | + foreach($this->viewport() as $template_var_name => $value) { |
|
| 171 | + $smarty->assign($template_var_name, $value); |
|
| 172 | + } |
|
| 159 | 173 | |
| 160 | 174 | if($standalone === false) |
| 161 | 175 | { |
| 162 | 176 | $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template)); |
| 163 | - } |
|
| 164 | - else |
|
| 177 | + } else |
|
| 165 | 178 | { |
| 166 | 179 | $smarty->display($template); |
| 167 | 180 | } |
@@ -205,8 +218,9 @@ discard block |
||
| 205 | 218 | |
| 206 | 219 | while(!is_null($tpl_path = array_shift($templates))) |
| 207 | 220 | { |
| 208 | - if($smarty->templateExists($tpl_path)) |
|
| 209 | - return $tpl_path; |
|
| 221 | + if($smarty->templateExists($tpl_path)) { |
|
| 222 | + return $tpl_path; |
|
| 223 | + } |
|
| 210 | 224 | } |
| 211 | 225 | |
| 212 | 226 | throw new \Exception('KADRO_ERR_NO_TEMPLATE_TO_DISPLAY'); |
@@ -228,8 +242,9 @@ discard block |
||
| 228 | 242 | */ |
| 229 | 243 | public function route_back($route_name=null, $route_params=[]) : string |
| 230 | 244 | { |
| 231 | - if(is_null($route_name)) |
|
| 232 | - return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
| 245 | + if(is_null($route_name)) { |
|
| 246 | + return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME); |
|
| 247 | + } |
|
| 233 | 248 | |
| 234 | 249 | return $this->route_back = $this->route_factory($route_name, $route_params); |
| 235 | 250 | } |
@@ -240,10 +255,11 @@ discard block |
||
| 240 | 255 | |
| 241 | 256 | if(is_string($route_name) && !empty($route_name)) |
| 242 | 257 | { |
| 243 | - if($this->router()->route_exists($route_name)) |
|
| 244 | - $route = $this->router()->prehop($route_name, $route_params); |
|
| 245 | - else |
|
| 246 | - $route = $route_name; |
|
| 258 | + if($this->router()->route_exists($route_name)) { |
|
| 259 | + $route = $this->router()->prehop($route_name, $route_params); |
|
| 260 | + } else { |
|
| 261 | + $route = $route_name; |
|
| 262 | + } |
|
| 247 | 263 | |
| 248 | 264 | return $route; |
| 249 | 265 | } |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | $picture_directory = $this->build_path_to_directory(); |
| 17 | 17 | $thumbnail_directory = $picture_directory; |
| 18 | 18 | |
| 19 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 20 | - return []; |
|
| 19 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) { |
|
| 20 | + return []; |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | $filenames = self::preg_scandir($picture_directory, '/^[0-9]+_[0-9]+\.[a-zA-Z]+/');// ID_SEQUENCENUMBER.ext |
| 23 | 24 | |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | { |
| 30 | 31 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 31 | 32 | $filepathes = []; |
| 32 | - foreach($filenames as $filename) |
|
| 33 | - $filepathes[] = $this->locate_thumbnail($filename); |
|
| 33 | + foreach($filenames as $filename) { |
|
| 34 | + $filepathes[] = $this->locate_thumbnail($filename); |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | return $filepathes; |
| 36 | 38 | } |
@@ -39,8 +41,9 @@ discard block |
||
| 39 | 41 | { |
| 40 | 42 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 41 | 43 | $uris = []; |
| 42 | - foreach($filenames as $filename) |
|
| 43 | - $uris[] = $this->locate_file($filename); |
|
| 44 | + foreach($filenames as $filename) { |
|
| 45 | + $uris[] = $this->locate_file($filename); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | dd($uris); |
| 46 | 49 | return $uris; |
@@ -55,31 +58,37 @@ discard block |
||
| 55 | 58 | 'image/gif' => 'imagecreatefromgif', |
| 56 | 59 | ); |
| 57 | 60 | $mime = mime_content_type($filepath); |
| 58 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 59 | - return true; |
|
| 61 | + if(array_key_exists($mime, $picture_mime_to_gd_create_function)) { |
|
| 62 | + return true; |
|
| 63 | + } |
|
| 60 | 64 | return $mime; |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | |
| 64 | 68 | public function upload() |
| 65 | 69 | { |
| 66 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 67 | - throw new \Exception($this->get_type()." not found in _FILES"); |
|
| 70 | + if(!array_key_exists($this->get_type(), $_FILES)) { |
|
| 71 | + throw new \Exception($this->get_type()." not found in _FILES"); |
|
| 72 | + } |
|
| 68 | 73 | |
| 69 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 70 | - throw new \Exception('uploaded file has no size'); |
|
| 74 | + if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) { |
|
| 75 | + throw new \Exception('uploaded file has no size'); |
|
| 76 | + } |
|
| 71 | 77 | |
| 72 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 73 | - throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
| 78 | + if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) { |
|
| 79 | + throw new \Exception('data sent is not an image but a '.$file_type.''); |
|
| 80 | + } |
|
| 74 | 81 | |
| 75 | 82 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 76 | 83 | $filepath = $this->locate_file($filepath); |
| 77 | 84 | |
| 78 | - if(file_exists($filepath)) |
|
| 79 | - throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
| 85 | + if(file_exists($filepath)) { |
|
| 86 | + throw new \Exception($this->get_type()." new path '$filepath' already exists"); |
|
| 87 | + } |
|
| 80 | 88 | |
| 81 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 82 | - throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 89 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) { |
|
| 90 | + throw new \Exception(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 91 | + } |
|
| 83 | 92 | |
| 84 | 93 | $this->make_thumbnail($filepath); |
| 85 | 94 | } |
@@ -142,19 +151,23 @@ discard block |
||
| 142 | 151 | { |
| 143 | 152 | $filenames = $this->filenames(); |
| 144 | 153 | |
| 145 | - foreach($filenames as $filename) |
|
| 146 | - $this->remove($filename); |
|
| 154 | + foreach($filenames as $filename) { |
|
| 155 | + $this->remove($filename); |
|
| 156 | + } |
|
| 147 | 157 | |
| 148 | 158 | $directory = $this->build_path_to_directory(); |
| 149 | 159 | if(file_exists($directory) === true) |
| 150 | 160 | { |
| 151 | - if(is_dir($directory) === false) |
|
| 152 | - throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
| 161 | + if(is_dir($directory) === false) { |
|
| 162 | + throw new \Exception($this->get_type()."' directory '$directory' is not a directory"); |
|
| 163 | + } |
|
| 153 | 164 | |
| 154 | - if(rmdir($directory) === false) |
|
| 155 | - throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 165 | + if(rmdir($directory) === false) { |
|
| 166 | + throw new \Exception("rmdir($directory) failed like a bitch"); |
|
| 167 | + } |
|
| 168 | + } else { |
|
| 169 | + trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 156 | 170 | } |
| 157 | - else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 158 | 171 | } |
| 159 | 172 | |
| 160 | 173 | public function remove($picture_filename) |
@@ -169,14 +182,15 @@ discard block |
||
| 169 | 182 | foreach($pathes as $what => $path) |
| 170 | 183 | { |
| 171 | 184 | $error = null; |
| 172 | - if(!file_exists($path)) |
|
| 173 | - $error = 'file does not exist'; |
|
| 174 | - elseif(unlink($path)===false) |
|
| 175 | - $error = 'unlink() failed'; |
|
| 176 | - |
|
| 177 | - if(is_null($error)) |
|
| 178 | - $deleted[]= $what; |
|
| 179 | - else |
|
| 185 | + if(!file_exists($path)) { |
|
| 186 | + $error = 'file does not exist'; |
|
| 187 | + } elseif(unlink($path)===false) { |
|
| 188 | + $error = 'unlink() failed'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if(is_null($error)) { |
|
| 192 | + $deleted[]= $what; |
|
| 193 | + } else |
|
| 180 | 194 | { |
| 181 | 195 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 182 | 196 | $still_walking[]=$what; |
@@ -226,13 +240,15 @@ discard block |
||
| 226 | 240 | $pictures = $pi_manager->filenames(); |
| 227 | 241 | |
| 228 | 242 | $item_model_type = get_class($item)::model_type(); |
| 229 | - if(count($pictures)===0) |
|
| 230 | - return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
| 243 | + if(count($pictures)===0) { |
|
| 244 | + return $settings[$item_model_type][$picture_type]['generic_picture']; |
|
| 245 | + } |
|
| 231 | 246 | |
| 232 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 233 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 234 | - else |
|
| 235 | - $filename = array_shift($pictures); |
|
| 247 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) { |
|
| 248 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 249 | + } else { |
|
| 250 | + $filename = array_shift($pictures); |
|
| 251 | + } |
|
| 236 | 252 | |
| 237 | 253 | return $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename); |
| 238 | 254 | } |
@@ -243,8 +259,9 @@ discard block |
||
| 243 | 259 | if(count($filenames = $this->filenames()) > 0) |
| 244 | 260 | { |
| 245 | 261 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 246 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 247 | - throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 262 | + if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) { |
|
| 263 | + throw new \Exception("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 264 | + } |
|
| 248 | 265 | |
| 249 | 266 | $last_index = $last_index[1]; |
| 250 | 267 | } |
@@ -259,8 +276,9 @@ discard block |
||
| 259 | 276 | |
| 260 | 277 | public function build_filename($index=null) |
| 261 | 278 | { |
| 262 | - if(is_null($index)) |
|
| 263 | - $index = $this->last_index()+1; |
|
| 279 | + if(is_null($index)) { |
|
| 280 | + $index = $this->last_index()+1; |
|
| 281 | + } |
|
| 264 | 282 | |
| 265 | 283 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
| 266 | 284 | } |
@@ -9,11 +9,13 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | private static function compute_field_value($model,$field_name) |
| 11 | 11 | { |
| 12 | - if(method_exists($model,$field_name)) |
|
| 13 | - return $model->$field_name(); |
|
| 12 | + if(method_exists($model,$field_name)) { |
|
| 13 | + return $model->$field_name(); |
|
| 14 | + } |
|
| 14 | 15 | |
| 15 | - if(property_exists($model,$field_name)) |
|
| 16 | - return $model->$field_name; |
|
| 16 | + if(property_exists($model,$field_name)) { |
|
| 17 | + return $model->$field_name; |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | return ''; |
| 19 | 21 | } |
@@ -51,74 +53,66 @@ discard block |
||
| 51 | 53 | |
| 52 | 54 | $table = get_class($model)::table(); |
| 53 | 55 | |
| 54 | - if(is_null($table->column($field_name))) |
|
| 55 | - return Form::input($field_name,$field_value,$attributes,$errors); |
|
| 56 | + if(is_null($table->column($field_name))) { |
|
| 57 | + return Form::input($field_name,$field_value,$attributes,$errors); |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | 60 | $ret = ''; |
| 58 | 61 | |
| 59 | 62 | $field = $table->column($field_name); |
| 60 | 63 | |
| 61 | 64 | |
| 62 | - if(isset($attributes['required']) && $attributes['required'] === false) |
|
| 63 | - unset($attributes['required']); |
|
| 64 | - |
|
| 65 | - elseif(!$field->is_nullable()) |
|
| 66 | - $attributes[] = 'required'; |
|
| 65 | + if(isset($attributes['required']) && $attributes['required'] === false) { |
|
| 66 | + unset($attributes['required']); |
|
| 67 | + } elseif(!$field->is_nullable()) { |
|
| 68 | + $attributes[] = 'required'; |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | if($field->is_auto_incremented()) |
| 69 | 72 | { |
| 70 | 73 | $ret .= Form::hidden($field->name(),$field_value); |
| 71 | - } |
|
| 72 | - elseif($field->type()->is_boolean()) |
|
| 74 | + } elseif($field->type()->is_boolean()) |
|
| 73 | 75 | { |
| 74 | 76 | $option_list = $attributes['values'] ?? [0 => 0, 1 => 1]; |
| 75 | 77 | $ret .= Form::select($field->name(), $option_list ,$field_value, $attributes); // |
| 76 | - } |
|
| 77 | - elseif($field->type()->is_integer()) |
|
| 78 | + } elseif($field->type()->is_integer()) |
|
| 78 | 79 | { |
| 79 | 80 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 80 | - } |
|
| 81 | - elseif($field->type()->is_year()) |
|
| 81 | + } elseif($field->type()->is_year()) |
|
| 82 | 82 | { |
| 83 | 83 | $attributes['size'] = $attributes['maxlength'] = 4; |
| 84 | 84 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 85 | - } |
|
| 86 | - elseif($field->type()->is_date()) |
|
| 85 | + } elseif($field->type()->is_date()) |
|
| 87 | 86 | { |
| 88 | 87 | $ret .= Form::date($field->name(),$field_value,$attributes,$errors); |
| 89 | - } |
|
| 90 | - elseif($field->type()->is_time()) |
|
| 88 | + } elseif($field->type()->is_time()) |
|
| 91 | 89 | { |
| 92 | 90 | $ret .= Form::time($field->name(),$field_value,$attributes,$errors); |
| 93 | - } |
|
| 94 | - elseif($field->type()->is_datetime()) |
|
| 91 | + } elseif($field->type()->is_datetime()) |
|
| 95 | 92 | { |
| 96 | 93 | $ret .= Form::datetime($field->name(),$field_value,$attributes,$errors); |
| 97 | - } |
|
| 98 | - elseif($field->type()->is_text()) |
|
| 94 | + } elseif($field->type()->is_text()) |
|
| 99 | 95 | { |
| 100 | 96 | $ret .= Form::textarea($field->name(),$field_value,$attributes,$errors); |
| 101 | - } |
|
| 102 | - elseif($field->type()->is_enum()) |
|
| 97 | + } elseif($field->type()->is_enum()) |
|
| 103 | 98 | { |
| 104 | 99 | |
| 105 | 100 | $enum_values = []; |
| 106 | - foreach($field->type()->enum_values() as $e_val) |
|
| 107 | - $enum_values[$e_val] = $e_val; |
|
| 101 | + foreach($field->type()->enum_values() as $e_val) { |
|
| 102 | + $enum_values[$e_val] = $e_val; |
|
| 103 | + } |
|
| 108 | 104 | |
| 109 | 105 | $selected = $attributes['value'] ?? $field_value ?? ''; |
| 110 | 106 | // foreach($field->) |
| 111 | 107 | $ret .= Form::select($field->name(), $enum_values, $selected, $attributes); // |
| 112 | 108 | |
| 113 | 109 | // throw new \Exception('ENUM IS NOT HANDLED BY TableToFom'); |
| 114 | - } |
|
| 115 | - elseif($field->type()->is_string()) |
|
| 110 | + } elseif($field->type()->is_string()) |
|
| 116 | 111 | { |
| 117 | 112 | $max_length = $field->type()->length(); |
| 118 | 113 | $attributes['size'] = $attributes['maxlength'] = $max_length; |
| 119 | 114 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 120 | - } |
|
| 121 | - else |
|
| 115 | + } else |
|
| 122 | 116 | { |
| 123 | 117 | $ret .= Form::input($field->name(),$field_value,$attributes,$errors); |
| 124 | 118 | } |
@@ -130,8 +124,9 @@ discard block |
||
| 130 | 124 | public static function field_with_label($model,$field_name,$attributes=[],$errors=[]) : string |
| 131 | 125 | { |
| 132 | 126 | $field_attributes = $attributes; |
| 133 | - if(isset($attributes['label'])) |
|
| 134 | - unset($field_attributes['label']); |
|
| 127 | + if(isset($attributes['label'])) { |
|
| 128 | + unset($field_attributes['label']); |
|
| 129 | + } |
|
| 135 | 130 | |
| 136 | 131 | return sprintf('%s %s', self::label($model,$field_name,$attributes,$errors), self::field($model,$field_name,$field_attributes,$errors)); |
| 137 | 132 | } |
@@ -148,14 +143,15 @@ discard block |
||
| 148 | 143 | $form_field = ''; |
| 149 | 144 | if($column->is_auto_incremented()) |
| 150 | 145 | { |
| 151 | - if(!$model->is_new()) |
|
| 152 | - $form_field = self::field($model,$column_name); |
|
| 153 | - } |
|
| 154 | - else |
|
| 146 | + if(!$model->is_new()) { |
|
| 147 | + $form_field = self::field($model,$column_name); |
|
| 148 | + } |
|
| 149 | + } else |
|
| 155 | 150 | { |
| 156 | 151 | $form_field = self::field_with_label($model,$column_name); |
| 157 | - if(!is_null($group_class)) |
|
| 158 | - $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
| 152 | + if(!is_null($group_class)) { |
|
| 153 | + $form_field = new Element('div',$form_field, ['class' => $group_class]); |
|
| 154 | + } |
|
| 159 | 155 | } |
| 160 | 156 | $ret .= PHP_EOL.$form_field; |
| 161 | 157 | } |