| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | namespace MBSocial; |
| 3 | 3 | defined('ABSPATH') or die('No direct access permitted'); |
| 4 | 4 | |
| 5 | 5 | use \MaxButtons\MaxUtils as MaxUtils; |
| 6 | +use \MaxButtons\simple_html_dom as simple_html_dom; | |
| 6 | 7 | |
| 7 | 8 | abstract class mbNetwork |
| 8 | 9 | { |
| 9 | 10 | |
| @@ -13,26 +14,56 @@ | ||
| 13 | 14 | //protected $api_url; // URL of API to request information |
| 14 | 15 | protected $countable = false; // If network supports count of likes / shares / favs |
| 15 | 16 | protected $count_api = ''; // API URL for requesting counts |
| 16 | 17 | protected $count_check_time = 14400; // (PHP 5.3) 4 * HOUR_IN_SECONDS; // Transient time, how often to check network for new counts |
| 17 | - protected $share_url; // URL to link to when sharing something | |
| 18 | - protected $popup = true; // Open in Popup or not | |
| 18 | + protected $share_url = null; // URL to link to when sharing something | |
| 19 | + protected $alternate_url = null; // if another URL needs to be | |
| 20 | + protected $alternate_label = null; // Label for the other option (checkbox) | |
| 21 | + protected $is_popup = true; // Open in Popup or not | |
| 19 | 22 | protected $popup_dimensions = array(400,300); // Default popup dimensions |
| 20 | 23 | protected $return_var; // Count API return var ( JSON format ) |
| 21 | 24 | |
| 22 | - protected $displayMobile = true; | |
| 23 | - protected $displayDesktop = true; | |
| 25 | + // mobile or not settings - not yet developed | |
| 26 | + protected $displayMobile = true; // network should be displayed on mobiles | |
| 27 | + protected $displayDesktop = true; // network should be displayed on desktop | |
| 24 | 28 | |
| 25 | - protected $nice_name; | |
| 29 | + /** Options for Share Icons */ | |
| 30 | + protected $profile_url = null; // URL to the network's profiles. | |
| 31 | + protected $profile_placeholder; // Placeholder for profile input text field [aka 'user name' or so ] | |
| 32 | + protected $profile_label; // Not in use at the moment? | |
| 26 | 33 | |
| 27 | - protected $label; | |
| 34 | + protected $nice_name; // Nice name for display in the Editor interface | |
| 28 | 35 | |
| 29 | - protected $icon_type = 'fa'; | |
| 30 | - protected $icon = 'fa-circle'; | |
| 36 | + protected $label; // Label (default) Text. This will be in the button, e.g. on hover | |
| 31 | 37 | |
| 32 | - abstract public function __construct(); | |
| 38 | + protected $icon_type = 'fab'; // Icon library set | |
| 39 | + protected $icon = 'fa-circle'; // Icon | |
| 40 | + protected $icon_image_id; // for svg type icons. | |
| 41 | + protected $icon_image_url; | |
| 42 | + protected $icon_image_size; | |
| 43 | +// protected $icon_image_alt = ''; | |
| 33 | 44 | |
| 45 | + protected $color = '#fff'; | |
| 34 | 46 | |
| 47 | + // extra options [internal] | |
| 48 | + protected $is_native = true; // is this network built-in, or imported? Relevant for network settings | |
| 49 | + protected $is_editable = true; // should this network be user-editable? | |
| 50 | + protected $is_active = true; | |
| 51 | + protected $is_limitedpro = false; // the network is only intended for MB PRO | |
| 52 | + protected $forcesamewindow = false; // never open this in a new window / i.e. email / print type networks | |
| 53 | + | |
| 54 | + protected $default_options = null; | |
| 55 | + | |
| 56 | + public function __construct() | |
| 57 | + { | |
| 58 | + if (is_null($this->profile_placeholder)) | |
| 59 | + $this->profile_placeholder = __('User Name','mbsocial'); | |
| 60 | + if (is_null($this->profile_label)) | |
| 61 | + $this->profile_label = __('Follow', 'mbsocial'); | |
| 62 | + | |
| 63 | + $this->default_options = $this->get_all_options(); // init them as default. For save function | |
| 64 | + } | |
| 65 | + | |
| 35 | 66 | public function get($name) |
| 36 | 67 | { |
| 37 | 68 | if (isset($this->$name)) |
| 38 | 69 | return $this->$name; |
| @@ -37,11 +68,77 @@ | ||
| 37 | 68 | if (isset($this->$name)) |
| 38 | 69 | return $this->$name; |
| 39 | 70 | else |
| 40 | 71 | return null; |
| 72 | + } | |
| 41 | 73 | |
| 74 | + public function get_all_options() | |
| 75 | + { | |
| 76 | + $popup_width = isset($this->popup_dimensions[0]) ? $this->popup_dimensions[0] : 0; | |
| 77 | + $popup_height = isset($this->popup_dimensions[1]) ? $this->popup_dimensions[1] : 0; | |
| 78 | + | |
| 79 | + | |
| 80 | + // iterate on this next time perhaps. | |
| 81 | + //$attrs = get_object_vars($this); | |
| 82 | + | |
| 83 | + $options = array( | |
| 84 | + 'active' => $this->is_active, // no nw setting for this | |
| 85 | + 'popup' => $this->is_popup, | |
| 86 | + 'label' => $this->label, | |
| 87 | + 'share_url' => $this->share_url, | |
| 88 | + 'profile_url' => $this->profile_url, | |
| 89 | + 'popup_width' => $popup_width, | |
| 90 | + 'popup_height' => $popup_height, | |
| 91 | + 'icon_type' => $this->icon_type, | |
| 92 | + 'icon' => $this->icon, | |
| 93 | + 'icon_image_id' => $this->icon_image_id, | |
| 94 | + 'icon_image_url' => $this->icon_image_url, | |
| 95 | + // 'icon_image_alt' => $this->icon_image_alt, | |
| 96 | + 'icon_image_size' => $this->icon_image_size, | |
| 97 | + 'color' => $this->color, | |
| 98 | + 'displayMobile' => $this->displayMobile, | |
| 99 | + 'displayDesktop' => $this->displayDesktop, | |
| 100 | + ); | |
| 101 | + | |
| 102 | + return $options; | |
| 42 | 103 | } |
| 43 | 104 | |
| 105 | + public function get_all_defaults() | |
| 106 | + { | |
| 107 | + return $this->default_options; | |
| 108 | + } | |
| 109 | + | |
| 110 | + public function load_settings($settings) | |
| 111 | + { | |
| 112 | + if (! $settings) | |
| 113 | + return; | |
| 114 | + foreach($settings as $setting => $value) | |
| 115 | + { | |
| 116 | + if (is_null($value) || strlen($value) == 0) | |
| 117 | + continue; | |
| 118 | + | |
| 119 | + switch($setting) | |
| 120 | + { | |
| 121 | + case 'active': | |
| 122 | + $this->is_active = ($value == 1) ? true : false; | |
| 123 | + break; | |
| 124 | + case 'popup': | |
| 125 | + $this->is_popup = ($value == 1) ? true : false; | |
| 126 | + break; | |
| 127 | + case 'popup_width': | |
| 128 | + $this->popup_dimensions[0] = $value; | |
| 129 | + break; | |
| 130 | + case 'popup_height': | |
| 131 | + $this->popup_dimensions[1] = $value; | |
| 132 | + break; | |
| 133 | + default: | |
| 134 | + $this->{$setting} = $value; | |
| 135 | + break; | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + | |
| 44 | 141 | public function forMobile() |
| 45 | 142 | { |
| 46 | 143 | return $this->displayMobile; |
| 47 | 144 | } |
| @@ -50,13 +147,69 @@ | ||
| 50 | 147 | { |
| 51 | 148 | return $this->displayDesktop; |
| 52 | 149 | } |
| 53 | 150 | |
| 151 | + /** If current running setting of network should display count | |
| 152 | + * | |
| 153 | + * Even if network supports displaying a counter, this should not be the case when showing the 'profile' | |
| 154 | + * @return boolean | |
| 155 | + */ | |
| 54 | 156 | public function isCountable() |
| 55 | 157 | { |
| 158 | + $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); | |
| 159 | + if ($use_profile == 1) | |
| 160 | + return false; | |
| 161 | + | |
| 56 | 162 | return $this->countable; |
| 57 | 163 | } |
| 58 | 164 | |
| 165 | + // If network is capable of sharing profile | |
| 166 | + public function is_share_icon() | |
| 167 | + { | |
| 168 | + if (is_null($this->profile_url)) | |
| 169 | + return false; | |
| 170 | + | |
| 171 | + return true; | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** If network is capable of sharing site page */ | |
| 175 | + public function is_social_share() | |
| 176 | + { | |
| 177 | + if (is_null($this->share_url)) | |
| 178 | + return false; | |
| 179 | + | |
| 180 | + return true; | |
| 181 | + } | |
| 182 | + | |
| 183 | + public function has_alternate() | |
| 184 | + { | |
| 185 | + if (is_null($this->alternate_url)) | |
| 186 | + return false; | |
| 187 | + | |
| 188 | + return true; | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** Use this function to check if popup link should be used **/ | |
| 192 | + public function is_popup() | |
| 193 | + { | |
| 194 | + $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); | |
| 195 | + if ($use_profile == 1) | |
| 196 | + return false; | |
| 197 | + else { | |
| 198 | + return $this->is_popup; | |
| 199 | + } | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** Return the label for this network and use **/ | |
| 203 | + public function get_label() | |
| 204 | + { | |
| 205 | + $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); | |
| 206 | + if ($use_profile == 1 && strlen($this->profile_label) > 0) | |
| 207 | + return $this->profile_label; | |
| 208 | + else | |
| 209 | + return $this->label; | |
| 210 | + } | |
| 211 | + | |
| 59 | 212 | public function get_nice_name() |
| 60 | 213 | { |
| 61 | 214 | if (isset($this->nice_name)) |
| 62 | 215 | return $this->nice_name; |
| @@ -61,9 +214,72 @@ | ||
| 61 | 214 | if (isset($this->nice_name)) |
| 62 | 215 | return $this->nice_name; |
| 63 | 216 | else |
| 64 | 217 | return ucfirst($this->network); |
| 218 | + } | |
| 65 | 219 | |
| 220 | + /** Find and get the proper URL to link to. | |
| 221 | + * This can be the network link to sharing a page | |
| 222 | + * or the network link to linking the profile. | |
| 223 | + * Try to find out automatically or whistle ask */ | |
| 224 | + public function get_url() | |
| 225 | + { | |
| 226 | + $is_profile = $this->is_share_icon(); | |
| 227 | + $is_share = $this->is_social_share(); | |
| 228 | + | |
| 229 | + if ($is_profile && ! $is_share) // profile only network | |
| 230 | + { | |
| 231 | + return $this->profile_url; | |
| 232 | + } | |
| 233 | + elseif (! $is_profile && $is_share) // share page only network | |
| 234 | + { | |
| 235 | + return $this->share_url; | |
| 236 | + } | |
| 237 | + elseif ($is_profile && $is_share) | |
| 238 | + { | |
| 239 | + $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); | |
| 240 | + $use_alternate = MBSocial()->whistle()->ask('editor/profile/alternate'); | |
| 241 | + | |
| 242 | + if ($use_profile == 1) | |
| 243 | + { | |
| 244 | + if ($use_alternate == 1) | |
| 245 | + return $this->alternate_url; | |
| 246 | + else | |
| 247 | + return $this->profile_url; | |
| 248 | + } | |
| 249 | + else { | |
| 250 | + return $this->share_url; | |
| 251 | + } | |
| 252 | + | |
| 253 | + } | |
| 254 | + } | |
| 255 | + | |
| 256 | + /* Network dependent creating of a button. Called from collection class */ | |
| 257 | + public function createButton($args = array()) | |
| 258 | + { | |
| 259 | + $defaults = array('link' => 'javascript:void(0)', | |
| 260 | + 'preview' => false, | |
| 261 | + 'index' => -1, | |
| 262 | + 'name' => '', | |
| 263 | + 'data' => array(), | |
| 264 | + 'collection_count' => 0, | |
| 265 | + ); | |
| 266 | + | |
| 267 | + $item_index = $args['index']; | |
| 268 | + if ($args['collection_count'] > 1) | |
| 269 | + { | |
| 270 | + $item_index = $args['collection_count'] . "_" . $item_index; | |
| 271 | + } | |
| 272 | + | |
| 273 | + $args = wp_parse_args($args, $defaults); | |
| 274 | + $html = "<span class='mb-item item-" . $item_index . "'> | |
| 275 | + <a href='" . $args['link'] . "' class='mb-social '> | |
| 276 | + "; | |
| 277 | + | |
| 278 | + $html .= "</a></span>"; | |
| 279 | + | |
| 280 | + $button = \MaxButtons\str_get_html($html); | |
| 281 | + return $button; | |
| 66 | 282 | } |
| 67 | 283 | |
| 68 | 284 | public function getRemoteShareCount($share_url) |
| 69 | 285 | { |