PluginProbe
Timed Content / 2.9
Timed Content v2.9
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 | lib/customFieldsInterface.php +57 -77 2.02.9 View file →
@@ -1,57 +1,5 @@
1 1 <?php
2 -// http://ca1.php.net/manual/en/function.timezone-identifiers-list.php#79284
3 -function __timeZoneChoice( $selectedzone ) {
4 - $the_timezones = timezone_identifiers_list();
5 -
6 - $i = 0;
7 - foreach($the_timezones AS $zone) {
8 - $zone = explode( "/", $zone );
9 - $zonen[$i]['continent'] = isset( $zone[0] ) ? $zone[0] : "";
10 - $zonen[$i]['city'] = isset( $zone[1] ) ? $zone[1] : "";
11 - $zonen[$i]['subcity'] = isset( $zone[2] ) ? $zone[2] : "";
12 - $i++;
13 - }
14 -
15 - asort( $zonen );
16 - $structure = "";
17 - foreach( $zonen as $zone ) {
18 - extract( $zone );
19 - if ( $continent == "Africa"
20 - || $continent == "America"
21 - || $continent == "Antarctica"
22 - || $continent == "Arctic"
23 - || $continent == "Asia"
24 - || $continent == "Atlantic"
25 - || $continent == "Australia"
26 - || $continent == "Europe"
27 - || $continent == "Indian"
28 - || $continent == "Pacific" ) {
29 - if ( !isset( $selectcontinent ) ) {
30 - $structure .= "<optgroup label=\"" . $continent . "\">\n"; // continent
31 - } elseif ( $selectcontinent != $continent ) {
32 - $structure .= "</optgroup>\n<optgroup label=\"" . $continent . "\">\n"; // continent
33 - }
34 -
35 - if ( isset( $city ) != "") {
36 - if ( !empty( $subcity ) != "" ) {
37 - $city = $city . "/". $subcity;
38 - }
39 - $structure .= "\t<option" . ( ( ( $continent . "/" . $city ) == $selectedzone ) ? " selected=\"selected\"" : "" ) . " value=\"" . ( $continent . "/" . $city ) . "\">" . str_replace( "_", " ", $city ). "</option>\n"; //Timezone
40 - } else {
41 - if ( !empty( $subcity ) != "" ) {
42 - $city = $city . "/". $subcity;
43 - }
44 - $structure .= "\t<option " . ( ( $continent == $selectedzone ) ? "selected=\"selected\"" : "" ) . " value=\"" . $continent . "\">" . $continent . "</option>\n"; //Timezone
45 - }
46 -
47 - $selectcontinent = $continent;
48 - }
49 - }
50 - $structure .= "</optgroup>\n";
51 - return $structure;
52 -}
53 -
54 2 if ( !class_exists('customFieldsInterface') ) {
55 3
56 4 class customFieldsInterface {
57 5 /**
@@ -78,12 +26,8 @@
78 26 * @var array $customFields Defines the custom fields available
79 27 */
80 28 var $customFields = array();
81 29 /**
82 - * PHP 4 Compatible Constructor
83 - */
84 - function customFieldsInterface( $handle, $label, $desc, $prefix, $postTypes, $customFields ) { $this->__construct( $handle, $label, $desc, $prefix, $postTypes, $customFields ); }
85 - /**
86 30 * PHP 5 Constructor
87 31 */
88 32 function __construct( $handle, $label, $desc, $prefix, $postTypes, $customFields ) {
89 33
@@ -97,9 +41,37 @@
97 41 add_action( 'save_post', array( &$this, 'saveCustomFields' ), 1, 2 );
98 42 // Comment this line out if you want to keep default custom fields meta box
99 43 add_action( 'do_meta_boxes', array( &$this, 'removeDefaultCustomFields' ), 10, 3 );
100 44 }
101 - /**
45 +
46 + // Inspired by http://ca1.php.net/manual/en/function.timezone-identifiers-list.php#79284
47 + static function __generateTimezoneSelectOptions( $default_tz ) {
48 + $timezone_identifiers = timezone_identifiers_list();
49 + sort( $timezone_identifiers );
50 + $current_continent = "";
51 + $options_list = "";
52 +
53 + foreach ( $timezone_identifiers as $timezone_identifier ) {
54 + list( $continent, ) = explode( "/", $timezone_identifier, 2);
55 + if ( in_array( $continent, array( "Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia", "Europe", "Indian", "Pacific" ) ) ) {
56 + list( , $city ) = explode( "/", $timezone_identifier, 2);
57 + if ( strlen( $current_continent ) === 0 ) {
58 + $options_list .= "<optgroup label=\"" . $continent . "\">"; // Start first continent optgroup
59 + }
60 + elseif ( $current_continent != $continent ) {
61 + $options_list .= "</optgroup><optgroup label=\"" . $continent . "\">"; // End old optgroup and start new continent optgroup
62 + }
63 + $options_list .= "<option" . ( ( $timezone_identifier == $default_tz ) ? " selected=\"selected\"" : "" )
64 + . " value=\"" . $timezone_identifier . "\">" . str_replace( "_", " ", $city ). "</option>"; //Timezone
65 + }
66 + $current_continent = $continent;
67 + }
68 + $options_list .= "</optgroup>"; // End last continent optgroup
69 +
70 + return $options_list;
71 + }
72 +
73 + /**
102 74 * Remove the default Custom Fields meta box
103 75 */
104 76 function removeDefaultCustomFields( $type, $context, $post ) {
105 77 foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
@@ -111,8 +83,10 @@
111 83 /**
112 84 * Create the new Custom Fields meta box
113 85 */
114 86 function createCustomFields() {
87 +
88 + include("jquery-ui-datetime-i18n.php" );
115 89 // Only enqueue scripts if we're dealing with 'timed-content-rule' pages
116 90 foreach ( $this->postTypes as $a_postType ) {
117 91 if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $a_postType )
118 92 || ( isset( $post_type ) && $post_type == $a_postType )
@@ -119,16 +93,24 @@
119 93 || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == $a_postType ) ) {
120 94
121 95 wp_enqueue_style( 'wp-color-picker' );
122 96 wp_enqueue_script( 'wp-color-picker' );
123 - wp_enqueue_style( 'timed-content-jquery-ui', TIMED_CONTENT_JQUERY_UI_CSS );
124 - wp_enqueue_script( 'jquery-ui-datepicker' );
125 - wp_enqueue_script( 'jquery-ui-spinner' );
126 - wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS );
127 - wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' );
128 - wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION );
129 - wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' );
130 - if ( function_exists( 'add_meta_box' ) )
97 + wp_enqueue_script( 'jquery-ui-spinner' );
98 +
99 + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-css', TIMED_CONTENT_JQUERY_UI_CSS);
100 + wp_enqueue_script('jquery-ui-datepicker');
101 + wp_register_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS);
102 + wp_enqueue_style(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-css');
103 + wp_register_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION);
104 + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js');
105 + if (!(wp_script_is(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'registered'))) {
106 + wp_register_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', TIMED_CONTENT_PLUGIN_URL . "/js/content-protector-datetime-i18n.js", array('jquery', 'jquery-ui-datepicker', TIMED_CONTENT_SLUG . '-jquery-ui-timepicker-js'), TIMED_CONTENT_VERSION);
107 + wp_enqueue_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js');
108 + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQDatepickerI18n', $jquery_ui_datetime_datepicker_i18n);
109 + wp_localize_script(TIMED_CONTENT_SLUG . '-jquery-ui-datetime-i18n-js', 'TimedContentJQTimepickerI18n', $jquery_ui_datetime_timepicker_i18n);
110 + }
111 +
112 + if ( function_exists( 'add_meta_box' ) )
131 113 add_meta_box( $this->handle, $this->label, array( &$this, 'displayCustomFields' ), $a_postType, 'normal', 'high' );
132 114 }
133 115 }
134 116 }
@@ -179,12 +161,12 @@
179 161 case "menu": {
180 162 // menu
181 163 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label><br />\n";
182 164 if ( sizeof ( $customField['values'] ) == 0 )
183 - echo "<em>This menu is empty.</em>\n";
165 + echo "<em>" . __( "This menu is empty.", "timed-content" ) . "</em>\n";
184 166 else {
185 167 $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
186 - echo "<select name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto; height: auto; padding: 3px;\" size=\"" . $customField['size'] . "\" multiple=\"multiple\">\n";
168 + echo "<select name=\"" . $this->prefix . $customField['name'] . "[]\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto; height: auto; padding: 3px;\" size=\"" . $customField['size'] . "\" multiple=\"multiple\">\n";
187 169 foreach ( $customField['values'] as $value => $label ) {
188 170 echo "\t<option value=\"" . $value . "\"";
189 171 if ( $selected_value == $value )
190 172 echo " selected=\"selected\"";
@@ -197,9 +179,9 @@
197 179 case "list": {
198 180 // list
199 181 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
200 182 if ( sizeof ( $customField['values'] ) == 0 )
201 - echo "<em>This list is empty.</em>\n";
183 + echo "<em>" . __( "This menu is empty.", "timed-content" ) . "</em>\n";
202 184 else {
203 185 $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
204 186 echo "<select name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto;\">\n";
205 187 foreach ( $customField['values'] as $value => $label ) {
@@ -217,9 +199,9 @@
217 199 $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
218 200
219 201 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
220 202 echo "<select name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto;\">\n";
221 - echo __timeZoneChoice( $selected_value );
203 + echo customFieldsInterface::__generateTimezoneSelectOptions( $selected_value );
222 204 echo "</select>\n";
223 205 break;
224 206 }
225 207 case "checkbox": {
@@ -238,9 +220,9 @@
238 220 $checked_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
239 221
240 222 echo "<strong>" . $customField[ 'title' ] . "</strong><br />\n";
241 223 if ( sizeof ( $customField['values'] ) == 0 )
242 - echo "<em>This list is empty.</em>\n";
224 + echo "<em>" . __( "This menu is empty.", "timed-content" ) . "</em>\n";
243 225 else {
244 226 foreach ( $customField['values'] as $value => $label ) {
245 227 echo "<input type=\"checkbox\" name=\"" . $this->prefix . $customField['name'] . "[]\" id=\"" . $this->prefix . $customField['name'] . "_" . $value . "\" value=\"" . $value . "\"";
246 228 if ( ( is_array( $checked_value ) ) && ( in_array( $value, $checked_value ) ) )
@@ -292,9 +274,10 @@
292 274 echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" size=\"7\" maxlength=\"7\" style=\"width: 100px;\" />\n";
293 275 break;
294 276 }
295 277 case "date": {
296 - echo "<span style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></span>&nbsp;&nbsp;\n";
278 + echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
279 +// echo "<span style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></span>&nbsp;&nbsp;\n";
297 280 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
298 281 // Date picker using WP's built-in Datepicker jQuery plugin ?>
299 282 <script type="text/javascript">
300 283 //<![CDATA[
@@ -300,9 +283,9 @@
300 283 //<![CDATA[
301 284 jQuery(document).ready(function() {
302 285 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>" ).datepicker(
303 286 {
304 - dateFormat: "<?php _ex( "MM d, yy", "Date format for jQuery UI Datepicker", 'timed-content' ); ?>",
287 + <?php if( isset( $customField[ 'custom_functions' ] ) ) echo $customField[ 'custom_functions' ]; ?>
305 288 changeMonth: true,
306 289 changeYear: true
307 290 }
308 291 );
@@ -308,10 +291,10 @@
308 291 );
309 292 });
310 293 //]]>
311 294 </script>
312 - <?php
313 - echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . htmlspecialchars( $value ) . "\" style=\"width: 175px;\" />\n";
295 + <?php
296 + echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . htmlspecialchars( $value ) . "\" style=\"width: 175px;\" />\n";
314 297 break;
315 298 }
316 299 case "datetime": {
317 300 echo "<span style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></span><br />\n";
@@ -325,9 +308,8 @@
325 308 //<![CDATA[
326 309 jQuery(document).ready(function() {
327 310 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>_date" ).datepicker(
328 311 {
329 - dateFormat: "<?php _ex( "MM d, yy", "Date format for jQuery UI Datepicker", 'timed-content' ); ?>",
330 312 changeMonth: true,
331 313 changeYear: true
332 314 }
333 315 );
@@ -332,10 +314,8 @@
332 314 }
333 315 );
334 316 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>_time" ).timepicker(
335 317 {
336 - showLeadingZero: false,
337 - showPeriod: true,
338 318 defaultTime: 'now'
339 319 }
340 320 );
341 321 });