Exemple #1
0
 /**
  * Send HTTP response
  *
  * Send the specific X-Sendfile HTTP headers for internal processing by the server.
  *
  * - Apache : X-Sendfile
  * - Nginx  : X-Accel-Redirect
  *
  * @param DispatcherResponseInterface $response
  * @return boolean
  */
 public function send(DispatcherResponseInterface $response)
 {
     if ($response->isDownloadable()) {
         $server = strtolower($_SERVER['SERVER_SOFTWARE']);
         //Apache
         if (strpos($server, 'apache') !== FALSE) {
             if (in_array('mod_xsendfile', apache_get_modules())) {
                 $path = $response->getStream()->getPath();
                 $response->headers->set('X-Sendfile', $path);
                 return parent::send($response);
             }
         }
         //Nginx
         if (strpos($server, 'nginx') !== FALSE) {
             $path = $response->getStream()->getPath();
             $path = preg_replace('/' . preg_quote(\Kodekit::getInstance()->getRootPath(), '/') . '/', '', $path, 1);
             $response->headers->set('X-Accel-Redirect', $path);
             return parent::send($response);
         }
     }
 }
Exemple #2
0
 /**
  * Render debug information
  *
  * @param  string  $source  The template source
  * @return string The rendered template source
  */
 public function renderDebug($source)
 {
     $template = end($this->__stack);
     if ($this->getObject('filter.path')->validate($template)) {
         $path = $this->locateSource($template);
     } else {
         $path = '';
     }
     //Render debug comments
     if ($this->isDebug()) {
         $type = $this->getIdentifier()->getName();
         $path = str_replace(rtrim(\Kodekit::getInstance()->getRootPath(), '/') . '/', '', $path);
         $format = PHP_EOL . '<!--BEGIN ' . $type . ':render ' . $path . ' -->' . PHP_EOL;
         $format .= '%s';
         $format .= PHP_EOL . '<!--END ' . $type . ':render ' . $path . ' -->' . PHP_EOL;
         $source = sprintf($format, trim($source));
     }
     return $source;
 }
Exemple #3
0
 /**
  * Removes root path from a filename replacing them with the plain text equivalents.
  *
  * Useful for debugging when you want to display a shorter path.
  *
  * @param   array   $config An optional array with configuration options
  * @return  string  Html
  */
 public function path($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('file' => '', 'line' => '', 'root' => \Kodekit::getInstance()->getRootPath(), 'editor' => $this->_editor));
     $html = $config->file;
     if (strpos($config->file, $config->root) === 0) {
         $html = '...' . DIRECTORY_SEPARATOR . trim(substr($config->file, strlen($config->root)), DIRECTORY_SEPARATOR);
     }
     if ($config->editor && isset($this->_editors[$config->editor])) {
         $editor = $this->_editors[$config->editor];
         foreach ($this->_getSharedPaths() as $guest => $host) {
             if (substr($config->file, 0, strlen($guest)) == $guest) {
                 $config->file = str_replace($guest, $host, $config->file);
             }
         }
         if (is_callable($editor)) {
             $editor = call_user_func($editor, $config->file, $config->line);
         }
         $editor = str_replace("%line", $config->line, $editor);
         $editor = str_replace("%file", $config->file, $editor);
         $html = '<a href="' . $editor . '" title="' . $html . '">' . $html . '</a>';
     }
     return $html;
 }
Exemple #4
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $config Configuration options.
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('language' => locale_get_default(), 'language_fallback' => 'en-GB', 'cache' => \Kodekit::getInstance()->isCache(), 'cache_namespace' => 'kodekit', 'catalogue' => 'default'));
     parent::_initialize($config);
 }
Exemple #5
0
 /**
  * Loads the calendar behavior and attaches it to a specified element
  *
  * @param array|ObjectConfig $config
  * @return string   The html output
  */
 public function calendar($config = array())
 {
     $config = new ObjectConfigJson($config);
     $config->append(array('debug' => \Kodekit::getInstance()->isDebug(), 'offset' => 'UTC', 'user_offset' => $this->getObject('user')->getParameter('timezone'), 'server_offset' => date_default_timezone_get(), 'offset_seconds' => 0, 'value' => gmdate("M d Y H:i:s"), 'name' => '', 'format' => '%Y-%m-%d %H:%M:%S', 'first_week_day' => 0, 'attribs' => array('size' => 25, 'maxlength' => 19, 'placeholder' => '')))->append(array('id' => 'datepicker-' . $config->name, 'options_callback' => null, 'options' => array('todayBtn' => 'linked', 'todayHighlight' => true, 'language' => 'en-GB', 'autoclose' => true, 'keyboardNavigation' => false)));
     if ($config->offset) {
         if (strtoupper($config->offset) === 'SERVER_UTC') {
             $config->offset = $config->server_offset;
         } else {
             if (strtoupper($config->offset) === 'USER_UTC') {
                 $config->offset = $config->user_offset ?: $config->server_offset;
             }
         }
         $timezone = new \DateTimeZone($config->offset);
         $config->offset_seconds = $timezone->getOffset(new \DateTime());
     }
     if ($config->value && $config->value != '0000-00-00 00:00:00' && $config->value != '0000-00-00') {
         if (strtoupper($config->value) == 'NOW') {
             $config->value = strftime($config->format);
         }
         $date = new \DateTime($config->value, new \DateTimeZone('UTC'));
         $config->value = strftime($config->format, (int) $date->format('U') + $config->offset_seconds);
     } else {
         $config->value = '';
     }
     $attribs = $this->buildAttributes($config->attribs);
     $value = StringEscaper::attr($config->value);
     if ($config->attribs->readonly === 'readonly' || $config->attribs->disabled === 'disabled') {
         $html = '<div>';
         $html .= '<input type="text" name="' . $config->name . '" id="' . $config->id . '" value="' . $value . '" ' . $attribs . ' />';
         $html .= '</div>';
     } else {
         $html = $this->_loadCalendarScripts($config);
         if (!isset(self::$_loaded['calendar-triggers'])) {
             self::$_loaded['calendar-triggers'] = array();
         }
         // Only display the triggers once for each control.
         if (!in_array($config->id, self::$_loaded['calendar-triggers'])) {
             $options = (string) $config->options;
             if ($config->options_callback) {
                 $options = $config->options_callback . '(' . $options . ')';
             }
             $html .= "<script>\n                    kQuery(function(\$){\n                        \$('#" . $config->id . "').kodekitDatepicker(" . $config->options . ");\n                    });\n                </script>";
             if ($config->offset_seconds) {
                 $html .= "<script>\n                        kQuery(function(\$){\n                            \$('.-koowa-form').on('koowa:submit', function() {\n                                var element = kQuery('#" . $config->id . "'),\n                                    picker  = element.data('datepicker'),\n                                    offset  = {$config->offset_seconds};\n\n                                if (picker && element.children('input').val()) {\n                                    picker.setDate(new Date(picker.getDate().getTime() + (-1*offset*1000)));\n                                }\n                            });\n                        });\n                    </script>";
             }
             self::$_loaded['calendar-triggers'][] = $config->id;
         }
         $format = str_replace(array('%Y', '%y', '%m', '%d', '%H', '%M', '%S'), array('yyyy', 'yy', 'mm', 'dd', 'hh', 'ii', 'ss'), $config->format);
         $html .= '<div class="input-group date datepicker" data-date-format="' . $format . '" id="' . $config->id . '">';
         $html .= '<input class="input-group-form-control" type="text" name="' . $config->name . '" value="' . $value . '"  ' . $attribs . ' />';
         $html .= '<span class="input-group-btn">';
         $html .= '<span class="btn" >';
         $html .= '<span class="koowa_icon--calendar"><i>calendar</i></span>';
         $html .= '</span>';
         $html .= '</span>';
         $html .= '</div>';
     }
     return $html;
 }
Exemple #6
0
 /**
  * Initializes the options for the object
  *
  * Called from {@link __construct()} as a first step of object instantiation.
  *
  * @param   ObjectConfig $config Configuration options.
  * @return  void
  */
 protected function _initialize(ObjectConfig $config)
 {
     $config->append(array('debug' => \Kodekit::getInstance()->isDebug(), 'cache' => \Kodekit::getInstance()->isCache(), 'cache_path' => '', 'engines' => array('lib:template.engine.kodekit')))->append(array('cache_reload' => $config->debug));
 }