add('name', PLUGIN_EVENT_DBCLEAN_NAME); $propbag->add('description', PLUGIN_EVENT_DBCLEAN_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Malte Paskuda, Matthias Mees'); $propbag->add('version', '0.2.10'); $propbag->add('requirements', array( 'serendipity' => '0.8' )); $propbag->add('event_hooks', array( 'backend_sidebar_admin' => true, 'backend_sidebar_entries_event_display_dbclean' => true, 'external_plugin' => true, 'css_backend' => true, 'cronjob' => true ) ); $propbag->add('groups', array('BACKEND_FEATURES')); $propbag->add('configuration', array('cronjob', 'days')); } function generate_content(&$title) { $title = $this->title; } function introspect_config_item($name, &$propbag) { switch($name) { case 'cronjob': if (class_exists('serendipity_event_cronjob')) { $propbag->add('type', 'select'); $propbag->add('name', PLUGIN_EVENT_DBCLEAN_CRONJOB); $propbag->add('description', ''); $propbag->add('default', 'daily'); $propbag->add('select_values', serendipity_event_cronjob::getValues()); } break; case 'days': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_DBCLEAN_MENU_KEEP . ' (' . DAYS . ')'); $propbag->add('description', ''); $propbag->add('default', '30'); break; default: return false; } return true; } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'cronjob': if ($this->get_config('cronjob') == $eventData) { serendipity_event_cronjob::log('DBClean', 'plugin'); $days = (int)$this->get_config('days'); if ($days > 0) { $this->cleanDB('cronjoblog', $days); $this->cleanDB('spamblocklog', $days); $this->cleanDB('spamblock_htaccess', $days); $this->cleanDB('visitors', $days); $this->cleanDB('referrers', $days); $this->cleanDB('exits', $days); } } return true; break; case 'external_plugin': switch ($eventData) { case 'dbclean': if (! (serendipity_checkPermission('siteConfiguration') || serendipity_checkPermission('blogConfiguration'))) { return; } $days = $_REQUEST['days']; if (is_numeric($days)) { if (isset($_REQUEST['cronjoblog'])) { $this->cleanDB('cronjoblog', $days); } if (isset($_REQUEST['spamblocklog'])) { $this->cleanDB('spamblocklog', $days); } if (isset($_REQUEST['spamblock_htaccess'])) { $this->cleanDB('spamblock_htaccess', $days); } if (isset($_REQUEST['visitors'])) { $this->cleanDB('visitors', $days); } if (isset($_REQUEST['referrers'])) { $this->cleanDB('referrers', $days); } if (isset($_REQUEST['exits'])) { $this->cleanDB('exits', $days); } } #redirect the user back to the menu echo ''; return true; break; } return true; break; case 'backend_sidebar_admin': if ($serendipity['version'][0] == '1') { echo ''; } else { echo '
  • ' .PLUGIN_EVENT_DBCLEAN_NAME .'
  • '; } return true; break; case 'backend_sidebar_entries_event_display_dbclean': $this->displayMenu(); return true; break; case 'css_backend': if ($serendipity['version'][0] > 1) { ?> #dbcleanTable { border: 1px solid #aaa; border-bottom: 0 none; width: 100%; } #dbcleanTable thead tr { background-color: #eee; } #dbcleanTable tr { border-bottom: 1px solid #aaa; } #dbcleanTable th, #dbcleanTable td { padding: .125em .25em; } #dbcleanTable { width: 100%; text-align: center; } #dbcleanTable th { text-align: center; }'; } echo '

    ' . PLUGIN_EVENT_DBCLEAN_NAME_MENU . '

    '; echo '
    '; if ($serendipity['version'][0] == '1') { echo PLUGIN_EVENT_DBCLEAN_MENU_KEEP . ' ' . DAYS; } else { echo '
    '; echo ''; echo ' '; echo '
    '; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
    ' . DELETE . '' . PLUGIN_EVENT_DBCLEAN_TABLE . '' . ENTRIES . '
    spamblocklog' . $this->countElements('spamblocklog') . '
    spamblock_htaccess' . $this->countElements('spamblock_htaccess') . '
    visitors' . $this->countElements('visitors') . '
    referrers' . $this->countElements('referrers') . '
    exits' . $this->countElements('exits') . '
    cronjoblog' . $this->countElements('cronjoblog') . '
    '; if ($serendipity['version'][0] == '1') { echo ''; } else { echo '
    '; } echo '
    '; } function countElements($table, $timespan=false) { global $serendipity; if (! $timespan) { $sql = "SELECT COUNT(*) FROM {$serendipity['dbPrefix']}$table"; } else { if ($table=='visitors') { $sql = "SELECT COUNT(*) FROM {$serendipity['dbPrefix']}visitors WHERE unix_timestamp(concat(day,' ',time)) < $timespan"; } else if ($table =='referrers') { $sql = "SELECT COUNT(*) FROM {$serendipity['dbPrefix']}$table WHERE day < $timespan"; } else { $sql = "SELECT COUNT(*) FROM {$serendipity['dbPrefix']}$table WHERE timestamp < $timespan"; } } $count = 0; try { $count = serendipity_db_query($sql); } catch (Exception $e) { } if(is_array($count)) { if (is_array($count[0])) { return $count[0][0]; } } return 0; } function debugMsg($msg) { global $serendipity; $this->debug_fp = @fopen ( $serendipity ['serendipityPath'] . 'templates_c/dbclean.log', 'a' ); if (! $this->debug_fp) { return false; } if (empty ( $msg )) { fwrite ( $this->debug_fp, "failure \n" ); } else { fwrite ( $this->debug_fp, print_r ( $msg, true ) ); } fclose ( $this->debug_fp ); } } /* vim: set sts=4 ts=4 expandtab : */ ?>