mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-25 14:23:17 +00:00
Issue issue-1312: Reworked "public server" addon
This commit is contained in:
parent
a4a89c7f5f
commit
446ab8c678
1 changed files with 90 additions and 106 deletions
|
@ -9,20 +9,16 @@
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Model\User;
|
|
||||||
use Friendica\Util\DateTimeFormat;
|
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('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('cron', 'addon/public_server/public_server.php', 'public_server_cron');
|
||||||
Addon::registerHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify');
|
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');
|
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('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('cron', 'addon/public_server/public_server.php', 'public_server_cron');
|
||||||
Addon::unregisterHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify');
|
Addon::unregisterHook('enotify', 'addon/public_server/public_server.php', 'public_server_enotify');
|
||||||
|
@ -30,31 +26,28 @@ function public_server_uninstall() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function public_server_register_account($a, $b) {
|
function public_server_register_account($a, $b) {
|
||||||
|
|
||||||
$uid = $b;
|
$uid = $b;
|
||||||
|
|
||||||
$days = Config::get('public_server', 'expiredays');
|
$days = Config::get('public_server', 'expiredays');
|
||||||
$days_posts = Config::get('public_server', 'expireposts');
|
$days_posts = Config::get('public_server', 'expireposts');
|
||||||
if(! $days)
|
if (!$days) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d",
|
$fields = ['account_expires_on' => DateTimeFormat::utc('now +' . $days . ' days'), 'expire' => $days_posts];
|
||||||
dbesc(DateTimeFormat::utc('now +' . $days . ' days')),
|
dba::update('user', $fields, ['uid' => $uid]);
|
||||||
intval($days_posts),
|
}
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function public_server_cron($a, $b) {
|
function public_server_cron($a, $b) {
|
||||||
logger("public_server: cron start");
|
logger("public_server: cron start");
|
||||||
|
|
||||||
require_once('include/enotify.php');
|
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
|
$r = q("select * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND
|
||||||
expire_notification_sent = '0000-00-00 00:00:00' ");
|
`account_expires_on` > '%s' AND
|
||||||
|
expire_notification_sent <= '%s'",
|
||||||
|
dbesc(NULL_DATE), dbesc(NULL_DATE));
|
||||||
|
|
||||||
if(count($r)) {
|
if (DBM::is_result($r)) {
|
||||||
foreach ($r as $rr) {
|
foreach ($r as $rr) {
|
||||||
notification([
|
notification([
|
||||||
'uid' => $rr['uid'],
|
'uid' => $rr['uid'],
|
||||||
|
@ -68,59 +61,48 @@ function public_server_cron($a,$b) {
|
||||||
'source_photo' => $a->get_baseurl() . '/images/person-80.jpg',
|
'source_photo' => $a->get_baseurl() . '/images/person-80.jpg',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
q("update user set expire_notification_sent = '%s' where uid = %d",
|
$fields = ['expire_notification_sent' => DateTimeFormat::utcNow()];
|
||||||
dbesc(DateTimeFormat::utcNow()),
|
dba::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
intval($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'");
|
$nologin = Config::get('public_server', 'nologin', false);
|
||||||
if(count($r)) {
|
|
||||||
foreach($r as $rr) {
|
|
||||||
User::remove($rr['uid']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$nologin = Config::get('public_server','nologin');
|
|
||||||
if ($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));
|
$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'",
|
||||||
if(count($r)) {
|
dbesc(NULL_DATE), intval($nologin), dbesc(NULL_DATE));
|
||||||
foreach($r as $rr)
|
if (DBM::is_result($r)) {
|
||||||
q("update user set account_expires_on = '%s' where uid = %d",
|
foreach ($r as $rr) {
|
||||||
dbesc(DateTimeFormat::utc('now +' . '6 days')),
|
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
||||||
intval($rr['uid'])
|
dba::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$flagusers = Config::get('public_server', 'flagusers', false);
|
||||||
$flagusers = Config::get('public_server','flagusers');
|
|
||||||
if ($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));
|
$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",
|
||||||
if(count($r)) {
|
intval($flagusers), dbesc(NULL_DATE));
|
||||||
foreach($r as $rr)
|
if (DBM::is_result($r)) {
|
||||||
q("update user set account_expires_on = '%s' where uid = %d",
|
foreach ($r as $rr) {
|
||||||
dbesc(DateTimeFormat::utc('now +' . '6 days')),
|
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
||||||
intval($rr['uid'])
|
dba::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$flagposts = Config::get('public_server', 'flagposts');
|
$flagposts = Config::get('public_server', 'flagposts');
|
||||||
$flagpostsexpire = Config::get('public_server', 'flagpostsexpire');
|
$flagpostsexpire = Config::get('public_server', 'flagpostsexpire');
|
||||||
if ($flagposts && $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));
|
$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",
|
||||||
if(count($r)) {
|
intval($flagposts), dbesc(NULL_DATE));
|
||||||
foreach($r as $rr)
|
if (DBM::is_result($r)) {
|
||||||
q("update user set expire = %d where uid = %d",
|
foreach ($r as $rr) {
|
||||||
intval($flagpostsexpire),
|
dba::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]);
|
||||||
intval($rr['uid'])
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger("public_server: cron end");
|
logger("public_server: cron end");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function public_server_enotify(&$a, &$b) {
|
function public_server_enotify(&$a, &$b) {
|
||||||
|
@ -135,22 +117,23 @@ function public_server_enotify(&$a, &$b) {
|
||||||
|
|
||||||
function public_server_login($a, $b) {
|
function public_server_login($a, $b) {
|
||||||
$days = Config::get('public_server', 'expiredays');
|
$days = Config::get('public_server', 'expiredays');
|
||||||
if(! $days)
|
if (!$days) {
|
||||||
return;
|
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) {
|
function public_server_addon_admin_post (&$a) {
|
||||||
check_form_security_token_redirectOnErr('/admin/addons/publicserver', 'publicserver');
|
check_form_security_token_redirectOnErr('/admin/addons/publicserver', 'publicserver');
|
||||||
$expiredays = (( x($_POST, 'expiredays') ) ? notags(trim($_POST['expiredays'] )) : '');
|
$expiredays = (x($_POST, 'expiredays') ? notags(trim($_POST['expiredays'])) : '');
|
||||||
$expireposts = (( x($_POST, 'expireposts') ) ? notags(trim($_POST['expireposts'] )) : '');
|
$expireposts = (x($_POST, 'expireposts') ? notags(trim($_POST['expireposts'])) : '');
|
||||||
$nologin = (( x($_POST, 'nologin') ) ? notags(trim($_POST['nologin'] )) : '');
|
$nologin = (x($_POST, 'nologin') ? notags(trim($_POST['nologin'])) : '');
|
||||||
$flagusers = (( x($_POST, 'flagusers') ) ? notags(trim($_POST['flagusers'] )) : '');
|
$flagusers = (x($_POST, 'flagusers') ? notags(trim($_POST['flagusers'])) : '');
|
||||||
$flagposts = (( x($_POST, 'flagposts') ) ? notags(trim($_POST['flagposts'] )) : '');
|
$flagposts = (x($_POST, 'flagposts') ? notags(trim($_POST['flagposts'])) : '');
|
||||||
$flagpostsexpire = (( x($_POST, 'flagpostsexpire') ) ? notags(trim($_POST['flagpostsexpire'] )) : '');
|
$flagpostsexpire = (x($_POST, 'flagpostsexpire') ? notags(trim($_POST['flagpostsexpire'])) : '');
|
||||||
Config::set('public_server', 'expiredays', $expiredays);
|
Config::set('public_server', 'expiredays', $expiredays);
|
||||||
Config::set('public_server', 'expireposts', $expireposts);
|
Config::set('public_server', 'expireposts', $expireposts);
|
||||||
Config::set('public_server', 'nologin', $nologin);
|
Config::set('public_server', 'nologin', $nologin);
|
||||||
|
@ -159,6 +142,7 @@ function public_server_addon_admin_post ( &$a ) {
|
||||||
Config::set('public_server', 'flagpostsexpire', $flagpostsexpire);
|
Config::set('public_server', 'flagpostsexpire', $flagpostsexpire);
|
||||||
info(L10n::t('Settings saved').EOL);
|
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");
|
$token = get_form_security_token("publicserver");
|
||||||
$t = get_markup_template("admin.tpl", "addon/public_server");
|
$t = get_markup_template("admin.tpl", "addon/public_server");
|
||||||
|
|
Loading…
Reference in a new issue