We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit ada615d3 authored by Sarven Capadisli's avatar Sarven Capadisli

Merge branch '0.8.x' of git@gitorious.org:laconica/mainline into 0.8.x

parents fc89c345 31329c33
...@@ -445,7 +445,7 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { ...@@ -445,7 +445,7 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) {
'(?:/[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;]*)?'. // /path '(?:/[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;]*)?'. // /path
'(?:\?[\pN\pL\$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/]*)?'. // ?query string '(?:\?[\pN\pL\$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/]*)?'. // ?query string
'(?:\#[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/\?\#]*)?'. // #fragment '(?:\#[\pN\pL$\[\]\,\!\(\)\.\-\_\+\/\=\&\;\/\?\#]*)?'. // #fragment
')(?<![\?\.\,\#\)\]\,])'. ')(?<![\?\.\,\#\,])'.
')'. ')'.
'#ixu'; '#ixu';
preg_match_all($regex,$text,$matches); preg_match_all($regex,$text,$matches);
...@@ -454,16 +454,52 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) { ...@@ -454,16 +454,52 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) {
} }
function callback_helper($matches, $callback, $notice_id) { function callback_helper($matches, $callback, $notice_id) {
$pos = strpos($matches[0],$matches['url']); $url=$matches['url'];
$left = substr($matches[0],0,$pos); $left = strpos($matches[0],$url);
$right = substr($matches[0],$pos+strlen($matches['url'])); $right = $left+strlen($url);
$groupSymbolSets=array(
array(
'left'=>'(',
'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)){ if(empty($notice_id)){
$result = call_user_func_array($callback,$matches['url']); $result = call_user_func_array($callback,$url);
}else{ }else{
$result = call_user_func_array($callback, array($matches['url'],$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) { function curry($fn) {
......
...@@ -28,7 +28,7 @@ class HashTagDetectionTest extends PHPUnit_Framework_TestCase ...@@ -28,7 +28,7 @@ class HashTagDetectionTest extends PHPUnit_Framework_TestCase
array('hello', array('hello',
'hello'), 'hello'),
array('#hello', array('#hello',
'<a href="/tag/hello">hello</a>'), '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>'),
); );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment