function frontier_can_clone($tmp_post_type = "NONE")
{
    global $fps_access_check_msg;
    $tmp_can_do = true;
    // first check if user can add
    if (!frontier_can_add($tmp_post_type)) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to add new posts", "frontier-post") . "<br>";
    }
    if (!current_user_can('frontier_post_can_clone')) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to clone posts", "frontier-post") . "<br>";
    }
    // Always allow the boss
    if (current_user_can('administrator')) {
        $tmp_can_do = true;
        $fps_access_check_msg = "";
    }
    // check if it is an allowed posttype
    if (!fp_check_post_type($tmp_post_type)) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("You are not allowed to clone post type", "frontier-post") . ": " . $tmp_post_type;
        $fps_access_check_msg .= " - Allowed: (" . implode(", ", fp_default_post_type_list()) . ")<br>";
    }
    // check if posttype exists
    if (!post_type_exists($tmp_post_type)) {
        $tmp_can_do = false;
        $fps_access_check_msg .= __("Post type does not exists", "frontier-post") . ": " . $tmp_post_type . "<br>";
    }
    //echo "<hr>add validation msg: ".$fps_access_check_msg."<br>";
    return $tmp_can_do;
}
function frontier_clone_post($fpost_sc_parms = array())
{
    //extract($fpost_sc_parms);
    //echo "CLONE POST<br>";
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    if (isset($_POST['task'])) {
        $post_task = $_POST['task'];
    } else {
        if (isset($_GET['task'])) {
            $post_task = $_GET['task'];
        } else {
            $post_task = "notaskset";
        }
    }
    $post_action = isset($_POST['action']) ? $_POST['action'] : "Unknown";
    if ($post_task == "clone" && $_REQUEST['postid']) {
        $old_post = get_post($_REQUEST['postid']);
        $old_post_id = $old_post->ID;
        //double check current user can add a post with this post type
        if (frontier_can_add($old_post->post_type)) {
            require_once ABSPATH . '/wp-admin/includes/post.php';
            global $current_user;
            //Get permalink from old post
            $old_permalink = get_permalink($old_post_id);
            // lets clone it
            $thispost = get_default_post_to_edit($fpost_sc_parms['frontier_add_post_type'], true);
            $new_post_id = $thispost->ID;
            $tmp_post = array('ID' => $new_post_id, 'post_type' => $old_post->post_type, 'post_title' => __("CLONED from", "frontier-post") . ': <a href="' . $old_permalink . '">' . $old_post->post_title . '</a>', 'post_content' => __("CLONED from", "frontier-post") . ': <a href="' . $old_permalink . '">' . $old_post->post_title . '</a><br>' . $old_post->post_content, 'post_status' => "draft", 'post_author' => $current_user->ID);
            //****************************************************************************************************
            // Apply filter before update of post
            // filter:			frontier_post_clone
            // $tmp_post 		Array that holds the updated fields
            // $old_post  		The post being cloed (Object)
            //****************************************************************************************************
            $tmp_post = apply_filters('frontier_post_clone', $tmp_post, $old_post);
            // save post
            wp_update_post($tmp_post);
            //Get the updated post
            $new_post = get_post($new_post_id);
            //get all current post terms ad set them to the new post draft
            $taxonomies = get_object_taxonomies($old_post->post_type);
            // returns array of taxonomy names for post type, ex array("category", "post_tag");
            foreach ($taxonomies as $taxonomy) {
                $post_terms = wp_get_object_terms($old_post_id, $taxonomy, array('fields' => 'slugs'));
                wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
            }
            // Set featured image:
            $post_thumbnail_id = get_post_thumbnail_id($old_post_id);
            if (intval($post_thumbnail_id) > 0) {
                set_post_thumbnail($new_post_id, $post_thumbnail_id);
            }
            // Add/Update message
            frontier_post_set_msg(__("Post Cloned and ready edit", "frontier-post") . ": " . $new_post->post_title);
            frontier_post_set_msg(__("Post status set to Draft", "frontier-post"));
            frontier_user_post_list($fpost_sc_parms);
        }
    }
}
function frontier_quickpost($fpost_sc_parms = array())
{
    if (fp_get_option_bool('fps_use_quickpost') && frontier_can_add($fpost_sc_parms['frontier_add_post_type'])) {
        // Show/Hide Quickpost
        ?>
		<script type="text/javascript">
		jQuery(document).ready(function($) 
			{
			$("#fp-quickpost-show").click(function ()
				{
				/*alert('show');*/
				$("#frontier-post-quickpost").show();
				$("#fp-quickpost-show").hide();
				$("#fp-quickpost-hide").show();
				$(".frontier-quickpost-hide").hide();
				$(".frontier-quickpost-show").show();
				$("#fp_show_quickpost").val("true");
				}
			);
			$("#fp-quickpost-hide").click(function ()
				{
				/*alert('hide');*/
				$("#frontier-post-quickpost").hide();
				$("#fp-quickpost-show").show();
				$("#fp-quickpost-hide").hide();
				$(".frontier-quickpost-hide").show();
				$(".frontier-quickpost-show").hide();
				$("#fp_show_quickpost").val("false");
				}
			);
			}
		
		);
		</script>
	
	
	
		<?php 
        if (strlen(trim($fpost_sc_parms['frontier_add_link_text'])) > 0) {
            $tmp_add_text = $fpost_sc_parms['frontier_add_link_text'];
        } else {
            $tmp_add_text = __("Create New", "frontier-post") . " " . fp_get_posttype_label_singular($fpost_sc_parms['frontier_add_post_type']);
        }
        echo '<button class="button frontier-post-quickpost-button frontier-quickpost-hide" type="button" name="fp-quickpost-show" id="fp-quickpost-show" value="show">' . $tmp_add_text . '</button>';
        echo '<button class="button frontier-post-quickpost-button frontier-quickpost-show" type="button" name="fp-quickpost-hide" id="fp-quickpost-hide" value="hide">' . __("Hide", "frontier-post") . " " . $tmp_add_text . '</button>';
        echo '<fieldset id="frontier-post-quickpost" class="frontier-quickpost-show">';
        frontier_post_add_edit($fpost_sc_parms, true);
        echo '</fieldset>';
    }
    // fps_use_quickpost
}
*/
$concat = get_option("permalink_structure") ? "?" : "&";
//set the permalink for the page itself
$frontier_permalink = get_permalink();
//Display before text from shortcode
if (strlen($frontier_list_text_before) > 1) {
    echo '<div id="frontier_list_text_before">' . $frontier_list_text_before . '</div>';
}
//Display message
frontier_post_output_msg();
$fp_cat_list = implode(",", $frontier_cat_id);
/*
echo "post_type: ".$frontier_add_post_type."<br>";
echo "Label: ".fp_get_posttype_label_singular($frontier_add_post_type);
*/
if (frontier_can_add() && !fp_get_option_bool("fps_hide_add_on_list")) {
    if (strlen(trim($frontier_add_link_text)) > 0) {
        $tmp_add_text = $frontier_add_link_text;
    } else {
        $tmp_add_text = __("Create New", "frontier-post") . " " . fp_get_posttype_label_singular($frontier_add_post_type);
    }
    ?>
	<table class="frontier-menu" >
		<tr class="frontier-menu">
			<th class="frontier-menu" >&nbsp;</th>
			<th class="frontier-menu" ><a id="frontier-post-add-new-link" href='<?php 
    echo frontier_post_add_link($tmp_p_id);
    ?>
'><?php 
    echo $tmp_add_text;
    ?>
Пример #5
0
function frontier_post_add_edit($frontier_post_shortcode_parms = array())
{
    require_once ABSPATH . '/wp-admin/includes/post.php';
    global $current_user;
    global $wpdb;
    //add_thickbox();
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    //set start of output debug query
    $qlog = $wpdb->queries;
    $qlog_start = count($qlog);
    $fps_access_check_msg = "";
    $user_can_edit_this_post = false;
    //Reset access message
    $fps_access_check_msg = "";
    //Get Frontier Post capabilities
    $fp_capabilities = frontier_post_get_capabilities();
    //$fp_settings		= frontier_post_get_settings()
    // Get vars from shortcode
    extract($frontier_post_shortcode_parms);
    if (!is_user_logged_in()) {
        echo fp_login_text();
    } else {
        // Check if new, and if Edit that current users is allowed to edit
        if (isset($_REQUEST['task']) && $_REQUEST['task'] == "edit") {
            $thispost = get_post($_REQUEST['postid']);
            $user_post_excerpt = get_post_meta($thispost->ID, "user_post_excerpt");
            $tmp_task_new = false;
            if (frontier_can_edit($thispost) == true) {
                $user_can_edit_this_post = true;
            }
        } else {
            $tmp_post_type = post_type_exists($frontier_add_post_type) ? $frontier_add_post_type : 'post';
            if (frontier_can_add($tmp_post_type) == true) {
                if (empty($thispost->ID)) {
                    $thispost = get_default_post_to_edit("{$tmp_post_type}", true);
                    $thispost->post_author = $current_user->ID;
                    $thispost->post_type = $tmp_post_type;
                    //echo "New post for edit: ".$thispost->ID."<br>";
                }
                $_REQUEST['task'] = "new";
                $tmp_task_new = true;
                $user_can_edit_this_post = true;
            }
        }
    }
    // Do not proceed with all the processing if user is not able to add/edit
    if ($user_can_edit_this_post == true) {
        $post_id = $thispost->ID;
        //get users role:
        $users_role = frontier_get_user_role();
        // get list of taxonomies
        $tax_form_lists = frontier_get_tax_lists($frontier_page_id, intval($frontier_parent_cat_id), intval($fps_cache_time_tax_lists));
        //******************************************************************************************
        // Set defaults, so post can be saved without errors
        //******************************************************************************************
        if (!isset($thispost->post_type)) {
            $thispost->post_type = 'post';
        }
        if (!isset($thispost->post_content)) {
            $thispost->post_content = '';
        }
        // Call media fix (to support older versions)
        frontier_media_fix($post_id);
        //******************************************************************************************
        // Manage post status
        //******************************************************************************************
        //build post status list based on current status and users capability
        $tmp_status_list = get_post_statuses();
        $tmp_status_list = array_reverse($tmp_status_list);
        // Remove private status from array if not allowed
        if (!current_user_can('frontier_post_can_private')) {
            unset($tmp_status_list['private']);
        }
        // Remove draft status from array if user is not allowed to use drafts
        if (!current_user_can('frontier_post_can_draft')) {
            unset($tmp_status_list['draft']);
        }
        // Remove pending status from array if user is not allowed to use pending status or if it is a page we are editing
        if (!current_user_can('frontier_post_can_pending') || $thispost->post_type == 'page') {
            unset($tmp_status_list['pending']);
        }
        // Remove publish status from array if not allowed
        if (!current_user_can('frontier_post_can_publish')) {
            unset($tmp_status_list['publish']);
        }
        // Set default status if new post - Check if the default status is in the allowed statuses, and if so set the default status
        $tmp_default_status = fp_get_option("fps_default_status", "publish");
        if ($tmp_task_new == true && array_key_exists($tmp_default_status, $tmp_status_list)) {
            $thispost->post_status = $tmp_default_status;
        }
        $status_list = array();
        $tmp_post_status = $thispost->post_status ? $thispost->post_status : $tmp_default_status;
        // if The deafult status is not in the list, set default status to the first in the list
        if (!in_array($tmp_post_status, array_keys($tmp_status_list))) {
            $tmp_post_status = current(array_keys($tmp_status_list));
        }
        $status_list = $tmp_status_list;
        //**************************************************************************************************
        // -- Setup wp_editor layout
        // full: full Tiny MCE
        // minimal-visual: Teeny layout
        // minimal-html: simple layout with html options
        // text: text only
        //**************************************************************************************************
        // If capabilities is managed from other plugin, use default setting for all profiles
        if (get_option("frontier_post_external_cap", "false") == "true") {
            $editor_type = fp_get_option("fps_default_editor", "full");
        } else {
            $editor_type = $fp_capabilities[$users_role]['fps_role_editor_type'] ? $fp_capabilities[$users_role]['fps_role_editor_type'] : "full";
        }
        $editor_layout = array('dfw' => false, 'tabfocus_elements' => 'sample-permalink,post-preview', 'editor_height' => 300);
        $frontier_media_button = current_user_can('frontier_post_can_media') ? current_user_can('frontier_post_can_media') : false;
        // Call to wp_editor in done in entry form
        //************************************************************************
        // Setup category
        //************************************************************************
        // Do not manage categories for page
        if ($thispost->post_type != 'page') {
            // If capabilities is managed from other plugin, use default setting for all profiles
            if (fp_get_option("fps_external_cap", "false") == "true") {
                $category_type = fp_get_option("fps_default_cat_select", "multi");
            } else {
                $category_type = $fp_capabilities[$users_role]['fps_role_category_layout'] ? $fp_capabilities[$users_role]['fps_role_category_layout'] : "multi";
            }
            $default_category = $fp_capabilities[$users_role]['fps_role_default_category'] ? $fp_capabilities[$users_role]['fps_role_default_category'] : get_option("default_category");
            // set default category, if new and category parsed from shortcode,
            if ($tmp_task_new) {
                $cats_selected = $frontier_cat_id;
                if (count($frontier_cat_id) > 0 && $frontier_cat_id[0] > 0) {
                    $default_category = $frontier_cat_id[0];
                }
            } else {
                $cats_selected = $thispost->post_category;
            }
            // if no category selected (from post), insert default category.
            // removed in version 3.5.7, as default category is set on save
            /*
            if (empty($cats_selected[0]))
            	$cats_selected[0] = $default_category;
            */
            // Build list of categories (3 levels)
            // removed in version 3.5.7
            /*
            if ( ($category_type == "multi") || ($category_type == "checkbox") )
            	{
            	$catlist 		= array();
            	$catlist 		= frontier_tax_list("category", fp_get_option("fps_excl_cats", ''), $frontier_parent_cat_id );
            	}
            */
        } else {
            $cats_selected = array();
        }
        // end exclude categories for pages
        // Set variable for hidden field, if category field is removed from the form
        $cats_selected_txt = implode(',', $cats_selected);
        //echo "Cats selected: ".$cats_selected_txt."<hr>";
        //***************************************************************************************
        //* Set tags
        //***************************************************************************************
        $fp_tag_count = fp_get_option_int("fps_tag_count", 3);
        if (current_user_can('frontier_post_tags_edit') && $thispost->post_type != 'page') {
            $taglist = array();
            if (isset($thispost->ID)) {
                $tmptags = get_the_tags($thispost->ID);
                if ($tmptags) {
                    foreach ($tmptags as $tag) {
                        array_push($taglist, $tag->name);
                    }
                }
            }
        }
        $hide_post_status = fp_get_option("fps_hide_status", "false") == "true" ? true : false;
        $frontier_use_feat_img = fp_get_option("fps_show_feat_img", "false");
        //***************************************************************************************
        //* Get post moderation fields
        //***************************************************************************************
        if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $thispost->post_author)) {
            $fp_moderation_comments = get_post_meta($post_id, 'FRONTIER_POST_MODERATION_TEXT', true);
        }
    }
    // end if OK to Edit
    if ($user_can_edit_this_post) {
        $fp_form = $frontier_edit_form;
        if ($thispost->post_type == 'page') {
            $fp_form = "page";
        }
        //echo "Form: ".$fp_form."<br>";
        switch ($fp_form) {
            case "standard":
                include frontier_load_form("frontier_post_form_standard.php");
                break;
            case "old":
                include frontier_load_form("frontier_post_form_old.php");
                break;
            case "simple":
                include frontier_load_form("frontier_post_form_simple.php");
                break;
            case "page":
                include frontier_load_form("frontier_post_form_page.php");
                break;
            default:
                include frontier_load_form("frontier_post_form_standard.php");
                break;
        }
        //output debug query
        if (1 === 2) {
            error_log('---------------- SQL LOG START (' . $qlog_start . ')---------------');
            global $wpdb;
            $q_log = $wpdb->queries;
            error_log("Queries");
            error_log(print_r($q_log, true));
            $l = 0;
            echo "<hr>Queries<hr>";
            foreach ($q_log as $tmp_sql) {
                if ($l >= $qlog_start) {
                    //error_log('('.zeroise($l,3).') '.$tmp_sql[1].' '.$tmp_sql[0]);
                    echo '(' . zeroise($l, 3) . ') ' . $tmp_sql[1] . ' ' . $tmp_sql[0] . "<hr>";
                }
                $l++;
            }
            error_log('---------------- SQL LOG END---------------');
        }
    } else {
        // Echo reason why user cant add/edit post.
        global $fps_access_check_msg;
        if (empty($fps_access_check_msg) || $fps_access_check_msg < " ") {
            echo __("You are not allowed to edit this post, sorry ", "frontier-post");
        } else {
            echo "<br>" . $fps_access_check_msg;
        }
        //Reset message once displayed
        $fps_access_check_msg = "";
    }
}
function frontier_post_add_edit($fpost_sc_parms = array(), $fp_use_quickpost = false)
{
    require_once ABSPATH . '/wp-admin/includes/post.php';
    global $current_user;
    //global $wpdb;
    global $fps_access_check_msg;
    //Reset access message
    $fps_access_check_msg = "";
    $frontier_permalink = get_permalink();
    $concat = get_option("permalink_structure") ? "?" : "&";
    $user_can_edit_this_post = false;
    //Get Frontier Post capabilities
    $fp_capabilities = frontier_post_get_capabilities();
    //$fp_settings		= frontier_post_get_settings()
    // Get vars from shortcode
    //extract($frontier_post_shortcode_parms);
    if (!is_user_logged_in()) {
        // stop and display message
        echo fp_login_text();
    } else {
        // Check if new, and if Edit that current users is allowed to edit
        if (isset($_REQUEST['task']) && $_REQUEST['task'] == "edit") {
            $thispost = get_post($_REQUEST['postid']);
            $user_post_excerpt = get_post_meta($thispost->ID, "user_post_excerpt");
            $tmp_task_new = false;
            if (frontier_can_edit($thispost)) {
                $user_can_edit_this_post = true;
            }
        } else {
            if (frontier_can_add($fpost_sc_parms['frontier_add_post_type'])) {
                if (empty($thispost->ID)) {
                    $thispost = get_default_post_to_edit($fpost_sc_parms['frontier_add_post_type'], true);
                    $thispost->post_author = $current_user->ID;
                    $thispost->post_type = $fpost_sc_parms['frontier_add_post_type'];
                    //echo "New post for edit: <pre>".print_r($thispost, true)."</pre><br>";
                }
                $_REQUEST['task'] = "new";
                $tmp_task_new = true;
                $user_can_edit_this_post = true;
            } else {
                echo '<br><div id="frontier-post-alert">';
                echo $fps_access_check_msg;
                echo '</div><br>';
                return;
            }
        }
    }
    //**************************************************************************************************
    // Do not proceed with all the processing if user is not able to add/edit
    //**************************************************************************************************
    if (!$user_can_edit_this_post) {
        // Echo reason why user cant add/edit post.
        global $fps_access_check_msg;
        if (empty($fps_access_check_msg) || $fps_access_check_msg < " ") {
            echo __("You are not allowed to edit this post, sorry ", "frontier-post");
        } else {
            echo "<br>" . $fps_access_check_msg;
        }
        //Reset message once displayed
        $fps_access_check_msg = "";
        return;
    } else {
        $post_id = $thispost->ID;
        $users_role = frontier_get_user_role();
        $tax_form_lists = frontier_get_tax_lists($fpost_sc_parms['frontier_page_id'], intval($fpost_sc_parms['frontier_parent_cat_id']), intval($fpost_sc_parms['fps_cache_time_tax_lists']));
        //******************************************************************************************
        // Set defaults, so post can be saved without errors
        //******************************************************************************************
        if (!isset($thispost->post_type)) {
            $thispost->post_type = 'post';
        }
        if (!isset($thispost->post_content)) {
            $thispost->post_content = '';
        }
        // Call media fix (to support older versions)
        frontier_media_fix($post_id);
        //******************************************************************************************
        // Manage post status
        //******************************************************************************************
        //build post status list based on current status and users capability
        $tmp_status_list = get_post_statuses();
        $tmp_status_list = array_reverse($tmp_status_list);
        // Remove private status from array if not allowed
        if (!current_user_can('frontier_post_can_private')) {
            unset($tmp_status_list['private']);
        }
        // Remove draft status from array if user is not allowed to use drafts
        if (!current_user_can('frontier_post_can_draft')) {
            unset($tmp_status_list['draft']);
        }
        // Remove pending status from array if user is not allowed to use pending status or if it is a page we are editing
        if (!current_user_can('frontier_post_can_pending') || $thispost->post_type == 'page') {
            unset($tmp_status_list['pending']);
        }
        // Remove publish status from array if not allowed
        if (!current_user_can('frontier_post_can_publish')) {
            unset($tmp_status_list['publish']);
        }
        // Add Future to status list, if post status is future
        if ($thispost->post_status == "future") {
            $tmp_status_list['future'] = __("Future", "frontier-post");
        }
        // Set default status if new post - Check if the default status is in the allowed statuses, and if so set the default status
        $tmp_default_status = fp_get_option("fps_default_status", "publish");
        if ($tmp_task_new == true && array_key_exists($tmp_default_status, $tmp_status_list)) {
            $thispost->post_status = $tmp_default_status;
        }
        $status_list = array();
        $tmp_post_status = $thispost->post_status ? $thispost->post_status : $tmp_default_status;
        // if The deafult status is not in the list, set default status to the first in the list
        if (!in_array($tmp_post_status, array_keys($tmp_status_list))) {
            $tmp_post_status = current(array_keys($tmp_status_list));
        }
        $status_list = $tmp_status_list;
        //************************************************************************
        // Setup category
        //************************************************************************
        // Do not manage categories for page
        if ($thispost->post_type != 'page') {
            // If capabilities is managed from other plugin, use default setting for all profiles
            if (fp_get_option("fps_external_cap", "false") == "true") {
                $category_type = fp_get_option("fps_default_cat_select", "multi");
            } else {
                $category_type = $fp_capabilities[$users_role]['fps_role_category_layout'] ? $fp_capabilities[$users_role]['fps_role_category_layout'] : "multi";
            }
            $default_category = $fp_capabilities[$users_role]['fps_role_default_category'] ? $fp_capabilities[$users_role]['fps_role_default_category'] : get_option("default_category");
            // set default category, if new and category parsed from shortcode,
            if ($tmp_task_new) {
                $cats_selected = $fpost_sc_parms['frontier_cat_id'];
                if (count($cats_selected) > 0 && ${$cats_selected}[0] > 0) {
                    $default_category = $frontier_cat_id[0];
                }
            } else {
                $cats_selected = $thispost->post_category;
            }
        } else {
            $cats_selected = array();
        }
        // end exclude categories for pages
        // Set variable for hidden field, if category field is removed from the form
        $cats_selected_txt = implode(',', $cats_selected);
        //***************************************************************************************
        //* Set tags
        //***************************************************************************************
        $fp_tag_count = fp_get_option_int("fps_tag_count", 3);
        if (current_user_can('frontier_post_tags_edit') && $thispost->post_type != 'page') {
            $taglist = array();
            if (isset($thispost->ID)) {
                $tmptags = get_the_tags($thispost->ID);
                if ($tmptags) {
                    foreach ($tmptags as $tag) {
                        array_push($taglist, $tag->name);
                    }
                }
            }
        }
        //***************************************************************************************
        //* Get post moderation fields
        //***************************************************************************************
        if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $thispost->post_author)) {
            $fp_moderation_comments = get_post_meta($post_id, 'FRONTIER_POST_MODERATION_TEXT', true);
        }
        //***************************************************************************************
        // Enqueue media javascript
        //***************************************************************************************
        wp_enqueue_media(array('post' => $thispost->ID));
        //***************************************************************************************
        // Setup entry form
        //***************************************************************************************
        $fp_form = $fpost_sc_parms['frontier_edit_form'];
        // override if this is a quickpost
        if (fp_bool($fp_use_quickpost)) {
            $fp_form = "quickpost";
        }
        if ($thispost->post_type == 'page') {
            $fp_form = "page";
        }
        switch ($fp_form) {
            case "standard":
                include frontier_load_form("frontier_post_form_standard.php");
                break;
            case "old":
                include frontier_load_form("frontier_post_form_old.php");
                break;
            case "simple":
                include frontier_load_form("frontier_post_form_simple.php");
                break;
            case "page":
                include frontier_load_form("frontier_post_form_page.php");
                break;
            case "quickpost":
                include frontier_load_form("frontier_post_form_quickpost.php");
                break;
            default:
                include frontier_load_form("frontier_post_form_standard.php");
                break;
        }
    }
    // end  $user_can_edit_this_post
}
$tmp_status_list['future'] = __("Future", "frontier-post");
$tmp_info_separator = " | ";
//Display before text from shortcode
if (strlen($fpost_sc_parms['frontier_list_text_before']) > 1) {
    echo '<div id="frontier_list_text_before">' . $frontier_list_text_before . '</div>';
}
// Dummy translation of ago for human readable time
$crap = __("ago", "frontier-post");
if (strlen(trim($fpost_sc_parms['frontier_add_link_text'])) > 0) {
    $tmp_add_text = $fpost_sc_parms['frontier_add_link_text'];
} else {
    $tmp_add_text = __("Create New", "frontier-post") . " " . fp_get_posttype_label_singular($fpost_sc_parms['frontier_add_post_type']);
}
//Display message
frontier_post_output_msg();
if (frontier_can_add($fpost_sc_parms['frontier_add_post_type']) && !fp_get_option_bool("fps_hide_add_on_list")) {
    ?>
	<fieldset class="frontier-new-menu">
		<a id="frontier-post-add-new-link" href='<?php 
    echo frontier_post_add_link($tmp_p_id);
    ?>
'><?php 
    echo $tmp_add_text;
    ?>
</a>
	</fieldset>
	<?php 
} else {
    if (current_user_can("manage_options") && strlen(trim($fps_access_check_msg)) > 0) {
        echo '<div id="frontier-post-posttype-warning">';
        echo $fps_access_check_msg;
$concat = get_option("permalink_structure") ? "?" : "&";
//set the permalink for the page itself
$frontier_permalink = get_permalink();
$tmp_status_list = get_post_statuses();
// Add future to list
$tmp_status_list['future'] = __("Future", "frontier-post");
$tmp_info_separator = " | ";
//Display before text from shortcode
if (strlen($frontier_list_text_before) > 1) {
    echo '<div id="frontier_list_text_before">' . $frontier_list_text_before . '</div>';
}
// Dummy translation of ago for human readable time
$crap = __("ago", "frontier-post");
//Display message
frontier_post_output_msg();
if (frontier_can_add($frontier_add_post_type) && !fp_get_option_bool("fps_hide_add_on_list")) {
    if (strlen(trim($frontier_add_link_text)) > 0) {
        $tmp_add_text = $frontier_add_link_text;
    } else {
        $tmp_add_text = __("Create New", "frontier-post") . " " . fp_get_posttype_label_singular($frontier_add_post_type);
    }
    ?>
	<fieldset class="frontier-new-menu">
		<a id="frontier-post-add-new-link" href='<?php 
    echo frontier_post_add_link($tmp_p_id);
    ?>
'><?php 
    echo $tmp_add_text;
    ?>
</a>
	</fieldset>
    /** @see WP_Widget::widget */
    function widget($args, $instance)
    {
        if (is_user_logged_in()) {
            // check access level
            if (array_key_exists('fp_access_level', $instance) && !current_user_can($instance['fp_access_level'])) {
                return;
            }
            global $current_user, $wpdb, $r;
            $instance = array_merge($this->defaults, $instance);
            $frontier_page_link = get_permalink(fp_get_option('fps_page_id'));
            $author = (int) $current_user->ID;
            $rec_limit = (int) (isset($instance['limit']) ? $instance['limit'] : 10);
            $excerpt_length = (int) (isset($instance['excerpt_length']) ? $instance['excerpt_length'] : 20);
            if (isset($instance['postdateformat']) && $instance['postdateformat'] != 'nodate') {
                $show_date = true;
            } else {
                $show_date = false;
            }
            if (isset($instance['cmtdateformat']) && $instance['cmtdateformat'] != 'nodate') {
                $show_comment_date = true;
            } else {
                $show_comment_date = false;
            }
            if (isset($instance['showcomments']) && $instance['showcomments'] != 'posts') {
                $show_comments = true;
            } else {
                $show_comments = false;
            }
            // Get comment icon from theme, first check local file path, if exists set tu url of icon
            $comment_icon = frontier_get_icon('comment');
            // from version 3.4.6 caching will be available, and as such changed to handle in one array.
            // cache name must contain author id as results are specific to authors
            $fp_cache_name = FRONTIER_MY_POSTS_W_PREFIX . $this->number . "-U-" . $author;
            $fp_cache_time = $instance['fp_cache_time'];
            $fp_cache_test = "Cache active";
            //echo "Cache name: ".$fp_cache_name."<br>";
            $post_status_list = $instance['post_status_list'];
            // manage posts status
            if (!is_array($post_status_list)) {
                $post_status_list = array($post_status_list);
            }
            if (fp_bool($instance['show_pending_posts']) && !in_array('pending', $post_status_list)) {
                $post_status_list[] = 'pending';
            }
            if (fp_bool($instance['show_draft_posts']) && !in_array('draft', $post_status_list)) {
                $post_status_list[] = 'draft';
            }
            //echo "<pre>".print_r($post_status_list, true)."</pre><br>";
            if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) {
                $fp_wdata = array();
                $fp_wdata['tmp_post_cnt'] = $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM {$wpdb->posts} WHERE post_author = " . $author . " AND post_status = 'publish' AND post_type = 'post'");
                // Build sql statement
                if ($show_comments) {
                    $tmp_sql = " SELECT ";
                    $tmp_sql .= " {$wpdb->posts}.ID \t\t\t\t\tAS post_id, ";
                    $tmp_sql .= " {$wpdb->posts}.post_title \t\t\tAS post_title, ";
                    $tmp_sql .= " {$wpdb->posts}.post_date \t\t\tAS post_date, ";
                    $tmp_sql .= " {$wpdb->comments}.comment_ID \t\tAS comment_id, ";
                    $tmp_sql .= " {$wpdb->comments}.comment_author \tAS comment_author, ";
                    $tmp_sql .= " {$wpdb->comments}.comment_date \t\tAS comment_date, ";
                    $tmp_sql .= " {$wpdb->comments}.comment_approved\tAS comment_approved, ";
                    $tmp_sql .= " {$wpdb->comments}.comment_content \tAS comment_content ";
                    $tmp_sql .= " FROM {$wpdb->posts} ";
                    $tmp_sql .= "   left OUTER JOIN {$wpdb->comments} ON {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID ";
                    $tmp_sql .= " WHERE {$wpdb->posts}.post_status IN ('" . implode("','", $post_status_list) . "') ";
                    $tmp_sql .= "   AND {$wpdb->posts}.post_type \t= '" . $instance['post_type'] . "'";
                    $tmp_sql .= "   AND {$wpdb->posts}.post_author \t= " . $author . "";
                    $tmp_sql .= " ORDER BY {$wpdb->posts}.post_date DESC, {$wpdb->comments}.comment_date_gmt DESC";
                    $tmp_sql .= " LIMIT " . $rec_limit * 5 . ";";
                } else {
                    $tmp_sql = " SELECT {$wpdb->posts}.ID \tAS post_id, ";
                    $tmp_sql .= " {$wpdb->posts}.post_title \tAS post_title, ";
                    $tmp_sql .= " {$wpdb->posts}.post_date \tAS post_date ";
                    $tmp_sql .= " FROM {$wpdb->posts} ";
                    $tmp_sql .= " WHERE {$wpdb->posts}.post_author = " . $author . " ";
                    $tmp_sql .= " AND {$wpdb->posts}.post_status IN ('" . implode("','", $post_status_list) . "') ";
                    $tmp_sql .= " AND {$wpdb->posts}.post_type = '" . $instance['post_type'] . "' ";
                    $tmp_sql .= " ORDER BY {$wpdb->posts}.post_date DESC ";
                    $tmp_sql .= " LIMIT " . $rec_limit * 5 . ";";
                    // needs to multiply to account for non approved comments
                    //echo "<pre>".print_r($tmp_sql, true)."</pre><br>";
                }
                $fp_wdata['presult'] = $wpdb->get_results($tmp_sql);
                if ($fp_cache_time <= 0) {
                    $fp_cache_test = "Caching disabled";
                } else {
                    $fp_cache_test = "Cache refreshed";
                    set_transient($fp_cache_name, $fp_wdata, $fp_cache_time);
                }
            }
            // end caching
            echo $args['before_widget'];
            if (!empty($instance['title'])) {
                echo $args['before_title'];
                echo $instance['title'];
                echo $args['after_title'];
            }
            //echo $args['before_widget'];
            //if ( $args['title'] ) echo $args['before_title'] . $args['title'] . $args['after_title'];
            //$title = apply_filters('widget_title', empty($instance['title']) ? __('My posts') : $instance['title'], $instance, $this->id_base);
            ?>
		
		
		
		
		<div  class="frontier-my-post-widget">
		<ul class="frontier-my-post-widget-list">
		
		
		<?php 
            $last_post = 0;
            $post_cnt = 0;
            if ($fp_wdata['presult']) {
                foreach ($fp_wdata['presult'] as $q_post) {
                    $tmp_link = "xx";
                    if ($last_post != $q_post->post_id) {
                        // $q_post is not a WP_post object
                        $tmp_post = get_post($q_post->post_id);
                        if ($post_cnt > 0) {
                            echo "</li>";
                        }
                        echo '<li class="frontier-my-post-widget-list">';
                        if ($instance['show_edit_link'] == 'before') {
                            echo frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-edit-link') . ' ';
                        }
                        if ($instance['show_delete_link'] == 'before') {
                            echo frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-delete-link') . ' ';
                        }
                        $post_cnt++;
                        if ($show_date) {
                            echo mysql2date($instance['postdateformat'], $q_post->post_date);
                            echo '&nbsp;&nbsp;';
                        }
                        if ($tmp_post->post_status == "publish") {
                            echo '<a class="frontier-my-post-widget-link frontier-my-post-widget-status-publish" href="' . get_permalink($q_post->post_id) . '">' . $q_post->post_title . '</a>';
                        } else {
                            echo '<div id="frontier-my-post-widget-status-' . $tmp_post->post_status . '">' . $q_post->post_title . '</div>';
                        }
                        if ($instance['show_edit_link'] == 'after') {
                            echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-edit-link');
                        }
                        if ($instance['show_delete_link'] == 'after') {
                            echo frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-widget-post-delete-link') . ' ';
                        }
                    }
                    $last_post = $q_post->post_id;
                    if ($show_comments && !empty($q_post->comment_id) && $q_post->comment_approved == 1) {
                        echo "</br>" . $comment_icon . "&nbsp;&nbsp;";
                        if ($show_comment_date) {
                            echo mysql2date($instance['cmtdateformat'], $q_post->comment_date) . " - ";
                        }
                        echo $q_post->comment_author;
                        if ($instance['showcomments'] == 'excerpts') {
                            $tmp_comment = substr($q_post->comment_content, 0, $excerpt_length);
                            if (strlen($q_post->comment_content) > strlen($tmp_comment)) {
                                $tmp_comment = $tmp_comment . "...";
                            }
                            echo ":&nbsp" . "</br><i>" . $tmp_comment . "</i>";
                        }
                    }
                    if ($post_cnt >= $rec_limit) {
                        break;
                    }
                }
            } else {
                echo "<li>" . $instance['no_posts_text'] . "</li>";
            }
            ?>
		</li>
		</ul>
		<?php 
            if (isset($instance['show_add_post']) && $instance['show_add_post'] == 1 && frontier_can_add($instance['post_type'])) {
                if ($instance['post_type'] !== "post") {
                    $tmp_post_type_parm = "&frontier_add_post_type=" . $instance['post_type'];
                } else {
                    $tmp_post_type_parm = "";
                }
                echo '<p><center><a id"frontier-post-widget-add-link" href="' . frontier_post_add_link() . $tmp_post_type_parm . '">' . __("Create New", "frontier-post") . " " . fp_get_posttype_label_singular($instance['post_type']) . '</a></center></p>';
            }
            // Count authors posts - get_permalink(fp_get_option('fps_page_id'))
            if (isset($instance['show_post_count']) && $instance['show_post_count'] == 1) {
                //$tmp_post_cnt	= $wpdb->get_var("SELECT count(ID) AS tmp_post_cnt FROM $wpdb->posts WHERE post_author = ".$author." AND post_status = 'publish' AND post_type = 'post'" );
                $tmp_post_cnt = $fp_wdata['tmp_post_cnt'];
                echo '<p><center><a id="frontier-post-widget-post-count" href="' . get_permalink(fp_get_option('fps_page_id')) . '">' . __("You have published: ", "frontier-post") . $tmp_post_cnt . '&nbsp;' . __("posts", "frontier-post") . '</a></center></p>';
            }
            ?>
		</div>
		<?php 
            //echo "<pre>".print_r($instance)."<pre>";
            echo $args['after_widget'];
        } else {
            // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>";
        }
    }