diff --git a/.gitignore b/.gitignore index 5394f5eac5..1cde3a6254 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ avatar/* background/* files/* file/* +local/* _darcs/* logs/* config.php diff --git a/classes/File_redirection.php b/classes/File_redirection.php index d6fa0bcb62..363e3b947c 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -182,7 +182,7 @@ class File_redirection extends Memcached_DataObject } } - if (('ftp' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) { + if (('ftp' == $p['scheme']) || ('ftps' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) { if (empty($p['host'])) return false; if (empty($p['path'])) { $out_url .= '/'; diff --git a/lib/designsettings.php b/lib/designsettings.php index a48ec9d227..b86265971c 100644 --- a/lib/designsettings.php +++ b/lib/designsettings.php @@ -326,6 +326,7 @@ class DesignSettingsAction extends AccountSettingsAction $this->script('js/farbtastic/farbtastic.js'); $this->script('js/farbtastic/farbtastic.go.js'); + $this->script('js/userdesign.go.js'); } /** diff --git a/lib/util.php b/lib/util.php index 2be4213e79..7c1e219138 100644 --- a/lib/util.php +++ b/lib/util.php @@ -404,7 +404,7 @@ function common_render_text($text) $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r); $r = common_replace_urls_callback($r, 'common_linkify'); - $r = preg_replace('/(^|\(|\[|\s+)#([\pL\pN_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); + $r = preg_replace('/(^|\"\;|\'|\(|\[|\{|\s+)#([\pL\pN_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); // XXX: machine tags return $r; } @@ -412,44 +412,94 @@ function common_render_text($text) function common_replace_urls_callback($text, $callback, $notice_id = null) { // Start off with a regex $regex = '#'. - '(?:^|[\s\(\)\[\]\{\}]+)'. - '('. + '(?:^|[\s\(\)\[\]\{\}\\\'\\\";]+)(?![\@\!\#])'. + '(?P'. '(?:'. '(?:'. //Known protocols '(?:'. - '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'. + '(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://)'. '|'. - '(?:mailto|aim|tel|xmpp):'. - ')[^\s\/]+'. + '(?:(?:mailto|aim|tel|xmpp):)'. + ')'. + '(?:[\pN\pL\-\_\+]+(?::[\pN\pL\-\_\+]+)?\@)?'. //user:pass@ + '(?:'. + '(?:'. + '\[[\pN\pL\-\_\:\.]+(?'(', + 'right'=>')' + ), + array( + 'left'=>'[', + 'right'=>']' + ), + array( + 'left'=>'{', + 'right'=>'}' + ) + ); + $cannotEndWith=array('.','?',',','#'); + $original_url=$url; + do{ + $original_url=$url; + foreach($groupSymbolSets as $groupSymbolSet){ + if(substr($url,-1)==$groupSymbolSet['right']){ + $group_left_count = substr_count($url,$groupSymbolSet['left']); + $group_right_count = substr_count($url,$groupSymbolSet['right']); + if($group_left_count<$group_right_count){ + $right-=1; + $url=substr($url,0,-1); + } + } + } + if(in_array(substr($url,-1),$cannotEndWith)){ + $right-=1; + $url=substr($url,0,-1); + } + }while($original_url!=$url); + + if(empty($notice_id)){ - $result = call_user_func_array($callback,$matches[1]); + $result = call_user_func_array($callback,$url); }else{ - $result = call_user_func_array($callback, array($matches[1],$notice_id) ); + $result = call_user_func_array($callback, array($url,$notice_id) ); } - return $left . $result . $right; + return substr($matches[0],0,$left) . $result . substr($matches[0],$right); } function curry($fn) { diff --git a/plugins/TemplatePlugin.php b/plugins/TemplatePlugin.php index 03daf6219c..6c14f19881 100644 --- a/plugins/TemplatePlugin.php +++ b/plugins/TemplatePlugin.php @@ -198,13 +198,13 @@ class TemplatePlugin extends Plugin { // unless laconica config: // $config['template']['mode'] = 'html'; if (!(common_config('template', 'mode') == 'html')) { - $tpl_file = 'tpl/index.php'; + $tpl_file = $this->templateFolder() . '/index.php'; $tags = array_merge($vars,$this->blocks); include $tpl_file; return; } - $tpl_file = 'tpl/index.html'; + $tpl_file = $this->templateFolder() . '/index.html'; // read the static template $output = file_get_contents( $tpl_file ); @@ -236,6 +236,9 @@ class TemplatePlugin extends Plugin { return true; } + function templateFolder() { + return 'tpl'; + } // catching the StartShowHTML event to halt the rendering function onStartShowHTML( &$act ) { @@ -300,7 +303,7 @@ class TemplateAction extends Action $this->clientError(_('only User #1 can update the template'), $code = 401); // open the old template - $tpl_file = 'tpl/index.html'; + $tpl_file = $this->templateFolder() . '/index.html'; $fp = fopen( $tpl_file, 'w+' ); // overwrite with the new template diff --git a/tests/HashTagDetectionTest.php b/tests/HashTagDetectionTest.php new file mode 100644 index 0000000000..901e0611cc --- /dev/null +++ b/tests/HashTagDetectionTest.php @@ -0,0 +1,47 @@ +assertEquals($expected, $rendered); + } + + static public function provider() + { + return array( + array('hello', + 'hello'), + array('#hello people', + '# people'), + array('"#hello" people', + '"#" people'), + array('say "#hello" people', + 'say "#" people'), + array('say (#hello) people', + 'say (#) people'), + array('say [#hello] people', + 'say [#] people'), + array('say {#hello} people', + 'say {#} people'), + array('say \'#hello\' people', + 'say \'#\' people'), + ); + } +} + diff --git a/tests/URLDetectionTest.php b/tests/URLDetectionTest.php index f35b03eaf2..7b2e8c5ae7 100644 --- a/tests/URLDetectionTest.php +++ b/tests/URLDetectionTest.php @@ -25,158 +25,214 @@ class URLDetectionTest extends PHPUnit_Framework_TestCase static public function provider() { return array( + array('http://127.0.0.1', + 'http://127.0.0.1'), + array('127.0.0.1', + '127.0.0.1'), + array('127.0.0.1:99', + '127.0.0.1:99'), + array('127.0.0.1/test.php', + '127.0.0.1/test.php'), + array('http://[::1]:99/test.php', + 'http://[::1]:99/test.php'), + array('http://::1/test.php', + 'http://::1/test.php'), + array('http://::1', + 'http://::1'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php'), + array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', + '[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab'), + array('http://127.0.0.1', + 'http://127.0.0.1'), + array('example.com', + 'example.com'), + array('example.com', + 'example.com'), + array('http://example.com', + 'http://example.com'), + array('http://example.com.', + 'http://example.com.'), + array('/var/lib/example.so', + '/var/lib/example.so'), array('example', 'example'), + array('user@example.com', + 'user@example.com'), + array('user_name+other@example.com', + 'user_name+other@example.com'), + array('mailto:user@example.com', + 'mailto:user@example.com'), + array('mailto:user@example.com?subject=test', + 'mailto:user@example.com?subject=test'), + array('#example', + '#'), + array('#example.com', + '#'), + array('#.net', + '#'), array('http://example', - 'http://example'), + 'http://example'), + array('http://3xampl3', + 'http://3xampl3'), array('http://example/', - 'http://example/'), + 'http://example/'), array('http://example/path', - 'http://example/path'), + 'http://example/path'), array('http://example.com', - 'http://example.com'), + 'http://example.com'), array('https://example.com', - 'https://example.com'), + 'https://example.com'), array('ftp://example.com', - 'ftp://example.com'), + 'ftp://example.com'), array('ftps://example.com', - 'ftps://example.com'), + 'ftps://example.com'), array('http://user@example.com', - 'http://user@example.com'), + 'http://user@example.com'), array('http://user:pass@example.com', - 'http://user:pass@example.com'), + 'http://user:pass@example.com'), array('http://example.com:8080', - 'http://example.com:8080'), + 'http://example.com:8080'), + array('http://example.com:8080/test.php', + 'http://example.com:8080/test.php'), + array('example.com:8080/test.php', + 'example.com:8080/test.php'), array('http://www.example.com', - 'http://www.example.com'), + 'http://www.example.com'), array('http://example.com/', - 'http://example.com/'), + 'http://example.com/'), array('http://example.com/path', - 'http://example.com/path'), + 'http://example.com/path'), array('http://example.com/path.html', - 'http://example.com/path.html'), + 'http://example.com/path.html'), array('http://example.com/path.html#fragment', - 'http://example.com/path.html#fragment'), + 'http://example.com/path.html#fragment'), array('http://example.com/path.php?foo=bar&bar=foo', - 'http://example.com/path.php?foo=bar&bar=foo'), - array('http://müllärör.de', - 'http://müllärör.de'), - array('http://ﺱﺲﺷ.com', - 'http://ﺱﺲﺷ.com'), - array('http://сделаткартинки.com', - 'http://сделаткартинки.com'), - array('http://tūdaliņ.lv', - 'http://tūdaliņ.lv'), - array('http://brændendekærlighed.com', - 'http://brændendekærlighed.com'), - array('http://あーるいん.com', - 'http://あーるいん.com'), - array('http://예비교사.com', - 'http://예비교사.com'), + 'http://example.com/path.php?foo=bar&bar=foo'), array('http://example.com.', - 'http://example.com.'), + 'http://example.com.'), + array('http://müllärör.de', + 'http://müllärör.de'), + array('http://ﺱﺲﺷ.com', + 'http://ﺱﺲﺷ.com'), + array('http://сделаткартинки.com', + 'http://сделаткартинки.com'), + array('http://tūdaliņ.lv', + 'http://tūdaliņ.lv'), + array('http://brændendekærlighed.com', + 'http://brændendekærlighed.com'), + array('http://あーるいん.com', + 'http://あーるいん.com'), + array('http://예비교사.com', + 'http://예비교사.com'), + array('http://example.com.', + 'http://example.com.'), array('http://example.com?', - 'http://example.com?'), + 'http://example.com?'), array('http://example.com!', - 'http://example.com!'), + 'http://example.com!'), array('http://example.com,', - 'http://example.com,'), + 'http://example.com,'), array('http://example.com;', - 'http://example.com;'), + 'http://example.com;'), array('http://example.com:', - 'http://example.com:'), + 'http://example.com:'), array('\'http://example.com\'', - '\'http://example.com\''), + '\'http://example.com\''), array('"http://example.com"', - '"http://example.com"'), - array('http://example.com ', - 'http://example.com'), + '"http://example.com"'), + array('http://example.com', + 'http://example.com'), array('(http://example.com)', - '(http://example.com)'), + '(http://example.com)'), array('[http://example.com]', - '[http://example.com]'), + '[http://example.com]'), array('', - '<http://example.com>'), + '<http://example.com>'), array('http://example.com/path/(foo)/bar', - 'http://example.com/path/(foo)/bar'), + 'http://example.com/path/(foo)/bar'), array('http://example.com/path/[foo]/bar', - 'http://example.com/path/[foo]/bar'), + 'http://example.com/path/[foo]/bar'), array('http://example.com/path/foo/(bar)', - 'http://example.com/path/foo/(bar)'), + 'http://example.com/path/foo/(bar)'), + //Not a valid url - urls cannot contain unencoded square brackets array('http://example.com/path/foo/[bar]', - 'http://example.com/path/foo/[bar]'), + 'http://example.com/path/foo/[bar]'), array('Hey, check out my cool site http://example.com okay?', - 'Hey, check out my cool site http://example.com okay?'), + 'Hey, check out my cool site http://example.com okay?'), array('What about parens (e.g. http://example.com/path/foo/(bar))?', - 'What about parens (e.g. http://example.com/path/foo/(bar))?'), + 'What about parens (e.g. http://example.com/path/foo/(bar))?'), array('What about parens (e.g. http://example.com/path/foo/(bar)?', - 'What about parens (e.g. http://example.com/path/foo/(bar)?'), + 'What about parens (e.g. http://example.com/path/foo/(bar)?'), array('What about parens (e.g. http://example.com/path/foo/(bar).)?', - 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + //Not a valid url - urls cannot contain unencoded commas array('What about parens (e.g. http://example.com/path/(foo,bar)?', - 'What about parens (e.g. http://example.com/path/(foo,bar)?'), + 'What about parens (e.g. http://example.com/path/(foo,bar)?'), array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', - 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), + 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', - 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), + 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', - 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), + 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', - 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), + 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), array('example.com', - 'example.com'), + 'example.com'), array('example.org', - 'example.org'), + 'example.org'), array('example.co.uk', - 'example.co.uk'), + 'example.co.uk'), array('www.example.co.uk', - 'www.example.co.uk'), + 'www.example.co.uk'), array('farm1.images.example.co.uk', - 'farm1.images.example.co.uk'), + 'farm1.images.example.co.uk'), array('example.museum', - 'example.museum'), + 'example.museum'), array('example.travel', - 'example.travel'), + 'example.travel'), array('example.com.', - 'example.com.'), + 'example.com.'), array('example.com?', - 'example.com?'), + 'example.com?'), array('example.com!', - 'example.com!'), + 'example.com!'), array('example.com,', - 'example.com,'), + 'example.com,'), array('example.com;', - 'example.com;'), + 'example.com;'), array('example.com:', - 'example.com:'), + 'example.com:'), array('\'example.com\'', - '\'example.com\''), + '\'example.com\''), array('"example.com"', - '"example.com"'), - array('example.com ', - 'example.com'), + '"example.com"'), + array('example.com', + 'example.com'), array('(example.com)', - '(example.com)'), + '(example.com)'), array('[example.com]', - '[example.com]'), + '[example.com]'), array('', - '<example.com>'), + '<example.com>'), array('Hey, check out my cool site example.com okay?', - 'Hey, check out my cool site example.com okay?'), + 'Hey, check out my cool site example.com okay?'), array('Hey, check out my cool site example.com.I made it.', - 'Hey, check out my cool site example.com.I made it.'), + 'Hey, check out my cool site example.com.I made it.'), array('Hey, check out my cool site example.com.Funny thing...', - 'Hey, check out my cool site example.com.Funny thing...'), + 'Hey, check out my cool site example.com.Funny thing...'), array('Hey, check out my cool site example.com.You will love it.', - 'Hey, check out my cool site example.com.You will love it.'), + 'Hey, check out my cool site example.com.You will love it.'), array('What about parens (e.g. example.com/path/foo/(bar))?', - 'What about parens (e.g. example.com/path/foo/(bar))?'), + 'What about parens (e.g. example.com/path/foo/(bar))?'), array('What about parens (e.g. example.com/path/foo/(bar)?', - 'What about parens (e.g. example.com/path/foo/(bar)?'), + 'What about parens (e.g. example.com/path/foo/(bar)?'), array('What about parens (e.g. example.com/path/foo/(bar).)?', - 'What about parens (e.g. example.com/path/foo/(bar).)?'), + 'What about parens (e.g. example.com/path/foo/(bar).)?'), array('What about parens (e.g. example.com/path/(foo,bar)?', - 'What about parens (e.g. example.com/path/(foo,bar)?'), + 'What about parens (e.g. example.com/path/(foo,bar)?'), array('file.ext', 'file.ext'), array('file.html', diff --git a/tpl/index.php b/tpl/index.php index be375e75a6..36a1611449 100644 --- a/tpl/index.php +++ b/tpl/index.php @@ -1,4 +1,4 @@ - +xml version="1.0" encoding="UTF-8"?> <?php echo section('title'); ?>