Version Description
- Adds http/https check for pagination links.
- Fixes
post_status
andpost_type
parameters for using multiple post statuses and types. - Big refactor: Thumbnail code, parameters moved to new class, created util class, removed bad and repeated code, moved category code to new class. Small fixes all around the place. Went from a very bad 1.77 GPA to 3.23 on CodeClimate.
- Fixes
Download this release
Release Info
Developer | fernandobt |
Plugin | List category posts |
Version | 0.54 |
Comparing to | |
See all releases |
Code changes from version 0.53 to 0.54
- include/lcp-category.php +89 -0
- include/lcp-catlist.php +148 -407
- include/lcp-catlistdisplayer.php +52 -61
- include/lcp-parameters.php +173 -0
- include/lcp-post-builder.php +126 -0
- include/lcp-thumbnail.php +88 -0
- include/lcp-utils.php +19 -0
- include/lcp-widget.php +1 -2
- list_cat_posts.php +1 -1
- readme.txt +27 -9
- templates/default.php +12 -3
include/lcp-category.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* This Singleton class has the code for defining which category to
|
4 |
+
* use according to the shortcode.
|
5 |
+
* @author fernando@picandocodigo.net
|
6 |
+
*/
|
7 |
+
class LcpCategory{
|
8 |
+
// Singleton implementation
|
9 |
+
private static $instance = null;
|
10 |
+
|
11 |
+
public static function get_instance(){
|
12 |
+
if( !isset( self::$instance ) ){
|
13 |
+
self::$instance = new self;
|
14 |
+
}
|
15 |
+
return self::$instance;
|
16 |
+
}
|
17 |
+
|
18 |
+
/*
|
19 |
+
* When the category is set using the `name` parameter.
|
20 |
+
*/
|
21 |
+
public function with_name($name){
|
22 |
+
$lcp_category_id = null;
|
23 |
+
// AND relationship
|
24 |
+
if ( preg_match('/\+/', $name) ){
|
25 |
+
$categories = array();
|
26 |
+
$cat_array = explode("+", $name);
|
27 |
+
|
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 )){
|
35 |
+
$categories = '';
|
36 |
+
$cat_array = explode(",", $name);
|
37 |
+
|
38 |
+
foreach ($cat_array as $category){
|
39 |
+
$id = $this->get_category_id_by_name($category);
|
40 |
+
$categories .= $id . ",";
|
41 |
+
}
|
42 |
+
|
43 |
+
$lcp_category_id = $categories;
|
44 |
+
} else {
|
45 |
+
$lcp_category_id = $this->get_category_id_by_name($name);
|
46 |
+
}
|
47 |
+
return $lcp_category_id;
|
48 |
+
}
|
49 |
+
|
50 |
+
public function with_id($id){
|
51 |
+
if (preg_match('/\+/', $id)){
|
52 |
+
if ( preg_match('/(-[0-9]+)+/', $id, $matches) ){
|
53 |
+
$this->exclude = implode(',', explode("-", ltrim($matches[0], '-') ));
|
54 |
+
}
|
55 |
+
$lcp_category_id = array_map( 'intval', explode( "+", $id ) );
|
56 |
+
} else {
|
57 |
+
$lcp_category_id = $id;
|
58 |
+
}
|
59 |
+
return $lcp_category_id;
|
60 |
+
}
|
61 |
+
|
62 |
+
public function current_category(){
|
63 |
+
$category = get_category( get_query_var( 'category' ) );
|
64 |
+
if(
|
65 |
+
isset( $category->errors ) &&
|
66 |
+
$category->errors["invalid_term"][0] == __("Empty Term")
|
67 |
+
){
|
68 |
+
global $post;
|
69 |
+
$categories = get_the_category($post->ID);
|
70 |
+
return $categories[0]->cat_ID;
|
71 |
+
}
|
72 |
+
return $category->cat_ID;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Get the category id from its name
|
77 |
+
* by Eric Celeste / http://eric.clst.org
|
78 |
+
*/
|
79 |
+
private function get_category_id_by_name($cat_name){
|
80 |
+
//TODO: Support multiple names (this used to work, but not anymore)
|
81 |
+
//We check if the name gets the category id, if not, we check the slug.
|
82 |
+
$term = get_term_by('slug', $cat_name, 'category');
|
83 |
+
if (!$term){
|
84 |
+
$term = get_term_by('name', $cat_name, 'category');
|
85 |
+
}
|
86 |
+
return ($term) ? $term->term_id : 0;
|
87 |
+
}
|
88 |
+
|
89 |
+
}
|
include/lcp-catlist.php
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
class CatList{
|
8 |
private $params = array();
|
9 |
private $lcp_category_id = 0;
|
@@ -11,20 +17,22 @@ class CatList{
|
|
11 |
private $page = 1;
|
12 |
private $posts_count = 0;
|
13 |
private $instance = 0;
|
|
|
14 |
|
15 |
/**
|
16 |
* Constructor gets the shortcode attributes as parameter
|
17 |
* @param array $atts
|
18 |
*/
|
19 |
public function __construct($atts) {
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
$this->params = $atts;
|
|
|
26 |
|
27 |
-
if ($this->lcp_not_empty('instance')){
|
28 |
$this->instance = $atts['instance'];
|
29 |
}
|
30 |
//Get the category posts:
|
@@ -37,106 +45,9 @@ class CatList{
|
|
37 |
*/
|
38 |
private function set_lcp_parameters(){
|
39 |
$args = $this->lcp_categories();
|
40 |
-
$
|
41 |
-
|
42 |
-
|
43 |
-
'order' => $this->params['order'],
|
44 |
-
'offset' => $this->params['offset']
|
45 |
-
));
|
46 |
-
|
47 |
-
// Check posts to exclude
|
48 |
-
$args = $this->lcp_check_excludes($args);
|
49 |
-
|
50 |
-
// Check type, status, parent params
|
51 |
-
$args = $this->lcp_types_and_statuses($args);
|
52 |
-
|
53 |
-
if($this->lcp_not_empty('year')):
|
54 |
-
$args['year'] = $this->params['year'];
|
55 |
-
endif;
|
56 |
-
|
57 |
-
if($this->lcp_not_empty('monthnum')):
|
58 |
-
$args['monthnum'] = $this->params['monthnum'];
|
59 |
-
endif;
|
60 |
-
|
61 |
-
if($this->lcp_not_empty('search')):
|
62 |
-
$args['s'] = $this->params['search'];
|
63 |
-
endif;
|
64 |
-
|
65 |
-
if($this->lcp_not_empty('author_posts')):
|
66 |
-
$args['author_name'] = $this->params['author_posts'];
|
67 |
-
endif;
|
68 |
-
|
69 |
-
/*
|
70 |
-
* Custom fields 'customfield_name' & 'customfield_value'
|
71 |
-
* should both be defined
|
72 |
-
*/
|
73 |
-
if( $this->lcp_not_empty('customfield_value') ):
|
74 |
-
$args['meta_key'] = $this->params['customfield_name'];
|
75 |
-
$args['meta_value'] = $this->params['customfield_value'];
|
76 |
-
endif;
|
77 |
-
|
78 |
-
//Get private posts
|
79 |
-
if(is_user_logged_in()):
|
80 |
-
if ( !empty($args['post_status']) ):
|
81 |
-
$args['post_status'] = array_merge($args['post_status'], array('private'));
|
82 |
-
else:
|
83 |
-
$args['post_status'] = array('private', 'publish');
|
84 |
-
endif;
|
85 |
-
endif;
|
86 |
-
|
87 |
-
if ( $this->lcp_not_empty('exclude_tags') ):
|
88 |
-
$excluded_tags = explode(",", $this->params['exclude_tags']);
|
89 |
-
$tag_ids = array();
|
90 |
-
foreach ( $excluded_tags as $excluded):
|
91 |
-
$tag_ids[] = get_term_by('slug', $excluded, 'post_tag')->term_id;
|
92 |
-
endforeach;
|
93 |
-
$args['tag__not_in'] = $tag_ids;
|
94 |
-
endif;
|
95 |
-
|
96 |
-
// Current tags
|
97 |
-
if ( $this->lcp_not_empty('currenttags') && $this->params['currenttags'] == "yes" ):
|
98 |
-
$tags = $this->lcp_get_current_tags();
|
99 |
-
if ( !empty($tags) ):
|
100 |
-
$args['tag__in'] = $tags;
|
101 |
-
endif;
|
102 |
-
endif;
|
103 |
-
|
104 |
-
// Added custom taxonomy support
|
105 |
-
if ( $this->lcp_not_empty('taxonomy') && $this->lcp_not_empty('tags') ):
|
106 |
-
$args['tax_query'] = array(array(
|
107 |
-
'taxonomy' => $this->params['taxonomy'],
|
108 |
-
'field' => 'slug',
|
109 |
-
'terms' => explode(",",$this->params['tags'])
|
110 |
-
));
|
111 |
-
elseif ( !empty($this->params['tags']) ):
|
112 |
-
$args['tag'] = $this->params['tags'];
|
113 |
-
endif;
|
114 |
-
|
115 |
-
if ( !empty($this->params['exclude'])):
|
116 |
-
$args['category__not_in'] = array($this->params['exclude']);
|
117 |
-
endif;
|
118 |
-
|
119 |
-
if ( $this->lcp_not_empty('customfield_orderby') ):
|
120 |
-
$args['orderby'] = 'meta_value';
|
121 |
-
$args['meta_key'] = $this->params['customfield_orderby'];
|
122 |
-
endif;
|
123 |
-
|
124 |
-
if ( $this->lcp_not_empty('pagination')):
|
125 |
-
if(isset($_SERVER['QUERY_STRING']) &&
|
126 |
-
!empty($_SERVER['QUERY_STRING']) ){
|
127 |
-
if( preg_match('/lcp_page' . preg_quote($this->instance) .
|
128 |
-
'=([0-9]+)/i', $_SERVER['QUERY_STRING'], $match) ):
|
129 |
-
$this->page = $match[1];
|
130 |
-
$offset = ($this->page - 1) * $this->params['numberposts'];
|
131 |
-
$args = array_merge($args, array('offset' => $offset));
|
132 |
-
endif;
|
133 |
-
}
|
134 |
-
endif;
|
135 |
-
|
136 |
-
// Posts that start with a given letter:
|
137 |
-
if ( $this->lcp_not_empty('starting_with') ){
|
138 |
-
add_filter('posts_where' , array( $this, 'starting_with') );
|
139 |
-
}
|
140 |
|
141 |
// for WP_Query compatibility
|
142 |
// http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
|
@@ -149,84 +60,39 @@ class CatList{
|
|
149 |
remove_all_filters('posts_where');
|
150 |
}
|
151 |
|
152 |
-
public function starting_with($where){
|
153 |
-
$letters = explode(',', $this->params['starting_with']);
|
154 |
-
$where .= 'AND (wp_posts.post_title ' .
|
155 |
-
'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[0] . "%'";
|
156 |
-
for ($i=1; $i <sizeof($letters); $i++) {
|
157 |
-
$where .= 'OR wp_posts.post_title ' .
|
158 |
-
'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
|
159 |
-
}
|
160 |
-
$where.=')';
|
161 |
-
return $where;
|
162 |
-
}
|
163 |
-
|
164 |
/* Should I return posts or show that the tag/category or whatever
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
|
171 |
/** HELPER FUNCTIONS **/
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
/**
|
174 |
* Check if there's one or more categories.
|
175 |
* Used in the beginning when setting up the parameters.
|
176 |
*/
|
177 |
private function lcp_categories(){
|
178 |
-
if (is_array($this->lcp_category_id))
|
179 |
return array('category__and' => $this->lcp_category_id);
|
180 |
-
else
|
181 |
return array('cat'=> $this->lcp_category_id);
|
182 |
-
endif;
|
183 |
-
}
|
184 |
-
|
185 |
-
// Check posts to exclude
|
186 |
-
private function lcp_check_excludes($args){
|
187 |
-
if( $this->lcp_not_empty('excludeposts') ){
|
188 |
-
$exclude = array(
|
189 |
-
'post__not_in' => explode(",", $this->params['excludeposts'])
|
190 |
-
);
|
191 |
-
if (strpos($this->params['excludeposts'], 'this') > -1){
|
192 |
-
$exclude = array_merge(
|
193 |
-
$exclude,
|
194 |
-
array('post__not_in' => array($this->lcp_get_current_post_id() ) )
|
195 |
-
);
|
196 |
-
}
|
197 |
-
$args = array_merge($args, $exclude);
|
198 |
}
|
199 |
-
return $args;
|
200 |
-
}
|
201 |
-
|
202 |
-
private function lcp_types_and_statuses($args){
|
203 |
-
// Post type, status, parent params:
|
204 |
-
if($this->lcp_not_empty('post_type')):
|
205 |
-
$args['post_type'] = $this->params['post_type'];
|
206 |
-
endif;
|
207 |
-
|
208 |
-
if($this->lcp_not_empty('post_status')):
|
209 |
-
$args['post_status'] = array(
|
210 |
-
$this->params['post_status']
|
211 |
-
);
|
212 |
-
endif;
|
213 |
-
|
214 |
-
if($this->lcp_not_empty('post_parent')):
|
215 |
-
$args['post_parent'] = $this->params['post_parent'];
|
216 |
-
endif;
|
217 |
-
return $args;
|
218 |
-
}
|
219 |
-
|
220 |
-
/**
|
221 |
-
* Check for empty parameters (being empty strings or zero).
|
222 |
-
*/
|
223 |
-
private function lcp_not_empty($param){
|
224 |
-
return (
|
225 |
-
isset($this->params[$param]) &&
|
226 |
-
!empty($this->params[$param]) &&
|
227 |
-
$this->params[$param] !== '0' &&
|
228 |
-
$this->params[$param] !== ''
|
229 |
-
);
|
230 |
}
|
231 |
|
232 |
private function lcp_get_current_post_id(){
|
@@ -236,88 +102,23 @@ class CatList{
|
|
236 |
|
237 |
private function get_lcp_category(){
|
238 |
// In a category page:
|
239 |
-
if ( $this->lcp_not_empty('categorypage') &&
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
elseif ( $this->lcp_not_empty('name') )
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
$id = $this->get_category_id_by_name($category);
|
251 |
-
$categories[] = $id;
|
252 |
-
endforeach;
|
253 |
-
|
254 |
-
$this->lcp_category_id = $categories;
|
255 |
-
|
256 |
-
elseif (preg_match('/,/', $this->params['name'])):
|
257 |
-
$categories = '';
|
258 |
-
$cat_array = explode(",", $this->params['name']);
|
259 |
-
|
260 |
-
foreach ($cat_array as $category) :
|
261 |
-
$id = $this->get_category_id_by_name($category);
|
262 |
-
$categories .= $id . ",";
|
263 |
-
endforeach;
|
264 |
-
|
265 |
-
$this->lcp_category_id = $categories;
|
266 |
-
|
267 |
-
else:
|
268 |
-
$this->lcp_category_id = $this->get_category_id_by_name($this->params['name']);
|
269 |
-
endif;
|
270 |
-
// Using the id:
|
271 |
-
elseif ( isset($this->params['id']) && $this->params['id'] != '0' ):
|
272 |
-
if (preg_match('/\+/', $this->params['id'])):
|
273 |
-
if ( preg_match('/(-[0-9]+)+/', $this->params['id'], $matches) ):
|
274 |
-
$this->exclude = implode(',', explode("-", ltrim($matches[0], '-') ));
|
275 |
-
endif;
|
276 |
-
$this->lcp_category_id = array_map('intval', explode( "+", $this->params['id'] ) );
|
277 |
-
else:
|
278 |
-
$this->lcp_category_id = $this->params['id'];
|
279 |
-
endif;
|
280 |
-
endif;
|
281 |
-
}
|
282 |
-
|
283 |
-
public function lcp_get_current_category(){
|
284 |
-
$category = get_category( get_query_var( 'category' ) );
|
285 |
-
if(isset($category->errors) && $category->errors["invalid_term"][0] == __("Empty Term") ):
|
286 |
-
global $post;
|
287 |
-
$categories = get_the_category($post->ID);
|
288 |
-
return $categories[0]->cat_ID;
|
289 |
-
endif;
|
290 |
-
return $category->cat_ID;
|
291 |
-
}
|
292 |
-
|
293 |
-
public function lcp_get_current_tags(){
|
294 |
-
$tags = get_the_tags();
|
295 |
-
$tag_ids = array();
|
296 |
-
if( !empty($tags) ){
|
297 |
-
foreach ($tags as $tag_id => $tag) {
|
298 |
-
array_push($tag_ids, $tag_id);
|
299 |
-
}
|
300 |
}
|
301 |
-
return $tag_ids;
|
302 |
-
}
|
303 |
-
|
304 |
-
/**
|
305 |
-
* Get the category id from its name
|
306 |
-
* by Eric Celeste / http://eric.clst.org
|
307 |
-
*/
|
308 |
-
private function get_category_id_by_name($cat_name){
|
309 |
-
//TODO: Support multiple names (this used to work, but not anymore)
|
310 |
-
//We check if the name gets the category id, if not, we check the slug.
|
311 |
-
$term = get_term_by('slug', $cat_name, 'category');
|
312 |
-
if (!$term):
|
313 |
-
$term = get_term_by('name', $cat_name, 'category');
|
314 |
-
endif;
|
315 |
|
316 |
-
return ($term) ? $term->term_id : 0;
|
317 |
}
|
318 |
|
319 |
public function get_category_id(){
|
320 |
-
|
321 |
}
|
322 |
|
323 |
public function get_categories_posts(){
|
@@ -328,41 +129,41 @@ class CatList{
|
|
328 |
* Load category name and link to the category:
|
329 |
*/
|
330 |
public function get_category_link(){
|
331 |
-
if(($this->lcp_not_empty('catlink') &&
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
// Check for one id or several:
|
337 |
$ids = null;
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
}
|
363 |
-
array_push($link, $cat_string);
|
364 |
}
|
365 |
-
|
|
|
|
|
366 |
else:
|
367 |
return null;
|
368 |
endif;
|
@@ -374,8 +175,8 @@ class CatList{
|
|
374 |
public function get_morelink(){
|
375 |
if (!empty($this->params['morelink'])) :
|
376 |
$href = 'href="' . get_category_link($this->lcp_category_id) . '"';
|
377 |
-
|
378 |
-
|
379 |
else:
|
380 |
return null;
|
381 |
endif;
|
@@ -384,7 +185,7 @@ class CatList{
|
|
384 |
|
385 |
|
386 |
public function get_category_count($id){
|
387 |
-
if($this->lcp_not_empty('category_count') && $this->params['category_count'] == 'yes'):
|
388 |
return ' (' . get_category($id)->category_count . ')';
|
389 |
endif;
|
390 |
}
|
@@ -396,35 +197,35 @@ class CatList{
|
|
396 |
* @param int $post_id
|
397 |
*/
|
398 |
public function get_custom_fields($custom_key, $post_id){
|
399 |
-
if( $this->lcp_not_empty('customfield_display') &&
|
400 |
-
|
401 |
$lcp_customs = '';
|
402 |
|
403 |
-
|
404 |
-
|
405 |
|
406 |
-
|
407 |
-
|
408 |
|
409 |
-
|
410 |
-
|
411 |
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
|
427 |
-
|
428 |
else:
|
429 |
return null;
|
430 |
endif;
|
@@ -432,7 +233,7 @@ class CatList{
|
|
432 |
|
433 |
public function get_comments_count($single){
|
434 |
if (isset($this->params['comments']) &&
|
435 |
-
|
436 |
return ' (' . $single->comment_count . ')';
|
437 |
else:
|
438 |
return null;
|
@@ -442,15 +243,15 @@ class CatList{
|
|
442 |
public function get_author_to_show($single){
|
443 |
if ($this->params['author'] == 'yes'):
|
444 |
$lcp_userdata = get_userdata($single->post_author);
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
else:
|
455 |
return null;
|
456 |
endif;
|
@@ -493,26 +294,26 @@ class CatList{
|
|
493 |
|
494 |
public function get_content($single){
|
495 |
if (isset($this->params['content']) &&
|
496 |
-
|
497 |
-
|
498 |
|
499 |
$lcp_content = $single->post_content;
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
else:
|
517 |
return null;
|
518 |
endif;
|
@@ -526,7 +327,7 @@ class CatList{
|
|
526 |
$lcp_excerpt = $this->lcp_trim_excerpt($single->post_content);
|
527 |
}else{
|
528 |
if(!empty($this->params['excerpt_overwrite']) &&
|
529 |
-
|
530 |
// Excerpt but we want to overwrite it:";
|
531 |
$lcp_excerpt = $this->lcp_trim_excerpt($single->post_content);
|
532 |
} else {
|
@@ -549,86 +350,26 @@ class CatList{
|
|
549 |
$text = apply_filters('the_excerpt', $text);
|
550 |
$text = str_replace(']]>',']]>', $text);
|
551 |
|
552 |
-
if( $this->lcp_not_empty('excerpt_strip') &&
|
553 |
-
|
554 |
$text = strip_tags($text);
|
555 |
endif;
|
556 |
|
557 |
$words = explode(' ', $text, $excerpt_length + 1);
|
558 |
if(count($words) > $excerpt_length) :
|
559 |
array_pop($words);
|
560 |
-
|
561 |
-
|
562 |
endif;
|
563 |
return $text;
|
564 |
}
|
565 |
|
566 |
-
/**
|
567 |
-
* Get the post Thumbnail
|
568 |
-
* @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
|
569 |
-
* @param unknown_type $single
|
570 |
-
*
|
571 |
-
*/
|
572 |
public function get_thumbnail($single, $lcp_thumb_class = null){
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
$
|
577 |
-
|
578 |
-
|
579 |
-
$available_image_sizes = array_unique(
|
580 |
-
array_merge(
|
581 |
-
get_intermediate_image_sizes(),
|
582 |
-
array("thumbnail", "medium", "large", "full")
|
583 |
-
)
|
584 |
-
);
|
585 |
-
if ( in_array(
|
586 |
-
$this->params['thumbnail_size'],
|
587 |
-
$available_image_sizes
|
588 |
-
)
|
589 |
-
):
|
590 |
-
$lcp_thumb_size = $this->params['thumbnail_size'];
|
591 |
-
elseif ($this->params['thumbnail_size']):
|
592 |
-
$lcp_thumb_size = explode(",", $this->params['thumbnail_size']);
|
593 |
-
else:
|
594 |
-
$lcp_thumb_size = 'thumbnail';
|
595 |
-
endif;
|
596 |
-
|
597 |
-
$lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
|
598 |
-
'" title="' . esc_attr($single->post_title) . '">';
|
599 |
-
|
600 |
-
$lcp_thumbnail .= get_the_post_thumbnail(
|
601 |
-
$single->ID,
|
602 |
-
$lcp_thumb_size,
|
603 |
-
($lcp_thumb_class != null) ? array('class' => $lcp_thumb_class ) : null
|
604 |
-
);
|
605 |
-
$lcp_thumbnail .= '</a>';
|
606 |
-
|
607 |
-
# Check for a YouTube video thumbnail
|
608 |
-
elseif (
|
609 |
-
preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $single->post_content, $matches)
|
610 |
-
||
|
611 |
-
preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/", $single->post_content, $matches)
|
612 |
-
||
|
613 |
-
preg_match("/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(embed)\/([a-zA-Z0-9\-\_]{11})[^<\s]*/", $single->post_content, $matches)
|
614 |
-
):
|
615 |
-
$youtubeurl = $matches[0];
|
616 |
-
|
617 |
-
if ($youtubeurl):
|
618 |
-
$imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
|
619 |
-
endif;
|
620 |
-
|
621 |
-
$lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
|
622 |
-
|
623 |
-
if ($lcp_thumb_class != null):
|
624 |
-
$thmbn_class = ' class="' . $lcp_thumb_class . '" />';
|
625 |
-
$lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
|
626 |
-
endif;
|
627 |
-
|
628 |
-
$lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
|
629 |
-
|
630 |
-
endif;
|
631 |
-
endif;
|
632 |
-
return $lcp_thumbnail;
|
633 |
}
|
|
|
634 |
}
|
1 |
<?php
|
2 |
+
define( 'LCP_PATH', plugin_dir_path( __FILE__ ) );
|
3 |
+
require_once ( LCP_PATH . 'lcp-thumbnail.php' );
|
4 |
+
require_once ( LCP_PATH . 'lcp-parameters.php' );
|
5 |
+
require_once ( LCP_PATH . 'lcp-utils.php' );
|
6 |
+
require_once ( LCP_PATH . 'lcp-category.php' );
|
7 |
+
|
8 |
+
/**
|
9 |
+
* The CatList object gets the info for the CatListDisplayer to show.
|
10 |
+
* Each time you use the shortcode, you get an instance of this class.
|
11 |
+
* @author fernando@picandocodigo.net
|
12 |
+
*/
|
13 |
class CatList{
|
14 |
private $params = array();
|
15 |
private $lcp_category_id = 0;
|
17 |
private $page = 1;
|
18 |
private $posts_count = 0;
|
19 |
private $instance = 0;
|
20 |
+
private $utils;
|
21 |
|
22 |
/**
|
23 |
* Constructor gets the shortcode attributes as parameter
|
24 |
* @param array $atts
|
25 |
*/
|
26 |
public function __construct($atts) {
|
27 |
+
load_plugin_textdomain(
|
28 |
+
'list-category-posts',
|
29 |
+
false,
|
30 |
+
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
|
31 |
+
);
|
32 |
$this->params = $atts;
|
33 |
+
$this->utils = new LcpUtils($this->params);
|
34 |
|
35 |
+
if ( $this->utils->lcp_not_empty('instance') ){
|
36 |
$this->instance = $atts['instance'];
|
37 |
}
|
38 |
//Get the category posts:
|
45 |
*/
|
46 |
private function set_lcp_parameters(){
|
47 |
$args = $this->lcp_categories();
|
48 |
+
$processed_params = LcpParameters::get_instance()->get_query_params($this->params);
|
49 |
+
$args = array_merge($args, $processed_params);
|
50 |
+
$args = $this->check_pagination($args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
// for WP_Query compatibility
|
53 |
// http://core.trac.wordpress.org/browser/tags/3.7.1/src/wp-includes/post.php#L1686
|
60 |
remove_all_filters('posts_where');
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
/* Should I return posts or show that the tag/category or whatever
|
64 |
+
posts combination that I called has no posts? By default I've
|
65 |
+
always returned the latest posts because that's what the query
|
66 |
+
does when the params are "wrong". But could make for a better user
|
67 |
+
experience if I returned an empty list in certain cases.
|
68 |
+
private function lcp_should_return_posts() */
|
69 |
|
70 |
/** HELPER FUNCTIONS **/
|
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));
|
81 |
+
}
|
82 |
+
}
|
83 |
+
return $args;
|
84 |
+
}
|
85 |
+
|
86 |
/**
|
87 |
* Check if there's one or more categories.
|
88 |
* Used in the beginning when setting up the parameters.
|
89 |
*/
|
90 |
private function lcp_categories(){
|
91 |
+
if ( is_array($this->lcp_category_id) ){
|
92 |
return array('category__and' => $this->lcp_category_id);
|
93 |
+
} else {
|
94 |
return array('cat'=> $this->lcp_category_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
}
|
97 |
|
98 |
private function lcp_get_current_post_id(){
|
102 |
|
103 |
private function get_lcp_category(){
|
104 |
// In a category page:
|
105 |
+
if ( $this->utils->lcp_not_empty('categorypage') &&
|
106 |
+
$this->params['categorypage'] == 'yes' ||
|
107 |
+
$this->params['id'] == -1){
|
108 |
+
// Use current category
|
109 |
+
$this->lcp_category_id = LcpCategory::get_instance()->current_category();
|
110 |
+
} elseif ( $this->utils->lcp_not_empty('name') ){
|
111 |
+
// Using the category name:
|
112 |
+
$this->lcp_category_id = LcpCategory::get_instance()->with_name( $this->params['name'] );
|
113 |
+
} elseif ( isset($this->params['id']) && $this->params['id'] != '0' ){
|
114 |
+
// Using the id:
|
115 |
+
$this->lcp_category_id = LcpCategory::get_instance()->with_id( $this->params['id'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
|
|
118 |
}
|
119 |
|
120 |
public function get_category_id(){
|
121 |
+
return $this->lcp_category_id;
|
122 |
}
|
123 |
|
124 |
public function get_categories_posts(){
|
129 |
* Load category name and link to the category:
|
130 |
*/
|
131 |
public function get_category_link(){
|
132 |
+
if(($this->utils->lcp_not_empty('catlink') &&
|
133 |
+
$this->params['catlink'] == 'yes' ||
|
134 |
+
$this->utils->lcp_not_empty('catname') &&
|
135 |
+
$this->params['catname'] == 'yes') &&
|
136 |
+
$this->lcp_category_id != 0):
|
137 |
// Check for one id or several:
|
138 |
$ids = null;
|
139 |
+
if (is_array($this->lcp_category_id)){
|
140 |
+
$ids = $this->lcp_category_id;
|
141 |
+
} else{
|
142 |
+
$ids = explode(",", $this->lcp_category_id);
|
143 |
+
}
|
144 |
|
145 |
+
$link = array();
|
146 |
+
// Loop on several categories:
|
147 |
+
foreach($ids as $lcp_id){
|
148 |
+
$cat_link = get_category_link($lcp_id);
|
149 |
+
$cat_title = get_cat_name($lcp_id);
|
150 |
|
151 |
+
// Use the category title or 'catlink_string' set by user:
|
152 |
+
if ($this->utils->lcp_not_empty('catlink_string')){
|
153 |
+
$cat_string = $this->params['catlink_string'];
|
154 |
+
} else {
|
155 |
+
$cat_string = $cat_title;
|
156 |
+
}
|
157 |
|
158 |
+
// Do we want the link or just the title?
|
159 |
+
if ($this->params['catlink'] == 'yes'){
|
160 |
+
$cat_string = '<a href="' . $cat_link . '" title="' . $cat_title . '">' .
|
161 |
+
$cat_string .
|
162 |
+
$this->get_category_count($lcp_id) . '</a>';
|
|
|
|
|
163 |
}
|
164 |
+
array_push($link, $cat_string);
|
165 |
+
}
|
166 |
+
return implode(", ", $link);
|
167 |
else:
|
168 |
return null;
|
169 |
endif;
|
175 |
public function get_morelink(){
|
176 |
if (!empty($this->params['morelink'])) :
|
177 |
$href = 'href="' . get_category_link($this->lcp_category_id) . '"';
|
178 |
+
$readmore = ($this->params['morelink'] !== '' ? $this->params['morelink'] : 'More posts');
|
179 |
+
return '<a ' . $href . ' >' . $readmore . '</a>';
|
180 |
else:
|
181 |
return null;
|
182 |
endif;
|
185 |
|
186 |
|
187 |
public function get_category_count($id){
|
188 |
+
if($this->utils->lcp_not_empty('category_count') && $this->params['category_count'] == 'yes'):
|
189 |
return ' (' . get_category($id)->category_count . ')';
|
190 |
endif;
|
191 |
}
|
197 |
* @param int $post_id
|
198 |
*/
|
199 |
public function get_custom_fields($custom_key, $post_id){
|
200 |
+
if( $this->utils->lcp_not_empty('customfield_display') &&
|
201 |
+
( $this->params['customfield_display'] != '') ):
|
202 |
$lcp_customs = '';
|
203 |
|
204 |
+
//Doesn't work for many custom fields when having spaces:
|
205 |
+
$custom_key = trim($custom_key);
|
206 |
|
207 |
+
//Create array for many fields:
|
208 |
+
$custom_array = explode(",", $custom_key);
|
209 |
|
210 |
+
//Get post custom fields:
|
211 |
+
$custom_fields = get_post_custom($post_id);
|
212 |
|
213 |
+
//Loop on custom fields and if there's a value, add it:
|
214 |
+
foreach ($custom_array as $user_customfield) :
|
215 |
+
if(isset($custom_fields[$user_customfield])):
|
216 |
+
$my_custom_field = $custom_fields[$user_customfield];
|
217 |
|
218 |
+
if (sizeof($my_custom_field) > 0 ):
|
219 |
+
foreach ( $my_custom_field as $key => $value ) :
|
220 |
+
if ($this->params['customfield_display_name'] != "no")
|
221 |
+
$lcp_customs .= $user_customfield . " : ";
|
222 |
+
$lcp_customs .= $value;
|
223 |
+
endforeach;
|
224 |
+
endif;
|
225 |
+
endif;
|
226 |
+
endforeach;
|
227 |
|
228 |
+
return $lcp_customs;
|
229 |
else:
|
230 |
return null;
|
231 |
endif;
|
233 |
|
234 |
public function get_comments_count($single){
|
235 |
if (isset($this->params['comments']) &&
|
236 |
+
$this->params['comments'] == 'yes'):
|
237 |
return ' (' . $single->comment_count . ')';
|
238 |
else:
|
239 |
return null;
|
243 |
public function get_author_to_show($single){
|
244 |
if ($this->params['author'] == 'yes'):
|
245 |
$lcp_userdata = get_userdata($single->post_author);
|
246 |
+
$author_name = $lcp_userdata->display_name;
|
247 |
+
if($this->utils->lcp_not_empty('author_posts_link') &&
|
248 |
+
$this->params['author_posts_link'] == 'yes'){
|
249 |
+
$link = get_author_posts_url($lcp_userdata->ID);
|
250 |
+
return "<a href=" . $link . " title='" . $author_name .
|
251 |
+
"'>" . $author_name . "</a>";
|
252 |
+
} else {
|
253 |
+
return $author_name;
|
254 |
+
}
|
255 |
else:
|
256 |
return null;
|
257 |
endif;
|
294 |
|
295 |
public function get_content($single){
|
296 |
if (isset($this->params['content']) &&
|
297 |
+
$this->params['content'] =='yes' &&
|
298 |
+
$single->post_content):
|
299 |
|
300 |
$lcp_content = $single->post_content;
|
301 |
+
$lcp_content = apply_filters('the_content', $lcp_content);
|
302 |
+
$lcp_content = str_replace(']]>', ']]>', $lcp_content);
|
303 |
+
|
304 |
+
if ( preg_match('/[\S\s]+(<!--more(.*?)?-->)[\S\s]+/', $lcp_content, $matches) ):
|
305 |
+
if( empty($this->params['posts_morelink']) ):
|
306 |
+
$lcp_more = __('Continue reading →', 'list-category-posts');
|
307 |
+
else:
|
308 |
+
$lcp_more = '';
|
309 |
+
endif;
|
310 |
+
$lcp_post_content = explode($matches[1], $lcp_content);
|
311 |
+
$lcp_content = $lcp_post_content[0] .
|
312 |
+
' <a href="' . get_permalink($single->ID) . '" title="' . "$lcp_more" . '">' .
|
313 |
+
$lcp_more . '</a>';
|
314 |
+
endif;
|
315 |
+
|
316 |
+
return $lcp_content;
|
317 |
else:
|
318 |
return null;
|
319 |
endif;
|
327 |
$lcp_excerpt = $this->lcp_trim_excerpt($single->post_content);
|
328 |
}else{
|
329 |
if(!empty($this->params['excerpt_overwrite']) &&
|
330 |
+
$this->params['excerpt_overwrite'] == 'yes'){
|
331 |
// Excerpt but we want to overwrite it:";
|
332 |
$lcp_excerpt = $this->lcp_trim_excerpt($single->post_content);
|
333 |
} else {
|
350 |
$text = apply_filters('the_excerpt', $text);
|
351 |
$text = str_replace(']]>',']]>', $text);
|
352 |
|
353 |
+
if( $this->utils->lcp_not_empty('excerpt_strip') &&
|
354 |
+
$this->params['excerpt_strip'] == 'yes'):
|
355 |
$text = strip_tags($text);
|
356 |
endif;
|
357 |
|
358 |
$words = explode(' ', $text, $excerpt_length + 1);
|
359 |
if(count($words) > $excerpt_length) :
|
360 |
array_pop($words);
|
361 |
+
array_push($words, '...');
|
362 |
+
$text = implode(' ', $words);
|
363 |
endif;
|
364 |
return $text;
|
365 |
}
|
366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
public function get_thumbnail($single, $lcp_thumb_class = null){
|
368 |
+
return LcpThumbnail::get_instance()->get_thumbnail(
|
369 |
+
$single,
|
370 |
+
$this->params['thumbnail'],
|
371 |
+
$this->params['thumbnail_size'],
|
372 |
+
$lcp_thumb_class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
}
|
374 |
+
|
375 |
}
|
include/lcp-catlistdisplayer.php
CHANGED
@@ -19,14 +19,14 @@ class CatListDisplayer {
|
|
19 |
public function __construct($atts) {
|
20 |
$this->params = $atts;
|
21 |
$this->catlist = new CatList($atts);
|
22 |
-
$this->
|
23 |
}
|
24 |
|
25 |
public function display(){
|
26 |
return $this->lcp_output;
|
27 |
}
|
28 |
|
29 |
-
private function
|
30 |
// Check if we got a template param:
|
31 |
if (isset($this->params['template']) &&
|
32 |
!empty($this->params['template'])){
|
@@ -186,8 +186,13 @@ class CatListDisplayer {
|
|
186 |
$query = preg_replace($pattern, '', $_SERVER['QUERY_STRING']);
|
187 |
|
188 |
$url = strtok($_SERVER["REQUEST_URI"],'?');
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
-
$page_link = "
|
191 |
$amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
|
192 |
"#lcp_instance_" . $this->catlist->get_instance();
|
193 |
$link .= "<li><a href='$page_link' title='$page'>";
|
@@ -218,26 +223,12 @@ class CatListDisplayer {
|
|
218 |
$lcp_display_output .= $this->get_post_title($single);
|
219 |
|
220 |
// Comments count
|
221 |
-
|
222 |
-
if (!empty($this->params['comments_class'])):
|
223 |
-
$lcp_display_output .= $this->get_comments($single,
|
224 |
-
$this->params['comments_tag'],
|
225 |
-
$this->params['comments_class']);
|
226 |
-
else:
|
227 |
-
$lcp_display_output .= $this->get_comments($single, $this->params['comments_tag']);
|
228 |
-
endif;
|
229 |
-
else:
|
230 |
-
$lcp_display_output .= $this->get_comments($single);
|
231 |
-
endif;
|
232 |
|
233 |
// Date
|
234 |
-
|
235 |
-
$lcp_display_output .= $this->get_date($single,
|
236 |
$this->params['date_tag'],
|
237 |
$this->params['date_class']);
|
238 |
-
else:
|
239 |
-
$lcp_display_output .= $this->get_date($single);
|
240 |
-
endif;
|
241 |
|
242 |
// Date Modified
|
243 |
if (!empty($this->params['date_modified_tag']) || !empty($this->params['date_modified_class'])):
|
@@ -249,17 +240,9 @@ class CatListDisplayer {
|
|
249 |
endif;
|
250 |
|
251 |
// Author
|
252 |
-
|
253 |
-
if (!empty($this->params['author_class'])):
|
254 |
-
$lcp_display_output .= $this->get_author($single,
|
255 |
$this->params['author_tag'],
|
256 |
$this->params['author_class']);
|
257 |
-
else:
|
258 |
-
$lcp_display_output .= $this->get_author($single, $this->params['author_tag']);
|
259 |
-
endif;
|
260 |
-
else:
|
261 |
-
$lcp_display_output .= $this->get_author($single);
|
262 |
-
endif;
|
263 |
|
264 |
// Display ID
|
265 |
if (!empty($this->params['display_id']) && $this->params['display_id'] == 'yes'){
|
@@ -271,29 +254,15 @@ class CatListDisplayer {
|
|
271 |
|
272 |
$lcp_display_output .= $this->get_thumbnail($single);
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
$lcp_display_output .= $this->get_content($single,
|
277 |
$this->params['content_tag'],
|
278 |
$this->params['content_class']);
|
279 |
-
else:
|
280 |
-
$lcp_display_output .= $this->get_content($single, $this->params['content_tag']);
|
281 |
-
endif;
|
282 |
-
else:
|
283 |
-
$lcp_display_output .= $this->get_content($single);
|
284 |
-
endif;
|
285 |
|
286 |
-
|
287 |
-
|
288 |
-
$lcp_display_output .= $this->get_excerpt($single,
|
289 |
$this->params['excerpt_tag'],
|
290 |
$this->params['excerpt_class']);
|
291 |
-
else:
|
292 |
-
$lcp_display_output .= $this->get_excerpt($single, $this->params['excerpt_tag']);
|
293 |
-
endif;
|
294 |
-
else:
|
295 |
-
$lcp_display_output .= $this->get_excerpt($single);
|
296 |
-
endif;
|
297 |
|
298 |
$lcp_display_output .= $this->get_posts_morelink($single);
|
299 |
|
@@ -320,18 +289,43 @@ class CatListDisplayer {
|
|
320 |
/**
|
321 |
* Auxiliary functions for templates
|
322 |
*/
|
323 |
-
private function
|
324 |
-
|
325 |
-
return $this->assign_style($info, $tag, $css_class);
|
326 |
}
|
327 |
|
328 |
-
|
329 |
-
|
330 |
-
return $this->
|
331 |
}
|
332 |
|
333 |
private function get_content($single, $tag = null, $css_class = null){
|
334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
return $this->assign_style($info, $tag, $css_class);
|
336 |
}
|
337 |
|
@@ -356,12 +350,6 @@ class CatListDisplayer {
|
|
356 |
return $this->assign_style($info, $tag, $css_class);
|
357 |
}
|
358 |
|
359 |
-
private function get_excerpt($single, $tag = null, $css_class = null){
|
360 |
-
$info = $this->catlist->get_excerpt($single);
|
361 |
-
$info = preg_replace('/\[.*\]/', '', $info);
|
362 |
-
return $this->assign_style($info, $tag, $css_class);
|
363 |
-
}
|
364 |
-
|
365 |
private function get_thumbnail($single, $tag = null){
|
366 |
if ( !empty($this->params['thumbnail_class']) ) :
|
367 |
$lcp_thumb_class = $this->params['thumbnail_class'];
|
@@ -373,7 +361,7 @@ class CatListDisplayer {
|
|
373 |
return $this->assign_style($info, $tag);
|
374 |
}
|
375 |
|
376 |
-
private function get_post_title($single){
|
377 |
$info = '<a href="' . get_permalink($single->ID);
|
378 |
|
379 |
$lcp_post_title = apply_filters('the_title', $single->post_title, $single->ID);
|
@@ -396,7 +384,6 @@ class CatListDisplayer {
|
|
396 |
$info .= ' class="' . $this->params['title_class'] . '"';
|
397 |
endif;
|
398 |
|
399 |
-
|
400 |
$info .= '>' . $lcp_post_title . '</a>';
|
401 |
|
402 |
if( !empty($this->params['post_suffix']) ):
|
@@ -413,6 +400,10 @@ class CatListDisplayer {
|
|
413 |
$info = $pre . $info . $post;
|
414 |
}
|
415 |
|
|
|
|
|
|
|
|
|
416 |
return $info;
|
417 |
}
|
418 |
|
19 |
public function __construct($atts) {
|
20 |
$this->params = $atts;
|
21 |
$this->catlist = new CatList($atts);
|
22 |
+
$this->select_template();
|
23 |
}
|
24 |
|
25 |
public function display(){
|
26 |
return $this->lcp_output;
|
27 |
}
|
28 |
|
29 |
+
private function select_template(){
|
30 |
// Check if we got a template param:
|
31 |
if (isset($this->params['template']) &&
|
32 |
!empty($this->params['template'])){
|
186 |
$query = preg_replace($pattern, '', $_SERVER['QUERY_STRING']);
|
187 |
|
188 |
$url = strtok($_SERVER["REQUEST_URI"],'?');
|
189 |
+
$protocol = "http";
|
190 |
+
if ( (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ||
|
191 |
+
$_SERVER['SERVER_PORT'] == 443){
|
192 |
+
$protocol = "https";
|
193 |
+
}
|
194 |
|
195 |
+
$page_link = "$protocol://$_SERVER[HTTP_HOST]$url?$query" .
|
196 |
$amp . "lcp_page" . $this->catlist->get_instance() . "=". $page .
|
197 |
"#lcp_instance_" . $this->catlist->get_instance();
|
198 |
$link .= "<li><a href='$page_link' title='$page'>";
|
223 |
$lcp_display_output .= $this->get_post_title($single);
|
224 |
|
225 |
// Comments count
|
226 |
+
$lcp_display_output .= $this->get_comments($single, $this->params['comments_tag'], $this->params['comments_class']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
// Date
|
229 |
+
$lcp_display_output .= $this->get_date($single,
|
|
|
230 |
$this->params['date_tag'],
|
231 |
$this->params['date_class']);
|
|
|
|
|
|
|
232 |
|
233 |
// Date Modified
|
234 |
if (!empty($this->params['date_modified_tag']) || !empty($this->params['date_modified_class'])):
|
240 |
endif;
|
241 |
|
242 |
// Author
|
243 |
+
$lcp_display_output .= $this->get_author($single,
|
|
|
|
|
244 |
$this->params['author_tag'],
|
245 |
$this->params['author_class']);
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
// Display ID
|
248 |
if (!empty($this->params['display_id']) && $this->params['display_id'] == 'yes'){
|
254 |
|
255 |
$lcp_display_output .= $this->get_thumbnail($single);
|
256 |
|
257 |
+
// Content
|
258 |
+
$lcp_display_output .= $this->get_content($single,
|
|
|
259 |
$this->params['content_tag'],
|
260 |
$this->params['content_class']);
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
|
262 |
+
// Excerpt
|
263 |
+
$lcp_display_output .= $this->get_excerpt($single,
|
|
|
264 |
$this->params['excerpt_tag'],
|
265 |
$this->params['excerpt_class']);
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
$lcp_display_output .= $this->get_posts_morelink($single);
|
268 |
|
289 |
/**
|
290 |
* Auxiliary functions for templates
|
291 |
*/
|
292 |
+
private function get_comments($single, $tag = null, $css_class = null){
|
293 |
+
return $this->content_getter('comments', $single, $tag, $css_class);
|
|
|
294 |
}
|
295 |
|
296 |
+
|
297 |
+
private function get_author($single, $tag = null, $css_class = null){
|
298 |
+
return $this->content_getter('author', $single, $tag, $css_class);
|
299 |
}
|
300 |
|
301 |
private function get_content($single, $tag = null, $css_class = null){
|
302 |
+
return $this->content_getter('content', $single, $tag, $css_class);
|
303 |
+
}
|
304 |
+
|
305 |
+
private function get_excerpt($single, $tag = null, $css_class = null){
|
306 |
+
return $this->content_getter('excerpt', $single, $tag, $css_class);
|
307 |
+
}
|
308 |
+
|
309 |
+
/*
|
310 |
+
* These used to be separate functions, now starting to get the code
|
311 |
+
* in the same function for less repetition.
|
312 |
+
*/
|
313 |
+
private function content_getter($type, $post, $tag = null, $css_class = null) {
|
314 |
+
$info = '';
|
315 |
+
switch( $type ){
|
316 |
+
case 'comments':
|
317 |
+
$info = $this->catlist->get_comments_count($post);
|
318 |
+
break;
|
319 |
+
case 'author':
|
320 |
+
$info = $this->catlist->get_author_to_show($post);
|
321 |
+
break;
|
322 |
+
case 'content':
|
323 |
+
$info = $this->catlist->get_content($post);
|
324 |
+
break;
|
325 |
+
case 'excerpt':
|
326 |
+
$info = $this->catlist->get_excerpt($post);
|
327 |
+
$info = preg_replace('/\[.*\]/', '', $info);
|
328 |
+
}
|
329 |
return $this->assign_style($info, $tag, $css_class);
|
330 |
}
|
331 |
|
350 |
return $this->assign_style($info, $tag, $css_class);
|
351 |
}
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
private function get_thumbnail($single, $tag = null){
|
354 |
if ( !empty($this->params['thumbnail_class']) ) :
|
355 |
$lcp_thumb_class = $this->params['thumbnail_class'];
|
361 |
return $this->assign_style($info, $tag);
|
362 |
}
|
363 |
|
364 |
+
private function get_post_title($single, $tag = null, $css_class = null){
|
365 |
$info = '<a href="' . get_permalink($single->ID);
|
366 |
|
367 |
$lcp_post_title = apply_filters('the_title', $single->post_title, $single->ID);
|
384 |
$info .= ' class="' . $this->params['title_class'] . '"';
|
385 |
endif;
|
386 |
|
|
|
387 |
$info .= '>' . $lcp_post_title . '</a>';
|
388 |
|
389 |
if( !empty($this->params['post_suffix']) ):
|
400 |
$info = $pre . $info . $post;
|
401 |
}
|
402 |
|
403 |
+
if( $tag !== null || $css_class !== null){
|
404 |
+
$info = $this->assign_style($info, $tag, $css_class);
|
405 |
+
}
|
406 |
+
|
407 |
return $info;
|
408 |
}
|
409 |
|
include/lcp-parameters.php
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once ( LCP_PATH . 'lcp-utils.php' );
|
3 |
+
|
4 |
+
class LcpParameters{
|
5 |
+
// Singleton implementation
|
6 |
+
private static $instance = null;
|
7 |
+
private $starting_with = null;
|
8 |
+
private $utils;
|
9 |
+
|
10 |
+
public static function get_instance(){
|
11 |
+
if( !isset( self::$instance ) ){
|
12 |
+
self::$instance = new self;
|
13 |
+
}
|
14 |
+
return self::$instance;
|
15 |
+
}
|
16 |
+
|
17 |
+
public function get_query_params($params){
|
18 |
+
# Essential parameters:
|
19 |
+
$args = array(
|
20 |
+
'numberposts' => $params['numberposts'],
|
21 |
+
'orderby' => $params['orderby'],
|
22 |
+
'order' => $params['order'],
|
23 |
+
'offset' => $params['offset']
|
24 |
+
);
|
25 |
+
$this->utils = new LcpUtils($params);
|
26 |
+
|
27 |
+
// Check posts to exclude
|
28 |
+
$args = $this->lcp_check_excludes($args);
|
29 |
+
|
30 |
+
// Check type, status, parent params
|
31 |
+
$args = $this->lcp_types_and_statuses($args);
|
32 |
+
|
33 |
+
if($this->utils->lcp_not_empty('year')):
|
34 |
+
$args['year'] = $params['year'];
|
35 |
+
endif;
|
36 |
+
|
37 |
+
if($this->utils->lcp_not_empty('monthnum')):
|
38 |
+
$args['monthnum'] = $params['monthnum'];
|
39 |
+
endif;
|
40 |
+
|
41 |
+
if($this->utils->lcp_not_empty('search')):
|
42 |
+
$args['s'] = $params['search'];
|
43 |
+
endif;
|
44 |
+
|
45 |
+
if($this->utils->lcp_not_empty('author_posts')):
|
46 |
+
$args['author_name'] = $params['author_posts'];
|
47 |
+
endif;
|
48 |
+
|
49 |
+
/*
|
50 |
+
* Custom fields 'customfield_name' & 'customfield_value'
|
51 |
+
* should both be defined
|
52 |
+
*/
|
53 |
+
if( $this->utils->lcp_not_empty('customfield_value') ){
|
54 |
+
$args['meta_key'] = $params['customfield_name'];
|
55 |
+
$args['meta_value'] = $params['customfield_value'];
|
56 |
+
}
|
57 |
+
|
58 |
+
//Get private posts
|
59 |
+
if( is_user_logged_in() ){
|
60 |
+
if ( !empty($args['post_status']) ){
|
61 |
+
$args['post_status'] = array_merge($args['post_status'], array('private'));
|
62 |
+
} else{
|
63 |
+
$args['post_status'] = array('private', 'publish');
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
if ( $this->utils->lcp_not_empty('exclude_tags') ){
|
68 |
+
$this->lcp_excluded_tags($args);
|
69 |
+
}
|
70 |
+
|
71 |
+
// Current tags
|
72 |
+
if ( $this->utils->lcp_not_empty('currenttags') && $params['currenttags'] == "yes" ){
|
73 |
+
$tags = $this->lcp_get_current_tags();
|
74 |
+
if ( !empty($tags) ){
|
75 |
+
$args['tag__in'] = $tags;
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
// Custom taxonomy support
|
80 |
+
if ( $this->utils->lcp_not_empty('taxonomy') && $this->utils->lcp_not_empty('tags') ){
|
81 |
+
$args['tax_query'] = array(array(
|
82 |
+
'taxonomy' => $params['taxonomy'],
|
83 |
+
'field' => 'slug',
|
84 |
+
'terms' => explode(",",$params['tags'])
|
85 |
+
));
|
86 |
+
} elseif ( !empty($params['tags']) ) {
|
87 |
+
$args['tag'] = $params['tags'];
|
88 |
+
}
|
89 |
+
|
90 |
+
if ( !empty($params['exclude'])){
|
91 |
+
$args['category__not_in'] = array($params['exclude']);
|
92 |
+
}
|
93 |
+
|
94 |
+
if ( $this->utils->lcp_not_empty('customfield_orderby') ){
|
95 |
+
$args['orderby'] = 'meta_value';
|
96 |
+
$args['meta_key'] = $params['customfield_orderby'];
|
97 |
+
}
|
98 |
+
|
99 |
+
// Posts that start with a given letter:
|
100 |
+
if ( $this->utils->lcp_not_empty('starting_with') ){
|
101 |
+
$this->starting_with = $params['starting_with'];
|
102 |
+
add_filter('posts_where' , array( $this, 'starting_with') );
|
103 |
+
}
|
104 |
+
|
105 |
+
return $args;
|
106 |
+
}
|
107 |
+
|
108 |
+
// Check posts to exclude
|
109 |
+
private function lcp_check_excludes($args){
|
110 |
+
if( $this->utils->lcp_not_empty('excludeposts') ){
|
111 |
+
$exclude = array(
|
112 |
+
'post__not_in' => explode(",", $this->params['excludeposts'])
|
113 |
+
);
|
114 |
+
if (strpos($this->params['excludeposts'], 'this') > -1){
|
115 |
+
$exclude = array_merge(
|
116 |
+
$exclude,
|
117 |
+
array('post__not_in' => array($this->lcp_get_current_post_id() ) )
|
118 |
+
);
|
119 |
+
}
|
120 |
+
$args = array_merge($args, $exclude);
|
121 |
+
}
|
122 |
+
return $args;
|
123 |
+
}
|
124 |
+
|
125 |
+
private function lcp_types_and_statuses($args){
|
126 |
+
// Post type, status, parent params:
|
127 |
+
if($this->utils->lcp_not_empty('post_type')):
|
128 |
+
$args['post_type'] = explode( ',', $this->params['post_type'] );
|
129 |
+
endif;
|
130 |
+
|
131 |
+
if($this->utils->lcp_not_empty('post_status')):
|
132 |
+
$args['post_status'] = explode( ',', $this->params['post_status'] );
|
133 |
+
endif;
|
134 |
+
|
135 |
+
if($this->utils->lcp_not_empty('post_parent')):
|
136 |
+
$args['post_parent'] = $this->params['post_parent'];
|
137 |
+
endif;
|
138 |
+
return $args;
|
139 |
+
}
|
140 |
+
|
141 |
+
private function lcp_excluded_tags($args){
|
142 |
+
$excluded_tags = explode(",", $params['exclude_tags']);
|
143 |
+
$tag_ids = array();
|
144 |
+
foreach ( $excluded_tags as $excluded){
|
145 |
+
$tag_ids[] = get_term_by('slug', $excluded, 'post_tag')->term_id;
|
146 |
+
}
|
147 |
+
$args['tag__not_in'] = $tag_ids;
|
148 |
+
return $args;
|
149 |
+
}
|
150 |
+
|
151 |
+
private function lcp_get_current_tags(){
|
152 |
+
$tags = get_the_tags();
|
153 |
+
$tag_ids = array();
|
154 |
+
if( !empty($tags) ){
|
155 |
+
foreach ($tags as $tag_id => $tag) {
|
156 |
+
array_push($tag_ids, $tag_id);
|
157 |
+
}
|
158 |
+
}
|
159 |
+
return $tag_ids;
|
160 |
+
}
|
161 |
+
|
162 |
+
public function starting_with($where){
|
163 |
+
$letters = explode(',', $this->starting_with);
|
164 |
+
$where .= 'AND (wp_posts.post_title ' .
|
165 |
+
'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[0] . "%'";
|
166 |
+
for ($i=1; $i <sizeof($letters); $i++) {
|
167 |
+
$where .= 'OR wp_posts.post_title ' .
|
168 |
+
'COLLATE UTF8_GENERAL_CI LIKE \'' . $letters[$i] . "%'";
|
169 |
+
}
|
170 |
+
$where.=')';
|
171 |
+
return $where;
|
172 |
+
}
|
173 |
+
}
|
include/lcp-post-builder.php
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?
|
2 |
+
|
3 |
+
class LcpPostBuilder{
|
4 |
+
// Singleton implementation
|
5 |
+
private static $instance = null;
|
6 |
+
|
7 |
+
public static function get_instance(){
|
8 |
+
if( !isset( self::$instance ) ){
|
9 |
+
self::$instance = new self;
|
10 |
+
}
|
11 |
+
return self::$instance;
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* This function should be overriden for template system.
|
16 |
+
* @param post $single
|
17 |
+
* @param HTML tag to display $tag
|
18 |
+
* @return string
|
19 |
+
*/
|
20 |
+
public function lcp_build_post($single, $tag){
|
21 |
+
global $post;
|
22 |
+
|
23 |
+
$class ='';
|
24 |
+
if ( $post->ID == $single->ID ):
|
25 |
+
$class = " class = current ";
|
26 |
+
endif;
|
27 |
+
|
28 |
+
$lcp_display_output = '<'. $tag . $class . '>';
|
29 |
+
|
30 |
+
$lcp_display_output .= $this->get_post_title($single);
|
31 |
+
|
32 |
+
// Comments count
|
33 |
+
$lcp_display_output .= $this->get_comments($single, $this->params['comments_tag'], $this->params['comments_class']);
|
34 |
+
|
35 |
+
// Date
|
36 |
+
$lcp_display_output .= $this->get_date($single,
|
37 |
+
$this->params['date_tag'],
|
38 |
+
$this->params['date_class']);
|
39 |
+
|
40 |
+
// Date Modified
|
41 |
+
if (!empty($this->params['date_modified_tag']) || !empty($this->params['date_modified_class'])):
|
42 |
+
$lcp_display_output .= $this->get_modified_date($single,
|
43 |
+
$this->params['date_modified_tag'],
|
44 |
+
$this->params['date_modified_class']);
|
45 |
+
else:
|
46 |
+
$lcp_display_output .= $this->get_modified_date($single);
|
47 |
+
endif;
|
48 |
+
|
49 |
+
// Author
|
50 |
+
$lcp_display_output .= $this->get_author($single,
|
51 |
+
$this->params['author_tag'],
|
52 |
+
$this->params['author_class']);
|
53 |
+
|
54 |
+
// Display ID
|
55 |
+
if (!empty($this->params['display_id']) && $this->params['display_id'] == 'yes'){
|
56 |
+
$lcp_display_output .= $single->ID;
|
57 |
+
}
|
58 |
+
|
59 |
+
// Custom field display
|
60 |
+
$lcp_display_output .= $this->get_custom_fields($single);
|
61 |
+
|
62 |
+
$lcp_display_output .= $this->get_thumbnail($single);
|
63 |
+
|
64 |
+
// Content
|
65 |
+
$lcp_display_output .= $this->get_content($single,
|
66 |
+
$this->params['content_tag'],
|
67 |
+
$this->params['content_class']);
|
68 |
+
|
69 |
+
// Excerpt
|
70 |
+
$lcp_display_output .= $this->get_excerpt($single,
|
71 |
+
$this->params['excerpt_tag'],
|
72 |
+
$this->params['excerpt_class']);
|
73 |
+
|
74 |
+
$lcp_display_output .= $this->get_posts_morelink($single);
|
75 |
+
|
76 |
+
$lcp_display_output .= '</' . $tag . '>';
|
77 |
+
return $lcp_display_output;
|
78 |
+
}
|
79 |
+
|
80 |
+
private function get_post_title($single, $tag = null, $css_class = null){
|
81 |
+
$info = '<a href="' . get_permalink($single->ID);
|
82 |
+
|
83 |
+
$lcp_post_title = apply_filters('the_title', $single->post_title, $single->ID);
|
84 |
+
|
85 |
+
if ( !empty($this->params['title_limit']) && $this->params['title_limit'] != "0" ):
|
86 |
+
$lcp_post_title = substr($lcp_post_title, 0, intval($this->params['title_limit']));
|
87 |
+
if( strlen($lcp_post_title) >= intval($this->params['title_limit']) ):
|
88 |
+
$lcp_post_title .= "…";
|
89 |
+
endif;
|
90 |
+
endif;
|
91 |
+
|
92 |
+
$info.= '" title="' . wptexturize($single->post_title) . '"';
|
93 |
+
|
94 |
+
if (!empty($this->params['link_target'])):
|
95 |
+
$info .= ' target="' . $this->params['link_target'] . '" ';
|
96 |
+
endif;
|
97 |
+
|
98 |
+
if ( !empty($this->params['title_class'] ) &&
|
99 |
+
empty($this->params['title_tag']) ):
|
100 |
+
$info .= ' class="' . $this->params['title_class'] . '"';
|
101 |
+
endif;
|
102 |
+
|
103 |
+
$info .= '>' . $lcp_post_title . '</a>';
|
104 |
+
|
105 |
+
if( !empty($this->params['post_suffix']) ):
|
106 |
+
$info .= " " . $this->params['post_suffix'];
|
107 |
+
endif;
|
108 |
+
|
109 |
+
if (!empty($this->params['title_tag'])){
|
110 |
+
$pre = "<" . $this->params['title_tag'];
|
111 |
+
if (!empty($this->params['title_class'])){
|
112 |
+
$pre .= ' class="' . $this->params['title_class'] . '"';
|
113 |
+
}
|
114 |
+
$pre .= '>';
|
115 |
+
$post = "</" . $this->params['title_tag'] . ">";
|
116 |
+
$info = $pre . $info . $post;
|
117 |
+
}
|
118 |
+
|
119 |
+
if( $tag !== null || $css_class !== null){
|
120 |
+
$info = $this->assign_style($info, $tag, $css_class);
|
121 |
+
}
|
122 |
+
|
123 |
+
return $info;
|
124 |
+
}
|
125 |
+
|
126 |
+
}
|
include/lcp-thumbnail.php
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class LcpThumbnail{
|
3 |
+
|
4 |
+
// Singleton implementation
|
5 |
+
private static $instance = null;
|
6 |
+
|
7 |
+
public static function get_instance(){
|
8 |
+
if( !isset( self::$instance ) ){
|
9 |
+
self::$instance = new self;
|
10 |
+
}
|
11 |
+
return self::$instance;
|
12 |
+
}
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Get the post Thumbnail
|
16 |
+
* @see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
|
17 |
+
* @param unknown_type $single
|
18 |
+
*
|
19 |
+
*/
|
20 |
+
public function get_thumbnail($single, $thumbnail, $thumbnail_size, $lcp_thumb_class = null){
|
21 |
+
$lcp_thumbnail = null;
|
22 |
+
|
23 |
+
if( $thumbnail == 'yes' ){
|
24 |
+
$lcp_thumbnail = '';
|
25 |
+
|
26 |
+
if ( has_post_thumbnail($single->ID) ){
|
27 |
+
$image_sizes = array_unique(
|
28 |
+
array_merge(
|
29 |
+
get_intermediate_image_sizes(),
|
30 |
+
array("thumbnail", "medium", "large", "full")
|
31 |
+
)
|
32 |
+
);
|
33 |
+
|
34 |
+
if( in_array( $thumbnail_size, $image_sizes ) ){
|
35 |
+
$lcp_thumb_size = $thumbnail_size;
|
36 |
+
} elseif( $thumbnail_size ) {
|
37 |
+
$lcp_thumb_size = explode(",", $thumbnail_size);
|
38 |
+
} else {
|
39 |
+
$lcp_thumb_size = 'thumbnail';
|
40 |
+
}
|
41 |
+
|
42 |
+
$lcp_thumbnail = '<a href="' . esc_url(get_permalink($single->ID)) .
|
43 |
+
'" title="' . esc_attr($single->post_title) . '">';
|
44 |
+
|
45 |
+
$lcp_thumbnail .= get_the_post_thumbnail(
|
46 |
+
$single->ID,
|
47 |
+
$lcp_thumb_size,
|
48 |
+
( $lcp_thumb_class != null ) ? array( 'class' => $lcp_thumb_class ) : null
|
49 |
+
);
|
50 |
+
$lcp_thumbnail .= '</a>';
|
51 |
+
}
|
52 |
+
} else {
|
53 |
+
# Check for a YouTube video thumbnail
|
54 |
+
$lcp_thumbnail = $this->check_youtube_thumbnail($single->content);
|
55 |
+
}
|
56 |
+
return $lcp_thumbnail;
|
57 |
+
}
|
58 |
+
|
59 |
+
private function check_youtube_thumbnail($content){
|
60 |
+
# youtube.com/watch?v=id
|
61 |
+
$yt_pattern = '/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/';
|
62 |
+
# youtube.com/v[id]
|
63 |
+
$yt_vpattern = "/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/";
|
64 |
+
# youtube embedded code
|
65 |
+
$yt_epattern = "/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/(embed)\/([a-zA-Z0-9\-\_]{11})[^<\s]*/";
|
66 |
+
|
67 |
+
if (
|
68 |
+
preg_match($yt_pattern, $content, $matches) ||
|
69 |
+
preg_match($yt_vpattern, $content, $matches) ||
|
70 |
+
preg_match($yt_epattern, $content, $matches)
|
71 |
+
){
|
72 |
+
$youtubeurl = $matches[0];
|
73 |
+
|
74 |
+
if ($youtubeurl):
|
75 |
+
$imageurl = "http://i.ytimg.com/vi/{$matches[3]}/1.jpg";
|
76 |
+
endif;
|
77 |
+
|
78 |
+
$lcp_ytimage = '<img src="' . $imageurl . '" alt="' . $single->post_title . '" />';
|
79 |
+
|
80 |
+
if ($lcp_thumb_class != null):
|
81 |
+
$thmbn_class = ' class="' . $lcp_thumb_class . '" />';
|
82 |
+
$lcp_ytimage = preg_replace("/\>/", $thmbn_class, $lcp_ytimage);
|
83 |
+
endif;
|
84 |
+
|
85 |
+
$lcp_thumbnail .= '<a href="' . get_permalink($single->ID).'">' . $lcp_ytimage . '</a>';
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
include/lcp-utils.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class LcpUtils{
|
3 |
+
private $params;
|
4 |
+
|
5 |
+
public function __construct($params){
|
6 |
+
$this->params = $params;
|
7 |
+
}
|
8 |
+
/**
|
9 |
+
* Check for empty parameters (being empty strings or zero).
|
10 |
+
*/
|
11 |
+
public function lcp_not_empty($param){
|
12 |
+
return (
|
13 |
+
isset($this->params[$param]) &&
|
14 |
+
!empty($this->params[$param]) &&
|
15 |
+
$this->params[$param] !== '0' &&
|
16 |
+
$this->params[$param] !== ''
|
17 |
+
);
|
18 |
+
}
|
19 |
+
}
|
include/lcp-widget.php
CHANGED
@@ -111,5 +111,4 @@ class ListCategoryPostsWidget extends WP_Widget{
|
|
111 |
}
|
112 |
}
|
113 |
|
114 |
-
add_action('widgets_init', create_function('', 'return register_widget("listCategoryPostsWidget");'));
|
115 |
-
?>
|
111 |
}
|
112 |
}
|
113 |
|
114 |
+
add_action('widgets_init', create_function('', 'return register_widget("listCategoryPostsWidget");'));
|
|
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.
|
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.54
|
7 |
Author: Fernando Briano
|
8 |
Author URI: http://fernandobriano.com
|
9 |
|
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
|
7 |
-
Stable tag: 0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -132,10 +132,6 @@ update the plugin.
|
|
132 |
|
133 |
==Other parameters==
|
134 |
|
135 |
-
* **starting_with** - Get posts starting with a given letter. You can
|
136 |
-
use several letters. Example: `[catlist starting_with="m,o,t"]` will
|
137 |
-
list posts whose title start with either m, o or t.
|
138 |
-
|
139 |
* **author_posts** - Get posts by author. Use 'user_nicename' (NOT
|
140 |
name). Example: `[catlist author_posts="fernando"]`
|
141 |
|
@@ -169,7 +165,9 @@ list posts whose title start with either m, o or t.
|
|
169 |
* **ASC** - Ascending (lowest to highest).
|
170 |
* **DESC** - Descending (highest to lowest). Ex: `[catlist name=mycategory orderby=title order=asc]`
|
171 |
|
172 |
-
* **starting_with** - Get posts whose title starts with a certain
|
|
|
|
|
173 |
|
174 |
* **numberposts** - Number of posts to return. Set to 0 to use the max
|
175 |
number of posts per page. Set to -1 to remove the limit.
|
@@ -241,7 +239,7 @@ Show the full content of the post. If there's a <!--more--> tag in the pos
|
|
241 |
|
242 |
* **thumbnail_class** - Set a CSS class for the thumbnail.
|
243 |
|
244 |
-
* **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types.
|
245 |
|
246 |
* **post_status** - use post status, default value is 'publish'. Valid values:
|
247 |
* **publish** - a published post or page.
|
@@ -253,6 +251,7 @@ Show the full content of the post. If there's a <!--more--> tag in the pos
|
|
253 |
* **inherit** - a revision. see get_children.
|
254 |
* **trash** - post is in trashbin (available with Version 2.9).
|
255 |
* **any** - retrieves any status except those from post types with 'exclude_from_search' set to true.
|
|
|
256 |
|
257 |
* **show_protected** - Show posts protected by password. By default
|
258 |
they are not displayed. Use: `[catlist show_protected=yes]`
|
@@ -333,7 +332,17 @@ Then just add a new text widget to your blog and use the shortcode there as the
|
|
333 |
|
334 |
== HTML & CSS Customization ==
|
335 |
|
336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
The customizable elements (so far) are: author, catlink (category link), comments, date, excerpt, morelink ("Read More" link), thumbnail and title (post title).
|
339 |
|
@@ -426,8 +435,17 @@ Template system has changed. Custom templates should be stored in WordPress them
|
|
426 |
|
427 |
== Changelog ==
|
428 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
= 0.53 =
|
430 |
-
*
|
431 |
|
432 |
= 0.52 =
|
433 |
* Small fix for pagination and query string.
|
4 |
Tags: list, categories, posts, cms
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 0.54
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
132 |
|
133 |
==Other parameters==
|
134 |
|
|
|
|
|
|
|
|
|
135 |
* **author_posts** - Get posts by author. Use 'user_nicename' (NOT
|
136 |
name). Example: `[catlist author_posts="fernando"]`
|
137 |
|
165 |
* **ASC** - Ascending (lowest to highest).
|
166 |
* **DESC** - Descending (highest to lowest). Ex: `[catlist name=mycategory orderby=title order=asc]`
|
167 |
|
168 |
+
* **starting_with** - Get posts whose title starts with a certain
|
169 |
+
letter. Example: `[catlist starting_with="l"]` will list all posts
|
170 |
+
whose title starts with L. You can use several letters: `[catlist starting_with="m,o,t"]`.
|
171 |
|
172 |
* **numberposts** - Number of posts to return. Set to 0 to use the max
|
173 |
number of posts per page. Set to -1 to remove the limit.
|
239 |
|
240 |
* **thumbnail_class** - Set a CSS class for the thumbnail.
|
241 |
|
242 |
+
* **post_type** - The type of post to show. Available options are: post - Default, page, attachment, any - all post types. You can use several types, example: `[catlist post_type="page,post" numberposts=-1]`
|
243 |
|
244 |
* **post_status** - use post status, default value is 'publish'. Valid values:
|
245 |
* **publish** - a published post or page.
|
251 |
* **inherit** - a revision. see get_children.
|
252 |
* **trash** - post is in trashbin (available with Version 2.9).
|
253 |
* **any** - retrieves any status except those from post types with 'exclude_from_search' set to true.
|
254 |
+
You can use several post statuses. Example: `[catlist post_status="future, publish" excludeposts=this]`
|
255 |
|
256 |
* **show_protected** - Show posts protected by password. By default
|
257 |
they are not displayed. Use: `[catlist show_protected=yes]`
|
332 |
|
333 |
== HTML & CSS Customization ==
|
334 |
|
335 |
+
By default, the plugin lists the posts in an unordered list with the
|
336 |
+
`lcp_catlist` CSS class, like this:
|
337 |
+
|
338 |
+
`<ul class="lcp_catlist">`
|
339 |
+
|
340 |
+
So if you want to customize the appearance of the List Category Posts
|
341 |
+
lists, you can just edit the lcp_catlist class in your theme's CSS.
|
342 |
+
|
343 |
+
You can also customize what HTML tags different elements will be
|
344 |
+
surrounded with, and set a CSS class for this element, or just a CSS class
|
345 |
+
which will wrap the element with a `span` tag.
|
346 |
|
347 |
The customizable elements (so far) are: author, catlink (category link), comments, date, excerpt, morelink ("Read More" link), thumbnail and title (post title).
|
348 |
|
435 |
|
436 |
== Changelog ==
|
437 |
|
438 |
+
= 0.54 =
|
439 |
+
* Adds http/https check for pagination links.
|
440 |
+
* Fixes `post_status` and `post_type` parameters for using multiple post statuses and types.
|
441 |
+
* Big refactor: Thumbnail code, parameters moved to new class,
|
442 |
+
created util class, removed bad and repeated code, moved category
|
443 |
+
code to new class. Small fixes all around the place. Went from a
|
444 |
+
very bad 1.77 GPA to 3.23 on CodeClimate.
|
445 |
+
|
446 |
+
|
447 |
= 0.53 =
|
448 |
+
* Makes "starting_with" parameter accept several letters, by Diego Sorribas. Thank you!
|
449 |
|
450 |
= 0.52 =
|
451 |
* Small fix for pagination and query string.
|
templates/default.php
CHANGED
@@ -41,7 +41,8 @@ $lcp_display_output .= $this->get_category_link('strong');
|
|
41 |
$lcp_display_output .= '<ul class="lcp_catlist">';
|
42 |
|
43 |
/**
|
44 |
-
*
|
|
|
45 |
* The code here will be executed for every post in the category.
|
46 |
* As you can see, the different options are being called from functions on the
|
47 |
* $this variable which is a CatListDisplayer.
|
@@ -56,7 +57,7 @@ foreach ($this->catlist->get_categories_posts() as $single){
|
|
56 |
$lcp_display_output .= "<li>";
|
57 |
|
58 |
//Show the title and link to the post:
|
59 |
-
$lcp_display_output .= $this->get_post_title($single);
|
60 |
|
61 |
//Show comments:
|
62 |
$lcp_display_output .= $this->get_comments($single);
|
@@ -64,11 +65,14 @@ foreach ($this->catlist->get_categories_posts() as $single){
|
|
64 |
//Show date:
|
65 |
$lcp_display_output .= ' ' . $this->get_date($single);
|
66 |
|
|
|
|
|
|
|
67 |
//Show author
|
68 |
$lcp_display_output .= $this->get_author($single);
|
69 |
|
70 |
//Custom fields:
|
71 |
-
$lcp_display_output .= $this->get_custom_fields($
|
72 |
|
73 |
//Post Thumbnail
|
74 |
$lcp_display_output .= $this->get_thumbnail($single);
|
@@ -85,10 +89,15 @@ foreach ($this->catlist->get_categories_posts() as $single){
|
|
85 |
*/
|
86 |
$lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');
|
87 |
|
|
|
|
|
|
|
|
|
88 |
//Close li tag
|
89 |
$lcp_display_output .= '</li>';
|
90 |
}
|
91 |
|
|
|
92 |
$lcp_display_output .= '</ul>';
|
93 |
|
94 |
// If there's a "more link", show it:
|
41 |
$lcp_display_output .= '<ul class="lcp_catlist">';
|
42 |
|
43 |
/**
|
44 |
+
* POSTS LOOP
|
45 |
+
*
|
46 |
* The code here will be executed for every post in the category.
|
47 |
* As you can see, the different options are being called from functions on the
|
48 |
* $this variable which is a CatListDisplayer.
|
57 |
$lcp_display_output .= "<li>";
|
58 |
|
59 |
//Show the title and link to the post:
|
60 |
+
$lcp_display_output .= $this->get_post_title($single, 'h4', 'lcp_post');
|
61 |
|
62 |
//Show comments:
|
63 |
$lcp_display_output .= $this->get_comments($single);
|
65 |
//Show date:
|
66 |
$lcp_display_output .= ' ' . $this->get_date($single);
|
67 |
|
68 |
+
//Show date modified:
|
69 |
+
$lcp_display_output .= ' ' . $this->get_modified_date($single);
|
70 |
+
|
71 |
//Show author
|
72 |
$lcp_display_output .= $this->get_author($single);
|
73 |
|
74 |
//Custom fields:
|
75 |
+
$lcp_display_output .= $this->get_custom_fields($single);
|
76 |
|
77 |
//Post Thumbnail
|
78 |
$lcp_display_output .= $this->get_thumbnail($single);
|
89 |
*/
|
90 |
$lcp_display_output .= $this->get_excerpt($single, 'div', 'lcp_excerpt');
|
91 |
|
92 |
+
|
93 |
+
// Get Posts "More" link:
|
94 |
+
$lcp_display_output .= $this->get_posts_morelink($single);
|
95 |
+
|
96 |
//Close li tag
|
97 |
$lcp_display_output .= '</li>';
|
98 |
}
|
99 |
|
100 |
+
// Close the wrapper I opened at the beginning:
|
101 |
$lcp_display_output .= '</ul>';
|
102 |
|
103 |
// If there's a "more link", show it:
|