PluginProbe
Timed Content / 2.55
Timed Content v2.55
2.99 trunk 1.0 1.1 1.2 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.10 2.11 2.12 2.15 2.2 2.3 2.3.1 2.4 2.5 2.5.1 2.50 2.51 2.52 All 67 releases
← All changes | timed-content.php +84 -39 2.522.55 View file →
@@ -5,9 +5,9 @@
5 5 Domain Path: /lang
6 6 Plugin URI: http://wordpress.org/plugins/timed-content/
7 7 Description: Plugin to show or hide portions of a Page or Post based on specific date/time characteristics. These actions can either be processed either server-side or client-side, depending on the desired effect.
8 8 Author: K. Tough, Arno Welzel
9 -Version: 2.52
9 +Version: 2.55
10 10 Author URI: http://wordpress.org/plugins/timed-content/
11 11 */
12 12 defined('ABSPATH') or die();
13 13
@@ -12,9 +12,9 @@
12 12 defined('ABSPATH') or die();
13 13
14 14 include 'lib/customFieldsInterface.php';
15 15
16 -define('TIMED_CONTENT_VERSION', '2.52');
16 +define('TIMED_CONTENT_VERSION', '2.55');
17 17 define('TIMED_CONTENT_SLUG', 'timed-content');
18 18 define('TIMED_CONTENT_PLUGIN_URL', plugins_url() . '/' . TIMED_CONTENT_SLUG);
19 19 define('TIMED_CONTENT_SHORTCODE_CLIENT', 'timed-content-client');
20 20 define('TIMED_CONTENT_SHORTCODE_SERVER', 'timed-content-server');
@@ -1378,52 +1378,77 @@
1378 1378 function serverShowHTML( $atts, $content = null )
1379 1379 {
1380 1380 global $post;
1381 1381 extract( shortcode_atts( array(
1382 - 'show' => TIMED_CONTENT_TIME_ZERO,
1383 - 'hide' => TIMED_CONTENT_TIME_END,
1382 + 'show' => 0,
1383 + 'hide' => 0,
1384 1384 'debug' => 'false'
1385 1385 ), $atts ) );
1386 1386
1387 + // Get time and timezone object for "show" time
1387 1388 $pos = strrpos( $show, ' ' );
1388 1389 if ( $pos !== false ) {
1389 1390 $show_time = substr( $show, 0, $pos );
1390 - $show_tz = substr( $show, $pos + 1 );
1391 + $show_tzname = substr( $show, $pos + 1 );
1391 1392 } else {
1392 1393 $show_time = $show;
1393 - $show_tz = date_default_timezone_get();
1394 + $show_tzname = date_default_timezone_get();
1394 1395 }
1396 + try {
1397 + $show_tz = new DateTimeZone($show_tzname);
1398 + } catch(Exception $e) {
1399 + $show_tz = new DateTimeZone('+0000');
1400 + }
1395 1401
1402 + // Create time and timezone object for "hide" time
1403 + $pos = strrpos( $hide, ' ' );
1404 + if ( $pos !== false ) {
1405 + $hide_time = substr( $hide, 0, $pos );
1406 + $hide_tzname = substr( $hide, $pos + 1 );
1407 + } else {
1408 + $hide_time = $hide;
1409 + $hide_tzname = date_default_timezone_get();
1410 + }
1411 + try {
1412 + $hide_tz = new DateTimeZone($hide_tzname);
1413 + } catch(Exception $e) {
1414 + $hide_tz = new DateTimeZone('+0000');
1415 + }
1416 +
1396 1417 // Try to parse date as ISO first
1397 - $show_dt = DateTime::createFromFormat( 'Y-m-d G:i', $show_time, new DateTimeZone( $show_tz ) );
1418 + $show_dt = DateTime::createFromFormat( 'Y-m-d G:i', $show_time, $show_tz);
1419 + // Fallback to American format
1398 1420 if ($show_dt === false) {
1399 - $show_dt = DateTime::createFromFormat('m/d/Y G:i', $show_time, new DateTimeZone($show_tz));
1421 + $show_dt = DateTime::createFromFormat('m/d/Y G:i', $show_time, $show_tz);
1400 1422 }
1401 1423
1402 1424 if ( $show_dt !== false ) {
1403 1425 $show_t = $show_dt->getTimeStamp();
1404 1426 } else {
1405 - $show_t = 0;
1427 + // If nothing else worked so far, try strtotime()
1428 + // as it was before version 2.50
1429 + $show_t = strtotime($show);
1430 + if($show_t === false) $show_t = 0;
1431 + $show_dt = new DateTime();
1432 + $show_dt->setTimeStamp($show_t);
1433 + $show_dt->setTimezone($show_tz);
1406 1434 }
1407 1435
1408 - $pos = strrpos( $hide, ' ' );
1409 - if ( $pos !== false ) {
1410 - $hide_time = substr( $hide, 0, $pos );
1411 - $hide_tz = substr( $hide, $pos + 1 );
1412 - } else {
1413 - $hide_time = $hide;
1414 - $hide_tz = date_default_timezone_get();
1415 - }
1416 -
1417 1436 // Try to parse date as ISO first
1418 - $hide_dt = DateTime::createFromFormat( 'Y-m-d G:i', $hide_time, new DateTimeZone( $show_tz ) );
1437 + $hide_dt = DateTime::createFromFormat( 'Y-m-d G:i', $hide_time, $hide_tz);
1419 1438 if ($hide_dt === false) {
1420 - $hide_dt = DateTime::createFromFormat( 'm/d/Y G:i', $hide_time, new DateTimeZone( $hide_tz ) );
1439 + $hide_dt = DateTime::createFromFormat( 'm/d/Y G:i', $hide_time, $hide_tz);
1421 1440 }
1422 1441 if ( $hide_dt !== false ) {
1423 1442 $hide_t = $hide_dt->getTimeStamp();
1424 1443 } else {
1425 - $hide_t = 0;
1444 + // If nothing else worked so far, try strtotime()
1445 + // as it was before version 2.50
1446 + $hide_t = strtotime($hide);
1447 + if($hide_t === false) $hide_t = 0;
1448 + $hide_dt = new DateTime();
1449 + $hide_dt->setTimeStamp($hide_t);
1450 + $hide_dt->setTimezone($hide_tz);
1426 1451 }
1427 1452
1428 1453 $right_now_t = current_time( 'timestamp', 1 );
1429 1454 $debug_message = "";
@@ -1438,8 +1463,13 @@
1438 1463
1439 1464 $the_filter = "timed_content_filter";
1440 1465 $the_filter = apply_filters( "timed_content_filter_override", $the_filter );
1441 1466
1467 + $show_content = false;
1468 + if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t || $hide_t == 0 ) ) {
1469 + $show_content = true;
1470 + }
1471 +
1442 1472 if ( ( $debug == "true" ) && ( current_user_can( "edit_post", $post->post_id ) ) ) {
1443 1473 add_filter( 'date_i18n', array( &$this, "fix_date_i18n" ), 10, 4 );
1444 1474 $temp_tz = date_default_timezone_get();
1445 1475 date_default_timezone_set( get_option( 'timezone_string' ) );
@@ -1462,38 +1492,44 @@
1462 1492 }
1463 1493
1464 1494 $debug_message = "<div class=\"tcr-warning\">\n";
1465 1495 $debug_message .= "<p class=\"heading\">" . _x( "Notice", "Noun", 'timed-content' ) . "</p>\n";
1466 - $debug_message .= "<p>" . sprintf( __( 'Debugging has been turned on for a %1$s shortcode on this Post/Page. Only website users who are currently logged in and can edit this Post/Page will see this. To turn off this message, remove the %2$s attribute from the shortcode.',
1496 + $debug_message .= "<p>" . sprintf( __( 'Debugging has been turned on for a %1$s shortcode on this post/page. Only website users who are currently logged in and can edit this post/page will see this. To turn off this message, remove the %2$s attribute from the shortcode.',
1467 1497 'timed-content' ), "<code>[timed-content-server]</code>", "<code>debug</code>" ) . "</p>\n";
1468 1498
1469 - if ( $show == TIMED_CONTENT_TIME_ZERO ) {
1470 - $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ),
1499 + if ( $show_t === 0 ) {
1500 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set or invalid.', 'timed-content' ),
1471 1501 "<code>show</code>" ) . "</p>\n";
1472 1502 } else {
1473 1503 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ),
1474 1504 "<code>show</code>" ) . ": " . $show . ",<br />\n "
1475 1505 . __( 'The Timed Content plugin thinks the intended date/time is',
1476 - 'timed-content' ) . ": " . date_i18n( TIMED_CONTENT_DATE_FORMAT_OUTPUT, $show_t )
1506 + 'timed-content' ) . ": " . $show_dt->format( TIMED_CONTENT_DATE_FORMAT_OUTPUT)
1477 1507 . " (" . $show_diff_str . ")</p>\n";
1478 1508 }
1479 1509
1480 - if ( $hide == TIMED_CONTENT_TIME_END ) {
1481 - $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set.', 'timed-content' ),
1510 + if ( $hide === 0 ) {
1511 + $debug_message .= "<p>" . sprintf( __( 'The %s attribute is not set or invalid.', 'timed-content' ),
1482 1512 "<code>hide</code>" ) . "</p>\n";
1483 1513 } else {
1484 1514 $debug_message .= "<p>" . sprintf( __( 'The %s attribute is currently set to', 'timed-content' ),
1485 1515 "<code>hide</code>" ) . ": " . $hide . ",<br />\n"
1486 1516 . __( 'The Timed Content plugin thinks the intended date/time is',
1487 - 'timed-content' ) . ": " . date_i18n( TIMED_CONTENT_DATE_FORMAT_OUTPUT, $hide_t )
1517 + 'timed-content' ) . ": " . $hide_dt->format(TIMED_CONTENT_DATE_FORMAT_OUTPUT)
1488 1518 . " (" . $hide_diff_str . ").</p>\n";
1489 1519 }
1490 1520
1491 1521 $debug_message .= "<p>" . __( 'Current date:',
1492 - 'timed-content' ) . "&nbsp;" . $right_now . "<br />\n";
1493 - $debug_message .= __( 'Content filter:', 'timed-content' ) . "&nbsp;" . $the_filter . "</p>\n";
1494 - $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content' ) . "&nbsp;" . $content . "</p>\n";
1522 + 'timed-content' ) . "&nbsp;" . $right_now . "</p>\n";
1523 + $debug_message .= "<p>" . __( 'Content filter:', 'timed-content' ) . "&nbsp;" . $the_filter . "</p>\n";
1524 + $debug_message .= "<p>" . _x( 'Content:', "Noun", 'timed-content' ) . "</p><p><code>" . htmlspecialchars($content) . "</code></p>\n";
1495 1525
1526 + if ( $show_content === true ) {
1527 + $debug_message .= "<p>" . __( 'The plugin will show the content.', 'timed-content' ) . "</p>";
1528 + } else {
1529 + $debug_message .= "<p>" . __( 'The plugin will hide the content.', 'timed-content' ). "</p>";
1530 + }
1531 +
1496 1532 $debug_message .= "</div>\n";
1497 1533
1498 1534 date_default_timezone_set( $temp_tz );
1499 1535 remove_filter( 'date_i18n', array( &$this, "fix_date_i18n" ), 10, 4 );
@@ -1498,10 +1534,9 @@
1498 1534 date_default_timezone_set( $temp_tz );
1499 1535 remove_filter( 'date_i18n', array( &$this, "fix_date_i18n" ), 10, 4 );
1500 1536 }
1501 1537
1502 -
1503 - if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t || $hide_t == 0 ) ) {
1538 + if ( $show_content === true ) {
1504 1539 do_action( "timed_content_server_show", $post->ID, $show, $hide, $content );
1505 1540
1506 1541 return $debug_message . str_replace( ']]>', ']]&gt;', apply_filters( $the_filter, $content ) ) . "\n";
1507 1542 } else {
@@ -1891,9 +1926,19 @@
1891 1926 function setupCustomFields()
1892 1927 {
1893 1928 global $post;
1894 1929
1895 - $now_t = current_time( "timestamp" );
1930 + $now_ts = current_time( 'timestamp' );
1931 + $now_plus1h_dt = new DateTime();
1932 + $now_plus2h_dt = new DateTime();
1933 + $now_plus1y_dt = new DateTime();
1934 + $now_plus1h_dt->setTimeStamp($now_ts);
1935 + $now_plus2h_dt->setTimeStamp($now_ts);
1936 + $now_plus1y_dt->setTimeStamp($now_ts);
1937 + $now_plus1h_dt->add(new DateInterval('PT1H'));
1938 + $now_plus2h_dt->add(new DateInterval('PT2H'));
1939 + $now_plus1y_dt->add(new DateInterval('P1Y'));
1940 +
1896 1941 $post_id = ( isset( $_GET['post'] ) && ( TIMED_CONTENT_RULE_TYPE === get_post_type( $_GET['post'] ) ) ? intval( $_GET['post'] ) : intval( 0 ) );
1897 1942 $timed_content_rules_exceptions_dates = ( "" === get_post_meta( $post_id, TIMED_CONTENT_RULE_POSTMETA_PREFIX . "exceptions_dates", true ) ? array() : get_post_meta( $post_id, TIMED_CONTENT_RULE_POSTMETA_PREFIX . "exceptions_dates", true ) );
1898 1943 if ( empty( $timed_content_rules_exceptions_dates ) )
1899 1944 $timed_content_rules_exceptions_dates_array = array( "0" => __( "- No exceptions set -", 'timed-content' ) );
@@ -1926,10 +1971,10 @@
1926 1971 "display" => "block",
1927 1972 "title" => __( "Starting date/time", 'timed-content' ),
1928 1973 "description" => __( "Sets the date and time for the beginning of the first active period for this rule.", 'timed-content' ),
1929 1974 "type" => "datetime",
1930 - "default" => array("date" => date_i18n( get_option('date_format'), strtotime( "+1 hour", $now_t ) ),
1931 - "time" => date_i18n( get_option('time_format'), strtotime( "+1 hour", $now_t ) ) ),
1975 + "default" => array("date" => strftime('%Y-%m-%d', $now_plus1h_dt->getTimeStamp()),
1976 + "time" => strftime('%H:%M', $now_plus1h_dt->getTimeStamp())),
1932 1977 "scope" => array(TIMED_CONTENT_RULE_TYPE ),
1933 1978 "capability" => "edit_posts"
1934 1979 ),
1935 1980 array(
@@ -1937,10 +1982,10 @@
1937 1982 "display" => "block",
1938 1983 "title" => __( "Ending date/time", 'timed-content' ),
1939 1984 "description" => __( "Sets the date and time for the end of the first active period for this rule.", 'timed-content' ),
1940 1985 "type" => "datetime",
1941 - "default" => array("date" => date_i18n( get_option('date_format'), strtotime( "+2 hour", $now_t ) ),
1942 - "time" => date_i18n( get_option('time_format'), strtotime( "+2 hour", $now_t ) ) ),
1986 + "default" => array("date" => strftime('%Y-%m-%d', $now_plus2h_dt->getTimeStamp()),
1987 + "time" => strftime('%H:%M', $now_plus2h_dt->getTimeStamp())),
1943 1988 "scope" => array( TIMED_CONTENT_RULE_TYPE ),
1944 1989 "capability" => "edit_posts"
1945 1990 ),
1946 1991 array(
@@ -2085,9 +2130,9 @@
2085 2130 "display" => "none",
2086 2131 "title" => __( "End Date", 'timed-content' ),
2087 2132 "description" => __( "Using the settings above, repeat this action until this date.", 'timed-content' ),
2088 2133 "type" => "date",
2089 - "default" => date_i18n( get_option('date_format'), strtotime( "+1 year", $now_t ) ),
2134 + "default" => strftime('%Y-%m-%d', $now_plus1y_dt->getTimeStamp()),
2090 2135 "scope" => array( TIMED_CONTENT_RULE_TYPE ),
2091 2136 "capability" => "edit_posts"
2092 2137 ),
2093 2138 array(