/** * 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 < sizeof($jstree_open); $i++) { $jstree_open[$i] = (int) str_replace("#cms-tpv-", "", $jstree_open[$i]); } } ob_start(); cms_tpv_print_childs(0, $cms_tpv_view, $jstree_open, $post_type); $json_data = ob_get_clean(); if (!$json_data) { $json_data = '{}'; } ?> <script type="text/javascript"> cms_tpv_jsondata["<?php echo $post_type; ?> "] = <?php echo $json_data; ?> ; </script> <?php do_action("cms_tree_page_view/before_wrapper"); ?> <div class="cms_tpv_wrapper"> <input type="hidden" name="cms_tpv_meta_post_type" value="<?php echo $post_type; ?> " /> <input type="hidden" name="cms_tpv_meta_post_type_hierarchical" value="<?php echo (int) cms_tpv_is_post_type_hierarchical($post_type_object); ?> " /> <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang; ?> " /> <?php // check if WPML is activated and show a language-menu if ($wmpl_active_for_post) { $wpml_langs = icl_get_languages(); $wpml_active_lang = null; if (sizeof($wpml_langs) >= 1) { $lang_out = ""; $lang_out .= "<ul class='cms-tpv-subsubsub cms_tvp_switch_langs'>"; foreach ($wpml_langs as $one_lang) { $one_lang_details = $sitepress->get_language_details($one_lang["language_code"]); // english_name | display_name $selected = ""; if ($one_lang["active"]) { $wpml_active_lang = $one_lang; $selected = "current"; } $lang_count = (int) @$wpml_post_counts["publish"][$one_lang["language_code"]] + (int) @$wpml_post_counts["draft"][$one_lang["language_code"]]; $lang_out .= "\n\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t<a class='cms_tvp_switch_lang {$selected} cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'>\n\t\t\t\t\t\t\t\t{$one_lang_details['display_name']}\n\t\t\t\t\t\t\t\t<span class='count'>(" . $lang_count . ")</span>\n\t\t\t\t\t\t\t</a> |</li>"; } $lang_out = preg_replace('/ \\|<\\/li>$/', "</li>", $lang_out); $lang_out .= "</ul>"; echo $lang_out; } } if (true) { // start the party! ?> <ul class="cms-tpv-subsubsub cms-tpv-subsubsub-select-view"> <li class="cms_tvp_view_is_status_view"> <a class="cms_tvp_view_all <?php echo $cms_tpv_view == "all" ? "current" : ""; ?> " href="#" <?php echo $status_data_attributes["all"]; ?> > <?php _e("All", 'cms-tree-page-view'); ?> <span class="count">(<?php echo $post_count_all; ?> )</span> </a> |</li> <li class="cms_tvp_view_is_status_view"> <a class="cms_tvp_view_public <?php echo $cms_tpv_view == "public" ? "current" : ""; ?> " href="#" <?php echo $status_data_attributes["publish"]; ?> > <?php _e("Public", 'cms-tree-page-view'); ?> <span class="count">(<?php echo $post_count_publish; ?> )</span> </a> |</li> <li class="cms_tvp_view_is_status_view"> <a class="cms_tvp_view_trash <?php echo $cms_tpv_view == "trash" ? "current" : ""; ?> " href="#" <?php echo $status_data_attributes["trash"]; ?> > <?php _e("Trash", 'cms-tree-page-view'); ?> <span class="count">(<?php echo $post_count_trash; ?> )</span> </a> </li> <?php if (cms_tpv_is_post_type_hierarchical($post_type_object)) { ?> <li><a href="#" class="cms_tpv_open_all"><?php _e("Expand", 'cms-tree-page-view'); ?> </a> |</li> <li><a href="#" class="cms_tpv_close_all"><?php _e("Collapse", 'cms-tree-page-view'); ?> </a></li> <?php } ?> <li> <form class="cms_tree_view_search_form" method="get" action=""> <input type="text" name="search" class="cms_tree_view_search" /> <a title="<?php _e("Clear search", 'cms-tree-page-view'); ?> " class="cms_tree_view_search_form_reset" href="#">x</a> <input type="submit" class="cms_tree_view_search_submit button button-small" value="<?php _e("Search", 'cms-tree-page-view'); ?> " /> <span class="cms_tree_view_search_form_working"><?php _e("Searching...", 'cms-tree-page-view'); ?> </span> <span class="cms_tree_view_search_form_no_hits"><?php _e("Nothing found.", 'cms-tree-page-view'); ?> </span> </form> </li> </ul> <div class="cms_tpv_working"> <?php _e("Loading...", 'cms-tree-page-view'); ?> </div> <div class="cms_tpv_message updated below-h2 hidden"><p>Message goes here.</p></div> <div class="updated below-h2 hidden cms_tpv_search_no_hits"><p><?php _e("Search: no pages found", 'cms-tree-page-view'); ?> </p></div> <div class="cms_tpv_container tree-default"> <?php _e("Loading tree", 'cms-tree-page-view'); ?> </div> <div style="clear: both;"></div> <!-- template forpopup with actions --> <div class="cms_tpv_page_actions"> <!-- cms_tpv_page_actions_page_id --> <h4 class="cms_tpv_page_actions_headline"></h4> <p class="cms_tpv_action_edit_and_view"> <a href="#" title='<?php _e("Edit page", "cms-tree-page-view"); ?> ' class='cms_tpv_action_edit'><?php _e("Edit", "cms-tree-page-view"); ?> </a> <a href="#" title='<?php _e("View page", "cms-tree-page-view"); ?> ' class='cms_tpv_action_view'><?php _e("View", "cms-tree-page-view"); ?> </a> </p> <!-- links to add page --> <p class="cms_tpv_action_add_and_edit_page"> <span class='cms_tpv_action_add_page'><?php echo $post_type_object->labels->add_new_item; ?> </span> <a class='cms_tpv_action_add_page_after' href="#" title='<?php _e("Add new page after", "cms-tree-page-view"); ?> ' ><?php _e("After", "cms-tree-page-view"); ?> </a> <?php // if post type is hierarchical we can add pages inside if (cms_tpv_is_post_type_hierarchical($post_type_object)) { ?> <a class='cms_tpv_action_add_page_inside' href="#" title='<?php _e("Add new page inside", "cms-tree-page-view"); ?> ' ><?php _e("Inside", "cms-tree-page-view"); ?> </a><?php } // if post status = draft then we can not add pages inside because wordpress currently can not keep its parent if we edit the page ?> <!-- <span class="cms_tpv_action_add_page_inside_disallowed"><?php _e("Can not create page inside of a page with draft status", "cms-tree-page-view"); ?> </span> --> </p> <div class="cms_tpv_action_add_doit"> <form method="post" action="<?php echo admin_url('admin-ajax.php', 'relative'); ?> "> <input type="hidden" name="action" value="cms_tpv_add_pages"> <input type="hidden" name="ref_post_id" value=""> <?php wp_nonce_field("cms-tpv-add-pages"); ?> <!-- lang for wpml --> <input type="hidden" name="lang" value=""> <!-- <fieldset> --> <h4><?php _e("Add page(s)", "cms-tree-page-view"); ?> </h4> <div> <!-- Pages<br> --> <ul class="cms_tpv_action_add_doit_pages"> <li><span></span><input placeholder="<?php _e("Enter title here"); ?> " type="text" name="cms_tpv_add_new_pages_names[]"></li> </ul> </div> <div class="cms_tpv_add_position"> <?php _e("Position", "cms-tree-page-view"); ?> <br> <label><input type="radio" name="cms_tpv_add_type" value="after"> <?php _e("After", "cms-tree-page-view"); ?> </label> <label><input type="radio" name="cms_tpv_add_type" value="inside"> <?php _e("Inside", "cms-tree-page-view"); ?> </label> </div> <div> <?php _e("Status", "cms-tree-page-view"); ?> <br> <label><input type="radio" name="cms_tpv_add_status" value="draft" checked> <?php _e("Draft", "cms-tree-page-view"); ?> </label> <label><input type="radio" name="cms_tpv_add_status" value="published"> <?php current_user_can('publish_posts') ? _e("Published", "cms-tree-page-view") : _e("Submit for Review", "cms-tree-page-view"); ?> </label> </div> <div> <input type="submit" value="<?php _e("Add", "cms-tree-page-view"); ?> " class="button-primary"> <?php _e("or", "cms-tree-page-view"); ?> <a href="#" class="cms_tpv_add_cancel"><?php _e("cancel", "cms-tree-page-view"); ?> </a> </div> <!-- </fieldset> --> </form> </div> <dl> <dt><?php _e("Last modified", 'cms-tree-page-view'); ?> </dt> <dd> <span class="cms_tpv_page_actions_modified_time"></span> <?php _e("by", "cms-tree-page-view"); ?> <span class="cms_tpv_page_actions_modified_by"></span> </dd> <dt><?php _e("Page ID", "cms-tree-page-view"); ?> </dt> <dd><span class="cms_tpv_page_actions_page_id"></span></dd> </dl> <div class="cms_tpv_page_actions_columns"></div> <span class="cms_tpv_page_actions_arrow"></span> </div> <?php } if (empty($pages)) { echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>'; } ?> </div> <?php }
/** * Print tree stuff that is common for both dashboard and page */ function cms_tpv_print_common_tree_stuff($post_type = "") { if (!$post_type) { $post_type = cms_tpv_get_selected_post_type(); } #echo "post_type: $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); $wpml_current_lang = ""; if (defined("ICL_SITEPRESS_VERSION") && $post_type == "page") { global $sitepress; $wpml_current_lang = $sitepress->get_current_language(); } global $cms_tpv_view; // 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 < sizeof($jstree_open); $i++) { $jstree_open[$i] = (int) str_replace("#cms-tpv-", "", $jstree_open[$i]); } } ob_start(); cms_tpv_print_childs(0, $cms_tpv_view, $jstree_open, $post_type); $json_data = ob_get_clean(); ?> <script type="text/javascript"> cms_tpv_jsondata.<?php echo $post_type; ?> = <?php echo $json_data; ?> ; </script> <div class="cms_tpv_wrapper"> <input type="hidden" name="cms_tpv_meta_post_type" value="<?php echo $post_type; ?> " /> <input type="hidden" name="cms_tpv_meta_post_type_hierarchical" value="<?php echo (int) cms_tpv_is_post_type_hierarchical($post_type_object); ?> " /> <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang; ?> " /> <?php // check if WPML is activated // if: show a language-menu if (defined("ICL_SITEPRESS_VERSION") && $post_type == "page") { $wpml_langs = icl_get_languages(); $wpml_active_lang = null; if (sizeof($wpml_langs) >= 1) { $lang_out = ""; $lang_out .= "<ul class='cms-tpv-subsubsub cms_tvp_switch_langs'>"; foreach ($wpml_langs as $one_lang) { $one_lang_details = $sitepress->get_language_details($one_lang["language_code"]); // english_name | display_name $selected = ""; if ($one_lang["active"]) { $wpml_active_lang = $one_lang; $selected = "current"; } $lang_out .= "<li><a class='cms_tvp_switch_lang {$selected} cms_tpv_switch_language_code_{$one_lang["language_code"]}' href='#'>{$one_lang_details['display_name']}</a> | </li>"; } $lang_out = preg_replace('/ \\| <\\/li>$/', "</li>", $lang_out); $lang_out .= "</ul>"; echo $lang_out; } } /* Array ( [en] => Array ( [id] => 1 [active] => 1 [native_name] => English [language_code] => en [translated_name] => English [url] => http://localhost/wordpress3 [country_flag_url] => http://localhost/wordpress3/wp-content/plugins/sitepress-multilingual-cms/res/flags/en.png ) */ if (empty($pages)) { echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>'; } else { // start the party! ?> <ul class="cms-tpv-subsubsub"> <li><a class="cms_tvp_view_all <?php echo $cms_tpv_view == "all" ? "current" : ""; ?> " href="#"><?php _e("All", 'cms-tree-page-view'); ?> </a> |</li> <li><a class="cms_tvp_view_public <?php echo $cms_tpv_view == "public" ? "current" : ""; ?> " href="#"><?php _e("Public", 'cms-tree-page-view'); ?> </a> |</li> <li><a class="cms_tvp_view_trash <?php echo $cms_tpv_view == "trash" ? "current" : ""; ?> " href="#"><?php _e("Trash", 'cms-tree-page-view'); ?> </a></li> <?php if (cms_tpv_is_post_type_hierarchical($post_type_object)) { ?> <li><a href="#" class="cms_tpv_open_all"><?php _e("Expand", 'cms-tree-page-view'); ?> </a> |</li> <li><a href="#" class="cms_tpv_close_all"><?php _e("Collapse", 'cms-tree-page-view'); ?> </a></li> <?php } ?> <li> <form class="cms_tree_view_search_form" method="get" action=""> <input type="text" name="search" class="cms_tree_view_search" /> <a title="<?php _e("Clear search", 'cms-tree-page-view'); ?> " class="cms_tree_view_search_form_reset" href="#">x</a> <input type="submit" class="cms_tree_view_search_submit" value="<?php _e("Search", 'cms-tree-page-view'); ?> " /> <span class="cms_tree_view_search_form_working"><?php _e("Searching...", 'cms-tree-page-view'); ?> </span> <span class="cms_tree_view_search_form_no_hits"><?php _e("Nothing found.", 'cms-tree-page-view'); ?> </span> </form> </li> </ul> <div class="cms_tpv_working"> <?php _e("Loading...", 'cms-tree-page-view'); ?> </div> <div class="cms_tpv_message updated below-h2 hidden"><p>Message goes here.</p></div> <div class="updated below-h2 hidden cms_tpv_search_no_hits"><p><?php _e("Search: no pages found", 'cms-tree-page-view'); ?> </p></div> <div class="cms_tpv_container tree-default"> <?php _e("Loading tree", 'cms-tree-page-view'); ?> </div> <div style="clear: both;"></div> <div class="cms_tpv_page_actions"> <p> <a href="#" title='<?php _e("Edit page", "cms-tree-page-view"); ?> ' class='cms_tpv_action_edit'><?php _e("Edit", "cms-tree-page-view"); ?> </a> | <a href="#" title='<?php _e("View page", "cms-tree-page-view"); ?> ' class='cms_tpv_action_view'><?php _e("View", "cms-tree-page-view"); ?> </a> </p> <p class="cms_tpv_action_add_and_edit_page"> <span class='cms_tpv_action_add_page'><?php echo $post_type_object->labels->add_new_item; ?> </span> <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> <?php // if post type is hierarchical we can add pages inside if (cms_tpv_is_post_type_hierarchical($post_type_object)) { ?> | <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 } // if post status = draft then we can not add pages inside because wordpress currently can not keep its parent if we edit the page ?> <!-- <span class="cms_tpv_action_add_page_inside_disallowed"><?php _e("Can not create page inside of a page with draft status", "cms-tree-page-view"); ?> </span> --> </p> <dl> <dt><?php _e("Last modified", "cms-tree-page-view"); ?> </dt> <dd> <span class="cms_tpv_page_actions_modified_time"></span> <?php _e("by", "cms-tree-page-view"); ?> <span class="cms_tpv_page_actions_modified_by"></span> </dd> <dt><?php _e("Page ID", "cms-tree-page-view"); ?> </dt> <dd><span class="cms_tpv_page_actions_page_id"></span></dd> </dl> <div class="cms_tpv_page_actions_columns"></div> <span class="cms_tpv_page_actions_arrow"></span> </div> <?php } ?> </div> <?php }