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 surfbar for your members *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Eine Surfbar fuer Ihre Mitglieder *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.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` 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 `userid_url` (`url_userid`, `url`),
72 INDEX `status_userid` (`url_status`, `url_userid`)",
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 `userid_url` (`locks_userid`, `locks_url_id`),
84 INDEX (`locks_url_id`)",
85 'Surfbar reload locks');
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 `salts_userid_url` (`salts_userid`, `salts_url_id`),
96 INDEX (`salts_url_id`)",
97 'Surfbar last used salts');
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 `userid_url` (`stats_userid`, `stats_url_id`),
109 INDEX (`stats_url_id`)",
110 'Surfbar Statistics');
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 `status_action` (`actions_status`, `actions_action`)",
121 'Surfbar 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')");
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'");
178 addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `surfbar_low_notified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
181 addMemberMenuSql('surfbar', NULL, 'Surfbar', 4);
182 addMemberMenuSql('surfbar', 'start_surfbar', 'Surfbar 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);
188 addAdminMenuSql('surfbar', NULL, 'Surfbar', 'URLs in der Surfbar verwalten, Einstellungen ändern und vieles mehr.', 7);
189 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 in die Surfbar einzufügen.', 1);
190 addAdminMenuSql('surfbar', 'list_surfbar_urls', 'URLs verwalten', 'Verwalten Sie hier alle in der Surfbar befindlichen URLs mit nur wenigen Klicks.', 2);
191 addAdminMenuSql('surfbar', 'unlock_surfbar_urls', 'Wartende URLs freigeben', 'Geben Sie hier nur direkt in der Surfbar gebuchte URLs frei.', 3);
192 addAdminMenuSql('surfbar', 'config_surfbar', 'Einstellungen', 'Einstellungen an der Surfbar ändern, wie Festvergütung, prozentuale Ref-Vergütung und vieles mehr.', 4);
193 addAdminMenuSql('surfbar', 'surfbar_stats', 'Statistiken', 'Detailierte Statistiken zu einer ausgewählten URL anzeigen.', 5);
194 addAdminMenuSql('surfbar', 'list_surfbar_actions', 'Mitgliederaktionen', 'Listet alle Mitgliederaktionen auf.', 6);
197 addModuleSql('surfbar', 'Y', 'Y', 'N', 'N');
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')");
202 // This extension depends on ext-sql_patches
203 addExtensionDependency('sql_patches');
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());
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'");
221 addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='surfbar' LIMIT 1");
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());
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");
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");
240 case 'update': // Update an extension
241 switch (getCurrentExtensionVersion()) {
242 case '0.0.1': // SQL queries for v0.0.1
245 // Update notes (these will be set as task text!)
246 setExtensionUpdateNotes('');
251 case 'modify': // When the extension got modified
254 case 'test': // For testing purposes
257 case 'init': // Do stuff when extension is initialized
260 default: // Unknown extension mode
261 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown extension mode %s in extension %s detected.", getExtensionMode(), getCurrentExtensionName()));