X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=66918e9a66e1c1fae6412acf91d0d07b7d25a093;hb=0fe832ef8aeafa1ddba793a8b084005cf070f1f4;hp=cbba8d0c5b501065c3ff451e14706be4ec9704a9;hpb=394e94cbc1b3a11e50cd6b076582403d62839c86;p=friendica.git diff --git a/include/text.php b/include/text.php index cbba8d0c5b..66918e9a66 100644 --- a/include/text.php +++ b/include/text.php @@ -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"; @@ -994,7 +997,7 @@ function contact_block() { function micropro($contact, $redirect = false, $class = '', $textmode = false) { // Use the contact URL if no address is available - if ($contact["addr"] == "") { + if (!x($contact, "addr")) { $contact["addr"] = $contact["url"]; } @@ -1003,14 +1006,13 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { $redir = false; if ($redirect) { - $a = get_app(); $redirect_url = 'redir/' . $contact['id']; if (local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) { $redir = true; $url = $redirect_url; $sparkle = ' sparkle'; } else { - $url = zrl($url); + $url = Profile::zrl($url); } } @@ -1020,7 +1022,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { } return replace_macros(get_markup_template(($textmode)?'micropro_txt.tpl':'micropro_img.tpl'),array( - '$click' => (($contact['click']) ? $contact['click'] : ''), + '$click' => defaults($contact, 'click', ''), '$class' => $class, '$url' => $url, '$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), @@ -1033,24 +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 bool $save Show save search button. + * @param bool $aside Display the search widgit aside. * - * @param string $s search query - * @param string $id html id - * @param string $url search url - * @param boolean $savedsearch show save search button + * @return string Formatted HTML. */ -function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = true) { - $a = get_app(); +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) { @@ -1202,11 +1214,15 @@ function redir_private_images($a, &$item) } } -function put_item_in_cache(&$item, $update = false) { - - if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") || - ($item["rendered-html"] == "") || Config::get("system", "ignore_cache")) { +function put_item_in_cache(&$item, $update = false) +{ + $rendered_hash = defaults($item, 'rendered-hash', ''); + if ($rendered_hash == '' + || $item["rendered-html"] == "" + || $rendered_hash != hash("md5", $item["body"]) + || Config::get("system", "ignore_cache") + ) { // The function "redir_private_images" changes the body. // I'm not sure if we should store it permanently, so we save the old value. $body = $item["body"]; @@ -1467,9 +1483,8 @@ function prepare_text($text) { * ] * ] */ -function get_cats_and_terms($item) { - - $a = get_app(); +function get_cats_and_terms($item) +{ $categories = array(); $folders = array(); @@ -1894,12 +1909,12 @@ 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"; - - $result = false; - if (! intval($uid)) +function file_tag_save_file($uid, $item, $file) +{ + if (! intval($uid)) { return false; + } + $r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval($uid) @@ -1913,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) . ']')) { @@ -1924,12 +1939,11 @@ 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"; - - $result = false; - if (! intval($uid)) +function file_tag_unsave_file($uid, $item, $file, $cat = false) +{ + if (! intval($uid)) { return false; + } if ($cat == true) { $pattern = '<' . file_tag_encode($file) . '>' ; @@ -1939,7 +1953,6 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) { $termtype = TERM_FILE; } - $r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval($uid) @@ -1954,14 +1967,14 @@ 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), intval(TERM_OBJ_POST), intval($termtype), - intval($uid)); - + intval($uid) + ); if (!DBM::is_result($r)) { $saved = PConfig::get($uid, 'system', 'filetags'); PConfig::set($uid, 'system', 'filetags', str_replace($pattern, '', $saved)); @@ -2026,7 +2039,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) { } function formatBytes($bytes, $precision = 2) { - $units = array('B', 'KB', 'MB', 'GB', 'TB'); + $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); @@ -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 = ''.network_to_name($network, $url).""; + $network_name = ''.ContactSelector::networkToName($network, $url).""; } 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);