From: Keith Fernie Date: Fri, 18 May 2012 08:12:02 +0000 (+0100) Subject: new file: public_server.tgz add public_server plugin X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2031a7240cae35dbfbc3e1aa749ae9157250b033;p=friendica-addons.git new file: public_server.tgz add public_server plugin new file: public_server/README.md add public_server plugin new file: public_server/public_server.php add public_server plugin modified: testdrive.tgz puts content in notification emails modified: testdrive/testdrive.php puts content in notification emails --- diff --git a/public_server.tgz b/public_server.tgz new file mode 100755 index 00000000..c9a67fe3 Binary files /dev/null and b/public_server.tgz differ diff --git a/public_server/README.md b/public_server/README.md new file mode 100644 index 00000000..44b29f8e --- /dev/null +++ b/public_server/README.md @@ -0,0 +1,29 @@ +Public Server +============= + + +Public Server is a Friendica plugin which implements automatic account & post expiration so that a site may be used as a public +test bed with reduced data retention. + +This is a modified version of the testdrive plugin, DO NOT ACTIVATE AT THE SAME TIME AS THE TESTDRIVE PLUGIN. + +//When an account is created on the site, it is given a hard expiration date of +$a->config['public_server']['expiredays'] = 30; +//Set the default days for posts to expire here +$a->config['public_server']['expireposts'] = 30; +//Remove users who have never logged in after nologin days +$a->config['public_server']['nologin'] = 30; +//Remove users who last logged in over flagusers days ago +$a->config['public_server']['flagusers'] = 146; +//For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire +$a->config['public_server']['flagposts'] = 90; +$a->config['public_server']['flagpostsexpire'] = 146; + +Set these in your .htconfig.php file. By default nothing is defined in case the plugin is activated accidentally. +They can be ommitted or set to 0 to disable each option. +The default values are those used by friendica.eu, change these as desired. + +The expiration date is updated when the user logs in. + +An email warning will be sent out approximately five days before the expiration occurs. Five days later the account is removed completely. + diff --git a/public_server/public_server.php b/public_server/public_server.php new file mode 100644 index 00000000..9d469829 --- /dev/null +++ b/public_server/public_server.php @@ -0,0 +1,140 @@ + + */ + + + + +function public_server_install() { + + register_hook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); + register_hook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); + register_hook('enotify','addon/public_server/public_server.php', 'public_server_enotify'); + register_hook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); +} + + +function public_server_uninstall() { + + unregister_hook('register_account', 'addon/public_server/public_server.php', 'public_server_register_account'); + unregister_hook('cron', 'addon/public_server/public_server.php', 'public_server_cron'); + unregister_hook('enotify','addon/public_server/public_server.php', 'public_server_enotify'); + unregister_hook('logged_in', 'addon/public_server/public_server.php', 'public_server_login'); +} + +function public_server_register_account($a,$b) { + + $uid = $b; + + $days = get_config('public_server','expiredays'); + $days_posts = get_config('public_server','expireposts'); + if(! $days) + return; + + $r = q("UPDATE user set account_expires_on = '%s', expire = %d where uid = %d limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), + intval($days_posts), + intval($uid) + ); + +}; + + +function public_server_cron($a,$b) { + 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' "); + + if(count($r)) { + foreach($r as $rr) { + notification(array( + 'uid' => $rr['uid'], + 'type' => NOTIFY_SYSTEM, + 'system_type' => 'public_server_expire', + 'language' => $rr['language'], + 'to_name' => $rr['username'], + 'to_email' => $rr['email'], + 'source_name' => t('Administrator'), + 'source_link' => $a->get_baseurl(), + 'source_photo' => $a->get_baseurl() . '/images/person-80.jpg', + )); + + q("update user set expire_notification_sent = '%s' where uid = %d limit 1", + dbesc(datetime_convert()), + 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'"); + if(count($r)) { + require_once('include/Contact.php'); + foreach($r as $rr) + user_remove($rr['uid']); + + } + $nologin = get_config('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 limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), + intval($rr['uid']) + ); + } + } + + + $flagusers = get_config('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 limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . '6 days')), + intval($rr['uid']) + ); + } + } + + $flagposts = get_config('public_server','flagposts'); + $flagpostsexpire = get_config('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 limit 1", + intval($flagpostsexpire), + intval($rr['uid']) + ); + } + } + + +} + +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(); + $b['epreamble'] = $b['preamble'] = sprintf( t('Your account on %s will expire in a few days.'), get_config('system','sitename')); + $b['subject'] = t('Your Friendica account is about to expire.'); + $b['body'] = sprintf( 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 = get_config('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' limit 1", + dbesc(datetime_convert('UTC','UTC','now +' . $days . ' days')), + local_user() + ); +} diff --git a/testdrive.tgz b/testdrive.tgz old mode 100644 new mode 100755 index 7d314ea2..3369481c Binary files a/testdrive.tgz and b/testdrive.tgz differ diff --git a/testdrive/testdrive.php b/testdrive/testdrive.php index b7c021a1..909f4338 100644 --- a/testdrive/testdrive.php +++ b/testdrive/testdrive.php @@ -14,6 +14,8 @@ function testdrive_install() { register_hook('register_account', 'addon/testdrive/testdrive.php', 'testdrive_register_account'); register_hook('cron', 'addon/testdrive/testdrive.php', 'testdrive_cron'); + register_hook('enotify','addon/testdrive/testdrive.php', 'testdrive_enotify'); + } @@ -21,6 +23,7 @@ function testdrive_uninstall() { unregister_hook('register_account', 'addon/testdrive/testdrive.php', 'testdrive_register_account'); unregister_hook('cron', 'addon/testdrive/testdrive.php', 'testdrive_cron'); + unregister_hook('enotify','addon/testdrive/testdrive.php', 'testdrive_enotify'); }