X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=92a74eb49ee94ad542793caac0543417f8e85488;hb=11c06e21b7a656c4aeae0d5c157e1db97d6db02e;hp=a0ff1600ed4bcb4a9c961e50c83b4324e831c55b;hpb=ea4be0db89b5e95b50211e023e94aa008aadae46;p=friendica.git diff --git a/include/text.php b/include/text.php index a0ff1600ed..58f69449f4 100644 --- a/include/text.php +++ b/include/text.php @@ -9,19 +9,38 @@ // depending on the order in which they were declared in the array. require_once("include/template_processor.php"); +require_once("include/friendica_smarty.php"); if(! function_exists('replace_macros')) { function replace_macros($s,$r) { global $t; - - //$ts = microtime(); - $r = $t->replace($s,$r); - //$tt = microtime() - $ts; - - //$a = get_app(); - //$a->page['debug'] .= "$tt
\n"; - return template_unescape($r); +// $ts = microtime(); + $a = get_app(); + + if($a->theme['template_engine'] === 'smarty3') { + $template = ''; + if(gettype($s) === 'string') { + $template = $s; + $s = new FriendicaSmarty(); + } + foreach($r as $key=>$value) { + if($key[0] === '$') { + $key = substr($key, 1); + } + $s->assign($key, $value); + } + $output = $s->parsed($template); + } + else { + $r = $t->replace($s,$r); + + $output = template_unescape($r); + } +// $tt = microtime() - $ts; +// $a = get_app(); +// $a->page['debug'] .= "$tt
\n"; + return $output; }} @@ -70,7 +89,7 @@ function notags($string) { if(! function_exists('escape_tags')) { function escape_tags($string) { - return(htmlspecialchars($string)); + return(htmlspecialchars($string, ENT_COMPAT, 'UTF-8', false)); }} @@ -80,6 +99,9 @@ function escape_tags($string) { if(! function_exists('autoname')) { function autoname($len) { + if($len <= 0) + return ''; + $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u'); if(mt_rand(0,5) == 4) $vowels[] = 'y'; @@ -205,7 +227,6 @@ function hex2bin($s) { return ''; if(! ctype_xdigit($s)) { - logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true)); return($s); } @@ -226,6 +247,9 @@ if(! function_exists('paginate')) { function paginate(&$a) { $o = ''; $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string); + +// $stripped = preg_replace('/&zrl=(.*?)([\?&]|$)/ism','',$stripped); + $stripped = str_replace('q=','',$stripped); $stripped = trim($stripped,'/'); $pagenum = $a->pager['page']; @@ -275,6 +299,31 @@ function paginate(&$a) { return $o; }} +if(! function_exists('alt_pager')) { +function alt_pager(&$a, $i) { + $o = ''; + $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string); + $stripped = str_replace('q=','',$stripped); + $stripped = trim($stripped,'/'); + $pagenum = $a->pager['page']; + $url = $a->get_baseurl() . '/' . $stripped; + + $o .= '
'; + + if($a->pager['page']>1) + $o .= "pager['page'] - 1).'" class="pager_newer">' . t('newer') . ''; + if($i>0) { + if($a->pager['page']>1) + $o .= " - "; + $o .= "pager['page'] + 1).'" class="pager_older">' . t('older') . ''; + } + + + $o .= '
'."\r\n"; + + return $o; +}} + // Turn user/group ACLs stored as angle bracketed text into arrays if(! function_exists('expand_acl')) { @@ -306,11 +355,18 @@ function sanitise_acl(&$item) { // Convert an ACL array to a storable string +// Normally ACL permissions will be an array. +// We'll also allow a comma-separated string. if(! function_exists('perms2str')) { function perms2str($p) { $ret = ''; - $tmp = $p; + + if(is_array($p)) + $tmp = $p; + else + $tmp = explode(',',$p); + if(is_array($tmp)) { array_walk($tmp,'sanitise_acl'); $ret = implode('',$tmp); @@ -373,7 +429,7 @@ function load_view_file($s) { return file_get_contents("$d/$lang/$b"); $theme = current_theme(); - + if(file_exists("$d/theme/$theme/$b")) return file_get_contents("$d/theme/$theme/$b"); @@ -384,29 +440,64 @@ if(! function_exists('get_intltext_template')) { function get_intltext_template($s) { global $lang; + $a = get_app(); + $engine = ''; + if($a->theme['template_engine'] === 'smarty3') + $engine = "/smarty3"; + if(! isset($lang)) $lang = 'en'; - if(file_exists("view/$lang/$s")) - return file_get_contents("view/$lang/$s"); - elseif(file_exists("view/en/$s")) - return file_get_contents("view/en/$s"); + if(file_exists("view/$lang$engine/$s")) + return file_get_contents("view/$lang$engine/$s"); + elseif(file_exists("view/en$engine/$s")) + return file_get_contents("view/en$engine/$s"); else - return file_get_contents("view/$s"); + return file_get_contents("view$engine/$s"); }} if(! function_exists('get_markup_template')) { -function get_markup_template($s) { - $a=get_app(); +function get_markup_template($s, $root = '') { +// $ts = microtime(); + $a = get_app(); + + if($a->theme['template_engine'] === 'smarty3') { + $template_file = get_template_file($a, 'smarty3/' . $s, $root); + + $template = new FriendicaSmarty(); + $template->filename = $template_file; + +// $tt = microtime() - $ts; +// $a->page['debug'] .= "$tt
\n"; + return $template; + } + else { + $template_file = get_template_file($a, $s, $root); +// $file_contents = file_get_contents($template_file); +// $tt = microtime() - $ts; +// $a->page['debug'] .= "$tt
\n"; +// return $file_contents; +// logger($template_file); + return file_get_contents($template_file); + } +}} + +if(! function_exists("get_template_file")) { +function get_template_file($a, $filename, $root = '') { $theme = current_theme(); - - if(file_exists("view/theme/$theme/$s")) - return file_get_contents("view/theme/$theme/$s"); - elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/$s")) - return file_get_contents("view/theme/".$a->theme_info["extends"]."/$s"); + + // Make sure $root ends with a slash / + if($root !== '' && $root[strlen($root)-1] !== '/') + $root = $root . '/'; + + if(file_exists($root . "view/theme/$theme/$filename")) + $template_file = $root . "view/theme/$theme/$filename"; + elseif (x($a->theme_info,"extends") && file_exists($root . "view/theme/".$a->theme_info["extends"]."/$filename")) + $template_file = $root . "view/theme/".$a->theme_info["extends"]."/$filename"; else - return file_get_contents("view/$s"); + $template_file = $root . "view/$filename"; + return $template_file; }} @@ -474,6 +565,10 @@ function get_tags($s) { $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s); + // ignore anything in a bbtag + + $s = preg_replace('/\[(.*?)\]/sm','',$s); + // 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. @@ -553,7 +648,7 @@ function contact_block() { if((! is_array($a->profile)) || ($a->profile['hide-friends'])) return $o; - $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0", + $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0", intval($a->profile['uid']) ); if(count($r)) { @@ -564,7 +659,7 @@ function contact_block() { $micropro = Null; } else { - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 ORDER BY RAND() LIMIT %d", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), intval($shown) ); @@ -610,6 +705,8 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { $url = $redirect_url; $sparkle = ' sparkle'; } + else + $url = zrl($url); } $click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : ''); if($click) @@ -639,7 +736,7 @@ function search($s,$id='search-box',$url='/search',$save = false) { $a = get_app(); $o = '
'; $o .= '
'; - $o .= ''; + $o .= ''; $o .= ''; if($save) $o .= ''; @@ -649,6 +746,10 @@ function search($s,$id='search-box',$url='/search',$save = false) { if(! function_exists('valid_email')) { function valid_email($x){ + + if(get_config('system','disable_email_validation')) + return true; + if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) return true; return false; @@ -670,6 +771,55 @@ function linkify($s) { return($s); }} +function get_poke_verbs() { + + // index is present tense verb + // value is array containing past tense verb, translation of present, translation of past + + $arr = array( + 'poke' => array( 'poked', t('poke'), t('poked')), + 'ping' => array( 'pinged', t('ping'), t('pinged')), + 'prod' => array( 'prodded', t('prod'), t('prodded')), + 'slap' => array( 'slapped', t('slap'), t('slapped')), + 'finger' => array( 'fingered', t('finger'), t('fingered')), + 'rebuff' => array( 'rebuffed', t('rebuff'), t('rebuffed')), + ); + call_hooks('poke_verbs', $arr); + return $arr; +} + +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'), + 'mellow' => t('mellow'), + 'tired' => t('tired'), + 'perky' => t('perky'), + 'angry' => t('angry'), + 'stupefied' => t('stupified'), + 'puzzled' => t('puzzled'), + 'interested' => t('interested'), + 'bitter' => t('bitter'), + 'cheerful' => t('cheerful'), + 'alive' => t('alive'), + 'annoyed' => t('annoyed'), + 'anxious' => t('anxious'), + 'cranky' => t('cranky'), + 'disturbed' => t('disturbed'), + 'frustrated' => t('frustrated'), + 'motivated' => t('motivated'), + 'relaxed' => t('relaxed'), + 'surprised' => t('surprised'), + ); + + call_hooks('mood_verbs', $arr); + return $arr; +} + /** * @@ -709,27 +859,23 @@ function smilies($s, $sample = false) { '</3', '<\\3', ':-)', -// ':)', ';-)', -// ';)', ':-(', -// ':(', ':-P', -// ':P', + ':-p', ':-"', ':-"', ':-x', ':-X', ':-D', -// ':D', '8-|', '8-O', ':-O', '\\o/', 'o.O', 'O.o', - '\\.../', - '\\ooo/', + 'o_O', + 'O_o', ":'(", ":-!", ":-/", @@ -739,56 +885,46 @@ function smilies($s, $sample = false) { ':homebrew', ':coffee', ':facepalm', - ':headdesk', - '~friendika', - '~friendica', -// 'Diaspora*' - ':beard', - ':whitebeard' + ':like', + ':dislike', + '~friendica' ); $icons = array( - '<3', - '</3', - '<\\3', - ':-)', -// ':)', - ';-)', -// ';)', - ':-(', -// ':(', - ':-P', -// ':P', - ':-\', - ':-\', - ':-x', - ':-X', - ':-D', -// ':D', - '8-|', - '8-O', - ':-O', - '\\o/', - 'o.O', - 'O.o', - '\\.../', - '\\ooo/', - ':\'(', - ':-!', - ':-/', - ':-[', - '8-)', - ':beer', - ':homebrew', - ':coffee', - ':facepalm', - ':headdesk', - '~friendika ~friendika', - '~friendica ~friendica', -// 'DiasporaDiaspora*', - ':beard', - ':whitebeard' + '<3', + '</3', + '<\\3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-\', + ':-\', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendica ~friendica' ); $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); @@ -828,7 +964,7 @@ function preg_heart($x) { return $x[0]; $t = ''; for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) - $t .= '<3'; + $t .= '<3'; $r = str_replace($x[0],$t,$x[0]); return $r; } @@ -880,13 +1016,11 @@ if(! function_exists('prepare_body')) { function prepare_body($item,$attach = false) { $a = get_app(); - call_hooks('prepare_body_init', $item); + call_hooks('prepare_body_init', $item); - $cache = get_config('system','itemcache'); - - if (($cache != '')) { - $cachefile = $cache."/".$item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']); + $cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); + if (($cachefile != '')) { if (file_exists($cachefile)) $s = file_get_contents($cachefile); else { @@ -896,11 +1030,15 @@ function prepare_body($item,$attach = false) { } else $s = prepare_text($item['body']); + $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; if(! $attach) { + // Replace the blockquotes with quotes that are used in mails + $mailquote = '
'; + $s = str_replace(array('
', '
', '
'), array($mailquote, $mailquote, $mailquote), $s); return $s; } @@ -910,54 +1048,64 @@ function prepare_body($item,$attach = false) { foreach($arr as $r) { $matches = false; $icon = ''; - $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches); + $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches, PREG_SET_ORDER); if($cnt) { - $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/'))); - switch($icontype) { - case 'video': - case 'audio': - case 'image': - case 'text': - $icon = '
'; - break; - default: - $icon = '
'; - break; + foreach($matches as $mtch) { + $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); + switch($icontype) { + case 'video': + case 'audio': + case 'image': + case 'text': + $icon = '
'; + break; + default: + $icon = '
'; + break; + } + $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1])); + $title .= ' ' . $mtch[2] . ' ' . t('bytes'); + if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) + $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; + else + $the_url = $mtch[1]; + + $s .= '' . $icon . ''; } - $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1])); - $title .= ' ' . $matches[2] . ' ' . t('bytes'); - - $s .= '' . $icon . ''; } } $s .= '
'; } - $matches = false; - $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); - if($cnt) { -// logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); - foreach($matches as $mtch) { - if(strlen($x)) - $x .= ','; - $x .= file_tag_decode($mtch[1]); - } - if(strlen($x)) - $s .= '
' . t('Categories:') . ' ' . $x . '
'; + // Look for spoiler + $spoilersearch = '
'; + + // Remove line breaks before the spoiler + while ((strpos($s, "\n".$spoilersearch) !== false)) + $s = str_replace("\n".$spoilersearch, $spoilersearch, $s); + while ((strpos($s, "
".$spoilersearch) !== false)) + $s = str_replace("
".$spoilersearch, $spoilersearch, $s); + + while ((strpos($s, $spoilersearch) !== false)) { + + $pos = strpos($s, $spoilersearch); + $rnd = random_string(8); + $spoilerreplace = '
'.sprintf(t('Click to open/close')).''. + '