return $content;
}
- $theme = current_theme();
+ $theme = $a->getCurrentTheme();
if (file_exists("$d/theme/$theme/$b")) {
$stamp1 = microtime(true);
// turn off logger in install mode
if (
- $a->module == 'install'
+ $a->mode == App::MODE_INSTALL
|| !dba::$connected
) {
return;
// turn off logger in install mode
if (
- $a->module == 'install'
+ $a->mode == App::MODE_INSTALL
|| !dba::$connected
) {
return;
{
$body = $item["body"];
- // Add the content warning
- if (!empty($item['content-warning'])) {
- $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]';
- }
-
$rendered_hash = defaults($item, 'rendered-hash', '');
+ $rendered_html = defaults($item, 'rendered-html', '');
if ($rendered_hash == ''
|| $item["rendered-html"] == ""
$item["rendered-html"] = prepare_text($item["body"]);
$item["rendered-hash"] = hash("md5", $item["body"]);
+ // Force an update if the generated values differ from the existing ones
+ if ($rendered_hash != $item["rendered-hash"]) {
+ $update = true;
+ }
+
+ // Only compare the HTML when we forcefully ignore the cache
+ if (Config::get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
+ $update = true;
+ }
+
if ($update && ($item["id"] > 0)) {
dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
['id' => $item["id"]], false);
* @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 array $item
* @param boolean $attach
+ * @param boolean $is_preview
* @return string item body html
* @hook prepare_body_init item array before any work
- * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html
+ * @hook prepare_body_content_filter ('item'=>item array, 'filter_reasons'=>string array) before first bbcode to html
+ * @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
* @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
*/
-function prepare_body(&$item, $attach = false, $preview = false) {
-
+function prepare_body(array &$item, $attach = false, $is_preview = false)
+{
$a = get_app();
Addon::callHooks('prepare_body_init', $item);
- $searchpath = System::baseUrl() . "/search?tag=";
-
- $tags = [];
- $hashtags = [];
- $mentions = [];
-
// In order to provide theme developers more possibilities, event items
// are treated differently.
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
return $ev;
}
- $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));
-
- while ($tag = dba::fetch($taglist)) {
- if ($tag["url"] == "") {
- $tag["url"] = $searchpath . strtolower($tag["term"]);
- }
-
- $orig_tag = $tag["url"];
+ $tags = \Friendica\Model\Term::populateTagsFromItem($item);
- $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+ $item['tags'] = $tags['tags'];
+ $item['hashtags'] = $tags['hashtags'];
+ $item['mentions'] = $tags['mentions'];
- if ($tag["type"] == TERM_HASHTAG) {
- if ($orig_tag != $tag["url"]) {
- $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
- }
-
- $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
- $prefix = "#";
- } elseif ($tag["type"] == TERM_MENTION) {
- $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
- $prefix = "@";
+ // Compile eventual content filter reasons
+ $filter_reasons = [];
+ if (!$is_preview && public_contact() != $item['author-id']) {
+ if (!empty($item['content-warning']) && (!local_user() || !PConfig::get(local_user(), 'system', 'disable_cw', false))) {
+ $filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']);
}
- $tags[] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
+ $hook_data = [
+ 'item' => $item,
+ 'filter_reasons' => $filter_reasons
+ ];
+ Addon::callHooks('prepare_body_content_filter', $hook_data);
+ $filter_reasons = $hook_data['filter_reasons'];
+ unset($hook_data);
}
- 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() && !remote_user() && ($item["uid"] == 0));
put_item_in_cache($item, $update);
$s = $item["rendered-html"];
- $prep_arr = ['item' => $item, 'html' => $s, 'preview' => $preview];
- Addon::callHooks('prepare_body', $prep_arr);
- $s = $prep_arr['html'];
+ $hook_data = [
+ 'item' => $item,
+ 'html' => $s,
+ 'preview' => $is_preview,
+ 'filter_reasons' => $filter_reasons
+ ];
+ Addon::callHooks('prepare_body', $hook_data);
+ $s = $hook_data['html'];
+ unset($hook_data);
+
+ $s = apply_content_filter($s, $filter_reasons);
if (! $attach) {
// Replace the blockquotes with quotes that are used in mails.
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
}
- $prep_arr = ['item' => $item, 'html' => $s];
- Addon::callHooks('prepare_body_final', $prep_arr);
+ $hook_data = ['item' => $item, 'html' => $s];
+ Addon::callHooks('prepare_body_final', $hook_data);
- return $prep_arr['html'];
+ return $hook_data['html'];
+}
+
+/**
+ * Given a HTML text and a set of filtering reasons, adds a content hiding header with the provided reasons
+ *
+ * Reasons are expected to have been translated already.
+ *
+ * @param string $html
+ * @param array $reasons
+ * @return string
+ */
+function apply_content_filter($html, array $reasons)
+{
+ if (count($reasons)) {
+ $tpl = get_markup_template('wall/content_filter.tpl');
+ $html = replace_macros($tpl, [
+ '$reasons' => $reasons,
+ '$rnd' => random_string(8),
+ '$openclose' => L10n::t('Click to open/close'),
+ '$html' => $html
+ ]);
+ }
+
+ return $html;
}
/**
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
if ($r) {
foreach ($matches as $mtch) {
- if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
- $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
- elseif (stristr($mtch[1],'vimeo'))
- $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
+ if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
+ $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
+ } elseif (stristr($mtch[1], 'vimeo')) {
+ $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
+ }
}
}
return $s;
}
// ex. given music,video return <music><video> or [music][video]
-function file_tag_list_to_file($list,$type = 'file') {
+function file_tag_list_to_file($list, $type = 'file') {
$tag_list = '';
if (strlen($list)) {
$list_array = explode(",",$list);
}
// ex. given <music><video>[friends], return music,video or friends
-function file_tag_file_to_list($file,$type = 'file') {
+function file_tag_file_to_list($file, $type = 'file') {
$matches = false;
$list = '';
if ($type == 'file') {
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
foreach ($check_new_tags as $tag) {
- if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
+ if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
$new_tags[] = $tag;
+ }
}
$filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
foreach ($check_deleted_tags as $tag) {
- if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
+ if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
$deleted_tags[] = $tag;
+ }
}
foreach ($deleted_tags as $key => $tag) {
if ($i > 1900) {
$y = date('Y');
if ($i <= $y + 1 && strpos($s, '-') == 4) {
- $m = intval(substr($s,5));
+ $m = intval(substr($s, 5));
if ($m > 0 && $m <= 12)
return true;
+ }
}
}
return false;
preg_match("|^" . $chr . "*|", $lines[$k], $m);
$count = strlen($m[0]);
}
+
for ($k = 0; $k < count($lines); $k++) {
$lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
}