Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'dev'
Conflicts:
	kirby/lib/template.php
	kirby/parsers/kirbytext.php
	license.mdown
  • Loading branch information
bastianallgeier committed Oct 25, 2014
2 parents 1cd95de + 319902b commit 91cf9c4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 43 deletions.
2 changes: 1 addition & 1 deletion kirby/defaults.php
Expand Up @@ -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
Expand Down
55 changes: 30 additions & 25 deletions kirby/lib/kirby.php
Expand Up @@ -3,7 +3,7 @@
/**
* Kirby -- A stripped down and easy to use toolkit for PHP
*
* @version 0.95
* @version 0.96
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://toolkit.getkirby.com
* @copyright Copyright 2009-2012 Bastian Allgeier
Expand All @@ -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__));
Expand Down Expand Up @@ -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;

}

}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion kirby/lib/obj.php
Expand Up @@ -31,7 +31,7 @@ function __get($n) {
}

function __call($n, $args) {
return a::get($this->_, $n);
return a::get($this->_, strtolower($n));
}

function rewind() {
Expand Down
6 changes: 4 additions & 2 deletions kirby/lib/site.php
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kirby/lib/template.php
Expand Up @@ -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();
Expand Down
28 changes: 15 additions & 13 deletions kirby/parsers/kirbytext.php
Expand Up @@ -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) {

Expand Down Expand Up @@ -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 '<a' . $target . $title . $class . $rel . ' href="' . $this->url($url) . '">' . html($text) . '</a>';

Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 91cf9c4

Please sign in to comment.