Add content_filter hook #566

Merged
MrPetovan merged 10 commits from task/add-content_filter-hook into develop 2018-04-06 06:44:01 +02:00
10 changed files with 119 additions and 112 deletions

View file

@ -12,7 +12,7 @@ use Friendica\Core\PConfig;
function blockem_install() function blockem_install()
{ {
Addon::registerHook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body'); Addon::registerHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
Addon::registerHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item'); Addon::registerHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
Addon::registerHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings'); Addon::registerHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post'); Addon::registerHook('addon_settings_post', 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
@ -23,6 +23,7 @@ function blockem_install()
function blockem_uninstall() function blockem_uninstall()
{ {
Addon::unregisterHook('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
Addon::unregisterHook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body'); Addon::unregisterHook('prepare_body', 'addon/blockem/blockem.php', 'blockem_prepare_body');
Addon::unregisterHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item'); Addon::unregisterHook('display_item', 'addon/blockem/blockem.php', 'blockem_display_item');
Addon::unregisterHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings'); Addon::unregisterHook('addon_settings', 'addon/blockem/blockem.php', 'blockem_addon_settings');
@ -106,38 +107,33 @@ function blockem_enotify_store(&$a,&$b) {
} }
} }
function blockem_prepare_body(&$a,&$b) { function blockem_prepare_body_content_filter(\Friendica\App $a, &$hook_data)
{
if(! local_user()) if (!local_user()) {
return; return;
}
$words = null; $profiles_string = null;
if(local_user()) { if (local_user()) {
$words = PConfig::get(local_user(),'blockem','words'); $profiles_string = PConfig::get(local_user(), 'blockem', 'words');
} }
if($words) {
$arr = explode(',',$words); if ($profiles_string) {
} $profiles_array = explode(',', $profiles_string);
else { } else {
return; return;
} }
$found = false; $found = false;
if(count($arr)) { foreach ($profiles_array as $word) {
foreach($arr as $word) { if (link_compare($hook_data['item']['author-link'], trim($word))) {
if(! strlen(trim($word))) { $found = true;
continue; break;
}
if(link_compare($b['item']['author-link'],$word)) {
$found = true;
break;
}
} }
} }
if($found) {
$rnd = random_string(8); if ($found) {
$b['html'] = '<div id="blockem-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'blockem-' . $rnd . '\'); >' . L10n::t('Hidden content by %s - Click to open/close', $word) . '</div><div id="blockem-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>'; $hook_data['filter_reasons'][] = L10n::t('Filtered user: %s', $hook_data['item']['author-name']);
} }
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-09 13:00+0100\n" "POT-Creation-Date: 2018-04-01 11:11-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,41 +17,41 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: blockem.php:51 blockem.php:55 #: blockem.php:52 blockem.php:56
msgid "\"Blockem\"" msgid "\"Blockem\""
msgstr "" msgstr ""
#: blockem.php:59 #: blockem.php:60
msgid "" msgid ""
"Hides user's content by collapsing posts. Also replaces their avatar with " "Hides user's content by collapsing posts. Also replaces their avatar with "
"generic image." "generic image."
msgstr "" msgstr ""
#: blockem.php:60 #: blockem.php:61
msgid "Comma separated profile URLS:" msgid "Comma separated profile URLS:"
msgstr "" msgstr ""
#: blockem.php:64 #: blockem.php:65
msgid "Save Settings" msgid "Save Settings"
msgstr "" msgstr ""
#: blockem.php:77 #: blockem.php:78
msgid "BLOCKEM Settings saved." msgid "BLOCKEM Settings saved."
msgstr "" msgstr ""
#: blockem.php:140 #: blockem.php:136
#, php-format #, php-format
msgid "Hidden content by %s - Click to open/close" msgid "Filtered user: %s"
msgstr "" msgstr ""
#: blockem.php:193 #: blockem.php:189
msgid "Unblock Author" msgid "Unblock Author"
msgstr "" msgstr ""
#: blockem.php:195 #: blockem.php:191
msgid "Block Author" msgid "Block Author"
msgstr "" msgstr ""
#: blockem.php:227 #: blockem.php:223
msgid "blockem settings updated" msgid "blockem settings updated"
msgstr "" msgstr ""

View file

@ -103,7 +103,7 @@ function fromgplus_addon_admin(&$a, &$o)
$o = replace_macros($t, [ $o = replace_macros($t, [
'$submit' => L10n::t('Save Settings'), '$submit' => L10n::t('Save Settings'),
'$key' => ['key', L10n::t('Key'), trim(Config::get('fromgplus', 'key')), L10n::t('')], '$key' => ['key', L10n::t('Key'), trim(Config::get('fromgplus', 'key')), ''],
]); ]);
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-11-12 16:52+0000\n" "POT-Creation-Date: 2018-04-01 11:14-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,34 +17,34 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: fromgplus.php:46 fromgplus.php:50 #: fromgplus.php:55 fromgplus.php:59
msgid "Google+ Mirror" msgid "Google+ Mirror"
msgstr "" msgstr ""
#: fromgplus.php:55 #: fromgplus.php:64
msgid "Enable Google+ Import" msgid "Enable Google+ Import"
msgstr "" msgstr ""
#: fromgplus.php:58 #: fromgplus.php:67
msgid "Google Account ID" msgid "Google Account ID"
msgstr "" msgstr ""
#: fromgplus.php:61 #: fromgplus.php:70
msgid "Add keywords to post" msgid "Add keywords to post"
msgstr "" msgstr ""
#: fromgplus.php:66 fromgplus.php:95 #: fromgplus.php:75 fromgplus.php:105
msgid "Save Settings" msgid "Save Settings"
msgstr "" msgstr ""
#: fromgplus.php:87 #: fromgplus.php:96
msgid "Google+ Import Settings saved." msgid "Google+ Import Settings saved."
msgstr "" msgstr ""
#: fromgplus.php:96 #: fromgplus.php:106
msgid "Key" msgid "Key"
msgstr "" msgstr ""
#: fromgplus.php:103 #: fromgplus.php:114
msgid "Settings updated." msgid "Settings updated."
msgstr "" msgstr ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-29 22:43+0700\n" "POT-Creation-Date: 2018-04-01 11:11-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,62 +17,62 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: langfilter.php:57 #: langfilter.php:58
msgid "Language Filter" msgid "Language Filter"
msgstr "" msgstr ""
#: langfilter.php:58 #: langfilter.php:59
msgid "" msgid ""
"This addon tries to identify the language posts are writen in. If it does " "This addon tries to identify the language posts are writen in. If it does "
"not match any language specifed below, posts will be hidden by collapsing " "not match any language specifed below, posts will be hidden by collapsing "
"them." "them."
msgstr "" msgstr ""
#: langfilter.php:59 #: langfilter.php:60
msgid "Use the language filter" msgid "Use the language filter"
msgstr "" msgstr ""
#: langfilter.php:60 #: langfilter.php:61
msgid "Able to read" msgid "Able to read"
msgstr "" msgstr ""
#: langfilter.php:60 #: langfilter.php:61
msgid "" msgid ""
"List of abbreviations (iso2 codes) for languages you speak, comma separated. " "List of abbreviations (iso2 codes) for languages you speak, comma separated. "
"For example \"de,it\"." "For example \"de,it\"."
msgstr "" msgstr ""
#: langfilter.php:61 #: langfilter.php:62
msgid "Minimum confidence in language detection" msgid "Minimum confidence in language detection"
msgstr "" msgstr ""
#: langfilter.php:61 #: langfilter.php:62
msgid "" msgid ""
"Minimum confidence in language detection being correct, from 0 to 100. Posts " "Minimum confidence in language detection being correct, from 0 to 100. Posts "
"will not be filtered when the confidence of language detection is below this " "will not be filtered when the confidence of language detection is below this "
"percent value." "percent value."
msgstr "" msgstr ""
#: langfilter.php:62 #: langfilter.php:63
msgid "Minimum length of message body" msgid "Minimum length of message body"
msgstr "" msgstr ""
#: langfilter.php:62 #: langfilter.php:63
msgid "" msgid ""
"Minimum number of characters in message body for filter to be used. Posts " "Minimum number of characters in message body for filter to be used. Posts "
"shorter than this will not be filtered. Note: Language detection is " "shorter than this will not be filtered. Note: Language detection is "
"unreliable for short content (<200 characters)." "unreliable for short content (<200 characters)."
msgstr "" msgstr ""
#: langfilter.php:63 #: langfilter.php:64
msgid "Save Settings" msgid "Save Settings"
msgstr "" msgstr ""
#: langfilter.php:104 #: langfilter.php:105
msgid "Language Filter Settings saved." msgid "Language Filter Settings saved."
msgstr "" msgstr ""
#: langfilter.php:181 #: langfilter.php:182
#, php-format #, php-format
msgid "Hidden content in %s - Click to open/close" msgid "Filtered language: %s"
msgstr "" msgstr ""

View file

@ -19,13 +19,14 @@ use Friendica\Core\PConfig;
function langfilter_install() function langfilter_install()
{ {
Addon::registerHook('prepare_body', 'addon/langfilter/langfilter.php', 'langfilter_prepare_body', 10); Addon::registerHook('prepare_body_content_filter', 'addon/langfilter/langfilter.php', 'langfilter_prepare_body_content_filter', 10);
Addon::registerHook('addon_settings', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings'); Addon::registerHook('addon_settings', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings_post'); Addon::registerHook('addon_settings_post', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings_post');
} }
function langfilter_uninstall() function langfilter_uninstall()
{ {
Addon::unregisterHook('prepare_body_content_filter', 'addon/langfilter/langfilter.php', 'langfilter_prepare_body_content_filter');
Addon::unregisterHook('prepare_body', 'addon/langfilter/langfilter.php', 'langfilter_prepare_body'); Addon::unregisterHook('prepare_body', 'addon/langfilter/langfilter.php', 'langfilter_prepare_body');
Addon::unregisterHook('addon_settings', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings'); Addon::unregisterHook('addon_settings', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings');
Addon::unregisterHook('addon_settings_post', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings_post'); Addon::unregisterHook('addon_settings_post', 'addon/langfilter/langfilter.php', 'langfilter_addon_settings_post');
@ -114,7 +115,7 @@ function langfilter_addon_settings_post(App $a, &$b)
* expand it again. * expand it again.
*/ */
function langfilter_prepare_body(App $a, &$b) function langfilter_prepare_body_content_filter(App $a, &$hook_data)
{ {
$logged_user = local_user(); $logged_user = local_user();
if (!$logged_user) { if (!$logged_user) {
@ -124,7 +125,7 @@ function langfilter_prepare_body(App $a, &$b)
// Never filter own messages // Never filter own messages
// TODO: find a better way to extract this // TODO: find a better way to extract this
$logged_user_profile = $a->get_baseurl() . '/profile/' . $a->user['nickname']; $logged_user_profile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
if ($logged_user_profile == $b['item']['author-link']) { if ($logged_user_profile == $hook_data['item']['author-link']) {
return; return;
} }
@ -138,24 +139,26 @@ function langfilter_prepare_body(App $a, &$b)
if (!$minlen) { if (!$minlen) {
$minlen = 32; $minlen = 32;
} }
if (strlen($b['item']['body']) < $minlen) { if (strlen($hook_data['item']['body']) < $minlen) {
return; return;
} }
$spoken_config = PConfig::get(local_user(), 'langfilter', 'languages'); $read_languages_string = PConfig::get(local_user(), 'langfilter', 'languages');
$minconfidence = PConfig::get(local_user(), 'langfilter', 'minconfidence'); $minconfidence = PConfig::get(local_user(), 'langfilter', 'minconfidence');
// Don't filter if no spoken languages are configured // Don't filter if no spoken languages are configured
if (!$spoken_config) if (!$read_languages_string) {
return; return;
$spoken_languages = explode(',', $spoken_config); }
$read_languages_array = explode(',', $read_languages_string);
// Extract the language of the post // Extract the language of the post
$opts = $b['item']['postopts']; $opts = $hook_data['item']['postopts'];
if (!$opts) { if (!$opts) {
// no options associated to post // no options associated to post
return; return;
} }
if (!preg_match('/\blang=([^;]*);([^:]*)/', $opts, $matches)) { if (!preg_match('/\blang=([^;]*);([^:]*)/', $opts, $matches)) {
// no lang options associated to post // no lang options associated to post
return; return;
@ -174,10 +177,8 @@ function langfilter_prepare_body(App $a, &$b)
if (!$iso2) { if (!$iso2) {
return; return;
} }
$spoken = in_array($iso2, $spoken_languages);
if (!$spoken) { if (!in_array($iso2, $read_languages_array)) {
$rnd = random_string(8); $hook_data['filter_reasons'][] = L10n::t('Filtered language: %s', ucfirst($lang));
$b['html'] = '<div id="langfilter-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'langfilter-' . $rnd . '\'); >' . L10n::t('Hidden content in %s - Click to open/close', $lang) . '</div><div id="langfilter-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>';
} }
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-15 17:54+0700\n" "POT-Creation-Date: 2018-04-01 11:11-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -49,7 +49,12 @@ msgstr ""
msgid "NSFW Settings saved." msgid "NSFW Settings saved."
msgstr "" msgstr ""
#: nsfw.php:167 #: nsfw.php:162
#, php-format #, php-format
msgid "%s - Click to open/close" msgid "Filtered tag: %s"
msgstr ""
#: nsfw.php:164
#, php-format
msgid "Filtered word: %s"
msgstr "" msgstr ""

View file

@ -13,13 +13,14 @@ use Friendica\Core\PConfig;
function nsfw_install() function nsfw_install()
{ {
Addon::registerHook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body', 10); Addon::registerHook('prepare_body_content_filter', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body_content_filter', 10);
Addon::registerHook('addon_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings'); Addon::registerHook('addon_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings');
Addon::registerHook('addon_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post'); Addon::registerHook('addon_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post');
} }
function nsfw_uninstall() function nsfw_uninstall()
{ {
Addon::unregisterHook('prepare_body_content_filter', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body_content_filter');
Addon::unregisterHook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body'); Addon::unregisterHook('prepare_body', 'addon/nsfw/nsfw.php', 'nsfw_prepare_body');
Addon::unregisterHook('addon_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings'); Addon::unregisterHook('addon_settings', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings');
Addon::unregisterHook('addon_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post'); Addon::unregisterHook('addon_settings_post', 'addon/nsfw/nsfw.php', 'nsfw_addon_settings_post');
@ -109,13 +110,8 @@ function nsfw_addon_settings_post(&$a, &$b)
} }
} }
function nsfw_prepare_body(Friendica\App $a, &$b) function nsfw_prepare_body_content_filter(\Friendica\App $a, &$hook_data)
{ {
// Don't do the check when there is a content warning
if (!empty($b['item']['content-warning'])) {
return;
}
$words = null; $words = null;
if (PConfig::get(local_user(), 'nsfw', 'disable')) { if (PConfig::get(local_user(), 'nsfw', 'disable')) {
return; return;
@ -133,7 +129,7 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
$found = false; $found = false;
if (count($word_list)) { if (count($word_list)) {
$body = $b['item']['title'] . "\n" . nsfw_extract_photos($b['html']); $body = $hook_data['item']['title'] . "\n" . nsfw_extract_photos($hook_data['item']['body']);
foreach ($word_list as $word) { foreach ($word_list as $word) {
$word = trim($word); $word = trim($word);
@ -141,15 +137,17 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
continue; continue;
} }
$tag_search = false;
switch ($word[0]) { switch ($word[0]) {
case '/'; // Regular expression case '/'; // Regular expression
$found = preg_match($word, $body); $found = preg_match($word, $body);
break; break;
case '#': // Hashtag-only search case '#': // Hashtag-only search
$found = nsfw_find_word_in_item_tags($b['item']['hashtags'], substr($word, 1)); $tag_search = true;
$found = nsfw_find_word_in_item_tags($hook_data['item']['hashtags'], substr($word, 1));
break; break;
default: default:
$found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($b['item']['tags'], $word); $found = stripos($body, $word) !== false || nsfw_find_word_in_item_tags($hook_data['item']['tags'], $word);
break; break;
} }
@ -160,10 +158,11 @@ function nsfw_prepare_body(Friendica\App $a, &$b)
} }
if ($found) { if ($found) {
$rnd = random_string(8); if ($tag_search) {
$b['html'] = '<div id="nsfw-wrap-' . $rnd . '" class="fakelink" onclick=openClose(\'nsfw-' . $rnd . '\'); >' . $hook_data['filter_reasons'][] = L10n::t('Filtered tag: %s', $word);
L10n::t('%s - Click to open/close', $word) . } else {
'</div><div id="nsfw-' . $rnd . '" style="display: none; " >' . $b['html'] . '</div>'; $hook_data['filter_reasons'][] = L10n::t('Filtered word: %s', $word);
}
} }
} }

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-02-27 05:01-0500\n" "POT-Creation-Date: 2018-04-01 11:11-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,26 +17,26 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: showmore.php:38 #: showmore.php:41 showmore.php:45
msgid "\"Show more\" Settings" msgid "\"Show more\" Settings"
msgstr "" msgstr ""
#: showmore.php:41 #: showmore.php:50
msgid "Enable Show More" msgid "Enable Show More"
msgstr "" msgstr ""
#: showmore.php:44 #: showmore.php:53
msgid "Cutting posts after how much characters" msgid "Cutting posts after how much characters"
msgstr "" msgstr ""
#: showmore.php:48 #: showmore.php:57
msgid "Submit" msgid "Save Settings"
msgstr "" msgstr ""
#: showmore.php:65 #: showmore.php:74
msgid "Show More Settings saved." msgid "Show More Settings saved."
msgstr "" msgstr ""
#: showmore.php:119 #: showmore.php:134
msgid "show more" msgid "show more"
msgstr "" msgstr ""

View file

@ -107,26 +107,32 @@ function get_body_length($body) {
return strlen($string); return strlen($string);
} }
function showmore_prepare_body(&$a,&$b) { function showmore_prepare_body(\Friendica\App $a, &$hook_data)
{
$words = null; // No combination with content filters
if(PConfig::get(local_user(),'showmore','disable')) if (!empty($hook_data['filter_reasons'])) {
return; return;
$chars = (int)PConfig::get(local_user(),'showmore','chars');
if(!$chars)
$chars = 1100;
if (get_body_length($b['html']) > $chars) {
$found = true;
$shortened = trim(showmore_cutitem($b['html'], $chars))."...";
} }
if($found) { if (PConfig::get(local_user(), 'showmore', 'disable')) {
return;
}
$chars = (int) PConfig::get(local_user(), 'showmore', 'chars');
if (!$chars) {
$chars = 1100;
}
if (get_body_length($hook_data['html']) > $chars) {
$found = true;
$shortened = trim(showmore_cutitem($hook_data['html'], $chars)) . "...";
}
if ($found) {
$rnd = random_string(8); $rnd = random_string(8);
$b['html'] = '<span id="showmore-teaser-'.$rnd.'" class="showmore-teaser" style="display: block;">'.$shortened." ". $hook_data['html'] = '<span id="showmore-teaser-' . $rnd . '" class="showmore-teaser" style="display: block;">' . $shortened . " " .
'<span id="showmore-wrap-'.$rnd.'" style="white-space:nowrap;" class="showmore-wrap fakelink" onclick="openClose(\'showmore-'.$rnd.'\'); openClose(\'showmore-teaser-'.$rnd.'\');" >'.L10n::t('show more').'</span></span>'. '<span id="showmore-wrap-' . $rnd . '" style="white-space:nowrap;" class="showmore-wrap fakelink" onclick="openClose(\'showmore-' . $rnd . '\'); openClose(\'showmore-teaser-' . $rnd . '\');" >' . L10n::t('show more') . '</span></span>' .
'<div id="showmore-'.$rnd.'" class="showmore-content" style="display: none;">'.$b['html'].'</div>'; '<div id="showmore-' . $rnd . '" class="showmore-content" style="display: none;">' . $hook_data['html'] . '</div>';
} }
} }