Example #1
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/disable_timestamp_timezone_adjustment')) {
             $dateObj = new Zend_Date();
             $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP);
         }
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/zend_date_gmt_offset')) {
                 // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, we replace + with - below if affected by this.
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
             } else {
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
             }
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
	/**
	 *
	 * @param string $value
	 * @return Zend_Date
	 */
    public function filter($value){
		$d = new Zend_Date();
		$d->setTimezone('Europe/London');
		$d->set($value, 'yyyy-MM-dd hh-mm-ss');
		$d->setTimezone();
		return $d;
	}
Example #3
0
 /**
  * Convert given date string with UTC timezone into default locale format
  * and locale timezone
  *
  * @param string $date date string in SQL format with UTC timezone
  * @return Zend_Date
  */
 public static function getDateFromDb($date)
 {
     if (!is_string($date)) {
         throw new Zmz_Date_Exception('$date must be a string');
     }
     $tmpDate = new Zend_Date();
     $tmpDate->setTimezone('UTC');
     $tmpDate->set($date, self::SQL_DATETIME);
     $tmpDate->setTimezone(Zmz_Culture::getTimezone());
     return $tmpDate;
 }
Example #4
0
 public function eventCalendarAction()
 {
     $viewer = Engine_Api::_()->user()->getViewer();
     //Get user month
     $oldTz = date_default_timezone_get();
     date_default_timezone_set($viewer->timezone);
     $month = $this->_getParam('month', date('m'));
     $year = $this->_getParam('year', date('y'));
     date_default_timezone_set($oldTz);
     $search = Engine_Api::_()->ynevent()->getDateSearch($month, $year);
     $eventTable = Engine_Api::_()->getItemTable('event');
     //Get first date and last day in month server time zone
     $events = $eventTable->getAllEventsInMonth($search[0], $search[1]);
     // var_dump($events);die;
     $event_count = array();
     $i = 0;
     if (count($events)) {
         $eventDates = array();
         foreach ($events as $event) {
             //convert start time to user time zone
             $dateObject = new Zend_Date(strtotime($event->starttime));
             $dateObject->setTimezone($viewer->timezone);
             $event_count[$dateObject->toString('yyyy-MM-dd')][] = $event->event_id;
         }
         date_default_timezone_set($oldTz);
         foreach ($event_count as $index => $evt) {
             $eventDates[$i]['day'] = $index;
             $eventDates[$i]['event_count'] = count($evt);
             $i++;
         }
         $this->view->eventDates = $eventDates;
     }
 }
Example #5
0
 /**
  * Returns the date.
  *
  * @return Zend_Date
  */
 public function getDate()
 {
     $date = new Zend_Date(0);
     $date->setTimezone('UTC');
     $date->set($this->getText(), $this->_format ? $this->_format : Zend_Date::ISO_8601);
     return $date;
 }
Example #6
0
 /**
  * Convert given date string with UTC timezone into default locale format
  * and locale timezone
  *
  * @param string $date date string in SQL format with UTC timezone
  * @param string $defaultDate date to use if $date is null
  * @return Zend_Date
  */
 public static function getDateFromDb($date, $defaultDate = null)
 {
     if ($defaultDate == null) {
         $defaultDate = "1970-01-01 00:00:00";
     }
     if (null === $date) {
         $date = $defaultDate;
     }
     if (!is_string($date)) {
         throw new Exception('$date must be a string');
     }
     $tmpDate = new Zend_Date();
     $tmpDate->setTimezone('UTC');
     $tmpDate->set($date, self::SQL_DATETIME);
     $tmpDate->setTimezone(Zmz_Culture::getTimezone());
     return $tmpDate;
 }
Example #7
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Example #8
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, replace + with - below if you're affected by this.
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Example #9
0
 public function getNow()
 {
     if ($this->_now === null) {
         require_once 'Zend/Date.php';
         $date = new Zend_Date('en_US');
         $date->setTimezone('UTC');
         $this->_now = $date->get('YYYY-MM-dd HH:mm:ss');
     }
     return $this->_now;
 }
Example #10
0
 public function getAtom()
 {
     $table = $this->_controller->getFrontController()->getBlogPackage()->getPostsTable();
     $whereClauses = array("publish = '1'", $this->_controller->getDatabase()->quoteInto('blogId = ?', $this->_controller->getEntity()->getAncestorId()));
     $select = $table->select()->order('cdate DESC')->limit(20, 0);
     foreach ($whereClauses as $clause) {
         if ($clause) {
             $select->where($clause);
         }
     }
     $items = $table->fetchAll($select);
     $data = array('title' => $this->_rssTitle, 'link' => $this->_rssLink, 'charset' => 'UTF-8', 'email' => $this->_rssEmail, 'webmaster' => $this->_rssWebmaster, 'generator' => 'sitengine', 'language' => 'en');
     foreach ($items as $item) {
         $row = $table->complementRow($item);
         #Sitengine_Debug::print_r($row);
         $args = array(Sitengine_Env::PARAM_ANCESTORID => $this->_controller->getEntity()->getAncestorSlug(), Sitengine_Env::PARAM_ID => $row['id']);
         $route = $this->_controller->getFrontController()->getRouter()->getRoute(Sitengine_Blog_Frontend_Front::ROUTE_BLOGS_POSTS_SHARP);
         $uriView = $this->_controller->getRequest()->getBasePath() . '/' . $route->assemble($args, true);
         require_once 'Zend/Date.php';
         $date = new Zend_Date($item->cdate, 'yyyy-MM-dd HH:mm:ss');
         $date->setTimezone('UTC');
         $cdate = $date->get(Zend_Date::TIMESTAMP);
         $post = array('link' => 'http://' . $_SERVER['SERVER_NAME'] . $uriView, 'comments' => 'http://' . $_SERVER['SERVER_NAME'] . $uriView, 'lastUpdate' => $cdate);
         #print $item->cdate.'<br />';
         #html_entity_decode(strip_tags($row['info']), ENT_COMPAT, 'UTF-8')
         switch ($row['type']) {
             case Sitengine_Blog_Posts_Table::TYPE_VIDEO:
                 $postDetail = array('title' => $row['title'], 'description' => '(Video) ' . $row['teaser'], 'content' => $row['teaser']);
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_AUDIO:
                 $postDetail = array('title' => $row['title'], 'description' => '(Audio) ' . html_entity_decode(strip_tags($row['markup']), ENT_COMPAT, 'UTF-8'), 'content' => $row['markup'], 'enclosure' => array(array('url' => $row['file1OriginalUri'], 'type' => $row['file1OriginalMime'])));
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_LINK:
                 $postDetail = array('title' => $row['title'], 'description' => $row['teaser'], 'content' => $row['teaser']);
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_QUOTE:
                 $postDetail = array('title' => $row['teaser'], 'description' => $row['title'] ? 'Quote By ' . $row['title'] : 'Quote', 'content' => $row['title'] ? 'Quote By ' . $row['title'] : 'Quote');
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_GALLERY:
                 $postDetail = array('title' => $row['title'], 'description' => $row['teaser'], 'content' => $row['markup']);
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_PHOTO:
                 $postDetail = array('title' => $row['title'], 'description' => html_entity_decode(strip_tags($row['markup']), ENT_COMPAT, 'UTF-8'), 'content' => $row['markup']);
                 break;
             case Sitengine_Blog_Posts_Table::TYPE_TEXT:
                 $postDetail = array('title' => $row['title'], 'description' => $row['teaser'], 'content' => $row['markup']);
                 break;
         }
         $data['entries'][] = array_merge($post, $postDetail);
     }
     require_once 'Zend/Uri/Http.php';
     require_once 'Zend/Feed.php';
     $atom = Zend_Feed::importArray($data, 'atom');
     return $atom->send();
 }
Example #11
0
 /**
  * @see Document_Tag_Interface::setDataFromEditmode
  * @param mixed $data
  * @return void
  */
 public function setDataFromEditmode($data)
 {
     if (strlen($data) > 5) {
         // ext 2.0 returns the selected date in UTC
         date_default_timezone_set("UTC");
         $this->date = new Pimcore_Date($data, Zend_Date::ISO_8601);
         $this->date->setTimezone(Pimcore_Config::getSystemConfig()->general->timezone);
         // set default timezone
         date_default_timezone_set(Pimcore_Config::getSystemConfig()->general->timezone);
     }
 }
Example #12
0
 public function getGivenDate()
 {
     $viewer = Engine_Api::_()->user()->getViewer();
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     $givenDate = new Zend_Date(strtotime($this->given_date));
     $givenDate->setTimezone($timezone);
     return $givenDate;
 }
 public function saveAction()
 {
     $this->_isAllowed();
     if ($data = $this->getRequest()->getPost()) {
         $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
         $localeCode = Mage::app()->getLocale()->getLocaleCode();
         if (empty($data['date_from'])) {
             $from = new Zend_Date();
         } else {
             $from = new Zend_Date($data['date_from'], $dateFormatIso, $localeCode);
         }
         $data['date_from'] = $from->setTimezone('utc')->toString(Varien_Date::DATE_INTERNAL_FORMAT);
         if (empty($data['date_to'])) {
             $to = new Zend_Date();
             $to->addMonth(1);
         } else {
             $to = new Zend_Date($data['date_to'], $dateFormatIso, $localeCode);
         }
         $data['date_to'] = $to->setTimezone('utc')->toString(Varien_Date::DATE_INTERNAL_FORMAT);
         if (!isset($data['store_view'])) {
             $data['store_view'][] = '0';
         }
         if ($data['store_view'][0] == '0') {
             $stores = Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true);
             foreach ($stores as $store) {
                 if (is_array($store['value'])) {
                     foreach ($store['value'] as $value) {
                         $data['store_view'][] = $value['value'];
                     }
                 }
             }
         }
         $model = Mage::getModel('promotional/promotional');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('promotional')->__('Popup was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
                 return;
             }
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('promotional')->__('Unable to find Popup to save'));
     $this->_redirect('*/*/');
 }
Example #14
0
 /**
  * Format a date based on locale and timezone
  *
  * @param	string	$date		Timestamp
  * @param	string	$timezone	Timezone to use
  * @param	string	$format		Format to output date in
  */
 public function formatDate($date, $timezone = null, $format = null)
 {
     if (!$date) {
         return false;
     }
     $zendDate = new Zend_Date($date, Zend_Date::ISO_8601, Zend_Registry::get('Zend_Locale'));
     if ($timezone) {
         $zendDate->setTimezone($timezone);
     }
     if ($format) {
         return $zendDate->get($format);
     }
     return $zendDate;
 }
Example #15
0
 /**
  * Filter select object by date since.
  *
  * @param Zend_Db_Select $select
  * @param string $dateSince ISO 8601 formatted date
  * @param string $dateField "added" or "modified"
  */
 public function filterBySince($select, $dateSince, $dateField)
 {
     // Reject invalid date fields.
     if (!in_array($dateField, array('added', 'modified'))) {
         return;
     }
     // Accept an ISO 8601 date, set the tiemzone to the server's default
     // timezone, and format the date to be MySQL timestamp compatible.
     $date = new Zend_Date($dateSince, Zend_Date::ISO_8601);
     $date->setTimezone(date_default_timezone_get());
     $date = $date->get('yyyy-MM-dd HH:mm:ss');
     // Select all dates that are greater than the passed date.
     $select->where("files.{$dateField} > ?", $date);
 }
Example #16
0
 public function indexAction()
 {
     // Prepare data
     $this->view->event = $event = Engine_Api::_()->core()->getSubject();
     $this->view->fullAddress = $event->getFullAddress();
     // Convert the dates for the viewer
     $tz = date_default_timezone_get();
     $viewer = Engine_Api::_()->user()->getViewer();
     $startDateObject = new Zend_Date(strtotime($event->starttime));
     if ($viewer->getIdentity()) {
         $tz = $viewer->timezone;
     }
     $startDateObject->setTimezone($tz);
     $this->view->startDateObject = $startDateObject;
 }
Example #17
0
 public static function getCsvFile($params)
 {
     $data_output = array();
     $separator = ',';
     $c = $params['offset'];
     $row = array('#');
     $columns_keys = array();
     foreach ($params['columns'] as $k => $value) {
         $columns_keys[] = $k;
         $row[] = $value;
     }
     $data_output[] = implode($separator, $row);
     foreach ($params['data'] as $item) {
         $row = array($c++);
         foreach ($columns_keys as $h) {
             $data = $item->get($h);
             if (($h == 'from' || $h == 'to' || $h == 'urt' || $h == 'notify_time') && $data) {
                 if (!empty($item["tzoffset"])) {
                     // TODO change this to regex; move it to utils
                     $tzoffset = $item['tzoffset'];
                     $sign = substr($tzoffset, 0, 1);
                     $hours = substr($tzoffset, 1, 2);
                     $minutes = substr($tzoffset, 3, 2);
                     $time = $hours . ' hours ' . $minutes . ' minutes';
                     if ($sign == "-") {
                         $time .= ' ago';
                     }
                     $timsetamp = strtotime($time, $item['urt']->sec);
                     $zend_date = new Zend_Date($timsetamp);
                     $zend_date->setTimezone('UTC');
                     $row[] = $zend_date->toString("d/M/Y H:m:s") . $item['tzoffset'];
                 } else {
                     $zend_date = new Zend_Date($data->sec);
                     $row[] = $zend_date->toString("d/M/Y H:m:s");
                 }
             } else {
                 $row[] = $data;
             }
         }
         $data_output[] = implode($separator, $row);
     }
     $output = implode(PHP_EOL, $data_output);
     header("Cache-Control: max-age=0");
     header("Content-type: application/csv");
     header("Content-Disposition: attachment; filename=csv_export.csv");
     die($output);
 }
Example #18
0
 /**
  * Build Apache_Solr_Document from Zoo_Content_Interface object
  *
  * @param Zoo_Content_Interface $item
  * @return Apache_Solr_Document
  */
 protected function _build(Zoo_Content_Interface $item)
 {
     // (Re-)Index document
     $document = new Apache_Solr_Document();
     $document->nid = $item->id;
     $document->title = $item->title;
     list($content) = Zoo::getService('content')->getRenderedContent($item->id, 'Display');
     $document->contents = strip_tags($content);
     $document->link = $item->url();
     $document->type = $item->type;
     $document->uid = $item->uid;
     // Index wants a W3C canonical timestamp in GMT _WITH_ Z at the end
     $date = new Zend_Date($item->published, Zend_Date::TIMESTAMP);
     $date->setTimezone('gmt');
     $document->published = str_replace("+00:00", "Z", $date->get(Zend_Date::W3C));
     return $document;
 }
Example #19
0
 /** 
  * Takes a "field" and grabs all the corresponding disparate fields from $_POST and translates into a timestamp
  * @param string $field The name of the field to translate
  * @param array $arr = null The array containing the value. If null (default) we'll use $_POST
  * @return string|false $dateTime In case of success returns the timestamp (in the format 'Y-m-d H:i:s' or 'Y-m-d'), otherwise returns false ($field value is not in the array) or '' (if $field value is empty).
  * If $field has both date and time, the resulting value will be converted fro user timezone to system timezone.
  * If $field has only date and not time, no timezone conversion will occur. 
  */
 public function translate($field, $arr = null)
 {
     if ($arr == null) {
         $arr = $_POST;
     }
     /* @var $dateHelper DateHelper */
     $dateHelper = Loader::helper('date');
     if (isset($arr[$field . '_dt'])) {
         $value = $arr[$field . '_dt'];
         if (strlen(trim($value)) === 0) {
             return '';
         }
         $format = defined('CUSTOM_DATE_APP_GENERIC_MDY') ? CUSTOM_DATE_APP_GENERIC_MDY : t('n/j/Y');
         $h = is_numeric($arr[$field . '_h']) ? $arr[$field . '_h'] : '00';
         $m = is_numeric($arr[$field . '_m']) ? $arr[$field . '_m'] : '00';
         if (isset($arr[$field . '_a'])) {
             if ($arr[$field . '_a'] === 'AM') {
                 $a = $dateHelper->date('A', mktime(1));
             } else {
                 $a = $dateHelper->date('A', mktime(13));
             }
             $value .= " {$h}:{$m} {$a}";
             $format .= ' h:i A';
         } else {
             $value .= " {$h}:{$m}";
             $format .= ' H:i';
         }
         $d = new Zend_Date();
         $d->setTimezone($dateHelper->getTimezone('user'));
         $d->set($value, $format, Localization::activeLocale());
         return $dateHelper->formatCustom('Y-m-d H:i:s', $d, 'system');
     } elseif (isset($arr[$field])) {
         $value = $arr[$field];
         if (strlen(trim($value)) === 0) {
             return '';
         }
         $format = defined('CUSTOM_DATE_APP_GENERIC_MDY') ? CUSTOM_DATE_APP_GENERIC_MDY : t('n/j/Y');
         $d = new Zend_Date();
         $d->setTimezone($dateHelper->getTimezone('system'));
         $d->set($value, $format, Localization::activeLocale());
         return $dateHelper->formatCustom('Y-m-d', $d, 'system');
     } else {
         return false;
     }
 }
 public function getTotal($type, $start = null, $end = null)
 {
     $select = new Zend_Db_Select($this->getAdapter());
     $select->from($this->info('name'), 'SUM(value) as sum')->where('type = ?', $type);
     // Can pass "today" into start
     $date = new Zend_Date();
     $date->setTimezone(Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'));
     switch ($start) {
         case 'day':
             $start = $date->setTime('00:00:00')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") + 1, gmdate("Y"));
             break;
         case 'week':
             $start = $date->setTime('00:00:00')->setWeekday(0)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") - gmdate('N') + 1, gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j") - gmdate('N') + 1 + 7, gmdate("Y"));
             break;
         case 'month':
             $start = $date->setTime('00:00:00')->setDate(1)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n") + 1, gmdate("j"), gmdate("Y"));
             break;
         case 'year':
             $start = $date->setTime('00:00:00')->setDayOfYear(1)->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y"));
             $end = $date->setTime('23:59:59')->toValue();
             // mktime(0, 0, 0, gmdate("n"), gmdate("j"), gmdate("Y") + 1);
             break;
     }
     if (null !== $start) {
         $select->where('date >= ?', gmdate('Y-m-d H:i:s', $start));
     }
     if (null !== $end) {
         $select->where('date < ?', gmdate('Y-m-d H:i:s', $end));
     }
     $data = $select->query()->fetch();
     if (!isset($data['sum'])) {
         return 0;
     }
     return $data['sum'];
 }
 public function timeShift($datetime)
 {
     if ($this->_timezone == 'PST') {
         $dateObj = new Zend_Date($datetime, null, Mage::app()->getLocale()->getLocaleCode());
         $dateObj->setTimezone('America/Los_Angeles');
         $dateObj->set($datetime, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setTimezone('UTC');
         return $dateObj->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
     } elseif ($this->_timezone == 'PST4PM') {
         $dateObj = new Zend_Date($datetime, null, Mage::app()->getLocale()->getLocaleCode());
         $dateObj->setTimezone('EST');
         $dateObj->set($datetime, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setTimezone('America/Denver');
         return $dateObj->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
     } else {
         //UTC
         return $datetime;
     }
 }
Example #22
0
 public function insert()
 {
     try {
         $parentId = $this->_controller->getEntity()->getAncestorId();
         $fields = $this->_getFields();
         $input = $this->_controller->getRequest()->getPost(null);
         $id = Sitengine_String::createId();
         $data = $this->_controller->getFrontController()->getBlogPackage()->getCommentsTable()->getDefaultPermissionData($this->_controller->getPermiso(), $this->_controller->getFrontController()->getBlogPackage()->getOwnerGroup());
         if (!$this->_checkInput()) {
             return null;
         }
         foreach ($fields[self::FIELDS_ONOFF] as $k => $v) {
             $data[$k] = array_key_exists($k, $input) ? 1 : 0;
         }
         foreach ($fields[self::FIELDS_NORMAL] as $k => $v) {
             $data[$k] = array_key_exists($k, $input) ? $input[$k] : $v;
         }
         $data['id'] = $id;
         $data['parentId'] = $parentId;
         $date = new Zend_Date();
         $date->setTimezone('UTC');
         $data['cdate'] = $date->get('YYYY-MM-dd HH:mm:ss', Sitengine_Env::LANGUAGE_EN);
         $data['mdate'] = $data['cdate'];
         $data['origin'] = $this->_controller->getFrontController()->getBlogPackage()->getName();
         #Sitengine_Debug::print_r($data);
         $data['approve'] = 1;
         $insertId = $this->_controller->getFrontController()->getBlogPackage()->getCommentsTable()->insertOrRollback($data);
         if (!$insertId) {
             $error = $this->_controller->getFrontController()->getBlogPackage()->getCommentsTable()->getError();
             if ($error === null) {
                 return null;
             }
             $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($error));
             $this->_controller->getStatus()->addHint('record', $message);
             return null;
         }
         return $data;
     } catch (Exception $exception) {
         require_once 'Sitengine/Blog/Frontend/Blogs/Posts/Comments/Exception.php';
         throw new Sitengine_Blog_Frontend_Blogs_Posts_Comments_Exception('insert error', $exception);
     }
 }
Example #23
0
 public function reauthenticate(Zend_Auth_Adapter_Interface $adapter, $id)
 {
     $result = $adapter->reauthenticate($id);
     if ($result->isValid()) {
         require_once 'Zend/Session.php';
         Zend_Session::regenerateId();
         $user = $adapter->getResultRowObject();
         $this->getStorage()->write($user->name);
         $this->getStorage()->writeData($user);
         $this->getStorage()->writeExpires(time() + $this->_lifetime);
         $this->getStorage()->writeIpAddress($_SERVER['REMOTE_ADDR']);
         require_once 'Zend/Date.php';
         $date = new Zend_Date();
         $date->setTimezone('UTC');
         $now = $date->get(Zend_Date::ISO_8601);
         $data = array('lastLogin' => $now, 'lastRequest' => $now);
         $adapter->update($user->id, $data);
     }
     return $result;
 }
Example #24
0
 protected function _getMainSection()
 {
     try {
         $data = $this->_controller->getFrontController()->getBlogPackage()->getFilesTable()->complementRow($this->_controller->getEntity()->getRow());
         $name = 'cdate';
         $date = new Zend_Date($data[$name], Zend_Date::ISO_8601, $this->_controller->getLocale());
         $date->setTimezone($this->_controller->getPreferences()->getTimezone());
         $data[$name] = $date->get(Zend_Date::DATE_FULL) . ' ';
         $data[$name] .= $date->get(Zend_Date::TIME_FULL);
         $name = 'mdate';
         $date = new Zend_Date($data[$name], Zend_Date::ISO_8601, $this->_controller->getLocale());
         $date->setTimezone($this->_controller->getPreferences()->getTimezone());
         $data[$name] = $date->get(Zend_Date::DATE_LONG) . ' ';
         $data[$name] .= $date->get(Zend_Date::TIME_LONG);
         return $data;
     } catch (Exception $exception) {
         require_once 'Sitengine/Blog/Frontend/Blogs/Posts/Files/Exception.php';
         throw new Sitengine_Blog_Frontend_Blogs_Posts_Files_Exception('main section error', $exception);
     }
 }
Example #25
0
 public function log($source, $action, $code = null, $message = null)
 {
     try {
         /*
         if(
         	!$this->_permiso->getAuth()->hasIdentity() &&
         	($source != 'permiso' && $action != 'login')
         ) {
         	return false;
         }
         */
         require_once 'Sitengine_String.php';
         require_once 'Zend/Date.php';
         $date = new Zend_Date();
         $date->setTimezone('UTC');
         $data = array('id' => Sitengine_String::createId(), 'uid' => $this->_permiso->getAuth()->getId(), 'name' => $this->_permiso->getAuth()->getIdentity(), 'cdate' => $date->get(Zend_Date::ISO_8601), 'ip' => $_SERVER['REMOTE_ADDR'], 'source' => $source, 'action' => $action, 'code' => $code, 'message' => $message);
         return $this->_database->insert($this->_permiso->getAuditTableName(), $data);
     } catch (Exception $exception) {
         require_once 'Sitengine/Permiso/Exception.php';
         throw new Sitengine_Permiso_Exception('log error', $exception);
     }
 }
Example #26
0
 public function filterLs($lsResult, $io)
 {
     $_lsResult = array();
     foreach ($lsResult as $r) {
         if ($io->getUdbatchGrep() && !fnmatch($io->getUdbatchGrep(), $r['text']) || $io->isDir($r['text'])) {
             continue;
         }
         $_lsResult[] = $r;
     }
     $lsResult = $_lsResult;
     if ($io->getUdbatch() && ($dateFilter = $io->getUdbatch()->getDatetimeFilter())) {
         $filterFrom = null;
         if ('0000-00-00 00:00:00' != $dateFilter[0] && !empty($dateFilter[0])) {
             $filterFrom = new Zend_Date();
             $filterFrom->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
             $filterFrom->set($dateFilter[0], Varien_Date::DATETIME_INTERNAL_FORMAT);
             $filterFrom->setTimezone($dateFilter[2]);
         }
         $filterTo = null;
         if ('0000-00-00 00:00:00' != $dateFilter[1] && !empty($dateFilter[1])) {
             $filterTo = new Zend_Date();
             $filterTo->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
             $filterTo->set($dateFilter[1], Varien_Date::DATETIME_INTERNAL_FORMAT);
             $filterTo->setTimezone($dateFilter[2]);
         }
         $_lsResult = array();
         foreach ($lsResult as $r) {
             $filter = new Zend_Date();
             $filter->setTimezone($dateFilter[2]);
             $filter->set($io->mdtm($r['text']));
             if ((empty($filterFrom) || $filter->compare($filterFrom) >= 0) && (empty($filterTo) || $filter->compare($filterTo) == -1)) {
                 $_lsResult[] = $r;
             }
         }
         $lsResult = $_lsResult;
     }
     return $lsResult;
 }
Example #27
0
 protected function mapDirectiveSalePriceEffectiveDate($params = array())
 {
     /** @var $product Mage_Catalog_Model_Product */
     $product = $this->getProduct();
     $assocMapArr = $this->getAssocMaps();
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     $cell = "";
     if (!$this->hasSpecialPrice($product, $this->getSpecialPrice($product))) {
         return $cell;
     }
     $has_default_qty = $this->_hasDefaultQty($assocMapArr);
     $display_min = $this->getConfigVar('grouped_price_display_mode', 'columns');
     if ($has_default_qty) {
         if ($display_min == RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_SUM_DEFAULT_QTY) {
             $product_from_date = $product_to_date = null;
             $from_time = -1;
             $to_time = PHP_INT_MAX;
             foreach ($assocMapArr as $assocMap) {
                 $associatedProduct = $assocMap->getProduct();
                 if ($associatedProduct->getQty() > 0) {
                     if ($assocMap->hasSpecialPrice($associatedProduct, $assocMap->getSpecialPrice($associatedProduct))) {
                         if ($assocMap->hasPriceByCatalogRules($associatedProduct)) {
                             // Current date to cdate + ttl
                             $fromDate = clone $cDate;
                             $fromDate->setTime('00:00:00', 'HH:mm:ss');
                             $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
                             if ($timezone) {
                                 $toDate->setTimezone($timezone);
                             }
                             $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
                             $toDate->setTime('23:59:59', 'HH:mm:ss');
                             $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
                             $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00');
                             $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59');
                         } else {
                             $compare_from_date = $associatedProduct->getSpecialFromDate();
                             $compare_to_date = $associatedProduct->getSpecialToDate();
                         }
                         if ($from_time < $this->dateToTime($compare_from_date)) {
                             $product_from_date = $compare_from_date;
                             $from_time = $this->dateToTime($product_from_date);
                         }
                         if (!is_empty_date($compare_to_date) && $to_time > $this->dateToTime($compare_to_date)) {
                             $product_to_date = $compare_to_date;
                             $to_time = $this->dateToTime($product_to_date);
                         }
                     }
                 }
             }
         } else {
             // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT
             $minAssocMap = $this->findMinimalPriceProduct($assocMapArr);
             if ($minAssocMap === false) {
                 return $cell;
             }
             $associatedProduct = $minAssocMap->getProduct();
             if ($minAssocMap->hasPriceByCatalogRules($associatedProduct)) {
                 // Current date to cdate + ttl
                 $fromDate = clone $cDate;
                 $fromDate->setTime('00:00:00', 'HH:mm:ss');
                 $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
                 if ($timezone) {
                     $toDate->setTimezone($timezone);
                 }
                 $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
                 $toDate->setTime('23:59:59', 'HH:mm:ss');
                 $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
                 $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00');
                 $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59');
             } else {
                 $compare_from_date = $associatedProduct->getSpecialFromDate();
                 $compare_to_date = $associatedProduct->getSpecialToDate();
             }
             $product_from_date = $compare_from_date;
             $product_to_date = $compare_to_date;
         }
     } else {
         // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT
         $minAssocMap = $this->findMinimalPriceProduct($assocMapArr);
         if ($minAssocMap === false) {
             return $cell;
         }
         $associatedProduct = $minAssocMap->getProduct();
         $product_from_date = $associatedProduct->getSpecialFromDate();
         $product_to_date = $associatedProduct->getSpecialToDate();
     }
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     if ($product_from_date) {
         $fromDate->setDate(substr($product_from_date, 0, 10), 'yyyy-MM-dd');
         $fromDate->setTime(substr($product_from_date, 11, 8), 'HH:mm:ss');
     }
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if (!is_empty_date($product_to_date)) {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate(substr($product_to_date, 0, 10), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
     } else {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
         $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY);
     }
     $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601);
     return $cell;
 }
Example #28
0
 public function chartAction()
 {
     // Disable layout and viewrenderer
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $viewer = Engine_Api::_()->user()->getViewer();
     // Get params
     $start = $this->_getParam('start');
     $offset = $this->_getParam('offset', 0);
     $type = $this->_getParam('type', 'all');
     $mode = $this->_getParam('mode');
     $chunk = $this->_getParam('chunk');
     $period = $this->_getParam('period');
     $periodCount = $this->_getParam('periodCount', 1);
     $campaign_ids = $this->_getParam('campaign_ids');
     // Validate chunk/period
     if (!$chunk || !in_array($chunk, $this->_periods)) {
         $chunk = Zend_Date::DAY;
     }
     if (!$period || !in_array($period, $this->_periods)) {
         $period = Zend_Date::MONTH;
     }
     if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) {
         die('whoops');
         return;
     }
     // Validate start
     if ($start && !is_numeric($start)) {
         $start = strtotime($start);
     }
     if (!$start) {
         $start = time();
     }
     // Fixes issues with month view
     Zend_Date::setOptions(array('extend_month' => true));
     // Get timezone
     $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT');
     if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) {
         $timezone = $viewer->timezone;
     }
     // Make start fit to period?
     $startObject = new Zend_Date($start);
     $startObject->setTimezone($timezone);
     $partMaps = $this->_periodMap[$period];
     foreach ($partMaps as $partType => $partValue) {
         $startObject->set($partValue, $partType);
     }
     // Do offset
     if ($offset != 0) {
         $startObject->add($offset, $period);
     }
     $arr_campaigns = array();
     if ($campaign_ids) {
         $arr_campaigns = explode(',', $campaign_ids);
     }
     // Get end time
     $endObject = new Zend_Date($startObject->getTimestamp());
     $endObject->setTimezone($timezone);
     $endObject->add($periodCount, $period);
     $endObject->sub(1, Zend_Date::SECOND);
     // Subtract one second
     $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads');
     if (count($arr_campaigns)) {
         $adList = $adTbl->fetchAll($adTbl->select()->from($adTbl->info("name"), 'ad_id')->where('campaign_id IN (?)', $arr_campaigns));
         $adList = $adList->toArray();
     } else {
         $adList = array();
     }
     // Get data
     $staTable = Engine_Api::_()->getDbtable('statistics', 'ynsocialads');
     $staName = $staTable->info('name');
     if ($type != "all") {
         $select = $staTable->select();
         // Get data
         if (count($adList)) {
             $select->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             if ($type != "all") {
                 $select->where('type = ?', $type);
             }
             $rawData = $staTable->fetchAll($select);
         } else {
             $rawData = array();
         }
         // Now create data structure
         $currentObject = clone $startObject;
         $nextObject = clone $startObject;
         $data = array();
         $dataLabels = array();
         $cumulative = 0;
         $previous = 0;
         do {
             $nextObject->add(1, $chunk);
             $currentObjectTimestamp = $currentObject->getTimestamp();
             $nextObjectTimestamp = $nextObject->getTimestamp();
             $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative;
             // Get everything that matches
             $currentPeriodCount = 0;
             foreach ($rawData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCount += 1;
                 }
             }
             // Now do stuff with it
             switch ($mode) {
                 default:
                 case 'normal':
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount;
                     break;
                 case 'cumulative':
                     $cumulative += $currentPeriodCount;
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative;
                     break;
                 case 'delta':
                     $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount - $previous;
                     $previous = $currentPeriodCount;
                     break;
             }
             $currentObject->add(1, $chunk);
         } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
         // Remove some grid lines if there are too many
         $xsteps = 1;
         if (count($data) > 100) {
             $xsteps = ceil(count($data) / 100);
         }
         $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject);
         echo Zend_Json::encode(array('json' => $data, 'title' => $title));
     } else {
         $selectClick = $staTable->select();
         // Get data
         if (count($adList)) {
             $selectClick->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             $selectClick->where("type = 'click'");
             $clickData = $staTable->fetchAll($selectClick);
         } else {
             $clickData = array();
         }
         $selectImpression = $staTable->select();
         // Get data
         if (count($adList)) {
             $selectImpression->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC');
             $selectImpression->where("type = 'impression'");
             $impressionData = $staTable->fetchAll($selectImpression);
         } else {
             $impressionData = array();
         }
         // Now create data structure
         $currentObject = clone $startObject;
         $nextObject = clone $startObject;
         $dataClick = array();
         $dataImpression = array();
         $dataLabels = array();
         $cumulativeClick = 0;
         $cumulativeIm = 0;
         $previousClick = 0;
         $previousIm = 0;
         do {
             $nextObject->add(1, $chunk);
             $currentObjectTimestamp = $currentObject->getTimestamp();
             $nextObjectTimestamp = $nextObject->getTimestamp();
             $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick;
             $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm;
             // Get everything that matches
             $currentPeriodCountClick = 0;
             foreach ($clickData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCountClick += 1;
                 }
             }
             $currentPeriodCountIm = 0;
             foreach ($impressionData as $rawDatum) {
                 $rawDatumDate = strtotime($rawDatum->timestamp);
                 if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) {
                     $currentPeriodCountIm += 1;
                 }
             }
             // Now do stuff with it
             switch ($mode) {
                 default:
                 case 'normal':
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm;
                     break;
                 case 'cumulative':
                     $cumulativeClick += $currentPeriodCountClick;
                     $cumulativeIm += $currentPeriodCountIm;
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm;
                     break;
                 case 'delta':
                     $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick - $previousClick;
                     $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm - $previousIm;
                     $previousClick = $currentPeriodCountClick;
                     $previousIm = $currentPeriodCountIm;
                     break;
             }
             $currentObject->add(1, $chunk);
         } while ($currentObject->getTimestamp() < $endObject->getTimestamp());
         // Remove some grid lines if there are too many
         $xsteps = 1;
         if (count($dataClick) > 100) {
             $xsteps = ceil(count($dataClick) / 100);
         }
         $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject);
         echo Zend_Json::encode(array('json' => $dataClick, 'title' => $title, 'json2' => $dataImpression));
     }
     return true;
 }
Example #29
0
 /**
  * Create Zend_Date object with date converted to store timezone and store Locale
  *
  * This method from Mage_Core_Model_Locale.
  * This need for backward compatibility with older magento versions which not have 4th parameter in this method
  *
  * @param   mixed                               $store       Information about store
  * @param   string|integer|Zend_Date|array|null $date        date in UTC
  * @param   boolean                             $includeTime flag for including time to date
  * @param   string|null                         $format
  * @return  Zend_Date
  */
 public function storeDate($store = null, $date = null, $includeTime = false, $format = null)
 {
     $timezone = Mage::app()->getStore($store)->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     $date = new Zend_Date($date, $format, Mage::app()->getLocale()->getLocale());
     $date->setTimezone($timezone);
     if (!$includeTime) {
         $date->setHour(0)->setMinute(0)->setSecond(0);
     }
     return $date;
 }
Example #30
0
 /**
  * Returns the date describing for how long the price is valid.
  *
  * @internal The ID3v2 standard does not declare the time zone to be used
  *  in the date. Date must thus be expressed as GMT/UTC.
  * @return Zend_Date
  */
 public function getDate()
 {
     require_once 'Zend/Date.php';
     $date = new Zend_Date(0);
     $date->setTimezone('UTC');
     $date->set($this->_date, 'yyyyMMdd');
     return $date;
 }