本文整理匯總了PHP中JDate::toUnix方法的典型用法代碼示例。如果您正苦於以下問題:PHP JDate::toUnix方法的具體用法?PHP JDate::toUnix怎麽用?PHP JDate::toUnix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JDate
的用法示例。
在下文中一共展示了JDate::toUnix方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: filterByTime
/**
* Filter by time, either on registration or last visit date.
*
* @param JDate $starting Starting date or null if older than ending date.
* @param JDate $ending Ending date or null if newer than starting date.
* @param bool $register True = registration date, False = last visit date.
*
* @return $this
*/
public function filterByTime(JDate $starting = null, JDate $ending = null, $register = true)
{
$name = $register ? 'registerDate' : 'lastvisitDate';
if ($starting && $ending) {
$this->query->where("a.{$name} BETWEEN {$this->db->quote($starting->toUnix())} AND {$this->db->quote($ending->toUnix())}");
} elseif ($starting) {
$this->query->where("a.{$name} > {$this->db->quote($starting->toUnix())}");
} elseif ($ending) {
$this->query->where("a.{$name} <= {$this->db->quote($ending->toUnix())}");
}
return $this;
}
示例2: XmapNav
function XmapNav(&$config, &$sitemap) {
$this->_list=array();
$this->view='navigator';
global $mainframe;
jimport('joomla.utilities.date');
$user =& JFactory::getUser();
$access = new stdClass();
$access->canEdit = $user->authorize('com_content', 'edit', 'content', 'all');
$access->canEditOwn = $user->authorize('com_content', 'edit', 'content', 'own');
$access->canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
$this->access = &$access;
$date = new JDate();
$this->noauth = $mainframe->getCfg( 'shownoauth' );
$this->gid = $user->get('gid');
$this->now = $date->toUnix();
$this->config = &$config;
$this->sitemap = &$sitemap;
$this->isNews = false;
$this->_isAdmin = ($this->gid == "25");
}
示例3: getShortDate
/**
* Returns date/time in short format. i.e. 6m, 6h, 6d, 6w, 6m, 6y etc
* @param unknown $date
* @return Ambigous <string, string, mixed, multitype:>|Ambigous <string, string, mixed>
*/
public static function getShortDate($date)
{
if (empty($date) || $date == '0000-00-00 00:00:00') {
return JText::_('LBL_NA');
}
jimport('joomla.utilities.date');
$user = JFactory::getUser();
// Given time
$date = new JDate(JHtml::date($date, 'Y-m-d H:i:s'));
$compareTo = new JDate(JHtml::date('now', 'Y-m-d H:i:s'));
$diff = $compareTo->toUnix() - $date->toUnix();
$diff = abs($diff);
$dayDiff = floor($diff / 86400);
if ($dayDiff == 0) {
if ($diff < 120) {
return '1m';
} elseif ($diff < 3600) {
return floor($diff / 60) . 'm';
} else {
return floor($diff / 3600) . 'h';
}
} elseif ($dayDiff < 7) {
return $dayDiff . 'd';
} elseif ($dayDiff < 7 * 6) {
return ceil($dayDiff / 7) . 'w';
} elseif ($dayDiff < 365) {
return ceil($dayDiff / (365 / 12)) . 'm';
} else {
return round($dayDiff / 365) . 'y';
}
}
示例4: onAKSubscriptionChange
/**
* Called whenever a subscription is modified. Namely, when its enabled status,
* payment status or valid from/to dates are changed.
*/
public function onAKSubscriptionChange($row, $info)
{
if (is_null($info['modified']) || empty($info['modified'])) {
return;
}
//if(!array_key_exists('enabled', (array)$info['modified'])) return;
// Load the plugin's language files
$lang = JFactory::getLanguage();
$lang->load('plg_akeebasubs_invoices', JPATH_ADMINISTRATOR, 'en-GB', true);
$lang->load('plg_akeebasubs_invoices', JPATH_ADMINISTRATOR, null, true);
// Akeeba Subscriptions language files
$lang->load('com_akeebasubs', JPATH_SITE, 'en-GB', true);
$lang->load('com_akeebasubs', JPATH_SITE, $lang->getDefault(), true);
$lang->load('com_akeebasubs', JPATH_SITE, null, true);
$lang->load('com_akeebasubs', JPATH_ADMINISTRATOR, 'en-GB', true);
$lang->load('com_akeebasubs', JPATH_ADMINISTRATOR, $lang->getDefault(), true);
$lang->load('com_akeebasubs', JPATH_ADMINISTRATOR, null, true);
// Do not issue invoices for free subscriptions
if ($row->gross_amount < 0.01) {
return;
}
// Should we handle this subscription?
$generateAnInvoice = $row->state == "C";
$whenToGenerate = $this->params->get('generatewhen', '0');
if ($whenToGenerate == 1) {
// Handle new subscription, even if they are not yet enabled
$specialCasePending = in_array($row->state, array('P', 'C')) && !$row->enabled;
$generateAnInvoice = $generateAnInvoice || $specialCasePending;
}
// If the payment is over a week old do not generate an invoice. This
// prevents accidentally creating an invoice for pas subscriptions not
// handled by ccInvoices
JLoader::import('joomla.utilities.date');
$jCreated = new JDate($row->created_on);
$jNow = new JDate();
$dateDiff = $jNow->toUnix() - $jCreated->toUnix();
if ($dateDiff > 604800) {
return;
}
// Only handle not expired subscriptions
if ($generateAnInvoice && !defined('AKEEBA_INVOICE_GENERATED')) {
define('AKEEBA_INVOICE_GENERATED', 1);
$db = JFactory::getDBO();
// Check if there is an invoice for this subscription already
$query = $db->getQuery(true)->select('*')->from('#__akeebasubs_invoices')->where($db->qn('akeebasubs_subscription_id') . ' = ' . $db->q($row->akeebasubs_subscription_id));
$db->setQuery($query);
$oldInvoices = $db->loadObjectList('akeebasubs_subscription_id');
if (count($oldInvoices) > 0) {
return;
}
// Create (and, optionally, send) a new invoice
F0FModel::getAnInstance('Invoices', 'AkeebasubsModel')->createInvoice($row);
}
}
示例5: onAfterParseData
public function onAfterParseData($params)
{
$db = JFactory::getDbo();
$table = new JTableJed($db);
$table->load(array('md5url' => md5($params->get('url'))));
$lastUpdate = new JDate($params->get('data.last_update'));
$dateAdded = new JDate($params->get('data.date_added'));
$today = new JDate();
$table->url = $params->get('url');
$table->md5url = md5($table->url);
$table->title = $params->get('data.title', '');
$table->alias = JApplication::stringURLSafe($table->title);
$table->fulltext = $params->get('data.description', '');
$table->introtext = $this->getIntrotext($table->fulltext);
$table->catid = $this->getCategory($params);
$table->avatar = $this->getAvatar($params);
$table->gallery = $this->getGallery($params);
$table->featured = $params->get('data.feature', '') == '' ? false : true;
$table->popular = $params->get('data.popular', '') == '' ? false : true;
$table->component = $params->get('data.component', '') == '' ? false : true;
$table->module = $params->get('data.module', '') == '' ? false : true;
$table->plugin = $params->get('data.plugin', '') == '' ? false : true;
$table->language = $params->get('data.language', '') == '' ? false : true;
$table->specific = $params->get('data.specific', '') == '' ? false : true;
$table->compat_15 = $params->get('data.compat_15', '') == '' ? false : true;
$table->compat_25 = $params->get('data.compat_25', '') == '' ? false : true;
$table->compat_30 = $params->get('data.compat_30', '') == '' ? false : true;
$table->version = $params->get('data.version', '');
$table->date_added = $dateAdded->toSql();
$table->last_update = $lastUpdate->toSql();
$table->rating = $params->get('data.rating', 0);
$table->rating_count = $params->get('data.rating_user', 0);
$table->rating_sum = round($table->rating * $table->rating_count);
$table->favorite = $params->get('data.favorite', 0);
$table->license = $params->get('data.license', '');
$table->view = $params->get('data.view', 0);
$table->developer = $params->get('data.developer', '');
$table->website = $this->getRedirectUrl($params->get('data.website'));
$table->download_url = $params->get('data.download_link');
$table->demo_url = $params->get('data.demo_link');
$table->support_url = $params->get('data.support_link');
$table->document_url = $params->get('data.document_link');
$time = $today->toUnix() - $dateAdded->toUnix();
$days = $time / (60 * 60 * 24) + 1;
$table->ordering = floor($table->view / $days);
if (!$table->id) {
$table->state = 1;
}
//print_r($params);
//print_r($table);die();
if ($table->store()) {
$params->set('success', true);
}
}
示例6: loadChartData
function loadChartData()
{
$db = $this->getDBO();
$type = JRequest::getCmd('type');
switch ($type) {
case 'sales':
jimport('joomla.utilities.date');
$date = JFactory::getDate();
$interval = JRequest::getInt('interval', '14');
$today = $date->toFormat('%Y-%m-%d');
$startDate = strtotime('-' . $interval . ' day', strtotime($today));
$startDate = new JDate($startDate);
$query = "SELECT COUNT(virtuemart_order_id) AS sales, DATE(created_on) as `date` FROM #__virtuemart_orders WHERE created_on > " . $db->Quote($startDate->toMySQL()) . " GROUP BY `date` ORDER BY `date`";
$db->setQuery($query);
$rows = $db->loadObjectList();
$data = array();
foreach ($rows as $row) {
$data[$row->date] = (int) $row->sales;
}
$today = $date->toUnix();
for ($time = $startDate->toUnix(); $time <= $today; $time += 86400) {
$date = date('Y', $time) . '-' . date('m', $time) . '-' . date('d', $time);
if (!array_key_exists($date, $data)) {
$data[$date] = 0;
}
}
ksort($data);
$startYear = $startDate->toFormat('%Y');
$startMonth = $startDate->toFormat('%m') - 1;
$startDay = $startDate->toFormat('%d');
$script = "\r\n k2martSalesChartOptions.title.text = '" . JText::_('K2MART_TOTAL_SALES', true) . "';\r\n k2martSalesChartOptions.subtitle.text = '* " . JText::_('K2MART_CLICK_AND_DRAG_IN_THE_PLOT_AREA_TO_ZOOM_IN', true) . "';\r\n k2martSalesChartOptions.yAxis.title.text = '" . JText::_('K2MART_SALES', true) . "';\r\n k2martSalesChartOptions.series[0].pointStart=Date.UTC(" . $startYear . ", " . $startMonth . ", " . $startDay . "); \r\n k2martSalesChartOptions.series[0].data=[" . implode(',', $data) . "];\r\n ";
break;
case 'products':
$limit = JRequest::getInt('limit', '20');
$query = "SELECT product.product_sales, productData.product_name FROM #__virtuemart_products AS product \r\n LEFT JOIN #__virtuemart_products_" . VMLANG . " AS productData ON product.virtuemart_product_id = productData.virtuemart_product_id\r\n WHERE product.product_sales > 0 ORDER BY product.product_sales DESC LIMIT 0, {$limit}";
$db->setQuery($query);
$rows = $db->loadObjectList();
$data = array();
$categories = array();
foreach ($rows as $row) {
$data[] = (int) $row->product_sales;
$categories[] = "'" . $row->product_name . "'";
}
$script = "\r\n k2martProductsChartOptions.title.text = '" . JText::_('K2MART_TOP_SELLING_PRODUCTS', true) . "';\r\n k2martProductsChartOptions.yAxis.title.text = '" . JText::_('K2MART_SALES', true) . "';\r\n k2martProductsChartOptions.xAxis.categories =[" . implode(',', $categories) . "]; \r\n k2martProductsChartOptions.series[0].data=[" . implode(',', $data) . "];\r\n ";
break;
}
$script .= "k2martChartType = '{$type}';";
echo $script;
}
示例7: onAfterInitialise
/**
* Run the session cleaner (garbage collector) on a schedule
*/
public function onAfterInitialise()
{
$minutes = (int) $this->params->get('ses_freq', 0);
if ($minutes <= 0) {
return;
}
$lastJob = $this->getTimestamp('session_clean');
$nextJob = $lastJob + $minutes * 60;
JLoader::import('joomla.utilities.date');
$now = new JDate();
if ($now->toUnix() >= $nextJob) {
$this->setTimestamp('session_clean');
$this->purgeSession();
}
}
示例8: timeLapse
/**
*
* @param JDate $date
*
*/
public static function timeLapse($date)
{
$now = new JDate();
$dateDiff = CTimeHelper::timeDifference($date->toUnix(), $now->toUnix());
if ($dateDiff['days'] > 0) {
$lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['days']) ? 'CC LAPSED DAY MANY' : 'CC LAPSED DAY', $dateDiff['days']);
} elseif ($dateDiff['hours'] > 0) {
$lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['hours']) ? 'CC LAPSED HOUR MANY' : 'CC LAPSED HOUR', $dateDiff['hours']);
} elseif ($dateDiff['minutes'] > 0) {
$lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['minutes']) ? 'CC LAPSED MINUTE MANY' : 'CC LAPSED MINUTE', $dateDiff['minutes']);
} else {
$lapse = JText::sprintf(CStringHelper::isPlural($dateDiff['seconds']) ? 'CC LAPSED SECOND MANY' : 'CC LAPSED SECOND', $dateDiff['seconds']);
}
return $lapse;
}
示例9: onAfterInitialise
public function onAfterInitialise()
{
$minutes = (int) $this->params->get('cleantemp_freq', 0);
if ($minutes <= 0) {
return;
}
$lastJob = $this->getTimestamp('clean_temp');
$nextJob = $lastJob + $minutes * 60;
JLoader::import('joomla.utilities.date');
$now = new JDate();
if ($now->toUnix() >= $nextJob) {
$this->setTimestamp('clean_temp');
$this->tempDirectoryCleanup();
}
}
示例10: validate
public function validate($data)
{
if (empty($data) or !is_array($data)) {
throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARDS"));
}
$filter = JFilterInput::getInstance();
$params = JComponentHelper::getParams("com_crowdfunding");
/** @var $params Joomla\Registry\Registry */
// Create a currency object.
$currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency"));
// Create the object "amount".
$amount = new Crowdfunding\Amount($params);
$amount->setCurrency($currency);
foreach ($data as $key => $item) {
$item["amount"] = $amount->setValue($item["amount"])->parse();
// Filter data
if (!is_numeric($item["amount"])) {
$item["amount"] = 0;
}
$item["title"] = $filter->clean($item["title"], "string");
$item["title"] = Joomla\String\String::trim($item["title"]);
$item["title"] = Joomla\String\String::substr($item["title"], 0, 128);
$item["description"] = $filter->clean($item["description"], "string");
$item["description"] = Joomla\String\String::trim($item["description"]);
$item["description"] = Joomla\String\String::substr($item["description"], 0, 500);
$item["number"] = (int) $item["number"];
$item["delivery"] = Joomla\String\String::trim($item["delivery"]);
$item["delivery"] = $filter->clean($item["delivery"], "string");
if (!empty($item["delivery"])) {
$date = new JDate($item["delivery"]);
$unixTime = $date->toUnix();
if ($unixTime < 0) {
$item["delivery"] = "";
}
}
if (!$item["title"]) {
throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_TITLE"));
}
if (!$item["description"]) {
throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION"));
}
if (!$item["amount"]) {
throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"));
}
$data[$key] = $item;
}
return $data;
}
示例11: validate
public function validate($data)
{
if (!is_array($data) or count($data) === 0) {
throw new InvalidArgumentException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_REWARDS'));
}
$filter = JFilterInput::getInstance();
$params = JComponentHelper::getParams('com_crowdfunding');
/** @var $params Joomla\Registry\Registry */
// Create a currency object.
$currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get('project_currency'));
// Create the object 'amount'.
$amount = new Crowdfunding\Amount($params);
$amount->setCurrency($currency);
foreach ($data as $key => &$item) {
$item['amount'] = $amount->setValue($item['amount'])->parse();
// Filter data
if (!is_numeric($item['amount'])) {
$item['amount'] = 0;
}
$item['title'] = $filter->clean($item['title'], 'string');
$item['title'] = JString::trim($item['title']);
$item['title'] = JString::substr($item['title'], 0, 128);
$item['description'] = $filter->clean($item['description'], 'string');
$item['description'] = JString::trim($item['description']);
$item['description'] = JString::substr($item['description'], 0, 500);
$item['number'] = (int) $item['number'];
$item['delivery'] = JString::trim($item['delivery']);
$item['delivery'] = $filter->clean($item['delivery'], 'string');
if (!empty($item['delivery'])) {
$date = new JDate($item['delivery']);
$unixTime = $date->toUnix();
if ($unixTime < 0) {
$item['delivery'] = '';
}
}
if (!$item['title']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_TITLE'));
}
if (!$item['description']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION'));
}
if (!$item['amount']) {
throw new RuntimeException(JText::_('COM_CROWDFUNDING_ERROR_INVALID_AMOUNT'));
}
}
unset($item);
return $data;
}
示例12: onProcessList
public function onProcessList(&$resultArray)
{
// Implement the coupon automatic expiration
if (empty($resultArray)) {
return;
}
if ($this->getState('skipOnProcessList', 0)) {
return;
}
JLoader::import('joomla.utilities.date');
$jNow = new JDate();
$uNow = $jNow->toUnix();
$table = $this->getTable($this->table);
$k = $table->getKeyName();
foreach ($resultArray as $index => &$row) {
$triggered = false;
if (!property_exists($row, 'publish_down')) {
continue;
}
if (!property_exists($row, 'publish_up')) {
continue;
}
if ($row->publish_down && $row->publish_down != '0000-00-00 00:00:00') {
$regex = '/^\\d{1,4}(\\/|-)\\d{1,2}(\\/|-)\\d{2,4}[[:space:]]{0,}(\\d{1,2}:\\d{1,2}(:\\d{1,2}){0,1}){0,1}$/';
if (!preg_match($regex, $row->publish_down)) {
$row->publish_down = '2037-01-01';
}
if (!preg_match($regex, $row->publish_up)) {
$row->publish_up = '2001-01-01';
}
$jDown = new JDate($row->publish_down);
$jUp = new JDate($row->publish_up);
if ($uNow >= $jDown->toUnix() && $row->enabled) {
$row->enabled = 0;
$triggered = true;
} elseif ($uNow >= $jUp->toUnix() && !$row->enabled && $uNow < $jDown->toUnix()) {
$row->enabled = 1;
$triggered = true;
}
}
if ($triggered) {
$table->reset();
$table->load($row->{$k});
$table->save($row);
}
}
}
示例13: add
/**
* Append the given comment to the particular content.
*
* @return, full-text of the content
*/
public function add($actor, $comment, $content)
{
$commentJson = '';
$json = new Services_JSON();
$comments = $this->getCommentsData($content);
// Once we retrive the comment, we can remove them
$content = preg_replace('/\\<comment\\>(.*?)\\<\\/comment\\>/i', '', $content);
$newComment = new stdClass();
$date = new JDate();
$newComment->creator = $actor;
$newComment->text = $comment;
$newComment->date = $date->toUnix();
$comments[] = $newComment;
$commentJson = $json->encode($comments);
$content .= '<comment>' . $commentJson . '</comment>';
return $content;
}
示例14: jimport
function __construct($config, $sitemap)
{
jimport('joomla.utilities.date');
jimport('joomla.user.helper');
$user = JFactory::getUser();
$groups = array_keys(JUserHelper::getUserGroups($user->get('id')));
$date = new JDate();
$this->userLevels = (array) $user->getAuthorisedViewLevels();
// Deprecated: should use userLevels from now on
// $this->gid = $user->gid;
$this->now = $date->toUnix();
$this->config = $config;
$this->sitemap = $sitemap;
$this->isNews = false;
$this->count = 0;
$this->canEdit = false;
}
示例15: getStatic
/**
* Get the rendering of this field type for static display, e.g. in a single
* item view (typically a "read" task).
*
* @since 2.0
*/
public function getStatic()
{
// Initialize some field attributes.
$format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
// Get some system objects.
$config = JFactory::getConfig();
$user = JFactory::getUser();
// If a known filter is given use it.
switch (strtoupper((string) $this->element['filter'])) {
case 'SERVER_UTC':
// Convert a date to UTC based on the server timezone.
if ((int) $this->value) {
// Get a date object based on the correct timezone.
$date = JFactory::getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($config->get('offset')));
// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);
}
break;
case 'USER_UTC':
// Convert a date to UTC based on the user timezone.
if ((int) $this->value) {
// Get a date object based on the correct timezone.
$date = JFactory::getDate($this->value, 'UTC');
$date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
// Transform the date string.
$this->value = $date->format('Y-m-d H:i:s', true, false);
}
break;
}
jimport('joomla.utilities.date');
$jDue = new JDate($this->value);
$jNow = new JDate();
$daysLeft = $jDue->toUnix() - $jNow->toUnix();
if ($daysLeft < 0) {
$class = 'todo-due-overdue';
} elseif ($daysLeft < 7) {
$class = 'todo-due-closing';
} else {
$class = 'todo-due-enoughtime';
}
$html = '<span class="' . $class . '">' . $jDue->format(JText::_('DATE_FORMAT_LC'), true, true) . '</span>';
return $html;
}