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

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