WordPress.org

Plugin Directory

Changeset 641321


Ignore:
Timestamp:
12/18/12 21:35:28 (16 months ago)
Author:
eskapism
Message:

add settings + icons for tree view in post overview page

Location:
cms-tree-page-view/trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • cms-tree-page-view/trunk/functions.php

    r636337 r641321  
    176176// $firephp = FirePHP::getInstance(true); 
    177177 
     178/** 
     179 * Output and add hooks in head 
     180 */ 
    178181function cms_tpv_admin_head() { 
    179182 
    180183    if (!cms_tpv_is_one_of_our_pages()) return; 
     184 
     185    cms_tpv_setup_postsoverview(); 
    181186 
    182187    global $cms_tpv_view; 
     
    229234    } 
    230235 
     236    // Check if current page is one of the ones defined in $options["postsoverview"] 
     237    if ($current_screen->base === "edit" && in_array($current_screen->post_type, $options["postsoverview"])) { 
     238        $is_plugin_page = TRUE; 
     239    } 
     240 
    231241    if ($current_screen->id === "settings_page_cms-tpv-options") { 
    232242        // Is settings page for plugin 
    233243        $is_plugin_page = TRUE; 
    234244    } elseif ($current_screen->id === "dashboard" && !empty($options["dashboard"])) { 
     245        // At least one post type is enabled to be visible on dashboard 
    235246        $is_plugin_page = TRUE; 
    236247    } 
     
    244255 */ 
    245256function cms_admin_enqueue_scripts() { 
    246  
    247257 
    248258    if (cms_tpv_is_one_of_our_pages()) { 
     
    310320 
    311321/** 
     322 * Check if this is a post overview page and that plugin is enabled for this overview page 
     323 */ 
     324function cms_tpv_setup_postsoverview() { 
     325 
     326    $options = cms_tpv_get_options(); 
     327    $current_screen = get_current_screen(); 
     328 
     329    if ("edit" === $current_screen->base && in_array($current_screen->post_type, $options["postsoverview"])) { 
     330 
     331        // Ok, this is a post overview page that we are enabled for 
     332         
     333        // The filter we can use is in class-wp-list-table.php method views() 
     334        // $views = apply_filters( 'views_' . $this->screen->id, $views ); 
     335        // it's the code that gets the links for the current views filters 
     336         
     337        add_filter("views_" . $current_screen->id, "cmstpv_filter_views_edit"); 
     338        // filter: views_edit-page $this->screen->id 
     339 
     340    } 
     341     
     342} 
     343 
     344function cmstpv_filter_views_edit($views) { 
     345     
     346    $current_screen = get_current_screen(); 
     347     
     348    ob_start(); 
     349    cms_tpv_print_common_tree_stuff(); 
     350    $tree_common_stuff = ob_get_clean(); 
     351 
     352    /* 
     353    on non hierarcical post types this one exists: 
     354    tablenav-pages one-page 
     355    then after: 
     356    <div class="view-switch"> 
     357 
     358    if view-switch exists: add item to it 
     359    if view-switch not exists: add it + item to it 
     360 
     361    http://playground.ep/wordpress/wp-admin/images/list.png 
     362    */ 
     363    $mode = "tree"; 
     364    $class = isset($_GET["mode"]) && $_GET["mode"] == $mode ? " class='current' " : ""; 
     365    $title = __("Tree View", 'cms-tree-page-view'); 
     366    $tree_a = "<a href='" . esc_url( add_query_arg( 'mode', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class> <img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n"; 
     367 
     368    // Copy of wordpress own, if it does not exist 
     369    $wp_list_a = ""; 
     370    if (is_post_type_hierarchical( $current_screen->post_type ) ) { 
     371 
     372        $mode = "list"; 
     373        $class = isset($_GET["mode"]) && $_GET["mode"] != $mode ? "" : " class='current' "; 
     374        $title = __("List View"); 
     375        $wp_list_a = "<a href='" . esc_url( add_query_arg( 'mode', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class><img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n"; 
     376 
     377    } 
     378 
     379    $out = ""; 
     380    $out .= $tree_a; 
     381    $out .= $wp_list_a; 
     382 
     383    // Output tree related stuff if that view/mode is selected 
     384    if (isset($_GET["mode"]) && $_GET["mode"] === "tree") { 
     385     
     386        $out .= sprintf(' 
     387            <div class="cmstpv-postsoverview-wrap"> 
     388                %1$s 
     389            </div> 
     390        ', $tree_common_stuff); 
     391     
     392    } 
     393 
     394    echo $out; 
     395 
     396    return $views; 
     397 
     398} 
     399 
     400 
     401/** 
    312402 * Add settings link to plugin page 
    313403 * Hopefully this helps some people to find the settings page quicker 
     
    326416 
    327417 
    328 // save settings 
     418/** 
     419 * Save settings, called when saving settings in general > cms tree page view 
     420 */ 
    329421function cms_tpv_save_settings() { 
     422     
    330423    if (isset($_POST["cms_tpv_action"]) && $_POST["cms_tpv_action"] == "save_settings") { 
     424 
    331425        $options = array(); 
    332426        $options["dashboard"] = (array) $_POST["post-type-dashboard"]; 
    333427        $options["menu"] = (array) $_POST["post-type-menu"]; 
     428        $options["postsoverview"] = (array) $_POST["post-type-postsoverview"]; 
     429         
    334430        update_option('cms_tpv_options', $options); // enable this to show box 
    335     } 
     431 
     432    } 
     433 
    336434} 
    337435 
     
    393491     
    394492        <?php cms_tpv_show_annoying_box(); ?> 
    395          
     493     
     494        <?php screen_icon(); ?>  
    396495        <h2><?php echo CMS_TPV_NAME ?> <?php _e("settings", 'cms-tree-page-view') ?></h2> 
    397496 
     
    402501             
    403502            <?php 
     503             
    404504            $options = cms_tpv_get_options(); 
    405505 
     
    407507                "show_ui" => TRUE 
    408508            ), "objects"); 
     509             
    409510            $arr_page_options = array(); 
    410511            foreach ($post_types as $one_post_type) { 
     512 
    411513                $name = $one_post_type->name; 
    412514                 
    413                 if ($name == "post") { 
     515                if ($name === "post") { 
    414516                    // no support for pages. you could show them.. but since we can't reorder them there is not idea to show them.. or..? 
    415517                    // 14 jul 2011: ok, let's enable it for posts too. some people says it useful 
    416518                    // http://wordpress.org/support/topic/this-plugin-should-work-also-on-posts 
    417519                    // continue; 
     520                } else if ($name === "attachment") { 
     521                    // No support for media/attachment 
     522                    continue; 
    418523                } 
    419524 
    420525                $arr_page_options[] = "post-type-dashboard-$name"; 
    421526                $arr_page_options[] = "post-type-menu-$name"; 
     527                $arr_page_options[] = "post-type-postsoverview-$name"; 
     528                 
     529 
     530                echo "<h3>".$one_post_type->label."</h3>"; 
    422531                echo "<p>"; 
    423                 echo "<strong>".$one_post_type->label."</strong>"; 
    424532                 
    425533                $checked = (in_array($name, $options["dashboard"])) ? " checked='checked' " : ""; 
    426                 echo "<br />"; 
    427534                echo "<input $checked type='checkbox' name='post-type-dashboard[]' value='$name' id='post-type-dashboard-$name' /> <label for='post-type-dashboard-$name'>" . __("On dashboard", 'cms-tree-page-view') . "</label>"; 
    428535                 
     536                echo "<br />"; 
    429537                $checked = (in_array($name, $options["menu"])) ? " checked='checked' " : ""; 
     538                echo "<input $checked type='checkbox' name='post-type-menu[]' value='$name' id='post-type-menu-$name' /> <label for='post-type-menu-$name'>" . __("In menu", 'cms-tree-page-view') . "</label>"; 
     539 
    430540                echo "<br />"; 
    431                 echo "<input $checked type='checkbox' name='post-type-menu[]' value='$name' id='post-type-menu-$name' /> <label for='post-type-menu-$name'>" . __("In menu", 'cms-tree-page-view') . "</label>"; 
     541                $checked = (in_array($name, $options["postsoverview"])) ? " checked='checked' " : ""; 
     542                echo "<input $checked type='checkbox' name='post-type-postsoverview[]' value='$name' id='post-type-postsoverview-$name' /> <label for='post-type-postsoverview-$name'>" . __("In post overview screen", 'cms-tree-page-view') . "</label>"; 
     543 
    432544                echo "</p>"; 
    433545 
     
    448560} 
    449561 
     562/** 
     563 * Load settings 
     564 * @return array with options 
     565 */ 
    450566function cms_tpv_get_options() { 
    451567    $arr_options = (array) get_option('cms_tpv_options'); 
    452568    $arr_options["dashboard"] = (array) @$arr_options["dashboard"]; 
    453569    $arr_options["menu"] = (array) @$arr_options["menu"]; 
     570    $arr_options["postsoverview"] = (array) @$arr_options["postsoverview"]; 
    454571    return $arr_options; 
    455572} 
     
    542659        $post_type = cms_tpv_get_selected_post_type(); 
    543660    } 
    544     #echo "post_type: $post_type"; 
     661     
    545662    $post_type_object = get_post_type_object($post_type); 
    546663    $get_pages_args = array("post_type" => $post_type); 
     
    832949        <?php echo get_screen_icon(); ?> 
    833950        <h2><?php 
     951 
    834952            $page_title = _x(sprintf('%1$s Tree View', $post_type_object->labels->name), "headline of page with tree", "cms-tree-page-view"); 
    835953            echo $page_title; 
     
    839957                echo ' <a href="' . esc_url( $post_new_file ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>'; 
    840958            } 
    841  
    842  
    843  
    844959 
    845960        ?></h2> 
     
    15131628    // check and update version 
    15141629    $version = get_option('cms_tpv_version', 0); 
    1515  
    1516     //$version = 0; 
     1630    // $version = 0; // uncomment to test default settings 
    15171631 
    15181632    if ($version <= 0) { 
  • cms-tree-page-view/trunk/index.php

    r631434 r641321  
    6969register_activation_hook( WP_PLUGIN_DIR . "/cms-tree-page-view/index.php" , 'cms_tpv_install' ); 
    7070 
     71// To test activation hook, uncomment function below 
     72// cms_tpv_install(); 
     73 
    7174// catch upgrade 
    7275add_action('plugins_loaded', 'cms_tpv_plugins_loaded' , 1); 
  • cms-tree-page-view/trunk/readme.txt

    r636337 r641321  
    115115- Fixed wrong language count for WPML-enabled post types 
    116116- Perhaps fixed a problem with some other plugins, for example Formidable Pro 
     117- Added icon to settings page 
    117118 
    118119= 1.1 = 
  • cms-tree-page-view/trunk/scripts/cms_tree_page_view.js

    r636337 r641321  
    828828 
    829829} 
     830 
     831 
     832 
     833 
     834jQuery(function($) { 
     835 
     836    // Move tree link into position 
     837    var tree_view_switch = $("#view-switch-tree"), 
     838        tree_view_switch_a = tree_view_switch.closest("a"); 
     839 
     840    // Check if view-switch exists and add if not 
     841    var view_switch = $("div.view-switch"); 
     842    if (! view_switch.length) { 
     843         
     844        view_switch = $("<div class='view-switch'></div>"); 
     845        $("div.tablenav-pages:first").after(view_switch); 
     846 
     847        var view_switch_list = $("#view-switch-list"), 
     848            view_switch_list_a = view_switch_list.closest("a"); 
     849 
     850        view_switch.append(view_switch_list_a); 
     851 
     852    } 
     853     
     854    // Add our link inside view switch 
     855    view_switch.append(tree_view_switch_a); 
     856 
     857 
     858 
     859    /* 
     860    $(document).on("click", "div.cmstpv-postsoverview-nav a", function(e) { 
     861         
     862        e.preventDefault(); 
     863         
     864        var $t = $(this), 
     865            $li = $t.closest("li"), 
     866            $div = $t.closest("div"), 
     867            is_list_view = $li.hasClass("cmstpv-postsoverview-nav-list"), 
     868            is_tree_view = !is_list_view; 
     869         
     870        $div.find("li").removeClass("cmstpv-active"); 
     871 
     872        if (is_list_view) { 
     873 
     874            $("div.cmstpv-postsoverview-wrap").hide(); 
     875            $("ul.subsubsub, #posts-filter").show(); 
     876            $li.addClass("cmstpv-active"); 
     877 
     878        } else if (is_tree_view) { 
     879             
     880            $("div.cmstpv-postsoverview-wrap").show(); 
     881            $("ul.subsubsub, #posts-filter").hide(); 
     882            $li.addClass("cmstpv-active"); 
     883 
     884        } 
     885 
     886    }); 
     887*/ 
     888 
     889}); 
  • cms-tree-page-view/trunk/styles/styles.css

    r636337 r641321  
    463463    visibility: hidden; 
    464464} 
     465 
     466/* 
     467 
     468*/ 
     469#view-switch-tree { 
     470    background: url(images/switch-view-icons.png) 0 0; 
     471 
     472} 
     473.current #view-switch-tree { 
     474    background-position: -20px 0; 
     475} 
Note: See TracChangeset for help on using the changeset viewer.