Admin Menu Tree Page View - Version 1.6

Version Description

  • Fixed: post titles where not escaped.
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin Admin Menu Tree Page View
Version 1.6
Comparing to
See all releases

Code changes from version 1.5 to 1.6

Files changed (4) hide show
  1. css/styles.css +10 -0
  2. index.php +165 -4
  3. js/scripts.js +72 -1
  4. readme.txt +4 -1
css/styles.css CHANGED
@@ -565,4 +565,14 @@ ul.admin-menu-tree-page-tree span.child-count {
565
 
566
  ul.amtpv-editpopup-addpages-names-ul .ui-state-highlight {
567
  display: block;
 
 
 
 
 
 
 
 
 
 
568
  }
565
 
566
  ul.amtpv-editpopup-addpages-names-ul .ui-state-highlight {
567
  display: block;
568
+ }
569
+
570
+ .amtpv-draghandle {
571
+ display: none;
572
+ position: absolute;
573
+ width: 7px;
574
+ height: 8px;
575
+ left: 0;
576
+ top: 5px;
577
+ background: transparent url(https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/ui-darkness/images/ui-icons_222222_256x240.png) no-repeat -5px -228px;
578
  }
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Admin Menu Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/admin-menu-tree-page-view/
5
  Description: Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
6
- Version: 1.5
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -29,10 +29,11 @@ add_action("admin_head", "admin_menu_tree_page_view_admin_head");
29
  add_action('admin_menu', 'admin_menu_tree_page_view_admin_menu');
30
  add_action("admin_init", "admin_menu_tree_page_view_admin_init");
31
  add_action('wp_ajax_admin_menu_tree_page_view_add_page', 'admin_menu_tree_page_view_add_page');
 
32
 
33
  function admin_menu_tree_page_view_admin_init() {
34
 
35
- define( "admin_menu_tree_page_view_VERSION", "1.5" );
36
  define( "admin_menu_tree_page_view_URL", WP_PLUGIN_URL . '/admin-menu-tree-page-view/' );
37
  define( "admin_menu_tree_page_view_DIR", WP_PLUGIN_DIR . '/admin-menu-tree-page-view/' );
38
 
@@ -77,6 +78,7 @@ function admin_menu_tree_page_view_get_pages($args) {
77
  foreach ($pages as $one_page) {
78
  $edit_link = get_edit_post_link($one_page->ID);
79
  $title = get_the_title($one_page->ID);
 
80
 
81
  // add num of children to the title
82
  $post_children = get_children(array(
@@ -150,11 +152,15 @@ function admin_menu_tree_page_view_get_pages($args) {
150
 
151
  // add the view link, hidden, used in popup
152
  $permalink = get_permalink($one_page->ID);
153
- $output .= "<span class='admin-menu-tree-page-view-view-link'>$permalink</span>";
154
- $output .= "<span class='admin-menu-tree-page-view-edit'></span>";
 
 
 
155
 
156
  $output .= "</a>";
157
 
 
158
  // popup edit div
159
  $output .= "
160
  <div class='amtpv-editpopup'>
@@ -379,3 +385,158 @@ function admin_menu_tree_page_view_add_page() {
379
  #print_r($post_new);
380
  exit;
381
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  Plugin Name: Admin Menu Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/admin-menu-tree-page-view/
5
  Description: Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
6
+ Version: 1.6
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
29
  add_action('admin_menu', 'admin_menu_tree_page_view_admin_menu');
30
  add_action("admin_init", "admin_menu_tree_page_view_admin_init");
31
  add_action('wp_ajax_admin_menu_tree_page_view_add_page', 'admin_menu_tree_page_view_add_page');
32
+ add_action('wp_ajax_admin_menu_tree_page_view_move_page', 'admin_menu_tree_page_view_move_page');
33
 
34
  function admin_menu_tree_page_view_admin_init() {
35
 
36
+ define( "admin_menu_tree_page_view_VERSION", "1.6" );
37
  define( "admin_menu_tree_page_view_URL", WP_PLUGIN_URL . '/admin-menu-tree-page-view/' );
38
  define( "admin_menu_tree_page_view_DIR", WP_PLUGIN_DIR . '/admin-menu-tree-page-view/' );
39
 
78
  foreach ($pages as $one_page) {
79
  $edit_link = get_edit_post_link($one_page->ID);
80
  $title = get_the_title($one_page->ID);
81
+ $title = esc_html($title);
82
 
83
  // add num of children to the title
84
  $post_children = get_children(array(
152
 
153
  // add the view link, hidden, used in popup
154
  $permalink = get_permalink($one_page->ID);
155
+ // $output .= "<span class='admin-menu-tree-page-view-view-link'>$permalink</span>";
156
+ // $output .= "<span class='admin-menu-tree-page-view-edit'></span>";
157
+
158
+ // drag handle
159
+ $output .= "<span class='amtpv-draghandle'></span>";
160
 
161
  $output .= "</a>";
162
 
163
+
164
  // popup edit div
165
  $output .= "
166
  <div class='amtpv-editpopup'>
385
  #print_r($post_new);
386
  exit;
387
  }
388
+
389
+
390
+
391
+ // move a post up or down
392
+ // code from our internal theme, "ma-theme"
393
+ function admin_menu_tree_page_view_move_page() {
394
+
395
+ /*
396
+ Array ( [action] => admin_menu_tree_page_view_move_page [post_to_update_id] => 567 [direction] => down )
397
+ */
398
+
399
+ // fetch all info we need from $_GET-params
400
+ $post_to_update_id = (int) $_POST["post_to_update_id"];
401
+ $direction = $_POST["direction"];
402
+ $post_to_update = get_post($post_to_update_id);
403
+
404
+ // get all posts with the same parent as our article
405
+ $args = array(
406
+ "post_type" => $post_to_update->post_type,
407
+ "orderby" => "menu_order",
408
+ "order" => "ASC",
409
+ "post_parent" => $post_to_update->post_parent,
410
+ "post_status" => "any",
411
+ "numberposts" => -1
412
+ );
413
+ $posts = get_posts($args);
414
+
415
+ if ($direction == "down") {
416
+
417
+ // let's move the article down
418
+ // update menu order of all pages
419
+ /*
420
+
421
+ 1 Page A
422
+ 2 Page B
423
+ 5 Page C <- flytta
424
+ 7 Page D <- menu_order inte alltid vårt menu_order +1, kan "glappa" liksom
425
+ 8 Page E
426
+ 9 Page F
427
+
428
+ Ta reda på aktuellt menu_order
429
+ Ta reda på efterföljande posts menu_order
430
+ Byt plats på menu_order på vald artikel + efterföljande artikel
431
+
432
+ */
433
+
434
+ // loop until we find our post
435
+ $did_find_post = false;
436
+ foreach ($posts as $one_post) {
437
+ if ($one_post->ID == $post_to_update->ID) {
438
+ $did_find_post = true;
439
+ break;
440
+ }
441
+ }
442
+
443
+ if ($did_find_post) {
444
+ // cool, we found our post
445
+ // but do we have a next post too?
446
+ $post_next = current($posts); // not next() as I thought first
447
+ if ($post_next) {
448
+ // yep, got the next one
449
+
450
+ // there can be situations where both posts have the same menu_order
451
+ // it that case, increase the menu_order of all posts above and including our next post
452
+ // and then do the swap
453
+ // clean_post_cache( $id ) ?
454
+ if ($post_to_update->menu_order == $post_next->menu_order) {
455
+ // echo "<p>Both posts have the same menu_order. Updating menu_order for all posts that are after post_next...</p>";
456
+
457
+ // first update menu_order of the next post
458
+ $post_next->menu_order++;
459
+ wp_update_post(array(
460
+ "ID" => $post_next->ID,
461
+ "menu_order" => $post_next->menu_order
462
+ ));
463
+
464
+ // and then loop through the rest of the posts in $posts
465
+ $one_post = null;
466
+ while ($one_post = next($posts)) {
467
+ wp_update_post(array(
468
+ "ID" => $one_post->ID,
469
+ "menu_order" => $one_post->menu_order + 1
470
+ ));
471
+ }
472
+ }
473
+
474
+ // now swap the order of our posts
475
+ wp_update_post(array(
476
+ "ID" => $post_to_update->ID,
477
+ "menu_order" => $post_next->menu_order
478
+ ));
479
+ wp_update_post(array(
480
+ "ID" => $post_next->ID,
481
+ "menu_order" => $post_to_update->menu_order
482
+ ));
483
+
484
+ }
485
+ }
486
+
487
+ // echo "move down";
488
+
489
+ } elseif ($direction == "up") {
490
+
491
+ // echo "move up";
492
+
493
+ /*
494
+ Move article up
495
+
496
+ 0 Page A
497
+ 1 Page B
498
+ 2 Page C
499
+
500
+ 2 Page B
501
+ 5 Page B <- kan ha samma menu_order..
502
+ 5 Page C <- menu_order inte alltid vårt menu_order -1, kan "glappa"
503
+ 7 Page D <- flytta
504
+ 8 Page E
505
+ 9 Page F
506
+
507
+ Ta reda på aktuellt menu_order
508
+ Ta reda på föregående posts menu_order
509
+ Byt plats på menu_order på vald artikel + föregående artikel
510
+
511
+ */
512
+
513
+ // find our post and also find the previous post
514
+ $prev_post = null;
515
+ $found_post = false;
516
+ foreach ($posts as $one_post) {
517
+ if ($one_post->ID == $post_to_update->ID) {
518
+ $found_post = true;
519
+ break;
520
+ }
521
+ $prev_post = $one_post;
522
+ }
523
+
524
+ if ($found_post && $prev_post) {
525
+ // swap the order of our posts
526
+ wp_update_post(array(
527
+ "ID" => $post_to_update->ID,
528
+ "menu_order" => $prev_post->menu_order
529
+ ));
530
+ wp_update_post(array(
531
+ "ID" => $prev_post->ID,
532
+ "menu_order" => $post_to_update->menu_order
533
+ ));
534
+ } else {
535
+ // nah, don't do it!
536
+ }
537
+ } // if direction
538
+
539
+ echo 1;
540
+ die();
541
+
542
+ } // move post
js/scripts.js CHANGED
@@ -247,7 +247,6 @@ jQuery(function($) {
247
  });
248
 
249
  // add new page-link
250
- // @TODO:
251
  $("div.amtpv-editpopup-addpages-addpage a").live("click", function(e) {
252
  e.preventDefault();
253
  var t = $(this);
@@ -347,6 +346,78 @@ jQuery(function($) {
347
  });
348
 
349
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  });
352
 
247
  });
248
 
249
  // add new page-link
 
250
  $("div.amtpv-editpopup-addpages-addpage a").live("click", function(e) {
251
  e.preventDefault();
252
  var t = $(this);
346
  });
347
 
348
  });
349
+
350
+ // make the tree sortable
351
+ $("ul.admin-menu-tree-page-tree, ul.admin-menu-tree-page-tree ul").sortable({
352
+ "axis": "y",
353
+ "containment": 'parent',
354
+ "forceHelperSize": true,
355
+ "forcePlaceholderSize": true,
356
+ "delay": 20,
357
+ "distance": 5,
358
+ "xhandle": "span.amtpv-draghandle",
359
+ "revert": true,
360
+ "start": function(event, ui) {
361
+ var li = $(ui.item);
362
+ //console.log("index start", li.index());
363
+ li.data("startindex", li.index());
364
+ },
365
+ "update": function(event, ui) {
366
+ console.log(event);
367
+ console.log(ui);
368
+ /*
369
+ ui.item <- the post that was moved
370
+ send post id to server, with info about post above or under, depending on if there is a post above/under
371
+ */
372
+ var li = $(ui.item);
373
+ var a = li.find("a:first");
374
+ var post_id = a.data("post-id");
375
+
376
+ //console.log("index update", li.index());
377
+ // check if we have a post above
378
+ /*
379
+ var prev = li.prev();
380
+ var aboveOrNextItem;
381
+ var aboveOrNext;
382
+ if (prev.length > 0) {
383
+ aboveOrNextItem = prev;
384
+ aboveOrNext = "above";
385
+ } else {
386
+ // ... or below
387
+ var next = li.next();
388
+ aboveOrNextItem = next;
389
+ aboveOrNext = "below";
390
+ }
391
+
392
+ // get id of above or below post
393
+ var aboveOrNextPostID = $(aboveOrNextItem).find("a:first").data("post-id");
394
+ */
395
+
396
+ // ok, i thought wrong. we "only" need to find the direction instead!
397
+ // flytt upp = start > update
398
+ // flytt ner = start < update
399
+ var startindex = li.data("startindex");
400
+ var updateindex = li.index();
401
+ var direction;
402
+ if (startindex > updateindex) {
403
+ direction = "up";
404
+ } else {
405
+ direction = "down";
406
+ }
407
+ //console.log("direction", direction);
408
+
409
+ // now we have all we need, tell the server to do the move
410
+ $.post(ajaxurl, {
411
+ "action": "admin_menu_tree_page_view_move_page",
412
+ "post_to_update_id": post_id,
413
+ "direction": direction
414
+ }, function(data) {
415
+ console.log(data);
416
+ });
417
+
418
+ }
419
+ });
420
+
421
 
422
  });
423
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: admin, page, pages, tree, view, admin menu, menu
5
  Requires at least: 3.0
6
  Tested up to: 3.0
7
- Stable tag: 1.5
8
 
9
  Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
10
 
@@ -41,6 +41,9 @@ Now the tree with the pages will be visible in the admin menu to the left.
41
 
42
  == Changelog ==
43
 
 
 
 
44
  = 1.5 =
45
  - Could not edit names in Chrome
46
  - Removed add page-link. pages are instead added automatically. no more clicks; I think feels so much more effective.
4
  Tags: admin, page, pages, tree, view, admin menu, menu
5
  Requires at least: 3.0
6
  Tested up to: 3.0
7
+ Stable tag: 1.6
8
 
9
  Get a tree view of all your pages directly in the admin menu. Search, edit, view and add pages - all with just one click away!
10
 
41
 
42
  == Changelog ==
43
 
44
+ = 1.6 =
45
+ - Fixed: post titles where not escaped.
46
+
47
  = 1.5 =
48
  - Could not edit names in Chrome
49
  - Removed add page-link. pages are instead added automatically. no more clicks; I think feels so much more effective.