Skip to content
This repository
Browse code

Documentation.

  • Loading branch information...
commit 6471298a36dd3654f1930f184f7963ecbfaaf17a 1 parent e089bc1
Paraschos Vasiliadis authored
39 system/classes/File.php
... ... @@ -1,6 +1,7 @@
1 1 <?php if (!defined('SYSTEM')) exit('No direct script access allowed');
2 2
3 3 class File {
  4 +
4 5 /**
5 6 * @access protected
6 7 * @var array Stores validation errors
@@ -362,32 +363,32 @@ protected function _pre_validate()
362 363 switch ($this->_file['error'])
363 364 {
364 365 case 0:
365   - break;
  366 + break;
366 367 case 1:
367   - static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_filesize'), $this->_file['name']);
368   - break;
  368 + static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_filesize'), $this->_file['name']);
  369 + break;
369 370 case 2:
370   - static::$_errors[$this->_file['name']] = $general_error;
371   - Log::write('error', "File '{$this->_file['name']}' exceeds the maximum size allowed by the submission form");
372   - break;
  371 + static::$_errors[$this->_file['name']] = $general_error;
  372 + Log::write('error', "File '{$this->_file['name']}' exceeds the maximum size allowed by the submission form");
  373 + break;
373 374 case 3:
374   - static::$_errors[$this->_file['name']] = $general_error;
375   - Log::write('error', "File '{$this->_file['name']}' was only partially uploaded");
376   - break;
  375 + static::$_errors[$this->_file['name']] = $general_error;
  376 + Log::write('error', "File '{$this->_file['name']}' was only partially uploaded");
  377 + break;
377 378 case 4:
378   - break;
  379 + break;
379 380 case 6:
380   - static::$_errors[$this->_file['name']] = $general_error;
381   - Log::write('error', 'The temporary folder is missing');
382   - break;
  381 + static::$_errors[$this->_file['name']] = $general_error;
  382 + Log::write('error', 'The temporary folder is missing');
  383 + break;
383 384 case 7:
384   - static::$_errors[$this->_file['name']] = $general_error;
385   - Log::write('error', "File '{$this->_file['name']}' could not be written to disk");
386   - break;
  385 + static::$_errors[$this->_file['name']] = $general_error;
  386 + Log::write('error', "File '{$this->_file['name']}' could not be written to disk");
  387 + break;
387 388 case 8:
388   - static::$_errors[$this->_file['name']] = $general_error;
389   - Log::write('error', "File '{$this->_file['name']}' was stopped by extension");
390   - break;
  389 + static::$_errors[$this->_file['name']] = $general_error;
  390 + Log::write('error', "File '{$this->_file['name']}' was stopped by extension");
  391 + break;
391 392 }
392 393 }
393 394
70 system/classes/Filesystem.php
@@ -4,71 +4,71 @@ class Filesystem {
4 4
5 5 /**
6 6 * Renames a file in filesystem.
7   - *
  7 + *
8 8 * @access public
9 9 * @param string $old Path to old file name.
10 10 * @param string $new Path to new file name.
11 11 * @return boolean True on successful rename, false otherwise.
12 12 * @uses Filesystem::file_check Writes into log file in case file is absent (or wrong path passed).
13   - * @static
  13 + * @static
14 14 */
15 15 public static function rename_file($old, $new)
16   - {
  16 + {
17 17 if (static::file_check($file) === false)
18 18 {
19 19 return false;
20 20 }
21 21
22   - return rename($old, $new);
23   - }
24   -
  22 + return rename($old, $new);
  23 + }
  24 +
25 25 /**
26 26 * Renames a folder in filesystem.
27   - *
  27 + *
28 28 * @access public
29 29 * @param string $old Path to old folder name.
30 30 * @param string $new Path to new folder name.
31 31 * @return boolean True on successful rename, false otherwise.
32 32 * @uses Filesystem::dir_check Writes into log file in case folder is absent (or wrong path passed).
33   - * @static
  33 + * @static
34 34 */
35   - public static function rename_folder($old, $new)
36   - {
  35 + public static function rename_folder($old, $new)
  36 + {
37 37 if (static::dir_check($old) === false)
38 38 {
39 39 return false;
40 40 }
41 41
42 42 return rename($old, $new);
43   - }
44   -
  43 + }
  44 +
45 45 /**
46 46 * Deletes a file from filesystem.
47   - *
  47 + *
48 48 * @access public
49 49 * @param string $file Path of file to be deleted.
50 50 * @return boolean True on successful delete, false otherwise.
51 51 * @uses Filesystem::file_check Writes into log file in case file is absent (or wrong path passed).
52   - * @static
  52 + * @static
53 53 */
54   - public static function delete_file($file)
55   - {
  54 + public static function delete_file($file)
  55 + {
56 56 if (static::file_check($file) === false)
57 57 {
58 58 return false;
59 59 }
60 60
61 61 return unlink($file);
62   - }
  62 + }
63 63
64 64 /**
65 65 * Deletes a folder from filesystem.
66   - *
  66 + *
67 67 * @access public
68 68 * @param string $dir Path of folder to be deleted.
69 69 * @return boolean True on successful delete, false otherwise.
70 70 * @uses Filesystem::dir_check Writes into log file in case file is absent (or wrong path passed).
71   - * @static
  71 + * @static
72 72 */
73 73 public static function delete_folder($dir)
74 74 {
@@ -88,35 +88,35 @@ public static function delete_folder($dir)
88 88 $objects = scandir($dir);
89 89
90 90 // now scan contents one by one
91   - foreach ($objects as $object)
  91 + foreach ($objects as $object)
92 92 {
93 93 // skip current/parent dir objects
94   - if ($object != '.' && $object != '..')
  94 + if ($object != '.' && $object != '..')
95 95 {
96   - if (is_dir($path . $object))
  96 + if (is_dir($path . $object))
97 97 {
98 98 // recurse if content is directory
99   - static::_delete_folder($object);
100   - }
101   - else
102   - {
  99 + static::_delete_folder($object);
  100 + }
  101 + else
  102 + {
103 103 // just delete if content is file
104 104 unlink($path . $object);
105 105 }
106 106 }
107 107 }
108   -
  108 +
109 109 // by now, directory is empty, delete!
110 110 return rmdir($dir);
111 111 }
112 112
113 113 /**
114 114 * Renames a file in filesystem.
115   - *
  115 + *
116 116 * @access public
117 117 * @param string $old_path Old file path.
118 118 * @param string $new_path New file path.
119   - * @return boolean True on successful check, false otherwise.
  119 + * @return boolean True on successful check, false otherwise.
120 120 * @uses Filesystem::rename_file Renames file.
121 121 * @static
122 122 */
@@ -127,11 +127,11 @@ public static function move_file($old_path, $new_path)
127 127
128 128 /**
129 129 * Renames a folder in filesystem.
130   - *
  130 + *
131 131 * @access public
132 132 * @param string $old_path Old folder path.
133 133 * @param string $new_path New folder path.
134   - * @return boolean True on successful check, false otherwise.
  134 + * @return boolean True on successful check, false otherwise.
135 135 * @uses Filesystem::rename_folder Renames folder.
136 136 * @static
137 137 */
@@ -142,10 +142,10 @@ public static function move_folder($old_path, $new_path)
142 142
143 143 /**
144 144 * Checks if directory exists and is writeable.
145   - *
  145 + *
146 146 * @access public
147 147 * @param string $dir Directory path to be checked.
148   - * @return boolean True on successful check, false otherwise.
  148 + * @return boolean True on successful check, false otherwise.
149 149 * @uses Log::write Writes in log file if directory is absent or not writeable.
150 150 * @static
151 151 */
@@ -167,10 +167,10 @@ public static function dir_check($dir)
167 167
168 168 /**
169 169 * Checks if file exists and is writeable.
170   - *
  170 + *
171 171 * @access public
172 172 * @param string $file Directory path to be checked.
173   - * @return boolean True on successful check, false otherwise.
  173 + * @return boolean True on successful check, false otherwise.
174 174 * @uses Log::write Writes in log file if file is absent or not writeable.
175 175 * @static
176 176 */
84 system/classes/Image.php
... ... @@ -1,44 +1,44 @@
1 1 <?php if (!defined('SYSTEM')) exit('No direct script access allowed');
2 2
3 3 class Image extends File {
4   -
5   - protected $_max_width;
6   - protected $_max_height;
7   -
8   - public static function factory($field, $remove_whitespace = false)
9   - {
  4 +
  5 + protected $_max_width;
  6 + protected $_max_height;
  7 +
  8 + public static function factory($field, $remove_whitespace = false)
  9 + {
10 10 return new Image($field, $remove_whitespace);
11   - }
12   -
13   - protected function __construct($field, $remove_whitespace)
14   - {
15   - parent::__construct($field, $remove_whitespace);
16   - }
17   -
18   - public function set_max_dimensions($width, $height)
19   - {
20   - $this->_max_width = $width;
21   - $this->_max_height = $height;
  11 + }
  12 +
  13 + protected function __construct($field, $remove_whitespace)
  14 + {
  15 + parent::__construct($field, $remove_whitespace);
  16 + }
  17 +
  18 + public function set_max_dimensions($width, $height)
  19 + {
  20 + $this->_max_width = $width;
  21 + $this->_max_height = $height;
22 22
23   - return $this;
24   - }
25   -
26   - public function set_max_width($width)
27   - {
28   - $this->_max_width = $width;
  23 + return $this;
  24 + }
  25 +
  26 + public function set_max_width($width)
  27 + {
  28 + $this->_max_width = $width;
29 29
30   - return $this;
31   - }
32   -
33   - public function set_max_height($height)
34   - {
35   - $this->_max_height = $height;
  30 + return $this;
  31 + }
  32 +
  33 + public function set_max_height($height)
  34 + {
  35 + $this->_max_height = $height;
36 36
37   - return $this;
38   - }
  37 + return $this;
  38 + }
39 39
40   - public function validate()
41   - {
  40 + public function validate()
  41 + {
42 42 if ($this->_pre_validate() === true)
43 43 {
44 44 return true;
@@ -51,24 +51,24 @@ public function validate()
51 51
52 52 $this->_validate_size();
53 53 $this->_validate_types();
54   -
  54 +
55 55 /*
56   - * $atts[0] -> width, $atts[1] -> height
57   - */
58   - $atts = @getimagesize($this->_file['tmp_name']);
  56 + * $atts[0] -> width, $atts[1] -> height
  57 + */
  58 + $atts = @getimagesize($this->_file['tmp_name']);
59 59
60   - // check width
  60 + // check width
61 61 if (isset($this->_max_width) && $atts[0] > $this->_max_width)
62 62 {
63 63 static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_width'), $this->_file['name']);
64 64 }
65   -
66   - // check height
  65 +
  66 + // check height
67 67 if (isset($this->_max_height) && $atts[1] > $this->_max_height)
68 68 {
69 69 static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_height'), $this->_file['name']);
70 70 }
71   -
  71 +
72 72 return count(static::$_errors) > 0 ? false : true;
73   - }
  73 + }
74 74 }

0 comments on commit 6471298

Please sign in to comment.
Something went wrong with that request. Please try again.