CMS Tree Page View - Version 0.7.3

Version Description

  • a page can now be moved above a page with the same menu order. moved page will get the menu order of the page that it's moved aboved, and the other page will get a menu order of previous menu order + 1. i think/hope this is finaly solved now!
  • using wp_update_post when moving pages (instead of sql directly). this should make this plugin work better with some cache plugins, for example DB Cache Reloaded
  • root of tree is added initially, without the need to run an ajax query. loading the root of the tree
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin CMS Tree Page View
Version 0.7.3
Comparing to
See all releases

Code changes from version 0.7.1 to 0.7.3

Files changed (5) hide show
  1. functions.php +94 -35
  2. index.php +2 -2
  3. readme.txt +15 -6
  4. scripts/cms_tree_page_view.js +50 -2
  5. styles/styles.css +5 -0
functions.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
 
3
  // for debug, remember to comment out (yes.. i *know* i will forget this later on...)
4
- #require("FirePHPCore/FirePHP.class.php");
5
- #$firephp = FirePHP::getInstance(true);
6
 
7
  function cms_tpv_admin_head() {
8
 
@@ -18,6 +18,7 @@ function cms_tpv_admin_head() {
18
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
19
  var CMS_TPV_AJAXURL = "?action=cms_tpv_get_childs&view=";
20
  var CMS_TPV_VIEW = "<?php echo $cms_tpv_view ?>";
 
21
  /* ]]> */
22
  </script>
23
 
@@ -35,15 +36,11 @@ function cms_tpv_admin_head() {
35
 
36
  function cms_tpv_admin_init() {
37
 
38
- // this no longer works since we can have multiple menu items
39
- #define( "CMS_TPV_PAGE_FILE", menu_page_url("cms-tpv-pages-page", false));
40
-
41
  wp_enqueue_style( "cms_tpv_styles", CMS_TPV_URL . "styles/styles.css", false, CMS_TPV_VERSION );
42
  wp_enqueue_style( "jquery-alerts", CMS_TPV_URL . "styles/jquery.alerts.css", false, CMS_TPV_VERSION );
43
  wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery")); // renamed from cookie to fix problems with mod_security
44
  wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION);
45
  wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION);
46
-
47
  wp_enqueue_script( "cms_tree_page_view", CMS_TPV_URL . "scripts/cms_tree_page_view.js", false, CMS_TPV_VERSION);
48
 
49
  // DEBUG
@@ -80,7 +77,6 @@ function cms_tpv_save_settings() {
80
  $options["dashboard"] = (array) $_POST["post-type-dashboard"];
81
  $options["menu"] = (array) $_POST["post-type-menu"];
82
  update_option('cms_tpv_options', $options); // enable this to show box
83
- #bonny_d($options);
84
  }
85
  /*
86
  [post-type-dashboard] => Array
@@ -229,7 +225,18 @@ function cms_tpv_get_options() {
229
  }
230
 
231
  function cms_tpv_get_selected_post_type() {
 
 
 
 
 
232
  $post_type = $_GET["post_type"];
 
 
 
 
 
 
233
  if (!$post_type) { $post_type = "post"; }
234
  return $post_type;
235
  }
@@ -242,6 +249,7 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
242
  if (!$post_type) {
243
  $post_type = cms_tpv_get_selected_post_type();
244
  }
 
245
  $post_type_object = get_post_type_object($post_type);
246
  $get_pages_args = array("post_type" => $post_type);
247
 
@@ -253,7 +261,27 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
253
  $wpml_current_lang = $sitepress->get_current_language();
254
  }
255
 
256
- ?><div class="cms_tpv_wrapper">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  <input type="hidden" name="cms_tpv_meta_post_type" value="<?php echo $post_type ?>" />
258
  <input type="hidden" name="cms_tpv_meta_post_type_hierarchical" value="<?php echo (int) $post_type_object->hierarchical ?>" />
259
  <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang ?>" />
@@ -301,7 +329,6 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
301
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
302
  } else {
303
  // start the party!
304
- global $cms_tpv_view;
305
  ?>
306
 
307
  <ul class="cms-tpv-subsubsub">
@@ -328,23 +355,27 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
328
  </li>
329
  </ul>
330
 
331
- <div class="cms_tpv_working"><?php _e("Loading...", 'cms-tree-page-view') ?></div>
 
 
332
 
333
  <div class="updated below-h2 hidden cms_tpv_search_no_hits"><p><?php _e("Search: no pages found", 'cms-tree-page-view') ?></p></div>
334
 
335
- <div class="cms_tpv_container tree-default"><?php _e("Loading tree", 'cms-tree-page-view') ?></div>
 
 
336
  <div style="clear: both;"></div>
337
  <div class="cms_tpv_page_actions">
338
  <p>
339
  <a href="#" title='<?php _e("Edit page", "cms-tree-page-view")?>' class='cms_tpv_action_edit'><?php _e("Edit", "cms-tree-page-view")?></a> |
340
  <a href="#" title='<?php _e("View page", "cms-tree-page-view")?>' class='cms_tpv_action_view'><?php _e("View", "cms-tree-page-view")?></a>
341
  </p>
342
- <p>
343
  <span class='cms_tpv_action_add_page'><?php echo $post_type_object->labels->add_new_item ?></span>
344
- <a href="#" title='<?php _e("Add new page after", "cms-tree-page-view")?>' class='cms_tpv_action_add_page_after'><?php _e("after", "cms-tree-page-view")?></a>
345
  <?php
346
  if ($post_type_object->hierarchical) {
347
- ?> | <a href="#" title='<?php _e("Add new page inside", "cms-tree-page-view")?>' class='cms_tpv_action_add_page_inside'><?php _e("inside", "cms-tree-page-view")?></a><?php
348
  }
349
  ?>
350
  </p>
@@ -374,6 +405,7 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
374
  * A page with the tree. Good stuff.
375
  */
376
  function cms_tpv_pages_page() {
 
377
  $post_type = cms_tpv_get_selected_post_type();
378
  $post_type_object = get_post_type_object($post_type);
379
 
@@ -383,7 +415,7 @@ function cms_tpv_pages_page() {
383
 
384
  <?php
385
  cms_tpv_show_annoying_box();
386
- cms_tpv_print_common_tree_stuff();
387
  ?>
388
  </div>
389
  <?php
@@ -423,7 +455,7 @@ function cms_tpv_get_pages($args = null) {
423
  $get_posts_args["post_status"] = "publish";
424
  }
425
 
426
- // does not work with plugin role scoper. don't know why, but this shold fix it
427
  remove_action("get_pages", array('ScoperHardway', 'flt_get_pages'), 1, 2);
428
 
429
  #do_action_ref_array('parse_query', array(&$this));
@@ -438,7 +470,6 @@ function cms_tpv_get_pages($args = null) {
438
  }
439
 
440
  function cms_tpv_parse_query($q) {
441
- # bonny_d($q);
442
  }
443
 
444
  function cms_tpv_firedebug($var) {
@@ -462,7 +493,7 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
462
  unset($posts_columns["cb"], $posts_columns["title"], $posts_columns["author"], $posts_columns["categories"], $posts_columns["tags"], $posts_columns["date"]);
463
 
464
  global $post;
465
- #$tmpPost = $post;
466
  #cms_tpv_firedebug(timer_stop());
467
 
468
  ?>[<?php
@@ -470,6 +501,8 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
470
 
471
  #cms_tpv_firedebug(timer_stop());
472
  $onePage = $arrPages[$i];
 
 
473
  $page_id = $onePage->ID;
474
 
475
  $editLink = get_edit_post_link($onePage->ID, 'notDisplay');
@@ -498,7 +531,6 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
498
  $post_modified_time = date_i18n(get_option('date_format'), $post_modified_time, false);
499
 
500
  // last edited by
501
- $post = $onePage;
502
  setup_postdata($post);
503
  $post_author = get_the_modified_author();
504
  if (empty($post_author)) {
@@ -513,6 +545,15 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
513
  #$title = html_entity_decode($title, ENT_COMPAT, "UTF-8");
514
  #$title = html_entity_decode($title, ENT_COMPAT);
515
 
 
 
 
 
 
 
 
 
 
516
  // fetch columns
517
  $str_columns = "";
518
  foreach ( $posts_columns as $column_name => $column_display_name ) {
@@ -552,9 +593,7 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
552
  if ($str_columns) {
553
  $str_columns = "<dl>$str_columns</dl>";
554
  }
555
- // @todo: lägg till col comments, data
556
 
557
- #$post = $tmpPost; // @todo: should do this at the end instead?
558
  ?>
559
  {
560
  "data": {
@@ -568,7 +607,8 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
568
  "attr": {
569
  "xhref": "<?php echo $editLink ?>",
570
  "id": "cms-tpv-<?php echo $onePage->ID ?>",
571
- "xtitle": "<?php _e("Click to edit. Drag to move.", 'cms-tree-page-view') ?>"
 
572
  },
573
  <?php echo $strState ?>
574
  "metadata": {
@@ -582,7 +622,8 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
582
  "editlink": "<?php echo htmlspecialchars_decode($editLink) ?>",
583
  "modified_time": "<?php echo $post_modified_time ?>",
584
  "modified_author": "<?php echo $post_author ?>",
585
- "columns": "<?php echo rawurlencode($str_columns) ?>"
 
586
  }
587
  <?php
588
  // if id is in $arrOpenChilds then also output children on this one
@@ -599,6 +640,10 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
599
  if ($i < $pagesCount-1) {
600
  ?>,<?php
601
  }
 
 
 
 
602
  }
603
  ?>]<?php
604
  }
@@ -607,7 +652,6 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
607
  // Act on AJAX-call
608
  function cms_tpv_get_childs() {
609
 
610
- // @todo: activate again!
611
  header("Content-type: application/json");
612
 
613
  $action = $_GET["action"];
@@ -818,23 +862,21 @@ function cms_tpv_move_page() {
818
  } elseif ( "before" == $type ) {
819
 
820
  // post_node is placed before ref_post_node
821
-
822
  // update menu_order of all pages with a menu order more than or equal ref_node_post and with the same parent as ref_node_post
823
  // we do this so there will be room for our page if it's the first page
 
824
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_parent = %d", $post_ref_node->post_parent ) );
825
 
826
  // update menu order with +1 for all pages below ref_node, this should fix the problem with "unmovable" pages because of
827
  // multiple pages with the same menu order (...which is not the fault of this plugin!)
828
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE menu_order => %d", $post_ref_node->menu_order) );
829
 
830
- // update menu_order of $post_node to the menu_order that ref_post_node had, and update post_parent to the same as ref_post
831
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d, post_parent = %d WHERE ID = %d", $post_ref_node->menu_order+1, $post_ref_node->post_parent, $post_node->ID ) );
832
-
833
- #2 moved..
834
-
835
- #2 home
836
- #2 our products
837
- #3 contact us <- ref
838
 
839
  echo "did before";
840
 
@@ -847,7 +889,14 @@ function cms_tpv_move_page() {
847
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+2 WHERE post_parent = %d AND menu_order >= %d AND id <> %d ", $post_ref_node->post_parent, $post_ref_node->menu_order, $post_ref_node->ID ) );
848
 
849
  // update menu_order of post_node to the same that ref_post_node_had+1
850
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d, post_parent = %d WHERE ID = %d", $post_ref_node->menu_order+1, $post_ref_node->post_parent, $post_node->ID ) );
 
 
 
 
 
 
 
851
 
852
  echo "did after";
853
  }
@@ -858,6 +907,16 @@ function cms_tpv_move_page() {
858
  // error
859
  }
860
 
 
 
 
 
 
 
 
 
 
 
861
  exit;
862
  }
863
 
1
  <?php
2
 
3
  // for debug, remember to comment out (yes.. i *know* i will forget this later on...)
4
+ // require("FirePHPCore/FirePHP.class.php");
5
+ // $firephp = FirePHP::getInstance(true);
6
 
7
  function cms_tpv_admin_head() {
8
 
18
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
19
  var CMS_TPV_AJAXURL = "?action=cms_tpv_get_childs&view=";
20
  var CMS_TPV_VIEW = "<?php echo $cms_tpv_view ?>";
21
+ var cms_tpv_jsondata = {};
22
  /* ]]> */
23
  </script>
24
 
36
 
37
  function cms_tpv_admin_init() {
38
 
 
 
 
39
  wp_enqueue_style( "cms_tpv_styles", CMS_TPV_URL . "styles/styles.css", false, CMS_TPV_VERSION );
40
  wp_enqueue_style( "jquery-alerts", CMS_TPV_URL . "styles/jquery.alerts.css", false, CMS_TPV_VERSION );
41
  wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery")); // renamed from cookie to fix problems with mod_security
42
  wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION);
43
  wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION);
 
44
  wp_enqueue_script( "cms_tree_page_view", CMS_TPV_URL . "scripts/cms_tree_page_view.js", false, CMS_TPV_VERSION);
45
 
46
  // DEBUG
77
  $options["dashboard"] = (array) $_POST["post-type-dashboard"];
78
  $options["menu"] = (array) $_POST["post-type-menu"];
79
  update_option('cms_tpv_options', $options); // enable this to show box
 
80
  }
81
  /*
82
  [post-type-dashboard] => Array
225
  }
226
 
227
  function cms_tpv_get_selected_post_type() {
228
+ // fix for Ozh' Admin Drop Down Menu that does something with the urls
229
+ // movies funkar:
230
+ // http://localhost/wp-admin/edit.php?post_type=movies&page=cms-tpv-page-xmovies
231
+ // movies funkar inte:
232
+ // http://localhost/wp-admin/admin.php?page=cms-tpv-page-movies
233
  $post_type = $_GET["post_type"];
234
+ if (!$post_type) {
235
+ // no post type, happens with ozh admin drop down, so get it via page instead
236
+ $page = $_GET["page"];
237
+ $post_type = str_replace("cms-tpv-page-", "", $page);
238
+ }
239
+
240
  if (!$post_type) { $post_type = "post"; }
241
  return $post_type;
242
  }
249
  if (!$post_type) {
250
  $post_type = cms_tpv_get_selected_post_type();
251
  }
252
+ #echo "post_type: $post_type";
253
  $post_type_object = get_post_type_object($post_type);
254
  $get_pages_args = array("post_type" => $post_type);
255
 
261
  $wpml_current_lang = $sitepress->get_current_language();
262
  }
263
 
264
+ global $cms_tpv_view;
265
+ // output js for the root/top level
266
+ // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {
267
+ // @todo: make into function since used at other places
268
+ $jstree_open = array();
269
+ if ( isset( $_COOKIE["jstree_open"] ) ) {
270
+ $jstree_open = $_COOKIE["jstree_open"]; // like this: [jstree_open] => cms-tpv-1282,cms-tpv-1284,cms-tpv-3
271
+ $jstree_open = explode( ",", $jstree_open );
272
+ for( $i=0; $i<sizeof( $jstree_open ); $i++ ) {
273
+ $jstree_open[$i] = (int) str_replace("#cms-tpv-", "", $jstree_open[$i]);
274
+ }
275
+ }
276
+ ob_start();
277
+ cms_tpv_print_childs(0, $cms_tpv_view, $jstree_open, $post_type);
278
+ $json_data = ob_get_clean();
279
+ ?>
280
+ <script type="text/javascript">
281
+ cms_tpv_jsondata.<?php echo $post_type ?> = <?php echo $json_data ?>;
282
+ </script>
283
+
284
+ <div class="cms_tpv_wrapper">
285
  <input type="hidden" name="cms_tpv_meta_post_type" value="<?php echo $post_type ?>" />
286
  <input type="hidden" name="cms_tpv_meta_post_type_hierarchical" value="<?php echo (int) $post_type_object->hierarchical ?>" />
287
  <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang ?>" />
329
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
330
  } else {
331
  // start the party!
 
332
  ?>
333
 
334
  <ul class="cms-tpv-subsubsub">
355
  </li>
356
  </ul>
357
 
358
+ <div class="cms_tpv_working">
359
+ <?php _e("Loading...", 'cms-tree-page-view') ?>
360
+ </div>
361
 
362
  <div class="updated below-h2 hidden cms_tpv_search_no_hits"><p><?php _e("Search: no pages found", 'cms-tree-page-view') ?></p></div>
363
 
364
+ <div class="cms_tpv_container tree-default">
365
+ <?php _e("Loading tree", 'cms-tree-page-view') ?>
366
+ </div>
367
  <div style="clear: both;"></div>
368
  <div class="cms_tpv_page_actions">
369
  <p>
370
  <a href="#" title='<?php _e("Edit page", "cms-tree-page-view")?>' class='cms_tpv_action_edit'><?php _e("Edit", "cms-tree-page-view")?></a> |
371
  <a href="#" title='<?php _e("View page", "cms-tree-page-view")?>' class='cms_tpv_action_view'><?php _e("View", "cms-tree-page-view")?></a>
372
  </p>
373
+ <p class="cms_tpv_action_add_and_edit_page">
374
  <span class='cms_tpv_action_add_page'><?php echo $post_type_object->labels->add_new_item ?></span>
375
+ <a href="#" title='<?php _e("Add new page after", "cms-tree-page-view")?>' class='cms_tpv_action_add_page_after'><?php _e("After", "cms-tree-page-view")?></a>
376
  <?php
377
  if ($post_type_object->hierarchical) {
378
+ ?> | <a href="#" title='<?php _e("Add new page inside", "cms-tree-page-view")?>' class='cms_tpv_action_add_page_inside'><?php _e("Inside", "cms-tree-page-view")?></a><?php
379
  }
380
  ?>
381
  </p>
405
  * A page with the tree. Good stuff.
406
  */
407
  function cms_tpv_pages_page() {
408
+
409
  $post_type = cms_tpv_get_selected_post_type();
410
  $post_type_object = get_post_type_object($post_type);
411
 
415
 
416
  <?php
417
  cms_tpv_show_annoying_box();
418
+ cms_tpv_print_common_tree_stuff($post_type);
419
  ?>
420
  </div>
421
  <?php
455
  $get_posts_args["post_status"] = "publish";
456
  }
457
 
458
+ // does not work with plugin role scoper. don't know why, but this should fix it
459
  remove_action("get_pages", array('ScoperHardway', 'flt_get_pages'), 1, 2);
460
 
461
  #do_action_ref_array('parse_query', array(&$this));
470
  }
471
 
472
  function cms_tpv_parse_query($q) {
 
473
  }
474
 
475
  function cms_tpv_firedebug($var) {
493
  unset($posts_columns["cb"], $posts_columns["title"], $posts_columns["author"], $posts_columns["categories"], $posts_columns["tags"], $posts_columns["date"]);
494
 
495
  global $post;
496
+
497
  #cms_tpv_firedebug(timer_stop());
498
 
499
  ?>[<?php
501
 
502
  #cms_tpv_firedebug(timer_stop());
503
  $onePage = $arrPages[$i];
504
+ $tmpPost = $post;
505
+ $post = $onePage;
506
  $page_id = $onePage->ID;
507
 
508
  $editLink = get_edit_post_link($onePage->ID, 'notDisplay');
531
  $post_modified_time = date_i18n(get_option('date_format'), $post_modified_time, false);
532
 
533
  // last edited by
 
534
  setup_postdata($post);
535
  $post_author = get_the_modified_author();
536
  if (empty($post_author)) {
545
  #$title = html_entity_decode($title, ENT_COMPAT, "UTF-8");
546
  #$title = html_entity_decode($title, ENT_COMPAT);
547
 
548
+ // can edit?
549
+ if ( current_user_can( 'edit_page', $page_id ) ) {
550
+ $user_can_edit_page = true;
551
+ $user_can_edit_page_css = "cms_tpv_user_can_edit_page_yes";
552
+ } else {
553
+ $user_can_edit_page = false;
554
+ $user_can_edit_page_css = "cms_tpv_user_can_edit_page_no";
555
+ }
556
+
557
  // fetch columns
558
  $str_columns = "";
559
  foreach ( $posts_columns as $column_name => $column_display_name ) {
593
  if ($str_columns) {
594
  $str_columns = "<dl>$str_columns</dl>";
595
  }
 
596
 
 
597
  ?>
598
  {
599
  "data": {
607
  "attr": {
608
  "xhref": "<?php echo $editLink ?>",
609
  "id": "cms-tpv-<?php echo $onePage->ID ?>",
610
+ "xtitle": "<?php _e("Click to edit. Drag to move.", 'cms-tree-page-view') ?>",
611
+ "class": "<?php echo $user_can_edit_page_css ?>"
612
  },
613
  <?php echo $strState ?>
614
  "metadata": {
622
  "editlink": "<?php echo htmlspecialchars_decode($editLink) ?>",
623
  "modified_time": "<?php echo $post_modified_time ?>",
624
  "modified_author": "<?php echo $post_author ?>",
625
+ "columns": "<?php echo rawurlencode($str_columns) ?>",
626
+ "user_can_edit_page": "<?php echo (int) $user_can_edit_page ?>"
627
  }
628
  <?php
629
  // if id is in $arrOpenChilds then also output children on this one
640
  if ($i < $pagesCount-1) {
641
  ?>,<?php
642
  }
643
+
644
+ // return orgiginal post
645
+ $post = $tmpPost;
646
+
647
  }
648
  ?>]<?php
649
  }
652
  // Act on AJAX-call
653
  function cms_tpv_get_childs() {
654
 
 
655
  header("Content-type: application/json");
656
 
657
  $action = $_GET["action"];
862
  } elseif ( "before" == $type ) {
863
 
864
  // post_node is placed before ref_post_node
 
865
  // update menu_order of all pages with a menu order more than or equal ref_node_post and with the same parent as ref_node_post
866
  // we do this so there will be room for our page if it's the first page
867
+ // so: no move of individial posts yet
868
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_parent = %d", $post_ref_node->post_parent ) );
869
 
870
  // update menu order with +1 for all pages below ref_node, this should fix the problem with "unmovable" pages because of
871
  // multiple pages with the same menu order (...which is not the fault of this plugin!)
872
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE menu_order >= %d", $post_ref_node->menu_order+1) );
873
 
874
+ $post_to_save = array(
875
+ "ID" => $post_node->ID,
876
+ "menu_order" => $post_ref_node->menu_order,
877
+ "post_parent" => $post_ref_node->post_parent
878
+ );
879
+ wp_update_post( $post_to_save );
 
 
880
 
881
  echo "did before";
882
 
889
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+2 WHERE post_parent = %d AND menu_order >= %d AND id <> %d ", $post_ref_node->post_parent, $post_ref_node->menu_order, $post_ref_node->ID ) );
890
 
891
  // update menu_order of post_node to the same that ref_post_node_had+1
892
+ #$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d, post_parent = %d WHERE ID = %d", $post_ref_node->menu_order+1, $post_ref_node->post_parent, $post_node->ID ) );
893
+
894
+ $post_to_save = array(
895
+ "ID" => $post_node->ID,
896
+ "menu_order" => $post_ref_node->menu_order+1,
897
+ "post_parent" => $post_ref_node->post_parent
898
+ );
899
+ wp_update_post( $post_to_save );
900
 
901
  echo "did after";
902
  }
907
  // error
908
  }
909
 
910
+ // ok, we have updated the order of the pages
911
+ // but we must tell wordpress that we have done something
912
+ // other plugins (cache plugins) will not know to clear the cache otherwise
913
+ // edit_post seems like the most appropriate action to fire
914
+ // fire for the page that was moved? can not fire for all.. would be crazy, right?
915
+ #wp_update_post(array("ID" => $node_id));
916
+ #wp_update_post(array("ID" => $post_ref_node));
917
+ #clean_page_cache($node_id); clean_page_cache($post_ref_node); // hmpf.. db cache reloaded don't care
918
+
919
+
920
  exit;
921
  }
922
 
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. By using the tree you can edit, view, add pages and even search pages (useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
- Version: 0.7.1
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -27,7 +27,7 @@ License: GPL2
27
 
28
  require("functions.php");
29
 
30
- define( "CMS_TPV_VERSION", "0.7.1");
31
  define( "CMS_TPV_URL", WP_PLUGIN_URL . '/cms-tree-page-view/');
32
  define( "CMS_TPV_NAME", "CMS Tree Page View");
33
 
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. By using the tree you can edit, view, add pages and even search pages (useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
+ Version: 0.7.3
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
27
 
28
  require("functions.php");
29
 
30
+ define( "CMS_TPV_VERSION", "0.7.3");
31
  define( "CMS_TPV_URL", WP_PLUGIN_URL . '/cms-tree-page-view/');
32
  define( "CMS_TPV_NAME", "CMS Tree Page View");
33
 
readme.txt CHANGED
@@ -1,4 +1,4 @@
1
- === Plugin Name ===
2
  Contributors: eskapism
3
  Donate link: http://eskapism.se/sida/donate/
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
@@ -13,21 +13,21 @@ Adds a CMS-like tree overview of your pages or custom posts. Rearrange the order
13
  This plugin adds a CMS-like tree overview of all your pages and custom posts to WordPress - much like the view often found in a page-focused CMS, or like Windows Explorer or OS X Finder.
14
  Within this tree you can edit pages, view pages, add pages, search pages, and drag and drop pages to rearrange the order.
15
 
16
- CMS Tree Page View is a good alternative to plugins such as [pageMash](http://wordpress.org/extend/plugins/pagemash/), [WordPress Page Tree](http://wordpress.org/extend/plugins/page-tree/)
17
- and [My Page Order](http://wordpress.org/extend/plugins/my-page-order/) .
18
 
19
  Page management won't get any easier than this!
20
 
21
  #### Features and highlights:
22
 
23
- * drag and drop to rearrange your pages
24
  * add pages after or inside a page
25
  * edit pages
26
  * view pages
27
  * search pages
28
  * available for both regular pages and custom posts
29
- * easy view your site hierarchy directly from the WordPress dashboard
30
- * supports WPML, so you can manage all the languages of your site
31
 
32
  #### Screencast
33
 
@@ -72,6 +72,15 @@ Now the tree with the pages will be visible both on the dashboard and in the men
72
 
73
  == Changelog ==
74
 
 
 
 
 
 
 
 
 
 
75
  = 0.7.1 =
76
  - quick fix: capability edit_pages required to view the tree menu, instead of editor (which led to administrators not being able to view the tree...)
77
 
1
+ === CMS Tree Page View ===
2
  Contributors: eskapism
3
  Donate link: http://eskapism.se/sida/donate/
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
13
  This plugin adds a CMS-like tree overview of all your pages and custom posts to WordPress - much like the view often found in a page-focused CMS, or like Windows Explorer or OS X Finder.
14
  Within this tree you can edit pages, view pages, add pages, search pages, and drag and drop pages to rearrange the order.
15
 
16
+ CMS Tree Page View is a good alternative to plugins such as pageMash, WordPress Page Tree
17
+ and My Page Order.
18
 
19
  Page management won't get any easier than this!
20
 
21
  #### Features and highlights:
22
 
23
+ * drag and drop to rearrange/order your pages
24
  * add pages after or inside a page
25
  * edit pages
26
  * view pages
27
  * search pages
28
  * available for both regular pages and custom posts
29
+ * view your site hierarchy directly from the WordPress dashboard
30
+ * support for translation plugin [WPML](http://wordpress.org/extend/plugins/sitepress-multilingual-cms/), so you can manage all the languages of your site
31
 
32
  #### Screencast
33
 
72
 
73
  == Changelog ==
74
 
75
+ = 0.7.3 =
76
+ - a page can now be moved above a page with the same menu order. moved page will get the menu order of the page that it's moved aboved, and the other page will get a menu order of previous menu order + 1. i think/hope this is finaly solved now!
77
+ - using wp_update_post when moving pages (instead of sql directly). this should make this plugin work better with some cache plugins, for example DB Cache Reloaded
78
+ - root of tree is added initially, without the need to run an ajax query. loading the root of the tree = super fast! child nodes that are not previosly open are still loaded with ajax, because I want to be sure that the plugin does not hang if there is a page with super-mega-lots of children.
79
+
80
+ = 0.7.2 =
81
+ - pages that the user is not allowed to edit now get "dimmed". they will still be visible becuase a page a user is not allowed to edit, may have a child-page that they are allowed to edit, so the sub-pages must still be accessible
82
+ - some problems with Ozh' Admin Drop Down Menu fixed (tree showed posts instead of pages)
83
+
84
  = 0.7.1 =
85
  - quick fix: capability edit_pages required to view the tree menu, instead of editor (which led to administrators not being able to view the tree...)
86
 
scripts/cms_tree_page_view.js CHANGED
@@ -27,6 +27,41 @@ jQuery(function($) {
27
  }
28
 
29
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  },
31
  "themes": {
32
  "theme": "wordpress"
@@ -49,8 +84,10 @@ jQuery(function($) {
49
  var $elm = $(elm);
50
 
51
  // init tree, with settings specific for each post type
52
- var treeOptionsTmp = jQuery.extend(true, {}, treeOptions);
53
- treeOptionsTmp.json_data.ajax.url = treeOptionsTmp.json_data.ajax.url + "&post_type=" + cms_tpv_get_post_type(elm) + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
 
 
54
 
55
  var isHierarchical = $(elm).closest(".cms_tpv_wrapper").find("[name=cms_tpv_meta_post_type_hierarchical]").val();
56
  if (isHierarchical == 0) {
@@ -179,6 +216,17 @@ jQuery(".jstree li").live("mouseover", function(e) {
179
  var editlink = $li.data("jstree").editlink;
180
  $edit.attr("href", editlink);
181
 
 
 
 
 
 
 
 
 
 
 
 
182
  // ..and some extras
183
  div_actions_for_post_type.find(".cms_tpv_page_actions_modified_time").text($li.data("jstree").modified_time);
184
  div_actions_for_post_type.find(".cms_tpv_page_actions_modified_by").text($li.data("jstree").modified_author);
27
  }
28
 
29
  }
30
+ /*
31
+ // data can be initially set like this
32
+ // but it has to be set by type...
33
+ "data": [{
34
+ "data": {
35
+ "title": "I am a new page",
36
+ "attr": {
37
+ "href": "http://localhost/wp-admin/post.php?post=1060&action=edit",
38
+ "xid": "cms-tpv-1060"
39
+ },
40
+ "xicon": "http://localhost/wp-content/plugins/cms-tree-page-view/images/page_white_text.png"
41
+ },
42
+ "attr": {
43
+ "xhref": "http://localhost/wp-admin/post.php?post=1060&action=edit",
44
+ "id": "cms-tpv-1060",
45
+ "xtitle": "Click to edit. Drag to move.",
46
+ "class": "cms_tpv_user_can_edit_page_yes"
47
+ },
48
+ "metadata": {
49
+ "id": "cms-tpv-1060",
50
+ "post_id": "1060",
51
+ "post_type": "page",
52
+ "post_status": "publish",
53
+ "rel": "publish",
54
+ "childCount": 0,
55
+ "permalink": "http://localhost/i-am-a-new-page/",
56
+ "editlink": "http://localhost/wp-admin/post.php?post=1060&action=edit",
57
+ "modified_time": "August 15, 2010",
58
+ "modified_author": "admin",
59
+ "columns": "%3Cdl%3E%3Cdt%3EComments%3C%2Fdt%3E%3Cdd%3E%3Cdiv%20class%3D%22post-com-count-wrapper%22%3E%3Ca%20href%3D%27edit-comments.php%3Fp%3D1060%27%20title%3D%270%20pending%27%3E%3Cspan%3E0%3C%2Fspan%3E%3C%2Fa%3E%3C%2Fdiv%3E%3C%2Fdd%3E%3C%2Fdl%3E",
60
+ "user_can_edit_page": "1"
61
+ }
62
+
63
+ }
64
+ ]*/
65
  },
66
  "themes": {
67
  "theme": "wordpress"
84
  var $elm = $(elm);
85
 
86
  // init tree, with settings specific for each post type
87
+ var treeOptionsTmp = jQuery.extend(true, {}, treeOptions); // make copy of object
88
+ var post_type = cms_tpv_get_post_type(elm);
89
+ treeOptionsTmp.json_data.ajax.url = treeOptionsTmp.json_data.ajax.url + "&post_type=" + post_type + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
90
+ treeOptionsTmp.json_data.data = cms_tpv_jsondata[post_type]; // get from js
91
 
92
  var isHierarchical = $(elm).closest(".cms_tpv_wrapper").find("[name=cms_tpv_meta_post_type_hierarchical]").val();
93
  if (isHierarchical == 0) {
216
  var editlink = $li.data("jstree").editlink;
217
  $edit.attr("href", editlink);
218
 
219
+ // check if user is allowed to edit page
220
+ var $cms_tpv_action_add_and_edit_page = div_actions_for_post_type.find(".cms_tpv_action_add_and_edit_page");
221
+ if ($li.data("jstree").user_can_edit_page == 0) {
222
+ // nooope
223
+ $edit.hide();
224
+ $cms_tpv_action_add_and_edit_page.hide();
225
+ } else {
226
+ $edit.show();
227
+ $cms_tpv_action_add_and_edit_page.show();
228
+ }
229
+
230
  // ..and some extras
231
  div_actions_for_post_type.find(".cms_tpv_page_actions_modified_time").text($li.data("jstree").modified_time);
232
  div_actions_for_post_type.find(".cms_tpv_page_actions_modified_by").text($li.data("jstree").modified_author);
styles/styles.css CHANGED
@@ -294,3 +294,8 @@ p.cms_tpv_annoying_little_box_close {
294
  }
295
  .cms_tpv_wrapper .cms_tpv_page_actions_columns a.post-com-count {
296
  }
 
 
 
 
 
294
  }
295
  .cms_tpv_wrapper .cms_tpv_page_actions_columns a.post-com-count {
296
  }
297
+
298
+ li.cms_tpv_user_can_edit_page_no a {
299
+ opacity: .6; /* Standard: FF gt 1.5, Opera, Safari */
300
+ -ms-filter: "alpha(opacity=60)"; /* IE 8 */
301
+ }