| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
|
| 4 |
use \maxButtons\maxUtils as maxUtils; |
| 5 |
|
| 6 |
class mbSocialPlugin |
| 7 |
{ |
| 8 |
protected static $instance = null; |
| 9 |
protected static $whistle = null; |
| 10 |
|
| 11 |
protected $plugin_url; |
| 12 |
protected $plugin_path; |
| 13 |
protected $version; |
| 14 |
|
| 15 |
protected $networks; |
| 16 |
protected $admin; |
| 17 |
|
| 18 |
public function __construct() |
| 19 |
{ |
| 20 |
|
| 21 |
$this->plugin_url = $this->get_plugin_url(); |
| 22 |
$this->plugin_path = $this->get_plugin_path(); |
| 23 |
$this->version = $this->get_version(); |
| 24 |
|
| 25 |
|
| 26 |
self::$instance = $this; |
| 27 |
} |
| 28 |
|
| 29 |
// one time run. These thingies need the instance |
| 30 |
public function init() |
| 31 |
{ |
| 32 |
$this->loadClasses(); |
| 33 |
|
| 34 |
if (! is_admin()) |
| 35 |
$hook_bool = collections::setupHooks(); |
| 36 |
|
| 37 |
//add_action('admin_menu', array($this, 'admin_menu') ); |
| 38 |
add_action('admin_enqueue_scripts', array($this, 'admin_styles') ); |
| 39 |
|
| 40 |
// load admin pages, after MB. |
| 41 |
add_filter('maxbuttons/plugin/admin_pages', array($this, 'admin_menu')); |
| 42 |
|
| 43 |
add_action('add_meta_boxes', array($this, 'meta_boxes'), 10, 2 ); |
| 44 |
add_action('save_post', array($this, 'save_meta_boxes'), 10, 3 ); |
| 45 |
|
| 46 |
add_action('wp_enqueue_scripts', array($this, 'front_scripts') ); |
| 47 |
|
| 48 |
add_shortcode('maxsocial', array($this->admin()->namespaceit('collections'), 'shortcode') ); |
| 49 |
|
| 50 |
add_action('maxbuttons/ajax/save_collection', array( $this->admin()->namespaceit('collections'), 'ajax_save') ); |
| 51 |
add_action('maxbuttons/ajax/remove-collection', array( $this->admin()->namespaceit('collections'), 'ajax_remove_collection') ); |
| 52 |
|
| 53 |
add_action('maxbuttons/ajax/refreshblock', array($this->admin()->namespaceit('collections'), 'ajax_refreshblock') ); |
| 54 |
add_action('maxbuttons/ajax/get_presets', array($this->admin()->namespaceit('collections'), 'ajax_getpresets') ); |
| 55 |
add_action('maxbuttons/ajax/set_preset', array($this->admin()->namespaceit('collections'), 'ajax_setpreset') ); |
| 56 |
|
| 57 |
add_action('maxbuttons/ajax/network-settings', array($this->networks(), 'ajax_networksettings') ); |
| 58 |
add_action('maxbuttons/ajax/save-network', array($this->networks(), 'ajax_savenetwork') ); |
| 59 |
add_action('maxbuttons/ajax/remove-networksettings', array($this->networks(), 'ajax_removesettings')); |
| 60 |
add_action('maxbuttons/ajax/show-customnetworks', array($this->networks(), 'ajax_showcustomnetworks')); |
| 61 |
add_action('maxbuttons/ajax/import-customnetworks', array($this->networks(), 'ajax_importcustomnetworks')); |
| 62 |
|
| 63 |
// FRONT AJAX |
| 64 |
add_action('wp_ajax_mbsocial_get_count', array($this->admin()->namespaceit("collections"), "ajax_action_front")); // front end for all users |
| 65 |
add_action('wp_ajax_nopriv_mbsocial_get_count', array($this->admin()->namespaceit("collections"), "ajax_action_front")); |
| 66 |
|
| 67 |
remove_action('admin_init', array(maxUtils::namespaceit('maxAdmin'), 'do_review_notice')); |
| 68 |
add_action('admin_init', array($this->admin(), 'do_review_notice')); |
| 69 |
add_action('maxbuttons/ajax/mbsocial_review_notice_status', array($this->admin(), 'save_review_notice')); |
| 70 |
|
| 71 |
add_action('wp_ajax_maxbuttons_social_css', array($this->admin()->namespaceit('collections'), 'outputFileCSS')); |
| 72 |
add_action('wp_ajax_nopriv_maxbuttons_social_css', array($this->admin()->namespaceit('collections'), 'outputFileCSS')); |
| 73 |
//add_filter('mb-block-paths', array($this, 'block_templates')); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/* Singleton pattern */ |
| 78 |
public static function getInstance() |
| 79 |
{ |
| 80 |
return self::$instance; |
| 81 |
} |
| 82 |
|
| 83 |
/* Loads all variable / pluggable MBSocial Classes */ |
| 84 |
protected function loadClasses() |
| 85 |
{ |
| 86 |
$paths = array( mbSocial()->get_plugin_path() . 'classes/blocks/', |
| 87 |
mbSocial()->get_plugin_path() . 'classes/network/', |
| 88 |
mbSocial()->get_plugin_path() . 'classes/styles/', |
| 89 |
// mbSocial()->get_plugin_path() . 'classes/styles/', |
| 90 |
); |
| 91 |
$paths = apply_filters("mbsocial/paths", $paths ); // for addons and custom blocks / networks |
| 92 |
|
| 93 |
$collectionBlock = array(); |
| 94 |
$styles = array(); |
| 95 |
|
| 96 |
foreach($paths as $cpath) |
| 97 |
{ |
| 98 |
|
| 99 |
$dir_iterator = new \RecursiveDirectoryIterator($cpath, \FilesystemIterator::SKIP_DOTS); |
| 100 |
$iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST); |
| 101 |
|
| 102 |
foreach ($iterator as $fileinfo) |
| 103 |
{ |
| 104 |
$file = $fileinfo->getFilename(); |
| 105 |
if (substr($file, 0,1) == '_') // exclude files starting with _ |
| 106 |
continue; |
| 107 |
|
| 108 |
if (file_exists($cpath . $file)) |
| 109 |
{ |
| 110 |
require_once( $cpath . $file); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
// no auto-load since order matter. |
| 118 |
// $style_dir = ; |
| 119 |
|
| 120 |
/* $styles = array( |
| 121 |
'round-style', |
| 122 |
'roundflip-style', |
| 123 |
// 'round-style-nucleo', // perphaps for square |
| 124 |
'square-style', |
| 125 |
'dropsquare-style', |
| 126 |
'liftsquare-style', |
| 127 |
'rectangle-style', |
| 128 |
'shiftsquare-style', |
| 129 |
'horizontal-style', |
| 130 |
); |
| 131 |
|
| 132 |
foreach($styles as $style) |
| 133 |
{ |
| 134 |
require_once($style_dir . $style . '.php'); |
| 135 |
} |
| 136 |
*/ |
| 137 |
collections::setBlocks($collectionBlock); |
| 138 |
//styles::setStyles($styles); |
| 139 |
//self::$collectionClass = $collectionClass; |
| 140 |
//self::$collectionBlock = $collectionBlock; |
| 141 |
} |
| 142 |
|
| 143 |
/*public function blocks_templates($paths) |
| 144 |
{ |
| 145 |
$paths['social_start'] = $this->get_plugin_url . 'includes/tpl/'; |
| 146 |
return $paths; |
| 147 |
} */ |
| 148 |
|
| 149 |
public function whistle() |
| 150 |
{ |
| 151 |
if (! is_null(static::$whistle)) |
| 152 |
return static::$whistle; |
| 153 |
else |
| 154 |
{ |
| 155 |
$w = whistle::getInstance(); |
| 156 |
static::$whistle = $w; |
| 157 |
return $w; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
public function networks() |
| 162 |
{ |
| 163 |
if (is_null($this->networks)) |
| 164 |
{ |
| 165 |
$this->networks = new mbSocialNetworks(); |
| 166 |
} |
| 167 |
|
| 168 |
return $this->networks; |
| 169 |
} |
| 170 |
|
| 171 |
public function admin() |
| 172 |
{ |
| 173 |
if ( is_null($this->admin)) |
| 174 |
{ |
| 175 |
$this->admin = new admin(); |
| 176 |
} |
| 177 |
|
| 178 |
return $this->admin; |
| 179 |
} |
| 180 |
|
| 181 |
public function admin_menu ($admin_pages) |
| 182 |
{ |
| 183 |
|
| 184 |
$page_title = __('WordPress Share Buttons', 'mb-social'); |
| 185 |
$menu_title = __('WordPress Share Buttons', 'mb-social'); |
| 186 |
//$capability = $maxbuttons_capabilities; |
| 187 |
$admin_capability = 'manage_options'; |
| 188 |
$menu_slug = 'maxbuttons-social'; |
| 189 |
$function = array($this, 'load_admin_page'); |
| 190 |
$icon_url = $this->plugin_url . 'images/mb-social-icon.png'; |
| 191 |
$submenu_function = array($this, 'load_admin_page'); |
| 192 |
|
| 193 |
$admin_pages[] = add_menu_page($page_title, $menu_title, $admin_capability, $menu_slug, $function, $icon_url, 82); |
| 194 |
|
| 195 |
if (Install::isPro()) |
| 196 |
{ |
| 197 |
$page_title = __('Settings', 'mb-social'); |
| 198 |
$submenu_slug = 'maxbuttons-social-settings'; |
| 199 |
$function = array($this, 'load_settings_page'); |
| 200 |
$admin_pages[] = add_submenu_page($menu_slug, $page_title, $page_title, $admin_capability, $submenu_slug, $function); |
| 201 |
} |
| 202 |
|
| 203 |
return $admin_pages; |
| 204 |
} |
| 205 |
|
| 206 |
public function admin_styles($hook) |
| 207 |
{ |
| 208 |
|
| 209 |
wp_register_style('mbsocial-global', $this->plugin_url . 'css/global-admin.css', array(), $this->version); |
| 210 |
|
| 211 |
if ( strpos($hook,'maxbuttons-social') === false ) |
| 212 |
return; |
| 213 |
|
| 214 |
wp_enqueue_style('mbsocial-admin', $this->plugin_url . 'css/admin.css', array(), $this->version); |
| 215 |
|
| 216 |
if (Install::isPro()) |
| 217 |
{ |
| 218 |
$deps = array('maxbuttons-pro-init','maxbuttons-ajax', 'mb-media-button', 'jquery-ui-sortable'); // pro init |
| 219 |
wp_register_script('maxbuttons-mbcustom', $this->plugin_url . 'js/maxbuttons-custom.js', $deps, $this->version, true); |
| 220 |
wp_enqueue_script('maxbuttons-mbcustom'); |
| 221 |
|
| 222 |
wp_register_script('mbsocial-icons', $this->plugin_url . 'js/images.js', $deps, $this->version, true); |
| 223 |
wp_enqueue_script('mbsocial-icons'); |
| 224 |
|
| 225 |
$deps[] = 'mbsocial-icons'; |
| 226 |
} |
| 227 |
else |
| 228 |
{ |
| 229 |
$deps = array('maxbutton-js-init', 'maxbuttons-ajax', 'mb-media-button', 'jquery-ui-sortable'); // free init |
| 230 |
} |
| 231 |
wp_register_script('maxbuttons-social', $this->plugin_url . 'js/maxbuttons-social.js', $deps , $this->version, true); |
| 232 |
wp_enqueue_script('maxbuttons-social'); |
| 233 |
|
| 234 |
|
| 235 |
wp_register_script('mbsocial-editor', $this->plugin_url . 'js/network-editor.js', $deps, $this->version, true); |
| 236 |
wp_enqueue_script('mbsocial-editor'); |
| 237 |
|
| 238 |
MB()->load_media_script(); |
| 239 |
|
| 240 |
wp_register_style('nucleo_icons', $this->plugin_url . 'libraries/nucleo_icons/nucleo_icons.css', array(), $this->version); |
| 241 |
wp_enqueue_style('nucleo_icons'); |
| 242 |
} |
| 243 |
|
| 244 |
public function front_scripts($hook) |
| 245 |
{ |
| 246 |
wp_register_script('mbsocial_front', $this->plugin_url . 'js/social-front.js', array('jquery'), |
| 247 |
$this->version, true); |
| 248 |
|
| 249 |
wp_localize_script('mbsocial_front','mbsocial', array('ajaxurl' => admin_url( 'admin-ajax.php' ))); |
| 250 |
|
| 251 |
wp_register_style('mbsocial-buttons', $this->plugin_url . 'css/buttons.css'); |
| 252 |
|
| 253 |
//wp_register_style('nucleo_icons', $this->plugin_url . 'libraries/nucleo_icons/nucleo_icons.css', array(), $this->version); |
| 254 |
//wp_enqueue_style('nucleo_icons'); |
| 255 |
} |
| 256 |
|
| 257 |
public function meta_boxes($post_type, $post) |
| 258 |
{ |
| 259 |
include_once($this->plugin_path . 'admin/meta_boxes.php'); |
| 260 |
|
| 261 |
} |
| 262 |
|
| 263 |
public function save_meta_boxes($post_id, $post, $update) |
| 264 |
{ |
| 265 |
|
| 266 |
if (! isset($_POST['mbsocial_save']) ) |
| 267 |
return; |
| 268 |
|
| 269 |
if (! wp_verify_nonce( $_POST['mbsocial_save'], 'save')) |
| 270 |
return; |
| 271 |
|
| 272 |
|
| 273 |
include_once($this->plugin_path . 'admin/save_meta_boxes.php'); |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
/** Returns the full path of the plugin installation directory */ |
| 278 |
public function get_plugin_path() |
| 279 |
{ |
| 280 |
return trailingslashit(plugin_dir_path(MBSOCIAL_ROOT_FILE)); |
| 281 |
} |
| 282 |
|
| 283 |
/** Returns the full URL of the plugin installation path */ |
| 284 |
public function get_plugin_url() |
| 285 |
{ |
| 286 |
return trailingslashit(plugin_dir_url(MBSOCIAL_ROOT_FILE)); |
| 287 |
} |
| 288 |
|
| 289 |
public function get_version() |
| 290 |
{ |
| 291 |
return MBSOCIAL_VERSION_NUM; |
| 292 |
} |
| 293 |
|
| 294 |
public function load_admin_page() |
| 295 |
{ |
| 296 |
if (Install::getIssue() == 'mb-wrong-version') |
| 297 |
include_once($this->plugin_path . 'admin/update_mb.php'); |
| 298 |
else |
| 299 |
include_once($this->plugin_path . 'admin/page_editor.php'); |
| 300 |
} |
| 301 |
|
| 302 |
public function load_settings_page() |
| 303 |
{ |
| 304 |
if (Install::getIssue() == 'mb-wrong-version') |
| 305 |
include_once($this->plugin_path . 'admin/update_mb.php'); |
| 306 |
else |
| 307 |
include_once($this->plugin_path . 'admin/page_settings.php'); |
| 308 |
} |
| 309 |
|
| 310 |
} |
| 311 |
|