| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
|
| 4 |
use \maxButtons\maxUtils as maxUtils; |
| 5 |
|
| 6 |
class mbSocialPlugin |
| 7 |
{ |
| 8 |
protected static $instance = null; |
| 9 |
|
| 10 |
protected $plugin_url; |
| 11 |
protected $plugin_path; |
| 12 |
protected $version; |
| 13 |
|
| 14 |
protected $networks; |
| 15 |
protected $admin; |
| 16 |
|
| 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 |
add_action('add_meta_boxes', array($this, 'meta_boxes'), 10, 2 ); |
| 41 |
add_action('save_post', array($this, 'save_meta_boxes'), 10, 3 ); |
| 42 |
|
| 43 |
add_action('wp_enqueue_scripts', array($this, 'front_scripts') ); |
| 44 |
|
| 45 |
add_action('wp_enqueue_scripts', array($this, 'front_scripts') ); |
| 46 |
|
| 47 |
add_shortcode('maxsocial', array($this->admin()->namespaceit('collections'), 'shortcode') ); |
| 48 |
add_action('maxbuttons/ajax/save_collection', array( $this->admin()->namespaceit('collections'), 'ajax_save') ); |
| 49 |
add_action('maxbuttons/ajax/refreshblock', array($this->admin()->namespaceit('collections'), 'ajax_refreshblock') ); |
| 50 |
add_action('maxbuttons/ajax/get_styles', array($this->admin()->namespaceit('collections'), 'ajax_getstyles') ); |
| 51 |
|
| 52 |
// FRONT AJAX |
| 53 |
add_action('wp_ajax_mbsocial_get_count', array($this->admin()->namespaceit("collections"), "ajax_action_front")); // front end for all users |
| 54 |
add_action('wp_ajax_nopriv_mbsocial_get_count', array($this->admin()->namespaceit("collections"), "ajax_action_front")); |
| 55 |
|
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
protected function loadClasses() |
| 60 |
{ |
| 61 |
$paths = array( mbSocial()->get_plugin_path() . 'classes/blocks/', |
| 62 |
mbSocial()->get_plugin_path() . 'classes/network/', |
| 63 |
// mbSocial()->get_plugin_path() . 'classes/styles/', |
| 64 |
); |
| 65 |
$paths = apply_filters("mbsocial/paths", $paths ); |
| 66 |
|
| 67 |
$collectionBlock = array(); |
| 68 |
$styles = array(); |
| 69 |
|
| 70 |
foreach($paths as $cpath) |
| 71 |
{ |
| 72 |
|
| 73 |
$dir_iterator = new \RecursiveDirectoryIterator($cpath, \FilesystemIterator::SKIP_DOTS); |
| 74 |
$iterator = new \RecursiveIteratorIterator($dir_iterator, \RecursiveIteratorIterator::SELF_FIRST); |
| 75 |
|
| 76 |
foreach ($iterator as $fileinfo) |
| 77 |
{ |
| 78 |
$file = $fileinfo->getFilename(); |
| 79 |
|
| 80 |
if (file_exists($cpath . $file)) |
| 81 |
{ |
| 82 |
require_once( $cpath . $file); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// no auto-load since order matter. |
| 90 |
$style_dir = mbSocial()->get_plugin_path() . 'classes/styles/'; |
| 91 |
|
| 92 |
$styles = array( |
| 93 |
'round-style', |
| 94 |
'roundflip-style', |
| 95 |
// 'round-style-nucleo', // perphaps for square |
| 96 |
'square-style', |
| 97 |
'dropsquare-style', |
| 98 |
'liftsquare-style', |
| 99 |
'rectangle-style', |
| 100 |
'shiftsquare-style', |
| 101 |
'horizontal-style', |
| 102 |
); |
| 103 |
|
| 104 |
foreach($styles as $style) |
| 105 |
{ |
| 106 |
require_once($style_dir . $style . '.php'); |
| 107 |
} |
| 108 |
|
| 109 |
collections::setBlocks($collectionBlock); |
| 110 |
//styles::setStyles($styles); |
| 111 |
//self::$collectionClass = $collectionClass; |
| 112 |
//self::$collectionBlock = $collectionBlock; |
| 113 |
} |
| 114 |
|
| 115 |
public static function getInstance() |
| 116 |
{ |
| 117 |
return self::$instance; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function networks() |
| 123 |
{ |
| 124 |
if (is_null($this->networks)) |
| 125 |
{ |
| 126 |
$this->networks = new mbSocialNetworks(); |
| 127 |
} |
| 128 |
|
| 129 |
return $this->networks; |
| 130 |
} |
| 131 |
|
| 132 |
public function admin() |
| 133 |
{ |
| 134 |
if ( is_null($this->admin)) |
| 135 |
{ |
| 136 |
$this->admin = new admin(); |
| 137 |
} |
| 138 |
|
| 139 |
return $this->admin; |
| 140 |
} |
| 141 |
|
| 142 |
public function admin_menu () |
| 143 |
{ |
| 144 |
|
| 145 |
$page_title = __('WordPress Share Buttons', 'mb-social'); |
| 146 |
$menu_title = __('WordPress Share Buttons', 'mb-social'); |
| 147 |
//$capability = $maxbuttons_capabilities; |
| 148 |
$admin_capability = 'manage_options'; |
| 149 |
$menu_slug = 'maxbuttons-social'; |
| 150 |
$function = array($this, 'load_admin_page'); |
| 151 |
$icon_url = $this->plugin_url . 'images/mb-social-icon.png'; |
| 152 |
$submenu_function = array($this, 'load_admin_page'); |
| 153 |
|
| 154 |
add_menu_page($page_title, $menu_title, $admin_capability, $menu_slug, $function, $icon_url, 81); |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
public function admin_styles($hook) |
| 159 |
{ |
| 160 |
wp_register_style('mbsocial-global', $this->plugin_url . 'css/global-admin.css', array(), $this->version); |
| 161 |
|
| 162 |
if ( strpos($hook,'maxbuttons-social') === false ) |
| 163 |
return; |
| 164 |
|
| 165 |
wp_enqueue_style('mbsocial-admin', $this->plugin_url . 'css/admin.css', array(), $this->version); |
| 166 |
|
| 167 |
wp_register_script('maxbuttons-social', $this->plugin_url . 'js/maxbuttons-social.js', array('jquery','maxbutton-admin', 'jquery-ui-sortable'), $this->version, true); |
| 168 |
wp_enqueue_script('maxbuttons-social'); |
| 169 |
|
| 170 |
wp_register_style('mbsocial-buttons', $this->plugin_url . 'css/buttons.css', array(), $this->version); |
| 171 |
wp_enqueue_style('mbsocial-buttons'); |
| 172 |
|
| 173 |
wp_register_style('nucleo_icons', $this->plugin_url . 'libraries/nucleo_icons/nucleo_icons.css', array(), $this->version); |
| 174 |
wp_enqueue_style('nucleo_icons'); |
| 175 |
} |
| 176 |
|
| 177 |
public function front_scripts($hook) |
| 178 |
{ |
| 179 |
wp_register_script('mbsocial_front', $this->plugin_url . 'js/social-front.js', array('jquery'), |
| 180 |
$this->version, true); |
| 181 |
|
| 182 |
wp_register_style('mbsocial-buttons', $this->plugin_url . 'css/buttons.css'); |
| 183 |
|
| 184 |
wp_register_style('nucleo_icons', $this->plugin_url . 'libraries/nucleo_icons/nucleo_icons.css', array(), $this->version); |
| 185 |
wp_enqueue_style('nucleo_icons'); |
| 186 |
} |
| 187 |
|
| 188 |
public function meta_boxes($post_type, $post) |
| 189 |
{ |
| 190 |
include_once($this->plugin_path . 'admin/meta_boxes.php'); |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
public function save_meta_boxes($post_id, $post, $update) |
| 195 |
{ |
| 196 |
|
| 197 |
if (! isset($_POST['mbsocial_save']) ) |
| 198 |
return; |
| 199 |
|
| 200 |
if (! wp_verify_nonce( $_POST['mbsocial_save'], 'save')) |
| 201 |
return; |
| 202 |
|
| 203 |
|
| 204 |
include_once($this->plugin_path . 'admin/save_meta_boxes.php'); |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
/** Returns the full path of the plugin installation directory */ |
| 209 |
public function get_plugin_path() |
| 210 |
{ |
| 211 |
return trailingslashit(plugin_dir_path(MBSOCIAL_ROOT_FILE)); |
| 212 |
} |
| 213 |
|
| 214 |
/** Returns the full URL of the plugin installation path */ |
| 215 |
public function get_plugin_url() |
| 216 |
{ |
| 217 |
return trailingslashit(plugin_dir_url(MBSOCIAL_ROOT_FILE)); |
| 218 |
} |
| 219 |
|
| 220 |
public function get_version() |
| 221 |
{ |
| 222 |
return MBSOCIAL_VERSION_NUM; |
| 223 |
} |
| 224 |
|
| 225 |
public function load_admin_page() |
| 226 |
{ |
| 227 |
if (Install::getIssue() == 'mb-wrong-version') |
| 228 |
include_once($this->plugin_path . 'admin/update_mb.php'); |
| 229 |
else |
| 230 |
include_once($this->plugin_path . 'admin/page_editor.php'); |
| 231 |
} |
| 232 |
|
| 233 |
} |
| 234 |
|