PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/Form/Element/File.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 907 lines | 454 code | 113 blank | 340 comment | 54 complexity | 553ab6bc5616a047db8b5b3547096e83 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Form
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /** Zend_Form_Element_Xhtml */
  21. require_once 'Zend/Form/Element/Xhtml.php';
  22. /**
  23. * Zend_Form_Element
  24. *
  25. * @category Zend
  26. * @package Zend_Form
  27. * @subpackage Element
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @version $Id: File.php 23871 2011-04-23 22:40:16Z ramon $
  31. */
  32. class Zend_Form_Element_File extends Zend_Form_Element_Xhtml
  33. {
  34. /**
  35. * Plugin loader type
  36. */
  37. const TRANSFER_ADAPTER = 'TRANSFER_ADAPTER';
  38. /**
  39. * @var string Default view helper
  40. */
  41. public $helper = 'formFile';
  42. /**
  43. * @var Zend_File_Transfer_Adapter_Abstract
  44. */
  45. protected $_adapter;
  46. /**
  47. * @var boolean Already validated ?
  48. */
  49. protected $_validated = false;
  50. /**
  51. * @var boolean Disable value to be equal to file content
  52. */
  53. protected $_valueDisabled = false;
  54. /**
  55. * @var integer Internal multifile counter
  56. */
  57. protected $_counter = 1;
  58. /**
  59. * @var integer Maximum file size for MAX_FILE_SIZE attribut of form
  60. */
  61. protected static $_maxFileSize = -1;
  62. /**
  63. * Load default decorators
  64. *
  65. * @return Zend_Form_Element_File
  66. */
  67. public function loadDefaultDecorators()
  68. {
  69. if ($this->loadDefaultDecoratorsIsDisabled()) {
  70. return $this;
  71. }
  72. $decorators = $this->getDecorators();
  73. if (empty($decorators)) {
  74. $this->addDecorator('File')
  75. ->addDecorator('Errors')
  76. ->addDecorator('Description', array('tag' => 'p', 'class' => 'description'))
  77. ->addDecorator('HtmlTag', array('tag' => 'dd'))
  78. ->addDecorator('Label', array('tag' => 'dt'));
  79. }
  80. return $this;
  81. }
  82. /**
  83. * Set plugin loader
  84. *
  85. * @param Zend_Loader_PluginLoader_Interface $loader
  86. * @param string $type
  87. * @return Zend_Form_Element_File
  88. */
  89. public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)
  90. {
  91. $type = strtoupper($type);
  92. if ($type != self::TRANSFER_ADAPTER) {
  93. return parent::setPluginLoader($loader, $type);
  94. }
  95. $this->_loaders[$type] = $loader;
  96. return $this;
  97. }
  98. /**
  99. * Get Plugin Loader
  100. *
  101. * @param string $type
  102. * @return Zend_Loader_PluginLoader_Interface
  103. */
  104. public function getPluginLoader($type)
  105. {
  106. $type = strtoupper($type);
  107. if ($type != self::TRANSFER_ADAPTER) {
  108. return parent::getPluginLoader($type);
  109. }
  110. if (!array_key_exists($type, $this->_loaders)) {
  111. require_once 'Zend/Loader/PluginLoader.php';
  112. $loader = new Zend_Loader_PluginLoader(array(
  113. 'Zend_File_Transfer_Adapter' => 'Zend/File/Transfer/Adapter/',
  114. ));
  115. $this->setPluginLoader($loader, self::TRANSFER_ADAPTER);
  116. }
  117. return $this->_loaders[$type];
  118. }
  119. /**
  120. * Add prefix path for plugin loader
  121. *
  122. * @param string $prefix
  123. * @param string $path
  124. * @param string $type
  125. * @return Zend_Form_Element_File
  126. */
  127. public function addPrefixPath($prefix, $path, $type = null)
  128. {
  129. $type = strtoupper($type);
  130. if (!empty($type) && ($type != self::TRANSFER_ADAPTER)) {
  131. return parent::addPrefixPath($prefix, $path, $type);
  132. }
  133. if (empty($type)) {
  134. $pluginPrefix = rtrim($prefix, '_') . '_Transfer_Adapter';
  135. $pluginPath = rtrim($path, DIRECTORY_SEPARATOR) . '/Transfer/Adapter/';
  136. $loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
  137. $loader->addPrefixPath($pluginPrefix, $pluginPath);
  138. return parent::addPrefixPath($prefix, $path, null);
  139. }
  140. $loader = $this->getPluginLoader($type);
  141. $loader->addPrefixPath($prefix, $path);
  142. return $this;
  143. }
  144. /**
  145. * Set transfer adapter
  146. *
  147. * @param string|Zend_File_Transfer_Adapter_Abstract $adapter
  148. * @return Zend_Form_Element_File
  149. */
  150. public function setTransferAdapter($adapter)
  151. {
  152. if ($adapter instanceof Zend_File_Transfer_Adapter_Abstract) {
  153. $this->_adapter = $adapter;
  154. } elseif (is_string($adapter)) {
  155. $loader = $this->getPluginLoader(self::TRANSFER_ADAPTER);
  156. $class = $loader->load($adapter);
  157. $this->_adapter = new $class;
  158. } else {
  159. require_once 'Zend/Form/Element/Exception.php';
  160. throw new Zend_Form_Element_Exception('Invalid adapter specified');
  161. }
  162. foreach (array('filter', 'validate') as $type) {
  163. $loader = $this->getPluginLoader($type);
  164. $this->_adapter->setPluginLoader($loader, $type);
  165. }
  166. return $this;
  167. }
  168. /**
  169. * Get transfer adapter
  170. *
  171. * Lazy loads HTTP transfer adapter when no adapter registered.
  172. *
  173. * @return Zend_File_Transfer_Adapter_Abstract
  174. */
  175. public function getTransferAdapter()
  176. {
  177. if (null === $this->_adapter) {
  178. $this->setTransferAdapter('Http');
  179. }
  180. return $this->_adapter;
  181. }
  182. /**
  183. * Add Validator; proxy to adapter
  184. *
  185. * @param string|Zend_Validate_Interface $validator
  186. * @param bool $breakChainOnFailure
  187. * @param mixed $options
  188. * @return Zend_Form_Element_File
  189. */
  190. public function addValidator($validator, $breakChainOnFailure = false, $options = array())
  191. {
  192. $adapter = $this->getTransferAdapter();
  193. $adapter->addValidator($validator, $breakChainOnFailure, $options, $this->getName());
  194. $this->_validated = false;
  195. return $this;
  196. }
  197. /**
  198. * Add multiple validators at once; proxy to adapter
  199. *
  200. * @param array $validators
  201. * @return Zend_Form_Element_File
  202. */
  203. public function addValidators(array $validators)
  204. {
  205. $adapter = $this->getTransferAdapter();
  206. $adapter->addValidators($validators, $this->getName());
  207. $this->_validated = false;
  208. return $this;
  209. }
  210. /**
  211. * Add multiple validators at once, overwriting; proxy to adapter
  212. *
  213. * @param array $validators
  214. * @return Zend_Form_Element_File
  215. */
  216. public function setValidators(array $validators)
  217. {
  218. $adapter = $this->getTransferAdapter();
  219. $adapter->setValidators($validators, $this->getName());
  220. $this->_validated = false;
  221. return $this;
  222. }
  223. /**
  224. * Retrieve validator by name; proxy to adapter
  225. *
  226. * @param string $name
  227. * @return Zend_Validate_Interface|null
  228. */
  229. public function getValidator($name)
  230. {
  231. $adapter = $this->getTransferAdapter();
  232. return $adapter->getValidator($name);
  233. }
  234. /**
  235. * Retrieve all validators; proxy to adapter
  236. *
  237. * @return array
  238. */
  239. public function getValidators()
  240. {
  241. $adapter = $this->getTransferAdapter();
  242. $validators = $adapter->getValidators($this->getName());
  243. if ($validators === null) {
  244. $validators = array();
  245. }
  246. return $validators;
  247. }
  248. /**
  249. * Remove validator by name; proxy to adapter
  250. *
  251. * @param string $name
  252. * @return Zend_Form_Element_File
  253. */
  254. public function removeValidator($name)
  255. {
  256. $adapter = $this->getTransferAdapter();
  257. $adapter->removeValidator($name);
  258. $this->_validated = false;
  259. return $this;
  260. }
  261. /**
  262. * Remove all validators; proxy to adapter
  263. *
  264. * @return Zend_Form_Element_File
  265. */
  266. public function clearValidators()
  267. {
  268. $adapter = $this->getTransferAdapter();
  269. $adapter->clearValidators();
  270. $this->_validated = false;
  271. return $this;
  272. }
  273. /**
  274. * Add Filter; proxy to adapter
  275. *
  276. * @param string|array $filter Type of filter to add
  277. * @param string|array $options Options to set for the filter
  278. * @return Zend_Form_Element_File
  279. */
  280. public function addFilter($filter, $options = null)
  281. {
  282. $adapter = $this->getTransferAdapter();
  283. $adapter->addFilter($filter, $options, $this->getName());
  284. return $this;
  285. }
  286. /**
  287. * Add Multiple filters at once; proxy to adapter
  288. *
  289. * @param array $filters
  290. * @return Zend_Form_Element_File
  291. */
  292. public function addFilters(array $filters)
  293. {
  294. $adapter = $this->getTransferAdapter();
  295. $adapter->addFilters($filters, $this->getName());
  296. return $this;
  297. }
  298. /**
  299. * Sets a filter for the class, erasing all previous set; proxy to adapter
  300. *
  301. * @param string|array $filter Filter to set
  302. * @return Zend_Form_Element_File
  303. */
  304. public function setFilters(array $filters)
  305. {
  306. $adapter = $this->getTransferAdapter();
  307. $adapter->setFilters($filters, $this->getName());
  308. return $this;
  309. }
  310. /**
  311. * Retrieve individual filter; proxy to adapter
  312. *
  313. * @param string $name
  314. * @return Zend_Filter_Interface|null
  315. */
  316. public function getFilter($name)
  317. {
  318. $adapter = $this->getTransferAdapter();
  319. return $adapter->getFilter($name);
  320. }
  321. /**
  322. * Returns all set filters; proxy to adapter
  323. *
  324. * @return array List of set filters
  325. */
  326. public function getFilters()
  327. {
  328. $adapter = $this->getTransferAdapter();
  329. $filters = $adapter->getFilters($this->getName());
  330. if ($filters === null) {
  331. $filters = array();
  332. }
  333. return $filters;
  334. }
  335. /**
  336. * Remove an individual filter; proxy to adapter
  337. *
  338. * @param string $name
  339. * @return Zend_Form_Element_File
  340. */
  341. public function removeFilter($name)
  342. {
  343. $adapter = $this->getTransferAdapter();
  344. $adapter->removeFilter($name);
  345. return $this;
  346. }
  347. /**
  348. * Remove all filters; proxy to adapter
  349. *
  350. * @return Zend_Form_Element_File
  351. */
  352. public function clearFilters()
  353. {
  354. $adapter = $this->getTransferAdapter();
  355. $adapter->clearFilters();
  356. return $this;
  357. }
  358. /**
  359. * Validate upload
  360. *
  361. * @param string $value File, can be optional, give null to validate all files
  362. * @param mixed $context
  363. * @return bool
  364. */
  365. public function isValid($value, $context = null)
  366. {
  367. if ($this->_validated) {
  368. return true;
  369. }
  370. $adapter = $this->getTransferAdapter();
  371. $translator = $this->getTranslator();
  372. if ($translator !== null) {
  373. $adapter->setTranslator($translator);
  374. }
  375. if (!$this->isRequired()) {
  376. $adapter->setOptions(array('ignoreNoFile' => true), $this->getName());
  377. } else {
  378. $adapter->setOptions(array('ignoreNoFile' => false), $this->getName());
  379. if ($this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) {
  380. $this->addValidator = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
  381. }
  382. }
  383. if($adapter->isValid($this->getName())) {
  384. $this->_validated = true;
  385. return true;
  386. }
  387. $this->_validated = false;
  388. return false;
  389. }
  390. /**
  391. * Receive the uploaded file
  392. *
  393. * @return boolean
  394. */
  395. public function receive()
  396. {
  397. if (!$this->_validated) {
  398. if (!$this->isValid($this->getName())) {
  399. return false;
  400. }
  401. }
  402. $adapter = $this->getTransferAdapter();
  403. if ($adapter->receive($this->getName())) {
  404. return true;
  405. }
  406. return false;
  407. }
  408. /**
  409. * Retrieve error codes; proxy to transfer adapter
  410. *
  411. * @return array
  412. */
  413. public function getErrors()
  414. {
  415. return parent::getErrors() + $this->getTransferAdapter()->getErrors();
  416. }
  417. /**
  418. * Are there errors registered?
  419. *
  420. * @return bool
  421. */
  422. public function hasErrors()
  423. {
  424. return (parent::hasErrors() || $this->getTransferAdapter()->hasErrors());
  425. }
  426. /**
  427. * Retrieve error messages; proxy to transfer adapter
  428. *
  429. * @return array
  430. */
  431. public function getMessages()
  432. {
  433. return parent::getMessages() + $this->getTransferAdapter()->getMessages();
  434. }
  435. /**
  436. * Set the upload destination
  437. *
  438. * @param string $path
  439. * @return Zend_Form_Element_File
  440. */
  441. public function setDestination($path)
  442. {
  443. $this->getTransferAdapter()->setDestination($path, $this->getName());
  444. return $this;
  445. }
  446. /**
  447. * Get the upload destination
  448. *
  449. * @return string
  450. */
  451. public function getDestination()
  452. {
  453. return $this->getTransferAdapter()->getDestination($this->getName());
  454. }
  455. /**
  456. * Get the final filename
  457. *
  458. * @param string $value (Optional) Element or file to return
  459. * @param boolean $path (Optional) Return also the path, defaults to true
  460. * @return string
  461. */
  462. public function getFileName($value = null, $path = true)
  463. {
  464. if (empty($value)) {
  465. $value = $this->getName();
  466. }
  467. return $this->getTransferAdapter()->getFileName($value, $path);
  468. }
  469. /**
  470. * Get internal file informations
  471. *
  472. * @param string $value (Optional) Element or file to return
  473. * @return array
  474. */
  475. public function getFileInfo($value = null)
  476. {
  477. if (empty($value)) {
  478. $value = $this->getName();
  479. }
  480. return $this->getTransferAdapter()->getFileInfo($value);
  481. }
  482. /**
  483. * Set a multifile element
  484. *
  485. * @param integer $count Number of file elements
  486. * @return Zend_Form_Element_File Provides fluent interface
  487. */
  488. public function setMultiFile($count)
  489. {
  490. if ((integer) $count < 2) {
  491. $this->setIsArray(false);
  492. $this->_counter = 1;
  493. } else {
  494. $this->setIsArray(true);
  495. $this->_counter = (integer) $count;
  496. }
  497. return $this;
  498. }
  499. /**
  500. * Returns the multifile element number
  501. *
  502. * @return integer
  503. */
  504. public function getMultiFile()
  505. {
  506. return $this->_counter;
  507. }
  508. /**
  509. * Sets the maximum file size of the form
  510. *
  511. * @return integer
  512. */
  513. public function getMaxFileSize()
  514. {
  515. if (self::$_maxFileSize < 0) {
  516. $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size')));
  517. $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize')));
  518. $min = max($ini, $max);
  519. if ($ini > 0) {
  520. $min = min($min, $ini);
  521. }
  522. if ($max > 0) {
  523. $min = min($min, $max);
  524. }
  525. self::$_maxFileSize = $min;
  526. }
  527. return self::$_maxFileSize;
  528. }
  529. /**
  530. * Sets the maximum file size of the form
  531. *
  532. * @param integer $size
  533. * @return integer
  534. */
  535. public function setMaxFileSize($size)
  536. {
  537. $ini = $this->_convertIniToInteger(trim(ini_get('post_max_size')));
  538. $max = $this->_convertIniToInteger(trim(ini_get('upload_max_filesize')));
  539. if (($max > -1) && ($size > $max)) {
  540. trigger_error("Your 'upload_max_filesize' config setting limits the maximum filesize to '$max'. You tried to set '$size'.", E_USER_NOTICE);
  541. $size = $max;
  542. }
  543. if (($ini > -1) && ($size > $ini)) {
  544. trigger_error("Your 'post_max_size' config setting limits the maximum filesize to '$ini'. You tried to set '$size'.", E_USER_NOTICE);
  545. $size = $ini;
  546. }
  547. self::$_maxFileSize = $size;
  548. return $this;
  549. }
  550. /**
  551. * Converts a ini setting to a integer value
  552. *
  553. * @param string $setting
  554. * @return integer
  555. */
  556. private function _convertIniToInteger($setting)
  557. {
  558. if (!is_numeric($setting)) {
  559. $type = strtoupper(substr($setting, -1));
  560. $setting = (integer) substr($setting, 0, -1);
  561. switch ($type) {
  562. case 'K' :
  563. $setting *= 1024;
  564. break;
  565. case 'M' :
  566. $setting *= 1024 * 1024;
  567. break;
  568. case 'G' :
  569. $setting *= 1024 * 1024 * 1024;
  570. break;
  571. default :
  572. break;
  573. }
  574. }
  575. return (integer) $setting;
  576. }
  577. /**
  578. * Set if the file will be uploaded when getting the value
  579. * This defaults to false which will force receive() when calling getValues()
  580. *
  581. * @param boolean $flag Sets if the file is handled as the elements value
  582. * @return Zend_Form_Element_File
  583. */
  584. public function setValueDisabled($flag)
  585. {
  586. $this->_valueDisabled = (bool) $flag;
  587. return $this;
  588. }
  589. /**
  590. * Returns if the file will be uploaded when calling getValues()
  591. *
  592. * @return boolean Receive the file on calling getValues()?
  593. */
  594. public function isValueDisabled()
  595. {
  596. return $this->_valueDisabled;
  597. }
  598. /**
  599. * Processes the file, returns null or the filename only
  600. * For the complete path, use getFileName
  601. *
  602. * @return null|string
  603. */
  604. public function getValue()
  605. {
  606. if ($this->_value !== null) {
  607. return $this->_value;
  608. }
  609. $content = $this->getTransferAdapter()->getFileName($this->getName());
  610. if (empty($content)) {
  611. return null;
  612. }
  613. if (!$this->isValid(null)) {
  614. return null;
  615. }
  616. if (!$this->_valueDisabled && !$this->receive()) {
  617. return null;
  618. }
  619. return $this->getFileName(null, false);
  620. }
  621. /**
  622. * Disallow setting the value
  623. *
  624. * @param mixed $value
  625. * @return Zend_Form_Element_File
  626. */
  627. public function setValue($value)
  628. {
  629. return $this;
  630. }
  631. /**
  632. * Set translator object for localization
  633. *
  634. * @param Zend_Translate|null $translator
  635. * @return Zend_Form_Element_File
  636. */
  637. public function setTranslator($translator = null)
  638. {
  639. $adapter = $this->getTransferAdapter();
  640. $adapter->setTranslator($translator);
  641. parent::setTranslator($translator);
  642. return $this;
  643. }
  644. /**
  645. * Retrieve localization translator object
  646. *
  647. * @return Zend_Translate_Adapter|null
  648. */
  649. public function getTranslator()
  650. {
  651. if ($this->translatorIsDisabled()) {
  652. return null;
  653. }
  654. $translator = $this->getTransferAdapter()->getTranslator();
  655. if (null === $translator) {
  656. require_once 'Zend/Form.php';
  657. return Zend_Form::getDefaultTranslator();
  658. }
  659. return $translator;
  660. }
  661. /**
  662. * Indicate whether or not translation should be disabled
  663. *
  664. * @param bool $flag
  665. * @return Zend_Form_Element_File
  666. */
  667. public function setDisableTranslator($flag)
  668. {
  669. $adapter = $this->getTransferAdapter();
  670. $adapter->setDisableTranslator($flag);
  671. $this->_translatorDisabled = (bool) $flag;
  672. return $this;
  673. }
  674. /**
  675. * Is translation disabled?
  676. *
  677. * @return bool
  678. */
  679. public function translatorIsDisabled()
  680. {
  681. $adapter = $this->getTransferAdapter();
  682. return $adapter->translatorIsDisabled();
  683. }
  684. /**
  685. * Was the file received?
  686. *
  687. * @return bool
  688. */
  689. public function isReceived()
  690. {
  691. $adapter = $this->getTransferAdapter();
  692. return $adapter->isReceived($this->getName());
  693. }
  694. /**
  695. * Was the file uploaded?
  696. *
  697. * @return bool
  698. */
  699. public function isUploaded()
  700. {
  701. $adapter = $this->getTransferAdapter();
  702. return $adapter->isUploaded($this->getName());
  703. }
  704. /**
  705. * Has the file been filtered?
  706. *
  707. * @return bool
  708. */
  709. public function isFiltered()
  710. {
  711. $adapter = $this->getTransferAdapter();
  712. return $adapter->isFiltered($this->getName());
  713. }
  714. /**
  715. * Returns the hash for this file element
  716. *
  717. * @param string $hash (Optional) Hash algorithm to use
  718. * @return string|array Hashstring
  719. */
  720. public function getHash($hash = 'crc32')
  721. {
  722. $adapter = $this->getTransferAdapter();
  723. return $adapter->getHash($hash, $this->getName());
  724. }
  725. /**
  726. * Returns the filesize for this file element
  727. *
  728. * @return string|array Filesize
  729. */
  730. public function getFileSize()
  731. {
  732. $adapter = $this->getTransferAdapter();
  733. return $adapter->getFileSize($this->getName());
  734. }
  735. /**
  736. * Returns the mimetype for this file element
  737. *
  738. * @return string|array Mimetype
  739. */
  740. public function getMimeType()
  741. {
  742. $adapter = $this->getTransferAdapter();
  743. return $adapter->getMimeType($this->getName());
  744. }
  745. /**
  746. * Render form element
  747. * Checks for decorator interface to prevent errors
  748. *
  749. * @param Zend_View_Interface $view
  750. * @return string
  751. */
  752. public function render(Zend_View_Interface $view = null)
  753. {
  754. $marker = false;
  755. foreach ($this->getDecorators() as $decorator) {
  756. if ($decorator instanceof Zend_Form_Decorator_Marker_File_Interface) {
  757. $marker = true;
  758. }
  759. }
  760. if (!$marker) {
  761. require_once 'Zend/Form/Element/Exception.php';
  762. throw new Zend_Form_Element_Exception('No file decorator found... unable to render file element');
  763. }
  764. return parent::render($view);
  765. }
  766. /**
  767. * Retrieve error messages and perform translation and value substitution
  768. *
  769. * @return array
  770. */
  771. protected function _getErrorMessages()
  772. {
  773. $translator = $this->getTranslator();
  774. $messages = $this->getErrorMessages();
  775. $value = $this->getFileName();
  776. foreach ($messages as $key => $message) {
  777. if (null !== $translator) {
  778. $message = $translator->translate($message);
  779. }
  780. if ($this->isArray() || is_array($value)) {
  781. $aggregateMessages = array();
  782. foreach ($value as $val) {
  783. $aggregateMessages[] = str_replace('%value%', $val, $message);
  784. }
  785. if (!empty($aggregateMessages)) {
  786. $messages[$key] = $aggregateMessages;
  787. }
  788. } else {
  789. $messages[$key] = str_replace('%value%', $value, $message);
  790. }
  791. }
  792. return $messages;
  793. }
  794. }