2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/28/2008 *
4 * =================== Last change: 08/28/2008 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 setThisExtensionVersion('0.0.0');
46 // Version history array (add more with , '0.0.1' and so on)
47 setExtensionVersionHistory(array('0.0.0'));
49 // This extension is in development (non-productive)
50 enableExtensionProductive(FALSE);
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_package_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
60 `url` VARCHAR(255) NOT NULL DEFAULT '',
61 `url_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
62 `url_views_total` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
63 `url_views_max` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
64 `url_views_allowed` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
65 `url_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NOT NULL DEFAULT 'PENDING',
66 `url_registered` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
67 `url_last_locked` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
68 `url_lock_reason` VARCHAR(255) NOT NULL DEFAULT '',
69 `url_reject_reason` VARCHAR(255) NOT NULL DEFAULT '',
70 `url_fixed_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
71 `url_fixed_waiting` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
72 PRIMARY KEY (`url_id`),
73 UNIQUE INDEX `userid_url` (`url_userid`, `url`),
74 INDEX `status_userid` (`url_status`, `url_userid`),
75 INDEX (`url_package_id`)",
76 'Visitor add-on URLs');
78 // Booking packages for members
79 addDropTableSql('surfbar_packages');
80 addCreateTableSql('surfbar_packages', "
81 `package_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
82 `package_reload` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
83 `package_waiting` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
84 `package_points_costs` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
85 `package_points_reward` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
86 PRIMARY KEY (`package_id`),
87 UNIQUE INDEX `package` (`package_reload`, `package_waiting`)",
91 addDropTableSql('surfbar_locks');
92 addCreateTableSql('surfbar_locks', "
93 `locks_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
94 `locks_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
95 `locks_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
96 `locks_last_surfed` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
97 PRIMARY KEY (`locks_id`),
98 UNIQUE INDEX `userid_url` (`locks_userid`, `locks_url_id`),
99 INDEX (`locks_url_id`)",
100 'Vistor-addon reload locks');
102 // Visitor add-on salts
103 addDropTableSql('surfbar_salts');
104 addCreateTableSql('surfbar_salts', "
105 `salts_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
106 `salts_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
107 `salts_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
108 `salts_last_salt` VARCHAR(255) NOT NULL DEFAULT '',
109 PRIMARY KEY (`salts_id`),
110 UNIQUE INDEX `salts_userid_url` (`salts_userid`, `salts_url_id`),
111 INDEX (`salts_url_id`)",
112 'Visitor add-on last used salts');
115 addDropTableSql('surfbar_stats');
116 addCreateTableSql('surfbar_stats', "
117 `stats_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
118 `stats_userid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
119 `stats_url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
120 `stats_count` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
121 `stats_last_surfed` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
122 PRIMARY KEY (`stats_id`),
123 UNIQUE INDEX `userid_url` (`stats_userid`, `stats_url_id`),
124 INDEX (`stats_url_id`)",
125 'Visitor add-on Statistics');
127 // Member actions pending on status
128 addDropTableSql('surfbar_actions');
129 addCreateTableSql('surfbar_actions', "
130 `actions_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
131 `actions_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NULL DEFAULT NULL,
132 `actions_action` ENUM('EDIT', 'DELETE', 'PAUSE', 'UNPAUSE', 'FRAMETEST', 'RETREAT', 'RESUBMIT', 'BOOKNOW') NULL DEFAULT NULL,
133 `actions_new_status` ENUM('PENDING', 'ACTIVE', 'LOCKED', 'STOPPED', 'REJECTED', 'DELETED', 'MIGRATED', 'DEPLETED') NULL DEFAULT NULL,
134 PRIMARY KEY (`actions_id`),
135 UNIQUE INDEX `status_action` (`actions_status`, `actions_action`)",
136 'Visitor add-on Member Actions');
139 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'RETREAT', 'DELETED')");
140 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'FRAMETEST',NULL)");
141 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('PENDING', 'EDIT',NULL)");
142 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'EDIT', 'PENDING')");
143 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'DELETE', 'DELETED')");
144 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'PAUSE', 'STOPPED')");
145 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('ACTIVE', 'FRAMETEST',NULL)");
146 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'DELETE', 'DELETED')");
147 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'FRAMETEST',NULL)");
148 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('LOCKED', 'RESUBMIT', 'PENDING')");
149 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'EDIT', 'PENDING')");
150 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'DELETE', 'DELETED')");
151 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('STOPPED', 'UNPAUSE', 'PENDING')");
152 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('DEPLETED', 'EDIT', 'PENDING')");
153 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('DEPLETED', 'DELETE', 'DELETED')");
154 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'EDIT', 'PENDING')");
155 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'DELETE', 'DELETED')");
156 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'FRAMETEST',NULL)");
157 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('REJECTED', 'RESUBMIT', 'PENDING')");
158 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'EDIT', 'MIGRATED')");
159 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'DELETE', 'DELETED')");
160 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'FRAMETEST',NULL)");
161 addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_actions` (`actions_status`, `actions_action`, `actions_new_status`) VALUES ('MIGRATED', 'BOOKNOW', 'PENDING')");
164 addConfigAddSql('surfbar_payment_model', "ENUM('STATIC', 'DYNAMIC') NOT NULL DEFAULT 'STATIC'");
165 addConfigAddSql('surfbar_static_reward', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.25000');
166 addConfigAddSql('surfbar_static_costs', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 1.00000');
167 addConfigAddSql('surfbar_static_time', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT 60');
168 addConfigAddSql('surfbar_static_lock', 'SMALLINT(6) UNSIGNED NOT NULL DEFAULT ' . (60 * 5));
169 addConfigAddSql('surfbar_dynamic_percent', 'FLOAT(10,5) UNSIGNED NOT NULL DEFAULT 10.00000');
170 addConfigAddSql('surfbar_max_order', 'INT(7) UNSIGNED NOT NULL DEFAULT 10');
171 addConfigAddSql('surfbar_restart_time', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (60 * 6));
172 addConfigAddSql('surfbar_auto_start', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
173 addConfigAddSql('surfbar_migrate_urls', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
174 addConfigAddSql('surfbar_total_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
175 addConfigAddSql('surfbar_daily_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
176 addConfigAddSql('surfbar_yester_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
177 addConfigAddSql('surfbar_weekly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
178 addConfigAddSql('surfbar_monthly_counter', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
179 addConfigAddSql('surfbar_stats_reload', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 30');
180 addConfigAddSql('surfbar_purge_deleted', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 7));
181 addConfigAddSql('surfbar_purge_migrated', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 3));
182 addConfigAddSql('surfbar_pause_mode', "ENUM('INTERNAL', 'EXERNAL') NOT NULL DEFAULT 'INTERNAL'");
183 addConfigAddSql('surfbar_pause_url', "VARCHAR(255) NOT NULL DEFAULT ''");
184 addConfigAddSql('surfbar_notify_limits', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
185 addConfigAddSql('surfbar_notify_admin_unlock', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
186 addConfigAddSql('surfbar_warn_low_points', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 100');
187 addConfigAddSql('surfbar_low_interval', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT {?ONE_DAY?}');
188 addConfigAddSql('surfbar_migrate_order', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
189 addConfigAddSql('surfbar_notification_mode', "ENUM('INSTANT', 'RESET') NOT NULL DEFAULT 'INSTANT'");
190 addConfigAddSql('surfbar_guest_login_form', "ENUM('Y', 'N') NOT NULL DEFAULT 'Y'");
193 addExtensionAddTableColumnSql('user_data', 'surfbar_low_notified', "TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
196 addMemberMenuSql('surfbar', NULL, 'Besuchertausch', 4);
197 addMemberMenuSql('surfbar', 'start_surfbar', 'Besuchertausch starten', 1);
198 addMemberMenuSql('surfbar', 'book_surfbar', 'Seite buchen', 2);
199 addMemberMenuSql('surfbar', 'list_surfbar', 'Seiten-Management', 3);
200 addMemberMenuSql('surfbar', 'stats_surfbar', 'Seiten-Statistik', 4);
203 addAdminMenuSql('surfbar', NULL, 'Besuchertausch', 'URLs im Besuchertausch verwalten, Einstellungen ändern und vieles mehr.', 7);
204 addAdminMenuSql('surfbar', 'add_surfbar_url', 'URL hinzufügen', 'Fü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ügen.', 1);
205 addAdminMenuSql('surfbar', 'list_surfbar_urls', 'URLs verwalten', 'Verwalten Sie hier alle im Besuchertausch befindlichen URLs mit nur wenigen Klicks.', 2);
206 addAdminMenuSql('surfbar', 'unlock_surfbar_urls', 'Wartende URLs freigeben', 'Geben Sie hier für den Besuchertausch gebuchte URLs frei.', 3);
207 addAdminMenuSql('surfbar', 'list_surfbar_packages', 'Buchungspakete verwalten', '"Buchungspakete" erlauben dem Mitglied nur von Ihnen definierte Reloadzeiten und Mindestauffenthalte.', 4);
208 addAdminMenuSql('surfbar', 'config_surfbar', 'Einstellungen', 'Einstellungen am Besuchertausch ändern, wie Festvergütung, prozentuale Ref-Vergütung und vieles mehr.', 5);
209 addAdminMenuSql('surfbar', 'surfbar_stats', 'Statistiken', 'Detailierte Statistiken zu einer ausgewählten URL anzeigen.', 6);
210 addAdminMenuSql('surfbar', 'list_surfbar_actions', 'Mitglieder-Aktionen', 'Listet alle Mitglieder-Aktionen auf.', 7);
213 addModuleSql('surfbar', '{OPEN_TEMPLATE}MODULE_SURFBAR_TITLE{CLOSE_TEMPLATE}', 'Y', 'Y', 'N', 'N');
215 // Insert data for points accounts
216 registerExtensionPointsData('monthly_surfbar', 'points', 'LOCKED', 'DIRECT');
218 // This extension depends on ext-sql_patches
219 addExtensionDependency('sql_patches');
222 registerFilter(__FILE__, __LINE__, 'post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', FALSE, TRUE, isExtensionDryRun());
223 registerFilter(__FILE__, __LINE__, 'pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', FALSE, TRUE, isExtensionDryRun());
226 case 'remove': // Do stuff when removing extension
227 // SQL commands to run
228 addDropTableSql('surfbar_actions');
229 addDropTableSql('surfbar_locks');
230 addDropTableSql('surfbar_salts');
231 addDropTableSql('surfbar_stats');
232 addDropTableSql('surfbar_packages');
233 addDropTableSql('surfbar_urls');
234 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='surfbar'");
235 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='surfbar'");
238 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='surfbar' LIMIT 1");
240 // Unregister points data
241 unregisterExtensionPointsData('monthly_surfbar');
244 unregisterFilter(__FILE__, __LINE__, 'post_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_STATUS', TRUE, isExtensionDryRun());
245 unregisterFilter(__FILE__, __LINE__, 'pre_change_surfbar_url_status', 'SURFBAR_CHANGE_URL_VALIDATE_DATA', TRUE, isExtensionDryRun());
248 case 'activate': // Do stuff when admin activates this extension
249 // SQL commands to run
250 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `action`='surfbar' LIMIT 5");
251 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='N',`hidden`='N',`admin_only`='N',`mem_only`='Y' WHERE `module`='surfbar' LIMIT 1");
254 case 'deactivate': // Do stuff when admin deactivates this extension
255 // SQL commands to run
256 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N',`locked`='Y' WHERE `action` = 'surfbar' LIMIT 5");
257 addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_mod_reg` SET `locked`='Y' WHERE `module`='surfbar' LIMIT 1");
260 case 'update': // Update an extension
261 switch (getCurrentExtensionVersion()) {
262 case '0.0.1': // SQL queries for v0.0.1
265 // Update notes (these will be set as task text!)
266 setExtensionUpdateNotes('');
271 case 'modify': // When the extension got modified
274 case 'test': // For testing purposes
277 case 'init': // Do stuff when extension is initialized
280 default: // Unknown extension mode
281 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));