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

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