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.7'); $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 ) ); $propbag->add('groups', array('BACKEND_FEATURES')); } function generate_content(&$title) { $title = $this->title; } /*function introspect_config_item($name, &$propbag) { }*/ function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { 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['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 '
    ' . 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') . '
    '; 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 = serendipity_db_query($sql); 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 : */ ?>