X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=b831859e993392d14de493f3ae349d9e61e919e2;hb=3bc55e7b8bff2fe331371333de9ff4f96c8584d2;hp=575e796f11dff1aa3b27098fa88001811de32b8c;hpb=0615fda25e81d686c7d7a67b4d0674716eeb5929;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index 575e796f11..b831859e99 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1,7 +1,7 @@ '(', + '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(array($url,$notice_id)) ); } - return $left . $result . $right; + return substr($matches[0],0,$left) . $result . substr($matches[0],$right); } function curry($fn) { @@ -467,16 +506,13 @@ function curry($fn) { array_shift($args); $id = uniqid('_partial'); $GLOBALS[$id] = array($fn, $args); - return create_function( - '', - ' - $args = func_get_args(); - return call_user_func_array( - $GLOBALS["'.$id.'"][0], - array_merge( - $args, - $GLOBALS["'.$id.'"][1])); - '); + return create_function('', + '$args = func_get_args(); '. + 'return call_user_func_array('. + '$GLOBALS["'.$id.'"][0],'. + 'array_merge('. + '$args,'. + '$GLOBALS["'.$id.'"][1]));'); } function common_linkify($url) { @@ -484,7 +520,7 @@ function common_linkify($url) { // functions $url = htmlspecialchars_decode($url); - if(strpos($url, '@')!==false && strpos($url, ':')===false){ + if(strpos($url, '@') !== false && strpos($url, ':') === false) { //url is an email address without the mailto: protocol return XMLStringer::estring('a', array('href' => "mailto:$url", 'rel' => 'external'), $url); } @@ -506,42 +542,31 @@ function common_linkify($url) { $attachment_id = null; $has_thumb = false; - // Check to see whether there's a filename associated with this URL. - // If there is, it's an upload and qualifies as an attachment + // Check to see whether this is a known "attachment" URL. - $localfile = File::staticGet('url', $longurl); + $f = File::staticGet('url', $longurl); - if (!empty($localfile)) { - if (isset($localfile->filename)) { - $is_attachment = true; - $attachment_id = $localfile->id; - } + if (empty($f)) { + // XXX: this writes to the database. :< + $f = File::processNew($longurl); } - // if this URL is an attachment, then we set class='attachment' and id='attahcment-ID' - // where ID is the id of the attachment for the given URL. - // - // we need a better test telling what can be shown as an attachment - // we're currently picking up oembeds only. - // I think the best option is another file_view table in the db - // and associated dbobject. - - $query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'"; - $file = new File; - $file->query($query); - $file->fetch(); - - if (!empty($file->file_id)) { - $is_attachment = true; - $attachment_id = $file->file_id; - - $query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'"; - $file2 = new File; - $file2->query($query); - $file2->fetch(); - - if (!empty($file2)) { - $has_thumb = true; + if (!empty($f)) { + if ($f->isEnclosure()) { + $is_attachment = true; + $attachment_id = $f->id; + } else { + $foe = File_oembed::staticGet('file_id', $f->id); + if (!empty($foe)) { + // if it has OEmbed info, it's an attachment, too + $is_attachment = true; + $attachment_id = $f->id; + + $thumb = File_thumbnail::staticGet('file_id', $f->id); + if (!empty($thumb)) { + $has_thumb = true; + } + } } } @@ -1278,7 +1303,7 @@ function common_cache_key($extra) $base_key = common_keyize(common_config('site', 'name')); } - return 'laconica:' . $base_key . ':' . $extra; + return 'statusnet:' . $base_key . ':' . $extra; } function common_keyize($str) @@ -1341,7 +1366,7 @@ function common_shorten_url($long_url) $curlh = curl_init(); curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait - curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); + curl_setopt($curlh, CURLOPT_USERAGENT, 'StatusNet'); curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); switch($svc) {