Large code cleanups:
[mailer.git] / inc / extensions / ext-surfbar.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/28/2008 *
4  * ===================                          Last change: 08/28/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-surfbar.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : A visitor add-on for your members                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Ein Besuchertausch fuer Ihre Mitglieder          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Version number
44 setThisExtensionVersion('0.0.0');
45
46 // Version history array (add more with , '0.0.1' and so on)
47 setExtensionVersionHistory(array('0.0.0'));
48
49 // This extension is in development (non-productive)
50 enableExtensionProductive(false);
51
52 switch (getExtensionMode()) {
53         case 'register': // Do stuff when installation is running
54                 // SQL commands to run (surfbar URLs)
55                 addDropTableSql('surfbar_urls');
56                 addCreateTableSql('surfbar_urls', "
57 `url_id` BIGINT(20) UNSIGNED  NOT NULL AUTO_INCREMENT,
58 `url_userid` BIGINT(20) UNSIGNED  NULL DEFAULT NULL,
59 `url` VARCHAR(255) NOT NULL DEFAULT '',
60 `url_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
61 `url_views_total` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
62 `url_views_max` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
63 `url_views_allowed` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
64 `url_status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NOT NULL DEFAULT 'PENDING',
65 `url_registered` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
66 `url_last_locked` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
67 `url_lock_reason` VARCHAR(255) NOT NULL DEFAULT '',
68 `url_reject_reason` VARCHAR(255) NOT NULL DEFAULT '',
69 `url_fixed_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
70 PRIMARY KEY (`url_id`),
71 UNIQUE INDEX `userid_url` (`url_userid`,`url`),
72 INDEX `status_userid` (`url_status`,`url_userid`)",
73                         'Visitor add-on URLs');
74
75                 // Reload locks
76                 addDropTableSql('surfbar_locks');
77                 addCreateTableSql('surfbar_locks', "
78 `locks_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
79 `locks_userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
80 `locks_url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
81 `locks_last_surfed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
82 PRIMARY KEY (`locks_id`),
83 UNIQUE INDEX `userid_url` (`locks_userid`,`locks_url_id`),
84 INDEX (`locks_url_id`)",
85                         'Vistor-addon reload locks');
86
87                 // Visitor add-on salts
88                 addDropTableSql('surfbar_salts');
89                 addCreateTableSql('surfbar_salts', "
90 `salts_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
91 `salts_userid` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
92 `salts_url_id` BIGINT(20) UNSIGNED  NOT NULL DEFAULT 0,
93 `salts_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
94 PRIMARY KEY (`salts_id`),
95 UNIQUE INDEX `salts_userid_url` (`salts_userid`,`salts_url_id`),
96 INDEX (`salts_url_id`)",
97                         'Visitor add-on last used salts');
98
99                 // Statistics
100                 addDropTableSql('surfbar_stats');
101                 addCreateTableSql('surfbar_stats', "
102 `stats_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
103 `stats_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
104 `stats_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
105 `stats_count` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
106 `stats_last_surfed` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
107 PRIMARY KEY (`stats_id`),
108 UNIQUE INDEX `userid_url` (`stats_userid`,`stats_url_id`),
109 INDEX (`stats_url_id`)",
110                         'Visitor add-on Statistics');
111
112                 // Member actions pending on status
113                 addDropTableSql('surfbar_actions');
114                 addCreateTableSql('surfbar_actions', "
115 `actions_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
116 `actions_status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NULL DEFAULT NULL,
117 `actions_action` ENUM('EDIT','DELETE','PAUSE','UNPAUSE','FRAMETEST','RETREAT','RESUBMIT','BOOKNOW') NULL DEFAULT NULL,
118 `actions_new_status` ENUM('PENDING','ACTIVE','LOCKED','STOPPED','REJECTED','DELETED','MIGRATED','DEPLETED') NULL DEFAULT NULL,
119 PRIMARY KEY (`actions_id`),
120 UNIQUE INDEX `status_action` (`actions_status`,`actions_action`)",
121                         'Visitor add-on Member Actions');
122
123                 // Member actions
124                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('PENDING','RETREAT','DELETED')");
125                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('PENDING','FRAMETEST',NULL)");
126                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('PENDING','EDIT',NULL)");
127                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('ACTIVE','EDIT','PENDING')");
128                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('ACTIVE','DELETE','DELETED')");
129                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('ACTIVE','PAUSE','STOPPED')");
130                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('ACTIVE','FRAMETEST',NULL)");
131                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('LOCKED','DELETE','DELETED')");
132                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('LOCKED','FRAMETEST',NULL)");
133                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('LOCKED','RESUBMIT','PENDING')");
134                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('STOPPED','EDIT','PENDING')");
135                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('STOPPED','DELETE','DELETED')");
136                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('STOPPED','UNPAUSE','PENDING')");
137                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('DEPLETED','EDIT','PENDING')");
138                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('DEPLETED','DELETE','DELETED')");
139                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('REJECTED','EDIT','PENDING')");
140                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('REJECTED','DELETE','DELETED')");
141                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('REJECTED','FRAMETEST',NULL)");
142                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('REJECTED','RESUBMIT','PENDING')");
143                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('MIGRATED','EDIT','MIGRATED')");
144                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('MIGRATED','DELETE','DELETED')");
145                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('MIGRATED','FRAMETEST',NULL)");
146                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`,`actions_action`,`actions_new_status`) VALUES ('MIGRATED','BOOKNOW','PENDING')");
147
148                 // Config entries
149                 addConfigAddSql('surfbar_payment_model', "ENUM('STATIC','DYNAMIC') NOT NULL DEFAULT 'STATIC'");
150                 addConfigAddSql('surfbar_static_reward', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000');
151                 addConfigAddSql('surfbar_static_costs', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000');
152                 addConfigAddSql('surfbar_static_time', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60');
153                 addConfigAddSql('surfbar_static_lock', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT ' . (60 * 5));
154                 addConfigAddSql('surfbar_dynamic_percent', 'FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000');
155                 addConfigAddSql('surfbar_max_order', 'INT(7) UNSIGNED NOT NULL DEFAULT 10');
156                 addConfigAddSql('surfbar_restart_time', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (60 * 6));
157                 addConfigAddSql('surfbar_autostart', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
158                 addConfigAddSql('surfbar_migrate_urls', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
159                 addConfigAddSql('surfbar_total_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
160                 addConfigAddSql('surfbar_daily_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
161                 addConfigAddSql('surfbar_yester_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
162                 addConfigAddSql('surfbar_weekly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
163                 addConfigAddSql('surfbar_monthly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
164                 addConfigAddSql('surfbar_stats_reload', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 30');
165                 addConfigAddSql('surfbar_purge_deleted', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 7));
166                 addConfigAddSql('surfbar_purge_migrated', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 3));
167                 addConfigAddSql('surfbar_pause_mode', "ENUM('INTERNAL','EXERNAL') NOT NULL DEFAULT 'INTERNAL'");
168                 addConfigAddSql('surfbar_pause_url', "VARCHAR(255) NOT NULL DEFAULT ''");
169                 addConfigAddSql('surfbar_notify_limits', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
170                 addConfigAddSql('surfbar_notify_admin_unlock', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
171                 addConfigAddSql('surfbar_warn_low_points', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 100');
172                 addConfigAddSql('surfbar_low_interval', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT {?ONE_DAY?}');
173                 addConfigAddSql('surfbar_migrate_order', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
174                 addConfigAddSql('surfbar_notification_mode', "ENUM('INSTANT','RESET') NOT NULL DEFAULT 'INSTANT'");
175                 addConfigAddSql('surfbar_guest_login_form', "ENUM('Y','N') NOT NULL DEFAULT 'Y'");
176
177                 // Extend user data
178                 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `surfbar_low_notified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
179
180                 // Member menus
181                 addMemberMenuSql('surfbar', NULL, 'Besuchertausch', 4);
182                 addMemberMenuSql('surfbar', 'start_surfbar', 'Besuchertausch starten', 1);
183                 addMemberMenuSql('surfbar', 'book_surfbar', 'Seite buchen', 2);
184                 addMemberMenuSql('surfbar', 'list_surfbar', 'Seiten-Management', 3);
185                 addMemberMenuSql('surfbar', 'stats_surfbar', 'Seiten-Statistik', 4);
186
187                 // Admin menus
188                 addAdminMenuSql('surfbar', NULL, 'Besuchertausch', 'URLs im Besuchertausch verwalten, Einstellungen &auml;ndern und vieles mehr.', 7);
189                 addAdminMenuSql('surfbar', 'add_surfbar_url', 'URL hinzuf&uuml;gen', 'F&uuml;gen Sie URLs z.B. von Werbenetzwerken hinzu, oder Ihre eigenen Projekte. <strong>Vorsicht!</strong> Ihnen muss es auch gestattet sein, URLs aus dem Werbenetzwerk im Besuchertausch einzuf&uuml;gen.', 1);
190                 addAdminMenuSql('surfbar', 'list_surfbar_urls', 'URLs verwalten', 'Verwalten Sie hier alle im Besuchertausch befindlichen URLs mit nur wenigen Klicks.', 2);
191                 addAdminMenuSql('surfbar', 'unlock_surfbar_urls', 'Wartende URLs freigeben', 'Geben Sie hier f&uuml;r den Besuchertausch gebuchte URLs frei.', 3);
192                 addAdminMenuSql('surfbar', 'config_surfbar', 'Einstellungen', 'Einstellungen am Besuchertausch &auml;ndern, wie Festverg&uuml;tung, prozentuale Ref-Verg&uuml;tung und vieles mehr.', 4);
193                 addAdminMenuSql('surfbar', 'surfbar_stats', 'Statistiken', 'Detailierte Statistiken zu einer ausgew&auml;hlten URL anzeigen.', 5);
194                 addAdminMenuSql('surfbar', 'list_surfbar_actions', 'Mitgliederaktionen', 'Listet alle Mitgliederaktionen auf.', 6);
195
196                 // Register module
197                 addModuleSql('surfbar', 'Y', 'Y', 'N', 'N');
198
199                 // Insert data for points accounts
200                 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`,`column_name`,`locked_mode`,`payment_method`) VALUES ('monthly_bonus','points','LOCKED','DIRECT')");
201
202                 // This extension depends on ext-sql_patches
203                 addExtensionDependency('sql_patches');
204
205                 // Register filters
206                 registerFilter('post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', false, true, isExtensionDryRun());
207                 registerFilter('pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', false, true, isExtensionDryRun());
208                 break;
209
210         case 'remove': // Do stuff when removing extension
211                 // SQL commands to run
212                 addDropTableSql('surfbar_actions');
213                 addDropTableSql('surfbar_locks');
214                 addDropTableSql('surfbar_salts');
215                 addDropTableSql('surfbar_stats');
216                 addDropTableSql('surfbar_urls');
217                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='surfbar'");
218                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='surfbar'");
219
220                 // Unregister module
221                 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='surfbar' LIMIT 1");
222
223                 // Unregister filter
224                 unregisterFilter(__FUNCTION__, __LINE__, 'post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', true, isExtensionDryRun());
225                 unregisterFilter(__FUNCTION__, __LINE__, 'pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', true, isExtensionDryRun());
226                 break;
227
228         case 'activate': // Do stuff when admin activates this extension
229                 // SQL commands to run
230                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `action`='surfbar' LIMIT 5");
231                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N',`hidden`='N',`admin_only`='N',`mem_only`='Y' WHERE `module`='surfbar' LIMIT 1");
232                 break;
233
234         case 'deactivate': // Do stuff when admin deactivates this extension
235                 // SQL commands to run
236                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N',`locked`='Y' WHERE `action` = 'surfbar' LIMIT 5");
237                 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='Y' WHERE `module`='surfbar' LIMIT 1");
238                 break;
239
240         case 'update': // Update an extension
241                 switch (getCurrentExtensionVersion()) {
242                         case '0.0.1': // SQL queries for v0.0.1
243                                 addExtensionSql('');
244
245                                 // Update notes (these will be set as task text!)
246                                 setExtensionUpdateNotes('');
247                                 break;
248                 } // END - switch
249                 break;
250
251         case 'modify': // When the extension got modified
252                 break;
253
254         case 'test': // For testing purposes
255                 break;
256
257         case 'init': // Do stuff when extension is initialized
258                 break;
259
260         default: // Unknown extension mode
261                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));
262                 break;
263 } // END - switch
264
265 // [EOF]
266 ?>