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