1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
<?php
if ( ! defined( 'ABSPATH' ) ) {
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
exit;
}
class Push7_Subscribe_Button {
const APP_ID_PATTERN = '[0-9a-f]{32}';
const APP_ID_PATTERN_PREG = '/\A[0-9a-f]{32}\z/';
const PUSH7_APPNO_NAME = 'push7_appno';
const PLUGIN_OPTIONS = 'push7sb_option';
const MAIN_ENTRY = __FILE__;
public static function get_instance() {
static $instance;
if ( ! $instance instanceof Push7_Subscribe_Button ) {
$instance = new static;
}
return $instance;
}
private function __construct() {
$this->add_actions();
$this->load_textdomain();
$this->jetpack();
}
private function add_actions() {
add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
add_action( 'init', array( $this, 'register_shortcodes' ) );
add_action( 'widgets_init', array( $this, 'register_widget' ) );
add_action( 'init', array( $this, 'load_sbz' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
public function register_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'push7-subscribe-button', 'https://push.app.push7.jp/static/button/p7.js', array(), false, true );
wp_register_script( 'push7-custom-button', plugins_url( 'js/push7sb' . $suffix . '.js', __FILE__ ), array( 'jquery' ), false, true );
wp_register_style( 'push7-custom-button', plugins_url( 'css/front' . $suffix . '.css', __FILE__ ) );
}
public function register_widget() {
register_widget( 'Push7_Subscribe_Button_Widget' );
}
public function load_textdomain() {
load_plugin_textdomain( 'simple-push-subscribe-button', null, basename( dirname( __FILE__ ) ) . '/languages/' );
}
public function load_sbz() {
$option = Push7_Subscribe_Button_Options::get_options();
if ( $option->enable_social_buzz ) {
$sbztypes = self::get_sbztypes();
$sm = $sbztypes[ $option->social_buzz_mode ];
if ( ! file_exists( $sm['file'] ) ) {
trigger_error( $sm['file'] . ' is not found at ' . __FILE__ . ' on line ' . __LINE__ );
return;
}
require_once $sm['file'];
if ( ! class_exists( $sm['class'] ) ) {
trigger_error( 'Class ' . $sm['class'] . ' is not found at ' . __FILE__ . ' on line ' . __LINE__ );
return;
}
if ( ! is_callable( array( $sm['class'], 'get_instance' ), null, $name ) ) {
trigger_error( $name . ' is not callable at ' . __FILE__ . ' on line ' . __LINE__ );
return;
}
call_user_func( array( $sm['class'], 'get_instance' ) );
}
}
public static function get_sbztypes() {
$modes = array(
'simple' => array(
'file' => dirname( __FILE__ ) . '/inc/socialbuzz/class.simple.php',
'class' => '\Push7SubscribeButtoon\SocialBuzz\SocialSimple',
'name' => __( 'Simple', 'simple-push-subscribe-button' ),
),
'withthumb' => array(
'file' => dirname( __FILE__ ) . '/inc/socialbuzz/class.withthumb.php',
'class' => '\Push7SubscribeButtoon\SocialBuzz\SocialWithThumb',
'name' => __( 'With Thumbnail or Site icon', 'simple-push-subscribe-button' ),
),
);
return apply_filters( 'push7_sb_socialbuzz_types', $modes );
}
public function register_shortcodes() {
add_shortcode( 'push7-sb', array( $this, 'shortcode' ) );
}
public function shortcode( $atts ) {
$a = shortcode_atts( array(
'id' => self::get_appid_inc_official(),
'type' => self::get_shortcode_type(),
), $atts );
wp_enqueue_script( 'push7-subscribe-button' );
return self::get_official_button( $a['id'], $a['type'] );
}
public function jetpack() {
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'sharedaddy' ) ) {
require_once dirname( __FILE__ ) . '/inc/class.sharedaddy.php';
}
}
public function admin_enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'push7-admin-sharing', plugins_url( 'css/admin-sharing' . $suffix . '.css', __FILE__ ) );
}
public function admin_menu() {
require_once dirname( __FILE__ ) . '/inc/admin/class.admin.php';
\Push7SubscribeButtoon\Admin\Admin::get_instance()->admin_menu();
}
public static function uninstall() {
delete_option( self::PLUGIN_OPTIONS );
}
public static function get_appid() {
return Push7_Subscribe_Button_Options::get_options()->appid;
}
public static function get_appid_inc_official() {
$app_id = self::get_appid();
return apply_filters( 'push7_sb_appid', $app_id ? $app_id : get_option( self::PUSH7_APPNO_NAME, '' ) );
}
public static function get_shortcode_type() {
return get_option( 'push7_sb_sctype', '' );
}
private static function format_official_button_type( $type ) {
switch ( $type ) {
case 'r':
case 'right':
case 'count':
return 'r';
break;
case 't':
case 'vertical':
case 'balloon':
return 't';
break;
default:
return 'n';
}
}
public static function get_official_button( $app_id, $type = '' ) {
return apply_filters( 'push7_sb_official_button', sprintf( '<div class="p7-b" data-p7id="%s" data-p7c="%s"></div>', $app_id, self::format_official_button_type( $type ) ), $app_id, $type );
}
}
register_uninstall_hook( __FILE__, array( 'Push7_Subscribe_Button', 'uninstall' ) );
add_action( 'plugins_loaded', array( 'Push7_Subscribe_Button', 'get_instance' ) );
require_once dirname( __FILE__ ) . '/inc/class.widget.php';
require_once dirname( __FILE__ ) . '/inc/class.options.php';