3
3
/*
4
4
* Plugin Name: One WP Feed RSS Monitor
5
5
* Description: Monitor and auto-publish podcast episodes as wordpress posts
6
- * Version: 1.0.2
6
+ * Version: 1.1.0
7
7
* Author: Victor Andeloci
8
8
* Author URI: https://github.com/victorandeloci
9
9
*/
@@ -33,12 +33,12 @@ function one_wp_feed_rss_monitor_page() {
33
33
'one_wp_feed_rss_monitor_main_js ' ,
34
34
plugin_dir_url (__FILE__ ) . 'js/main.js ' ,
35
35
[],
36
- '1.0.2 ' ,
36
+ '1.1.0 ' ,
37
37
true
38
38
);
39
39
40
40
$ options = [
41
- 'feed_url ' => get_option ('one_wp_feed_rss_monitor_feed_url ' , '' ),
41
+ 'feed_url_list ' => get_option ('one_wp_feed_rss_monitor_feed_url_list ' , '' ),
42
42
'default_category_id ' => get_option ('one_wp_feed_rss_monitor_default_cat ' , '' ),
43
43
'ids_to_terms ' => get_option ('one_wp_feed_rss_monitor_ids_to_terms ' , '' ),
44
44
];
@@ -56,7 +56,7 @@ function one_wp_feed_rss_monitor_page() {
56
56
57
57
function one_wp_feed_rss_monitor_save () {
58
58
try {
59
- update_option ('one_wp_feed_rss_monitor_feed_url ' , sanitize_text_field ($ _POST ['feed_url ' ]));
59
+ update_option ('one_wp_feed_rss_monitor_feed_url_list ' , stripslashes ($ _POST ['feed_url_list ' ]));
60
60
update_option ('one_wp_feed_rss_monitor_default_cat ' , sanitize_text_field ($ _POST ['default_category_id ' ]));
61
61
update_option ('one_wp_feed_rss_monitor_ids_to_terms ' , stripslashes ($ _POST ['ids_to_terms ' ]));
62
62
@@ -93,17 +93,25 @@ function one_wp_feed_rss_monitor_get_podcast_episodes($feed_url) {
93
93
foreach ($ rss ->channel ->item as $ item ) {
94
94
$ episode = [];
95
95
$ episode ['default_title ' ] = (string ) $ item ->title ;
96
- $ episode ['title ' ] = (string ) str_replace ('” ' , '" ' ,
97
- str_replace ('“ ' , '" ' ,
98
- str_replace ('‘ ' , "' " ,
99
- str_replace ('… ' , '... ' ,
100
- str_replace ('’ ' , "' " ,
101
- str_replace ('– ' , '- ' ,
102
- trim ($ item ->title )))))));
96
+
97
+ // title tricky chars removal
98
+ $ unwanted = [
99
+ '” ' => '" ' ,
100
+ '“ ' => '" ' ,
101
+ '‘ ' => "' " ,
102
+ '… ' => '... ' ,
103
+ '’ ' => "' " ,
104
+ '– ' => '- '
105
+ ];
106
+ $ episode ['title ' ] = strtr ( $ item ->title , $ unwanted );
107
+
103
108
$ episode ['description ' ] = (string ) $ item ->description ;
104
109
$ episode ['link ' ] = (string ) $ item ->link ;
105
110
$ episode ['mp3_url ' ] = (string ) one_wp_feed_rss_monitor_xml_attribute ($ item ->enclosure , 'url ' );
106
111
$ episode ['duration ' ] = (string ) $ item ->children ('itunes ' , true )->duration ;
112
+ $ episode ['season ' ] = (string ) $ item ->children ('itunes ' , true )->season ;
113
+ $ episode ['number ' ] = (string ) $ item ->children ('itunes ' , true )->episode ;
114
+ $ episode ['type ' ] = (string ) $ item ->children ('itunes ' , true )->episodeType ;
107
115
$ episode ['image_url ' ] = (string ) $ item ->children ('itunes ' , true )->image ->attributes ()->href ;
108
116
$ episode ['pub_date ' ] = (string ) $ item ->pubDate ;
109
117
$ episode ['tags ' ] = [];
@@ -125,7 +133,7 @@ function one_wp_feed_rss_monitor_get_podcast_episodes($feed_url) {
125
133
$ tags_str = substr ($ description , $ tags_start , $ tags_end - $ tags_start );
126
134
$ tags = explode (' ' , $ tags_str );
127
135
foreach ($ tags as $ tag ) {
128
- $ episode ['tags ' ][] = str_replace ( ' ç ' , 'c ' , str_replace ('ã ' , ' a ' , str_replace ( ' # ' , '' , $ tag) ));
136
+ $ episode ['tags ' ][] = iconv ( ' UTF-8 ' , 'ASCII//TRANSLIT ' , str_replace ('# ' , '' , $ tag ));
129
137
}
130
138
}
131
139
@@ -143,12 +151,15 @@ function one_wp_feed_rss_monitor_create_podcast_post($episode) {
143
151
'post_content ' => $ episode ['description ' ],
144
152
'post_status ' => 'publish ' ,
145
153
'post_type ' => 'post ' ,
146
- 'post_date ' => date ('Y-m-d ' , strtotime ($ episode ['pub_date ' ])),
154
+ 'post_date ' => date ('Y-m-d H:i:s ' , strtotime ($ episode ['pub_date ' ])),
147
155
'post_author ' => (get_current_user_id () ?? 1 ),
148
156
'meta_input ' => array (
149
157
'episode_link ' => $ episode ['link ' ],
150
158
'episode_mp3_url ' => $ episode ['mp3_url ' ],
151
159
'episode_duration ' => $ episode ['duration ' ],
160
+ 'episode_season ' => $ episode ['season ' ],
161
+ 'episode_number ' => $ episode ['number ' ],
162
+ 'episode_type ' => $ episode ['type ' ],
152
163
'episode_cover ' => $ episode ['image_url ' ]
153
164
)
154
165
);
@@ -201,20 +212,22 @@ function one_wp_feed_rss_monitor_create_podcast_post($episode) {
201
212
}
202
213
203
214
function one_wp_feed_rss_monitor_update_posts_episodes () {
204
- $ feed_url = get_option ('one_wp_feed_rss_monitor_feed_url ' , '' );
205
- if (!empty ($ feed_url )) {
206
- // get feed RSS eps
207
- $ episodes = one_wp_feed_rss_monitor_get_podcast_episodes ($ feed_url );
208
- if (!empty ($ episodes )) {
209
- // create posts foreach ep
210
- $ podcastPostCount = 0 ;
211
- foreach ($ episodes as $ episode ) {
212
- if (one_wp_feed_rss_monitor_create_podcast_post ($ episode ))
213
- $ podcastPostCount ++;
215
+ $ feed_url_list = get_option ('one_wp_feed_rss_monitor_feed_url_list ' , '' );
216
+ if (!empty ($ feed_url_list )) {
217
+ foreach (json_decode ($ feed_url_list ) as $ i => $ feed_url ) {
218
+ // get feed RSS eps
219
+ $ episodes = one_wp_feed_rss_monitor_get_podcast_episodes ($ feed_url );
220
+ if (!empty ($ episodes )) {
221
+ // create posts foreach ep
222
+ $ podcastPostCount = 0 ;
223
+ foreach ($ episodes as $ episode ) {
224
+ if (one_wp_feed_rss_monitor_create_podcast_post ($ episode ))
225
+ $ podcastPostCount ++;
226
+ }
227
+ echo $ podcastPostCount . ' post(s) created! ' ;
228
+ } else {
229
+ echo 'Could not find new episodes on feed ' . ($ i + 1 ) . '...<br> ' ;
214
230
}
215
- echo $ podcastPostCount . ' post(s) created! ' ;
216
- } else {
217
- echo 'Could not find new episodes... ' ;
218
231
}
219
232
} else {
220
233
echo 'Feed RSS URL not defined! ' ;
0 commit comments