Ejemplo n.º 1
0
 public function get($url)
 {
     $url .= '/token:' . $this->token;
     $cache = Shutter::get_cache('api/' . $url);
     if ($cache) {
         $data = json_decode($cache['data'], true);
     } else {
         $headers = array('Connection: Keep-Alive', 'Keep-Alive: 2', 'Cache-Control: must-revalidate');
         if (LOOPBACK_HOST_HEADER) {
             $host = $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT'];
             $headers[] = 'Host: ' . $_SERVER['HTTP_HOST'];
         } else {
             $host = $_SERVER['HTTP_HOST'];
         }
         $url = $this->protocol . '://' . $host . preg_replace('~/(app/site/site|(api|i))\\.php.*~', "/api.php?{$url}", $_SERVER['SCRIPT_NAME']);
         curl_setopt($this->curl, CURLOPT_URL, $url);
         curl_setopt($this->curl, CURLOPT_HEADER, 0);
         curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36');
         curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 5);
         curl_setopt($this->curl, CURLOPT_TIMEOUT, 10);
         curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
         if ($this->protocol === 'https') {
             curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
             curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
         }
         $data = json_decode(curl_exec($this->curl), true);
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Site url hook for newer koken versions
  */
 public function siteUrlHook()
 {
     if ($this->isSitemapUrl()) {
         if ($cache = Shutter::get_cache($this->getCachePath())) {
             header('Content-type: text/xml; charset=utf-8');
             echo $cache['data'];
             exit;
         } else {
             Koken::$cache_path = $this->getCachePath();
             $xmlSitemap = $this->buildXmlSitemap();
             $this->outputXmlSitemapAndExit($xmlSitemap);
         }
     }
 }
Ejemplo n.º 3
0
 private static function prep_api($url)
 {
     if (strpos($url, 'api.php?') !== false) {
         $bits = explode('api.php?', $url);
         $url = $bits[1];
     }
     if (self::$draft && !is_null(self::$site['draft_id'])) {
         $url .= '/draft_context:' . self::$site['draft_id'];
     } else {
         if (self::$preview) {
             $url .= '/draft_context:' . self::$preview;
         }
     }
     $url = Shutter::filter('site.api_url', $url);
     $cache = Shutter::get_cache('api' . $url);
     if ($cache) {
         return json_decode($cache['data'], true);
     } else {
         return $url;
     }
 }
Ejemplo n.º 4
0
 function check_for_rewrite()
 {
     if (defined('KOKEN_REWRITE')) {
         return KOKEN_REWRITE;
     }
     if (!file_exists(FCPATH . '.htaccess') && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === 0) {
         define('KOKEN_REWRITE', false);
         return false;
     }
     $cache_key = 'core/rewrite_check';
     $cache = Shutter::get_cache($cache_key, false);
     if ($cache !== false) {
         define('KOKEN_REWRITE', trim($cache['data']) === 'on');
         return KOKEN_REWRITE;
     }
     $s = new Setting();
     $s->where('name', 'site_url')->get();
     if ($s->value === 'default') {
         $koken_url_info = $this->config->item('koken_url_info');
         $url = $koken_url_info->base . '__rewrite_test/';
     } else {
         $url = 'http://' . $_SERVER['HTTP_HOST'] . rtrim($s->value, '/') . '/__rewrite_test/';
     }
     $headers = array('Cache-Control: must-revalidate');
     if (LOOPBACK_HOST_HEADER) {
         $host = $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT'];
         $headers[] = 'Host: ' . $_SERVER['HTTP_HOST'];
         $url = str_replace($_SERVER['HTTP_HOST'], $host, $url);
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     if (strpos($url, 'https://') === 0) {
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     }
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     $return = trim(curl_exec($curl));
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     $rewrite_check = $code === 200 && $return === 'koken:rewrite';
     Shutter::write_cache($cache_key, $rewrite_check ? 'on' : 'off');
     define('KOKEN_REWRITE', $rewrite_check);
     return $rewrite_check;
 }
Ejemplo n.º 5
0
 } else {
     if ($cache_url === '/koken.js') {
         $js = true;
         $cache_url = $base_path . $cache_url;
     } else {
         if (!preg_match('/\\.rss$/', $cache_url)) {
             $cache_url = $base_path . preg_replace('/\\?|&|=/', '_', preg_replace('/\\?|&_pjax=[^&$]+/', '', urldecode(rtrim($cache_url, '/')))) . '/cache';
         }
     }
 }
 if ($preview) {
     $cache_url = '/__preview/' . $preview . $cache_url;
 }
 $cache_path = 'site' . str_replace('/', DIRECTORY_SEPARATOR, $cache_url) . ($css || $js || preg_match('/\\.rss$/', $cache_url) ? '' : ($pjax ? '.phtml' : '.html'));
 $cache_path = Shutter::filter('site.cache.read.path', $cache_path);
 $cache = Shutter::get_cache($cache_path);
 if ($cache) {
     if ($css) {
         header('Content-type: text/css');
     } else {
         if ($js) {
             header('Content-type: text/javascript');
         } else {
             if (preg_match('/\\.rss$/', $cache_url)) {
                 header('Content-type: application/rss+xml; charset=UTF-8');
             } else {
                 header('Content-type: text/html; charset=UTF-8');
             }
         }
     }
     $mtime = $cache['modified'];
Ejemplo n.º 6
0
         }
     }
     if ($hires) {
         $d->retina();
     }
     if (!$settings['retain_image_metadata'] || max($w, $h) < 480 || $settings['image_processing_library'] === 'gd') {
         // Work around issue with mbstring.func_overload = 2
         if (ini_get('mbstring.func_overload') & 2 && function_exists('mb_internal_encoding')) {
             $previous_encoding = mb_internal_encoding();
             mb_internal_encoding('ISO-8859-1');
         }
         require $root . $ds . 'app' . $ds . 'koken' . $ds . 'icc.php';
         $icc = new JPEG_ICC();
         preg_match('~^(/\\d{3}/\\d{3}/)~', $path, $match);
         $icc_cache_key = 'icc' . $match[1] . 'profile.icc';
         $icc_cache = Shutter::get_cache($icc_cache_key);
         if ($icc_cache) {
             $icc->SetProfile($icc_cache['data']);
         } else {
             $icc->LoadFromJpeg($original);
             Shutter::write_cache($icc_cache_key, $icc->GetProfile());
         }
         $d->strip();
     }
     $blob = $d->render();
     if (isset($icc)) {
         $blob = $icc->SaveToBlob($blob);
     }
     Shutter::hook('darkroom.render.complete', array($blob));
 } else {
     header('HTTP/1.1 404 Not Found');