| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: FeedWordPress |
| 4 | 4 | Plugin URI: http://feedwordpress.radgeek.com/ |
| 5 | 5 | Description: simple and flexible Atom/RSS syndication for WordPress |
| 6 | -Version: 2010.0528 | |
| 6 | +Version: 2010.0602 | |
| 7 | 7 | Author: Charles Johnson |
| 8 | 8 | Author URI: http://radgeek.com/ |
| 9 | 9 | License: GPL |
| 10 | 10 | */ |
| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * @package FeedWordPress |
| 14 | - * @version 2010.0528 | |
| 14 | + * @version 2010.0602 | |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | # This uses code derived from: |
| 18 | 18 | # - wp-rss-aggregate.php by Kellan Elliot-McCrea <kellan@protest.net> |
| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | # or use a cron job. |
| 33 | 33 | |
| 34 | 34 | # -- Don't change these unless you know what you're doing... |
| 35 | 35 | |
| 36 | -define ('FEEDWORDPRESS_VERSION', '2010.0528'); | |
| 36 | +define ('FEEDWORDPRESS_VERSION', '2010.0602'); | |
| 37 | 37 | define ('FEEDWORDPRESS_AUTHOR_CONTACT', 'http://radgeek.com/contact'); |
| 38 | 38 | |
| 39 | 39 | // Defaults |
| 40 | 40 | define ('DEFAULT_SYNDICATION_CATEGORY', 'Contributors'); |
| @@ -57,8 +57,9 @@ | ||
| 57 | 57 | |
| 58 | 58 | define ('FEEDWORDPRESS_FRESHNESS_INTERVAL', 10*60); // Every ten minutes |
| 59 | 59 | |
| 60 | 60 | define ('FWP_SCHEMA_HAS_USERMETA', 2966); |
| 61 | +define ('FWP_SCHEMA_USES_ARGS_TAXONOMY', 12694); // Revision # for using $args['taxonomy'] to get link categories | |
| 61 | 62 | define ('FWP_SCHEMA_20', 3308); // Database schema # for WP 2.0 |
| 62 | 63 | define ('FWP_SCHEMA_21', 4772); // Database schema # for WP 2.1 |
| 63 | 64 | define ('FWP_SCHEMA_23', 5495); // Database schema # for WP 2.3 |
| 64 | 65 | define ('FWP_SCHEMA_25', 7558); // Database schema # for WP 2.5 |
| @@ -65,8 +66,9 @@ | ||
| 65 | 66 | define ('FWP_SCHEMA_26', 8201); // Database schema # for WP 2.6 |
| 66 | 67 | define ('FWP_SCHEMA_27', 9872); // Database schema # for WP 2.7 |
| 67 | 68 | define ('FWP_SCHEMA_28', 11548); // Database schema # for WP 2.8 |
| 68 | 69 | define ('FWP_SCHEMA_29', 12329); // Database schema # for WP 2.9 |
| 70 | +define ('FWP_SCHEMA_30', 12694); // Database schema # for WP 3.0 | |
| 69 | 71 | |
| 70 | 72 | if (FEEDWORDPRESS_DEBUG) : |
| 71 | 73 | // Help us to pick out errors, if any. |
| 72 | 74 | ini_set('error_reporting', E_ALL & ~E_NOTICE); |
| @@ -106,10 +108,12 @@ | ||
| 106 | 108 | require_once (ABSPATH . 'wp-admin/admin-db.php'); // for wp_insert_category |
| 107 | 109 | endif; |
| 108 | 110 | endif; |
| 109 | 111 | |
| 112 | +require_once (ABSPATH . WPINC . '/class-feed.php'); | |
| 110 | 113 | require_once(dirname(__FILE__) . '/compatability.php'); // LEGACY API: Replicate or mock up functions for legacy support purposes |
| 111 | 114 | require_once(dirname(__FILE__) . '/feedwordpresshtml.class.php'); |
| 115 | +require_once(dirname(__FILE__) . '/feedwordpress-content-type-sniffer.class.php'); | |
| 112 | 116 | |
| 113 | 117 | // Magic quotes are just about the stupidest thing ever. |
| 114 | 118 | if (is_array($_POST)) : |
| 115 | 119 | $fwp_post = stripslashes_deep($_POST); |
| @@ -128,31 +132,30 @@ | ||
| 128 | 132 | $fwp_path = 'feedwordpress'; |
| 129 | 133 | endif; |
| 130 | 134 | |
| 131 | 135 | function feedwordpress_admin_scripts () { |
| 136 | + global $fwp_path; | |
| 137 | + | |
| 132 | 138 | wp_enqueue_script('post'); // for magic tag and category boxes |
| 139 | + if (!FeedWordPressCompatibility::test_version(FWP_SCHEMA_29)) : // < 2.9 | |
| 140 | + wp_enqueue_script('thickbox'); // for fold-up boxes | |
| 141 | + endif; | |
| 133 | 142 | wp_enqueue_script('admin-forms'); // for checkbox selection |
| 143 | + | |
| 144 | + wp_register_script('feedwordpress-elements', WP_PLUGIN_URL.'/'.$fwp_path.'/feedwordpress-elements.js'); | |
| 145 | + wp_enqueue_script('feedwordpress-elements'); | |
| 134 | 146 | } |
| 135 | 147 | |
| 136 | 148 | // If this is a FeedWordPress admin page, queue up scripts for AJAX functions that FWP uses |
| 137 | 149 | // If it is a display page or a non-FeedWordPress admin page, don't. |
| 138 | 150 | if (is_admin() and isset($_REQUEST['page']) and preg_match("|^{$fwp_path}/|", $_REQUEST['page'])) : |
| 139 | - if (function_exists('wp_enqueue_script')) : | |
| 140 | - if (FeedWordPressCompatibility::test_version(FWP_SCHEMA_29)) : | |
| 141 | - add_action('admin_print_scripts', 'feedwordpress_admin_scripts'); | |
| 142 | - elseif (FeedWordPressCompatibility::test_version(FWP_SCHEMA_25)) : | |
| 143 | - wp_enqueue_script('post'); // for magic tag and category boxes | |
| 144 | - wp_enqueue_script('thickbox'); // for fold-up boxes | |
| 145 | - wp_enqueue_script('admin-forms'); // for checkbox selection | |
| 146 | - else : | |
| 147 | - wp_enqueue_script( 'ajaxcat' ); // Provides the handy-dandy new category text box | |
| 148 | - endif; | |
| 149 | - endif; | |
| 150 | - if (function_exists('wp_enqueue_style')) : | |
| 151 | - if (fwp_test_wp_version(FWP_SCHEMA_25)) : | |
| 152 | - wp_enqueue_style('dashboard'); | |
| 153 | - endif; | |
| 154 | - endif; | |
| 151 | + add_action('admin_print_scripts', 'feedwordpress_admin_scripts'); | |
| 152 | + | |
| 153 | + wp_register_style('feedwordpress-elements', WP_PLUGIN_URL.'/'.$fwp_path.'/feedwordpress-elements.css'); | |
| 154 | + | |
| 155 | + wp_enqueue_style('dashboard'); | |
| 156 | + wp_enqueue_style('feedwordpress-elements'); | |
| 157 | + | |
| 155 | 158 | if (function_exists('wp_admin_css')) : |
| 156 | 159 | if (fwp_test_wp_version(FWP_SCHEMA_25)) : |
| 157 | 160 | wp_admin_css('css/dashboard'); |
| 158 | 161 | endif; |
| @@ -202,8 +205,10 @@ | ||
| 202 | 205 | |
| 203 | 206 | add_action('admin_menu', 'feedwordpress_add_post_edit_controls'); |
| 204 | 207 | add_action('save_post', 'feedwordpress_save_post_edit_controls'); |
| 205 | 208 | |
| 209 | + add_action('admin_footer', array('FeedWordPress', 'admin_footer')); | |
| 210 | + | |
| 206 | 211 | # Inbound XML-RPC update methods |
| 207 | 212 | add_filter('xmlrpc_methods', 'feedwordpress_xmlrpc_hook'); |
| 208 | 213 | |
| 209 | 214 | # Outbound XML-RPC ping reform |
| @@ -778,9 +783,10 @@ | ||
| 778 | 783 | add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Feeds & Updates', 'Feeds & Updates', $fwp_capability['manage_options'], $fwp_path.'/feeds-page.php'); |
| 779 | 784 | add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Posts & Links', 'Posts & Links', $fwp_capability['manage_options'], $fwp_path.'/posts-page.php'); |
| 780 | 785 | add_submenu_page($fwp_path.'/syndication.php', 'Syndicated Authors', 'Authors', $fwp_capability['manage_options'], $fwp_path.'/authors-page.php'); |
| 781 | 786 | add_submenu_page($fwp_path.'/syndication.php', 'Categories'.FEEDWORDPRESS_AND_TAGS, 'Categories'.FEEDWORDPRESS_AND_TAGS, $fwp_capability['manage_options'], $fwp_path.'/categories-page.php'); |
| 782 | - add_submenu_page($fwp_path.'/syndication.php', 'FeedWordPress Back End', 'Back End', $fwp_capability['manage_options'], $fwp_path.'/backend-page.php'); | |
| 787 | + add_submenu_page($fwp_path.'/syndication.php', 'FeedWordPress Performance', 'Performance', $fwp_capability['manage_options'], $fwp_path.'/performance-page.php'); | |
| 788 | + add_submenu_page($fwp_path.'/syndication.php', 'FeedWordPress Diagnostics', 'Diagnostics', $fwp_capability['manage_options'], $fwp_path.'/diagnostics-page.php'); | |
| 783 | 789 | } /* function fwp_add_pages () */ |
| 784 | 790 | |
| 785 | 791 | function fwp_check_debug () { |
| 786 | 792 | // This is a horrible fucking kludge that I have to do because the |
| @@ -909,14 +915,16 @@ | ||
| 909 | 915 | endif; |
| 910 | 916 | |
| 911 | 917 | // OK, we're golden. Now let's save some data. |
| 912 | 918 | if (isset($_POST['freeze_updates'])) : |
| 913 | - update_post_meta($post_id, '_syndication_freeze_updates', $_POST['freeze_updates']); | |
| 919 | + update_post_meta($post_id, '_syndication_freeze_updates', $_POST['freeze_updates']); | |
| 920 | + $ret = $_POST['freeze_updates']; | |
| 914 | 921 | else : |
| 915 | 922 | delete_post_meta($post_id, '_syndication_freeze_updates'); |
| 923 | + $ret = NULL; | |
| 916 | 924 | endif; |
| 917 | 925 | |
| 918 | - return $_POST['freeze_updates']; | |
| 926 | + return $ret; | |
| 919 | 927 | } // function feedwordpress_save_edit_controls |
| 920 | 928 | |
| 921 | 929 | ################################################################################ |
| 922 | 930 | ## class FeedWordPress ######################################################### |
| @@ -1371,13 +1379,13 @@ | ||
| 1371 | 1379 | "); |
| 1372 | 1380 | } |
| 1373 | 1381 | |
| 1374 | 1382 | /*static*/ function fetch ($url) { |
| 1375 | - require_once (ABSPATH . WPINC . '/class-feed.php'); | |
| 1376 | 1383 | $feed = new SimplePie(); |
| 1377 | 1384 | $feed->set_feed_url($url); |
| 1378 | 1385 | $feed->set_cache_class('WP_Feed_Cache'); |
| 1379 | 1386 | $feed->set_file_class('WP_SimplePie_File'); |
| 1387 | + $feed->set_content_type_sniffer_class('FeedWordPress_Content_Type_Sniffer'); | |
| 1380 | 1388 | $feed->set_cache_duration(FeedWordPress::cache_duration()); |
| 1381 | 1389 | $feed->init(); |
| 1382 | 1390 | $feed->handle_content_type(); |
| 1383 | 1391 | |
| @@ -1398,12 +1406,13 @@ | ||
| 1398 | 1406 | // timestamp in `_transient_feed_mod_{md5 of url}`. Timeouts for |
| 1399 | 1407 | // these records are stored in `_transient_timeout_feed_{md5}`. |
| 1400 | 1408 | // Since the md5 is always 32 characters in length, the |
| 1401 | 1409 | // option_name is always over 32 characters. |
| 1402 | - $wpdb->query(" | |
| 1410 | + $ret = $wpdb->query(" | |
| 1403 | 1411 | DELETE FROM {$wpdb->options} |
| 1404 | 1412 | WHERE option_name LIKE '_transient%_feed_%' AND LENGTH(option_name) > 32 |
| 1405 | 1413 | "); |
| 1414 | + return (int) ($ret / 4); // Each transient has 4 rows: the data, the modified timestamp; and the timeouts for each | |
| 1406 | 1415 | } /* FeedWordPress::clear_cache () */ |
| 1407 | 1416 | |
| 1408 | 1417 | function cache_duration () { |
| 1409 | 1418 | $duration = NULL; |
| @@ -1457,9 +1466,54 @@ | ||
| 1457 | 1466 | if (FEEDWORDPRESS_DEBUG) : // halt only when we are doing debugging |
| 1458 | 1467 | FeedWordPress::critical_bug($varname, $var, $line); |
| 1459 | 1468 | endif; |
| 1460 | 1469 | } |
| 1470 | + | |
| 1471 | + function val ($v, $no_newlines = false) { | |
| 1472 | + ob_start(); | |
| 1473 | + var_dump($v); | |
| 1474 | + $out = ob_get_contents(); ob_end_clean(); | |
| 1475 | + | |
| 1476 | + if ($no_newlines) : | |
| 1477 | + $out = preg_replace('/\s+/', " ", $out); | |
| 1478 | + endif; | |
| 1479 | + return $out; | |
| 1480 | + } /* FeedWordPress:val () */ | |
| 1481 | + | |
| 1482 | + function diagnostic ($level, $out) { | |
| 1483 | + global $feedwordpress_admin_footer; | |
| 1484 | + | |
| 1485 | + $output = get_option('feedwordpress_diagnostics_output', array()); | |
| 1486 | + $show = get_option('feedwordpress_diagnostics_show', array()); | |
| 1487 | + | |
| 1488 | + $diagnostic_nesting = count(explode(":", $level)); | |
| 1489 | + | |
| 1490 | + if (in_array($level, $show)) : | |
| 1491 | + foreach ($output as $method) : | |
| 1492 | + switch ($method) : | |
| 1493 | + case 'echo' : | |
| 1494 | + echo "<div><pre><strong>Diag".str_repeat('====', $diagnostic_nesting-1).'|</strong> '.esc_html($out)."</pre></div>"; | |
| 1495 | + break; | |
| 1496 | + case 'admin_footer' : | |
| 1497 | + $feedwordpress_admin_footer[] = $out; | |
| 1498 | + break; | |
| 1499 | + case 'error_log' : | |
| 1500 | + error_log('[feedwordpress]' . $out); | |
| 1501 | + break; | |
| 1502 | + endswitch; | |
| 1503 | + endforeach; | |
| 1504 | + endif; | |
| 1505 | + } /* FeedWordPress::diagnostic () */ | |
| 1506 | + | |
| 1507 | + function admin_footer () { | |
| 1508 | + global $feedwordpress_admin_footer; | |
| 1509 | + foreach ($feedwordpress_admin_footer as $line) : | |
| 1510 | + echo '<div><pre>'.esc_html($line).'</pre></div>'; | |
| 1511 | + endforeach; | |
| 1512 | + } /* FeedWordPress::admin_footer () */ | |
| 1461 | 1513 | } // class FeedWordPress |
| 1514 | + | |
| 1515 | +$feedwordpress_admin_footer = array(); | |
| 1462 | 1516 | |
| 1463 | 1517 | require_once(dirname(__FILE__) . '/syndicatedpost.class.php'); |
| 1464 | 1518 | require_once(dirname(__FILE__) . '/syndicatedlink.class.php'); |
| 1465 | 1519 | |