diff --git a/kirby/defaults.php b/kirby/defaults.php index fabff0b..6e79a63 100644 --- a/kirby/defaults.php +++ b/kirby/defaults.php @@ -19,7 +19,7 @@ c::set('root.parsers', c::get('root.kirby') . '/parsers'); // define the default site url -c::set('scheme', (server::get('https')) ? 'https://' : 'http://'); +c::set('scheme', (server::get('https') && server::get('https') !== 'off') ? 'https://' : 'http://'); c::set('url', c::get('scheme') . server::get('http_host')); // rewrite url setup diff --git a/kirby/lib/kirby.php b/kirby/lib/kirby.php index e006521..451d620 100644 --- a/kirby/lib/kirby.php +++ b/kirby/lib/kirby.php @@ -3,7 +3,7 @@ /** * Kirby -- A stripped down and easy to use toolkit for PHP * - * @version 0.95 + * @version 0.96 * @author Bastian Allgeier * @link http://toolkit.getkirby.com * @copyright Copyright 2009-2012 Bastian Allgeier @@ -12,7 +12,7 @@ */ -c::set('version', 0.94); +c::set('version', 0.96); c::set('language', 'en'); c::set('charset', 'utf-8'); c::set('root', dirname(__FILE__)); @@ -403,23 +403,22 @@ static function sort($array, $field, $direction='desc', $method=SORT_REGULAR) { // natural sorting if($method === 'natural') { - natsort($helper); if($direction === SORT_DESC) $helper = array_reverse($helper); + } else if($direction === SORT_DESC) { + arsort($helper, $method); + } else { + asort($helper, $method); + } - $result = array(); + $result = array(); - foreach($helper as $key => $val) { - $result[$key] = $array[$key]; - } - - return $result; - - } else { - array_multisort($helper, $direction, $method, $array); - return $array; + foreach($helper as $key => $val) { + $result[$key] = $array[$key]; } - + + return $result; + } } @@ -1678,9 +1677,9 @@ class dir { * @param string $dir The path for the new directory * @return boolean True: the dir has been created, false: creating failed */ - static function make($dir) { + static function make($dir, $recursive = false) { if(is_dir($dir)) return true; - if(!@mkdir($dir, 0755)) return false; + if(!@mkdir($dir, 0755, $recursive)) return false; @chmod($dir, 0755); return true; } @@ -1928,7 +1927,11 @@ static function extension($filename) { * @return string */ static function filename($name) { - return basename($name); + $name = basename($name); + $name = url::strip_query($name); + $name = preg_replace('!\:.*!i', '', $name); + $name = preg_replace('!\#.*!i', '', $name); + return $name; } /** @@ -2747,19 +2750,14 @@ static function parse($string, $mode='json') { * @return string */ static function encode($string) { - $decoded = utf8_decode($string); $encoded = ''; $length = str::length($string); for($i=0; $i<$length; $i++) { - if($decoded[$i] === $string[$i]) { - $encoded .= (rand(1,2)==1) ? '&#'.ord($string[$i]).';' : '&#x'.dechex(ord($string[$i])).';'; - } else { - $encoded .= (rand(1,2)==1) ? '&#'.ord($decoded[$i]).';' : '&#x'.dechex(ord($decoded[$i])).';'; - } + $encoded .= (rand(1,2)==1) ? '&#' . ord($string[$i]) . ';' : '&#x' . dechex(ord($string[$i])) . ';'; } return $encoded; } - + /** * Creates an encoded email address, including proper html-tags * @@ -3051,11 +3049,13 @@ static function urlify($text) { // replace all special characters $text = str_replace(array_keys($replace), array_values($replace), $text); // replace spaces with simple dashes - $text = preg_replace('![^a-z0-9._-]!i','-', $text); + $text = preg_replace('![^a-z0-9]!i','-', $text); // remove double dashes $text = preg_replace('![-]{2,}!','-', $text); // trim trailing and leading dashes $text = trim($text, '-'); + // replace slashes with dashes + $text = str_replace('/', '-', $text); return $text; @@ -3266,10 +3266,15 @@ static function short($url, $chars=false, $base=false, $rep='…') { $url = str_replace('https://','',$url); $url = str_replace('ftp://','',$url); $url = str_replace('www.','',$url); + if($base) { $a = explode('/', $url); $url = a::get($a, 0); } + + // try to remove the last / after the url + $url = preg_replace('!(\/)$!', '', $url); + return ($chars) ? str::short($url, $chars, $rep) : $url; } diff --git a/kirby/lib/obj.php b/kirby/lib/obj.php index 6c25228..f8d5390 100644 --- a/kirby/lib/obj.php +++ b/kirby/lib/obj.php @@ -31,7 +31,7 @@ function __get($n) { } function __call($n, $args) { - return a::get($this->_, $n); + return a::get($this->_, strtolower($n)); } function rewind() { diff --git a/kirby/lib/site.php b/kirby/lib/site.php index d5b1959..4b624b1 100644 --- a/kirby/lib/site.php +++ b/kirby/lib/site.php @@ -430,8 +430,10 @@ function languageSetup() { if(c::get('lang.detect')) { // detect the current language - $detected = str::split(server::get('http_accept_language'), '-'); - $detected = str::trim(a::first($detected)); + $detected = str::split(server::get('http_accept_language'), ','); + $detected = a::first($detected); + $detected = str::split($detected, '-'); + $detected = a::first($detected); $detected = (!in_array($detected, $available)) ? c::get('lang.default') : $detected; // set the detected code as current code diff --git a/kirby/lib/template.php b/kirby/lib/template.php index 75c0b5d..6c9b0d1 100755 --- a/kirby/lib/template.php +++ b/kirby/lib/template.php @@ -28,8 +28,9 @@ static function load($template='default', $vars=array(), $return=false) { static function loadFile($file, $vars=array(), $return=false) { if(!file_exists($file)) return false; if(!is_array($vars)) { - $vars = array(); + $vars = array(); } + clearstatcache(); @extract(self::$vars); @extract($vars); content::start(); diff --git a/kirby/parsers/kirbytext.php b/kirby/parsers/kirbytext.php index e0b112d..bb4c22d 100644 --- a/kirby/parsers/kirbytext.php +++ b/kirby/parsers/kirbytext.php @@ -67,7 +67,7 @@ class kirbytext { var $mdown = true; var $smartypants = true; var $tags = array('gist', 'twitter', 'date', 'image', 'file', 'link', 'email', 'youtube', 'vimeo'); - var $attr = array('text', 'file', 'width', 'height', 'link', 'popup', 'class', 'title', 'alt', 'rel', 'lang', 'target'); + var $attr = array('text', 'file', 'width', 'height', 'link', 'popup', 'class', 'title', 'alt', 'rel', 'lang', 'target', 'download'); static function init($text=false, $mdown=true, $smartypants=true) { @@ -280,17 +280,19 @@ function image($params) { function file($params) { - $url = @$params['file']; - $text = @$params['text']; - $class = @$params['class']; - $rel = @$params['rel']; - $title = @$params['title']; - $target = self::target($params); + $url = @$params['file']; + $text = @$params['text']; + $class = @$params['class']; + $rel = @$params['rel']; + $title = @$params['title']; + $download = @$params['download']; + $target = self::target($params); - if(empty($text)) $text = str_replace('_', '\_', $url); // ignore markdown italic underscores in filenames - if(!empty($class)) $class = ' class="' . $class . '"'; - if(!empty($rel)) $rel = ' rel="' . $rel . '"'; - if(!empty($title)) $title = ' title="' . html($title) . '"'; + if(empty($text)) $text = str_replace('_', '\_', $url); // ignore markdown italic underscores in filenames + if(!empty($class)) $class = ' class="' . $class . '"'; + if(!empty($rel)) $rel = ' rel="' . $rel . '"'; + if(!empty($download)) $download = ' download="' . html($download) . '"'; + if(!empty($title)) $title = ' title="' . html($title) . '"'; return '' . html($text) . ''; @@ -378,7 +380,7 @@ static function youtube($params) { if(empty($id)) return false; // build the embed url for the iframe - $url = 'http://www.youtube.com/embed/' . $id; + $url = 'https://www.youtube.com/embed/' . $id; // default width and height if no custom values are set if(empty($params['width'])) $params['width'] = c::get('kirbytext.video.width'); @@ -404,7 +406,7 @@ static function vimeo($params) { if(empty($id)) return false; // build the embed url for the iframe - $url = 'http://player.vimeo.com/video/' . $id; + $url = 'https://player.vimeo.com/video/' . $id; // default width and height if no custom values are set if(empty($params['width'])) $params['width'] = c::get('kirbytext.video.width');