| @@ -137,8 +137,26 @@ | ||
| 137 | 137 | else |
| 138 | 138 | return false; // no binds, don't check. |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + // When MB PRO is configured to output CSS via file. | |
| 142 | + static function outputFileCSS() | |
| 143 | + { | |
| 144 | + $collection_id = intval($_GET['id']); | |
| 145 | + $doc_id = intval($_GET['doc']); | |
| 146 | + $collection = new collection($collection_id); | |
| 147 | + $css = $collection->getDisplayCSS($doc_id); | |
| 148 | + header( "Content-type: text/css; charset: UTF-8" ); | |
| 149 | + | |
| 150 | + if ($css) | |
| 151 | + { | |
| 152 | + header( "Content-type: text/css; charset: UTF-8" ); | |
| 153 | + echo $css; | |
| 154 | + } | |
| 155 | + exit(); | |
| 156 | + | |
| 157 | + } | |
| 158 | + | |
| 141 | 159 | /* Try to find the current place we are at in the site ( front / blog / page etc ) .*/ |
| 142 | 160 | protected static function getCurrentHook() |
| 143 | 161 | { |
| 144 | 162 | $hook = ''; |
| @@ -159,24 +177,25 @@ | ||
| 159 | 177 | { |
| 160 | 178 | $hook = "display_archive"; |
| 161 | 179 | } |
| 162 | 180 | |
| 163 | - $post_types = \get_post_types( | |
| 164 | - array('public' => true, | |
| 165 | - '_builtin' => false, | |
| 166 | - ) | |
| 167 | - ); | |
| 181 | + $post_types = \get_post_types( | |
| 182 | + array('public' => true, | |
| 183 | + '_builtin' => false, | |
| 184 | + ) | |
| 185 | + ); | |
| 168 | 186 | |
| 169 | - $this_post_type = get_post_type( get_the_ID() ); | |
| 187 | + $this_post_type = get_post_type( get_the_ID() ); | |
| 170 | 188 | |
| 171 | - foreach($post_types as $post_type) // custom post type | |
| 172 | - { | |
| 173 | - if ($post_type == $this_post_type) | |
| 189 | + foreach($post_types as $post_type) // custom post type | |
| 174 | 190 | { |
| 175 | - $hook = 'display_' . $this_post_type; | |
| 191 | + if ($post_type == $this_post_type) | |
| 192 | + { | |
| 193 | + $hook = 'display_' . $this_post_type; | |
| 194 | + } | |
| 195 | + | |
| 176 | 196 | } |
| 177 | 197 | |
| 178 | - } | |
| 179 | 198 | |
| 180 | 199 | return $hook; |
| 181 | 200 | } |
| 182 | 201 | |
| @@ -265,11 +284,26 @@ | ||
| 265 | 284 | parse_str($form, $post_form); |
| 266 | 285 | |
| 267 | 286 | $collection_id = intval($post_form["collection_id"]); |
| 268 | 287 | |
| 269 | - $admin = MB()->getClass('admin'); | |
| 288 | + $admin = MB()->getClass('admin'); | |
| 289 | + $collection = new collection(); | |
| 270 | 290 | |
| 271 | 291 | |
| 292 | + if (! Install::isPro() && $collection_id == 0) | |
| 293 | + { | |
| 294 | + $collections = self::getCollections(); | |
| 295 | + if (count($collections) > 0) | |
| 296 | + { | |
| 297 | + $result = array( | |
| 298 | + "error" => true, | |
| 299 | + ); | |
| 300 | + $collection->endAjaxRequest($result); | |
| 301 | + } | |
| 302 | + } | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 272 | 306 | $close_text = __('Close', 'maxbuttons'); |
| 273 | 307 | |
| 274 | 308 | $result = array( |
| 275 | 309 | "error" => false, |
| @@ -280,15 +314,10 @@ | ||
| 280 | 314 | "new_nonce" => 0, |
| 281 | 315 | "title" => __("Saved!","mbsocial"), |
| 282 | 316 | ); |
| 283 | 317 | |
| 284 | - | |
| 285 | - | |
| 286 | - | |
| 287 | - $collection = new collection(); | |
| 288 | 318 | $collection->set($collection_id); |
| 289 | 319 | |
| 290 | - | |
| 291 | 320 | // this can be a new id (!) |
| 292 | 321 | $collection_id = $collection->save($post_form); |
| 293 | 322 | |
| 294 | 323 | $result["data"]["id"] = $collection_id; |
| @@ -297,17 +326,40 @@ | ||
| 297 | 326 | // $result["data"]["reload"] = apply_filters("collections_ajax_force_reload",$force_reload); |
| 298 | 327 | |
| 299 | 328 | // $result["title"] = $result_title["success"]; |
| 300 | 329 | |
| 301 | - $admin->endAjaxRequest($result); | |
| 330 | + $collection->endAjaxRequest($result); | |
| 331 | + } | |
| 302 | 332 | |
| 303 | - //echo json_encode($result); | |
| 304 | - //exit(); | |
| 305 | - } | |
| 333 | + static function ajax_remove_collection() | |
| 334 | + { | |
| 335 | + $admin = MB()->getClass('admin'); | |
| 306 | 336 | |
| 337 | + $collection_id = intval($_POST['param']); | |
| 338 | + $collection = new collection(); | |
| 339 | + | |
| 340 | + | |
| 341 | + $url = admin_url('?page=maxbuttons-social'); | |
| 342 | + | |
| 343 | + $result = array( | |
| 344 | + 'error' => false, | |
| 345 | + 'redirect' => $url, | |
| 346 | + ); | |
| 347 | + | |
| 348 | + global $wpdb; | |
| 349 | + | |
| 350 | + $table = maxUtils::get_collection_table_name(); | |
| 351 | + $where = array("collection_id" => $collection_id); | |
| 352 | + $where_format = array("%d"); | |
| 353 | + $wpdb->delete($table, $where, $where_format); | |
| 354 | + | |
| 355 | + | |
| 356 | + $collection->endAjaxRequest($result); | |
| 357 | + | |
| 358 | + } | |
| 359 | + | |
| 307 | 360 | static function ajax_action_front() |
| 308 | 361 | { |
| 309 | - | |
| 310 | 362 | // only for trivial front page actions! |
| 311 | 363 | self::ajax_action(array("ajax_nopriv" => true)); |
| 312 | 364 | } |
| 313 | 365 | |
| @@ -316,9 +368,8 @@ | ||
| 316 | 368 | ob_start(); |
| 317 | 369 | $defaults = array("ajax_nopriv" => false); |
| 318 | 370 | $args = wp_parse_args($args, $defaults); |
| 319 | 371 | |
| 320 | - | |
| 321 | 372 | $admin = MB()->getClass('admin'); |
| 322 | 373 | |
| 323 | 374 | $nonce = isset($_POST["nonce"]) ? $_POST["nonce"] : false; |
| 324 | 375 | $block_name = sanitize_text_field($_POST["block_name"]); |
| @@ -325,14 +376,31 @@ | ||
| 325 | 376 | $block_action = sanitize_text_field($_POST["block_action"]); |
| 326 | 377 | $block_data = (isset($_POST["block_data"])) ? $_POST["block_data"] : ''; |
| 327 | 378 | $action = sanitize_text_field($_POST["action"]); |
| 328 | 379 | |
| 380 | + // Weirdly only one, but security, lets checks this without changing other code too much | |
| 381 | + $possible_actions =['mbsocial_get_count']; | |
| 382 | + | |
| 329 | 383 | $collection_id = intval($_POST["collection_id"]); |
| 384 | + $collection = new collection($collection_id); | |
| 385 | + | |
| 386 | + if (false === in_array($action, $possible_actions)) | |
| 387 | + { | |
| 388 | + $result["error"] = true; | |
| 389 | + $result["body"] = __("Bad Action","maxbuttons"); | |
| 390 | + $result["result"] = false; | |
| 391 | + $result["title"] = __("Security error","maxbuttons"); | |
| 392 | + $result["data"] = array("id" => $collection_id); | |
| 393 | + | |
| 394 | + $collection->endAjaxRequest($result); | |
| 395 | + } | |
| 396 | + | |
| 397 | + | |
| 330 | 398 | // $collection_type = sanitize_text_field($_POST["collection_type"]); |
| 331 | 399 | |
| 332 | - if(! $args["ajax_nopriv"]) | |
| 333 | - { | |
| 334 | - if (! wp_verify_nonce($nonce, $action . "-" . $collection_id)) | |
| 400 | + //if(! $args["ajax_nopriv"]) | |
| 401 | + //{ | |
| 402 | + if (! wp_verify_nonce($nonce, "maxsocial_ajax_action-" . $collection_id)) | |
| 335 | 403 | { |
| 336 | 404 | $result["error"] = true; |
| 337 | 405 | $result["body"] = __("Nonce not verified","maxbuttons"); |
| 338 | 406 | $result["result"] = false; |
| @@ -338,12 +406,12 @@ | ||
| 338 | 406 | $result["result"] = false; |
| 339 | 407 | $result["title"] = __("Security error","maxbuttons"); |
| 340 | 408 | $result["data"] = array("id" => $collection_id); |
| 341 | 409 | |
| 342 | - $admin->endAjaxRequest($result); | |
| 410 | + $collection->endAjaxRequest($result); | |
| 343 | 411 | |
| 344 | 412 | } |
| 345 | - } | |
| 413 | + //} | |
| 346 | 414 | |
| 347 | 415 | $result = array( |
| 348 | 416 | "error" => false, |
| 349 | 417 | "body" => '', |
| @@ -351,16 +419,13 @@ | ||
| 351 | 419 | "data" => array(), |
| 352 | 420 | "new_nonce" => 0, |
| 353 | 421 | ); |
| 354 | 422 | |
| 355 | - $collection = new collection($collection_id); | |
| 356 | - | |
| 357 | 423 | $result = $collection->doBlockAjax($result, $block_name, $block_action, $block_data); |
| 358 | 424 | |
| 359 | 425 | //ob_end_clean(); // prevent PHP errors from breaking JSON response. |
| 360 | 426 | |
| 361 | - $admin->endAjaxRequest($result); | |
| 362 | - $results = $collection->get_meta($name, 'collection_name'); | |
| 427 | + $collection->endAjaxRequest($result); | |
| 363 | 428 | } |
| 364 | 429 | |
| 365 | 430 | |
| 366 | 431 | public static function ajax_refreshblock() |
| @@ -520,9 +585,16 @@ | ||
| 520 | 585 | } |
| 521 | 586 | |
| 522 | 587 | $collection->saveData(); |
| 523 | 588 | |
| 524 | - echo json_encode( array('done' => true) ); | |
| 589 | + $collection_id = $collection->getID(); | |
| 590 | + $url = admin_url('?page=maxbuttons-social'); | |
| 591 | + $url = add_query_arg('social_id', $collection_id, $url); | |
| 592 | + | |
| 593 | + echo json_encode( array( | |
| 594 | + 'done' => true, | |
| 595 | + 'redirect' => $url, | |
| 596 | + ) ); | |
| 525 | 597 | exit(); |
| 526 | 598 | |
| 527 | 599 | } |
| 528 | 600 | |
| @@ -533,9 +605,9 @@ | ||
| 533 | 605 | global $wpdb; |
| 534 | 606 | |
| 535 | 607 | $table = maxUtils::get_collection_table_name(); |
| 536 | 608 | |
| 537 | - $sql = "SELECT distinct collection_id from $table WHERE collection_key = 'collection_type' and collection_value = 'social_share' "; | |
| 609 | + $sql = "SELECT distinct collection_id from $table WHERE collection_key = 'collection_type' and collection_value = 'social_share' order by collection_id "; | |
| 538 | 610 | |
| 539 | 611 | $results = $wpdb->get_col($sql); |
| 540 | 612 | return $results; |
| 541 | 613 | } |