X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=8ce54b3c6786c130a6c93e5e72402e855946418b;hb=cdebdc777e38506e673864377ce17a5af91dd8a1;hp=658c2cdd64cb391d4c64fc1e22d4aca996bc507f;hpb=016b6428a091e4d9067962e2d8931e7e51254621;p=friendica.git diff --git a/include/text.php b/include/text.php index 658c2cdd64..8ce54b3c67 100644 --- a/include/text.php +++ b/include/text.php @@ -2,6 +2,7 @@ require_once("include/template_processor.php"); require_once("include/friendica_smarty.php"); +require_once("mod/proxy.php"); if(! function_exists('replace_macros')) { /** @@ -269,23 +270,23 @@ if(! function_exists('paginate_data')) { * @return Array data for pagination template */ function paginate_data(&$a, $count=null) { - $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string); + $stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string); $stripped = str_replace('q=','',$stripped); $stripped = trim($stripped,'/'); $pagenum = $a->pager['page']; - if (($a->page_offset != "") AND !strstr($stripped, "&offset=")) + if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped)) $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="") { + if (!strpos($url, "?")) { + if ($pos = strpos($url, "&")) + $url = substr($url, 0, $pos)."?".substr($url, $pos + 1); + } $d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class); } @@ -384,6 +385,18 @@ function alt_pager(&$a, $i) { }} +if(! function_exists('scroll_loader')) { +/** + * Loader for infinite scrolling + * @return string html for loader + */ +function scroll_loader() { + $tpl = get_markup_template("scroll_loader.tpl"); + return replace_macros($tpl, array( + 'wait' => t('Loading more entries...'), + 'end' => t('The end') + )); +}} if(! function_exists('expand_acl')) { /** @@ -739,6 +752,9 @@ if(! function_exists('get_tags')) { function get_tags($s) { $ret = array(); + // Convert hashtag links to hashtags + $s = preg_replace("/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism", "#$2", $s); + // ignore anything in a code block $s = preg_replace('/\[code\](.*?)\[\/code\]/sm','',$s); @@ -928,7 +944,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { . (($click) ? ' fakelink' : '') . '" ' . (($redir) ? ' target="redir" ' : '') . (($url) ? ' href="' . $url . '"' : '') . $click . ' >' . $contact['name']
+			. proxy_url($contact['micro']) . '' . "\r\n"; } }} @@ -1109,7 +1125,8 @@ function smilies($s, $sample = false) { ':like', ':dislike', '~friendica', - 'red#' + 'red#', + 'red#matrix' ); @@ -1147,7 +1164,8 @@ function smilies($s, $sample = false) { ':like', ':dislike', '~friendica ~friendica', - 'red red' + 'redredmatrix', + 'redredmatrix' ); $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); @@ -1278,6 +1296,28 @@ function redir_private_images($a, &$item) { }} +function put_item_in_cache(&$item, $update = false) { + + if (($item["rendered-hash"] != hash("md5", $item["body"])) OR ($item["rendered-hash"] == "") OR + ($item["rendered-html"] == "") OR get_config("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"]; + + $a = get_app(); + redir_private_images($a, $item); + + $item["rendered-html"] = prepare_text($item["body"]); + $item["rendered-hash"] = hash("md5", $item["body"]); + $item["body"] = $body; + + if ($update AND ($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"])); + } + } +} // 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 @@ -1329,30 +1369,11 @@ function prepare_body(&$item,$attach = false, $preview = false) { $item['hashtags'] = $hashtags; $item['mentions'] = $mentions; + put_item_in_cache($item, true); + $s = $item["rendered-html"]; - //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); - $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); - - if (($cachefile != '')) { - if (file_exists($cachefile)) { - $stamp1 = microtime(true); - $s = file_get_contents($cachefile); - $a->save_timestamp($stamp1, "file"); - } else { - redir_private_images($a, $item); - $s = prepare_text($item['body']); - - $stamp1 = microtime(true); - file_put_contents($cachefile, $s); - $a->save_timestamp($stamp1, "file"); - - logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile); - } - } else { - redir_private_images($a, $item); - $s = prepare_text($item['body']); - } - + require_once("mod/proxy.php"); + $s = proxy_parse_html($s); $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); @@ -1501,7 +1522,7 @@ function prepare_text($text) { else $s = smilies(bbcode($text)); - return $s; + return trim($s); }} @@ -2227,3 +2248,22 @@ function is_a_date_arg($s) { } return false; } + +/** + * remove intentation from a text + */ +function deindent($text, $chr="[\t ]", $count=NULL) { + $text = fix_mce_lf($text); + $lines = explode("\n", $text); + if (is_null($count)) { + $m = array(); + $k=0; while($k