PluginProbe
Timed Content / 2.1
Timed Content v2.1
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
timed-content / lib / customFieldsInterface.php

customFieldsInterface.php in Timed Content 2.1, at lib/customFieldsInterface.php

436 lines 21.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 if ( !class_exists('customFieldsInterface') ) {
55
56 class customFieldsInterface {
57 /**
58 * @var string $handle The handle for the box containing the custom fields
59 */
60 var $handle = "";
61 /**
62 * @var string $label The label for the box containing the custom fields
63 */
64 var $label = "";
65 /**
66 * @var string $desc The description/introduction for the box containing the custom fields
67 */
68 var $desc = "";
69 /**
70 * @var string $prefix The prefix for storing custom fields in the postmeta table
71 */
72 var $prefix = "";
73 /**
74 * @var array $postTypes An array of public custom post types, plus the standard "post" and "page" - add the custom types you want to include here
75 */
76 var $postTypes = array();
77 /**
78 * @var array $customFields Defines the custom fields available
79 */
80 var $customFields = array();
81 /**
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 * PHP 5 Constructor
87 */
88 function __construct( $handle, $label, $desc, $prefix, $postTypes, $customFields ) {
89
90 $this->handle = $handle;
91 $this->label = $label;
92 $this->desc = $desc;
93 $this->prefix = $prefix;
94 $this->postTypes = $postTypes ;
95 $this->customFields = $customFields;
96 add_action( 'admin_menu', array( &$this, 'createCustomFields' ) );
97 add_action( 'save_post', array( &$this, 'saveCustomFields' ), 1, 2 );
98 // Comment this line out if you want to keep default custom fields meta box
99 add_action( 'do_meta_boxes', array( &$this, 'removeDefaultCustomFields' ), 10, 3 );
100 }
101 /**
102 * Remove the default Custom Fields meta box
103 */
104 function removeDefaultCustomFields( $type, $context, $post ) {
105 foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
106 foreach ( $this->postTypes as $postType ) {
107 remove_meta_box( 'postcustom', $postType, $context );
108 }
109 }
110 }
111 /**
112 * Create the new Custom Fields meta box
113 */
114 function createCustomFields() {
115 // Only enqueue scripts if we're dealing with 'timed-content-rule' pages
116 foreach ( $this->postTypes as $a_postType ) {
117 if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $a_postType )
118 || ( isset( $post_type ) && $post_type == $a_postType )
119 || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == $a_postType ) ) {
120
121 wp_enqueue_style( 'wp-color-picker' );
122 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' ) )
131 add_meta_box( $this->handle, $this->label, array( &$this, 'displayCustomFields' ), $a_postType, 'normal', 'high' );
132 }
133 }
134 }
135 /**
136 * Display the new Custom Fields meta box
137 */
138 function displayCustomFields() {
139 global $post;
140 ?>
141 <p><?php echo $this->desc; ?></p>
142 <div class="form-wrap">
143 <?php
144 wp_nonce_field( $this->handle, $this->handle . '_wpnonce', false, true );
145 foreach ( $this->customFields as $customField ) {
146 // Check scope
147 $scope = $customField[ 'scope' ];
148 $output = false;
149 foreach ( $scope as $scopeItem ) {
150 switch ( $scopeItem ) {
151 default: {
152 if ( $post->post_type == $scopeItem )
153 $output = true;
154 break;
155 }
156 }
157 if ( $output ) break;
158 }
159 // Check capability
160 if ( !current_user_can( $customField['capability'], $post->ID ) )
161 $output = false;
162 // Output if allowed
163 if ( $output ) { ?>
164 <div class="form-field form-required" id="<?php echo $this->prefix . $customField[ 'name' ]; ?>_div" style="display: <?php echo $customField[ 'display' ]; ?>">
165 <?php
166 switch ( $customField[ 'type' ] ) {
167 case "radio": {
168 // radio
169 $checked_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
170 echo "<strong>" . $customField[ 'title' ] . "</strong><br />\n";
171 foreach ( $customField['values'] as $value => $label ) {
172 echo "<input type=\"radio\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "_" . $value . "\" value=\"" . $value . "\"";
173 if ( $checked_value == $value )
174 echo " checked=\"checked\"";
175 echo " style=\"width: 30px;\" /><label for=\"" . $this->prefix . $customField[ 'name' ] . "_" . $value . "\" style=\"display: inline;\">" . $label . "</label><br />\n";
176 }
177 break;
178 }
179 case "menu": {
180 // menu
181 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label><br />\n";
182 if ( sizeof ( $customField['values'] ) == 0 )
183 echo "<em>This menu is empty.</em>\n";
184 else {
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 ) );
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";
187 foreach ( $customField['values'] as $value => $label ) {
188 echo "\t<option value=\"" . $value . "\"";
189 if ( $selected_value == $value )
190 echo " selected=\"selected\"";
191 echo ">" . $label . "</option>\n";
192 }
193 echo "</select>\n";
194 }
195 break;
196 }
197 case "list": {
198 // list
199 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
200 if ( sizeof ( $customField['values'] ) == 0 )
201 echo "<em>This list is empty.</em>\n";
202 else {
203 $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 echo "<select name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto;\">\n";
205 foreach ( $customField['values'] as $value => $label ) {
206 echo "\t<option value=\"" . $value . "\"";
207 if ( $selected_value == $value )
208 echo " selected=\"selected\"";
209 echo ">" . $label . "</option>\n";
210 }
211 echo "</select>\n";
212 }
213 break;
214 }
215 case "timezone-list": {
216 // timezone list
217 $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
219 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
220 echo "<select name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" style=\"width: auto;\">\n";
221 echo __timeZoneChoice( $selected_value );
222 echo "</select>\n";
223 break;
224 }
225 case "checkbox": {
226 // Checkbox
227 $checked_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
228
229 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
230 echo "<input type=\"checkbox\" name=\"" . $this->prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" value=\"yes\"";
231 if ( $checked_value == "yes" )
232 echo " checked=\"checked\"";
233 echo " style=\"width: 30px;\" />\n";
234 break;
235 }
236 case "checkbox-list": {
237 // Checkbox list
238 $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
240 echo "<strong>" . $customField[ 'title' ] . "</strong><br />\n";
241 if ( sizeof ( $customField['values'] ) == 0 )
242 echo "<em>This list is empty.</em>\n";
243 else {
244 foreach ( $customField['values'] as $value => $label ) {
245 echo "<input type=\"checkbox\" name=\"" . $this->prefix . $customField['name'] . "[]\" id=\"" . $this->prefix . $customField['name'] . "_" . $value . "\" value=\"" . $value . "\"";
246 if ( ( is_array( $checked_value ) ) && ( in_array( $value, $checked_value ) ) )
247 echo " checked=\"checked\"";
248 echo " style=\"width: 30px;\" /><label for=\"" . $this->prefix . $customField['name'] . "_" . $value . "\" style=\"display: inline;\" >" . $label . "</label><br />\n";
249 }
250 }
251 break;
252 }
253 case "textarea":
254 case "wysiwyg": {
255 // Text area
256 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
257 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] ."\"><strong>" . $customField[ 'title' ] . "</strong></label>\n";
258 echo "<textarea name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" columns=\"30\" rows=\"3\">" . htmlspecialchars( $value ) . "</textarea>\n";
259 // WYSIWYG
260 if ( $customField[ 'type' ] == "wysiwyg" ) { ?>
261 <script type="text/javascript">
262 //<![CDATA[
263 jQuery( document ).ready( function() {
264 jQuery( "<?php echo $this->prefix . $customField[ 'name' ]; ?>" ).addClass( "mceEditor" );
265 if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
266 tinyMCE.execCommand( "mceAddControl", false, "<?php echo $this->prefix . $customField[ 'name' ]; ?>" );
267 }
268 });
269 //]]>
270 </script>
271 <?php }
272 break;
273 }
274 case "color-picker": {
275 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
276 // Color picker using WP's built-in Iris jQuery plugin ?>
277 <script type="text/javascript">
278 //<![CDATA[
279 jQuery(document).ready(function() {
280 var <?php echo $this->prefix . $customField[ 'name' ]; ?>Options = {
281 defaultColor: false,
282 hide: true,
283 palettes: true
284 };
285
286 jQuery("#<?php echo $this->prefix . $customField[ 'name' ]; ?>").wpColorPicker(<?php echo $this->prefix . $customField[ 'name' ]; ?>Options);
287 });
288 //]]>
289 </script>
290 <?php
291 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
292 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 break;
294 }
295 case "date": {
296 echo "<span style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></span>&nbsp;&nbsp;\n";
297 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
298 // Date picker using WP's built-in Datepicker jQuery plugin ?>
299 <script type="text/javascript">
300 //<![CDATA[
301 jQuery(document).ready(function() {
302 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>" ).datepicker(
303 {
304 dateFormat: "<?php _ex( "MM d, yy", "Date format for jQuery UI Datepicker", 'timed-content' ); ?>",
305 changeMonth: true,
306 changeYear: true
307 }
308 );
309 });
310 //]]>
311 </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";
314 break;
315 }
316 case "datetime": {
317 echo "<span style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></span><br />\n";
318 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
319 foreach ( $value as $k => $v )
320 $value[$k] = htmlspecialchars( $v );
321 // Date picker using WP's built-in Datepicker jQuery plugin
322 // Time picker using jQuery UI Timepicker: http://fgelinas.com/code/timepicker
323 ?>
324 <script type="text/javascript">
325 //<![CDATA[
326 jQuery(document).ready(function() {
327 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>_date" ).datepicker(
328 {
329 dateFormat: "<?php _ex( "MM d, yy", "Date format for jQuery UI Datepicker", 'timed-content' ); ?>",
330 changeMonth: true,
331 changeYear: true
332 }
333 );
334 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>_time" ).timepicker(
335 {
336 showLeadingZero: false,
337 showPeriod: true,
338 defaultTime: 'now'
339 }
340 );
341 });
342 //]]>
343 </script>
344 <?php
345 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "_date\" style=\"display:inline;\"><em>" . _x( 'Date', 'Date field label', 'timed-content' ) . ":</em></label>&nbsp;&nbsp;\n";
346 echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "[date]\" id=\"" . $this->prefix . $customField[ 'name' ] . "_date\" value=\"" . $value['date'] . "\" style=\"width: 175px;\" />\n";
347 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] ."_time\" style=\"display:inline;\"><em>" . _x( 'Time', 'Time field label', 'timed-content' ) . ":</em></label>&nbsp;&nbsp;\n";
348 echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "[time]\" id=\"" . $this->prefix . $customField[ 'name' ] . "_time\" value=\"" . $value['time'] . "\" style=\"width: 125px;\" />\n";
349 break;
350 }
351 case "number": {
352 (int)$value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
353 // Number picker using WP's built-in Spinner jQuery plugin ?>
354 <script type="text/javascript">
355 //<![CDATA[
356 jQuery(document).ready(function() {
357 jQuery( "#<?php echo $this->prefix . $customField[ 'name' ]; ?>" ).spinner(
358 {
359 stop: function( event, ui ) { jQuery( this ).trigger("change"); },
360 <?php if ( isset( $customField[ 'min' ] ) ) { ?>min: <?php echo $customField[ 'min' ]; ?>, <?php } ?>
361 <?php if ( isset( $customField[ 'max' ] ) ) { ?>max: <?php echo $customField[ 'max' ]; ?> <?php } ?>
362 }
363 );
364 });
365 //]]>
366 </script>
367 <?php
368 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\" style=\"display:inline;\"><strong>" . $customField[ 'title' ] . "</strong></label>&nbsp;&nbsp;\n";
369 echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" size=\"2\" />\n";
370 break;
371 }
372 case "hidden": {
373 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
374 // Hidden field
375 echo "<input type=\"hidden\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" />\n";
376 break;
377 }
378 default: {
379 $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) );
380 // Plain text field
381 echo "<label for=\"" . $this->prefix . $customField[ 'name' ] . "\"><strong>" . $customField[ 'title' ] . "</strong></label>\n";
382 echo "<input type=\"text\" name=\"" . $this->prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" />\n";
383 break;
384 }
385 }
386 ?>
387 <?php if ( isset( $customField[ 'description' ] ) ) echo "<p>" . $customField[ 'description' ] . "</p>\n"; ?>
388 </div>
389 <?php
390 }
391 } ?>
392 </div>
393 <?php
394 }
395 /**
396 * Save the new Custom Fields values
397 */
398 function saveCustomFields( $post_id, $post ) {
399 // Only save if the user intends to save
400 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
401 return;
402 // Make sure the Save request is coming from the right place
403 if ( !isset( $_POST[ $this->handle . '_wpnonce' ] ) || !wp_verify_nonce( $_POST[ $this->handle . '_wpnonce' ], $this->handle ) )
404 return;
405 // Make sure the user can edit this specific post
406 if ( !current_user_can( 'edit_post', $post_id ) )
407 return;
408 // Make sure this meta box is associated with the right post types
409 if ( ! in_array( $post->post_type, $this->postTypes ) )
410 return;
411 foreach ( $this->customFields as $customField ) {
412 if ( current_user_can( $customField['capability'], $post_id ) ) {
413 if ( isset( $_POST[ $this->prefix . $customField['name'] ] ) ) {
414 if ( is_array( $_POST[ $this->prefix . $customField['name'] ] ) ) {
415 foreach ( $_POST[ $this->prefix . $customField['name'] ] as $k => $v )
416 $_POST[ $this->prefix . $customField['name'] ][$k] = trim( $v );
417 } else
418 $_POST[ $this->prefix . $customField['name'] ] = trim( $_POST[ $this->prefix . $customField['name'] ] );
419 $value = $_POST[ $this->prefix . $customField['name'] ];
420 // Auto-paragraphs for any WYSIWYG
421 if ( $customField['type'] == "wysiwyg" ) $value = wpautop( $value );
422 if ( $customField['type'] == "checkbox" ) $value = "yes";
423 if ( $customField['type'] == "number" ) $value = intval( $value );
424 update_post_meta( $post_id, $this->prefix . $customField[ 'name' ], $value );
425 } else {
426 delete_post_meta( $post_id, $this->prefix . $customField[ 'name' ] );
427 }
428 }
429 }
430 }
431
432
433 } // End Class
434
435 } // End if class exists statement
436 ?>