]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Update functions and calls
[friendica.git] / include / text.php
index 0b763d687c69294752cbc64ade24f198748fc932..66918e9a66e1c1fae6412acf91d0d07b7d25a093 100644 (file)
@@ -3,12 +3,15 @@
  * @file include/text.php
  */
 use Friendica\App;
+use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Content\Smilies;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Profile;
+use Friendica\Model\Term;
 use Friendica\Util\Map;
 
 require_once "include/friendica_smarty.php";
@@ -1009,7 +1012,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
                        $url = $redirect_url;
                        $sparkle = ' sparkle';
                } else {
-                       $url = zrl($url);
+                       $url = Profile::zrl($url);
                }
        }
 
@@ -1032,22 +1035,34 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
 }
 
 /**
- * search box
+ * Search box.
  *
- * @param string $s search query
- * @param string $id html id
- * @param string $url search url
- * @param boolean $savedsearch show save search button
+ * @param string $s     Search query.
+ * @param string $id    HTML id
+ * @param string $url   Search url.
+ * @param bool   $save  Show save search button.
+ * @param bool   $aside Display the search widgit aside.
+ *
+ * @return string Formatted HTML.
  */
-function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = true) {
+function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = true)
+{
+       $mode = 'text';
+
+       if (strpos($s, '#') === 0) {
+               $mode = 'tag';
+       }
+       $save_label = $mode === 'text' ? t('Save') : t('Follow');
+
        $values = array(
                        '$s' => htmlspecialchars($s),
                        '$id' => $id,
                        '$action_url' => $url,
                        '$search_label' => t('Search'),
-                       '$save_label' => t('Save'),
+                       '$save_label' => $save_label,
                        '$savedsearch' => Feature::isEnabled(local_user(),'savedsearch'),
                        '$search_hint' => t('@name, !forum, #tags, content'),
+                       '$mode' => $mode
                );
 
        if (!$aside) {
@@ -1894,9 +1909,8 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
        return true;
 }
 
-function file_tag_save_file($uid, $item, $file) {
-       require_once "include/files.php";
-
+function file_tag_save_file($uid, $item, $file)
+{
        if (! intval($uid)) {
                return false;
        }
@@ -1914,7 +1928,7 @@ function file_tag_save_file($uid, $item, $file) {
                        );
                }
 
-               create_files_from_item($item);
+               Term::createFromItem($item);
 
                $saved = PConfig::get($uid, 'system', 'filetags');
                if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
@@ -1925,9 +1939,8 @@ function file_tag_save_file($uid, $item, $file) {
        return true;
 }
 
-function file_tag_unsave_file($uid, $item, $file, $cat = false) {
-       require_once "include/files.php";
-
+function file_tag_unsave_file($uid, $item, $file, $cat = false)
+{
        if (! intval($uid)) {
                return false;
        }
@@ -1954,7 +1967,7 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) {
                intval($uid)
        );
 
-       create_files_from_item($item);
+       Term::createFromItem($item);
 
        $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
                dbesc($file),
@@ -2048,16 +2061,14 @@ function formatBytes($bytes, $precision = 2) {
  */
 function format_network_name($network, $url = 0) {
        if ($network != "") {
-               require_once 'include/contact_selectors.php';
                if ($url != "") {
-                       $network_name = '<a href="'.$url.'">'.network_to_name($network, $url)."</a>";
+                       $network_name = '<a href="'.$url.'">'.ContactSelector::networkToName($network, $url)."</a>";
                } else {
-                       $network_name = network_to_name($network);
+                       $network_name = ContactSelector::networkToName($network);
                }
 
                return $network_name;
        }
-
 }
 
 /**
@@ -2096,7 +2107,8 @@ function text_highlight($s, $lang) {
        }
 
        $renderer = new Text_Highlighter_Renderer_Html($options);
-       $hl = Text_Highlighter::factory($lang);
+       $factory = new Text_Highlighter();
+       $hl = $factory->factory($lang);
        $hl->setRenderer($renderer);
        $o = $hl->highlight($s);
        $o = str_replace("\n", '', $o);