/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { $tmp_cat_id = get_query_var("cat"); // Only show if on category archive pages if (!isset($tmp_cat_id) || $tmp_cat_id == 0) { return; } $instance = array_merge($this->defaults, $instance); $tmp_cat_name = get_cat_name($tmp_cat_id); //error_log("cat id: "); //error_log($tmp_cat_id); // Set link & Title name $tmp_link_name = str_replace('#category#', $tmp_cat_name, $instance['link_name']); $tmp_title_name = str_replace('#category#', $tmp_cat_name, $instance['title']); echo $args['before_widget']; if (!empty($instance['title'])) { echo $args['before_title']; //echo $instance['title']; echo $tmp_title_name; echo $args['after_title']; } ?> <div class="frontier-category-post-widget"> <?php //echo "Category: "; //echo $tmp_cat_name."(".$tmp_cat_id.")"; echo '<p><center><a href="' . frontier_post_add_link(null, $tmp_cat_id) . '&frontier_new_cat_widget=true' . '">' . $tmp_link_name . '</a></center></p>'; ?> </div> <?php echo $args['after_widget']; } else { // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>"; } }
/* 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" > </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; ?> </a></th> <th class="frontier-menu" > </th> </tr> </table> <?php } // if can_add if ($user_posts->found_posts > 0) { $tmp_status_list = get_post_statuses(); // If post for all users is viewed, show author instead of category
/** @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>"; } }
/** @see WP_Widget::widget */ function widget($args, $instance) { if (is_user_logged_in()) { global $current_user, $wpdb, $r; $instance = array_merge($this->defaults, $instance); $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 = $args['widget_id'] . "_fpuser_" . $author; $fp_cache_time = $instance['fp_cache_time']; $fp_cache_test = "Cache active"; 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 \n\t\t\t\t\t\t\t {$wpdb->posts}.ID \t\t\t\t\tAS post_id, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_title \t\t\tAS post_title, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_date \t\t\tAS post_date, \n\t\t\t\t\t\t\t {$wpdb->comments}.comment_ID \t\tAS comment_id, \n\t\t\t\t\t\t\t {$wpdb->comments}.comment_author \tAS comment_author,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_date \t\tAS comment_date,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_approved\tAS comment_approved,\n\t\t\t\t\t\t\t {$wpdb->comments}.comment_content \tAS comment_content \n\t\t\t\t\t\t\t\t FROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t left OUTER JOIN {$wpdb->comments} ON \n\t\t\t\t\t\t\t\t\t {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID \n\t\t\t\t\t\t\t\t WHERE {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\t\t\t AND {$wpdb->posts}.post_type \t= 'post' \n\t\t\t\t\t\t\t\t AND {$wpdb->posts}.post_author \t= " . $author . "\n\t\t\t\t\t\t\t\t ORDER BY {$wpdb->posts}.post_date DESC, {$wpdb->comments}.comment_date_gmt DESC \n\t\t\t\t\t\t\t\t LIMIT " . $rec_limit * 5; } else { $tmp_sql = " SELECT {$wpdb->posts}.ID \tAS post_id, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_title \tAS post_title, \n\t\t\t\t\t\t\t {$wpdb->posts}.post_date \tAS post_date \n\t\t\t\t\t\t\t FROM {$wpdb->posts} \n\t\t\t\t\t\t\t WHERE {$wpdb->posts}.post_author = " . $author . " AND {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_type = 'post' \n\t\t\t\t\t\t\t ORDER BY {$wpdb->posts}.post_date DESC \n\t\t\t\t\t\t\t LIMIT " . $rec_limit * 5; // needs to multiply to account for non approved comments } $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> <?php $last_post = 0; $post_cnt = 0; if ($fp_wdata['presult']) { foreach ($fp_wdata['presult'] as $post) { $tmp_link = "xx"; if ($last_post != $post->post_id) { if ($post_cnt > 0) { echo "</li>"; } echo "<li>"; $post_cnt++; if ($show_date) { echo mysql2date($instance['postdateformat'], $post->post_date); echo ' '; } ?> <a href="<?php echo post_permalink($post->post_id); ?> "><?php echo $post->post_title; ?> </a> <?php } $last_post = $post->post_id; if ($show_comments && !empty($post->comment_id) && $post->comment_approved == 1) { echo "</br>" . $comment_icon . " "; if ($show_comment_date) { echo mysql2date($instance['cmtdateformat'], $post->comment_date) . " - "; } echo $post->comment_author; if ($instance['showcomments'] == 'excerpts') { $tmp_comment = substr($post->comment_content, 0, $excerpt_length); if (strlen($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')) { echo '<p><center><a href="' . frontier_post_add_link() . '">' . __("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 $args['after_widget']; } else { // echo "<p>".__("You need to login to see your posts", "frontier-post")."</p>"; } }
frontier_post_output_msg(); 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']); } $fp_cat_list = implode(",", $fpost_sc_parms['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($fpost_sc_parms['frontier_add_post_type']) && !fp_get_option_bool("fps_hide_add_on_list")) { echo '<table class="frontier-menu" >'; echo '<tr class="frontier-menu">'; echo '<th class="frontier-menu" > </th>'; echo '<th class="frontier-menu" ><a id="frontier-post-add-new-link" href="' . frontier_post_add_link($tmp_p_id) . '">' . $tmp_add_text . '</a></th>'; echo '<th class="frontier-menu" > </th>'; echo '</tr>'; echo '</table>'; } 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; echo ' - ' . __("This message is only shown to admins", "frontier-post") . '<br><br>'; echo '</div>'; } } // if can_add //******************************************************************************************************* // Quickpost //*******************************************************************************************************