From 9b77bbeafb8df13b363b2dc3e8975006a19761ab Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 18 Feb 2018 10:21:44 +0100 Subject: [PATCH 1/4] EN_GB translation of blockem addon THX Andy H3 --- blockem/lang/en-gb/messages.po | 59 ++++++++++++++++++++++++++++++++++ blockem/lang/en-gb/strings.php | 16 +++++++++ 2 files changed, 75 insertions(+) create mode 100644 blockem/lang/en-gb/messages.po create mode 100644 blockem/lang/en-gb/strings.php diff --git a/blockem/lang/en-gb/messages.po b/blockem/lang/en-gb/messages.po new file mode 100644 index 00000000..b2fb55e8 --- /dev/null +++ b/blockem/lang/en-gb/messages.po @@ -0,0 +1,59 @@ +# ADDON blockem +# Copyright (C) +# This file is distributed under the same license as the Friendica blockem addon package. +# +# +# Translators: +# Andy H3 , 2018 +msgid "" +msgstr "" +"Project-Id-Version: friendica\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-09 13:00+0100\n" +"PO-Revision-Date: 2018-02-17 11:24+0000\n" +"Last-Translator: Andy H3 \n" +"Language-Team: English (United Kingdom) (http://www.transifex.com/Friendica/friendica/language/en_GB/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: en_GB\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: blockem.php:51 blockem.php:55 +msgid "\"Blockem\"" +msgstr "\"Blockem\"" + +#: blockem.php:59 +msgid "" +"Hides user's content by collapsing posts. Also replaces their avatar with " +"generic image." +msgstr "Hides user's content by collapsing posts. Also replaces their avatar with generic image." + +#: blockem.php:60 +msgid "Comma separated profile URLS:" +msgstr "Comma separated profile URLs:" + +#: blockem.php:64 +msgid "Save Settings" +msgstr "Save settings" + +#: blockem.php:77 +msgid "BLOCKEM Settings saved." +msgstr "Blockem settings saved." + +#: blockem.php:140 +#, php-format +msgid "Hidden content by %s - Click to open/close" +msgstr "Hidden content by %s - Show/hide" + +#: blockem.php:193 +msgid "Unblock Author" +msgstr "Unblock author" + +#: blockem.php:195 +msgid "Block Author" +msgstr "Block author" + +#: blockem.php:227 +msgid "blockem settings updated" +msgstr "Blockem settings updated" diff --git a/blockem/lang/en-gb/strings.php b/blockem/lang/en-gb/strings.php new file mode 100644 index 00000000..3ad8da0d --- /dev/null +++ b/blockem/lang/en-gb/strings.php @@ -0,0 +1,16 @@ +strings["\"Blockem\""] = "\"Blockem\""; +$a->strings["Hides user's content by collapsing posts. Also replaces their avatar with generic image."] = "Hides user's content by collapsing posts. Also replaces their avatar with generic image."; +$a->strings["Comma separated profile URLS:"] = "Comma separated profile URLs:"; +$a->strings["Save Settings"] = "Save settings"; +$a->strings["BLOCKEM Settings saved."] = "Blockem settings saved."; +$a->strings["Hidden content by %s - Click to open/close"] = "Hidden content by %s - Show/hide"; +$a->strings["Unblock Author"] = "Unblock author"; +$a->strings["Block Author"] = "Block author"; +$a->strings["blockem settings updated"] = "Blockem settings updated"; From 446ab8c6780a19b17d425d371bcb5c3c1970f9cf Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 18 Feb 2018 22:20:38 +0000 Subject: [PATCH 2/4] Issue issue-1312: Reworked "public server" addon --- public_server/public_server.php | 196 +++++++++++++++----------------- 1 file changed, 90 insertions(+), 106 deletions(-) diff --git a/public_server/public_server.php b/public_server/public_server.php index a5c4cec7..a86dd82a 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -9,53 +9,46 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; -use Friendica\Model\User; use Friendica\Util\DateTimeFormat; function public_server_install() { - Addon::registerHook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); Addon::registerHook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); Addon::registerHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify'); Addon::registerHook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); } - function public_server_uninstall() { - Addon::unregisterHook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); Addon::unregisterHook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); Addon::unregisterHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify'); Addon::unregisterHook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); } -function public_server_register_account($a,$b) { - +function public_server_register_account($a, $b) { $uid = $b; - $days = Config::get('public_server','expiredays'); - $days_posts = Config::get('public_server','expireposts'); - if(! $days) + $days = Config::get('public_server', 'expiredays'); + $days_posts = Config::get('public_server', 'expireposts'); + if (!$days) { return; + } - $r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d", - dbesc(DateTimeFormat::utc('now +' . $days . ' days')), - intval($days_posts), - intval($uid) - ); + $fields = ['account_expires_on' => DateTimeFormat::utc('now +' . $days . ' days'), 'expire' => $days_posts]; + dba::update('user', $fields, ['uid' => $uid]); +} -}; - - -function public_server_cron($a,$b) { +function public_server_cron($a, $b) { logger("public_server: cron start"); require_once('include/enotify.php'); - $r = q("select * from user where account_expires_on < UTC_TIMESTAMP() + INTERVAL 5 DAY and account_expires_on > '0000-00-00 00:00:00' and - expire_notification_sent = '0000-00-00 00:00:00' "); + $r = q("select * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND + `account_expires_on` > '%s' AND + expire_notification_sent <= '%s'", + dbesc(NULL_DATE), dbesc(NULL_DATE)); - if(count($r)) { - foreach($r as $rr) { + if (DBM::is_result($r)) { + foreach ($r as $rr) { notification([ 'uid' => $rr['uid'], 'type' => NOTIFY_SYSTEM, @@ -68,109 +61,100 @@ function public_server_cron($a,$b) { 'source_photo' => $a->get_baseurl() . '/images/person-80.jpg', ]); - q("update user set expire_notification_sent = '%s' where uid = %d", - dbesc(DateTimeFormat::utcNow()), - intval($rr['uid']) - ); + $fields = ['expire_notification_sent' => DateTimeFormat::utcNow()]; + dba::update('user', $fields, ['uid' => $rr['uid']]); } } - $r = q("select * from user where account_expired = 1 and account_expires_on < UTC_TIMESTAMP() - INTERVAL 5 DAY and account_expires_on > '0000-00-00 00:00:00'"); - if(count($r)) { - foreach($r as $rr) { - User::remove($rr['uid']); + $nologin = Config::get('public_server', 'nologin', false); + if ($nologin) { + $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND login_date <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", + dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE)); + if (DBM::is_result($r)) { + foreach ($r as $rr) { + $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; + dba::update('user', $fields, ['uid' => $rr['uid']]); + } } } - $nologin = Config::get('public_server','nologin'); - if($nologin) { - $r = q("select uid from user where account_expired = 0 and login_date = '0000-00-00 00:00:00' and register_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00'",intval($nologin)); - if(count($r)) { - foreach($r as $rr) - q("update user set account_expires_on = '%s' where uid = %d", - dbesc(DateTimeFormat::utc('now +' . '6 days')), - intval($rr['uid']) - ); + + $flagusers = Config::get('public_server', 'flagusers', false); + if ($flagusers) { + $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0", + intval($flagusers), dbesc(NULL_DATE)); + if (DBM::is_result($r)) { + foreach ($r as $rr) { + $fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')]; + dba::update('user', $fields, ['uid' => $rr['uid']]); + } } - } + } - - $flagusers = Config::get('public_server','flagusers'); - if($flagusers) { - $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and `page-flags` = 0",intval($flagusers)); - if(count($r)) { - foreach($r as $rr) - q("update user set account_expires_on = '%s' where uid = %d", - dbesc(DateTimeFormat::utc('now +' . '6 days')), - intval($rr['uid']) - ); - } - } - - $flagposts = Config::get('public_server','flagposts'); - $flagpostsexpire = Config::get('public_server','flagpostsexpire'); + $flagposts = Config::get('public_server', 'flagposts'); + $flagpostsexpire = Config::get('public_server', 'flagpostsexpire'); if ($flagposts && $flagpostsexpire) { - $r = q("select uid from user where account_expired = 0 and login_date < UTC_TIMESTAMP() - INTERVAL %d DAY and account_expires_on = '0000-00-00 00:00:00' and expire = 0 and `page-flags` = 0",intval($flagposts)); - if(count($r)) { - foreach($r as $rr) - q("update user set expire = %d where uid = %d", - intval($flagpostsexpire), - intval($rr['uid']) - ); + $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0", + intval($flagposts), dbesc(NULL_DATE)); + if (DBM::is_result($r)) { + foreach ($r as $rr) { + dba::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]); + } } - } + } logger("public_server: cron end"); - } function public_server_enotify(&$a, &$b) { - if (x($b, 'params') && $b['params']['type'] == NOTIFY_SYSTEM + if (x($b, 'params') && $b['params']['type'] == NOTIFY_SYSTEM && x($b['params'], 'system_type') && $b['params']['system_type'] === 'public_server_expire') { - $b['itemlink'] = $a->get_baseurl(); - $b['epreamble'] = $b['preamble'] = L10n::t('Your account on %s will expire in a few days.', Config::get('system', 'sitename')); - $b['subject'] = L10n::t('Your Friendica account is about to expire.'); - $b['body'] = L10n::t("Hi %1\$s,\n\nYour account on %2\$s will expire in less than five days. You may keep your account by logging in at least once every 30 days", $b['params']['to_name'], "[url=" . $app->config["system"]["url"] . "]" . $app->config["sitename"] . "[/url]"); - } + $b['itemlink'] = $a->get_baseurl(); + $b['epreamble'] = $b['preamble'] = L10n::t('Your account on %s will expire in a few days.', Config::get('system', 'sitename')); + $b['subject'] = L10n::t('Your Friendica account is about to expire.'); + $b['body'] = L10n::t("Hi %1\$s,\n\nYour account on %2\$s will expire in less than five days. You may keep your account by logging in at least once every 30 days", $b['params']['to_name'], "[url=" . $app->config["system"]["url"] . "]" . $app->config["sitename"] . "[/url]"); + } } -function public_server_login($a,$b) { - $days = Config::get('public_server','expiredays'); - if(! $days) +function public_server_login($a, $b) { + $days = Config::get('public_server', 'expiredays'); + if (!$days) { return; - $r = q("UPDATE user set account_expires_on = '%s' where uid = %d and account_expires_on > '0000-00-00 00:00:00'", - dbesc(DateTimeFormat::utc('now +' . $days . ' days')), - local_user() - ); + } + + $fields = ['account_expires_on' => DateTimeFormat::utc('now +' . $days . ' days')]; + $condition = ["`uid` = ? AND `account_expires_on` > ?", local_user(), NULL_DATE]; + dba::update('user', $fields, $condition); } -function public_server_addon_admin_post ( &$a ) { - check_form_security_token_redirectOnErr('/admin/addons/publicserver', 'publicserver'); - $expiredays = (( x($_POST, 'expiredays') ) ? notags(trim($_POST['expiredays'] )) : ''); - $expireposts = (( x($_POST, 'expireposts') ) ? notags(trim($_POST['expireposts'] )) : ''); - $nologin = (( x($_POST, 'nologin') ) ? notags(trim($_POST['nologin'] )) : ''); - $flagusers = (( x($_POST, 'flagusers') ) ? notags(trim($_POST['flagusers'] )) : ''); - $flagposts = (( x($_POST, 'flagposts') ) ? notags(trim($_POST['flagposts'] )) : ''); - $flagpostsexpire = (( x($_POST, 'flagpostsexpire') ) ? notags(trim($_POST['flagpostsexpire'] )) : ''); - Config::set( 'public_server','expiredays',$expiredays ); - Config::set( 'public_server','expireposts',$expireposts ); - Config::set( 'public_server','nologin',$nologin ); - Config::set( 'public_server','flagusers',$flagusers); - Config::set( 'public_server','flagposts',$flagposts ); - Config::set( 'public_server','flagpostsexpire',$flagpostsexpire ); - info(L10n::t('Settings saved').EOL ); +function public_server_addon_admin_post (&$a) { + check_form_security_token_redirectOnErr('/admin/addons/publicserver', 'publicserver'); + $expiredays = (x($_POST, 'expiredays') ? notags(trim($_POST['expiredays'])) : ''); + $expireposts = (x($_POST, 'expireposts') ? notags(trim($_POST['expireposts'])) : ''); + $nologin = (x($_POST, 'nologin') ? notags(trim($_POST['nologin'])) : ''); + $flagusers = (x($_POST, 'flagusers') ? notags(trim($_POST['flagusers'])) : ''); + $flagposts = (x($_POST, 'flagposts') ? notags(trim($_POST['flagposts'])) : ''); + $flagpostsexpire = (x($_POST, 'flagpostsexpire') ? notags(trim($_POST['flagpostsexpire'])) : ''); + Config::set('public_server', 'expiredays', $expiredays); + Config::set('public_server', 'expireposts', $expireposts); + Config::set('public_server', 'nologin', $nologin); + Config::set('public_server', 'flagusers', $flagusers); + Config::set('public_server', 'flagposts', $flagposts); + Config::set('public_server', 'flagpostsexpire', $flagpostsexpire); + info(L10n::t('Settings saved').EOL); } -function public_server_addon_admin ( &$a, &$o) { - $token = get_form_security_token("publicserver"); - $t = get_markup_template( "admin.tpl", "addon/public_server"); - $o = replace_macros($t, [ - '$submit' => L10n::t('Save Settings'), - '$form_security_token' => $token, - '$infotext' => L10n::t('Set any of these options to 0 to deactivate it.'), - '$expiredays' => [ "expiredays","Expire Days", intval(Config::get('public_server', 'expiredays')), "When an account is created on the site, it is given a hard "], - '$expireposts' => [ "expireposts", "Expire Posts", intval(Config::get('public_server','expireposts')), "Set the default days for posts to expire here"], - '$nologin' => [ "nologin", "No Login", intval(Config::get('public_server','nologin')), "Remove users who have never logged in after nologin days "], - '$flagusers' => [ "flagusers", "Flag users", intval(Config::get('public_server','flagusers')), "Remove users who last logged in over flagusers days ago"], - '$flagposts' => [ "flagposts", "Flag posts", intval(Config::get('public_server','flagposts')), "For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire "], - '$flagpostsexpire' => [ "flagpostsexpire", "Flag posts expire", intval(Config::get('public_server','flagpostsexpire'))], - ]); + +function public_server_addon_admin (&$a, &$o) { + $token = get_form_security_token("publicserver"); + $t = get_markup_template("admin.tpl", "addon/public_server"); + $o = replace_macros($t, [ + '$submit' => L10n::t('Save Settings'), + '$form_security_token' => $token, + '$infotext' => L10n::t('Set any of these options to 0 to deactivate it.'), + '$expiredays' => ["expiredays","Expire Days", intval(Config::get('public_server', 'expiredays')), "When an account is created on the site, it is given a hard "], + '$expireposts' => ["expireposts", "Expire Posts", intval(Config::get('public_server', 'expireposts')), "Set the default days for posts to expire here"], + '$nologin' => ["nologin", "No Login", intval(Config::get('public_server', 'nologin')), "Remove users who have never logged in after nologin days "], + '$flagusers' => ["flagusers", "Flag users", intval(Config::get('public_server', 'flagusers')), "Remove users who last logged in over flagusers days ago"], + '$flagposts' => ["flagposts", "Flag posts", intval(Config::get('public_server', 'flagposts')), "For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire "], + '$flagpostsexpire' => ["flagpostsexpire", "Flag posts expire", intval(Config::get('public_server', 'flagpostsexpire'))], + ]); } From f37adf4342428c236f9df2e4dd2e6ab43a870f79 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 19 Feb 2018 05:19:02 +0000 Subject: [PATCH 3/4] standards --- public_server/public_server.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/public_server/public_server.php b/public_server/public_server.php index a86dd82a..1df37c66 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -11,21 +11,24 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Util\DateTimeFormat; -function public_server_install() { +function public_server_install() +{ Addon::registerHook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); Addon::registerHook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); Addon::registerHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify'); Addon::registerHook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); } -function public_server_uninstall() { +function public_server_uninstall() +{ Addon::unregisterHook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); Addon::unregisterHook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); Addon::unregisterHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify'); Addon::unregisterHook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); } -function public_server_register_account($a, $b) { +function public_server_register_account($a, $b) +{ $uid = $b; $days = Config::get('public_server', 'expiredays'); @@ -38,13 +41,14 @@ function public_server_register_account($a, $b) { dba::update('user', $fields, ['uid' => $uid]); } -function public_server_cron($a, $b) { +function public_server_cron($a, $b) +{ logger("public_server: cron start"); require_once('include/enotify.php'); - $r = q("select * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND + $r = q("SELECT * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND `account_expires_on` > '%s' AND - expire_notification_sent <= '%s'", + `expire_notification_sent` <= '%s'", dbesc(NULL_DATE), dbesc(NULL_DATE)); if (DBM::is_result($r)) { @@ -68,7 +72,7 @@ function public_server_cron($a, $b) { $nologin = Config::get('public_server', 'nologin', false); if ($nologin) { - $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND login_date <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", + $r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'", dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE)); if (DBM::is_result($r)) { foreach ($r as $rr) { @@ -105,7 +109,8 @@ function public_server_cron($a, $b) { logger("public_server: cron end"); } -function public_server_enotify(&$a, &$b) { +function public_server_enotify(&$a, &$b) +{ if (x($b, 'params') && $b['params']['type'] == NOTIFY_SYSTEM && x($b['params'], 'system_type') && $b['params']['system_type'] === 'public_server_expire') { $b['itemlink'] = $a->get_baseurl(); @@ -115,7 +120,8 @@ function public_server_enotify(&$a, &$b) { } } -function public_server_login($a, $b) { +function public_server_login($a, $b) +{ $days = Config::get('public_server', 'expiredays'); if (!$days) { return; @@ -126,7 +132,8 @@ function public_server_login($a, $b) { dba::update('user', $fields, $condition); } -function public_server_addon_admin_post (&$a) { +function public_server_addon_admin_post(&$a) +{ check_form_security_token_redirectOnErr('/admin/addons/publicserver', 'publicserver'); $expiredays = (x($_POST, 'expiredays') ? notags(trim($_POST['expiredays'])) : ''); $expireposts = (x($_POST, 'expireposts') ? notags(trim($_POST['expireposts'])) : ''); @@ -143,7 +150,8 @@ function public_server_addon_admin_post (&$a) { info(L10n::t('Settings saved').EOL); } -function public_server_addon_admin (&$a, &$o) { +function public_server_addon_admin(&$a, &$o) +{ $token = get_form_security_token("publicserver"); $t = get_markup_template("admin.tpl", "addon/public_server"); $o = replace_macros($t, [ From bd6ec212c19ea9f5fc34e20e6992bea7249b9836 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 19 Feb 2018 13:56:47 +0000 Subject: [PATCH 4/4] Missed "use" --- public_server/public_server.php | 1 + 1 file changed, 1 insertion(+) diff --git a/public_server/public_server.php b/public_server/public_server.php index 1df37c66..cfcb8fd7 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -9,6 +9,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Database\DBM; use Friendica\Util\DateTimeFormat; function public_server_install()