| @@ -1,246 +1,40 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: Timed Content |
| 4 | 4 | Text Domain: timed-content |
| 5 | -Plugin URI: http://www.notabenemarketing.com/resources/wordpress-plugins/timed-content-plugin | |
| 6 | -Description: Plugin to show or hide portions of a Page or Post at a specified time after loading. These actions can either be processed either server-side or client-side, depending on the desired effect. | |
| 7 | -Author: K. Tough | |
| 8 | -Version: 1.1 | |
| 9 | -Author URI: http://www.notabenemarketing.com/resources/wordpress-plugins/timed-content-plugin | |
| 5 | +Domain Path: /lang | |
| 6 | +Plugin URI: http://wordpress.org/plugins/timed-content/ | |
| 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 | +Author: K. Tough, Arno Welzel, Enrico Bacis | |
| 9 | +Version: 2.74 | |
| 10 | +Author URI: http://wordpress.org/plugins/timed-content/ | |
| 10 | 11 | */ |
| 12 | +defined( 'ABSPATH' ) or die(); | |
| 11 | 13 | |
| 12 | -define( "TIMED_CONTENT_PLUGIN_URL", WP_PLUGIN_URL . '/timed-content' ); | |
| 13 | -define( "TIMED_CONTENT_CLIENT_TAG", "timed-content-client" ); | |
| 14 | -define( "TIMED_CONTENT_SERVER_TAG", "timed-content-server" ); | |
| 15 | -define( "TIMED_CONTENT_ZERO_TIME", "1970-Jan-01 00:00:00 +000" ); // Start of Unix Epoch | |
| 16 | -define( "TIMED_CONTENT_END_TIME", "2038-Jan-19 03:14:07 +000" ); // End of Unix Epoch | |
| 17 | -/* translators: date/time format for debugging messages. */ | |
| 18 | -define( "TIMED_CONTENT_DT_FORMAT", __( "l, F jS, Y, g:i:s A T (e)" , 'timed-content') ); | |
| 14 | +require 'lib/class-customfieldsinterface.php'; | |
| 15 | +require 'lib/class-timedcontentplugin.php'; | |
| 19 | 16 | |
| 17 | +define( 'TIMED_CONTENT_VERSION', '2.74' ); | |
| 18 | +define( 'TIMED_CONTENT_SLUG', 'timed-content' ); | |
| 19 | +define( 'TIMED_CONTENT_PLUGIN_URL', plugins_url() . '/' . TIMED_CONTENT_SLUG ); | |
| 20 | +define( 'TIMED_CONTENT_SHORTCODE_CLIENT', 'timed-content-client' ); | |
| 21 | +define( 'TIMED_CONTENT_SHORTCODE_SERVER', 'timed-content-server' ); | |
| 22 | +define( 'TIMED_CONTENT_SHORTCODE_RULE', 'timed-content-rule' ); | |
| 23 | +define( 'TIMED_CONTENT_TIME_ZERO', '1970-01-01 00:00:00 +000' ); // Start of Unix Epoch (32 bit) | |
| 24 | +define( 'TIMED_CONTENT_TIME_END', '2038-01-19 03:14:06 +000' ); // End of Unix Epoch (32 bit) | |
| 25 | +define( 'TIMED_CONTENT_RULE_TYPE', 'timed_content_rule' ); | |
| 26 | +define( 'TIMED_CONTENT_RULE_POSTMETA_PREFIX', TIMED_CONTENT_RULE_TYPE . '_' ); | |
| 27 | +define( 'TIMED_CONTENT_CSS', TIMED_CONTENT_PLUGIN_URL . '/css/timed-content.css' ); | |
| 28 | +define( 'TIMED_CONTENT_CSS_DASHICONS', TIMED_CONTENT_PLUGIN_URL . '/css/dashicons/style.css' ); | |
| 29 | +define( 'TIMED_CONTENT_JQUERY_UI_CSS', TIMED_CONTENT_PLUGIN_URL . '/css/jqueryui/1.10.3/themes/smoothness/jquery-ui.css' ); | |
| 30 | +define( 'TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS', TIMED_CONTENT_PLUGIN_URL . '/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.min.js' ); | |
| 31 | +define( 'TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS', TIMED_CONTENT_PLUGIN_URL . '/js/jquery-ui-timepicker-0.3.3/jquery.ui.timepicker.css' ); | |
| 32 | +define( 'TIMED_CONTENT_DATE_FORMAT_OUTPUT', 'Y-m-d H:i O' ); | |
| 33 | +define( 'TIMED_CONTENT_FREQ_HOURLY', 0 ); | |
| 34 | +define( 'TIMED_CONTENT_FREQ_DAILY', 1 ); | |
| 35 | +define( 'TIMED_CONTENT_FREQ_WEEKLY', 2 ); | |
| 36 | +define( 'TIMED_CONTENT_FREQ_MONTHLY', 3 ); | |
| 37 | +define( 'TIMED_CONTENT_FREQ_YEARLY', 4 ); | |
| 20 | 38 | |
| 21 | -if ( !class_exists( "timedContentPlugin" ) ) { | |
| 22 | - class timedContentPlugin { | |
| 23 | - | |
| 24 | - function timedContentPlugin() { | |
| 25 | - //constructor | |
| 26 | - | |
| 27 | - } | |
| 28 | - | |
| 29 | - function _date_diff( $date_1 = 0, $date_2 = 0 ) { | |
| 30 | - // | |
| 31 | - // Compares two timestamps and returns array with period differences (year, month, day, hour, minute, second) | |
| 32 | - // http://ca2.php.net/manual/en/function.mktime.php#93914 | |
| 33 | - // | |
| 34 | - | |
| 35 | - //check higher timestamp and switch if neccessary | |
| 36 | - if ($date_1 < $date_2){ | |
| 37 | - $temp = $date_2; | |
| 38 | - $date_2 = $date_1; | |
| 39 | - $date_1 = $temp; | |
| 40 | - $diff['before'] = true; | |
| 41 | - } | |
| 42 | - else { | |
| 43 | - $temp = $date_1; //temp can be used for day count if required | |
| 44 | - $diff['before'] = false; | |
| 45 | - } | |
| 46 | - $date_1 = date_parse( date( "Y-m-d H:i:s", $date_1 ) ); | |
| 47 | - $date_2 = date_parse( date( "Y-m-d H:i:s", $date_2 ) ); | |
| 48 | - //seconds | |
| 49 | - if ( $date_1['second'] >= $date_2['second'] ) { | |
| 50 | - $diff['second'] = $date_1['second'] - $date_2['second']; | |
| 51 | - } | |
| 52 | - else { | |
| 53 | - $date_1['minute']--; | |
| 54 | - $diff['second'] = 60 - $date_2['second'] + $date_1['second']; | |
| 55 | - } | |
| 56 | - //minutes | |
| 57 | - if ( $date_1['minute'] >= $date_2['minute'] ) { | |
| 58 | - $diff['minute'] = $date_1['minute'] - $date_2['minute']; | |
| 59 | - } | |
| 60 | - else { | |
| 61 | - $date_1['hour']--; | |
| 62 | - $diff['minute'] = 60 - $date_2['minute'] + $date_1['minute']; | |
| 63 | - } | |
| 64 | - //hours | |
| 65 | - if ( $date_1['hour'] >= $date_2['hour'] ) { | |
| 66 | - $diff['hour'] = $date_1['hour'] - $date_2['hour']; | |
| 67 | - } | |
| 68 | - else { | |
| 69 | - $date_1['day']--; | |
| 70 | - $diff['hour'] = 24 - $date_2['hour'] + $date_1['hour']; | |
| 71 | - } | |
| 72 | - //days | |
| 73 | - if ( $date_1['day'] >= $date_2['day'] ) { | |
| 74 | - $diff['day'] = $date_1['day'] - $date_2['day']; | |
| 75 | - } | |
| 76 | - else { | |
| 77 | - $date_1['month']--; | |
| 78 | - $diff['day'] = date( "t", $temp ) - $date_2['day'] + $date_1['day']; | |
| 79 | - } | |
| 80 | - //months | |
| 81 | - if ( $date_1['month'] >= $date_2['month'] ) { | |
| 82 | - $diff['month'] = $date_1['month'] - $date_2['month']; | |
| 83 | - } | |
| 84 | - else { | |
| 85 | - $date_1['year']--; | |
| 86 | - $diff['month'] = 12 - $date_2['month'] + $date_1['month']; | |
| 87 | - } | |
| 88 | - //years | |
| 89 | - $diff['year'] = $date_1['year'] - $date_2['year']; | |
| 90 | - return $diff; | |
| 91 | - } | |
| 92 | - | |
| 93 | - function clientShowHTML( $atts, $content = null ) { | |
| 94 | - $show_attr = ""; | |
| 95 | - $hide_attr = ""; | |
| 96 | - extract( shortcode_atts( array( 'show' => '0:00:000' , 'hide' => '0:00:000' ), $atts ) ); | |
| 97 | - | |
| 98 | - // Initialize show/hide arguments | |
| 99 | - $s_min = 0; $s_sec = 0; $s_fade = 0; | |
| 100 | - $h_min = 0; $h_sec = 0; $h_fade = 0; | |
| 101 | - @list( $s_min, $s_sec, $s_fade ) = explode( ":", $show ); | |
| 102 | - @list( $h_min, $h_sec, $h_fade ) = explode( ":", $hide ); | |
| 103 | - | |
| 104 | - if ( ( (int)$s_min + (int)$s_sec ) > 0 ) | |
| 105 | - $show_attr = "_show_" . $s_min . "_" . $s_sec . "_" . $s_fade; | |
| 106 | - if ( ( (int)$h_min + (int)$h_sec ) > 0 ) | |
| 107 | - $hide_attr = "_hide_" . $h_min . "_" . $h_sec . "_" . $h_fade; | |
| 108 | - | |
| 109 | - $the_class = TIMED_CONTENT_CLIENT_TAG . $show_attr . $hide_attr ; | |
| 110 | - //die($the_class); | |
| 111 | - $the_HTML = "<div class='" . $the_class . "'" . ( ( $show_attr != "" ) ? " style='display: none;'" : "" ) .">" . do_shortcode($content) . "</div>"; | |
| 112 | - | |
| 113 | - return $the_HTML; | |
| 114 | - } | |
| 115 | - | |
| 116 | - function serverShowHTML( $atts, $content = null ) { | |
| 117 | - extract( shortcode_atts( array( 'show' => TIMED_CONTENT_ZERO_TIME , 'hide' => TIMED_CONTENT_END_TIME, 'debug' => 'false' ), $atts ) ); | |
| 118 | - $show_t = strtotime( $show ); | |
| 119 | - $hide_t = strtotime( $hide ); | |
| 120 | - $right_now_t = time(); | |
| 121 | - $debug_header = ""; | |
| 122 | - | |
| 123 | - if ( $debug == "true" ) { | |
| 124 | - $temp_tz = date_default_timezone_get(); | |
| 125 | - date_default_timezone_set( get_option( 'timezone_string' ) ); | |
| 126 | - | |
| 127 | - $right_now = date_i18n( TIMED_CONTENT_DT_FORMAT, $right_now_t ); | |
| 128 | - | |
| 129 | - $show_diff = $this->_date_diff( $show_t, $right_now_t ); | |
| 130 | - $show_diff_str = sprintf( _n( "%d year", "%d years", $show_diff['year'] , 'timed-content'), $show_diff['year'] ) . ", "; | |
| 131 | - $show_diff_str .= sprintf( _n( "%d month", "%d months", $show_diff['month'] , 'timed-content'), $show_diff['month'] ) . ", "; | |
| 132 | - $show_diff_str .= sprintf( _n( "%d day", "%d days", $show_diff['day'] , 'timed-content'), $show_diff['day'] ) . ", "; | |
| 133 | - $show_diff_str .= sprintf( _n( "%d hour", "%d hours", $show_diff['hour'] , 'timed-content'), $show_diff['hour'] ) . ", "; | |
| 134 | - $show_diff_str .= sprintf( _n( "%d minute", "%d minutes", $show_diff['minute'] , 'timed-content'), $show_diff['minute'] ) . ", "; | |
| 135 | - $show_diff_str .= sprintf( _n( "%d second", "%d seconds", $show_diff['second'] , 'timed-content'), $show_diff['second'] ) . " "; | |
| 136 | - $show_diff_str .= ( $show_diff['before'] == true ? __( "ago" , 'timed-content') : __( "from now" , 'timed-content') ); | |
| 137 | - | |
| 138 | - $hide_diff = $this->_date_diff( $hide_t, $right_now_t ); | |
| 139 | - $hide_diff_str = sprintf( _n( "%d year", "%d years", $hide_diff['year'] , 'timed-content'), $hide_diff['year'] ) . ", " ; | |
| 140 | - $hide_diff_str .= sprintf( _n( "%d month", "%d months", $hide_diff['month'] , 'timed-content'), $hide_diff['month'] ) . ", "; | |
| 141 | - $hide_diff_str .= sprintf( _n( "%d day", "%d days", $hide_diff['day'] , 'timed-content'), $hide_diff['day'] ) . ", "; | |
| 142 | - $hide_diff_str .= sprintf( _n( "%d hour", "%d hours", $hide_diff['hour'] , 'timed-content'), $hide_diff['hour'] ) . ", "; | |
| 143 | - $hide_diff_str .= sprintf( _n( "%d minute", "%d minutes", $hide_diff['minute'] , 'timed-content'), $hide_diff['minute'] ) . ", "; | |
| 144 | - $hide_diff_str .= sprintf( _n( "%d second", "%d seconds", $hide_diff['second'] , 'timed-content'), $hide_diff['second'] ) . " "; | |
| 145 | - $hide_diff_str .= ( $hide_diff['before'] == true ? __( "ago" , 'timed-content') : __( "from now" , 'timed-content') ); | |
| 146 | - | |
| 147 | - $debug_header = "<!-- " . __( "START TIMED-CONTENT-SERVER DEBUGGING" , 'timed-content') . " -->\n<!--\n\n"; | |
| 148 | - | |
| 149 | - if ( $show == TIMED_CONTENT_ZERO_TIME ) | |
| 150 | - $debug_header .= " " . __( "'Show' attribute not set." , 'timed-content') . "\n"; | |
| 151 | - else | |
| 152 | - $debug_header .= " " . __( "'Show' attribute" , 'timed-content') . " : " . $show . ",\n " . __( "Timestamp derived from 'Show' attribute" , 'timed-content') . " = " . $show_t . ",\n " . __( "Date/time derived from timestamp" , 'timed-content') . " : " . date_i18n(TIMED_CONTENT_DT_FORMAT, $show_t) . ". " . $show_diff_str . ". \n\n"; | |
| 153 | - | |
| 154 | - if ( $hide == TIMED_CONTENT_END_TIME ) | |
| 155 | - $debug_header .= " " . __( "'Hide' attribute not set." , 'timed-content') . "\n"; | |
| 156 | - else | |
| 157 | - $debug_header .= " " . __( "'Hide' attribute" , 'timed-content') . " : " . $hide . ",\n " . __( "Timestamp derived from 'Hide' attribute" , 'timed-content') . " = " . $hide_t . ",\n " . __( "Date/time derived from timestamp" , 'timed-content') . " : " . date_i18n(TIMED_CONTENT_DT_FORMAT, $hide_t) . ". " . $hide_diff_str . ". \n\n"; | |
| 158 | - | |
| 159 | - $debug_header .= " " . __( "Current time" , 'timed-content') . " : " . $right_now . ", " . __( "Timestamp derived from current time" , 'timed-content') . " = " . $right_now_t . "\n"; | |
| 160 | - | |
| 161 | - $debug_header .= " " . __( "Wordpress option" , 'timed-content') . " 'gmt_offset' : " . get_option( 'gmt_offset' ) . "\n"; | |
| 162 | - $debug_header .= " " . __( "Wordpress option" , 'timed-content') . " 'timezone_string' : " . get_option( 'timezone_string' ) . "\n\n"; | |
| 163 | - | |
| 164 | - | |
| 165 | - $debug_header .= "-->\n<!-- " . __( "END TIMED-CONTENT-SERVER DEBUGGING" , 'timed-content') . " -->\n"; | |
| 166 | - date_default_timezone_set( $temp_tz ); | |
| 167 | - | |
| 168 | - } | |
| 169 | - $content_header = "<!-- " . __( "START TIMED-CONTENT-SERVER CONTENT" , 'timed-content') . " -->\n"; | |
| 170 | - $content_footer = "<!-- " . __( "END TIMED-CONTENT-SERVER CONTENT" , 'timed-content') . " -->\n"; | |
| 171 | - | |
| 172 | - if ( ( $show_t <= $right_now_t ) && ( $right_now_t <= $hide_t ) ) | |
| 173 | - $the_HTML = $debug_header . do_shortcode($content) . "\n"; | |
| 174 | - else | |
| 175 | - $the_HTML = $debug_header; | |
| 176 | - | |
| 177 | - return $content_header . $the_HTML . $content_footer; | |
| 178 | - } | |
| 179 | - | |
| 180 | - function addHeaderCode() { | |
| 181 | - global $wp_query; | |
| 182 | - if ( ! is_admin() ) | |
| 183 | - { | |
| 184 | - foreach ( $wp_query->posts as $post ) { | |
| 185 | - $pattern = get_shortcode_regex(); | |
| 186 | - preg_match_all( '/' . $pattern . '/s', $post->post_content, $matches, PREG_SET_ORDER ); | |
| 187 | - if ( is_array( $matches ) ) { | |
| 188 | - foreach ( $matches as $m ) { | |
| 189 | - if ( $m[2] == TIMED_CONTENT_CLIENT_TAG ) { | |
| 190 | - //shortcode is being used; enqueue script and get out (script can handle multiple uses of the shortcode already) | |
| 191 | - wp_enqueue_script( 'timed-content_js', TIMED_CONTENT_PLUGIN_URL . '/js/timed-content.js', array( 'jquery' ), '1.0' ); | |
| 192 | - break 2; | |
| 193 | - } | |
| 194 | - } | |
| 195 | - } | |
| 196 | - } | |
| 197 | - } | |
| 198 | - } | |
| 199 | - | |
| 200 | - function initTinyMCEPlugin() { | |
| 201 | - if ( ( ! current_user_can( 'edit_posts' ) ) && ( ! current_user_can( 'edit_pages' ) ) ) | |
| 202 | - return; | |
| 203 | - | |
| 204 | - // Add only in Rich Editor mode | |
| 205 | - if ( get_user_option( 'rich_editing' ) == 'true' ) { | |
| 206 | - add_filter( "mce_external_plugins", array( &$this, "addTimedContentTinyMCEPlugin" ) ); | |
| 207 | - add_filter( "mce_buttons", array( &$this, "registerTinyMCEButton" ) ); | |
| 208 | - } | |
| 209 | - | |
| 210 | - | |
| 211 | - } | |
| 212 | - | |
| 213 | - function registerTinyMCEButton( $buttons ) { | |
| 214 | - array_push( $buttons, "|", "timed_content" ); | |
| 215 | - return $buttons; | |
| 216 | - } | |
| 217 | - | |
| 218 | - // Load the TinyMCE plugin : editor_plugin.js (wp2.5) | |
| 219 | - function addTimedContentTinyMCEPlugin( $plugin_array ) { | |
| 220 | - $plugin_array['timed_content'] = TIMED_CONTENT_PLUGIN_URL . "/tinymce_plugin/editor_plugin_src.js"; | |
| 221 | - return $plugin_array; | |
| 222 | - } | |
| 223 | - | |
| 224 | - function i18nInit() { | |
| 225 | - $plugin_dir = basename( dirname( __FILE__ ) ) . "/lang/"; | |
| 226 | - load_plugin_textdomain( 'timed-content', null, $plugin_dir ); | |
| 227 | - } | |
| 228 | - | |
| 229 | - } | |
| 230 | - | |
| 231 | -} //End Class timedContentPlugin | |
| 232 | - | |
| 233 | 39 | // Initialize plugin |
| 234 | -if ( class_exists( "timedContentPlugin" ) ) { | |
| 235 | - $timedContentPluginInstance = new timedContentPlugin(); | |
| 236 | -} | |
| 237 | - | |
| 238 | -// Actions and Filters | |
| 239 | -if ( isset( $timedContentPluginInstance ) ) { | |
| 240 | - add_action( "init", array( &$timedContentPluginInstance, "i18nInit" ), 1 ); | |
| 241 | - add_action( "wp_head", array( &$timedContentPluginInstance, "addHeaderCode" ), 1 ); | |
| 242 | - add_action( "admin_init", array( &$timedContentPluginInstance, "initTinyMCEPlugin" ), 1 ); | |
| 243 | - add_shortcode( TIMED_CONTENT_CLIENT_TAG, array( &$timedContentPluginInstance, "clientShowHTML" ), 1 ); | |
| 244 | - add_shortcode( TIMED_CONTENT_SERVER_TAG, array( &$timedContentPluginInstance, "serverShowHTML" ), 1 ); | |
| 245 | -} | |
| 246 | -?> | |
| 40 | +$timed_content_plugin_instance = new TimedContentPlugin(); | |