PluginProbe
Social Share Buttons / 1.9
Social Share Buttons v1.9
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.9, at classes/class-social.php

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