<commit_before><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 * All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

/**
 * Module class for displaying site wide notices
 */
class modNotices extends Hubzero_Module
{
	/**
	 * Calculate the time left from a date time
	 * 
	 * @param      integer $year   Year
	 * @param      integer $month  Month
	 * @param      integer $day    Day
	 * @param      integer $hour   Hour
	 * @param      integer $minute Minute
	 * @return     array 
	 */
	private function _countdown($year, $month, $day, $hour, $minute)
	{
		$config = JFactory::getConfig();

		// make a unix timestamp for the given date
		$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

		// get current unix timestamp
		$now = time() + ($config->getValue('config.offset') * 60 * 60);

		$difference = $the_countdown_date - $now;
		if ($difference < 0) 
		{
			$difference = 0;
		}

		$days_left = floor($difference/60/60/24);
		$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
		$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

		$left = array($days_left, $hours_left, $minutes_left);
		return $left;
	}

	/**
	 * Turn datetime 0000-00-00 00:00:00 to time
	 * 
	 * @param      string $stime Datetime to convert
	 * @return     integer
	 */
	private function _mkt($stime)
	{
		if ($stime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $stime, $regs)) 
		{
			$stime = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
		}
		return $stime;
	}

	/**
	 * Break a timestamp into its parts
	 * 
	 * @param      integer $stime Timestamp
	 * @return     array
	 */
	private function _convert($stime)
	{
		$t = array();
		$t['year']   = date('Y', $stime);
		$t['month']  = date('M', $stime);
		$t['day']    = date('jS', $stime);
		$t['hour']   = date('g', $stime);
		$t['minute'] = date('i', $stime);
		$t['ampm']   = date('A', $stime);
		return $t;
	}

	/**
	 * Show the amoutn of time left
	 * 
	 * @param      array $stime Timestamp
	 * @return     string 
	 */
	private function _timeto($stime)
	{
		if ($stime[0] == 0 && $stime[1] == 0 && $stime[2] == 0) 
		{
			$o  = JText::_('MOD_NOTICES_IMMEDIATELY');
		} 
		else 
		{
			$o  = JText::_('MOD_NOTICES_IN') . ' ';
			$o .= ($stime[0] > 0) ? $stime[0] . ' ' . JText::_('MOD_NOTICES_DAYS') . ', '  : '';
			$o .= ($stime[1] > 0) ? $stime[1] . ' ' . JText::_('MOD_NOTICES_HOURS') . ', ' : '';
			$o .= ($stime[2] > 0) ? $stime[2] . ' ' . JText::_('MOD_NOTICES_MINUTES')      : '';
		}
		return $o;
	}

	/**
	 * Display module content
	 * 
	 * @return     void
	 */
	public function display()
	{
		$database =& JFactory::getDBO();

		// Set today's time and date
		$now = JFactory::getDate();

		$database->setQuery("SELECT publish_up, publish_down FROm #__modules WHERE id=" . $this->module->id);
		$item = $database->loadObject();
		$this->module->publish_up = $item->publish_up;
		$this->module->publish_down = $item->publish_down;

		// Get some initial parameters
		$start = $this->params->get('start_publishing', $this->module->publish_up);
		//$start = JHTML::_('date', $start, JText::_('DATE_FORMAT_HZ1'));
		$stop  = $this->params->get('stop_publishing', $this->module->publish_down);
		//$stop  = JHTML::_('date', $stop, JText::_('DATE_FORMAT_HZ1'));

		$this->publish = false;
		if (!$start || $start == $database->getNullDate()) 
		{
			$this->publish = true;
		} 
		else 
		{
			if ($start <= $now) 
			{
				$this->publish = true;
			} 
			else 
			{
				$this->publish = false;
			}
		}
		if (!$stop || $stop == $database->getNullDate()) 
		{
			$this->publish = true;
		} 
		else 
		{
			if ($stop >= $now && $this->publish) 
			{
				$this->publish = true;
			} 
			else 
			{
				$this->publish = false;
			}
		}

		$hide = '';
		if ($this->publish && $this->params->get('allowClose', 1))
		{
			// Figure out days left

			// make a unix timestamp for the given date
			$the_countdown_date = $this->_mkt($stop);

			// get current unix timestamp
			$now = time() + (JFactory::getConfig()->getValue('config.offset') * 60 * 60);

			$difference = $the_countdown_date - $now;
			if ($difference < 0) 
			{
				$difference = 0;
			}

			$this->days_left = floor($difference/60/60/24);

			$expires = $now + 60*60*24*$this->days_left;

			if ($hide = JRequest::getVar($this->params->get('moduleid', 'sitenotice'), '', 'get'))
			{
				setcookie($this->params->get('moduleid', 'sitenotice'), 'closed', $expires);
			}
			$hide = JRequest::getVar($this->params->get('moduleid', 'sitenotice'), '', 'cookie');
		}

		// Only do something if the module's time frame hasn't expired
		if ($this->publish && !$hide) 
		{
			ximport('Hubzero_Document');
			Hubzero_Document::addModuleStylesheet($this->module->module);

			// Get some parameters
			$this->moduleid   = $this->params->get('moduleid', 'sitenotice');
			$this->alertlevel = $this->params->get('alertlevel', 'medium');
			$timezone         = $this->params->get('timezone');
			$message          = $this->params->get('message');

			// Convert start time
			$start = $this->_mkt($start);
			$d = $this->_convert($start);
			$time_start = $d['hour'] . ':' . $d['minute'] . ' ' . $d['ampm'] . ', ' . $d['month'] . ' ' . $d['day'] . ', ' . $d['year'];

			// Convert end time
			$stop = $this->_mkt($stop);
			$u = $this->_convert($stop);
			$time_end  = $u['hour'] . ':' . $u['minute'] . ' ' . $u['ampm'] . ', ' . $u['month'] . ' ' . $u['day'] . ', ' . $u['year'];

			// Convert countdown-to-start time
			$d_month   = date('m', $start);
			$d_day     = date('d', $start);
			$d_hour    = date('H', $start);
			$time_left = $this->_countdown($d['year'], $d_month, $d_day, $d_hour, $d['minute']);
			$time_cd_tostart = $this->_timeto($time_left);

			// Convert countdown-to-return time
			$u_month   = date('m', $stop);
			$u_day     = date('d', $stop);
			$u_hour    = date('H', $stop);
			$time_left = $this->_countdown($u['year'], $u_month, $u_day, $u_hour, $u['minute']);
			$time_cd_toreturn = $this->_timeto($time_left);

			// Parse message for tags
			$message = str_replace('<notice:start>', $time_start, $message);
			$message = str_replace('<notice:end>', $time_end, $message);
			$message = str_replace('<notice:countdowntostart>', $time_cd_tostart, $message);
			$message = str_replace('<notice:countdowntoreturn>', $time_cd_toreturn, $message);
			$message = str_replace('<notice:timezone>', $timezone, $message);

			$this->message = $message;

			require(JModuleHelper::getLayoutPath($this->module->module));
		}
	}
}
<commit_msg>[HUBZERO][#3484] Fixed issue with publish dates in notices module<commit_after><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 * All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

/**
 * Module class for displaying site wide notices
 */
class modNotices extends Hubzero_Module
{
	/**
	 * Calculate the time left from a date time
	 * 
	 * @param      integer $year   Year
	 * @param      integer $month  Month
	 * @param      integer $day    Day
	 * @param      integer $hour   Hour
	 * @param      integer $minute Minute
	 * @return     array 
	 */
	private function _countdown($year, $month, $day, $hour, $minute)
	{
		$config = JFactory::getConfig();

		// make a unix timestamp for the given date
		$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);

		// get current unix timestamp
		$now = time() + ($config->getValue('config.offset') * 60 * 60);

		$difference = $the_countdown_date - $now;
		if ($difference < 0) 
		{
			$difference = 0;
		}

		$days_left = floor($difference/60/60/24);
		$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
		$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);

		$left = array($days_left, $hours_left, $minutes_left);
		return $left;
	}

	/**
	 * Turn datetime 0000-00-00 00:00:00 to time
	 * 
	 * @param      string $stime Datetime to convert
	 * @return     integer
	 */
	private function _mkt($stime)
	{
		if ($stime && preg_match("/([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $stime, $regs)) 
		{
			$stime = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
		}
		return $stime;
	}

	/**
	 * Break a timestamp into its parts
	 * 
	 * @param      integer $stime Timestamp
	 * @return     array
	 */
	private function _convert($stime)
	{
		$t = array();
		$t['year']   = date('Y', $stime);
		$t['month']  = date('M', $stime);
		$t['day']    = date('jS', $stime);
		$t['hour']   = date('g', $stime);
		$t['minute'] = date('i', $stime);
		$t['ampm']   = date('A', $stime);
		return $t;
	}

	/**
	 * Show the amoutn of time left
	 * 
	 * @param      array $stime Timestamp
	 * @return     string 
	 */
	private function _timeto($stime)
	{
		if ($stime[0] == 0 && $stime[1] == 0 && $stime[2] == 0) 
		{
			$o  = JText::_('MOD_NOTICES_IMMEDIATELY');
		} 
		else 
		{
			$o  = JText::_('MOD_NOTICES_IN') . ' ';
			$o .= ($stime[0] > 0) ? $stime[0] . ' ' . JText::_('MOD_NOTICES_DAYS') . ', '  : '';
			$o .= ($stime[1] > 0) ? $stime[1] . ' ' . JText::_('MOD_NOTICES_HOURS') . ', ' : '';
			$o .= ($stime[2] > 0) ? $stime[2] . ' ' . JText::_('MOD_NOTICES_MINUTES')      : '';
		}
		return $o;
	}

	/**
	 * Display module content
	 * 
	 * @return     void
	 */
	public function display()
	{
		$database =& JFactory::getDBO();

		// Set today's time and date
		$now = JFactory::getDate();

		$database->setQuery("SELECT publish_up, publish_down FROm #__modules WHERE id=" . $this->module->id);
		$item = $database->loadObject();
		$this->module->publish_up = (isset($item->publish_up)) ? $item->publish_up : null;
		$this->module->publish_down = (isset($item->publish_down)) ? $item->publish_down : null;

		// Get some initial parameters
		$start = $this->params->get('start_publishing', $this->module->publish_up);
		//$start = JHTML::_('date', $start, JText::_('DATE_FORMAT_HZ1'));
		$stop  = $this->params->get('stop_publishing', $this->module->publish_down);
		//$stop  = JHTML::_('date', $stop, JText::_('DATE_FORMAT_HZ1'));

		$this->publish = false;
		if (!$start || $start == $database->getNullDate()) 
		{
			$this->publish = true;
		} 
		else 
		{
			if ($start <= $now) 
			{
				$this->publish = true;
			} 
			else 
			{
				$this->publish = false;
			}
		}
		if (!$stop || $stop == $database->getNullDate()) 
		{
			$this->publish = true;
		} 
		else 
		{
			if ($stop >= $now && $this->publish) 
			{
				$this->publish = true;
			} 
			else 
			{
				$this->publish = false;
			}
		}

		$hide = '';
		if ($this->publish && $this->params->get('allowClose', 1))
		{
			// Figure out days left

			// make a unix timestamp for the given date
			$the_countdown_date = $this->_mkt($stop);

			// get current unix timestamp
			$now = time() + (JFactory::getConfig()->getValue('config.offset') * 60 * 60);

			$difference = $the_countdown_date - $now;
			if ($difference < 0) 
			{
				$difference = 0;
			}

			$this->days_left = floor($difference/60/60/24);

			$expires = $now + 60*60*24*$this->days_left;

			if ($hide = JRequest::getVar($this->params->get('moduleid', 'sitenotice'), '', 'get'))
			{
				setcookie($this->params->get('moduleid', 'sitenotice'), 'closed', $expires);
			}
			$hide = JRequest::getVar($this->params->get('moduleid', 'sitenotice'), '', 'cookie');
		}

		// Only do something if the module's time frame hasn't expired
		if ($this->publish && !$hide) 
		{
			ximport('Hubzero_Document');
			Hubzero_Document::addModuleStylesheet($this->module->module);

			// Get some parameters
			$this->moduleid   = $this->params->get('moduleid', 'sitenotice');
			$this->alertlevel = $this->params->get('alertlevel', 'medium');
			$timezone         = $this->params->get('timezone');
			$message          = $this->params->get('message');

			// Convert start time
			$start = $this->_mkt($start);
			$d = $this->_convert($start);
			$time_start = $d['hour'] . ':' . $d['minute'] . ' ' . $d['ampm'] . ', ' . $d['month'] . ' ' . $d['day'] . ', ' . $d['year'];

			// Convert end time
			$stop = $this->_mkt($stop);
			$u = $this->_convert($stop);
			$time_end  = $u['hour'] . ':' . $u['minute'] . ' ' . $u['ampm'] . ', ' . $u['month'] . ' ' . $u['day'] . ', ' . $u['year'];

			// Convert countdown-to-start time
			$d_month   = date('m', $start);
			$d_day     = date('d', $start);
			$d_hour    = date('H', $start);
			$time_left = $this->_countdown($d['year'], $d_month, $d_day, $d_hour, $d['minute']);
			$time_cd_tostart = $this->_timeto($time_left);

			// Convert countdown-to-return time
			$u_month   = date('m', $stop);
			$u_day     = date('d', $stop);
			$u_hour    = date('H', $stop);
			$time_left = $this->_countdown($u['year'], $u_month, $u_day, $u_hour, $u['minute']);
			$time_cd_toreturn = $this->_timeto($time_left);

			// Parse message for tags
			$message = str_replace('<notice:start>', $time_start, $message);
			$message = str_replace('<notice:end>', $time_end, $message);
			$message = str_replace('<notice:countdowntostart>', $time_cd_tostart, $message);
			$message = str_replace('<notice:countdowntoreturn>', $time_cd_toreturn, $message);
			$message = str_replace('<notice:timezone>', $timezone, $message);

			$this->message = $message;

			require(JModuleHelper::getLayoutPath($this->module->module));
		}
	}
}

{'fraction_non_alphanumeric': 0.1958242880858128, 'fraction_numerical': 0.016856084791214403, 'mean_word_length': 3.292408879144971, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196287', 'n_tokens_mistral': 6339, 'n_tokens_neox': 5560, 'n_words': 1286}