/
home
/
assocoweys
/
avexp
/
plugins
/
system
/
articlesanywhere
/
src
/
Helpers
/
Upload File
HOME
<?php /** * @package Articles Anywhere * @version 8.5.2 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2018 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Plugin\System\ArticlesAnywhere\Helpers; use Joomla\CMS\Date\Date as JDate; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; use RegularLabs\Library\Date as RL_Date; use RegularLabs\Library\RegEx as RL_RegEx; defined('_JEXEC') or die; class ValueHelper { public static function placeholderToDate($value) { if (in_array($value, [ 'NOW', 'now()', 'JFactory::getDate()', ])) { $date = new JDate('now', JFactory::getConfig()->get('offset', 'UTC')); return $date->toSql(); } $regex = '^date\(' . '(?:\'(?<time>.*?)\')?' . '(?:,\s*\'(?<format>.*?)\')?' . '\)$'; if ( ! RL_RegEx::match($regex, $value, $match)) { return false; } $time = isset($match['time']) ? $match['time'] : 'now'; $format = isset($match['format']) ? $match['format'] : 'Y-m-d H:s:i'; if ( ! isset($match['format'])) { $time = date('Y-m-d', strtotime($time)); } $date = new JDate($time, JFactory::getConfig()->get('offset', 'UTC')); return $date->format($format); } public static function isDateValue($value) { // Check if string could be a date if (is_array($value)) { return false; } if ( // Dates must contain a '-' and not letters (strpos($value, '-') == false) || RL_RegEx::match('[a-z]', $value) // Check string it passes a simple strtotime || ! strtotime($value) ) { return false; } return true; } public static function dateToString($value, $attributes) { $showtime = isset($attributes->showtime) ? $attributes->showtime : true; $format = isset($attributes->format) ? $attributes->format : ''; $is_custom_field = isset($attributes->is_custom_field) ? $attributes->is_custom_field : false; if (empty($format)) { $format = $showtime ? JText::_('DATE_FORMAT_LC2') : JText::_('DATE_FORMAT_LC1'); } if (strpos($format, '%') !== false) { $format = RL_Date::strftimeToDateFormat($format); } // Don't pass custom fields through JHtml, as it will double the offset if ($is_custom_field) { return (new JDate($value))->format($format); } return JHtml::_('date', $value, $format); } }