PluginProbe
Social Share Buttons / 1.6
Social Share Buttons v1.6
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / class-social.php

class-social.php in Social Share Buttons 1.6, at classes/class-social.php

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