@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | // const MOVIE_POSTER = 'poster'; |
| 26 | 26 | // const MOVIE_SNAPSHOT = 'snapshot'; |
| 27 | 27 | |
| 28 | - public function filenames($replace_by_thumbs_if_exists=false) |
|
| 28 | + public function filenames($replace_by_thumbs_if_exists = false) |
|
| 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) |
|
| 32 | + if (!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | 33 | throw new PictureManagerException("directory '$picture_directory' does not exist"); |
| 34 | 34 | |
| 35 | 35 | $filenames = self::preg_scandir($picture_directory, self::FILENAME_REGEX); |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | return $filenames; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function filepathes($replace_by_thumbs_if_exists=false) |
|
| 41 | + public function filepathes($replace_by_thumbs_if_exists = false) |
|
| 42 | 42 | { |
| 43 | 43 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 44 | 44 | $filepathes = []; |
| 45 | - foreach($filenames as $filename) |
|
| 45 | + foreach ($filenames as $filename) |
|
| 46 | 46 | $filepathes[] = $this->locate_thumbnail($filename); |
| 47 | 47 | |
| 48 | 48 | return $filepathes; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function file_uris($replace_by_thumbs_if_exists=false) |
|
| 51 | + public function file_uris($replace_by_thumbs_if_exists = false) |
|
| 52 | 52 | { |
| 53 | 53 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 54 | 54 | $uris = []; |
| 55 | - foreach($filenames as $filename) |
|
| 55 | + foreach ($filenames as $filename) |
|
| 56 | 56 | $uris[] = hopper::file_uri($this->locate_file($filename)); ; |
| 57 | 57 | |
| 58 | 58 | return $uris; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | 'image/gif' => 'imagecreatefromgif', |
| 68 | 68 | ); |
| 69 | 69 | $mime = mime_content_type($filepath); |
| 70 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 70 | + if (array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 71 | 71 | return true; |
| 72 | 72 | return $mime; |
| 73 | 73 | } |
@@ -75,22 +75,22 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function upload() |
| 77 | 77 | { |
| 78 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 78 | + if (!array_key_exists($this->get_type(), $_FILES)) |
|
| 79 | 79 | throw new PictureManagerException($this->get_type()." not found in _FILES"); |
| 80 | 80 | |
| 81 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 81 | + if (!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 82 | 82 | throw new PictureManagerException('uploaded file has no size'); |
| 83 | 83 | |
| 84 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 84 | + if (($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 85 | 85 | throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
| 86 | 86 | |
| 87 | - $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 87 | + $filepath = $this->build_filename().'.'.self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 88 | 88 | $filepath = $this->locate_file($filepath); |
| 89 | 89 | |
| 90 | - if(file_exists($filepath)) |
|
| 90 | + if (file_exists($filepath)) |
|
| 91 | 91 | throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
| 92 | 92 | |
| 93 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 93 | + if (copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | 94 | throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
| 95 | 95 | |
| 96 | 96 | $this->make_thumbnail($filepath); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function download($url) |
| 100 | 100 | { |
| 101 | - $filepath = $this->build_filename() . '.' . self::file_ext($url); |
|
| 101 | + $filepath = $this->build_filename().'.'.self::file_ext($url); |
|
| 102 | 102 | $filepath = $this->locate_file($filepath); |
| 103 | 103 | |
| 104 | 104 | \qivive\Curlyb::fetch($url, $filepath); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $cover_iri = null; |
| 114 | 114 | |
| 115 | 115 | $mime_type = mime_content_type($filepath); |
| 116 | - switch($mime_type) |
|
| 116 | + switch ($mime_type) |
|
| 117 | 117 | { |
| 118 | 118 | case 'image/jpeg': |
| 119 | 119 | case 'image/pjpeg': |
@@ -129,21 +129,21 @@ discard block |
||
| 129 | 129 | break; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if(!is_null($cover_iri)) |
|
| 132 | + if (!is_null($cover_iri)) |
|
| 133 | 133 | { |
| 134 | - $width = imagesx( $cover_iri ); |
|
| 135 | - $height = imagesy( $cover_iri ); |
|
| 134 | + $width = imagesx($cover_iri); |
|
| 135 | + $height = imagesy($cover_iri); |
|
| 136 | 136 | |
| 137 | 137 | // calculate thumbnail size |
| 138 | 138 | |
| 139 | 139 | $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
| 140 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 140 | + $new_height = floor($height * ($new_width / $width)); |
|
| 141 | 141 | |
| 142 | 142 | // create a new temporary image |
| 143 | 143 | $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
| 144 | 144 | |
| 145 | 145 | // copy and resize old image into new image |
| 146 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 146 | + imagecopyresized($thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
| 147 | 147 | |
| 148 | 148 | // save thumbnail into a file |
| 149 | 149 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | $filenames = $this->filenames(); |
| 156 | 156 | |
| 157 | - foreach($filenames as $filename) |
|
| 157 | + foreach ($filenames as $filename) |
|
| 158 | 158 | $this->remove($filename); |
| 159 | 159 | |
| 160 | 160 | $directory = $this->build_path_to_directory(); |
| 161 | - if(file_exists($directory) === true) |
|
| 161 | + if (file_exists($directory) === true) |
|
| 162 | 162 | { |
| 163 | - if(is_dir($directory) === false) |
|
| 163 | + if (is_dir($directory) === false) |
|
| 164 | 164 | throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
| 165 | 165 | |
| 166 | - if(rmdir($directory) === false) |
|
| 166 | + if (rmdir($directory) === false) |
|
| 167 | 167 | throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
| 168 | 168 | } |
| 169 | 169 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
@@ -174,27 +174,27 @@ discard block |
||
| 174 | 174 | // removing a picture, and maybe a thumbnail? build the $pathes array accordingly |
| 175 | 175 | $pathes = []; |
| 176 | 176 | $pathes[$this->get_type()] = $this->locate_file($picture_filename); |
| 177 | - $pathes[$this->get_type() . ' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 177 | + $pathes[$this->get_type().' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 178 | 178 | |
| 179 | 179 | $deleted = []; |
| 180 | 180 | $still_walking = []; |
| 181 | - foreach($pathes as $what => $path) |
|
| 181 | + foreach ($pathes as $what => $path) |
|
| 182 | 182 | { |
| 183 | 183 | $error = null; |
| 184 | - if(!file_exists($path)) |
|
| 184 | + if (!file_exists($path)) |
|
| 185 | 185 | $error = 'file does not exist'; |
| 186 | - elseif(unlink($path)===false) |
|
| 186 | + elseif (unlink($path) === false) |
|
| 187 | 187 | $error = 'unlink() failed'; |
| 188 | 188 | |
| 189 | - if(is_null($error)) |
|
| 190 | - $deleted[]= $what; |
|
| 189 | + if (is_null($error)) |
|
| 190 | + $deleted[] = $what; |
|
| 191 | 191 | else |
| 192 | 192 | { |
| 193 | 193 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 194 | - $still_walking[]=$what; |
|
| 194 | + $still_walking[] = $what; |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | - return count($still_walking)===0; |
|
| 197 | + return count($still_walking) === 0; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | public function locate_thumbnail($filename) |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | return $settings['thumbnail']['file_prefix'].''.pathinfo($picture_basename, PATHINFO_FILENAME).'.jpg'; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public static function file_info($absolute_path_to_picture, $what=null) |
|
| 211 | + public static function file_info($absolute_path_to_picture, $what = null) |
|
| 212 | 212 | { |
| 213 | - $ret = parent::file_info($absolute_path_to_picture, $what=null); |
|
| 213 | + $ret = parent::file_info($absolute_path_to_picture, $what = null); |
|
| 214 | 214 | |
| 215 | - if(is_array($ret)) |
|
| 215 | + if (is_array($ret)) |
|
| 216 | 216 | { |
| 217 | 217 | $t = getimagesize($absolute_path_to_picture); |
| 218 | 218 | $ret['width'] = $t[0]; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
| 233 | - public static function uri_for($item, $picture_type, $thumbnail=true) |
|
| 233 | + public static function uri_for($item, $picture_type, $thumbnail = true) |
|
| 234 | 234 | { |
| 235 | 235 | global $settings; |
| 236 | 236 | $pi_manager = new PictureManager($item, $picture_type); |
@@ -238,24 +238,24 @@ discard block |
||
| 238 | 238 | $pictures = $pi_manager->filenames(); |
| 239 | 239 | |
| 240 | 240 | $item_model_type = get_class($item)::model_type(); |
| 241 | - if(count($pictures)===0) |
|
| 241 | + if (count($pictures) === 0) |
|
| 242 | 242 | return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
| 243 | 243 | |
| 244 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 244 | + if ($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | 245 | $filename = $pictures[array_rand($pictures, 1)]; |
| 246 | 246 | else |
| 247 | 247 | $filename = array_shift($pictures); |
| 248 | 248 | |
| 249 | - return hopper::file_uri( $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
|
| 249 | + return hopper::file_uri($thumbnail === true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function last_index() |
| 253 | 253 | { |
| 254 | 254 | $last_index = 0; |
| 255 | - if(count($filenames = $this->filenames()) > 0) |
|
| 255 | + if (count($filenames = $this->filenames()) > 0) |
|
| 256 | 256 | { |
| 257 | 257 | $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) |
|
| 258 | + if (preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 259 | 259 | throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
| 260 | 260 | |
| 261 | 261 | $last_index = $last_index[1]; |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | return sprintf('%s%s.jpg', $settings['thumbnail']['file_prefix'], pathinfo($picture_basename, PATHINFO_FILENAME)); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - public function build_filename($index=null) |
|
| 272 | + public function build_filename($index = null) |
|
| 273 | 273 | { |
| 274 | - if(is_null($index)) |
|
| 274 | + if (is_null($index)) |
|
| 275 | 275 | $index = $this->last_index()+1; |
| 276 | 276 | |
| 277 | 277 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | $new_thumbname_path = $this->locate_file($this->build_thumb_filename($new_filename_path)); //move current to zero |
| 291 | 291 | $this->rename($selected_thumbname_path, $new_thumbname_path); |
| 292 | 292 | |
| 293 | - for($i=$filename_index-1; $i>=0; --$i) |
|
| 293 | + for ($i = $filename_index-1; $i >= 0; --$i) |
|
| 294 | 294 | { |
| 295 | 295 | $move_this = $this->locate_file($files[$i]); |
| 296 | 296 | $to_that = $this->locate_file($files[$i+1]); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | // $options : https://www.php.net/manual/fr/session.configuration.php |
| 12 | 12 | public function __construct($options) |
| 13 | 13 | { |
| 14 | - if(isset($options['session_name'])) |
|
| 14 | + if (isset($options['session_name'])) |
|
| 15 | 15 | { |
| 16 | 16 | session_name($options['session_name']); |
| 17 | 17 | unset($options['session_name']); |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | return isset($_SESSION[$this->index_filter][$filter_name]) && strlen(''.$_SESSION[$this->index_filter][$filter_name]) > 0; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function filters($filter_name=null, $value=null) |
|
| 35 | + public function filters($filter_name = null, $value = null) |
|
| 36 | 36 | { |
| 37 | - if(is_null($filter_name)) |
|
| 37 | + if (is_null($filter_name)) |
|
| 38 | 38 | return $_SESSION[$this->index_filter]; |
| 39 | 39 | |
| 40 | - if(!is_null($value)) |
|
| 40 | + if (!is_null($value)) |
|
| 41 | 41 | $_SESSION[$this->index_filter][$filter_name] = $value; |
| 42 | 42 | |
| 43 | 43 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function reset_filters($filter_name=null) |
|
| 46 | + public function reset_filters($filter_name = null) |
|
| 47 | 47 | { |
| 48 | - if(is_null($filter_name)) |
|
| 49 | - $_SESSION[$this->index_filter]=[]; |
|
| 48 | + if (is_null($filter_name)) |
|
| 49 | + $_SESSION[$this->index_filter] = []; |
|
| 50 | 50 | else |
| 51 | 51 | unset($_SESSION[$this->index_filter][$filter_name]); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function operator_id($setter = null) |
| 55 | 55 | { |
| 56 | - if(!is_null($setter)) |
|
| 56 | + if (!is_null($setter)) |
|
| 57 | 57 | $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
| 58 | 58 | |
| 59 | 59 | return $_SESSION[$this->index_operator]['id'] ?? null; |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | public function destroy() : bool |
| 69 | 69 | { |
| 70 | 70 | |
| 71 | - if(ini_get("session.use_cookies")) |
|
| 71 | + if (ini_get("session.use_cookies")) |
|
| 72 | 72 | { |
| 73 | 73 | $params = session_get_cookie_params(); |
| 74 | - setcookie(session_name(), '', time() - 42000, |
|
| 74 | + setcookie(session_name(), '', time()-42000, |
|
| 75 | 75 | $params["path"], $params["domain"], |
| 76 | 76 | $params["secure"], $params["httponly"] |
| 77 | 77 | ); |
@@ -8,17 +8,17 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function permission_names() |
| 10 | 10 | { |
| 11 | - if(property_exists($this, 'permission_names')) |
|
| 11 | + if (property_exists($this, 'permission_names')) |
|
| 12 | 12 | { |
| 13 | 13 | return explode(',', $this->permission_names); |
| 14 | 14 | } |
| 15 | - elseif(property_exists($this, 'permission_ids')) |
|
| 15 | + elseif (property_exists($this, 'permission_ids')) |
|
| 16 | 16 | { |
| 17 | 17 | $ids = explode(',', $this->permission_ids); |
| 18 | 18 | $ret = []; |
| 19 | 19 | $permissions = Permission::get_many_by_AIPK($ids); |
| 20 | - foreach($permissions as $id => $p) |
|
| 21 | - $ret[]="$p"; |
|
| 20 | + foreach ($permissions as $id => $p) |
|
| 21 | + $ret[] = "$p"; |
|
| 22 | 22 | return $ret; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | public function permissions() |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - if(!is_null($this->permissions)) |
|
| 34 | + if (!is_null($this->permissions)) |
|
| 35 | 35 | return $this->permissions; |
| 36 | 36 | $permission_unique_keys = null; |
| 37 | - if(property_exists($this, 'permission_names')) |
|
| 37 | + if (property_exists($this, 'permission_names')) |
|
| 38 | 38 | { |
| 39 | 39 | $permission_unique_keys = explode(',', $this->permission_names); |
| 40 | 40 | // vd(Permission::table()->select()); |
| 41 | 41 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
| 42 | 42 | } |
| 43 | - elseif(property_exists($this, 'permission_ids')) |
|
| 43 | + elseif (property_exists($this, 'permission_ids')) |
|
| 44 | 44 | { |
| 45 | 45 | $permission_unique_keys = explode(',', $this->permission_ids); |
| 46 | 46 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
@@ -56,40 +56,40 @@ discard block |
||
| 56 | 56 | public function has_permission($p) : bool |
| 57 | 57 | { |
| 58 | 58 | // new instances or inactive operators, none shall pass |
| 59 | - if($this->is_new() === true || $this->is_active() === false) |
|
| 59 | + if ($this->is_new() === true || $this->is_active() === false) |
|
| 60 | 60 | return false; |
| 61 | 61 | |
| 62 | 62 | $permission_name = $permission_id = null; |
| 63 | - if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
| 63 | + if (is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
| 64 | 64 | { |
| 65 | 65 | $permission_name = $p->get('name'); |
| 66 | 66 | $permission_id = $p->get_id(); |
| 67 | 67 | } |
| 68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
| 68 | + elseif (preg_match('/[0-9]+/', $p)) |
|
| 69 | 69 | $permission_id = $p; |
| 70 | 70 | else |
| 71 | 71 | $permission_name = $p; |
| 72 | 72 | |
| 73 | 73 | |
| 74 | - if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
| 74 | + if (!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
| 75 | 75 | { |
| 76 | 76 | return strpos($this->get('permission_names'), $permission_name) !== false; |
| 77 | 77 | } |
| 78 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 78 | + elseif (!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 79 | 79 | { |
| 80 | 80 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
| 81 | 81 | } |
| 82 | - elseif(!is_null($permission_name)) |
|
| 82 | + elseif (!is_null($permission_name)) |
|
| 83 | 83 | { |
| 84 | - if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
| 84 | + if (method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
| 85 | 85 | { |
| 86 | 86 | return true; |
| 87 | 87 | } |
| 88 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 88 | + elseif (property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 89 | 89 | { |
| 90 | 90 | return true; |
| 91 | 91 | } |
| 92 | - elseif(ACL::match($this, $permission_name) === true) |
|
| 92 | + elseif (ACL::match($this, $permission_name) === true) |
|
| 93 | 93 | { |
| 94 | 94 | return true; |
| 95 | 95 | } |
@@ -17,19 +17,19 @@ 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'))) // extraction failed but we have an fk |
|
| 21 | 21 | $this->operator = Operator::exists($operator_id); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function operator() : ?OperatorInterface |
| 25 | 25 | { |
| 26 | - if(is_null($this->operator)) |
|
| 26 | + if (is_null($this->operator)) |
|
| 27 | 27 | { |
| 28 | 28 | $extract_attempt = $this->extract(new Operator(), true); |
| 29 | - if(!is_null($extract_attempt)) |
|
| 29 | + if (!is_null($extract_attempt)) |
|
| 30 | 30 | { |
| 31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | - if(property_exists($this, $permission_marker)) |
|
| 31 | + foreach (['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | + if (property_exists($this, $permission_marker)) |
|
| 33 | 33 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
| 34 | 34 | |
| 35 | 35 | $this->operator = $extract_attempt; |
@@ -45,23 +45,23 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static function enhance_query_retrieve($Query, $filters, $options) |
| 47 | 47 | { |
| 48 | - $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
| 48 | + $joined_alias = $Query->auto_join([ACL::table(), 'ACL'], null, 'LEFT OUTER'); |
|
| 49 | 49 | $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
| 50 | 50 | |
| 51 | 51 | $permission_ids_and_names = []; |
| 52 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
| 53 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
| 52 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
| 53 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
| 54 | 54 | $Query->select_also($permission_ids_and_names); |
| 55 | 55 | |
| 56 | 56 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
| 57 | 57 | |
| 58 | - if(isset($filters['username'])) |
|
| 58 | + if (isset($filters['username'])) |
|
| 59 | 59 | $Query->aw_eq('username', $filters['username'], 'operator'); |
| 60 | 60 | |
| 61 | - if(isset($filters['email'])) |
|
| 61 | + if (isset($filters['email'])) |
|
| 62 | 62 | $Query->aw_eq('email', $filters['email'], 'operator'); |
| 63 | 63 | |
| 64 | - if(isset($filters['active'])) |
|
| 64 | + if (isset($filters['active'])) |
|
| 65 | 65 | $Query->aw_eq('active', $filters['active'], 'operator'); |
| 66 | 66 | |
| 67 | 67 | return $Query; |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $dir_content = FileSystem::preg_scandir($base_dir, '/^[A-Z]{1}[A-Za-z]+(?!\.class.\.php)$/'); |
| 42 | 42 | |
| 43 | - foreach($dir_content as $res) |
|
| 43 | + foreach ($dir_content as $res) |
|
| 44 | 44 | { |
| 45 | - if(is_dir($fullpath = $base_dir.'/'.$res)) |
|
| 45 | + if (is_dir($fullpath = $base_dir.'/'.$res)) |
|
| 46 | 46 | { |
| 47 | 47 | $this->addNamespace('HexMakina\kadro\\'.$res, $fullpath); |
| 48 | 48 | $this->addNamespaceTree($fullpath); |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | |
| 56 | 56 | // normalize namespace prefix |
| 57 | - $prefix = trim($prefix, '\\') . '\\'; |
|
| 57 | + $prefix = trim($prefix, '\\').'\\'; |
|
| 58 | 58 | |
| 59 | 59 | // normalize the base directory with a trailing separator |
| 60 | - $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; |
|
| 60 | + $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR).'/'; |
|
| 61 | 61 | |
| 62 | 62 | // initialize the namespace prefix array |
| 63 | 63 | if (isset($this->prefixes[$prefix]) === false) { |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | while (false !== $pos = strrpos($prefix, '\\')) |
| 91 | 91 | { |
| 92 | 92 | // retain the trailing namespace separator in the prefix |
| 93 | - $prefix = substr($class, 0, $pos + 1); |
|
| 93 | + $prefix = substr($class, 0, $pos+1); |
|
| 94 | 94 | // var_dump("prefix: $prefix"); |
| 95 | 95 | // the rest is the relative class name |
| 96 | - $relative_class = substr($class, $pos + 1); |
|
| 96 | + $relative_class = substr($class, $pos+1); |
|
| 97 | 97 | // try to load a mapped file for the prefix and relative class |
| 98 | 98 | |
| 99 | 99 | $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
@@ -13,10 +13,10 @@ |
||
| 13 | 13 | public function match($requestUrl = null, $requestMethod = null); |
| 14 | 14 | |
| 15 | 15 | // generates URL for href and location |
| 16 | - public function prehop($route, $route_params=[]); |
|
| 16 | + public function prehop($route, $route_params = []); |
|
| 17 | 17 | |
| 18 | 18 | // heads to another location |
| 19 | - public function hop($route, $route_params=[]); |
|
| 19 | + public function hop($route, $route_params = []); |
|
| 20 | 20 | |
| 21 | 21 | // do you GET it ? |
| 22 | 22 | public function requests() : bool; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param string $basePath |
| 37 | 37 | * @param array $matchTypes |
| 38 | 38 | */ |
| 39 | - public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) { |
|
| 39 | + public function __construct($routes = array(), $basePath = '', $matchTypes = array()) { |
|
| 40 | 40 | $this->addRoutes($routes); |
| 41 | 41 | $this->setBasePath($basePath); |
| 42 | 42 | $this->addMatchTypes($matchTypes); |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | * @author Koen Punt |
| 64 | 64 | * @throws Exception |
| 65 | 65 | */ |
| 66 | - public function addRoutes($routes){ |
|
| 67 | - if(!is_array($routes) && !$routes instanceof Traversable) { |
|
| 66 | + public function addRoutes($routes) { |
|
| 67 | + if (!is_array($routes) && !$routes instanceof Traversable) { |
|
| 68 | 68 | throw new \Exception('Routes should be an array or an instance of Traversable'); |
| 69 | 69 | } |
| 70 | - foreach($routes as $route) { |
|
| 70 | + foreach ($routes as $route) { |
|
| 71 | 71 | call_user_func_array(array($this, 'map'), $route); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $this->routes[] = array($method, $route, $target, $name); |
| 104 | 104 | |
| 105 | - if($name) { |
|
| 106 | - if(isset($this->namedRoutes[$name])) { |
|
| 105 | + if ($name) { |
|
| 106 | + if (isset($this->namedRoutes[$name])) { |
|
| 107 | 107 | throw new \Exception("Can not redeclare route '{$name}'"); |
| 108 | 108 | } else { |
| 109 | 109 | $this->namedRoutes[$name] = $route; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | public function generate($routeName, array $params = array()) { |
| 128 | 128 | |
| 129 | 129 | // Check if named route exists |
| 130 | - if(!isset($this->namedRoutes[$routeName])) { |
|
| 130 | + if (!isset($this->namedRoutes[$routeName])) { |
|
| 131 | 131 | throw new \Exception("Route '{$routeName}' does not exist."); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | $route = $this->namedRoutes[$routeName]; |
| 136 | 136 | |
| 137 | 137 | // prepend base path to route url again |
| 138 | - $url = $this->basePath . $route; |
|
| 138 | + $url = $this->basePath.$route; |
|
| 139 | 139 | |
| 140 | 140 | if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { |
| 141 | 141 | |
| 142 | - foreach($matches as $match) { |
|
| 142 | + foreach ($matches as $match) { |
|
| 143 | 143 | list($block, $pre, $type, $param, $optional) = $match; |
| 144 | 144 | |
| 145 | 145 | if ($pre) { |
| 146 | 146 | $block = substr($block, 1); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if(isset($params[$param])) { |
|
| 149 | + if (isset($params[$param])) { |
|
| 150 | 150 | $url = str_replace($block, $params[$param], $url); |
| 151 | 151 | } elseif ($optional) { |
| 152 | - $url = str_replace($pre . $block, '', $url); |
|
| 152 | + $url = str_replace($pre.$block, '', $url); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $match = false; |
| 172 | 172 | |
| 173 | 173 | // set Request Url if it isn't passed as parameter |
| 174 | - if($requestUrl === null) { |
|
| 174 | + if ($requestUrl === null) { |
|
| 175 | 175 | $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,11 +184,11 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // set Request Method if it isn't passed as a parameter |
| 187 | - if($requestMethod === null) { |
|
| 187 | + if ($requestMethod === null) { |
|
| 188 | 188 | $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - foreach($this->routes as $handler) { |
|
| 191 | + foreach ($this->routes as $handler) { |
|
| 192 | 192 | list($methods, $route, $target, $name) = $handler; |
| 193 | 193 | $method_match = (stripos($methods, $requestMethod) !== false); |
| 194 | 194 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $match = true; |
| 201 | 201 | } elseif (isset($route[0]) && $route[0] === '@') { |
| 202 | 202 | // @ regex delimiter |
| 203 | - $pattern = '`' . substr($route, 1) . '`u'; |
|
| 203 | + $pattern = '`'.substr($route, 1).'`u'; |
|
| 204 | 204 | $match = preg_match($pattern, $requestUrl, $params) === 1; |
| 205 | 205 | } elseif (($position = strpos($route, '[')) === false) { |
| 206 | 206 | // No params in url, do string comparison |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | if ($match) { |
| 218 | 218 | |
| 219 | 219 | if ($params) { |
| 220 | - foreach($params as $key => $value) { |
|
| 221 | - if(is_numeric($key)) unset($params[$key]); |
|
| 220 | + foreach ($params as $key => $value) { |
|
| 221 | + if (is_numeric($key)) unset($params[$key]); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { |
| 240 | 240 | |
| 241 | 241 | $matchTypes = $this->matchTypes; |
| 242 | - foreach($matches as $match) { |
|
| 242 | + foreach ($matches as $match) { |
|
| 243 | 243 | list($block, $pre, $type, $param, $optional) = $match; |
| 244 | 244 | |
| 245 | 245 | if (isset($matchTypes[$type])) { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | namespace HexMakina\kadro\Controllers; |
| 13 | 13 | |
| 14 | 14 | use \HexMakina\Crudites\Crudites; |
| 15 | -use \HexMakina\kadro\Auth\{Operator,OperatorInterface,ACL,AccessRefusedException}; |
|
| 15 | +use \HexMakina\kadro\Auth\{Operator, OperatorInterface, ACL, AccessRefusedException}; |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | class OperatorController extends \HexMakina\kadro\Controllers\ORMController |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | parent::edit(); |
| 24 | 24 | |
| 25 | 25 | // do we create? or do we edit someone else ? must be admin |
| 26 | - if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
| 26 | + if (is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) |
|
| 27 | 27 | $this->authorize('group_admin'); |
| 28 | 28 | |
| 29 | 29 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function save() |
| 37 | 37 | { |
| 38 | - if($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
| 38 | + if ($this->operator()->operator_id() !== $this->form_model->operator_id()) |
|
| 39 | 39 | $this->authorize('group_admin'); |
| 40 | 40 | |
| 41 | 41 | parent::save(); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | public function before_save() : array |
| 45 | 45 | { |
| 46 | 46 | //------------------------------------------------------------- PASSWORDS |
| 47 | - if($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
| 47 | + if ($this->form_model->get('password') != $this->form_model->get('password_verification')) |
|
| 48 | 48 | { |
| 49 | 49 | $this->logger()->warning('KADRO_operator_ERR_PASSWORDS_MISMATCH'); |
| 50 | 50 | return $this->edit(); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | public function dashboard() |
| 59 | 59 | { |
| 60 | 60 | $real_operator_class = get_class($this->operator()); |
| 61 | - $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null,'username', 'ASC']])); |
|
| 61 | + $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null, 'username', 'ASC']])); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function destroy() |
@@ -71,10 +71,10 @@ discard block |
||
| 71 | 71 | parent::authorize('group_admin'); |
| 72 | 72 | |
| 73 | 73 | $operator = Operator::one($this->router()->params()); |
| 74 | - if($operator->username() == $this->operator()->username()) |
|
| 74 | + if ($operator->username() == $this->operator()->username()) |
|
| 75 | 75 | throw new AccessRefusedException(); |
| 76 | 76 | |
| 77 | - if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
| 77 | + if (Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true) |
|
| 78 | 78 | { |
| 79 | 79 | $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED'; |
| 80 | 80 | $this->logger()->nice($confirmation_message, [$operator->get('name')]); |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | parent::authorize('group_admin'); |
| 93 | 93 | |
| 94 | 94 | $operator = Operator::one(['username' => $this->router()->params('username')]); |
| 95 | - if($operator->username() == $this->operator()->username()) |
|
| 95 | + if ($operator->username() == $this->operator()->username()) |
|
| 96 | 96 | throw new AccessRefusedException(); |
| 97 | 97 | |
| 98 | 98 | $permission_id = $this->router()->params('permission_id'); |
| 99 | 99 | |
| 100 | 100 | $row_data = ['operator_id' => $operator->operator_id(), 'permission_id' => $permission_id]; |
| 101 | 101 | $row = ACL::table()->restore($row_data); |
| 102 | - if($row->is_new()) |
|
| 102 | + if ($row->is_new()) |
|
| 103 | 103 | { |
| 104 | 104 | $row = ACL::table()->produce($row_data); |
| 105 | 105 | $res = $row->persist(); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | return $this->router()->prehop('traduko'); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function update_file($lang='fra') |
|
| 22 | + public function update_file($lang = 'fra') |
|
| 23 | 23 | { |
| 24 | 24 | $locale_path = $this->box('settings.locale_data_path'); |
| 25 | 25 | self::create_file($locale_path, $lang); |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | $res = Traduko::filter(['lang' => $lang]); |
| 34 | 34 | $assoc = []; |
| 35 | - foreach($res as $id => $trad) |
|
| 35 | + foreach ($res as $id => $trad) |
|
| 36 | 36 | { |
| 37 | - if(!isset($assoc[$trad->kategorio])) |
|
| 37 | + if (!isset($assoc[$trad->kategorio])) |
|
| 38 | 38 | $assoc[$trad->kategorio] = []; |
| 39 | - if(!isset($assoc[$trad->kategorio][$trad->sekcio])) |
|
| 39 | + if (!isset($assoc[$trad->kategorio][$trad->sekcio])) |
|
| 40 | 40 | $assoc[$trad->kategorio][$trad->sekcio] = []; |
| 41 | 41 | |
| 42 | 42 | $assoc[$trad->kategorio][$trad->sekcio][$trad->referenco] = $trad->$lang; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // { |
| 47 | 47 | $path_to_file = $locale_path.'/'.$lang; |
| 48 | 48 | // test directory access & creation |
| 49 | - if(!JSON::exists($path_to_file)) |
|
| 49 | + if (!JSON::exists($path_to_file)) |
|
| 50 | 50 | JSON::make_dir($path_to_file); |
| 51 | 51 | |
| 52 | 52 | $file = new JSON($path_to_file.'/'.self::JSON_FILENAME, 'w+'); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public static function init($locale_path) |
| 62 | 62 | { |
| 63 | 63 | $languages = array_keys(array_slice(Traduko::inspect(Traduko::table_name())->columns(), 4)); |
| 64 | - foreach($languages as $l) |
|
| 64 | + foreach ($languages as $l) |
|
| 65 | 65 | self::create_file($locale_path, $l); |
| 66 | 66 | |
| 67 | 67 | return $languages; |