This repository has been archived by the owner on Jan 11, 2018. It is now read-only.
/
wordpress-popular-posts-feedmaker.php
662 lines (563 loc) · 33.1 KB
/
wordpress-popular-posts-feedmaker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
<?php
/*
Plugin Name: WordPress Popular Posts Feedmaker
Plugin URI: http://wpdevelopers.com
Description: Creates a popular feed at /feed/popular, which uses WordPress Popular Posts
Version: 1.7.6
Author: Ted Slater & Tyler Johnson
Author URI: http://libertyalliance.com
Author Email: tyler@libertyalliance.com
Text Domain: wordpress-popular-posts-feedmaker
Copyright 2016 WP Developers & Liberty Alliance
*/
/**********
Check for Plugin Updates
**********/
require 'plugin-update-checker-3.0/plugin-update-checker.php';
$wpdevUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/LibertyAllianceGit/wordpress-popular-posts-feedmaker',
__FILE__,
'wordpress-popular-posts-feedmaker'
);
$wpdevUpdateChecker->setAccessToken('4921ce230f2bd252dd1fafc7afeac812ddf091de');
/**********
Refresh Permalinks on Plugin Activation
**********/
register_activation_hook( __FILE__, 'wpprss_activation_rewrite_permalinks' );
function wpprss_activation_rewrite_permalinks() {
//Ensure the $wp_rewrite global is loaded
global $wp_rewrite;
//Call flush_rules() as a method of the $wp_rewrite object, so that permalinks are flushed
$wp_rewrite->flush_rules( false );
}
/**********
Add Image Sizes for Patriot Times & Email Newsletters
**********/
// Add Thumbnail Theme Support
add_theme_support( 'post-thumbnails' );
// Add Patriot Times Sizes
add_image_size( 'patriottimes-main', 250, 205, true );
add_image_size( 'patriottimes-headline', 155, 110, true );
add_image_size( 'patriottimes-email', 330, 175, true );
// Fix Cropping for Small Images
function wpdev_thumbnail_crop_fix_pt( $default, $orig_w, $orig_h, $new_w, $new_h, $crop ){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'wpdev_thumbnail_crop_fix_pt', 10, 6 );
/**********
WPP Feedmaker Options
**********/
// Enqueue Admin Styles
function wpp_rss_plugin_css() {
wp_register_style( 'wpprss-plugin-css', plugin_dir_url(__FILE__) . 'admin/wpprss-css.css' );
wp_enqueue_style( 'wpprss-plugin-css' );
}
add_action('admin_enqueue_scripts', 'wpp_rss_plugin_css', 20);
// Create Options Page
add_action( 'admin_menu', 'wpprss_add_admin_menu' );
add_action( 'admin_init', 'wpprss_settings_init' );
function wpprss_add_admin_menu() {
add_submenu_page(
'options-general.php',
'WordPress Popular Posts Feedmaker',
'WordPress Popular Posts Feedmaker',
'manage_options',
'wpprss',
'wpprss_options_page'
);
}
function wpprss_settings_init() {
register_setting( 'wppFeedPage', 'wpprss_settings' );
add_settings_section(
'wpprss_wppFeedPage_section',
__( 'RSS Feed Options', 'wpprss' ),
'wpprss_settings_section_callback',
'wppFeedPage'
);
add_settings_field(
'wpprss_text_limit_field',
__( '<span>Limit</span><p>Sets the maximum number of popular posts to be shown in the RSS feed.</p>', 'wpprss' ),
'wpprss_text_limit_field_render',
'wppFeedPage',
'wpprss_wppFeedPage_section'
);
add_settings_field(
'wpprss_select_range_field',
__( '<span>Range</span><p>Tells WordPress Popular Posts to retrieve the most popular entries within the time range specified for the RSS feed.</p>', 'wpprss' ),
'wpprss_select_range_field_render',
'wppFeedPage',
'wpprss_wppFeedPage_section'
);
add_settings_field(
'wpprss_select_freshness_field',
__( '<span>Freshness</span><p>Tells WordPress Popular Posts to retrieve the most popular entries published within the time range specified above.</p>', 'wpprss' ),
'wpprss_select_freshness_field_render',
'wppFeedPage',
'wpprss_wppFeedPage_section'
);
add_settings_field(
'wpprss_select_orderby_field',
__( '<span>Order By</span><p>Sets the sorting option of the popular posts with the RSS feed.</p>', 'wpprss' ),
'wpprss_select_orderby_field_render',
'wppFeedPage',
'wpprss_wppFeedPage_section'
);
}
function wpprss_text_limit_field_render() {
$options = get_option( 'wpprss_settings' );
?>
<input type='text' name='wpprss_settings[wpprss_text_limit_field]' value='<?php echo $options['wpprss_text_limit_field']; ?>' placeholder="10">
<?php
}
function wpprss_select_range_field_render() {
$options = get_option( 'wpprss_settings' );
?>
<select name='wpprss_settings[wpprss_select_range_field]'>
<option value='1' <?php selected( $options['wpprss_select_range_field'], 1 ); ?>>Daily</option>
<option value='2' <?php selected( $options['wpprss_select_range_field'], 2 ); ?>>Weekly</option>
<option value='3' <?php selected( $options['wpprss_select_range_field'], 3 ); ?>>Monthly</option>
<option value='4' <?php selected( $options['wpprss_select_range_field'], 4 ); ?>>All Time</option>
</select>
<?php
}
function wpprss_select_freshness_field_render() {
$options = get_option( 'wpprss_settings' );
?>
<select name='wpprss_settings[wpprss_select_freshness_field]'>
<option value='1' <?php selected( $options['wpprss_select_freshness_field'], 1 ); ?>>Enable</option>
<option value='2' <?php selected( $options['wpprss_select_freshness_field'], 2 ); ?>>Disable</option>
</select>
<?php
}
function wpprss_select_orderby_field_render() {
$options = get_option( 'wpprss_settings' );
?>
<select name='wpprss_settings[wpprss_select_orderby_field]'>
<option value='1' <?php selected( $options['wpprss_select_orderby_field'], 1 ); ?>>Comments</option>
<option value='2' <?php selected( $options['wpprss_select_orderby_field'], 2 ); ?>>Total Views</option>
<option value='3' <?php selected( $options['wpprss_select_orderby_field'], 3 ); ?>>Average Views</option>
</select>
<?php
}
function wpprss_settings_section_callback() {
echo __( 'Settings for the most popular posts output within the custom RSS feed located at: ', 'wpprss' );
echo '<a href="' . get_bloginfo('url') . '/feed/popular/" target="_blank">' . get_bloginfo('url') . '/feed/popular/' . '</a>. If feed displays 404, please save permalinks to refresh the link structure. You can refresh permalinks <a href="' . get_bloginfo('url') . '/wp-admin/options-permalink.php" target="_blank">HERE</a>.';
}
function wpprss_options_page() {
?>
<div class="wpp-rss-admin-page">
<form action='options.php' method='post'>
<h2><img src="<?php echo plugin_dir_url(__FILE__) . 'admin/wpp-rss-logo.png'; ?>" /></h2>
<?php
settings_fields( 'wppFeedPage' );
do_settings_sections( 'wppFeedPage' );
submit_button();
?>
</form>
<hr/>
<h3>RSS Shortcode Output — Instructions</h3>
<div class="wpp-rss-admin-section">
<p>In order to embed RSS feeds, please use the shortcode. The base shortcode requires and URL setting and is like this:</p>
<code>[wpp_rss url="http://feeds.feedburner.com/TechCrunch/"]</code>
<p>Add additonal RSS feeds by placing commas between the feed URLs, like so:</p>
<code>[aggregation_rss url="http://feeds.feedburner.com/TechCrunch/,http://feeds.feedburner.com/TechCrunch/"]</code>
</div><div class="wpp-rss-admin-section">
<p>Additional shortcode properties include:</p>
<ul>
<li>type - Specifies the output structure of the RSS. (reg for regular output, emailfeat for featured spot in email output, and email for list/top stories spot in email template). <em>NOTE: Using type="emailfeat" or type="email" removes all other options.</em></li>
<li>items – Number of items from the feed you wish to fetch. Default is 10.</li>
<li>orderby – Order the items by date or reverse date (date or reverse_date).</li>
<li>title – Choose whether to display the title or not (true or false, defaults to true).</li>
<li>excerpt – How many words you want to display for each item’s excerpt (default is 0 or infinite, use ‘none’ to remove the excerpt).</li>
<li>read_more – Choose whether to display a read more link or not (true or false, defaults to true).</li>
<li>new_window – Choose whether to open the title link and read more link in a new window (true or false, defaults to true).</li>
<li>thumbnail – Choose whether or not you want to display a thumbnail, and if so, what size you want it to be (true or false, defaults to true, inserting a number will change the size, default is 150).</li>
<li>source – Choose whether to display the source or note (true or false, defaults to true).</li>
<li>date – Choose whether to display the publish date of the post or not (true or false, defaults to true).</li>
<li>cache – Choose how long you want the feed to cache in seconds(default is 43200, which is 12 hours).</li>
</ul>
</div>
<div class="wpp-rss-admin-section">
<p>Full example:</p>
<code>[wpp_rss type="reg" url="http://feeds.feedburner.com/TechCrunch/,http://feeds.feedburner.com/TechCrunch/" items="10" excerpt="50" read_more="true" new_window="true" thumbnail="200" cache="7200"]</code>
</div>
<div class="wpp-rss-plugin-footer">
<p>Copyright © <?php echo date('Y'); ?> <a href="//wpdevelopers.com" target="_blank">WP Developers</a> & <a href="//libertyalliance.com" target="_blank">Liberty Alliance</a>. All Rights Reserved.</p>
</div>
</div>
<?php
}
/**********
Options Loaded
**********/
// Get Options
$wpprssoptions = get_option( 'wpprss_settings' );
// Assign Options to Variables
$wpprsslimit = $wpprssoptions['wpprss_text_limit_field'];
$wpprssrange = $wpprssoptions['wpprss_select_range_field'];
$wpprssfreshness = $wpprssoptions['wpprss_select_freshness_field'];
$wpprssorderby = $wpprssoptions['wpprss_select_orderby_field'];
/**********
Setup RSS Feed
**********/
// Create RSS
function wpdev_custom_rss_feed() {
add_feed('popular', 'wpdev_custom_rss_temp');
}
add_action('init', 'wpdev_custom_rss_feed');
// RSS Template
function wpdev_custom_rss_temp() {
include( plugin_dir_path(__FILE__) . 'templates/wpdev-wpp-rss-feed.php');
}
/**********
Create WPP Template for RSS
**********/
// Create Excerpt for WPP
function wpdev_wpp_rss_get_excerpt_by_id($post_id){
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
$excerpt_length = 35; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if (count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$the_excerpt = implode(' ', $words);
endif;
$the_excerpt = $the_excerpt;
return $the_excerpt;
}
// Build Custom HTML for WPP
function wpdev_wpp_rss_custom_html( $mostpopular, $instance ){
// loop the array of popular posts objects
foreach( $mostpopular as $popular ) {
$title = esc_attr( $popular->title );
$link = get_the_permalink( $popular->id );
$date = get_the_date( 'r', $popular->id );
$authid = get_post_field( 'post_author', $popular->id );
$author = get_the_author_meta( 'display_name', $authid );
$wppexcerpt = wpdev_wpp_rss_get_excerpt_by_id( $popular->id ); // Excerpt placeholder
$image = wp_get_attachment_image_src(get_post_thumbnail_id( $popular->id ), 'full' );
$imagereplace = preg_replace('/-\d+[Xx]\d+\./', '.', $image[0]);
$pathinfo = pathinfo($image[0]);
$output .= '<item>';
$output .= '<title>' . $title . '</title>';
$output .= '<link>' . $link . '</link>';
$output .= '<pubDate>' . $date . '</pubDate>';
$output .= '<dc:creator><![CDATA[' . $author . ']]></dc:creator>';
$output .= '<enclosure url="' . $imagereplace . '" type="image/' . $pathinfo['extension'] . '" length="1" />';
$output .= '<guid isPermaLink=\'true\'>' . $link . '</guid>';
$output .= '<description><![CDATA[<img src="' . $imagereplace . '" />' . $wppexcerpt . ']]></description>';
$output .= '<content:encoded><![CDATA[<img src="' . $imagereplace . '" />' . $wppexcerpt . ']]></content:encoded>';
$output .= '</item>';
//Wed, 02 Oct 2002 08:00:00 EST
}
return $output;
}
// Output Custom HTML on RSS Feeds ONLY
function wpdev_wpp_rss_custom_html_output() {
if(is_feed()) {
add_filter( 'wpp_custom_html', 'wpdev_wpp_rss_custom_html', 10, 2 );
}
}
add_action('wp', 'wpdev_wpp_rss_custom_html_output');
/**********
RSS Output for Newsletter - Shortcode
**********/
// Main Shortcode
add_shortcode( 'wpp_rss', 'wpp_rss_function' );
function wpp_rss_function( $atts, $content = null ){
extract( shortcode_atts( array(
'type' => 'reg',
'url' => '#',
'offsetitems' => '0',
'linkcolor' => '#A60000',
'btncolor' => '#000000',
'items' => '10',
'orderby' => 'default',
'title' => 'true',
'excerpt' => '0',
'read_more' => 'true',
'new_window' => 'true',
'thumbnail' => 'false',
'randomthumbnail' => 'false',
'source' => 'true',
'date' => 'true',
'cache' => '43200'
), $atts ) );
update_option( 'wp_rss_cache', $cache );
//multiple urls
$urls = explode(',', $url);
add_filter( 'wp_feed_cache_transient_lifetime', 'wpp_rss_cache' );
$rss = fetch_feed( $urls );
remove_filter( 'wp_feed_cache_transient_lifetime', 'wpp_rss_cache' );
if ( ! is_wp_error( $rss ) ) :
if ($orderby == 'date' || $orderby == 'date_reverse') {
$rss->enable_order_by_date(true);
}
$maxitems = $rss->get_item_quantity( $items );
$rss_items = $rss->get_items( $offsetitems, $maxitems );
if ( $new_window != 'false' ) {
$newWindowOutput = 'target="_blank" ';
} else {
$newWindowOutput = NULL;
}
if ($orderby == 'date_reverse') {
$rss_items = array_reverse($rss_items);
}
endif;
// Shortcode Output
if($type == 'reg') {
$output = '<div class="post_item">';
$output .= '<ul class="post_item_list">';
if ( !isset($maxitems) ) :
$output .= '<li>' . _e( 'No items', 'wpp-rss-retriever' ) . '</li>';
else :
//loop through each feed item and display each item.
foreach ( $rss_items as $item ) :
//variables
$content = $item->get_content();
$messy_title = $item->get_title();
$remove_tags = array('<em>', '</em>', '<i>', '</i>', '<b>', '</b>', '<strong>', '</strong>');
$replace_tags = array('', '', '', '', '', '', '', '');
$the_title = str_replace($remove_tags, $replace_tags, $messy_title);
$enclosure = $item->get_enclosure();
//build output
$output .= '<li class="post_item_item"><div class="post_item_item_wrapper">';
//random thumbnail
$randnums = range(1,$items);
$maxnums = $items * 0.2;
shuffle($randnums);
$maximumnums = round($maxnums);
$arraynums = array_slice($randnums, 0, $maximumnums);
if ($randomthumbnail != 'false' && $enclosure && in_array($postcount, $arraynums)) {
$thumbnail_image = $enclosure->get_thumbnail();
if ($thumbnail_image) {
//use thumbnail image if it exists
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($thumbnail_image);
$output .= '<div class="post_item_image"' . $resize . '><a ' . $newWindowOutput . ' href="' . esc_url( $item->get_permalink() ) . '"><img' . $class . ' src="' . $thumbnail_image . '" alt="' . $title . '"></a></div>';
} else {
//if not than find and use first image in content
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $first_image);
if ($first_image){
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($first_image["src"]);
$output .= '<div class="post_item_image"' . $resize . '><a ' . $newWindowOutput . ' href="' . esc_url( $item->get_permalink() ) . '"><img' . $class . ' src="' . $first_image["src"] . '" alt="' . $title . '"></a></div>';
}
}
$hasrandthumbnail = 'wpdev-has-thumb';
} else {
$hasrandthumbnail = '';
}
//title
if ($title == 'true') {
$output .= '<a class="post_item_title ' . $hasrandthumbnail . '" ' . $newWindowOutput . 'href="' . esc_url( $item->get_permalink() ) . '"
title="' . $the_title . '"><h1>';
$output .= $the_title;
$output .= '</h1></a>';
}
//thumbnail
if ($thumbnail != 'false' && $enclosure) {
$thumbnail_image = $enclosure->get_thumbnail();
if ($thumbnail_image) {
//use thumbnail image if it exists
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($thumbnail_image);
$output .= '<div class="post_item_image"' . $resize . '><a ' . $newWindowOutput . ' href="' . esc_url( $item->get_permalink() ) . '"><img' . $class . ' src="' . $thumbnail_image . '" alt="' . $title . '"></a></div>';
} else {
//if not than find and use first image in content
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $first_image);
if ($first_image){
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($first_image["src"]);
$output .= '<div class="post_item_image"' . $resize . '><a ' . $newWindowOutput . ' href="' . esc_url( $item->get_permalink() ) . '"><img' . $class . ' src="' . $first_image["src"] . '" alt="' . $title . '"></a></div>';
}
}
}
//content
$output .= '<div class="post_item_container">';
if ( $excerpt != 'none' ) {
if ( $excerpt > 0 ) {
$output .= esc_html(implode(' ', array_slice(explode(' ', strip_tags($content)), 0, $excerpt))) . "...";
} else {
$output .= $content;
}
if( $read_more == 'true' ) {
$output .= ' <div class="post_item_readmore_cont"><a class="post_item_readmore" ' . $newWindowOutput . 'href="' . esc_url( $item->get_permalink() ) . '"
title="' . sprintf( __( 'Posted %s', 'wpp-rss-retriever' ), $item->get_date('j F Y | g:i a') ) . '">';
$output .= __( 'Read more <i class="fa fa-angle-right"></i>', 'wpp-rss-retriever' );
$output .= '</a></div>';
}
}
//metadata
if ($source == 'true' || $date == 'true') {
$output .= '<div class="post_item_metadata">';
$source_title = $item->get_feed()->get_title();
$time = $item->get_date('F j, Y - g:i a');
if ($source == 'true' && $source_title) {
$output .= '<span class="post_item_source">' . sprintf( __( 'Source: %s', 'wpp-rss-retriever' ), $source_title ) . '</span>';
}
if ($source == 'true' && $date == 'true') {
$output .= '';
}
if ($date == 'true' && $time) {
$output .= '<span class="post_item_date">' . sprintf( __( 'Published: %s', 'wpp-rss-retriever' ), $time ) . '</span>';
}
$output .= '</div>';
}
$output .= '</div></div></li>';
endforeach;
endif;
$output .= '</ul>';
$output .= '</div>';
} elseif($type == 'emailfeat') {
$linkcolor;
$btncolor;
$output = '<table border="0" cellpadding="0" cellspacing="0" class="columns-container" style="margin-bottom: 30px;">';
if ( !isset($maxitems) ) :
$output .= '<tr>' . _e( 'No items', 'wpp-rss-retriever' ) . '</tr>';
else :
//loop through each feed item and display each item.
foreach ( $rss_items as $item ) :
//variables
$content = $item->get_content();
$messy_title = $item->get_title();
$remove_tags = array('<em>', '</em>', '<i>', '</i>', '<b>', '</b>', '<strong>', '</strong>');
$replace_tags = array('', '', '', '', '', '', '', '');
$the_title = str_replace($remove_tags, $replace_tags, $messy_title);
$enclosure = $item->get_enclosure();
//build output
$output .= '<tr>';
//title
$output .= '<td class="force-col" style="padding-right: 20px;" valign="top"><table border="0" cellspacing="0" cellpadding="0" width="324" align="left" class="featured"><tr><td align="left" valign="top" style="font-size:28px; line-height: 32px; font-family: Arial, sans-serif;">';
$output .= '<a href="' . esc_url($item->get_permalink()) . '" title="' . $the_title . '" style="font-weight:bold; color: ' . $linkcolor . '">' . $the_title . '</a>';
$output .= '<br><br>';
$output .= '<a href="' . esc_url($item->get_permalink()) . '" title="' . $the_title . '" style="width: 100%; line-height: 16px; font-size: 14px; font-style: normal; font-family: Arial, sans-serif; text-decoration: none; border: 2px solid; padding: 8px 15px; border-radius: 1px; border-color: ' . $btncolor . '; color: ' . $btncolor . '; font-weight: bold;">Read This</a>';
$output .= '<br><br></td></tr></table></td>';
//thumbnail
if ($thumbnail != 'false' && $enclosure) {
$thumbnail_image = $enclosure->get_thumbnail();
if ($thumbnail_image) {
//use thumbnail image if it exists
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($thumbnail_image);
$output .= '<td class="force-col" valign="top"><table border="0" cellspacing="0" cellpadding="0" width="324" align="right" class="featured" id="featured-last"><tr><td align="left" valign="top" style="font-size:13px; line-height: 20px; font-family: Arial, sans-serif; height: 200px !important; display: block; overflow: hidden;}">';
$output .= '<a href="' . esc_url($item->get_permalink()) . '"><img src="' . $thumbnail_image . '" alt="' . $the_title . '" border="0" hspace="0" vspace="0" style="vertical-align:top; max-width: 300px;" class="emailimg"></a>';
$output .= '<br><br></td></tr></table></td>';
} else {
//if not than find and use first image in content
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $first_image);
if ($first_image){
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($first_image["src"]);
$output .= '<td class="force-col" valign="top"><table border="0" cellspacing="0" cellpadding="0" width="324" align="right" class="featured" id="featured-last"><tr><td align="left" valign="top" style="font-size:13px; line-height: 20px; font-family: Arial, sans-serif; height: 200px !important; display: block; overflow: hidden;">';
$output .= '<a href="' . esc_url($item->get_permalink()) . '"><img src="' . $first_image["src"] . '" alt="' . $the_title . '" border="0" hspace="0" vspace="0" style="vertical-align:top; max-width: 324px;" class="emailimg"></a>';
$output .= '<br></td></tr></table></td>';
}
}
}
$output .= '</tr>';
endforeach;
endif;
$output .= '</table>';
} elseif($type == 'email') {
if ( !isset($maxitems) ) :
$output .= '<tr>' . _e( 'No items', 'wpp-rss-retriever' ) . '</tr>';
else :
//loop through each feed item and display each item.
foreach ( $rss_items as $item ) :
//variables
$content = $item->get_content();
$messy_title = $item->get_title();
$remove_tags = array('<em>', '</em>', '<i>', '</i>', '<b>', '</b>', '<strong>', '</strong>');
$replace_tags = array('', '', '', '', '', '', '', '');
$the_title = str_replace($remove_tags, $replace_tags, $messy_title);
$enclosure = $item->get_enclosure();
$linkcolor;
//build output
$output .= '<tr>';
//title
$output .= '<td align="left" valign="top" style="font-size:22px; line-height: 26px; font-family: Arial, sans-serif; padding-bottom: 5px; display: block; margin-bottom: 20px; border-bottom: 1px solid ' . $btncolor . ';">';
$output .= '<a href="' . esc_url($item->get_permalink()) . '" title="' . $the_title . '" style="font-weight:bold; font-size:22px; line-height: 26px; font-family: Arial, sans-serif; color: ' . $linkcolor . ';">' . $the_title . '</a><br><a href="https://www.facebook.com/sharer/sharer.php?u=' . esc_url($item->get_permalink()) . '" style="margin-right: 5px;"><img src="/wp-content/uploads/2016/01/pt-fb-share.jpg" /></a><a href="https://twitter.com/home?status=' . esc_url($item->get_permalink()) . '"><img src="/wp-content/uploads/2016/01/pt-tw-share.jpg" /></a>';
$output .= '</td>';
endforeach;
endif;
} elseif($type == 'emailprod') {
$linkcolor;
$btncolor;
if ( !isset($maxitems) ) :
$output .= '<tr>' . _e( 'No items', 'wpp-rss-retriever' ) . '</tr>';
else :
//loop through each feed item and display each item.
foreach ( $rss_items as $item ) :
//variables
$content = $item->get_content();
$messy_title = $item->get_title();
$remove_tags = array('<em>', '</em>', '<i>', '</i>', '<b>', '</b>', '<strong>', '</strong>');
$replace_tags = array('', '', '', '', '', '', '', '');
$the_title = str_replace($remove_tags, $replace_tags, $messy_title);
$enclosure = $item->get_enclosure();
//build output
$output .= '<td class="force-col" style="padding-right: 20px;" valign="top"><table border="0" cellspacing="0" cellpadding="0" width="324" align="left" class="col-2"><tbody><tr><td align="left" valign="top" style="font-size:16px; line-height: 22px; font-family: Arial, sans-serif;"><br>';
//thumbnail
if ($thumbnail != 'false' && $enclosure) {
$thumbnail_image = $enclosure->get_thumbnail();
if ($thumbnail_image) {
//use thumbnail image if it exists
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($thumbnail_image);
$output .= '<a href="' . esc_url($item->get_permalink()) . '" style="font-weight:bold; font-size:20px;text-decoration:none; display: block !important; height: 200px !important;overflow: hidden;">';
$output .= '<img src="' . $thumbnail_image . '" alt="' . $the_title . '" border="0" hspace="0" vspace="0" style="vertical-align:top; padding-bottom:12px; max-width: 324px; width:300px;" class="emailimg" width="300"></a>';
$output .= '<br>';
} else {
//if not than find and use first image in content
preg_match('/<img.+src=[\'"](?P<src>.*cdn1.+?)[\'"].*>/i', $content, $first_image);
if ($first_image){
$resize = wpp_rss_resize_thumbnail($thumbnail);
$class = wpp_rss_get_image_class($first_image["src"]);
$output .= '<a href="' . esc_url($item->get_permalink()) . '" style="font-weight:bold; font-size:20px;text-decoration:none;display: block !important; height: 200px !important;overflow: hidden;">';
$output .= '<img src="' . $first_image["src"] . '" alt="' . $the_title . '" border="0" hspace="0" vspace="0" style="vertical-align:top; padding-bottom:12px; max-width: 324px; width:300px;" class="emailimg" width="300"></a>';
$output .= '<br>';
}
}
}
//title
$output .= '<a href="' . esc_url($item->get_permalink()) . '" title="' . $the_title . '" style="font-weight:bold; color: ' . $linkcolor . '">' . $the_title . '</a><br><br>';
$output .= '<a href="' . esc_url($item->get_permalink()) . '" style="width: 100%; line-height: 16px; font-size: 14px; font-style: normal; font-family: Arial, sans-serif; text-decoration: none; border: 2px solid; padding: 8px 15px; border-radius: 1px; border-color: ' . $btncolor . '; color: ' . $btncolor . '; font-weight: bold;">Buy Now</a>';
$output .= '<br><br></td></tr></tbody></table></td>';
endforeach;
endif;
}
return $output;
}
add_option( 'wp_rss_cache', 43200 );
function wpp_rss_cache() {
//change the default feed cache
$cache = get_option( 'wp_rss_cache', 43200 );
return $cache;
}
function wpp_rss_get_image_class($image_src) {
list($width, $height) = getimagesize($image_src);
if ($height > $width) {
$class = ' class="portrait"';
} else {
$class = '';
}
return $class;
}
function wpp_rss_resize_thumbnail($thumbnail) {
if (is_numeric($thumbnail)){
$resize = ' style="width:' . $thumbnail . 'px; height:' . $thumbnail . 'px;"';
} else {
$resize = '';
}
return $resize;
}