Changeset 2119169
- Timestamp:
- 07/08/2019 05:59:52 AM (7 years ago)
- Location:
- lich-van-nien
- Files:
-
- 14 edited
- 8 copied
-
tags/1.1 (copied) (copied from lich-van-nien/trunk)
-
tags/1.1/LVN_Lunar.php (copied) (copied from lich-van-nien/trunk/LVN_Lunar.php) (6 diffs)
-
tags/1.1/LVN_Lunar_Date.php (copied) (copied from lich-van-nien/trunk/LVN_Lunar_Date.php) (1 diff)
-
tags/1.1/assets (copied) (copied from lich-van-nien/trunk/assets)
-
tags/1.1/assets/css/custom.css (modified) (4 diffs)
-
tags/1.1/assets/images/left-arrow.png (modified) (previous)
-
tags/1.1/assets/images/right-arrow.png (modified) (previous)
-
tags/1.1/assets/js/custom.js (modified) (5 diffs)
-
tags/1.1/calendar-lunar.php (copied) (copied from lich-van-nien/trunk/calendar-lunar.php) (3 diffs)
-
tags/1.1/readme.txt (copied) (copied from lich-van-nien/trunk/readme.txt) (3 diffs)
-
tags/1.1/shortcode.php (copied) (copied from lich-van-nien/trunk/shortcode.php) (3 diffs)
-
tags/1.1/widget.php (copied) (copied from lich-van-nien/trunk/widget.php) (5 diffs)
-
trunk/LVN_Lunar.php (modified) (6 diffs)
-
trunk/LVN_Lunar_Date.php (modified) (1 diff)
-
trunk/assets/css/custom.css (modified) (4 diffs)
-
trunk/assets/images/left-arrow.png (modified) (previous)
-
trunk/assets/images/right-arrow.png (modified) (previous)
-
trunk/assets/js/custom.js (modified) (5 diffs)
-
trunk/calendar-lunar.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/shortcode.php (modified) (3 diffs)
-
trunk/widget.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lich-van-nien/tags/1.1/LVN_Lunar.php
r2116699 r2119169 456 456 'Mão', 457 457 'Thìn', 458 'T ị',458 'Tỵ', 459 459 'Ngọ', 460 460 'Mùi', … … 727 727 public function get_can_chi( $lunar_date ) { 728 728 $day_name = $this->can[ ( $lunar_date->jd + 9 ) % 10 ] . ' ' . $this->chi[ ( $lunar_date->jd + 1 ) % 12 ]; 729 $month_name = $this->can[ $lunar_date->year * 12 + $lunar_date->month + 3] . ' ' . $this->chi[ ( $lunar_date->month + 1 ) % 12 ];729 $month_name = $this->can[ ($lunar_date->year * 12 + $lunar_date->month + 3)%10 ] . ' ' . $this->chi[ ( $lunar_date->month + 1 ) % 12 ]; 730 730 if ( $lunar_date->leap == 1 ) { 731 $month_name .= " (nhu \u1EADn)";731 $month_name .= " (nhuận)"; 732 732 } 733 733 $year_name = $this->get_year_can_chi( $lunar_date->year ); … … 741 741 } 742 742 $canchi = $this->get_can_chi( $lunar_date ); 743 $day_name = "Ngày " . $canchi[0] . " , tháng" . $canchi[1] . ", năm " . $canchi[2];743 $day_name = "Ngày " . $canchi[0] . "<br> Tháng " . $canchi[1] . "<br> Năm " . $canchi[2]; 744 744 745 745 return $day_name; … … 760 760 $day .= "Ngày " . $lunar->day . " Tháng " . $lunar->month; 761 761 if ( $lunar->leap == 1 ) { 762 $day .= " nhu \u1EADn";762 $day .= " nhuận"; 763 763 } 764 764 … … 795 795 $result .= ', '; 796 796 } 797 if ( $count ++== 3 ) {797 if ( $count == 3 ) { 798 798 $result .= ''; 799 799 } 800 800 } 801 802 return $result; 803 } 801 } 802 return $result; 804 803 } 805 804 … … 962 961 } 963 962 963 public function print_day( $dd, $mm, $yy ) { 964 965 $result = ""; 966 set_query_var( 'lunar', array( 967 'lunar' => $this, 968 'day' => $dd, 969 'month' => $mm, 970 'year' => $yy 971 ) ); 972 ob_start(); 973 require LVN_DIR . '/parts/lunar-day.php'; 974 $result .= ob_get_contents(); 975 ob_end_clean(); 976 977 return $result; 978 } 979 964 980 } 965 981 } -
lich-van-nien/tags/1.1/LVN_Lunar_Date.php
r2116699 r2119169 1 1 <?php 2 if (!class_exists('LVN_Lunar_Date')){2 if ( ! class_exists( 'LVN_Lunar_Date' ) ) { 3 3 class LVN_Lunar_Date { 4 4 public $day; -
lich-van-nien/tags/1.1/assets/css/custom.css
r2116699 r2119169 1 .lunar-year table {1 .lunar-year table { 2 2 table-layout: unset; 3 3 } 4 4 5 .year-name { 5 6 text-align: center; … … 12 13 13 14 table.month { 14 width: 100%;15 width: 100%; 15 16 font-size: 13px; 16 17 padding: 1px; … … 18 19 table-layout: unset; 19 20 } 21 20 22 .month .navi-left, 21 23 .month .month-name, 22 .month .navi-right {24 .month .navi-right { 23 25 text-align: -webkit-center; 24 26 vertical-align: middle; 25 27 } 28 26 29 .month, 27 30 table.month tbody tr th, 28 table.month tbody tr td{ 29 padding:5px; 30 border:1px solid #dedede; 31 font-weight: bold; 32 } 33 .month td{ 31 table.month tbody tr td { 32 padding: 5px; 33 border: 1px solid #dedede; 34 font-weight: bold; 35 } 36 37 .month td { 34 38 cursor: pointer; 35 39 } 36 .month td:hover{ 37 background:#dedede; 38 } 39 .month td .date-lunar{ 40 41 .month td:hover { 42 background: #dedede; 43 } 44 45 .month td .date-lunar { 40 46 font-weight: normal; 41 padding-top: 3px;47 padding-top: 3px; 42 48 } 43 49 … … 122 128 color: red 123 129 } 124 .lunar-search{ 125 display:flex; 130 131 .lunar-search { 132 display: flex; 126 133 justify-items: center; 127 margin:10px 0px; 128 } 129 .lunar-search .lunar-search-item{ 134 margin: 10px 0px; 135 } 136 137 .lunar-search .lunar-search-item { 130 138 height: 35px; 131 139 } 132 .lunar-search select.lunar-search-item{ 133 width:20%; 134 -webkit-appearance:none; 140 141 .lunar-search select.lunar-search-item { 142 width: 20%; 143 -webkit-appearance: none; 135 144 -webkit-border-radius: 0px; 136 145 -moz-border-radius: 0px; 137 146 border-radius: 0px; 138 padding:0px 8px; 139 height:37px; 140 141 } 142 .lunar-search input{ 143 width:45%; 144 padding:0px 10px; 147 padding: 0px 8px; 148 height: 37px; 149 150 } 151 152 .lunar-search input { 153 width: 45%; 154 padding: 0px 10px; 145 155 margin: 0px 10px; 146 156 } 147 .lunar-search button.lunar-search-item{ 148 width:35%; 157 158 .lunar-search button.lunar-search-item { 159 width: 35%; 149 160 font-weight: bold; 150 161 cursor: pointer; 151 162 height: 37px; 152 163 } 153 td a.lunar-next{ 164 165 td a.lunar-next { 154 166 border-bottom: 0px; 155 167 display: block; 156 width: 20px;157 height: 20px;168 width: 20px; 169 height: 20px; 158 170 background: url('../images/right-arrow.png'); 159 171 -webkit-background-size: cover; 160 172 background-size: cover; 161 173 } 162 td a.lunar-prev{ 174 175 td a.lunar-prev { 163 176 border-bottom: 0px; 164 177 display: block; 165 width: 20px;166 height: 20px;178 width: 20px; 179 height: 20px; 167 180 background: url('../images/left-arrow.png'); 168 181 -webkit-background-size: cover; 169 182 background-size: cover; 170 183 } 171 .lunar-year>table>tbody>tr>td{ 172 padding:5px; 173 } 184 185 .lunar-year > table > tbody > tr > td { 186 padding: 5px; 187 } 188 189 .ui-datepicker { 190 background-color: #fff; 191 width: 17em; 192 padding: .2em .2em 0; 193 border: 1px solid #dedede; 194 -webkit-border-radius: 3px; 195 -moz-border-radius: 3px; 196 border-radius: 3px; 197 display: none; 198 } 199 200 .ui-datepicker .ui-datepicker-header { 201 position: relative; 202 padding: .2em 0; 203 } 204 205 .ui-datepicker .ui-datepicker-prev, 206 .ui-datepicker .ui-datepicker-next { 207 cursor: pointer; 208 position: absolute; 209 top: 8px; 210 width: 1em; 211 height: 1em; 212 } 213 214 .ui-datepicker .ui-datepicker-prev { 215 background: url('../images/left-arrow.png'); 216 -webkit-background-size: cover; 217 background-size: cover; 218 left: 2px; 219 } 220 221 .ui-datepicker .ui-datepicker-next { 222 background: url('../images/right-arrow.png'); 223 -webkit-background-size: cover; 224 background-size: cover; 225 right: 2px; 226 } 227 228 .ui-datepicker .ui-datepicker-prev span, 229 .ui-datepicker .ui-datepicker-next span { 230 display: block; 231 position: absolute; 232 left: 50%; 233 margin-left: -8px; 234 top: 50%; 235 margin-top: -8px; 236 } 237 238 .ui-datepicker .ui-datepicker-title { 239 margin: 0 2.3em; 240 line-height: 1.8em; 241 text-align: center; 242 } 243 244 .ui-datepicker .ui-datepicker-title select { 245 font-size: 1em; 246 margin: 1px 0; 247 } 248 249 .ui-datepicker select.ui-datepicker-month, 250 .ui-datepicker select.ui-datepicker-year { 251 width: 49%; 252 } 253 254 .ui-datepicker table { 255 width: 100%; 256 font-size: .9em; 257 border-collapse: collapse; 258 margin: 0 0 .4em; 259 } 260 261 .ui-datepicker th { 262 background: #dedede; 263 padding: .5em .3em; 264 text-align: center; 265 font-weight: bold; 266 border: 0; 267 } 268 269 .ui-datepicker td { 270 border: 1px solid #dfdfdf; 271 padding: 1px; 272 } 273 274 .ui-datepicker td:hover { 275 background: #13a923; 276 } 277 278 .ui-datepicker td:hover a { 279 color: #fff; 280 } 281 282 .ui-datepicker-current-day { 283 background: #13a923; 284 } 285 286 .ui-datepicker td span, 287 .ui-datepicker td a { 288 display: block; 289 color: #454545; 290 padding: 8px; 291 text-align: center; 292 text-decoration: none; 293 } 294 295 .ui-datepicker-current-day a.ui-state-active { 296 color: #fff; 297 } 298 299 .ui-datepicker .ui-datepicker-buttonpane { 300 background-image: none; 301 margin: .7em 0 0 0; 302 padding: 0 .2em; 303 border-left: 0; 304 border-right: 0; 305 border-bottom: 0; 306 } 307 308 .ui-datepicker .ui-datepicker-buttonpane button { 309 float: right; 310 margin: .5em .2em .4em; 311 cursor: pointer; 312 padding: .2em .6em .3em .6em; 313 width: auto; 314 overflow: visible; 315 } 316 317 .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { 318 float: left; 319 } 320 321 /* with multiple calendars */ 322 .ui-datepicker.ui-datepicker-multi { 323 width: auto; 324 } 325 326 .ui-datepicker-multi .ui-datepicker-group { 327 float: left; 328 } 329 330 .ui-datepicker-multi .ui-datepicker-group table { 331 width: 95%; 332 margin: 0 auto .4em; 333 } 334 335 .ui-datepicker-multi-2 .ui-datepicker-group { 336 width: 50%; 337 } 338 339 .ui-datepicker-multi-3 .ui-datepicker-group { 340 width: 33.3%; 341 } 342 343 .ui-datepicker-multi-4 .ui-datepicker-group { 344 width: 25%; 345 } 346 347 .ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header, 348 .ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { 349 border-left-width: 0; 350 } 351 352 .ui-datepicker-multi .ui-datepicker-buttonpane { 353 clear: left; 354 } 355 356 .ui-datepicker-row-break { 357 clear: both; 358 width: 100%; 359 font-size: 0; 360 } 361 362 /* RTL support */ 363 .ui-datepicker-rtl { 364 direction: rtl; 365 } 366 367 .ui-datepicker-rtl .ui-datepicker-prev { 368 right: 2px; 369 left: auto; 370 } 371 372 .ui-datepicker-rtl .ui-datepicker-next { 373 left: 2px; 374 right: auto; 375 } 376 377 .ui-datepicker-rtl .ui-datepicker-prev:hover { 378 right: 1px; 379 left: auto; 380 } 381 382 .ui-datepicker-rtl .ui-datepicker-next:hover { 383 left: 1px; 384 right: auto; 385 } 386 387 .ui-datepicker-rtl .ui-datepicker-buttonpane { 388 clear: right; 389 } 390 391 .ui-datepicker-rtl .ui-datepicker-buttonpane button { 392 float: left; 393 } 394 395 .ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current, 396 .ui-datepicker-rtl .ui-datepicker-group { 397 float: right; 398 } 399 400 .ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header, 401 .ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { 402 border-right-width: 0; 403 border-left-width: 1px; 404 } 405 406 .day-top { 407 display: flex; 408 justify-content: space-between; 409 background: #13a923; 410 padding: 5px; 411 text-align: center; 412 } 413 414 .day-top .lunar-prev, 415 .day-top .lunar-next { 416 margin-top: 4px; 417 cursor: pointer; 418 width: 1.4em; 419 height: 1.4em; 420 } 421 422 .day-top .lunar-prev { 423 float: left; 424 margin-left: 5px; 425 background: url('../images/left-arrow.png'); 426 background-size: cover; 427 } 428 429 .day-top .lunar-next { 430 float: right; 431 margin-right: 5px; 432 background: url('../images/right-arrow.png'); 433 background-size: cover; 434 } 435 436 .day-top input { 437 width: 120px; 438 height: 30px; 439 -webkit-border-radius: 3px; 440 -moz-border-radius: 3px; 441 border-radius: 3px; 442 } 443 444 .day-content { 445 line-height: 1; 446 padding: 10px 10px 15px 10px; 447 text-align: center; 448 background-image: linear-gradient(to top, rgba(66,59,16,0.1), rgba(36,230,57,0.2)); 449 } 450 451 .day-content h5.month-of-year { 452 font-size: 13px; 453 color: #e62470; 454 } 455 456 .day-content .day { 457 padding: 10px 0px; 458 font-size: 60px; 459 font-weight: bold; 460 color: #a9134e; 461 } 462 463 .day-content .hoangdao { 464 font-size: 12px; 465 line-height: 16px; 466 color: #828883; 467 } 468 .day-content .calendar-lunar{ 469 display: flex; 470 margin-top:10px; 471 } 472 .day-content .calendar-lunar .col-left, 473 .day-content .calendar-lunar .col-right { 474 width:50%; 475 } 476 .day-content .calendar-lunar h5.title{ 477 font-size:16px; 478 font-weight: bold; 479 margin-bottom:10px; 480 } 481 .day-content .calendar-lunar .description{ 482 font-size:13px; 483 color: #555; 484 line-height: 16px; 485 } 486 .day-content .calendar-lunar .day{ 487 font-size:30px; 488 padding:0px; 489 } -
lich-van-nien/tags/1.1/assets/js/custom.js
r2116699 r2119169 13 13 url: lvn_data.ajax_url, 14 14 data: data, 15 dataType: 'json',15 dataType: 'json', 16 16 success: function (data) { 17 17 switch (data.code) { 18 18 case 200: 19 jQuery('.lunar-widget ').html(jQuery.parseHTML(data.content)[0].data);19 jQuery('.lunar-widget .month').html(jQuery.parseHTML(data.content)[0].data); 20 20 wp_nonce.val(data._wp_nonce); 21 lunar_next_prev_month(); 21 22 break; 22 23 case 404: … … 31 32 32 33 }); 33 lunar_next_prev(); 34 lunar_next_prev_month(); 35 lunar_next_prev_day(); 34 36 37 /*Datepicker for input search date*/ 38 let lunar_find_day = jQuery('.lunar-find-day'); 39 lunar_find_day.datepicker( 40 { 41 nextText: '', 42 prevText: '', 43 dateFormat: 'dd-mm-yy' 44 } 45 ); 46 47 /* Onchange input choose lunar date */ 48 lunar_find_day.on('change', function (e) { 49 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 50 let data = { 51 _wp_nonce: wp_nonce.val(), 52 action: 'lvn_find_day', 53 lunar_date: jQuery(this).val(), 54 type: 'onchange' 55 }; 56 lunar_send_ajax_find_day(lvn_data.ajax_url, data, jQuery(this)); 57 }); 35 58 }); 36 59 37 function lunar_next_prev() { 38 jQuery('.lunar-next,.lunar-prev').click(function (e) { 60 /* Next month in widget */ 61 function lunar_next_prev_month() { 62 jQuery('.month .navi-right .lunar-next,.month .navi-left .lunar-prev').click(function (e) { 39 63 let lunar_month = jQuery(this).data('month'); 40 64 let lunar_year = jQuery(this).data('year'); 41 let wp_nonce = jQuery(' input[name="_wpnonce"]');65 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 42 66 let data = { 43 67 _wp_nonce: wp_nonce.val(), … … 50 74 url: lvn_data.ajax_url, 51 75 data: data, 52 dataType: 'json',76 dataType: 'json', 53 77 success: function (data) { 54 78 switch (data.code) { 55 79 case 200: 56 jQuery('.lunar-widget ').html(jQuery.parseHTML(data.content)[0].data);80 jQuery('.lunar-widget .month').html(jQuery.parseHTML(data.content)[0].data); 57 81 jQuery('.search-month').val(lunar_month); 58 82 jQuery('.search-year').val(lunar_year); 59 83 wp_nonce.val(data._wp_nonce); 60 lunar_next_prev ();84 lunar_next_prev_month(); 61 85 break; 62 86 case 404: … … 66 90 default: 67 91 alert('Có lỗi xảy ra. Vui lòng thử lại'); 68 69 92 } 70 93 } … … 72 95 }) 73 96 } 97 98 /* Next day in widget */ 99 function lunar_next_prev_day() { 100 jQuery('.calendar-day .lunar-next,.calendar-day .lunar-prev').click(function () { 101 let type = 'next'; 102 if (jQuery(this).hasClass('lunar-next')) { 103 type = 'next'; 104 } else { 105 type = 'prev'; 106 } 107 let lunar_date = jQuery('.calendar-day .lunar-find-day'); 108 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 109 let data = { 110 _wp_nonce: wp_nonce.val(), 111 action: 'lvn_find_day', 112 lunar_date: lunar_date.val(), 113 lunar_type: type 114 }; 115 lunar_send_ajax_find_day(lvn_data.ajax_url, data, lunar_date); 116 }) 117 } 118 119 /* Send ajax find day */ 120 function lunar_send_ajax_find_day(url, data, lunar_date) { 121 jQuery.ajax({ 122 type: 'POST', 123 url: url, 124 data: data, 125 dataType: 'json', 126 success: function (data) { 127 switch (data.code) { 128 case 200: 129 jQuery('.calendar-day .day-content').html(jQuery.parseHTML(data.content)[0].data); 130 lunar_date.val(data.new_date); 131 break; 132 case 404: 133 case 401: 134 alert(data.message); 135 break; 136 default: 137 alert('Có lỗi xảy ra. Vui lòng thử lại'); 138 } 139 } 140 }) 141 } -
lich-van-nien/tags/1.1/calendar-lunar.php
r2116699 r2119169 21 21 function lvn_load_script() { 22 22 wp_enqueue_style( 'lvn-custom', LVN_URL . '/assets/css/custom.css' ); 23 wp_enqueue_script( 'jquery-ui-datepicker' ); 23 24 wp_enqueue_script( 'lvn-custom', LVN_URL . '/assets/js/custom.js', '', '', true ); 24 25 wp_localize_script( 'lvn-custom', 'lvn_data', array( … … 26 27 'nonce' => wp_create_nonce( - 1 ) 27 28 ) ); 29 28 30 } 29 31 … … 74 76 add_action( 'wp_ajax_nopriv_lvn_find_month', 'lvn_find_month_callback' ); 75 77 } 78 79 /* Ajax find day */ 80 if ( ! function_exists( 'lvn_find_day_callback' ) ) { 81 function lvn_find_day_callback() { 82 // Check sercurity 83 check_ajax_referer( 'lvn-find-day', '_wp_nonce' ); 84 if ( isset( $_POST ) ) { 85 $lunar_date = sanitize_text_field( $_POST['lunar_date'] ); 86 $lunar_type = sanitize_text_field( $_POST['lunar_type'] ); 87 if ( lvn_validate_date( $lunar_date ) == false ) { 88 $data = array( 89 'code' => 404, 90 'message' => __( 'Dữ liệu không hợp lệ', 'calendar-lunar' ) 91 ); 92 echo json_encode( $data ); 93 die(); 94 } else { 95 $lunar = new LVN_Lunar(); 96 $ajax_nonce = wp_create_nonce( 'lvn-find-day' ); 97 $new_date = date_create( $lunar_date ); 98 if ( $lunar_type == 'next' ) { 99 $new_date = $new_date->modify( '+1 day' ); 100 } elseif($lunar_type == 'prev') { 101 $new_date = $new_date->modify( '-1 day' ); 102 } 103 104 $new_date = $new_date->format( 'd-m-Y' ); 105 $new_date_arr = explode( '-', $new_date ); 106 $data = array( 107 'code' => 200, 108 '_wp_nonce' => $ajax_nonce, 109 'content' => esc_html( $lunar->print_day( $new_date_arr[0], $new_date_arr[1], $new_date_arr[2] ) ), 110 'new_date' => $new_date 111 ); 112 echo json_encode( $data ); 113 die(); 114 } 115 } 116 $data = array( 117 'code' => 401, 118 'message' => __( 'Có lỗi xảy ra. Vui lòng thử lại!', 'calendar-lunar' ) 119 ); 120 echo json_encode( $data ); 121 die(); 122 } 123 124 // Load lunar month ajax 125 add_action( 'wp_ajax_lvn_find_day', 'lvn_find_day_callback' ); 126 add_action( 'wp_ajax_nopriv_lvn_find_day', 'lvn_find_day_callback' ); 127 } 128 129 if ( ! function_exists( 'lvn_validate_date' ) ) { 130 function lvn_validate_date( $str ) { 131 if ( preg_match( "/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/", $str ) ) { 132 return true; 133 } else { 134 return false; 135 } 136 } 137 } -
lich-van-nien/tags/1.1/readme.txt
r2116699 r2119169 1 = Calendar Lunar===1 = Lịch vạn niên === 2 2 Contributors: Cao Dat 3 3 Tags: lịch vạn niên, âm lịch, lịch vạn sự, lịch âm dương … … 5 5 Tested up to: 5.2 6 6 Requires PHP: 7.0 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Calendar Lunar allow you show calendar lunar on your website viawidget, shortcode11 Plugin Lịch vạn niên cho phép bạn hiển thị lịch ngày, lịch tháng, lịch năm bằng widget, shortcode 12 12 13 == Description==13 == Mô tả == 14 14 15 Calendar Lunar allow you show calendar lunar on your website viawidget, shortcode15 Plugin Lịch vạn niên giúp bạn hiển thị lịch âm dương theo ngày, tháng, năm bằng widget, shortcode 16 16 17 Major features in Calendar Lunar include: 17 Những tính năng của plugin bao gồm: 18 * Hiển thị cả lịch âm và lịch dương 19 * Hiển thị lịch ngày, lịch tháng, lịch năm bằng shortcode, widget 20 * Nhiều tuỳ chọn cho shortcode: Hiển thị theo ngày, tháng, năm, số cột hiển thị trên 1 hàng,... 21 * Tìm kiếm ngày, tháng, năm dễ dàng trên widget 18 22 19 * Show calendar lunar via widget, shortcode 20 * Multi option for shorcode: Show only month, only year, columns month in row 21 * Find any month in widget, action next and previous month,.. 22 23 == Installation == 24 25 Upload the Calendar Lunar plugin to your website , Activate it, then show it in widget or via shortcode 23 == Cài đặt == 24 Tải plugin lên trên website của bạn tại đường dẫn wp-content/plugins và kích hoạt nó 26 25 27 26 == Hướng dẫn sử dụng == … … 31 30 32 31 [show_lunar view='year' year=2019 month=06 columns=2] 33 - view: Kiểu hiển thị. Có 2 loại là hiển thị theo năm(year) hoặc theo tháng (month). Defaltlà month34 - year: Năm cần hiển thị. Default: năm hiện hành35 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Default: tháng hiện hành36 - columns: Số cột hiển thị. Default: 232 - view: Kiểu hiển thị. Có 3 loại là hiển thị theo năm(year), theo tháng (month), theo ngày (day) . Mặc định là month 33 - year: Năm cần hiển thị. Mặc định: năm hiện hành 34 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Mặc định: tháng hiện hành 35 - columns: Số cột hiển thị. Mặc định: 2 37 36 38 37 == Frequently Asked Questions == 39 * No question 38 39 * Không có câu hỏi 40 40 41 == Upgrade Notice == 41 * No notice 42 43 * Cập nhật ngay phiên bản 1.1 để sử dụng những tính năng mới 44 - Hiển thị lịch ngày trên widget 45 42 46 == Screenshots == 43 * No screenshot 47 48 1. Hiển thị lịch ngày 49 2. Hiển thị lịch tháng 50 3. Hiển thị lịch năm 51 44 52 == Changelog == 45 * No changelog 53 54 = 1.1 = 55 *Release Date - 08 July 2019* 56 57 * Thêm chức năng hiển thị lịch ngày trên widget, shortcode 58 * Cải thiện chức năng tìm kiếm theo tháng -
lich-van-nien/tags/1.1/shortcode.php
r2116699 r2119169 1 1 <?php 2 if (!function_exists('show_lunar_callback')){2 if ( ! function_exists( 'show_lunar_callback' ) ) { 3 3 function show_lunar_callback( $atts ) { 4 4 $params = shortcode_atts( array( … … 10 10 $lunar = new LVN_Lunar(); 11 11 $lunar->columns = $params['columns']; 12 $result = "";12 $result = ""; 13 13 switch ( $params['view'] ) { 14 14 case 'year': 15 $result .='<div class="lunar-year">'; 16 $result.= $lunar->print_year( $params['year'] ); 17 $result.= '</div>'; 15 $result .= '<div class="lunar-year">'; 16 $result .= $lunar->print_year( $params['year'] ); 17 $result .= '</div>'; 18 18 19 return $result; 19 20 break; 20 21 case 'month': 21 22 return $lunar->print_month( $params['month'], $params['year'] ); 23 break; 24 case 'day': 25 $result .= '<div class="lunar-widget">'; 26 $result .= '<div class="calendar-day">'; 27 $result .= ' 28 <div class="day-top"> 29 <a href="javascript:void(0)" class="lunar-prev"></a> 30 <input value="08-07-2019" class="lunar-find-day"> 31 <a href="javascript:void(0)" class="lunar-next"></a> 32 </div>'; 33 $result .='<div class="day-content">'; 34 $result .= $lunar->print_day( date( 'd' ), date( 'm' ), date( 'Y' ) ); 35 $result .= '</div>'; 36 $result.='</div>'; 37 $result .= '</div>'; 38 39 return $result; 22 40 break; 23 41 default: … … 29 47 } 30 48 add_shortcode( 'show_lunar', 'show_lunar_callback' ); 49 ?> 50 -
lich-van-nien/tags/1.1/widget.php
r2116699 r2119169 1 1 <?php 2 if (!class_exists('LVN_Widget_Lunar')){2 if ( ! class_exists( 'LVN_Widget_Lunar' ) ) { 3 3 Class LVN_Widget_Lunar extends WP_Widget { 4 4 function __construct() { … … 14 14 echo $args['before_widget']; 15 15 echo $args['before_title'] . $instance['lunar_title'] . $args['after_title']; 16 $this->lunar_search();17 wp_nonce_field('lvn-find-month');18 16 echo "<div class='lunar-widget'>"; 19 echo $lunar->print_month( date( 'm' ), date( 'Y' ) ); 17 switch ( $instance['lunar_type'] ) { 18 case 'month': 19 $this->lunar_search(); 20 wp_nonce_field( 'lvn-find-month' ); 21 echo $lunar->print_month( date( 'm' ), date( 'Y' ) ); 22 break; 23 case 'day': 24 wp_nonce_field( 'lvn-find-day' ); 25 $this->show_day(); 26 break; 27 } 20 28 echo "</div>"; 29 21 30 echo $args['after_widget']; 22 31 … … 37 46 38 47 </p> 48 <p> 49 <label for="<?php echo $this->get_field_id( 'lunar_type' ); ?>"><?php _e( 'Hiển thị' ); ?></label> 50 <br> 51 <select name="<?php echo $this->get_field_name( 'lunar_type' ); ?>"> 52 <option <?php if ( $instance['lunar_type'] == 'month' ) 53 echo 'selected' ?> value="month">Tháng 54 </option> 55 <option <?php if ( $instance['lunar_type'] == 'day' ) 56 echo 'selected' ?> value="day">Ngày 57 </option> 58 </select> 59 </p> 39 60 <?php 40 61 } … … 44 65 45 66 $instance['lunar_title'] = strip_tags( $new_instance['lunar_title'] ); 67 $instance['lunar_type'] = strip_tags( $new_instance['lunar_type'] ); 46 68 47 69 return $instance; … … 52 74 <div class="lunar-search"> 53 75 <select class="search-month lunar-search-item"> 54 <?php for($i=1;$i<=12;$i++): ?> 55 <option value="<?php echo $i; ?>" <?php if($i==date('m')) echo 'selected'; ?>><?php echo $i ?></option> 76 <?php for ( $i = 1; $i <= 12; $i ++ ): ?> 77 <option value="<?php echo $i; ?>" <?php if ( $i == date( 'm' ) ) { 78 echo 'selected'; 79 } ?>><?php echo $i ?></option> 56 80 <?php endfor; ?> 57 81 </select> 58 <input type="number" class="search-year lunar-search-item" value="<?php echo date( 'Y') ?>"/>82 <input type="number" class="search-year lunar-search-item" value="<?php echo date( 'Y' ) ?>"/> 59 83 <button class="lunar-search-button lunar-search-item">Tìm</button> 60 84 </div> 61 85 <?php 62 86 } 87 88 public function show_day() { 89 $lunar = new LVN_Lunar(); 90 ?> 91 <div class='calendar-day'> 92 <div class="day-top"> 93 <a href="javascript:void(0)" class="lunar-prev"></a> 94 <input value="<?php echo date( 'd-m-Y' ) ?>" class="lunar-find-day"/> 95 <a href="javascript:void(0)" class="lunar-next"></a> 96 </div> 97 <div class="day-content"> 98 <?php 99 $lunar_date = $lunar->print_day( date( 'd' ), date( 'm' ), date( 'Y' ) ); 100 echo $lunar_date; 101 echo "</div>"; 102 echo "</div>"; 103 } 63 104 } 64 105 } 65 106 66 if (!function_exists('lvn_register_widget_lunar')){107 if ( ! function_exists( 'lvn_register_widget_lunar' ) ) { 67 108 function lvn_register_widget_lunar() { 68 109 register_widget( 'LVN_Widget_Lunar' ); -
lich-van-nien/trunk/LVN_Lunar.php
r2116699 r2119169 456 456 'Mão', 457 457 'Thìn', 458 'T ị',458 'Tỵ', 459 459 'Ngọ', 460 460 'Mùi', … … 727 727 public function get_can_chi( $lunar_date ) { 728 728 $day_name = $this->can[ ( $lunar_date->jd + 9 ) % 10 ] . ' ' . $this->chi[ ( $lunar_date->jd + 1 ) % 12 ]; 729 $month_name = $this->can[ $lunar_date->year * 12 + $lunar_date->month + 3] . ' ' . $this->chi[ ( $lunar_date->month + 1 ) % 12 ];729 $month_name = $this->can[ ($lunar_date->year * 12 + $lunar_date->month + 3)%10 ] . ' ' . $this->chi[ ( $lunar_date->month + 1 ) % 12 ]; 730 730 if ( $lunar_date->leap == 1 ) { 731 $month_name .= " (nhu \u1EADn)";731 $month_name .= " (nhuận)"; 732 732 } 733 733 $year_name = $this->get_year_can_chi( $lunar_date->year ); … … 741 741 } 742 742 $canchi = $this->get_can_chi( $lunar_date ); 743 $day_name = "Ngày " . $canchi[0] . " , tháng" . $canchi[1] . ", năm " . $canchi[2];743 $day_name = "Ngày " . $canchi[0] . "<br> Tháng " . $canchi[1] . "<br> Năm " . $canchi[2]; 744 744 745 745 return $day_name; … … 760 760 $day .= "Ngày " . $lunar->day . " Tháng " . $lunar->month; 761 761 if ( $lunar->leap == 1 ) { 762 $day .= " nhu \u1EADn";762 $day .= " nhuận"; 763 763 } 764 764 … … 795 795 $result .= ', '; 796 796 } 797 if ( $count ++== 3 ) {797 if ( $count == 3 ) { 798 798 $result .= ''; 799 799 } 800 800 } 801 802 return $result; 803 } 801 } 802 return $result; 804 803 } 805 804 … … 962 961 } 963 962 963 public function print_day( $dd, $mm, $yy ) { 964 965 $result = ""; 966 set_query_var( 'lunar', array( 967 'lunar' => $this, 968 'day' => $dd, 969 'month' => $mm, 970 'year' => $yy 971 ) ); 972 ob_start(); 973 require LVN_DIR . '/parts/lunar-day.php'; 974 $result .= ob_get_contents(); 975 ob_end_clean(); 976 977 return $result; 978 } 979 964 980 } 965 981 } -
lich-van-nien/trunk/LVN_Lunar_Date.php
r2116699 r2119169 1 1 <?php 2 if (!class_exists('LVN_Lunar_Date')){2 if ( ! class_exists( 'LVN_Lunar_Date' ) ) { 3 3 class LVN_Lunar_Date { 4 4 public $day; -
lich-van-nien/trunk/assets/css/custom.css
r2116699 r2119169 1 .lunar-year table {1 .lunar-year table { 2 2 table-layout: unset; 3 3 } 4 4 5 .year-name { 5 6 text-align: center; … … 12 13 13 14 table.month { 14 width: 100%;15 width: 100%; 15 16 font-size: 13px; 16 17 padding: 1px; … … 18 19 table-layout: unset; 19 20 } 21 20 22 .month .navi-left, 21 23 .month .month-name, 22 .month .navi-right {24 .month .navi-right { 23 25 text-align: -webkit-center; 24 26 vertical-align: middle; 25 27 } 28 26 29 .month, 27 30 table.month tbody tr th, 28 table.month tbody tr td{ 29 padding:5px; 30 border:1px solid #dedede; 31 font-weight: bold; 32 } 33 .month td{ 31 table.month tbody tr td { 32 padding: 5px; 33 border: 1px solid #dedede; 34 font-weight: bold; 35 } 36 37 .month td { 34 38 cursor: pointer; 35 39 } 36 .month td:hover{ 37 background:#dedede; 38 } 39 .month td .date-lunar{ 40 41 .month td:hover { 42 background: #dedede; 43 } 44 45 .month td .date-lunar { 40 46 font-weight: normal; 41 padding-top: 3px;47 padding-top: 3px; 42 48 } 43 49 … … 122 128 color: red 123 129 } 124 .lunar-search{ 125 display:flex; 130 131 .lunar-search { 132 display: flex; 126 133 justify-items: center; 127 margin:10px 0px; 128 } 129 .lunar-search .lunar-search-item{ 134 margin: 10px 0px; 135 } 136 137 .lunar-search .lunar-search-item { 130 138 height: 35px; 131 139 } 132 .lunar-search select.lunar-search-item{ 133 width:20%; 134 -webkit-appearance:none; 140 141 .lunar-search select.lunar-search-item { 142 width: 20%; 143 -webkit-appearance: none; 135 144 -webkit-border-radius: 0px; 136 145 -moz-border-radius: 0px; 137 146 border-radius: 0px; 138 padding:0px 8px; 139 height:37px; 140 141 } 142 .lunar-search input{ 143 width:45%; 144 padding:0px 10px; 147 padding: 0px 8px; 148 height: 37px; 149 150 } 151 152 .lunar-search input { 153 width: 45%; 154 padding: 0px 10px; 145 155 margin: 0px 10px; 146 156 } 147 .lunar-search button.lunar-search-item{ 148 width:35%; 157 158 .lunar-search button.lunar-search-item { 159 width: 35%; 149 160 font-weight: bold; 150 161 cursor: pointer; 151 162 height: 37px; 152 163 } 153 td a.lunar-next{ 164 165 td a.lunar-next { 154 166 border-bottom: 0px; 155 167 display: block; 156 width: 20px;157 height: 20px;168 width: 20px; 169 height: 20px; 158 170 background: url('../images/right-arrow.png'); 159 171 -webkit-background-size: cover; 160 172 background-size: cover; 161 173 } 162 td a.lunar-prev{ 174 175 td a.lunar-prev { 163 176 border-bottom: 0px; 164 177 display: block; 165 width: 20px;166 height: 20px;178 width: 20px; 179 height: 20px; 167 180 background: url('../images/left-arrow.png'); 168 181 -webkit-background-size: cover; 169 182 background-size: cover; 170 183 } 171 .lunar-year>table>tbody>tr>td{ 172 padding:5px; 173 } 184 185 .lunar-year > table > tbody > tr > td { 186 padding: 5px; 187 } 188 189 .ui-datepicker { 190 background-color: #fff; 191 width: 17em; 192 padding: .2em .2em 0; 193 border: 1px solid #dedede; 194 -webkit-border-radius: 3px; 195 -moz-border-radius: 3px; 196 border-radius: 3px; 197 display: none; 198 } 199 200 .ui-datepicker .ui-datepicker-header { 201 position: relative; 202 padding: .2em 0; 203 } 204 205 .ui-datepicker .ui-datepicker-prev, 206 .ui-datepicker .ui-datepicker-next { 207 cursor: pointer; 208 position: absolute; 209 top: 8px; 210 width: 1em; 211 height: 1em; 212 } 213 214 .ui-datepicker .ui-datepicker-prev { 215 background: url('../images/left-arrow.png'); 216 -webkit-background-size: cover; 217 background-size: cover; 218 left: 2px; 219 } 220 221 .ui-datepicker .ui-datepicker-next { 222 background: url('../images/right-arrow.png'); 223 -webkit-background-size: cover; 224 background-size: cover; 225 right: 2px; 226 } 227 228 .ui-datepicker .ui-datepicker-prev span, 229 .ui-datepicker .ui-datepicker-next span { 230 display: block; 231 position: absolute; 232 left: 50%; 233 margin-left: -8px; 234 top: 50%; 235 margin-top: -8px; 236 } 237 238 .ui-datepicker .ui-datepicker-title { 239 margin: 0 2.3em; 240 line-height: 1.8em; 241 text-align: center; 242 } 243 244 .ui-datepicker .ui-datepicker-title select { 245 font-size: 1em; 246 margin: 1px 0; 247 } 248 249 .ui-datepicker select.ui-datepicker-month, 250 .ui-datepicker select.ui-datepicker-year { 251 width: 49%; 252 } 253 254 .ui-datepicker table { 255 width: 100%; 256 font-size: .9em; 257 border-collapse: collapse; 258 margin: 0 0 .4em; 259 } 260 261 .ui-datepicker th { 262 background: #dedede; 263 padding: .5em .3em; 264 text-align: center; 265 font-weight: bold; 266 border: 0; 267 } 268 269 .ui-datepicker td { 270 border: 1px solid #dfdfdf; 271 padding: 1px; 272 } 273 274 .ui-datepicker td:hover { 275 background: #13a923; 276 } 277 278 .ui-datepicker td:hover a { 279 color: #fff; 280 } 281 282 .ui-datepicker-current-day { 283 background: #13a923; 284 } 285 286 .ui-datepicker td span, 287 .ui-datepicker td a { 288 display: block; 289 color: #454545; 290 padding: 8px; 291 text-align: center; 292 text-decoration: none; 293 } 294 295 .ui-datepicker-current-day a.ui-state-active { 296 color: #fff; 297 } 298 299 .ui-datepicker .ui-datepicker-buttonpane { 300 background-image: none; 301 margin: .7em 0 0 0; 302 padding: 0 .2em; 303 border-left: 0; 304 border-right: 0; 305 border-bottom: 0; 306 } 307 308 .ui-datepicker .ui-datepicker-buttonpane button { 309 float: right; 310 margin: .5em .2em .4em; 311 cursor: pointer; 312 padding: .2em .6em .3em .6em; 313 width: auto; 314 overflow: visible; 315 } 316 317 .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { 318 float: left; 319 } 320 321 /* with multiple calendars */ 322 .ui-datepicker.ui-datepicker-multi { 323 width: auto; 324 } 325 326 .ui-datepicker-multi .ui-datepicker-group { 327 float: left; 328 } 329 330 .ui-datepicker-multi .ui-datepicker-group table { 331 width: 95%; 332 margin: 0 auto .4em; 333 } 334 335 .ui-datepicker-multi-2 .ui-datepicker-group { 336 width: 50%; 337 } 338 339 .ui-datepicker-multi-3 .ui-datepicker-group { 340 width: 33.3%; 341 } 342 343 .ui-datepicker-multi-4 .ui-datepicker-group { 344 width: 25%; 345 } 346 347 .ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header, 348 .ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { 349 border-left-width: 0; 350 } 351 352 .ui-datepicker-multi .ui-datepicker-buttonpane { 353 clear: left; 354 } 355 356 .ui-datepicker-row-break { 357 clear: both; 358 width: 100%; 359 font-size: 0; 360 } 361 362 /* RTL support */ 363 .ui-datepicker-rtl { 364 direction: rtl; 365 } 366 367 .ui-datepicker-rtl .ui-datepicker-prev { 368 right: 2px; 369 left: auto; 370 } 371 372 .ui-datepicker-rtl .ui-datepicker-next { 373 left: 2px; 374 right: auto; 375 } 376 377 .ui-datepicker-rtl .ui-datepicker-prev:hover { 378 right: 1px; 379 left: auto; 380 } 381 382 .ui-datepicker-rtl .ui-datepicker-next:hover { 383 left: 1px; 384 right: auto; 385 } 386 387 .ui-datepicker-rtl .ui-datepicker-buttonpane { 388 clear: right; 389 } 390 391 .ui-datepicker-rtl .ui-datepicker-buttonpane button { 392 float: left; 393 } 394 395 .ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current, 396 .ui-datepicker-rtl .ui-datepicker-group { 397 float: right; 398 } 399 400 .ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header, 401 .ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { 402 border-right-width: 0; 403 border-left-width: 1px; 404 } 405 406 .day-top { 407 display: flex; 408 justify-content: space-between; 409 background: #13a923; 410 padding: 5px; 411 text-align: center; 412 } 413 414 .day-top .lunar-prev, 415 .day-top .lunar-next { 416 margin-top: 4px; 417 cursor: pointer; 418 width: 1.4em; 419 height: 1.4em; 420 } 421 422 .day-top .lunar-prev { 423 float: left; 424 margin-left: 5px; 425 background: url('../images/left-arrow.png'); 426 background-size: cover; 427 } 428 429 .day-top .lunar-next { 430 float: right; 431 margin-right: 5px; 432 background: url('../images/right-arrow.png'); 433 background-size: cover; 434 } 435 436 .day-top input { 437 width: 120px; 438 height: 30px; 439 -webkit-border-radius: 3px; 440 -moz-border-radius: 3px; 441 border-radius: 3px; 442 } 443 444 .day-content { 445 line-height: 1; 446 padding: 10px 10px 15px 10px; 447 text-align: center; 448 background-image: linear-gradient(to top, rgba(66,59,16,0.1), rgba(36,230,57,0.2)); 449 } 450 451 .day-content h5.month-of-year { 452 font-size: 13px; 453 color: #e62470; 454 } 455 456 .day-content .day { 457 padding: 10px 0px; 458 font-size: 60px; 459 font-weight: bold; 460 color: #a9134e; 461 } 462 463 .day-content .hoangdao { 464 font-size: 12px; 465 line-height: 16px; 466 color: #828883; 467 } 468 .day-content .calendar-lunar{ 469 display: flex; 470 margin-top:10px; 471 } 472 .day-content .calendar-lunar .col-left, 473 .day-content .calendar-lunar .col-right { 474 width:50%; 475 } 476 .day-content .calendar-lunar h5.title{ 477 font-size:16px; 478 font-weight: bold; 479 margin-bottom:10px; 480 } 481 .day-content .calendar-lunar .description{ 482 font-size:13px; 483 color: #555; 484 line-height: 16px; 485 } 486 .day-content .calendar-lunar .day{ 487 font-size:30px; 488 padding:0px; 489 } -
lich-van-nien/trunk/assets/js/custom.js
r2116699 r2119169 13 13 url: lvn_data.ajax_url, 14 14 data: data, 15 dataType: 'json',15 dataType: 'json', 16 16 success: function (data) { 17 17 switch (data.code) { 18 18 case 200: 19 jQuery('.lunar-widget ').html(jQuery.parseHTML(data.content)[0].data);19 jQuery('.lunar-widget .month').html(jQuery.parseHTML(data.content)[0].data); 20 20 wp_nonce.val(data._wp_nonce); 21 lunar_next_prev_month(); 21 22 break; 22 23 case 404: … … 31 32 32 33 }); 33 lunar_next_prev(); 34 lunar_next_prev_month(); 35 lunar_next_prev_day(); 34 36 37 /*Datepicker for input search date*/ 38 let lunar_find_day = jQuery('.lunar-find-day'); 39 lunar_find_day.datepicker( 40 { 41 nextText: '', 42 prevText: '', 43 dateFormat: 'dd-mm-yy' 44 } 45 ); 46 47 /* Onchange input choose lunar date */ 48 lunar_find_day.on('change', function (e) { 49 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 50 let data = { 51 _wp_nonce: wp_nonce.val(), 52 action: 'lvn_find_day', 53 lunar_date: jQuery(this).val(), 54 type: 'onchange' 55 }; 56 lunar_send_ajax_find_day(lvn_data.ajax_url, data, jQuery(this)); 57 }); 35 58 }); 36 59 37 function lunar_next_prev() { 38 jQuery('.lunar-next,.lunar-prev').click(function (e) { 60 /* Next month in widget */ 61 function lunar_next_prev_month() { 62 jQuery('.month .navi-right .lunar-next,.month .navi-left .lunar-prev').click(function (e) { 39 63 let lunar_month = jQuery(this).data('month'); 40 64 let lunar_year = jQuery(this).data('year'); 41 let wp_nonce = jQuery(' input[name="_wpnonce"]');65 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 42 66 let data = { 43 67 _wp_nonce: wp_nonce.val(), … … 50 74 url: lvn_data.ajax_url, 51 75 data: data, 52 dataType: 'json',76 dataType: 'json', 53 77 success: function (data) { 54 78 switch (data.code) { 55 79 case 200: 56 jQuery('.lunar-widget ').html(jQuery.parseHTML(data.content)[0].data);80 jQuery('.lunar-widget .month').html(jQuery.parseHTML(data.content)[0].data); 57 81 jQuery('.search-month').val(lunar_month); 58 82 jQuery('.search-year').val(lunar_year); 59 83 wp_nonce.val(data._wp_nonce); 60 lunar_next_prev ();84 lunar_next_prev_month(); 61 85 break; 62 86 case 404: … … 66 90 default: 67 91 alert('Có lỗi xảy ra. Vui lòng thử lại'); 68 69 92 } 70 93 } … … 72 95 }) 73 96 } 97 98 /* Next day in widget */ 99 function lunar_next_prev_day() { 100 jQuery('.calendar-day .lunar-next,.calendar-day .lunar-prev').click(function () { 101 let type = 'next'; 102 if (jQuery(this).hasClass('lunar-next')) { 103 type = 'next'; 104 } else { 105 type = 'prev'; 106 } 107 let lunar_date = jQuery('.calendar-day .lunar-find-day'); 108 let wp_nonce = jQuery('.lunar-widget input[name="_wpnonce"]'); 109 let data = { 110 _wp_nonce: wp_nonce.val(), 111 action: 'lvn_find_day', 112 lunar_date: lunar_date.val(), 113 lunar_type: type 114 }; 115 lunar_send_ajax_find_day(lvn_data.ajax_url, data, lunar_date); 116 }) 117 } 118 119 /* Send ajax find day */ 120 function lunar_send_ajax_find_day(url, data, lunar_date) { 121 jQuery.ajax({ 122 type: 'POST', 123 url: url, 124 data: data, 125 dataType: 'json', 126 success: function (data) { 127 switch (data.code) { 128 case 200: 129 jQuery('.calendar-day .day-content').html(jQuery.parseHTML(data.content)[0].data); 130 lunar_date.val(data.new_date); 131 break; 132 case 404: 133 case 401: 134 alert(data.message); 135 break; 136 default: 137 alert('Có lỗi xảy ra. Vui lòng thử lại'); 138 } 139 } 140 }) 141 } -
lich-van-nien/trunk/calendar-lunar.php
r2116699 r2119169 21 21 function lvn_load_script() { 22 22 wp_enqueue_style( 'lvn-custom', LVN_URL . '/assets/css/custom.css' ); 23 wp_enqueue_script( 'jquery-ui-datepicker' ); 23 24 wp_enqueue_script( 'lvn-custom', LVN_URL . '/assets/js/custom.js', '', '', true ); 24 25 wp_localize_script( 'lvn-custom', 'lvn_data', array( … … 26 27 'nonce' => wp_create_nonce( - 1 ) 27 28 ) ); 29 28 30 } 29 31 … … 74 76 add_action( 'wp_ajax_nopriv_lvn_find_month', 'lvn_find_month_callback' ); 75 77 } 78 79 /* Ajax find day */ 80 if ( ! function_exists( 'lvn_find_day_callback' ) ) { 81 function lvn_find_day_callback() { 82 // Check sercurity 83 check_ajax_referer( 'lvn-find-day', '_wp_nonce' ); 84 if ( isset( $_POST ) ) { 85 $lunar_date = sanitize_text_field( $_POST['lunar_date'] ); 86 $lunar_type = sanitize_text_field( $_POST['lunar_type'] ); 87 if ( lvn_validate_date( $lunar_date ) == false ) { 88 $data = array( 89 'code' => 404, 90 'message' => __( 'Dữ liệu không hợp lệ', 'calendar-lunar' ) 91 ); 92 echo json_encode( $data ); 93 die(); 94 } else { 95 $lunar = new LVN_Lunar(); 96 $ajax_nonce = wp_create_nonce( 'lvn-find-day' ); 97 $new_date = date_create( $lunar_date ); 98 if ( $lunar_type == 'next' ) { 99 $new_date = $new_date->modify( '+1 day' ); 100 } elseif($lunar_type == 'prev') { 101 $new_date = $new_date->modify( '-1 day' ); 102 } 103 104 $new_date = $new_date->format( 'd-m-Y' ); 105 $new_date_arr = explode( '-', $new_date ); 106 $data = array( 107 'code' => 200, 108 '_wp_nonce' => $ajax_nonce, 109 'content' => esc_html( $lunar->print_day( $new_date_arr[0], $new_date_arr[1], $new_date_arr[2] ) ), 110 'new_date' => $new_date 111 ); 112 echo json_encode( $data ); 113 die(); 114 } 115 } 116 $data = array( 117 'code' => 401, 118 'message' => __( 'Có lỗi xảy ra. Vui lòng thử lại!', 'calendar-lunar' ) 119 ); 120 echo json_encode( $data ); 121 die(); 122 } 123 124 // Load lunar month ajax 125 add_action( 'wp_ajax_lvn_find_day', 'lvn_find_day_callback' ); 126 add_action( 'wp_ajax_nopriv_lvn_find_day', 'lvn_find_day_callback' ); 127 } 128 129 if ( ! function_exists( 'lvn_validate_date' ) ) { 130 function lvn_validate_date( $str ) { 131 if ( preg_match( "/^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/", $str ) ) { 132 return true; 133 } else { 134 return false; 135 } 136 } 137 } -
lich-van-nien/trunk/readme.txt
r2116699 r2119169 1 = Calendar Lunar===1 = Lịch vạn niên === 2 2 Contributors: Cao Dat 3 3 Tags: lịch vạn niên, âm lịch, lịch vạn sự, lịch âm dương … … 5 5 Tested up to: 5.2 6 6 Requires PHP: 7.0 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Calendar Lunar allow you show calendar lunar on your website viawidget, shortcode11 Plugin Lịch vạn niên cho phép bạn hiển thị lịch ngày, lịch tháng, lịch năm bằng widget, shortcode 12 12 13 == Description==13 == Mô tả == 14 14 15 Calendar Lunar allow you show calendar lunar on your website viawidget, shortcode15 Plugin Lịch vạn niên giúp bạn hiển thị lịch âm dương theo ngày, tháng, năm bằng widget, shortcode 16 16 17 Major features in Calendar Lunar include: 17 Những tính năng của plugin bao gồm: 18 * Hiển thị cả lịch âm và lịch dương 19 * Hiển thị lịch ngày, lịch tháng, lịch năm bằng shortcode, widget 20 * Nhiều tuỳ chọn cho shortcode: Hiển thị theo ngày, tháng, năm, số cột hiển thị trên 1 hàng,... 21 * Tìm kiếm ngày, tháng, năm dễ dàng trên widget 18 22 19 * Show calendar lunar via widget, shortcode 20 * Multi option for shorcode: Show only month, only year, columns month in row 21 * Find any month in widget, action next and previous month,.. 22 23 == Installation == 24 25 Upload the Calendar Lunar plugin to your website , Activate it, then show it in widget or via shortcode 23 == Cài đặt == 24 Tải plugin lên trên website của bạn tại đường dẫn wp-content/plugins và kích hoạt nó 26 25 27 26 == Hướng dẫn sử dụng == … … 31 30 32 31 [show_lunar view='year' year=2019 month=06 columns=2] 33 - view: Kiểu hiển thị. Có 2 loại là hiển thị theo năm(year) hoặc theo tháng (month). Defaltlà month34 - year: Năm cần hiển thị. Default: năm hiện hành35 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Default: tháng hiện hành36 - columns: Số cột hiển thị. Default: 232 - view: Kiểu hiển thị. Có 3 loại là hiển thị theo năm(year), theo tháng (month), theo ngày (day) . Mặc định là month 33 - year: Năm cần hiển thị. Mặc định: năm hiện hành 34 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Mặc định: tháng hiện hành 35 - columns: Số cột hiển thị. Mặc định: 2 37 36 38 37 == Frequently Asked Questions == 39 * No question 38 39 * Không có câu hỏi 40 40 41 == Upgrade Notice == 41 * No notice 42 43 * Cập nhật ngay phiên bản 1.1 để sử dụng những tính năng mới 44 - Hiển thị lịch ngày trên widget 45 42 46 == Screenshots == 43 * No screenshot 47 48 1. Hiển thị lịch ngày 49 2. Hiển thị lịch tháng 50 3. Hiển thị lịch năm 51 44 52 == Changelog == 45 * No changelog 53 54 = 1.1 = 55 *Release Date - 08 July 2019* 56 57 * Thêm chức năng hiển thị lịch ngày trên widget, shortcode 58 * Cải thiện chức năng tìm kiếm theo tháng -
lich-van-nien/trunk/shortcode.php
r2116699 r2119169 1 1 <?php 2 if (!function_exists('show_lunar_callback')){2 if ( ! function_exists( 'show_lunar_callback' ) ) { 3 3 function show_lunar_callback( $atts ) { 4 4 $params = shortcode_atts( array( … … 10 10 $lunar = new LVN_Lunar(); 11 11 $lunar->columns = $params['columns']; 12 $result = "";12 $result = ""; 13 13 switch ( $params['view'] ) { 14 14 case 'year': 15 $result .='<div class="lunar-year">'; 16 $result.= $lunar->print_year( $params['year'] ); 17 $result.= '</div>'; 15 $result .= '<div class="lunar-year">'; 16 $result .= $lunar->print_year( $params['year'] ); 17 $result .= '</div>'; 18 18 19 return $result; 19 20 break; 20 21 case 'month': 21 22 return $lunar->print_month( $params['month'], $params['year'] ); 23 break; 24 case 'day': 25 $result .= '<div class="lunar-widget">'; 26 $result .= '<div class="calendar-day">'; 27 $result .= ' 28 <div class="day-top"> 29 <a href="javascript:void(0)" class="lunar-prev"></a> 30 <input value="08-07-2019" class="lunar-find-day"> 31 <a href="javascript:void(0)" class="lunar-next"></a> 32 </div>'; 33 $result .='<div class="day-content">'; 34 $result .= $lunar->print_day( date( 'd' ), date( 'm' ), date( 'Y' ) ); 35 $result .= '</div>'; 36 $result.='</div>'; 37 $result .= '</div>'; 38 39 return $result; 22 40 break; 23 41 default: … … 29 47 } 30 48 add_shortcode( 'show_lunar', 'show_lunar_callback' ); 49 ?> 50 -
lich-van-nien/trunk/widget.php
r2116699 r2119169 1 1 <?php 2 if (!class_exists('LVN_Widget_Lunar')){2 if ( ! class_exists( 'LVN_Widget_Lunar' ) ) { 3 3 Class LVN_Widget_Lunar extends WP_Widget { 4 4 function __construct() { … … 14 14 echo $args['before_widget']; 15 15 echo $args['before_title'] . $instance['lunar_title'] . $args['after_title']; 16 $this->lunar_search();17 wp_nonce_field('lvn-find-month');18 16 echo "<div class='lunar-widget'>"; 19 echo $lunar->print_month( date( 'm' ), date( 'Y' ) ); 17 switch ( $instance['lunar_type'] ) { 18 case 'month': 19 $this->lunar_search(); 20 wp_nonce_field( 'lvn-find-month' ); 21 echo $lunar->print_month( date( 'm' ), date( 'Y' ) ); 22 break; 23 case 'day': 24 wp_nonce_field( 'lvn-find-day' ); 25 $this->show_day(); 26 break; 27 } 20 28 echo "</div>"; 29 21 30 echo $args['after_widget']; 22 31 … … 37 46 38 47 </p> 48 <p> 49 <label for="<?php echo $this->get_field_id( 'lunar_type' ); ?>"><?php _e( 'Hiển thị' ); ?></label> 50 <br> 51 <select name="<?php echo $this->get_field_name( 'lunar_type' ); ?>"> 52 <option <?php if ( $instance['lunar_type'] == 'month' ) 53 echo 'selected' ?> value="month">Tháng 54 </option> 55 <option <?php if ( $instance['lunar_type'] == 'day' ) 56 echo 'selected' ?> value="day">Ngày 57 </option> 58 </select> 59 </p> 39 60 <?php 40 61 } … … 44 65 45 66 $instance['lunar_title'] = strip_tags( $new_instance['lunar_title'] ); 67 $instance['lunar_type'] = strip_tags( $new_instance['lunar_type'] ); 46 68 47 69 return $instance; … … 52 74 <div class="lunar-search"> 53 75 <select class="search-month lunar-search-item"> 54 <?php for($i=1;$i<=12;$i++): ?> 55 <option value="<?php echo $i; ?>" <?php if($i==date('m')) echo 'selected'; ?>><?php echo $i ?></option> 76 <?php for ( $i = 1; $i <= 12; $i ++ ): ?> 77 <option value="<?php echo $i; ?>" <?php if ( $i == date( 'm' ) ) { 78 echo 'selected'; 79 } ?>><?php echo $i ?></option> 56 80 <?php endfor; ?> 57 81 </select> 58 <input type="number" class="search-year lunar-search-item" value="<?php echo date( 'Y') ?>"/>82 <input type="number" class="search-year lunar-search-item" value="<?php echo date( 'Y' ) ?>"/> 59 83 <button class="lunar-search-button lunar-search-item">Tìm</button> 60 84 </div> 61 85 <?php 62 86 } 87 88 public function show_day() { 89 $lunar = new LVN_Lunar(); 90 ?> 91 <div class='calendar-day'> 92 <div class="day-top"> 93 <a href="javascript:void(0)" class="lunar-prev"></a> 94 <input value="<?php echo date( 'd-m-Y' ) ?>" class="lunar-find-day"/> 95 <a href="javascript:void(0)" class="lunar-next"></a> 96 </div> 97 <div class="day-content"> 98 <?php 99 $lunar_date = $lunar->print_day( date( 'd' ), date( 'm' ), date( 'Y' ) ); 100 echo $lunar_date; 101 echo "</div>"; 102 echo "</div>"; 103 } 63 104 } 64 105 } 65 106 66 if (!function_exists('lvn_register_widget_lunar')){107 if ( ! function_exists( 'lvn_register_widget_lunar' ) ) { 67 108 function lvn_register_widget_lunar() { 68 109 register_widget( 'LVN_Widget_Lunar' );
Note: See TracChangeset
for help on using the changeset viewer.