]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Bugfix of the bugfix :)
[friendica.git] / include / text.php
index 264dd76a5e49a1362660ac6f0955654bc7274add..a47e352bae7fecdcee91fbcb58622ead3a2b15bf 100644 (file)
@@ -21,7 +21,7 @@ if(! function_exists('replace_macros')) {
  * @return string substituted string
  */
 function replace_macros($s,$r) {
-       
+
        $stamp1 = microtime(true);
 
        $a = get_app();
@@ -55,7 +55,7 @@ function random_string($size = 64,$type = RANDOM_STRING_HEX) {
 
 if(! function_exists('notags')) {
 /**
- * This is our primary input filter. 
+ * This is our primary input filter.
  *
  * The high bit hack only involved some old IE browser, forget which (IE5/Mac?)
  * that had an XSS attack vector due to stripping the high-bit on an 8-bit character
@@ -278,12 +278,19 @@ function paginate_data(&$a, $count=null) {
        $stripped = str_replace('q=','',$stripped);
        $stripped = trim($stripped,'/');
        $pagenum = $a->pager['page'];
-       $url = $a->get_baseurl() . '/' . $stripped;
 
+       if (($a->page_offset != "") AND !strstr($stripped, "&offset="))
+               $stripped .= "&offset=".urlencode($a->page_offset);
+       if (!strpos($stripped, "?")) {
+               if ($pos = strpos($stripped, "&"))
+                       $stripped = substr($stripped, 0, $pos)."?".substr($stripped, $pos + 1);
+       }
+
+       $url = $a->get_baseurl() . '/' . $stripped;
 
        $data = array();
-       function _l(&$d, $name, $url, $text, $class="") { 
-               
+       function _l(&$d, $name, $url, $text, $class="") {
+
                $d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class); 
        }
 
@@ -292,7 +299,7 @@ function paginate_data(&$a, $count=null) {
                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'));
+                       _l($data,  "next", $url.'&page='.($a->pager['page'] + 1), t('older'));
        } else {
                // full pager
                if($a->pager['total'] > $a->pager['itemspage']) {
@@ -301,7 +308,7 @@ function paginate_data(&$a, $count=null) {
 
                        _l($data, "first", $url."&page=1",  t('first'));
 
-                       
+
                        $numpages = $a->pager['total'] / $a->pager['itemspage'];
 
                        $numstart = 1;
@@ -332,11 +339,11 @@ function paginate_data(&$a, $count=null) {
 
                        $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'));
 
-               }       
+               }
        }
        return $data;
 
@@ -359,7 +366,7 @@ if(! function_exists('paginate')) {
  * @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));
@@ -378,14 +385,14 @@ function alt_pager(&$a, $i) {
        $data = paginate_data($a, $i);
        $tpl = get_markup_template("paginate.tpl");
        return replace_macros($tpl, array('pager' => $data));
-       
+
 }}
 
 
 if(! function_exists('expand_acl')) {
 /**
  * Turn user/group ACLs stored as angle bracketed text into arrays
- * 
+ *
  * @param string $s
  * @return array
  */
@@ -1269,11 +1276,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[] = "#<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']));
 
@@ -1523,7 +1561,7 @@ if(! function_exists('feed_hublinks')) {
  * @return string hub link xml elements
  */
 function feed_hublinks() {
-
+       $a = get_app();
        $hub = get_config('system','huburl');
 
        $hubxml = '';
@@ -1534,6 +1572,8 @@ function feed_hublinks() {
                                $h = trim($h);
                                if(! strlen($h))
                                        continue;
+                               if ($h === '[internal]')
+                                       $h = $a->get_baseurl() . '/pubsubhubbub';
                                $hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
                        }
                }