Website : phonehp.ir
backdoor
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Home
Console
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
nehpir
/
www
/
wp-content
/
plugins
/
woocommersa
/
includes
/
Core
/
SEO
/
Filename :
RedirectManager.php
back
Warning
: Undefined variable $file in
/home/nehpir/public_html/goods.php
on line
545
Copy
<?php namespace WooCommersa\Core\SEO; if (!defined('ABSPATH')) exit; class RedirectManager { private $table_name; private $cache_key = 'woocommersa_redirects_cache'; public function __construct() { global $wpdb; $this->table_name = $wpdb->prefix . 'woocommersa_redirects'; // Hooks for automatic redirect detection add_action('post_updated', [$this, 'detect_slug_change'], 10, 3); add_action('template_redirect', [$this, 'handle_redirects'], 1); } public function create_table() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $this->table_name ( id bigint(20) NOT NULL AUTO_INCREMENT, old_url varchar(255) NOT NULL, new_url varchar(255) NOT NULL, type int(3) NOT NULL DEFAULT 301, status varchar(20) NOT NULL DEFAULT 'active', hits int(11) NOT NULL DEFAULT 0, created_at datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY old_url (old_url) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } public function add($old_url, $new_url, $type = 301, $status = 'active') { global $wpdb; $old_path = $this->normalize_url($old_url); $new_path = $this->normalize_url($new_url); if ($old_path === $new_path || empty($old_path)) return false; // Prevent loops if ($this->check_loop($old_path, $new_path)) return false; $result = $wpdb->replace( $this->table_name, [ 'old_url' => $old_path, 'new_url' => $new_path, 'type' => (int)$type, 'status' => $status ] ); if ($result !== false) { $this->refresh_cache(); } return $result; } public function update($id, $data) { global $wpdb; $result = $wpdb->update($this->table_name, $data, ['id' => $id]); if ($result !== false) { $this->refresh_cache(); } return $result; } public function delete($id) { global $wpdb; $result = $wpdb->delete($this->table_name, ['id' => $id], ['%d']); if ($result) $this->refresh_cache(); return $result; } public function remove_by_path($path) { global $wpdb; $normalized = $this->normalize_url($path); $result = $wpdb->delete($this->table_name, ['old_url' => $normalized], ['%s']); if ($result) $this->refresh_cache(); return $result; } public function refresh_cache() { global $wpdb; $redirects = $wpdb->get_results("SELECT old_url, new_url, type FROM $this->table_name WHERE status = 'active'", ARRAY_A); $cache = []; foreach ($redirects as $r) { $cache[$r['old_url']] = [ 'url' => $r['new_url'], 'type' => (int)$r['type'] ]; } update_option($this->cache_key, $cache, 'no'); } public function detect_slug_change($post_id, $post_after, $post_before) { if ($post_before->post_name !== $post_after->post_name && $post_after->post_type === 'product') { $old_link = get_permalink($post_before); // This might still return new slug in some WP versions $new_link = get_permalink($post_after); // Safer way: build paths manually if permalink structures vary $old_path = parse_url($old_link, PHP_URL_PATH); $new_path = parse_url($new_link, PHP_URL_PATH); $this->add($old_path, $new_path); } } public function handle_redirects() { if (is_admin()) return; $current_url = $this->normalize_url($_SERVER['REQUEST_URI']); if (empty($current_url)) return; $cache = get_option($this->cache_key, []); if (isset($cache[$current_url])) { $redirect = $cache[$current_url]; // Increment hits add_action('shutdown', function() use ($current_url) { global $wpdb; $wpdb->query($wpdb->prepare( "UPDATE $this->table_name SET hits = hits + 1 WHERE old_url = %s", $current_url )); }); $target = $redirect['url']; if (!preg_match('~^(?:f|ht)tps?://~i', $target)) { $target = home_url($target); } wp_redirect($target, $redirect['type']); exit; } } private function normalize_url($url) { if (empty($url)) return ''; $path = parse_url($url, PHP_URL_PATH); if (!$path) $path = $url; // Remove site path if installed in subdirectory $site_path = parse_url(home_url(), PHP_URL_PATH); if ($site_path && $site_path !== '/' && strpos($path, $site_path) === 0) { $path = substr($path, strlen($site_path)); } return trim($path, '/'); } private function check_loop($old_url, $new_url, $depth = 0) { if ($depth > 5) return true; if ($old_url === $new_url) return true; global $wpdb; $next = $wpdb->get_var($wpdb->prepare( "SELECT new_url FROM $this->table_name WHERE old_url = %s", $new_url )); if ($next) return $this->check_loop($old_url, $next, $depth + 1); return false; } }