X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=c0b716afb238d0aa5ae5cef47135ecf99e6c4164;hb=34e7206ba49b2835ce21a762a59a8a3626f29b60;hp=628b4fc2daaa4be33ba7997863275b888d1ad6d1;hpb=ddf1caf0fd9ea4fc97147ba7b45587bcf7a6fab4;p=friendica.git diff --git a/include/text.php b/include/text.php index 628b4fc2da..c0b716afb2 100644 --- a/include/text.php +++ b/include/text.php @@ -27,7 +27,11 @@ function replace_macros($s,$r) { $a = get_app(); $t = $a->template_engine(); - $output = $t->replace_macros($s,$r); + try { + $output = $t->replace_macros($s,$r); + } catch (Exception $e) { + echo "
".__function__.": ".$e->getMessage().""; killme(); + } $a->save_timestamp($stamp1, "rendering"); @@ -260,75 +264,106 @@ function hex2bin($s) { }} -if(! function_exists('paginate')) { +if(! function_exists('paginate_data')) { /** - * Automatic pagination. + * Automatica pagination data. * - * To use, get the count of total items. - * Then call $a->set_pager_total($number_items); - * Optionally call $a->set_pager_itemspage($n) to the number of items to display on each page - * Then call paginate($a) after the end of the display loop to insert the pager block on the page - * (assuming there are enough items to paginate). - * When using with SQL, the setting LIMIT %d, %d => $a->pager['start'],$a->pager['itemspage'] - * will limit the results to the correct items for the current page. - * The actual page handling is then accomplished at the application layer. - * * @param App $a App instance - * @return string html for pagination #FIXME remove html + * @param int $count [optional] item count (used with alt pager) + * @return Array data for pagination template */ -function paginate(&$a) { - $o = ''; +function paginate_data(&$a, $count=null) { $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']; $url = $a->get_baseurl() . '/' . $stripped; - if($a->pager['total'] > $a->pager['itemspage']) { - $o .= '
".__function__.": ".$e->getMessage().""; killme(); + } $a->save_timestamp($stamp1, "file"); return $template; - /* - - if($a->theme['template_engine'] === 'smarty3') { - $template_file = get_template_file($a, 'smarty3/' . $s, $root); - - $template = new FriendicaSmarty(); - $template->filename = $template_file; - $a->save_timestamp($stamp1, "rendering"); - - return $template; - } - else { - $template_file = get_template_file($a, $s, $root); - $a->save_timestamp($stamp1, "rendering"); - - $stamp1 = microtime(true); - $content = file_get_contents($template_file); - $a->save_timestamp($stamp1, "file"); - return $content; - - } - */ }} if(! function_exists("get_template_file")) { @@ -613,6 +613,8 @@ function get_template_file($a, $filename, $root = '') { $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"; + elseif (file_exists("{$root}/$filename")) + $template_file = "{$root}/$filename"; else $template_file = "{$root}view/$filename"; @@ -1081,7 +1083,8 @@ function smilies($s, $sample = false) { ':facepalm', ':like', ':dislike', - '~friendica' + '~friendica', + 'red#' ); @@ -1118,7 +1121,8 @@ function smilies($s, $sample = false) { '', '', '', - '~friendica ' + '~friendica ', + 'red ' ); $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); @@ -1265,11 +1269,42 @@ if(! function_exists('prepare_body')) { * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author) */ -function prepare_body($item,$attach = false) { +function prepare_body(&$item,$attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); + $searchpath = $a->get_baseurl()."/search?tag="; + + $tags=array(); + $hashtags = array(); + $mentions = array(); + + if (!get_config('system','suppress_tags')) { + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", + intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); + + foreach($taglist as $tag) { + + if ($tag["url"] == "") + $tag["url"] = $searchpath.strtolower($tag["term"]); + + if ($tag["type"] == TERM_HASHTAG) { + $hashtags[] = "#".$tag["term"].""; + $prefix = "#"; + } elseif ($tag["type"] == TERM_MENTION) { + $mentions[] = "@".$tag["term"].""; + $prefix = "@"; + } + $tags[] = $prefix."".$tag["term"].""; + } + } + + $item['tags'] = $tags; + $item['hashtags'] = $hashtags; + $item['mentions'] = $mentions; + + //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); @@ -1305,18 +1340,49 @@ function prepare_body($item,$attach = false) { return $s; } + $as = ''; + $vhead = false; $arr = explode('[/attach],',$item['attach']); if(count($arr)) { - $s .= '