Contact Form 7 Datepicker - Version 0.3

Version Description

  • Added tag generator
Download this release

Release Info

Developer shockware
Plugin Icon wp plugin Contact Form 7 Datepicker
Version 0.3
Comparing to
See all releases

Code changes from version 0.2.1 to 0.3

contact-form-7-datepicker.php CHANGED
@@ -4,12 +4,12 @@ Plugin Name: Contact Form 7 Datepicker
4
Plugin URI: https://github.com/relu/contact-form-7-datepicker/
5
Description: Implements a new [date] tag in Contact Form 7 that adds a date field to a form. When clicking the field a calendar pops up enabling your site visitors to easily select any date.
6
Author: Aurel Canciu
7
- Version: 0.2.1
8
Author URI: https://github.com/relu/
9
*/
10
?>
11
<?php
12
- /* Copyright 2011 Aurel Canciu <aurelcanciu@gmail.com>
13
14
This program is free software; you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
@@ -28,82 +28,92 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
?>
29
<?php
30
31
- define('CF7_DATE_PICKER_VERSION', '0.2.1');
32
-
33
- /**
34
- * deactivate_cf7datepicker()
35
- *
36
- * Action triggered when plugin is activated
37
- * It inserts some default values as options
38
- */
39
- function activate_cf7datepicker(){
40
- global $wpdb, $blog_id;
41
- $table = $wpdb->prefix."options";
42
- $query = "INSERT INTO $table (blog_id, option_name, option_value)
43
- VALUES (".$blog_id.",'cf7datepicker','2;false;false;beige;%d-%m-%Y;1;ltr') ";
44
- $result = $wpdb->query( $query );
45
- }
46
47
- /**
48
- * deactivate_cf7datepicker()
49
- *
50
- * Action triggered when plugin is deactivated
51
- * It deletes the settings stored in the database
52
- */
53
- function deactivate_cf7datepicker() {
54
- global $wpdb, $blog_id;
55
- $table = $wpdb->prefix."options";
56
-
57
- $query = " DELETE FROM $table WHERE blog_id=".$blog_id." AND option_name='cf7datepicker' ";
58
- $result = $wpdb->query( $query );
59
60
- }
61
62
- /**
63
- * load_settings_cf7datepicker()
64
- *
65
- * Loads plugin's settings from the database
66
- */
67
- function load_settings_cf7datepicker() {
68
- global $wpdb, $blog_id;
69
- $table = $wpdb->prefix."options";
70
- return $wpdb->get_row( "SELECT * FROM $table WHERE blog_id=".$blog_id." AND option_name='cf7datepicker' ");
71
- }
72
73
- /**
74
- * update_settings_cf7datepicker($dataupdate)
75
- *
76
- * Updates plugin's settings into the database
77
- * @param Array $dateupdate, contains the updated settings
78
- */
79
- function update_settings_cf7datepicker($dataupdate) {
80
- global $wpdb, $blog_id;
81
- $table = $wpdb->prefix."options";
82
- $query = " UPDATE $table SET option_value = '".$dataupdate[0].";".$dataupdate[1].";".$dataupdate[2].";".$dataupdate[3].";".$dataupdate[4].";".$dataupdate[5].";".$dataupdate[6]."' WHERE blog_id=".$blog_id." AND option_name='cf7datepicker' ";
83
- $result = $wpdb->query( $query );
84
- }
85
86
- /**
87
- * register_admin_settings_cf7datepicker()
88
- *
89
- * Registers the Admin panel so that it will show up as a submenu page in Contact Form 7's menu
90
- */
91
- function register_admin_settings_cf7datepicker() {
92
- if (function_exists('add_submenu_page')) {
93
- add_submenu_page('wpcf7',__('Datepicker Settings', 'contact-form-7-datepicker'),__('Datepicker Settings', 'contact-form-7-datepicker'),
94
- 'edit_themes',
95
- basename(__FILE__),
96
- 'admin_settings_html_cf7datepicker');
97
- }
98
- }
99
100
- /**
101
- * read_schemes_cf7datepicker()
102
- *
103
- * Gets the names of the schemes available from the img/ directory
104
- * @return Array $themes, the names of the schemes found
105
- */
106
- function read_schemes_cf7datepicker() {
107
$path = ABSPATH.'/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/';
108
if ($handle = opendir($path)) {
109
$themes = array() ;
@@ -117,48 +127,46 @@ function read_schemes_cf7datepicker() {
117
return $themes;
118
}
119
120
- /**
121
- * get_scheme_images_cf7datepicker()
122
- *
123
- * Gets the images of a scheme and natural sorts them
124
- * @param String $scheme, the name of the scheme to get images for
125
- * @return Array $schemeimg, the paths to the scheme images
126
- */
127
- function get_scheme_images_cf7datepicker($scheme) {
128
- $path = ABSPATH.'/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/'.$scheme.'/';
129
- if ($handle = opendir($path)) {
130
- $schemeimg = array();
131
- while (false !== ($file = readdir($handle))) {
132
- if (is_file($path.$file) && preg_match('/\.gif#x2F;i', $file))
133
- $schemeimg[] = '/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/'.$scheme.'/'.$file;
134
}
135
- natsort($schemeimg);
136
}
137
- closedir($handle);
138
- return $schemeimg;
139
- }
140
141
- /**
142
- * admin_settings_html_cf7datepicker()
143
- *
144
- * Generates the admin panel HTML
145
- */
146
- function admin_settings_html_cf7datepicker() {
147
- if(isset($_POST['datepickersave'])) {
148
- $dataupdate = array($_POST['useMode'], $_POST['isStripped'], $_POST['limitToToday'], $_POST['cellColorScheme'], $_POST['dateFormat'], $_POST['weekStartDay'], $_POST['directionality']);
149
- update_settings_cf7datepicker($dataupdate);
150
- }
151
-
152
- $loadsetting = load_settings_cf7datepicker();
153
- $setting = explode(";",$loadsetting->option_value);
154
- $useMode = array(1,2);
155
- $limitToToday = $isStripped = array(__('true', 'contact-form-7-datepicker'),__('false', 'contact-form-7-datepicker'));
156
- $cellColorScheme = read_schemes_cf7datepicker();
157
- $weekStartDay = array(__('Sunday', 'contact-form-7-datepicker'),__('Monday', 'contact-form-7-datepicker'));
158
- $directionality = array(__('Left to right', 'contact-form-7-datepicker'),__('Right to left', 'contact-form-7-datepicker'));
159
160
- ?>
161
- <div class="wrap">
162
<h2>Contact Form 7 Datepicker</h2><?php
163
echo __('<p>This plugin implements a new <strong>[date]</strong> tag in <a href="http://wordpress.org/extend/plugins/contact-form-7/">Contact Form 7</a>
164
that adds a date field to a form. When clicking the field a calendar pops up enabling your site visitors to easily select any date.<br />
@@ -173,7 +181,7 @@ function admin_settings_html_cf7datepicker() {
173
</th>
174
<td colspan="2"><?php
175
foreach($cellColorScheme as $scheme) {
176
- if($scheme == $setting[3])
177
$checked = "checked='checked'";
178
else
179
$checked = ""; ?>
@@ -181,7 +189,7 @@ function admin_settings_html_cf7datepicker() {
181
<div style="float: left; width: 100px; margin: 30px 30px 0 0; text-align: center;">
182
<div style="display: block; padding: 5px; background: #fff; border: 1px solid #ccc; border-radius: 4px 4px 4px 4px;">
183
<label><?php echo $scheme; ?></label><br /><?php
184
- foreach(get_scheme_images_cf7datepicker($scheme) as $img) { ?>
185
<img src="<?php echo get_option('siteurl') . $img; ?>" style="margin: 5px;" /><?php
186
} ?><br /><br />
187
<input name="cellColorScheme" type="radio" width="24" height="25" value="<?php echo $scheme; ?>" <?php echo $checked; ?> />
@@ -198,7 +206,7 @@ function admin_settings_html_cf7datepicker() {
198
<td>
199
<select name="useMode"><?php
200
foreach($useMode as $row) {
201
- if($row == $setting[0])
202
$selected = "selected";
203
else
204
$selected = "";
@@ -225,7 +233,7 @@ function admin_settings_html_cf7datepicker() {
225
else
226
$val = "false";
227
228
- if ($val == $setting[1])
229
$selected = "selected";
230
else
231
$selected = "";
@@ -251,7 +259,7 @@ function admin_settings_html_cf7datepicker() {
251
else
252
$val = "false";
253
254
- if ($val == $setting[2])
255
$selected = "selected";
256
else
257
$selected = "";
@@ -277,7 +285,7 @@ function admin_settings_html_cf7datepicker() {
277
else
278
$val = 1;
279
280
- if($val == $setting[5])
281
$selected = "selected";
282
else
283
$selected = "";
@@ -302,7 +310,7 @@ function admin_settings_html_cf7datepicker() {
302
else
303
$val = "rtl";
304
305
- if($val == $setting[6])
306
$selected = "selected";
307
else
308
$selected = "";
@@ -320,7 +328,7 @@ function admin_settings_html_cf7datepicker() {
320
<label><?php echo __('Date Format', 'contact-form-7-datepicker'); ?></label>
321
</th>
322
<td>
323
- <input name="dateFormat" id="dateFormat" type="text" value="<?php echo $setting[4]; ?>" />
324
</td>
325
<td>
326
<?php echo __('<p>Possible values to use in the date format:<br />
@@ -349,224 +357,284 @@ You can of course put whatever divider you want between them.<br /></p>',
349
</tbody>
350
</table>
351
</form><?php
352
- }
353
354
- /**
355
- * enqueues_cf7datepicker()
356
- *
357
- * Loads needed scripts and CSS
358
- */
359
- function enqueues_cf7datepicker() {
360
- $loadsetting = load_settings_cf7datepicker();
361
- $setting = explode(";",$loadsetting->option_value);
362
-
363
- if( is_admin() )
364
- return; ?>
365
- <link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/css/jsDatePick_'.(($setting[6] != "") ? $setting[6] : "ltr").'.min.css', __FILE__ ); ?>" />
366
- <script type="text/javascript" src="<?php echo plugins_url( '/js/jsDatePick.jquery.min.1.3.js', __FILE__ ); ?>"></script>
367
- <script type="text/javascript"><?php echo "
368
- g_l = [];
369
- g_l[\"MONTHS\"] = [\"".__('Janaury', 'contact-form-7-datepicker').
370
- "\",\"".__('February', 'contact-form-7-datepicker').
371
- "\",\"".__('March', 'contact-form-7-datepicker').
372
- "\",\"".__('April', 'contact-form-7-datepicker').
373
- "\",\"".__('May', 'contact-form-7-datepicker').
374
- "\",\"".__('June', 'contact-form-7-datepicker').
375
- "\",\"".__('July', 'contact-form-7-datepicker').
376
- "\",\"".__('August', 'contact-form-7-datepicker').
377
- "\",\"".__('September', 'contact-form-7-datepicker').
378
- "\",\"".__('October', 'contact-form-7-datepicker').
379
- "\",\"".__('November', 'contact-form-7-datepicker').
380
- "\",\"".__('December', 'contact-form-7-datepicker')."\"];
381
- g_l[\"DAYS_3\"] = [\"".__('Sun', 'contact-form-7-datepicker').
382
- "\",\"".__('Mon', 'contact-form-7-datepicker').
383
- "\",\"".__('Tue', 'contact-form-7-datepicker').
384
- "\",\"".__('Wed', 'contact-form-7-datepicker').
385
- "\",\"".__('Thu', 'contact-form-7-datepicker').
386
- "\",\"".__('Fri', 'contact-form-7-datepicker').
387
- "\",\"".__('Sat', 'contact-form-7-datepicker')."\"];
388
- g_l[\"MONTH_FWD\"] = \"".__('Move a month forward', 'contact-form-7-datepicker')."\";
389
- g_l[\"MONTH_BCK\"] = \"".__('Move a month backward', 'contact-form-7-datepicker')."\";
390
- g_l[\"YEAR_FWD\"] = \"".__('Move a year forward', 'contact-form-7-datepicker')."\";
391
- g_l[\"YEAR_BCK\"] = \"".__('Move a year backward', 'contact-form-7-datepicker')."\";
392
- g_l[\"CLOSE\"] = \"".__('Close the calendar', 'contact-form-7-datepicker')."\";
393
- g_l[\"ERROR_2\"] = g_l[\"ERROR_1\"] = \"".__('Date object invalid!', 'contact-form-7-datepicker')."\";
394
- g_l[\"ERROR_4\"] = g_l[\"ERROR_3\"] = \"".__('Target invalid!', 'contact-form-7-datepicker')."\";"; ?>
395
</script><?php
396
- }
397
-
398
- /**
399
- * page_text_filter_cf7datepicker($content)
400
- *
401
- * Searches for [datepicker ] tag inside page content
402
- * @param String $content, the page content which gets filtered
403
- * @return function preg_replace_callback, searches for the tag and calls page_text_filter_callback_cf7datepicker if found
404
- */
405
- function page_text_filter_cf7datepicker($content) {
406
- $regex = '/\[datepicker\s(.*?)\]/';
407
- return preg_replace_callback($regex, 'page_text_filter_callback_cf7datepicker', $content);
408
- }
409
410
- /**
411
- * page_text_filter_callback_cf7datepicker($matches)
412
- *
413
- * If a match is found in the content of a form, this returns the HTML for the matched date input field
414
- * @param Array $matches, the name of the input date field that we generate code for
415
- * @return String $string, the HTML for our match
416
- */
417
- function page_text_filter_callback_cf7datepicker($matches) {
418
- $loadsetting = load_settings_cf7datepicker();
419
- $setting = explode(";",$loadsetting->option_value);
420
-
421
- $string = "<input type=\"text\" name=\"".$matches[1]."\" id=\"".$matches[1]."\" />
422
- <script type=\"text/javascript\">
423
- jQuery(document).ready(function() {
424
- DatePicker_".$matches[1]." = new JsDatePick({
425
- useMode:".$setting[0].",
426
- isStripped:".$setting[1].",
427
- target:\"".$matches[1]."\",
428
- limitToToday:".$setting[2].",
429
- cellColorScheme:\"".$setting[3]."\",
430
- dateFormat:\"".$setting[4]."\",
431
- imgPath:\"".plugins_url( '/img/'.$setting[3].'/', __FILE__ )."\",
432
- weekStartDay:".$setting[5].",
433
- directionality:\"".$setting[6]."\"
434
});
435
- });
436
- </script>";
437
- return $string;
438
- }
439
-
440
- /**
441
- * wpcf7_shotcode_handler_cf7datepicker($tag)
442
- *
443
- * Handler for wpcf7 shortcodes [date ] and [date* ]
444
- * @param Array $tag, this is the tag that will be handled (can be 'date' or 'date*')
445
- * @return String $html, the HTML that will be appended to the form
446
- */
447
- function wpcf7_shotcode_handler_cf7datepicker($tag) {
448
- global $wpcf7_contact_form;
449
-
450
- if ( ! is_array( $tag ) )
451
- return '';
452
453
- $type = $tag['type'];
454
- $name = $tag['name'];
455
- $options = (array) $tag['options'];
456
- $values = (array) $tag['values'];
457
458
- if ( empty( $name ) )
459
- return '';
460
461
- $atts = '';
462
- $id_att = '';
463
- $class_att = '';
464
- $size_att = '';
465
- $maxlength_att = '';
466
467
- if ( 'date*' == $type )
468
- $class_att .= ' wpcf7-validates-as-required';
469
470
- foreach ( $options as $option ) {
471
- if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
472
- $id_att = $matches[1];
473
474
- } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
475
- $class_att .= ' ' . $matches[1];
476
477
- } elseif ( preg_match( '%^([0-9]*)[/x]([0-9]*)$%', $option, $matches ) ) {
478
- $size_att = (int) $matches[1];
479
- $maxlength_att = (int) $matches[2];
480
}
481
- }
482
483
- if ( $id_att )
484
- $atts .= ' id="' . trim( $id_att ) . '"';
485
486
- if ( $class_att )
487
- $atts .= ' class="' . trim( $class_att ) . '"';
488
489
- if ( $size_att )
490
- $atts .= ' size="' . $size_att . '"';
491
- else
492
- $atts .= ' size="40"';
493
-
494
- if ( $maxlength_att )
495
- $atts .= ' maxlength="' . $maxlength_att . '"';
496
-
497
- if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) {
498
- if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['ok'] )
499
- $value = '';
500
else
501
- $value = $_POST[$name];
502
- } else {
503
- $value = $values[0];
504
- }
505
506
- $html = page_text_filter_callback_cf7datepicker(array('',$name));
507
- $validation_error = '';
508
- if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
509
- $validation_error = $wpcf7_contact_form->validation_error( $name );
510
511
- $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . str_replace('<p>','',$html) . $validation_error . '</span>';
512
513
- return $html;
514
- }
515
-
516
- /**
517
- * wpcf7_validation_filter_cf7datepicker($result, $tag)
518
- *
519
- * This is used to validate the Contact Form 7 'date' field
520
- * @param Array $result, 'valid' key has a boolean value (true if valid)
521
- * and 'reason' key with a message if not valid
522
- * @param Array $tag, contains the type and name of the field that is validated
523
- * @return Array $result
524
- */
525
- function wpcf7_validation_filter_cf7datepicker( $result, $tag ) {
526
- global $wpcf7_contact_form;
527
528
- $type = $tag['type'];
529
- $name = $tag['name'];
530
531
- $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
532
533
- if ( 'date*' == $type ) {
534
- if ( '' == $_POST[$name] ) {
535
- $result['valid'] = false;
536
- $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' );
537
}
538
}
539
540
- return $result;
541
- }
542
543
- /* Add wpcf7 shortcodes [date ] and [date* ] */
544
- if ( ! function_exists( 'wpcf7_add_shortcode' ) ) {
545
- if( is_file( WP_PLUGIN_DIR."/contact-form-7/includes/shortcodes.php" ) ) {
546
- include WP_PLUGIN_DIR."/contact-form-7/includes/shortcodes.php";
547
- wpcf7_add_shortcode( 'date', 'wpcf7_shotcode_handler_cf7datepicker', true );
548
- wpcf7_add_shortcode( 'date*', 'wpcf7_shotcode_handler_cf7datepicker', true );
549
}
550
- }
551
552
- /**
553
- * load_plugin_text_domain_cf7datepicker()
554
- *
555
- * Function for loading the l10n files from /languages/ dir
556
- */
557
- function load_plugin_text_domain_cf7datepicker() {
558
- load_plugin_textdomain( 'contact-form-7-datepicker', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
559
}
560
561
- /* Register the plugin, actions and filters */
562
- register_activation_hook( __FILE__, 'activate_cf7datepicker' );
563
- register_deactivation_hook( __FILE__, 'deactivate_cf7datepicker' );
564
-
565
- add_action('admin_menu', 'register_admin_settings_cf7datepicker');
566
- add_action('wp_head', 'enqueues_cf7datepicker', 1002);
567
- add_action('init', 'load_plugin_text_domain_cf7datepicker');
568
-
569
- add_filter( 'wpcf7_validate_date', 'wpcf7_validation_filter_cf7datepicker', 10, 2 );
570
- add_filter( 'wpcf7_validate_date*', 'wpcf7_validation_filter_cf7datepicker', 10, 2 );
571
572
?>
4
Plugin URI: https://github.com/relu/contact-form-7-datepicker/
5
Description: Implements a new [date] tag in Contact Form 7 that adds a date field to a form. When clicking the field a calendar pops up enabling your site visitors to easily select any date.
6
Author: Aurel Canciu
7
+ Version: 0.3
8
Author URI: https://github.com/relu/
9
*/
10
?>
11
<?php
12
+ /* Copyright 2011 Aurel Canciu <aurelcanciu at gmail.com>
13
14
This program is free software; you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
28
?>
29
<?php
30
31
+ define('CF7_DATE_PICKER_VERSION', '0.3');
32
33
+ class CF7DatePicker {
34
+
35
+ static $option_defaults = array(
36
+ "useMode" => 2,
37
+ "isStripped" => "false",
38
+ "limitToToday" => "false",
39
+ "cellColorScheme" => "beige",
40
+ "dateFormat" => "%d-%m-%Y",
41
+ "weekStartDay" => 1,
42
+ "directionality" => "ltr"
43
+ );
44
+
45
+ function init() {
46
+ register_activation_hook(__FILE__, array(__CLASS__, 'activate'));
47
+ register_deactivation_hook(__FILE__, array(__CLASS__, 'deactivate'));
48
49
+ add_action('init', array(__CLASS__, 'load_plugin_text_domain'));
50
+ add_action('plugins_loaded', array(__CLASS__, 'register_shortcodes'));
51
+ add_action('admin_init', array(__CLASS__, 'tag_generator'));
52
+ add_action('admin_menu', array(__CLASS__, 'register_admin_settings'));
53
+ add_action('wp_head', array(__CLASS__, 'plugin_enqueues'), 1002);
54
+
55
+ add_filter('wpcf7_validate_date', array(__CLASS__, 'wpcf7_validation_filter'), 10, 2);
56
+ add_filter('wpcf7_validate_date*', array(__CLASS__, 'wpcf7_validation_filter'), 10, 2);
57
+ }
58
59
+ /**
60
+ * activate()
61
+ *
62
+ * Action triggered when plugin is activated
63
+ * It inserts some default values as options
64
+ */
65
+ public static function activate() {
66
+ foreach (self::$option_defaults as $option => $value) {
67
+ add_option($option, $value);
68
+ }
69
+ }
70
71
+ /**
72
+ * deactivate()
73
+ *
74
+ * Action triggered when plugin is deactivated
75
+ * It deletes the settings stored in the database
76
+ */
77
+ public static function deactivate() {
78
+ foreach (self::$option_defaults as $option => $value) {
79
+ delete_option($option);
80
+ }
81
+ }
82
83
+ /**
84
+ * update_settings($dataupdate)
85
+ *
86
+ * Updates plugin's settings into the database
87
+ * @param Array $dateupdate, contains the updated settings
88
+ */
89
+ public static function update_settings($dataupdate) {
90
+ foreach ($dataupdate as $option => $value) {
91
+ if ($value != get_option($option))
92
+ update_option($option, $value);
93
+ }
94
+ }
95
96
+ /**
97
+ * register_admin_settings()
98
+ *
99
+ * Registers the Admin panel so that it will show up as a submenu page in Contact Form 7's menu
100
+ */
101
+ public static function register_admin_settings() {
102
+ if (function_exists('add_submenu_page')) {
103
+ add_submenu_page('wpcf7',__('Datepicker Settings', 'contact-form-7-datepicker'),__('Datepicker Settings', 'contact-form-7-datepicker'),
104
+ 'edit_themes',
105
+ basename(__FILE__),
106
+ array(__CLASS__,'admin_settings_html'));
107
+ }
108
+ }
109
+
110
+ /**
111
+ * read_schemes()
112
+ *
113
+ * Gets the names of the schemes available from the img/ directory
114
+ * @return Array $themes, the names of the schemes found
115
+ */
116
+ private function read_schemes() {
117
$path = ABSPATH.'/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/';
118
if ($handle = opendir($path)) {
119
$themes = array() ;
127
return $themes;
128
}
129
130
+ /**
131
+ * get_scheme_images()
132
+ *
133
+ * Gets the images of a scheme and natural sorts them
134
+ * @param String $scheme, the name of the scheme to get images for
135
+ * @return Array $schemeimg, the paths to the scheme images
136
+ */
137
+ private function get_scheme_images($scheme) {
138
+ $path = ABSPATH.'/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/'.$scheme.'/';
139
+ if ($handle = opendir($path)) {
140
+ $schemeimg = array();
141
+ while (false !== ($file = readdir($handle))) {
142
+ if (is_file($path.$file) && preg_match('/\.gif#x2F;i', $file))
143
+ $schemeimg[] = '/wp-content/plugins/'.plugin_basename(dirname(__FILE__)).'/img/'.$scheme.'/'.$file;
144
+ }
145
+ natsort($schemeimg);
146
}
147
+ closedir($handle);
148
+ return $schemeimg;
149
}
150
151
+ /**
152
+ * admin_settings_html()
153
+ *
154
+ * Generates the admin panel HTML
155
+ */
156
+ public static function admin_settings_html() {
157
+ if(isset($_POST['datepickersave'])) {
158
+ foreach(self::$option_defaults as $option => $value)
159
+ $dataupdate[$option] = $_POST[$option];
160
+ self::update_settings($dataupdate);
161
+ }
162
+ $useMode = array(1,2);
163
+ $limitToToday = $isStripped = array(__('true', 'contact-form-7-datepicker'),__('false', 'contact-form-7-datepicker'));
164
+ $cellColorScheme = self::read_schemes();
165
+ $weekStartDay = array(__('Sunday', 'contact-form-7-datepicker'),__('Monday', 'contact-form-7-datepicker'));
166
+ $directionality = array(__('Left to right', 'contact-form-7-datepicker'),__('Right to left', 'contact-form-7-datepicker'));
167
168
+ ?>
169
+ <div class="wrap">
170
<h2>Contact Form 7 Datepicker</h2><?php
171
echo __('<p>This plugin implements a new <strong>[date]</strong> tag in <a href="http://wordpress.org/extend/plugins/contact-form-7/">Contact Form 7</a>
172
that adds a date field to a form. When clicking the field a calendar pops up enabling your site visitors to easily select any date.<br />
181
</th>
182
<td colspan="2"><?php
183
foreach($cellColorScheme as $scheme) {
184
+ if($scheme == get_option('cellColorScheme'))
185
$checked = "checked='checked'";
186
else
187
$checked = ""; ?>
189
<div style="float: left; width: 100px; margin: 30px 30px 0 0; text-align: center;">
190
<div style="display: block; padding: 5px; background: #fff; border: 1px solid #ccc; border-radius: 4px 4px 4px 4px;">
191
<label><?php echo $scheme; ?></label><br /><?php
192
+ foreach(self::get_scheme_images($scheme) as $img) { ?>
193
<img src="<?php echo get_option('siteurl') . $img; ?>" style="margin: 5px;" /><?php
194
} ?><br /><br />
195
<input name="cellColorScheme" type="radio" width="24" height="25" value="<?php echo $scheme; ?>" <?php echo $checked; ?> />
206
<td>
207
<select name="useMode"><?php
208
foreach($useMode as $row) {
209
+ if($row == get_option('useMode'))
210
$selected = "selected";
211
else
212
$selected = "";
233
else
234
$val = "false";
235
236
+ if ($val == get_option('isStripped'))
237
$selected = "selected";
238
else
239
$selected = "";
259
else
260
$val = "false";
261
262
+ if ($val == get_option('limitToToday'))
263
$selected = "selected";
264
else
265
$selected = "";
285
else
286
$val = 1;
287
288
+ if($val == get_option('weekStartDay'))
289
$selected = "selected";
290
else
291
$selected = "";
310
else
311
$val = "rtl";
312
313
+ if($val == get_option('directionality'))
314
$selected = "selected";
315
else
316
$selected = "";
328
<label><?php echo __('Date Format', 'contact-form-7-datepicker'); ?></label>
329
</th>
330
<td>
331
+ <input name="dateFormat" id="dateFormat" type="text" value="<?php echo get_option('dateFormat'); ?>" />
332
</td>
333
<td>
334
<?php echo __('<p>Possible values to use in the date format:<br />
357
</tbody>
358
</table>
359
</form><?php
360
+ }
361
362
+ /**
363
+ * plugin_enqueues()
364
+ *
365
+ * Loads needed scripts and CSS
366
+ */
367
+ public static function plugin_enqueues() {
368
+ if(is_admin())
369
+ return; ?>
370
+ <link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/css/jsDatePick_'.((get_option('directionality') != "") ? get_option('directionality') : "ltr").'.min.css', __FILE__ ); ?>" />
371
+ <script type="text/javascript" src="<?php echo plugins_url( '/js/jsDatePick.jquery.min.1.3.js', __FILE__ ); ?>"></script>
372
+ <script type="text/javascript"><?php echo "
373
+ g_l = [];
374
+ g_l[\"MONTHS\"] = [\"".__('Janaury', 'contact-form-7-datepicker').
375
+ "\",\"".__('February', 'contact-form-7-datepicker').
376
+ "\",\"".__('March', 'contact-form-7-datepicker').
377
+ "\",\"".__('April', 'contact-form-7-datepicker').
378
+ "\",\"".__('May', 'contact-form-7-datepicker').
379
+ "\",\"".__('June', 'contact-form-7-datepicker').
380
+ "\",\"".__('July', 'contact-form-7-datepicker').
381
+ "\",\"".__('August', 'contact-form-7-datepicker').
382
+ "\",\"".__('September', 'contact-form-7-datepicker').
383
+ "\",\"".__('October', 'contact-form-7-datepicker').
384
+ "\",\"".__('November', 'contact-form-7-datepicker').
385
+ "\",\"".__('December', 'contact-form-7-datepicker')."\"];
386
+ g_l[\"DAYS_3\"] = [\"".__('Sun', 'contact-form-7-datepicker').
387
+ "\",\"".__('Mon', 'contact-form-7-datepicker').
388
+ "\",\"".__('Tue', 'contact-form-7-datepicker').
389
+ "\",\"".__('Wed', 'contact-form-7-datepicker').
390
+ "\",\"".__('Thu', 'contact-form-7-datepicker').
391
+ "\",\"".__('Fri', 'contact-form-7-datepicker').
392
+ "\",\"".__('Sat', 'contact-form-7-datepicker')."\"];
393
+ g_l[\"MONTH_FWD\"] = \"".__('Move a month forward', 'contact-form-7-datepicker')."\";
394
+ g_l[\"MONTH_BCK\"] = \"".__('Move a month backward', 'contact-form-7-datepicker')."\";
395
+ g_l[\"YEAR_FWD\"] = \"".__('Move a year forward', 'contact-form-7-datepicker')."\";
396
+ g_l[\"YEAR_BCK\"] = \"".__('Move a year backward', 'contact-form-7-datepicker')."\";
397
+ g_l[\"CLOSE\"] = \"".__('Close the calendar', 'contact-form-7-datepicker')."\";
398
+ g_l[\"ERROR_2\"] = g_l[\"ERROR_1\"] = \"".__('Date object invalid!', 'contact-form-7-datepicker')."\";
399
+ g_l[\"ERROR_4\"] = g_l[\"ERROR_3\"] = \"".__('Target invalid!', 'contact-form-7-datepicker')."\";"; ?>
400
</script><?php
401
+ }
402
403
+ /**
404
+ * page_text_filter_callback($matches)
405
+ *
406
+ * If a match is found in the content of a form, this returns the HTML for the matched date input field
407
+ * @param Array $matches, the name of the input date field that we generate code for
408
+ * @return String $string, the HTML for our match
409
+ */
410
+ private function page_text_filter_callback($matches) {
411
+ $string = "<input type=\"text\" name=\"".$matches[1]."\" id=\"".$matches[1]."\" />
412
+ <script type=\"text/javascript\">
413
+ jQuery(document).ready(function() {
414
+ DatePicker_".$matches[1]." = new JsDatePick({
415
+ useMode:".get_option('useMode').",
416
+ isStripped:".get_option('isStripped').",
417
+ target:\"".$matches[1]."\",
418
+ limitToToday:".get_option('limitToToday').",
419
+ cellColorScheme:\"".get_option('cellColorScheme')."\",
420
+ dateFormat:\"".get_option('dateFormat')."\",
421
+ imgPath:\"".plugins_url( '/img/'.get_option('cellColorScheme').'/', __FILE__ )."\",
422
+ weekStartDay:".get_option('weekStartDay').",
423
+ directionality:\"".get_option('directionality')."\"
424
+ });
425
});
426
+ </script>";
427
+ return $string;
428
+ }
429
430
+ /**
431
+ * wpcf7_shotcode_handler($tag)
432
+ *
433
+ * Handler for wpcf7 shortcodes [date ] and [date* ]
434
+ * @param Array $tag, this is the tag that will be handled (can be 'date' or 'date*')
435
+ * @return String $html, the HTML that will be appended to the form
436
+ */
437
+ public static function wpcf7_shotcode_handler($tag) {
438
+ global $wpcf7_contact_form;
439
+
440
+ if ( ! is_array( $tag ) )
441
+ return '';
442
+
443
+ $type = $tag['type'];
444
+ $name = $tag['name'];
445
+ $options = (array) $tag['options'];
446
+ $values = (array) $tag['values'];
447
448
+ if ( empty( $name ) )
449
+ return '';
450
451
+ $atts = '';
452
+ $id_att = '';
453
+ $class_att = '';
454
+ $size_att = '';
455
+ $maxlength_att = '';
456
457
+ if ( 'date*' == $type )
458
+ $class_att .= ' wpcf7-validates-as-required';
459
460
+ foreach ( $options as $option ) {
461
+ if ( preg_match( '%^id:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
462
+ $id_att = $matches[1];
463
464
+ } elseif ( preg_match( '%^class:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
465
+ $class_att .= ' ' . $matches[1];
466
467
+ } elseif ( preg_match( '%^([0-9]*)[/x]([0-9]*)$%', $option, $matches ) ) {
468
+ $size_att = (int) $matches[1];
469
+ $maxlength_att = (int) $matches[2];
470
+ }
471
}
472
473
+ if ( $id_att )
474
+ $atts .= ' id="' . trim( $id_att ) . '"';
475
476
+ if ( $class_att )
477
+ $atts .= ' class="' . trim( $class_att ) . '"';
478
479
+ if ( $size_att )
480
+ $atts .= ' size="' . $size_att . '"';
481
else
482
+ $atts .= ' size="40"';
483
+
484
+ if ( $maxlength_att )
485
+ $atts .= ' maxlength="' . $maxlength_att . '"';
486
+
487
+ if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) && $wpcf7_contact_form->is_posted() ) {
488
+ if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['ok'] )
489
+ $value = '';
490
+ else
491
+ $value = $_POST[$name];
492
+ } else {
493
+ $value = $values[0];
494
+ }
495
496
+ $html = self::page_text_filter_callback(array('',$name));
497
+ $validation_error = '';
498
+ if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
499
+ $validation_error = $wpcf7_contact_form->validation_error( $name );
500
501
+ $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . str_replace('<p>','',$html) . $validation_error . '</span>';
502
503
+ return $html;
504
+ }
505
506
+ /**
507
+ * wpcf7_validation_filter($result, $tag)
508
+ *
509
+ * This is used to validate the Contact Form 7 'date' field
510
+ * @param Array $result, 'valid' key has a boolean value (true if valid)
511
+ * and 'reason' key with a message if not valid
512
+ * @param Array $tag, contains the type and name of the field that is validated
513
+ * @return Array $result
514
+ */
515
+ public static function wpcf7_validation_filter( $result, $tag ) {
516
+ global $wpcf7_contact_form;
517
+
518
+ $type = $tag['type'];
519
+ $name = $tag['name'];
520
+
521
+ $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
522
+
523
+ if ( 'date*' == $type ) {
524
+ if ( '' == $_POST[$name] ) {
525
+ $result['valid'] = false;
526
+ $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' );
527
+ }
528
+ }
529
530
+ return $result;
531
+ }
532
533
+ /**
534
+ * load_plugin_text_domain()
535
+ *
536
+ * Function for loading the l10n files from /languages/ dir
537
+ */
538
+ public static function load_plugin_text_domain() {
539
+ load_plugin_textdomain( 'contact-form-7-datepicker', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
540
+ }
541
+
542
+ /**
543
+ * register_shortcodes()
544
+ *
545
+ * Function for registering our shortcodes with CF7
546
+ */
547
+ public static function register_shortcodes() {
548
+ if (function_exists('wpcf7_add_shortcode')) {
549
+ wpcf7_add_shortcode('date', array(__CLASS__, 'wpcf7_shotcode_handler'), true);
550
+ wpcf7_add_shortcode('date*', array(__CLASS__, 'wpcf7_shotcode_handler'), true);
551
}
552
}
553
+
554
+ /**
555
+ * tag_generator()
556
+ *
557
+ * Registers the tag generator for CF7
558
+ */
559
+ public static function tag_generator() {
560
+ if (function_exists('wpcf7_add_tag_generator')) {
561
+ wpcf7_add_tag_generator('date', __('Date field', 'contact-form-7-datepicker'),
562
+ 'wpcf7-tg-pane-date', array(__CLASS__, 'wpcf7_tg_pane_datepicker_'));
563
+ }
564
+ }
565
+
566
+ /**
567
+ * wpcf7_tg_pane_datepicker_(&$contact_form)
568
+ *
569
+ * Caller function for the tag generator
570
+ * @param reference &$contact_form
571
+ */
572
+ public static function wpcf7_tg_pane_datepicker_(&$contact_form) {
573
+ self::wpcf7_tg_pane_datepicker( 'date' );
574
+ }
575
+
576
+ /**
577
+ * wpcf7_tg_pane_datepicker($type = 'date')
578
+ *
579
+ * Callback function for the tag generator (called by wpcf7_tg_pane_datepicker_)
580
+ * @param $type = 'date'
581
+ */
582
+ private function wpcf7_tg_pane_datepicker($type = 'date') { ?>
583
+ <div id="wpcf7-tg-pane-<?php echo $type; ?>" class="hidden">
584
+ <form action="">
585
+ <table>
586
+ <tr>
587
+ <td>
588
+ <input type="checkbox" name="required" />&nbsp;<?php echo esc_html( __( 'Required field?', 'wpcf7' ) ); ?>
589
+ </td>
590
+ </tr>
591
+ <tr>
592
+ <td>
593
+ <?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?><br /><input type="text" name="name" class="tg-name oneline" />
594
+ </td>
595
+ <td></td>
596
+ </tr>
597
+ </table>
598
599
+ <table>
600
+ <tr>
601
+ <td>
602
+ <code>id</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
603
+ <input type="text" name="id" class="idvalue oneline option" />
604
+ </td>
605
+
606
+ <td>
607
+ <code>class</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
608
+ <input type="text" name="class" class="classvalue oneline option" />
609
+ </td>
610
+ </tr>
611
+
612
+ <tr>
613
+ <td>
614
+ <code>size</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
615
+ <input type="text" name="size" class="numeric oneline option" />
616
+ </td>
617
+
618
+ <td>
619
+ <code>maxlength</code> (<?php echo esc_html( __( 'optional', 'wpcf7' ) ); ?>)<br />
620
+ <input type="text" name="maxlength" class="numeric oneline option" />
621
+ </td>
622
+ </tr>
623
+ </table>
624
+
625
+ <div class="tg-tag">
626
+ <?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="<?php echo $type; ?>" class="tag" readonly="readonly" onfocus="this.select()" />
627
+ </div>
628
629
+ <div class="tg-mail-tag">
630
+ <?php echo esc_html( __( "And, put this code into the Mail fields below.", 'wpcf7' ) ); ?><br /><span class="arrow">&#11015;</span>&nbsp;<input type="text" class="mail-tag" readonly="readonly" onfocus="this.select()" />
631
+ </div>
632
+ </form>
633
+ </div><?php
634
}
635
636
}
637
638
+ CF7DatePicker::init();
639
640
?>
img/oceanblue/oceanblue_dayDown.gif ADDED
Binary file
img/oceanblue/oceanblue_dayNormal.gif ADDED
Binary file
img/oceanblue/oceanblue_dayOver.gif ADDED
Binary file
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
Tags: wordpress, datepicker, calendar, contact form 7, forms
5
Requires at least: WordPress 2.9
6
Tested up to: WordPress 3.1.2
7
- Stable tag: 0.2.1
8
9
Datepicker for Contact Form 7 Wordpress Plugin based on jsDatePick script.
10
@@ -35,6 +35,9 @@ You can contact me anywhere and I'll add them to the project :)
35
36
== Changelog ==
37
38
= 0.2.1 =
39
* Fixed input field not being populated on date selection
40
4
Tags: wordpress, datepicker, calendar, contact form 7, forms
5
Requires at least: WordPress 2.9
6
Tested up to: WordPress 3.1.2
7
+ Stable tag: 0.3
8
9
Datepicker for Contact Form 7 Wordpress Plugin based on jsDatePick script.
10
35
36
== Changelog ==
37
38
+ = 0.3 =
39
+ * Added tag generator
40
+
41
= 0.2.1 =
42
* Fixed input field not being populated on date selection
43