/**
* This is our template processor
*
- * @global Template $t
* @param string|FriendicaSmarty $s the string requiring macro substitution,
* or an instance of FriendicaSmarty
* @param array $r key value pairs (search => replace)
* @return string substituted string
*/
function replace_macros($s,$r) {
- global $t;
$stamp1 = microtime(true);
$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);
+ $t = $a->template_engine();
+ try {
+ $output = $t->replace_macros($s,$r);
+ } catch (Exception $e) {
+ echo "<pre><b>".__function__."</b>: ".$e->getMessage()."</pre>"; killme();
}
- else {
- $r = $t->replace($s,$r);
- $output = template_unescape($r);
- }
- $a = get_app();
$a->save_timestamp($stamp1, "rendering");
return $output;
}}
-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 .= '<div class="pager">';
- if($a->pager['page'] != 1)
- $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
+ $data = array();
+ function _l(&$d, $name, $url, $text, $class="") {
+
+ $d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class);
+ }
+
+ if (!is_null($count)){
+ // alt pager
+ if($a->pager['page']>1)
+ _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('newer'));
+ if($count>0)
+ _l($data, "next", $url.'&page='.($a->pager['page'] + 1), t('older'));
+ } else {
+ // full pager
+ if($a->pager['total'] > $a->pager['itemspage']) {
+ if($a->pager['page'] != 1)
+ _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('prev'));
- $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
+ _l($data, "first", $url."&page=1", t('first'));
- $numpages = $a->pager['total'] / $a->pager['itemspage'];
+
+ $numpages = $a->pager['total'] / $a->pager['itemspage'];
$numstart = 1;
- $numstop = $numpages;
+ $numstop = $numpages;
- if($numpages > 14) {
- $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
- $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
- }
-
- for($i = $numstart; $i <= $numstop; $i++){
- if($i == $a->pager['page'])
- $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
- else
- $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
- $o .= '</span> ';
- }
+ if($numpages > 14) {
+ $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
+ $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
+ }
- if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
- if($i == $a->pager['page'])
- $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
- else
- $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
- $o .= '</span> ';
- }
+ $pages = array();
+
+ for($i = $numstart; $i <= $numstop; $i++){
+ if($i == $a->pager['page'])
+ _l($pages, $i, "#", $i, "current");
+ else
+ _l($pages, $i, $url."&page=$i", $i, "n");
+ }
+
+ if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
+ if($i == $a->pager['page'])
+ _l($pages, $i, "#", $i, "current");
+ else
+ _l($pages, $i, $url."&page=$i", $i, "n");
+ }
+
+ $data['pages'] = $pages;
- $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
- $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
+ $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
+ _l($data, "last", $url."&page=$lastpage", t('last'));
+
+ if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
+ _l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next'));
- if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
- $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
- $o .= '</div>'."\r\n";
+ }
}
- return $o;
+ return $data;
+
+}}
+
+if(! function_exists('paginate')) {
+/**
+ * Automatic pagination.
+ *
+ * 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
+ */
+function paginate(&$a) {
+
+ $data = paginate_data($a);
+ $tpl = get_markup_template("paginate.tpl");
+ return replace_macros($tpl, array("pager" => $data));
+
}}
if(! function_exists('alt_pager')) {
* @return string html for pagination #FIXME remove html
*/
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 .= '<div class="pager">';
-
- if($a->pager['page']>1)
- $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'" class="pager_newer">' . t('newer') . '</a>';
- if($i>0) {
- if($a->pager['page']>1)
- $o .= " - ";
- $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'" class="pager_older">' . t('older') . '</a>';
- }
-
- $o .= '</div>'."\r\n";
-
- return $o;
+ $data = paginate_data($a, $i);
+ $tpl = get_markup_template("paginate.tpl");
+ return replace_macros($tpl, array('pager' => $data));
+
}}
$stamp1 = microtime(true);
$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;
- $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;
-
+ $t = $a->template_engine();
+ try {
+ $template = $t->get_template_file($s, $root);
+ } catch (Exception $e) {
+ echo "<pre><b>".__function__."</b>: ".$e->getMessage()."</pre>"; killme();
}
+
+ $a->save_timestamp($stamp1, "file");
+
+ return $template;
}}
if(! function_exists("get_template_file")) {
$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";
':facepalm',
':like',
':dislike',
- '~friendica'
+ '~friendica',
+ 'red#'
);
'<img class="smiley" src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
'<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
- '<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>'
+ '<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
+ '<a href="http://friendica.com">red <img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" /></a>'
);
$params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
* @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[] = "#<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+ $prefix = "#";
+ } elseif ($tag["type"] == TERM_MENTION) {
+ $mentions[] = "@<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+ $prefix = "@";
+ }
+ $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"external-link\">".$tag["term"]."</a>";
+ }
+ }
+
+ $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']));
return $s;
}
+ $as = '';
+ $vhead = false;
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
- $s .= '<div class="body-attach">';
+ $as .= '<div class="body-attach">';
foreach($arr as $r) {
$matches = false;
$icon = '';
$cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
- $filetype = strtolower(substr( $mtch[3], 0, strpos($mtch[3],'/') ));
+ $mime = $mtch[3];
+
+ 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];
+
+ if(strpos($mime, 'video') !== false) {
+ if(!$vhead) {
+ $vhead = true;
+ $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array(
+ '$baseurl' => $a->get_baseurl(),
+ ));
+ $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), array(
+ '$baseurl' => $a->get_baseurl(),
+ ));
+ }
+
+ $id = end(explode('/', $the_url));
+ $as .= replace_macros(get_markup_template('video_top.tpl'), array(
+ '$video' => array(
+ 'id' => $id,
+ 'title' => t('View Video'),
+ 'src' => $the_url,
+ 'mime' => $mime,
+ ),
+ ));
+ }
+
+ $filetype = strtolower(substr( $mime, 0, strpos($mime,'/') ));
if($filetype) {
- $filesubtype = strtolower(substr( $mtch[3], strpos($mtch[3],'/') + 1 ));
+ $filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 ));
$filesubtype = str_replace('.', '-', $filesubtype);
}
else {
$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 .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
+ $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
}
}
}
- $s .= '<div class="clear"></div></div>';
+ $as .= '<div class="clear"></div></div>';
}
+ $s = $s . $as;
// Look for spoiler