Ejemplo n.º 1
0
 private static function _formatTimestamp($timestamp, $format)
 {
     switch ($format) {
         case '':
             return $timestamp;
         case 'date':
             // Custom locale manipulations
             switch (TIP::getLocaleId()) {
                 case 'it_IT':
                     $same_year = date('Y', $timestamp) == date('Y');
                     $same_day = date('z', $timestamp) == date('z');
                     if ($same_year && $same_day) {
                         return 'oggi';
                     }
                     return strftime($same_year ? '%d %B' : '%d %B %Y', $timestamp);
             }
             return strftime('%x', $timestamp);
         case 'datetime':
             // Custom locale manipulations
             switch (TIP::getLocaleId()) {
                 case 'it_IT':
                     $date = TIP::_formatTimestamp($timestamp, 'date');
                     return $date . ' alle ' . strftime('%H:%M', $timestamp);
             }
             return strftime('%c', $timestamp);
         case 'date_sql':
         case 'date_iso8601':
             return strftime('%Y-%m-%d', $timestamp);
         case 'datetime_sql':
             return strftime('%Y-%m-%d %H:%M:%S', $timestamp);
         case 'datetime_iso8601':
             return date(DATE_ISO8601, $timestamp);
         case 'datetime_rfc3339':
             return date(DATE_RFC3339, $timestamp);
     }
     return strftime($format, $timestamp);
 }
Ejemplo n.º 2
0
 /**
  * The "main" function
  *
  * The starting point of the TIP system. This must be called somewhere from
  * your index.php.
  */
 public function go()
 {
     // Configure the locale
     $locale_module = $this->shared_modules['locale'];
     if (TIP::setLocaleId(TIP::getOption($locale_module, 'locale'))) {
         date_default_timezone_set(TIP::getOption($locale_module, 'timezone'));
     }
     // Executes the action
     if ($this->_request['module'] && $this->_request['action']) {
         if (is_null($module =& TIP_Type::getInstance($this->_request['module'], false))) {
             TIP::notifyError('module');
         } else {
             if (isset($this->_request['id'])) {
                 // Now the module is loaded: force id type casting
                 $id_type = $module->getProperty('id_type');
                 isset($id_type) || ($id_type = 'integer');
                 settype($this->_request['id'], $id_type);
                 $this->keys['ID'] = $this->_request['id'];
             }
             if (is_null($module->callAction($this->_request['action']))) {
                 TIP::notifyError(is_null(TIP::getUserId()) ? 'reserved' : 'denied');
             }
         }
     } elseif ($this->_request['module']) {
         TIP::notifyError('noaction');
     } elseif ($this->_request['action']) {
         TIP::notifyError('nomodule');
     } elseif (TIP_AHAH) {
         // AHAH request without module/action specified: perform a test
         $this->content = "<pre>\n" . TIP::toHtml(print_r($_SERVER, true)) . "\n</pre>\n";
     }
     if (TIP_AHAH) {
         // AHAH request: output the page and return
         header('Content-Type: application/xml');
         echo $this->content;
         return;
     }
     // Generates the page: body must be called before the head because
     // some head tags can be modified by body templates
     $body = $this->tagRun($this->body_template);
     echo str_replace('{locale}', TIP::getLocaleId('-'), $this->incipit);
     $this->run($this->head_template);
     echo $body . $this->explicit;
     $this->_session_started && HTTP_Session2::pause();
 }
Ejemplo n.º 3
0
 private function &_widgetDate(&$field, $args)
 {
     HTML_QuickForm::registerRule('date', 'callback', '_ruleDate', 'TIP_Form');
     $id = $field['id'];
     $label = $this->getLocale('label.' . $id);
     $info = TIP::getLocale('comment.' . $id, $this->locale_prefix);
     // Set the date in a format suitable for HTML_QuickForm_date
     $sql_date = @$this->_defaults[$id];
     $timestamp = empty($sql_date) ? time() : TIP::getTimestamp($sql_date, 'sql');
     $this->_defaults[$id] = $timestamp;
     $field_year = date('Y', $this->_defaults[$id]);
     $this_year = date('Y');
     // $min_year > $max_year, so the year list is properly sorted in reversed
     // order
     $options = array('language' => substr(TIP::getLocaleId(), 0, 2), 'format' => 'dFY', 'minYear' => $this_year + 1, 'maxYear' => $field_year < $this_year - 5 ? $field_year : $this_year - 5);
     ++$this->_tabindex;
     $element =& $this->_form->addElement('date', $id, $label, $options, array('tabindex' => $this->_tabindex));
     $element->setInfo($info);
     $this->_addRule($id, 'date');
     $this->_addConverter($id, 'SqlDate');
     return $element;
 }