FeedWordPress - Version 2020.0118

Version Description

Download this release

Release Info

Developer radgeek
Plugin Icon wp plugin FeedWordPress
Version 2020.0118
Comparing to
See all releases

Code changes from version 2017.1020 to 2020.0118

admin-ui.php CHANGED
@@ -1,741 +1,19 @@
1
  <?php
2
- class FeedWordPressAdminPage {
3
- protected $context;
4
- protected $updated = false;
5
- protected $mesg = NULL;
6
-
7
- var $link = NULL;
8
- var $dispatch = NULL;
9
- var $filename = NULL;
10
- var $pagenames = array();
11
-
12
- /**
13
- * Construct the admin page object.
14
- *
15
- * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
16
- */
17
- public function __construct( $page = 'feedwordpressadmin', $link = NULL ) {
18
- $this->link = $link;
19
-
20
- // Set meta-box context name
21
- $this->context = $page;
22
- if ($this->for_feed_settings()) :
23
- $this->context .= 'forfeed';
24
- endif;
25
- } /* FeedWordPressAdminPage constructor */
26
-
27
- public function pageslug () {
28
- $slug = preg_replace('/FeedWordPress(.*)Page/', '$1', get_class($this));
29
- return strtolower($slug);
30
- }
31
-
32
- public function pagename ($context = NULL) {
33
- if (is_null($context)) :
34
- $context = 'default';
35
- endif;
36
-
37
- if (isset($this->pagenames[$context])) :
38
- $name = $this->pagenames[$context];
39
- elseif (isset($tis->pagenames['default'])) :
40
- $name = $this->pagenames['default'];
41
- else :
42
- $name = $this->pageslug();
43
- endif;
44
- return __($name);
45
- } /* FeedWordPressAdminPage::pagename () */
46
-
47
- public function accept_POST ($post) {
48
- if ($this->for_feed_settings() and $this->update_requested_in($post)) :
49
- $this->update_feed();
50
- elseif ($this->save_requested_in($post)) : // User mashed Save Changes
51
- $this->save_settings($post);
52
- endif;
53
- do_action($this->dispatch.'_post', $post, $this);
54
- }
55
-
56
- public function update_feed () {
57
- global $feedwordpress;
58
-
59
- add_action('feedwordpress_check_feed', 'update_feeds_mention');
60
- add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
61
-
62
- $link = $this->link;
63
-
64
- print '<div class="updated">';
65
- print "<ul>";
66
- $uri = $this->link->uri();
67
- $displayUrl = $uri;
68
-
69
- // check for effects of an effective-url filter
70
- $effectiveUrl = $link->uri(array('fetch' => true));
71
- if ($uri != $effectiveUrl) : $displayUrl .= ' | ' . $effectiveUrl; endif;
72
-
73
- $delta = $feedwordpress->update($uri);
74
- print "</ul>";
75
-
76
- if (!is_null($delta)) :
77
- echo "<p><strong>Update complete.</strong>".fwp_update_set_results_message($delta)."</p>";
78
- echo "\n"; flush();
79
- else :
80
- $effectiveUrl = esc_html($effectiveUrl);
81
- echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$effectiveUrl\">$displayUrl</a></p>\n";
82
- endif;
83
- print "</div>\n";
84
- remove_action('feedwordpress_check_feed', 'update_feeds_mention');
85
- remove_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
86
- }
87
-
88
- public function save_settings ($post) {
89
- do_action($this->dispatch.'_save', $post, $this);
90
-
91
- if ($this->for_feed_settings()) :
92
- // Save settings
93
- $this->link->save_settings(/*reload=*/ true);
94
- $this->updated = true;
95
-
96
- // Reset, reload
97
- $link_id = $this->link->id;
98
- unset($this->link);
99
- $this->link = new SyndicatedLink($link_id);
100
- else :
101
- $this->updated = true;
102
- endif;
103
- } /* FeedWordPressAdminPage::save_settings () */
104
-
105
- public function for_feed_settings () { return (is_object($this->link) and method_exists($this->link, 'found') and $this->link->found()); }
106
- public function for_default_settings () { return !$this->for_feed_settings(); }
107
-
108
- public function setting ($names, $fallback_value = NULL, $params = array()) {
109
- if (!is_array($params)) :
110
- $params = array('default' => $params);
111
- endif;
112
- $params = shortcode_atts(array(
113
- 'default' => 'default',
114
- 'fallback' => true,
115
- ), $params);
116
-
117
- if (is_string($names)) :
118
- $feed_name = $names;
119
- $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names);
120
- else :
121
- $feed_name = $names['feed'];
122
- $global_name = 'feedwordpress_'.$names['global'];
123
- endif;
124
-
125
- if ($this->for_feed_settings()) : // Check feed-specific setting first; fall back to global
126
- if (!$params['fallback']) : $global_name = NULL; endif;
127
- $ret = $this->link->setting($feed_name, $global_name, $fallback_value, $params['default']);
128
- else : // Check global setting
129
- $ret = get_option($global_name, $fallback_value);
130
- endif;
131
- return $ret;
132
- }
133
-
134
- public function update_setting ($names, $value, $default = 'default') {
135
- if (is_string($names)) :
136
- $feed_name = $names;
137
- $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names);
138
- else :
139
- $feed_name = $names['feed'];
140
- $global_name = 'feedwordpress_'.$names['global'];
141
- endif;
142
-
143
- if ($this->for_feed_settings()) : // Update feed-specific setting
144
- $this->link->update_setting($feed_name, $value, $default);
145
- else : // Update global setting
146
- update_option($global_name, $value);
147
- endif;
148
- } /* FeedWordPressAdminPage::update_setting () */
149
-
150
- public function save_requested_in ($post) {
151
- return (isset($post['save']) or isset($post['submit']));
152
- }
153
- public function update_requested_in ($post) {
154
- return (isset($post['update']) and (strlen($post['update']) > 0));
155
- }
156
-
157
- public function submitted_link_id () {
158
- global $fwp_post;
159
-
160
- // Presume global unless we get a specific link ID
161
- $link_id = NULL;
162
-
163
- $submit_buttons = array(
164
- 'save',
165
- 'submit',
166
- 'fix_mismatch',
167
- 'feedfinder',
168
- );
169
- foreach ($submit_buttons as $field) :
170
- if (isset($fwp_post[$field])) :
171
- $link_id = MyPHP::request('save_link_id');
172
- endif;
173
- endforeach;
174
-
175
- if (is_null($link_id) and isset($_REQUEST['link_id'])) :
176
- $link_id = MyPHP::request('link_id');
177
- endif;
178
-
179
- return $link_id;
180
- } /* FeedWordPressAdminPage::submitted_link_id() */
181
-
182
- public function submitted_link () {
183
- $link_id = $this->submitted_link_id();
184
- if (is_numeric($link_id) and $link_id) :
185
- $link = new SyndicatedLink($link_id);
186
- else :
187
- $link = NULL;
188
- endif;
189
- return $link;
190
- } /* FeedWordPressAdminPage::submitted_link () */
191
-
192
- public function stamp_link_id ($field = null) {
193
- if (is_null($field)) : $field = 'save_link_id'; endif;
194
- ?>
195
- <input type="hidden" name="<?php print esc_attr($field); ?>" value="<?php print ($this->for_feed_settings() ? $this->link->id : '*'); ?>" />
196
- <?php
197
- } /* FeedWordPressAdminPage::stamp_link_id () */
198
-
199
- public function these_posts_phrase () {
200
- if ($this->for_feed_settings()) :
201
- $phrase = __('posts from this feed');
202
- else :
203
- $phrase = __('syndicated posts');
204
- endif;
205
- return $phrase;
206
- } /* FeedWordPressAdminPage::these_posts_phrase() */
207
-
208
- /**
209
- * Provides a uniquely identifying name for the interface context for
210
- * use with add_meta_box() and do_meta_boxes(),
211
- *
212
- * @return string the context name
213
- *
214
- * @see add_meta_box()
215
- * @see do_meta_boxes()
216
- */
217
- public function meta_box_context () {
218
- return $this->context;
219
- } /* FeedWordPressAdminPage::meta_box_context () */
220
-
221
- /**
222
- * Outputs JavaScript to fix AJAX toggles settings.
223
- *
224
- * @uses FeedWordPressAdminPage::meta_box_context()
225
- */
226
- public function fix_toggles () {
227
- FeedWordPressSettingsUI::fix_toggles_js($this->meta_box_context());
228
- } /* FeedWordPressAdminPage::fix_toggles() */
229
-
230
- public function ajax_interface_js () {
231
- ?>
232
- function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
233
- if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
234
-
235
- var rollup=document.getElementById(item);
236
- if (rollup) {
237
- if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
238
- jQuery('#'+disappear).hide();
239
- jQuery('#'+appear).show(600);
240
- } else {
241
- jQuery('#'+appear).hide();
242
- jQuery('#'+disappear).show(600);
243
- }
244
- }
245
- }
246
- <?php
247
- } /* FeedWordPressAdminPage::ajax_interface_js () */
248
-
249
- public function admin_page_href ($page, $params = array(), $link = NULL) {
250
- global $fwp_path;
251
-
252
- // Merge in the page's filename
253
- $params = array_merge($params, array('page' => $fwp_path.'/'.$page));
254
-
255
- // If there is a link ID provided, then merge that in too.
256
- if (!is_null($link)) :
257
- $link_id = NULL;
258
- if (is_object($link)) :
259
- if (method_exists($link, 'found')) :
260
- // Is this a SyndicatedLink object?
261
- if ($link->found()) :
262
- $link_id = $link->link->link_id;
263
- endif;
264
- else :
265
- // Is this a wp_links table record?
266
- $link_id = $link->link_id;
267
- endif;
268
- else :
269
- // Is this just a numeric ID?
270
- $link_id = $link;
271
- endif;
272
-
273
- if (!is_null($link_id)) :
274
- $params = array_merge($params, array('link_id' => $link_id));
275
- endif;
276
- endif;
277
-
278
- return MyPHP::url(admin_url('admin.php'), $params);
279
- } /* FeedWordPressAdminPage::admin_page_href () */
280
-
281
- public function display_feed_settings_page_links ($params = array()) {
282
- global $fwp_path;
283
-
284
- $params = wp_parse_args($params, array(
285
- 'before' => '',
286
- 'between' => ' | ',
287
- 'after' => '',
288
- 'long' => false,
289
- 'subscription' => $this->link,
290
- ));
291
- $sub = $params['subscription'];
292
-
293
- $links = array(
294
- "Feed" => array('page' => 'feeds-page.php', 'long' => 'Feeds & Updates'),
295
- "Posts" => array('page' => 'posts-page.php', 'long' => 'Posts & Links'),
296
- "Authors" => array('page' => 'authors-page.php', 'long' => 'Authors'),
297
- 'Categories' => array('page' => 'categories-page.php', 'long' => 'Categories & Tags'),
298
- );
299
-
300
- $link_id = NULL;
301
- if (is_object($sub)) :
302
- if (method_exists($sub, 'found')) :
303
- if ($sub->found()) :
304
- $link_id = $sub->link->link_id;
305
- endif;
306
- else :
307
- $link_id = $sub->link_id;
308
- endif;
309
- endif;
310
-
311
- print $params['before']; $first = true;
312
- foreach ($links as $label => $link) :
313
- if (!$first) : print $params['between']; endif;
314
-
315
- if (isset($link['url'])) : MyPHP::url($link['url'], array("link_id" => $link_id));
316
- else : $url = $this->admin_page_href($link['page'], array(), $sub);
317
- endif;
318
- $url = esc_html($url);
319
-
320
- if ($link['page']==basename($this->filename)) :
321
- print "<strong>";
322
- else :
323
- print "<a href=\"${url}\">";
324
- endif;
325
-
326
- if ($params['long']) : print esc_html(__($link['long']));
327
- else : print esc_html(__($label));
328
- endif;
329
-
330
- if ($link['page']==basename($this->filename)) :
331
- print "</strong>";
332
- else :
333
- print "</a>";
334
- endif;
335
-
336
- $first = false;
337
- endforeach;
338
- print $params['after'];
339
- } /* FeedWordPressAdminPage::display_feed_settings_page_links */
340
-
341
- public function display_feed_select_dropdown() {
342
- $links = FeedWordPress::syndicated_links();
343
-
344
- ?>
345
- <div id="fwpfs-container"><ul class="subsubsub">
346
- <li><select name="link_id" class="fwpfs" style="max-width: 20.0em;">
347
- <option value="*"<?php if ($this->for_default_settings()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
348
- <?php if ($links) : foreach ($links as $ddlink) : ?>
349
- <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($this->link) and ($this->link->id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print esc_html($ddlink->link_name); ?></option>
350
- <?php endforeach; endif; ?>
351
- </select>
352
- <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" /></li>
353
-
354
- <?php
355
- $this->display_feed_settings_page_links(array(
356
- 'before' => '<li>',
357
- 'between' => "</li>\n<li>",
358
- 'after' => '</li>',
359
- 'subscription' => $this->link,
360
- ));
361
-
362
- if ($this->for_feed_settings()) :
363
- ?>
364
- <li><input class="button" type="submit" name="update" value="Update Now" /></li>
365
- <?php
366
- endif;
367
- ?>
368
- </ul>
369
- </div>
370
- <?php
371
- } /* FeedWordPressAdminPage::display_feed_select_dropdown() */
372
-
373
- public function display_sheet_header ($pagename = 'Syndication', $all = false) {
374
- global $fwp_path;
375
- ?>
376
- <div class="icon32"><img src="<?php print esc_html( plugins_url( '/'.$fwp_path.'/feedwordpress.png') ); ?>" alt="" /></div>
377
- <h2><?php print esc_html(__($pagename.($all ? '' : ' Settings'))); ?><?php if ($this->for_feed_settings()) : ?>: <?php echo esc_html($this->link->name(/*from feed=*/ false)); ?><?php endif; ?></h2>
378
- <?php
379
- }
380
-
381
- public function display_update_notice_if_updated ($pagename = 'Syndication', $mesg = NULL) {
382
- if (!is_null($mesg)) :
383
- $this->mesg = $mesg;
384
- endif;
385
-
386
- if ($this->updated) :
387
- if ($this->updated === true) :
388
- $this->mesg = $pagename . ' settings updated.';
389
- else :
390
- $this->mesg = $this->updated;
391
- endif;
392
- endif;
393
-
394
- if (!is_null($this->mesg)) :
395
- ?>
396
- <div class="updated">
397
- <p><?php print esc_html($this->mesg); ?></p>
398
- </div>
399
- <?php
400
- endif;
401
- } /* FeedWordPressAdminPage::display_update_notice_if_updated() */
402
-
403
- public function display_settings_scope_message () {
404
- if ($this->for_feed_settings()) :
405
- ?>
406
- <p>These settings only affect posts syndicated from
407
- <strong><?php echo esc_html($this->link->link->link_name); ?></strong>.</p>
408
- <?php
409
- else :
410
- ?>
411
- <p>These settings affect posts syndicated from any feed unless they are overridden
412
- by settings for that specific feed.</p>
413
- <?php
414
- endif;
415
- } /* FeedWordPressAdminPage::display_settings_scope_message () */
416
-
417
- /*static*/ function has_link () { return true; }
418
-
419
- public function form_action ($filename = NULL) {
420
- global $fwp_path;
421
-
422
- if (is_null($filename)) :
423
- $filename = basename($this->filename);
424
- endif;
425
- return $this->admin_page_href($filename);
426
- } /* FeedWordPressAdminPage::form_action () */
427
-
428
- public function update_message () {
429
- return $this->mesg;
430
- }
431
-
432
- public function display () {
433
- global $fwp_post;
434
-
435
- if (FeedWordPress::needs_upgrade()) :
436
- fwp_upgrade_page();
437
- return;
438
- endif;
439
-
440
- FeedWordPressCompatibility::validate_http_request(/*action=*/ $this->dispatch, /*capability=*/ 'manage_links');
441
-
442
- ////////////////////////////////////////////////
443
- // Process POST request, if any ////////////////
444
- ////////////////////////////////////////////////
445
- if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
446
- $this->accept_POST($fwp_post);
447
- else :
448
- $this->updated = false;
449
- endif;
450
-
451
- ////////////////////////////////////////////////
452
- // Prepare settings page ///////////////////////
453
- ////////////////////////////////////////////////
454
-
455
- $this->display_update_notice_if_updated(
456
- $this->pagename('settings-update'),
457
- $this->update_message()
458
- );
459
-
460
- $this->open_sheet($this->pagename('open-sheet'));
461
- ?>
462
- <div id="post-body">
463
- <?php
464
- foreach ($this->boxes_by_methods as $method => $row) :
465
- if (is_array($row)) :
466
- $id = $row['id'];
467
- $title = $row['title'];
468
- else :
469
- $id = 'feedwordpress_'.$method;
470
- $title = $row;
471
- endif;
472
-
473
- add_meta_box(
474
- /*id=*/ $id,
475
- /*title=*/ $title,
476
- /*callback=*/ array($this, $method),
477
- /*page=*/ $this->meta_box_context(),
478
- /*context=*/ $this->meta_box_context()
479
- );
480
- endforeach;
481
- do_action($this->dispatch.'_meta_boxes', $this);
482
- ?>
483
- <div class="metabox-holder">
484
- <?php
485
- fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
486
- ?>
487
- </div> <!-- class="metabox-holder" -->
488
- </div> <!-- id="post-body" -->
489
- <?php $this->close_sheet(); ?>
490
- <?php
491
- }
492
-
493
- public function open_sheet ($header) {
494
- // Set up prepatory AJAX stuff
495
- ?>
496
- <script type="text/javascript">
497
- <?php
498
- $this->ajax_interface_js();
499
- ?>
500
- </script>
501
-
502
- <?php
503
- add_action(
504
- FeedWordPressCompatibility::bottom_script_hook($this->filename),
505
- /*callback=*/ array($this, 'fix_toggles'),
506
- /*priority=*/ 10000
507
- );
508
- FeedWordPressSettingsUI::ajax_nonce_fields();
509
-
510
- ?>
511
- <div class="wrap feedwordpress-admin" id="feedwordpress-admin-<?php print $this->pageslug(); ?>">
512
- <?php
513
- if (!is_null($header)) :
514
- $this->display_sheet_header($header);
515
- endif;
516
-
517
- if (!is_null($this->dispatch)) :
518
- ?>
519
- <form action="<?php print $this->form_action(); ?>" method="post">
520
- <div><?php
521
- FeedWordPressCompatibility::stamp_nonce($this->dispatch);
522
- $this->stamp_link_id();
523
- ?></div>
524
- <?php
525
- endif;
526
-
527
- if ($this->has_link()) :
528
- $this->display_settings_scope_message();
529
- endif;
530
-
531
- ?><div class="tablenav"><?php
532
- if (!is_null($this->dispatch)) :
533
- ?><div class="alignright"><?php
534
- $this->save_button();
535
- ?></div><?php
536
- endif;
537
-
538
- if ($this->has_link()) :
539
- $this->display_feed_select_dropdown();
540
- endif;
541
- ?>
542
- </div>
543
-
544
- <div id="poststuff">
545
- <?php
546
- } /* FeedWordPressAdminPage::open_sheet () */
547
-
548
- public function close_sheet () {
549
- ?>
550
-
551
- </div> <!-- id="poststuff" -->
552
- <?php
553
- if (!is_null($this->dispatch)) :
554
- $this->save_button();
555
- print "</form>\n";
556
- endif;
557
- ?>
558
- </div> <!-- class="wrap" -->
559
-
560
- <?php
561
- } /* FeedWordPressAdminPage::close_sheet () */
562
-
563
- public function setting_radio_control ($localName, $globalName, $options, $params = array()) {
564
- global $fwp_path;
565
-
566
- if (isset($params['filename'])) : $filename = $params['filename'];
567
- else : $filename = basename($this->filename);
568
- endif;
569
-
570
- if (isset($params['site-wide-url'])) : $href = $params['site-wide-url'];
571
- else : $href = $this->admin_page_href($filename);
572
- endif;
573
-
574
- if (isset($params['setting-default'])) : $settingDefault = $params['setting-default'];
575
- else : $settingDefault = NULL;
576
- endif;
577
-
578
- if (isset($params['global-setting-default'])) : $globalSettingDefault = $params['global-setting-default'];
579
- else : $globalSettingDefault = $settingDefault;
580
- endif;
581
-
582
- $globalSetting = get_option('feedwordpress_'.$globalName, $globalSettingDefault);
583
- if ($this->for_feed_settings()) :
584
- $setting = $this->link->setting($localName, NULL, $settingDefault);
585
- else :
586
- $setting = $globalSetting;
587
- endif;
588
-
589
- if (isset($params['offer-site-wide'])) : $offerSiteWide = $params['offer-site-wide'];
590
- else : $offerSiteWide = $this->for_feed_settings();
591
- endif;
592
-
593
- // This allows us to provide an alternative set of human-readable
594
- // labels for each potential value. For use in Currently: line.
595
- if (isset($params['labels'])) : $labels = $params['labels'];
596
- elseif (is_callable($options)) : $labels = NULL;
597
- else : $labels = $options;
598
- endif;
599
-
600
- if (isset($params['input-name'])) : $inputName = $params['input-name'];
601
- else : $inputName = $globalName;
602
- endif;
603
-
604
- if (isset($params['default-input-id'])) : $defaultInputId = $params['default-input-id'];
605
- else : $defaultInputId = NULL;
606
- endif;
607
-
608
- if (isset($params['default-input-id-no'])) : $defaultInputIdNo = $params['default-input-id-no'];
609
- elseif (!is_null($defaultInputId)) : $defaultInputIdNo = $defaultInputId.'-no';
610
- else : $defaultInputIdNo = NULL;
611
- endif;
612
-
613
- // This allows us to either include the site-default setting as
614
- // one of the options within the radio box, or else as a simple
615
- // yes/no toggle that controls whether or not to check another
616
- // set of inputs.
617
- if (isset($params['default-input-name'])) : $defaultInputName = $params['default-input-name'];
618
- else : $defaultInputName = $inputName;
619
- endif;
620
-
621
- if ($defaultInputName != $inputName) :
622
- $defaultInputValue = 'yes';
623
- else :
624
- $defaultInputValue = (
625
- isset($params['default-input-value'])
626
- ? $params['default-input-value']
627
- : 'site-default'
628
- );
629
- endif;
630
-
631
- $settingDefaulted = (is_null($setting) or ($settingDefault === $setting));
632
-
633
- if (!is_callable($options)) :
634
- $checked = array();
635
- if ($settingDefaulted) :
636
- $checked[$defaultInputValue] = ' checked="checked"';
637
- endif;
638
-
639
- foreach ($options as $value => $label) :
640
- if ($setting == $value) :
641
- $checked[$value] = ' checked="checked"';
642
- else :
643
- $checked[$value] = '';
644
- endif;
645
- endforeach;
646
- endif;
647
-
648
- $defaulted = array();
649
- if ($defaultInputName != $inputName) :
650
- $defaulted['yes'] = ($settingDefaulted ? ' checked="checked"' : '');
651
- $defaulted['no'] = ($settingDefaulted ? '' : ' checked="checked"');
652
- else :
653
- $defaulted['yes'] = (isset($checked[$defaultInputValue]) ? $checked[$defaultInputValue] : '');
654
- endif;
655
-
656
- if (isset($params['defaulted'])) :
657
- $defaulted['yes'] = ($params['defaulted'] ? ' checked="checked"' : '');
658
- $defaulted['no'] = ($params['defaulted'] ? '' : ' checked="checked"');
659
- endif;
660
-
661
- if ($offerSiteWide) :
662
- ?>
663
- <table class="twofer">
664
- <tbody>
665
- <tr><td class="equals first inactive">
666
- <ul class="options">
667
- <li><label><input type="radio"
668
- name="<?php print $defaultInputName; ?>"
669
- value="<?php print $defaultInputValue; ?>"
670
- <?php if (!is_null($defaultInputId)) : ?>id="<?php print $defaultInputId; ?>" <?php endif; ?>
671
- <?php print $defaulted['yes']; ?> />
672
- Use the site-wide setting</label>
673
- <span class="current-setting">Currently:
674
- <strong><?php if (is_callable($labels)) :
675
- print call_user_func($labels, $globalSetting, $defaulted, $params);
676
- elseif (is_null($labels)) :
677
- print $globalSetting;
678
- else :
679
- print $labels[$globalSetting];
680
- endif; ?></strong> (<a href="<?php print $href; ?>">change</a>)</span></li>
681
- </ul></td>
682
-
683
- <td class="equals second inactive">
684
- <?php if ($defaultInputName != $inputName) : ?>
685
- <ul class="options">
686
- <li><label><input type="radio"
687
- name="<?php print $defaultInputName; ?>"
688
- value="no"
689
- <?php if (!is_null($defaultInputIdNo)) : ?>id="<?php print $defaultInputIdNo; ?>" <?php endif; ?>
690
- <?php print $defaulted['no']; ?> />
691
- <?php _e('Do something different with this feed.'); ?></label>
692
- <?php endif;
693
- endif;
694
-
695
- // Let's spit out the controls here.
696
- if (is_callable($options)) :
697
- // Method call to print out options list
698
- call_user_func($options, $setting, $defaulted, $params);
699
- else :
700
- ?>
701
- <ul class="options">
702
- <?php foreach ($options as $value => $label) : ?>
703
- <li><label><input type="radio" name="<?php print $inputName; ?>"
704
- value="<?php print $value; ?>"
705
- <?php print $checked[$value]; ?> />
706
- <?php print $label; ?></label></li>
707
- <?php endforeach; ?>
708
- </ul> <!-- class="options" -->
709
- <?php
710
- endif;
711
-
712
- if ($offerSiteWide) :
713
- if ($defaultInputName != $inputName) :
714
- // Close the <li> and <ul class="options"> we opened above
715
- ?>
716
- </li>
717
- </ul> <!-- class="options" -->
718
- <?php
719
- endif;
720
-
721
- // Close off the twofer table that we opened up above.
722
- ?>
723
- </td></tr>
724
- </tbody>
725
- </table>
726
- <?php
727
- endif;
728
- } /* FeedWordPressAdminPage::setting_radio_control () */
729
 
730
- public function save_button ($caption = NULL) {
731
- if (is_null($caption)) : $caption = __('Save Changes'); endif;
732
- ?>
733
- <p class="submit">
734
- <input class="button-primary" type="submit" name="save" value="<?php print $caption; ?>" />
735
- </p>
736
- <?php
737
- }
738
- } /* class FeedWordPressAdminPage */
739
 
740
  function fwp_update_set_results_message ($delta, $joiner = ';') {
741
  $mesg = array();
@@ -764,21 +42,6 @@ function fwp_authors_single_submit ($link = NULL) {
764
  <?php
765
  }
766
 
767
- function fwp_option_box_opener ($legend, $id, $class = "stuffbox") {
768
- ?>
769
- <div id="<?php print $id; ?>" class="<?php print $class; ?>">
770
- <h3><?php print htmlspecialchars($legend); ?></h3>
771
- <div class="inside">
772
- <?php
773
- }
774
-
775
- function fwp_option_box_closer () {
776
- ?>
777
- </div> <!-- class="inside" -->
778
- </div> <!-- class="stuffbox" -->
779
- <?php
780
- }
781
-
782
  function fwp_tags_box ($tags, $object, $params = array()) {
783
  $params = wp_parse_args($params, array( // Default values
784
  'taxonomy' => 'post_tag',
@@ -961,112 +224,6 @@ function fwp_author_list () {
961
  return $ret;
962
  }
963
 
964
- class FeedWordPressSettingsUI {
965
- static function is_admin () {
966
- global $fwp_path;
967
-
968
- $admin_page = false; // Innocent until proven guilty
969
- if (isset($_REQUEST['page'])) :
970
- $admin_page = (
971
- is_admin()
972
- and preg_match("|^{$fwp_path}/|", $_REQUEST['page'])
973
- );
974
- endif;
975
- return $admin_page;
976
- }
977
-
978
- static function admin_scripts () {
979
- global $fwp_path;
980
-
981
- wp_enqueue_script('post'); // for magic tag and category boxes
982
- wp_enqueue_script('admin-forms'); // for checkbox selection
983
-
984
- wp_register_script('feedwordpress-elements', plugins_url('/' . $fwp_path . '/feedwordpress-elements.js') );
985
- wp_enqueue_script('feedwordpress-elements');
986
- }
987
-
988
- static function admin_styles () {
989
- ?>
990
- <style type="text/css">
991
- #feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x {
992
- background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll 0 0 transparent;
993
- }
994
-
995
- #feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x {
996
- background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll -10px 0 transparent;
997
- }
998
-
999
- .fwpfs {
1000
- background-image: url(<?php print admin_url('images/fav.png'); ?>);
1001
- background-repeat: repeat-x;
1002
- background-position: left center;
1003
- background-attachment: scroll;
1004
- }
1005
- .fwpfs.slide-down {
1006
- background-image:url(<?php print admin_url('images/fav-top.png'); ?>);
1007
- background-position:0 top;
1008
- background-repeat:repeat-x;
1009
- }
1010
-
1011
- .update-results {
1012
- max-width: 100%;
1013
- overflow: auto;
1014
- }
1015
-
1016
- </style>
1017
- <?php
1018
- } /* FeedWordPressSettingsUI::admin_styles () */
1019
-
1020
- static function ajax_nonce_fields () {
1021
- if (function_exists('wp_nonce_field')) :
1022
- echo "<form style='display: none' method='get' action=''>\n<p>\n";
1023
- wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
1024
- wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
1025
- echo "</p>\n</form>\n";
1026
- endif;
1027
- } /* FeedWordPressSettingsUI::ajax_nonce_fields () */
1028
-
1029
- static function fix_toggles_js ($context) {
1030
- ?>
1031
- <script type="text/javascript">
1032
- jQuery(document).ready( function($) {
1033
- // In case someone got here first...
1034
- $('.postbox h3, .postbox .handlediv').unbind('click');
1035
- $('.postbox h3 a').unbind('click');
1036
- $('.hide-postbox-tog').unbind('click');
1037
- $('.columns-prefs input[type="radio"]').unbind('click');
1038
- $('.meta-box-sortables').sortable('destroy');
1039
-
1040
- postboxes.add_postbox_toggles('<?php print $context; ?>');
1041
- } );
1042
- </script>
1043
- <?php
1044
- } /* FeedWordPressSettingsUI::fix_toggles_js () */
1045
-
1046
- static function magic_input_tip_js ($id) {
1047
- if (!preg_match('/^[.#]/', $id)) :
1048
- $id = '#'.$id;
1049
- endif;
1050
- ?>
1051
- <script type="text/javascript">
1052
- jQuery(document).ready( function () {
1053
- var inputBox = jQuery("<?php print $id; ?>");
1054
- var boxEl = inputBox.get(0);
1055
- if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); }
1056
- inputBox.focus(function() {
1057
- if ( this.value == this.defaultValue )
1058
- jQuery(this).val( '' ).removeClass( 'form-input-tip' );
1059
- });
1060
- inputBox.blur(function() {
1061
- if ( this.value == '' )
1062
- jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' );
1063
- });
1064
- } );
1065
- </script>
1066
- <?php
1067
- } /* FeedWordPressSettingsUI::magic_input_tip_js () */
1068
- } /* class FeedWordPressSettingsUI */
1069
-
1070
  function fwp_insert_new_user ($newuser_name) {
1071
  global $wpdb;
1072
 
@@ -1090,35 +247,10 @@ function fwp_insert_new_user ($newuser_name) {
1090
  return $ret;
1091
  } /* fwp_insert_new_user () */
1092
 
1093
- /**
1094
- * fwp_add_meta_box
1095
- *
1096
- * This function is no longer necessary, since no versions of WordPress that FWP
1097
- * still supports lack add_meta_box(). But I've left it in place for the time
1098
- * being for add-on modules that may have used it in setting up their UI.
1099
- */
1100
- function fwp_add_meta_box ($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args = null) {
1101
- return add_meta_box($id, $title, $callback, $page, $context, $priority, $callback_args);
1102
- } /* function fwp_add_meta_box () */
1103
-
1104
- function fwp_do_meta_boxes($page, $context, $object) {
1105
- $ret = do_meta_boxes($page, $context, $object);
1106
-
1107
- // Avoid JavaScript error from WordPress 2.5 bug
1108
- ?>
1109
- <div style="display: none">
1110
- <div id="tags-input"></div> <!-- avoid JS error from WP 2.5 bug -->
1111
- </div>
1112
- <?php
1113
- return $ret;
1114
- } /* function fwp_do_meta_boxes() */
1115
-
1116
- function fwp_remove_meta_box($id, $page, $context) {
1117
- return remove_meta_box($id, $page, $context);
1118
- } /* function fwp_remove_meta_box() */
1119
-
1120
  function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') {
1121
 
 
 
1122
  $subscribed = ('Y' == strtoupper($visible));
1123
  if ($subscribed or (count($links) > 0)) :
1124
  ?>
@@ -1126,14 +258,15 @@ function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible =
1126
  <thead>
1127
  <tr>
1128
  <th class="check-column" scope="col"><input type="checkbox" /></th>
1129
- <th scope="col"><?php _e('Name'); ?></th>
1130
- <th scope="col"><?php _e('Feed'); ?></th>
1131
- <th scope="col"><?php _e('Updated'); ?></th>
1132
- </tr>
1133
- </thead>
1134
-
1135
- <tbody>
1136
  <?php
 
 
 
 
 
 
 
 
1137
  $alt_row = true;
1138
  if (count($links) > 0):
1139
  foreach ($links as $link):
@@ -1149,11 +282,12 @@ function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible =
1149
 
1150
  // Prep: get last error timestamp, if any
1151
  $fileSizeLines = array();
 
1152
  if (is_null($sLink->setting('update/error'))) :
1153
  $errorsSince = '';
1154
  if (!is_null($sLink->setting('link/item count'))) :
1155
  $N = $sLink->setting('link/item count');
1156
- $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N);
1157
  endif;
1158
 
1159
  if (!is_null($sLink->setting('link/filesize'))) :
@@ -1255,7 +389,7 @@ function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible =
1255
  </div>
1256
  </td>
1257
  <?php if (strlen($link->link_rss) > 0): ?>
1258
- <td><a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></td>
1259
  <?php else: ?>
1260
  <td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
1261
  <?php endif; ?>
@@ -1263,10 +397,12 @@ function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible =
1263
  <td><div style="float: right; padding-left: 10px">
1264
  <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" />
1265
  </div>
1266
- <?php print $lastUpdated; ?>
1267
- <?php print $fileSize; ?>
1268
- <?php print $errorsSince; ?>
1269
- <?php print $nextUpdate; ?>
 
 
1270
  </td>
1271
  </tr>
1272
  <?php
1
  <?php
2
+ /**
3
+ * admin-ui.php: This is kind of a junk pile of utility functions mostly created to smooth
4
+ * out interactions to make things show up, or behave correctly, within the WordPress admin
5
+ * settings interface. Major chunks of this code that deal with making it easy for FWP,
6
+ * add-on modules, etc. to create new settings panels have since been hived off into class
7
+ * FeedWordPressAdminPage. Many of the functions that remain here were created to handle
8
+ * compatibility across multiple, sometimes very old, versions of WordPress, many of which
9
+ * are no longer supported anymore. It's likely that some of these functions will be
10
+ * re-evaluated, re-organized, deprecated, or clipped out in the next few versions.
11
+ * -cj 2017-10-27
12
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ $dir = dirname(__FILE__);
15
+ require_once("${dir}/feedwordpressadminpage.class.php");
16
+ require_once("${dir}/feedwordpresssettingsui.class.php");
 
 
 
 
 
 
17
 
18
  function fwp_update_set_results_message ($delta, $joiner = ';') {
19
  $mesg = array();
42
  <?php
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  function fwp_tags_box ($tags, $object, $params = array()) {
46
  $params = wp_parse_args($params, array( // Default values
47
  'taxonomy' => 'post_tag',
224
  return $ret;
225
  }
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  function fwp_insert_new_user ($newuser_name) {
228
  global $wpdb;
229
 
247
  return $ret;
248
  } /* fwp_insert_new_user () */
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') {
251
 
252
+ $fwp_syndicated_sources_columns = array(__('Name'), __('Feed'), __('Updated'));
253
+
254
  $subscribed = ('Y' == strtoupper($visible));
255
  if ($subscribed or (count($links) > 0)) :
256
  ?>
258
  <thead>
259
  <tr>
260
  <th class="check-column" scope="col"><input type="checkbox" /></th>
 
 
 
 
 
 
 
261
  <?php
262
+ foreach ($fwp_syndicated_sources_columns as $col) :
263
+ print "\t<th scope='col'>${col}</th>\n";
264
+ endforeach;
265
+ print "</tr>\n";
266
+ print "</thead>\n";
267
+ print "\n";
268
+ print "<tbody>\n";
269
+
270
  $alt_row = true;
271
  if (count($links) > 0):
272
  foreach ($links as $link):
282
 
283
  // Prep: get last error timestamp, if any
284
  $fileSizeLines = array();
285
+ $feed_type = $sLink->get_feed_type();
286
  if (is_null($sLink->setting('update/error'))) :
287
  $errorsSince = '';
288
  if (!is_null($sLink->setting('link/item count'))) :
289
  $N = $sLink->setting('link/item count');
290
+ $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N) . ", " . $feed_type;
291
  endif;
292
 
293
  if (!is_null($sLink->setting('link/filesize'))) :
389
  </div>
390
  </td>
391
  <?php if (strlen($link->link_rss) > 0): ?>
392
+ <td><div><a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></div></td>
393
  <?php else: ?>
394
  <td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
395
  <?php endif; ?>
397
  <td><div style="float: right; padding-left: 10px">
398
  <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" />
399
  </div>
400
+ <?php
401
+ print $lastUpdated;
402
+ print $fileSize;
403
+ print $errorsSince;
404
+ print $nextUpdate;
405
+ ?>
406
  </td>
407
  </tr>
408
  <?php
diagnostics-page.php CHANGED
@@ -15,9 +15,6 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
15
  function has_link () { return false; }
16
 
17
  function display () {
18
- global $wpdb, $wp_db_version, $fwp_path;
19
- global $fwp_post;
20
-
21
  if (FeedWordPress::needs_upgrade()) :
22
  fwp_upgrade_page();
23
  return;
@@ -27,8 +24,8 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
27
  FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_diagnostics', /*capability=*/ 'manage_options');
28
 
29
  if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
30
- $this->accept_POST($fwp_post);
31
- do_action('feedwordpress_admin_page_diagnostics_save', $fwp_post, $this);
32
  endif;
33
 
34
  ////////////////////////////////////////////////
@@ -61,7 +58,7 @@ class FeedWordPressDiagnosticsPage extends FeedWordPressAdminPage {
61
  ?>
62
  <div class="metabox-holder">
63
  <?php
64
- fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
65
  ?>
66
  </div> <!-- class="metabox-holder" -->
67
  </div> <!-- id="post-body" -->
15
  function has_link () { return false; }
16
 
17
  function display () {
 
 
 
18
  if (FeedWordPress::needs_upgrade()) :
19
  fwp_upgrade_page();
20
  return;
24
  FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_diagnostics', /*capability=*/ 'manage_options');
25
 
26
  if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
27
+ $this->accept_POST($_POST);
28
+ do_action('feedwordpress_admin_page_diagnostics_save', $_POST, $this);
29
  endif;
30
 
31
  ////////////////////////////////////////////////
58
  ?>
59
  <div class="metabox-holder">
60
  <?php
61
+ do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
62
  ?>
63
  </div> <!-- class="metabox-holder" -->
64
  </div> <!-- id="post-body" -->
feeds-page.php CHANGED
@@ -161,6 +161,17 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
161
  /*checkbox=*/ true
162
  );
163
  } /* for */
 
 
 
 
 
 
 
 
 
 
 
164
  } );
165
 
166
  <?php
@@ -186,7 +197,7 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
186
  <?php if ($page->for_default_settings()) : ?>
187
 
188
  <tr>
189
- <th scope="row">Updates:</th>
190
  <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
191
  <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
192
  <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
@@ -198,23 +209,25 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
198
  // If it's available, use it to execute `which` to try to get a realistic path to curl,
199
  // or to wget. If everything fails or shell_exec() isn't available, then just make
200
  // up something for the sake of example.
 
 
201
  $shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'));
202
 
203
  if ($shellExecAvailable) :
204
- $path = `which curl`; $opts = '--silent %s';
205
  endif;
206
 
207
- if ($shellExecAvailable and (is_null($path) or strlen(trim($path))==0)) :
208
- $path = `which wget`; $opts = '-q -O - %s';
209
  endif;
210
 
211
- if (is_null($path) or strlen(trim($path))==0) :
212
- $path = '/usr/bin/curl'; $opts = '--silent %s';
213
  endif;
214
 
215
- $path = preg_replace('/\n+$/', '', $path);
216
 
217
- $cmdline = $path . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1');
218
 
219
  ?>If you want to use a cron job,
220
  you can perform scheduled updates by sending regularly-scheduled
@@ -267,7 +280,25 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
267
  </select></td></tr>
268
 
269
  <?php endif; ?>
270
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  <tr>
272
  <th scope="row"><?php print __('Update scheduling:') ?></th>
273
  <td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
@@ -506,11 +537,7 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
506
  $cat_id = FeedWordPress::link_category_id();
507
 
508
  $params = array();
509
- if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_USES_ARGS_TAXONOMY)) :
510
- $params['taxonomy'] = 'link_category';
511
- else :
512
- $params['type'] = 'link';
513
- endif;
514
  $params['hide_empty'] = false;
515
  $results = get_categories($params);
516
 
@@ -1215,6 +1242,10 @@ class FeedWordPressFeedsPage extends FeedWordPressAdminPage {
1215
 
1216
  endif;
1217
 
 
 
 
 
1218
  if (isset($post['fetch_timeout'])) :
1219
  if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') :
1220
  $timeout = NULL;
161
  /*checkbox=*/ true
162
  );
163
  } /* for */
164
+
165
+ // Let's make the interface for the PAUSE/RESUME a bit better
166
+ jQuery('<tr id="reveal-pause-resume"><th></th><td><button id="pause-resume-reveal-button">&#8212; PAUSE or RESUME UPDATES &#8212;</button></td></tr>').insertBefore('#pause-resume');
167
+ jQuery('#pause-resume').hide();
168
+ jQuery('#pause-resume-reveal-button').click(function(ev) {
169
+ ev.preventDefault();
170
+
171
+ jQuery('#pause-resume').toggle();
172
+ return false;
173
+ });
174
+
175
  } );
176
 
177
  <?php
197
  <?php if ($page->for_default_settings()) : ?>
198
 
199
  <tr>
200
+ <th scope="row">Update Method:</th>
201
  <td><select id="automatic-updates-selector" name="automatic_updates" size="1" onchange="contextual_appearance('automatic-updates-selector', 'cron-job-explanation', null, 'no');">
202
  <option value="shutdown"<?php echo ($automatic_updates=='shutdown')?' selected="selected"':''; ?>>automatically check for updates after pages load</option>
203
  <option value="init"<?php echo ($automatic_updates=='init')?' selected="selected"':''; ?>>automatically check for updates before pages load</option>
209
  // If it's available, use it to execute `which` to try to get a realistic path to curl,
210
  // or to wget. If everything fails or shell_exec() isn't available, then just make
211
  // up something for the sake of example.
212
+ $curlOrWgetPath = NULL;
213
+
214
  $shellExecAvailable = (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec'));
215
 
216
  if ($shellExecAvailable) :
217
+ $curlOrWgetPath = `which curl`; $opts = '--silent %s';
218
  endif;
219
 
220
+ if ($shellExecAvailable and (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0)) :
221
+ $curlOrWgetPath = `which wget`; $opts = '-q -O - %s';
222
  endif;
223
 
224
+ if (is_null($curlOrWgetPath) or strlen(trim($curlOrWgetPath))==0) :
225
+ $curlOrWgetPath = '/usr/bin/curl'; $opts = '--silent %s';
226
  endif;
227
 
228
+ $curlOrWgetPath = preg_replace('/\n+$/', '', $curlOrWgetPath);
229
 
230
+ $cmdline = $curlOrWgetPath . ' ' . sprintf($opts, get_bloginfo('url').'?update_feedwordpress=1');
231
 
232
  ?>If you want to use a cron job,
233
  you can perform scheduled updates by sending regularly-scheduled
280
  </select></td></tr>
281
 
282
  <?php endif; ?>
283
+
284
+ <tr id="pause-resume">
285
+ <th scope="row"><?php print __('Pause/Resume:'); ?></th>
286
+ <td><?php
287
+ $this->setting_radio_control(
288
+ 'update/pause', 'update_pause',
289
+ /*options=*/ array(
290
+ 'no' => '<strong>UPDATE:</strong> import new posts as normal',
291
+ 'yes' => '<strong>PAUSE:</strong> do not import new posts until I unpause updates',
292
+ ),
293
+ /*params=*/ array(
294
+ 'setting-default' => NULL,
295
+ 'global-setting-default' => 'no',
296
+ 'default-input-value' => 'default',
297
+ )
298
+ );
299
+ ?></td>
300
+ </tr>
301
+
302
  <tr>
303
  <th scope="row"><?php print __('Update scheduling:') ?></th>
304
  <td><p style="margin-top:0px">How long should FeedWordPress wait between updates before it considers this feed ready to be polled for updates again?</p>
537
  $cat_id = FeedWordPress::link_category_id();
538
 
539
  $params = array();
540
+ $params['taxonomy'] = 'link_category';
 
 
 
 
541
  $params['hide_empty'] = false;
542
  $results = get_categories($params);
543
 
1242
 
1243
  endif;
1244
 
1245
+ if (isset($post['update_pause'])) :
1246
+ $this->update_setting('update/pause', $post['update_pause']);
1247
+ endif;
1248
+
1249
  if (isset($post['fetch_timeout'])) :
1250
  if (isset($post['fetch_timeout_default']) and $post['fetch_timeout_default']=='yes') :
1251
  $timeout = NULL;
feedwordpress.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://feedwordpress.radgeek.com/
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
- Version: 2017.1020
7
  Author: C. Johnson
8
  Author URI: https://feedwordpress.radgeek.com/contact/
9
  License: GPL
@@ -11,28 +11,25 @@ License: GPL
11
 
12
  /**
13
  * @package FeedWordPress
14
- * @version 2017.1020
15
  */
16
 
17
- # This uses code derived from:
18
  # - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
19
  # - SimplePie feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al.
20
  # - MagpieRSS feed parser by Kellan Elliot-McCrea <kellan@protest.net>
21
  # - Ultra-Liberal Feed Finder by Mark Pilgrim <mark@diveintomark.org>
22
  # - WordPress Blog Tool and Publishing Platform <http://wordpress.org/>
 
 
 
23
  # according to the terms of the GNU General Public License.
24
- #
25
- # INSTALLATION: see readme.txt or <http://feedwordpress.radgeek.com/install>
26
- #
27
- # USAGE: once FeedWordPress is installed, you manage just about everything from
28
- # the WordPress Dashboard, under the Syndication menu. To keep fresh content
29
- # coming in as it becomes available, you'll have to either check for updates
30
- # manually, or set up one of the automatically-scheduled update methods. See
31
- # <http://feedwordpress.radgeek.com/wiki/quick-start/> for some details.
32
-
33
- # -- Don't change these unless you know what you're doing...
34
-
35
- define ('FEEDWORDPRESS_VERSION', '2017.1020');
36
  define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://feedwordpress.radgeek.com/contact');
37
 
38
  if (!defined('FEEDWORDPRESS_BLEG')) :
@@ -41,11 +38,10 @@ endif;
41
  define('FEEDWORDPRESS_BLEG_BTC', '15EsQ9QMZtLytsaVYZUaUCmrkSMaxZBTso');
42
  define('FEEDWORDPRESS_BLEG_PAYPAL', '22PAJZZCK5Z3W');
43
 
44
- define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process
45
-
46
  // Defaults
47
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
48
  define ('DEFAULT_UPDATE_PERIOD', 60); // value in minutes
 
49
 
50
  if (isset($_REQUEST['feedwordpress_debug'])) :
51
  $feedwordpress_debug = $_REQUEST['feedwordpress_debug'];
@@ -66,9 +62,7 @@ define ('FEEDVALIDATOR_URI', 'http://feedvalidator.org/check.cgi');
66
 
67
  define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes
68
 
69
- define ('FWP_SCHEMA_HAS_USERMETA', 2966);
70
- define ('FWP_SCHEMA_USES_ARGS_TAXONOMY', 12694); // Revision # for using $args['taxonomy'] to get link categories
71
- define ('FWP_SCHEMA_30', 12694); // Database schema # for WP 3.0
72
 
73
  if (FEEDWORDPRESS_DEBUG) :
74
  // Help us to pick out errors, if any.
@@ -91,8 +85,9 @@ else :
91
  define('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT', 20);
92
  endif;
93
 
94
- // Use our the cache settings that we want.
95
- add_filter('wp_feed_cache_transient_lifetime', array('FeedWordPress', 'cache_lifetime'));
 
96
 
97
  // Dependencies: modules packaged with WordPress core
98
  $wpCoreDependencies = array(
@@ -129,7 +124,11 @@ endif;
129
  // Dependences: modules packaged with FeedWordPress plugin
130
  $dir = dirname(__FILE__);
131
  require_once("${dir}/externals/myphp/myphp.class.php");
 
 
 
132
  require_once("${dir}/admin-ui.php");
 
133
  require_once("${dir}/feedwordpresssyndicationpage.class.php");
134
  require_once("${dir}/compatability.php"); // Legacy API
135
  require_once("${dir}/syndicatedpost.class.php");
@@ -146,12 +145,21 @@ require_once("${dir}/feedwordpressrpc.class.php");
146
  require_once("${dir}/feedwordpresshttpauthenticator.class.php");
147
  require_once("${dir}/feedwordpresslocalpost.class.php");
148
 
149
- // Magic quotes are just about the stupidest thing ever.
 
 
 
 
 
 
 
 
 
 
150
  if (is_array($_POST)) :
151
  $fwp_post = $_POST;
152
- if (get_magic_quotes_gpc()) :
153
- $fwp_post = stripslashes_deep($fwp_post);
154
- endif;
155
  endif;
156
 
157
  // Get the path relative to the plugins directory in which FWP is stored
@@ -167,6 +175,10 @@ else : // Something went wrong. Let's just guess.
167
  $fwp_path = 'feedwordpress';
168
  endif;
169
 
 
 
 
 
170
  $feedwordpress = new FeedWordPress;
171
  if (!$feedwordpress->needs_upgrade()) : // only work if the conditions are safe!
172
 
@@ -281,64 +293,24 @@ if (!$feedwordpress->needs_upgrade()) : // only work if the conditions are safe!
281
  add_action('plugins_loaded', array($feedwordpress, 'admin_api'));
282
  add_action('all_admin_notices', array($feedwordpress, 'all_admin_notices'));
283
 
 
 
 
 
284
  else :
285
  # Hook in the menus, which will just point to the upgrade interface
286
  add_action('admin_menu', 'fwp_add_pages');
287
  endif; // if (!FeedWordPress::needs_upgrade())
288
 
 
 
 
 
 
289
  ################################################################################
290
  ## LOGGING FUNCTIONS: log status updates to error_log if you want it ###########
291
  ################################################################################
292
 
293
- class FeedWordPressDiagnostic {
294
- public static function feed_error ($error, $old, $link) {
295
- $wpError = $error['object'];
296
- $url = $link->uri();
297
-
298
- // check for effects of an effective-url filter
299
- $effectiveUrl = $link->uri(array('fetch' => true));
300
- if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif;
301
-
302
- $mesgs = $wpError->get_error_messages();
303
- foreach ($mesgs as $mesg) :
304
- $mesg = esc_html($mesg);
305
- FeedWordPress::diagnostic(
306
- 'updated_feeds:errors',
307
- "Feed Error: [${url}] update returned error: $mesg"
308
- );
309
-
310
- $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
311
- $span = ($error['ts'] - $error['since']);
312
-
313
- if ($span >= ($hours * 60 * 60)) :
314
- $since = date('r', $error['since']);
315
- $mostRecent = date('r', $error['ts']);
316
- FeedWordPress::diagnostic(
317
- 'updated_feeds:errors:persistent',
318
- "Feed Update Error: [${url}] returning errors"
319
- ." since ${since}:<br/><code>$mesg</code>",
320
- $url, $error['since'], $error['ts']
321
- );
322
- endif;
323
- endforeach;
324
- }
325
-
326
- function admin_emails ($id = '') {
327
- $users = get_users_of_blog($id);
328
- $recipients = array();
329
- foreach ($users as $user) :
330
- $user_id = (isset($user->user_id) ? $user->user_id : $user->ID);
331
- $dude = new WP_User($user_id);
332
- if ($dude->has_cap('administrator')) :
333
- if ($dude->user_email) :
334
- $recipients[] = $dude->user_email;
335
- endif;
336
- endif;
337
- endforeach;
338
- return $recipients;
339
- }
340
- } /* class FeedWordPressDiagnostic */
341
-
342
  function debug_out_human_readable_bytes ($quantity) {
343
  $quantity = (int) $quantity;
344
  $magnitude = 'B';
@@ -351,7 +323,7 @@ function debug_out_human_readable_bytes ($quantity) {
351
  }
352
 
353
  function debug_out_feedwordpress_footer () {
354
- if (FeedWordPress::diagnostic_on('memory_usage')) :
355
  if (function_exists('memory_get_usage')) :
356
  FeedWordPress::diagnostic ('memory_usage', "Memory: Current usage: ".debug_out_human_readable_bytes(memory_get_usage()));
357
  endif;
@@ -361,161 +333,6 @@ function debug_out_feedwordpress_footer () {
361
  endif;
362
  } /* debug_out_feedwordpress_footer() */
363
 
364
- ################################################################################
365
- ## TEMPLATE API: functions to make your templates syndication-aware ############
366
- ################################################################################
367
-
368
- /**
369
- * is_syndicated: Tests whether the current post in a Loop context, or a post
370
- * given by ID number, was syndicated by FeedWordPress. Useful for templates
371
- * to determine whether or not to retrieve syndication-related meta-data in
372
- * displaying a post.
373
- *
374
- * @param int $id The post to check for syndicated status. Defaults to the current post in a Loop context.
375
- * @return bool TRUE if the post's meta-data indicates it was syndicated; FALSE otherwise
376
- */
377
- function is_syndicated ($id = NULL) {
378
- $p = new FeedWordPressLocalPost($id);
379
- return $p->is_syndicated();
380
- } /* function is_syndicated() */
381
-
382
- function feedwordpress_display_url ($url, $before = 60, $after = 0) {
383
- $bits = parse_url($url);
384
-
385
- // Strip out crufty subdomains
386
- if (isset($bits['host'])) :
387
- $bits['host'] = preg_replace('/^www[0-9]*\./i', '', $bits['host']);
388
- endif;
389
-
390
- // Reassemble bit-by-bit with minimum of crufty elements
391
- $url = (isset($bits['user'])?$bits['user'].'@':'')
392
- .(isset($bits['host'])?$bits['host']:'')
393
- .(isset($bits['path'])?$bits['path']:'')
394
- .(isset($uri_bits['port'])?':'.$uri_bits['port']:'')
395
- .(isset($bits['query'])?'?'.$bits['query']:'');
396
-
397
- if (strlen($url) > ($before+$after)) :
398
- $url = substr($url, 0, $before).'.'.substr($url, 0 - $after, $after);
399
- endif;
400
-
401
- return $url;
402
- } /* feedwordpress_display_url () */
403
-
404
- function get_syndication_source_property ($original, $id, $local, $remote = NULL) {
405
- $p = new FeedWordPressLocalPost($id);
406
- return $p->meta($local, array("unproxy" => $original, "unproxied setting" => $remote));
407
- } /* function get_syndication_source_property () */
408
-
409
- function get_syndication_source_link ($original = NULL, $id = NULL) {
410
- $p = new FeedWordPressLocalPost($id);
411
- return $p->syndication_source_link($original);
412
- } /* function get_syndication_source_link() */
413
-
414
- function the_syndication_source_link ($original = NULL, $id = NULL) {
415
- echo get_syndication_source_link($original, $id);
416
- } /* function the_syndication_source_link() */
417
-
418
- function get_syndication_source ($original = NULL, $id = NULL) {
419
- $p = new FeedWordPressLocalPost($id);
420
- return $p->syndication_source($original);
421
- } /* function get_syndication_source() */
422
-
423
- function the_syndication_source ($original = NULL, $id = NULL) {
424
- echo get_syndication_source($original, $id);
425
- } /* function the_syndication_source () */
426
-
427
- function get_syndication_feed ($original = NULL, $id = NULL) {
428
- $p = new FeedWordPressLocalPost($id);
429
- return $p->syndication_feed($original);
430
- } /* function get_syndication_feed() */
431
-
432
- function the_syndication_feed ($original = NULL, $id = NULL) {
433
- echo get_syndication_feed($original, $id);
434
- } /* function the_syndication_feed() */
435
-
436
- function get_syndication_feed_guid ($original = NULL, $id = NULL) {
437
- $p = new FeedWordPressLocalPost($id);
438
- return $p->syndication_feed_guid($original);
439
- } /* function get_syndication_feed_guid () */
440
-
441
- function the_syndication_feed_guid ($original = NULL, $id = NULL) {
442
- echo get_syndication_feed_guid($original, $id);
443
- } /* function the_syndication_feed_guid () */
444
-
445
- function get_syndication_feed_id ($id = NULL) {
446
- $p = new FeedWordPressLocalPost($id);
447
- return $p->feed_id();
448
- } /* function get_syndication_feed_id () */
449
-
450
- function the_syndication_feed_id ($id = NULL) {
451
- echo get_syndication_feed_id($id);
452
- } /* function the_syndication_feed_id () */
453
-
454
- function get_syndication_feed_object ($id = NULL) {
455
- $p = new FeedWordPressLocalPost($id);
456
- return $p->feed();
457
- } /* function get_syndication_feed_object() */
458
-
459
- function get_feed_meta ($key, $id = NULL) {
460
- $ret = NULL;
461
-
462
- $link = get_syndication_feed_object($id);
463
- if (is_object($link) and isset($link->settings[$key])) :
464
- $ret = $link->settings[$key];
465
- endif;
466
- return $ret;
467
- } /* function get_feed_meta() */
468
-
469
- function get_syndication_permalink ($id = NULL) {
470
- $p = new FeedWordPressLocalPost($id);
471
- return $p->syndication_permalink();
472
- } /* function get_syndication_permalink () */
473
-
474
- function the_syndication_permalink ($id = NULL) {
475
- echo get_syndication_permalink($id);
476
- } /* function the_syndication_permalink () */
477
-
478
- /**
479
- * get_local_permalink: returns a string containing the internal permalink
480
- * for a post (whether syndicated or not) on your local WordPress installation.
481
- * This may be useful if you want permalinks to point to the original source of
482
- * an article for most purposes, but want to retrieve a URL for the local
483
- * representation of the post for one or two limited purposes (for example,
484
- * linking to a comments page on your local aggregator site).
485
- *
486
- * @param $id The numerical ID of the post to get the permalink for. If empty,
487
- * defaults to the current post in a Loop context.
488
- * @return string The URL of the local permalink for this post.
489
- *
490
- * @uses get_permalink()
491
- * @global $feedwordpress_the_original_permalink
492
- *
493
- * @since 2010.0217
494
- */
495
- function get_local_permalink ($id = NULL) {
496
- global $feedwordpress_the_original_permalink;
497
-
498
- // get permalink, and thus activate filter and force global to be filled
499
- // with original URL.
500
- $url = get_permalink($id);
501
- return $feedwordpress_the_original_permalink;
502
- } /* get_local_permalink() */
503
-
504
- /**
505
- * the_original_permalink: displays the contents of get_original_permalink()
506
- *
507
- * @param $id The numerical ID of the post to get the permalink for. If empty,
508
- * defaults to the current post in a Loop context.
509
- *
510
- * @uses get_local_permalinks()
511
- * @uses apply_filters
512
- *
513
- * @since 2010.0217
514
- */
515
- function the_local_permalink ($id = NULL) {
516
- print apply_filters('the_permalink', get_local_permalink($id));
517
- } /* function the_local_permalink() */
518
-
519
  ################################################################################
520
  ## FILTERS: syndication-aware handling of post data for templates and feeds ####
521
  ################################################################################
@@ -862,7 +679,7 @@ function fwp_publish_post_hook ($post_id) {
862
 
863
  add_filter('user_can_richedit', array($feedwordpress, 'user_can_richedit'), 1000, 1);
864
 
865
- if (FeedWordPress::diagnostic_on('syndicated_posts:static_meta_data')) :
866
  $inspectPostMeta = new InspectPostMeta;
867
  endif;
868
  } // function feedwordpress_add_post_edit_controls ()
@@ -882,7 +699,7 @@ function fwp_publish_post_hook ($post_id) {
882
  global $post;
883
 
884
  $frozen_values = get_post_custom_values('_syndication_freeze_updates', $post->ID);
885
- $frozen_post = (count($frozen_values) > 0 and 'yes' == $frozen_values[0]);
886
 
887
  if (is_syndicated($post->ID)) :
888
  ?>
@@ -1187,6 +1004,7 @@ class FeedWordPress {
1187
  $this->feeds = array ();
1188
  $this->feedurls = array();
1189
  $links = FeedWordPress::syndicated_links();
 
1190
  if ($links): foreach ($links as $link):
1191
  $id = intval($link->link_id);
1192
  $url = $link->link_rss;
@@ -1198,8 +1016,12 @@ class FeedWordPress {
1198
  endif;
1199
  endforeach; endif;
1200
 
1201
- add_filter('feedwordpress_update_complete', array($this, 'process_retirements'), 1000, 1);
 
1202
 
 
 
 
1203
  $this->httpauth = new FeedWordPressHTTPAuthenticator;
1204
  } /* FeedWordPress::__construct () */
1205
 
@@ -1490,7 +1312,7 @@ class FeedWordPress {
1490
 
1491
  // This should never happen.
1492
  else :
1493
- FeedWordPress::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
1494
  endif;
1495
 
1496
  else :
@@ -1713,10 +1535,6 @@ class FeedWordPress {
1713
 
1714
  wp_enqueue_style('dashboard');
1715
  wp_enqueue_style('feedwordpress-elements');
1716
-
1717
- /*if (function_exists('wp_admin_css')) :
1718
- wp_admin_css('css/dashboard');
1719
- endif;*/
1720
  endif;
1721
 
1722
  // These are a special post statuses for hiding posts that have
@@ -1765,6 +1583,27 @@ class FeedWordPress {
1765
  $this->update_magic_url();
1766
  } /* FeedWordPress::wp_loaded () */
1767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1768
  public function fwp_feeds () {
1769
  $feeds = array();
1770
  $feed_ids = $this->feeds;
@@ -2496,40 +2335,6 @@ class FeedWordPress {
2496
  } /* FeedWordPress::affirmative () */
2497
 
2498
  # Internal debugging functions
2499
- static function critical_bug ($varname, $var, $line, $file = NULL) {
2500
- global $wp_version;
2501
-
2502
- if (!is_null($file)) :
2503
- $location = "line # ${line} of ".basename($file);
2504
- else :
2505
- $location = "line # ${line}";
2506
- endif;
2507
-
2508
- print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
2509
- print "\n<plaintext>";
2510
- print "Triggered at ${location}\n";
2511
- print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n";
2512
- print "WordPress: {$wp_version}\n";
2513
- print "PHP: ".phpversion()."\n";
2514
- print "Error data: ";
2515
- print $varname.": "; var_dump($var); echo "\n";
2516
- die;
2517
- } /* FeedWordPress::critical_bug () */
2518
-
2519
- static function noncritical_bug ($varname, $var, $line, $file = NULL) {
2520
- if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging
2521
- FeedWordPress::critical_bug($varname, $var, $line, $file);
2522
- endif;
2523
- } /* FeedWordPress::noncritical_bug () */
2524
-
2525
- static function val ($v, $no_newlines = false) {
2526
- return MyPHP::val($v, $no_newlines);
2527
- } /* FeedWordPress::val () */
2528
-
2529
- static function diagnostic_on ($level) {
2530
- $show = get_option('feedwordpress_diagnostics_show', array());
2531
- return (in_array($level, $show));
2532
- } /* FeedWordPress::diagnostic_on () */
2533
 
2534
  static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL) {
2535
  global $feedwordpress_admin_footer;
@@ -2539,7 +2344,7 @@ class FeedWordPress {
2539
 
2540
  $diagnostic_nesting = count(explode(":", $level));
2541
 
2542
- if (self::diagnostic_on($level)) :
2543
  foreach ($output as $method) :
2544
  switch ($method) :
2545
  case 'echo' :
@@ -2772,9 +2577,13 @@ EOMAIL;
2772
  return $path;
2773
  } /* FeedWordPress::path () */
2774
 
2775
- // These are superceded by MyPHP::param/post/get/request, but kept
2776
- // here for backward compatibility.
2777
-
 
 
 
 
2778
  static function param ($key, $type = 'REQUEST', $default = NULL) {
2779
  return MyPHP::param($key, $default, $type);
2780
  } /* FeedWordPress::param () */
@@ -2783,6 +2592,22 @@ EOMAIL;
2783
  return MyPHP::post($key, $default);
2784
  } /* FeedWordPress::post () */
2785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2786
  } /* class FeedWordPress */
2787
 
2788
  $feedwordpress_admin_footer = array();
3
  Plugin Name: FeedWordPress
4
  Plugin URI: http://feedwordpress.radgeek.com/
5
  Description: simple and flexible Atom/RSS syndication for WordPress
6
+ Version: 2020.0118
7
  Author: C. Johnson
8
  Author URI: https://feedwordpress.radgeek.com/contact/
9
  License: GPL
11
 
12
  /**
13
  * @package FeedWordPress
14
+ * @version 2020.0118
15
  */
16
 
17
+ # This plugin uses code derived from:
18
  # - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net>
19
  # - SimplePie feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al.
20
  # - MagpieRSS feed parser by Kellan Elliot-McCrea <kellan@protest.net>
21
  # - Ultra-Liberal Feed Finder by Mark Pilgrim <mark@diveintomark.org>
22
  # - WordPress Blog Tool and Publishing Platform <http://wordpress.org/>
23
+ # - Github contributors @Flynsarmy, @BandonRandon, @david-robinson-practiceweb,
24
+ # @daidais, @thegreatmichael, @stedaniels, @alexiskulash, @quassy, @zoul0813,
25
+ # @timmmmyboy, @vobornik, and @inanimatt
26
  # according to the terms of the GNU General Public License.
27
+
28
+ ####################################################################################
29
+ ## CONSTANTS & DEFAULTS ############################################################
30
+ ####################################################################################
31
+
32
+ define ('FEEDWORDPRESS_VERSION', '2020.0118');
 
 
 
 
 
 
33
  define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://feedwordpress.radgeek.com/contact');
34
 
35
  if (!defined('FEEDWORDPRESS_BLEG')) :
38
  define('FEEDWORDPRESS_BLEG_BTC', '15EsQ9QMZtLytsaVYZUaUCmrkSMaxZBTso');
39
  define('FEEDWORDPRESS_BLEG_PAYPAL', '22PAJZZCK5Z3W');
40
 
 
 
41
  // Defaults
42
  define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors');
43
  define ('DEFAULT_UPDATE_PERIOD', 60); // value in minutes
44
+ define ('FEEDWORDPRESS_DEFAULT_CHECKIN_INTERVAL', DEFAULT_UPDATE_PERIOD/10);
45
 
46
  if (isset($_REQUEST['feedwordpress_debug'])) :
47
  $feedwordpress_debug = $_REQUEST['feedwordpress_debug'];
62
 
63
  define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes
64
 
65
+ define('FEEDWORDPRESS_BOILERPLATE_DEFAULT_HOOK_ORDER', 11000); // at the tail end of the filtering process
 
 
66
 
67
  if (FEEDWORDPRESS_DEBUG) :
68
  // Help us to pick out errors, if any.
85
  define('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT', 20);
86
  endif;
87
 
88
+ ####################################################################################
89
+ ## CORE DEPENDENCIES & PLUGIN MODULES ##############################################
90
+ ####################################################################################
91
 
92
  // Dependencies: modules packaged with WordPress core
93
  $wpCoreDependencies = array(
124
  // Dependences: modules packaged with FeedWordPress plugin
125
  $dir = dirname(__FILE__);
126
  require_once("${dir}/externals/myphp/myphp.class.php");
127
+ require_once("${dir}/feedwordpressadminpage.class.php");
128
+ require_once("${dir}/feedwordpresssettingsui.class.php");
129
+ require_once("${dir}/feedwordpressdiagnostic.class.php");
130
  require_once("${dir}/admin-ui.php");
131
+ require_once("${dir}/template-functions.php");
132
  require_once("${dir}/feedwordpresssyndicationpage.class.php");
133
  require_once("${dir}/compatability.php"); // Legacy API
134
  require_once("${dir}/syndicatedpost.class.php");
145
  require_once("${dir}/feedwordpresshttpauthenticator.class.php");
146
  require_once("${dir}/feedwordpresslocalpost.class.php");
147
 
148
+ ####################################################################################
149
+ ## GLOBAL PARAMETERS ###############################################################
150
+ ####################################################################################
151
+
152
+ // $fwp_post used to be a global variable used to make it easier to cope
153
+ // with the frustrating sometime presence of "Magic Quotes" in earlier
154
+ // versions of PHP (<http://php.net/manual/en/security.magicquotes.php>).
155
+ // Magic quotes were DEPRECATED as of PHP 5.3.0, and REMOVED as of PHP
156
+ // 5.4.0, so for the time being $fwp_post just gets a copy of $_POST.
157
+ global $fwp_post;
158
+
159
  if (is_array($_POST)) :
160
  $fwp_post = $_POST;
161
+ else:
162
+ $fwp_post = null;
 
163
  endif;
164
 
165
  // Get the path relative to the plugins directory in which FWP is stored
175
  $fwp_path = 'feedwordpress';
176
  endif;
177
 
178
+ ####################################################################################
179
+ ## FEEDWORDPRESS: INITIALIZE OBJECT AND FILTERS ####################################
180
+ ####################################################################################
181
+
182
  $feedwordpress = new FeedWordPress;
183
  if (!$feedwordpress->needs_upgrade()) : // only work if the conditions are safe!
184
 
293
  add_action('plugins_loaded', array($feedwordpress, 'admin_api'));
294
  add_action('all_admin_notices', array($feedwordpress, 'all_admin_notices'));
295
 
296
+ // Use our the cache settings that we want.
297
+ add_filter('wp_feed_cache_transient_lifetime', array('FeedWordPress', 'cache_lifetime'));
298
+
299
+
300
  else :
301
  # Hook in the menus, which will just point to the upgrade interface
302
  add_action('admin_menu', 'fwp_add_pages');
303
  endif; // if (!FeedWordPress::needs_upgrade())
304
 
305
+ register_deactivation_hook(__FILE__, 'feedwordpress_deactivate');
306
+ function feedwordpress_deactivate () {
307
+ wp_clear_scheduled_hook('fwp_scheduled_update_checkin');
308
+ } /* feedwordpress_deactivate () */
309
+
310
  ################################################################################
311
  ## LOGGING FUNCTIONS: log status updates to error_log if you want it ###########
312
  ################################################################################
313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  function debug_out_human_readable_bytes ($quantity) {
315
  $quantity = (int) $quantity;
316
  $magnitude = 'B';
323
  }
324
 
325
  function debug_out_feedwordpress_footer () {
326
+ if (FeedWordPressDiagnostic::is_on('memory_usage')) :
327
  if (function_exists('memory_get_usage')) :
328
  FeedWordPress::diagnostic ('memory_usage', "Memory: Current usage: ".debug_out_human_readable_bytes(memory_get_usage()));
329
  endif;
333
  endif;
334
  } /* debug_out_feedwordpress_footer() */
335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  ################################################################################
337
  ## FILTERS: syndication-aware handling of post data for templates and feeds ####
338
  ################################################################################
679
 
680
  add_filter('user_can_richedit', array($feedwordpress, 'user_can_richedit'), 1000, 1);
681
 
682
+ if (FeedWordPressDiagnostic::is_on('syndicated_posts:static_meta_data')) :
683
  $inspectPostMeta = new InspectPostMeta;
684
  endif;
685
  } // function feedwordpress_add_post_edit_controls ()
699
  global $post;
700
 
701
  $frozen_values = get_post_custom_values('_syndication_freeze_updates', $post->ID);
702
+ $frozen_post = ($frozen_values !== null and count($frozen_values) > 0 and 'yes' == $frozen_values[0]);
703
 
704
  if (is_syndicated($post->ID)) :
705
  ?>
1004
  $this->feeds = array ();
1005
  $this->feedurls = array();
1006
  $links = FeedWordPress::syndicated_links();
1007
+
1008
  if ($links): foreach ($links as $link):
1009
  $id = intval($link->link_id);
1010
  $url = $link->link_rss;
1016
  endif;
1017
  endforeach; endif;
1018
 
1019
+ // System-related event hooks
1020
+ add_filter('cron_schedules', array($this, 'cron_schedules'), 10, 1);
1021
 
1022
+ // FeedWordPress-related event hooks
1023
+ add_filter('feedwordpress_update_complete', array($this, 'process_retirements'), 1000, 1);
1024
+
1025
  $this->httpauth = new FeedWordPressHTTPAuthenticator;
1026
  } /* FeedWordPress::__construct () */
1027
 
1312
 
1313
  // This should never happen.
1314
  else :
1315
+ FeedWordPressDiagnostic::critical_bug('FeedWordPress::stale::last', $last, __LINE__, __FILE__);
1316
  endif;
1317
 
1318
  else :
1535
 
1536
  wp_enqueue_style('dashboard');
1537
  wp_enqueue_style('feedwordpress-elements');
 
 
 
 
1538
  endif;
1539
 
1540
  // These are a special post statuses for hiding posts that have
1583
  $this->update_magic_url();
1584
  } /* FeedWordPress::wp_loaded () */
1585
 
1586
+ /**
1587
+ * FeedWordPress::cron_schedules(): Filter hook to add WP-Cron schedules
1588
+ * that plugins like FeedWordPress can use to carry out scheduled events.
1589
+ *
1590
+ * @param array $schedules An associative array containing the current set of cron schedules (hourly, daily, etc.)
1591
+ * @return array The same array, with a new entry ('fwp_checkin_interval') added to the list.
1592
+ *
1593
+ * @since 2017.1021
1594
+ */
1595
+ public function cron_schedules ($schedules) {
1596
+ $interval = FEEDWORDPRESS_DEFAULT_CHECKIN_INTERVAL*60 /*sec/min*/;
1597
+
1598
+ // add 'fwp_checkin_interval' to the existing set
1599
+ $schedules['fwp_checkin_interval'] = array(
1600
+ 'interval' => $interval,
1601
+ 'display' => 'FeedWordPress update schedule check-in',
1602
+ );
1603
+
1604
+ return $schedules;
1605
+ } /* FeedWordPress::cron_schedules () */
1606
+
1607
  public function fwp_feeds () {
1608
  $feeds = array();
1609
  $feed_ids = $this->feeds;
2335
  } /* FeedWordPress::affirmative () */
2336
 
2337
  # Internal debugging functions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2338
 
2339
  static function diagnostic ($level, $out, $persist = NULL, $since = NULL, $mostRecent = NULL) {
2340
  global $feedwordpress_admin_footer;
2344
 
2345
  $diagnostic_nesting = count(explode(":", $level));
2346
 
2347
+ if (FeedWordPressDiagnostic::is_on($level)) :
2348
  foreach ($output as $method) :
2349
  switch ($method) :
2350
  case 'echo' :
2577
  return $path;
2578
  } /* FeedWordPress::path () */
2579
 
2580
+ // -- DEPRCATED UTILITY FUNCTIONS -------------------------------------
2581
+ // These are superceded by later code re-organization, (for example
2582
+ // MyPHP::param/post/get/request, or FeedWordPressDiagnostic methods),
2583
+ // but for the last several versions have been kept here for backward
2584
+ // compatibility with add-ons, older code, etc. Maybe someday they
2585
+ // will go away.
2586
+ // -------------------------------------------------------------------
2587
  static function param ($key, $type = 'REQUEST', $default = NULL) {
2588
  return MyPHP::param($key, $default, $type);
2589
  } /* FeedWordPress::param () */
2592
  return MyPHP::post($key, $default);
2593
  } /* FeedWordPress::post () */
2594
 
2595
+ static function val ($v, $no_newlines = false) {
2596
+ return MyPHP::val($v, $no_newlines);
2597
+ } /* FeedWordPress::val () */
2598
+
2599
+ static function critical_bug ($varname, $var, $line, $file = NULL) {
2600
+ FeedWordPressDiagnostic::critical_bug($varname, $var, $line, $file);
2601
+ } /* FeedWordPress::critical_bug () */
2602
+
2603
+ static function noncritical_bug ($varname, $var, $line, $file = NULL) {
2604
+ FeedWordPressDiagnostic::noncritical_bug($varname, $var, $line, $file);
2605
+ } /* FeedWordPress::noncritical_bug () */
2606
+
2607
+ static function diagnostic_on ($level) {
2608
+ return FeedWordPressDiagnostic::is_on($level);
2609
+ } /* FeedWordPress::diagnostic_on () */
2610
+
2611
  } /* class FeedWordPress */
2612
 
2613
  $feedwordpress_admin_footer = array();
feedwordpress_parser.class.php CHANGED
@@ -1,6 +1,19 @@
1
  <?php
2
  class FeedWordPress_Parser extends SimplePie_Parser {
3
  function reset_parser (&$xml) {
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  xml_parser_free($xml);
5
 
6
  $xml = xml_parser_create_ns($this->encoding, $this->separator);
@@ -12,7 +25,7 @@ class FeedWordPress_Parser extends SimplePie_Parser {
12
  xml_set_start_namespace_decl_handler($xml, 'start_xmlns');
13
  }
14
 
15
- function parse (&$data, $encoding) {
16
  $data = apply_filters('feedwordpress_parser_parse', $data, $encoding, $this);
17
 
18
  // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
@@ -95,32 +108,28 @@ class FeedWordPress_Parser extends SimplePie_Parser {
95
  $endOfJunk = strpos($data, '<?xml');
96
  if (!$parseResults and $endOfJunk > 0) :
97
  // There is some junk before the feed prolog. Try to get rid of it.
98
- $newData = substr($data, $endOfJunk);
99
- $newData = trim($newData);
100
  $this->reset_parser($xml);
101
 
102
- $parseResults = xml_parse($xml, $newData, true);
103
  endif;
104
 
105
- if (!$parseResults)
106
- {
107
- if (class_exists('DOMDocument')) :
108
- libxml_use_internal_errors(true);
109
- $doc = new DOMDocument;
110
- $doc->loadHTML('<html>'.$data.'</html>');
111
- ///*DBG*/ echo "<plaintext>";
112
- ///*DBG*/ $dd = $doc->getElementsByTagName('html');
113
- ///*DBG*/ for ($i = 0; $i < $dd->length; $i++) :
114
- ///*DBG*/ var_dump($dd->item($i)->nodeName);
115
- ///*DBG*/ endfor;
116
- ///*DBG*/ var_dump($doc);
117
- libxml_use_internal_errors(false);
118
- ///*DBG*/ die;
119
- endif;
120
-
121
  $this->error_code = xml_get_error_code($xml);
122
  $this->error_string = xml_error_string($this->error_code);
123
- ///*DBG*/ echo "WOOGA WOOGA"; var_dump($this->error_string); die;
124
  $return = false;
125
  }
126
 
@@ -240,5 +249,281 @@ class FeedWordPress_Parser extends SimplePie_Parser {
240
  endif;
241
  return true;
242
  } /* FeedWordPress_Parser::start_xmlns() */
243
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
 
1
  <?php
2
  class FeedWordPress_Parser extends SimplePie_Parser {
3
  function reset_parser (&$xml) {
4
+ // reset members
5
+ $this->namespace = array('');
6
+ $this->element = array('');
7
+ $this->xml_base = array('');
8
+ $this->xml_base_explicit = array(false);
9
+ $this->xml_lang = array('');
10
+ $this->data = array();
11
+ $this->datas = array(array());
12
+ $this->current_xhtml_construct = -1;
13
+ $this->xmlns_stack = array();
14
+ $this->xmlns_current = array();
15
+
16
+ // reset libxml parser
17
  xml_parser_free($xml);
18
 
19
  $xml = xml_parser_create_ns($this->encoding, $this->separator);
25
  xml_set_start_namespace_decl_handler($xml, 'start_xmlns');
26
  }
27
 
28
+ public function parse (&$data, $encoding) {
29
  $data = apply_filters('feedwordpress_parser_parse', $data, $encoding, $this);
30
 
31
  // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
108
  $endOfJunk = strpos($data, '<?xml');
109
  if (!$parseResults and $endOfJunk > 0) :
110
  // There is some junk before the feed prolog. Try to get rid of it.
111
+ $data = substr($data, $endOfJunk);
112
+ $data = trim($data);
113
  $this->reset_parser($xml);
114
 
115
+ $parseResults = xml_parse($xml, $data, true);
116
  endif;
117
 
118
+ $badEntity = (xml_get_error_code($xml) == 26);
119
+ if (!$parseResults and $badEntity) :
120
+ // There was an entity that libxml couldn't understand.
121
+ // Chances are, it was a stray HTML entity. So let's try
122
+ // converting all the named HTML entities to numeric XML
123
+ // entities and starting over.
124
+ $data = $this->html_convert_entities($data);
125
+ $this->reset_parser($xml);
126
+
127
+ $parseResults = xml_parse($xml, $data, true);
128
+ endif;
129
+
130
+ if (!$parseResults) {
 
 
 
131
  $this->error_code = xml_get_error_code($xml);
132
  $this->error_string = xml_error_string($this->error_code);
 
133
  $return = false;
134
  }
135
 
249
  endif;
250
  return true;
251
  } /* FeedWordPress_Parser::start_xmlns() */
252
+
253
+ /* html_convert_entities($string) -- convert named HTML entities to
254
+ * XML-compatible numeric entities. Adapted from code by @inanimatt:
255
+ * https://gist.github.com/inanimatt/879249
256
+ */
257
+ public function html_convert_entities($string) {
258
+ return preg_replace_callback('/&([a-zA-Z][a-zA-Z0-9]+);/S',
259
+ array($this, 'convert_entity'), $string);
260
+ }
261
+
262
+ /* Swap HTML named entity with its numeric equivalent. If the entity
263
+ * isn't in the lookup table, this function returns a blank, which
264
+ * destroys the character in the output - this is probably the
265
+ * desired behaviour when producing XML. Adapted from code by @inanimatt:
266
+ * https://gist.github.com/inanimatt/879249
267
+ */
268
+ public function convert_entity($matches) {
269
+ static $table = array(
270
+ 'quot' => '&#34;',
271
+ 'amp' => '&#38;',
272
+ 'lt' => '&#60;',
273
+ 'gt' => '&#62;',
274
+ 'OElig' => '&#338;',
275
+ 'oelig' => '&#339;',
276
+ 'Scaron' => '&#352;',
277
+ 'scaron' => '&#353;',
278
+ 'Yuml' => '&#376;',
279
+ 'circ' => '&#710;',
280
+ 'tilde' => '&#732;',
281
+ 'ensp' => '&#8194;',
282
+ 'emsp' => '&#8195;',
283
+ 'thinsp' => '&#8201;',
284
+ 'zwnj' => '&#8204;',
285
+ 'zwj' => '&#8205;',
286
+ 'lrm' => '&#8206;',
287
+ 'rlm' => '&#8207;',
288
+ 'ndash' => '&#8211;',
289
+ 'mdash' => '&#8212;',
290
+ 'lsquo' => '&#8216;',
291
+ 'rsquo' => '&#8217;',
292
+ 'sbquo' => '&#8218;',
293
+ 'ldquo' => '&#8220;',
294
+ 'rdquo' => '&#8221;',
295
+ 'bdquo' => '&#8222;',
296
+ 'dagger' => '&#8224;',
297
+ 'Dagger' => '&#8225;',
298
+ 'permil' => '&#8240;',
299
+ 'lsaquo' => '&#8249;',
300
+ 'rsaquo' => '&#8250;',
301
+ 'euro' => '&#8364;',
302
+ 'fnof' => '&#402;',
303
+ 'Alpha' => '&#913;',
304
+ 'Beta' => '&#914;',
305
+ 'Gamma' => '&#915;',
306
+ 'Delta' => '&#916;',
307
+ 'Epsilon' => '&#917;',
308
+ 'Zeta' => '&#918;',
309
+ 'Eta' => '&#919;',
310
+ 'Theta' => '&#920;',
311
+ 'Iota' => '&#921;',
312
+ 'Kappa' => '&#922;',
313
+ 'Lambda' => '&#923;',
314
+ 'Mu' => '&#924;',
315
+ 'Nu' => '&#925;',
316
+ 'Xi' => '&#926;',
317
+ 'Omicron' => '&#927;',
318
+ 'Pi' => '&#928;',
319
+ 'Rho' => '&#929;',
320
+ 'Sigma' => '&#931;',
321
+ 'Tau' => '&#932;',
322
+ 'Upsilon' => '&#933;',
323
+ 'Phi' => '&#934;',
324
+ 'Chi' => '&#935;',
325
+ 'Psi' => '&#936;',
326
+ 'Omega' => '&#937;',
327
+ 'alpha' => '&#945;',
328
+ 'beta' => '&#946;',
329
+ 'gamma' => '&#947;',
330
+ 'delta' => '&#948;',
331
+ 'epsilon' => '&#949;',
332
+ 'zeta' => '&#950;',
333
+ 'eta' => '&#951;',
334
+ 'theta' => '&#952;',
335
+ 'iota' => '&#953;',
336
+ 'kappa' => '&#954;',
337
+ 'lambda' => '&#955;',
338
+ 'mu' => '&#956;',
339
+ 'nu' => '&#957;',
340
+ 'xi' => '&#958;',
341
+ 'omicron' => '&#959;',
342
+ 'pi' => '&#960;',
343
+ 'rho' => '&#961;',
344
+ 'sigmaf' => '&#962;',
345
+ 'sigma' => '&#963;',
346
+ 'tau' => '&#964;',
347
+ 'upsilon' => '&#965;',
348
+ 'phi' => '&#966;',
349
+ 'chi' => '&#967;',
350
+ 'psi' => '&#968;',
351
+ 'omega' => '&#969;',
352
+ 'thetasym' => '&#977;',
353
+ 'upsih' => '&#978;',
354
+ 'piv' => '&#982;',
355
+ 'bull' => '&#8226;',
356
+ 'hellip' => '&#8230;',
357
+ 'prime' => '&#8242;',
358
+ 'Prime' => '&#8243;',
359
+ 'oline' => '&#8254;',
360
+ 'frasl' => '&#8260;',
361
+ 'weierp' => '&#8472;',
362
+ 'image' => '&#8465;',
363
+ 'real' => '&#8476;',
364
+ 'trade' => '&#8482;',
365
+ 'alefsym' => '&#8501;',
366
+ 'larr' => '&#8592;',
367
+ 'uarr' => '&#8593;',
368
+ 'rarr' => '&#8594;',
369
+ 'darr' => '&#8595;',
370
+ 'harr' => '&#8596;',
371
+ 'crarr' => '&#8629;',
372
+ 'lArr' => '&#8656;',
373
+ 'uArr' => '&#8657;',
374
+ 'rArr' => '&#8658;',
375
+ 'dArr' => '&#8659;',
376
+ 'hArr' => '&#8660;',
377
+ 'forall' => '&#8704;',
378
+ 'part' => '&#8706;',
379
+ 'exist' => '&#8707;',
380
+ 'empty' => '&#8709;',
381
+ 'nabla' => '&#8711;',
382
+ 'isin' => '&#8712;',
383
+ 'notin' => '&#8713;',
384
+ 'ni' => '&#8715;',
385
+ 'prod' => '&#8719;',
386
+ 'sum' => '&#8721;',
387
+ 'minus' => '&#8722;',
388
+ 'lowast' => '&#8727;',
389
+ 'radic' => '&#8730;',
390
+ 'prop' => '&#8733;',
391
+ 'infin' => '&#8734;',
392
+ 'ang' => '&#8736;',
393
+ 'and' => '&#8743;',
394
+ 'or' => '&#8744;',
395
+ 'cap' => '&#8745;',
396
+ 'cup' => '&#8746;',
397
+ 'int' => '&#8747;',
398
+ 'there4' => '&#8756;',
399
+ 'sim' => '&#8764;',
400
+ 'cong' => '&#8773;',
401
+ 'asymp' => '&#8776;',
402
+ 'ne' => '&#8800;',
403
+ 'equiv' => '&#8801;',
404
+ 'le' => '&#8804;',
405
+ 'ge' => '&#8805;',
406
+ 'sub' => '&#8834;',
407
+ 'sup' => '&#8835;',
408
+ 'nsub' => '&#8836;',
409
+ 'sube' => '&#8838;',
410
+ 'supe' => '&#8839;',
411
+ 'oplus' => '&#8853;',
412
+ 'otimes' => '&#8855;',
413
+ 'perp' => '&#8869;',
414
+ 'sdot' => '&#8901;',
415
+ 'lceil' => '&#8968;',
416
+ 'rceil' => '&#8969;',
417
+ 'lfloor' => '&#8970;',
418
+ 'rfloor' => '&#8971;',
419
+ 'lang' => '&#9001;',
420
+ 'rang' => '&#9002;',
421
+ 'loz' => '&#9674;',
422
+ 'spades' => '&#9824;',
423
+ 'clubs' => '&#9827;',
424
+ 'hearts' => '&#9829;',
425
+ 'diams' => '&#9830;',
426
+ 'nbsp' => '&#160;',
427
+ 'iexcl' => '&#161;',
428
+ 'cent' => '&#162;',
429
+ 'pound' => '&#163;',
430
+ 'curren' => '&#164;',
431
+ 'yen' => '&#165;',
432
+ 'brvbar' => '&#166;',
433
+ 'sect' => '&#167;',
434
+ 'uml' => '&#168;',
435
+ 'copy' => '&#169;',
436
+ 'ordf' => '&#170;',
437
+ 'laquo' => '&#171;',
438
+ 'not' => '&#172;',
439
+ 'shy' => '&#173;',
440
+ 'reg' => '&#174;',
441
+ 'macr' => '&#175;',
442
+ 'deg' => '&#176;',
443
+ 'plusmn' => '&#177;',
444
+ 'sup2' => '&#178;',
445
+ 'sup3' => '&#179;',
446
+ 'acute' => '&#180;',
447
+ 'micro' => '&#181;',
448
+ 'para' => '&#182;',
449
+ 'middot' => '&#183;',
450
+ 'cedil' => '&#184;',
451
+ 'sup1' => '&#185;',
452
+ 'ordm' => '&#186;',
453
+ 'raquo' => '&#187;',
454
+ 'frac14' => '&#188;',
455
+ 'frac12' => '&#189;',
456
+ 'frac34' => '&#190;',
457
+ 'iquest' => '&#191;',
458
+ 'Agrave' => '&#192;',
459
+ 'Aacute' => '&#193;',
460
+ 'Acirc' => '&#194;',
461
+ 'Atilde' => '&#195;',
462
+ 'Auml' => '&#196;',
463
+ 'Aring' => '&#197;',
464
+ 'AElig' => '&#198;',
465
+ 'Ccedil' => '&#199;',
466
+ 'Egrave' => '&#200;',
467
+ 'Eacute' => '&#201;',
468
+ 'Ecirc' => '&#202;',
469
+ 'Euml' => '&#203;',
470
+ 'Igrave' => '&#204;',
471
+ 'Iacute' => '&#205;',
472
+ 'Icirc' => '&#206;',
473
+ 'Iuml' => '&#207;',
474
+ 'ETH' => '&#208;',
475
+ 'Ntilde' => '&#209;',
476
+ 'Ograve' => '&#210;',
477
+ 'Oacute' => '&#211;',
478
+ 'Ocirc' => '&#212;',
479
+ 'Otilde' => '&#213;',
480
+ 'Ouml' => '&#214;',
481
+ 'times' => '&#215;',
482
+ 'Oslash' => '&#216;',
483
+ 'Ugrave' => '&#217;',
484
+ 'Uacute' => '&#218;',
485
+ 'Ucirc' => '&#219;',
486
+ 'Uuml' => '&#220;',
487
+ 'Yacute' => '&#221;',
488
+ 'THORN' => '&#222;',
489
+ 'szlig' => '&#223;',
490
+ 'agrave' => '&#224;',
491
+ 'aacute' => '&#225;',
492
+ 'acirc' => '&#226;',
493
+ 'atilde' => '&#227;',
494
+ 'auml' => '&#228;',
495
+ 'aring' => '&#229;',
496
+ 'aelig' => '&#230;',
497
+ 'ccedil' => '&#231;',
498
+ 'egrave' => '&#232;',
499
+ 'eacute' => '&#233;',
500
+ 'ecirc' => '&#234;',
501
+ 'euml' => '&#235;',
502
+ 'igrave' => '&#236;',
503
+ 'iacute' => '&#237;',
504
+ 'icirc' => '&#238;',
505
+ 'iuml' => '&#239;',
506
+ 'eth' => '&#240;',
507
+ 'ntilde' => '&#241;',
508
+ 'ograve' => '&#242;',
509
+ 'oacute' => '&#243;',
510
+ 'ocirc' => '&#244;',
511
+ 'otilde' => '&#245;',
512
+ 'ouml' => '&#246;',
513
+ 'divide' => '&#247;',
514
+ 'oslash' => '&#248;',
515
+ 'ugrave' => '&#249;',
516
+ 'uacute' => '&#250;',
517
+ 'ucirc' => '&#251;',
518
+ 'uuml' => '&#252;',
519
+ 'yacute' => '&#253;',
520
+ 'thorn' => '&#254;',
521
+ 'yuml' => '&#255;'
522
+ );
523
+ // Entity not found? Destroy it.
524
+ return isset($table[$matches[1]]) ? $table[$matches[1]] : '';
525
+ } /* FeedWordPress_Parser::convert_entity() */
526
+
527
+ } /* class FeedWordPress_Parser */
528
+
529
 
feedwordpressadminpage.class.php ADDED
@@ -0,0 +1,745 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * class FeedWordPressAdminPage
4
+ *
5
+ * Handles a lot of the interface-code related jots and tittles for putting together
6
+ * admin / settings pages within FeedWordPress, like Syndication > Posts & Links,
7
+ * Syndication > Feeds & Updates, etc., whether for setting global defaults, or for
8
+ * settings on particular feeds.
9
+ *
10
+ */
11
+ class FeedWordPressAdminPage {
12
+ protected $context;
13
+ protected $updated = false;
14
+ protected $mesg = NULL;
15
+
16
+ var $link = NULL;
17
+ var $dispatch = NULL;
18
+ var $filename = NULL;
19
+ var $pagenames = array();
20
+
21
+ /**
22
+ * Construct the admin page object.
23
+ *
24
+ * @param mixed $link An object of class {@link SyndicatedLink} if created for one feed's settings, NULL if created for global default settings
25
+ */
26
+ public function __construct( $page = 'feedwordpressadmin', $link = NULL ) {
27
+ $this->link = $link;
28
+
29
+ // Set meta-box context name
30
+ $this->context = $page;
31
+ if ($this->for_feed_settings()) :
32
+ $this->context .= 'forfeed';
33
+ endif;
34
+ } /* FeedWordPressAdminPage constructor */
35
+
36
+ public function pageslug () {
37
+ $slug = preg_replace('/FeedWordPress(.*)Page/', '$1', get_class($this));
38
+ return strtolower($slug);
39
+ }
40
+
41
+ public function pagename ($context = NULL) {
42
+ if (is_null($context)) :
43
+ $context = 'default';
44
+ endif;
45
+
46
+ if (isset($this->pagenames[$context])) :
47
+ $name = $this->pagenames[$context];
48
+ elseif (isset($tis->pagenames['default'])) :
49
+ $name = $this->pagenames['default'];
50
+ else :
51
+ $name = $this->pageslug();
52
+ endif;
53
+ return __($name);
54
+ } /* FeedWordPressAdminPage::pagename () */
55
+
56
+ public function accept_POST ($post) {
57
+ if ($this->for_feed_settings() and $this->update_requested_in($post)) :
58
+ $this->update_feed();
59
+ elseif ($this->save_requested_in($post)) : // User mashed Save Changes
60
+ $this->save_settings($post);
61
+ endif;
62
+ do_action($this->dispatch.'_post', $post, $this);
63
+ }
64
+
65
+ public function update_feed () {
66
+ global $feedwordpress;
67
+
68
+ add_action('feedwordpress_check_feed', 'update_feeds_mention');
69
+ add_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
70
+
71
+ $link = $this->link;
72
+
73
+ print '<div class="updated">';
74
+ print "<ul>";
75
+ $uri = $this->link->uri();
76
+ $displayUrl = $uri;
77
+
78
+ // check for effects of an effective-url filter
79
+ $effectiveUrl = $link->uri(array('fetch' => true));
80
+ if ($uri != $effectiveUrl) : $displayUrl .= ' | ' . $effectiveUrl; endif;
81
+
82
+ $delta = $feedwordpress->update($uri);
83
+ print "</ul>";
84
+
85
+ if (!is_null($delta)) :
86
+ echo "<p><strong>Update complete.</strong>".fwp_update_set_results_message($delta)."</p>";
87
+ echo "\n"; flush();
88
+ else :
89
+ $effectiveUrl = esc_html($effectiveUrl);
90
+ echo "<p><strong>Error:</strong> There was a problem updating <a href=\"$effectiveUrl\">$displayUrl</a></p>\n";
91
+ endif;
92
+ print "</div>\n";
93
+ remove_action('feedwordpress_check_feed', 'update_feeds_mention');
94
+ remove_action('feedwordpress_check_feed_complete', 'update_feeds_finish', 10, 3);
95
+ }
96
+
97
+ public function save_settings ($post) {
98
+ do_action($this->dispatch.'_save', $post, $this);
99
+
100
+ if ($this->for_feed_settings()) :
101
+ // Save settings
102
+ $this->link->save_settings(/*reload=*/ true);
103
+ $this->updated = true;
104
+
105
+ // Reset, reload
106
+ $link_id = $this->link->id;
107
+ unset($this->link);
108
+ $this->link = new SyndicatedLink($link_id);
109
+ else :
110
+ $this->updated = true;
111
+ endif;
112
+ } /* FeedWordPressAdminPage::save_settings () */
113
+
114
+ public function for_feed_settings () { return (is_object($this->link) and method_exists($this->link, 'found') and $this->link->found()); }
115
+ public function for_default_settings () { return !$this->for_feed_settings(); }
116
+
117
+ public function setting ($names, $fallback_value = NULL, $params = array()) {
118
+ if (!is_array($params)) :
119
+ $params = array('default' => $params);
120
+ endif;
121
+ $params = shortcode_atts(array(
122
+ 'default' => 'default',
123
+ 'fallback' => true,
124
+ ), $params);
125
+
126
+ if (is_string($names)) :
127
+ $feed_name = $names;
128
+ $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names);
129
+ else :
130
+ $feed_name = $names['feed'];
131
+ $global_name = 'feedwordpress_'.$names['global'];
132
+ endif;
133
+
134
+ if ($this->for_feed_settings()) : // Check feed-specific setting first; fall back to global
135
+ if (!$params['fallback']) : $global_name = NULL; endif;
136
+ $ret = $this->link->setting($feed_name, $global_name, $fallback_value, $params['default']);
137
+ else : // Check global setting
138
+ $ret = get_option($global_name, $fallback_value);
139
+ endif;
140
+ return $ret;
141
+ }
142
+
143
+ public function update_setting ($names, $value, $default = 'default') {
144
+ if (is_string($names)) :
145
+ $feed_name = $names;
146
+ $global_name = 'feedwordpress_'.preg_replace('![\s/]+!', '_', $names);
147
+ else :
148
+ $feed_name = $names['feed'];
149
+ $global_name = 'feedwordpress_'.$names['global'];
150
+ endif;
151
+
152
+ if ($this->for_feed_settings()) : // Update feed-specific setting
153
+ $this->link->update_setting($feed_name, $value, $default);
154
+ else : // Update global setting
155
+ update_option($global_name, $value);
156
+ endif;
157
+ } /* FeedWordPressAdminPage::update_setting () */
158
+
159
+ public function save_requested_in ($post) {
160
+ return (isset($post['save']) or isset($post['submit']));
161
+ }
162
+ public function update_requested_in ($post) {
163
+ return (isset($post['update']) and (strlen($post['update']) > 0));
164
+ }
165
+
166
+ public function submitted_link_id () {
167
+ global $fwp_post;
168
+
169
+ // Presume global unless we get a specific link ID
170
+ $link_id = NULL;
171
+
172
+ $submit_buttons = array(
173
+ 'save',
174
+ 'submit',
175
+ 'fix_mismatch',
176
+ 'feedfinder',
177
+ );
178
+ foreach ($submit_buttons as $field) :
179
+ if (isset($fwp_post[$field])) :
180
+ $link_id = MyPHP::request('save_link_id');
181
+ endif;
182
+ endforeach;
183
+
184
+ if (is_null($link_id) and isset($_REQUEST['link_id'])) :
185
+ $link_id = MyPHP::request('link_id');
186
+ endif;
187
+
188
+ return $link_id;
189
+ } /* FeedWordPressAdminPage::submitted_link_id() */
190
+
191
+ public function submitted_link () {
192
+ $link_id = $this->submitted_link_id();
193
+ if (is_numeric($link_id) and $link_id) :
194
+ $link = new SyndicatedLink($link_id);
195
+ else :
196
+ $link = NULL;
197
+ endif;
198
+ return $link;
199
+ } /* FeedWordPressAdminPage::submitted_link () */
200
+
201
+ public function stamp_link_id ($field = null) {
202
+ if (is_null($field)) : $field = 'save_link_id'; endif;
203
+ ?>
204
+ <input type="hidden" name="<?php print esc_attr($field); ?>" value="<?php print ($this->for_feed_settings() ? $this->link->id : '*'); ?>" />
205
+ <?php
206
+ } /* FeedWordPressAdminPage::stamp_link_id () */
207
+
208
+ public function these_posts_phrase () {
209
+ if ($this->for_feed_settings()) :
210
+ $phrase = __('posts from this feed');
211
+ else :
212
+ $phrase = __('syndicated posts');
213
+ endif;
214
+ return $phrase;
215
+ } /* FeedWordPressAdminPage::these_posts_phrase() */
216
+
217
+ /**
218
+ * Provides a uniquely identifying name for the interface context for
219
+ * use with add_meta_box() and do_meta_boxes(),
220
+ *
221
+ * @return string the context name
222
+ *
223
+ * @see add_meta_box()
224
+ * @see do_meta_boxes()
225
+ */
226
+ public function meta_box_context () {
227
+ return $this->context;
228
+ } /* FeedWordPressAdminPage::meta_box_context () */
229
+
230
+ /**
231
+ * Outputs JavaScript to fix AJAX toggles settings.
232
+ *
233
+ * @uses FeedWordPressAdminPage::meta_box_context()
234
+ */
235
+ public function fix_toggles () {
236
+ FeedWordPressSettingsUI::fix_toggles_js($this->meta_box_context());
237
+ } /* FeedWordPressAdminPage::fix_toggles() */
238
+
239
+ public function ajax_interface_js () {
240
+ ?>
241
+ function contextual_appearance (item, appear, disappear, value, visibleStyle, checkbox) {
242
+ if (typeof(visibleStyle)=='undefined') visibleStyle = 'block';
243
+
244
+ var rollup=document.getElementById(item);
245
+ if (rollup) {
246
+ if ((checkbox && rollup.checked) || (!checkbox && value==rollup.value)) {
247
+ jQuery('#'+disappear).hide();
248
+ jQuery('#'+appear).show(600);
249
+ } else {
250
+ jQuery('#'+appear).hide();
251
+ jQuery('#'+disappear).show(600);
252
+ }
253
+ }
254
+ }
255
+ <?php
256
+ } /* FeedWordPressAdminPage::ajax_interface_js () */
257
+
258
+ public function admin_page_href ($page, $params = array(), $link = NULL) {
259
+ global $fwp_path;
260
+
261
+ // Merge in the page's filename
262
+ $params = array_merge($params, array('page' => $fwp_path.'/'.$page));
263
+
264
+ // If there is a link ID provided, then merge that in too.
265
+ if (!is_null($link)) :
266
+ $link_id = NULL;
267
+ if (is_object($link)) :
268
+ if (method_exists($link, 'found')) :
269
+ // Is this a SyndicatedLink object?
270
+ if ($link->found()) :
271
+ $link_id = $link->link->link_id;
272
+ endif;
273
+ else :
274
+ // Is this a wp_links table record?
275
+ $link_id = $link->link_id;
276
+ endif;
277
+ else :
278
+ // Is this just a numeric ID?
279
+ $link_id = $link;
280
+ endif;
281
+
282
+ if (!is_null($link_id)) :
283
+ $params = array_merge($params, array('link_id' => $link_id));
284
+ endif;
285
+ endif;
286
+
287
+ return MyPHP::url(admin_url('admin.php'), $params);
288
+ } /* FeedWordPressAdminPage::admin_page_href () */
289
+
290
+ public function display_feed_settings_page_links ($params = array()) {
291
+ global $fwp_path;
292
+
293
+ $params = wp_parse_args($params, array(
294
+ 'before' => '',
295
+ 'between' => ' | ',
296
+ 'after' => '',
297
+ 'long' => false,
298
+ 'subscription' => $this->link,
299
+ ));
300
+ $sub = $params['subscription'];
301
+
302
+ $links = array(
303
+ "Feed" => array('page' => 'feeds-page.php', 'long' => 'Feeds & Updates'),
304
+ "Posts" => array('page' => 'posts-page.php', 'long' => 'Posts & Links'),
305
+ "Authors" => array('page' => 'authors-page.php', 'long' => 'Authors'),
306
+ 'Categories' => array('page' => 'categories-page.php', 'long' => 'Categories & Tags'),
307
+ );
308
+
309
+ $link_id = NULL;
310
+ if (is_object($sub)) :
311
+ if (method_exists($sub, 'found')) :
312
+ if ($sub->found()) :
313
+ $link_id = $sub->link->link_id;
314
+ endif;
315
+ else :
316
+ $link_id = $sub->link_id;
317
+ endif;
318
+ endif;
319
+
320
+ print $params['before']; $first = true;
321
+ foreach ($links as $label => $link) :
322
+ if (!$first) : print $params['between']; endif;
323
+
324
+ if (isset($link['url'])) : MyPHP::url($link['url'], array("link_id" => $link_id));
325
+ else : $url = $this->admin_page_href($link['page'], array(), $sub);
326
+ endif;
327
+ $url = esc_html($url);
328
+
329
+ if ($link['page']==basename($this->filename)) :
330
+ print "<strong>";
331
+ else :
332
+ print "<a href=\"${url}\">";
333
+ endif;
334
+
335
+ if ($params['long']) : print esc_html(__($link['long']));
336
+ else : print esc_html(__($label));
337
+ endif;
338
+
339
+ if ($link['page']==basename($this->filename)) :
340
+ print "</strong>";
341
+ else :
342
+ print "</a>";
343
+ endif;
344
+
345
+ $first = false;
346
+ endforeach;
347
+ print $params['after'];
348
+ } /* FeedWordPressAdminPage::display_feed_settings_page_links */
349
+
350
+ public function display_feed_select_dropdown() {
351
+ $links = FeedWordPress::syndicated_links();
352
+
353
+ ?>
354
+ <div id="fwpfs-container"><ul class="subsubsub">
355
+ <li><select name="link_id" class="fwpfs" style="max-width: 20.0em;">
356
+ <option value="*"<?php if ($this->for_default_settings()) : ?> selected="selected"<?php endif; ?>>- defaults for all feeds -</option>
357
+ <?php if ($links) : foreach ($links as $ddlink) : ?>
358
+ <option value="<?php print (int) $ddlink->link_id; ?>"<?php if (!is_null($this->link) and ($this->link->id==$ddlink->link_id)) : ?> selected="selected"<?php endif; ?>><?php print esc_html($ddlink->link_name); ?></option>
359
+ <?php endforeach; endif; ?>
360
+ </select>
361
+ <input id="fwpfs-button" class="button" type="submit" name="go" value="<?php _e('Go') ?> &raquo;" /></li>
362
+
363
+ <?php
364
+ $this->display_feed_settings_page_links(array(
365
+ 'before' => '<li>',
366
+ 'between' => "</li>\n<li>",
367
+ 'after' => '</li>',
368
+ 'subscription' => $this->link,
369
+ ));
370
+
371
+ if ($this->for_feed_settings()) :
372
+ ?>
373
+ <li><input class="button" type="submit" name="update" value="Update Now" /></li>
374
+ <?php
375
+ endif;
376
+ ?>
377
+ </ul>
378
+ </div>
379
+ <?php
380
+ } /* FeedWordPressAdminPage::display_feed_select_dropdown() */
381
+
382
+ public function display_sheet_header ($pagename = 'Syndication', $all = false) {
383
+ ?>
384
+ <div class="icon32"><img src="<?php print esc_attr( plugins_url( 'feedwordpress.png', __FILE__ ) ); ?>" alt="" /></div>
385
+ <h2><?php print esc_html(__($pagename.($all ? '' : ' Settings'))); ?><?php if ($this->for_feed_settings()) : ?>: <?php echo esc_html($this->link->name(/*from feed=*/ false)); ?><?php endif; ?></h2>
386
+ <?php
387
+ }
388
+
389
+ public function display_update_notice_if_updated ($pagename = 'Syndication', $mesg = NULL) {
390
+ if (!is_null($mesg)) :
391
+ $this->mesg = $mesg;
392
+ endif;
393
+
394
+ if ($this->updated) :
395
+ if ($this->updated === true) :
396
+ $this->mesg = $pagename . ' settings updated.';
397
+ else :
398
+ $this->mesg = $this->updated;
399
+ endif;
400
+ endif;
401
+
402
+ if (!is_null($this->mesg)) :
403
+ ?>
404
+ <div class="updated">
405
+ <p><?php print esc_html($this->mesg); ?></p>
406
+ </div>
407
+ <?php
408
+ endif;
409
+ } /* FeedWordPressAdminPage::display_update_notice_if_updated() */
410
+
411
+ public function display_settings_scope_message () {
412
+ if ($this->for_feed_settings()) :
413
+ ?>
414
+ <p>These settings only affect posts syndicated from
415
+ <strong><?php echo esc_html($this->link->link->link_name); ?></strong>.</p>
416
+ <?php
417
+ else :
418
+ ?>
419
+ <p>These settings affect posts syndicated from any feed unless they are overridden
420
+ by settings for that specific feed.</p>
421
+ <?php
422
+ endif;
423
+ } /* FeedWordPressAdminPage::display_settings_scope_message () */
424
+
425
+ /*static*/ function has_link () { return true; }
426
+
427
+ public function form_action ($filename = NULL) {
428
+ if (is_null($filename)) :
429
+ $filename = basename($this->filename);
430
+ endif;
431
+ return $this->admin_page_href($filename);
432
+ } /* FeedWordPressAdminPage::form_action () */
433
+
434
+ public function update_message () {
435
+ return $this->mesg;
436
+ }
437
+
438
+ public function display () {
439
+ global $fwp_post;
440
+
441
+ if (FeedWordPress::needs_upgrade()) :
442
+ fwp_upgrade_page();
443
+ return;
444
+ endif;
445
+
446
+ FeedWordPressCompatibility::validate_http_request(/*action=*/ $this->dispatch, /*capability=*/ 'manage_links');
447
+
448
+ ////////////////////////////////////////////////
449
+ // Process POST request, if any ////////////////
450
+ ////////////////////////////////////////////////
451
+ if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
452
+ $this->accept_POST($fwp_post);
453
+ else :
454
+ $this->updated = false;
455
+ endif;
456
+
457
+ ////////////////////////////////////////////////
458
+ // Prepare settings page ///////////////////////
459
+ ////////////////////////////////////////////////
460
+
461
+ $this->display_update_notice_if_updated(
462
+ $this->pagename('settings-update'),
463
+ $this->update_message()
464
+ );
465
+
466
+ $this->open_sheet($this->pagename('open-sheet'));
467
+ ?>
468
+ <div id="post-body">
469
+ <?php
470
+ foreach ($this->boxes_by_methods as $method => $row) :
471
+ if (is_array($row)) :
472
+ $id = $row['id'];
473
+ $title = $row['title'];
474
+ else :
475
+ $id = 'feedwordpress_'.$method;
476
+ $title = $row;
477
+ endif;
478
+
479
+ add_meta_box(
480
+ /*id=*/ $id,
481
+ /*title=*/ $title,
482
+ /*callback=*/ array($this, $method),
483
+ /*page=*/ $this->meta_box_context(),
484
+ /*context=*/ $this->meta_box_context()
485
+ );
486
+ endforeach;
487
+ do_action($this->dispatch.'_meta_boxes', $this);
488
+ ?>
489
+ <div class="metabox-holder">
490
+ <?php
491
+ do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
492
+ ?>
493
+ </div> <!-- class="metabox-holder" -->
494
+ </div> <!-- id="post-body" -->
495
+ <?php $this->close_sheet(); ?>
496
+ <?php
497
+ }
498
+
499
+ public function open_sheet ($header) {
500
+ // Set up prepatory AJAX stuff
501
+ ?>
502
+ <script type="text/javascript">
503
+ <?php
504
+ $this->ajax_interface_js();
505
+ ?>
506
+ </script>
507
+
508
+ <?php
509
+ add_action(
510
+ FeedWordPressCompatibility::bottom_script_hook($this->filename),
511
+ /*callback=*/ array($this, 'fix_toggles'),
512
+ /*priority=*/ 10000
513
+ );
514
+ FeedWordPressSettingsUI::ajax_nonce_fields();
515
+
516
+ ?>
517
+ <div class="wrap feedwordpress-admin" id="feedwordpress-admin-<?php print $this->pageslug(); ?>">
518
+ <?php
519
+ if (!is_null($header)) :
520
+ $this->display_sheet_header($header);
521
+ endif;
522
+
523
+ if (!is_null($this->dispatch)) :
524
+ ?>
525
+ <form action="<?php print $this->form_action(); ?>" method="post">
526
+ <div><?php
527
+ FeedWordPressCompatibility::stamp_nonce($this->dispatch);
528
+ $this->stamp_link_id();
529
+ ?></div>
530
+ <?php
531
+ endif;
532
+
533
+ if ($this->has_link()) :
534
+ $this->display_settings_scope_message();
535
+ endif;
536
+
537
+ ?><div class="tablenav"><?php
538
+ if (!is_null($this->dispatch)) :
539
+ ?><div class="alignright"><?php
540
+ $this->save_button();
541
+ ?></div><?php
542
+ endif;
543
+
544
+ if ($this->has_link()) :
545
+ $this->display_feed_select_dropdown();
546
+ endif;
547
+ ?>
548
+ </div>
549
+
550
+ <div id="poststuff">
551
+ <?php
552
+ } /* FeedWordPressAdminPage::open_sheet () */
553
+
554
+ public function close_sheet () {
555
+ ?>
556
+
557
+ </div> <!-- id="poststuff" -->
558
+ <?php
559
+ if (!is_null($this->dispatch)) :
560
+ $this->save_button();
561
+ print "</form>\n";
562
+ endif;
563
+ ?>
564
+ </div> <!-- class="wrap" -->
565
+
566
+ <?php
567
+ } /* FeedWordPressAdminPage::close_sheet () */
568
+
569
+ public function setting_radio_control ($localName, $globalName, $options, $params = array()) {
570
+ global $fwp_path;
571
+
572
+ if (isset($params['filename'])) : $filename = $params['filename'];
573
+ else : $filename = basename($this->filename);
574
+ endif;
575
+
576
+ if (isset($params['site-wide-url'])) : $href = $params['site-wide-url'];
577
+ else : $href = $this->admin_page_href($filename);
578
+ endif;
579
+
580
+ if (isset($params['setting-default'])) : $settingDefault = $params['setting-default'];
581
+ else : $settingDefault = NULL;
582
+ endif;
583
+
584
+ if (isset($params['global-setting-default'])) : $globalSettingDefault = $params['global-setting-default'];
585
+ else : $globalSettingDefault = $settingDefault;
586
+ endif;
587
+
588
+ $globalSetting = get_option('feedwordpress_'.$globalName, $globalSettingDefault);
589
+ if ($this->for_feed_settings()) :
590
+ $setting = $this->link->setting($localName, NULL, $settingDefault);
591
+ else :
592
+ $setting = $globalSetting;
593
+ endif;
594
+
595
+ if (isset($params['offer-site-wide'])) : $offerSiteWide = $params['offer-site-wide'];
596
+ else : $offerSiteWide = $this->for_feed_settings();
597
+ endif;
598
+
599
+ // This allows us to provide an alternative set of human-readable
600
+ // labels for each potential value. For use in Currently: line.
601
+ if (isset($params['labels'])) : $labels = $params['labels'];
602
+ elseif (is_callable($options)) : $labels = NULL;
603
+ else : $labels = $options;
604
+ endif;
605
+
606
+ if (isset($params['input-name'])) : $inputName = $params['input-name'];
607
+ else : $inputName = $globalName;
608
+ endif;
609
+
610
+ if (isset($params['default-input-id'])) : $defaultInputId = $params['default-input-id'];
611
+ else : $defaultInputId = NULL;
612
+ endif;
613
+
614
+ if (isset($params['default-input-id-no'])) : $defaultInputIdNo = $params['default-input-id-no'];
615
+ elseif (!is_null($defaultInputId)) : $defaultInputIdNo = $defaultInputId.'-no';
616
+ else : $defaultInputIdNo = NULL;
617
+ endif;
618
+
619
+ // This allows us to either include the site-default setting as
620
+ // one of the options within the radio box, or else as a simple
621
+ // yes/no toggle that controls whether or not to check another
622
+ // set of inputs.
623
+ if (isset($params['default-input-name'])) : $defaultInputName = $params['default-input-name'];
624
+ else : $defaultInputName = $inputName;
625
+ endif;
626
+
627
+ if ($defaultInputName != $inputName) :
628
+ $defaultInputValue = 'yes';
629
+ else :
630
+ $defaultInputValue = (
631
+ isset($params['default-input-value'])
632
+ ? $params['default-input-value']
633
+ : 'site-default'
634
+ );
635
+ endif;
636
+
637
+ $settingDefaulted = (is_null($setting) or ($settingDefault === $setting));
638
+
639
+ if (!is_callable($options)) :
640
+ $checked = array();
641
+ if ($settingDefaulted) :
642
+ $checked[$defaultInputValue] = ' checked="checked"';
643
+ endif;
644
+
645
+ foreach ($options as $value => $label) :
646
+ if ($setting == $value) :
647
+ $checked[$value] = ' checked="checked"';
648
+ else :
649
+ $checked[$value] = '';
650
+ endif;
651
+ endforeach;
652
+ endif;
653
+
654
+ $defaulted = array();
655
+ if ($defaultInputName != $inputName) :
656
+ $defaulted['yes'] = ($settingDefaulted ? ' checked="checked"' : '');
657
+ $defaulted['no'] = ($settingDefaulted ? '' : ' checked="checked"');
658
+ else :
659
+ $defaulted['yes'] = (isset($checked[$defaultInputValue]) ? $checked[$defaultInputValue] : '');
660
+ endif;
661
+
662
+ if (isset($params['defaulted'])) :
663
+ $defaulted['yes'] = ($params['defaulted'] ? ' checked="checked"' : '');
664
+ $defaulted['no'] = ($params['defaulted'] ? '' : ' checked="checked"');
665
+ endif;
666
+
667
+ if ($offerSiteWide) :
668
+ ?>
669
+ <table class="twofer">
670
+ <tbody>
671
+ <tr><td class="equals first inactive">
672
+ <ul class="options">
673
+ <li><label><input type="radio"
674
+ name="<?php print $defaultInputName; ?>"
675
+ value="<?php print $defaultInputValue; ?>"
676
+ <?php if (!is_null($defaultInputId)) : ?>id="<?php print $defaultInputId; ?>" <?php endif; ?>
677
+ <?php print $defaulted['yes']; ?> />
678
+ Use the site-wide setting</label>
679
+ <span class="current-setting">Currently:
680
+ <strong><?php if (is_callable($labels)) :
681
+ print call_user_func($labels, $globalSetting, $defaulted, $params);
682
+ elseif (is_null($labels)) :
683
+ print $globalSetting;
684
+ else :
685
+ print $labels[$globalSetting];
686
+ endif; ?></strong> (<a href="<?php print $href; ?>">change</a>)</span></li>
687
+ </ul></td>
688
+
689
+ <td class="equals second inactive">
690
+ <?php if ($defaultInputName != $inputName) : ?>
691
+ <ul class="options">
692
+ <li><label><input type="radio"
693
+ name="<?php print $defaultInputName; ?>"
694
+ value="no"
695
+ <?php if (!is_null($defaultInputIdNo)) : ?>id="<?php print $defaultInputIdNo; ?>" <?php endif; ?>
696
+ <?php print $defaulted['no']; ?> />
697
+ <?php _e('Do something different with this feed.'); ?></label>
698
+ <?php endif;
699
+ endif;
700
+
701
+ // Let's spit out the controls here.
702
+ if (is_callable($options)) :
703
+ // Method call to print out options list
704
+ call_user_func($options, $setting, $defaulted, $params);
705
+ else :
706
+ ?>
707
+ <ul class="options">
708
+ <?php foreach ($options as $value => $label) : ?>
709
+ <li><label><input type="radio" name="<?php print $inputName; ?>"
710
+ value="<?php print $value; ?>"
711
+ <?php print $checked[$value]; ?> />
712
+ <?php print $label; ?></label></li>
713
+ <?php endforeach; ?>
714
+ </ul> <!-- class="options" -->
715
+ <?php
716
+ endif;
717
+
718
+ if ($offerSiteWide) :
719
+ if ($defaultInputName != $inputName) :
720
+ // Close the <li> and <ul class="options"> we opened above
721
+ ?>
722
+ </li>
723
+ </ul> <!-- class="options" -->
724
+ <?php
725
+ endif;
726
+
727
+ // Close off the twofer table that we opened up above.
728
+ ?>
729
+ </td></tr>
730
+ </tbody>
731
+ </table>
732
+ <?php
733
+ endif;
734
+ } /* FeedWordPressAdminPage::setting_radio_control () */
735
+
736
+ public function save_button ($caption = NULL) {
737
+ if (is_null($caption)) : $caption = __('Save Changes'); endif;
738
+ ?>
739
+ <p class="submit">
740
+ <input class="button-primary" type="submit" name="save" value="<?php print $caption; ?>" />
741
+ </p>
742
+ <?php
743
+ }
744
+ } /* class FeedWordPressAdminPage */
745
+
feedwordpressdiagnostic.class.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * class FeedWordPressDiagnostic: help to organize some diagnostics output functions.
4
+ */
5
+ class FeedWordPressDiagnostic {
6
+ public static function feed_error ($error, $old, $link) {
7
+ $wpError = $error['object'];
8
+ $url = $link->uri();
9
+
10
+ // check for effects of an effective-url filter
11
+ $effectiveUrl = $link->uri(array('fetch' => true));
12
+ if ($url != $effectiveUrl) : $url .= ' | ' . $effectiveUrl; endif;
13
+
14
+ $mesgs = $wpError->get_error_messages();
15
+ foreach ($mesgs as $mesg) :
16
+ $mesg = esc_html($mesg);
17
+ FeedWordPress::diagnostic(
18
+ 'updated_feeds:errors',
19
+ "Feed Error: [${url}] update returned error: $mesg"
20
+ );
21
+
22
+ $hours = get_option('feedwordpress_diagnostics_persistent_errors_hours', 2);
23
+ $span = ($error['ts'] - $error['since']);
24
+
25
+ if ($span >= ($hours * 60 * 60)) :
26
+ $since = date('r', $error['since']);
27
+ $mostRecent = date('r', $error['ts']);
28
+ FeedWordPress::diagnostic(
29
+ 'updated_feeds:errors:persistent',
30
+ "Feed Update Error: [${url}] returning errors"
31
+ ." since ${since}:<br/><code>$mesg</code>",
32
+ $url, $error['since'], $error['ts']
33
+ );
34
+ endif;
35
+ endforeach;
36
+ }
37
+
38
+ public static function admin_emails ($id = '') {
39
+ $users = get_users_of_blog($id);
40
+ $recipients = array();
41
+ foreach ($users as $user) :
42
+ $user_id = (isset($user->user_id) ? $user->user_id : $user->ID);
43
+ $dude = new WP_User($user_id);
44
+ if ($dude->has_cap('administrator')) :
45
+ if ($dude->user_email) :
46
+ $recipients[] = $dude->user_email;
47
+ endif;
48
+ endif;
49
+ endforeach;
50
+ return $recipients;
51
+ }
52
+
53
+ public static function noncritical_bug ($varname, $var, $line, $file = NULL) {
54
+ if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging
55
+ self::critical_bug($varname, $var, $line, $file);
56
+ endif;
57
+ } /* FeedWordPressDiagnostic::noncritical_bug () */
58
+
59
+ public static function critical_bug ($varname, $var, $line, $file = NULL) {
60
+ global $wp_version;
61
+
62
+ if (!is_null($file)) :
63
+ $location = "line # ${line} of ".basename($file);
64
+ else :
65
+ $location = "line # ${line}";
66
+ endif;
67
+
68
+ print '<p><strong>Critical error:</strong> There may be a bug in FeedWordPress. Please <a href="'.FEEDWORDPRESS_AUTHOR_CONTACT.'">contact the author</a> and paste the following information into your e-mail:</p>';
69
+ print "\n<plaintext>";
70
+ print "Triggered at ${location}\n";
71
+ print "FeedWordPress: ".FEEDWORDPRESS_VERSION."\n";
72
+ print "WordPress: {$wp_version}\n";
73
+ print "PHP: ".phpversion()."\n";
74
+ print "Error data: ";
75
+ print $varname.": "; var_dump($var); echo "\n";
76
+ die;
77
+ } /* FeedWordPressDiagnostic::critical_bug () */
78
+
79
+ public static function is_on ($level) {
80
+ $show = get_option('feedwordpress_diagnostics_show', array());
81
+ return (in_array($level, $show));
82
+ } /* FeedWordPressDiagnostic::is_on () */
83
+
84
+ } /* class FeedWordPressDiagnostic */
feedwordpresslocalpost.class.php CHANGED
@@ -17,8 +17,12 @@ class FeedWordPressLocalPost {
17
  }
18
 
19
  public function id () {
20
- return $this->post->ID;
21
- }
 
 
 
 
22
 
23
  public function meta ($what, $params = array()) {
24
 
@@ -31,6 +35,12 @@ class FeedWordPressLocalPost {
31
  "unproxy" => false,
32
  ));
33
 
 
 
 
 
 
 
34
  // This is a little weird, just bear with me here.
35
  $results = array();
36
 
@@ -152,18 +162,41 @@ class FeedWordPressLocalPost {
152
 
153
 
154
  public function content () {
155
- return apply_filters('the_content', $this->post->post_content, $this->post->ID);
 
 
 
 
 
 
 
156
  }
157
 
158
  public function title () {
159
- return apply_filters('the_title', $this->post->post_title, $this->post->ID);
 
 
 
 
 
 
 
160
  }
161
 
162
  public function guid () {
163
- return apply_filters('get_the_guid', $this->post->guid);
 
 
 
 
 
164
  }
165
 
166
  public function get_categories () {
 
 
 
 
167
  $terms = wp_get_object_terms(
168
  $this->post->ID,
169
  get_taxonomies(array(
17
  }
18
 
19
  public function id () {
20
+ if (is_null($this->post) or !is_object($this->post)) :
21
+ return NULL;
22
+ else :
23
+ return $this->post->ID;
24
+ endif;
25
+ } /* FeedWordPressLocalPost::id () */
26
 
27
  public function meta ($what, $params = array()) {
28
 
35
  "unproxy" => false,
36
  ));
37
 
38
+ // If we got put through the_content without a current
39
+ // $post object set, then bail out immediately.
40
+ if (is_null($this->post) or !is_object($this->post)) :
41
+ return $params['default'];
42
+ endif;
43
+
44
  // This is a little weird, just bear with me here.
45
  $results = array();
46
 
162
 
163
 
164
  public function content () {
165
+ if (is_null($this->post) or !is_object($this->post)) :
166
+ $post_content = NULL;
167
+ $post_id = NULL;
168
+ else :
169
+ $post_content = $this->post->post_content;
170
+ $post_id = $this->post->ID;
171
+ endif;
172
+ return apply_filters('the_content', $post_content, $post_id);
173
  }
174
 
175
  public function title () {
176
+ if (is_null($this->post) or !is_object($this->post)) :
177
+ $post_title = NULL;
178
+ $post_id = NULL;
179
+ else :
180
+ $post_title = $this->post->post_title;
181
+ $post_id = $this->post->ID;
182
+ endif;
183
+ return apply_filters('the_title', $post_title, $post_id);
184
  }
185
 
186
  public function guid () {
187
+ if (is_null($this->post) or !is_object($this->post)) :
188
+ $post_guid = NULL;
189
+ else :
190
+ $post_guid = $this->post->guid;
191
+ endif;
192
+ return apply_filters('get_the_guid', $post_guid);
193
  }
194
 
195
  public function get_categories () {
196
+ if (is_null($this->post) or !is_object($this->post)) :
197
+ return array();
198
+ endif;
199
+
200
  $terms = wp_get_object_terms(
201
  $this->post->ID,
202
  get_taxonomies(array(
feedwordpresssettingsui.class.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * class FeedWordPressSettingsUI: Module to package several functions related to the
4
+ * WordPress administrative / settings interface.
5
+ */
6
+ class FeedWordPressSettingsUI {
7
+ static function is_admin () {
8
+ global $fwp_path;
9
+
10
+ $admin_page = false; // Innocent until proven guilty
11
+ if (isset($_REQUEST['page'])) :
12
+ $admin_page = (
13
+ is_admin()
14
+ and preg_match("|^{$fwp_path}/|", $_REQUEST['page'])
15
+ );
16
+ endif;
17
+ return $admin_page;
18
+ }
19
+
20
+ static function admin_scripts () {
21
+ global $fwp_path;
22
+
23
+ wp_enqueue_script('post'); // for magic tag and category boxes
24
+ wp_enqueue_script('admin-forms'); // for checkbox selection
25
+
26
+ wp_register_script('feedwordpress-elements', plugins_url('/' . $fwp_path . '/feedwordpress-elements.js') );
27
+ wp_enqueue_script('feedwordpress-elements');
28
+ }
29
+
30
+ static function admin_styles () {
31
+ ?>
32
+ <style type="text/css">
33
+ #feedwordpress-admin-feeds .link-rss-params-remove .x, .feedwordpress-admin .remove-it .x {
34
+ background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll 0 0 transparent;
35
+ }
36
+
37
+ #feedwordpress-admin-feeds .link-rss-params-remove:hover .x, .feedwordpress-admin .remove-it:hover .x {
38
+ background: url(<?php print admin_url('images/xit.gif') ?>) no-repeat scroll -10px 0 transparent;
39
+ }
40
+
41
+ .fwpfs {
42
+ background-image: url(<?php print admin_url('images/fav.png'); ?>);
43
+ background-repeat: repeat-x;
44
+ background-position: left center;
45
+ background-attachment: scroll;
46
+ }
47
+ .fwpfs.slide-down {
48
+ background-image:url(<?php print admin_url('images/fav-top.png'); ?>);
49
+ background-position:0 top;
50
+ background-repeat:repeat-x;
51
+ }
52
+
53
+ .update-results {
54
+ max-width: 100%;
55
+ overflow: auto;
56
+ }
57
+
58
+ </style>
59
+ <?php
60
+ } /* FeedWordPressSettingsUI::admin_styles () */
61
+
62
+ static function ajax_nonce_fields () {
63
+ if (function_exists('wp_nonce_field')) :
64
+ echo "<form style='display: none' method='get' action=''>\n<p>\n";
65
+ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
66
+ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
67
+ echo "</p>\n</form>\n";
68
+ endif;
69
+ } /* FeedWordPressSettingsUI::ajax_nonce_fields () */
70
+
71
+ static function fix_toggles_js ($context) {
72
+ ?>
73
+ <script type="text/javascript">
74
+ jQuery(document).ready( function($) {
75
+ // In case someone got here first...
76
+ $('.postbox h3, .postbox .handlediv').unbind('click');
77
+ $('.postbox h3 a').unbind('click');
78
+ $('.hide-postbox-tog').unbind('click');
79
+ $('.columns-prefs input[type="radio"]').unbind('click');
80
+ $('.meta-box-sortables').sortable('destroy');
81
+
82
+ postboxes.add_postbox_toggles('<?php print $context; ?>');
83
+ } );
84
+ </script>
85
+ <?php
86
+ } /* FeedWordPressSettingsUI::fix_toggles_js () */
87
+
88
+ static function magic_input_tip_js ($id) {
89
+ if (!preg_match('/^[.#]/', $id)) :
90
+ $id = '#'.$id;
91
+ endif;
92
+ ?>
93
+ <script type="text/javascript">
94
+ jQuery(document).ready( function () {
95
+ var inputBox = jQuery("<?php print $id; ?>");
96
+ var boxEl = inputBox.get(0);
97
+ if (boxEl.value==boxEl.defaultValue) { inputBox.addClass('form-input-tip'); }
98
+ inputBox.focus(function() {
99
+ if ( this.value == this.defaultValue )
100
+ jQuery(this).val( '' ).removeClass( 'form-input-tip' );
101
+ });
102
+ inputBox.blur(function() {
103
+ if ( this.value == '' )
104
+ jQuery(this).val( this.defaultValue ).addClass( 'form-input-tip' );
105
+ });
106
+ } );
107
+ </script>
108
+ <?php
109
+ } /* FeedWordPressSettingsUI::magic_input_tip_js () */
110
+ } /* class FeedWordPressSettingsUI */
111
+
feedwordpresssyndicationpage.class.php CHANGED
@@ -139,17 +139,18 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
139
  $update_set[] = $target->link_rss;
140
  endforeach;
141
  else : // This should never happen
142
- FeedWordPress::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
143
  endif;
144
  elseif (!is_null(MyPHP::post('update_uri'))) :
145
  $targets = MyPHP::post('update_uri');
146
  if (!is_array($targets)) :
147
  $targets = array($targets);
148
  endif;
149
-
150
- $first = each($targets);
151
- if (!is_numeric($first['key'])) : // URLs in keys
152
- $targets = array_keys($targets);
 
153
  endif;
154
  $update_set = $targets;
155
  endif;
@@ -439,7 +440,7 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
439
  ?>
440
  <div class="metabox-holder">
441
  <?php
442
- fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
443
  ?>
444
  </div> <!-- class="metabox-holder" -->
445
  </div> <!-- id="post-body" -->
@@ -454,8 +455,6 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
454
  } /* FeedWordPressSyndicationPage::display () */
455
 
456
  function dashboard_box ($page, $box = NULL) {
457
- global $fwp_path;
458
-
459
  $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
460
  $sources = $this->sources('*');
461
 
@@ -477,7 +476,7 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
477
 
478
  // Hey ho, let's go...
479
  ?>
480
- <div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_html(plugins_url( "/${fwp_path}/feedwordpress.png") ); ?>" alt="" /></a></div>
481
 
482
  <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
483
  <?php print FEEDWORDPRESS_VERSION; ?>.</p>
@@ -536,7 +535,7 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
536
 
537
  <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
538
  <input type="hidden" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
539
- <input style="vertical-align: middle;" type="image" src="<?php print plugins_url('/'.$fwp_path .'/plus.png' ); ?>" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
540
  </form>
541
  </div> <!-- id="add-single-uri" -->
542
 
@@ -546,7 +545,6 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
546
  } /* FeedWordPressSyndicationPage::dashboard_box () */
547
 
548
  function syndicated_sources_box ($page, $box = NULL) {
549
- global $fwp_path;
550
 
551
  $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
552
  $sources = $this->sources('*');
@@ -602,9 +600,9 @@ class FeedWordPressSyndicationPage extends FeedWordPressAdminPage {
602
 
603
  <input type="hidden" name="action" value="feedfinder" />
604
  <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
605
- <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print plugins_url('/' . $fwp_path . '/down.png'); ?>" alt="" /> add multiple</a>
606
  <span class="screen-reader-text"> or </span>
607
- <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print plugins_url('/' . $fwp_path . '/plus.png'); ?>" alt="" style="vertical-align: middle" /> import source list</a></div>
608
  </li>
609
  </ul>
610
  </form>
@@ -1198,7 +1196,7 @@ function fwp_feedfinder_page () {
1198
  } /* function fwp_feedfinder_page () */
1199
 
1200
  function fwp_switchfeed_page () {
1201
- global $wpdb, $wp_db_version;
1202
  global $fwp_post, $fwp_path;
1203
 
1204
  // If this is a POST, validate source and user credentials
139
  $update_set[] = $target->link_rss;
140
  endforeach;
141
  else : // This should never happen
142
+ FeedWordPressDiagnostic::critical_bug('fwp_syndication_manage_page::targets', $targets, __LINE__, __FILE__);
143
  endif;
144
  elseif (!is_null(MyPHP::post('update_uri'))) :
145
  $targets = MyPHP::post('update_uri');
146
  if (!is_array($targets)) :
147
  $targets = array($targets);
148
  endif;
149
+
150
+ $targets_keys = array_keys($targets);
151
+ $first_key = reset($targets_keys);
152
+ if (!is_numeric($first_key)) : // URLs in keys
153
+ $targets = $targets_keys;
154
  endif;
155
  $update_set = $targets;
156
  endif;
440
  ?>
441
  <div class="metabox-holder">
442
  <?php
443
+ do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
444
  ?>
445
  </div> <!-- class="metabox-holder" -->
446
  </div> <!-- id="post-body" -->
455
  } /* FeedWordPressSyndicationPage::display () */
456
 
457
  function dashboard_box ($page, $box = NULL) {
 
 
458
  $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
459
  $sources = $this->sources('*');
460
 
476
 
477
  // Hey ho, let's go...
478
  ?>
479
+ <div style="float: left; background: #F5F5F5; padding-top: 5px; padding-right: 5px;"><a href="<?php print $this->form_action(); ?>"><img src="<?php print esc_url(plugins_url( "feedwordpress.png", __FILE__ ) ); ?>" alt="" /></a></div>
480
 
481
  <p class="info" style="margin-bottom: 0px; border-bottom: 1px dotted black;">Managed by <a href="http://feedwordpress.radgeek.com/">FeedWordPress</a>
482
  <?php print FEEDWORDPRESS_VERSION; ?>.</p>
535
 
536
  <?php FeedWordPressSettingsUI::magic_input_tip_js('add-uri'); ?>
537
  <input type="hidden" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
538
+ <input style="vertical-align: middle;" type="image" src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="<?php print FWP_SYNDICATE_NEW; ?>" /></div>
539
  </form>
540
  </div> <!-- id="add-single-uri" -->
541
 
545
  } /* FeedWordPressSyndicationPage::dashboard_box () */
546
 
547
  function syndicated_sources_box ($page, $box = NULL) {
 
548
 
549
  $links = FeedWordPress::syndicated_links(array("hide_invisible" => false));
550
  $sources = $this->sources('*');
600
 
601
  <input type="hidden" name="action" value="feedfinder" />
602
  <input type="submit" class="button-secondary" name="action" value="<?php print FWP_SYNDICATE_NEW; ?>" />
603
+ <div style="text-align: right; margin-right: 2.0em"><a id="turn-on-multiple-sources" href="#add-multiple-uri"><img style="vertical-align: middle" src="<?php print esc_url(plugins_url('down.png', __FILE__)); ?>" alt="" /> add multiple</a>
604
  <span class="screen-reader-text"> or </span>
605
+ <a id="turn-on-opml-upload" href="#upload-opml"><img src="<?php print esc_url(plugins_url('plus.png', __FILE__)); ?>" alt="" style="vertical-align: middle" /> import source list</a></div>
606
  </li>
607
  </ul>
608
  </form>
1196
  } /* function fwp_feedfinder_page () */
1197
 
1198
  function fwp_switchfeed_page () {
1199
+ global $wpdb;
1200
  global $fwp_post, $fwp_path;
1201
 
1202
  // If this is a POST, validate source and user credentials
performance-page.php CHANGED
@@ -12,9 +12,6 @@ class FeedWordPressPerformancePage extends FeedWordPressAdminPage {
12
  public function has_link () { return false; }
13
 
14
  function display () {
15
- global $wpdb, $wp_db_version, $fwp_path;
16
- global $fwp_post;
17
-
18
  if (FeedWordPress::needs_upgrade()) :
19
  fwp_upgrade_page();
20
  return;
@@ -24,8 +21,8 @@ class FeedWordPressPerformancePage extends FeedWordPressAdminPage {
24
  FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_performance', /*capability=*/ 'manage_options');
25
 
26
  if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
27
- $this->accept_POST($fwp_post);
28
- do_action('feedwordpress_admin_page_performance_save', $fwp_post, $this);
29
  endif;
30
 
31
  ////////////////////////////////////////////////
@@ -55,7 +52,7 @@ class FeedWordPressPerformancePage extends FeedWordPressAdminPage {
55
  ?>
56
  <div class="metabox-holder">
57
  <?php
58
- fwp_do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
59
  ?>
60
  </div> <!-- class="metabox-holder" -->
61
  </div> <!-- id="post-body" -->
12
  public function has_link () { return false; }
13
 
14
  function display () {
 
 
 
15
  if (FeedWordPress::needs_upgrade()) :
16
  fwp_upgrade_page();
17
  return;
21
  FeedWordPressCompatibility::validate_http_request(/*action=*/ 'feedwordpress_performance', /*capability=*/ 'manage_options');
22
 
23
  if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') :
24
+ $this->accept_POST($_POST);
25
+ do_action('feedwordpress_admin_page_performance_save', $_POST, $this);
26
  endif;
27
 
28
  ////////////////////////////////////////////////
52
  ?>
53
  <div class="metabox-holder">
54
  <?php
55
+ do_meta_boxes($this->meta_box_context(), $this->meta_box_context(), $this);
56
  ?>
57
  </div> <!-- class="metabox-holder" -->
58
  </div> <!-- id="post-body" -->
readme.txt CHANGED
@@ -1,10 +1,12 @@
1
  === FeedWordPress ===
2
  Contributors: C. Johnson
3
- Donate link: http://feedwordpress.radgeek.com/
4
  Tags: syndication, aggregation, feed, atom, rss
5
  Requires at least: 4.5
6
- Tested up to: 4.8.2
7
- Stable tag: 2017.1020
 
 
8
 
9
  FeedWordPress syndicates content from feeds you choose into your WordPress weblog.
10
 
@@ -20,15 +22,14 @@ FeedWordPress is an Atom/RSS aggregator for WordPress. It syndicates content fro
20
 
21
  FeedWordPress is designed with flexibility, ease of use, and ease of configuration in mind. You'll need a working installation of WordPress (version [4.5][] or later), and it helps to have SFTP or FTP access to your web host. The ability to create cron jobs on your web host is helpful but not required.
22
 
23
- [WordPress]: http://wordpress.org/
24
- [WordPress MU]: http://mu.wordpress.org/
25
  [4.5]: http://codex.wordpress.org/Version_4.5
26
 
27
  == Installation ==
28
 
29
  To use FeedWordPress, you will need:
30
 
31
- * an installed and configured copy of [WordPress][] (version 4.5 or later).
32
 
33
  * the ability to install new plugins on your site using either WordPress's Plugins Repository, SFTP, FTP or shell access to your web host
34
 
@@ -1919,8 +1920,7 @@ between version 0.98 of WordPress and the recently released WordPress 2.1.
1919
 
1920
  == License ==
1921
 
1922
- The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses
1923
- code derived or translated from:
1924
 
1925
  - [wp-rss-aggregate.php][] by [Kellan Elliot-McCrea](kellan@protest.net)
1926
  - [SimplePie][] feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al.
@@ -1930,14 +1930,9 @@ code derived or translated from:
1930
 
1931
  according to the terms of the [GNU General Public License][].
1932
 
1933
- This program is free software; you can redistribute it and/or modify it under
1934
- the terms of the [GNU General Public License][] as published by the Free
1935
- Software Foundation; either version 2 of the License, or (at your option) any
1936
- later version.
1937
 
1938
- This program is distributed in the hope that it will be useful, but WITHOUT ANY
1939
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
1940
- PARTICULAR PURPOSE. See the GNU General Public License for more details.
1941
 
1942
  [wp-rss-aggregate.php]: http://laughingmeme.org/archives/002203.html
1943
  [SimplePie]: http://www.simplepie.org/
1
  === FeedWordPress ===
2
  Contributors: C. Johnson
3
+ Donate link: http://feedwordpress.radgeek.com/donate/
4
  Tags: syndication, aggregation, feed, atom, rss
5
  Requires at least: 4.5
6
+ Tested up to: 5.3.2
7
+ Stable tag: 2020.0118
8
+ License: GPLv2 or later
9
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  FeedWordPress syndicates content from feeds you choose into your WordPress weblog.
12
 
22
 
23
  FeedWordPress is designed with flexibility, ease of use, and ease of configuration in mind. You'll need a working installation of WordPress (version [4.5][] or later), and it helps to have SFTP or FTP access to your web host. The ability to create cron jobs on your web host is helpful but not required.
24
 
25
+ [WordPress]: https://wordpress.org/
 
26
  [4.5]: http://codex.wordpress.org/Version_4.5
27
 
28
  == Installation ==
29
 
30
  To use FeedWordPress, you will need:
31
 
32
+ * an installed and configured copy of [WordPress](https://wordpress.org/) (version 4.5 or later).
33
 
34
  * the ability to install new plugins on your site using either WordPress's Plugins Repository, SFTP, FTP or shell access to your web host
35
 
1920
 
1921
  == License ==
1922
 
1923
+ The FeedWordPress plugin is copyright © 2005-2017 by Charles Johnson. It uses code derived or translated from:
 
1924
 
1925
  - [wp-rss-aggregate.php][] by [Kellan Elliot-McCrea](kellan@protest.net)
1926
  - [SimplePie][] feed parser by Ryan Parman, Geoffrey Sneddon, Ryan McCue, et al.
1930
 
1931
  according to the terms of the [GNU General Public License][].
1932
 
1933
+ This program is free software; you can redistribute it and/or modify it under the terms of the [GNU General Public License][] as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 
 
 
1934
 
1935
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
 
1936
 
1937
  [wp-rss-aggregate.php]: http://laughingmeme.org/archives/002203.html
1938
  [SimplePie]: http://www.simplepie.org/
syndicatedlink.class.php CHANGED
@@ -128,6 +128,10 @@ class SyndicatedLink {
128
  return $ret;
129
  } /* SyndicatedLink::live_posts () */
130
 
 
 
 
 
131
  public function poll ($crash_ts = NULL) {
132
  global $wpdb;
133
 
@@ -211,6 +215,8 @@ class SyndicatedLink {
211
  endif;
212
  endif;
213
 
 
 
214
  $this->merge_settings($channel, 'feed/');
215
 
216
  $this->update_setting('update/last', time());
@@ -275,23 +281,24 @@ class SyndicatedLink {
275
 
276
  if (is_array($posts)) :
277
  foreach ($posts as $key => $item) :
278
- $post = new SyndicatedPost($item, $this);
279
-
280
- if (!$resume or !in_array(trim($post->guid()), $processed)) :
281
- $processed[] = $post->guid();
282
- if (!$post->filtered()) :
283
- $new = $post->store();
284
- if ( $new !== false ) $new_count[$new]++;
285
- endif;
 
286
 
287
- if (!is_null($crash_ts) and (time() > $crash_ts)) :
288
- $crashed = true;
289
- break;
 
290
  endif;
291
- endif;
292
 
293
- unset($post);
294
-
295
  endforeach;
296
  endif;
297
 
@@ -299,7 +306,7 @@ class SyndicatedLink {
299
  // Check for use of Atom tombstones. Spec:
300
  // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18>
301
  $tombstones = $this->simplepie->get_feed_tags('http://purl.org/atompub/tombstones/1.0', 'deleted-entry');
302
- if (count($tombstones) > 0) :
303
  foreach ($tombstones as $tombstone) :
304
  $ref = NULL;
305
  foreach (array('', 'http://purl.org/atompub/tombstones/1.0') as $ns) :
@@ -740,6 +747,42 @@ class SyndicatedLink {
740
  return ('complete'==$this->setting('update_incremental', 'update_incremental', 'incremental'));
741
  } /* SyndicatedLink::is_non_incremental () */
742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743
  public function uri ($params = array()) {
744
  $params = wp_parse_args($params, array(
745
  'add_params' => false,
128
  return $ret;
129
  } /* SyndicatedLink::live_posts () */
130
 
131
+ protected function pause_updates () {
132
+ return ('yes'==$this->setting("update/pause", "update_pause", 'no'));
133
+ } /* SyndicatedLink::pause_updates () */
134
+
135
  public function poll ($crash_ts = NULL) {
136
  global $wpdb;
137
 
215
  endif;
216
  endif;
217
 
218
+ $this->update_setting('link/feed_type', $this->simplepie->get_type());
219
+
220
  $this->merge_settings($channel, 'feed/');
221
 
222
  $this->update_setting('update/last', time());
281
 
282
  if (is_array($posts)) :
283
  foreach ($posts as $key => $item) :
284
+ if (!$this->pause_updates()) :
285
+ $post = new SyndicatedPost($item, $this);
286
+
287
+ if (!$resume or !in_array(trim($post->guid()), $processed)) :
288
+ $processed[] = $post->guid();
289
+ if (!$post->filtered()) :
290
+ $new = $post->store();
291
+ if ( $new !== false ) $new_count[$new]++;
292
+ endif;
293
 
294
+ if (!is_null($crash_ts) and (time() > $crash_ts)) :
295
+ $crashed = true;
296
+ break;
297
+ endif;
298
  endif;
 
299
 
300
+ unset($post);
301
+ endif;
302
  endforeach;
303
  endif;
304
 
306
  // Check for use of Atom tombstones. Spec:
307
  // <http://tools.ietf.org/html/draft-snell-atompub-tombstones-18>
308
  $tombstones = $this->simplepie->get_feed_tags('http://purl.org/atompub/tombstones/1.0', 'deleted-entry');
309
+ if (!is_null($tombstones) && count($tombstones) > 0) :
310
  foreach ($tombstones as $tombstone) :
311
  $ref = NULL;
312
  foreach (array('', 'http://purl.org/atompub/tombstones/1.0') as $ns) :
747
  return ('complete'==$this->setting('update_incremental', 'update_incremental', 'incremental'));
748
  } /* SyndicatedLink::is_non_incremental () */
749
 
750
+ public function get_feed_type () {
751
+ $type_code = $this->setting('link/feed_type');
752
+
753
+ // list derived from: <http://simplepie.org/api/class-SimplePie.html>, retrieved 2020/01/18
754
+ $bitmasks = array(
755
+ SIMPLEPIE_TYPE_RSS_090 => 'RSS 0.90',
756
+ SIMPLEPIE_TYPE_RSS_091_NETSCAPE => 'RSS 0.91 (Netscape)',
757
+ SIMPLEPIE_TYPE_RSS_091_USERLAND => 'RSS 0.91 (Userland)',
758
+ SIMPLEPIE_TYPE_RSS_091 => 'RSS 0.91',
759
+ SIMPLEPIE_TYPE_RSS_092 => 'RSS 0.92',
760
+ SIMPLEPIE_TYPE_RSS_093 => 'RSS 0.93',
761
+ SIMPLEPIE_TYPE_RSS_094 => 'RSS 0.94',
762
+ SIMPLEPIE_TYPE_RSS_10 => 'RSS 1.0',
763
+ SIMPLEPIE_TYPE_RSS_20 => 'RSS 2.0.x',
764
+ SIMPLEPIE_TYPE_RSS_RDF => 'RDF-based RSS',
765
+ SIMPLEPIE_TYPE_RSS_SYNDICATION => 'Non-RDF-based RSS',
766
+ SIMPLEPIE_TYPE_RSS_ALL => 'Any version of RSS',
767
+ SIMPLEPIE_TYPE_ATOM_03 => 'Atom 0.3',
768
+ SIMPLEPIE_TYPE_ATOM_10 => 'Atom 1.0',
769
+ SIMPLEPIE_TYPE_ATOM_ALL => 'Atom (any version)',
770
+ SIMPLEPIE_TYPE_ALL => 'Supported Feed (unspecified format)',
771
+ );
772
+
773
+ $type = "Unknown or unsupported format";
774
+ foreach ($bitmasks as $format_flag => $format_string) :
775
+ if (is_numeric($format_flag)) : // Guard against failure of constants to be defined.
776
+ if ($type_code & $format_flag) :
777
+ $type = $format_string;
778
+ break; // foreach
779
+ endif;
780
+ endif;
781
+ endforeach;
782
+
783
+ return $type;
784
+ } /* SyndicatedLink::get_feed_type () */
785
+
786
  public function uri ($params = array()) {
787
  $params = wp_parse_args($params, array(
788
  'add_params' => false,
syndicatedpost.class.php CHANGED
@@ -1228,7 +1228,7 @@ class SyndicatedPost {
1228
  global $wpdb;
1229
 
1230
  if ($this->filtered()) : // This should never happen.
1231
- FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1232
  endif;
1233
 
1234
  if (is_null($this->_freshness)) : // Not yet checked and cached.
@@ -1244,7 +1244,9 @@ class SyndicatedPost {
1244
  $old_post = NULL;
1245
  if ($q->have_posts()) :
1246
  while ($q->have_posts()) : $q->the_post();
1247
- $old_post = $q->post;
 
 
1248
  endwhile;
1249
  endif;
1250
 
@@ -1305,7 +1307,7 @@ class SyndicatedPost {
1305
  $updated = true; // Can't find syndication meta-data
1306
  endif;
1307
 
1308
- if ($updated and FeedWordPress::diagnostic_on('feed_items:freshness:reasons')) :
1309
  // In the absence of definitive
1310
  // timestamp information, we
1311
  // just have to assume that a
@@ -1451,7 +1453,7 @@ class SyndicatedPost {
1451
 
1452
  function wp_id () {
1453
  if ($this->filtered()) : // This should never happen.
1454
- FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1455
  endif;
1456
 
1457
  if (is_null($this->_wp_id) and is_null($this->_freshness)) :
@@ -1460,120 +1462,163 @@ class SyndicatedPost {
1460
  return $this->_wp_id;
1461
  }
1462
 
1463
- public function store () {
1464
- global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1465
 
1466
- if ($this->filtered()) : // This should never happen.
1467
- FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
 
1468
  endif;
 
1469
 
1470
- $freshness = $this->freshness();
1471
- if ($this->has_fresh_content()) :
1472
- # -- Look up, or create, numeric ID for author
1473
- $this->post['post_author'] = $this->author_id (
1474
- $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create')
1475
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1476
 
1477
- if (is_null($this->post['post_author'])) :
1478
- FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available');
1479
- $this->post = NULL;
1480
- endif;
1481
- endif;
 
 
 
 
1482
 
1483
- // We have to check again in case post has been filtered during
1484
- // the author_id lookup
1485
- if ($this->has_fresh_content()) :
1486
- $mapping = apply_filters('syndicated_post_terms_mapping', array(
1487
- 'category' => array('abbr' => 'cats', 'unfamiliar' => 'category', 'domain' => array('category', 'post_tag')),
1488
- 'post_tag' => array('abbr' => 'tags', 'unfamiliar' => 'post_tag', 'domain' => array('post_tag')),
1489
- ), $this);
1490
-
1491
- $termSet = array(); $valid = null;
1492
- foreach ($this->feed_terms as $what => $anTerms) :
1493
- // Default to using the inclusive procedures (for cats) rather than exclusive (for inline tags)
1494
- $taxes = (isset($mapping[$what]) ? $mapping[$what] : $mapping['category']);
1495
- $unfamiliar = $taxes['unfamiliar'];
1496
-
1497
- if (!is_null($this->post)) : // Not filtered out yet
1498
- # -- Look up, or create, numeric ID for categories
1499
- $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']);
1500
-
1501
- // Eliminate dummy variables
1502
- $taxonomies = array_filter($taxonomies, 'remove_dummy_zero');
1503
-
1504
- // Allow FWP add-on filters to control the taxonomies we use to search for a term
1505
- $taxonomies = apply_filters("syndicated_post_terms_match", $taxonomies, $what, $this);
1506
- $taxonomies = apply_filters("syndicated_post_terms_match_${what}", $taxonomies, $this);
1507
-
1508
- // Allow FWP add-on filters to control with greater precision what happens on unmatched
1509
- $unmatched = apply_filters("syndicated_post_terms_unfamiliar",
1510
- $this->link->setting(
1511
- "unfamiliar {$unfamiliar}",
1512
- "unfamiliar_{$unfamiliar}",
1513
- 'create:'.$unfamiliar
1514
- ),
1515
- $what,
1516
- $this
1517
- );
1518
 
1519
- $terms = $this->category_ids (
1520
- $anTerms,
1521
- $unmatched,
1522
- /*taxonomies=*/ $taxonomies,
1523
- array(
1524
- 'singleton' => false, // I don't like surprises
1525
- 'filters' => true,
1526
- )
1527
- );
 
1528
 
1529
- if (is_null($terms) or is_null($termSet)) :
1530
- // filtered out -- no matches
1531
- else :
1532
- $valid = true;
1533
-
1534
- // filter mode off, or at least one match
1535
- foreach ($terms as $tax => $term_ids) :
1536
- if (!isset($termSet[$tax])) :
1537
- $termSet[$tax] = array();
1538
- endif;
1539
- $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
1540
- endforeach;
1541
- endif;
1542
  endif;
 
 
 
 
1543
  endforeach;
1544
 
1545
- if (is_null($valid)) : // Plonked
1546
- $this->post = NULL;
1547
- else : // We can proceed
1548
- $this->post['tax_input'] = array();
1549
- foreach ($termSet as $tax => $term_ids) :
1550
- if (!isset($this->post['tax_input'][$tax])) :
1551
- $this->post['tax_input'][$tax] = array();
1552
- endif;
1553
- $this->post['tax_input'][$tax] = array_merge(
1554
- $this->post['tax_input'][$tax],
1555
- $term_ids
1556
- );
1557
- endforeach;
1558
 
1559
- // Now let's add on the feed and global presets
1560
- foreach ($this->preset_terms as $tax => $term_ids) :
1561
- if (!isset($this->post['tax_input'][$tax])) :
1562
- $this->post['tax_input'][$tax] = array();
1563
- endif;
 
 
 
 
 
 
 
 
1564
 
1565
- $this->post['tax_input'][$tax] = array_merge (
1566
- $this->post['tax_input'][$tax],
1567
- $this->category_ids (
1568
- /*terms=*/ $term_ids,
1569
- /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist
1570
- /*taxonomies=*/ array($tax),
1571
- array(
1572
- 'singleton' => true,
1573
- ))
1574
- );
1575
- endforeach;
1576
- endif;
 
 
 
 
 
 
 
1577
  endif;
1578
 
1579
  // We have to check again in case the post has been filtered
@@ -1786,10 +1831,22 @@ class SyndicatedPost {
1786
  return $ret;
1787
  } /* function SyndicatedPost::insert_post () */
1788
 
 
 
 
 
 
 
1789
  function insert_new () {
1790
  $this->insert_post(/*update=*/ false, 1);
1791
  } /* SyndicatedPost::insert_new() */
1792
 
 
 
 
 
 
 
1793
  function update_existing () {
1794
  $this->insert_post(/*update=*/ true, 2);
1795
  } /* SyndicatedPost::update_existing() */
@@ -1934,7 +1991,7 @@ The WordPress API returned an invalid post ID
1934
 
1935
  $ns::_wp_id
1936
  EOM;
1937
- FeedWordPress::noncritical_bug(
1938
  /*message=*/ $mesg,
1939
  /*var =*/ array(
1940
  "\$this->_wp_id" => $this->_wp_id,
@@ -2142,13 +2199,14 @@ EOM;
2142
  // or forbidden names.
2143
 
2144
  $author = NULL;
2145
- while (is_null($author) and ($candidate = each($candidates))) :
2146
- if (!is_null($candidate['value'])
2147
- and (strlen(trim($candidate['value'])) > 0)
2148
- and !in_array(strtolower(trim($candidate['value'])), $forbidden)) :
2149
- $author = $candidate['value'];
 
2150
  endif;
2151
- endwhile;
2152
 
2153
  $email = (isset($a['email']) ? $a['email'] : NULL);
2154
  $authorUrl = (isset($a['uri']) ? $a['uri'] : NULL);
@@ -2252,9 +2310,9 @@ EOM;
2252
  if ($unfamiliar_author === 'create') :
2253
  $userdata = array();
2254
 
2255
- // WordPress 3 is going to pitch a fit if we attempt to register
2256
- // more than one user account with an empty e-mail address, so we
2257
- // need *something* here. Ugh.
2258
  if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) :
2259
  $url = parse_url($hostUrl);
2260
  $email = $nice_author.'@'.$url['host'];
@@ -2268,13 +2326,17 @@ EOM;
2268
  $userdata['user_email'] = $email;
2269
  $userdata['user_url'] = $authorUrl;
2270
  $userdata['nickname'] = $author;
 
2271
  $parts = preg_split('/\s+/', trim($author), 2);
2272
  if (isset($parts[0])) : $userdata['first_name'] = $parts[0]; endif;
2273
  if (isset($parts[1])) : $userdata['last_name'] = $parts[1]; endif;
 
2274
  $userdata['display_name'] = $author;
2275
  $userdata['role'] = 'contributor';
2276
 
2277
- do { // Keep trying until you get it right. Or until PHP crashes, I guess.
 
 
2278
  $id = wp_insert_user($userdata);
2279
  if (is_wp_error($id)) :
2280
  $codes = $id->get_error_code();
@@ -2285,11 +2347,11 @@ EOM;
2285
  $userdata['user_login'] .= substr(md5(uniqid(microtime())), 0, 6);
2286
  break;
2287
  case 'user_nicename_too_long' :
2288
- // Add a limited 50 caracters user_nicename based on user_login
2289
  $userdata['user_nicename'] = mb_substr( $userdata['user_login'], 0, 50 );
2290
  break;
2291
  case 'existing_user_email' :
2292
- // No disassemble!
2293
  $parts = explode('@', $userdata['user_email'], 2);
2294
 
2295
  // Add a random disambiguator as a gmail-style username extension
@@ -2301,6 +2363,14 @@ EOM;
2301
  endswitch;
2302
  endif;
2303
  } while (is_wp_error($id));
 
 
 
 
 
 
 
 
2304
  elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) :
2305
  $id = (int) $unfamiliar_author;
2306
  elseif ($unfamiliar_author === 'default') :
1228
  global $wpdb;
1229
 
1230
  if ($this->filtered()) : // This should never happen.
1231
+ FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1232
  endif;
1233
 
1234
  if (is_null($this->_freshness)) : // Not yet checked and cached.
1244
  $old_post = NULL;
1245
  if ($q->have_posts()) :
1246
  while ($q->have_posts()) : $q->the_post();
1247
+ if (get_post_type($q->post->ID) == $this->post['post_type']):
1248
+ $old_post = $q->post;
1249
+ endif;
1250
  endwhile;
1251
  endif;
1252
 
1307
  $updated = true; // Can't find syndication meta-data
1308
  endif;
1309
 
1310
+ if ($updated and FeedWordPressDiagnostic::is_on('feed_items:freshness:reasons')) :
1311
  // In the absence of definitive
1312
  // timestamp information, we
1313
  // just have to assume that a
1453
 
1454
  function wp_id () {
1455
  if ($this->filtered()) : // This should never happen.
1456
+ FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1457
  endif;
1458
 
1459
  if (is_null($this->_wp_id) and is_null($this->_freshness)) :
1462
  return $this->_wp_id;
1463
  }
1464
 
1465
+ /**
1466
+ * SyndicatedPost::secure_author_id(). Look up, or create, a numeric ID
1467
+ * for the author of the incoming post.
1468
+ *
1469
+ * side effect: int|NULL stored in $this->post['post_author']
1470
+ * side effect: IF no valid author is found, NULL stored in $this->post
1471
+ * side effect: diagnostic output in case item is rejected with NULL author
1472
+ *
1473
+ * @used-by SyndicatedPost::store
1474
+ *
1475
+ * @uses SyndicatedPost::post
1476
+ * @uses SyndicatedPost::author_id
1477
+ * @uses SyndicatedLink::setting
1478
+ * @uses FeedWordPress::diagnostic
1479
+ */
1480
+ protected function secure_author_id () {
1481
+ # -- Look up, or create, numeric ID for author
1482
+ $this->post['post_author'] = $this->author_id (
1483
+ $this->link->setting('unfamiliar author', 'unfamiliar_author', 'create')
1484
+ );
1485
 
1486
+ if (is_null($this->post['post_author'])) :
1487
+ FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item ['.$this->guid().'] without syndication: no author available');
1488
+ $this->post = NULL;
1489
  endif;
1490
+ } /* SyndicatedPost::secure_author_id() */
1491
 
1492
+ /**
1493
+ * SyndicatedPost::secure_term_ids(). Look up, or create, numeric IDs
1494
+ * for the terms (categories, tags, etc.) assigned to the incoming post,
1495
+ * whether by global settings, feed settings, or by the tags on the feed.
1496
+ *
1497
+ * side effect: array of term ids stored in $this->post['tax_input']
1498
+ * side effect: IF settings or filters determine post should be filtered out,
1499
+ * NULL stored in $this->post
1500
+ *
1501
+ * @used-by SyndicatedPost::store
1502
+ *
1503
+ * @uses apply_filters
1504
+ * @uses SyndicatedLink::setting
1505
+ * @uses SyndicatedPost::category_ids
1506
+ * @uses SyndicatedPost::preset_terms
1507
+ * @uses SyndicatedPost::post
1508
+ */
1509
+ protected function secure_term_ids () {
1510
+ $mapping = apply_filters('syndicated_post_terms_mapping', array(
1511
+ 'category' => array('abbr' => 'cats', 'unfamiliar' => 'category', 'domain' => array('category', 'post_tag')),
1512
+ 'post_tag' => array('abbr' => 'tags', 'unfamiliar' => 'post_tag', 'domain' => array('post_tag')),
1513
+ ), $this);
1514
+
1515
+ $termSet = array(); $valid = null;
1516
+ foreach ($this->feed_terms as $what => $anTerms) :
1517
+ // Default to using the inclusive procedures (for cats) rather than exclusive (for inline tags)
1518
+ $taxes = (isset($mapping[$what]) ? $mapping[$what] : $mapping['category']);
1519
+ $unfamiliar = $taxes['unfamiliar'];
1520
+
1521
+ if (!is_null($this->post)) : // Not filtered out yet
1522
+ # -- Look up, or create, numeric ID for categories
1523
+ $taxonomies = $this->link->setting("match/".$taxes['abbr'], 'match_'.$taxes['abbr'], $taxes['domain']);
1524
+
1525
+ // Eliminate dummy variables
1526
+ $taxonomies = array_filter($taxonomies, 'remove_dummy_zero');
1527
+
1528
+ // Allow FWP add-on filters to control the taxonomies we use to search for a term
1529
+ $taxonomies = apply_filters("syndicated_post_terms_match", $taxonomies, $what, $this);
1530
+ $taxonomies = apply_filters("syndicated_post_terms_match_${what}", $taxonomies, $this);
1531
+
1532
+ // Allow FWP add-on filters to control with greater precision what happens on unmatched
1533
+ $unmatched = apply_filters("syndicated_post_terms_unfamiliar",
1534
+ $this->link->setting(
1535
+ "unfamiliar {$unfamiliar}",
1536
+ "unfamiliar_{$unfamiliar}",
1537
+ 'create:'.$unfamiliar
1538
+ ),
1539
+ $what,
1540
+ $this
1541
+ );
1542
 
1543
+ $terms = $this->category_ids (
1544
+ $anTerms,
1545
+ $unmatched,
1546
+ /*taxonomies=*/ $taxonomies,
1547
+ array(
1548
+ 'singleton' => false, // I don't like surprises
1549
+ 'filters' => true,
1550
+ )
1551
+ );
1552
 
1553
+ if (is_null($terms) or is_null($termSet)) :
1554
+ // filtered out -- no matches
1555
+ else :
1556
+ $valid = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1557
 
1558
+ // filter mode off, or at least one match
1559
+ foreach ($terms as $tax => $term_ids) :
1560
+ if (!isset($termSet[$tax])) :
1561
+ $termSet[$tax] = array();
1562
+ endif;
1563
+ $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
1564
+ endforeach;
1565
+ endif;
1566
+ endif;
1567
+ endforeach;
1568
 
1569
+ if (is_null($valid)) : // Plonked
1570
+ $this->post = NULL;
1571
+ else : // We can proceed
1572
+ $this->post['tax_input'] = array();
1573
+ foreach ($termSet as $tax => $term_ids) :
1574
+ if (!isset($this->post['tax_input'][$tax])) :
1575
+ $this->post['tax_input'][$tax] = array();
 
 
 
 
 
 
1576
  endif;
1577
+ $this->post['tax_input'][$tax] = array_merge(
1578
+ $this->post['tax_input'][$tax],
1579
+ $term_ids
1580
+ );
1581
  endforeach;
1582
 
1583
+ // Now let's add on the feed and global presets
1584
+ foreach ($this->preset_terms as $tax => $term_ids) :
1585
+ if (!isset($this->post['tax_input'][$tax])) :
1586
+ $this->post['tax_input'][$tax] = array();
1587
+ endif;
 
 
 
 
 
 
 
 
1588
 
1589
+ $this->post['tax_input'][$tax] = array_merge (
1590
+ $this->post['tax_input'][$tax],
1591
+ $this->category_ids (
1592
+ /*terms=*/ $term_ids,
1593
+ /*unfamiliar=*/ 'create:'.$tax, // These are presets; for those added in a tagbox editor, the tag may not yet exist
1594
+ /*taxonomies=*/ array($tax),
1595
+ array(
1596
+ 'singleton' => true,
1597
+ ))
1598
+ );
1599
+ endforeach;
1600
+ endif;
1601
+ } /* SyndicatedPost::secure_term_ids() */
1602
 
1603
+ /**
1604
+ * SyndicatedPost::store
1605
+ *
1606
+ * @uses SyndicatedPost::secure_author_id
1607
+ */
1608
+ public function store () {
1609
+ global $wpdb;
1610
+
1611
+ if ($this->filtered()) : // This should never happen.
1612
+ FeedWordPressDiagnostic::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
1613
+ endif;
1614
+
1615
+ $freshness = $this->freshness();
1616
+ if ($this->has_fresh_content()) :
1617
+ $this->secure_author_id();
1618
+ endif;
1619
+
1620
+ if ($this->has_fresh_content()) : // Was this filtered during author_id lookup?
1621
+ $this->secure_term_ids();
1622
  endif;
1623
 
1624
  // We have to check again in case the post has been filtered
1831
  return $ret;
1832
  } /* function SyndicatedPost::insert_post () */
1833
 
1834
+ /**
1835
+ * SyndicatedPost::insert_new(). Uses the data collected in this post object to insert
1836
+ * a new post into the wp_posts table.
1837
+ *
1838
+ * @uses SyndicatedPost::insert_post
1839
+ */
1840
  function insert_new () {
1841
  $this->insert_post(/*update=*/ false, 1);
1842
  } /* SyndicatedPost::insert_new() */
1843
 
1844
+ /**
1845
+ * SyndicatedPost::insert_new(). Uses the data collected in this post object to update
1846
+ * an existing post in the wp_posts table.
1847
+ *
1848
+ * @uses SyndicatedPost::insert_post
1849
+ */
1850
  function update_existing () {
1851
  $this->insert_post(/*update=*/ true, 2);
1852
  } /* SyndicatedPost::update_existing() */
1991
 
1992
  $ns::_wp_id
1993
  EOM;
1994
+ FeedWordPressDiagnostic::noncritical_bug(
1995
  /*message=*/ $mesg,
1996
  /*var =*/ array(
1997
  "\$this->_wp_id" => $this->_wp_id,
2199
  // or forbidden names.
2200
 
2201
  $author = NULL;
2202
+ foreach ($candidates as $candidate) {
2203
+ if (!is_null($candidate)
2204
+ and (strlen(trim($candidate)) > 0)
2205
+ and !in_array(strtolower(trim($candidate)), $forbidden)) :
2206
+ $author = $candidate;
2207
+ break;
2208
  endif;
2209
+ }
2210
 
2211
  $email = (isset($a['email']) ? $a['email'] : NULL);
2212
  $authorUrl = (isset($a['uri']) ? $a['uri'] : NULL);
2310
  if ($unfamiliar_author === 'create') :
2311
  $userdata = array();
2312
 
2313
+ #-- we need *something* for the email here or WordPress
2314
+ #-- is liable to pitch a fit. So, make something up if
2315
+ #-- necessary. (Ugh.)
2316
  if (strlen($email) == 0 or FeedWordPress::is_null_email($email)) :
2317
  $url = parse_url($hostUrl);
2318
  $email = $nice_author.'@'.$url['host'];
2326
  $userdata['user_email'] = $email;
2327
  $userdata['user_url'] = $authorUrl;
2328
  $userdata['nickname'] = $author;
2329
+
2330
  $parts = preg_split('/\s+/', trim($author), 2);
2331
  if (isset($parts[0])) : $userdata['first_name'] = $parts[0]; endif;
2332
  if (isset($parts[1])) : $userdata['last_name'] = $parts[1]; endif;
2333
+
2334
  $userdata['display_name'] = $author;
2335
  $userdata['role'] = 'contributor';
2336
 
2337
+ #-- loop. Keep trying to add the user until you get it
2338
+ #-- right. Or until PHP crashes, I guess.
2339
+ do {
2340
  $id = wp_insert_user($userdata);
2341
  if (is_wp_error($id)) :
2342
  $codes = $id->get_error_code();
2347
  $userdata['user_login'] .= substr(md5(uniqid(microtime())), 0, 6);
2348
  break;
2349
  case 'user_nicename_too_long' :
2350
+ // Add a limited 50 characters user_nicename based on user_login
2351
  $userdata['user_nicename'] = mb_substr( $userdata['user_login'], 0, 50 );
2352
  break;
2353
  case 'existing_user_email' :
2354
+ // Disassemble email for username, host
2355
  $parts = explode('@', $userdata['user_email'], 2);
2356
 
2357
  // Add a random disambiguator as a gmail-style username extension
2363
  endswitch;
2364
  endif;
2365
  } while (is_wp_error($id));
2366
+
2367
+ // $id should now contain the numeric ID of a newly minted
2368
+ // user account. Let's mark them as having been generated
2369
+ // by FeedWordPress in the usermeta table, as per the
2370
+ // suggestion of @boonebgorges, in case we need to process,
2371
+ // winnow, filter, or merge syndicated author accounts, &c.
2372
+ add_user_meta($id, 'feedwordpress_generated', 1);
2373
+
2374
  elseif (is_numeric($unfamiliar_author) and get_userdata((int) $unfamiliar_author)) :
2375
  $id = (int) $unfamiliar_author;
2376
  elseif ($unfamiliar_author === 'default') :
syndicatedpostterm.class.php CHANGED
@@ -181,11 +181,11 @@ class SyndicatedPostTerm {
181
  if (is_wp_error($aTerm)) :
182
 
183
  // If debug mode is ON, this will halt us here.
184
- FeedWordPress::noncritical_bug(
185
  'term insertion problem', array(
186
  'term' => $this->term,
187
  'result' => $aTerm,
188
- 'post' => $post,
189
  'this' => $this
190
  ), __LINE__, __FILE__
191
  );
181
  if (is_wp_error($aTerm)) :
182
 
183
  // If debug mode is ON, this will halt us here.
184
+ FeedWordPressDiagnostic::noncritical_bug(
185
  'term insertion problem', array(
186
  'term' => $this->term,
187
  'result' => $aTerm,
188
+ 'post' => $this->post,
189
  'this' => $this
190
  ), __LINE__, __FILE__
191
  );
template-functions.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ ################################################################################
3
+ ## TEMPLATE API: functions to make your templates syndication-aware ############
4
+ ################################################################################
5
+
6
+ /**
7
+ * is_syndicated: Tests whether the current post in a Loop context, or a post
8
+ * given by ID number, was syndicated by FeedWordPress. Useful for templates
9
+ * to determine whether or not to retrieve syndication-related meta-data in
10
+ * displaying a post.
11
+ *
12
+ * @param int $id The post to check for syndicated status. Defaults to the current post in a Loop context.
13
+ * @return bool TRUE if the post's meta-data indicates it was syndicated; FALSE otherwise
14
+ */
15
+ function is_syndicated ($id = NULL) {
16
+ $p = new FeedWordPressLocalPost($id);
17
+ return $p->is_syndicated();
18
+ } /* function is_syndicated() */
19
+
20
+ function feedwordpress_display_url ($url, $before = 60, $after = 0) {
21
+ $bits = parse_url($url);
22
+
23
+ // Strip out crufty subdomains
24
+ if (isset($bits['host'])) :
25
+ $bits['host'] = preg_replace('/^www[0-9]*\./i', '', $bits['host']);
26
+ endif;
27
+
28
+ // Reassemble bit-by-bit with minimum of crufty elements
29
+ $url = (isset($bits['user'])?$bits['user'].'@':'')
30
+ .(isset($bits['host'])?$bits['host']:'')
31
+ .(isset($bits['path'])?$bits['path']:'')
32
+ .(isset($uri_bits['port'])?':'.$uri_bits['port']:'')
33
+ .(isset($bits['query'])?'?'.$bits['query']:'');
34
+
35
+ if (strlen($url) > ($before+$after)) :
36
+ $url = substr($url, 0, $before).'.'.substr($url, 0 - $after, $after);
37
+ endif;
38
+
39
+ return $url;
40
+ } /* feedwordpress_display_url () */
41
+
42
+ function get_syndication_source_property ($original, $id, $local, $remote = NULL) {
43
+ $p = new FeedWordPressLocalPost($id);
44
+ return $p->meta($local, array("unproxy" => $original, "unproxied setting" => $remote));
45
+ } /* function get_syndication_source_property () */
46
+
47
+ function get_syndication_source_link ($original = NULL, $id = NULL) {
48
+ $p = new FeedWordPressLocalPost($id);
49
+ return $p->syndication_source_link($original);
50
+ } /* function get_syndication_source_link() */
51
+
52
+ function the_syndication_source_link ($original = NULL, $id = NULL) {
53
+ echo get_syndication_source_link($original, $id);
54
+ } /* function the_syndication_source_link() */
55
+
56
+ function get_syndication_source ($original = NULL, $id = NULL) {
57
+ $p = new FeedWordPressLocalPost($id);
58
+ return $p->syndication_source($original);
59
+ } /* function get_syndication_source() */
60
+
61
+ function the_syndication_source ($original = NULL, $id = NULL) {
62
+ echo get_syndication_source($original, $id);
63
+ } /* function the_syndication_source () */
64
+
65
+ function get_syndication_feed ($original = NULL, $id = NULL) {
66
+ $p = new FeedWordPressLocalPost($id);
67
+ return $p->syndication_feed($original);
68
+ } /* function get_syndication_feed() */
69
+
70
+ function the_syndication_feed ($original = NULL, $id = NULL) {
71
+ echo get_syndication_feed($original, $id);
72
+ } /* function the_syndication_feed() */
73
+
74
+ function get_syndication_feed_guid ($original = NULL, $id = NULL) {
75
+ $p = new FeedWordPressLocalPost($id);
76
+ return $p->syndication_feed_guid($original);
77
+ } /* function get_syndication_feed_guid () */
78
+
79
+ function the_syndication_feed_guid ($original = NULL, $id = NULL) {
80
+ echo get_syndication_feed_guid($original, $id);
81
+ } /* function the_syndication_feed_guid () */
82
+
83
+ function get_syndication_feed_id ($id = NULL) {
84
+ $p = new FeedWordPressLocalPost($id);
85
+ return $p->feed_id();
86
+ } /* function get_syndication_feed_id () */
87
+
88
+ function the_syndication_feed_id ($id = NULL) {
89
+ echo get_syndication_feed_id($id);
90
+ } /* function the_syndication_feed_id () */
91
+
92
+ function get_syndication_feed_object ($id = NULL) {
93
+ $p = new FeedWordPressLocalPost($id);
94
+ return $p->feed();
95
+ } /* function get_syndication_feed_object() */
96
+
97
+ function get_feed_meta ($key, $id = NULL) {
98
+ $ret = NULL;
99
+
100
+ $link = get_syndication_feed_object($id);
101
+ if (is_object($link) and isset($link->settings[$key])) :
102
+ $ret = $link->settings[$key];
103
+ endif;
104
+ return $ret;
105
+ } /* function get_feed_meta() */
106
+
107
+ function get_syndication_permalink ($id = NULL) {
108
+ $p = new FeedWordPressLocalPost($id);
109
+ return $p->syndication_permalink();
110
+ } /* function get_syndication_permalink () */
111
+
112
+ function the_syndication_permalink ($id = NULL) {
113
+ echo get_syndication_permalink($id);
114
+ } /* function the_syndication_permalink () */
115
+
116
+ /**
117
+ * get_local_permalink: returns a string containing the internal permalink
118
+ * for a post (whether syndicated or not) on your local WordPress installation.
119
+ * This may be useful if you want permalinks to point to the original source of
120
+ * an article for most purposes, but want to retrieve a URL for the local
121
+ * representation of the post for one or two limited purposes (for example,
122
+ * linking to a comments page on your local aggregator site).
123
+ *
124
+ * @param $id The numerical ID of the post to get the permalink for. If empty,
125
+ * defaults to the current post in a Loop context.
126
+ * @return string The URL of the local permalink for this post.
127
+ *
128
+ * @uses get_permalink()
129
+ * @global $feedwordpress_the_original_permalink
130
+ *
131
+ * @since 2010.0217
132
+ */
133
+ function get_local_permalink ($id = NULL) {
134
+ global $feedwordpress_the_original_permalink;
135
+
136
+ // get permalink, and thus activate filter and force global to be filled
137
+ // with original URL.
138
+ $url = get_permalink($id);
139
+ return $feedwordpress_the_original_permalink;
140
+ } /* get_local_permalink() */
141
+
142
+ /**
143
+ * the_original_permalink: displays the contents of get_original_permalink()
144
+ *
145
+ * @param $id The numerical ID of the post to get the permalink for. If empty,
146
+ * defaults to the current post in a Loop context.
147
+ *
148
+ * @uses get_local_permalinks()
149
+ * @uses apply_filters
150
+ *
151
+ * @since 2010.0217
152
+ */
153
+ function the_local_permalink ($id = NULL) {
154
+ print apply_filters('the_permalink', get_local_permalink($id));
155
+ } /* function the_local_permalink() */
156
+