CMS Tree Page View - Version 1.5

Version Description

(January 2018) =

  • Remove unused function cms_tpv_add_page().
  • Add nonce check when moving page.
Download this release

Release Info

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

Code changes from version 1.4 to 1.5

Files changed (4) hide show
  1. functions.php +6 -82
  2. index.php +2 -2
  3. readme.txt +6 -1
  4. scripts/cms_tree_page_view.js +60 -59
functions.php CHANGED
@@ -290,10 +290,11 @@ function cms_tpv_admin_head() {
290
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
291
  var CMS_TPV_AJAXURL = "action=cms_tpv_get_childs&view=";
292
  CMS_TPV_AJAXURL = ((window.ajaxurl.indexOf("admin-ajax.php?") !== -1) ? "&" : "?") + CMS_TPV_AJAXURL;
293
- var CMS_TPV_VIEW = "<?php echo $cms_tpv_view ?>";
294
  //var CMS_TPV_CAN_DND = "<?php echo current_user_can( CMS_TPV_MOVE_PERMISSION ) ? "dnd" : "" ?>";
295
  var CMS_TPV_CAN_DND = "dnd";
296
  var cms_tpv_jsondata = {};
 
297
  /* ]]> */
298
  </script>
299
 
@@ -1548,6 +1549,8 @@ function cms_tpv_get_childs() {
1548
 
1549
  header("Content-type: application/json");
1550
 
 
 
1551
  $action = $_GET["action"];
1552
  $view = $_GET["view"]; // all | public | trash
1553
  $post_type = (isset($_GET["post_type"])) ? $_GET["post_type"] : null;
@@ -1644,87 +1647,6 @@ function cms_tpv_get_childs() {
1644
  exit;
1645
  }
1646
 
1647
- /**
1648
- * @TODO: check if this is used any longer? If not then delete it!
1649
- */
1650
- function cms_tpv_add_page() {
1651
- global $wpdb;
1652
-
1653
- /*
1654
- (
1655
- [action] => cms_tpv_add_page
1656
- [pageID] => cms-tpv-1318
1657
- type
1658
- )
1659
- */
1660
- $type = $_POST["type"];
1661
- $pageID = $_POST["pageID"];
1662
- $pageID = str_replace("cms-tpv-", "", $pageID);
1663
- $page_title = trim($_POST["page_title"]);
1664
- $post_type = $_POST["post_type"];
1665
- $wpml_lang = $_POST["wpml_lang"];
1666
- if (!$page_title) { $page_title = __("New page", 'cms-tree-page-view'); }
1667
-
1668
- $ref_post = get_post($pageID);
1669
-
1670
- if ("after" == $type) {
1671
-
1672
- /*
1673
- add page under/below ref_post
1674
- */
1675
-
1676
- // update menu_order of all pages below our page
1677
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+2 WHERE post_type = %s AND post_parent = %d AND menu_order >= %d AND id <> %d ", $ref_post->post_type, $ref_post->post_parent, $ref_post->menu_order, $ref_post->ID ) );
1678
-
1679
- // create a new page and then goto it
1680
- $post_new = array();
1681
- $post_new["menu_order"] = $ref_post->menu_order+1;
1682
- $post_new["post_parent"] = $ref_post->post_parent;
1683
- $post_new["post_type"] = "page";
1684
- $post_new["post_status"] = "draft";
1685
- $post_new["post_title"] = $page_title;
1686
- $post_new["post_content"] = "";
1687
- $post_new["post_type"] = $post_type;
1688
- $newPostID = wp_insert_post($post_new);
1689
-
1690
- } else if ( "inside" == $type ) {
1691
-
1692
- /*
1693
- add page inside ref_post
1694
- */
1695
-
1696
- // update menu_order, so our new post is the only one with order 0
1697
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_type = %s AND post_parent = %d", $ref_post->post_type, $ref_post->ID) );
1698
-
1699
- $post_new = array();
1700
- $post_new["menu_order"] = 0;
1701
- $post_new["post_parent"] = $ref_post->ID;
1702
- $post_new["post_type"] = "page";
1703
- $post_new["post_status"] = "draft";
1704
- $post_new["post_title"] = $page_title;
1705
- $post_new["post_content"] = "";
1706
- $post_new["post_type"] = $post_type;
1707
- $newPostID = wp_insert_post($post_new);
1708
-
1709
- }
1710
-
1711
- if ($newPostID) {
1712
- // return editlink for the newly created page
1713
- $editLink = get_edit_post_link($newPostID, '');
1714
- if ($wpml_lang) {
1715
- $editLink = esc_url( add_query_arg("lang", $wpml_lang, $editLink) );
1716
- }
1717
- echo $editLink;
1718
- } else {
1719
- // fail, tell js
1720
- echo "0";
1721
- }
1722
-
1723
-
1724
- exit;
1725
- }
1726
-
1727
-
1728
  // AJAX: perform move of article
1729
  function cms_tpv_move_page() {
1730
  /*
@@ -1734,6 +1656,8 @@ function cms_tpv_move_page() {
1734
  inside = man placerar den under en sida som inte har några barn?
1735
  */
1736
 
 
 
1737
  global $wpdb;
1738
 
1739
  $node_id = $_POST["node_id"]; // the node that was moved
290
  var CMS_TPV_URL = "<?php echo CMS_TPV_URL ?>";
291
  var CMS_TPV_AJAXURL = "action=cms_tpv_get_childs&view=";
292
  CMS_TPV_AJAXURL = ((window.ajaxurl.indexOf("admin-ajax.php?") !== -1) ? "&" : "?") + CMS_TPV_AJAXURL;
293
+ var CMS_TPV_VIEW = <?php echo wp_json_encode($cms_tpv_view); ?>
294
  //var CMS_TPV_CAN_DND = "<?php echo current_user_can( CMS_TPV_MOVE_PERMISSION ) ? "dnd" : "" ?>";
295
  var CMS_TPV_CAN_DND = "dnd";
296
  var cms_tpv_jsondata = {};
297
+ var CMS_TPV_NONCE = <?php echo wp_json_encode(wp_create_nonce('cms-tpv-ajax')) ?>
298
  /* ]]> */
299
  </script>
300
 
1549
 
1550
  header("Content-type: application/json");
1551
 
1552
+ check_ajax_referer('cms-tpv-ajax', 'cms-tpv-nonce');
1553
+
1554
  $action = $_GET["action"];
1555
  $view = $_GET["view"]; // all | public | trash
1556
  $post_type = (isset($_GET["post_type"])) ? $_GET["post_type"] : null;
1647
  exit;
1648
  }
1649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1650
  // AJAX: perform move of article
1651
  function cms_tpv_move_page() {
1652
  /*
1656
  inside = man placerar den under en sida som inte har några barn?
1657
  */
1658
 
1659
+ check_ajax_referer('cms-tpv-ajax', 'cms-tpv-nonce');
1660
+
1661
  global $wpdb;
1662
 
1663
  $node_id = $_POST["node_id"]; // the node that was moved
index.php CHANGED
@@ -5,7 +5,7 @@ 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. Use the tree view to edit, view, add pages and search pages (very 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
  Text Domain: cms-tree-page-view
7
  Domain Path: /languages/
8
- Version: 1.4
9
  Author: Pär Thernström
10
  Author URI: http://eskapism.se/
11
  License: GPL2
@@ -29,7 +29,7 @@ License: GPL2
29
 
30
  #require("functions.php");
31
 
32
- define( "CMS_TPV_VERSION", "1.4");
33
  define( "CMS_TPV_NAME", "CMS Tree Page View");
34
 
35
  require(dirname(__FILE__) . "/functions.php");
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very 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
  Text Domain: cms-tree-page-view
7
  Domain Path: /languages/
8
+ Version: 1.5
9
  Author: Pär Thernström
10
  Author URI: http://eskapism.se/
11
  License: GPL2
29
 
30
  #require("functions.php");
31
 
32
+ define( "CMS_TPV_VERSION", "1.5");
33
  define( "CMS_TPV_NAME", "CMS Tree Page View");
34
 
35
  require(dirname(__FILE__) . "/functions.php");
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and
5
  Text Domain: cms-tree-page-view
6
  Requires at least: 3.8
7
  Tested up to: 4.8
8
- Stable tag: 1.4
9
 
10
  Adds a tree view of all pages & custom posts. Get a great overview + options to drag & drop to reorder & option to add multiple pages.
11
 
@@ -117,6 +117,11 @@ Now the tree with the pages will be visible both on the dashboard and in the men
117
 
118
  == Changelog ==
119
 
 
 
 
 
 
120
  = 1.4 (October 2017) =
121
 
122
  - Check that a user is allowed to edit pages/posts when making AJAX call, making sure users with subscribers role can't move pages.
5
  Text Domain: cms-tree-page-view
6
  Requires at least: 3.8
7
  Tested up to: 4.8
8
+ Stable tag: 1.5
9
 
10
  Adds a tree view of all pages & custom posts. Get a great overview + options to drag & drop to reorder & option to add multiple pages.
11
 
117
 
118
  == Changelog ==
119
 
120
+ = 1.5 (January 2018) =
121
+
122
+ - Remove unused function `cms_tpv_add_page()`.
123
+ - Add nonce check when moving page.
124
+
125
  = 1.4 (October 2017) =
126
 
127
  - Check that a user is allowed to edit pages/posts when making AJAX call, making sure users with subscribers role can't move pages.
scripts/cms_tree_page_view.js CHANGED
@@ -15,17 +15,17 @@ Timers:
15
  * Should have a module for all instead...
16
  */
17
  var cms_tree_page_view = (function ($) {
18
-
19
  var my = {},
20
  privateVariable = 1;
21
-
22
  function privateMethod() {
23
  // ...
24
  }
25
-
26
  my.moduleProperty = 1;
27
  my.elements = {};
28
-
29
  my.selectors = {
30
  containers: "div.cms_tpv_container",
31
  action_div: "div.cms_tpv_page_actions",
@@ -47,7 +47,7 @@ var cms_tree_page_view = (function ($) {
47
  };
48
 
49
  my.setup_listeners = function() {
50
-
51
  // When something has been written in one of the page titles: show another row
52
  // Also: if more than one row are empty at the end, remove all but the last
53
  $(document).on("keyup", "ul.cms_tpv_action_add_doit_pages li:last-child input", function(e) {
@@ -56,12 +56,12 @@ var cms_tree_page_view = (function ($) {
56
  var $li = $t.closest("li");
57
 
58
  if ($.trim($t.val()) !== "") {
59
-
60
  var $new_li = $li.clone().hide();
61
  $new_li.find("input").val("");
62
  $li.after( $new_li );
63
  $new_li.slideDown();
64
-
65
  }
66
 
67
  });
@@ -132,7 +132,7 @@ var cms_tree_page_view = (function ($) {
132
  actions_div_doit.find("[name='cms_tpv_add_new_pages_names[]']").focus();
133
  });
134
 
135
-
136
  }); // click add page
137
 
138
  // submit form with new pages
@@ -155,7 +155,7 @@ var cms_tree_page_view = (function ($) {
155
  // console.log(what);
156
  }
157
  };
158
-
159
  return my;
160
 
161
  }(jQuery));
@@ -169,7 +169,7 @@ jQuery(function() {
169
  // @todo: add prefix to treeOptions, div_actions
170
  var cms_tpv_tree, treeOptions, div_actions, cms_tpv_current_li_id = null;
171
  jQuery(function($) {
172
-
173
  // Globals, don't "var" them! :)
174
  cms_tpv_tree = $("div.cms_tpv_container");
175
  div_actions = $("div.cms_tpv_page_actions");
@@ -206,7 +206,7 @@ jQuery(function($) {
206
  },
207
  "json_data": {
208
  "ajax": {
209
- "url": ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW,
210
  // this function is executed in the instance's scope (this refers to the tree instance)
211
  // the parameter is the node being loaded (may be -1, 0, or undefined when loading the root nodes)
212
  "data" : function (n) {
@@ -219,7 +219,7 @@ jQuery(function($) {
219
  }
220
  },
221
  "success": function(data, status) {
222
-
223
  // If data is null or empty = show message about no nodes
224
  if (data === null || !data) {
225
  cms_tpv_message.html( "<p>" + cmstpv_l10n["No posts found"] + "</p>" );
@@ -241,7 +241,7 @@ jQuery(function($) {
241
  },
242
  "search": {
243
  "ajax" : {
244
- "url": ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW
245
  },
246
  "case_insensitive": true
247
  },
@@ -261,10 +261,10 @@ jQuery(function($) {
261
  var post_type = cms_tpv_get_post_type(elm);
262
  treeOptionsTmp.json_data.ajax.url = treeOptionsTmp.json_data.ajax.url + "&post_type=" + post_type + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
263
  treeOptionsTmp.json_data.data = cms_tpv_jsondata[post_type]; // get from js
264
-
265
  var isHierarchical = $(elm).closest(".cms_tpv_wrapper").find("[name=cms_tpv_meta_post_type_hierarchical]").val();
266
  if (isHierarchical === "0") {
267
-
268
  // no move to children if not hierarchical
269
  treeOptionsTmp.types = {
270
  "types": {
@@ -275,9 +275,9 @@ jQuery(function($) {
275
  };
276
 
277
  }
278
-
279
  // set search url to include post type
280
- treeOptionsTmp.search.ajax.url = ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW + "&post_type=" + cms_tpv_get_post_type(this);
281
 
282
  $elm.bind("search.jstree", function (event, data) {
283
  if (data.rslt.nodes.length === 0) {
@@ -285,10 +285,10 @@ jQuery(function($) {
285
  $(this).closest(".cms_tpv_wrapper").find(".cms_tree_view_search_form_no_hits").fadeIn("fast");
286
  }
287
  });
288
-
289
  // whole tre loaded
290
  $elm.bind("loaded.jstree", cms_tpv_tree_loaded);
291
-
292
  $elm.jstree(treeOptionsTmp);
293
 
294
  });
@@ -311,7 +311,7 @@ function cms_tpv_mouseover(e) {
311
  * Is only fired when tree was loaded and contained stuff
312
  */
313
  function cms_tpv_tree_loaded(event, data) {
314
-
315
  var $container = jQuery(event.target);
316
  var actions_div_doit = cms_tpv_get_page_actions_div_doit(event.target);
317
 
@@ -365,7 +365,7 @@ function cms_tpv_tree_loaded(event, data) {
365
  * so hide the action div and cancel the timer
366
  */
367
  jQuery($container).on("mousedown", "a", function(e) {
368
-
369
  cms_tree_page_view.log("mousedown a");
370
 
371
  var $target = jQuery(e.target);
@@ -423,7 +423,7 @@ function cms_tpv_mouseover_li(e) {
423
  var $cms_tpv_container = $li.closest("div.cms_tpv_container");
424
 
425
  if (cms_tpv_is_dragging() === false) {
426
-
427
  var is_visible = div_actions_for_post_type.is(":visible");
428
  is_visible = false;
429
 
@@ -442,7 +442,7 @@ function cms_tpv_mouseover_li(e) {
442
  $li.addClass("has-visible-actions");
443
  $cms_tpv_container.addClass("has-visible-actions");
444
  $li.find("a:first").addClass("hover");
445
-
446
  // setup link for view page
447
  $view = div_actions_for_post_type.find(".cms_tpv_action_view");
448
  var permalink = $li.data("permalink");
@@ -465,13 +465,13 @@ function cms_tpv_mouseover_li(e) {
465
 
466
  // add post id to data
467
  div_actions_for_post_type.data("post_id", $li.data("post_id"));
468
-
469
 
470
  // check permissions, may the current user add page, after or inside
471
  // If page has status draft then no one is allowed to add page inside
472
  // div_actions_for_post_type.find(".cms_tpv_action_add_page_inside, .cms_tpv_action_add_page_inside").show();
473
  div_actions_for_post_type.find(".cms_tpv_action_add_page_inside, .cms_tpv_action_add_page_inside").removeClass("hidden");
474
-
475
  var inside_allowed = true;
476
  if ("draft" === $li.data("post_status")) {
477
  inside_allowed = false;
@@ -487,7 +487,7 @@ function cms_tpv_mouseover_li(e) {
487
  var width = $a.outerWidth(true);
488
  var new_offset = div_actions_for_post_type.offset();
489
  var new_offset_left = e.pageX + 35;
490
-
491
  new_offset_left = $a.offset().left + $a.width() + 20;
492
  new_offset.left = new_offset_left;
493
  new_offset.top = $a.offset().top - 30;
@@ -496,18 +496,18 @@ function cms_tpv_mouseover_li(e) {
496
  // check if action div bottom is visible in browser window, if not move it up until it is
497
  var pos_diff = (div_actions_for_post_type.offset().top + div_actions_for_post_type.height()) - (jQuery(window).height() + jQuery(window).scrollTop());
498
  if (pos_diff > 0) {
499
-
500
  // set action div to begin at bottom of link instead
501
  new_offset.top = $a.offset().top - div_actions_for_post_type.height() + 15; // <- ska bli botten på vår div
502
  div_actions_for_post_type.offset( new_offset );
503
  div_actions_for_post_type.addClass("cms_tpv_page_actions_visible_from_bottom");
504
-
505
  } else {
506
  div_actions_for_post_type.removeClass("cms_tpv_page_actions_visible_from_bottom");
507
  }
508
-
509
  div_actions_for_post_type.addClass("cms_tpv_page_actions_visible");
510
-
511
  // check if user is allowed to edit page
512
  var $cms_tpv_action_add_and_edit_page = div_actions_for_post_type.find(".cms_tpv_action_add_and_edit_page");
513
  if ($li.data("user_can_edit_page") === "0") {
@@ -543,11 +543,11 @@ function cms_tpv_mouseover_li(e) {
543
  jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
544
 
545
  cms_tree_page_view.log("mouseleave container");
546
-
547
  var $container = jQuery(e.target).closest("div.cms_tpv_container");
548
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
549
  var t = this;
550
-
551
  // Reset global timer
552
  var global_timer = $container.data("cmstpv_global_link_timer");
553
  if (global_timer) {
@@ -562,7 +562,7 @@ jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
562
 
563
  // Maybe hide popup after a short while
564
  var hideTimer = setTimeout(function() {
565
-
566
  cms_tree_page_view.log("maybe hide popup because outside container");
567
 
568
  // But don't hide if we are inside the popup
@@ -587,12 +587,12 @@ jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
587
  // When mouse enters actions div then cancel possibly global hide timer
588
  // If moved outside container and then back, cancel possibly global timer
589
  jQuery(document).on("mouseenter", "div.cms_tpv_page_actions", function(e) {
590
-
591
  var $this = jQuery(this);
592
  var $wrapper = $this.closest("div.cms_tpv_wrapper");
593
  var $container = $wrapper.find("div.cms_tpv_container");
594
  var timer = $container.data("cmstpv_global_link_timer");
595
-
596
  clearTimeout(timer);
597
 
598
  });
@@ -611,7 +611,7 @@ jQuery(document).on("mouseenter", "div.cms_tpv_container", function(e) {
611
  * add childcount and other things to each li
612
  */
613
  function cms_tpv_bind_clean_node() {
614
-
615
  cms_tpv_tree.bind("move_node.jstree", function (event, data) {
616
  var nodeBeingMoved = data.rslt.o; // noden vi flyttar
617
  var nodeNewParent = data.rslt.np;
@@ -623,13 +623,13 @@ function cms_tpv_bind_clean_node() {
623
 
624
  // om ovanför
625
  o ovanför or
626
-
627
  // om efter
628
  o efter r
629
-
630
  // om inside
631
  o ovanför or
632
-
633
 
634
  drop_target : ".jstree-drop",
635
  drop_check : function (data) { return true; },
@@ -637,12 +637,12 @@ function cms_tpv_bind_clean_node() {
637
  drag_target : ".jstree-draggable",
638
  drag_finish : $.noop,
639
  drag_check : function (data) { return { after : false, before : false, inside : true }; }
640
-
641
  Gets executed after a valid drop, you get one parameter, which is as follows:
642
  data.o - the object being dragged
643
  data.r - the drop target
644
  */
645
-
646
  var node_id,
647
  ref_node_id;
648
  if (nodePosition == "before") {
@@ -655,19 +655,20 @@ function cms_tpv_bind_clean_node() {
655
  node_id = jQuery( nodeBeingMoved ).attr( "id" );
656
  ref_node_id = jQuery( nodeR ).attr( "id" );
657
  }
658
-
659
  // Update parent or menu order
660
  jQuery.post(ajaxurl, {
661
  action: "cms_tpv_move_page",
662
  "node_id": node_id,
663
  "ref_node_id": ref_node_id,
664
  "type": nodePosition,
665
- "icl_post_language": selected_lang
 
666
  }, function(data, textStatus) {
667
  });
668
 
669
  });
670
-
671
  cms_tpv_tree.bind("clean_node.jstree", function(event, data) {
672
  var obj = (data.rslt.obj);
673
  if (obj && obj != -1) {
@@ -687,7 +688,7 @@ function cms_tpv_bind_clean_node() {
687
  if (childCount > 0) {
688
  aFirst.append("<span title='" + childCount + " " + cmstpv_l10n.child_pages + "' class='child_count'>("+childCount+")</span>");
689
  }
690
-
691
  // add protection type
692
  var rel = li.data("rel");
693
  if(rel == "password") {
@@ -719,7 +720,7 @@ function cms_tpv_bind_clean_node() {
719
 
720
  // Perform search when submiting form
721
  jQuery(document).on("submit", "form.cms_tree_view_search_form", function(e) {
722
-
723
  var $wrapper = jQuery(this).closest(".cms_tpv_wrapper");
724
  $wrapper.find(".cms_tpv_search_no_hits").hide();
725
  var s = $wrapper.find(".cms_tree_view_search").attr("value");
@@ -737,7 +738,7 @@ jQuery(document).on("submit", "form.cms_tree_view_search_form", function(e) {
737
  $wrapper.find(".cms_tree_view_search_form_reset").fadeOut("fast");
738
  }
739
  $wrapper.find(".cms_tree_view_search_form_working").fadeOut("fast");
740
-
741
  return false;
742
 
743
  });
@@ -784,7 +785,7 @@ jQuery(document).on("click", "a.cms_tvp_view_trash", function() {
784
 
785
  // click on link to change WPML-language
786
  jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
787
-
788
  $wrapper = cms_tpv_get_wrapper(this);
789
 
790
  // Mark clicked link as selected
@@ -803,7 +804,7 @@ jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
803
  // Post counts are stored on the links for all | public | trash
804
  var $ul_select_view = $wrapper.find(".cms-tpv-subsubsub-select-view");
805
  $ul_select_view.find("li.cms_tvp_view_is_status_view a").each(function(i, a_tag) {
806
-
807
  // check if this link has a data attr with count for the selected lang
808
  var $a = jQuery(a_tag);
809
  var link_count = $a.data("post-count-" + lang_code);
@@ -816,20 +817,20 @@ jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
816
  // Set the view = reload the tree
817
  var current_view = cms_tpv_get_current_view(this);
818
  cms_tvp_set_view(current_view, this);
819
-
820
  return false;
821
 
822
  });
823
 
824
  function cms_tpv_hide_action_div() {
825
-
826
  }
827
 
828
 
829
  function cms_tpv_get_current_view(elm) {
830
-
831
  $wrapper = cms_tpv_get_wrapper(elm);
832
-
833
  if ($wrapper.find(".cms_tvp_view_all").hasClass("current")) {
834
  return "all";
835
  } else if ($wrapper.find(".cms_tvp_view_public").hasClass("current")) {
@@ -867,12 +868,12 @@ function cms_tvp_set_view(view, elm) {
867
  } else if (view == "trash") {
868
  $wrapper.find(".cms_tvp_view_trash").addClass("current");
869
  } else {
870
-
871
  }
872
-
873
  // Reload tree
874
  var treeOptionsTmp = jQuery.extend(true, {}, treeOptions);
875
- treeOptionsTmp.json_data.ajax.url = ajaxurl + CMS_TPV_AJAXURL + view + "&post_type=" + cms_tpv_get_post_type(elm) + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
876
 
877
  $wrapper.find(".cms_tpv_container").bind("loaded.jstree open_node.jstree", cms_tpv_tree_loaded);
878
  $wrapper.find(".cms_tpv_container").jstree(treeOptionsTmp);
@@ -895,7 +896,7 @@ jQuery(function($) {
895
  // It must exist because that's where we have our switch to tree-icon
896
  var view_switch = $("div.view-switch");
897
  if (! view_switch.length) {
898
-
899
  view_switch = $("<div class='view-switch'></div>");
900
  $("div.tablenav-pages:first").after(view_switch);
901
 
@@ -906,13 +907,13 @@ jQuery(function($) {
906
  //view_switch.append(" ");
907
 
908
  }
909
-
910
  // Add our link inside view switch
911
 
912
  /*
913
  view_switch.append(tree_view_switch_a);
914
  view_switch.addClass("view-switch-cstpv-icon-added");
915
-
916
  // if in tree mode: add a class to wpbody so we can style things
917
  if (cmstpv_postsoverview_wrap.length) {
918
 
15
  * Should have a module for all instead...
16
  */
17
  var cms_tree_page_view = (function ($) {
18
+
19
  var my = {},
20
  privateVariable = 1;
21
+
22
  function privateMethod() {
23
  // ...
24
  }
25
+
26
  my.moduleProperty = 1;
27
  my.elements = {};
28
+
29
  my.selectors = {
30
  containers: "div.cms_tpv_container",
31
  action_div: "div.cms_tpv_page_actions",
47
  };
48
 
49
  my.setup_listeners = function() {
50
+
51
  // When something has been written in one of the page titles: show another row
52
  // Also: if more than one row are empty at the end, remove all but the last
53
  $(document).on("keyup", "ul.cms_tpv_action_add_doit_pages li:last-child input", function(e) {
56
  var $li = $t.closest("li");
57
 
58
  if ($.trim($t.val()) !== "") {
59
+
60
  var $new_li = $li.clone().hide();
61
  $new_li.find("input").val("");
62
  $li.after( $new_li );
63
  $new_li.slideDown();
64
+
65
  }
66
 
67
  });
132
  actions_div_doit.find("[name='cms_tpv_add_new_pages_names[]']").focus();
133
  });
134
 
135
+
136
  }); // click add page
137
 
138
  // submit form with new pages
155
  // console.log(what);
156
  }
157
  };
158
+
159
  return my;
160
 
161
  }(jQuery));
169
  // @todo: add prefix to treeOptions, div_actions
170
  var cms_tpv_tree, treeOptions, div_actions, cms_tpv_current_li_id = null;
171
  jQuery(function($) {
172
+
173
  // Globals, don't "var" them! :)
174
  cms_tpv_tree = $("div.cms_tpv_container");
175
  div_actions = $("div.cms_tpv_page_actions");
206
  },
207
  "json_data": {
208
  "ajax": {
209
+ "url": ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW + '&cms-tpv-nonce=' + window.CMS_TPV_NONCE,
210
  // this function is executed in the instance's scope (this refers to the tree instance)
211
  // the parameter is the node being loaded (may be -1, 0, or undefined when loading the root nodes)
212
  "data" : function (n) {
219
  }
220
  },
221
  "success": function(data, status) {
222
+
223
  // If data is null or empty = show message about no nodes
224
  if (data === null || !data) {
225
  cms_tpv_message.html( "<p>" + cmstpv_l10n["No posts found"] + "</p>" );
241
  },
242
  "search": {
243
  "ajax" : {
244
+ "url": ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW + '&cms-tpv-nonce=' + window.CMS_TPV_NONCE
245
  },
246
  "case_insensitive": true
247
  },
261
  var post_type = cms_tpv_get_post_type(elm);
262
  treeOptionsTmp.json_data.ajax.url = treeOptionsTmp.json_data.ajax.url + "&post_type=" + post_type + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
263
  treeOptionsTmp.json_data.data = cms_tpv_jsondata[post_type]; // get from js
264
+
265
  var isHierarchical = $(elm).closest(".cms_tpv_wrapper").find("[name=cms_tpv_meta_post_type_hierarchical]").val();
266
  if (isHierarchical === "0") {
267
+
268
  // no move to children if not hierarchical
269
  treeOptionsTmp.types = {
270
  "types": {
275
  };
276
 
277
  }
278
+
279
  // set search url to include post type
280
+ treeOptionsTmp.search.ajax.url = ajaxurl + CMS_TPV_AJAXURL + CMS_TPV_VIEW + '&cms-tpv-nonce=' + window.CMS_TPV_NONCE + "&post_type=" + cms_tpv_get_post_type(this);
281
 
282
  $elm.bind("search.jstree", function (event, data) {
283
  if (data.rslt.nodes.length === 0) {
285
  $(this).closest(".cms_tpv_wrapper").find(".cms_tree_view_search_form_no_hits").fadeIn("fast");
286
  }
287
  });
288
+
289
  // whole tre loaded
290
  $elm.bind("loaded.jstree", cms_tpv_tree_loaded);
291
+
292
  $elm.jstree(treeOptionsTmp);
293
 
294
  });
311
  * Is only fired when tree was loaded and contained stuff
312
  */
313
  function cms_tpv_tree_loaded(event, data) {
314
+
315
  var $container = jQuery(event.target);
316
  var actions_div_doit = cms_tpv_get_page_actions_div_doit(event.target);
317
 
365
  * so hide the action div and cancel the timer
366
  */
367
  jQuery($container).on("mousedown", "a", function(e) {
368
+
369
  cms_tree_page_view.log("mousedown a");
370
 
371
  var $target = jQuery(e.target);
423
  var $cms_tpv_container = $li.closest("div.cms_tpv_container");
424
 
425
  if (cms_tpv_is_dragging() === false) {
426
+
427
  var is_visible = div_actions_for_post_type.is(":visible");
428
  is_visible = false;
429
 
442
  $li.addClass("has-visible-actions");
443
  $cms_tpv_container.addClass("has-visible-actions");
444
  $li.find("a:first").addClass("hover");
445
+
446
  // setup link for view page
447
  $view = div_actions_for_post_type.find(".cms_tpv_action_view");
448
  var permalink = $li.data("permalink");
465
 
466
  // add post id to data
467
  div_actions_for_post_type.data("post_id", $li.data("post_id"));
468
+
469
 
470
  // check permissions, may the current user add page, after or inside
471
  // If page has status draft then no one is allowed to add page inside
472
  // div_actions_for_post_type.find(".cms_tpv_action_add_page_inside, .cms_tpv_action_add_page_inside").show();
473
  div_actions_for_post_type.find(".cms_tpv_action_add_page_inside, .cms_tpv_action_add_page_inside").removeClass("hidden");
474
+
475
  var inside_allowed = true;
476
  if ("draft" === $li.data("post_status")) {
477
  inside_allowed = false;
487
  var width = $a.outerWidth(true);
488
  var new_offset = div_actions_for_post_type.offset();
489
  var new_offset_left = e.pageX + 35;
490
+
491
  new_offset_left = $a.offset().left + $a.width() + 20;
492
  new_offset.left = new_offset_left;
493
  new_offset.top = $a.offset().top - 30;
496
  // check if action div bottom is visible in browser window, if not move it up until it is
497
  var pos_diff = (div_actions_for_post_type.offset().top + div_actions_for_post_type.height()) - (jQuery(window).height() + jQuery(window).scrollTop());
498
  if (pos_diff > 0) {
499
+
500
  // set action div to begin at bottom of link instead
501
  new_offset.top = $a.offset().top - div_actions_for_post_type.height() + 15; // <- ska bli botten på vår div
502
  div_actions_for_post_type.offset( new_offset );
503
  div_actions_for_post_type.addClass("cms_tpv_page_actions_visible_from_bottom");
504
+
505
  } else {
506
  div_actions_for_post_type.removeClass("cms_tpv_page_actions_visible_from_bottom");
507
  }
508
+
509
  div_actions_for_post_type.addClass("cms_tpv_page_actions_visible");
510
+
511
  // check if user is allowed to edit page
512
  var $cms_tpv_action_add_and_edit_page = div_actions_for_post_type.find(".cms_tpv_action_add_and_edit_page");
513
  if ($li.data("user_can_edit_page") === "0") {
543
  jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
544
 
545
  cms_tree_page_view.log("mouseleave container");
546
+
547
  var $container = jQuery(e.target).closest("div.cms_tpv_container");
548
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
549
  var t = this;
550
+
551
  // Reset global timer
552
  var global_timer = $container.data("cmstpv_global_link_timer");
553
  if (global_timer) {
562
 
563
  // Maybe hide popup after a short while
564
  var hideTimer = setTimeout(function() {
565
+
566
  cms_tree_page_view.log("maybe hide popup because outside container");
567
 
568
  // But don't hide if we are inside the popup
587
  // When mouse enters actions div then cancel possibly global hide timer
588
  // If moved outside container and then back, cancel possibly global timer
589
  jQuery(document).on("mouseenter", "div.cms_tpv_page_actions", function(e) {
590
+
591
  var $this = jQuery(this);
592
  var $wrapper = $this.closest("div.cms_tpv_wrapper");
593
  var $container = $wrapper.find("div.cms_tpv_container");
594
  var timer = $container.data("cmstpv_global_link_timer");
595
+
596
  clearTimeout(timer);
597
 
598
  });
611
  * add childcount and other things to each li
612
  */
613
  function cms_tpv_bind_clean_node() {
614
+
615
  cms_tpv_tree.bind("move_node.jstree", function (event, data) {
616
  var nodeBeingMoved = data.rslt.o; // noden vi flyttar
617
  var nodeNewParent = data.rslt.np;
623
 
624
  // om ovanför
625
  o ovanför or
626
+
627
  // om efter
628
  o efter r
629
+
630
  // om inside
631
  o ovanför or
632
+
633
 
634
  drop_target : ".jstree-drop",
635
  drop_check : function (data) { return true; },
637
  drag_target : ".jstree-draggable",
638
  drag_finish : $.noop,
639
  drag_check : function (data) { return { after : false, before : false, inside : true }; }
640
+
641
  Gets executed after a valid drop, you get one parameter, which is as follows:
642
  data.o - the object being dragged
643
  data.r - the drop target
644
  */
645
+
646
  var node_id,
647
  ref_node_id;
648
  if (nodePosition == "before") {
655
  node_id = jQuery( nodeBeingMoved ).attr( "id" );
656
  ref_node_id = jQuery( nodeR ).attr( "id" );
657
  }
658
+
659
  // Update parent or menu order
660
  jQuery.post(ajaxurl, {
661
  action: "cms_tpv_move_page",
662
  "node_id": node_id,
663
  "ref_node_id": ref_node_id,
664
  "type": nodePosition,
665
+ "icl_post_language": selected_lang,
666
+ "cms-tpv-nonce": window.CMS_TPV_NONCE
667
  }, function(data, textStatus) {
668
  });
669
 
670
  });
671
+
672
  cms_tpv_tree.bind("clean_node.jstree", function(event, data) {
673
  var obj = (data.rslt.obj);
674
  if (obj && obj != -1) {
688
  if (childCount > 0) {
689
  aFirst.append("<span title='" + childCount + " " + cmstpv_l10n.child_pages + "' class='child_count'>("+childCount+")</span>");
690
  }
691
+
692
  // add protection type
693
  var rel = li.data("rel");
694
  if(rel == "password") {
720
 
721
  // Perform search when submiting form
722
  jQuery(document).on("submit", "form.cms_tree_view_search_form", function(e) {
723
+
724
  var $wrapper = jQuery(this).closest(".cms_tpv_wrapper");
725
  $wrapper.find(".cms_tpv_search_no_hits").hide();
726
  var s = $wrapper.find(".cms_tree_view_search").attr("value");
738
  $wrapper.find(".cms_tree_view_search_form_reset").fadeOut("fast");
739
  }
740
  $wrapper.find(".cms_tree_view_search_form_working").fadeOut("fast");
741
+
742
  return false;
743
 
744
  });
785
 
786
  // click on link to change WPML-language
787
  jQuery(document).on("click", "a.cms_tvp_switch_lang", function(e) {
788
+
789
  $wrapper = cms_tpv_get_wrapper(this);
790
 
791
  // Mark clicked link as selected
804
  // Post counts are stored on the links for all | public | trash
805
  var $ul_select_view = $wrapper.find(".cms-tpv-subsubsub-select-view");
806
  $ul_select_view.find("li.cms_tvp_view_is_status_view a").each(function(i, a_tag) {
807
+
808
  // check if this link has a data attr with count for the selected lang
809
  var $a = jQuery(a_tag);
810
  var link_count = $a.data("post-count-" + lang_code);
817
  // Set the view = reload the tree
818
  var current_view = cms_tpv_get_current_view(this);
819
  cms_tvp_set_view(current_view, this);
820
+
821
  return false;
822
 
823
  });
824
 
825
  function cms_tpv_hide_action_div() {
826
+
827
  }
828
 
829
 
830
  function cms_tpv_get_current_view(elm) {
831
+
832
  $wrapper = cms_tpv_get_wrapper(elm);
833
+
834
  if ($wrapper.find(".cms_tvp_view_all").hasClass("current")) {
835
  return "all";
836
  } else if ($wrapper.find(".cms_tvp_view_public").hasClass("current")) {
868
  } else if (view == "trash") {
869
  $wrapper.find(".cms_tvp_view_trash").addClass("current");
870
  } else {
871
+
872
  }
873
+
874
  // Reload tree
875
  var treeOptionsTmp = jQuery.extend(true, {}, treeOptions);
876
+ treeOptionsTmp.json_data.ajax.url = ajaxurl + CMS_TPV_AJAXURL + view + '&cms-tpv-nonce=' + window.CMS_TPV_NONCE + "&post_type=" + cms_tpv_get_post_type(elm) + "&lang=" + cms_tpv_get_wpml_selected_lang(elm);
877
 
878
  $wrapper.find(".cms_tpv_container").bind("loaded.jstree open_node.jstree", cms_tpv_tree_loaded);
879
  $wrapper.find(".cms_tpv_container").jstree(treeOptionsTmp);
896
  // It must exist because that's where we have our switch to tree-icon
897
  var view_switch = $("div.view-switch");
898
  if (! view_switch.length) {
899
+
900
  view_switch = $("<div class='view-switch'></div>");
901
  $("div.tablenav-pages:first").after(view_switch);
902
 
907
  //view_switch.append(" ");
908
 
909
  }
910
+
911
  // Add our link inside view switch
912
 
913
  /*
914
  view_switch.append(tree_view_switch_a);
915
  view_switch.addClass("view-switch-cstpv-icon-added");
916
+
917
  // if in tree mode: add a class to wpbody so we can style things
918
  if (cmstpv_postsoverview_wrap.length) {
919