]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
App::get_baseurl is now replaced with System::baseUrl
[friendica.git] / include / text.php
index 71a2564405714659f472904c2f1cf1850edd13c4..fa26b0ef83427caa2d759542e41cd8ce57288142 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Friendica\App;
+use Friendica\Core\System;
 
 require_once "include/template_processor.php";
 require_once "include/friendica_smarty.php";
@@ -24,7 +25,7 @@ function replace_macros($s, $r) {
        $a = get_app();
 
        // pass $baseurl to all templates
-       $r['$baseurl'] = App::get_baseurl();
+       $r['$baseurl'] = System::baseUrl();
 
        $t = $a->template_engine();
        try {
@@ -488,8 +489,6 @@ if (! function_exists('item_new_uri')) {
 function item_new_uri($hostname, $uid, $guid = "") {
 
        do {
-               $dups = false;
-
                if ($guid == "") {
                        $hash = get_guid(32);
                } else {
@@ -499,11 +498,7 @@ function item_new_uri($hostname, $uid, $guid = "") {
 
                $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash;
 
-               $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
-                       dbesc($uri));
-               if (dbm::is_result($r)) {
-                       $dups = true;
-               }
+               $dups = dba::exists('item', array('uri' => $uri));
        } while ($dups == true);
 
        return $uri;
@@ -1290,9 +1285,9 @@ function put_item_in_cache(&$item, $update = false) {
                $item["rendered-hash"] = hash("md5", $item["body"]);
                $item["body"] = $body;
 
-               if ($update && ($item["id"] != 0)) {
-                       q("UPDATE `item` SET `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
-                               dbesc($item["rendered-html"]), dbesc($item["rendered-hash"]), intval($item["id"]));
+               if ($update && ($item["id"] > 0)) {
+                       dba::update('item', array('rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]),
+                                       array('id' => $item["id"]), false);
                }
        }
 }
@@ -1317,22 +1312,29 @@ function prepare_body(&$item, $attach = false, $preview = false) {
        $a = get_app();
        call_hooks('prepare_body_init', $item);
 
-       $searchpath = z_root() . "/search?tag=";
+       $searchpath = System::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`",
+               $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
                                intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
 
-               foreach ($taglist as $tag) {
-
+               while ($tag = dba::fetch($taglist)) {
                        if ($tag["url"] == "") {
                                $tag["url"] = $searchpath.strtolower($tag["term"]);
                        }
 
+                       $orig_tag = $tag["url"];
+
+                       $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+
+                       if ($orig_tag != $tag["url"]) {
+                               $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+                       }
+
                        if ($tag["type"] == TERM_HASHTAG) {
                                $hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
                                $prefix = "#";
@@ -1342,6 +1344,7 @@ function prepare_body(&$item, $attach = false, $preview = false) {
                        }
                        $tags[] = $prefix."<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
                }
+               dba::close($taglist);
        }
 
        $item['tags'] = $tags;
@@ -1392,10 +1395,10 @@ function prepare_body(&$item, $attach = false, $preview = false) {
                                                if (!$vhead) {
                                                        $vhead = true;
                                                        $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array(
-                                                               '$baseurl' => z_root(),
+                                                               '$baseurl' => System::baseUrl(),
                                                        ));
                                                        $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), array(
-                                                               '$baseurl' => z_root(),
+                                                               '$baseurl' => System::baseUrl(),
                                                        ));
                                                }
 
@@ -1665,7 +1668,7 @@ function generate_user_guid() {
                if (! dbm::is_result($x)) {
                        $found = false;
                }
-       } while ($found == true );
+       } while ($found == true);
 
        return $guid;
 }