use Friendica\App;
use Friendica\Core\Hook;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session;
+use Friendica\DI;
use Friendica\Util\Strings;
+global $blockem_words;
+
function blockem_install()
{
Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
Hook::register('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
}
-function blockem_uninstall()
-{
- Hook::unregister('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
- Hook::unregister('prepare_body' , 'addon/blockem/blockem.php', 'blockem_prepare_body');
- Hook::unregister('display_item' , 'addon/blockem/blockem.php', 'blockem_display_item');
- Hook::unregister('addon_settings' , 'addon/blockem/blockem.php', 'blockem_addon_settings');
- Hook::unregister('addon_settings_post' , 'addon/blockem/blockem.php', 'blockem_addon_settings_post');
- Hook::unregister('conversation_start' , 'addon/blockem/blockem.php', 'blockem_conversation_start');
- Hook::unregister('item_photo_menu' , 'addon/blockem/blockem.php', 'blockem_item_photo_menu');
- Hook::unregister('enotify_store' , 'addon/blockem/blockem.php', 'blockem_enotify_store');
-}
-
-function blockem_addon_settings (App $a, &$s)
+function blockem_addon_settings(App $a, array &$data)
{
- if (!local_user()) {
+ if (!Session::getLocalUser()) {
return;
}
- /* Add our stylesheet to the page so we can make our settings look nice */
- $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseURL() . '/addon/blockem/blockem.css' . '" media="all" />' . "\r\n";
-
- $words = PConfig::get(local_user(), 'blockem', 'words');
-
- if (!$words) {
- $words = '';
- }
-
- $s .= '<span id="settings_blockem_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
- $s .= '<h3>' . L10n::t('Blockem') . '</h3>';
- $s .= '</span>';
- $s .= '<div id="settings_blockem_expanded" class="settings-block" style="display: none;">';
- $s .= '<span class="fakelink" onclick="openClose(\'settings_blockem_expanded\'); openClose(\'settings_blockem_inflated\');">';
- $s .= '<h3>' . L10n::t('Blockem') . '</h3>';
- $s .= '</span>';
+ $words = DI::pConfig()->get(Session::getLocalUser(), 'blockem', 'words', '');
- $s .= '<div id="blockem-wrapper">';
- $s .= '<div id="blockem-desc">'. L10n::t("Hides user's content by collapsing posts. Also replaces their avatar with generic image.") . ' </div>';
- $s .= '<label id="blockem-label" for="blockem-words">' . L10n::t('Comma separated profile URLS:') . ' </label>';
- $s .= '<textarea id="blockem-words" type="text" name="blockem-words" >' . htmlspecialchars($words) . '</textarea>';
- $s .= '</div><div class="clear"></div>';
-
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="blockem-submit" name="blockem-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
-
- return;
+ $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/blockem/');
+ $html = Renderer::replaceMacros($t, [
+ '$info' => DI::l10n()->t("Hides user's content by collapsing posts. Also replaces their avatar with generic image."),
+ '$words' => ['blockem-words', DI::l10n()->t('Comma separated profile URLS:'), $words],
+ ]);
+ $data = [
+ 'addon' => 'blockem',
+ 'title' => DI::l10n()->t('Blockem'),
+ 'html' => $html,
+ ];
}
function blockem_addon_settings_post(App $a, array &$b)
{
- if (!local_user()) {
+ if (!Session::getLocalUser()) {
return;
}
if (!empty($_POST['blockem-submit'])) {
- PConfig::set(local_user(), 'blockem', 'words', trim($_POST['blockem-words']));
- info(L10n::t('BLOCKEM Settings saved.') . EOL);
+ DI::pConfig()->set(Session::getLocalUser(), 'blockem', 'words', trim($_POST['blockem-words']));
}
}
function blockem_enotify_store(App $a, array &$b)
{
- $words = PConfig::get($b['uid'], 'blockem', 'words');
+ $words = DI::pConfig()->get($b['uid'], 'blockem', 'words');
if ($words) {
$arr = explode(',', $words);
}
if ($found) {
- $b['abort'] = true;
+ // empty out the fields
+ $b = [];
}
}
function blockem_prepare_body_content_filter(App $a, array &$hook_data)
{
- if (!local_user()) {
+ if (!Session::getLocalUser()) {
return;
}
$profiles_string = null;
- if (local_user()) {
- $profiles_string = PConfig::get(local_user(), 'blockem', 'words');
+ if (Session::getLocalUser()) {
+ $profiles_string = DI::pConfig()->get(Session::getLocalUser(), 'blockem', 'words');
}
if ($profiles_string) {
}
if ($found) {
- $hook_data['filter_reasons'][] = L10n::t('Filtered user: %s', $hook_data['item']['author-name']);
+ $hook_data['filter_reasons'][] = DI::l10n()->t('Filtered user: %s', $hook_data['item']['author-name']);
}
}
function blockem_display_item(App $a, array &$b = null)
{
if (!empty($b['output']['body']) && strstr($b['output']['body'], 'id="blockem-wrap-')) {
- $b['output']['thumb'] = $a->getBaseURL() . "/images/person-80.jpg";
+ $b['output']['thumb'] = DI::baseUrl()->get() . "/images/person-80.jpg";
}
}
function blockem_conversation_start(App $a, array &$b)
{
- if (!local_user()) {
+ global $blockem_words;
+
+ if (!Session::getLocalUser()) {
return;
}
- $words = PConfig::get(local_user(), 'blockem', 'words');
+ $words = DI::pConfig()->get(Session::getLocalUser(), 'blockem', 'words');
if ($words) {
- $a->data['blockem'] = explode(',', $words);
+ $blockem_words = explode(',', $words);
}
- $a->page['htmlhead'] .= <<< EOT
+ DI::page()['htmlhead'] .= <<< EOT
<script>
function blockemBlock(author) {
function blockem_item_photo_menu(App $a, array &$b)
{
- if (!local_user() || $b['item']['self']) {
+ global $blockem_words;
+
+ if (!Session::getLocalUser() || $b['item']['self']) {
return;
}
$blocked = false;
$author = $b['item']['author-link'];
- if (!empty($a->data['blockem'])) {
- foreach($a->data['blockem'] as $bloke) {
+ if (!empty($blockem_words)) {
+ foreach($blockem_words as $bloke) {
if (Strings::compareLink($bloke,$author)) {
$blocked = true;
break;
}
}
if ($blocked) {
- $b['menu'][L10n::t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
+ $b['menu'][DI::l10n()->t('Unblock Author')] = 'javascript:blockemUnblock(\'' . $author . '\');';
} else {
- $b['menu'][L10n::t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
+ $b['menu'][DI::l10n()->t('Block Author')] = 'javascript:blockemBlock(\'' . $author . '\');';
}
}
-function blockem_module()
-{
-}
+/**
+ * This is a statement rather than an actual function definition. The simple
+ * existence of this method is checked to figure out if the addon offers a
+ * module.
+ */
+function blockem_module() {}
function blockem_init(App $a)
{
- if (!local_user()) {
+ if (!Session::getLocalUser()) {
return;
}
- $words = PConfig::get(local_user(), 'blockem', 'words');
+ $words = DI::pConfig()->get(Session::getLocalUser(), 'blockem', 'words');
if (array_key_exists('block', $_GET) && $_GET['block']) {
if (strlen($words)) {
$words = implode(',', $newarr);
}
- PConfig::set(local_user(), 'blockem', 'words', $words);
- info(L10n::t('blockem settings updated') . EOL);
+ DI::pConfig()->set(Session::getLocalUser(), 'blockem', 'words', $words);
exit();
}