X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=8f0ff6e73e584153fce9fa13a318181bb55495e8;hb=e4a2430967f229dd02bc97c5c66be0620b3235d8;hp=ea5deb4c1442a7c43ebb8929dbac66f64209290a;hpb=638e6491cc305b0455ae890351183e03e0bce52b;p=friendica.git diff --git a/include/text.php b/include/text.php index ea5deb4c14..8f0ff6e73e 100644 --- a/include/text.php +++ b/include/text.php @@ -1,6 +1,7 @@ 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; @@ -707,20 +702,18 @@ $LOGGER_LEVELS = array(); * LOGGER_ALL * * @global App $a - * @global dba $db * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ function logger($msg, $level = 0) { $a = get_app(); - global $db; global $LOGGER_LEVELS; // turn off logger in install mode if ( $a->module == 'install' - || ! ($db && $db->connected) + || !dba::$connected ) { return; } @@ -753,7 +746,7 @@ function logger($msg, $level = 0) { $callers = debug_backtrace(); $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", - datetime_convert(), + datetime_convert('UTC', 'UTC', 'now', 'Y-m-d\TH:i:s\Z'), $process_id, $LOGGER_LEVELS[$level], basename($callers[0]['file']), @@ -781,7 +774,6 @@ function logger($msg, $level = 0) { * LOGGER_ALL * * @global App $a - * @global dba $db * @global array $LOGGER_LEVELS * @param string $msg * @param int $level @@ -789,12 +781,11 @@ function logger($msg, $level = 0) { function dlogger($msg, $level = 0) { $a = get_app(); - global $db; // turn off logger in install mode if ( $a->module == 'install' - || ! ($db && $db->connected) + || !dba::$connected ) { return; } @@ -1200,12 +1191,11 @@ function get_mood_verbs() { return $arr; } -if (! function_exists('day_translate')) { /** - * Translate days and months names - * - * @param string $s - * @return string + * @brief Translate days and months names. + * + * @param string $s String with day or month name. + * @return string Translated string. */ function day_translate($s) { $ret = str_replace(array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'), @@ -1217,8 +1207,23 @@ function day_translate($s) { $ret); return $ret; -}} +} +/** + * @brief Translate short days and months names. + * + * @param string $s String with short day or month name. + * @return string Translated string. + */ +function day_short_translate($s) { + $ret = str_replace(array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'), + array(t('Mon'), t('Tue'), t('Wed'), t('Thu'), t('Fri'), t('Sat'), t('Sund')), + $s); + $ret = str_replace(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov','Dec'), + array(t('Jan'), t('Feb'), t('Mar'), t('Apr'), t('May'), ('Jun'), t('Jul'), t('Aug'), t('Sep'), t('Oct'), t('Nov'), t('Dec')), + $ret); + return $ret; +} if (! function_exists('normalise_link')) { /** @@ -1290,20 +1295,16 @@ 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); } } } -// Given an item array, convert the body element from bbcode to html and add smilie icons. -// If attach is true, also add icons for item attachments - -if (! function_exists('prepare_body')) { /** - * Given an item array, convert the body element from bbcode to html and add smilie icons. - * If attach is true, also add icons for item attachments + * @brief Given an item array, convert the body element from bbcode to html and add smilie icons. + * If attach is true, also add icons for item attachments. * * @param array $item * @param boolean $attach @@ -1317,23 +1318,36 @@ 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(); + // In order to provide theme developers more possibilities, event items + // are treated differently. + if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) { + $ev = format_event_item($item); + return $ev; + } + 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 ($tag["type"] == TERM_HASHTAG) { + if ($orig_tag != $tag["url"]) { + $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']); + } $hashtags[] = "#".$tag["term"].""; $prefix = "#"; } elseif ($tag["type"] == TERM_MENTION) { @@ -1342,16 +1356,17 @@ function prepare_body(&$item, $attach = false, $preview = false) { } $tags[] = $prefix."".$tag["term"].""; } + dba::close($taglist); } $item['tags'] = $tags; $item['hashtags'] = $hashtags; $item['mentions'] = $mentions; - // Update the cached values if there is no "zrl=..." on the links - $update = (!local_user() and !remote_user() and ($item["uid"] == 0)); + // Update the cached values if there is no "zrl=..." on the links. + $update = (!local_user() && !remote_user() && ($item["uid"] == 0)); - // Or update it if the current viewer is the intented viewer + // Or update it if the current viewer is the intented viewer. if (($item["uid"] == local_user()) && ($item["uid"] != 0)) { $update = true; } @@ -1364,7 +1379,7 @@ function prepare_body(&$item, $attach = false, $preview = false) { $s = $prep_arr['html']; if (! $attach) { - // Replace the blockquotes with quotes that are used in mails + // Replace the blockquotes with quotes that are used in mails. $mailquote = '
'; $s = str_replace(array('
', '
', '
'), array($mailquote, $mailquote, $mailquote), $s); return $s; @@ -1374,11 +1389,10 @@ function prepare_body(&$item, $attach = false, $preview = false) { $vhead = false; $arr = explode('[/attach],', $item['attach']); if (count($arr)) { - $as .= '
'; foreach ($arr as $r) { $matches = false; $icon = ''; - $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER); + $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r ,$matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { $mime = $mtch[3]; @@ -1393,10 +1407,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(), )); } @@ -1411,53 +1425,41 @@ function prepare_body(&$item, $attach = false, $preview = false) { )); } - $filetype = strtolower(substr( $mime, 0, strpos($mime,'/') )); + $filetype = strtolower(substr($mime, 0, strpos($mime, '/'))); if ($filetype) { - $filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 )); + $filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1)); $filesubtype = str_replace('.', '-', $filesubtype); } else { $filetype = 'unkn'; $filesubtype = 'unkn'; } - $icon = '
'; - /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); - switch($icontype) { - case 'video': - case 'audio': - case 'image': - case 'text': - $icon = '
'; - break; - default: - $icon = '
'; - break; - }*/ - $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1])); $title .= ' ' . $mtch[2] . ' ' . t('bytes'); + $icon = '
'; $as .= '' . $icon . ''; } } } - $as .= '
'; } - $s = $s . $as; + if ($as != '') { + $s .= '
'.$as.'
'; + } - // map + // Map. if (strpos($s, '
') !== false && x($item, 'coord')) { $x = generate_map(trim($item['coord'])); if ($x) { - $s = preg_replace('/\
/','$0' . $x,$s); + $s = preg_replace('/\
/', '$0' . $x, $s); } } - // Look for spoiler + // Look for spoiler. $spoilersearch = '
'; - // Remove line breaks before the spoiler + // Remove line breaks before the spoiler. while ((strpos($s, "\n" . $spoilersearch) !== false)) { $s = str_replace("\n" . $spoilersearch, $spoilersearch, $s); } @@ -1473,7 +1475,7 @@ function prepare_body(&$item, $attach = false, $preview = false) { $s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch)); } - // Look for quote with author + // Look for quote with author. $authorsearch = '
'; while ((strpos($s, $authorsearch) !== false)) { @@ -1484,7 +1486,7 @@ function prepare_body(&$item, $attach = false, $preview = false) { $s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch)); } - // replace friendica image url size with theme preference + // Replace friendica image url size with theme preference. if (x($a->theme_info, 'item_image_size')){ $ps = $a->theme_info['item_image_size']; $s = preg_replace('|(]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s); @@ -1494,15 +1496,13 @@ function prepare_body(&$item, $attach = false, $preview = false) { call_hooks('prepare_body_final', $prep_arr); return $prep_arr['html']; -}} - +} -if (! function_exists('prepare_text')) { /** - * Given a text string, convert from bbcode to html and add smilie icons. + * @brief Given a text string, convert from bbcode to html and add smilie icons. * - * @param string $text - * @return string + * @param string $text String with bbcode. + * @return string Formattet HTML. */ function prepare_text($text) { @@ -1515,9 +1515,7 @@ function prepare_text($text) { } return trim($s); -}} - - +} /** * return array with details for categories and folders for an item @@ -1672,7 +1670,7 @@ function generate_user_guid() { if (! dbm::is_result($x)) { $found = false; } - } while ($found == true ); + } while ($found == true); return $guid; }