Skip to content

Commit 063b241

Browse files
committed
init
0 parents  commit 063b241

16 files changed

+733
-0
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.tp-time{
2+
margin-top: 10px;
3+
margin-bottom: 10px;
4+
font-size:12px;
5+
}
6+
Loading
Loading
Loading
Loading
Loading
Loading

timer_plugin/admin/css/jquery-ui.css

+377
Large diffs are not rendered by default.

timer_plugin/admin/js/admin-script.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
jQuery(document).ready(function($){
2+
$('.tp-time-edit').live('click',function() {
3+
4+
var $form = $(this).closest('form');
5+
6+
$form.find('.tp-date').datepicker({
7+
format:'m/d/Y',
8+
hourGrid: 4,
9+
minuteGrid: 10,
10+
position: 'right',
11+
onBeforeShow: function(){
12+
$(this).DatePickerSetDate($(this).val(), true);
13+
}
14+
});
15+
$form.find('.tp-date').addClass('editable');
16+
$form.find( ".tp-hour").slider({
17+
value:0,
18+
min: 0,
19+
max: 23,
20+
step: 1,
21+
slide: function( event, ui ) {
22+
$form.find(".tp-hour-val" ).val(ui.value);
23+
}
24+
});
25+
$form.find( ".tp-minute" ).slider({
26+
value:0,
27+
min: 0,
28+
max: 59,
29+
step: 1,
30+
slide: function( event, ui ) {
31+
$form.find(".tp-minute-val" ).val(ui.value);
32+
}
33+
});
34+
});
35+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<label>Title</label>
2+
<input type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" class="tp-title" value="<?php echo esc_attr($instance['title']); ?>" /><br/><br/>
3+
<a class="tp-time-edit" href="javascript:void(0);">[ Edit ]</a><br/><br/>
4+
<label>Select a date:</label><br/>
5+
<input type="text" name="<?php echo $this->get_field_name('date'); ?>" id="<?php echo $this->get_field_id('date'); ?>" class="tp-date " readonly="true" value="<?php echo esc_attr($instance['date']); ?>" />
6+
<p ><div class="tp-time"><label>Hours</label>
7+
<input name="<?php echo $this->get_field_name('hour'); ?>" id="<?php echo $this->get_field_id('hour'); ?>" class="tp-hour-val" value="<?php echo esc_attr($instance['hour']); ?>" readonly="true" /><div id="<?php echo $this->get_field_id('hour'); ?>" class="tp-hour"></div>
8+
</p>
9+
<p ><label>Minutes</label>
10+
<input name="<?php echo $this->get_field_name('minute'); ?>" id="<?php echo $this->get_field_id('minute'); ?>" class="tp-minute-val" readonly="true" value="<?php echo esc_attr($instance['minute']); ?>"><div id="<?php echo $this->get_field_id('minute'); ?>" class="tp-minute"></div>
11+
</p>
12+
<input type="hidden" name="tp-hidd" value="true" />
13+
</div>
14+
<?php
15+
$rand = rand( 0, 999 );
16+
$ed_id = $this->get_field_id( 'wp_editor_' . $rand );
17+
$ed_name = $this->get_field_name( 'wp_editor_' . $rand );
18+
$editor_id = $ed_id;
19+
$settings = array(
20+
'media_buttons' => false,
21+
'textarea_rows' => 3,
22+
'textarea_name' => $ed_name
23+
);
24+
wp_editor($descr, $editor_id, $settings);
25+
printf(
26+
'<input type="hidden" id="%s" name="%s" value="%d" />',
27+
$this->get_field_id( 'the_random_number' ),
28+
$this->get_field_name( 'the_random_number' ),
29+
$rand
30+
); ?>

timer_plugin/css/style.css

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.clockTitle{
2+
text-align: center;
3+
font-size: 20px;
4+
font-weight: bold;
5+
color: #d19fae;
6+
margin-top: 5px;
7+
}
8+
#clockdiv{
9+
font-family: sans-serif;
10+
text-align: center;
11+
display: inline-block;
12+
margin: auto;
13+
display: block;
14+
font-size: 20px;
15+
}
16+
17+
#clockdiv > div{
18+
padding: 8px;
19+
display: inline-block;
20+
}
21+
22+
#clockdiv div > span{
23+
padding: 5px;
24+
font-size: 30px;
25+
display: inline-block;
26+
color:#494949;
27+
font-weight: bold;
28+
}
29+
30+
.smalltext{
31+
padding-top: 3px;
32+
font-size: 16px;
33+
color: #d19fae;
34+
font-weight: bold;
35+
}
36+
37+
.tp-title {
38+
background-color: #d19fae;
39+
}

timer_plugin/includes/functions.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
function TP_widgets_init() {
3+
register_widget("Countdown_Timer");
4+
}
5+
6+
function TP_admin_register_scripts() {
7+
wp_register_script('tp-admin-script', plugins_url('/admin/js/admin-script.js', WP_Timer_PLUGIN));
8+
wp_enqueue_script('jquery-ui-core');
9+
wp_enqueue_script('jquery-ui-datepicker');
10+
wp_enqueue_script('jquery-ui-slider');
11+
wp_enqueue_script('tp-admin-script');
12+
}
13+
14+
function TP_admin_register_styles() {
15+
wp_register_style('jquery-ui-theme', plugins_url('/admin/css/jquery-ui.css', WP_Timer_PLUGIN));
16+
wp_register_style('tp-admin-style', plugins_url('/admin/css/admin-style.css', WP_Timer_PLUGIN));
17+
wp_enqueue_style('jquery-ui-theme');
18+
wp_enqueue_style('tp-admin-style');
19+
}
20+
21+
function TP_widget_script(){
22+
global $pagenow;
23+
if ( 'widgets.php' === $pagenow )
24+
wp_enqueue_script( 'widget-script', plugins_url( '/js/widget_script.js', WP_Timer_PLUGIN), array( 'jquery' ), false, true );
25+
}
26+
27+
function TP_register_scripts() {
28+
wp_register_script('tp-script', plugins_url('/js/script.js', WP_Timer_PLUGIN));
29+
wp_enqueue_script('jquery');
30+
wp_enqueue_script('tp-script');
31+
}
32+
33+
function TP_register_styles() {
34+
wp_register_style('tp-style', plugins_url('/css/style.css', WP_Timer_PLUGIN));
35+
wp_enqueue_style('tp-style');
36+
}
37+
38+
add_action('widgets_init', 'TP_widgets_init');
39+
add_action('admin_print_scripts', 'TP_admin_register_scripts');
40+
add_action('admin_print_styles', 'TP_admin_register_styles');
41+
add_action('wp_print_scripts', 'TP_register_scripts');
42+
add_action('wp_print_styles', 'TP_register_styles');
43+
add_action( 'admin_init', 'TP_widget_script' );
44+
?>

timer_plugin/includes/shortcodes.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
function TP_shortcode( $atts )
3+
{
4+
$filedir = get_stylesheet_directory() . '/' . 'countdown/layout.php';
5+
extract( shortcode_atts( array(
6+
'date' => 'NaN',
7+
'time' => 'NaN',
8+
), $atts ) );
9+
return file_exists(WP_Timer_THEME_TEMPLATE_DIR) ? include(WP_Timer_THEME_TEMPLATE_DIR) : '<div class="timer-main">
10+
<input type="hidden" class="tp-widget-date" value="'.$date.'" />
11+
<input type="hidden" class="tp-widget-time" value="'.$time.':0" />
12+
<p class="clockTitle">Time remains:</p>
13+
<div id="clockdiv">
14+
<div>
15+
<span id="years"></span>
16+
<div class="smalltext">Years</div>
17+
</div>
18+
<div>
19+
<span id="days"></span>
20+
<div class="smalltext">Days</div>
21+
</div>
22+
<div>
23+
<span id="hours"></span>
24+
<div class="smalltext">Hours</div>
25+
</div>
26+
<div>
27+
<span id ="minutes"></span>
28+
<div class="smalltext">Minutes</div>
29+
</div>
30+
<div>
31+
<span id="seconds"></span>
32+
<div class="smalltext">Seconds</div>
33+
</div>
34+
</div>
35+
</div>';
36+
}
37+
38+
add_shortcode('tp_shortcode', 'TP_shortcode' );
39+
?>

timer_plugin/js/script.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function calc_data(timer,tp_date,tp_time) {
2+
3+
var tp_years = 0;
4+
var tp_days=0;
5+
var tp_hours = 0;
6+
var tp_minutes = 0;
7+
var tp_seconds = 0;
8+
9+
var tempdate = tp_date.split("/");
10+
var temptime = tp_time.split(":");
11+
12+
var seconds=1000;
13+
var minutes=seconds*60;
14+
var hours=minutes*60;
15+
var days=hours*24;
16+
var years=days*365;
17+
18+
var db_time = new Date(tempdate[0], tempdate[1]-1, tempdate[2], temptime[0], temptime[1], 00);
19+
var now_time = new Date();
20+
db_time = db_time.getTime();
21+
now_time = now_time.getTime();
22+
var tp_result = db_time-now_time;
23+
if(tp_result < 0)
24+
tp_years=tp_days=tp_hours=tp_minutes=tp_seconds=0;
25+
else {
26+
tp_years = Math.floor(tp_result/years);
27+
tp_days = Math.floor(tp_result/days)-(tp_years*365);
28+
tp_hours = Math.floor(tp_result/hours)-(tp_days*24)-(tp_years*365*24);
29+
tp_minutes = Math.floor(tp_result/minutes)-(tp_hours*60)-(tp_days*24*60)-(tp_years*365*24*60);
30+
tp_seconds = Math.floor(tp_result/seconds)-(tp_minutes*60)-(tp_hours*60*60)-(tp_days*60*24*60)-(tp_years*365*24*60*60);
31+
singlebox=false;
32+
if(tp_years>99) {
33+
tp_years=99;
34+
}
35+
if(tp_days>99) {
36+
37+
singlebox=true;
38+
}
39+
if(tp_years<0)tp_years=0;
40+
if(tp_days<0)tp_days=0;
41+
if(tp_hours<0)tp_hours=0;
42+
if(tp_minutes>60)tp_minutes=60;
43+
if(tp_minutes<0)tp_minutes=0;
44+
if(tp_seconds<0)tp_seconds=0;
45+
}
46+
47+
timer.find('div#clockdiv span[id^="years"]').html(tp_years);
48+
timer.find('div#clockdiv span[id^="days"]').html(tp_days);
49+
timer.find('div#clockdiv span[id^="hours"]').html(tp_hours);
50+
timer.find('div#clockdiv span[id^="minutes"]').html(tp_minutes);
51+
timer.find('div#clockdiv span[id^="seconds"]').html(tp_seconds);
52+
}
53+
54+
jQuery(document).ready(function($) {
55+
$('.timer-main').each(function() {
56+
var tp_date=$(this).find('input.tp-widget-date').val();
57+
var tp_time=$(this).find('input.tp-widget-time').val();
58+
// console.log(tp_date);
59+
var timer = $(this);
60+
calc_data(timer, tp_date, tp_time);
61+
setInterval(function() {
62+
calc_data(timer, tp_date, tp_time);
63+
}, 1000)
64+
});
65+
66+
});

timer_plugin/js/widget_script.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
jQuery(document).ready(
2+
function($) {
3+
$( '.widget-control-save' ).click(
4+
function() {
5+
var saveID = $( this ).attr( 'id' );
6+
var ID = saveID.replace( /-savewidget/, '' );
7+
var numberID = ID + '-the_random_number';
8+
var randNum = $( '#'+numberID ).val();
9+
var textTab = ID + '-wp_editor_' + randNum + '-html';
10+
$( '#'+textTab ).trigger( 'click' );
11+
}
12+
);
13+
}
14+
);

timer_plugin/timer_plugin.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/*
3+
Plugin Name: Task timer
4+
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
5+
Description: Test task
6+
Version: 0.2
7+
Author: Okhmat Aleksey
8+
Author URI: http://URI_Of_The_Plugin_Author
9+
License: none
10+
11+
*/
12+
13+
define( 'WP_Timer_PLUGIN', __FILE__ );
14+
define( 'WP_Timer_PLUGIN_DIR', untrailingslashit( dirname( WP_Timer_PLUGIN ) ) );
15+
define( 'WP_Timer_THEME_TEMPLATE_DIR', (get_stylesheet_directory() . '/' . 'countdown/layout.php') );
16+
17+
class Countdown_Timer extends WP_Widget {
18+
19+
public function Countdown_Timer()
20+
{
21+
$widget_ops = array('classname' => 'Countdown_Timer', 'description' => 'Timer for the test task' );
22+
$this->WP_Widget('Countdown_Timer', 'Timer', $widget_ops);
23+
}
24+
25+
public function form($instance) {
26+
if( $instance) {
27+
$title = esc_attr($instance['title']);
28+
$descr=$instance['descr'];
29+
$date = esc_attr($instance['date']);
30+
$hour = esc_attr($instance['hour']);
31+
$minute = esc_attr($instance['minute']);
32+
} else {
33+
$title = '';
34+
$date = '';
35+
$hour = '';
36+
$descr='';
37+
$minute = '';
38+
}
39+
require_once WP_Timer_PLUGIN_DIR . '/admin/templates/admin-template.php';
40+
}
41+
42+
public function update($new_instance, $old_instance) {
43+
$instance = $old_instance;
44+
$rand = (int)$new_instance['the_random_number'];
45+
$instance['descr'] =$new_instance[ 'wp_editor_' . $rand ];
46+
$instance['title'] = strip_tags($new_instance['title']);
47+
$instance['date'] = strip_tags($new_instance['date']);
48+
$instance['hour'] = strip_tags($new_instance['hour']);
49+
$instance['minute'] = strip_tags($new_instance['minute']);
50+
return $instance;
51+
}
52+
53+
public function widget($args, $instance) {
54+
55+
$temp_date = explode("/", $instance['date']);
56+
$instance['date'] = $temp_date[2] . "/" . $temp_date[0] . "/" . $temp_date[1];
57+
extract($args);
58+
$title = apply_filters('widget_title', $instance['title']);
59+
echo $args['before_widget'];
60+
if (file_exists( WP_Timer_THEME_TEMPLATE_DIR)) {
61+
include WP_Timer_THEME_TEMPLATE_DIR;
62+
} else {
63+
if (!empty($title)){
64+
?>
65+
<div class="tp-title">
66+
<?php
67+
echo $before_title . $title . $after_title;
68+
}
69+
?>
70+
</div>
71+
<p class="clockTitle">Description:</p>
72+
<p><?php echo $instance['descr']; ?></p>
73+
<?php
74+
echo do_shortcode('[tp_shortcode date="' . $instance['date'] . '" time="'. $instance['hour'] . ':' . $instance['minute'] . '"]');
75+
}
76+
echo $after_widget;
77+
}
78+
}
79+
80+
require_once WP_Timer_PLUGIN_DIR . '/includes/shortcodes.php';
81+
require_once WP_Timer_PLUGIN_DIR . '/includes/functions.php';
82+
?>
83+

0 commit comments

Comments
 (0)