| @@ -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,9 +15,11 @@ | ||
| 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 |
| 18 | - protected $popup = true; // Open in Popup or not | |
| 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 | 25 | // mobile or not settings - not yet developed |
| @@ -25,30 +28,42 @@ | ||
| 25 | 28 | |
| 26 | 29 | /** Options for Share Icons */ |
| 27 | 30 | protected $profile_url = null; // URL to the network's profiles. |
| 28 | 31 | protected $profile_placeholder; // Placeholder for profile input text field [aka 'user name' or so ] |
| 29 | - protected $profile_label; | |
| 32 | + protected $profile_label; // Not in use at the moment? | |
| 30 | 33 | |
| 31 | 34 | protected $nice_name; // Nice name for display in the Editor interface |
| 32 | 35 | |
| 33 | - protected $label; // Lavel (default) Text. This will be in the button, e.g. on hover | |
| 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] |
| 41 | - protected $limitedpro = false; // the network is only intended for MB PRO | |
| 42 | - protected $forcesamewindow = false; // never open this in a new window | |
| 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 | |
| 43 | 53 | |
| 54 | + protected $default_options = null; | |
| 55 | + | |
| 44 | 56 | public function __construct() |
| 45 | 57 | { |
| 46 | - $this->profile_placeholder = __('User Name','mbsocial'); | |
| 47 | - $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 | |
| 48 | 64 | } |
| 49 | 65 | |
| 50 | - | |
| 51 | 66 | public function get($name) |
| 52 | 67 | { |
| 53 | 68 | if (isset($this->$name)) |
| 54 | 69 | return $this->$name; |
| @@ -53,11 +68,77 @@ | ||
| 53 | 68 | if (isset($this->$name)) |
| 54 | 69 | return $this->$name; |
| 55 | 70 | else |
| 56 | 71 | return null; |
| 72 | + } | |
| 57 | 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; | |
| 58 | 103 | } |
| 59 | 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 | + | |
| 60 | 141 | public function forMobile() |
| 61 | 142 | { |
| 62 | 143 | return $this->displayMobile; |
| 63 | 144 | } |
| @@ -66,8 +147,13 @@ | ||
| 66 | 147 | { |
| 67 | 148 | return $this->displayDesktop; |
| 68 | 149 | } |
| 69 | 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 | + */ | |
| 70 | 156 | public function isCountable() |
| 71 | 157 | { |
| 72 | 158 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| 73 | 159 | if ($use_profile == 1) |
| @@ -93,8 +179,16 @@ | ||
| 93 | 179 | |
| 94 | 180 | return true; |
| 95 | 181 | } |
| 96 | 182 | |
| 183 | + public function has_alternate() | |
| 184 | + { | |
| 185 | + if (is_null($this->alternate_url)) | |
| 186 | + return false; | |
| 187 | + | |
| 188 | + return true; | |
| 189 | + } | |
| 190 | + | |
| 97 | 191 | /** Use this function to check if popup link should be used **/ |
| 98 | 192 | public function is_popup() |
| 99 | 193 | { |
| 100 | 194 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| @@ -100,9 +194,9 @@ | ||
| 100 | 194 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| 101 | 195 | if ($use_profile == 1) |
| 102 | 196 | return false; |
| 103 | 197 | else { |
| 104 | - return $this->popup; | |
| 198 | + return $this->is_popup; | |
| 105 | 199 | } |
| 106 | 200 | } |
| 107 | 201 | |
| 108 | 202 | /** Return the label for this network and use **/ |
| @@ -142,12 +236,16 @@ | ||
| 142 | 236 | } |
| 143 | 237 | elseif ($is_profile && $is_share) |
| 144 | 238 | { |
| 145 | 239 | $use_profile = MBSocial()->whistle()->ask('editor/profile/use'); |
| 240 | + $use_alternate = MBSocial()->whistle()->ask('editor/profile/alternate'); | |
| 146 | 241 | |
| 147 | 242 | if ($use_profile == 1) |
| 148 | 243 | { |
| 149 | - return $this->profile_url; | |
| 244 | + if ($use_alternate == 1) | |
| 245 | + return $this->alternate_url; | |
| 246 | + else | |
| 247 | + return $this->profile_url; | |
| 150 | 248 | } |
| 151 | 249 | else { |
| 152 | 250 | return $this->share_url; |
| 153 | 251 | } |
| @@ -152,10 +250,8 @@ | ||
| 152 | 250 | return $this->share_url; |
| 153 | 251 | } |
| 154 | 252 | |
| 155 | 253 | } |
| 156 | - | |
| 157 | - | |
| 158 | 254 | } |
| 159 | 255 | |
| 160 | 256 | /* Network dependent creating of a button. Called from collection class */ |
| 161 | 257 | public function createButton($args = array()) |
| @@ -180,9 +276,9 @@ | ||
| 180 | 276 | "; |
| 181 | 277 | |
| 182 | 278 | $html .= "</a></span>"; |
| 183 | 279 | |
| 184 | - $button = str_get_html($html); | |
| 280 | + $button = \MaxButtons\str_get_html($html); | |
| 185 | 281 | return $button; |
| 186 | 282 | } |
| 187 | 283 | |
| 188 | 284 | public function getRemoteShareCount($share_url) |