| @@ -43,9 +43,9 @@ | ||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | 46 | // add a maxfield to be displayed on the admin. |
| 47 | - public function addfield($field, $start = '', $end = '') | |
| 47 | + public function addfield( $field, $start = '', $end = '') | |
| 48 | 48 | { |
| 49 | 49 | $field_id = isset($field->id) ? $field->id : $field->template . \rand(0,1000); |
| 50 | 50 | |
| 51 | 51 | $field->publish = false; // Output fields via class - never output. |
| @@ -55,65 +55,11 @@ | ||
| 55 | 55 | 'end' => $end); |
| 56 | 56 | $this->fields = apply_filters('mb/editor/addfield', $this->fields, $field); |
| 57 | 57 | |
| 58 | 58 | $this->defined_fields[] = $field_id; |
| 59 | - do_action('mb/editor/afterfield/'. $field_id, $field); | |
| 59 | + do_action('mb/editor/afterfield/'. $field_id); | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** Insert a field before or after a existing field | |
| 63 | - * | |
| 64 | - * @param String $insert_field Existing field to perform operation on | |
| 65 | - * @param Object $field The new field to insert | |
| 66 | - * @param String $start Start Template | |
| 67 | - * @param String $end End template | |
| 68 | - * @param String $op Insert before of after specified insert field | |
| 69 | - */ | |
| 70 | - public function insertField($insert_field, $field, $start = 'start', $end = 'end', $op = 'before') | |
| 71 | - { | |
| 72 | - $insert_pos = 0; | |
| 73 | - | |
| 74 | - $this->addField($field, $start, $end); // add the field to the array | |
| 75 | - | |
| 76 | - foreach($this->fields as $field_id => $array) | |
| 77 | - { | |
| 78 | - if ($field_id == $insert_field) | |
| 79 | - { | |
| 80 | - | |
| 81 | - break; | |
| 82 | - } | |
| 83 | - $insert_pos++; | |
| 84 | - } | |
| 85 | - | |
| 86 | - // Find inserted field and remove it from array. | |
| 87 | - $new_field_id = $field->id; | |
| 88 | - $new_field_ar = $this->fields[$new_field_id]; | |
| 89 | - unset($this->fields[$new_field_id]); | |
| 90 | - | |
| 91 | - // Find position to insert new field | |
| 92 | - // Yes this could be more efficient. | |
| 93 | - $new_fields = array(); | |
| 94 | - $i = 0; | |
| 95 | - foreach($this->fields as $field_id => $array) | |
| 96 | - { | |
| 97 | - if ($i == $insert_pos && $op == 'before') | |
| 98 | - { | |
| 99 | - $new_fields[$new_field_id] = $new_field_ar; | |
| 100 | - } | |
| 101 | - $new_fields[$field_id] = $array; | |
| 102 | - if ($i == $insert_pos && $op == 'after') | |
| 103 | - { | |
| 104 | - $new_fields[$new_field_id] = $new_field_ar; | |
| 105 | - } | |
| 106 | - $i++; | |
| 107 | - } | |
| 108 | - $this->fields = $new_fields; | |
| 109 | - } | |
| 110 | - | |
| 111 | - public function getFields() | |
| 112 | - { | |
| 113 | - return $this->fields; | |
| 114 | - } | |
| 115 | - | |
| 116 | 62 | public function display_fields($clean = true, $return = false) |
| 117 | 63 | { |
| 118 | 64 | $fields = apply_filters('mb/display_fields', $this->fields); |
| 119 | 65 | $output = ''; |
| @@ -200,8 +146,9 @@ | ||
| 200 | 146 | $sql = "SELECT id FROM " . maxUtils::get_table_name() . " WHERE status = '%s'"; |
| 201 | 147 | if ($args["orderby"] != '') |
| 202 | 148 | { |
| 203 | 149 | $sql .= " ORDER BY $orderby $order"; |
| 150 | + | |
| 204 | 151 | } |
| 205 | 152 | |
| 206 | 153 | if ($limit > 0) |
| 207 | 154 | { |
| @@ -217,8 +164,9 @@ | ||
| 217 | 164 | $sql = $this->wpdb->prepare($sql,$escape); |
| 218 | 165 | |
| 219 | 166 | $buttons = $this->wpdb->get_results($sql, ARRAY_A); |
| 220 | 167 | |
| 168 | + | |
| 221 | 169 | return $buttons; |
| 222 | 170 | |
| 223 | 171 | } |
| 224 | 172 | |
| @@ -292,29 +240,29 @@ | ||
| 292 | 240 | |
| 293 | 241 | return $return; |
| 294 | 242 | } |
| 295 | 243 | |
| 296 | - static public function getAjaxButtons($post) | |
| 244 | + static function getAjaxButtons() | |
| 297 | 245 | { |
| 298 | 246 | |
| 299 | 247 | $admin = self::getInstance(); |
| 300 | 248 | $args = array(); |
| 301 | 249 | |
| 302 | - $paged = (isset($post["page"])) ? intval($post["page"]) : 1; | |
| 250 | + $paged = (isset($_REQUEST["paged"])) ? intval($_REQUEST["paged"]) : 1; | |
| 303 | 251 | if ($paged > 0) |
| 304 | 252 | $args["paged" ] = $paged; |
| 305 | 253 | |
| 306 | - $button = MB()->getClass('button'); | |
| 254 | + | |
| 255 | + $button = new MaxButton(); | |
| 307 | 256 | $buttons = $admin->getButtons($args); |
| 308 | 257 | |
| 309 | - ob_start(); | |
| 310 | - echo "<div class='ajax-content'>"; | |
| 258 | + echo "<div id='maxbuttons'><div class='preview-buttons'>"; | |
| 311 | 259 | |
| 312 | -// echo '<div class="tablenav top"> '; | |
| 260 | + echo '<div class="tablenav top"> '; | |
| 313 | 261 | echo "<span class='hint'>" . __('Click on a button to select it and add the shortcode to the editor', 'maxbuttons') . "</span>"; |
| 314 | - do_action('mb-display-pagination', $args, 'top'); | |
| 262 | + do_action('mb-display-pagination', $args); | |
| 315 | 263 | echo '<span class="loading"></span>'; |
| 316 | -// echo '</div>'; | |
| 264 | + echo '</div>'; | |
| 317 | 265 | |
| 318 | 266 | |
| 319 | 267 | if (count($buttons) == 0) |
| 320 | 268 | { |
| @@ -319,10 +267,10 @@ | ||
| 319 | 267 | if (count($buttons) == 0) |
| 320 | 268 | { |
| 321 | 269 | |
| 322 | 270 | $url = admin_url('admin.php?page=maxbuttons-controller&action=edit'); |
| 323 | - echo "<h3 class='nobuttons-header'>" . __("You didn't create any buttons yet!","maxbuttons") . "</h3>"; | |
| 324 | - echo "<p class='nobuttons-link'>" . sprintf(__("Click %shere%s to add one", "maxbuttons"), | |
| 271 | + echo "<p><strong>" . __("You didn't add any buttons yet!","maxbuttons") . "</strong></p>"; | |
| 272 | + echo "<P>" . sprintf(__("Click %shere%s to add one", "maxbuttons"), | |
| 325 | 273 | "<a href='$url' target='_blank'>", "</a>") . "</strong></p>"; |
| 326 | 274 | |
| 327 | 275 | } |
| 328 | 276 | |
| @@ -330,191 +278,32 @@ | ||
| 330 | 278 | { |
| 331 | 279 | |
| 332 | 280 | $button_id = $b["id"]; |
| 333 | 281 | $button->set($button_id); |
| 334 | - echo "<div class='button-list button-select' data-button='$button_id'>"; | |
| 335 | - echo "<span class='button-id'> "; | |
| 282 | + echo "<div class='button-row button-select' data-button='$button_id'>"; | |
| 283 | + echo "<span class='col col_insert'> "; | |
| 336 | 284 | |
| 337 | 285 | echo "<span class='small'>[ID: $button_id ]</span> |
| 338 | 286 | </span> "; |
| 339 | 287 | |
| 340 | - echo "<span class='button-preview'><div class='shortcode-container'>"; | |
| 288 | + echo "<span class='col col_button'><div class='shortcode-container'>"; | |
| 341 | 289 | $button->display(array("mode" => "preview", "load_css" => "inline" )); |
| 342 | 290 | echo "</div></span>"; |
| 343 | - echo "<span class='button-name'>" . $button->getName() . "</span>"; | |
| 291 | + echo "<span class='col col_name'>" . $button->getName() . "</span>"; | |
| 344 | 292 | echo "</div>"; |
| 345 | 293 | } |
| 346 | - //echo '<div class="tablenav bottom"> '; | |
| 347 | - do_action('mb-display-pagination', $args, 'bottom'); | |
| 294 | + echo '<div class="tablenav bottom"> '; | |
| 295 | + do_action('mb-display-pagination', $args); | |
| 348 | 296 | echo '<span class="loading"></span>'; |
| 349 | - //echo '</div>'; | |
| 297 | + echo '</div>'; | |
| 350 | 298 | |
| 351 | 299 | |
| 352 | - echo "</div>"; | |
| 353 | - echo "<p style='height:80px;'> </p>"; | |
| 300 | + echo "</div></div>"; | |
| 301 | + echo "<p> </p>"; | |
| 354 | 302 | |
| 355 | - $output = ob_get_contents(); | |
| 356 | - ob_end_clean(); | |
| 357 | - | |
| 358 | - $result = array('output' => $output, | |
| 359 | - 'action' => 'buttons_load'); | |
| 360 | - | |
| 361 | - echo json_encode($result); | |
| 362 | - | |
| 363 | 303 | exit(); |
| 364 | 304 | |
| 365 | 305 | } |
| 366 | - | |
| 367 | - | |
| 368 | - static public function mediaShortcodeOptions($post) | |
| 369 | - { | |
| 370 | - $button_id = isset($post['button_id']) ? intval($post['button_id']) : false; | |
| 371 | - | |
| 372 | - $result = array('output' => '', | |
| 373 | - 'action' => 'shortcode_options'); | |
| 374 | - | |
| 375 | - $button = MB()->getClass("button"); | |
| 376 | - $button->set($button_id); | |
| 377 | - | |
| 378 | - //$data = $button->getd | |
| 379 | - | |
| 380 | - $data = array( | |
| 381 | - 'url' => maxBlocks::getValue('url'), | |
| 382 | - 'text' => maxBlocks::getValue('text'), | |
| 383 | - 'new_window' => maxBlocks::getValue('new_window'), | |
| 384 | - 'nofollow' => maxBlocks::getValue('nofollow'), | |
| 385 | - 'link_title' => maxBlocks::getValue('link_title'), | |
| 386 | - ); | |
| 387 | - | |
| 388 | - // hook spec. qtrans. | |
| 389 | - $mode = 'preview'; | |
| 390 | - $preview = true; | |
| 391 | - $compile = false; | |
| 392 | - $data = apply_filters('mb/button/data_before_display', $data, $mode, array('preview' => $preview, 'compile' => $compile) ); | |
| 393 | - | |
| 394 | - $admin = self::getInstance(); | |
| 395 | - $shortcode_data = array(); // data array to build shortcodes and check default values | |
| 396 | - | |
| 397 | - $display_args = array('echo'=> false, 'load_css' => 'inline'); | |
| 398 | - $preview = new maxField('generic'); | |
| 399 | - $preview->name = 'button-preview'; | |
| 400 | - $preview->content = '<h3>' . __('Shortcode Options') . '</h3> | |
| 401 | - <p>' . $button->display($display_args) . '</p> | |
| 402 | - <p>' . __('Change the options to add shortcode attributes. ', 'maxbuttons') . '</p>'; | |
| 403 | - | |
| 404 | - $admin->addField($preview, 'start','end'); | |
| 405 | - | |
| 406 | - $url = new maxField('text'); | |
| 407 | - $url->id = 'shortcode_url'; | |
| 408 | - $url->name = $url->id; | |
| 409 | - $url->placeholder = 'http://'; | |
| 410 | - $url->label = __('Button URL', 'maxbuttons'); | |
| 411 | - $url->value = $data['url']; | |
| 412 | - $shortcode_data[] = array( | |
| 413 | - 'name' => $url->name, | |
| 414 | - 'original' => $url->value, | |
| 415 | - 'shortcode' => 'url', | |
| 416 | - ); | |
| 417 | - | |
| 418 | - $admin->addField($url, 'start','end'); | |
| 419 | - | |
| 420 | - $text = new maxField('text'); | |
| 421 | - $text->id = 'shortcode_text'; | |
| 422 | - $text->name = $text->id; | |
| 423 | - $text->label = __('Button Text', 'maxbuttons'); | |
| 424 | - $text->value = $data['text']; | |
| 425 | - $shortcode_data[] = array( | |
| 426 | - 'name' => $text->name, | |
| 427 | - 'original' => $text->value, | |
| 428 | - 'shortcode' => 'text', | |
| 429 | - ); | |
| 430 | - | |
| 431 | - $admin->addField($text, 'start', 'end'); | |
| 432 | - | |
| 433 | - $more = new maxField('generic'); | |
| 434 | - $more->name = 'more'; | |
| 435 | - $more->content = '<div class="more-options"><a href="#">' . __('More Options', 'maxbuttons') . '</a></div>'; | |
| 436 | - | |
| 437 | - $admin->addField($more, 'start', 'end'); | |
| 438 | - | |
| 439 | - $new_window = new maxField('checkbox'); | |
| 440 | - $new_window->id = 'shortcode_window'; | |
| 441 | - $new_window->name = $new_window->id; | |
| 442 | - $new_window->label = __('Open in New Window', 'maxbuttons'); | |
| 443 | - $new_window->value = 1; | |
| 444 | - $new_window->main_class = 'option more-field'; | |
| 445 | - $new_window->checked = checked( $data['new_window'], 1, false); | |
| 446 | - $shortcode_data[] = array( | |
| 447 | - 'name' => $new_window->name, | |
| 448 | - 'original' => ( $data['new_window'] == 1) ? true : false, | |
| 449 | - 'shortcode' => 'window', | |
| 450 | - 'checked' => 'new', | |
| 451 | - 'unchecked' => 'same', | |
| 452 | - ); | |
| 453 | - | |
| 454 | - $admin->addField($new_window, 'start', 'end'); | |
| 455 | - | |
| 456 | - $ffollow = new maxField('checkbox'); | |
| 457 | - $ffollow->label = __('Use rel="nofollow"', 'maxbuttons'); | |
| 458 | - $ffollow->value = 1; | |
| 459 | - $ffollow->name = 'shortcode_nofollow'; | |
| 460 | - $ffollow->id = $ffollow->name; | |
| 461 | - $ffollow->main_class = 'option more-field'; | |
| 462 | - $ffollow->checked = checked( $data['nofollow'] , 1, false); | |
| 463 | - $shortcode_data[] = array( | |
| 464 | - 'name' => $ffollow->name, | |
| 465 | - 'original' => ( $data['nofollow'] == 1) ? true : false, | |
| 466 | - 'shortcode' => 'nofollow', | |
| 467 | - 'checked' => 'true', | |
| 468 | - 'unchecked' => 'false', | |
| 469 | - ); | |
| 470 | - | |
| 471 | - | |
| 472 | - $admin->addField($ffollow, 'start','end'); | |
| 473 | - | |
| 474 | - $field_title = new maxField('text'); | |
| 475 | - $field_title->label = __('Button Tooltip', 'maxbuttons'); | |
| 476 | - $field_title->name = 'shortcode_link_title'; // title is too generic | |
| 477 | - $field_title->id = $field_title->name; | |
| 478 | - $field_title->main_class = 'option more-field'; | |
| 479 | - $field_title->value = $data['link_title']; | |
| 480 | - | |
| 481 | - $shortcode_data[] = array( | |
| 482 | - 'name' => $field_title->name, | |
| 483 | - 'original' => $field_title->value, | |
| 484 | - 'shortcode' => 'linktitle', | |
| 485 | - ); | |
| 486 | - | |
| 487 | - $admin->addField($field_title, 'start','end'); | |
| 488 | - | |
| 489 | - $class = new maxField(); | |
| 490 | - $class->id = 'shortcode_extra_classes'; | |
| 491 | - $class->name = $class->id; | |
| 492 | - $class->label = __("Extra classes","maxbuttons"); | |
| 493 | - $class->value = ''; | |
| 494 | - $class->main_class = 'option more-field'; | |
| 495 | - | |
| 496 | - $shortcode_data[] = array( | |
| 497 | - 'name' => $class->name, | |
| 498 | - 'original' => $class->value, | |
| 499 | - 'shortcode' => 'extraclass', | |
| 500 | - ); | |
| 501 | - | |
| 502 | - $admin->addField($class, 'start', 'end'); | |
| 503 | - | |
| 504 | - $shortcode_data = apply_filters('mb/media/shortcode_data', $shortcode_data); | |
| 505 | - | |
| 506 | - $result['output'] = '<div class="ajax-content shortcode-options">' . $admin->display_fields(true,true) . '</div>'; | |
| 507 | - $result['shortcodeData'] = $shortcode_data; | |
| 508 | - $result['button_id'] = $button_id; | |
| 509 | - | |
| 510 | - echo json_encode($result); | |
| 511 | - | |
| 512 | - exit(); | |
| 513 | - | |
| 514 | - } | |
| 515 | - | |
| 516 | - | |
| 517 | 306 | function get_header($args =array() ) |
| 518 | 307 | { |
| 519 | 308 | $defaults = array( |
| 520 | 309 | "tabs_active" => false, |
| @@ -570,9 +359,9 @@ | ||
| 570 | 359 | if (! is_dir($dir)) |
| 571 | 360 | return false; |
| 572 | 361 | |
| 573 | 362 | $file = fopen( trailingslashit($dir) . "/maxbuttons.log", "a+"); |
| 574 | - $now = new \DateTime(); | |
| 363 | + $now = new DateTime() ; | |
| 575 | 364 | $now_format = $now->format("d/M/Y H:i:s"); |
| 576 | 365 | |
| 577 | 366 | $write_string = "[" . $now_format . "] $action - $message ( $caller )"; |
| 578 | 367 | fwrite($file, $write_string); |