Browse files

Documentation.

  • Loading branch information...
1 parent e089bc1 commit 6471298a36dd3654f1930f184f7963ecbfaaf17a @parvas committed May 30, 2011
Showing with 97 additions and 96 deletions.
  1. +20 −19 system/classes/File.php
  2. +35 −35 system/classes/Filesystem.php
  3. +42 −42 system/classes/Image.php
View
39 system/classes/File.php
@@ -1,6 +1,7 @@
<?php if (!defined('SYSTEM')) exit('No direct script access allowed');
class File {
+
/**
* @access protected
* @var array Stores validation errors
@@ -362,32 +363,32 @@ protected function _pre_validate()
switch ($this->_file['error'])
{
case 0:
- break;
+ break;
case 1:
- static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_filesize'), $this->_file['name']);
- break;
+ static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_filesize'), $this->_file['name']);
+ break;
case 2:
- static::$_errors[$this->_file['name']] = $general_error;
- Log::write('error', "File '{$this->_file['name']}' exceeds the maximum size allowed by the submission form");
- break;
+ static::$_errors[$this->_file['name']] = $general_error;
+ Log::write('error', "File '{$this->_file['name']}' exceeds the maximum size allowed by the submission form");
+ break;
case 3:
- static::$_errors[$this->_file['name']] = $general_error;
- Log::write('error', "File '{$this->_file['name']}' was only partially uploaded");
- break;
+ static::$_errors[$this->_file['name']] = $general_error;
+ Log::write('error', "File '{$this->_file['name']}' was only partially uploaded");
+ break;
case 4:
- break;
+ break;
case 6:
- static::$_errors[$this->_file['name']] = $general_error;
- Log::write('error', 'The temporary folder is missing');
- break;
+ static::$_errors[$this->_file['name']] = $general_error;
+ Log::write('error', 'The temporary folder is missing');
+ break;
case 7:
- static::$_errors[$this->_file['name']] = $general_error;
- Log::write('error', "File '{$this->_file['name']}' could not be written to disk");
- break;
+ static::$_errors[$this->_file['name']] = $general_error;
+ Log::write('error', "File '{$this->_file['name']}' could not be written to disk");
+ break;
case 8:
- static::$_errors[$this->_file['name']] = $general_error;
- Log::write('error', "File '{$this->_file['name']}' was stopped by extension");
- break;
+ static::$_errors[$this->_file['name']] = $general_error;
+ Log::write('error', "File '{$this->_file['name']}' was stopped by extension");
+ break;
}
}
View
70 system/classes/Filesystem.php
@@ -4,71 +4,71 @@ class Filesystem {
/**
* Renames a file in filesystem.
- *
+ *
* @access public
* @param string $old Path to old file name.
* @param string $new Path to new file name.
* @return boolean True on successful rename, false otherwise.
* @uses Filesystem::file_check Writes into log file in case file is absent (or wrong path passed).
- * @static
+ * @static
*/
public static function rename_file($old, $new)
- {
+ {
if (static::file_check($file) === false)
{
return false;
}
- return rename($old, $new);
- }
-
+ return rename($old, $new);
+ }
+
/**
* Renames a folder in filesystem.
- *
+ *
* @access public
* @param string $old Path to old folder name.
* @param string $new Path to new folder name.
* @return boolean True on successful rename, false otherwise.
* @uses Filesystem::dir_check Writes into log file in case folder is absent (or wrong path passed).
- * @static
+ * @static
*/
- public static function rename_folder($old, $new)
- {
+ public static function rename_folder($old, $new)
+ {
if (static::dir_check($old) === false)
{
return false;
}
return rename($old, $new);
- }
-
+ }
+
/**
* Deletes a file from filesystem.
- *
+ *
* @access public
* @param string $file Path of file to be deleted.
* @return boolean True on successful delete, false otherwise.
* @uses Filesystem::file_check Writes into log file in case file is absent (or wrong path passed).
- * @static
+ * @static
*/
- public static function delete_file($file)
- {
+ public static function delete_file($file)
+ {
if (static::file_check($file) === false)
{
return false;
}
return unlink($file);
- }
+ }
/**
* Deletes a folder from filesystem.
- *
+ *
* @access public
* @param string $dir Path of folder to be deleted.
* @return boolean True on successful delete, false otherwise.
* @uses Filesystem::dir_check Writes into log file in case file is absent (or wrong path passed).
- * @static
+ * @static
*/
public static function delete_folder($dir)
{
@@ -88,35 +88,35 @@ public static function delete_folder($dir)
$objects = scandir($dir);
// now scan contents one by one
- foreach ($objects as $object)
+ foreach ($objects as $object)
{
// skip current/parent dir objects
- if ($object != '.' && $object != '..')
+ if ($object != '.' && $object != '..')
{
- if (is_dir($path . $object))
+ if (is_dir($path . $object))
{
// recurse if content is directory
- static::_delete_folder($object);
- }
- else
- {
+ static::_delete_folder($object);
+ }
+ else
+ {
// just delete if content is file
unlink($path . $object);
}
}
}
-
+
// by now, directory is empty, delete!
return rmdir($dir);
}
/**
* Renames a file in filesystem.
- *
+ *
* @access public
* @param string $old_path Old file path.
* @param string $new_path New file path.
- * @return boolean True on successful check, false otherwise.
+ * @return boolean True on successful check, false otherwise.
* @uses Filesystem::rename_file Renames file.
* @static
*/
@@ -127,11 +127,11 @@ public static function move_file($old_path, $new_path)
/**
* Renames a folder in filesystem.
- *
+ *
* @access public
* @param string $old_path Old folder path.
* @param string $new_path New folder path.
- * @return boolean True on successful check, false otherwise.
+ * @return boolean True on successful check, false otherwise.
* @uses Filesystem::rename_folder Renames folder.
* @static
*/
@@ -142,10 +142,10 @@ public static function move_folder($old_path, $new_path)
/**
* Checks if directory exists and is writeable.
- *
+ *
* @access public
* @param string $dir Directory path to be checked.
- * @return boolean True on successful check, false otherwise.
+ * @return boolean True on successful check, false otherwise.
* @uses Log::write Writes in log file if directory is absent or not writeable.
* @static
*/
@@ -167,10 +167,10 @@ public static function dir_check($dir)
/**
* Checks if file exists and is writeable.
- *
+ *
* @access public
* @param string $file Directory path to be checked.
- * @return boolean True on successful check, false otherwise.
+ * @return boolean True on successful check, false otherwise.
* @uses Log::write Writes in log file if file is absent or not writeable.
* @static
*/
View
84 system/classes/Image.php
@@ -1,44 +1,44 @@
<?php if (!defined('SYSTEM')) exit('No direct script access allowed');
class Image extends File {
-
- protected $_max_width;
- protected $_max_height;
-
- public static function factory($field, $remove_whitespace = false)
- {
+
+ protected $_max_width;
+ protected $_max_height;
+
+ public static function factory($field, $remove_whitespace = false)
+ {
return new Image($field, $remove_whitespace);
- }
-
- protected function __construct($field, $remove_whitespace)
- {
- parent::__construct($field, $remove_whitespace);
- }
-
- public function set_max_dimensions($width, $height)
- {
- $this->_max_width = $width;
- $this->_max_height = $height;
+ }
+
+ protected function __construct($field, $remove_whitespace)
+ {
+ parent::__construct($field, $remove_whitespace);
+ }
+
+ public function set_max_dimensions($width, $height)
+ {
+ $this->_max_width = $width;
+ $this->_max_height = $height;
- return $this;
- }
-
- public function set_max_width($width)
- {
- $this->_max_width = $width;
+ return $this;
+ }
+
+ public function set_max_width($width)
+ {
+ $this->_max_width = $width;
- return $this;
- }
-
- public function set_max_height($height)
- {
- $this->_max_height = $height;
+ return $this;
+ }
+
+ public function set_max_height($height)
+ {
+ $this->_max_height = $height;
- return $this;
- }
+ return $this;
+ }
- public function validate()
- {
+ public function validate()
+ {
if ($this->_pre_validate() === true)
{
return true;
@@ -51,24 +51,24 @@ public function validate()
$this->_validate_size();
$this->_validate_types();
-
+
/*
- * $atts[0] -> width, $atts[1] -> height
- */
- $atts = @getimagesize($this->_file['tmp_name']);
+ * $atts[0] -> width, $atts[1] -> height
+ */
+ $atts = @getimagesize($this->_file['tmp_name']);
- // check width
+ // check width
if (isset($this->_max_width) && $atts[0] > $this->_max_width)
{
static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_width'), $this->_file['name']);
}
-
- // check height
+
+ // check height
if (isset($this->_max_height) && $atts[1] > $this->_max_height)
{
static::$_errors[$this->_file['name']] = sprintf(I18n::instance()->line('invalid_height'), $this->_file['name']);
}
-
+
return count(static::$_errors) > 0 ? false : true;
- }
+ }
}

0 comments on commit 6471298

Please sign in to comment.