cms_tpv_add_pages [cms_tpv_add_new_pages_names] => Array ( [0] => xxxxx [1] => yyyy [2] => ) [cms_tpv_add_type] => inside [cms_tpv_add_status] => draft [lang] => de ) */ $post_position = $_POST["cms_tpv_add_type"]; $post_status = $_POST["cms_tpv_add_status"]; $post_names = (array) $_POST["cms_tpv_add_new_pages_names"]; $ref_post_id = (int) $_POST["ref_post_id"]; $lang = $_POST["lang"]; // Check nonce if ( ! check_admin_referer("cms-tpv-add-pages") ) { wp_die( __( 'Cheatin’ uh?' ) ); } // If lang variable is set, then set some more wpml-related post/get-variables if ($lang) { // post seems to fix creating new posts in selcted lang $_POST["icl_post_language"] = $lang; // $_GET["lang"] = $lang; } // make sure the status is publish and nothing else (yes, perhaps I named it bad elsewhere) if ("published" === $post_status) $post_status = "publish"; // remove possibly empty posts $arr_post_names = array(); foreach ($post_names as $one_post_name) { if ( trim($one_post_name) ) { $arr_post_names[] = $one_post_name; } } $arr_post_names_count = sizeof($arr_post_names); // check that there are pages left if (empty($arr_post_names)) die("Error: no pages to add."); $ref_post = get_post($ref_post_id); if (NULL === $ref_post) die("Error: could not load reference post."); // Make room for our new pages // Get all pages at a level level and loop until our reference page // and then all pages after that one will get it's menu_order // increased by the same number as the number of new posts we're gonna add $ok_to_continue_by_permission = TRUE; $post_type_object = get_post_type_object($ref_post->post_type); $post_parent = 0; if ("after" === $post_position) { $post_parent = $ref_post->post_parent; $ok_to_continue_by_permission = apply_filters("cms_tree_page_view_post_user_can_add_after", current_user_can( $post_type_object->cap->create_posts, $ref_post_id), $ref_post_id); } elseif ("inside" === $post_position) { $post_parent = $ref_post->ID; $ok_to_continue_by_permission = apply_filters("cms_tree_page_view_post_user_can_add_inside", current_user_can( $post_type_object->cap->create_posts, $ref_post_id), $ref_post_id); } if ( ! $ok_to_continue_by_permission ) { wp_die( __( 'Cheatin’ uh?' ) ); return FALSE; } // $user_can_edit_page = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_type_object->cap->edit_post, $ref_post_id), $ref_post_id); /* perhaps for wpml: suppress_filters=0 */ $args = array( "post_status" => "any", "post_type" => $ref_post->post_type, "numberposts" => -1, "offset" => 0, "orderby" => 'menu_order', 'order' => 'asc', 'post_parent' => $post_parent, "suppress_filters" => FALSE ); //if ($lang) $args["lang"] = $lang; $posts = get_posts($args); #sf_d($_GET["lang"]);sf_d($args);sf_d($posts);exit; // If posts exist at this level, make room for our new pages by increasing the menu order if (sizeof($posts) > 0) { if ("after" === $post_position) { $has_passed_ref_post = FALSE; foreach ($posts as $one_post) { if ($has_passed_ref_post) { $post_update = array( "ID" => $one_post->ID, "menu_order" => $one_post->menu_order + $arr_post_names_count, "post_author" => $one_post->post_author, "post_modified" => $one_post->post_modified, //--- Added 2015-01-09 --- "post_modified_gmt" => $one_post->post_modified_gmt, //--- Added 2015-01-09 --- ); $return_id = wp_update_post($post_update); if (0 ===$return_id) die( "Error: could not update post with id " . $post_update->ID . "
Technical details: " . print_r($post_update) ); } if ( ! $has_passed_ref_post && $ref_post->ID === $one_post->ID ) { $has_passed_ref_post = TRUE; } } $new_menu_order = $ref_post->menu_order; } elseif ("inside" === $post_position) { // in inside, place at beginning // so just get first post and use that menu order as base $new_menu_order = $posts[0]->menu_order - $arr_post_names_count; } } else { // no posts, start at 0 $new_menu_order = 0; } $post_parent_id = NULL; if ("after" === $post_position) { $post_parent_id = $ref_post->post_parent; } elseif ("inside" === $post_position) { $post_parent_id = $ref_post->ID; } // Done maybe updating menu orders, add the new pages $arr_added_pages_ids = array(); foreach ($arr_post_names as $one_new_post_name) { $new_menu_order++; $newpost_args = array( "menu_order" => $new_menu_order, "post_parent" => $post_parent_id, "post_status" => ( ('publish' == $post_status) && !current_user_can('publish_posts') ? 'pending' : $post_status ), "post_title" => $one_new_post_name, "post_type" => $ref_post->post_type, ); $new_post_id = wp_insert_post($newpost_args); if (0 === $new_post_id) { die("Error: could not add post"); } $arr_added_pages_ids[] = $new_post_id; } // Done. Redirect to the first page created. $first_post_edit_link = get_edit_post_link($arr_added_pages_ids[0], ""); wp_redirect($first_post_edit_link); exit; } /** * Output and add hooks in head */ function cms_tpv_admin_head() { if (!cms_tpv_is_one_of_our_pages()) return; cms_tpv_setup_postsoverview(); global $cms_tpv_view; if (isset($_GET["cms_tpv_view"])) { $cms_tpv_view = htmlspecialchars($_GET["cms_tpv_view"]); } else { $cms_tpv_view = "all"; } ?> id, "_page_cms-tpv-page-{$one_post_type}") !== FALSE) { $is_plugin_page = TRUE; break; } } // Check if current page is one of the ones defined in $options["postsoverview"] if ($current_screen->base === "edit" && in_array($current_screen->post_type, $options["postsoverview"])) { $is_plugin_page = TRUE; } if ($current_screen->id === "settings_page_cms-tpv-options") { // Is settings page for plugin $is_plugin_page = TRUE; } elseif ($current_screen->id === "dashboard" && !empty($options["dashboard"])) { // At least one post type is enabled to be visible on dashboard $is_plugin_page = TRUE; } return $is_plugin_page; } /** * Add styles and scripts to pages that use the plugin */ function cms_admin_enqueue_scripts() { if (cms_tpv_is_one_of_our_pages()) { // renamed from cookie to fix problems with mod_security wp_enqueue_script( "jquery-cookie", CMS_TPV_URL . "scripts/jquery.biscuit.js", array("jquery")); wp_enqueue_script( "jquery-ui-sortable"); wp_enqueue_script( "jquery-jstree", CMS_TPV_URL . "scripts/jquery.jstree.js", false, CMS_TPV_VERSION); wp_enqueue_script( "jquery-alerts", CMS_TPV_URL . "scripts/jquery.alerts.js", false, CMS_TPV_VERSION); // wp_enqueue_script( "hoverIntent"); wp_enqueue_script( "cms_tree_page_view", CMS_TPV_URL . "scripts/cms_tree_page_view.js", false, CMS_TPV_VERSION); wp_enqueue_style( "cms_tpv_styles", CMS_TPV_URL . "styles/styles.css", false, CMS_TPV_VERSION ); wp_enqueue_style( "jquery-alerts", CMS_TPV_URL . "styles/jquery.alerts.css", false, CMS_TPV_VERSION ); $oLocale = array( "Enter_title_of_new_page" => __("Enter title of new page", 'cms-tree-page-view'), "child_pages" => __("child pages", 'cms-tree-page-view'), "Edit_page" => __("Edit page", 'cms-tree-page-view'), "View_page" => __("View page", 'cms-tree-page-view'), "Edit" => __("Edit", 'cms-tree-page-view'), "View" => __("View", 'cms-tree-page-view'), "Add_page" => __("Add page", 'cms-tree-page-view'), "Add_new_page_after" => __("Add new page after", 'cms-tree-page-view'), "after" => __("after", 'cms-tree-page-view'), "inside" => __("inside", 'cms-tree-page-view'), "Can_not_add_sub_page_when_status_is_draft" => __("Sorry, can't create a sub page to a page with status \"draft\".", 'cms-tree-page-view'), "Can_not_add_sub_page_when_status_is_trash" => __("Sorry, can't create a sub page to a page with status \"trash\".", 'cms-tree-page-view'), "Can_not_add_page_after_when_status_is_trash" => __("Sorry, can't create a page after a page with status \"trash\".", 'cms-tree-page-view'), "Add_new_page_inside" => __("Add new page inside", 'cms-tree-page-view'), "Status_draft" => __("draft", 'cms-tree-page-view'), "Status_future" => __("future", 'cms-tree-page-view'), "Status_password" => __("protected", 'cms-tree-page-view'), // is "protected" word better than "password" ? "Status_pending" => __("pending", 'cms-tree-page-view'), "Status_private" => __("private", 'cms-tree-page-view'), "Status_trash" => __("trash", 'cms-tree-page-view'), "Status_draft_ucase" => ucfirst( __("draft", 'cms-tree-page-view') ), "Status_future_ucase" => ucfirst( __("future", 'cms-tree-page-view') ), "Status_password_ucase" => ucfirst( __("protected", 'cms-tree-page-view') ), // is "protected" word better than "password" ? "Status_pending_ucase" => ucfirst( __("pending", 'cms-tree-page-view') ), "Status_private_ucase" => ucfirst( __("private", 'cms-tree-page-view') ), "Status_trash_ucase" => ucfirst( __("trash", 'cms-tree-page-view') ), "Password_protected_page" => __("Password protected page", 'cms-tree-page-view'), "Adding_page" => __("Adding page...", 'cms-tree-page-view'), "Adding" => __("Adding ...", 'cms-tree-page-view'), "No posts found" => __("No posts found.", 'cms-tree-page-view') ); wp_localize_script( "cms_tree_page_view", 'cmstpv_l10n', $oLocale); } } function cms_tpv_load_textdomain() { // echo "load textdomain"; if (is_admin()) { load_plugin_textdomain('cms-tree-page-view', WP_CONTENT_DIR . "/plugins/languages", "/cms-tree-page-view/languages"); } } function cms_tpv_admin_init() { // DEBUG //wp_enqueue_script( "jquery-hotkeys" ); // add row to plugin page add_filter( 'plugin_row_meta', 'cms_tpv_set_plugin_row_meta', 10, 2 ); // @todo: register settings #add_settings_section("cms_tree_page_view_settings", "cms_tree_page_view", "", ""); #register_setting( 'cms_tree_page_view_settings', "post-type-dashboard-post" ); // Add little promo box add_action("cms_tree_page_view/before_wrapper", "cms_tpv_promo_above_wrapper"); } function cms_tpv_promo_above_wrapper() { // enable this to show box while testing //update_option('cms_tpv_show_promo', 1); if ( isset($_GET["action"]) && "cms_tpv_remove_promo" == $_GET["action"] ) { $show_box = 0; update_option('cms_tpv_show_promo', $show_box); } else { $show_box = get_option('cms_tpv_show_promo', 1); } // Never show on dashboard, becuase highly annoying $current_screen = get_current_screen(); if ( $current_screen->id === "dashboard" ) { $show_box = false; } if ( ! $show_box ) { return; } ?>

Thanks for using CMS Tree Page View!

Do you like this plugin? Then give it a nice review!

Want to see who in you team edited what and when? Then Simple History is the plugin you need!

">

base && in_array($current_screen->post_type, $options["postsoverview"])) { // Ok, this is a post overview page that we are enabled for add_filter("views_" . $current_screen->id, "cmstpv_filter_views_edit_postsoverview"); cmstpv_postoverview_head(); } } /** * Add style etc to wp head to minimize flashing content */ function cmstpv_postoverview_head() { if ( isset($_GET["mode"]) && $_GET["mode"] === "tree" ) { ?> if view-switch exists: add item to it if view-switch not exists: add it + item to it */ $mode = "tree"; $class = isset($_GET["mode"]) && $_GET["mode"] == $mode ? " class='current' " : ""; $title = __("Tree View", 'cms-tree-page-view'); $tree_a = " $title\n"; // Copy of wordpress own, if it does not exist $wp_list_a = ""; if (is_post_type_hierarchical( $current_screen->post_type ) ) { $mode = "list"; $class = isset($_GET["mode"]) && $_GET["mode"] != $mode ? " class='cmstpv_add_list_view' " : " class='cmstpv_add_list_view current' "; $title = __("List View"); /* translation not missing - exists in wp */ $wp_list_a = "$title\n"; } $out = ""; $out .= $tree_a; $out .= $wp_list_a; // Output tree related stuff if that view/mode is selected if (isset($_GET["mode"]) && $_GET["mode"] === "tree") { $out .= sprintf('
%1$s
', $tree_common_stuff); } echo $out; return $filter_var; } /** * Add settings link to plugin page * Hopefully this helps some people to find the settings page quicker */ function cms_tpv_set_plugin_row_meta($links, $file) { if ($file === "cms-tree-page-view/index.php") { return array_merge( $links, array( sprintf( '%s', "cms-tpv-options", __('Settings') ) ) ); } return $links; } /** * Save settings, called when saving settings in general > cms tree page view */ function cms_tpv_save_settings() { if (isset($_POST["cms_tpv_action"]) && $_POST["cms_tpv_action"] == "save_settings" && check_admin_referer('update-options')) { $options = array(); $options["dashboard"] = isset( $_POST["post-type-dashboard"] ) ? (array) $_POST["post-type-dashboard"] : array(); $options["menu"] = isset( $_POST["post-type-menu"] ) ? (array) $_POST["post-type-menu"] : array(); $options["postsoverview"] = isset( $_POST["post-type-postsoverview"] ) ? (array) $_POST["post-type-postsoverview"] : array(); update_option('cms_tpv_options', $options); } } /** * Add widget to dashboard */ function cms_tpv_wp_dashboard_setup() { // echo "setup dashboard"; // add dashboard to capability edit_pages only if (current_user_can("edit_pages")) { $options = cms_tpv_get_options(); foreach ($options["dashboard"] as $one_dashboard_post_type) { $post_type_object = get_post_type_object($one_dashboard_post_type); $new_func_name = function () use ($one_dashboard_post_type){ cms_tpv_dashboard($one_dashboard_post_type); }; if ( ! empty( $post_type_object ) ) { $widget_name = sprintf( _x('%1$s Tree', "name of dashboard", "cms-tree-page-view"), $post_type_object->labels->name); wp_add_dashboard_widget( "cms_tpv_dashboard_widget_{$one_dashboard_post_type}", $widget_name, $new_func_name ); } } } } /** * Output on dashboard */ function cms_tpv_dashboard($post_type = "") { //cms_tpv_show_annoying_box(); cms_tpv_print_common_tree_stuff($post_type); } // Add items to the wp admin menu function cms_tpv_admin_menu() { // add $options = cms_tpv_get_options(); foreach ($options["menu"] as $one_menu_post_type) { if ( cms_tpv_post_type_is_ignored($one_menu_post_type) ) { continue; } // post is a special one. if ($one_menu_post_type == "post") { $slug = "edit.php"; } else { $slug = "edit.php?post_type=$one_menu_post_type"; } $post_type_object = get_post_type_object($one_menu_post_type); // Only try to add menu if we got a valid post type object // I think you can get a notice message here if you for example have enabled // the menu for a custom post type that you later on remove? if ( ! empty( $post_type_object ) ) { $menu_name = _x("Tree View", "name in menu", "cms-tree-page-view"); $page_title = sprintf(_x('%1$s Tree View', "title on page with tree", "cms-tree-page-view"), $post_type_object->labels->name); add_submenu_page($slug, $page_title, $menu_name, $post_type_object->cap->edit_posts, "cms-tpv-page-$one_menu_post_type", "cms_tpv_pages_page"); } } $page_title = apply_filters("cms_tree_page_view_options_page_title", CMS_TPV_NAME); $menu_title = apply_filters("cms_tree_page_view_options_menu_title", CMS_TPV_NAME); add_submenu_page( 'options-general.php', $page_title, $menu_title, "administrator", "cms-tpv-options", "cms_tpv_options"); } /** * Output options page */ function cms_tpv_options() { ?>

TRUE ), "objects"); $arr_page_options = array(); foreach ($post_types as $one_post_type) { if ( cms_tpv_post_type_is_ignored($one_post_type->name) ) { continue; } $name = $one_post_type->name; if ($name === "post") { // no support for pages. you could show them.. but since we can't reorder them there is not idea to show them.. or..? // 14 jul 2011: ok, let's enable it for posts too. some people says it useful // http://wordpress.org/support/topic/this-plugin-should-work-also-on-posts // continue; } else if ($name === "attachment") { // No support for media/attachment continue; } $arr_page_options[] = "post-type-dashboard-$name"; $arr_page_options[] = "post-type-menu-$name"; $arr_page_options[] = "post-type-postsoverview-$name"; echo ""; echo ""; echo ""; echo ""; } ?>
"; echo "

".$one_post_type->label."

"; echo "
"; echo "

"; $checked = (in_array($name, $options["dashboard"])) ? " checked='checked' " : ""; echo " "; echo "
"; $checked = (in_array($name, $options["menu"])) ? " checked='checked' " : ""; echo " "; echo "
"; $checked = (in_array($name, $options["postsoverview"])) ? " checked='checked' " : ""; echo " "; echo "

"; echo "
" />

hierarchical; // special case for posts, fake-support hierachical if ("post" == $post_type_object->name) { $is_hierarchical = true; } return $is_hierarchical; } /** * Get number of posts from WPML */ function cms_tpv_get_wpml_post_counts($post_type) { global $wpdb; $arr_statuses = array("publish", "draft", "trash", "future", "private"); $arr_counts = array(); foreach ($arr_statuses as $post_status) { $extra_cond = ""; if ($post_status){ $extra_cond .= " AND post_status = '" . $post_status . "'"; } if ($post_status != 'trash'){ $extra_cond .= " AND post_status <> 'trash'"; } $extra_cond .= " AND post_status <> 'auto-draft'"; $sql = " SELECT language_code, COUNT(p.ID) AS c FROM {$wpdb->prefix}icl_translations t JOIN {$wpdb->posts} p ON t.element_id=p.ID JOIN {$wpdb->prefix}icl_languages l ON t.language_code=l.code AND l.active = 1 WHERE p.post_type='{$post_type}' AND t.element_type='post_{$post_type}' {$extra_cond} GROUP BY language_code "; $res = $wpdb->get_results($sql); $langs = array(); $langs['all'] = 0; foreach($res as $r) { $langs[$r->language_code] = $r->c; $langs['all'] += $r->c; } $arr_counts[$post_status] = $langs; } return $arr_counts; } /** * Print tree stuff that is common for both dashboard and page */ function cms_tpv_print_common_tree_stuff($post_type = "") { global $sitepress, $cms_tpv_view, $wpdb; if ( ! $post_type ) { $post_type = cms_tpv_get_selected_post_type(); } $post_type_object = get_post_type_object($post_type); $get_pages_args = array("post_type" => $post_type); $pages = cms_tpv_get_pages($get_pages_args); // check if wpml is active and if this post type is one of its enabled ones $wpml_current_lang = ""; $wmpl_active_for_post = FALSE; if (defined("ICL_SITEPRESS_VERSION")) { $wpml_post_types = $sitepress->get_translatable_documents(); if (array_key_exists($post_type, $wpml_post_types)) { $wmpl_active_for_post = TRUE; $wpml_current_lang = $sitepress->get_current_language(); } } $status_data_attributes = array("all" => "", "publish" => "", "trash" => ""); // Calculate post counts if ($wpml_current_lang) { // Count code for WPML, mostly taken/inspired from WPML Multilingual CMS, sitepress.class.php $langs = array(); $wpml_post_counts = cms_tpv_get_wpml_post_counts($post_type); $post_count_all = (int) @$wpml_post_counts["private"][$wpml_current_lang] + (int) @$wpml_post_counts["future"][$wpml_current_lang] + (int) @$wpml_post_counts["publish"][$wpml_current_lang] + (int) @$wpml_post_counts["draft"][$wpml_current_lang]; $post_count_publish = (int) @$wpml_post_counts["publish"][$wpml_current_lang]; $post_count_trash = (int) @$wpml_post_counts["trash"][$wpml_current_lang]; foreach ($wpml_post_counts["publish"] as $one_wpml_lang => $one_wpml_lang_count) { if ("all" === $one_wpml_lang) continue; $lang_post_count_all = (int) @$wpml_post_counts["publish"][$one_wpml_lang] + (int) @$wpml_post_counts["draft"][$one_wpml_lang]; $lang_post_count_publish = (int) @$wpml_post_counts["publish"][$one_wpml_lang]; $lang_post_count_trash = (int) @$wpml_post_counts["trash"][$one_wpml_lang]; $status_data_attributes["all"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_all}' "; $status_data_attributes["publish"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_publish}' "; $status_data_attributes["trash"] .= " data-post-count-{$one_wpml_lang}='{$lang_post_count_trash}' "; } } else { $post_count = wp_count_posts($post_type); $post_count_all = $post_count->publish + $post_count->future + $post_count->draft + $post_count->pending + $post_count->private; $post_count_publish = $post_count->publish; $post_count_trash = $post_count->trash; } // output js for the root/top level // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) { // @todo: make into function since used at other places $jstree_open = array(); if ( isset( $_COOKIE["jstree_open"] ) ) { $jstree_open = $_COOKIE["jstree_open"]; // like this: [jstree_open] => cms-tpv-1282,cms-tpv-1284,cms-tpv-3 $jstree_open = explode( ",", $jstree_open ); for( $i=0; $i
=1) { $lang_out = ""; $lang_out .= ""; echo $lang_out; } } if (true) { // start the party! ?>

labels->add_new_item ?>

  • " type="text" name="cms_tpv_add_new_pages_names[]">


" class="button-primary">

' . __("No posts found.", 'cms-tree-page-view') . '

'; } ?>

labels->name); echo $page_title; // Add "add new" link the same way as the regular post page has if ( current_user_can( $post_type_object->cap->create_posts ) ) { echo ' ' . esc_html( $post_type_object->labels->add_new ) . ''; } ?>

"post", "parent" => "", "view" => "all" // all | public | trash ); $r = wp_parse_args( $args, $defaults ); $get_posts_args = array( "fields" => "ids", "numberposts" => "-1", "orderby" => "menu_order title", "order" => "ASC", // "caller_get_posts" => 1, // get sticky posts in natural order (or so I understand it anyway). Deprecated since 3.1 "ignore_sticky_posts" => 1, // "post_type" => "any", "post_type" => $r["post_type"], "xsuppress_filters" => "0" ); if ($r["parent"]) { $get_posts_args["post_parent"] = $r["parent"]; } else { $get_posts_args["post_parent"] = "0"; } if ($r["view"] == "all") { $get_posts_args["post_status"] = "any"; // "any" seems to get all but auto-drafts } elseif ($r["view"] == "trash") { $get_posts_args["post_status"] = "trash"; // if getting trash, just get all pages, don't care about parent? // because otherwise we have to mix trashed pages and pages with other statuses. messy. $get_posts_args["post_parent"] = null; } else { $get_posts_args["post_status"] = "publish"; } // does not work with plugin role scoper. don't know why, but this should fix it remove_action("get_pages", array('ScoperHardway', 'flt_get_pages'), 1, 2); // does not work with plugin ALO EasyMail Newsletter remove_filter('get_pages','ALO_exclude_page'); #do_action_ref_array('parse_query', array(&$this)); #print_r($get_posts_args); $pages = get_posts($get_posts_args); // filter out pages for wpml, by applying same filter as get_pages does // only run if wpml is available or always? // Note: get_pages filter uses orderby comma separated and with the key sort_column $get_posts_args["sort_column"] = str_replace(" ", ", ", $get_posts_args["orderby"]); // We only fetch ids above, but if we run the get_pages filter we need to send pages as object $pages_as_objects = array(); foreach ($pages as $page_id) { $one_page = new stdClass(); $one_page->ID = $page_id; $pages_as_objects[] = $one_page; } // echo "
";print_r($pages_as_objects);exit;

	$pages_as_objects = apply_filters('get_pages', $pages_as_objects, $get_posts_args);

	return $pages_as_objects;

}

function cms_tpv_parse_query($q) {
}


/**
 * Output JSON for the children of a node
 * $arrOpenChilds = array with id of pages to open children on
 */
function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {

	$arrPages = cms_tpv_get_pages("parent=$pageID&view=$view&post_type=$post_type");

	if ($arrPages) {

		global $current_screen;
		$screen = convert_to_screen("edit");
		#return;

		// If this is set to null then quick/bul edit stops working on posts (not pages)
		// If did set it to null sometime. Can't remember why...
		// $screen->post_type = null;

		$post_type_object = get_post_type_object($post_type);
		ob_start(); // some plugins, for example magic fields, return javascript and things here. we're not compatible with that, so just swallow any output
		$posts_columns = get_column_headers($screen);
		ob_get_clean();

		unset($posts_columns["cb"], $posts_columns["title"], $posts_columns["author"], $posts_columns["categories"], $posts_columns["tags"], $posts_columns["date"]);

		global $post;

		// Translated post statuses
		$post_statuses = get_post_statuses();


		?>[ID );

			$tmpPost = $post;
			$post = $onePage;
			$page_id = $onePage->ID;
			$arrChildPages = NULL;

			$editLink = get_edit_post_link($onePage->ID, 'notDisplay');
			$content = esc_html($onePage->post_content);
			$content = str_replace(array("\n","\r"), "", $content);
			$hasChildren = false;

			// if viewing trash, don't get children. we watch them "flat" instead
			if ($view == "trash") {
			} else {
				$arrChildPages = cms_tpv_get_pages("parent={$onePage->ID}&view=$view&post_type=$post_type");
			}

			if ( !empty($arrChildPages) ) {
				$hasChildren = true;
			}
			// if no children, output no state
			$strState = '"state": "closed",';
			if (!$hasChildren) {
				$strState = '';
			}

			// type of node
			$rel = $onePage->post_status;
			if ($onePage->post_password) {
				$rel = "password";
			}

			// modified time
			$post_modified_time = strtotime($onePage->post_modified);
			$post_modified_time =  date_i18n(get_option('date_format'), $post_modified_time, false);

			// last edited by
			setup_postdata($post);

			$post_author = cms_tpv_get_the_modified_author();
			if (empty($post_author)) {
				$post_author = __("Unknown user", 'cms-tree-page-view');
			}

			$title = get_the_title($onePage->ID); // so hooks and stuff will do their work

			$title = apply_filters("cms_tree_page_view_post_title", $title, $onePage);

			if (empty($title)) {
				$title = __("", 'cms-tree-page-view');
			}

			$arr_page_css_styles = array();
			$user_can_edit_page = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_type_object->cap->edit_post, $page_id), $page_id);
			$user_can_add_inside = apply_filters("cms_tree_page_view_post_user_can_add_inside", current_user_can( $post_type_object->cap->create_posts, $page_id), $page_id);
			$user_can_add_after = apply_filters("cms_tree_page_view_post_user_can_add_after", current_user_can( $post_type_object->cap->create_posts, $page_id), $page_id);

			if ( $user_can_edit_page ) {
				$arr_page_css_styles[] = "cms_tpv_user_can_edit_page_yes";
			} else {
				$arr_page_css_styles[] = "cms_tpv_user_can_edit_page_no";
			}

			if ( $user_can_add_inside ) {
				$arr_page_css_styles[] = "cms_tpv_user_can_add_page_inside_yes";
			} else {
				$arr_page_css_styles[] = "cms_tpv_user_can_add_page_inside_no";
			}

			if ( $user_can_add_after ) {
				$arr_page_css_styles[] = "cms_tpv_user_can_add_page_after_yes";
			} else {
				$arr_page_css_styles[] = "cms_tpv_user_can_add_page_after_no";
			}

			$page_css = join(" ", $arr_page_css_styles);

			// fetch columns
			$str_columns = "";
			foreach ( $posts_columns as $column_name => $column_display_name ) {
				$col_name = $column_display_name;
				if ($column_name == "comments") {
					$col_name = __("Comments");
				}
				$str_columns .= "
$col_name
"; $str_columns .= "
"; if ($column_name == "comments") { $str_columns .= '
'; $left = get_pending_comments_num( $onePage->ID ); $pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); $pending_phrase2 = ""; if ($left) { $pending_phrase2 = " + $left " . __("pending"); } if ( $left ) { $str_columns .= ''; } ob_start(); comments_number("" . _x('0', 'comment count') . "$pending_phrase2", "" . _x('1', 'comment count') . "$pending_phrase2", "" . _x('%', 'comment count') . "$pending_phrase2"); $str_columns .= ob_get_clean(); if ( $left ) { $str_columns .= ''; } $str_columns .= "
"; } else { ob_start(); do_action('manage_pages_custom_column', $column_name, $onePage->ID); $str_columns .= ob_get_clean(); } $str_columns .= "
"; } if ($str_columns) { $str_columns = "
$str_columns
"; } $str_columns = json_encode($str_columns); ?> { "data": { "title": , "attr": { "href": "" ID ?>" */ ?> }"*/?> }, "attr": { ", */ ?> "id": "cms-tpv-ID ?>", ", */ ?> "class": "" }, "metadata": { "id": "cms-tpv-ID ?>", "post_id": "ID ?>", "post_type": "post_type ?>", "post_status": "post_status ?>", "post_status_translated": "post_status]) ? $post_statuses[$onePage->post_status] : $onePage->post_status ?>", "rel": "", "childCount": , "permalink": "ID)) ?>", "editlink": "", "modified_time": "", "modified_author": "", "columns": , "user_can_edit_page": "", "user_can_add_page_inside": "", "user_can_add_page_after": "", "post_title": } ID, $arrOpenChilds)) { ?>, "children": ID, $view, $arrOpenChilds, $post_type); ?> } ,]cap->edit_posts ) ) { die( __( 'Cheatin’ uh?' ) ); } if ($action) { if ($search) { // find all pages that contains $search // collect all post_parent // for each parent id traverse up until post_parent is 0, saving all ids on the way // what to search: since all we see in the GUI is the title, just search that global $wpdb; $sqlsearch = "%{$search}%"; // feels bad to leave out the "'" in the query, but prepare seems to add it..?? $sql = $wpdb->prepare("SELECT id, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_title LIKE %s", $sqlsearch); $hits = $wpdb->get_results($sql); $arrNodesToOpen = array(); foreach ($hits as $oneHit) { $arrNodesToOpen[] = $oneHit->post_parent; } $arrNodesToOpen = array_unique($arrNodesToOpen); $arrNodesToOpen2 = array(); // find all parents to the arrnodestopen foreach ($arrNodesToOpen as $oneNode) { if ($oneNode > 0) { // not at top so check it out $parentNodeID = $oneNode; while ($parentNodeID != 0) { $hits = $wpdb->get_results($sql); $sql = "SELECT id, post_parent FROM $wpdb->posts WHERE id = $parentNodeID"; $row = $wpdb->get_row($sql); $parentNodeID = $row->post_parent; $arrNodesToOpen2[] = $parentNodeID; } } } $arrNodesToOpen = array_merge($arrNodesToOpen, $arrNodesToOpen2); $sReturn = ""; #foreach ($arrNodesToOpen as $oneNodeID) { # $sReturn .= "cms-tpv-{$oneNodeID},"; #} #$sReturn = preg_replace("/,$/", "", $sReturn); foreach ($arrNodesToOpen as $oneNodeID) { $sReturn .= "\"#cms-tpv-{$oneNodeID}\","; } $sReturn = preg_replace('/,$/', "", $sReturn); if ($sReturn) { $sReturn = "[" . $sReturn . "]"; } if ($sReturn) { echo $sReturn; } else { // if no hits echo "[]"; } exit; } else { // regular get $id = (isset($_GET["id"])) ? $_GET["id"] : null; $id = (int) str_replace("cms-tpv-", "", $id); $jstree_open = array(); if ( isset( $_COOKIE["jstree_open"] ) ) { $jstree_open = $_COOKIE["jstree_open"]; // like this: [jstree_open] => cms-tpv-1282,cms-tpv-1284,cms-tpv-3 #var_dump($jstree_open); string(22) "#cms-tpv-14,#cms-tpv-2" $jstree_open = explode( ",", $jstree_open ); for( $i=0; $isave_post_actions if ($node_id && $ref_node_id) { $post_node = get_post($node_id); $post_ref_node = get_post($ref_node_id); $post_node_post_type_object = get_post_type_object($post_node->post_type); $post_ref_node_post_type_object = get_post_type_object($post_ref_node->post_type); $user_can_edit_post_node_post = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_node_post_type_object->cap->edit_post, $node_id), $node_id); $user_can_edit_post_ref_node_post = apply_filters("cms_tree_page_view_post_can_edit", current_user_can( $post_ref_node_post_type_object->cap->edit_post, $ref_node_id), $ref_node_id); // Check that user is allowed to edit both pages thare are to be moved if (!$user_can_edit_post_node_post || !$user_can_edit_post_ref_node_post) { exit; } // first check that post_node (moved post) is not in trash. we do not move them if ($post_node->post_status == "trash") { exit; } if ( "inside" == $type ) { // post_node is moved inside ref_post_node // add ref_post_node as parent to post_node and set post_nodes menu_order to 0 // @todo: shouldn't menu order of existing items be changed? $post_to_save = array( "ID" => $post_node->ID, "menu_order" => 0, "post_parent" => $post_ref_node->ID, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did inside"; } elseif ( "before" == $type ) { // post_node is placed before ref_post_node // 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 // we do this so there will be room for our page if it's the first page // so: no move of individial posts yet $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_type = %s AND post_parent = %d", $post_ref_node->post_type, $post_ref_node->post_parent ) ); // update menu order with +1 for all pages below ref_node, this should fix the problem with "unmovable" pages because of // multiple pages with the same menu order (...which is not the fault of this plugin!) $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = menu_order+1 WHERE post_type = %s AND menu_order >= %d", $post_ref_node->post_type, $post_ref_node->menu_order+1) ); $post_to_save = array( "ID" => $post_node->ID, "menu_order" => $post_ref_node->menu_order, "post_parent" => $post_ref_node->post_parent, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did before"; } elseif ( "after" == $type ) { // post_node is placed after ref_post_node // update menu_order of all posts with the same parent ref_post_node and with a menu_order of the same as ref_post_node, but do not include ref_post_node // +2 since multiple can have same menu order and we want our moved post to have a unique "spot" $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 ", $post_ref_node->post_type, $post_ref_node->post_parent, $post_ref_node->menu_order, $post_ref_node->ID ) ); // update menu_order of post_node to the same that ref_post_node_had+1 #$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 ) ); $post_to_save = array( "ID" => $post_node->ID, "menu_order" => $post_ref_node->menu_order+1, "post_parent" => $post_ref_node->post_parent, "post_type" => $post_ref_node->post_type ); wp_update_post( $post_to_save ); echo "did after"; } #echo "ok"; // I'm done here! } else { // error } // ok, we have updated the order of the pages // but we must tell wordpress that we have done something // other plugins (cache plugins) will not know to clear the cache otherwise // edit_post seems like the most appropriate action to fire // fire for the page that was moved? can not fire for all.. would be crazy, right? #wp_update_post(array("ID" => $node_id)); #wp_update_post(array("ID" => $post_ref_node)); #clean_page_cache($node_id); clean_page_cache($post_ref_node); // hmpf.. db cache reloaded don't care do_action("cms_tree_page_view_node_move_finish"); exit; } /** * Show a box with some dontate-links and stuff */ function cms_tpv_show_annoying_box() { //update_option('cms_tpv_show_annoying_little_box', 1); // enable this to show box while testing if ( isset($_GET["action"]) && "cms_tpv_remove_annoying_box" == $_GET["action"] ) { $show_box = 0; update_option('cms_tpv_show_annoying_little_box', $show_box); } else { $show_box = get_option('cms_tpv_show_annoying_little_box', 1); } if ($show_box) { ?>

– how can I thank you?', 'cms-tree-page-view') ?>

  • Give it a nice review over at the WordPress Plugin Directory', 'cms-tree-page-view'), "http://wordpress.org/support/view/plugin-reviews/cms-tree-page-view") ?>
  • Give a donation – any amount will make me happy', 'cms-tree-page-view'), "http://eskapism.se/sida/donate/?utm_source=wordpress&utm_medium=banner&utm_campaign=promobox") ?>
  • Post a nice tweet or make a nice blog post about the plugin', 'cms-tree-page-view'), "https://twitter.com/intent/tweet?text=I really like the CMS Tree Page View plugin for WordPress http://wordpress.org/extend/plugins/cms-tree-page-view/") ?>

support forum for help.', 'cms-tree-page-view'), "http://wordpress.org/support/plugin/cms-tree-page-view") ?>

">

"; print_r($var); echo "
"; } } /** * Install function * Called from hook register_activation_hook() */ function cms_tpv_install() { // after upgrading/re-enabling the plugin, also re-enable the little please-donate-box update_option('cms_tpv_show_annoying_little_box', 1); update_option('cms_tpv_show_promo', 1); // first install or pre custom posts version: // make sure pages are enabled by default cms_tpv_setup_defaults(); // set to current version update_option('cms_tpv_version', CMS_TPV_VERSION); } function cms_tvp_setup_caps() { // Add necessary capabilities to allow moving tree of cms_tpv $roles = array( 'administrator' => array(CMS_TPV_MOVE_PERMISSION), 'editor' => array(CMS_TPV_MOVE_PERMISSION), // 'author' => array(CMS_TPV_MOVE_PERMISSION), // 'contributor' => array(CMS_TPV_MOVE_PERMISSION) ); foreach ( $roles as $role => $caps ) { cms_tpv_add_caps_to_role( $role, $caps ); } } function cms_tpv_uninstall() { // Remove capabilities to disallow moving tree of cms_tpv $roles = array( 'administrator' => array(CMS_TPV_MOVE_PERMISSION), 'editor' => array(CMS_TPV_MOVE_PERMISSION) ); foreach ( $roles as $role => $caps ) { cms_tpv_remove_caps_from_role( $role, $caps ); } } /** * Adds an array of capabilities to a role. */ function cms_tpv_add_caps_to_role( $role, $caps ) { global $wp_roles; if ( $wp_roles->is_role( $role ) ) { $role = get_role( $role ); foreach ( $caps as $cap ) $role->add_cap( $cap ); } } /** * Remove an array of capabilities from role. */ function cms_tpv_remove_caps_from_role( $role, $caps ) { global $wp_roles; if ( $wp_roles->is_role( $role ) ) { $role = get_role( $role ); foreach ( $caps as $cap ) $role->remove_cap( $cap ); } } // cms_tpv_install(); /** * setup some defaults */ function cms_tpv_setup_defaults() { // check and update version $version = get_option('cms_tpv_version', 0); #$version = 0; // uncomment to test default settings if ($version <= 0) { #error_log("tree: setup defaults, beacuse db version less than 0"); $options = array(); // Add pages to both dashboard and menu $options["dashboard"] = array("page"); // since 0.10.1 enable menu for all hierarchical custom post types // since 1.2 also enable on post overview page $post_types = get_post_types(array( "show_ui" => TRUE, "hierarchical" => TRUE ), "objects"); foreach ($post_types as $one_post_type) { $options["menu"][] = $one_post_type->name; $options["postsoverview"][] = $one_post_type->name; } $options["menu"] = array_unique($options["menu"]); $options["postsoverview"] = array_unique($options["postsoverview"]); update_option('cms_tpv_options', $options); } } /** * when plugins are loaded, check if current plugin version is same as stored * if not = it's an upgrade. right? */ function cms_tpv_plugins_loaded($a) { $installed_version = get_option('cms_tpv_version', 0); //echo "installed_version in options table: $installed_version"; //echo "
version according to this file" . CMS_TPV_VERSION; if ($installed_version != CMS_TPV_VERSION) { // new version! // upgrade stored version to current version update_option('cms_tpv_version', CMS_TPV_VERSION); // show that annoying litte box again update_option('cms_tpv_show_annoying_little_box', 1); update_option('cms_tpv_show_promo', 1); // setup caps/persmissions cms_tvp_setup_caps(); } } /** * modified version of get_the_modified_author() that checks that user was retrieved before applying filters * according to http://wordpress.org/support/topic/better-wp-security-conflict-1?replies=7 some users * had problems when a user had been deleted */ function cms_tpv_get_the_modified_author() { if ( $last_id = get_post_meta( get_post()->ID, '_edit_last', true) ) { $last_user = get_userdata($last_id); if( $last_user !== false ){ return apply_filters('the_modified_author', $last_user->display_name); } } }