| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ogp Plus |
| 4 |
* |
| 5 |
* @package Ogp Plus |
| 6 |
* @subpackage OgpPlusAdmin Management screen |
| 7 |
Copyright (c) 2019- Katsushi Kawamori (email : dodesyoswift312@gmail.com) |
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; version 2 of the License. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
$ogpplusadmin = new OgpPlusAdmin(); |
| 23 |
|
| 24 |
/** ================================================== |
| 25 |
* Management screen |
| 26 |
*/ |
| 27 |
class OgpPlusAdmin { |
| 28 |
|
| 29 |
/** ================================================== |
| 30 |
* Construct |
| 31 |
* |
| 32 |
* @since 1.00 |
| 33 |
*/ |
| 34 |
public function __construct() { |
| 35 |
|
| 36 |
add_action( 'admin_menu', array( $this, 'plugin_menu' ) ); |
| 37 |
add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_wp_admin_style' ) ); |
| 38 |
add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 ); |
| 39 |
} |
| 40 |
|
| 41 |
/** ================================================== |
| 42 |
* Add a "Settings" link to the plugins page |
| 43 |
* |
| 44 |
* @param array $links links array. |
| 45 |
* @param string $file file. |
| 46 |
* @return array $links links array. |
| 47 |
* @since 1.00 |
| 48 |
*/ |
| 49 |
public function settings_link( $links, $file ) { |
| 50 |
static $this_plugin; |
| 51 |
if ( empty( $this_plugin ) ) { |
| 52 |
$this_plugin = 'ogp-plus/ogpplus.php'; |
| 53 |
} |
| 54 |
if ( $file === $this_plugin ) { |
| 55 |
$links[] = '<a href="' . admin_url( 'options-general.php?page=ogpplus' ) . '">' . __( 'Settings' ) . '</a>'; |
| 56 |
} |
| 57 |
return $links; |
| 58 |
} |
| 59 |
|
| 60 |
/** ================================================== |
| 61 |
* Settings page |
| 62 |
* |
| 63 |
* @since 1.00 |
| 64 |
*/ |
| 65 |
public function plugin_menu() { |
| 66 |
add_options_page( 'Ogp Plus Options', 'Ogp Plus', 'manage_options', 'ogpplus', array( $this, 'plugin_options' ) ); |
| 67 |
} |
| 68 |
|
| 69 |
/** ================================================== |
| 70 |
* Add Css and Script |
| 71 |
* |
| 72 |
* @since 1.00 |
| 73 |
*/ |
| 74 |
public function load_custom_wp_admin_style() { |
| 75 |
if ( $this->is_my_plugin_screen() ) { |
| 76 |
wp_enqueue_script( 'jquery' ); |
| 77 |
wp_enqueue_script( 'ogpplus-admin-js', plugin_dir_url( __DIR__ ) . 'js/jquery.ogpplus.admin.js', array( 'jquery' ), '1.0.0', false ); |
| 78 |
wp_enqueue_media(); |
| 79 |
wp_localize_script( 'ogpplus-admin-js', 'ogpplus', array( 'button' => __( 'Choose Default OGP image', 'ogp-plus' ) ) ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/** ================================================== |
| 84 |
* For only admin style |
| 85 |
* |
| 86 |
* @since 1.00 |
| 87 |
*/ |
| 88 |
private function is_my_plugin_screen() { |
| 89 |
$screen = get_current_screen(); |
| 90 |
if ( is_object( $screen ) && 'settings_page_ogpplus' === $screen->id ) { |
| 91 |
return true; |
| 92 |
} else { |
| 93 |
return false; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
/** ================================================== |
| 98 |
* Settings page |
| 99 |
* |
| 100 |
* @since 1.00 |
| 101 |
*/ |
| 102 |
public function plugin_options() { |
| 103 |
|
| 104 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 105 |
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) ); |
| 106 |
} |
| 107 |
|
| 108 |
$this->options_updated(); |
| 109 |
|
| 110 |
$scriptname = admin_url( 'options-general.php?page=ogpplus' ); |
| 111 |
$ogpplus_settings = get_option( |
| 112 |
'ogpplus_settings', |
| 113 |
array( |
| 114 |
'excerpt' => 100, |
| 115 |
'df_img_id' => null, |
| 116 |
'og_img_size' => 'large', |
| 117 |
'tw_user_name' => null, |
| 118 |
'fb_app_id' => null, |
| 119 |
) |
| 120 |
); |
| 121 |
|
| 122 |
if ( ! empty( $ogpplus_settings['df_img_id'] ) ) { |
| 123 |
$thumb = wp_get_attachment_image_src( $ogpplus_settings['df_img_id'], $ogpplus_settings['og_img_size'] ); |
| 124 |
$ogp_img_url = $thumb[0]; |
| 125 |
} else { |
| 126 |
$ogp_img_url = null; |
| 127 |
} |
| 128 |
|
| 129 |
?> |
| 130 |
|
| 131 |
<div class="wrap"> |
| 132 |
<h2>Ogp Plus</h2> |
| 133 |
<div style="clear: both;"></div> |
| 134 |
|
| 135 |
<details> |
| 136 |
<summary><strong><?php esc_html_e( 'Various links of this plugin', 'ogp-plus' ); ?></strong></summary> |
| 137 |
<?php $this->credit(); ?> |
| 138 |
</details> |
| 139 |
|
| 140 |
<h3><?php esc_html_e( 'Settings' ); ?></h3> |
| 141 |
|
| 142 |
<form method="post" action="<?php echo esc_url( $scriptname ); ?>"> |
| 143 |
<?php wp_nonce_field( 'ogp_set', 'ogpplus_set' ); ?> |
| 144 |
|
| 145 |
<div style="display: block;padding:5px 5px"> |
| 146 |
<strong><?php esc_html_e( 'Description length', 'ogp-plus' ); ?>: </strong> |
| 147 |
<input type="range" id="excerpt_bar" style="vertical-align:middle;" step="1" min="0" max="120" name="excerpt" value="<?php echo esc_attr( $ogpplus_settings['excerpt'] ); ?>" /><span id="excerpt_range"></span> |
| 148 |
<p class="description"> |
| 149 |
<?php esc_html_e( 'Specify the length of each post and page excerpt display other than the homepage.', 'ogp-plus' ); ?> |
| 150 |
</p> |
| 151 |
</div> |
| 152 |
|
| 153 |
<div style="display: block;padding:5px 5px"> |
| 154 |
<div> |
| 155 |
<strong><?php esc_html_e( 'OGP image size', 'ogp-plus' ); ?> : </strong> |
| 156 |
<input type="radio" name="og_img_size" value="large" |
| 157 |
<?php |
| 158 |
if ( 'large' === $ogpplus_settings['og_img_size'] ) { |
| 159 |
echo 'checked'; |
| 160 |
} |
| 161 |
?> |
| 162 |
><?php esc_html_e( 'Large size' ); ?> |
| 163 |
<input type="radio" name="og_img_size" value="full" |
| 164 |
<?php |
| 165 |
if ( 'full' === $ogpplus_settings['og_img_size'] ) { |
| 166 |
echo 'checked'; |
| 167 |
} |
| 168 |
?> |
| 169 |
><?php esc_html_e( 'Full Size' ); ?> |
| 170 |
</div> |
| 171 |
<input type="hidden" name="df_img_id" value="<?php echo esc_attr( $ogpplus_settings['df_img_id'] ); ?>" id="media-id"> |
| 172 |
<div class="image-preview-wrapper"> |
| 173 |
<img src="<?php echo esc_url( $ogp_img_url ); ?>" height="100"> |
| 174 |
</div> |
| 175 |
<div> |
| 176 |
<button type="button" id="media-upload" class="button"><?php esc_html_e( 'Choose Default OGP image', 'ogp-plus' ); ?></button> |
| 177 |
</div> |
| 178 |
<?php |
| 179 |
if ( is_multisite() ) { |
| 180 |
$rts_install_url = network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=ratio-thumbnails-size' ); |
| 181 |
} else { |
| 182 |
$rts_install_url = admin_url( 'plugin-install.php?tab=plugin-information&plugin=ratio-thumbnails-size' ); |
| 183 |
} |
| 184 |
$rts_install_html = '<a href="' . $rts_install_url . '" target="_blank" rel="noopener noreferrer" style="text-decoration: none; word-break: break-all;">Ratio Thumbnails Size</a>'; |
| 185 |
?> |
| 186 |
<p class="description"> |
| 187 |
<?php esc_html_e( 'If there is an post thumbnail on post or page, it will take precedence.', 'ogp-plus' ); ?> |
| 188 |
<br /> |
| 189 |
<?php |
| 190 |
/* translators: Other plugin link */ |
| 191 |
echo wp_kses_post( sprintf( __( 'The optimal ratio of Facebook and X(Twitter) OGP images is 1:1.19. Please use %1$s if you want this ratio.', 'ogp-plus' ), $rts_install_html ) ); |
| 192 |
?> |
| 193 |
</p> |
| 194 |
</div> |
| 195 |
|
| 196 |
<div style="display: block;padding:5px 5px"> |
| 197 |
<strong><?php esc_html_e( 'X(Twitter) user name', 'ogp-plus' ); ?> : </strong> |
| 198 |
<input type="text" name="tw_user_name" value="<?php echo esc_attr( $ogpplus_settings['tw_user_name'] ); ?>"> |
| 199 |
</div> |
| 200 |
|
| 201 |
<div style="display: block;padding:5px 5px"> |
| 202 |
<strong><?php esc_html_e( 'Facebook App ID', 'ogp-plus' ); ?> : </strong> |
| 203 |
<input type="text" name="fb_app_id" value="<?php echo esc_attr( $ogpplus_settings['fb_app_id'] ); ?>"> |
| 204 |
</div> |
| 205 |
|
| 206 |
<p class="submit"> |
| 207 |
<?php submit_button( __( 'Save Changes' ), 'large', 'Manageset', false ); ?> |
| 208 |
<?php submit_button( __( 'Default' ), 'large', 'Defaultset', false ); ?> |
| 209 |
</p> |
| 210 |
|
| 211 |
</form> |
| 212 |
|
| 213 |
</div> |
| 214 |
<?php |
| 215 |
} |
| 216 |
|
| 217 |
/** ================================================== |
| 218 |
* Credit |
| 219 |
* |
| 220 |
* @since 1.00 |
| 221 |
*/ |
| 222 |
private function credit() { |
| 223 |
|
| 224 |
$plugin_name = null; |
| 225 |
$plugin_ver_num = null; |
| 226 |
$plugin_path = plugin_dir_path( __DIR__ ); |
| 227 |
$plugin_dir = untrailingslashit( wp_normalize_path( $plugin_path ) ); |
| 228 |
$slugs = explode( '/', $plugin_dir ); |
| 229 |
$slug = end( $slugs ); |
| 230 |
$files = scandir( $plugin_dir ); |
| 231 |
foreach ( $files as $file ) { |
| 232 |
if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) { |
| 233 |
continue; |
| 234 |
} else { |
| 235 |
$exts = explode( '.', $file ); |
| 236 |
$ext = strtolower( end( $exts ) ); |
| 237 |
if ( 'php' === $ext ) { |
| 238 |
$plugin_datas = get_file_data( |
| 239 |
$plugin_path . $file, |
| 240 |
array( |
| 241 |
'name' => 'Plugin Name', |
| 242 |
'version' => 'Version', |
| 243 |
) |
| 244 |
); |
| 245 |
if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) { |
| 246 |
$plugin_name = $plugin_datas['name']; |
| 247 |
$plugin_ver_num = $plugin_datas['version']; |
| 248 |
break; |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
$plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num; |
| 254 |
/* translators: FAQ Link & Slug */ |
| 255 |
$faq = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'ogp-plus' ), $slug ); |
| 256 |
$support = 'https://wordpress.org/support/plugin/' . $slug; |
| 257 |
$review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug; |
| 258 |
$translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug; |
| 259 |
$facebook = 'https://www.facebook.com/katsushikawamori/'; |
| 260 |
$twitter = 'https://twitter.com/dodesyo312'; |
| 261 |
$youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w'; |
| 262 |
$donate = __( 'https://shop.riverforest-wp.info/donate/', 'ogp-plus' ); |
| 263 |
|
| 264 |
?> |
| 265 |
<span style="font-weight: bold;"> |
| 266 |
<div> |
| 267 |
<?php echo esc_html( $plugin_version ); ?> | |
| 268 |
<a style="text-decoration: none;" href="<?php echo esc_url( $faq ); ?>" target="_blank" rel="noopener noreferrer">FAQ</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $support ); ?>" target="_blank" rel="noopener noreferrer">Support Forums</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $review ); ?>" target="_blank" rel="noopener noreferrer">Reviews</a> |
| 269 |
</div> |
| 270 |
<div> |
| 271 |
<a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank" rel="noopener noreferrer"> |
| 272 |
<?php |
| 273 |
/* translators: Plugin translation link */ |
| 274 |
echo esc_html( sprintf( __( 'Translations for %s' ), $plugin_name ) ); |
| 275 |
?> |
| 276 |
</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-video-alt3"></span></a> |
| 277 |
</div> |
| 278 |
</span> |
| 279 |
|
| 280 |
<div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;"> |
| 281 |
<h3><?php esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'ogp-plus' ); ?></h3> |
| 282 |
<div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div> |
| 283 |
<button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin »' ); ?></button> |
| 284 |
</div> |
| 285 |
|
| 286 |
<?php |
| 287 |
} |
| 288 |
|
| 289 |
/** ================================================== |
| 290 |
* Update wp_options table. |
| 291 |
* |
| 292 |
* @since 1.00 |
| 293 |
*/ |
| 294 |
private function options_updated() { |
| 295 |
|
| 296 |
if ( isset( $_POST['Manageset'] ) && ! empty( $_POST['Manageset'] ) ) { |
| 297 |
if ( check_admin_referer( 'ogp_set', 'ogpplus_set' ) ) { |
| 298 |
if ( isset( $_POST['excerpt'] ) ) { |
| 299 |
$ogpplus_settings['excerpt'] = intval( $_POST['excerpt'] ); |
| 300 |
} |
| 301 |
if ( isset( $_POST['df_img_id'] ) && ! empty( $_POST['df_img_id'] ) ) { |
| 302 |
$ogpplus_settings['df_img_id'] = intval( $_POST['df_img_id'] ); |
| 303 |
} else { |
| 304 |
$ogpplus_settings['df_img_id'] = null; |
| 305 |
} |
| 306 |
if ( isset( $_POST['og_img_size'] ) && ! empty( $_POST['og_img_size'] ) ) { |
| 307 |
$ogpplus_settings['og_img_size'] = sanitize_text_field( wp_unslash( $_POST['og_img_size'] ) ); |
| 308 |
} |
| 309 |
if ( isset( $_POST['tw_user_name'] ) && ! empty( $_POST['tw_user_name'] ) ) { |
| 310 |
$ogpplus_settings['tw_user_name'] = sanitize_text_field( wp_unslash( $_POST['tw_user_name'] ) ); |
| 311 |
} else { |
| 312 |
$ogpplus_settings['tw_user_name'] = null; |
| 313 |
} |
| 314 |
if ( isset( $_POST['fb_app_id'] ) && ! empty( $_POST['fb_app_id'] ) ) { |
| 315 |
$ogpplus_settings['fb_app_id'] = sanitize_text_field( wp_unslash( $_POST['fb_app_id'] ) ); |
| 316 |
} else { |
| 317 |
$ogpplus_settings['fb_app_id'] = null; |
| 318 |
} |
| 319 |
update_option( 'ogpplus_settings', $ogpplus_settings ); |
| 320 |
echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Settings' ) . ' --> ' . esc_html__( 'Settings saved.' ) . '</li></ul></div>'; |
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
if ( isset( $_POST['Defaultset'] ) && ! empty( $_POST['Defaultset'] ) ) { |
| 325 |
if ( check_admin_referer( 'ogp_set', 'ogpplus_set' ) ) { |
| 326 |
delete_option( 'ogpplus_settings' ); |
| 327 |
echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Settings' ) . ' --> ' . esc_html__( 'Default' ) . '</li></ul></div>'; |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
|