PluginProbe ʕ •ᴥ•ʔ
Redirection / 1.3.0
Redirection v1.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0
redirect-redirection / redirect-redirection.php
redirect-redirection Last commit date
analyst 1 month ago assets 1 month ago includes 1 month ago modules 1 month ago activation.php 1 month ago deactivation.php 1 month ago index.html 1 month ago readme.txt 1 month ago redirect-redirection.php 1 month ago uninstall.php 1 month ago
redirect-redirection.php
359 lines
1 <?php
2 /*
3 * Plugin Name: Redirect Redirection
4 * Description: Create specific URL redirections and redirection rules super-easily on a beautiful, user-friendly interface of the Redirect Redirection plugin.
5 * Version: 1.3.0
6 * Author: Inisev
7 * Author URI: https://inisev.com
8 * Plugin URI: https://redirection.pro
9 * Text Domain: redirect-redirection
10 */
11
12 if (!defined("ABSPATH")) {
13 exit();
14 }
15
16 /**
17 * Plugin's constants
18 */
19 define("IRRP_DIR_PATH", dirname(__FILE__));
20 define("IRRP_DIR_NAME", basename(IRRP_DIR_PATH));
21 define("IRRP_CRON_DELETE_LOGS", "irrp_cron_delete_logs");
22 define("IRRP_CRON_DELETE_LOGS_RECURRENCE_KEY", "irrp_custom_interval");
23 define("IRRP_CRON_DELETE_LOGS_RECURRENCE", 60);
24 define("IRRP_PLUGIN_VERSION", "1.3.0");
25
26 /**
27 * Create tables on activation.
28 */
29 register_activation_hook(__FILE__, function () {
30
31 include_once IRRP_DIR_PATH . '/activation.php';
32 });
33
34 /**
35 * Disable CRON job on deactivation
36 */
37 register_deactivation_hook(__FILE__, function () {
38
39 include_once IRRP_DIR_PATH . '/deactivation.php';
40 });
41
42 /**
43 * Load the plugin
44 */
45 add_action('wp_loaded', function () {
46
47 // Include our cool banner
48 include_once "includes/banner/misc.php";
49
50 include_once "includes/irrp-constants.php";
51 include_once "includes/irrp-cache-manager.php";
52 include_once "includes/irrp-db-manager.php";
53 include_once "includes/irrp-helper.php";
54 include_once "includes/settings/irrp-settings.php";
55 include_once "includes/irrp-helper-ajax.php";
56 include_once "includes/irrp-export-import.php";
57
58 class IrrPRedirection implements IRRPConstants {
59
60 /**
61 * @var IRRPDBManager
62 */
63 private $dbManager;
64
65 /**
66 * @var IRRPSettings
67 */
68 private $settings;
69
70 /**
71 * @var IRRPHelper
72 */
73 private $helper;
74
75 /**
76 * @var IRRPHelperAjax
77 */
78 private $helperAjax;
79
80 /**
81 * @var IRRPExportImport
82 */
83 private $exportImport;
84 private $minimum_php_version = '7.0.0';
85 private $minimum_wp_version = '5.0';
86 public static $TABS = [
87 "specific-url-redirections" => "specific-url-redirections",
88 "redirection-rules" => "redirection-rules",
89 "redirection-and-404-logs" => "redirection-and-404-logs",
90 "automatic-redirects" => "automatic-redirects",
91 "change-urls" => "change-urls",
92 ];
93 public static $CRITERIAS;
94 public static $PERMALINK_STRUCTURE_VALUES;
95 public static $ACTIONS;
96 public static $REDIRECTION_LOGS_DELETE;
97 public static $REDIRECTION_LOGS_FILTER;
98 private static $INSTANCE = null;
99
100 private function __construct() {
101
102 $this->dbManager = new IRRPDBManager();
103 //add_action("admin_notices", [&$this, "adminNotices"]);
104 add_action("wp_loaded", [&$this, "irrpDependencies"]);
105 //add_filter("cron_schedules", [$this, "irrpSetIntervals"]);
106 }
107
108 public static function getInstance() {
109 if (is_null(self::$INSTANCE)) {
110 self::$INSTANCE = new self();
111 }
112 return self::$INSTANCE;
113 }
114
115 /**
116 * Add a signature to the front page.
117 */
118 public function MetaVersion() {
119 echo '<meta name="redi-version" content="' . IRRP_PLUGIN_VERSION . '" />';
120 }
121
122 public function irrpInit() {
123 $rules = $this->dbManager->getRules();
124 $option404Status = $this->dbManager->isAre404sRuleExists($rules) ? "disabled" : "";
125 $optionAllUrlsStatus = $this->dbManager->isAllURLsRuleExists($rules) ? "disabled" : "";
126
127 self::$CRITERIAS = [
128 [
129 "option" => "contain",
130 "text" => __("Contain", "redirect-redirection"),
131 ],
132 [
133 "option" => "start-with",
134 "text" => __("Start with", "redirect-redirection"),
135 ],
136 [
137 "option" => "end-with",
138 "text" => __("End with", "redirect-redirection"),
139 ],
140 [
141 "option" => "have-permalink-structure",
142 "text" => __("Have permalink structure", "redirect-redirection"),
143 ],
144 // [
145 // "option" => "have-category",
146 // "text" => __("Have Category", "redirect-redirection"),
147 // ],
148 // [
149 // "option" => "have-tag",
150 // "text" => __("Have Tag", "redirect-redirection"),
151 // ],
152 // [
153 // "option" => "have-author",
154 // "text" => __("Have Author", "redirect-redirection"),
155 // ],
156 [
157 "option" => "regex-match",
158 "text" => __("Regex matches", "redirect-redirection"),
159 ],
160 [
161 "option" => "are-404s",
162 "text" => __("Are 404s", "redirect-redirection"),
163 "status" => $option404Status,
164 ],
165 [
166 "option" => "all-urls",
167 "text" => __("All URLs", "redirect-redirection"),
168 "status" => $optionAllUrlsStatus,
169 ],
170 ];
171
172 self::$PERMALINK_STRUCTURE_VALUES = [
173 [
174 "option" => "day-and-name",
175 "text" => __("Day and name", "redirect-redirection")
176 ],
177 [
178 "option" => "month-and-name",
179 "text" => __("Month and name", "redirect-redirection")
180 ],
181 [
182 "option" => "post-name",
183 "text" => __("Post name", "redirect-redirection")
184 ],
185 [
186 "option" => "category-and-name",
187 "text" => __("Category and name", "redirect-redirection")
188 ],
189 [
190 "option" => "author-and-name",
191 "text" => __("Author and name", "redirect-redirection")
192 ],
193 ];
194
195 self::$ACTIONS = [
196 [
197 "option" => "a-specific-url",
198 "text" => __("A Specific URL", "redirect-redirection")
199 ],
200 [
201 "option" => "urls-with-new-string",
202 "text" => __("URLs with new string", "redirect-redirection")
203 ],
204 [
205 "option" => "urls-with-removed-string",
206 "text" => __("URLs with removed string", "redirect-redirection")
207 ],
208 [
209 "option" => "new-permalink-structure",
210 "text" => __("New permalink structure", "redirect-redirection")
211 ],
212 [
213 "option" => "regex-match",
214 "text" => __("Regex matches", "redirect-redirection")
215 ],
216 [
217 "option" => "random-similar-post",
218 "text" => __("Random similar post", "redirect-redirection")
219 ],
220 [
221 "option" => "explain-those-options",
222 "text" => __("Explain those options", "redirect-redirection")
223 ],
224 ];
225
226 self::$REDIRECTION_LOGS_DELETE = [
227 [
228 "option" => "never",
229 "text" => __("Never", "redirect-redirection"),
230 ],
231 [
232 "option" => "older-than-a-week",
233 "text" => __("Older than a week", "redirect-redirection")
234 ],
235 [
236 "option" => "older-than-a-month",
237 "text" => __("Older than a month", "redirect-redirection")
238 ],
239 "selectedId" => 0,
240 ];
241
242 self::$REDIRECTION_LOGS_FILTER = [
243 [
244 "option" => "all",
245 "text" => __("All", "redirect-redirection"),
246 ],
247 [
248 "option" => "404s",
249 "text" => __("404s", "redirect-redirection")
250 ],
251 "selectedId" => 0,
252 ];
253 }
254
255 public function irrpDependencies() {
256 if (!defined('IRRP_ACTIVATION_REQUEST') && get_option('irrp_activation_redirect', false) == true) {
257 delete_option('irrp_activation_redirect');
258 wp_redirect(admin_url('admin.php?page=irrp-redirection'));
259 exit;
260 }
261
262 $this->helper = new IRRPHelper($this->dbManager);
263 $this->settings = new IRRPSettings($this->dbManager, $this->helper);
264 $this->helperAjax = new IRRPHelperAjax($this->dbManager, $this->settings, $this->helper);
265 $this->exportImport = new IRRPExportImport($this->dbManager, $this->helper);
266
267 add_action("wpmu_new_blog", [&$this->dbManager, "onNewBlog"], 10, 6);
268 add_filter("wpmu_drop_tables", [&$this->dbManager, "onDeleteBlog"]);
269
270 $plugin = plugin_basename(__FILE__);
271 add_filter("plugin_action_links_$plugin", [&$this, "links"]);
272
273 add_action("activated_plugin", [&$this, "activated"]);
274 add_action("admin_post_ir_uninstall", [&$this, "uninstall"]);
275
276 // Add signature to frontend.
277 add_action("wp_head", [&$this, "MetaVersion"]);
278 }
279
280 function irrpSetIntervals($schedules) {
281 $schedules[IRRP_CRON_DELETE_LOGS_RECURRENCE_KEY] = [
282 "interval" => IRRP_CRON_DELETE_LOGS_RECURRENCE,
283 "display" => esc_html__("Every 15 minutes", "redirect-redirection")
284 ];
285 return $schedules;
286 }
287
288 public function activated($plugin) {
289 if ($plugin == plugin_basename(__FILE__)) {
290 exit(wp_redirect(admin_url("admin.php?page=" . self::PAGE_SETTINGS)));
291 }
292 }
293
294 public function adminNotices() {
295 $wpVersion = get_bloginfo("version");
296 $phpVersion = phpversion();
297 if (current_user_can("manage_options") || current_user_can("redirect_redirection_admin")) {
298 if (version_compare($wpVersion, $this->minimum_wp_version, "<")) {
299 echo "<div class='error' style='padding:10px;'>" . __("Required minimum version of WordPress is : ", "redirect-redirection") . $this->minimum_wp_version . "</div>";
300 }
301
302 if (version_compare($phpVersion, $this->minimum_php_version, "<")) {
303 echo "<div class='error' style='padding:10px;'>" . __("Required minimum version of PHP is : ", "redirect-redirection") . $this->minimum_php_version . "</div>";
304 }
305 }
306 }
307
308 public function links($links) {
309 $links[] = "<a href='" . esc_url_raw(admin_url("admin.php?page=" . self::PAGE_SETTINGS)) . "'>" . esc_html__("Manage", "redirect-redirection") . "</a>";
310 $links[] = "<a class='ir-confirm-uninstall' href='" . esc_url_raw(admin_url("admin-post.php?action=ir_uninstall&nonce=" . wp_create_nonce('redi_uninstall'))) . "'>" . esc_html__("Reset", "redirect-redirection") . "</a>";
311 return $links;
312 }
313
314 public function uninstall() {
315 if (current_user_can("manage_options") || current_user_can("redirect_redirection_admin")) {
316
317 if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'redi_uninstall')) {
318 return wp_send_json_error();
319 }
320
321 delete_option(self::OPTIONS_MAIN);
322 delete_site_option(self::OPTIONS_MAIN);
323
324 $this->dbManager->dropTables();
325
326 deactivate_plugins(IRRP_DIR_NAME . "/" . basename(__FILE__));
327
328 die(wp_redirect(admin_url("plugins.php")));
329
330 }
331 }
332
333 }
334
335 $irrPRedirection = IrrPRedirection::getInstance();
336 // $irrPRedirection->irrpInit();
337
338 // Review banner
339 if (!(class_exists('Inisev\Subs\Inisev_Review') || class_exists('Inisev_Review'))) require_once __DIR__ . '/modules/review/review.php';
340 $review_banner = new \Inisev\Subs\Inisev_Review(__FILE__, __DIR__, 'redirect-redirection', 'Redirection', 'https://bit.ly/3Pw8VrS', 'irrp-redirection');
341
342 if (!(class_exists('\Inisev\Subs\New_BB_Banner') || class_exists('Inisev\Subs\New_BB_Banner') || class_exists('New_BB_Banner'))) {
343 require_once __DIR__ . '/modules/new-bb-banner/misc.php';
344 new \Inisev\Subs\New_BB_Banner(__FILE__, __DIR__, 'redirect-redirection', 'Redirection', 'irrp-redirection');
345 }
346
347 }, 9);
348
349 /**
350 * Analyst module
351 */
352 require_once 'analyst/main.php';
353
354 analyst_init(array(
355 'client-id' => 'pn8rx3lm7r4wamge',
356 'client-secret' => '9ccc7bfaa97519a4ac96c0214994a90b2de4f3c8',
357 'base-dir' => __FILE__
358 ));
359