4 * file: Import.Admin.class.php
5 * MTBlacklist refresh module
7 * Updates Sites MT Blacklist via Master MT Blacklist rss feed
9 * Copyright (C) 2004-2009 by the following authors:
10 * Author Tom Willett tomw AT pigstye DOT net
11 * Author Dirk Haun dirk AT haun-online DOT de
13 * Licensed under GNU General Public License
15 * Based on MT-Blacklist Updater by
16 * Cheah Chu Yeow (http://blog.codefront.net/)
22 if (strpos(strtolower($_SERVER['PHP_SELF']), 'import.admin.class.php') !== false) {
23 die('This file can not be used on its own!');
27 * Include Abstract Base Class
29 require_once $_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php';
37 class Import extends BaseAdmin {
45 if (DB_count($_TABLES['spamx'], 'name', 'MTBlacklist') > 0) {
46 $display = $this->_update_blacklist();
48 $display = $this->_initial_import();
56 global $_TABLES, $LANG_SX00;
58 if (DB_count($_TABLES['spamx'], 'name', 'MTBlacklist') > 0) {
59 $display = $LANG_SX00['uMTlist'];
61 $display = $LANG_SX00['initial_import'];
68 * Update MT Blacklist from RSS feed
70 function _update_blacklist()
72 global $_CONF, $_TABLES, $LANG_SX00, $_SPX_CONF;
74 require_once $_CONF['path'] . 'plugins/spamx/magpierss/rss_fetch.inc';
75 require_once $_CONF['path'] . 'plugins/spamx/magpierss/rss_utils.inc';
77 if (!defined('MAGPIE_USER_AGENT')) {
78 define('MAGPIE_USER_AGENT', 'Geeklog/' . VERSION);
80 $rss = fetch_rss($_SPX_CONF['rss_url']);
82 if (strpos($_SPX_CONF['rss_url'], 'jayallen.org') === false) {
83 return '<p>An error occured when updating MT Blacklist</p>';
85 $url = COM_createLink('discontinued', 'http://www.geeklog.net/article.php/mt-blacklist-discontinued');
86 return '<p>Please note that MT-Blacklist has been $url and will not be updated any more.</p>';
90 // entries to add and delete, according to the blacklist changes feed
94 foreach ($rss->items as $item) {
95 // time this entry was published (currently unused)
96 // $published_time = parse_w3cdtf( $item['dc']['date'] );
97 $entry = substr($item['description'], 0, -3); // blacklist entry
98 $subject = $item['dc']['subject']; // indicates addition or deletion
100 // is this an addition or a deletion?
101 $dbentry = addslashes($entry);
102 if (strpos($subject, 'addition') !== false) {
103 // save it to database
104 $result = DB_query("SELECT name FROM {$_TABLES['spamx']} WHERE name = 'MTBlacklist' AND value = '$dbentry'");
105 $nrows = DB_numRows($result);
107 DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('MTBlacklist', '$dbentry')");
110 } else if (strpos($subject, 'deletion') !== false) {
111 // delete it from database
112 $result = DB_query("SELECT name FROM {$_TABLES['spamx']} WHERE name = 'MTBlacklist' AND value = '$dbentry'");
113 $nrows = DB_numRows($result);
115 DB_delete($_TABLES['spamx'], array('name', 'value'),
116 array('MTBlacklist', $dbentry));
117 $to_delete[] = $entry;
121 $display = '<hr' . XHTML . '><p><b>' . $LANG_SX00['entriesadded'] . '</b></p><ul>';
122 foreach ($to_add as $e) {
123 $display .= "<li>$e</li>";
125 $display .= '</ul><p><b>' . $LANG_SX00['entriesdeleted'] . '</b></p><ul>';
126 foreach ($to_delete as $e) {
127 $display .= "<li>$e</li>";
130 SPAMX_log($LANG_SX00['uMTlist'] . $LANG_SX00['uMTlist2'] . count($to_add) . $LANG_SX00['uMTlist3'] . count($to_delete) . $LANG_SX00['entries']);
136 * Initial import of the MT Blacklist
138 function _initial_import()
140 global $_CONF, $_TABLES, $LANG_SX00, $_SPX_CONF;
142 if (ini_get('allow_url_fopen')) {
143 $blacklist = file($_SPX_CONF['mtblacklist_url']);
144 $count = $this->_do_import($blacklist);
147 $display = sprintf($LANG_SX00['import_success'], $count);
148 SPAMX_log($LANG_SX00['uMTlist'] . $LANG_SX00['uMTlist2']
149 . $count . $LANG_SX00['uMTlist3'] . '0'
150 . $LANG_SX00['entries']);
152 $display = $LANG_SX00['import_failure'];
154 } else { // read blacklist from local file
155 $fromfile = $_CONF['path_data'] . 'blacklist.txt';
157 if (file_exists($fromfile)) {
158 $blacklist = file($fromfile);
159 $count = $this->_do_import($blacklist);
162 $display = sprintf($LANG_SX00['import_success'], $count);
163 SPAMX_log($LANG_SX00['uMTlist'] . $LANG_SX00['uMTlist2']
164 . $count . $LANG_SX00['uMTlist3'] . '0'
165 . $LANG_SX00['entries']);
167 $display = $LANG_SX00['import_failure'];
170 $display = sprintf($LANG_SX00['allow_url_fopen'],
171 $_CONF['path_data']);
172 $display .= '<p>'. COM_createLink($_SPX_CONF['mtblacklist_url'],
173 $_SPX_CONF['mtblacklist_url']);
177 // Import Personal Blacklist for existing users.
178 $fromfile = $_CONF['path_html'] . 'spamx/blacklist.php';
179 if (file_exists($fromfile)) {
180 require_once $fromfile;
181 $count = $this->_do_importp($SPAMX_BLACKLIST);
182 $display .= $LANG_SX00['initial_Pimport'];
184 $display .= sprintf($LANG_SX00['import_success'], $count);
185 SPAMX_log($LANG_SX00['uPlist'] . $LANG_SX00['uMTlist2']
186 . $count . $LANG_SX00['uMTlist3'] . '0'
187 . $LANG_SX00['entries']);
189 $display .= $LANG_SX00['import_failure'];
197 * Import the blacklist
199 * @param array $lines The blacklist
200 * @return int number of lines imported
202 function _do_import($lines)
207 foreach ($lines as $line) {
208 $l = explode('#', $line);
209 $entry = addslashes(trim($l[0]));
210 if (!empty($entry)) {
211 DB_query("INSERT INTO {$_TABLES['spamx']} VALUE ('MTBlacklist', '$entry')");
220 * Import personal blacklist
222 * @param array $lines The blacklist
223 * @return int number of lines imported
225 function _do_importp($lines)
230 foreach ($lines as $entry) {
231 if (!empty($entry)) {
232 $entry = addslashes($entry);
233 DB_query("INSERT INTO {$_TABLES['spamx']} VALUES ('Personal', '$entry')");