| @@ -17,12 +17,15 @@ | ||
| 17 | 17 | |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | // add a maxfield to be displayed on the admin. |
| 21 | - public function addfield( $field, $start = '', $end = '') | |
| 21 | + public function addfield( $field, $start = '', $end = '', $trigger_update = true) | |
| 22 | 22 | { |
| 23 | 23 | $field_id = isset($field->id) ? $field->id : $field->template . \rand(0,1000); |
| 24 | - | |
| 24 | + if ($trigger_update) | |
| 25 | + { | |
| 26 | + $this->addUpdate($field); // make updating standard | |
| 27 | + } | |
| 25 | 28 | $field->publish = false; // Output fields via class - never output. |
| 26 | 29 | |
| 27 | 30 | $this->fields[$field_id] = array('field' => $field, |
| 28 | 31 | 'start' => $start, |
| @@ -35,11 +38,16 @@ | ||
| 35 | 38 | |
| 36 | 39 | public function addUpdate($field) |
| 37 | 40 | { |
| 38 | 41 | $field_id = $field->id; |
| 39 | - $this->defined_updatable[] = $field_id; | |
| 42 | + if (is_null($field_id) || $field_id == '') | |
| 43 | + return; // no bad names | |
| 44 | + | |
| 45 | + if (! isset($this->defined_updatable[$field_id])) // no double sets | |
| 46 | + $this->defined_updatable[] = $field_id; | |
| 40 | 47 | } |
| 41 | 48 | |
| 49 | + | |
| 42 | 50 | public function namespaceit($var) |
| 43 | 51 | { |
| 44 | 52 | return self::$namespace . $var; |
| 45 | 53 | } |
| @@ -48,9 +56,8 @@ | ||
| 48 | 56 | { |
| 49 | 57 | $fields = apply_filters('mbsocial/display_fields', $this->fields); |
| 50 | 58 | $output = ''; |
| 51 | 59 | |
| 52 | - | |
| 53 | 60 | foreach($fields as $id => $item) |
| 54 | 61 | { |
| 55 | 62 | $field = $item['field']; |
| 56 | 63 | $output .= $field->output($item['start'], $item['end']); |
| @@ -55,10 +62,8 @@ | ||
| 55 | 62 | $field = $item['field']; |
| 56 | 63 | $output .= $field->output($item['start'], $item['end']); |
| 57 | 64 | } |
| 58 | 65 | |
| 59 | - | |
| 60 | - | |
| 61 | 66 | // auto-update system |
| 62 | 67 | $updatable = $this->defined_updatable; |
| 63 | 68 | foreach($updatable as $index => $field) |
| 64 | 69 | { |
| @@ -90,36 +95,55 @@ | ||
| 90 | 95 | |
| 91 | 96 | /** @param $active_networks - Networks that were saved by the users. This should be loaded instead of the default ones **/ |
| 92 | 97 | public function get_default_networks($active_networks = array() ) |
| 93 | 98 | { |
| 99 | + if (! is_array($active_networks)) | |
| 100 | + { | |
| 101 | + $active_networks = array(); | |
| 102 | + } | |
| 94 | 103 | $networks = mbSocial()->networks()->get(); |
| 95 | - | |
| 96 | 104 | $selected = array(); |
| 97 | 105 | $unselected = array(); |
| 98 | 106 | $readmore = array(); |
| 99 | 107 | |
| 108 | + // set active networks. Support doubles. | |
| 109 | + foreach($active_networks as $index => $network_name) | |
| 110 | + { | |
| 111 | + $network = mbSocial()->networks()->get($network_name); | |
| 112 | + if (! is_object($network)) // could be removed network. | |
| 113 | + continue; | |
| 114 | + if ($network->get('is_active')) | |
| 115 | + $selected[$index] = $network; | |
| 116 | + } | |
| 117 | + | |
| 100 | 118 | foreach($networks as $index => $network) |
| 101 | 119 | { |
| 102 | 120 | $priority = $network->get('priority'); |
| 121 | + if (! $network->get('is_active')) | |
| 122 | + { continue; } | |
| 103 | 123 | $is_active = array_search($network->get('network'), $active_networks); // retrieve the array index |
| 104 | 124 | |
| 105 | 125 | if ($is_active !== false) |
| 126 | + { | |
| 106 | 127 | $priority = 'selected'; |
| 128 | + } | |
| 107 | 129 | |
| 108 | - if ($priority == 'selected') | |
| 109 | - $selected[$is_active] = $network; | |
| 110 | 130 | if ($priority == 'unselected') |
| 111 | 131 | $unselected[] = $network; |
| 112 | 132 | if ($priority == 'readmore') |
| 113 | 133 | $readmore[] = $network; |
| 114 | 134 | |
| 135 | + if ($network->get('network') == 'maxbutton' && $priority != 'readmore') // exceptions | |
| 136 | + { | |
| 115 | 137 | |
| 116 | - } | |
| 138 | + $readmore[] = $network; | |
| 139 | + } | |
| 117 | 140 | |
| 118 | 141 | |
| 142 | + } // foreach networks | |
| 143 | + | |
| 119 | 144 | // Sort networks by order saved. |
| 120 | 145 | ksort($selected); |
| 121 | - | |
| 122 | 146 | return array('selected' => $selected, 'unselected' => $unselected, 'readmore' => $readmore); |
| 123 | 147 | } |
| 124 | 148 | |
| 125 | 149 | |
| @@ -130,8 +154,110 @@ | ||
| 130 | 154 | $networks_array = $this->get_default_networks($active_networks); |
| 131 | 155 | return $networks_array; |
| 132 | 156 | } |
| 133 | 157 | |
| 158 | + // render icons with input from different icon libraries (/future) | |
| 159 | + public function renderIcon($args) | |
| 160 | + { | |
| 161 | + $defaults = array('icon' => '', | |
| 162 | + 'icon_type' => '', | |
| 163 | + 'icon_size' => 20, | |
| 164 | + 'title' => '', | |
| 165 | + ); | |
| 166 | + | |
| 167 | + $args = wp_parse_args($args, $defaults); | |
| 168 | + | |
| 169 | + $icon_type = $args['icon_type']; | |
| 170 | + $icon = $args['icon']; | |
| 171 | + $icon_size = $args['icon_size']; | |
| 172 | + $title = $args['title']; | |
| 173 | + | |
| 174 | + $faUtils = FAUtils::getInstance(); | |
| 175 | + | |
| 176 | + switch($icon_type) | |
| 177 | + { | |
| 178 | + case 'fa': // FA5 | |
| 179 | + case 'fab': | |
| 180 | + case 'fas': | |
| 181 | + case 'far': | |
| 182 | + $args = array('icon' => trim($icon_type) . ' ' . trim($icon), 'title' => $title); | |
| 183 | + if ($icon_size) | |
| 184 | + { | |
| 185 | + $args['size'] = $icon_size; | |
| 186 | + } | |
| 187 | + | |
| 188 | + $svg = $faUtils->getFASVG($args); | |
| 189 | + $output = "<span class='mb-icon'>$svg</span>"; | |
| 190 | + break; | |
| 191 | + case 'nucleo': | |
| 192 | + $output = "<span class='mb-icon'><i class='$icon_type $icon' title='$title' > </i></span>"; | |
| 193 | + break; | |
| 194 | + case 'svg': | |
| 195 | + case 'png': // via network settings, or whatever. | |
| 196 | + $output = "<span class='mb-icon " . $icon_type . "'><img src='" . $icon . "' alt='" . $title . "'></span>"; | |
| 197 | + break; | |
| 198 | + case 'image': // via media uploader | |
| 199 | + case 'image-remote': | |
| 200 | + if ($icon_type == 'image-remote') // when loading a custom network, before import | |
| 201 | + { | |
| 202 | + $url = $args['image_url']; | |
| 203 | + $output = '<img src="' . $url . '" border="0" />'; | |
| 204 | + } | |
| 205 | + else { | |
| 206 | + $image_id = isset($args['image_id']) ? $args['image_id'] : false; | |
| 207 | + $image_size = isset($args['image_size']) ? $args['image_size'] : false; | |
| 208 | + | |
| 209 | + $img_data = wp_get_attachment_image_src($image_id, $image_size); | |
| 210 | + $output = ''; | |
| 211 | + | |
| 212 | + if ($img_data) | |
| 213 | + { | |
| 214 | + $width = $img_data[1]; | |
| 215 | + $height = $img_data[2]; | |
| 216 | + $url = $img_data[0]; | |
| 217 | + $output = '<span class="mb-icon ' . $icon_type . '"><img src="' . $url . '" width="' . $width . '" height="' . $height . '" border="0" /></span>'; | |
| 218 | + } | |
| 219 | + | |
| 220 | + } | |
| 221 | + break; | |
| 222 | + default: | |
| 223 | + $output = ''; | |
| 224 | + break; | |
| 225 | + } | |
| 226 | + | |
| 227 | + return apply_filters('display/render/icon', $output, $args); | |
| 228 | + } | |
| 229 | + | |
| 230 | + public function applyVars($string) | |
| 231 | + { | |
| 232 | + //$vars = $this->getShareData(); | |
| 233 | + $w = MBSocial()->whistle(); | |
| 234 | + | |
| 235 | + preg_match_all('/\{(.*?)\}/im', $string, $matches); | |
| 236 | + //$vars = (isset($vars[0]) && count($vars[0]) > 0) ? $vars[0] : array(); | |
| 237 | + | |
| 238 | + if (count($matches) == 0) | |
| 239 | + return $string; | |
| 240 | + | |
| 241 | + $vars = $matches[0]; // i.e. {url} | |
| 242 | + $clean_vars = $matches[1]; // i.e. url | |
| 243 | + | |
| 244 | + for($i = 0; $i < count($vars); $i++) | |
| 245 | + { | |
| 246 | + $var = $vars[$i]; | |
| 247 | + $clean_var = $clean_vars[$i]; | |
| 248 | + | |
| 249 | + if (strpos($string, $var) !== false) | |
| 250 | + { | |
| 251 | + $val = $w->ask('display/vars/' . $clean_var); | |
| 252 | + $string = str_replace($var, $val, $string); | |
| 253 | + } | |
| 254 | + | |
| 255 | + } | |
| 256 | + | |
| 257 | + return $string; | |
| 258 | + } | |
| 259 | + | |
| 134 | 260 | public function header( $args = array() ) |
| 135 | 261 | { |
| 136 | 262 | $defaults = array( |
| 137 | 263 | 'title' => '', |
| @@ -147,7 +273,92 @@ | ||
| 147 | 273 | { |
| 148 | 274 | include_once( mbSocial()->get_plugin_path() . '/admin/footer.php'); |
| 149 | 275 | } |
| 150 | 276 | |
| 277 | + public function getProMessage() | |
| 278 | + { | |
| 279 | + return __( sprintf('You can only change these settings in the PRO version. Click %shere%s for upgrading to MaxButtons PRO', ' | |
| 280 | + <a href="https://maxbuttons.com" target="_blank">', '</a>') ); | |
| 281 | + } | |
| 151 | 282 | |
| 283 | + | |
| 284 | + public function do_review_notice () { | |
| 285 | + | |
| 286 | + $current_user_id = get_current_user_id(); | |
| 287 | + $version = MBSOCIAL_VERSION_NUM; | |
| 288 | + | |
| 289 | + $review = get_user_meta( $current_user_id, 'mbsocial_review_notice' , true ); | |
| 290 | + | |
| 291 | + if ($review == '') | |
| 292 | + { | |
| 293 | + //$created = get_option("MBFREE_CREATED"); | |
| 294 | + $show = time() + (7* DAY_IN_SECONDS); | |
| 295 | + update_user_meta($current_user_id, 'mbsocial_review_notice', $show); | |
| 296 | + return; | |
| 297 | + } | |
| 298 | + | |
| 299 | + $display_review = false; | |
| 300 | + | |
| 301 | + if ($review == 'off') | |
| 302 | + { return; // no show | |
| 303 | + | |
| 304 | + } | |
| 305 | + elseif (is_numeric($review)) | |
| 306 | + { | |
| 307 | + $now = time(); | |
| 308 | + | |
| 309 | + if ($now > $review) | |
| 310 | + { | |
| 311 | + $display_review = true; | |
| 312 | + | |
| 313 | + } | |
| 314 | + } | |
| 315 | + | |
| 316 | + // load style / script. It's seperated since it should show everywhere in admin. | |
| 317 | + if ($display_review) | |
| 318 | + { | |
| 319 | + add_action( 'admin_notices', array( $this, 'mbsocial_review_notice')); | |
| 320 | + // registered in admin scripts | |
| 321 | + if (method_exists(MB(), 'load_library')) | |
| 322 | + MB()->load_library('review_notice'); | |
| 323 | + } | |
| 324 | + | |
| 325 | + } | |
| 326 | + | |
| 327 | + public function mbsocial_review_notice() | |
| 328 | + { | |
| 329 | + include_once( mbSocial()->get_plugin_path() . '/admin/review_notice.php'); | |
| 330 | + } | |
| 331 | + | |
| 332 | + public function save_review_notice() | |
| 333 | + { | |
| 334 | + $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : ''; | |
| 335 | + $current_user_id = get_current_user_id(); | |
| 336 | + | |
| 337 | + $updated = false; | |
| 338 | + | |
| 339 | + if ($status == 'off') | |
| 340 | + { | |
| 341 | + $updated = true; | |
| 342 | + update_user_meta($current_user_id, 'mbsocial_review_notice', 'off'); | |
| 343 | + | |
| 344 | + } | |
| 345 | + if ($status == 'later') | |
| 346 | + { | |
| 347 | + $updated = true; | |
| 348 | + $later = time() + (14 * DAY_IN_SECONDS ); | |
| 349 | + | |
| 350 | + update_user_meta($current_user_id, 'mbsocial_review_notice', $later); | |
| 351 | + } | |
| 352 | + if ($status == 'reviewoffer-dismiss') // different ad! | |
| 353 | + { | |
| 354 | + $updated = true; | |
| 355 | + update_user_meta($current_user_id, 'mbsocial_review_notice', 'off'); | |
| 356 | + | |
| 357 | + } | |
| 358 | + | |
| 359 | + echo json_encode(array("updated" => $updated)) ; | |
| 360 | + | |
| 361 | + exit(); | |
| 362 | + } | |
| 152 | 363 | |
| 153 | 364 | } |