function fp_get_option_bool($tmp_option_name) { $fp_settings = frontier_post_get_settings(); if (array_key_exists($tmp_option_name, $fp_settings)) { $tmp_value = $fp_settings[$tmp_option_name] ? $fp_settings[$tmp_option_name] : "false"; return fp_bool($tmp_value); } else { return false; } }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { 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 ' '; } 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 . " "; 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 ": " . "</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 && current_user_can('frontier_post_can_add')) { 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 href="' . frontier_post_add_link() . $tmp_post_type_parm . '">' . __("Create New Post", "frontier-post") . '</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 href="' . get_permalink(fp_get_option('fps_page_id')) . '">' . __("You have published: ", "frontier-post") . $tmp_post_cnt . ' ' . __("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>"; } }
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 }
function frontier_user_post_list($fpost_sc_parms = array()) { //extract($fpost_sc_parms); global $post; $current_user = wp_get_current_user(); $tmp_p_id = get_the_id(); $pagenum = isset($_GET['pagenum']) ? intval($_GET['pagenum']) : 1; $tmp_default_status = array('draft', 'pending', 'publish', 'private', 'future'); if (count($fpost_sc_parms['frontier_user_status']) > 0) { $tmp_status_list = array_intersect($fpost_sc_parms['frontier_user_status'], $tmp_default_status); } else { $tmp_status_list = $tmp_default_status; } $args = array('post_type' => $fpost_sc_parms['frontier_list_post_types'], 'post_status' => $tmp_status_list, 'order' => 'DESC', 'orderby' => 'post_date', 'posts_per_page' => $fpost_sc_parms['frontier_ppp'], 'paged' => $pagenum); // add category from shortcode to limit posts if ($fpost_sc_parms['frontier_list_cat_id'] > 0) { $args["cat"] = implode(",", $fpost_sc_parms['frontier_list_cat_id']); } //List all published posts if (fp_bool($fpost_sc_parms['frontier_list_all_posts'])) { // limit list to status=publish to the list, if users do not have private posts (editors & admins) if (!current_user_can('edit_private_posts')) { $args["post_status"] = "publish"; } } else { $args["author"] = $current_user->ID; } // List pending posts if (fp_bool($fpost_sc_parms['frontier_list_pending_posts'])) { if (!current_user_can('edit_others_posts')) { echo '<br><div id="frontier-post-alert">' . __("You do not have access to other users pending posts", "frontier-post") . '</div><br>'; return; } $args["post_status"] = "pending"; if (array_key_exists("author", $args)) { unset($args['author']); } } // List pending posts if (fp_bool($fpost_sc_parms['frontier_list_draft_posts'])) { if (!current_user_can('edit_others_posts')) { echo '<br><div id="frontier-post-alert">' . __("You do not have access to other users draft posts", "frontier-post") . '</div><br>'; return; } $args["post_status"] = "draft"; if (array_key_exists("author", $args)) { unset($args['author']); } } $user_posts = new WP_Query($args); $fp_show_icons = fp_get_option_bool('fps_use_icons'); $fp_list_form = fp_get_option("fps_default_list", "list"); switch ($fp_list_form) { case 'simple': include_once frontier_load_form("frontier_post_form_list.php"); break; case 'theme': include_once frontier_load_form("frontier_post_form_list_theme.php"); break; default: include_once frontier_load_form("frontier_post_form_list_detail.php"); break; } /* if (fp_get_option("fps_default_list", "list") == "simple") include_once(frontier_load_form("frontier_post_form_list.php")); else include_once(frontier_load_form("frontier_post_form_list_detail.php")); */ }
</td> </tr> </table> </fieldset> <?php //echo '<hr>'; } // end while have posts if (fp_bool($fpost_sc_parms['frontier_pagination'])) { $pagination = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'prev_text' => __('«', 'frontier-post'), 'next_text' => __('»', 'frontier-post'), 'total' => $user_posts->max_num_pages, 'current' => $pagenum, 'add_args' => false)); //if ( $pagination ) // echo $pagination; if ($pagination) { echo '<br><div id="frontier-post-pagination">' . $pagination . '</div>'; } } if (!fp_bool($fpost_sc_parms['frontier_list_all_posts'])) { echo "</br>" . __("Number of posts already created by you: ", "frontier-post") . $user_posts->found_posts . "</br>"; } echo '</div>'; } else { echo "</br><center>"; _e('Sorry, you do not have any posts (yet)', 'frontier-post'); echo "</center><br></br>"; } // end post count //Re-instate $post for the page wp_reset_postdata();
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in() && current_user_can("edit_others_posts")) { $instance = array_merge($this->defaults, $instance); $frontier_page_link = get_permalink(fp_get_option('fps_page_id')); // from version 3.4.6 caching will be available, and as such changed to handle in one array. $fp_cache_name = FRONTIER_MY_APPROVALS_W_PREFIX . $this->number; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; global $wpdb; //error_log(print_r($instance), true); if ($fp_cache_time <= 0 || false === ($fp_wdata = get_transient($fp_cache_name))) { $fp_wdata = array(); if (isset($instance['show_draft']) && $instance['show_draft'] == true) { $fp_wdata['draft_cnt'] = $wpdb->get_var("SELECT count(id) AS draft_cnt FROM {$wpdb->posts} WHERE post_status = 'draft'"); $fp_wdata['draft_txt'] = $fp_wdata['draft_cnt'] . ' ' . __('draft posts', 'frontier-post'); $fp_wdata['show_draft'] = true; } else { $fp_wdata['show_draft'] = false; } if (isset($instance['show_pending']) && $instance['show_pending'] == true) { $fp_wdata['pending_cnt'] = $wpdb->get_var("SELECT count(id) AS pending_cnt FROM {$wpdb->posts} WHERE post_status = 'pending'"); $fp_wdata['pending_txt'] = $fp_wdata['pending_cnt'] . ' ' . __('posts to be approved', 'frontier-post'); $fp_wdata['show_pending'] = true; } else { $fp_wdata['show_pending'] = false; } if (isset($instance['show_comments']) && $instance['show_comments'] == true) { $fp_wdata['cmt_pending_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 0"); $fp_wdata['cmt_pending_txt'] = $fp_wdata['cmt_pending_cnt'] . ' ' . __('comments to be approved', 'frontier-post'); $fp_wdata['show_comments'] = true; } else { $fp_wdata['show_comments'] = false; } if (isset($instance['show_comment_spam']) && $instance['show_comment_spam'] == true) { $fp_wdata['cmt_spam_cnt'] = $wpdb->get_var("SELECT count(comment_ID) AS cmt_pending_cnt FROM {$wpdb->comments} WHERE comment_approved = 'spam'"); $fp_wdata['cmt_spam_txt'] = $fp_wdata['cmt_spam_cnt'] . ' ' . __('spam comments', 'frontier-post'); $fp_wdata['show_comment_spam'] = true; } else { $fp_wdata['show_comment_spam'] = false; } if (intval($instance['pending_count']) > 0) { //$tmp_sql = ""; $tmp_sql = "SELECT ID AS post_id, post_title AS post_title FROM {$wpdb->posts} WHERE post_status = 'pending' ORDER BY post_date DESC LIMIT " . intval($instance['pending_count']) . " "; $fp_wdata['pending_list'] = $wpdb->get_results($tmp_sql); $fp_wdata['pending_count'] = intval($instance['pending_count']); } else { $fp_wdata['pending_count'] = 0; } if (intval($instance['draft_count']) > 0) { //$tmp_sql = ""; $tmp_sql = "SELECT ID AS post_id, post_title AS post_title FROM {$wpdb->posts} WHERE post_status = 'draft' ORDER BY post_date DESC LIMIT " . intval($instance['draft_count']) . " "; $fp_wdata['draft_list'] = $wpdb->get_results($tmp_sql); $fp_wdata['draft_count'] = intval($instance['draft_count']); } else { $fp_wdata['draft_count'] = 0; } $fp_wdata['postdateformat'] = $instance['postdateformat']; $fp_wdata['show_author'] = fp_bool($instance['show_author']); 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 '<div class="frontier-my-post-widget">'; echo '<ul>'; if ($fp_wdata['show_pending']) { if (fp_get_option_int('fps_pending_page_id', 0) > 0) { $tmp_pending_link = get_permalink(fp_get_option('fps_pending_page_id')); } else { $tmp_pending_link = site_url('/wp-admin/edit.php?post_status=pending&post_type=post'); } if (fp_get_option_int('fps_draft_page_id', 0) > 0) { $tmp_draft_link = get_permalink(fp_get_option('fps_draft_page_id')); } else { $tmp_draft_link = site_url('/wp-admin/edit.php?post_status=draft&post_type=post'); } echo '<li>'; echo '<a href="' . $tmp_pending_link . '">' . $fp_wdata['pending_txt'] . '</a>'; echo '</li>'; } if (array_key_exists('pending_count', $fp_wdata) && $fp_wdata['pending_count'] > 0) { if (!$fp_wdata['show_pending']) { echo '<li>' . __("Pending posts", "frontier-post") . '</li>'; } echo '<ul class="frontier-my-approvals-pending">'; foreach ($fp_wdata['pending_list'] as $q_post) { $tmp_post = get_post($q_post->post_id); echo '<li class="frontier-my-approvals-pending">'; if ($fp_wdata['postdateformat'] != 'nodate') { echo '<div id="frontier-my-approvals-date-pending">' . mysql2date($instance['postdateformat'], $tmp_post->post_date) . ' </div>'; } echo $q_post->post_title; if ($fp_wdata['show_author']) { echo '<div id="frontier-my-approvals-author">' . ' (' . get_the_author_meta('nicename', $tmp_post->post_author) . ')</div>'; } echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-edit-link'); echo ' ' . frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-delete-link'); echo '</li>'; } echo '</ul>'; } if ($fp_wdata['show_draft']) { echo '<li>'; echo '<a href="' . $tmp_draft_link . '">' . $fp_wdata['draft_txt'] . '</a>'; echo '</li>'; } if (array_key_exists('draft_count', $fp_wdata) && $fp_wdata['draft_count'] > 0) { if (!$fp_wdata['show_draft']) { echo '<li>' . __("Draft posts", "frontier-post") . '</li>'; } echo '<ul class="frontier-my-approvals-draft">'; foreach ($fp_wdata['draft_list'] as $q_post) { $tmp_post = get_post($q_post->post_id); echo '<li class="frontier-my-approvals-draft">'; if ($fp_wdata['postdateformat'] != 'nodate') { echo '<div id="frontier-my-approvals-date-draft">' . mysql2date($instance['postdateformat'], $tmp_post->post_date) . ' </div>'; } echo $q_post->post_title; if ($fp_wdata['show_author']) { echo '<div id="frontier-my-approvals-author">' . ' (' . get_the_author_meta('nicename', $tmp_post->post_author) . ')</div>'; } echo ' ' . frontier_post_edit_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-edit-link'); echo ' ' . frontier_post_delete_link($tmp_post, true, $frontier_page_link, 'fp-my-approvals-post-delete-link'); echo '</li>'; } echo '</ul>'; } if ($fp_wdata['show_comments']) { echo '<li>'; echo '<a href="' . site_url('/wp-admin/edit-comments.php?comment_status=moderated') . '">' . $fp_wdata['cmt_pending_txt'] . '</a>'; echo '</li>'; } if ($fp_wdata['show_comment_spam']) { echo '<li>'; echo '<a href="' . site_url('/wp-admin/edit-comments.php?comment_status=spam') . '">' . $fp_wdata['cmt_spam_txt'] . '</a>'; echo '</li>'; } echo '</ul>'; echo '</div>'; //echo "<pre>".print_r($fp_wdata, true)."</pre><br>"; echo $args['after_widget']; } }
function frontier_posting_form_submit($fpost_sc_parms = array()) { //extract($fpost_sc_parms); global $current_user; // which button has been pressed $tmp_return = isset($_POST['user_post_submit']) ? $_POST['user_post_submit'] : "savereturn"; //Get Frontier Post capabilities $fp_capabilities = frontier_post_get_capabilities(); if (isset($_POST['action']) && $_POST['action'] == "wpfrtp_save_post") { if (!wp_verify_nonce($_POST['frontier_add_edit_post_' . $_POST['postid']], 'frontier_add_edit_post')) { wp_die(__("Security violation (Nonce check) - Please contact your Wordpress administrator", "frontier-post")); } //Save quick post mode if (isset($_POST['fp_show_quickpost']) && fp_bool($_POST['fp_show_quickpost'])) { update_user_meta($current_user->ID, 'frontier_post_show_quickpost', "true"); } else { update_user_meta($current_user->ID, 'frontier_post_show_quickpost', "false"); } if (isset($_REQUEST['task']) && $_REQUEST['task'] == "new") { $tmp_task_new = true; } else { $tmp_task_new = false; } //fp_log("New post ? : ".$tmp_task_new); if (isset($_POST['post_status'])) { $post_status = $_POST['post_status']; } else { $post_status = 'draft'; } //Check if Publish has been pressed if ($tmp_return === "publish" && current_user_can("frontier_post_can_publish")) { $post_status = 'publish'; } $tmp_post_type = isset($_POST['posttype']) ? $_POST['posttype'] : 'post'; $postid = $_POST['postid']; $tmp_title = trim($_POST['user_post_title']); $tmp_content = trim($_POST['frontier_post_content']); // check empty title, and set status to draft if status is empty if (empty($tmp_title)) { if (strlen($tmp_content) > 20) { $tmp_title = wp_trim_words($tmp_content, 10); } else { $tmp_title = __("No Title", "frontier-post"); } $post_status = 'draft'; frontier_post_set_msg('<div id="frontier-post-alert">' . __("Warning", "frontier-post") . ': ' . __("Title was empty", "frontier-post") . ' - ' . __("Post status set to draft", "frontier-post") . '</div>'); } $tmp_title = trim(strip_tags($tmp_title)); if (!fp_get_option_bool("fps_allow_empty_content") && empty($tmp_content)) { $tmp_content = __("No content", "frontier-post"); $post_status = 'draft'; frontier_post_set_msg('<div id="frontier-post-alert">' . __("Warning", "frontier-post") . ': ' . __("Content was empty", "frontier-post") . ' - ' . __("Post status set to draft", "frontier-post") . '</div>'); } $tmp_excerpt = isset($_POST['user_post_excerpt']) ? trim($_POST['user_post_excerpt']) : null; $users_role = frontier_get_user_role(); //**************************************************************************************************** // Manage Categories //**************************************************************************************************** // Do not manage categories for page if ($tmp_post_type != 'page') { $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"); $tmp_field_name = frontier_tax_field_name('category'); if ($category_type != "hide" && $category_type != "readonly") { $tmp_categorymulti = isset($_POST[$tmp_field_name]) ? $_POST[$tmp_field_name] : array(); } //frontier_post_set_msg("Default Category: ".$default_category); //frontier_post_set_msg("Post Categories: ".( isset($_POST['post_categories']) ? $_POST['post_categories'] : "NONE")); // if no category returned from entry form, check for hidden field, if this is empty set default category if (!isset($tmp_categorymulti) || count($tmp_categorymulti) == 0) { $tmp_categorymulti = isset($_POST['post_categories']) ? explode(',', $_POST['post_categories']) : array(); // Do not use default category if post type = page if ($tmp_post_type != 'page') { $tmp_categorymulti = count($tmp_categorymulti) > 0 && isset($tmp_categorymulti[0]) && $tmp_categorymulti[0] > 0 ? $tmp_categorymulti : array($default_category); } } //frontier_post_set_msg("Category from POST: ".print_r($tmp_categorymulti,true)); } // do not manage categories for pages //**************************************************************************************************** // Update post //**************************************************************************************************** $tmp_post = array('ID' => $postid, 'post_type' => $tmp_post_type, 'post_title' => $tmp_title, 'post_status' => $post_status, 'post_content' => $tmp_content, 'post_excerpt' => $tmp_excerpt); // Do not manage categories for page if ($tmp_post_type != 'page') { $tmp_post['post_category'] = $tmp_categorymulti; } //**************************************************************************************************** // Apply filter before update of post // filter: frontier_post_pre_update // $tmp_post Array that holds the updated fields // $tmp_task_new Equals true if the user is adding a post // $_POST Input form //**************************************************************************************************** $tmp_post = apply_filters('frontier_post_pre_update', $tmp_post, $tmp_task_new, $_POST); //Set $post_status to tmp_post value, if changed by filter $post_status = $tmp_post['post_status']; //force save with draft status first, if new post and status is set to published to align with wordpress standard if ($tmp_task_new == true && $post_status == "publish") { $tmp_post['post_status'] = "draft"; wp_update_post($tmp_post); $tmp_post = array('ID' => $postid, 'post_status' => $post_status); wp_update_post($tmp_post); } else { wp_update_post($tmp_post); } //**************************************************************************************************** // Tags //**************************************************************************************************** // Do not manage tags for page if (current_user_can('frontier_post_tags_edit') && $tmp_post_type != 'page') { $fp_tag_count = fp_get_option_int("fps_tag_count", 3); $taglist = array(); for ($i = 0; $i < $fp_tag_count; $i++) { if (isset($_POST['user_post_tag' . $i])) { array_push($taglist, fp_tag_transform($_POST['user_post_tag' . $i])); } } wp_set_post_tags($postid, $taglist); } //**************************************************************************************************** // Add/Update message //**************************************************************************************************** if ($tmp_task_new == true) { frontier_post_set_msg(__("Post added", "frontier-post") . ": " . $tmp_title); } else { frontier_post_set_msg(__("Post updated", "frontier-post") . ": " . $tmp_title); } //**************************************************************************************************** // Taxonomies //**************************************************************************************************** // Do not manage taxonomies for page if ($tmp_post_type != 'page') { foreach ($fpost_sc_parms['frontier_custom_tax'] as $tmp_tax_name) { if (!empty($tmp_tax_name) && $tmp_tax_name != 'category') { $tmp_field_name = frontier_tax_field_name($tmp_tax_name); $tmp_value = isset($_POST[$tmp_field_name]) ? $_POST[$tmp_field_name] : array(); if (is_array($tmp_value)) { $tmp_tax_selected = $tmp_value; } else { $tmp_tax_selected = array($tmp_value); } wp_set_post_terms($postid, $tmp_tax_selected, $tmp_tax_name); //error_log("set terms: ".$tmp_tax_name." : ". print_r($tmp_tax_selected,true)); } } } // end do not manage taxonomies for pages //**************************************************************************************************** // End updating post //**************************************************************************************************** //Get the updated post $my_post = get_post($postid); // Delete users cache for My Posts widget fp_delete_my_post_w_cache(); //*************************************************************************************** //* Save post moderation fields //*************************************************************************************** if (fp_get_option_bool("fps_use_moderation") && (current_user_can("edit_others_posts") || $current_user->ID == $my_post->post_author)) { if (isset($_POST['frontier_post_moderation_new_text'])) { $fp_moderation_comments_new = $_POST['frontier_post_moderation_new_text']; //$fp_moderation_comments_new = trim(stripslashes(strip_tags($fp_moderation_comments_new))); $fp_moderation_comments_new = wp_strip_all_tags($fp_moderation_comments_new); $fp_moderation_comments_new = nl2br($fp_moderation_comments_new); $fp_moderation_comments_new = stripslashes($fp_moderation_comments_new); $fp_moderation_comments_new = trim($fp_moderation_comments_new); if (strlen($fp_moderation_comments_new) > 0) { global $current_user; $fp_moderation_comments_old = get_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_TEXT', true); $fp_moderation_comments = current_time('mysql') . " - " . $current_user->user_login . ":<br>"; $fp_moderation_comments .= $fp_moderation_comments_new . "<br>"; $fp_moderation_comments .= '<hr>' . "<br>"; $fp_moderation_comments .= $fp_moderation_comments_old . "<br>"; update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_TEXT', $fp_moderation_comments); update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_DATE', current_time('mysql')); update_post_meta($my_post->ID, 'FRONTIER_POST_MODERATION_FLAG', 'true'); // Email author on moderation comments if (isset($_POST['frontier_post_moderation_send_email']) && $_POST['frontier_post_moderation_send_email'] == "true") { $to = get_the_author_meta('email', $my_post->post_author); $subject = __("Moderator has commented your pending post", "frontier-post") . " (" . get_bloginfo("name") . ")"; $body = __("Moderator has commented your pending post", "frontier-post") . ": " . $my_post->post_title . " (" . get_bloginfo("name") . ")" . "\r\n\r\n"; $body .= "Comments: " . $_POST['frontier_post_moderation_new_text'] . "\r\n\r\n"; if (!wp_mail($to, $subject, $body)) { frontier_post_set_msg(__("Message delivery failed - Recipient: (", "frontier-post") . $to . ")"); } } } } } //**************************************************************************************************** // Action fires after add/update of post, and after taxonomies are updated // Do action frontier_post_post_save // $my_post Post object for the post just updated // $tmp_task_new Equals true if the user is adding a post // $_POST Input form //**************************************************************************************************** do_action('frontier_post_post_save', $my_post, $tmp_task_new, $_POST); //If save, set task to edit if ($tmp_return == "save") { $_REQUEST['task'] = "edit"; $_REQUEST['postid'] = $postid; } // if shortcode frontier_mode=add, return to add form instead of list if ($fpost_sc_parms['frontier_mode'] == "add" && $tmp_return == "savereturn") { $tmp_return = "add"; } switch ($tmp_return) { case 'preview': frontier_preview_post($postid); break; case 'add': frontier_post_add_edit($fpost_sc_parms); break; case 'savereturn': frontier_user_post_list($fpost_sc_parms); break; case 'save': frontier_post_add_edit($fpost_sc_parms); break; case 'delete': frontier_prepare_delete_post($fpost_sc_parms); break; default: frontier_user_post_list($fpost_sc_parms); break; } } else { frontier_post_set_msg(__("Error - Unable to save post", "frontier-post")); frontier_user_post_list($fpost_sc_parms); } // end isset post }