| Total Complexity | 103 |
| Total Lines | 595 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like XoopsMediaUploader often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XoopsMediaUploader, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 72 | class XoopsMediaUploader |
||
| 73 | { |
||
| 74 | /** |
||
| 75 | * Flag indicating if unrecognized mimetypes should be allowed (use with precaution ! may lead to security issues ) |
||
| 76 | */ |
||
| 77 | |||
| 78 | public $allowUnknownTypes = false; |
||
| 79 | public $mediaName; |
||
| 80 | public $mediaType; |
||
| 81 | public $mediaSize; |
||
| 82 | public $mediaTmpName; |
||
| 83 | public $mediaError; |
||
| 84 | public $mediaRealType = ''; |
||
| 85 | public $uploadDir = ''; |
||
| 86 | public $allowedMimeTypes = array(); |
||
| 87 | public $deniedMimeTypes = array( |
||
| 88 | 'application/x-httpd-php'); |
||
| 89 | public $maxFileSize = 0; |
||
| 90 | public $maxWidth; |
||
| 91 | public $maxHeight; |
||
| 92 | public $targetFileName; |
||
| 93 | public $prefix; |
||
| 94 | public $errors = array(); |
||
| 95 | public $savedDestination; |
||
| 96 | public $savedFileName; |
||
| 97 | public $extensionToMime = array(); |
||
| 98 | public $checkImageType = true; |
||
| 99 | public $extensionsToBeSanitized = array( |
||
| 100 | 'php', |
||
| 101 | 'phtml', |
||
| 102 | 'phtm', |
||
| 103 | 'php3', |
||
| 104 | 'php4', |
||
| 105 | 'cgi', |
||
| 106 | 'pl', |
||
| 107 | 'asp', |
||
| 108 | 'php5', |
||
| 109 | 'php7', |
||
| 110 | ); |
||
| 111 | // extensions needed image check (anti-IE Content-Type XSS) |
||
| 112 | public $imageExtensions = array( |
||
| 113 | 1 => 'gif', |
||
| 114 | 2 => 'jpg', |
||
| 115 | 3 => 'png', |
||
| 116 | 4 => 'swf', |
||
| 117 | 5 => 'psd', |
||
| 118 | 6 => 'bmp', |
||
| 119 | 7 => 'tif', |
||
| 120 | 8 => 'tif', |
||
| 121 | 9 => 'jpc', |
||
| 122 | 10 => 'jp2', |
||
| 123 | 11 => 'jpx', |
||
| 124 | 12 => 'jb2', |
||
| 125 | 13 => 'swc', |
||
| 126 | 14 => 'iff', |
||
| 127 | 15 => 'wbmp', |
||
| 128 | 16 => 'xbm'); |
||
| 129 | public $randomFilename = false; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Constructor |
||
| 133 | * |
||
| 134 | * @param string $uploadDir |
||
| 135 | * @param array $allowedMimeTypes |
||
| 136 | * @param int $maxFileSize |
||
| 137 | * @param int $maxWidth |
||
| 138 | * @param int $maxHeight |
||
| 139 | * @param bool $randomFilename |
||
| 140 | */ |
||
| 141 | |||
| 142 | public function __construct($uploadDir, $allowedMimeTypes, $maxFileSize = 0, $maxWidth = null, $maxHeight = null, $randomFilename = false) |
||
| 143 | { |
||
| 144 | $this->extensionToMime = include $GLOBALS['xoops']->path('include/mimetypes.inc.php'); |
||
| 145 | if (!is_array($this->extensionToMime)) { |
||
| 146 | $this->extensionToMime = array(); |
||
| 147 | |||
| 148 | return false; |
||
| 149 | } |
||
| 150 | if (is_array($allowedMimeTypes)) { |
||
|
|
|||
| 151 | $this->allowedMimeTypes =& $allowedMimeTypes; |
||
| 152 | } |
||
| 153 | $this->uploadDir = $uploadDir; |
||
| 154 | |||
| 155 | $maxUploadInBytes = $this->return_bytes(ini_get('upload_max_filesize')); |
||
| 156 | $maxPostInBytes = $this->return_bytes(ini_get('post_max_size')); |
||
| 157 | $memoryLimitInBytes = $this->return_bytes(ini_get('memory_limit')); |
||
| 158 | if ((int)$maxFileSize > 0) { |
||
| 159 | $maxFileSizeInBytes = $this->return_bytes($maxFileSize); |
||
| 160 | $newMaxFileSize = min($maxFileSizeInBytes, $maxUploadInBytes, $maxPostInBytes, $memoryLimitInBytes); |
||
| 161 | } else { |
||
| 162 | $newMaxFileSize = min($maxUploadInBytes, $maxPostInBytes, $memoryLimitInBytes); |
||
| 163 | } |
||
| 164 | $this->maxFileSize = $newMaxFileSize; |
||
| 165 | |||
| 166 | if (isset($maxWidth)) { |
||
| 167 | $this->maxWidth = (int)$maxWidth; |
||
| 168 | } |
||
| 169 | if (isset($maxHeight)) { |
||
| 170 | $this->maxHeight = (int)$maxHeight; |
||
| 171 | } |
||
| 172 | if (isset($randomFilename)) { |
||
| 173 | $this->randomFilename = $randomFilename; |
||
| 174 | } |
||
| 175 | if (!include_once $GLOBALS['xoops']->path('language/' . $GLOBALS['xoopsConfig']['language'] . '/uploader.php')) { |
||
| 176 | include_once $GLOBALS['xoops']->path('language/english/uploader.php'); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * converts memory/file sizes as defined in php.ini to bytes |
||
| 182 | * |
||
| 183 | * @param $size_str |
||
| 184 | * |
||
| 185 | * @return int |
||
| 186 | */ |
||
| 187 | public function return_bytes($size_str) |
||
| 188 | { |
||
| 189 | switch (substr($size_str, -1)) { |
||
| 190 | case 'K': |
||
| 191 | case 'k': |
||
| 192 | return (int)$size_str * 1024; |
||
| 193 | case 'M': |
||
| 194 | case 'm': |
||
| 195 | return (int)$size_str * 1048576; |
||
| 196 | case 'G': |
||
| 197 | case 'g': |
||
| 198 | return (int)$size_str * 1073741824; |
||
| 199 | default: |
||
| 200 | return $size_str; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Count the uploaded files (in case of miltiple upload) |
||
| 206 | * |
||
| 207 | * @param string $media_name Name of the file field |
||
| 208 | * @return int |
||
| 209 | */ |
||
| 210 | public function countMedia($media_name) { |
||
| 211 | if (!isset($_FILES[$media_name])) { |
||
| 212 | $this->setErrors(_ER_UP_FILENOTFOUND); |
||
| 213 | return false; |
||
| 214 | } |
||
| 215 | return count($_FILES[$media_name]['name']); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Fetch the uploaded file |
||
| 220 | * |
||
| 221 | * @param string $media_name Name of the file field |
||
| 222 | * @param int $index Index of the file (if more than one uploaded under that name) |
||
| 223 | * @return bool |
||
| 224 | */ |
||
| 225 | public function fetchMedia($media_name, $index = null) |
||
| 226 | { |
||
| 227 | if (empty($this->extensionToMime)) { |
||
| 228 | $this->setErrors(_ER_UP_MIMETYPELOAD); |
||
| 229 | |||
| 230 | return false; |
||
| 231 | } |
||
| 232 | if (!isset($_FILES[$media_name])) { |
||
| 233 | $this->setErrors(_ER_UP_FILENOTFOUND); |
||
| 234 | |||
| 235 | return false; |
||
| 236 | } elseif (is_array($_FILES[$media_name]['name']) && isset($index)) { |
||
| 237 | $index = (int)$index; |
||
| 238 | $this->mediaName = get_magic_quotes_gpc() ? stripslashes($_FILES[$media_name]['name'][$index]) : $_FILES[$media_name]['name'][$index]; |
||
| 239 | if ($this->randomFilename) { |
||
| 240 | $unique = uniqid(); |
||
| 241 | $this->mediaName = '' . $unique . '--' . $this->mediaName; |
||
| 242 | } |
||
| 243 | $this->mediaType = $_FILES[$media_name]['type'][$index]; |
||
| 244 | $this->mediaSize = $_FILES[$media_name]['size'][$index]; |
||
| 245 | $this->mediaTmpName = $_FILES[$media_name]['tmp_name'][$index]; |
||
| 246 | $this->mediaError = !empty($_FILES[$media_name]['error'][$index]) ? $_FILES[$media_name]['error'][$index] : 0; |
||
| 247 | } elseif (is_array($_FILES[$media_name]['name']) && !isset($index)) { |
||
| 248 | $this->setErrors(_ER_UP_INDEXNOTSET); |
||
| 249 | |||
| 250 | return false; |
||
| 251 | } else { |
||
| 252 | $media_name =& $_FILES[$media_name]; |
||
| 253 | $this->mediaName = get_magic_quotes_gpc() ? stripslashes($media_name['name']) : $media_name['name']; |
||
| 254 | if ($this->randomFilename) { |
||
| 255 | $unique = uniqid(); |
||
| 256 | $this->mediaName = '' . $unique . '--' . $this->mediaName; |
||
| 257 | } |
||
| 258 | $this->mediaType = $media_name['type']; |
||
| 259 | $this->mediaSize = $media_name['size']; |
||
| 260 | $this->mediaTmpName = $media_name['tmp_name']; |
||
| 261 | $this->mediaError = !empty($media_name['error']) ? $media_name['error'] : 0; |
||
| 262 | } |
||
| 263 | |||
| 264 | if (($ext = strrpos($this->mediaName, '.')) !== false) { |
||
| 265 | $ext = strtolower(substr($this->mediaName, $ext + 1)); |
||
| 266 | if (isset($this->extensionToMime[$ext])) { |
||
| 267 | $this->mediaRealType = $this->extensionToMime[$ext]; |
||
| 268 | } |
||
| 269 | } |
||
| 270 | $this->errors = array(); |
||
| 271 | if ($this->mediaError > 0) { |
||
| 272 | switch($this->mediaError){ |
||
| 273 | case UPLOAD_ERR_INI_SIZE: |
||
| 274 | $this->setErrors(_ER_UP_INISIZE); |
||
| 275 | return false; |
||
| 276 | break; |
||
| 277 | case UPLOAD_ERR_FORM_SIZE: |
||
| 278 | $this->setErrors(_ER_UP_FORMSIZE); |
||
| 279 | return false; |
||
| 280 | break; |
||
| 281 | case UPLOAD_ERR_PARTIAL: |
||
| 282 | $this->setErrors(_ER_UP_PARTIAL); |
||
| 283 | return false; |
||
| 284 | break; |
||
| 285 | case UPLOAD_ERR_NO_FILE: |
||
| 286 | $this->setErrors(_ER_UP_NOFILE); |
||
| 287 | return false; |
||
| 288 | break; |
||
| 289 | case UPLOAD_ERR_NO_TMP_DIR: |
||
| 290 | $this->setErrors(_ER_UP_NOTMPDIR); |
||
| 291 | return false; |
||
| 292 | break; |
||
| 293 | case UPLOAD_ERR_CANT_WRITE: |
||
| 294 | $this->setErrors(_ER_UP_CANTWRITE); |
||
| 295 | return false; |
||
| 296 | break; |
||
| 297 | case UPLOAD_ERR_EXTENSION: |
||
| 298 | $this->setErrors(_ER_UP_EXTENSION); |
||
| 299 | return false; |
||
| 300 | break; |
||
| 301 | default: |
||
| 302 | $this->setErrors(_ER_UP_UNKNOWN); |
||
| 303 | return false; |
||
| 304 | break; |
||
| 305 | } |
||
| 306 | } |
||
| 307 | |||
| 308 | if ((int)$this->mediaSize < 0) { |
||
| 309 | $this->setErrors(_ER_UP_INVALIDFILESIZE); |
||
| 310 | |||
| 311 | return false; |
||
| 312 | } |
||
| 313 | if ($this->mediaName == '') { |
||
| 314 | $this->setErrors(_ER_UP_FILENAMEEMPTY); |
||
| 315 | |||
| 316 | return false; |
||
| 317 | } |
||
| 318 | if ($this->mediaTmpName === 'none' || !is_uploaded_file($this->mediaTmpName)) { |
||
| 319 | $this->setErrors(_ER_UP_NOFILEUPLOADED); |
||
| 320 | |||
| 321 | return false; |
||
| 322 | } |
||
| 323 | |||
| 324 | return true; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set the target filename |
||
| 329 | * |
||
| 330 | * @param string $value |
||
| 331 | */ |
||
| 332 | public function setTargetFileName($value) |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Set the prefix |
||
| 339 | * |
||
| 340 | * @param string $value |
||
| 341 | */ |
||
| 342 | public function setPrefix($value) |
||
| 343 | { |
||
| 344 | $this->prefix = (string)trim($value); |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Get the uploaded filename |
||
| 349 | * |
||
| 350 | * @return string |
||
| 351 | */ |
||
| 352 | public function getMediaName() |
||
| 353 | { |
||
| 354 | return $this->mediaName; |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Get the type of the uploaded file |
||
| 359 | * |
||
| 360 | * @return string |
||
| 361 | */ |
||
| 362 | public function getMediaType() |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Get the size of the uploaded file |
||
| 369 | * |
||
| 370 | * @return int |
||
| 371 | */ |
||
| 372 | public function getMediaSize() |
||
| 373 | { |
||
| 374 | return $this->mediaSize; |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Get the temporary name that the uploaded file was stored under |
||
| 379 | * |
||
| 380 | * @return string |
||
| 381 | */ |
||
| 382 | public function getMediaTmpName() |
||
| 383 | { |
||
| 384 | return $this->mediaTmpName; |
||
| 385 | } |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Get the saved filename |
||
| 389 | * |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | public function getSavedFileName() |
||
| 393 | { |
||
| 394 | return $this->savedFileName; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Get the destination the file is saved to |
||
| 399 | * |
||
| 400 | * @return string |
||
| 401 | */ |
||
| 402 | public function getSavedDestination() |
||
| 403 | { |
||
| 404 | return $this->savedDestination; |
||
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Check the file and copy it to the destination |
||
| 409 | * |
||
| 410 | * @param int $chmod |
||
| 411 | * @return bool |
||
| 412 | */ |
||
| 413 | public function upload($chmod = 0644) |
||
| 452 | } |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Copy the file to its destination |
||
| 456 | * |
||
| 457 | * @param $chmod |
||
| 458 | * @return bool |
||
| 459 | */ |
||
| 460 | public function _copyFile($chmod) |
||
| 461 | { |
||
| 462 | $matched = array(); |
||
| 463 | if (!preg_match("/\.([a-zA-Z0-9]+)$/", $this->mediaName, $matched)) { |
||
| 464 | $this->setErrors(_ER_UP_INVALIDFILENAME); |
||
| 465 | |||
| 466 | return false; |
||
| 467 | } |
||
| 468 | if (isset($this->targetFileName)) { |
||
| 469 | $this->savedFileName = $this->targetFileName; |
||
| 470 | } elseif (isset($this->prefix)) { |
||
| 471 | $this->savedFileName = uniqid($this->prefix) . '.' . strtolower($matched[1]); |
||
| 472 | } else { |
||
| 473 | $this->savedFileName = strtolower($this->mediaName); |
||
| 474 | } |
||
| 475 | |||
| 476 | $this->savedFileName = iconv('UTF-8', 'ASCII//TRANSLIT', $this->savedFileName); |
||
| 477 | $this->savedFileName = preg_replace('!\s+!', '_', $this->savedFileName); |
||
| 478 | $this->savedFileName = preg_replace("/[^a-zA-Z0-9\._-]/", '', $this->savedFileName); |
||
| 479 | |||
| 480 | $this->savedDestination = $this->uploadDir . '/' . $this->savedFileName; |
||
| 481 | if (!move_uploaded_file($this->mediaTmpName, $this->savedDestination)) { |
||
| 482 | $this->setErrors(sprintf(_ER_UP_FAILEDSAVEFILE, $this->savedDestination)); |
||
| 483 | |||
| 484 | return false; |
||
| 485 | } |
||
| 486 | // Check IE XSS before returning success |
||
| 487 | $ext = strtolower(substr(strrchr($this->savedDestination, '.'), 1)); |
||
| 488 | if (in_array($ext, $this->imageExtensions)) { |
||
| 489 | $info = @getimagesize($this->savedDestination); |
||
| 490 | if ($info === false || $this->imageExtensions[(int)$info[2]] != $ext) { |
||
| 491 | $this->setErrors(_ER_UP_SUSPICIOUSREFUSED); |
||
| 492 | @unlink($this->savedDestination); |
||
| 493 | |||
| 494 | return false; |
||
| 495 | } |
||
| 496 | } |
||
| 497 | @chmod($this->savedDestination, $chmod); |
||
| 498 | |||
| 499 | return true; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Is the file the right size? |
||
| 504 | * |
||
| 505 | * @return bool |
||
| 506 | */ |
||
| 507 | public function checkMaxFileSize() |
||
| 508 | { |
||
| 509 | if (!isset($this->maxFileSize)) { |
||
| 510 | return true; |
||
| 511 | } |
||
| 512 | if ($this->mediaSize > $this->maxFileSize) { |
||
| 513 | $this->setErrors(sprintf(_ER_UP_FILESIZETOOLARGE, $this->maxFileSize, $this->mediaSize)); |
||
| 514 | |||
| 515 | return false; |
||
| 516 | } |
||
| 517 | |||
| 518 | return true; |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Is the picture the right width? |
||
| 523 | * |
||
| 524 | * @return bool |
||
| 525 | */ |
||
| 526 | public function checkMaxWidth() |
||
| 527 | { |
||
| 528 | if (!isset($this->maxWidth)) { |
||
| 529 | return true; |
||
| 530 | } |
||
| 531 | if (false !== $dimension = getimagesize($this->mediaTmpName)) { |
||
| 532 | if ($dimension[0] > $this->maxWidth) { |
||
| 533 | $this->setErrors(sprintf(_ER_UP_FILEWIDTHTOOLARGE, $this->maxWidth, $dimension[0])); |
||
| 534 | |||
| 535 | return false; |
||
| 536 | } |
||
| 537 | } else { |
||
| 538 | trigger_error(sprintf(_ER_UP_FAILEDFETCHIMAGESIZE, $this->mediaTmpName), E_USER_WARNING); |
||
| 539 | } |
||
| 540 | |||
| 541 | return true; |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Is the picture the right height? |
||
| 546 | * |
||
| 547 | * @return bool |
||
| 548 | */ |
||
| 549 | public function checkMaxHeight() |
||
| 550 | { |
||
| 551 | if (!isset($this->maxHeight)) { |
||
| 552 | return true; |
||
| 553 | } |
||
| 554 | if (false !== $dimension = getimagesize($this->mediaTmpName)) { |
||
| 555 | if ($dimension[1] > $this->maxHeight) { |
||
| 556 | $this->setErrors(sprintf(_ER_UP_FILEHEIGHTTOOLARGE, $this->maxHeight, $dimension[1])); |
||
| 557 | |||
| 558 | return false; |
||
| 559 | } |
||
| 560 | } else { |
||
| 561 | trigger_error(sprintf(_ER_UP_FAILEDFETCHIMAGESIZE, $this->mediaTmpName), E_USER_WARNING); |
||
| 562 | } |
||
| 563 | |||
| 564 | return true; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Check whether or not the uploaded file type is allowed |
||
| 569 | * |
||
| 570 | * @return bool |
||
| 571 | */ |
||
| 572 | public function checkMimeType() |
||
| 573 | { |
||
| 574 | // if the browser supplied mime type looks suspicious, refuse it |
||
| 575 | $structureCheck = (bool) preg_match('/^\w+\/[-+.\w]+$/', $this->mediaType); |
||
| 576 | if (false === $structureCheck) { |
||
| 577 | $this->mediaType = 'invalid'; |
||
| 578 | $this->setErrors(_ER_UP_UNKNOWNFILETYPEREJECTED); |
||
| 579 | return false; |
||
| 580 | } |
||
| 581 | |||
| 582 | if (empty($this->mediaRealType) && empty($this->allowUnknownTypes)) { |
||
| 583 | $this->setErrors(_ER_UP_UNKNOWNFILETYPEREJECTED); |
||
| 584 | |||
| 585 | return false; |
||
| 586 | } |
||
| 587 | |||
| 588 | if ((!empty($this->allowedMimeTypes) && !in_array($this->mediaRealType, $this->allowedMimeTypes)) || (!empty($this->deniedMimeTypes) && in_array($this->mediaRealType, $this->deniedMimeTypes))) { |
||
| 589 | $this->setErrors(sprintf(_ER_UP_MIMETYPENOTALLOWED, htmlspecialchars($this->mediaRealType, ENT_QUOTES))); |
||
| 590 | |||
| 591 | return false; |
||
| 592 | } |
||
| 593 | |||
| 594 | return true; |
||
| 595 | } |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Check whether or not the uploaded image type is valid |
||
| 599 | * |
||
| 600 | * @return bool |
||
| 601 | */ |
||
| 602 | public function checkImageType() |
||
| 603 | { |
||
| 604 | if (empty($this->checkImageType)) { |
||
| 605 | return true; |
||
| 606 | } |
||
| 607 | |||
| 608 | if (('image' === substr($this->mediaType, 0, strpos($this->mediaType, '/'))) || (!empty($this->mediaRealType) && 'image' === substr($this->mediaRealType, 0, strpos($this->mediaRealType, '/')))) { |
||
| 609 | if (!($info = @getimagesize($this->mediaTmpName))) { |
||
| 610 | $this->setErrors(_ER_UP_INVALIDIMAGEFILE); |
||
| 611 | |||
| 612 | return false; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | return true; |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Sanitize executable filename with multiple extensions |
||
| 621 | */ |
||
| 622 | public function sanitizeMultipleExtensions() |
||
| 623 | { |
||
| 624 | if (empty($this->extensionsToBeSanitized)) { |
||
| 625 | return null; |
||
| 626 | } |
||
| 627 | |||
| 628 | $patterns = array(); |
||
| 629 | $replaces = array(); |
||
| 630 | foreach ($this->extensionsToBeSanitized as $ext) { |
||
| 631 | $patterns[] = "/\." . preg_quote($ext) . "\./i"; |
||
| 632 | $replaces[] = '_' . $ext . '.'; |
||
| 633 | } |
||
| 634 | $this->mediaName = preg_replace($patterns, $replaces, $this->mediaName); |
||
| 635 | } |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Add an error |
||
| 639 | * |
||
| 640 | * @param string $error |
||
| 641 | */ |
||
| 642 | public function setErrors($error) |
||
| 643 | { |
||
| 644 | $this->errors[] = trim($error); |
||
| 645 | } |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Get generated errors |
||
| 649 | * |
||
| 650 | * @param bool $ashtml Format using HTML? |
||
| 651 | * @return array |string Array of array messages OR HTML string |
||
| 652 | */ |
||
| 653 | public function &getErrors($ashtml = true) |
||
| 667 | } |
||
| 668 | } |
||
| 669 | } |
||
| 670 |