| @@ -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 | |
| @@ -14,8 +15,10 @@ | ||
| 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 | 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) | |
| 18 | 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 | |
| @@ -33,8 +36,12 @@ | ||
| 33 | 36 | protected $label; // Label (default) Text. This will be in the button, e.g. on hover |
| 34 | 37 | |
| 35 | 38 | protected $icon_type = 'fab'; // Icon library set |
| 36 | 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 = ''; | |
| 37 | 44 | |
| 38 | 45 | protected $color = '#fff'; |
| 39 | 46 | |
| 40 | 47 | // extra options [internal] |
| @@ -43,12 +50,18 @@ | ||
| 43 | 50 | protected $is_active = true; |
| 44 | 51 | protected $is_limitedpro = false; // the network is only intended for MB PRO |
| 45 | 52 | protected $forcesamewindow = false; // never open this in a new window / i.e. email / print type networks |
| 46 | 53 | |
| 54 | + protected $default_options = null; | |
| 55 | + | |
| 47 | 56 | public function __construct() |
| 48 | 57 | { |
| 49 | - $this->profile_placeholder = __('User Name','mbsocial'); | |
| 50 | - $this->profile_label = __('Follow', 'mbsocial'); | |
| 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 | |
| 51 | 64 | } |
| 52 | 65 | |
| 53 | 66 | public function get($name) |
| 54 | 67 | { |
| @@ -62,8 +75,12 @@ | ||
| 62 | 75 | { |
| 63 | 76 | $popup_width = isset($this->popup_dimensions[0]) ? $this->popup_dimensions[0] : 0; |
| 64 | 77 | $popup_height = isset($this->popup_dimensions[1]) ? $this->popup_dimensions[1] : 0; |
| 65 | 78 | |
| 79 | + | |
| 80 | + // iterate on this next time perhaps. | |
| 81 | + //$attrs = get_object_vars($this); | |
| 82 | + | |
| 66 | 83 | $options = array( |
| 67 | 84 | 'active' => $this->is_active, // no nw setting for this |
| 68 | 85 | 'popup' => $this->is_popup, |
| 69 | 86 | 'label' => $this->label, |
| @@ -72,14 +89,25 @@ | ||
| 72 | 89 | 'popup_width' => $popup_width, |
| 73 | 90 | 'popup_height' => $popup_height, |
| 74 | 91 | 'icon_type' => $this->icon_type, |
| 75 | 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, | |
| 76 | 97 | 'color' => $this->color, |
| 98 | + 'displayMobile' => $this->displayMobile, | |
| 99 | + 'displayDesktop' => $this->displayDesktop, | |
| 77 | 100 | ); |
| 78 | 101 | |
| 79 | 102 | return $options; |
| 80 | 103 | } |
| 81 | 104 | |
| 105 | + public function get_all_defaults() | |
| 106 | + { | |
| 107 | + return $this->default_options; | |
| 108 | + } | |
| 109 | + | |
| 82 | 110 | public function load_settings($settings) |
| 83 | 111 | { |
| 84 | 112 | if (! $settings) |
| 85 | 113 | return; |
| @@ -85,9 +113,9 @@ | ||
| 85 | 113 | return; |
| 86 | 114 | foreach($settings as $setting => $value) |
| 87 | 115 | { |
| 88 | 116 | if (is_null($value) || strlen($value) == 0) |
| 89 | - continue; | |
| 117 | + continue; | |
| 90 | 118 | |
| 91 | 119 | switch($setting) |
| 92 | 120 | { |
| 93 | 121 | case 'active': |
| @@ -151,8 +179,16 @@ | ||
| 151 | 179 | |
| 152 | 180 | return true; |
| 153 | 181 | } |
| 154 | 182 | |
| 183 | + public function has_alternate() | |
| 184 | + { | |
| 185 | + if (is_null($this->alternate_url)) | |
| 186 | + return false; | |
| 187 | + | |
| 188 | + return true; | |
| 189 | + } | |
| 190 | + | |
| 155 | 191 | /** Use this function to check if popup link should be used **/ |
| 156 | 192 | public function is_popup() |
| 157 | 193 | { |
| 158 | 194 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| @@ -200,12 +236,16 @@ | ||
| 200 | 236 | } |
| 201 | 237 | elseif ($is_profile && $is_share) |
| 202 | 238 | { |
| 203 | 239 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| 240 | + $use_alternate = MBSocial()->whistle()->ask('editor/profile/alternate'); | |
| 204 | 241 | |
| 205 | 242 | if ($use_profile == 1) |
| 206 | 243 | { |
| 207 | - return $this->profile_url; | |
| 244 | + if ($use_alternate == 1) | |
| 245 | + return $this->alternate_url; | |
| 246 | + else | |
| 247 | + return $this->profile_url; | |
| 208 | 248 | } |
| 209 | 249 | else { |
| 210 | 250 | return $this->share_url; |
| 211 | 251 | } |
| @@ -236,9 +276,9 @@ | ||
| 236 | 276 | "; |
| 237 | 277 | |
| 238 | 278 | $html .= "</a></span>"; |
| 239 | 279 | |
| 240 | - $button = str_get_html($html); | |
| 280 | + $button = \MaxButtons\str_get_html($html); | |
| 241 | 281 | return $button; |
| 242 | 282 | } |
| 243 | 283 | |
| 244 | 284 | public function getRemoteShareCount($share_url) |