admin.php
394 lines
| 1 | <?php |
| 2 | |
| 3 | if ( !class_exists( 'MeowApps_Admin' ) ) { |
| 4 | |
| 5 | class MeowApps_Admin { |
| 6 | |
| 7 | public static $loaded = false; |
| 8 | public static $admin_version = "1.4"; |
| 9 | |
| 10 | public $prefix; // prefix used for actions, filters (mfrh) |
| 11 | public $mainfile; // plugin main file (media-file-renamer.php) |
| 12 | public $domain; // domain used for translation (media-file-renamer) |
| 13 | |
| 14 | public function __construct( $prefix, $mainfile, $domain ) { |
| 15 | |
| 16 | // Core Admin (used by all Meow Apps plugins) |
| 17 | if ( !MeowApps_Admin::$loaded ) { |
| 18 | if ( is_admin() ) { |
| 19 | add_action( 'admin_menu', array( $this, 'admin_menu_start' ) ); |
| 20 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 21 | add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
| 22 | } |
| 23 | MeowApps_Admin::$loaded = true; |
| 24 | } |
| 25 | |
| 26 | // Variables for this plugin |
| 27 | $this->prefix = $prefix; |
| 28 | $this->mainfile = $mainfile; |
| 29 | $this->domain = $domain; |
| 30 | |
| 31 | register_activation_hook( $mainfile, array( $this, 'show_meowapps_create_rating_date' ) ); |
| 32 | |
| 33 | if ( is_admin() ) { |
| 34 | $license = get_option( $this->prefix . '_license', "" ); |
| 35 | if ( ( !empty( $license ) ) && !file_exists( plugin_dir_path( $this->mainfile ) . 'common/meowapps/admin.php' ) ) { |
| 36 | add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) ); |
| 37 | } |
| 38 | $rating_date = $this->create_rating_date(); |
| 39 | if ( time() > $rating_date ) { |
| 40 | add_action( 'admin_notices', array( $this, 'admin_notices_rating' ) ); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | function show_meowapps_create_rating_date() { |
| 46 | delete_option( 'meowapps_hide_meowapps' ); |
| 47 | $this->create_rating_date(); |
| 48 | } |
| 49 | |
| 50 | function create_rating_date() { |
| 51 | $rating_date = get_option( $this->prefix . '_rating_date' ); |
| 52 | if ( empty( $rating_date ) ) { |
| 53 | $two_months = strtotime( '+2 months' ); |
| 54 | $six_months = strtotime( '+6 months' ); |
| 55 | $rating_date = mt_rand( $two_months, $six_months ); |
| 56 | update_option( $this->prefix . '_rating_date', $rating_date, false ); |
| 57 | } |
| 58 | return $rating_date; |
| 59 | } |
| 60 | |
| 61 | function admin_notices_rating() { |
| 62 | if ( isset( $_POST[$this->prefix . '_remind_me'] ) ) { |
| 63 | $two_weeks = strtotime( '+2 weeks' ); |
| 64 | $six_weeks = strtotime( '+6 weeks' ); |
| 65 | $future_date = mt_rand( $two_weeks, $six_weeks ); |
| 66 | update_option( $this->prefix . '_rating_date', $future_date, false ); |
| 67 | return; |
| 68 | } |
| 69 | else if ( isset( $_POST[$this->prefix . '_never_remind_me'] ) ) { |
| 70 | $twenty_years = strtotime( '+20 years' ); |
| 71 | update_option( $this->prefix . '_rating_date', $twenty_years, false ); |
| 72 | return; |
| 73 | } |
| 74 | else if ( isset( $_POST[$this->prefix . '_did_it'] ) ) { |
| 75 | $twenty_years = strtotime( '+100 years' ); |
| 76 | update_option( $this->prefix . '_rating_date', $twenty_years, false ); |
| 77 | return; |
| 78 | } |
| 79 | $rating_date = get_option( $this->prefix . '_rating_date' ); |
| 80 | echo '<div class="notice notice-success" data-rating-date="' . $rating_date . '>'; |
| 81 | echo '<p style="font-size: 120%;">You have been using <b>' . $this->nice_name_from_file( $this->mainfile ) . '</b> for some time now. If you enjoy it, could you share your thoughts and give the developers a sweet spike of motivation? In that case, please: <a target="_blank" href="https://wordpress.org/support/plugin/' . $this->nice_short_url_from_file( $this->mainfile ) . '/reviews/?rate=5#new-post">review it</a>. Thank you :)'; |
| 82 | echo '<p> |
| 83 | <form method="post" action="" style="float: right;"> |
| 84 | <input type="hidden" name="' . $this->prefix . '_never_remind_me" value="true"> |
| 85 | <input type="submit" name="submit" id="submit" class="button button-red" value="Never remind me!"> |
| 86 | </form> |
| 87 | <form method="post" action="" style="float: right; margin-right: 10px;"> |
| 88 | <input type="hidden" name="' . $this->prefix . '_remind_me" value="true"> |
| 89 | <input type="submit" name="submit" id="submit" class="button button-primary" value="Remind me in a few weeks..."> |
| 90 | </form> |
| 91 | <form method="post" action="" style="float: right; margin-right: 10px;"> |
| 92 | <input type="hidden" name="' . $this->prefix . '_did_it" value="true"> |
| 93 | <input type="submit" name="submit" id="submit" class="button button-primary" value="Yes, I did it!"> |
| 94 | </form> |
| 95 | <div style="clear: both;"></div> |
| 96 | </p> |
| 97 | '; |
| 98 | echo '</div>'; |
| 99 | } |
| 100 | |
| 101 | function nice_short_url_from_file( $file ) { |
| 102 | $info = pathinfo( $file ); |
| 103 | if ( !empty( $info ) ) { |
| 104 | $info['filename'] = str_replace( '-pro', '', $info['filename'] ); |
| 105 | return $info['filename']; |
| 106 | } |
| 107 | return ""; |
| 108 | } |
| 109 | |
| 110 | function nice_name_from_file( $file ) { |
| 111 | $info = pathinfo( $file ); |
| 112 | if ( !empty( $info ) ) { |
| 113 | if ( $info['filename'] == 'wplr-sync' ) { |
| 114 | return "WP/LR Sync"; |
| 115 | } |
| 116 | $info['filename'] = str_replace( '-', ' ', $info['filename'] ); |
| 117 | $file = ucwords( $info['filename'] ); |
| 118 | } |
| 119 | return $file; |
| 120 | } |
| 121 | |
| 122 | function admin_notices_licensed_free() { |
| 123 | if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) { |
| 124 | delete_option( $this->prefix . '_pro_serial' ); |
| 125 | delete_option( $this->prefix . '_license' ); |
| 126 | return; |
| 127 | } |
| 128 | echo '<div class="error">'; |
| 129 | echo '<p>It looks like you are using the free version of the plugin (<b>' . $this->nice_name_from_file( $this->mainfile ) . '</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://store.meowapps.com">Meow Store</a>. If you wish to continue using the free version and clear this message, click on this button.'; |
| 130 | echo '<p> |
| 131 | <form method="post" action=""> |
| 132 | <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"> |
| 133 | <input type="submit" name="submit" id="submit" class="button" value="Remove the license"> |
| 134 | </form> |
| 135 | </p> |
| 136 | '; |
| 137 | echo '</div>'; |
| 138 | } |
| 139 | |
| 140 | function display_ads() { |
| 141 | return !get_option( 'meowapps_hide_ads', false ); |
| 142 | } |
| 143 | |
| 144 | function display_title( $title = "Meow Apps", |
| 145 | $author = "By <a style='text-decoration: none;' href='https://meowapps.com' target='_blank'>Jordy Meow</a>" ) { |
| 146 | if ( !empty( $this->prefix ) ) |
| 147 | $title = apply_filters( $this->prefix . '_plugin_title', $title ); |
| 148 | if ( $this->display_ads() ) { |
| 149 | echo '<a class="meow-header-ad" target="_blank" href="http://www.shareasale.com/r.cfm?b=906810&u=767054&m=41388&urllink=&afftrack=""> |
| 150 | <img src="' . $this->common_url( 'img/wpengine.png' ) . '" height="60" border="0" /></a>'; |
| 151 | } |
| 152 | ?> |
| 153 | <h1 style="line-height: 16px;"> |
| 154 | <img width="36" style="margin-right: 10px; float: left; position: relative; top: -5px;" |
| 155 | src="<?php echo $this->meowapps_logo_url(); ?>"><?php echo $title; ?><br /> |
| 156 | <span style="font-size: 12px"><?php echo $author; ?></span> |
| 157 | </h1> |
| 158 | <div style="clear: both;"></div> |
| 159 | <?php |
| 160 | } |
| 161 | |
| 162 | function admin_enqueue_scripts() { |
| 163 | wp_register_style( 'meowapps-core-css', $this->common_url( 'admin.css' ) ); |
| 164 | wp_enqueue_style( 'meowapps-core-css' ); |
| 165 | } |
| 166 | |
| 167 | function admin_menu_start() { |
| 168 | if ( get_option( 'meowapps_hide_meowapps', false ) ) { |
| 169 | register_setting( 'general', 'meowapps_hide_meowapps' ); |
| 170 | add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', array( $this, 'meowapps_hide_dashboard_callback' ), 'general' ); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | // Creates standard menu if it does NOT exist |
| 175 | global $submenu; |
| 176 | if ( !isset( $submenu[ 'meowapps-main-menu' ] ) ) { |
| 177 | add_menu_page( 'Meow Apps', 'Meow Apps', 'manage_options', 'meowapps-main-menu', |
| 178 | array( $this, 'admin_meow_apps' ), 'dashicons-camera', 82 ); |
| 179 | add_submenu_page( 'meowapps-main-menu', __( 'Dashboard', 'meowapps' ), |
| 180 | __( 'Dashboard', 'meowapps' ), 'manage_options', |
| 181 | 'meowapps-main-menu', array( $this, 'admin_meow_apps' ) ); |
| 182 | } |
| 183 | |
| 184 | add_settings_section( 'meowapps_common_settings', null, null, 'meowapps_common_settings-menu' ); |
| 185 | add_settings_field( 'meowapps_hide_meowapps', "Main Menu", |
| 186 | array( $this, 'meowapps_hide_dashboard_callback' ), |
| 187 | 'meowapps_common_settings-menu', 'meowapps_common_settings' ); |
| 188 | add_settings_field( 'meowapps_hide_ads', "Ads", |
| 189 | array( $this, 'meowapps_hide_ads_callback' ), |
| 190 | 'meowapps_common_settings-menu', 'meowapps_common_settings' ); |
| 191 | register_setting( 'meowapps_common_settings', 'meowapps_hide_meowapps' ); |
| 192 | register_setting( 'meowapps_common_settings', 'meowapps_hide_ads' ); |
| 193 | } |
| 194 | |
| 195 | function meowapps_hide_ads_callback() { |
| 196 | $value = get_option( 'meowapps_hide_ads', null ); |
| 197 | $html = '<input type="checkbox" id="meowapps_hide_ads" name="meowapps_hide_ads" value="1" ' . |
| 198 | checked( 1, get_option( 'meowapps_hide_ads' ), false ) . '/>'; |
| 199 | $html .= __( '<label>Hide</label><br /><small>Doesn\'t display the ads.</small>', 'wp-retina-2x' ); |
| 200 | echo $html; |
| 201 | } |
| 202 | |
| 203 | function meowapps_hide_dashboard_callback() { |
| 204 | $value = get_option( 'meowapps_hide_meowapps', null ); |
| 205 | $html = '<input type="checkbox" id="meowapps_hide_meowapps" name="meowapps_hide_meowapps" value="1" ' . |
| 206 | checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; |
| 207 | $html .= __( '<label>Hide <b>Meow Apps</b> Menu</label><br /><small>Hide Meow Apps menu and all its components, for a nicer an faster WordPress admin UI. An option will be added in Settings > General to display it again.</small>', 'wp-retina-2x' ); |
| 208 | echo $html; |
| 209 | } |
| 210 | |
| 211 | function display_serialkey_box( $url = "https://meowapps.com/" ) { |
| 212 | $html = '<div class="meow-box">'; |
| 213 | $html .= '<h3 class="' . ( $this->is_registered( $this->prefix ) ? 'meow-bk-blue' : 'meow-bk-red' ) . '">Pro Version ' . |
| 214 | ( $this->is_registered( $this->prefix ) ? '(enabled)' : '(disabled)' ) . '</h3>'; |
| 215 | $html .= '<div class="inside">'; |
| 216 | echo $html; |
| 217 | $html = apply_filters( $this->prefix . '_meowapps_license_input', ( 'More information about the Pro version here: |
| 218 | <a target="_blank" href="' . $url . '">' . $url . '</a>. If you actually bought the Pro version already, please remove the current plugin and download the Pro version from your account at the <a target="_blank" href="https://store.meowapps.com/account/downloads/">Meow Apps Store</a>.' ), $url ); |
| 219 | $html .= '</div>'; |
| 220 | $html .= '</div>'; |
| 221 | echo $html; |
| 222 | } |
| 223 | |
| 224 | function is_registered() { |
| 225 | return apply_filters( $this->prefix . '_meowapps_is_registered', false, $this->prefix ); |
| 226 | } |
| 227 | |
| 228 | function check_install( $plugin ) { |
| 229 | $pro = false; |
| 230 | $pluginpath = get_home_path() . 'wp-content/plugins/' . $plugin . '-pro'; |
| 231 | if ( !file_exists( $pluginpath ) ) { |
| 232 | $pluginpath = get_home_path() . 'wp-content/plugins/' . $plugin; |
| 233 | if ( !file_exists( $pluginpath ) ) { |
| 234 | $url = wp_nonce_url( "update.php?action=install-plugin&plugin=$plugin", "install-plugin_$plugin" ); |
| 235 | return "<a href='$url'><small><span class='' style='float: right;'>install</span></small></a>"; |
| 236 | } |
| 237 | } |
| 238 | else { |
| 239 | $pro = true; |
| 240 | $plugin = $plugin . "-pro"; |
| 241 | } |
| 242 | |
| 243 | $plugin_file = $plugin . '/' . $plugin . '.php'; |
| 244 | if ( is_plugin_active( $plugin_file ) ) { |
| 245 | if ( $plugin == 'wplr-sync' ) |
| 246 | $pro = true; |
| 247 | if ( $pro ) |
| 248 | return "<small><span style='float: right;'><span class='dashicons dashicons-heart' style='color: rgba(255, 63, 0, 1); font-size: 30px !important; margin-right: 10px;'></span></span></small>"; |
| 249 | else |
| 250 | return "<small><span style='float: right;'><span class='dashicons dashicons-yes' style='color: #00b4ff; font-size: 30px !important; margin-right: 10px;'></span></span></small>"; |
| 251 | } |
| 252 | else { |
| 253 | $url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin_file ), |
| 254 | 'activate-plugin_' . $plugin_file ); |
| 255 | return '<small><span style="color: black; float: right;">off |
| 256 | (<a style="color: rgba(30,140,190,1); text-decoration: none;" href="' . |
| 257 | $url . '">enable</a>)</span></small>'; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | function common_url( $file ) { |
| 262 | die( "Meow Apps: The function common_url( \$file ) needs to be overriden." ); |
| 263 | // Normally, this should be used: |
| 264 | // return plugin_dir_url( __FILE__ ) . ( '\/common\/' . $file ); |
| 265 | } |
| 266 | |
| 267 | function meowapps_logo_url() { |
| 268 | return $this->common_url( 'img/meowapps.png' ); |
| 269 | } |
| 270 | |
| 271 | function plugins_loaded() { |
| 272 | if ( isset( $_GET[ 'tool' ] ) && $_GET[ 'tool' ] == 'error_log' ) { |
| 273 | $sec = "5"; |
| 274 | header("Refresh: $sec;"); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | function admin_meow_apps() { |
| 279 | |
| 280 | echo '<div class="wrap meow-dashboard">'; |
| 281 | if ( isset( $_GET['tool'] ) && $_GET['tool'] == 'phpinfo' ) { |
| 282 | echo "<a href=\"javascript:history.go(-1)\">< Go back</a><br /><br />"; |
| 283 | echo '<div id="phpinfo">'; |
| 284 | ob_start(); |
| 285 | phpinfo(); |
| 286 | $pinfo = ob_get_contents(); |
| 287 | ob_end_clean(); |
| 288 | $pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $pinfo ); |
| 289 | echo $pinfo; |
| 290 | echo "</div>"; |
| 291 | } |
| 292 | else if ( isset( $_GET['tool'] ) && $_GET['tool'] == 'error_log' ) { |
| 293 | $errorpath = ini_get( 'error_log' ); |
| 294 | echo "<a href=\"javascript:history.go(-1)\">< Go back</a><br /><br />"; |
| 295 | echo '<div id="error_log">'; |
| 296 | if ( file_exists( $errorpath ) ) { |
| 297 | echo "Now (auto-reload every 5 seconds):<br />[" . date( "d-M-Y H:i:s", time() ) . " UTC]<br /<br /><br />Errors (order by latest):"; |
| 298 | $errors = file_get_contents( $errorpath ); |
| 299 | $errors = explode( "\n", $errors ); |
| 300 | $errors = array_reverse( $errors ); |
| 301 | $errors = implode( "<br />", $errors ); |
| 302 | echo $errors; |
| 303 | } |
| 304 | else { |
| 305 | echo "The PHP Error Logs cannot be found. Please ask your hosting service for it."; |
| 306 | } |
| 307 | echo "</div>"; |
| 308 | |
| 309 | } |
| 310 | else { |
| 311 | |
| 312 | ?> |
| 313 | <?php $this->display_title(); ?> |
| 314 | <p> |
| 315 | <?php _e( 'Meow Apps is run by Jordy Meow, a photographer and software developer living in Japan (and taking <a target="_blank" href="http://offbeatjapan.org">a lot of photos</a>). Meow Apps is a suite of plugins focusing on photography, imaging, optimization and it teams up with the best players in the community (other themes and plugins developers). For more information, please check <a href="http://meowapps.com" target="_blank">Meow Apps</a>.', 'meowapps' ) |
| 316 | ?> |
| 317 | </p> |
| 318 | <div class="meow-row"> |
| 319 | <div class="meow-box meow-col meow-span_1_of_2 "> |
| 320 | <h3 class=""><span class="dashicons dashicons-camera"></span> UI Plugins </h3> |
| 321 | <ul class=""> |
| 322 | <li><b>WP/LR Sync</b> <?php echo $this->check_install( 'wplr-sync' ) ?><br /> |
| 323 | Synchronize photos (folders, collections, keywords) from Lightroom to WordPress.</li> |
| 324 | <li><b>Meow Lightbox</b> <?php echo $this->check_install( 'meow-lightbox' ) ?><br /> |
| 325 | Light but powerful lightbox that can also display photo information (EXIF).</li> |
| 326 | <li><b>Meow Gallery</b> <?php echo $this->check_install( 'meow-gallery' ) ?><br /> |
| 327 | Gallery (using the built-in WP gallery) that makes your website look better.</li> |
| 328 | <!-- <li><b>Audio Story for Images</b> <?php echo $this->check_install( 'audio-story-images' ) ?><br /> |
| 329 | Add audio (music, explanation, ambiance) to your images.</li> --> |
| 330 | </ul> |
| 331 | </div> |
| 332 | <div class="meow-box meow-col meow-span_1_of_2"> |
| 333 | <h3 class=""><span class="dashicons dashicons-admin-tools"></span> System Plugins</h3> |
| 334 | <ul class=""> |
| 335 | <li><b>Media File Renamer</b> <?php echo $this->check_install( 'media-file-renamer' ) ?><br /> |
| 336 | For nicer filenames and better SEO.</li> |
| 337 | <li><b>Media Cleaner</b> <?php echo $this->check_install( 'media-cleaner' ) ?><br /> |
| 338 | Detect the files which are not in use.</li> |
| 339 | <li><b>WP Retina 2x</b> <?php echo $this->check_install( 'wp-retina-2x' ) ?><br /> |
| 340 | The famous plugin that adds Retina support.</li> |
| 341 | </ul> |
| 342 | </div> |
| 343 | </div> |
| 344 | |
| 345 | <div class="meow-row"> |
| 346 | <div class="meow-box meow-col meow-span_2_of_3"> |
| 347 | <h3><span class="dashicons dashicons-admin-tools"></span> Common</h3> |
| 348 | <div class="inside"> |
| 349 | <form method="post" action="options.php"> |
| 350 | <?php settings_fields( 'meowapps_common_settings' ); ?> |
| 351 | <?php do_settings_sections( 'meowapps_common_settings-menu' ); ?> |
| 352 | <?php submit_button(); ?> |
| 353 | </form> |
| 354 | </div> |
| 355 | </div> |
| 356 | |
| 357 | <div class="meow-box meow-col meow-span_1_of_3"> |
| 358 | <h3><span class="dashicons dashicons-admin-tools"></span> Debug</h3> |
| 359 | <div class="inside"> |
| 360 | <ul> |
| 361 | <li><a href="?page=meowapps-main-menu&tool=error_log">Display Error Log</a></li> |
| 362 | <li><a href="?page=meowapps-main-menu&tool=phpinfo">Display PHP Info</a></li> |
| 363 | </ul> |
| 364 | </div> |
| 365 | </div> |
| 366 | </div> |
| 367 | |
| 368 | <?php |
| 369 | |
| 370 | } |
| 371 | |
| 372 | echo "<br /><small style='color: lightgray;'>Meow Admin " . MeowApps_Admin::$admin_version . "</small></div>"; |
| 373 | } |
| 374 | |
| 375 | // HELPERS |
| 376 | |
| 377 | static function size_shortname( $name ) { |
| 378 | $name = preg_split( '[_-]', $name ); |
| 379 | $short = strtoupper( substr( $name[0], 0, 1 ) ); |
| 380 | if ( count( $name ) > 1 ) |
| 381 | $short .= strtoupper( substr( $name[1], 0, 1 ) ); |
| 382 | return $short; |
| 383 | } |
| 384 | |
| 385 | } |
| 386 | |
| 387 | } |
| 388 | |
| 389 | if ( file_exists( plugin_dir_path( __FILE__ ) . '/meowapps/admin.php' ) ) { |
| 390 | require( 'meowapps/admin.php' ); |
| 391 | } |
| 392 | |
| 393 | ?> |
| 394 |