/** * Tries to authenticate the user and start the backup, or send him back to the default task */ function authenticate() { // Enforce raw mode - I need to be in full control! $format = JRequest::getCmd('format', 'html'); if ($format != 'raw') { $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=light&format=raw'); parent::redirect(); } else { if (!$this->_checkPermissions()) { parent::redirect(); } else { $this->_setProfile(); jimport('joomla.utilities.date'); jpimport('core.cube'); JoomlapackCUBE::reset(); $cube =& JoomlapackCUBE::getInstance(); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); $cube->start(JText::_('DEFAULT_COMMENT') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2'), '')); $cube->save(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=light&task=step&key=' . JRequest::getVar('key') . '&profile=' . JRequest::getInt('profile') . '&format=raw'); } } }
/** * Tries to authenticate the user and start the backup, or send him back to the default task */ public function authenticate() { // Enforce raw mode - I need to be in full control! $document =& JFactory::getDocument(); $document->setType('raw'); if (!$this->_checkPermissions()) { parent::redirect(); } else { $session =& JFactory::getSession(); $session->set('litemodeauthorized', 1, 'akeeba'); $this->_setProfile(); jimport('joomla.utilities.date'); AECoreKettenrad::reset(); $memory_filename = AEUtilTempvars::get_storage_filename(AKEEBA_BACKUP_ORIGIN); @unlink($memory_filename); $kettenrad =& AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); if (AKEEBA_JVERSION == '16') { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->format(JText::_('DATE_FORMAT_LC2'), true); } else { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); } $options = array('description' => $description, 'comment' => ''); $kettenrad->setup($options); $ret = $kettenrad->tick(); AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN); $this->setRedirect(JURI::base() . 'index.php?option=com_akeeba&view=light&task=step&key=' . urlencode(JRequest::getVar('key')) . '&profile=' . JRequest::getInt('profile') . '&format=raw'); } }
function build() { $formatedDate = ""; if (!empty($this->dataValue) && $this->dataValue != "0000-00-00" && $this->dataValue != "00:00:00" && $this->dataValue != "0000-00-00 00:00:00") { jimport("joomla.utilities.date"); $date = new JDate($this->dataValue); if ($tz = $this->timezone) { if ($tz == 'server') { //TODO : Get the server timezone $tz = 0; //DBG } else { if ($tz == 'local') { //TODO : Get the current user local timezone $tz = 0; //DBG } } $date->setOffset((int) $tz); } $formatedDate = $date->format($this->dateFormat, !empty($tz)); } $this->addClass('fly-date'); $html = '<span <%STYLE%><%CLASS%><%SELECTORS%>>' . $formatedDate . '</span>'; return $html; }
/** * Starts a backup * @return */ function display() { // Check permissions $this->_checkPermissions(); // Set the profile $this->_setProfile(); // Force the output to be of the raw format type JRequest::setVar('format', 'raw'); $document =& JFactory::getDocument(); $document->setType('raw'); // Get the description, if present; otherwise use the default description jimport('joomla.utilities.date'); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); $default_description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); $description = JRequest::getString('description', $default_description); // Start the backup (CUBE Operation) jpimport('core.cube'); JoomlapackCUBE::reset(); $cube =& JoomlapackCUBE::getInstance(); $cube->start($description, ''); $cube->save(); // Return the JSON output parent::display(false); }
function display() { // Check permissions $this->_checkPermissions(); // Set the profile $this->_setProfile(); // Force the output to be of the raw format type JRequest::setVar('format', 'raw'); $document =& JFactory::getDocument(); $document->setType('raw'); // Start the backup jimport('joomla.utilities.date'); jpimport('core.cube'); JoomlapackCUBE::reset(); $cube =& JoomlapackCUBE::getInstance(); $jconfig =& JFactory::getConfig(); $userTZ = $jconfig->get('config.offset'); /* $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone',0); */ $dateNow = new JDate(); $dateNow->setOffset($userTZ); $cube->start(JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2'), '')); $cube->save(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=backup&task=step&key=' . JRequest::getVar('key') . '&profile=' . JRequest::getInt('profile', 1) . '&format=raw'); parent::display(); }
public function display() { // Check permissions $this->_checkPermissions(); // Set the profile $this->_setProfile(); // Start the backup jimport('joomla.utilities.date'); AECoreKettenrad::reset(); $memory_filename = AEUtilTempvars::get_storage_filename(AKEEBA_BACKUP_ORIGIN); @unlink($memory_filename); $kettenrad =& AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone',0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); if( AKEEBA_JVERSION == '16' ) { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION').' '.$dateNow->format(JText::_('DATE_FORMAT_LC2'), true); } else { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION').' '.$dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); } $options = array( 'description' => $description, 'comment' => '' ); $kettenrad->setup($options); $array = $kettenrad->tick(); $array = $kettenrad->tick(); AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN); if($array['Error'] != '') { // An error occured die('500 ERROR -- '.$array['Error']); } else { $noredirect = JRequest::getInt('noredirect', 0); if($noredirect != 0) { @ob_end_clean(); echo "301 More work required"; flush(); JFactory::getApplication()->close(); } else { $this->setRedirect(JURI::base().'index.php?option=com_akeeba&view=backup&task=step&key='.JRequest::getVar('key').'&profile='.JRequest::getInt('profile',1)); } } }
/** * Returns the backup description * * @param bool $noDefault Set to true to avoid setting a default * @return string */ function getDescription($noDefault = false) { $description = JRequest::getString('description'); if (empty($description) && !$noDefault) { jimport('joomla.utilities.date'); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); return JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); } return $description; }
/** * Retturn list of all event that start with the given month/year */ public function getMonthEvent($month, $year) { $db = JFactory::getDbo(); // Filter event up to 24 hours earlier $date = new JDate(); $date->setOffset(-24); // Select pending event and uncompleted milestone $where = '( (' . $db->nameQuote('type') . '=' . $db->Quote('event') . ' AND ' . $db->nameQuote('start_date') . '>' . $db->Quote($date->toMySQL()) . ')' . ' OR ' . '(' . $db->nameQuote('type') . '=' . $db->Quote('milestone') . ' AND ' . $db->nameQuote('status') . '=' . $db->Quote('0') . ')' . ')'; $where = $db->nameQuote('start_date') . '>= DATE(' . $db->Quote($year . '-' . $month . '-1') . ') '; $where .= ' AND ' . $db->nameQuote('start_date') . '<= DATE_ADD( DATE(' . $db->Quote($year . '-' . $month . '-1') . ') , INTERVAL 1 MONTH ) '; $where2 = $db->nameQuote('end_date') . '>= DATE(' . $db->Quote($year . '-' . $month . '-1') . ') '; $where2 .= ' AND ' . $db->nameQuote('end_date') . '<= DATE_ADD( DATE(' . $db->Quote($year . '-' . $month . '-1') . ') , INTERVAL 1 MONTH ) '; $where2 .= ' AND ' . $db->nameQuote('type') . '=' . $db->Quote('todo'); $my = JXFactory::getUser(); $userGroups = $my->getParam('groups_member'); $where = '( ' . $where . ') AND (' . $db->nameQuote('access') . "=" . $db->Quote(0); if (!empty($userGroups)) { $where .= ' OR ' . $db->nameQuote('group_id') . 'IN (' . $userGroups . ') )'; } else { $where .= ')'; } $where2 = '( ' . $where2 . ') AND (' . $db->nameQuote('access') . "=" . $db->Quote(0); if (!empty($userGroups)) { $where2 .= ' OR ' . $db->nameQuote('group_id') . 'IN (' . $userGroups . ') )'; } else { $where2 .= ')'; } $query = 'SELECT * FROM #__stream WHERE ' . $where . ' UNION SELECT * FROM #__stream WHERE ' . $where2 . ' ORDER BY ' . $db->nameQuote('start_date') . ' ASC'; $db->setQuery($query); $result = $db->loadObjectList(); $rows = array(); if (!empty($result)) { foreach ($result as $row) { $obj = JTable::getInstance('Stream', 'StreamTable'); $obj->bind($row); $rows[] = $obj; } } return $rows; }
function getDateRangeByViewType($date = null, $viewType = 'month') { global $now; $viewType = $viewType == '' ? 'month' : $viewType; if ($date == null) { $date = $now; } else { $arr = explode("/", $date); $date = $arr[2] . "-" . $arr[0] . "-" . $arr[1]; $date = new JDate($date); } switch ($viewType) { case 'month': $startoffset = -($arr[1] + 5); $date->setOffset($startoffset * 24); $startdate = $date->toFormat('%Y-%m-%d'); $endoffest = 35 - $arr[1]; $date->setOffset($endoffest * 24); $enddate = $date->toFormat('%Y-%m-%d'); break; case 'week': $startoffset = -7; $date->setOffset($startoffset * 24); $startdate = $date->toFormat('%Y-%m-%d'); $endoffest = 7; $date->setOffset($endoffest * 24); $enddate = $date->toFormat('%Y-%m-%d'); break; case 'day': $startoffset = -1; $date->setOffset($startoffset * 24); $startdate = $date->toFormat('%Y-%m-%d'); $endoffest = 1; $date->setOffset($endoffest * 24); $enddate = $date->toFormat('%Y-%m-%d'); break; } return array('startdate' => $startdate, 'enddate' => $enddate); }
case 'fail': $status = JText::_('STATS_LABEL_STATUS_FAIL'); break; case 'pending': $status = JText::_('STATS_LABEL_STATUS_PENDING'); break; } jimport('joomla.utilities.date'); $startTime = new JDate($record['backupstart']); $endTime = new JDate($record['backupend']); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone',0); $startTime->setOffset($userTZ); $filename_col = ''; if(empty($record['description'])) $record['description'] = JText::_('STATS_LABEL_NODESCRIPTION'); ?> <tr class="row<?php echo $id; ?>"> <td><?php echo $check; ?></td> <td> <?php echo $this->escape($record['description']) ?> </td> <td> <?php if( AKEEBA_JVERSION == '16' ): ?> <?php echo $startTime->format(JText::_('DATE_FORMAT_LC2'), true); ?> <?php else: ?> <?php echo $startTime->toFormat(JText::_('DATE_FORMAT_LC2')); ?>
/** * Writes a list of the articles * @param array An array of content objects */ function showList(&$rows, $page, $option, $lists) { jimport('joomla.utilities.date'); $limitstart = JRequest::getVar('limitstart', '0', '', 'int'); $user =& JFactory::getUser(); $db =& JFactory::getDBO(); $nullDate = $db->getNullDate(); $config =& JFactory::getConfig(); $now = new JDate(); //Ordering allowed ? $ordering = $lists['order'] == 'fpordering'; JHTML::_('behavior.tooltip'); ?> <form action="index.php?option=com_frontpage" method="post" name="adminForm"> <table> <tr> <td width="100%" class="filter"> <?php echo JText::_('Filter'); ?> : <input type="text" name="search" id="search" value="<?php echo $lists['search']; ?> " class="text_area" onchange="document.adminForm.submit();" /> <button onclick="this.form.submit();"><?php echo JText::_('Go'); ?> </button> <button onclick="document.getElementById('search').value=''; this.form.getElementById('filter_sectionid').value='-1'; this.form.getElementById('catid').value='0'; this.form.getElementById('filter_authorid').value='0'; this.form.getElementById('filter_state').value=''; this.form.submit();"><?php echo JText::_('Reset'); ?> </button> </td> <td nowrap="nowrap"> <?php echo $lists['sectionid']; echo $lists['catid']; echo $lists['authorid']; echo $lists['state']; ?> </td> </tr> </table> <table class="adminlist"> <thead> <tr> <th width="5"> <?php echo JText::_('Num'); ?> </th> <th width="20"> <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?> );" /> </th> <th class="title"> <?php echo JHTML::_('grid.sort', 'Title', 'c.title', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="10%" nowrap="nowrap"> <?php echo JHTML::_('grid.sort', 'Published', 'c.state', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="80" nowrap="nowrap"> <?php echo JHTML::_('grid.sort', 'Order', 'fpordering', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="1%"> <?php echo JHTML::_('grid.order', $rows); ?> </th> <th width="8%" nowrap="nowrap"> <?php echo JHTML::_('grid.sort', 'Access', 'groupname', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="2%" class="title" align="center" nowrap="nowrap"> <?php echo JHTML::_('grid.sort', 'ID', 'c.id', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="10%" class="title"> <?php echo JHTML::_('grid.sort', 'Section', 'sect_name', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="10%" class="title"> <?php echo JHTML::_('grid.sort', 'Category', 'cc.name', @$lists['order_Dir'], @$lists['order']); ?> </th> <th width="10%" class="title"> <?php echo JHTML::_('grid.sort', 'Author', 'author', @$lists['order_Dir'], @$lists['order']); ?> </th> </tr> </thead> <tfoot> <tr> <td colspan="13"> <?php echo $page->getListFooter(); ?> </td> </tr> </tfoot> <tbody> <?php $k = 0; for ($i = 0, $n = count($rows); $i < $n; $i++) { $row =& $rows[$i]; $link = JRoute::_('index.php?option=com_content&task=edit&cid[]=' . $row->id); $publish_up = new JDate($row->publish_up); $publish_down = new JDate($row->publish_down); $publish_up->setOffset($config->getValue('config.offset')); $publish_down->setOffset($config->getValue('config.offset')); if ($now->toUnix() <= $publish_up->toUnix() && $row->state == 1) { $img = 'publish_y.png'; $alt = JText::_('Published'); } else { if (($now->toUnix() <= $publish_down->toUnix() || $row->publish_down == $nullDate) && $row->state == 1) { $img = 'publish_g.png'; $alt = JText::_('Published'); } else { if ($now->toUnix() > $publish_down->toUnix() && $row->state == 1) { $img = 'publish_r.png'; $alt = JText::_('Expired'); } else { if ($row->state == 0) { $img = 'publish_x.png'; $alt = JText::_('Unpublished'); } else { if ($row->state == -1) { $img = 'disabled.png'; $alt = JText::_('Archived'); } } } } } $times = ''; if (isset($row->publish_up)) { if ($row->publish_up == $nullDate) { $times .= JText::_('Start: Always'); } else { $times .= JText::_('Start') . ": " . $publish_up->toFormat(); } } if (isset($row->publish_down)) { if ($row->publish_down == $nullDate) { $times .= "<br />" . JText::_('Finish: No Expiry'); } else { $times .= "<br />" . JText::_('Finish') . ": " . $publish_down->toFormat(); } } $access = JHTML::_('grid.access', $row, $i); $checked = JHTML::_('grid.checkedout', $row, $i); if ($user->authorize('com_users', 'manage')) { if ($row->created_by_alias) { $author = $row->created_by_alias; } else { $linkA = JRoute::_('index.php?option=com_users&task=edit&cid[]=' . $row->created_by); $author = '<span class="editlinktip hasTip" title="' . JText::_('Edit User') . '::' . $row->author . '">' . '<a href="' . $linkA . '">' . $row->author . '</a><span>'; } } else { if ($row->created_by_alias) { $author = $row->created_by_alias; } else { $author = $row->author; } } // section handling if ($row->sectionid) { $row->sect_link = JRoute::_('index.php?option=com_sections&task=edit&cid[]=' . $row->sectionid); $title_sec = JText::_('Edit Section'); } // category handling if ($row->catid) { $row->cat_link = JRoute::_('index.php?option=com_categories&task=edit&cid[]=' . $row->catid); $title_cat = JText::_('Edit Category'); } ?> <tr class="<?php echo "row{$k}"; ?> "> <td> <?php echo $page->getRowOffset($i); ?> </td> <td> <?php echo $checked; ?> </td> <td> <?php if (JTable::isCheckedOut($user->get('id'), $row->checked_out)) { echo $row->title; } else { ?> <span class="editlinktip hasTip" title="<?php echo JText::_('Edit Content'); ?> ::<?php echo $row->name; ?> "> <a href="<?php echo $link; ?> "> <?php echo $row->title; ?> </a></span> <?php } ?> </td> <?php if ($times) { ?> <td align="center"> <span class="editlinktip hasTip" title="<?php echo JText::_('Publish Information'); ?> ::<?php echo $times; ?> "> <a href="javascript:void(0);" onclick="return listItemTask('cb<?php echo $i; ?> ','<?php echo $row->state ? 'unpublish' : 'publish'; ?> ')"> <img src="images/<?php echo $img; ?> " width="16" height="16" border="0" alt="<?php echo $alt; ?> " /></a></span> </td> <?php } ?> <td class="order" colspan="2"> <span><?php echo $page->orderUpIcon($i, true, 'orderup', 'Move Up', $ordering); ?> </span> <span><?php echo $page->orderDownIcon($i, $n, true, 'orderdown', 'Move Down', $ordering); ?> </span> <?php $disabled = $ordering ? '' : 'disabled="disabled"'; ?> <input type="text" name="order[]" size="5" value="<?php echo $row->fpordering; ?> " <?php echo $disabled; ?> class="text_area" style="text-align: center" /> </td> <td align="center"> <?php echo $access; ?> </td> <td align="center"> <?php echo $row->id; ?> </td> <td> <?php if ($row->sectionid) { ?> <span class="editlinktip hasTip" title="<?php echo $title_sec; ?> ::<?php echo $row->sect_name; ?> "> <a href="<?php echo $row->sect_link; ?> "> <?php echo $row->sect_name; ?> </a></span> <?php } ?> </td> <td> <?php if ($row->catid) { ?> <span class="editlinktip hasTip" title="<?php echo $title_cat; ?> ::<?php echo $row->name; ?> "> <a href="<?php echo $row->cat_link; ?> " title="<?php echo $title_cat; ?> "> <?php echo $row->name; ?> </a></span> <?php } ?> </td> <td> <?php echo $author; ?> </td> </tr> <?php $k = 1 - $k; } ?> </tbody> </table> <?php JHTML::_('content.legend'); ?> <input type="hidden" name="option" value="<?php echo $option; ?> " /> <input type="hidden" name="task" value="" /> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?> " /> <input type="hidden" name="filter_order_Dir" value="<?php echo $lists['order_Dir']; ?> " /> <?php echo JHTML::_('form.token'); ?> </form> <?php }
/** * Returns the backup state ('none','start', or 'step') */ private function getBackupState() { $this->debugInfo = '<h6>Akeeba Backup Lazy Mode</h6><hr/>'; // Make sure we're not locked if($this->isLocked()) { $this->debugInfo .= 'Backup locked'; // If the backup has crashed, clean up if($this->isCrashed) { $this->debugInfo .= 'Crashed backup detected'; AEFactory::nuke(); AEUtilTempvars::reset('lazy'); $this->unsetNonce(); $this->unsetLock(); $this->saveStorage(); } else { return 'none'; } } // Is there a backup running? $this->getNonce(); $action = empty($this->nonce) ? 'start' : 'step'; $this->debugInfo .= '<br/>Action: '.$action; // If there is no running backup, try to figure out if we should start // a new backup. if($action == 'start') { // Get the last backup time $lastBackup = $this->getLastBackupTime(); $this->debugInfo .= '<br/>Last backup: '.$lastBackup.' ('.date('Y/m/d H:i:s',$lastBackup).' GMT)'; // Remove the time part of the backup time (we want the date starting at midnight!) $deconstructedDate = getdate($lastBackup); $lastBackup = mktime( 0,0,0, $deconstructedDate['mon'], $deconstructedDate['mday'], $deconstructedDate['year'] ); $this->debugInfo .= '<br/>Adjusted last backup time: '.$lastBackup.' ('.date('Y/m/d H:i:s',$lastBackup).' GMT)'; // Get the preferences and calculate the next backup time $daysfreq = (int)$this->params->get('daysfreq',1); if($daysfreq <= 0) $daysfreq = 1; $this->debugInfo .= '<br/>Days frequency: '.$daysfreq; $daysfreq *= 86400; $backuptime = $this->params->get('backuptime','00:00'); $this->debugInfo .= '<br/>Backup time: '.$backuptime; $backuptime = trim($backuptime); $parts = explode(':',$backuptime); if(count($parts) != 2) { $backuptime = 0; } else { $hours = (int)$parts[0]; $mins = (int)$parts[1]; $backuptime = $hours * 3600 + $mins * 60; } $this->debugInfo .= ' ('.$backuptime.' seconds)'; $nextBackup = $lastBackup + $daysfreq + $backuptime; $this->debugInfo .= '<br/>Next Backup: '.$nextBackup.' ('.date('Y/m/d H:i:s',$nextBackup).' GMT)'; // The next backup time is in GMT. Convert to local. jimport('joomla.utilities.date'); $date = new JDate($nextBackup, 0); $jreg = JFactory::getConfig(); $offset = $jreg->getValue('config.offset'); $date->setOffset($offset); $nextBackup = $date->toUnix(true); $this->debugInfo .= '<br/>Next Backup: '.$nextBackup.' ('.date('Y/m/d H:i:s',$nextBackup).' LOCAL)'; $this->debugInfo .= '<br/>Time Now: '.time().' ('.date('Y/m/d H:i:s').' LOCAL)'; // Is it time for the next backup to run? if( time() < $nextBackup ) { $this->debugInfo .= '<br/>I will not start a new backup.'; } else { $this->debugInfo .= '<br/><strong>Starting new backup.</strong>'; } if( time() < $nextBackup ) return 'none'; // Create a new nonce $this->setNonce(); $this->saveStorage(); } return $action; }
/** * Expands the archive's template name and returns an absolute path * * @param string $extension The extension to append, defaults to '.zip' * @return string The absolute filename of the archive file requested * @static */ function getExpandedTarName($extension = '.zip', $fullPath = true) { $configuration =& JoomlapackModelRegistry::getInstance(); // Get the proper extension $templateName = $configuration->get('TarNameTemplate'); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Archive template name: {$templateName}"); // Get current date/time and express it in user's timezone jimport('joomla.utilities.date'); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); // Parse [DATE] tag $dateExpanded = $dateNow->toFormat("%Y%m%d"); $templateName = str_replace("[DATE]", $dateExpanded, $templateName); // Parse [TIME] tag $timeExpanded = $dateNow->toFormat("%H%M%S"); $templateName = str_replace("[TIME]", $timeExpanded, $templateName); // Parse [HOST] tag $uri =& JURI::getInstance(); $host = $uri->getHost(); $host = empty($host) ? 'unknown_host' : $uri->getHost(); $templateName = str_replace("[HOST]", $_SERVER['SERVER_NAME'], $templateName); // Parse [RANDOM] tag $templateName = str_replace("[RANDOM]", md5(microtime()), $templateName); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Expanded template name: {$templateName}"); if ($fullPath) { $path = $configuration->get('OutputDirectory') . DS . $templateName . $extension; JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Calculated archive absolute path: {$path}"); return JoomlapackHelperUtils::TranslateWinPath($path); } else { return $templateName . $extension; } }
/** * Return locale date * * @param null * @return date object * @since 2.4.2 **/ function getLocaleDate($date = 'now') { $mainframe =& JFactory::getApplication(); if (method_exists('JDate', 'getOffsetFromGMT')) { // Joomla 1.6 $systemOffset = new CDate('now', $mainframe->getCfg('offset')); $systemOffset = $systemOffset->getOffsetFromGMT(true); } else { $systemOffset = $mainframe->getCfg('offset'); // Joomla 1.5 } $now = new JDate($date, $systemOffset); // // Joomla 1.6 $now->setOffset($systemOffset); // // Joomla 1.5 return $now; }
public static function getRelativeDate($value, $countParts = 1) { if (version_compare(JVERSION, '1.6.0', 'ge')) { $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); $now = JFactory::getDate(); $now->setTimeZone($tz); } else { $offset = JFactory::getConfig()->getValue('config.offset'); $now = new JDate(); $now->setOffset($offset); } $date = new JDate($value); $diff = $now->toUnix() - $date->toUnix(); $result = $value; $timeParts = array(31536000 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_YEARS', 2592000 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_MONTHS', 604800 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_WEEKS', 86400 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_DAYS', 3600 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_HOURS', 60 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_MINUTES', 1 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_SECONDS'); if ($diff < 5) { $result = JText::_('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_NOW'); } else { $dayDiff = floor($diff / 86400); $nowDay = date('d', $now->toUnix()); $dateDay = date('d', $date->toUnix()); if ($dayDiff == 1 || $dayDiff == 0 && $nowDay != $dateDay) { $result = JText::_('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_YESTERDAY'); } else { $count = 0; $resultParts = array(); foreach ($timeParts as $key => $value) { if ($diff >= $key) { $time = floor($diff / $key); $resultParts[] = modJCommentsLatestHelper::getPluralText($value, $time); $diff = $diff % $key; $count++; if ($count > $countParts - 1 || $diff == 0) { break; } } } if (count($resultParts)) { $result = JText::sprintf('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_AGO', implode(', ', $resultParts)); } } } return $result; }
/** * Gets the HTML for the pretty backup process pane * * @param array $array The CUBE Array */ function getBackupProcessHTML($array) { if (count($array) <= 0) { $domain = 'finale'; } else { $domain = $array['Domain']; $step = $array['Step']; $substep = $array['Substep']; } // Find current domain's index switch ($domain) { case 'init': $currentDomainIndex = 0; break; case 'installer': $currentDomainIndex = 1; break; case 'PackDB': $currentDomainIndex = 3; break; case 'Packing': $currentDomainIndex = 4; break; case 'finale': default: $currentDomainIndex = 6; break; } // Now, make an array indicating in what state each domain is $domainDisplayArray = array(); $domainDisplayArray[] = JoomlapackHelperBackup::_makeStepArrayEntry(JText::_('BACKUP_LABEL_DOMAIN_PACKDB'), 3, $currentDomainIndex, false); $domainDisplayArray[] = JoomlapackHelperBackup::_makeStepArrayEntry(JText::_('BACKUP_LABEL_DOMAIN_PACKING'), 4, $currentDomainIndex, false); $domainDisplayArray[] = JoomlapackHelperBackup::_makeStepArrayEntry(JText::_('BACKUP_LABEL_DOMAIN_FINISHED'), 5, $currentDomainIndex, false); $gridHTML = ''; foreach ($domainDisplayArray as $dispArray) { $class = $dispArray['class'] == '' ? '' : 'class="' . $dispArray['class'] . '"'; $imageLink = $dispArray['pic'] == '' ? '' : '<img src="' . JURI::base() . 'components/com_joomlapack/assets/images/' . $dispArray['pic'] . '" />'; $gridHTML .= "\t\t\t<tr {$class}>\n"; $gridHTML .= "\t\t\t\t<td>{$imageLink}</td>\n"; $gridHTML .= "\t\t\t\t<td>" . $dispArray['label'] . "</td>\n"; $gridHTML .= "\t\t\t</tr>\n"; } // Create the last response information jimport('joomla.utilities.date'); $dateNow = new JDate('now'); $user =& JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow->setOffset($userTZ); $lastResponseLabel = JText::_('BACKUP_TEXT_LASTRESPONSE'); $lastResponseStamp = $dateNow->toFormat('%H:%M:%S') . ' GMT' . ($userTZ == 0 ? '' : ($userTZ > 0 ? '+' . $userTZ : $userTZ)); $out = <<<ENDXXX1 \t<div class="sitePack"> \t\t<table class="stepstable" align="center"> \t\t\t<thead> \t\t\t\t<tr> \t\t\t\t\t<th width="16"></th> \t\t\t\t\t<th></th> \t\t\t\t</tr> \t\t\t</thead> \t\t\t<tbody> \t\t{$gridHTML} \t\t\t</tbody> \t\t</table> \t\t \t\t<div class="status"> \t\t\t<p id="JPStep">{$step}</p> \t\t\t<p id="JPSubstep">{$substep}</p> \t\t</div> \t\t \t\t<div class="jplastresponse"> \t\t\t<p>{$lastResponseLabel} {$lastResponseStamp}</p> \t\t</div> \t</div> ENDXXX1; return $out; }
private function _apiStartBackup($config) { // Get the passed configuration values $defConfig = array('profile' => 1, 'description' => '', 'comment' => ''); $config = array_merge($defConfig, $config); foreach ($config as $key => $value) { if (!array_key_exists($key, $defConfig)) { unset($config[$key]); } } extract($config); // Nuke the factory AEFactory::nuke(); // Set the profile $profile = (int) $profile; if (!is_numeric($profile)) { $profile = 1; } $session = JFactory::getSession(); $session->set('profile', $profile, 'akeeba'); AEPlatform::getInstance()->load_configuration($profile); // Use the default description if none specified if (empty($description)) { jimport('joomla.utilities.date'); $user = JFactory::getUser(); $userTZ = $user->getParam('timezone', 0); $dateNow = new JDate(); $dateNow->setOffset($userTZ); if (AKEEBA_JVERSION == '16') { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->format(JText::_('DATE_FORMAT_LC2'), true); } else { $description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); } } // Start the backup AECoreKettenrad::reset(array('maxrun' => 0)); AEUtilTempvars::reset(AKEEBA_BACKUP_ORIGIN); $kettenrad = AECoreKettenrad::load(AKEEBA_BACKUP_ORIGIN); $options = array('description' => $description, 'comment' => $comment, 'tag' => AKEEBA_BACKUP_ORIGIN); $kettenrad->setup($options); // Setting up the engine $array = $kettenrad->tick(); // Initializes the init domain AECoreKettenrad::save(AKEEBA_BACKUP_ORIGIN); $array = $kettenrad->getStatusArray(); if ($array['Error'] != '') { // A backup error had occurred. Why are we here?! $this->status = self::STATUS_ERROR; $this->encapsulation = self::ENCAPSULATION_RAW; return 'A backup error had occurred: ' . $array['Error']; } else { $statistics = AEFactory::getStatistics(); $array['BackupID'] = $statistics->getId(); $array['HasRun'] = 1; // Force the backup to go on. return $array; } }
public static function getInputDate($str = '') { require_once JPATH_ROOT . '/components/com_community/libraries/core.php'; $mainframe = JFactory::getApplication(); $config = CFactory::getConfig(); $timeZoneOffset = $mainframe->getCfg('offset'); $dstOffset = $config->get('daylightsavingoffset'); $date = new JDate($str); $my = CFactory::getUser(); $cMy = CFactory::getUser(); if ($my->id) { if (!empty($my->params)) { $timeZoneOffset = $my->getParam('timezone', $timeZoneOffset); $myParams = $cMy->getParams(); $dstOffset = $myParams->get('daylightsavingoffset', $dstOffset); } } $timeZoneOffset = -1 * $timeZoneOffset; $dstOffset = -1 * $dstOffset; $date->setOffset($timeZoneOffset + $dstOffset); return $date; }
/** * This mess of a code is probably not one of my highlights in my code * writing career. It's logically organized, badly architectured but I can * still maintain it - and it works! */ function display() { // Add some buttons JToolBarHelper::back('AKEEBA_CONTROLPANEL', 'index.php?option=' . JRequest::getCmd('option')); JToolBarHelper::spacer(); // Load the Status Helper if (!class_exists('AkeebaHelperStatus')) { JLoader::import('helpers.status', JPATH_COMPONENT_ADMINISTRATOR); } $helper =& AkeebaHelperStatus::getInstance(); // Determine default description jimport('joomla.utilities.date'); $jregistry =& JFactory::getConfig(); $tzDefault = $jregistry->getValue('config.offset'); $user =& JFactory::getUser(); $tz = $user->getParam('timezone', $tzDefault); if (AKEEBA_JVERSION == '16') { $dateNow = new JDate('now', $tz); $backup_description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->format(JText::_('DATE_FORMAT_LC2'), true); } else { $dateNow = new JDate(); $dateNow->setOffset($tz); $backup_description = JText::_('BACKUP_DEFAULT_DESCRIPTION') . ' ' . $dateNow->toFormat(JText::_('DATE_FORMAT_LC2')); } $backup_description = AkeebaHelperEscape::escapeJS($backup_description, "'"); $default_description = $backup_description; $backup_description = JRequest::getVar('description', $default_description); $comment = JRequest::getVar('comment', '', 'default', 'none', 2); // Get a potential return URL $returnurl = JRequest::getVar('returnurl', null); if (empty($returnurl)) { $returnurl = ''; } // If a return URL is set *and* the profile's name is "Site Transfer // Wizard", we are running the Site Transfer Wizard if (!class_exists('AkeebaModelProfiles')) { JLoader::import('models.profiles', JPATH_COMPONENT_ADMINISTRATOR); } if (!class_exists('AkeebaModelCpanel')) { JLoader::import('models.cpanel', JPATH_COMPONENT_ADMINISTRATOR); } $cpanelmodel = new AkeebaModelCpanel(); $profilemodel = new AkeebaModelProfiles(); $profilemodel->setId($cpanelmodel->getProfileID()); $profile_data = $profilemodel->getProfile(); $isSTW = $profile_data->description == 'Site Transfer Wizard (do not rename)' && !empty($returnurl); $this->assign('isSTW', $isSTW); // Get the domain details from scripting facility $registry =& AEFactory::getConfiguration(); $script = $registry->get('akeeba.basic.backup_type', 'full'); $scripting = AEUtilScripting::loadScripting(); $domains = array(); if (!empty($scripting)) { foreach ($scripting['scripts'][$script]['chain'] as $domain) { $description = JText::_($scripting['domains'][$domain]['text']); $domain_key = $scripting['domains'][$domain]['domain']; if ($isSTW && $domain_key == 'Packing') { $description = JText::_('BACKUP_LABEL_DOMAIN_PACKING_STW'); } $domains[] = array($domain_key, $description); } } $json_domains = AkeebaHelperEscape::escapeJS(json_encode($domains), '"\\'); // Get the maximum execution time and bias $maxexec = $registry->get('akeeba.tuning.max_exec_time', 14) * 1000; $bias = $registry->get('akeeba.tuning.run_time_bias', 75); // Check if the output directory is writable $quirks = AEUtilQuirks::get_quirks(); $unwritableOutput = array_key_exists('001', $quirks); // Pass on data $this->assign('haserrors', !$helper->status); $this->assign('hasquirks', $helper->hasQuirks()); $this->assign('quirks', $helper->getQuirksCell(!$helper->status)); $this->assign('description', $backup_description); $this->assign('comment', $comment); $this->assign('domains', $json_domains); $this->assign('maxexec', $maxexec); $this->assign('bias', $bias); $this->assign('useiframe', $registry->get('akeeba.basic.useiframe', 0) ? 'true' : 'false'); $this->assign('returnurl', $returnurl); $this->assign('unwritableoutput', $unwritableOutput); if ($registry->get('akeeba.advanced.archiver_engine', 'jpa') == 'jps') { $this->assign('showjpskey', 1); $this->assign('jpskey', $registry->get('engine.archiver.jps.key', '')); } else { $this->assign('showjpskey', 0); } $this->assign('autostart', JRequest::getInt('autostart', 0)); // Pass on profile info $this->assign('profileid', $cpanelmodel->getProfileID()); // Active profile ID $this->assign('profilelist', $cpanelmodel->getProfilesList()); // List of available profiles // Pass on state information pertaining to SRP $srpinfo = array('tag' => JRequest::getCmd('tag', 'backend'), 'type' => JRequest::getCmd('type', ''), 'name' => JRequest::getCmd('name', ''), 'group' => JRequest::getCmd('group', ''), 'customdirs' => JRequest::getVar('customdirs', array(), 'default', 'array', 2), 'extraprefixes' => JRequest::getVar('extraprefixes', array(), 'default', 'array', 2), 'customtables' => JRequest::getVar('customtables', array(), 'default', 'array', 2), 'xmlname' => JRequest::getString('xmlname', '')); $this->assign('srpinfo', $srpinfo); // Add references to CSS and JS files AkeebaHelperIncludes::includeMedia(false); // Add live help AkeebaHelperIncludes::addHelp(); // Set the toolbar title if ($srpinfo['tag'] == 'restorepoint') { $subtitle = JText::_('AKEEBASRP'); } elseif ($isSTW) { $subtitle = JText::_('SITETRANSFERWIZARD'); } else { $subtitle = JText::_('BACKUP'); } JToolBarHelper::title(JText::_('AKEEBA') . ':: <small>' . $subtitle . '</small>', 'akeeba'); parent::display(JRequest::getCmd('tpl', null)); }
/** * Return standardized formatted date * NOTE: FOR TEMPLATE DISPLAY PURPOSE ONLY!!! DO NOT USE FOR DB QUERIES * Also use only for server generated time, NOT */ static function formatDate($date, $long = self::LONG_DATE_FORMAT, $user = null) { // return original input date that cannot be processed if (strtotime($date) === false) { return $date; } $config = new JXConfig(); // First load account setting (if any) timezone to override timezone in language file $defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE'); $my = !$user instanceof JUser && !$user instanceof JXUser ? JXFactory::getUser() : $user; $timeZoneStr = $my->getParam('timezone'); // Second load user personalize timezone (if any) to override system default timezone $timeZoneStr = empty($timeZoneStr) ? $defaultTz : $timeZoneStr; $tz = new DateTimeZone($timeZoneStr); if ($date instanceof JDate) { $date = $date->format('Y-m-d h:i:s'); } $datenow = new JDate('now', $tz); $offset = $datenow->getOffset() / 3600; $date = new JDate($date); $date->setOffset($offset); $dateStr = $long == self::LONG_DATE_FORMAT ? $date->format(JText::_('JXLIB_DATE_FORMAT'), true) : $date->format(JText::_('JXLIB_DATE_SHORT_FORMAT'), true); if ($long == self::LONG_DATE_FORMAT) { // Test for today $dmy = $datenow->format(JText::_('JXLIB_DATE_DMY'), true); $dateStr = str_replace($dmy, JText::_('JXLIB_DATE_TODAY'), $dateStr); // Test for yesterday $datenow->modify('-1 day'); $dmy = $datenow->format(JText::_('JXLIB_DATE_DMY'), true); $dateStr = str_replace($dmy, JText::_('JXLIB_DATE_YESTERDAY'), $dateStr); } return $dateStr; }
public function ajaxCreate($postData, $objResponse) { $objResponse = new JAXResponse(); $filter = JFilterInput::getInstance(); $postData = $filter->clean($postData, 'array'); //prevent XSS injection foreach ($postData as &$data) { $data = strip_tags($data); } $config = CFactory::getConfig(); $my = CFactory::getUser(); if (!JRequest::checkToken()) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_INVALID_TOKEN')); $objResponse->sendResponse(); } CFactory::load('helpers', 'limits'); if (CLimitsHelper::exceededEventCreation($my->id)) { $eventLimit = $config->get('eventcreatelimit'); $objResponse->addScriptCall('__throwError', JText::sprintf('COM_COMMUNITY_EVENTS_LIMIT', $eventLimit)); $objResponse->sendResponse(); } CFactory::load('helpers', 'event'); $event = JTable::getInstance('Event', 'CTable'); $event->load(); $event->bind($postData); if ($postData['element'] == 'groups') { $event->contentid = $postData['target']; } $handler = CEventHelper::getHandler($event); if (!$handler->creatable()) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_ACCESS_FORBIDDEN')); $objResponse->sendResponse(); } // Format startdate and eendate with time before we bind into event object $this->_formatStartEndDate($postData); if (empty($event->title)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_TITLE_ERROR')); $objResponse->sendResponse(); } if (empty($event->location)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_LOCATION_ERR0R')); $objResponse->sendResponse(); } // @rule: Start date cannot be empty if (empty($event->startdate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } // @rule: End date cannot be empty if (empty($event->enddate)) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_ERROR')); $objResponse->sendResponse(); } require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'time.php'; if (CTimeHelper::timeIntervalDifference($event->startdate, $event->enddate) > 0) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_STARTDATE_GREATER_ERROR')); $objResponse->sendResponse(); } // @rule: Event must not end in the past $now = new JDate(); $jConfig = JFactory::getConfig(); $now->setOffset($jConfig->getValue('offset') + -COMMUNITY_DAY_HOURS); if (CTimeHelper::timeIntervalDifference($now->toMySQL(true), $event->enddate) > 0) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_EVENTS_ENDDATE_GREATER_ERROR')); $objResponse->sendResponse(); } $event->creator = $my->id; //@rule: If event moderation is enabled, event should be unpublished by default $event->published = $config->get('event_moderation') ? 0 : 1; $event->created = JFactory::getDate()->toMySQL(); $event->contentid = $handler->getContentId(); $event->type = $handler->getType(); $event->store(); // Since this is storing event, we also need to store the creator / admin // into the events members table $member = JTable::getInstance('EventMembers', 'CTable'); $member->eventid = $event->id; $member->memberid = $event->creator; // Creator should always be 1 as approved as they are the creator. $member->status = COMMUNITY_EVENT_STATUS_ATTEND; // @todo: Setup required permissions in the future $member->permission = '1'; $member->store(); // Increment the member count $event->updateGuestStats(); $event->store(); $actor = $my->id; $target = 0; $content = ''; $cid = $event->id; $app = 'events'; $act = $handler->getActivity('events.create', $actor, $target, $content, $cid, $app); $url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false, true, false); $act->groupid = $event->type == 'group' ? $event->contentid : null; $act->eventid = $event->id; $act->location = $event->location; $act->comment_id = $event->id; $act->comment_type = 'groups.event'; $act->like_id = $event->id; $act->like_type = 'group.event'; $cat_url = $handler->getFormattedLink('index.php?option=com_community&view=events&task=display&categoryid=' . $event->catid, false, true, false); $params = new CParameter(''); $action_str = 'events.create'; $params->set('action', $action_str); $params->set('event_url', $url); $params->set('event_category_url', $cat_url); // Add activity logging CFactory::load('libraries', 'activities'); CActivityStream::add($act, $params->toString()); // add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint($action_str); $this->triggerEvents('onEventCreate', $event); $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_EVENTS, COMMUNITY_CACHE_TAG_EVENTS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); return $event; }
/** * Returns the current timestamp, taking into account any TZ information, * in the format specified by $format. * @param string $format Timestamp format string (standard PHP format string) * @return string */ public function get_local_timestamp($format) { jimport('joomla.utilities.date'); $jregistry =& JFactory::getConfig(); $tzDefault = $jregistry->getValue('config.offset'); $user =& JFactory::getUser(); $tz = $user->getParam('timezone', $tzDefault); if (version_compare('JVERSION', '1.6.0', 'ge')) { $dateNow = new JDate('now', $tz); } else { $dateNow = new JDate(); $dateNow->setOffset($tz); } return $dateNow->toFormat($format); }
function getLatestComments(&$params) { $limit = $params->get('comments_limit', '5'); $user =& JFactory::getUser(); $aid = $user->get('aid'); $db =& JFactory::getDBO(); $cid = $params->get('category_id', NULL); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php'; $model = new K2ModelItem(); $componentParams =& JComponentHelper::getParams('com_k2'); $query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname FROM #__k2_comments as c" . " LEFT JOIN #__k2_items as i ON i.id=c.itemID" . " LEFT JOIN #__k2_categories as category ON category.id=i.catid" . " WHERE i.published=1 " . " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) " . " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )" . " AND i.trash=0 AND i.access<={$aid}" . " AND category.published=1 AND category.trash=0 AND category.access<={$aid}" . " AND c.published=1 "; if ($params->get('catfilter')) { if (!is_null($cid)) { if (is_array($cid)) { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(" . implode(',', $cid) . ")"; } else { $query .= " AND i.catid=" . (int) $cid; } } } $query .= " ORDER BY c.commentDate DESC "; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@"; if (count($rows)) { foreach ($rows as $row) { if ($params->get('commentDateFormat') == 'relative') { $config =& JFactory::getConfig(); $tzoffset = $config->getValue('config.offset'); $now = new JDate(); $now->setOffset($tzoffset); $created = new JDate($row->commentDate); $diff = $now->toUnix() - $created->toUnix(); $dayDiff = floor($diff / 86400); if ($dayDiff == 0) { if ($diff < 5) { $row->commentDate = JText::_('Just Now'); } elseif ($diff < 60) { $row->commentDate = $diff . ' ' . JText::_('Seconds ago'); } elseif ($diff < 120) { $row->commentDate = JText::_('1 Minute Ago'); } elseif ($diff < 3600) { $row->commentDate = floor($diff / 60) . ' ' . JText::_('Minutes Ago'); } elseif ($diff < 7200) { $row->commentDate = JText::_('1 Hour Ago'); } elseif ($diff < 86400) { $row->commentDate = floor($diff / 3600) . ' ' . JText::_('Hours Ago'); } } } $row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit')); $row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->commentText); $row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->catalias)))); $row->link = $row->itemLink . "#comment{$row->id}"; $row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid . ':' . urlencode($row->catalias)))); if ($row->userID > 0) { $row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID)); } $row->userImage = ''; if ($params->get('commentAvatar')) { $row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth')); } $comments[] = $row; } return $comments; } }
public static function getLatestComments(&$params) { $mainframe = JFactory::getApplication(); $limit = $params->get('comments_limit', '5'); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $cid = $params->get('category_id', NULL); $jnow = JFactory::getDate(); $now = K2_JVERSION != '15' ? $jnow->toSql() : $jnow->toMySQL(); $nullDate = $db->getNullDate(); $model = K2Model::getInstance('Item', 'K2Model'); $componentParams = JComponentHelper::getParams('com_k2'); $query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname\n\t\tFROM #__k2_comments as c\n\t\tLEFT JOIN #__k2_items as i ON i.id=c.itemID\n\t\tLEFT JOIN #__k2_categories as category ON category.id=i.catid\n\t\tWHERE i.published=1\n\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\tAND i.trash=0 "; if (K2_JVERSION != '15') { $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND i.access<={$aid} "; } $query .= " AND category.published=1 AND category.trash=0 "; if (K2_JVERSION != '15') { $query .= " AND category.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; } else { $query .= " AND category.access<={$aid} "; } $query .= " AND c.published=1 "; if ($params->get('catfilter')) { if (!is_null($cid)) { if (is_array($cid)) { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(" . implode(',', $cid) . ")"; } else { $query .= " AND i.catid=" . (int) $cid; } } } if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND category.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } $query .= " ORDER BY c.commentDate DESC "; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@"; if (count($rows)) { foreach ($rows as $row) { if ($params->get('commentDateFormat') == 'relative') { $config = JFactory::getConfig(); $tzoffset = K2_JVERSION == '30' ? $config->get('config.offset') : $config->getValue('config.offset'); $now = new JDate(); $now->setOffset($tzoffset); $created = new JDate($row->commentDate); $diff = $now->toUnix() - $created->toUnix(); $dayDiff = floor($diff / 86400); if ($dayDiff == 0) { if ($diff < 5) { $row->commentDate = JText::_('K2_JUST_NOW'); } elseif ($diff < 60) { $row->commentDate = $diff . ' ' . JText::_('K2_SECONDS_AGO'); } elseif ($diff < 120) { $row->commentDate = JText::_('K2_1_MINUTE_AGO'); } elseif ($diff < 3600) { $row->commentDate = floor($diff / 60) . ' ' . JText::_('K2_MINUTES_AGO'); } elseif ($diff < 7200) { $row->commentDate = JText::_('K2_1_HOUR_AGO'); } elseif ($diff < 86400) { $row->commentDate = floor($diff / 3600) . ' ' . JText::_('K2_HOURS_AGO'); } } } $row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit')); $row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->commentText); $row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->catalias)))); $row->link = $row->itemLink . "#comment{$row->id}"; $row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid . ':' . urlencode($row->catalias)))); if ($row->userID > 0) { $row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID)); $getExistingUser = JFactory::getUser($row->userID); $row->userUsername = $getExistingUser->username; } else { $row->userUsername = $row->userName; } // Switch between commenter name and username if ($params->get('commenterName', 1) == 2) { $row->userName = $row->userUsername; } $row->userImage = ''; if ($params->get('commentAvatar')) { $row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth')); } $comments[] = $row; } return $comments; } }
function getFormattedDate($strdate, $format = 'd m Y') { jimport('joomla.utilities.date'); $user =& JFactory::getUser(); if ($user->get('id')) { $tz = $user->getParam('timezone'); } else { $conf =& JFactory::getConfig(); $tz = $conf->getValue('config.offset'); } // Given time $jdate = new JDate($strdate); $jdate->setOffset($tz); $date = $jdate->toISO8601(); return Date_Difference::getStringResolved($date); }
/** * Returns the current timestamp, taking into account any TZ information, * in the format specified by $format. * @param string $format Timestamp format string (standard PHP format string) * @return string */ public function get_local_timestamp($format) { require_once JPATH_ROOT . '/libraries/joomla/base/object.php'; require_once JPATH_ROOT . '/libraries/joomla/utilities/date.php'; $tz = AEUtilJconfig::getValue('offset'); $format = str_replace('%A', date('%A'), $format); $dateNow = new JDate(); $dateNow->setOffset($tz); return $dateNow->toFormat($format); }
function showLoggedInMembers($option, &$rows) { global $mainframe; jimport('joomla.utilities.date'); $date = new JDate('now'); $tzoffset = $mainframe->getCfg('offset'); $date->setOffset($tzoffset); $timeStr = $date->toFormat("%l:%M %P"); $dateStr = $date->toFormat("%A, %B %e, %G"); //$tzEST = new DateTimeZone('America/New_York'); //$date = new DateTime("now", $tzEST); //$date = new DateTime("now"); //$timeStr = $date->format("g:i a"); //$dateStr = $date->format("l, F jS Y"); ?> <h2>There are currently <?php print count($rows); ?> members clocked in at <?php print "{$timeStr} on {$dateStr}"; ?> </h2> <form action="index.php" method="post" name="adminForm" id="adminForm"> <input type="hidden" name="option" value="<?php echo $option; ?> " /> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="task" value="" /> Clock out time: <?php echo "<select name=\"hour\">"; for ($q = 1; $q < 24; $q++) { echo "<option "; if ($q == 21) { echo "selected "; } echo "value=\"" . $q . "\">" . $q; } echo "</select><select name=\"minute\"><option value=\"0\">00</option>"; for ($q = 1; $q < 4; $q++) { echo "<option value=\"" . 15 * $q . "\">" . 15 * $q . "</option>"; } ?> </select><br> <table class="adminlist"> <thead> <tr> <th width="20px"> <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?> );" /> </th> <th width="50%">Name</th> <th width="15%">Email</th> <th width="10%">Emergency Phone</th> <th width="10%">Time in</th> <th width="10%">For</th> <th width="5%">Member?</th> </tr> </thead> <?php $k = 0; for ($i = 0, $n = count($rows); $i < $n; $i++) { $row =& $rows[$i]; $checked = JHTML::_('grid.id', $i, $row->transid); $link = JFilterOutput::ampReplace('index.php?option=' . $option . '&task=edit&cid[]=' . $row->id); ?> <tr class="<?php echo "row{$k}"; ?> "> <td> <?php echo $checked; ?> </td> <td> <a href="<?php echo $link; ?> "><?php echo $row->nameFirst . ' ' . $row->nameLast; ?> </a> </td> <td> <?php echo $row->emailAddress; ?> </td> <td> <?php echo $row->phoneEmerg; ?> </td> <td> <?php echo $row->dateOpen; ?> </td> <td> </td> <td align="center"> <?php echo $row->isMember ? JHTML::image('administrator/images/tick.png', 'yes') : JHTML::image('administrator/images/publish_x.png', 'yes'); ?> </td> </tr> <?php $k = 1 - $k; } ?> </table> </form> <?php }
public function getUpcomingHotEvent($filter = null, $limit = 6) { if ($filter == null) { $filter = array(); } // Filter event up to 24 hours earlier $date = new JDate(); $date->setOffset(-24); $filter['type'] = 'event'; $filter['start_date'] = $date->toMySQL(); $filter['order_by'] = 'length(`followers`) DESC'; $model = StreamFactory::getModel('stream'); $data = $model->getStream($filter, $limit); $group = JTable::getInstance('group', 'StreamTable'); $my = JXFactory::getUser(); $count = 0; $pendingEvent = array(); foreach ($data as $index => $event) { if ($count >= 6) { break; } $group->load($event->group_id); if (!$my->authorise('stream.group.read', $group)) { continue; } $pendingEvent[] = $event; $count++; } $tmpl = new StreamTemplate(); $tmpl->set('events', $pendingEvent); $tmpl->set('title', JText::_('COM_STREAM_LABEL_POPULAR_EVENTS')); $html = $tmpl->fetch('group.module.eventlist'); return $html; }
/** * This will return the user timezone * @param int $user_id id of the user * @param String $forDisplay get the display, if true then return value will be formatted to the proper display * @return String depends on the value of format */ public static function getUserTime($user_id = null, $forDisplay = false) { $config = new JXConfig(); $user = JFactory::getUser($user_id); // First load account setting (if any) timezone to override timezone in language file $defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE'); $my = !$user instanceof JUser && !$user instanceof JXUser ? JXFactory::getUser() : $user; $timeZoneStr = $my->getParam('timezone'); // Second load user personalize timezone (if any) to override system default timezone $timeZoneStr = empty($timeZoneStr) ? $defaultTz : $timeZoneStr; $tz = new DateTimeZone($timeZoneStr); $date2 = new JDate('now', $tz); $offset = $date2->getOffset() / 3600; $date = new JDate(); $date->setOffset($offset); $xdate = new JXDate(); /* if the value want to be used as display purposes */ if ($forDisplay) { return $xdate->formatDate($date); } else { return $xdate->format($date); } }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.*')); $query->from($db->quoteName('#__users') . ' AS a'); // If the model is set to check item state, add to the query. $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where('a.block = ' . (int) $state); } // If the model is set to check the activated state, add to the query. $active = $this->getState('filter.active'); if (is_numeric($active)) { if ($active == '0') { $query->where('a.activation = ' . $db->quote('')); } elseif ($active == '1') { $query->where($query->length('a.activation') . ' = 32'); } } // Filter the items over the group id if set. $groupId = $this->getState('filter.group_id'); $groups = $this->getState('filter.groups'); if ($groupId || isset($groups)) { $query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id'); $query->group('a.id,a.name,a.username,a.password,a.usertype,a.block,a.sendEmail,a.registerDate,a.lastvisitDate,a.activation,a.params,a.email'); if ($groupId) { $query->where('map2.group_id = ' . (int) $groupId); } if (isset($groups)) { $query->where('map2.group_id IN (' . implode(',', $groups) . ')'); } } // Filter the items over the search string if set. if ($this->getState('filter.search') !== '') { // Escape the search token. $token = $db->Quote('%' . $db->escape($this->getState('filter.search')) . '%'); // Compile the different search clauses. $searches = array(); $searches[] = 'a.name LIKE ' . $token; $searches[] = 'a.username LIKE ' . $token; $searches[] = 'a.email LIKE ' . $token; // Add the clauses to the query. $query->where('(' . implode(' OR ', $searches) . ')'); } // Add filter for registration ranges select list $range = $this->getState('filter.range'); // Apply the range filter. if ($range = $this->getState('filter.range')) { jimport('joomla.utilities.date'); // Get UTC for now. $dNow = new JDate(); $dStart = clone $dNow; switch ($range) { case 'past_week': $dStart->modify('-7 day'); break; case 'past_1month': $dStart->modify('-1 month'); break; case 'past_3month': $dStart->modify('-3 month'); break; case 'past_6month': $dStart->modify('-6 month'); break; case 'post_year': case 'past_year': $dStart->modify('-1 year'); break; case 'today': // Ranges that need to align with local 'days' need special treatment. $app = JFactory::getApplication(); $offset = $app->getCfg('offset'); // Reset the start time to be the beginning of today, local time. $dStart = new JDate('now', $offset); $dStart->setTime(0, 0, 0); // Now change the timezone back to UTC. $dStart->setOffset(0); break; } if ($range == 'post_year') { $query->where('a.registerDate < ' . $db->quote($dStart->format('Y-m-d H:i:s'))); } else { $query->where('a.registerDate >= ' . $db->quote($dStart->format('Y-m-d H:i:s')) . ' AND a.registerDate <=' . $db->quote($dNow->format('Y-m-d H:i:s'))); } } // Filter by excluded users $excluded = $this->getState('filter.excluded'); if (!empty($excluded)) { $query->where('id NOT IN (' . implode(',', $excluded) . ')'); } // Add the list ordering clause. $query->order($db->escape($this->getState('list.ordering', 'a.name')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); return $query; }