| Conditions | 4 |
| Paths | 8 |
| Total Lines | 170 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | function get_config($getprivates = false) |
||
| 24 | { |
||
| 25 | // We set up two different settings array, so that we can have settings |
||
| 26 | // that won't be shown to the public. |
||
| 27 | $Private = []; |
||
| 28 | $Public = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * For demo purposes, we can lie to the frontend and pretend to have user |
||
| 32 | * storage. Since we don't have a password mechanism, this simulation will |
||
| 33 | * accept any password. |
||
| 34 | */ |
||
| 35 | $Private['simulate_user_auth'] = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The capabilities array contains directives about what major options to |
||
| 39 | * allow or disallow. |
||
| 40 | */ |
||
| 41 | $Public['capabilities'] = [ |
||
| 42 | // Allow directory operations (e.g. rename, create, delete directories) |
||
| 43 | 'directory_operations' => true, |
||
| 44 | // Allow file operations (e.g. copy, rename, delete files) |
||
| 45 | 'file_operations' => true, |
||
| 46 | // Allow image operations (e.g. scale, rotate, convert images) |
||
| 47 | 'image_operations' => true, |
||
| 48 | // Allow file uploads |
||
| 49 | 'upload_operations' => true, |
||
| 50 | // Stored files have a published URL |
||
| 51 | 'shared_publish' => true, |
||
| 52 | // By default, if the user is authenticated, we enable user storage. |
||
| 53 | // Set to false to disable. |
||
| 54 | 'user_storage' => !empty($_SERVER['PHP_AUTH_USER']) || $Private['simulate_user_auth'] |
||
| 55 | ]; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Directory exposed to user operations. Be sure that the web server has |
||
| 59 | * read and write access to this directory. |
||
| 60 | */ |
||
| 61 | $Private['storage_dir'] = 'demo_images'; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The URL that the storage directory is exposed as. By default, we try |
||
| 65 | * and guess based on the URL used to access this page. Also, since we |
||
| 66 | * allow user upload, this directory should not be executable by the |
||
| 67 | * server. A sample .htaccess file is included in demo_images. |
||
| 68 | */ |
||
| 69 | $Private['storage_url'] = str_replace( |
||
| 70 | ['backend.php', 'manager.php'], |
||
| 71 | '', |
||
| 72 | $_SERVER['PHP_SELF'] |
||
| 73 | ) . $Private['storage_dir']; |
||
| 74 | |||
| 75 | /* |
||
| 76 | Possible values: true, false |
||
| 77 | |||
| 78 | TRUE - If PHP on the web server is in safe mode, set this to true. |
||
| 79 | SAFE MODE restrictions: directory creation will not be possible, |
||
| 80 | only the GD library can be used, other libraries require |
||
| 81 | Safe Mode to be off. |
||
| 82 | |||
| 83 | FALSE - Set to false if PHP on the web server is not in safe mode. |
||
| 84 | */ |
||
| 85 | $Private['safe_mode'] = ini_get('safe_mode'); |
||
| 86 | |||
| 87 | /** |
||
| 88 | * If PHP Safe Mode is on than only the GD image library will function, so |
||
| 89 | * we force the default |
||
| 90 | */ |
||
| 91 | if ($Private['safe_mode']) { |
||
| 92 | @define('IMAGE_CLASS', 'GD'); |
||
|
|
|||
| 93 | } else { |
||
| 94 | /* |
||
| 95 | Possible values: 'GD', 'IM', or 'NetPBM' |
||
| 96 | |||
| 97 | The image manipulation library to use, either GD or ImageMagick or NetPBM. |
||
| 98 | */ |
||
| 99 | @define('IMAGE_CLASS', 'GD'); |
||
| 100 | |||
| 101 | /* |
||
| 102 | After defining which library to use, if it is NetPBM or IM, you need to |
||
| 103 | specify where the binary for the selected library are. And of course |
||
| 104 | your server and PHP must be able to execute them (i.e. safe mode is OFF). |
||
| 105 | GD does not require the following definition. |
||
| 106 | */ |
||
| 107 | @define('IMAGE_TRANSFORM_LIB_PATH', '/usr/bin/'); |
||
| 108 | } |
||
| 109 | |||
| 110 | /* |
||
| 111 | The prefix for thumbnail files, something like .thumb will do. The |
||
| 112 | thumbnails files will be named as "prefix_imagefile.ext", that is, |
||
| 113 | prefix + orginal filename. |
||
| 114 | */ |
||
| 115 | $Private['thumbnail_prefix'] = 't_'; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The thumbnail array groups all of the configuration related to thumbnail |
||
| 119 | * operations. |
||
| 120 | */ |
||
| 121 | $Private['thumbnails'] = [ |
||
| 122 | // The prefix to apply to all created thumbnails. |
||
| 123 | 'prefix' => 't_', |
||
| 124 | // A subdirectory to keep thumbnails in. If this is empty, thumbnails |
||
| 125 | // will be stored alongside the files. |
||
| 126 | 'directory' => '', |
||
| 127 | // Whether or not to filter thumbnails from the directory listing. |
||
| 128 | 'filter' => true, |
||
| 129 | // Filetypes which we restrict thumbnail operations to. |
||
| 130 | 'filetypes' => ['jpg', 'gif', 'png', 'bmp'], |
||
| 131 | // What pixel sizes to save the thumbnails as. |
||
| 132 | 'width' => 84, |
||
| 133 | 'height' => 84 |
||
| 134 | ]; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Resized prefix |
||
| 138 | * |
||
| 139 | * The prefix for resized files, something like .resized will do. The |
||
| 140 | * resized files will be named <prefix>_<width>x<height>_<original> |
||
| 141 | * resized files are created when one changes the dimensions of an image |
||
| 142 | * in the image manager selection dialog - the image is scaled when the |
||
| 143 | * user clicks the ok button. |
||
| 144 | */ |
||
| 145 | |||
| 146 | $Private['resized_prefix'] = '.resized'; |
||
| 147 | |||
| 148 | // ------------------------------------------------------------------------- |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Resized Directory |
||
| 152 | * |
||
| 153 | * Resized images may also be stored in a directory, except in safe mode. |
||
| 154 | */ |
||
| 155 | |||
| 156 | $Private['resized_dir'] = ''; |
||
| 157 | |||
| 158 | /* Maximum upload file size |
||
| 159 | |||
| 160 | Possible values: number, "max" |
||
| 161 | |||
| 162 | number - maximum size in Kilobytes. |
||
| 163 | |||
| 164 | "max" - the maximum allowed by the server (the value is retrieved from the server configuration). |
||
| 165 | */ |
||
| 166 | $Private['max_filesize_kb_image'] = 200; |
||
| 167 | |||
| 168 | $Private['max_filesize_kb_link'] = 5000; |
||
| 169 | |||
| 170 | /* Maximum upload folder size in Megabytes. Use 0 to disable limit */ |
||
| 171 | $Private['max_foldersize_mb'] = 0; |
||
| 172 | |||
| 173 | /* |
||
| 174 | Allowed extensions that can be shown and allowed to upload. |
||
| 175 | Available icons are for "doc,fla,gif,gz,html,jpg,js,mov,pdf,php,png,ppt,rar,txt,xls,zip" |
||
| 176 | -Changed by AFRU. |
||
| 177 | */ |
||
| 178 | |||
| 179 | $Private['allowed_image_extensions'] = ['jpg', 'gif', 'png', 'bmp']; |
||
| 180 | $Private['allowed_link_extensions'] = ['jpg', 'gif', 'js', 'php', 'pdf', 'zip', 'txt', 'psd', 'png', 'html', 'swf', 'xml', 'xls', 'doc']; |
||
| 181 | |||
| 182 | /* |
||
| 183 | Image Editor temporary filename prefix. |
||
| 184 | */ |
||
| 185 | $Private['tmp_prefix'] = '.editor_'; |
||
| 186 | |||
| 187 | // Config variables are finished, this returns our data to the caller. |
||
| 188 | if ($getprivates) { |
||
| 189 | return $Public + $Private; |
||
| 190 | } |
||
| 191 | |||
| 192 | return $Public; |
||
| 193 | } |
||
| 196 |
If you suppress an error, we recommend checking for the error condition explicitly: