<?php
/*
Plugin Name: WP All Import - Link Cloaking Add-on
Plugin URI: http://www.wpallimport.com/
Description: Cloak all links present during import.
Version: 1.1.5
Author: Soflyy
*/
/**
* Plugin root dir with forward slashes as directory separator regardless of actuall DIRECTORY_SEPARATOR value
* @var string
*/
define('PMLCA_ROOT_DIR', str_replace('\\', '/', dirname(__FILE__)));
/**
* Plugin root url for referencing static content
* @var string
*/
define('PMLCA_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/'));
/**
* Plugin prefix for making names unique (be aware that this variable is used in conjuction with naming convention,
* i.e. in order to change it one must not only modify this constant but also rename all constants, classes and functions which
* names composed using this prefix)
* @var string
*/
define('PMLCA_PREFIX', 'pmlca_');
define('PMLCA_VERSION', '1.1.5');
/**
* Main plugin file, Introduces MVC pattern
*
* @singletone
* @author Maksym Tsypliakov <maksym.tsypliakov@gmail.com>
*/
final class WPAI_Link_Cloak {
/**
* Singletone instance
* @var WPAI_Link_Cloak
*/
protected static $instance;
/**
* Plugin root dir
* @var string
*/
const ROOT_DIR = PMLCA_ROOT_DIR;
/**
* Plugin root URL
* @var string
*/
const ROOT_URL = PMLCA_ROOT_URL;
/**
* Prefix used for names of shortcodes, action handlers, filter functions etc.
* @var string
*/
const PREFIX = PMLCA_PREFIX;
/**
* Plugin file path
* @var string
*/
const FILE = __FILE__;
public $input;
/**
* Return singletone instance
* @return PMLCA_Plugin
*/
static public function getInstance() {
if (self::$instance == NULL) {
self::$instance = new self();
}
return self::$instance;
}
function __construct(){
if (self::$instance == NULL) {
register_activation_hook(self::FILE, array($this, 'activation'));
// Register own wpallimport addon
add_filter('pmxi_addons', array( &$this, 'register_addon' ), 10, 1);
/*
* Function to render addon's view
*/
add_action('pmxi_extend_options_featured', array( &$this, 'view'), 10, 1);
add_action('admin_notices', array( &$this, 'admin_notices'));
add_action('wp_loaded', array( &$this, 'wp_loaded'));
add_filter('pmxi_the_content', array( &$this, 'pmxi_the_content'), 10, 2);
add_filter('pmxi_the_excerpt', array( &$this, 'pmxi_the_content'), 10, 2);
add_filter('pmxi_custom_field', array( &$this, 'pmxi_custom_field'), 10, 6);
add_filter('pmwi_cloak_affiliate_url', array( &$this, 'pmwi_cloak_affiliate_url'), 10, 2);
add_filter('pmxi_save_options', array( &$this, 'pmwi_pmxi_save_options'), 10, 1);
add_action('init', array(&$this, 'init'));
}
}
public function init(){
$this->load_plugin_textdomain();
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present
*
* @access public
* @return void
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'wp_all_import_link_cloaking_add_on' );
load_plugin_textdomain( 'wp_all_import_link_cloaking_add_on', false, dirname( plugin_basename( __FILE__ ) ) . "/i18n/languages" );
}
public function wp_loaded(){
$url = strpos($_SERVER['REQUEST_URI'], "?") ? strtok($_SERVER['REQUEST_URI'], '?') : $_SERVER['REQUEST_URI'];
// detect if cloaked link is requested and execute redirect.php if so
if ( ! is_admin() and (preg_match('%^' . preg_quote($this->site_url_no_domain(""), '%') . '/([\w-]+)(/([^/?]+))?/?($|\?)%', $url, $mtch) or preg_match('%^' . preg_quote($this->site_url_no_domain(), '%') . '/?\?(.*?&)?cloaked=([\w-]+)(&|$)%', $url, $mtch_alt) or preg_match('%^' . preg_quote($this->site_url_no_domain(), '%') . '/?\?(.*?&)?link=([\w-]+)(&|$)%', $url, $mtch_alt))) {
if ($mtch) {
$slug = $mtch[1];
$_GET['subid'] = $mtch[3];
} else {
$slug = $mtch_alt[2];
}
$table_prefix = self::getInstance()->getTablePrefix();
global $wpdb;
$link = $wpdb->get_row("SELECT * FROM {$table_prefix}links WHERE slug = '$slug'", ARRAY_A);
if ( empty($link) && !empty($mtch[0])){
$siteurl = site_url();
$siteurl_parsed = parse_url($siteurl);
if (!empty($siteurl_parsed['path']) && $siteurl_parsed['path'] != "/") {
$mtch[0] = str_replace($siteurl_parsed['path'], '', $mtch[0]);
}
$slug = ltrim($mtch[0], "/");
$link = $wpdb->get_row("SELECT * FROM {$table_prefix}links WHERE slug = '$slug'", ARRAY_A);
}
if ( $link != null ){
$http_response_code = apply_filters('wpai_link_cloak_http_response_code', 301, $link);
wp_redirect($link['afflink'], $http_response_code);
die();
}
}
}
/**
* Same as site_url() but return path without domain name
* @return string
*/
function site_url_no_domain($path = '') {
return preg_replace('%^https?://[^/]*%', '', site_url($path, 'http'));
}
/**
* Check whether plugin is activated as network one
* @return bool
*/
public function isNetwork() {
if ( !is_multisite() )
return false;
$plugins = get_site_option('active_sitewide_plugins');
if (isset($plugins[plugin_basename(self::FILE)]))
return true;
return false;
}
/**
* Return prefix for plugin database tables
* @return string
*/
public function getTablePrefix() {
global $wpdb;
return ($this->isNetwork() ? $wpdb->base_prefix : $wpdb->prefix) . self::PREFIX;
}
/**
* Plugin activation logic
*/
public function activation(){
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
require self::ROOT_DIR . '/schema.php';
global $wpdb;
if (function_exists('is_multisite') && is_multisite()) {
// check if it is a network activation - if so, run the activation function for each blog id
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
$old_blog = $wpdb->blogid;
// Get all blog ids
$blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blogids as $blog_id) {
switch_to_blog($blog_id);
require self::ROOT_DIR . '/schema.php';
dbDelta($plugin_queries);
}
switch_to_blog($old_blog);
return;
}
}
dbDelta($plugin_queries);
}
public function admin_notices(){
if ( ! class_exists( 'PMXI_Plugin' ) ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: WP All Import must be installed. Free edition of WP All Import at <a href="http://wordpress.org/plugins/wp-all-import/" target="_blank">http://wordpress.org/plugins/wp-all-import/</a> and the paid edition at <a href="http://www.wpallimport.com/">http://www.wpallimport.com/</a>', 'PMLI_Plugin'),
self::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( self::ROOT_DIR . '/wpai-linkcloak-add-on.php');
}
if ( class_exists( 'PMXI_Plugin' ) and ( version_compare(PMXI_VERSION, '4.1.7') < 0 and PMXI_EDITION == 'paid' or version_compare(PMXI_VERSION, '3.2.9') <= 0 and PMXI_EDITION == 'free') ) {
?>
<div class="error"><p>
<?php printf(
__('<b>%s Plugin</b>: Please update your WP All Import to the latest version', 'pmli_plugin'),
self::getInstance()->getName()
) ?>
</p></div>
<?php
deactivate_plugins( self::ROOT_DIR . '/wpai-linkcloak-add-on.php');
}
}
public static function getEddName(){
return 'Link Cloaking Add-On';
}
public function getName(){
return __('WP All Import - Link Cloaking Add-on', 'wp_all_import_link_cloaking_add_on');
}
public function register_addon( $addons ){
// link_cloaking_addon - own addon prefix (should be unique)
if ( empty($addons['WPAI_Link_Cloak']) ) $addons['WPAI_Link_Cloak'] = 1;
return $addons;
}
// define addon's options
public static function get_default_import_options(){
return array(
'pmlca_mode' => 'all',
'pmlca_prefix' => '',
'pmlca_old_prefix' => ''
);
【WordPress插件】2022年最新版完整功能demo+插件v1.1.5.zip
版权申诉
132 浏览量
2022-03-30
11:06:43
上传
评论
收藏 11KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/36a38b4e555749aca29de74acc8ba1db_tysonchiu.jpg!1)
Lee达森
- 粉丝: 969
- 资源: 1万+