WP RSS Aggregator - Version 2.0

Version Description

Download this release

Release Info

Developer jeangalea
Plugin Icon 128x128 WP RSS Aggregator
Version 2.0
Comparing to
See all releases

Version 2.0

changelog.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2.0 (2012-09-21)
2
+ Bulk of code rewritten and refactored
3
+ Added install and upgrade functions
4
+ Added DB version setting
5
+ Feed sources now stored as Custom Post Types
6
+ Feed source list sortable ascending or descending by name
7
+ Removed days subsections in feed display
8
+ Ability to limit total number of feeds displayed
9
+ Feeds now fetched via Cron
10
+ Cron job to delete old feed items, keeps max of 50 items in DB
11
+ Now requires WordPress 3.2
12
+ updated colorbox to v1.3.20.1
13
+ Limit of 15 items max imported for each source
14
+ Fixed issue of page content displaying incorrectly after feeds
15
+
16
+
17
+ 1.1 (2012-08-13)
18
+ Now requires WordPress 3.0
19
+ More flexible fetching of images directory
20
+ Has its own top level menu item
21
+ Added settings section
22
+ Ability to open in lightbox, new window or default browser behaviour
23
+ Ability to set links as follow or no follow
24
+ Using constants for oftenly used locations
25
+ Code refactoring
26
+ Changes in file and folder structure
27
+
28
+ 1.0 (2012-01-06)
29
+ First release
css/colorbox.css ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ ColorBox Core Style:
3
+ The following CSS is consistent between example themes and should not be altered.
4
+ */
5
+ #colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
6
+ #cboxOverlay{position:fixed; width:100%; height:100%;}
7
+ #cboxMiddleLeft, #cboxBottomLeft{clear:left;}
8
+ #cboxContent{position:relative;}
9
+ #cboxLoadedContent{overflow:auto;}
10
+ #cboxTitle{margin:0;}
11
+ #cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
12
+ #cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
13
+ .cboxPhoto{float:left; margin:auto; border:0; display:block; max-width:none;}
14
+ .cboxIframe{width:100%; height:100%; display:block; border:0;}
15
+ #colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box;}
16
+
17
+ /*
18
+ User Style:
19
+ Change the following styles to modify the appearance of ColorBox. They are
20
+ ordered & tabbed in a way that represents the nesting of the generated HTML.
21
+ */
22
+ #cboxOverlay{background:url(../img/colorbox/overlay.png) repeat 0 0;}
23
+ #colorbox{}
24
+ #cboxTopLeft{width:21px; height:21px; background:url(../img/colorbox/controls.png) no-repeat -101px 0;}
25
+ #cboxTopRight{width:21px; height:21px; background:url(../img/colorbox/controls.png) no-repeat -130px 0;}
26
+ #cboxBottomLeft{width:21px; height:21px; background:url(../img/colorbox/controls.png) no-repeat -101px -29px;}
27
+ #cboxBottomRight{width:21px; height:21px; background:url(../img/colorbox/controls.png) no-repeat -130px -29px;}
28
+ #cboxMiddleLeft{width:21px; background:url(../img/colorbox/controls.png) left top repeat-y;}
29
+ #cboxMiddleRight{width:21px; background:url(../img/colorbox/controls.png) right top repeat-y;}
30
+ #cboxTopCenter{height:21px; background:url(../img/colorbox/border.png) 0 0 repeat-x;}
31
+ #cboxBottomCenter{height:21px; background:url(../img/colorbox/border.png) 0 -29px repeat-x;}
32
+ #cboxContent{background:#fff; overflow:hidden;}
33
+ .cboxIframe{background:#fff;}
34
+ #cboxError{padding:50px; border:1px solid #ccc;}
35
+ #cboxLoadedContent{margin-bottom:28px;}
36
+ #cboxTitle{position:absolute; bottom:4px; left:0; text-align:center; width:100%; color:#949494;}
37
+ #cboxCurrent{position:absolute; bottom:4px; left:58px; color:#949494;}
38
+ #cboxSlideshow{position:absolute; bottom:4px; right:30px; color:#0092ef;}
39
+ #cboxPrevious{position:absolute; bottom:0; left:0; background:url(../img/colorbox/controls.png) no-repeat -75px 0; width:25px; height:25px; text-indent:-9999px;}
40
+ #cboxPrevious:hover{background-position:-75px -25px;}
41
+ #cboxNext{position:absolute; bottom:0; left:27px; background:url(../img/colorbox/controls.png) no-repeat -50px 0; width:25px; height:25px; text-indent:-9999px;}
42
+ #cboxNext:hover{background-position:-50px -25px;}
43
+ #cboxLoadingOverlay{background:url(../img/colorbox/loading_background.png) no-repeat center center;}
44
+ #cboxLoadingGraphic{background:url(../img/colorbox/loading.gif) no-repeat center center;}
45
+ #cboxClose{position:absolute; bottom:0; right:0; background:url(../img/colorbox/controls.png) no-repeat -25px 0; width:25px; height:25px; text-indent:-9999px;}
46
+ #cboxClose:hover{background-position:-25px -25px;}
47
+
48
+ /*
49
+ The following fixes a problem where IE7 and IE8 replace a PNG's alpha transparency with a black fill
50
+ when an alpha filter (opacity change) is set on the element or ancestor element. This style is not applied to or needed in IE9.
51
+ See: http://jacklmoore.com/notes/ie-transparency-problems/
52
+ */
53
+ .cboxIE #cboxTopLeft,
54
+ .cboxIE #cboxTopCenter,
55
+ .cboxIE #cboxTopRight,
56
+ .cboxIE #cboxBottomLeft,
57
+ .cboxIE #cboxBottomCenter,
58
+ .cboxIE #cboxBottomRight,
59
+ .cboxIE #cboxMiddleLeft,
60
+ .cboxIE #cboxMiddleRight {
61
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF);
62
+ }
css/styles.css ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wprss-input {
2
+ background: none repeat scroll 0 0 #EAF2FA;
3
+ margin-bottom: 20px;
4
+ padding-bottom: 10px;
5
+ padding-left: 10px;
6
+ padding-top: 10px;
7
+ width: 600px;
8
+ }
9
+
10
+ .wprss-input p { line-height: 28px; }
11
+
12
+ .wprss-input label {
13
+ float: left;
14
+ width: 95px !important;
15
+ }
16
+
17
+ .wprss-input input {
18
+ height: 28px;
19
+ margin-bottom: 0;
20
+ padding: 0 0 0 5px;
21
+ width: 400px;
22
+ }
23
+
24
+ #icon-wprss-aggregator {
25
+ background: transparent url( '../img/icon-adminpage32.png' ) no-repeat !important;
26
+ }
27
+
28
+ body.post-type-wprss_feed #titlediv div.inside { display: none !important; }
29
+
30
+ #misc-publishing-actions,
31
+ #minor-publishing-actions { display: none; }
32
+
33
+ #custom_meta_box .form-table th { width: 100px; }
34
+
35
+ body.post-type-wprss_feed_item .add-new-h2,
36
+ body.post-type-wprss_feed_item .tablenav select[name="m"],
37
+ body.post-type-wprss_feed_item #post-query-submit
38
+ { display: none; }
39
+
40
+ body.post-type-wprss_feed_item a.row-title {
41
+ cursor: default;
42
+ font-weight: normal;
43
+ color: #555;
44
+ }
45
+
46
+ #latest-news-cpac-settings li {
47
+ list-style: none;
48
+ line-height: 16px;
49
+ }
50
+
51
+ li.twitter a {
52
+ background: transparent url('../img/twitter.png') no-repeat 0;
53
+ padding-left: 20px;
54
+ }
55
+
56
+ li.facebook a {
57
+ background: transparent url('../img/facebook.png') no-repeat 0;
58
+ padding-left: 20px;
59
+ }
60
+
61
+ li.donate_link a:hover {
62
+ color: darkGreen;
63
+ }
64
+
65
+ /*.rss-aggregator_page_wprss-aggregator-settings .form-table th { width: 80px; }*/
img/colorbox/border.png ADDED
Binary file
img/colorbox/controls.png ADDED
Binary file
img/colorbox/loading.gif ADDED
Binary file
img/colorbox/loading_background.png ADDED
Binary file
img/colorbox/overlay.png ADDED
Binary file
img/facebook.png ADDED
Binary file
img/icon-adminmenu16-sprite.png ADDED
Binary file
img/icon-adminpage32.png ADDED
Binary file
img/twitter.png ADDED
Binary file
inc/activation.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin activation procedure
4
+ *
5
+ * @since 1.0
6
+ */
7
+ function wprss_activate() {
8
+ // Activates the plugin and checks for compatible version of WordPress
9
+ if ( version_compare( get_bloginfo( 'version' ), '3.2', '<' ) ) {
10
+ deactivate_plugins ( basename( __FILE__ )); // Deactivate plugin
11
+ wp_die( "This plugin requires WordPress version 3.2 or higher." );
12
+ }
13
+ wprss_schedule_fetch_feeds_cron();
14
+ }
inc/admin-options.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin administration related functions
4
+ *
5
+ * Note: Wording of options and settings is confusing, due to the plugin originally only having
6
+ * an 'options' page to enter feed sources, and now needing two screens, one for feed sources and one for
7
+ * general settings. Might implement something cleaner in the future.
8
+ *
9
+ * @package WPRSSAggregator
10
+ */
11
+
12
+
13
+ /**
14
+ * Custom Post Type Icon for Admin Menu & Post Screen
15
+ * @since 2.0
16
+ */
17
+ add_action( 'admin_head', 'wprss_custom_post_type_icon' );
18
+
19
+ function wprss_custom_post_type_icon() {
20
+ ?>
21
+ <style>
22
+ /* Post Screen - 32px */
23
+ .icon32-posts-wprss_feed {
24
+ background: transparent url( <?php echo WPRSS_IMG . 'icon-adminpage32.png'; ?> ) no-repeat left top !important;
25
+ }
26
+ /* Post Screen - 32px */
27
+ .icon32-posts-wprss_feed_item {
28
+ background: transparent url( <?php echo WPRSS_IMG . 'icon-adminpage32.png'; ?> ) no-repeat left top !important;
29
+ }
30
+ </style>
31
+ <?php }
32
+
33
+
34
+ /**
35
+ * Register menu and submenus
36
+ * @since 2.0
37
+ */
38
+
39
+ // Add the admin options pages as submenus to the Feed CPT
40
+ add_action( 'admin_menu', 'wprss_register_menu_pages' );
41
+
42
+ function wprss_register_menu_pages() {
43
+
44
+ //create submenu items
45
+ add_submenu_page( 'edit.php?post_type=wprss_feed', 'WP RSS Aggregator Settings', 'Settings', 'manage_options', 'wprss-aggregator-settings', 'wprss_settings_page' );
46
+ }
47
+
48
+
49
+
50
+ /**
51
+ * Register and define options and settings
52
+ * @since 2.0
53
+ * @todo add option for cron frequency
54
+ */
55
+
56
+ add_action( 'admin_init', 'wprss_admin_init' );
57
+
58
+ function wprss_admin_init() {
59
+ register_setting( 'wprss_options', 'wprss_options' );
60
+ add_settings_section( 'wprss_main', '', 'wprss_section_text', 'wprss' );
61
+
62
+ register_setting( 'wprss_settings', 'wprss_settings' );
63
+
64
+
65
+ add_settings_section( 'wprss-settings-main', '', 'wprss_settings_section_text', 'wprss-aggregator-settings' );
66
+
67
+ add_settings_field( 'wprss-settings-open-dd', 'Open links behaviour',
68
+ 'wprss_setting_open_dd', 'wprss-aggregator-settings', 'wprss-settings-main');
69
+
70
+ add_settings_field( 'wprss-settings-follow-dd', 'Set links as',
71
+ 'wprss_setting_follow_dd', 'wprss-aggregator-settings', 'wprss-settings-main');
72
+
73
+ add_settings_field( 'wprss-settings-feed-limit', 'Feed limit',
74
+ 'wprss_setting_feed_limit', 'wprss-aggregator-settings', 'wprss-settings-main');
75
+
76
+ }
77
+
78
+
79
+ /**
80
+ * Build the plugin settings page, used to save general settings like whether a link should be follow or no follow
81
+ * @since 1.1
82
+ */
83
+ function wprss_settings_page() {
84
+ ?>
85
+ <div class="wrap">
86
+ <?php screen_icon( 'wprss-aggregator' ); ?>
87
+
88
+ <h2>WP RSS Aggregator Settings</h2>
89
+
90
+ <form action="options.php" method="post">
91
+ <?php settings_fields( 'wprss_settings' ) ?>
92
+ <?php do_settings_sections( 'wprss-aggregator-settings' ); ?>
93
+ <p class="submit"><input type="submit" value="Save Settings" name="submit" class="button-primary"></p>
94
+ </form>
95
+ </div>
96
+ <?php
97
+ }
98
+
99
+
100
+ // Draw the section header
101
+ function wprss_settings_section_text() {
102
+ // echo '<p>Enter your settings here.</p>';
103
+ }
104
+
105
+
106
+ /**
107
+ * Follow or No Follow dropdown
108
+ * @since 1.1
109
+ */
110
+ function wprss_setting_follow_dd() {
111
+ $options = get_option( 'wprss_settings' );
112
+ $items = array( "No follow", "Follow" );
113
+ echo "<select id='follow-dd' name='wprss_settings[follow_dd]'>";
114
+ foreach( $items as $item ) {
115
+ $selected = ( $options['follow_dd'] == $item) ? 'selected="selected"' : '';
116
+ echo "<option value='$item' $selected>$item</option>";
117
+ }
118
+ echo "</select>";
119
+ }
120
+
121
+
122
+ /**
123
+ * Link open setting dropdown
124
+ * @since 1.1
125
+ */
126
+ function wprss_setting_open_dd() {
127
+ $options = get_option( 'wprss_settings' );
128
+ $items = array( "Lightbox", "New window", "None" );
129
+ echo "<select id='open-dd' name='wprss_settings[open_dd]'>";
130
+ foreach( $items as $item ) {
131
+ $selected = ( $options['open_dd'] == $item) ? 'selected="selected"' : '';
132
+ echo "<option value='$item' $selected>$item</option>";
133
+ }
134
+ echo "</select>";
135
+ }
136
+
137
+
138
+ /**
139
+ * Set limit for feeds on frontend
140
+ * @since 2.0
141
+ */
142
+ function wprss_setting_feed_limit() {
143
+ $options = get_option( 'wprss_settings' );
144
+ // echo the field
145
+
146
+ echo "<input id='feed-limit' name='wprss_settings[feed_limit]' type='text' value='$options[feed_limit]' />";
147
+ }
148
+
149
+
150
+ /**
151
+ * Set body class for admin screens
152
+ * http://www.kevinleary.net/customizing-wordpress-admin-css-javascript/
153
+ * @since 2.0
154
+ */
155
+ function wprss_base_admin_body_class( $classes )
156
+ {
157
+ // Current action
158
+ if ( is_admin() && isset($_GET['action']) ) {
159
+ $classes .= 'action-'.$_GET['action'];
160
+ }
161
+ // Current post ID
162
+ if ( is_admin() && isset($_GET['post']) ) {
163
+ $classes .= ' ';
164
+ $classes .= 'post-'.$_GET['post'];
165
+ }
166
+ // New post type & listing page
167
+ if ( isset($_GET['post_type']) ) $post_type = $_GET['post_type'];
168
+ if ( isset($post_type) ) {
169
+ $classes .= ' ';
170
+ $classes .= 'post-type-'.$post_type;
171
+ }
172
+ // Editting a post type
173
+ if ( isset( $_GET['post'] ) ) {
174
+ $post_query = $_GET['post'];
175
+ }
176
+ if ( isset($post_query) ) {
177
+ $current_post_edit = get_post($post_query);
178
+ $current_post_type = $current_post_edit->post_type;
179
+ if ( !empty($current_post_type) ) {
180
+ $classes .= ' ';
181
+ $classes .= 'post-type-'.$current_post_type;
182
+ }
183
+ }
184
+ // Return the $classes array
185
+ return $classes;
186
+ }
187
+ add_filter('admin_body_class', 'wprss_base_admin_body_class');
inc/cron-jobs.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Contains all the cron jobs in use by WP RSS Aggregator
4
+ *
5
+ * @package WPRSSAggregator
6
+ */
7
+
8
+
9
+ /**
10
+ * Creates the cron to fetch feeds every hour
11
+ *
12
+ * @since 2.0
13
+ */
14
+ function wprss_schedule_fetch_feeds_cron() {
15
+
16
+ // verify event has not been scheduled
17
+ if ( ! wp_next_scheduled( 'wprss_fetch_feeds_hook' ) ) {
18
+ // Schedule to run hourly
19
+ wp_schedule_event( time(), 'hourly', 'wprss_fetch_feeds_hook' );
20
+ }
21
+
22
+ add_action( 'wprss_fetch_feeds_hook', 'wprss_fetch_all_feed_items' );
23
+ }
24
+
25
+
26
+ /**
27
+ * Creates the cron to truncate wprss_feed_item posts daily
28
+ *
29
+ * @since 2.0
30
+ */
31
+ function wprss_schedule_truncate_posts_cron() {
32
+
33
+ // verify event has not been scheduled
34
+ if ( ! wp_next_scheduled( 'wprss_truncate_posts_hook') ) {
35
+ // Schedule to run daily
36
+ wp_schedule_event( time(), 'daily', 'wprss_truncate_posts_hook' );
37
+ }
38
+
39
+ add_action( 'wprss_truncate_posts_hook', 'wprss_truncate_posts' );
40
+ }
41
+
42
+
43
+ //add_filter( 'cron_schedules', 'wprss_cron_add_weekly' );
44
+ /**
45
+ * Not actually used at the moment, might use later on for custom scheduling
46
+ *
47
+ * @since 2.0
48
+ */
49
+ function wprss_cron_add_weekly( $schedules ) {
50
+ // Adds once weekly to the existing schedules.
51
+ $schedules['weekly'] = array(
52
+ 'interval' => 60, // 60*60*24*7
53
+ 'display' => __( 'Once Weekly' )
54
+ );
55
+ return $schedules;
56
+ }
inc/custom-post-types.php ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Contains all custom post type related functions
4
+ *
5
+ * @package WPRSSAggregator
6
+ */
7
+
8
+
9
+ add_action( 'init', 'wprss_register_post_types' );
10
+ /**
11
+ * Create Custom Post Types wprss_feed and wprss_feed_item
12
+ *
13
+ * @since 2.0
14
+ */
15
+ function wprss_register_post_types() {
16
+
17
+ // Set up the arguments for the 'wprss_feed' post type
18
+ $feed_args = array(
19
+ 'public' => true,
20
+ 'query_var' => 'feed',
21
+ 'menu_position' => 100,
22
+ 'menu_icon' => WPRSS_IMG . 'icon-adminmenu16-sprite.png',
23
+ 'show_in_menu' => true,
24
+ 'supports' => array( 'title' ),
25
+ 'rewrite' => array(
26
+ 'slug' => 'feeds',
27
+ 'with_front' => false
28
+ ),
29
+ 'labels' => array(
30
+ 'name' => __( 'Feed Sources' ),
31
+ 'singular_name' => __( 'Feed' ),
32
+ 'add_new' => __( 'Add New Feed Source' ),
33
+ 'all_items' => __( 'All Feed Sources' ),
34
+ 'add_new_item' => __( 'Add New Feed Source' ),
35
+ 'edit_item' => __( 'Edit Feed Source' ),
36
+ 'new_item' => __( 'New Feed Source' ),
37
+ 'view_item' => __( 'View Feed Source' ),
38
+ 'search_items' => __( 'Search Feeds' ),
39
+ 'not_found' => __( 'No Feed Sources Found' ),
40
+ 'not_found_in_trash' => __( 'No Feed Sources Found In Trash' ),
41
+ 'menu_name' => __( 'RSS Aggregator' )
42
+ ),
43
+ );
44
+
45
+ // Register the 'wprss_feed' post type
46
+ register_post_type( 'wprss_feed', $feed_args );
47
+
48
+ // Set up the arguments for the 'wprss_feed_item' post type
49
+ $feed_item_args = array(
50
+ 'public' => true,
51
+ 'query_var' => 'feed_item',
52
+ 'show_in_menu' => 'edit.php?post_type=wprss_feed',
53
+ 'rewrite' => array(
54
+ 'slug' => 'feeds/items',
55
+ 'with_front' => false,
56
+ ),
57
+ 'labels' => array(
58
+ 'name' => __( 'Imported Feeds' ),
59
+ 'singular_name' => __( 'Imported Feed' ),
60
+ 'all_items' => __( 'Imported Feeds' ),
61
+ 'view_item' => __( 'View Imported Feed' ),
62
+ 'search_items' => __( 'Search Imported Feeds' ),
63
+ 'not_found' => __( 'No Imported Feeds Found' ),
64
+ 'not_found_in_trash' => __( 'No Imported Feeds Found In Trash')
65
+ ),
66
+ );
67
+
68
+ // Register the 'feed_item' post type
69
+ register_post_type( 'wprss_feed_item', $feed_item_args );
70
+ }
71
+
72
+
73
+ add_filter( 'manage_edit-wprss_feed_columns', 'wprss_set_custom_columns');
74
+ /**
75
+ * Set up the custom columns for the wprss_feed list
76
+ *
77
+ * @since 2.0
78
+ */
79
+ function wprss_set_custom_columns( $columns ) {
80
+
81
+ $columns = array (
82
+ 'cb' => '<input type="checkbox" />',
83
+ 'title' => __( 'Name', 'wprss' ),
84
+ 'url' => __( 'URL', 'wprss' ),
85
+ 'description' => __( 'Description', 'wprss' ),
86
+ );
87
+ return $columns;
88
+ }
89
+
90
+
91
+ add_action( "manage_wprss_feed_posts_custom_column", "wprss_show_custom_columns", 10, 2 );
92
+ /**
93
+ * Show up the custom columns for the wprss_feed list
94
+ *
95
+ * @since 2.0
96
+ */
97
+ function wprss_show_custom_columns( $column, $post_id ) {
98
+
99
+ switch ( $column ) {
100
+ case 'url':
101
+ $url = get_post_meta( $post_id, 'wprss_url', true);
102
+ echo '<a href="' . esc_url($url) . '">' . esc_url($url) . '</a>';
103
+ break;
104
+ case 'description':
105
+ $description = get_post_meta( $post_id, 'wprss_description', true);
106
+ echo esc_html( $description );
107
+ break;
108
+ }
109
+ }
110
+
111
+
112
+ /**
113
+ * Make the custom columns sortable
114
+ *
115
+ * @since 2.0
116
+ */
117
+ function wprss_sortable_columns() {
118
+ return array(
119
+ // meta column id => sortby value used in query
120
+ 'title' => 'title',
121
+ );
122
+ }
123
+
124
+
125
+ add_filter( 'manage_edit-wprss_feed_item_columns', 'wprss_set_feed_item_custom_columns');
126
+ /**
127
+ * Set up the custom columns for the wprss_feed source list
128
+ *
129
+ * @since 2.0
130
+ */
131
+ function wprss_set_feed_item_custom_columns( $columns ) {
132
+
133
+ $columns = array (
134
+ 'cb' => '<input type="checkbox" />',
135
+ 'title' => __( 'Name', 'wprss' ),
136
+ 'permalink' => __( 'Permalink', 'wprss' ),
137
+ 'publishdate' => __( 'Date published', 'wprss' ),
138
+ 'source' => __( 'Source', 'wprss' )
139
+ );
140
+ return $columns;
141
+ }
142
+
143
+
144
+ add_action( "manage_wprss_feed_item_posts_custom_column", "wprss_show_feed_item_custom_columns", 10, 2 );
145
+ /**
146
+ * Show up the custom columns for the wprss_feed list
147
+ *
148
+ * @since 2.0
149
+ */
150
+ function wprss_show_feed_item_custom_columns( $column, $post_id ) {
151
+
152
+ switch ( $column ) {
153
+ case "permalink":
154
+ $url = get_post_meta( $post_id, 'wprss_item_permalink', true);
155
+ echo '<a href="' . $url . '">' . $url. '</a>';
156
+ break;
157
+
158
+ case "publishdate":
159
+ $publishdate = date( 'Y-m-d H:i:s', get_post_meta( get_the_ID(), 'wprss_item_date', true ) ) ;
160
+ echo $publishdate;
161
+ break;
162
+
163
+ case "source":
164
+ $query = new WP_Query();
165
+ $source = '<a href="' . get_edit_post_link( get_post_meta( $post_id, 'wprss_feed_id', true ) ) . '">' . get_the_title( get_post_meta( $post_id, 'wprss_feed_id', true ) ) . '</a>';
166
+ echo $source;
167
+ break;
168
+ }
169
+ }
170
+
171
+
172
+ add_filter( "manage_edit-wprss_feed_item_sortable_columns", "wprss_feed_item_sortable_columns" );
173
+ /**
174
+ * Make the custom columns sortable
175
+ *
176
+ * @since 2.0
177
+ */
178
+ function wprss_feed_item_sortable_columns() {
179
+ return array(
180
+ // meta column id => sortby value used in query
181
+ 'publishdate' => 'publishdate',
182
+ 'source' => 'source'
183
+ );
184
+ }
185
+
186
+
187
+ add_action( 'pre_get_posts', 'wprss_feed_item_orderby' );
188
+ /**
189
+ * Change ordering of posts on wprss_feed_item screen
190
+ *
191
+ * @since 2.0
192
+ */
193
+ function wprss_feed_item_orderby( $query ) {
194
+ if( ! is_admin() )
195
+ return;
196
+
197
+ $post_type = $query->get('post_type');
198
+
199
+ // If we're on the feed listing admin page
200
+ if ( $post_type == 'wprss_feed_item') {
201
+ // Set general orderby to date the feed item was published
202
+ $query->set('orderby','publishdate');
203
+ // If user clicks on the reorder link, implement reordering
204
+ $orderby = $query->get( 'orderby');
205
+ if( 'publishdate' == $orderby ) {
206
+ $query->set( 'meta_key', 'wprss_item_date' );
207
+ $query->set( 'orderby', 'meta_value_num' );
208
+ }
209
+ }
210
+ }
211
+
212
+
213
+ add_action( 'add_meta_boxes', 'wprss_add_meta_boxes');
214
+ /**
215
+ * Set up the input boxes for the wprss_feed post type
216
+ *
217
+ * @since 2.0
218
+ */
219
+ function wprss_add_meta_boxes() {
220
+ global $wprss_meta_fields;
221
+
222
+ // Remove the default WordPress Publish box, because we will be using custom ones
223
+ remove_meta_box( 'submitdiv', 'wprss_feed', 'side' );
224
+ add_meta_box(
225
+ 'submitdiv',
226
+ __('Save Feed Source'),
227
+ 'post_submit_meta_box',
228
+ 'wprss_feed',
229
+ 'side',
230
+ 'low');
231
+
232
+ /* add_meta_box(
233
+ 'wprss-save-link-side-meta',
234
+ 'Save Feed Source',
235
+ 'wprss_save_feed_source_meta_box',
236
+ 'wprss_feed',
237
+ 'side',
238
+ 'high'
239
+ );
240
+
241
+ add_meta_box(
242
+ 'wprss-save-link-bottom-meta',
243
+ __( 'Save Feed Source', 'wprss' ),
244
+ 'wprss_save_feed_source_meta_box',
245
+ 'wprss_feed',
246
+ 'normal',
247
+ 'low'
248
+ );*/
249
+
250
+ add_meta_box(
251
+ 'wprss-help-meta',
252
+ 'WP RSS Aggregator Help',
253
+ 'wprss_help_meta_box',
254
+ 'wprss_feed',
255
+ 'side',
256
+ 'low'
257
+ );
258
+
259
+ add_meta_box(
260
+ 'wprss-like-meta',
261
+ 'Like this plugin?',
262
+ 'wprss_like_meta_box',
263
+ 'wprss_feed',
264
+ 'side',
265
+ 'low'
266
+ );
267
+
268
+ add_meta_box(
269
+ 'wprss-follow-meta',
270
+ 'Follow us',
271
+ 'wprss_follow_meta_box',
272
+ 'wprss_feed',
273
+ 'side',
274
+ 'low'
275
+ );
276
+
277
+ add_meta_box(
278
+ 'custom_meta_box', // $id
279
+ __( 'Feed Source Details', 'wprss' ), // $title
280
+ 'wprss_show_meta_box', // $callback
281
+ 'wprss_feed', // $page
282
+ 'normal', // $context
283
+ 'high'); // $priority
284
+
285
+
286
+ add_meta_box(
287
+ 'preview_meta_box', // $id
288
+ __( 'Feed Preview', 'wprss' ), // $title
289
+ 'wprss_preview_meta_box', // $callback
290
+ 'wprss_feed', // $page
291
+ 'normal', // $context
292
+ 'low'); // $priority
293
+ }
294
+
295
+
296
+ /**
297
+ * Set up fields for the meta box
298
+ *
299
+ * @since 2.0
300
+ */
301
+ function wprss_custom_fields() {
302
+ $prefix = 'wprss_';
303
+
304
+ // Field Array
305
+ $wprss_meta_fields['url'] = array(
306
+ 'label' => __( 'URL', 'wprss' ),
307
+ 'desc' => __( 'Enter feed URL (including http://)', 'wprss' ),
308
+ 'id' => $prefix.'url',
309
+ 'type' => 'text'
310
+ );
311
+
312
+ $wprss_meta_fields['description'] = array(
313
+ 'label' => __( 'Description', 'wprss' ),
314
+ 'desc' => __( 'A short description about this feed source (optional)', 'wprss' ),
315
+ 'id' => $prefix.'description',
316
+ 'type' => 'textarea'
317
+ );
318
+
319
+ // for extensibility, allows more meta fields to be added
320
+ return apply_filters( 'wprss_fields', $wprss_meta_fields );
321
+ }
322
+
323
+
324
+ /**
325
+ * Set up the meta box for the wprss_feed post type
326
+ *
327
+ * @since 2.0
328
+ */
329
+ function wprss_show_meta_box() {
330
+ global $post;
331
+ $meta_fields = wprss_custom_fields();
332
+
333
+ // Use nonce for verification
334
+ echo '<input type="hidden" name="wprss_meta_box_nonce" value="' . wp_create_nonce( basename( __FILE__ ) ) . '" />';
335
+
336
+ // Begin the field table and loop
337
+ echo '<table class="form-table">';
338
+ foreach ( $meta_fields as $field ) {
339
+ // get value of this field if it exists for this post
340
+ $meta = get_post_meta( $post->ID, $field['id'], true );
341
+ // begin a table row with
342
+ echo '<tr>
343
+ <th><label for="' . $field['id'] . '">' . $field['label'] . '</label></th>
344
+ <td>';
345
+
346
+ switch( $field['type'] ) {
347
+
348
+ // text
349
+ case 'text':
350
+ echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="55" />
351
+ <br /><span class="description">'.$field['desc'].'</span>';
352
+ break;
353
+
354
+ // textarea
355
+ case 'textarea':
356
+ echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
357
+ <br /><span class="description">'.$field['desc'].'</span>';
358
+ break;
359
+
360
+ // checkbox
361
+ case 'checkbox':
362
+ echo '<input type="checkbox" name="'.$field['id'].'" id="'.$field['id'].'" ',$meta ? ' checked="checked"' : '','/>
363
+ <label for="'.$field['id'].'">'.$field['desc'].'</label>';
364
+ break;
365
+
366
+ // select
367
+ case 'select':
368
+ echo '<select name="'.$field['id'].'" id="'.$field['id'].'">';
369
+ foreach ($field['options'] as $option) {
370
+ echo '<option', $meta == $option['value'] ? ' selected="selected"' : '', ' value="'.$option['value'].'">'.$option['label'].'</option>';
371
+ }
372
+ echo '</select><br /><span class="description">'.$field['desc'].'</span>';
373
+ break;
374
+
375
+ } //end switch
376
+ echo '</td></tr>';
377
+ } // end foreach
378
+ echo '</table>'; // end table
379
+ }
380
+
381
+
382
+ add_action( 'save_post', 'wprss_save_custom_fields' );
383
+ /**
384
+ * Save the custom fields
385
+ *
386
+ * @since 2.0
387
+ */
388
+ function wprss_save_custom_fields( $post_id ) {
389
+ $meta_fields = wprss_custom_fields();
390
+
391
+ // verify nonce
392
+ if ( ! wp_verify_nonce( $_POST[ 'wprss_meta_box_nonce' ], basename( __FILE__ ) ) )
393
+ return $post_id;
394
+
395
+ // check autosave
396
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE)
397
+ return $post_id;
398
+
399
+ // check permissions
400
+ if ( 'page' == $_POST[ 'post_type' ] ) {
401
+ if ( ! current_user_can( 'edit_page', $post_id ) )
402
+ return $post_id;
403
+ } elseif ( ! current_user_can( 'edit_post', $post_id ) ) {
404
+ return $post_id;
405
+ }
406
+
407
+ // loop through fields and save the data
408
+ foreach ( $meta_fields as $field ) {
409
+ $old = get_post_meta( $post_id, $field[ 'id' ], true );
410
+ $new = $_POST[ $field[ 'id' ] ];
411
+ if ( $new && $new != $old ) {
412
+ update_post_meta( $post_id, $field[ 'id' ], $new );
413
+ } elseif ( '' == $new && $old ) {
414
+ delete_post_meta( $post_id, $field[ 'id' ], $old );
415
+ }
416
+ } // end foreach
417
+ }
418
+
419
+
420
+ /**
421
+ * Generate the Save Feed Source meta box
422
+ *
423
+ * @since 2.0
424
+ */
425
+ function wprss_save_feed_source_meta_box() {
426
+ global $post;
427
+
428
+ // insert nonce??
429
+
430
+ echo '<input type="submit" name="publish" id="publish" class="button-primary" value="Save" tabindex="5" accesskey="s">';
431
+
432
+ /**
433
+ * Check if user has disabled trash, in that case he can only delete feed sources permanently,
434
+ * else he can deactivate them. By default, if not modified in wp_config.php, EMPTY_TRASH_DAYS is set to 30.
435
+ */
436
+ if ( current_user_can( "delete_post", $post->ID ) ) {
437
+ if ( ! EMPTY_TRASH_DAYS )
438
+ $delete_text = __('Delete Permanently');
439
+ else
440
+ $delete_text = __('Move to Trash');
441
+
442
+ echo '&nbsp;&nbsp;<a class="submitdelete deletion" href="' . get_delete_post_link( $post->ID ) . '">' . $delete_text . '</a>';
443
+ }
444
+ }
445
+
446
+
447
+ /**
448
+ * Generate a preview of the latest 5 posts from the feed source being added/edited
449
+ *
450
+ * @since 2.0
451
+ */
452
+ function wprss_preview_meta_box() {
453
+ global $post;
454
+ $feed_url = get_post_meta( $post->ID, 'wprss_url', true );
455
+
456
+ if( ! empty( $feed_url ) ) {
457
+ $feed = fetch_feed( $feed_url );
458
+ if ( ! is_wp_error( $feed ) ) {
459
+ $items = $feed->get_items();
460
+
461
+ echo '<h4>Latest 5 feeds available from ' . get_the_title() . '</h4>';
462
+ $count = 0;
463
+ $feedlimit = 5;
464
+ foreach ( $items as $item ) {
465
+ echo '<ul>';
466
+ echo '<li>' . $item->get_title() . '</li>';
467
+ echo '</ul>';
468
+ if( ++$count == $feedlimit ) break; //break if count is met
469
+ }
470
+ }
471
+ else echo '<strong>Invalid feed URL</strong> - Double check the feed source URL setting above.';
472
+ }
473
+
474
+ else echo 'No feed URL defined yet';
475
+ }
476
+
477
+
478
+ /**
479
+ * Generate Help meta box
480
+ *
481
+ * @since 2.0
482
+ *
483
+ */
484
+ function wprss_help_meta_box() {
485
+ echo '<p><strong>';
486
+ _e( 'Need help?');
487
+ echo '</strong> <a target="_blank" href="http://wordpress.org/support/plugin/wp-rss-aggregator">';
488
+ _e( 'Check out the support forum');
489
+ echo '</a></p>';
490
+ }
491
+
492
+ /**
493
+ * Generate Like this plugin meta box
494
+ *
495
+ * @since 2.0
496
+ *
497
+ */
498
+ function wprss_like_meta_box() { ?>
499
+ <p><?php _e('Why not do any or all of the following') ?>:</p>
500
+ <ul>
501
+ <li><a href="http://wordpress.org/extend/plugins/wp-rss-aggregator/"><?php _e('Give it a 5 star rating on WordPress.org.') ?></a></li>
502
+ <li class="donate_link"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X9GP6BL4BLXBJ"><?php _e('Donate a token of your appreciation.'); ?></a></li>
503
+ </ul>
504
+ </p>
505
+ <?php }
506
+
507
+
508
+ /**
509
+ * Generate Like this plugin meta box
510
+ *
511
+ * @since 2.0
512
+ *
513
+ */
514
+ function wprss_follow_meta_box() {
515
+ ?>
516
+ <ul>
517
+ <li class="twitter"><a href="http://twitter.com/wpmayor"><?php _e('Follow WP Mayor on Twitter.') ?></a></li>
518
+ <li class="facebook"><a href="https://www.facebook.com/wpmayor"><?php _e('Like WP Mayor on Facebook.') ?></a></li>
519
+
520
+ </ul>
521
+ <?php }
522
+
523
+
524
+ add_filter( 'post_updated_messages', 'wprss_feed_updated_messages' );
525
+ /**
526
+ * Change default notification message when new feed is added or updated
527
+ *
528
+ * @since 2.0
529
+ */
530
+ function wprss_feed_updated_messages( $messages ) {
531
+ global $post, $post_ID;
532
+
533
+ $messages[ 'wprss_feed' ] = array(
534
+ 0 => '', // Unused. Messages start at index 1.
535
+ 1 => __( 'Feed source updated. ' ),
536
+ 2 => __( 'Custom field updated.' ),
537
+ 3 => __( 'Custom field deleted.' ),
538
+ 4 => __( 'Feed source updated.' ),
539
+ 5 => '',
540
+ 6 => __( 'Feed source saved.' ),
541
+ 7 => __( 'Feed source saved.' ),
542
+ 8 => __( 'Feed source submitted.' ),
543
+ 9 => '',
544
+ 10 => __( 'Feed source updated.' )
545
+ );
546
+
547
+ return $messages;
548
+ }
549
+
550
+
551
+ add_filter( 'post_row_actions', 'wprss_remove_row_actions', 10, 1 );
552
+ /**
553
+ * Remove actions row for imported feed items, we don't want them to be editable or viewable
554
+ *
555
+ * @since 2.0
556
+ */
557
+ function wprss_remove_row_actions( $actions )
558
+ {
559
+ if ( get_post_type() === 'wprss_feed_item' ) {
560
+ unset( $actions[ 'edit' ] );
561
+ unset( $actions[ 'view' ] );
562
+ //unset( $actions[ 'trash' ] );
563
+ unset( $actions[ 'inline hide-if-no-js' ] );
564
+ }
565
+ return $actions;
566
+ }
567
+
568
+
569
+ add_filter( 'bulk_actions-edit-wprss_feed_item', 'wprss_custom_bulk_actions' );
570
+ /**
571
+ * Remove bulk action link to edit imported feed items
572
+ *
573
+ * @since 2.0
574
+ */
575
+ function wprss_custom_bulk_actions( $actions ){
576
+ unset( $actions[ 'edit' ] );
577
+ return $actions;
578
+ }
579
+
580
+
581
+ add_action( 'admin_footer-edit.php', 'wprss_remove_a_from_feed_title' );
582
+ /**
583
+ * Remove hyperlink from imported feed titles in list posts screen
584
+ *
585
+ * @since 2.0
586
+ */
587
+ function wprss_remove_a_from_feed_title() {
588
+ if ( 'edit-wprss_feed_item' !== get_current_screen()->id )
589
+ return;
590
+ ?>
591
+
592
+ <script type="text/javascript">
593
+ jQuery('table.wp-list-table a.row-title').contents().unwrap();
594
+ </script>
595
+ <?php
596
+ }
597
+
598
+
599
+ add_action( 'add_meta_boxes', 'wprss_remove_meta_boxes', 100 );
600
+ /**
601
+ * Remove unneeded meta boxes from add feed source screen
602
+ *
603
+ * @since 2.0
604
+ */
605
+ function wprss_remove_meta_boxes() {
606
+ if ( 'wprss_feed' !== get_current_screen()->id ) return;
607
+ remove_meta_box( 'sharing_meta', 'wprss_feed' ,'advanced' );
608
+ remove_meta_box( 'content-permissions-meta-box', 'wprss_feed' ,'advanced' );
609
+ remove_meta_box( 'wpseo_meta', 'wprss_feed' ,'normal' );
610
+ remove_meta_box( 'theme-layouts-post-meta-box', 'wprss_feed' ,'side' );
611
+ remove_meta_box( 'post-stylesheets', 'wprss_feed' ,'side' );
612
+ remove_meta_box( 'hybrid-core-post-template', 'wprss_feed' ,'side' );
613
+ remove_meta_box( 'trackbacksdiv22', 'wprss_feed' ,'advanced' );
614
+ remove_action( 'post_submitbox_start', 'fpp_post_submitbox_start_action' );
615
+
616
+ }
617
+
618
+
619
+ add_filter( 'gettext', 'wprss_change_publish_button', 10, 2 );
620
+ /**
621
+ * Modify 'Publish' button text
622
+ *
623
+ * @since 2.0
624
+ */
625
+ function wprss_change_publish_button( $translation, $text ) {
626
+ if ( 'wprss_feed' == get_post_type())
627
+ if ( $text == 'Publish' )
628
+ return 'Publish Feed';
629
+
630
+ return $translation;
631
+ }
inc/deactivation.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin deactivation procedure
4
+ * @since 1.0
5
+ */
6
+ function wprss_deactivate() {
7
+ // on deactivation remove the cron job
8
+ if ( wp_next_scheduled( 'wprss_cron_hook' ) )
9
+ wp_clear_scheduled_hook( 'wprss_cron_hook' );
10
+ }
inc/shortcodes.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up shortcodes and call the main function for output
4
+ *
5
+ * @since 1.0
6
+ */
7
+ function wprss_shortcode( $atts ) {
8
+ if ( !empty ($atts) ) {
9
+ foreach ( $atts as $key => &$val ) {
10
+ $val = html_entity_decode($val);
11
+ }
12
+ }
13
+ ob_start(); //start an output buffer to output of the following function
14
+ wprss_display_feed_items( $atts );
15
+ return ob_get_clean(); //return the current buffer and clear it
16
+ }
17
+
18
+ // Register shortcodes
19
+ add_shortcode( 'wp_rss_aggregator', 'wprss_shortcode');
20
+ add_shortcode( 'wp-rss-aggregator', 'wprss_shortcode');
inc/update.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Contains all the functions related to updating the plugin from
4
+ * one version to another
5
+ *
6
+ * @package WPRSSAggregator
7
+ */
8
+
9
+ add_action( 'init', 'wprss_version_check' );
10
+ /**
11
+ * Checks the version number and runs install or update functions if needed.
12
+ *
13
+ * @since 2.0
14
+ */
15
+ function wprss_version_check() {
16
+
17
+ // Get the old database version.
18
+ $old_db_version = get_option( 'wprss_db_version' );
19
+
20
+ // Get the plugin settings.
21
+ $settings = get_option( 'wprss_settings' );
22
+
23
+ // Get the plugin options
24
+ $options = get_option( 'wprss_options' );
25
+
26
+ // For fresh installs
27
+ // If there is no old database version and no settings, run the install.
28
+ if ( empty( $old_db_version ) && false === $settings && false === $options ) {
29
+ wprss_install();
30
+ }
31
+
32
+ // For version 1.0 to 2.0
33
+ // If there is no old database version and no settings, but only options
34
+ elseif ( empty( $old_db_version ) && false === $settings && !empty( $options ) ) {
35
+ wp_clear_scheduled_hook( 'wprss_generate_hook' );
36
+ wprss_install();
37
+ wprss_migrate();
38
+ wprss_fetch_all_feed_items();
39
+ }
40
+
41
+ // For version 1.1 to 2.0
42
+ // If there is no old database version, but only settings and options
43
+ elseif ( empty( $old_db_version ) && !empty( $settings ) && !empty( $options ) ) {
44
+ wp_clear_scheduled_hook( 'wprss_generate_hook' );
45
+ wprss_update();
46
+ wprss_migrate();
47
+ wprss_fetch_all_feed_items();
48
+ }
49
+
50
+ // For any future versions where DB changes
51
+ // If the old version is less than the new version, run the update.
52
+ elseif ( intval( $old_db_version ) < intval( WPRSS_DB_VERSION ) ) {
53
+ wprss_update();
54
+ wprss_fetch_all_feed_items();
55
+ }
56
+ }
57
+
58
+
59
+ /**
60
+ * Adds the plugin settings on install.
61
+ *
62
+ * @since 2.0
63
+ */
64
+ function wprss_install() {
65
+
66
+ // Add the database version setting.
67
+ add_option( 'wprss_db_version', WPRSS_DB_VERSION );
68
+
69
+ // Add the default plugin settings.
70
+ add_option( 'wprss_settings', wprss_get_default_settings() );
71
+ }
72
+
73
+
74
+ /**
75
+ * Updates plugin settings if there are new settings to add.
76
+ *
77
+ * @since 2.0
78
+ */
79
+ function wprss_update() {
80
+
81
+ // Update the database version setting.
82
+ update_option( 'wprss_db_version', WPRSS_DB_VERSION );
83
+
84
+ // Get the settings from the database.
85
+ $settings = get_option( 'wprss_settings' );
86
+
87
+ // Get the default plugin settings.
88
+ $default_settings = wprss_get_default_settings();
89
+
90
+ // Loop through each of the default plugin settings.
91
+ foreach ( $default_settings as $setting_key => $setting_value ) {
92
+
93
+ // If the setting didn't previously exist, add the default value to the $settings array.
94
+ if ( ! isset( $settings[ $setting_key ] ) )
95
+ $settings[ $setting_key ] = $setting_value;
96
+ }
97
+
98
+ // Update the plugin settings.
99
+ update_option( 'wprss_settings', $settings );
100
+ }
101
+
102
+
103
+ /**
104
+ * Migrates the feed sources from the wprss_options field to the wp_posts table
105
+ *
106
+ * @since 2.0
107
+ */
108
+ function wprss_migrate() {
109
+
110
+ // Get the plugin options
111
+ $options = get_option( 'wprss_options' );
112
+
113
+ $feed_sources = array_chunk( $options, 2 );
114
+
115
+ foreach ( $feed_sources as $feed_source ) {
116
+ $feed_title = $feed_source[0];
117
+ $feed_url = $feed_source[1];
118
+
119
+ // Create post object
120
+ $feed_item = array(
121
+ 'post_title' => $feed_title,
122
+ 'post_content' => '',
123
+ 'post_status' => 'publish',
124
+ 'post_type' => 'wprss_feed'
125
+ );
126
+
127
+ $inserted_ID = wp_insert_post( $feed_item, $wp_error );
128
+ // insert post meta
129
+ update_post_meta( $inserted_ID, 'wprss_url', $feed_url );
130
+ }
131
+ // delete unneeded option
132
+ delete_option( 'wprss_options' );
133
+ }
134
+
135
+
136
+ /**
137
+ * Returns an array of the default plugin settings. These are only used on initial setup.
138
+ *
139
+ * @since 2.0
140
+ */
141
+ function wprss_get_default_settings() {
142
+
143
+ // Set up the default plugin settings
144
+ $settings = array(
145
+
146
+ // from version 1.1
147
+ 'open_dd' => 'New window',
148
+ 'follow_dd' => 'No follow',
149
+ // from version 2.0
150
+ 'feed_limit' => 10
151
+ );
152
+
153
+ // Return the default settings
154
+ return $settings;
155
+ }
js/custom.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ jQuery( document ).ready( function() {
2
+ jQuery( 'a.colorbox' ).colorbox(
3
+ {iframe:true, width:'80%', height:'80%'}
4
+ );
5
+ });
js/jquery.colorbox-min.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ // ColorBox v1.3.20.1 - jQuery lightbox plugin
2
+ // (c) 2012 Jack Moore - jacklmoore.com
3
+ // License: http://www.opensource.org/licenses/mit-license.php
4
+ (function(e,t,n){function G(n,r,i){var o=t.createElement(n);return r&&(o.id=s+r),i&&(o.style.cssText=i),e(o)}function Y(e){var t=T.length,n=(U+e)%t;return n<0?t+n:n}function Z(e,t){return Math.round((/%/.test(e)?(t==="x"?tt():nt())/100:1)*parseInt(e,10))}function et(e){return B.photo||/\.(gif|png|jp(e|g|eg)|bmp|ico)((#|\?).*)?$/i.test(e)}function tt(){return n.innerWidth||N.width()}function nt(){return n.innerHeight||N.height()}function rt(){var t,n=e.data(R,i);n==null?(B=e.extend({},r),console&&console.log&&console.log("Error: cboxElement missing settings object")):B=e.extend({},n);for(t in B)e.isFunction(B[t])&&t.slice(0,2)!=="on"&&(B[t]=B[t].call(R));B.rel=B.rel||R.rel||"nofollow",B.href=B.href||e(R).attr("href"),B.title=B.title||R.title,typeof B.href=="string"&&(B.href=e.trim(B.href))}function it(t,n){e.event.trigger(t),n&&n.call(R)}function st(){var e,t=s+"Slideshow_",n="click."+s,r,i,o;B.slideshow&&T[1]?(r=function(){M.text(B.slideshowStop).unbind(n).bind(f,function(){if(B.loop||T[U+1])e=setTimeout(J.next,B.slideshowSpeed)}).bind(a,function(){clearTimeout(e)}).one(n+" "+l,i),g.removeClass(t+"off").addClass(t+"on"),e=setTimeout(J.next,B.slideshowSpeed)},i=function(){clearTimeout(e),M.text(B.slideshowStart).unbind([f,a,l,n].join(" ")).one(n,function(){J.next(),r()}),g.removeClass(t+"on").addClass(t+"off")},B.slideshowAuto?r():i()):g.removeClass(t+"off "+t+"on")}function ot(t){V||(R=t,rt(),T=e(R),U=0,B.rel!=="nofollow"&&(T=e("."+o).filter(function(){var t=e.data(this,i),n;return t&&(n=t.rel||this.rel),n===B.rel}),U=T.index(R),U===-1&&(T=T.add(R),U=T.length-1)),W||(W=X=!0,g.show(),B.returnFocus&&e(R).blur().one(c,function(){e(this).focus()}),m.css({opacity:+B.opacity,cursor:B.overlayClose?"pointer":"auto"}).show(),B.w=Z(B.initialWidth,"x"),B.h=Z(B.initialHeight,"y"),J.position(),d&&N.bind("resize."+v+" scroll."+v,function(){m.css({width:tt(),height:nt(),top:N.scrollTop(),left:N.scrollLeft()})}).trigger("resize."+v),it(u,B.onOpen),H.add(A).hide(),P.html(B.close).show()),J.load(!0))}function ut(){!g&&t.body&&(Q=!1,N=e(n),g=G(K).attr({id:i,"class":p?s+(d?"IE6":"IE"):""}).hide(),m=G(K,"Overlay",d?"position:absolute":"").hide(),L=G(K,"LoadingOverlay").add(G(K,"LoadingGraphic")),y=G(K,"Wrapper"),b=G(K,"Content").append(C=G(K,"LoadedContent","width:0; height:0; overflow:hidden"),A=G(K,"Title"),O=G(K,"Current"),_=G(K,"Next"),D=G(K,"Previous"),M=G(K,"Slideshow").bind(u,st),P=G(K,"Close")),y.append(G(K).append(G(K,"TopLeft"),w=G(K,"TopCenter"),G(K,"TopRight")),G(K,!1,"clear:left").append(E=G(K,"MiddleLeft"),b,S=G(K,"MiddleRight")),G(K,!1,"clear:left").append(G(K,"BottomLeft"),x=G(K,"BottomCenter"),G(K,"BottomRight"))).find("div div").css({"float":"left"}),k=G(K,!1,"position:absolute; width:9999px; visibility:hidden; display:none"),H=_.add(D).add(O).add(M),e(t.body).append(m,g.append(y,k)))}function at(){return g?(Q||(Q=!0,j=w.height()+x.height()+b.outerHeight(!0)-b.height(),F=E.width()+S.width()+b.outerWidth(!0)-b.width(),I=C.outerHeight(!0),q=C.outerWidth(!0),g.css({"padding-bottom":j,"padding-right":F}),_.click(function(){J.next()}),D.click(function(){J.prev()}),P.click(function(){J.close()}),m.click(function(){B.overlayClose&&J.close()}),e(t).bind("keydown."+s,function(e){var t=e.keyCode;W&&B.escKey&&t===27&&(e.preventDefault(),J.close()),W&&B.arrowKey&&T[1]&&(t===37?(e.preventDefault(),D.click()):t===39&&(e.preventDefault(),_.click()))}),e("."+o,t).live("click",function(e){e.which>1||e.shiftKey||e.altKey||e.metaKey||(e.preventDefault(),ot(this))})),!0):!1}var r={transition:"elastic",speed:300,width:!1,initialWidth:"600",innerWidth:!1,maxWidth:!1,height:!1,initialHeight:"450",innerHeight:!1,maxHeight:!1,scalePhotos:!0,scrolling:!0,inline:!1,html:!1,iframe:!1,fastIframe:!0,photo:!1,href:!1,title:!1,rel:!1,opacity:.9,preloading:!0,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",xhrError:"This content failed to load.",imgError:"This image failed to load.",open:!1,returnFocus:!0,reposition:!0,loop:!0,slideshow:!1,slideshowAuto:!0,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:!1,onLoad:!1,onComplete:!1,onCleanup:!1,onClosed:!1,overlayClose:!0,escKey:!0,arrowKey:!0,top:!1,bottom:!1,left:!1,right:!1,fixed:!1,data:undefined},i="colorbox",s="cbox",o=s+"Element",u=s+"_open",a=s+"_load",f=s+"_complete",l=s+"_cleanup",c=s+"_closed",h=s+"_purge",p=!e.support.opacity&&!e.support.style,d=p&&!n.XMLHttpRequest,v=s+"_IE6",m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,$,J,K="div",Q;if(e.colorbox)return;e(ut),J=e.fn[i]=e[i]=function(t,n){var s=this;t=t||{},ut();if(at()){if(!s[0]){if(s.selector)return s;s=e("<a/>"),t.open=!0}n&&(t.onComplete=n),s.each(function(){e.data(this,i,e.extend({},e.data(this,i)||r,t))}).addClass(o),(e.isFunction(t.open)&&t.open.call(s)||t.open)&&ot(s[0])}return s},J.position=function(e,t){function f(e){w[0].style.width=x[0].style.width=b[0].style.width=e.style.width,b[0].style.height=E[0].style.height=S[0].style.height=e.style.height}var n,r=0,i=0,o=g.offset(),u,a;N.unbind("resize."+s),g.css({top:-9e4,left:-9e4}),u=N.scrollTop(),a=N.scrollLeft(),B.fixed&&!d?(o.top-=u,o.left-=a,g.css({position:"fixed"})):(r=u,i=a,g.css({position:"absolute"})),B.right!==!1?i+=Math.max(tt()-B.w-q-F-Z(B.right,"x"),0):B.left!==!1?i+=Z(B.left,"x"):i+=Math.round(Math.max(tt()-B.w-q-F,0)/2),B.bottom!==!1?r+=Math.max(nt()-B.h-I-j-Z(B.bottom,"y"),0):B.top!==!1?r+=Z(B.top,"y"):r+=Math.round(Math.max(nt()-B.h-I-j,0)/2),g.css({top:o.top,left:o.left}),e=g.width()===B.w+q&&g.height()===B.h+I?0:e||0,y[0].style.width=y[0].style.height="9999px",n={width:B.w+q,height:B.h+I,top:r,left:i},e===0&&g.css(n),g.dequeue().animate(n,{duration:e,complete:function(){f(this),X=!1,y[0].style.width=B.w+q+F+"px",y[0].style.height=B.h+I+j+"px",B.reposition&&setTimeout(function(){N.bind("resize."+s,J.position)},1),t&&t()},step:function(){f(this)}})},J.resize=function(e){W&&(e=e||{},e.width&&(B.w=Z(e.width,"x")-q-F),e.innerWidth&&(B.w=Z(e.innerWidth,"x")),C.css({width:B.w}),e.height&&(B.h=Z(e.height,"y")-I-j),e.innerHeight&&(B.h=Z(e.innerHeight,"y")),!e.innerHeight&&!e.height&&(C.css({height:"auto"}),B.h=C.height()),C.css({height:B.h}),J.position(B.transition==="none"?0:B.speed))},J.prep=function(t){function o(){return B.w=B.w||C.width(),B.w=B.mw&&B.mw<B.w?B.mw:B.w,B.w}function u(){return B.h=B.h||C.height(),B.h=B.mh&&B.mh<B.h?B.mh:B.h,B.h}if(!W)return;var n,r=B.transition==="none"?0:B.speed;C.remove(),C=G(K,"LoadedContent").append(t),C.hide().appendTo(k.show()).css({width:o(),overflow:B.scrolling?"auto":"hidden"}).css({height:u()}).prependTo(b),k.hide(),e(z).css({"float":"none"}),d&&e("select").not(g.find("select")).filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one(l,function(){this.style.visibility="inherit"}),n=function(){function y(){p&&g[0].style.removeAttribute("filter")}var t,n,o=T.length,u,a="frameBorder",l="allowTransparency",c,d,v,m;if(!W)return;c=function(){clearTimeout($),L.detach().hide(),it(f,B.onComplete)},p&&z&&C.fadeIn(100),A.html(B.title).add(C).show();if(o>1){typeof B.current=="string"&&O.html(B.current.replace("{current}",U+1).replace("{total}",o)).show(),_[B.loop||U<o-1?"show":"hide"]().html(B.next),D[B.loop||U?"show":"hide"]().html(B.previous),B.slideshow&&M.show();if(B.preloading){t=[Y(-1),Y(1)];while(n=T[t.pop()])m=e.data(n,i),m&&m.href?(d=m.href,e.isFunction(d)&&(d=d.call(n))):d=n.href,et(d)&&(v=new Image,v.src=d)}}else H.hide();B.iframe?(u=G("iframe")[0],a in u&&(u[a]=0),l in u&&(u[l]="true"),u.name=s+ +(new Date),B.fastIframe?c():e(u).one("load",c),u.src=B.href,B.scrolling||(u.scrolling="no"),e(u).addClass(s+"Iframe").appendTo(C).one(h,function(){u.src="//about:blank"})):c(),B.transition==="fade"?g.fadeTo(r,1,y):y()},B.transition==="fade"?g.fadeTo(r,0,function(){J.position(0,n)}):J.position(r,n)},J.load=function(t){var n,r,i=J.prep;X=!0,z=!1,R=T[U],t||rt(),it(h),it(a,B.onLoad),B.h=B.height?Z(B.height,"y")-I-j:B.innerHeight&&Z(B.innerHeight,"y"),B.w=B.width?Z(B.width,"x")-q-F:B.innerWidth&&Z(B.innerWidth,"x"),B.mw=B.w,B.mh=B.h,B.maxWidth&&(B.mw=Z(B.maxWidth,"x")-q-F,B.mw=B.w&&B.w<B.mw?B.w:B.mw),B.maxHeight&&(B.mh=Z(B.maxHeight,"y")-I-j,B.mh=B.h&&B.h<B.mh?B.h:B.mh),n=B.href,$=setTimeout(function(){L.show().appendTo(b)},100),B.inline?(G(K).hide().insertBefore(e(n)[0]).one(h,function(){e(this).replaceWith(C.children())}),i(e(n))):B.iframe?i(" "):B.html?i(B.html):et(n)?(e(z=new Image).addClass(s+"Photo").error(function(){B.title=!1,i(G(K,"Error").html(B.imgError))}).load(function(){var e;z.onload=null,B.scalePhotos&&(r=function(){z.height-=z.height*e,z.width-=z.width*e},B.mw&&z.width>B.mw&&(e=(z.width-B.mw)/z.width,r()),B.mh&&z.height>B.mh&&(e=(z.height-B.mh)/z.height,r())),B.h&&(z.style.marginTop=Math.max(B.h-z.height,0)/2+"px"),T[1]&&(B.loop||T[U+1])&&(z.style.cursor="pointer",z.onclick=function(){J.next()}),p&&(z.style.msInterpolationMode="bicubic"),setTimeout(function(){i(z)},1)}),setTimeout(function(){z.src=n},1)):n&&k.load(n,B.data,function(t,n,r){i(n==="error"?G(K,"Error").html(B.xhrError):e(this).contents())})},J.next=function(){!X&&T[1]&&(B.loop||T[U+1])&&(U=Y(1),J.load())},J.prev=function(){!X&&T[1]&&(B.loop||U)&&(U=Y(-1),J.load())},J.close=function(){W&&!V&&(V=!0,W=!1,it(l,B.onCleanup),N.unbind("."+s+" ."+v),m.fadeTo(200,0),g.stop().fadeTo(300,0,function(){g.add(m).css({opacity:1,cursor:"auto"}).hide(),it(h),C.remove(),setTimeout(function(){V=!1,it(c,B.onClosed)},1)}))},J.remove=function(){e([]).add(g).add(m).remove(),g=null,e("."+o).removeData(i).removeClass(o).die()},J.element=function(){return e(R)},J.settings=r})(jQuery,document,this);
readme.txt ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP RSS Aggregator ===
2
+ Contributors: jeangalea
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=X9GP6BL4BLXBJ
4
+ Plugin URI: http://wordpress.org/extend/plugins/wp-rss-aggregator/
5
+ Tags: rss, feeds, aggregation, aggregator, import, feed aggregator, rss aggregator
6
+ Requires at least: 3.3
7
+ Tested up to: 3.4
8
+ Stable tag: 2.0
9
+ Imports and merges multiple RSS Feeds using SimplePie. Outputs feeds sorted by date (latest first).
10
+
11
+ == Description ==
12
+
13
+ WP RSS Aggregator helps you create a feed reader on your WordPress site. It works in a similar fashion to RSS readers like for example Netvibes.
14
+ You can add any number of feeds through an administration panel, the plugin will then pull all the feeds from these sites, merge them and sort them by date.
15
+
16
+ The plugin uses SimplePie for the feed operations. The actual news feeds are not stored in your databases but only cached for faster response times.
17
+ You can call the function from within the theme or even use a shortcode with parameters.
18
+
19
+ = Demo =
20
+ The plugin can be seen in use on the [WPMayor.com WordPress News page](http://www.wpmayor.com/wordpress-news/)
21
+
22
+ = Credit =
23
+ Created by Jean Galea. Need a [WordPress Freelance Developer](http://www.jeangalea.com/services/wordpress-consultancy-development/)?
24
+
25
+ == Installation ==
26
+
27
+ 1. Upload the `wp-rss-aggregator` folder to the `/wp-content/plugins/` directory
28
+ 2. Activate the WP RSS Aggregator plugin through the 'Plugins' menu in WordPress
29
+ 3. Configure the plugin by going to the `RSS Aggregator` menu item that appears in your dashboard menu.
30
+ 3. Use the shortcode in your posts or pages: `[wp_rss_aggregator]`
31
+
32
+ The parameters accepted are:
33
+
34
+ * links_before
35
+ * links_after
36
+ * link_before
37
+ * link_after
38
+
39
+ An example of a shortcode with parameters:
40
+ `[wp_rss_aggregator link_before='<li class="feed-link">' link_after='</li>']`
41
+ It is advisable to use the 'HTML' view of the editor when inserting the shortcode with paramters.
42
+
43
+ An example of a function call from within the template files:
44
+ `
45
+ <?php
46
+ wprss_display_feed_items( $args = array(
47
+ 'links_before' => '<ul>',
48
+ 'links_after' => '</ul>',
49
+ 'link_before' => '<li>',
50
+ 'link_after' => '</li>'
51
+ ));
52
+ ?>
53
+ `
54
+
55
+ OR
56
+
57
+ `<?php do_shortcode('[wp-rss-aggregator]'); ?>`
58
+
59
+ You can also set whether the feed links should open in a new window, current window or even a lightbox, via the settings panel.
60
+
61
+ The settings panel also has an option to set links as nofollow for SEO purposes.
62
+
63
+ Since version 2.0 you can also specify the number of feed items shown on the frontend.
64
+
65
+ == Frequently Asked Questions ==
66
+ = How can I output the feeds in my theme? =
67
+
68
+ You can either call the function directly within the theme:
69
+ `<?php wprss_display_feed_items(); ?>`
70
+
71
+ Or use the shortcode in your posts and pages:
72
+ [wp_rss_aggregator]
73
+
74
+ == Screenshots ==
75
+
76
+ 1. The output of this plugin on the frontend, as seen on www.wpmayor.com.
77
+
78
+ 2. Admin administration panel.
79
+
80
+ 3. The settings page.
81
+
82
+ == Changelog ==
83
+
84
+ = Version 2.0 (2012-09-21) =
85
+ * Bulk of code rewritten and refactored
86
+ * Added install and upgrade functions
87
+ * Added DB version setting
88
+ * Feed sources now stored as Custom Post Types
89
+ * Feed source list sortable ascending or descending by name
90
+ * Removed days subsections in feed display
91
+ * Ability to limit total number of feeds displayed
92
+ * Feeds now fetched via Cron
93
+ * Cron job to delete old feed items, keeps max of 50 items in DB
94
+ * Now requires WordPress 3.2
95
+ * Updated colorbox to v1.3.20.1
96
+ * Limit of 15 items max imported for each source
97
+ * Fixed issue of page content displaying incorrectly after feeds
98
+
99
+
100
+ = Version 1.1 (2012-08-13) =
101
+ * Now requires WordPress 3.0
102
+ * More flexible fetching of images directory
103
+ * Has its own top level menu item
104
+ * Added settings section
105
+ * Ability to open in lightbox, new window or default browser behaviour
106
+ * Ability to set links as follow or no follow
107
+ * Using constants for oftenly used locations
108
+ * Code refactoring
109
+ * Changes in file and folder structure
110
+
111
+
112
+ = Version 1.0 (2012-01-06) =
113
+ * Initial release.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
uninstall.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // If uninstall not called from WordPress exit
3
+ if( ! defined( 'WP_UNINSTALL_PLUGIN' ) )
4
+ exit ();
5
+
6
+ // Delete option from options table
7
+ delete_option( 'wprss_options' );
8
+ delete_option( 'wprss_settings' );
9
+ delete_option( 'wprss_db_version' );
wp-rss-aggregator.php ADDED
@@ -0,0 +1,457 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP RSS Aggregator
4
+ Plugin URI: http://wordpress.org/extend/plugins/wp-rss-aggregator/
5
+ Description: Imports and merges multiple RSS Feeds using SimplePie
6
+ Version: 2.0
7
+ Author: Jean Galea
8
+ Author URI: http://www.jeangalea.com
9
+ License: GPLv3
10
+ */
11
+
12
+ /*
13
+ Copyright 2011-2012 Jean Galea (email : jean@jpgalea.com)
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+ /*
30
+ @version 2.0
31
+ @author Jean Galea <info@jeangalea.com>
32
+ @copyright Copyright (c) 2012, Jean Galea
33
+ @link http://www.jeangalea.com/
34
+ @license http://www.gnu.org/licenses/gpl.html
35
+ */
36
+
37
+
38
+ /**
39
+ * Define constants used by the plugin.
40
+ *
41
+ * We're not checking if constants are defined before setting them, as the prefix 'wprss' pretty
42
+ * much eliminates the possibility of them being set before. If there is a reasonable chance
43
+ * that they would have been set earlier or by another plugin, it's better to check before
44
+ * setting them via if !(defined).
45
+ *
46
+ */
47
+
48
+ /* Set the version number of the plugin. */
49
+ define( 'WPRSS_VERSION', '2.0', true );
50
+
51
+ /* Set the database version number of the plugin. */
52
+ define( 'WPRSS_DB_VERSION', 2 );
53
+
54
+ /* Set the plugin prefix */
55
+ define( 'WPRSS_PREFIX', 'wprss', true );
56
+
57
+ /* Set constant path to the plugin directory. */
58
+ define( 'WPRSS_DIR', plugin_dir_path( __FILE__ ) );
59
+
60
+ /* Set constant URI to the plugin URL. */
61
+ define( 'WPRSS_URI', plugin_dir_url( __FILE__ ) );
62
+
63
+ /* Set the constant path to the plugin's javascript directory. */
64
+ define( 'WPRSS_JS', WPRSS_URI . trailingslashit( 'js' ), true );
65
+
66
+ /* Set the constant path to the plugin's CSS directory. */
67
+ define( 'WPRSS_CSS', WPRSS_URI . trailingslashit( 'css' ), true );
68
+
69
+ /* Set the constant path to the plugin's images directory. */
70
+ define( 'WPRSS_IMG', WPRSS_URI . trailingslashit( 'img' ), true );
71
+
72
+ /* Set the constant path to the plugin's includes directory. */
73
+ define( 'WPRSS_INC', WPRSS_DIR . trailingslashit( 'inc' ), true );
74
+
75
+
76
+ /**
77
+ * Load required files.
78
+ */
79
+
80
+ /* Load the activation functions file. */
81
+ require_once ( WPRSS_INC . 'activation.php' );
82
+
83
+ /* Load the deactivation functions file. */
84
+ require_once ( WPRSS_INC . 'deactivation.php' );
85
+
86
+ /* Load install, upgrade and migration code. */
87
+ require_once ( WPRSS_INC . 'update.php' );
88
+
89
+ /* Load the shortcodes functions file. */
90
+ require_once ( WPRSS_INC . 'shortcodes.php' );
91
+
92
+ /* Load the admin functions file. */
93
+ require_once ( WPRSS_INC . 'admin-options.php' );
94
+
95
+ /* Load the custom post types and taxonomies. */
96
+ require_once ( WPRSS_INC . 'custom-post-types.php' );
97
+
98
+ /* Load the cron job scheduling functions. */
99
+ require_once ( WPRSS_INC . 'cron-jobs.php' );
100
+
101
+ add_action( 'init', 'wprss_schedule_fetch_feeds_cron' );
102
+ add_action( 'init', 'wprss_schedule_truncate_posts_cron' );
103
+
104
+
105
+ add_action( 'init', 'wprss_init' );
106
+ /**
107
+ * Initialise the plugin
108
+ *
109
+ * @since 2.0
110
+ */
111
+ function wprss_init() {
112
+
113
+ register_activation_hook( WPRSS_INC . 'activation.php', 'wprss_activate' );
114
+ register_deactivation_hook( WPRSS_INC . 'deactivation.php', 'wprss_deactivate' );
115
+ }
116
+
117
+
118
+ add_action( 'admin_enqueue_scripts', 'wprss_admin_scripts_styles' );
119
+ /**
120
+ * Insert required scripts, styles and filters on the admin side
121
+ *
122
+ * @since 2.0
123
+ */
124
+ function wprss_admin_scripts_styles() {
125
+ // Only load scripts if we are on this plugin's options or settings pages (admin)
126
+ if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'wprss-aggregator' || $_GET['page'] == 'wprss-aggregator-settings' ) ) {
127
+ wp_enqueue_style( 'styles', WPRSS_CSS . 'styles.css' );
128
+ }
129
+
130
+ // Only load scripts if we are on wprss_feed add post or edit post screens
131
+ $screen = get_current_screen();
132
+
133
+ if ( ( 'post' === $screen->base || 'edit' === $screen->base ) && ( 'wprss_feed' === $screen->post_type || 'wprss_feed_item' === $screen->post_type ) ) {
134
+ wp_enqueue_style( 'styles', WPRSS_CSS . 'styles.css' );
135
+ if ( 'post' === $screen->base && 'wprss_feed' === $screen->post_type ) {
136
+ // Change text on post screen from 'Enter title here' to 'Enter feed name here'
137
+ add_filter( 'enter_title_here', 'wprss_change_title_text' );
138
+ }
139
+ }
140
+ }
141
+
142
+
143
+ /**
144
+ * Change title on wprss_feed post type screen
145
+ *
146
+ * @since 2.0
147
+ */
148
+ function wprss_change_title_text() {
149
+ return "Enter feed name here (e.g. WP Mayor)";
150
+ }
151
+
152
+
153
+ add_action( 'wp_head', 'wprss_head_scripts_styles' );
154
+ /**
155
+ * Scripts and styles to be inserted into <head> section in front end
156
+ *
157
+ * @since 2.0
158
+ */
159
+ function wprss_head_scripts_styles() {
160
+ wp_enqueue_style( 'colorbox', WPRSS_CSS . 'colorbox.css' );
161
+ wp_enqueue_script( 'jquery.colorbox-min', WPRSS_JS .'jquery.colorbox-min.js', array('jquery') );
162
+ wp_enqueue_script( 'custom', WPRSS_JS .'custom.js', array('jquery','jquery.colorbox-min') );
163
+ }
164
+
165
+
166
+ /**
167
+ * Fetches feed items from sources provided
168
+ *
169
+ * @since 2.0
170
+ */
171
+ function wprss_fetch_all_feed_items( ) {
172
+
173
+ // Get all feed sources
174
+ $feed_sources = new WP_Query( array(
175
+ 'post_type' => 'wprss_feed',
176
+ 'post_status' => 'publish',
177
+ 'posts_per_page' => -1,
178
+ ) );
179
+
180
+ if( $feed_sources->have_posts() ) {
181
+ /* Start by getting one feed source, we will cycle through them one by one,
182
+ fetching feed items and adding them to the database in each pass */
183
+ while ( $feed_sources->have_posts() ) {
184
+ $feed_sources->the_post();
185
+
186
+ $feed_ID = get_the_ID();
187
+ $feed_url = get_post_meta( get_the_ID(), 'wprss_url', true );
188
+
189
+ // Use the URL custom field to fetch the feed items for this source
190
+ if( !empty( $feed_url ) ) {
191
+ $feed = fetch_feed( $feed_url );
192
+ if ( !is_wp_error( $feed ) ) {
193
+ // Figure out how many total items there are, but limit it to 10.
194
+ $maxitems = $feed->get_item_quantity(10);
195
+
196
+ // Build an array of all the items, starting with element 0 (first element).
197
+ $items = $feed->get_items( 0, $maxitems );
198
+ }
199
+ }
200
+
201
+ if ( ! empty( $items ) ) {
202
+ // Gather the permalinks of existing feed item's related to this feed source
203
+ global $wpdb;
204
+ $existing_permalinks = $wpdb->get_col(
205
+ "SELECT meta_value
206
+ FROM $wpdb->postmeta
207
+ WHERE meta_key = 'wprss_item_permalink'
208
+ AND post_id IN ( SELECT post_id FROM $wpdb->postmeta WHERE meta_value = $feed_ID)
209
+ ");
210
+
211
+ foreach ( $items as $item ) {
212
+
213
+ // Check if newly fetched item already present in existing feed item item,
214
+ // if not insert it into wp_posts and insert post meta.
215
+ if ( ! ( in_array( $item->get_permalink(), $existing_permalinks ) ) ) {
216
+ // Create post object
217
+ $feed_item = array(
218
+ 'post_title' => $item->get_title(),
219
+ 'post_content' => '',
220
+ 'post_status' => 'publish',
221
+ 'post_type' => 'wprss_feed_item'
222
+ );
223
+ $inserted_ID = wp_insert_post( $feed_item, $wp_error );
224
+
225
+ update_post_meta( $inserted_ID, 'wprss_item_permalink', $item->get_permalink() );
226
+ update_post_meta( $inserted_ID, 'wprss_item_description', $item->get_description() );
227
+ update_post_meta( $inserted_ID, 'wprss_item_date', $item->get_date( 'U' ) ); // Save as Unix timestamp format
228
+ update_post_meta( $inserted_ID, 'wprss_feed_id', $feed_ID);
229
+ } //end if
230
+ } //end foreach
231
+ } // end if
232
+ } // end $feed_sources while loop
233
+ wp_reset_postdata(); // Restore the $post global to the current post in the main query
234
+ // } // end if
235
+ } // end if
236
+ }
237
+
238
+
239
+ add_action('wp_insert_post', 'wprss_fetch_feed_items');
240
+ /**
241
+ * Fetches feed items from sources provided
242
+ *
243
+ * @since 2.0
244
+ */
245
+ function wprss_fetch_feed_items( $post_id ) {
246
+
247
+ // Get current post that triggered the hook, $post_id passed via the hook
248
+ $post = get_post( $post_id );
249
+
250
+ if( ( $post->post_type == 'wprss_feed') && ( $post->post_status == 'publish' ) ) {
251
+
252
+ // Get all feed sources
253
+ $feed_sources = new WP_Query( array(
254
+ 'post_type' => 'wprss_feed',
255
+ 'post_status' => 'publish',
256
+ 'posts_per_page' => -1,
257
+ ) );
258
+
259
+ if( $feed_sources->have_posts() ) {
260
+ // Start by getting one feed source, we will cycle through them one by one,
261
+ // fetching feed items and adding them to the database in each pass
262
+ while ( $feed_sources->have_posts() ) {
263
+ $feed_sources->the_post();
264
+
265
+ $feed_ID = get_the_ID();
266
+ $feed_url = get_post_meta( get_the_ID(), 'wprss_url', true );
267
+
268
+ // Use the URL custom field to fetch the feed items for this source
269
+ if( ! empty( $feed_url ) ) {
270
+ $feed = fetch_feed( $feed_url );
271
+ if ( ! is_wp_error( $feed ) ) {
272
+ // Figure out how many total items there are, but limit it to 10.
273
+ $maxitems = $feed->get_item_quantity(10);
274
+
275
+ // Build an array of all the items, starting with element 0 (first element).
276
+ $items = $feed->get_items(0, $maxitems);
277
+ }
278
+ }
279
+
280
+ if ( ! empty( $items ) ) {
281
+ // Gather the permalinks of existing feed item's related to this feed source
282
+ global $wpdb;
283
+ $existing_permalinks = $wpdb->get_col(
284
+ "SELECT meta_value
285
+ FROM $wpdb->postmeta
286
+ WHERE meta_key = 'wprss_item_permalink'
287
+ AND post_id IN ( SELECT post_id FROM $wpdb->postmeta WHERE meta_value = $feed_ID)
288
+ ");
289
+
290
+ foreach ( $items as $item ) {
291
+
292
+ // Check if newly fetched item already present in existing feed item item,
293
+ // if not insert it into wp_postsm and insert post meta.
294
+ if ( ! ( in_array( $item->get_permalink(), $existing_permalinks ) ) ) {
295
+ // Create post object
296
+ $feed_item = array(
297
+ 'post_title' => $item->get_title(),
298
+ 'post_content' => '',
299
+ 'post_status' => 'publish',
300
+ 'post_type' => 'wprss_feed_item'
301
+ );
302
+ $inserted_ID = wp_insert_post( $feed_item, $wp_error );
303
+
304
+ update_post_meta( $inserted_ID, 'wprss_item_permalink', $item->get_permalink() );
305
+ update_post_meta( $inserted_ID, 'wprss_item_description', $item->get_description() );
306
+ update_post_meta( $inserted_ID, 'wprss_item_date', $item->get_date( 'U' ) ); // Save as Unix timestamp format
307
+ update_post_meta( $inserted_ID, 'wprss_feed_id', $feed_ID);
308
+ } //end if
309
+ } //end foreach
310
+ } // end if
311
+ } // end $feed_sources while loop
312
+ wp_reset_postdata(); // Restore the $post global to the current post in the main query
313
+ } // end if
314
+ } // end if
315
+ }
316
+
317
+
318
+ /**
319
+ * Display feed items on the front end (via shortcode or function)
320
+ *
321
+ * @since 2.0
322
+ */
323
+ function wprss_display_feed_items( $args = array() ) {
324
+ $defaults = array(
325
+ 'links_before' => '<ul>',
326
+ 'links_after' => '</ul>',
327
+ 'link_before' => '<li>',
328
+ 'link_after' => '</li>'
329
+ );
330
+
331
+ $settings = get_option( 'wprss_settings' );
332
+ $class = '';
333
+ $open_setting = '';
334
+ $follow_setting = '';
335
+
336
+ switch ( $settings['open_dd'] ) {
337
+
338
+ case 'Lightbox' :
339
+ $class = 'class="colorbox"';
340
+ break;
341
+
342
+ case 'New window' :
343
+ $open_setting = 'target="_blank"';
344
+ break;
345
+ }
346
+
347
+ switch ( $settings['follow_dd'] ) {
348
+
349
+ case 'No follow' :
350
+ $follow_setting = 'rel="nofollow"';
351
+ break;
352
+ }
353
+
354
+ // Parse incoming $args into an array and merge it with $defaults
355
+ $args = wp_parse_args( $args, $defaults );
356
+ // Declare each item in $args as its own variable
357
+ extract( $args, EXTR_SKIP );
358
+
359
+ // Query to get all feed items for display
360
+ $feed_items = new WP_Query( array(
361
+ 'post_type' => 'wprss_feed_item',
362
+ 'posts_per_page' => $settings['feed_limit'],
363
+ 'orderby' => 'meta_value',
364
+ 'meta_key' => 'wprss_item_date',
365
+ 'order' => 'DESC',
366
+ ) );
367
+
368
+ if( $feed_items->have_posts() ) {
369
+ echo "$links_before\n";
370
+ while ( $feed_items->have_posts() ) {
371
+ $feed_items->the_post();
372
+ $permalink = get_post_meta( get_the_ID(), 'wprss_item_permalink', true );
373
+ $feed_source_id = get_post_meta( get_the_ID(), 'wprss_feed_id', true );
374
+ $source_name = get_the_title( $feed_source_id );
375
+
376
+ // convert from Unix timestamp
377
+ $date = date( 'Y-m-d', intval( get_post_meta( get_the_ID(), 'wprss_item_date', true ) ) );
378
+ echo "\t\t".'<li><a ' . $class . $open_setting . ' ' . $follow_setting . ' href="'. $permalink . '">'. get_the_title(). '</a><br>' . "\n";
379
+ echo "\t\t".'<span class="feed-source">Source: ' . $source_name . ' | ' . $date . '</span></li>'. "\n\n";
380
+ }
381
+ echo "\t\t $links_after";
382
+ echo paginate_links();
383
+
384
+ wp_reset_postdata();
385
+
386
+ } else {
387
+ echo 'No feed items found';
388
+ }
389
+ }
390
+
391
+
392
+ add_action( 'trash_wprss_feed', 'wprss_delete_feed_items' );
393
+ /**
394
+ * Delete feed items on trashing of corresponding feed source
395
+ *
396
+ * @since 2.0
397
+ */
398
+ function wprss_delete_feed_items() {
399
+ global $post;
400
+
401
+ $args = array(
402
+ 'post_type' => 'wprss_feed_item',
403
+ 'meta_key' => 'wprss_feed_id',
404
+ 'meta_value_num' => $post->ID,
405
+ 'posts_per_page' => -1
406
+ );
407
+
408
+ $feed_items = new WP_Query( $args );
409
+
410
+ if ( $feed_items->have_posts() ) :
411
+ while ( $feed_items->have_posts() ) : $feed_items->the_post();
412
+ $postid = get_the_ID();
413
+
414
+ $purge = wp_delete_post( $postid, true );
415
+ endwhile;
416
+ endif;
417
+
418
+ wp_reset_postdata();
419
+ }
420
+
421
+
422
+ /**
423
+ * Delete old feed items from the database to avoid bloat
424
+ *
425
+ * @since 2.0
426
+ */
427
+ function wprss_truncate_posts() {
428
+ global $wpdb;
429
+
430
+ // Set your threshold of max posts and post_type name
431
+ $threshold = 50;
432
+ $post_type = 'wprss_feed_item';
433
+
434
+ // Query post type
435
+ // $wpdb query allows me to select specific columns instead of grabbing the entire post object.
436
+ $query = "
437
+ SELECT ID, post_title FROM $wpdb->posts
438
+ WHERE post_type = '$post_type'
439
+ AND post_status = 'publish'
440
+ ORDER BY post_modified DESC
441
+ ";
442
+ $results = $wpdb->get_results( $query );
443
+
444
+ // Check if there are any results
445
+ if ( count( $results ) ){
446
+ foreach ( $results as $post ) {
447
+ $i++;
448
+
449
+ // Skip any posts within our threshold
450
+ if ( $i <= $threshold )
451
+ continue;
452
+
453
+ // Let the WordPress API do the heavy lifting for cleaning up entire post trails
454
+ $purge = wp_delete_post( $post->ID, true );
455
+ }
456
+ }
457
+ }