diff options
Diffstat (limited to 'include/text.php')
-rwxr-xr-x | include/text.php | 96 |
1 files changed, 80 insertions, 16 deletions
diff --git a/include/text.php b/include/text.php index 53b92c05f..b36e550f9 100755 --- a/include/text.php +++ b/include/text.php @@ -278,6 +278,11 @@ function hex2bin($s) { if(! (is_string($s) && strlen($s))) return ''; + if(strlen($s) & 1) { + logger('hex2bin: illegal hex string: ' . $s); + return $s; + } + if(! ctype_xdigit($s)) { return($s); } @@ -569,9 +574,20 @@ function get_tags($s) { $s = preg_replace('/\[style=(.*?)\]/sm','',$s); + // match any double quoted tags + + if(preg_match_all('/([@#]\"\;.*?\"\;)/',$s,$match)) { + foreach($match[1] as $mtch) { + $ret[] = $mtch; + } + } + // Match full names against @tags including the space between first and last // We will look these up afterward to see if they are full names or not recognisable. + + + if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) { foreach($match[1] as $mtch) { if(strstr($mtch,"]")) { @@ -602,6 +618,10 @@ function get_tags($s) { // try not to catch url fragments if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1))) continue; + // or quote remnants from the quoted strings we already picked out earlier + if(strpos($mtch,'"')) + continue; + $ret[] = $mtch; } } @@ -614,12 +634,28 @@ function get_tags($s) { } } + // make sure the longer tags are returned first so that if two or more have common substrings + // we'll replace the longest ones first. Otherwise the common substring would be found in + // both strings and the string replacement would link both to the shorter strings and + // fail to link the longer string. RedMatrix github issue #378 + + usort($ret,'tag_sort_length'); - // logger('get_tags: ' . print_r($ret,true)); + +// logger('get_tags: ' . print_r($ret,true)); return $ret; } +function tag_sort_length($a,$b) { + if(mb_strlen($a) == mb_strlen($b)) + return 0; + return((mb_strlen($b) < mb_strlen($a)) ? (-1) : 1); +} + + + + function strip_zids($s) { return preg_replace('/[\?&]zid=(.*?)(&|$)/ism','$2',$s); @@ -671,11 +707,10 @@ function contact_block() { if((! is_array($a->profile)) || ($a->profile['hide_friends'])) return $o; - $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and abook_flags = 0 and not (xchan_flags & %d) and not (xchan_flags & %d) and not (xchan_flags & %d)", + $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and not ( abook_flags & %d ) and not (xchan_flags & %d)", intval($a->profile['uid']), - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED) + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_HIDDEN|XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED) ); if(count($r)) { $total = intval($r[0]['total']); @@ -686,11 +721,10 @@ function contact_block() { } else { - $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND abook_flags = 0 and not (xchan_flags & %d ) and not (xchan_flags & %d ) and not (xchan_flags & %d ) ORDER BY RAND() LIMIT %d", + $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND not ( abook_flags & %d) and not (xchan_flags & %d ) ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED), + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_HIDDEN|XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED), intval($shown) ); @@ -780,9 +814,9 @@ function searchbox($s,$id='search-box',$url='/search',$save = false) { $o .= '<form action="' . z_root() . '/' . $url . '" method="get" >'; $o .= '<input type="hidden" name="f" value="" />'; $o .= '<input type="text" class="icon-search" name="search" id="search-text" placeholder="" value="' . $s .'" onclick="this.submit();" />'; - $o .= '<input type="submit" name="submit" id="search-submit" value="' . t('Search') . '" />'; + $o .= '<input type="submit" name="submit" class="btn btn-default" id="search-submit" value="' . t('Search') . '" />'; if(feature_enabled(local_user(),'savedsearch')) - $o .= '<input type="submit" name="searchsave" id="search-save" value="' . t('Save') . '" />'; + $o .= '<input type="submit" name="searchsave" class="btn btn-default" id="search-save" value="' . t('Save') . '" />'; $o .= '</form></div>'; return $o; } @@ -861,9 +895,6 @@ function get_poke_verbs() { function get_mood_verbs() { - // index is present tense verb - // value is array containing past tense verb, translation of present, translation of past - $arr = array( 'happy' => t('happy'), 'sad' => t('sad'), @@ -882,6 +913,7 @@ function get_mood_verbs() { 'cranky' => t('cranky'), 'disturbed' => t('disturbed'), 'frustrated' => t('frustrated'), + 'depressed' => t('depressed'), 'motivated' => t('motivated'), 'relaxed' => t('relaxed'), 'surprised' => t('surprised'), @@ -1169,6 +1201,33 @@ function format_categories(&$item,$writeable) { return $s; } +// Add any hashtags which weren't mentioned in the message body, e.g. community tags + +function format_hashtags(&$item) { + + $s = ''; + $terms = get_terms_oftype($item['term'],TERM_HASHTAG); + if($terms) { + $categories = array(); + foreach($terms as $t) { + $term = htmlspecialchars($t['term'],ENT_COMPAT,'UTF-8',false) ; + if(! trim($term)) + continue; + if(strpos($item['body'], $t['url'])) + continue; + + if($s) + $s .= ' '; + + $s .= '#<a href="' . zid($t['url']) . '" >' . $term . '</a>'; + } + } + return $s; +} + + + + function format_filer(&$item) { @@ -1221,6 +1280,9 @@ function prepare_body(&$item,$attach = false) { $writeable = ((get_observer_hash() == $item['owner_xchan']) ? true : false); + + $s .= format_hashtags($item); + $s .= format_categories($item,$writeable); if(local_user() == $item['uid']) @@ -1712,6 +1774,7 @@ function check_webbie($arr) { $str .= "'" . dbesc($y) . "'"; } } + if(strlen($str)) { $r = q("select channel_address from channel where channel_address in ( $str ) "); if(count($r)) { @@ -1720,8 +1783,9 @@ function check_webbie($arr) { } } foreach($arr as $x) { - if(! in_array($x,$taken)) { - return $x; + $y = legal_webbie($x); + if(! in_array($y,$taken)) { + return $y; } } } |