]> git.mxchange.org Git - friendica.git/commitdiff
content expiration
authorFriendika <info@friendika.com>
Wed, 16 Mar 2011 00:31:49 +0000 (17:31 -0700)
committerFriendika <info@friendika.com>
Wed, 16 Mar 2011 00:31:49 +0000 (17:31 -0700)
15 files changed:
boot.php
database.sql
include/expire.php [new file with mode: 0644]
include/items.php
include/notifier.php
include/poller.php
mod/item.php
mod/settings.php
update.php
view/de/settings.tpl
view/en/settings.tpl
view/fr/settings.tpl
view/it/settings.tpl
view/theme/duepuntozero/style.css
view/theme/loozah/style.css

index baecdc9c3fc83accf6e4c01fd3b5d03732653358..b03221bf80dfd8ba4921523aa94de1eb3bafa9d2 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -4,7 +4,7 @@ set_time_limit(0);
 
 define ( 'FRIENDIKA_VERSION',      '2.1.919' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.1'  );
-define ( 'DB_UPDATE_VERSION',      1042   );
+define ( 'DB_UPDATE_VERSION',      1043   );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
index 3a58decd12f066bd5a2f799bbed8ccf6388de0e8..0ecf0ea200e006e842a2bba5d562e77a3ed5ed5b 100644 (file)
@@ -379,6 +379,7 @@ CREATE TABLE IF NOT EXISTS `user` (
   `page-flags` int(11) unsigned NOT NULL DEFAULT '0',
   `pwdreset` char(255) NOT NULL,
   `maxreq` int(11) NOT NULL DEFAULT '10',
+  `expire` int(11) unsigned NOT NULL DEFAULT '0',
   `allow_cid` mediumtext NOT NULL, 
   `allow_gid` mediumtext NOT NULL,
   `deny_cid` mediumtext NOT NULL, 
diff --git a/include/expire.php b/include/expire.php
new file mode 100644 (file)
index 0000000..3c30e01
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+require_once("boot.php");
+
+function expire_run($argv, $argc){
+       global $a, $db;
+
+       if(is_null($a)) {
+               $a = new App;
+       }
+  
+       if(is_null($db)) {
+           @include(".htconfig.php");
+       require_once("dba.php");
+           $db = new dba($db_host, $db_user, $db_pass, $db_data);
+       unset($db_host, $db_user, $db_pass, $db_data);
+       };
+
+       require_once('session.php');
+       require_once('datetime.php');
+       require_once('simplepie/simplepie.inc');
+       require_once('include/items.php');
+       require_once('include/Contact.php');
+
+       $a->set_baseurl(get_config('system','url'));
+
+
+       logger('expire: start');
+       
+       $r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0");
+       if(count($r)) {
+               foreach($r as $rr) {
+                       logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG);
+                       item_expire($rr['uid'],$rr['expire']);
+               }
+       }
+
+       return;
+}
+
+if (array_search(__file__,get_included_files())===0){
+  expire_run($argv,$argc);
+  killme();
+}
index 2294fe294a03776d4786a88f450e9826f3cf7493..05165932183b8871bee966462d1f9794185bc326 100644 (file)
@@ -1507,3 +1507,49 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
        return $o;
 }
        
+function item_expire($uid,$days) {
+
+       if((! $uid) || (! $days))
+               return;
+
+       $r = q("SELECT * FROM `item` 
+               WHERE `uid` = %d 
+               AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY 
+               AND `id` = `parent` 
+               AND `deleted` = 0",
+               intval($uid),
+               intval($days)
+       );
+
+       if(! count($r))
+               return;
+       logger('expire: # items=' . count($r) );
+
+       foreach($r as $item) {
+
+               // Only expire posts, not photos and photo comments
+
+               if(strlen($item['resource-id']))
+                       continue;
+
+               $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       intval($item['id'])
+               );
+
+               // kill the kids
+
+               $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
+                       dbesc(datetime_convert()),
+                       dbesc(datetime_convert()),
+                       dbesc($item['parent-uri']),
+                       intval($item['uid'])
+               );
+
+       }
+
+       proc_run('php',"include/notifier.php","expire","$uid");
+
+}
\ No newline at end of file
index 648a07062c02aa0104ffd6571fc4c76f2ea1cbe4..ca2304845ed276655aa009c8d7717e72b3b31e65 100644 (file)
@@ -40,6 +40,7 @@ function notifier_run($argv, $argc){
                        break;
        }
 
+       $expire = false;
        $top_level = false;
        $recipients = array();
        $url_recipients = array();
@@ -57,6 +58,17 @@ function notifier_run($argv, $argc){
                $item = $message[0];
 
        }
+       elseif($cmd === 'expire') {
+               $expire = true;
+               $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 
+                       AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 10 MINUTE",
+                       intval($item_id)
+               );
+               $uid = $item_id;
+               $item_id = 0;
+               if(! count($items))
+                       return;
+       }
        else {
 
                // find ancestors
@@ -76,11 +88,10 @@ function notifier_run($argv, $argc){
                        intval($parent_id)
                );
 
-               if(! count($items)){
+               if(! count($items)) {
                        return;
                }
 
-
                // avoid race condition with deleting entries
 
                if($items[0]['deleted']) {
@@ -98,11 +109,11 @@ function notifier_run($argv, $argc){
                intval($uid)
        );
 
-       if(count($r))
-               $owner = $r[0];
-       else {
+       if(! count($r))
                return;
-       }
+
+       $owner = $r[0];
+
        $hub = get_config('system','huburl');
 
        // If this is a public conversation, notify the feed hub
@@ -117,7 +128,7 @@ function notifier_run($argv, $argc){
 
                $parent = $items[0];
 
-               if($parent['type'] === 'remote') {
+               if($parent['type'] === 'remote' && (! $expire)) {
                        // local followup to remote post
                        $followup = true;
                        $notify_hub = false; // not public
@@ -235,6 +246,7 @@ function notifier_run($argv, $argc){
                }
                else {
                        foreach($items as $item) {
+
                                if(! $item['parent'])
                                        continue;
 
@@ -242,9 +254,9 @@ function notifier_run($argv, $argc){
                                if(! $contact)
                                        continue;
 
-                               $atom   .= atom_entry($item,'text',$contact,$owner,true);
+                               $atom .= atom_entry($item,'text',$contact,$owner,true);
 
-                               if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link'])) 
+                               if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link']) && (! $expire)
                                        $slaps[] = atom_entry($item,'html',$contact,$owner,true);
                        }
                }
@@ -319,7 +331,7 @@ function notifier_run($argv, $argc){
                                                // only send salmon if public - e.g. if it's ok to notify
                                                // a public hub, it's ok to send a salmon
 
-                                               if(count($slaps) && $notify_hub) {
+                                               if((count($slaps)) && ($notify_hub) && (! $expire)) {
                                                        logger('notifier: slapdelivery: ' . $contact['name']);
                                                        foreach($slaps as $slappy) {
                                                                if($contact['notify']) {
@@ -350,7 +362,7 @@ function notifier_run($argv, $argc){
                
        // send additional slaps to mentioned remote tags (@foo@example.com)
 
-       if($slap && count($url_recipients) && $followup && $notify_hub) {
+       if($slap && count($url_recipients) && $followup && $notify_hub && (! $expire)) {
                foreach($url_recipients as $url) {
                        if($url) {
                                logger('notifier: urldelivery: ' . $url);
index a093190a60e9b1f02784f5f6b288e404938ca119..8619697d9661d3697f1f20e5ed00d0b7e013208b 100644 (file)
@@ -29,6 +29,17 @@ function poller_run($argv, $argc){
 
        proc_run('php',"include/queue.php");
        
+       // once daily run expire in background
+
+       $d1 = get_config('system','last_expire_day');
+       $d2 = intval(datetime_convert('UTC','UTC','now','d'));
+
+       if($d2 != intval($d1)) {
+               set_config('system','last_expire_day',$d2);
+               proc_run('php','include/expire.php');
+       }
+
+
        // clear old cache
        q("DELETE FROM `cache` WHERE `updated` < '%s'",
                dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
index 5989d096745422dc0cf9c238d3efd53256944a38..90fb546bce917025c2fd14f435689e60f918c5f5 100644 (file)
@@ -532,7 +532,7 @@ function item_content(&$a) {
 
        require_once('include/security.php');
 
-       $uid = $_SESSION['uid'];
+       $uid = local_user();
 
        if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
 
index ebe07612eb1fa152a0a5d6c74ec60ec15e8c73cf..85029b3d729fd2d16391b4b62741cece0c881daf 100644 (file)
@@ -63,6 +63,7 @@ function settings_post(&$a) {
        $defloc           = ((x($_POST,'defloc'))     ? notags(trim($_POST['defloc']))       : '');
        $openid           = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url']))   : '');
        $maxreq           = ((x($_POST,'maxreq'))     ? intval($_POST['maxreq'])             : 0);
+       $expire           = ((x($_POST,'expire'))     ? intval($_POST['expire'])             : 0);
 
        $allow_location   = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0);
        $publish          = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0);
@@ -139,7 +140,7 @@ function settings_post(&$a) {
                        $openidserver = '';
        }
 
-       $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s',  `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s', `maxreq` = %d, `openidserver` = '%s'  WHERE `uid` = %d LIMIT 1",
+       $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s',  `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `theme` = '%s', `maxreq` = %d, `expire` = %d, `openidserver` = '%s'  WHERE `uid` = %d LIMIT 1",
                        dbesc($username),
                        dbesc($email),
                        dbesc($openid),
@@ -154,6 +155,7 @@ function settings_post(&$a) {
                        intval($allow_location),
                        dbesc($theme),
                        intval($maxreq),
+                       intval($expire),
                        dbesc($openidserver),
                        intval(local_user())
        );
@@ -238,6 +240,7 @@ function settings_content(&$a) {
        $defloc   = $a->user['default-location'];
        $openid   = $a->user['openid'];
        $maxreq   = $a->user['maxreq'];
+       $expire   = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
 
        if(! strlen($a->user['timezone']))
                $timezone = date_default_timezone_get();
@@ -358,6 +361,7 @@ function settings_content(&$a) {
                '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
                '$sel_notify5' => (($notify & NOTIFY_MAIL)    ? ' checked="checked" ' : ''),
                '$maxreq' => $maxreq,
+               '$expire' => $expire,
                '$theme' => $theme_selector,
                '$pagetype' => $pagetype
        ));
index 7a885193cdb5cded80fce50809536e1b385f5d9c..0be919f3f1f3fe75664f3a44d2cd2629d97c11c2 100644 (file)
@@ -400,4 +400,10 @@ function update_1040() {
 function update_1041() {
        q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
        q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
-}
\ No newline at end of file
+}
+
+function update_1042() {
+       q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
+}
+
+
index 0ef50546f457c28397d5b554218ff74cc1fd98ac..675ef675f581b022941ebce27c1ab6d3404ebe0e 100644 (file)
@@ -78,7 +78,7 @@ $profile_in_net_dir
 
 
 <div id="settings-default-perms" class="settings-default-perms" >
-       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >&#x21e9; $permissions</div>
+       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >$permissions</div>
        <div id="settings-default-perms-menu-end"></div>
 
        <div id="settings-default-perms-select" style="display: none;" >
@@ -89,6 +89,10 @@ $profile_in_net_dir
 </div>
 <div id="settings-default-perms-end"></div>
 
+<div id="settings-expire-desc">Automatically expire (delete) posts older than <input type="text" size="3" name="expire" value="$expire" /> days</div>
+<div id="settings-expire-end"></div>
+
+
 <div class="settings-submit-wrapper" >
 <input type="submit" name="submit" class="settings-submit" value="Submit" />
 </div>
index 97d67cbf61679d07f8303bc6df2f27e452560bbf..39b18c12621e55bb67dde4155f841888d7921be4 100644 (file)
@@ -76,9 +76,8 @@ $profile_in_dir
 $profile_in_net_dir
 
 
-
 <div id="settings-default-perms" class="settings-default-perms" >
-       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >&#x21e9; $permissions</div>
+       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >$permissions</div>
        <div id="settings-default-perms-menu-end"></div>
 
        <div id="settings-default-perms-select" style="display: none;" >
@@ -89,6 +88,10 @@ $profile_in_net_dir
 </div>
 <div id="settings-default-perms-end"></div>
 
+<div id="settings-expire-desc">Automatically expire (delete) posts older than <input type="text" size="3" name="expire" value="$expire" /> days</div>
+<div id="settings-expire-end"></div>
+
+
 <div class="settings-submit-wrapper" >
 <input type="submit" name="submit" class="settings-submit" value="Submit" />
 </div>
index 97d67cbf61679d07f8303bc6df2f27e452560bbf..eb386579f0b72aaa9c7af9655f3a9381861acd2a 100644 (file)
@@ -78,7 +78,7 @@ $profile_in_net_dir
 
 
 <div id="settings-default-perms" class="settings-default-perms" >
-       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >&#x21e9; $permissions</div>
+       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >$permissions</div>
        <div id="settings-default-perms-menu-end"></div>
 
        <div id="settings-default-perms-select" style="display: none;" >
@@ -89,6 +89,9 @@ $profile_in_net_dir
 </div>
 <div id="settings-default-perms-end"></div>
 
+<div id="settings-expire-desc">Automatically expire (delete) posts older than <input type="text" size="3" name="expire" value="$expire" /> days</div>
+<div id="settings-expire-end"></div>
+
 <div class="settings-submit-wrapper" >
 <input type="submit" name="submit" class="settings-submit" value="Submit" />
 </div>
index 3b68923cf45ba470a53cf2eb4a7860b3f3716426..87f40f26fc57f42f22f10011d80980655a66f4e6 100644 (file)
@@ -79,7 +79,7 @@ $profile_in_net_dir
 
 
 <div id="settings-default-perms" class="settings-default-perms" >
-       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >&#x21e9; $permissions</div>
+       <div id="settings-default-perms-menu" class="fakelink" onClick="openClose('settings-default-perms-select');" >$permissions</div>
        <div id="settings-default-perms-menu-end"></div>
 
        <div id="settings-default-perms-select" style="display: none;" >
@@ -90,6 +90,9 @@ $profile_in_net_dir
 </div>
 <div id="settings-default-perms-end"></div>
 
+<div id="settings-expire-desc">Automatically expire (delete) posts older than <input type="text" size="3" name="expire" value="$expire" /> days</div>
+<div id="settings-expire-end"></div>
+
 <div class="settings-submit-wrapper" >
 <input type="submit" name="submit" class="settings-submit" value="Aggiorna" />
 </div>
index ca8764283ce584b4f62ecabeb053c726e936b6b4..54a522881ff84955ab84e5c3d9c8df9e1d5e495b 100644 (file)
@@ -373,6 +373,10 @@ input#dfrn-url {
        margin-bottom: 30px;
 }
 
+#settings-expire-end {
+       margin-bottom: 30px;
+}
+
 #settings-username-end,
 #settings-email-end,
 #settings-nick-end,
index aadfbd3c4ff0f9722e823bba589a31e72fbd3e91..f1de801cb01e8649a3694ba0da9826686f4f0e15 100644 (file)
@@ -506,6 +506,10 @@ input#dfrn-url {
        margin-bottom: 30px;
 }
 
+#settings-expire-end {
+       margin-bottom: 30px;
+}
+
 #settings-username-end,
 #settings-email-end,
 #settings-nick-end,