List category posts - Version 0.76

Version Description

  • Starting_with support for utf8mb4 charset
  • Improve catlink/catlist in widget
  • Avoid PHP Notices when trying to replace widget title but no category is present.
  • Fix 'current category' handling
  • Better test coverage
  • Fix dates parameters: before and after are now working again
  • Remove warning for deprecated create_function in PHP 7
Download this release

Release Info

Developer fernandobt
Plugin Icon 128x128 List category posts
Version 0.76
Comparing to
See all releases

Code changes from version 0.75.2 to 0.76

include/lcp-category.php CHANGED
@@ -59,7 +59,7 @@ class LcpCategory{
59
  }
60
 
61
  public function current_category(){
62
- $category = get_category( get_query_var( 'category' ) );
63
  if( isset( $category->errors ) && $category->errors["invalid_term"][0] == __("Empty Term.") ){
64
  global $post;
65
  $categories = get_the_category($post->ID);
59
  }
60
 
61
  public function current_category(){
62
+ $category = get_category( get_query_var( 'cat' ) );
63
  if( isset( $category->errors ) && $category->errors["invalid_term"][0] == __("Empty Term.") ){
64
  global $post;
65
  $categories = get_the_category($post->ID);
include/lcp-catlist.php CHANGED
@@ -96,7 +96,7 @@ class CatList{
96
  /** HELPER FUNCTIONS **/
97
 
98
  private function check_pagination($args){
99
- if ( $this->utils->lcp_not_empty('pagination') ){
100
  if( array_key_exists('QUERY_STRING', $_SERVER) && null !== $_SERVER['QUERY_STRING'] ){
101
  $query = $_SERVER['QUERY_STRING'];
102
  if ($query !== '' && preg_match('/lcp_page' . preg_quote($this->instance) .
@@ -285,7 +285,7 @@ class CatList{
285
  if($this->utils->lcp_not_empty('author_posts_link') &&
286
  $this->params['author_posts_link'] == 'yes'){
287
  $link = get_author_posts_url($lcp_userdata->ID);
288
- return "<a href=" . $link . " title='" . $author_name .
289
  "'>" . $author_name . "</a>";
290
  } else {
291
  return $author_name;
@@ -332,29 +332,28 @@ class CatList{
332
 
333
  public function get_content($single){
334
  if (isset($this->params['content']) &&
335
- ($this->params['content'] =='yes' || $this->params['content'] =='full') &&
336
- $single->post_content):
337
- $lcp_content = $single->post_content;
338
- $lcp_content = apply_filters('the_content', $lcp_content);
339
- $lcp_content = str_replace(']]>', ']]&gt', $lcp_content);
340
-
341
- if ($this->params['content'] =='yes' &&
342
- preg_match('/[\S\s]+(<!--more(.*?)?-->)[\S\s]+/', $lcp_content, $matches) ):
343
- if( empty($this->params['posts_morelink']) ):
344
- $lcp_more = __('Continue reading &rarr;', 'list-category-posts');
345
- else:
346
- $lcp_more = '';
347
- endif;
348
- $lcp_post_content = explode($matches[1], $lcp_content);
349
- $lcp_content = $lcp_post_content[0] . ($lcp_more ?
350
- ' <a href="' . get_permalink($single->ID) . '" title="' . "$lcp_more" . '">' .
351
- $lcp_more . '</a>' : '');
352
- endif;
353
-
354
- return $lcp_content;
355
- else:
356
- return null;
357
- endif;
358
  }
359
 
360
  public function get_excerpt($single){
96
  /** HELPER FUNCTIONS **/
97
 
98
  private function check_pagination($args){
99
+ if ( LcpUtils::lcp_show_pagination($this->params['pagination']) ){
100
  if( array_key_exists('QUERY_STRING', $_SERVER) && null !== $_SERVER['QUERY_STRING'] ){
101
  $query = $_SERVER['QUERY_STRING'];
102
  if ($query !== '' && preg_match('/lcp_page' . preg_quote($this->instance) .
285
  if($this->utils->lcp_not_empty('author_posts_link') &&
286
  $this->params['author_posts_link'] == 'yes'){
287
  $link = get_author_posts_url($lcp_userdata->ID);
288
+ return "<a href='" . $link . "' title='" . $author_name .
289
  "'>" . $author_name . "</a>";
290
  } else {
291
  return $author_name;
332
 
333
  public function get_content($single){
334
  if (isset($this->params['content']) &&
335
+ ($this->params['content'] =='yes' || $this->params['content'] == 'full') &&
336
+ $single->post_content){
337
+ // get_extended - get content split by <!--more-->
338
+ $lcp_extended = get_extended($single->post_content);
339
+ $lcp_content = $lcp_extended['main'];
340
+ $lcp_content = apply_filters('the_content', $lcp_content);
341
+ $lcp_content = str_replace(']]>', ']]&gt', $lcp_content);
342
+
343
+ if ($this->params['content'] == 'full') {
344
+ $lcp_extended_content = str_replace(']]>', ']]&gt', apply_filters('the_content', $lcp_extended['extended']) );
345
+ $lcp_content .= $lcp_extended_content;
346
+ } else {
347
+ if( empty($this->params['posts_morelink']) ){
348
+ $lcp_more = __('Continue reading &rarr;', 'list-category-posts');
349
+ $lcp_content .= ' <a href="' . get_permalink($single->ID) . '" title="' . "$lcp_more" . '">' .
350
+ $lcp_more . '</a>';
351
+ }
352
+ }
353
+ return $lcp_content;
354
+ }else {
355
+ return null;
356
+ }
 
357
  }
358
 
359
  public function get_excerpt($single){
include/lcp-catlistdisplayer.php CHANGED
@@ -7,7 +7,7 @@
7
  require_once 'lcp-catlist.php';
8
 
9
  class CatListDisplayer {
10
- private $catlist;
11
  private $params = array();
12
  private $lcp_output;
13
 
7
  require_once 'lcp-catlist.php';
8
 
9
  class CatListDisplayer {
10
+ public $catlist;
11
  private $params = array();
12
  private $lcp_output;
13
 
include/lcp-options.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  if ( is_admin() ){
3
  add_action( 'admin_menu', 'list_category_posts_menu' );
4
  add_action( 'admin_init', 'lcp_settings' );
@@ -12,15 +13,15 @@ function lcp_settings() { // whitelist options
12
  }
13
 
14
  function list_category_posts_menu() {
15
- add_options_page( 'List Category Posts Options', 'List Category Posts',
16
  'manage_options', 'list-category-posts',
17
  'list_category_posts_options' );
18
  }
19
 
20
  function list_category_posts_options() {
21
- if ( !current_user_can( 'manage_options' ) ) {
22
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
23
- }
24
  ?>
25
  <div class="wrap">
26
  <h2>List Category Posts</h2>
@@ -78,11 +79,7 @@ function list_category_posts_options() {
78
  <td>
79
  <select id="lcp_orderby" name="lcp_orderby" type="text" >
80
  <?php
81
- $lcp_orders = array("date" => __("Date", "list-category-posts"),
82
- "modified" => __("Modified Date", "list-category-posts"),
83
- "title" => __("Post title", "list-category-posts"),
84
- "author" => __("Author", "list-category-posts"),
85
- "rand" => __("Random", "list-category-posts"));
86
  $orderby = get_option('lcp_orderby');
87
  foreach ($lcp_orders as $key=>$value){
88
  $option = '<option value="' . $key . '" ';
1
  <?php
2
+ include_once("lcp-utils.php");
3
  if ( is_admin() ){
4
  add_action( 'admin_menu', 'list_category_posts_menu' );
5
  add_action( 'admin_init', 'lcp_settings' );
13
  }
14
 
15
  function list_category_posts_menu() {
16
+ add_options_page( 'List Category Posts Options', 'List Category Posts',
17
  'manage_options', 'list-category-posts',
18
  'list_category_posts_options' );
19
  }
20
 
21
  function list_category_posts_options() {
22
+ if ( !current_user_can( 'manage_options' ) ) {
23
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
24
+ }
25
  ?>
26
  <div class="wrap">
27
  <h2>List Category Posts</h2>
79
  <td>
80
  <select id="lcp_orderby" name="lcp_orderby" type="text" >
81
  <?php
82
+ $lcp_orders = LcpUtils::lcp_orders();
 
 
 
 
83
  $orderby = get_option('lcp_orderby');
84
  foreach ($lcp_orders as $key=>$value){
85
  $option = '<option value="' . $key . '" ';
include/lcp-paginator.php CHANGED
@@ -23,20 +23,9 @@ class LcpPaginator {
23
  # is not set to 'no' (since shortcode parameters should
24
  # override general options).
25
  # Receives params['pagination'] from CatList
26
- private function show_pagination($pagination){
27
- return (!empty($pagination) && (
28
- $pagination == 'yes' ||
29
- $pagination == 'true')
30
- )
31
- ||
32
- (get_option('lcp_pagination') === 'true' &&
33
- ($pagination !== 'false') &&
34
- ($pagination !== 'no')
35
- );
36
- }
37
 
38
  public function get_pagination($params){
39
- if ($this->show_pagination($params['pagination'])){
40
  $lcp_paginator = '';
41
  $pages_count = ceil (
42
  $params['posts_count'] /
23
  # is not set to 'no' (since shortcode parameters should
24
  # override general options).
25
  # Receives params['pagination'] from CatList
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  public function get_pagination($params){
28
+ if (LcpUtils::lcp_show_pagination($params['pagination'])){
29
  $lcp_paginator = '';
30
  $pages_count = ceil (
31
  $params['posts_count'] /
include/lcp-parameters.php CHANGED
@@ -297,11 +297,16 @@ class LcpParameters{
297
 
298
  public function starting_with($where){
299
  $letters = explode(',', $this->starting_with);
 
 
 
 
 
300
  $where .= 'AND (wp_posts.post_title ' .
301
- 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[0] . "%'";
302
  for ($i=1; $i <sizeof($letters); $i++) {
303
  $where .= 'OR wp_posts.post_title ' .
304
- 'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
305
  }
306
  $where.=')';
307
  return $where;
@@ -341,9 +346,9 @@ class LcpParameters{
341
  * should be created.
342
  */
343
  foreach ($params_set as $key=>$value){
344
- if ( isset($this->{$key}) ){
345
  $params_set[$key] = true;
346
- $trutify = substr($key, 0, strpos( $key, '_') );
347
  ${$trutify} = true;
348
  }
349
  }
297
 
298
  public function starting_with($where){
299
  $letters = explode(',', $this->starting_with);
300
+
301
+ // Support for both utf8 and utf8mb4
302
+ global $wpdb;
303
+ $charset = $wpdb->get_col_charset('wp_posts', 'post_title');
304
+
305
  $where .= 'AND (wp_posts.post_title ' .
306
+ 'COLLATE ' . strtoupper($charset) . '_GENERAL_CI LIKE \'' . $letters[0] . "%'";
307
  for ($i=1; $i <sizeof($letters); $i++) {
308
  $where .= 'OR wp_posts.post_title ' .
309
+ 'COLLATE ' . strtoupper($charset) . '_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
310
  }
311
  $where.=')';
312
  return $where;
346
  * should be created.
347
  */
348
  foreach ($params_set as $key=>$value){
349
+ if ( property_exists($this, $key) ){
350
  $params_set[$key] = true;
351
+ $trutify = explode('_', $key)[0];
352
  ${$trutify} = true;
353
  }
354
  }
include/lcp-utils.php CHANGED
@@ -16,4 +16,24 @@ class LcpUtils{
16
  $this->params[$param] !== ''
17
  );
18
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  }
16
  $this->params[$param] !== ''
17
  );
18
  }
19
+
20
+ public static function lcp_orders(){
21
+ return array("date" => __("Date", "list-category-posts"),
22
+ "modified" => __("Modified Date", "list-category-posts"),
23
+ "title" => __("Post title", "list-category-posts"),
24
+ "author" => __("Author", "list-category-posts"),
25
+ "rand" => __("Random", "list-category-posts"));
26
+ }
27
+
28
+ public static function lcp_show_pagination($pagination){
29
+ return (!empty($pagination) && (
30
+ $pagination == 'yes' ||
31
+ $pagination == 'true')
32
+ )
33
+ ||
34
+ (get_option('lcp_pagination') === 'true' &&
35
+ ($pagination !== 'false') &&
36
+ ($pagination !== 'no')
37
+ );
38
+ }
39
  }
include/lcp-widget-form.php CHANGED
@@ -25,6 +25,7 @@
25
  'template' => '',
26
  'pagination' => ''
27
  );
 
28
  $instance = wp_parse_args( (array) $instance, $default);
29
 
30
  $title = strip_tags($instance['title']);
@@ -114,11 +115,7 @@
114
  </label> <br/>
115
  <select id="<?php echo $this->get_field_id('orderby'); ?>"
116
  name="<?php echo $this->get_field_name('orderby'); ?>" type="text" >
117
- <?php $lcp_orders = array("date" => __("Date", "list-category-posts"),
118
- "modified" => __("Modified Date", "list-category-posts"),
119
- "title" => __("Post title", "list-category-posts"),
120
- "author" => __("Author", "list-category-posts"),
121
- "rand" => __("Random", "list-category-posts"));
122
  foreach ($lcp_orders as $key=>$value):
123
  $option = '<option value="' . $key . '" ';
124
  if ($orderby == $key):
25
  'template' => '',
26
  'pagination' => ''
27
  );
28
+ include_once("lcp-utils.php");
29
  $instance = wp_parse_args( (array) $instance, $default);
30
 
31
  $title = strip_tags($instance['title']);
115
  </label> <br/>
116
  <select id="<?php echo $this->get_field_id('orderby'); ?>"
117
  name="<?php echo $this->get_field_name('orderby'); ?>" type="text" >
118
+ <?php $lcp_orders = LcpUtils::lcp_orders();
 
 
 
 
119
  foreach ($lcp_orders as $key=>$value):
120
  $option = '<option value="' . $key . '" ';
121
  if ($orderby == $key):
include/lcp-widget.php CHANGED
@@ -75,7 +75,17 @@ class ListCategoryPostsWidget extends WP_Widget{
75
 
76
  if ($pagination === 'yes') lcp_pagination_css();
77
 
78
- if ($title == 'catlink') {
 
 
 
 
 
 
 
 
 
 
79
  // If the user has setup 'catlink' as the title, replace it with
80
  // the category link:
81
  $lcp_category = get_category($category_id);
@@ -84,13 +94,12 @@ class ListCategoryPostsWidget extends WP_Widget{
84
  } elseif ($title == 'catname') {
85
  // If the user has setup 'catname' as the title, replace it with
86
  // the category link:
87
- $lcp_category = get_the_category($post->ID);
88
- $title = $lcp_category[0]->name;
89
  }
90
  echo $before_title . $title . $after_title;
91
 
92
- $catlist_displayer = new CatListDisplayer($atts);
93
- echo $catlist_displayer->display();
94
  echo $after_widget;
95
  }
96
 
@@ -129,4 +138,7 @@ class ListCategoryPostsWidget extends WP_Widget{
129
  }
130
  }
131
 
132
- add_action('widgets_init', create_function('', 'return register_widget("listCategoryPostsWidget");'));
 
 
 
75
 
76
  if ($pagination === 'yes') lcp_pagination_css();
77
 
78
+ // To make the widget title replacement work with "Current category" we need to
79
+ // run the displayer here to determine the current cat id.
80
+ // Otherwise the id remains set to "-1".
81
+ $catlist_displayer = new CatListDisplayer($atts);
82
+ $lcp_display = $catlist_displayer->display();
83
+
84
+ // Fetch the category id from the Catlist instance.
85
+ $category_id = $catlist_displayer->catlist->get_category_id();
86
+ if ($category_id === null && ($title == 'catlink' || $title == 'catname')) {
87
+ $title = '';
88
+ } elseif ($title == 'catlink') {
89
  // If the user has setup 'catlink' as the title, replace it with
90
  // the category link:
91
  $lcp_category = get_category($category_id);
94
  } elseif ($title == 'catname') {
95
  // If the user has setup 'catname' as the title, replace it with
96
  // the category link:
97
+ $lcp_category = get_category($category_id);
98
+ $title = $lcp_category->name;
99
  }
100
  echo $before_title . $title . $after_title;
101
 
102
+ echo $lcp_display;
 
103
  echo $after_widget;
104
  }
105
 
138
  }
139
  }
140
 
141
+ function lcp_register_widget() {
142
+ return register_widget("listCategoryPostsWidget");
143
+ }
144
+ add_action('widgets_init', 'lcp_register_widget');
list-category-posts.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
- Version: 0.75.2
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
3
  Plugin Name: List category posts
4
  Plugin URI: https://github.com/picandocodigo/List-Category-Posts
5
  Description: List Category Posts allows you to list posts by category in a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, the number of posts to display and many more parameters. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
6
+ Version: 0.76
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: fernandobt
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
- Tested up to: 4.9
7
  Requires PHP: 5.2.4
8
- Stable tag: 0.75.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -440,6 +440,16 @@ Template system has changed. Custom templates should be stored in WordPress them
440
 
441
  == Changelog ==
442
 
 
 
 
 
 
 
 
 
 
 
443
  = 0.75.2 =
444
 
445
  * Fix `author_post` and `search` parameters.
3
  Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/#support
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
+ Tested up to: 4.9.4
7
  Requires PHP: 5.2.4
8
+ Stable tag: 0.76
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
440
 
441
  == Changelog ==
442
 
443
+ = 0.76 =
444
+
445
+ * Starting_with support for utf8mb4 charset
446
+ * Improve catlink/catlist in widget
447
+ * Avoid PHP Notices when trying to replace widget title but no category is present.
448
+ * Fix 'current category' handling
449
+ * Better test coverage
450
+ * Fix dates parameters: `before` and `after` are now working again
451
+ * Remove warning for deprecated `create_function` in PHP 7
452
+
453
  = 0.75.2 =
454
 
455
  * Fix `author_post` and `search` parameters.