示例#1
0
	protected function getInput()
	{
		$this->params = $this->element->attributes();

		$label = $this->get('label');
		$format = $this->get('format');

		$date = JFactory::getDate();

		$tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
		$date->setTimeZone($tz);

		if ($format)
		{
			if (strpos($format, '%') !== false)
			{
				require_once JPATH_PLUGINS . '/system/nnframework/helpers/text.php';
				$format = nnText::dateToDateFormat($format);
			}
			$html = $date->format($format, 1);
		}
		else
		{
			$html = $date->format('', 1);
		}

		if ($label)
		{
			$html = JText::sprintf($label, $html);
		}

		return '<div class="nn_block nn_title">' . $html . '</div>';
	}
示例#2
0
 static function dateToDateFormat($dateFormat)
 {
     require_once __DIR__ . '/text.php';
     return nnText::dateToDateFormat($dateFormat);
 }
示例#3
0
 public function convertDateToString($string, $extra)
 {
     // Check if string could be a date
     if (strpos($string, '-') == false || preg_match('#[a-z]#i', $string) || !strtotime($string)) {
         return $string;
     }
     if (!$extra) {
         $extra = JText::_('DATE_FORMAT_LC2');
     }
     if (strpos($extra, '%') !== false) {
         $extra = nnText::dateToDateFormat($extra);
     }
     return JHtml::_('date', $string, $extra);
 }
示例#4
0
 function replaceVars(&$str)
 {
     if (!(strpos($str, '[[user:'******'#\\[\\[user\\:([^\\]]+)\\]\\]#', $str, $matches, PREG_SET_ORDER) > 0) {
             $user = JFactory::getUser();
             $contact = null;
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
             foreach ($matches as $match) {
                 if ($match['1'] == 'password' || $match['1']['0'] == '_') {
                     $str = str_replace($match['0'], '', $str);
                 } else {
                     if (isset($user->{$match['1']})) {
                         $str = str_replace($match['0'], $user->{$match['1']}, $str);
                     } else {
                         if (!$contact) {
                             $query->clear()->select('c.*')->from('#__' . $this->_config->contact_table . ' as c')->where('c.user_id = ' . (int) $user->id);
                             $db->setQuery($query);
                             $contact = $db->loadObject();
                         }
                         if (isset($contact->{$match['1']})) {
                             $str = str_replace($match['0'], $contact->{$match['1']}, $str);
                         } else {
                             $str = str_replace($match['0'], '', $str);
                         }
                     }
                 }
             }
         }
     }
     if (!(strpos($str, '[[date:') === false)) {
         if (preg_match_all('#\\[\\[date\\:([^\\]]+)\\]\\]#', $str, $matches, PREG_SET_ORDER) > 0) {
             require_once JPATH_PLUGINS . '/system/nnframework/helpers/text.php';
             foreach ($matches as $match) {
                 if ($match['1'] && !(strpos($match['1'], '%') === false)) {
                     $match['1'] = nnText::dateToDateFormat($match['1']);
                 }
                 $replace = JHtml::_('date', time(), $match['1']);
                 $str = str_replace($match['0'], $replace, $str);
             }
         }
     }
     if (!(strpos($str, '[[random:') === false)) {
         while (preg_match('#\\[\\[random\\:([0-9]+)-([0-9]+)\\]\\]#', $str, $match)) {
             $search = '#' . preg_quote($match['0'], "#") . '#';
             $replace = rand((int) $match['1'], (int) $match['2']);
             $str = preg_replace($search, $replace, $str, 1);
         }
     }
 }