List category posts - Version 0.58

Version Description

  • Removes filter interfering with filters set by other plugins. Thanks zulkamal for the Pull Request!
  • Adds option to display titles without links. Thanks zulkamal for this Pull Request too! :D
  • Workaround to prevent '?&' to appear in URLs. Thanks mhoeher for the Pull Request!
  • General refactors for improving code quality/security.
  • Fixed typo in Readme (Thanks Irma!).
  • Fixes excluding tags when using category name (should fix other issues with category name too since there was a bug there).
Download this release

Release Info

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

Code changes from version 0.57 to 0.58

include/lcp-category.php CHANGED
@@ -28,7 +28,6 @@ class LcpCategory{
28
  foreach ($cat_array as $category){
29
  $categories[] = $this->get_category_id_by_name($category);
30
  }
31
-
32
  $lcp_category_id = $categories;
33
  // OR relationship
34
  } elseif (preg_match('/,/', $name )){
28
  foreach ($cat_array as $category){
29
  $categories[] = $this->get_category_id_by_name($category);
30
  }
 
31
  $lcp_category_id = $categories;
32
  // OR relationship
33
  } elseif (preg_match('/,/', $name )){
include/lcp-catlist.php CHANGED
@@ -57,7 +57,7 @@ class CatList{
57
  $this->lcp_categories_posts = $query->query($args);
58
  $this->posts_count = $query->found_posts;
59
  remove_all_filters('posts_orderby');
60
- remove_all_filters('posts_where');
61
  }
62
 
63
  /* Should I return posts or show that the tag/category or whatever
@@ -71,10 +71,12 @@ class CatList{
71
 
72
  private function check_pagination($args){
73
  if ( $this->utils->lcp_not_empty('pagination') ){
74
- if(isset($_SERVER['QUERY_STRING']) &&
75
- !empty($_SERVER['QUERY_STRING']) &&
76
- ( preg_match('/lcp_page' . preg_quote($this->instance) .
77
- '=([0-9]+)/i', $_SERVER['QUERY_STRING'], $match) ) ){
 
 
78
  $this->page = $match[1];
79
  $offset = ($this->page - 1) * $this->params['numberposts'];
80
  $args = array_merge($args, array('offset' => $offset));
@@ -98,13 +100,14 @@ class CatList{
98
  private function get_lcp_category(){
99
  // In a category page:
100
  if ( $this->utils->lcp_not_empty('categorypage') &&
101
- $this->params['categorypage'] == 'yes' ||
102
- $this->params['id'] == -1){
103
  // Use current category
104
  $this->lcp_category_id = LcpCategory::get_instance()->current_category();
105
  } elseif ( $this->utils->lcp_not_empty('name') ){
106
  // Using the category name:
107
  $this->lcp_category_id = LcpCategory::get_instance()->with_name( $this->params['name'] );
 
108
  } elseif ( isset($this->params['id']) && $this->params['id'] != '0' ){
109
  // Using the id:
110
  $this->lcp_category_id = LcpCategory::get_instance()->with_id( $this->params['id'] );
@@ -125,43 +128,43 @@ class CatList{
125
  */
126
  public function get_category_link(){
127
  if(($this->utils->lcp_not_empty('catlink') &&
128
- $this->params['catlink'] == 'yes' ||
129
- $this->utils->lcp_not_empty('catname') &&
130
- $this->params['catname'] == 'yes') &&
131
- $this->lcp_category_id != 0):
132
  // Check for one id or several:
133
  $ids = null;
134
- if (is_array($this->lcp_category_id)){
135
- $ids = $this->lcp_category_id;
136
- } else{
137
- $ids = explode(",", $this->lcp_category_id);
138
- }
139
-
140
- $link = array();
141
- // Loop on several categories:
142
- foreach($ids as $lcp_id){
143
- $cat_link = get_category_link($lcp_id);
144
- $cat_title = get_cat_name($lcp_id);
145
-
146
- // Use the category title or 'catlink_string' set by user:
147
- if ($this->utils->lcp_not_empty('catlink_string')){
148
- $cat_string = $this->params['catlink_string'];
149
- } else {
150
- $cat_string = $cat_title;
151
  }
152
 
153
- // Do we want the link or just the title?
154
- if ($this->params['catlink'] == 'yes'){
155
- $cat_string = '<a href="' . $cat_link . '" title="' . $cat_title . '">' .
156
- $cat_string .
157
- $this->get_category_count($lcp_id) . '</a>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
- array_push($link, $cat_string);
160
- }
161
- return implode(", ", $link);
162
- else:
163
  return null;
164
- endif;
165
  }
166
 
167
  /**
@@ -339,23 +342,23 @@ class CatList{
339
  }
340
 
341
  private function lcp_trim_excerpt($text = ''){
342
- $excerpt_length = intval($this->params['excerpt_size']);
343
 
344
  $text = strip_shortcodes($text);
345
  $text = apply_filters('the_excerpt', $text);
346
  $text = str_replace(']]>',']]&gt;', $text);
347
 
348
  if( $this->utils->lcp_not_empty('excerpt_strip') &&
349
- $this->params['excerpt_strip'] == 'yes'):
350
  $text = strip_tags($text);
351
- endif;
352
 
353
  $words = explode(' ', $text, $excerpt_length + 1);
354
- if(count($words) > $excerpt_length) :
355
  array_pop($words);
356
- array_push($words, '...');
357
- $text = implode(' ', $words);
358
- endif;
359
  return $text;
360
  }
361
 
57
  $this->lcp_categories_posts = $query->query($args);
58
  $this->posts_count = $query->found_posts;
59
  remove_all_filters('posts_orderby');
60
+ remove_filter('posts_where', array( $this, 'starting_with'));
61
  }
62
 
63
  /* Should I return posts or show that the tag/category or whatever
71
 
72
  private function check_pagination($args){
73
  if ( $this->utils->lcp_not_empty('pagination') ){
74
+ if( null !== filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_STRING) ){
75
+ $query = filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_STRING);
76
+ }
77
+
78
+ if ($query !== '' && preg_match('/lcp_page' . preg_quote($this->instance) .
79
+ '=([0-9]+)/i', $query, $match) ) {
80
  $this->page = $match[1];
81
  $offset = ($this->page - 1) * $this->params['numberposts'];
82
  $args = array_merge($args, array('offset' => $offset));
100
  private function get_lcp_category(){
101
  // In a category page:
102
  if ( $this->utils->lcp_not_empty('categorypage') &&
103
+ $this->params['categorypage'] == 'yes' ||
104
+ $this->params['id'] == -1){
105
  // Use current category
106
  $this->lcp_category_id = LcpCategory::get_instance()->current_category();
107
  } elseif ( $this->utils->lcp_not_empty('name') ){
108
  // Using the category name:
109
  $this->lcp_category_id = LcpCategory::get_instance()->with_name( $this->params['name'] );
110
+ $this->params['name'] = null;
111
  } elseif ( isset($this->params['id']) && $this->params['id'] != '0' ){
112
  // Using the id:
113
  $this->lcp_category_id = LcpCategory::get_instance()->with_id( $this->params['id'] );
128
  */
129
  public function get_category_link(){
130
  if(($this->utils->lcp_not_empty('catlink') &&
131
+ $this->params['catlink'] == 'yes' ||
132
+ $this->utils->lcp_not_empty('catname') &&
133
+ $this->params['catname'] == 'yes') &&
134
+ $this->lcp_category_id != 0){
135
  // Check for one id or several:
136
  $ids = null;
137
+ if (is_array($this->lcp_category_id)){
138
+ $ids = $this->lcp_category_id;
139
+ } else{
140
+ $ids = explode(",", $this->lcp_category_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
+ $link = array();
144
+ // Loop on several categories:
145
+ foreach($ids as $lcp_id){
146
+ $cat_link = get_category_link($lcp_id);
147
+ $cat_title = get_cat_name($lcp_id);
148
+
149
+ // Use the category title or 'catlink_string' set by user:
150
+ if ($this->utils->lcp_not_empty('catlink_string')){
151
+ $cat_string = $this->params['catlink_string'];
152
+ } else {
153
+ $cat_string = $cat_title;
154
+ }
155
+
156
+ // Do we want the link or just the title?
157
+ if ($this->params['catlink'] == 'yes'){
158
+ $cat_string = '<a href="' . $cat_link . '" title="' . $cat_title . '">' .
159
+ $cat_string .
160
+ $this->get_category_count($lcp_id) . '</a>';
161
+ }
162
+ array_push($link, $cat_string);
163
  }
164
+ return implode(", ", $link);
165
+ } else {
 
 
166
  return null;
167
+ }
168
  }
169
 
170
  /**
342
  }
343
 
344
  private function lcp_trim_excerpt($text = ''){
345
+ $excerpt_length = intval( $this->params['excerpt_size'] );
346
 
347
  $text = strip_shortcodes($text);
348
  $text = apply_filters('the_excerpt', $text);
349
  $text = str_replace(']]>',']]&gt;', $text);
350
 
351
  if( $this->utils->lcp_not_empty('excerpt_strip') &&
352
+ $this->params['excerpt_strip'] == 'yes' ){
353
  $text = strip_tags($text);
354
+ }
355
 
356
  $words = explode(' ', $text, $excerpt_length + 1);
357
+ if(count($words) > $excerpt_length){
358
  array_pop($words);
359
+ array_push($words, '...');
360
+ $text = implode(' ', $words);
361
+ }
362
  return $text;
363
  }
364
 
include/lcp-catlistdisplayer.php CHANGED
@@ -186,18 +186,22 @@ class CatListDisplayer {
186
  if ($page == $current_page){
187
  $link = "<li>$current_page</li>";
188
  } else {
189
- $amp = ( strpos($_SERVER["REQUEST_URI"], "?") ) ? "&" : "";
 
 
190
  $pattern = "/[&|?]?lcp_page" . preg_quote($this->catlist->get_instance()) . "=([0-9]+)/";
191
- $query = preg_replace($pattern, '', $_SERVER['QUERY_STRING']);
192
 
193
- $url = strtok($_SERVER["REQUEST_URI"],'?');
194
  $protocol = "http";
195
- if ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
196
- $_SERVER['SERVER_PORT'] == 443){
 
 
197
  $protocol = "https";
198
  }
199
-
200
- $page_link = "$protocol://$_SERVER[HTTP_HOST]$url?$query" .
201
  $amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
202
  "#lcp_instance_" . $this->catlist->get_instance();
203
  $link .= "<li><a href='$page_link' title='$page'>";
@@ -206,6 +210,8 @@ class CatListDisplayer {
206
 
207
  $link .= "</a></li>";
208
  }
 
 
209
  return $link;
210
  }
211
 
@@ -231,17 +237,7 @@ class CatListDisplayer {
231
  endif;
232
 
233
  // Comments count
234
- if (!empty($this->params['comments_tag'])):
235
- if (!empty($this->params['comments_class'])):
236
- $lcp_display_output .= $this->get_comments($single,
237
- $this->params['comments_tag'],
238
- $this->params['comments_class']);
239
- else:
240
- $lcp_display_output .= $this->get_comments($single, $this->params['comments_tag']);
241
- endif;
242
- else:
243
- $lcp_display_output .= $this->get_comments($single);
244
- endif;
245
 
246
  // Date
247
  if (!empty($this->params['date_tag']) || !empty($this->params['date_class'])):
@@ -262,17 +258,7 @@ class CatListDisplayer {
262
  endif;
263
 
264
  // Author
265
- if (!empty($this->params['author_tag'])):
266
- if (!empty($this->params['author_class'])):
267
- $lcp_display_output .= $this->get_author($single,
268
- $this->params['author_tag'],
269
- $this->params['author_class']);
270
- else:
271
- $lcp_display_output .= $this->get_author($single, $this->params['author_tag']);
272
- endif;
273
- else:
274
- $lcp_display_output .= $this->get_author($single);
275
- endif;
276
 
277
  // Display ID
278
  if (!empty($this->params['display_id']) && $this->params['display_id'] == 'yes'){
@@ -284,17 +270,7 @@ class CatListDisplayer {
284
 
285
  $lcp_display_output .= $this->get_thumbnail($single);
286
 
287
- if (!empty($this->params['content_tag'])):
288
- if (!empty($this->params['content_class'])):
289
- $lcp_display_output .= $this->get_content($single,
290
- $this->params['content_tag'],
291
- $this->params['content_class']);
292
- else:
293
- $lcp_display_output .= $this->get_content($single, $this->params['content_tag']);
294
- endif;
295
- else:
296
- $lcp_display_output .= $this->get_content($single);
297
- endif;
298
 
299
  if (!empty($this->params['excerpt_tag'])):
300
  if (!empty($this->params['excerpt_class'])):
@@ -314,6 +290,21 @@ class CatListDisplayer {
314
  return $lcp_display_output;
315
  }
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  private function category_title(){
318
  // More link
319
  if (!empty($this->params['catlink_tag'])):
@@ -405,7 +396,13 @@ class CatListDisplayer {
405
  return $this->assign_style($info, $tag);
406
  }
407
 
408
- private function get_post_title($single, $tag = null, $css_class = null){
 
 
 
 
 
 
409
  $info = '<a href="' . get_permalink($single->ID);
410
 
411
  $lcp_post_title = apply_filters('the_title', $single->post_title, $single->ID);
186
  if ($page == $current_page){
187
  $link = "<li>$current_page</li>";
188
  } else {
189
+ $request_uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING);
190
+ $query = filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_STRING);
191
+ $amp = ( strpos( $request_uri, "?") ) ? "&" : "";
192
  $pattern = "/[&|?]?lcp_page" . preg_quote($this->catlist->get_instance()) . "=([0-9]+)/";
193
+ $query = preg_replace($pattern, '', $query);
194
 
195
+ $url = strtok($request_uri,'?');
196
  $protocol = "http";
197
+ $port = filter_input(INPUT_SERVER, 'SERVER_PORT', FILTER_SANITIZE_STRING);
198
+ $https = filter_input(INPUT_SERVER, 'HTTPS', FILTER_SANITIZE_STRING);
199
+ if ( (!empty($https) && $https !== 'off') ||
200
+ $port == 443){
201
  $protocol = "https";
202
  }
203
+ $http_host = filter_input(INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_STRING);
204
+ $page_link = "$protocol://$http_host$url?$query" .
205
  $amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
206
  "#lcp_instance_" . $this->catlist->get_instance();
207
  $link .= "<li><a href='$page_link' title='$page'>";
210
 
211
  $link .= "</a></li>";
212
  }
213
+ // WA: Replace '?&' by '?' to avoid potential redirection problems later on
214
+ $link = str_replace('?&', '?', $link );
215
  return $link;
216
  }
217
 
237
  endif;
238
 
239
  // Comments count
240
+ $lcp_display_output .= $this->get_stuff_with_tags_and_classes('comments', $single);
 
 
 
 
 
 
 
 
 
 
241
 
242
  // Date
243
  if (!empty($this->params['date_tag']) || !empty($this->params['date_class'])):
258
  endif;
259
 
260
  // Author
261
+ $lcp_display_output .= $this->get_stuff_with_tags_and_classes('author', $single);
 
 
 
 
 
 
 
 
 
 
262
 
263
  // Display ID
264
  if (!empty($this->params['display_id']) && $this->params['display_id'] == 'yes'){
270
 
271
  $lcp_display_output .= $this->get_thumbnail($single);
272
 
273
+ $lcp_display_output .= $this->get_stuff_with_tags_and_classes('content', $single);
 
 
 
 
 
 
 
 
 
 
274
 
275
  if (!empty($this->params['excerpt_tag'])):
276
  if (!empty($this->params['excerpt_class'])):
290
  return $lcp_display_output;
291
  }
292
 
293
+ private function get_stuff_with_tags_and_classes($entity, $single){
294
+ $result = '';
295
+ $stuffFunction = 'get_' . $entity;
296
+ if (!empty($this->params[$entity . '_tag'])):
297
+ if (!empty($this->params[$entity . '_class'])):
298
+ $result = $this->stuffFunction($single, $this->params[$entity . '_tag'], $this->params[$entity . '_class']);
299
+ else:
300
+ $result = $this->$stuffFunction($single, $this->params[$entity . '_tag']);
301
+ endif;
302
+ else:
303
+ $result = $this->$stuffFunction($single);
304
+ endif;
305
+ return $result;
306
+ }
307
+
308
  private function category_title(){
309
  // More link
310
  if (!empty($this->params['catlink_tag'])):
396
  return $this->assign_style($info, $tag);
397
  }
398
 
399
+ // Link is a parameter here in case you want to use it on a template
400
+ // and not show the links for all the shortcodes using this template:
401
+ private function get_post_title($single, $tag = null, $css_class = null, $link = true){
402
+ if ( !$link || !empty($this->params['link_titles']) && $this->params['link_titles'] === "false" ) {
403
+ return $single->post_title;
404
+ }
405
+
406
  $info = '<a href="' . get_permalink($single->ID);
407
 
408
  $lcp_post_title = apply_filters('the_title', $single->post_title, $single->ID);
list_cat_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.57
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
@@ -119,7 +119,8 @@ class ListCategoryPosts{
119
  'pagination_prev' => '<<',
120
  'no_posts_text' => "",
121
  'instance' => '0',
122
- 'no_post_titles' => 'no'
 
123
  ), $atts);
124
  if( $atts['numberposts'] == ''){
125
  $atts['numberposts'] = get_option('numberposts');
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.58
7
  Author: Fernando Briano
8
  Author URI: http://fernandobriano.com
9
 
119
  'pagination_prev' => '<<',
120
  'no_posts_text' => "",
121
  'instance' => '0',
122
+ 'no_post_titles' => 'no',
123
+ 'link_titles' => true
124
  ), $atts);
125
  if( $atts['numberposts'] == ''){
126
  $atts['numberposts'] = get_option('numberposts');
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://picandocodigo.net/programacion/wordpress/list-category-posts
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.1.1
7
- Stable tag: 0.57
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -330,6 +330,8 @@ Will print the value of the Custom Field "Mood" but not the text
330
 
331
  * **no_post_titles** - If set to `yes`, no post titles will be shown. This may make sense together with `content=yes`.
332
 
 
 
333
  == Widget ==
334
 
335
  The widget is quite simple, and it doesn't implement all of the plugin's functionality. To use a shortcode in a widget add this code to your theme's functions.php file:
@@ -355,7 +357,7 @@ which will wrap the element with a `span` tag.
355
  The customizable elements (so far) are: author, catlink (category link), comments, date, excerpt, morelink ("Read More" link), thumbnail and title (post title).
356
 
357
  The parameters are:
358
- `autor_tag, author_class, catlink_tag, catlink_class, comments_tag,
359
  comments_class, date_tag, date_class, date_modified_tag,
360
  date_modified_class, excerpt_tag, excerpt_class, morelink_class,
361
  thumbnail_class, title_tag, title_class, posts_morelink_class,
@@ -443,6 +445,14 @@ Template system has changed. Custom templates should be stored in WordPress them
443
 
444
  == Changelog ==
445
 
 
 
 
 
 
 
 
 
446
  = 0.57 =
447
  * Add custom image sizes to the list of selectable image sizes in the widget. Thanks [nuss](https://github.com/nuss) for the Pull Request!
448
  * New Attribute 'no_post_titles'. Thanks [thomasWeise](https://github.com/thomasWeise) for the Pull Request!
4
  Tags: list, categories, posts, cms
5
  Requires at least: 3.3
6
  Tested up to: 4.1.1
7
+ Stable tag: 0.58
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
330
 
331
  * **no_post_titles** - If set to `yes`, no post titles will be shown. This may make sense together with `content=yes`.
332
 
333
+ * **link_titles** - Option to display titles without links. If set to `false`, the post titles won't be linking to the article.
334
+
335
  == Widget ==
336
 
337
  The widget is quite simple, and it doesn't implement all of the plugin's functionality. To use a shortcode in a widget add this code to your theme's functions.php file:
357
  The customizable elements (so far) are: author, catlink (category link), comments, date, excerpt, morelink ("Read More" link), thumbnail and title (post title).
358
 
359
  The parameters are:
360
+ `author_tag, author_class, catlink_tag, catlink_class, comments_tag,
361
  comments_class, date_tag, date_class, date_modified_tag,
362
  date_modified_class, excerpt_tag, excerpt_class, morelink_class,
363
  thumbnail_class, title_tag, title_class, posts_morelink_class,
445
 
446
  == Changelog ==
447
 
448
+ = 0.58 =
449
+ * Removes filter interfering with filters set by other plugins. Thanks [zulkamal](https://github.com/zulkamal) for the Pull Request!
450
+ * Adds option to display titles without links. Thanks zulkamal for this Pull Request too! :D
451
+ * Workaround to prevent '?&' to appear in URLs. Thanks [mhoeher](https://github.com/mhoeher) for the Pull Request!
452
+ * General refactors for improving code quality/security.
453
+ * Fixed typo in Readme (Thanks Irma!).
454
+ * Fixes excluding tags when using category name (should fix other issues with category name too since there was a bug there).
455
+
456
  = 0.57 =
457
  * Add custom image sizes to the list of selectable image sizes in the widget. Thanks [nuss](https://github.com/nuss) for the Pull Request!
458
  * New Attribute 'no_post_titles'. Thanks [thomasWeise](https://github.com/thomasWeise) for the Pull Request!