PluginProbe ʕ •ᴥ•ʔ
Redirection / 1.1.5
Redirection v1.1.5
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 3 years ago assets 3 years ago includes 3 years ago activation.php 3 years ago deactivation.php 3 years ago index.html 3 years ago readme.txt 3 years ago redirect-redirection.php 3 years ago uninstall.php 3 years ago
redirect-redirection.php
332 lines
1 <?php
2
3 /*
4 * Plugin Name: Redirect Redirection
5 * Description: Create specific URL redirections and redirection rules super-easily on a beautiful, user-friendly interface of the Redirect Redirection plugin.
6 * Version: 1.1.5
7 * Author: Inisev
8 * Author URI: https://inisev.com
9 * Plugin URI: https://inisev.com/
10 * Text Domain: redirect-redirection
11 */
12
13 if (!defined("ABSPATH")) {
14 exit();
15 }
16
17 /**
18 * Plugin's constants
19 */
20 define("IRRP_DIR_PATH", dirname(__FILE__));
21 define("IRRP_DIR_NAME", basename(IRRP_DIR_PATH));
22 define("IRRP_CRON_DELETE_LOGS", "irrp_cron_delete_logs");
23 define("IRRP_CRON_DELETE_LOGS_RECURRENCE_KEY", "irrp_custom_interval");
24 define("IRRP_CRON_DELETE_LOGS_RECURRENCE", 60);
25 define("IRRP_PLUGIN_VERSION", "1.1.5");
26
27 /**
28 * Create tables on activation.
29 */
30 register_activation_hook(__FILE__, function () {
31
32 include_once IRRP_DIR_PATH . '/activation.php';
33 });
34
35 /**
36 * Disable CRON job on deactivation
37 */
38 register_deactivation_hook(__FILE__, function () {
39
40 include_once IRRP_DIR_PATH . '/deactivation.php';
41 });
42
43 /**
44 * Load the plugin
45 */
46 add_action('plugins_loaded', function () {
47
48 // Include our cool banner
49 include_once "includes/banner/misc.php";
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" => "have-permalink-structure",
137 "text" => __("Have permalink structure", "redirect-redirection"),
138 ],
139 [
140 "option" => "regex-match",
141 "text" => __("Regex matches", "redirect-redirection"),
142 ],
143 [
144 "option" => "are-404s",
145 "text" => __("Are 404s", "redirect-redirection"),
146 "status" => $option404Status,
147 ],
148 [
149 "option" => "all-urls",
150 "text" => __("All URLs", "redirect-redirection"),
151 "status" => $optionAllUrlsStatus,
152 ],
153 ];
154
155 self::$PERMALINK_STRUCTURE_VALUES = [
156 [
157 "option" => "day-and-name",
158 "text" => __("Day and name", "redirect-redirection")
159 ],
160 [
161 "option" => "month-and-name",
162 "text" => __("Month and name", "redirect-redirection")
163 ],
164 [
165 "option" => "post-name",
166 "text" => __("Post name", "redirect-redirection")
167 ],
168 [
169 "option" => "category-and-name",
170 "text" => __("Category and name", "redirect-redirection")
171 ],
172 [
173 "option" => "author-and-name",
174 "text" => __("Author and name", "redirect-redirection")
175 ],
176 ];
177
178 self::$ACTIONS = [
179 [
180 "option" => "a-specific-url",
181 "text" => __("A Specific URL", "redirect-redirection")
182 ],
183 [
184 "option" => "urls-with-new-string",
185 "text" => __("URLs with new string", "redirect-redirection")
186 ],
187 [
188 "option" => "urls-with-removed-string",
189 "text" => __("URLs with removed string", "redirect-redirection")
190 ],
191 [
192 "option" => "new-permalink-structure",
193 "text" => __("New permalink structure", "redirect-redirection")
194 ],
195 [
196 "option" => "regex-match",
197 "text" => __("Regex matches", "redirect-redirection")
198 ],
199 [
200 "option" => "random-similar-post",
201 "text" => __("Random similar post", "redirect-redirection")
202 ],
203 [
204 "option" => "explain-those-options",
205 "text" => __("Explain those options", "redirect-redirection")
206 ],
207 ];
208
209 self::$REDIRECTION_LOGS_DELETE = [
210 [
211 "option" => "never",
212 "text" => __("Never", "redirect-redirection"),
213 ],
214 [
215 "option" => "older-than-a-week",
216 "text" => __("Older than a week", "redirect-redirection")
217 ],
218 [
219 "option" => "older-than-a-month",
220 "text" => __("Older than a month", "redirect-redirection")
221 ],
222 "selectedId" => 0,
223 ];
224
225 self::$REDIRECTION_LOGS_FILTER = [
226 [
227 "option" => "all",
228 "text" => __("All", "redirect-redirection"),
229 ],
230 [
231 "option" => "404s",
232 "text" => __("404s", "redirect-redirection")
233 ],
234 "selectedId" => 0,
235 ];
236 }
237
238 public function irrpDependencies() {
239 if (!defined('IRRP_ACTIVATION_REQUEST') && get_option('irrp_activation_redirect', false) == true) {
240 delete_option('irrp_activation_redirect');
241 wp_redirect(admin_url('admin.php?page=irrp-redirection'));
242 exit;
243 }
244
245 $this->helper = new IRRPHelper($this->dbManager);
246 $this->settings = new IRRPSettings($this->dbManager, $this->helper);
247 $this->helperAjax = new IRRPHelperAjax($this->dbManager, $this->settings, $this->helper);
248 $this->exportImport = new IRRPExportImport($this->dbManager, $this->helper);
249
250 add_action("wpmu_new_blog", [&$this->dbManager, "onNewBlog"], 10, 6);
251 add_filter("wpmu_drop_tables", [&$this->dbManager, "onDeleteBlog"]);
252
253 $plugin = plugin_basename(__FILE__);
254 add_filter("plugin_action_links_$plugin", [&$this, "links"]);
255
256 add_action("activated_plugin", [&$this, "activated"]);
257 add_action("admin_post_ir_uninstall", [&$this, "uninstall"]);
258
259 // Add signature to frontend.
260 add_action("wp_head", [&$this, "MetaVersion"]);
261 }
262
263 function irrpSetIntervals($schedules) {
264 $schedules[IRRP_CRON_DELETE_LOGS_RECURRENCE_KEY] = [
265 "interval" => IRRP_CRON_DELETE_LOGS_RECURRENCE,
266 "display" => esc_html__("Every 15 minutes", "redirect-redirection")
267 ];
268 return $schedules;
269 }
270
271 public function activated($plugin) {
272 if ($plugin == plugin_basename(__FILE__)) {
273 exit(wp_redirect(admin_url("admin.php?page=" . self::PAGE_SETTINGS)));
274 }
275 }
276
277 public function adminNotices() {
278 $wpVersion = get_bloginfo("version");
279 $phpVersion = phpversion();
280 if (current_user_can("manage_options")) {
281 if (version_compare($wpVersion, $this->minimum_wp_version, "<")) {
282 echo "<div class='error' style='padding:10px;'>" . __("Required minimum version of WordPress is : ", "redirect-redirection") . $this->minimum_wp_version . "</div>";
283 }
284
285 if (version_compare($phpVersion, $this->minimum_php_version, "<")) {
286 echo "<div class='error' style='padding:10px;'>" . __("Required minimum version of PHP is : ", "redirect-redirection") . $this->minimum_php_version . "</div>";
287 }
288 }
289 }
290
291 public function links($links) {
292 $links[] = "<a href='" . esc_url_raw(admin_url("admin.php?page=" . self::PAGE_SETTINGS)) . "'>" . esc_html__("Manage", "redirect-redirection") . "</a>";
293 $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>";
294 return $links;
295 }
296
297 public function uninstall() {
298 if (current_user_can("manage_options")) {
299
300 if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'redi_uninstall')) {
301 return wp_send_json_error();
302 }
303
304 delete_option(self::OPTIONS_MAIN);
305 delete_site_option(self::OPTIONS_MAIN);
306
307 $this->dbManager->dropTables();
308
309 deactivate_plugins(IRRP_DIR_NAME . "/" . basename(__FILE__));
310
311 die(wp_redirect(admin_url("plugins.php")));
312
313 }
314 }
315
316 }
317
318 $irrPRedirection = IrrPRedirection::getInstance();
319 $irrPRedirection->irrpInit();
320 }, 9);
321
322 /**
323 * Analyst module
324 */
325 require_once 'analyst/main.php';
326
327 analyst_init(array(
328 'client-id' => 'pn8rx3lm7r4wamge',
329 'client-secret' => '9ccc7bfaa97519a4ac96c0214994a90b2de4f3c8',
330 'base-dir' => __FILE__
331 ));
332