| 1 |
<?php |
| 2 |
|
| 3 |
if ( !class_exists( 'MeowCommon_Admin' ) ) { |
| 4 |
|
| 5 |
class MeowCommon_Admin { |
| 6 |
|
| 7 |
public static $loaded = false; |
| 8 |
public static $version = "4.0"; |
| 9 |
public static $admin_version = "4.0"; |
| 10 |
|
| 11 |
public $prefix; // prefix used for actions, filters (mfrh) |
| 12 |
public $mainfile; // plugin main file (media-file-renamer.php) |
| 13 |
public $domain; // domain used for translation (media-file-renamer) |
| 14 |
public $isPro = false; |
| 15 |
|
| 16 |
public static $logo = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxIiB2aWV3Qm94PSIwIDAgMTY1IDE2NSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8c3R5bGU+CiAgICAuc3Qye2ZpbGw6IzgwNDYyNX0uc3Qze2ZpbGw6I2ZkYTk2MH0KICA8L3N0eWxlPgogIDxwYXRoIGQ9Ik03MiA3YTc2IDc2IDAgMCAxIDg0IDkxQTc1IDc1IDAgMSAxIDcyIDd6IiBmaWxsPSIjNGE2YjhjIi8+CiAgPHBhdGggZD0iTTQ4IDQ4YzIgNSAyIDEwIDUgMTQgNSA4IDEzIDE3IDIyIDIwbDEtMTBjMS0yIDMtMyA1LTNoMTNjMiAwIDQgMSA1IDNsMyA5IDQtMTBjMi0zIDYtMiA5LTJoMTFjMyAyIDMgNSAzIDhsMiAzN2MwIDMtMSA3LTQgOGgtMTJjLTIgMC0zLTItNS00LTEgMS0yIDMtNCAzLTUgMS05IDEtMTMtMS0zIDItNSAyLTkgMnMtOSAxLTEwLTNjLTItNC0xLTggMC0xMi04LTMtMTUtNy0yMi0xMi03LTctMTUtMTQtMjAtMjMtMy00LTUtOC01LTEzIDEtNCAzLTEwIDYtMTMgNC0zIDEyLTIgMTUgMnoiIGZpbGw9IiMxMDEwMTAiLz4KICA8cGF0aCBjbGFzcz0ic3QyIiBkPSJNNDMgNTFsNCAxMS02IDVoLTZjLTMtNS0zLTExIDAtMTYgMi0yIDYtMyA4IDB6Ii8+CiAgPHBhdGggY2xhc3M9InN0MyIgZD0iTTQ3IDYybDMgNmMwIDMgMCA0LTIgNnMtNCAyLTcgMmwtNi05aDZsNi01eiIvPgogIDxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik01MCA2OGw4IDljLTMgMy01IDYtOSA4bC04LTljMyAwIDUgMCA3LTJzMy0zIDItNnoiLz4KICA8cGF0aCBkPSJNODIgNzRoMTJsNSAxOCAzIDExIDgtMjloMTNsMiA0MmgtOGwtMS0yLTEtMzEtMTAgMzItNyAxLTktMzMtMSAyOS0xIDRoLThsMy00MnoiIGZpbGw9IiNmZmYiLz4KICA8cGF0aCBjbGFzcz0ic3QzIiBkPSJNNTggNzdsNSA1Yy0xIDQtMiA4LTcgOGwtNy01YzQtMiA2LTUgOS04eiIvPgogIDxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik02MyA4Mmw5IDUtNiA5LTEwLTZjNSAwIDYtNCA3LTh6Ii8+CiAgPHBhdGggY2xhc3M9InN0MyIgZD0iTTcyIDg3bDMgMS0xIDExLTgtMyA2LTEweiIvPgo8L3N2Zz4K'; |
| 17 |
|
| 18 |
public function __construct( $prefix, $mainfile, $domain, $isPro = false, $disableReview = false, $freeOnly = false ) { |
| 19 |
|
| 20 |
if ( !MeowCommon_Admin::$loaded ) { |
| 21 |
if ( is_admin() ) { |
| 22 |
|
| 23 |
if ( MeowCommon_Helpers::is_asynchronous_request() ) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
// Check potential issues with this WordPress install, other plugins, etc. |
| 28 |
new MeowCommon_Issues( $prefix, $mainfile, $domain ); |
| 29 |
|
| 30 |
// Create the Meow Apps Menu |
| 31 |
add_action( 'admin_menu', array( $this, 'admin_menu_start' ) ); |
| 32 |
$page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null; |
| 33 |
if ( $page === 'meowapps-main-menu' ) { |
| 34 |
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 100000, 1 ); |
| 35 |
} |
| 36 |
} |
| 37 |
MeowCommon_Admin::$loaded = true; |
| 38 |
} |
| 39 |
|
| 40 |
// Variables for this plugin |
| 41 |
$this->prefix = $prefix; |
| 42 |
$this->mainfile = $mainfile; |
| 43 |
$this->domain = $domain; |
| 44 |
$this->isPro = $isPro; |
| 45 |
|
| 46 |
// If there is no mainfile, it's either a Pro only Plugin (with no Free version available) or a Theme. |
| 47 |
if ( is_admin() ) { |
| 48 |
$license = get_option( $this->prefix . '_license', "" ); |
| 49 |
if ( !empty( $license ) && !$this->isPro ) { |
| 50 |
add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) ); |
| 51 |
} |
| 52 |
if ( !$disableReview ) { |
| 53 |
new MeowCommon_Ratings( $prefix, $mainfile, $domain ); |
| 54 |
} |
| 55 |
new MeowCommon_News( $domain ); |
| 56 |
} |
| 57 |
add_filter( 'plugin_row_meta', array( $this, 'custom_plugin_row_meta' ), 10, 2 ); |
| 58 |
add_filter( 'edd_sl_api_request_verify_ssl', array( $this, 'request_verify_ssl' ), 10, 0 ); |
| 59 |
} |
| 60 |
|
| 61 |
function custom_plugin_row_meta( $links, $file ) { |
| 62 |
$path = pathinfo( $file ); |
| 63 |
$pathName = basename( $path['dirname'] ); |
| 64 |
$thisPath = pathinfo( $this->mainfile ); |
| 65 |
$thisPathName = basename( $thisPath['dirname'] ); |
| 66 |
$isActive = is_plugin_active( $file ); |
| 67 |
if ( !$isActive ) { |
| 68 |
return $links; |
| 69 |
} |
| 70 |
$isIssue = $this->isPro && !$this->is_registered(); |
| 71 |
if ( strpos( $pathName, $thisPathName ) !== false ) { |
| 72 |
$new_links = array( |
| 73 |
'settings' => |
| 74 |
sprintf( __( '<a href="admin.php?page=%s_settings">Settings</a>', $this->domain ), $this->prefix ), |
| 75 |
'license' => |
| 76 |
$this->is_registered() ? |
| 77 |
('<span style="color: #a75bd6;">' . __( 'Pro Version', $this->domain ) . '</span>') : |
| 78 |
( $isIssue ? (sprintf( '<span style="color: #ff3434;">' . __( 'License Issue', $this->domain ), $this->prefix ) . '</span>') : (sprintf( '<span>' . __( '<a target="_blank" href="https://meowapps.com">Get the <u>Pro Version</u></a>', $this->domain ), $this->prefix ) . '</span>') ), |
| 79 |
); |
| 80 |
$links = array_merge( $new_links, $links ); |
| 81 |
} |
| 82 |
return $links; |
| 83 |
} |
| 84 |
|
| 85 |
function request_verify_ssl() { |
| 86 |
return get_option( 'force_sslverify', false ); |
| 87 |
} |
| 88 |
|
| 89 |
function nice_name_from_file( $file ) { |
| 90 |
$info = pathinfo( $file ); |
| 91 |
if ( !empty( $info ) ) { |
| 92 |
if ( $info['filename'] == 'wplr-sync' ) { |
| 93 |
return "WP/LR Sync"; |
| 94 |
} |
| 95 |
$info['filename'] = str_replace( '-', ' ', $info['filename'] ); |
| 96 |
$file = ucwords( $info['filename'] ); |
| 97 |
} |
| 98 |
return $file; |
| 99 |
} |
| 100 |
|
| 101 |
function admin_notices_licensed_free() { |
| 102 |
if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) { |
| 103 |
delete_option( $this->prefix . '_pro_serial' ); |
| 104 |
delete_option( $this->prefix . '_license' ); |
| 105 |
return; |
| 106 |
} |
| 107 |
$html = '<div class="notice notice-error">'; |
| 108 |
$html .= sprintf( |
| 109 |
__( '<p>It looks like you are using the free version of the plugin (<b>%s</b>) but a license for the Pro version was also found. The Pro version might have been replaced by the Free version during an update (might be caused by a temporarily issue). If it is the case, <b>please download it again</b> from the <a target="_blank" href="https://meowapps.com">Meow Store</a>. If you wish to continue using the free version and clear this message, click on this button.', $this->domain ), |
| 110 |
$this->nice_name_from_file( $this->mainfile ) ); |
| 111 |
$html .= '<p> |
| 112 |
<form method="post" action=""> |
| 113 |
<input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"> |
| 114 |
<input type="submit" name="submit" id="submit" class="button" value="' |
| 115 |
. __( 'Remove the license', $this->domain ) . '"> |
| 116 |
</form> |
| 117 |
</p>'; |
| 118 |
$html .= '</div>'; |
| 119 |
wp_kses_post( $html ); |
| 120 |
} |
| 121 |
|
| 122 |
function admin_menu_start() { |
| 123 |
// Hide the admin if user doesn't like Meow much |
| 124 |
if ( get_option( 'meowapps_hide_meowapps', false ) ) { |
| 125 |
register_setting( 'general', 'meowapps_hide_meowapps' ); |
| 126 |
add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', array( $this, 'meowapps_hide_dashboard_callback' ), 'general' ); |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
// Create standard menu if it does not already exist |
| 131 |
global $submenu; |
| 132 |
if ( !isset( $submenu[ 'meowapps-main-menu' ] ) ) { |
| 133 |
add_menu_page( 'Meow Apps', '<img alt="Meow Apps" style="width: 24px; margin-left: -30px; position: absolute; margin-top: -3px;" src="' . MeowCommon_Admin::$logo . '" />Meow Apps', 'manage_options', 'meowapps-main-menu', |
| 134 |
array( $this, 'admin_meow_apps' ), '', 82 ); |
| 135 |
add_submenu_page( 'meowapps-main-menu', __( 'Dashboard', $this->domain ), |
| 136 |
__( 'Dashboard', $this->domain ), 'manage_options', |
| 137 |
'meowapps-main-menu', array( $this, 'admin_meow_apps' ) ); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
function meowapps_hide_dashboard_callback() { |
| 142 |
$html = '<input type="checkbox" id="meowapps_hide_meowapps" name="meowapps_hide_meowapps" value="1" ' . |
| 143 |
checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; |
| 144 |
$html .= __( '<label>Hide <b>Meow Apps</b> Menu</label><br /><small>Hide Meow Apps menu and all its components, for a cleaner admin. This option will be reset if a new Meow Apps plugin is installed.<br /><b>Once activated, an option will be added in your General settings to display it again.</b></small>', $this->domain ); |
| 145 |
echo MeowCommon_Helpers::wp_kses( $html ); |
| 146 |
} |
| 147 |
|
| 148 |
function is_registered() { |
| 149 |
$is_registered = apply_filters( $this->prefix . '_meowapps_is_registered', false, $this->prefix ); |
| 150 |
return $is_registered; |
| 151 |
} |
| 152 |
|
| 153 |
function get_phpinfo() { |
| 154 |
if ( !current_user_can( 'administrator' ) || !function_exists( 'phpinfo' ) ) { |
| 155 |
return; |
| 156 |
} |
| 157 |
ob_start(); |
| 158 |
// phpcs:disable WordPress.PHP.DevelopmentFunctions |
| 159 |
phpinfo( INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES ); |
| 160 |
// phpcs:enable |
| 161 |
$html = ob_get_contents(); |
| 162 |
ob_end_clean(); |
| 163 |
$html = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $html ); |
| 164 |
return $html; |
| 165 |
} |
| 166 |
|
| 167 |
function admin_meow_apps() { |
| 168 |
$html = "<div id='meow-common-dashboard'></div>"; |
| 169 |
$html .= "<div style='height: 0; width: 0; overflow: hidden;' id='meow-common-phpinfo'>"; |
| 170 |
$html .= $this->get_phpinfo(); |
| 171 |
$html .= "</div>"; |
| 172 |
$html = preg_replace("/<img[^>]+\>/i", "", $html); |
| 173 |
echo wp_kses_post( $html ); |
| 174 |
} |
| 175 |
|
| 176 |
function admin_footer_text( $current ) { |
| 177 |
return sprintf( |
| 178 |
// translators: %1$s is the version of the interface; %2$s is a file path. |
| 179 |
__( 'Thanks for using <a href="https://meowapps.com">Meow Apps</a>! This is the Meow Admin %1$s <br /><i>Loaded from %2$s </i>', $this->domain ), |
| 180 |
MeowCommon_Admin::$version, |
| 181 |
__FILE__ |
| 182 |
); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|