Plugin Directory

Changeset 2119169


Ignore:
Timestamp:
07/08/2019 05:59:52 AM (7 years ago)
Author:
caodat
Message:

Tagging version 1.1

Location:
lich-van-nien
Files:
14 edited
8 copied

Legend:

Unmodified
Added
Removed
  • lich-van-nien/tags/1.1/LVN_Lunar.php

    r2116699 r2119169  
    456456                'Mão',
    457457                'Thìn',
    458                 'T',
     458                'T',
    459459                'Ngọ',
    460460                'Mùi',
     
    727727        public function get_can_chi( $lunar_date ) {
    728728            $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 ];
    730730            if ( $lunar_date->leap == 1 ) {
    731                 $month_name .= " (nhu\u1EADn)";
     731                $month_name .= " (nhun)";
    732732            }
    733733            $year_name = $this->get_year_can_chi( $lunar_date->year );
     
    741741            }
    742742            $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];
    744744
    745745            return $day_name;
     
    760760            $day         .= "Ngày " . $lunar->day . " Tháng " . $lunar->month;
    761761            if ( $lunar->leap == 1 ) {
    762                 $day .= " nhu\u1EADn";
     762                $day .= " nhun";
    763763            }
    764764
     
    795795                        $result .= ', ';
    796796                    }
    797                     if ( $count ++ == 3 ) {
     797                    if ( $count == 3 ) {
    798798                        $result .= '';
    799799                    }
    800800                }
    801 
    802                 return $result;
    803             }
     801            }
     802            return $result;
    804803        }
    805804
     
    962961        }
    963962
     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
    964980    }
    965981}
  • lich-van-nien/tags/1.1/LVN_Lunar_Date.php

    r2116699 r2119169  
    11<?php
    2 if(!class_exists('LVN_Lunar_Date')){
     2if ( ! class_exists( 'LVN_Lunar_Date' ) ) {
    33    class LVN_Lunar_Date {
    44        public $day;
  • lich-van-nien/tags/1.1/assets/css/custom.css

    r2116699 r2119169  
    1 .lunar-year table{
     1.lunar-year table {
    22    table-layout: unset;
    33}
     4
    45.year-name {
    56    text-align: center;
     
    1213
    1314table.month {
    14     width:100%;
     15    width: 100%;
    1516    font-size: 13px;
    1617    padding: 1px;
     
    1819    table-layout: unset;
    1920}
     21
    2022.month .navi-left,
    2123.month .month-name,
    22 .month .navi-right{
     24.month .navi-right {
    2325    text-align: -webkit-center;
    2426    vertical-align: middle;
    2527}
     28
    2629.month,
    2730table.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{
     31table.month tbody tr td {
     32    padding: 5px;
     33    border: 1px solid #dedede;
     34    font-weight: bold;
     35}
     36
     37.month td {
    3438    cursor: pointer;
    3539}
    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 {
    4046    font-weight: normal;
    41     padding-top:3px;
     47    padding-top: 3px;
    4248}
    4349
     
    122128    color: red
    123129}
    124 .lunar-search{
    125     display:flex;
     130
     131.lunar-search {
     132    display: flex;
    126133    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 {
    130138    height: 35px;
    131139}
    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;
    135144    -webkit-border-radius: 0px;
    136145    -moz-border-radius: 0px;
    137146    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;
    145155    margin: 0px 10px;
    146156}
    147 .lunar-search button.lunar-search-item{
    148     width:35%;
     157
     158.lunar-search button.lunar-search-item {
     159    width: 35%;
    149160    font-weight: bold;
    150161    cursor: pointer;
    151162    height: 37px;
    152163}
    153 td a.lunar-next{
     164
     165td a.lunar-next {
    154166    border-bottom: 0px;
    155167    display: block;
    156     width:20px;
    157     height:20px;
     168    width: 20px;
     169    height: 20px;
    158170    background: url('../images/right-arrow.png');
    159171    -webkit-background-size: cover;
    160172    background-size: cover;
    161173}
    162 td a.lunar-prev{
     174
     175td a.lunar-prev {
    163176    border-bottom: 0px;
    164177    display: block;
    165     width:20px;
    166     height:20px;
     178    width: 20px;
     179    height: 20px;
    167180    background: url('../images/left-arrow.png');
    168181    -webkit-background-size: cover;
    169182    background-size: cover;
    170183}
    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  
    1313            url: lvn_data.ajax_url,
    1414            data: data,
    15             dataType:'json',
     15            dataType: 'json',
    1616            success: function (data) {
    1717                switch (data.code) {
    1818                    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);
    2020                        wp_nonce.val(data._wp_nonce);
     21                        lunar_next_prev_month();
    2122                        break;
    2223                    case 404:
     
    3132
    3233    });
    33     lunar_next_prev();
     34    lunar_next_prev_month();
     35    lunar_next_prev_day();
    3436
     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    });
    3558});
    3659
    37 function lunar_next_prev() {
    38     jQuery('.lunar-next,.lunar-prev').click(function (e) {
     60/* Next month in widget */
     61function lunar_next_prev_month() {
     62    jQuery('.month .navi-right .lunar-next,.month .navi-left .lunar-prev').click(function (e) {
    3963        let lunar_month = jQuery(this).data('month');
    4064        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"]');
    4266        let data = {
    4367            _wp_nonce: wp_nonce.val(),
     
    5074            url: lvn_data.ajax_url,
    5175            data: data,
    52             dataType:'json',
     76            dataType: 'json',
    5377            success: function (data) {
    5478                switch (data.code) {
    5579                    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);
    5781                        jQuery('.search-month').val(lunar_month);
    5882                        jQuery('.search-year').val(lunar_year);
    5983                        wp_nonce.val(data._wp_nonce);
    60                         lunar_next_prev();
     84                        lunar_next_prev_month();
    6185                        break;
    6286                    case 404:
     
    6690                    default:
    6791                        alert('Có lỗi xảy ra. Vui lòng thử lại');
    68 
    6992                }
    7093            }
     
    7295    })
    7396}
     97
     98/* Next day in widget */
     99function 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 */
     120function 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  
    2121    function lvn_load_script() {
    2222        wp_enqueue_style( 'lvn-custom', LVN_URL . '/assets/css/custom.css' );
     23        wp_enqueue_script( 'jquery-ui-datepicker' );
    2324        wp_enqueue_script( 'lvn-custom', LVN_URL . '/assets/js/custom.js', '', '', true );
    2425        wp_localize_script( 'lvn-custom', 'lvn_data', array(
     
    2627            'nonce'    => wp_create_nonce( - 1 )
    2728        ) );
     29
    2830    }
    2931
     
    7476    add_action( 'wp_ajax_nopriv_lvn_find_month', 'lvn_find_month_callback' );
    7577}
     78
     79/* Ajax find day */
     80if ( ! 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
     129if ( ! 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 ===
    22Contributors: Cao Dat
    33Tags: lịch vạn niên, âm lịch, lịch vạn sự, lịch âm dương
     
    55Tested up to: 5.2
    66Requires PHP: 7.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Calendar Lunar allow you show calendar lunar on your website via widget, shortcode
     11Plugin 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
    1212
    13 == Description ==
     13== Mô tả ==
    1414
    15 Calendar Lunar allow you show calendar lunar on your website via widget, shortcode
     15Plugin 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
    1616
    17 Major features in Calendar Lunar include:
     17Nhữ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
    1822
    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 ==
     24Tả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ó
    2625
    2726== Hướng dẫn sử dụng ==
     
    3130
    3231[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). Defalt là month
    34 - year: Năm cần hiển thị. Default: năm hiện hành
    35 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Default: tháng hiện hành
    36 - columns: Số cột hiển thị. Default: 2
     32- 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
    3736
    3837== Frequently Asked Questions ==
    39 * No question
     38
     39* Không có câu hỏi
     40
    4041== 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
    4246== Screenshots ==
    43 * No screenshot
     47
     481. Hiển thị lịch ngày
     492. Hiển thị lịch tháng
     503. Hiển thị lịch năm
     51
    4452== 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  
    11<?php
    2 if(!function_exists('show_lunar_callback')){
     2if ( ! function_exists( 'show_lunar_callback' ) ) {
    33    function show_lunar_callback( $atts ) {
    44        $params         = shortcode_atts( array(
     
    1010        $lunar          = new LVN_Lunar();
    1111        $lunar->columns = $params['columns'];
    12         $result = "";
     12        $result         = "";
    1313        switch ( $params['view'] ) {
    1414            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
    1819                return $result;
    1920                break;
    2021            case 'month':
    2122                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;
    2240                break;
    2341            default:
     
    2947}
    3048add_shortcode( 'show_lunar', 'show_lunar_callback' );
     49?>
     50
  • lich-van-nien/tags/1.1/widget.php

    r2116699 r2119169  
    11<?php
    2 if(!class_exists('LVN_Widget_Lunar')){
     2if ( ! class_exists( 'LVN_Widget_Lunar' ) ) {
    33    Class LVN_Widget_Lunar extends WP_Widget {
    44        function __construct() {
     
    1414            echo $args['before_widget'];
    1515            echo $args['before_title'] . $instance['lunar_title'] . $args['after_title'];
    16             $this->lunar_search();
    17             wp_nonce_field('lvn-find-month');
    1816            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            }
    2028            echo "</div>";
     29
    2130            echo $args['after_widget'];
    2231
     
    3746
    3847            </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>
    3960            <?php
    4061        }
     
    4465
    4566            $instance['lunar_title'] = strip_tags( $new_instance['lunar_title'] );
     67            $instance['lunar_type']  = strip_tags( $new_instance['lunar_type'] );
    4668
    4769            return $instance;
     
    5274            <div class="lunar-search">
    5375                <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>
    5680                    <?php endfor; ?>
    5781                </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' ) ?>"/>
    5983                <button class="lunar-search-button lunar-search-item">Tìm</button>
    6084            </div>
    6185            <?php
    6286        }
     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        }
    63104    }
    64105}
    65106
    66 if(!function_exists('lvn_register_widget_lunar')){
     107if ( ! function_exists( 'lvn_register_widget_lunar' ) ) {
    67108    function lvn_register_widget_lunar() {
    68109        register_widget( 'LVN_Widget_Lunar' );
  • lich-van-nien/trunk/LVN_Lunar.php

    r2116699 r2119169  
    456456                'Mão',
    457457                'Thìn',
    458                 'T',
     458                'T',
    459459                'Ngọ',
    460460                'Mùi',
     
    727727        public function get_can_chi( $lunar_date ) {
    728728            $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 ];
    730730            if ( $lunar_date->leap == 1 ) {
    731                 $month_name .= " (nhu\u1EADn)";
     731                $month_name .= " (nhun)";
    732732            }
    733733            $year_name = $this->get_year_can_chi( $lunar_date->year );
     
    741741            }
    742742            $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];
    744744
    745745            return $day_name;
     
    760760            $day         .= "Ngày " . $lunar->day . " Tháng " . $lunar->month;
    761761            if ( $lunar->leap == 1 ) {
    762                 $day .= " nhu\u1EADn";
     762                $day .= " nhun";
    763763            }
    764764
     
    795795                        $result .= ', ';
    796796                    }
    797                     if ( $count ++ == 3 ) {
     797                    if ( $count == 3 ) {
    798798                        $result .= '';
    799799                    }
    800800                }
    801 
    802                 return $result;
    803             }
     801            }
     802            return $result;
    804803        }
    805804
     
    962961        }
    963962
     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
    964980    }
    965981}
  • lich-van-nien/trunk/LVN_Lunar_Date.php

    r2116699 r2119169  
    11<?php
    2 if(!class_exists('LVN_Lunar_Date')){
     2if ( ! class_exists( 'LVN_Lunar_Date' ) ) {
    33    class LVN_Lunar_Date {
    44        public $day;
  • lich-van-nien/trunk/assets/css/custom.css

    r2116699 r2119169  
    1 .lunar-year table{
     1.lunar-year table {
    22    table-layout: unset;
    33}
     4
    45.year-name {
    56    text-align: center;
     
    1213
    1314table.month {
    14     width:100%;
     15    width: 100%;
    1516    font-size: 13px;
    1617    padding: 1px;
     
    1819    table-layout: unset;
    1920}
     21
    2022.month .navi-left,
    2123.month .month-name,
    22 .month .navi-right{
     24.month .navi-right {
    2325    text-align: -webkit-center;
    2426    vertical-align: middle;
    2527}
     28
    2629.month,
    2730table.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{
     31table.month tbody tr td {
     32    padding: 5px;
     33    border: 1px solid #dedede;
     34    font-weight: bold;
     35}
     36
     37.month td {
    3438    cursor: pointer;
    3539}
    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 {
    4046    font-weight: normal;
    41     padding-top:3px;
     47    padding-top: 3px;
    4248}
    4349
     
    122128    color: red
    123129}
    124 .lunar-search{
    125     display:flex;
     130
     131.lunar-search {
     132    display: flex;
    126133    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 {
    130138    height: 35px;
    131139}
    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;
    135144    -webkit-border-radius: 0px;
    136145    -moz-border-radius: 0px;
    137146    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;
    145155    margin: 0px 10px;
    146156}
    147 .lunar-search button.lunar-search-item{
    148     width:35%;
     157
     158.lunar-search button.lunar-search-item {
     159    width: 35%;
    149160    font-weight: bold;
    150161    cursor: pointer;
    151162    height: 37px;
    152163}
    153 td a.lunar-next{
     164
     165td a.lunar-next {
    154166    border-bottom: 0px;
    155167    display: block;
    156     width:20px;
    157     height:20px;
     168    width: 20px;
     169    height: 20px;
    158170    background: url('../images/right-arrow.png');
    159171    -webkit-background-size: cover;
    160172    background-size: cover;
    161173}
    162 td a.lunar-prev{
     174
     175td a.lunar-prev {
    163176    border-bottom: 0px;
    164177    display: block;
    165     width:20px;
    166     height:20px;
     178    width: 20px;
     179    height: 20px;
    167180    background: url('../images/left-arrow.png');
    168181    -webkit-background-size: cover;
    169182    background-size: cover;
    170183}
    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  
    1313            url: lvn_data.ajax_url,
    1414            data: data,
    15             dataType:'json',
     15            dataType: 'json',
    1616            success: function (data) {
    1717                switch (data.code) {
    1818                    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);
    2020                        wp_nonce.val(data._wp_nonce);
     21                        lunar_next_prev_month();
    2122                        break;
    2223                    case 404:
     
    3132
    3233    });
    33     lunar_next_prev();
     34    lunar_next_prev_month();
     35    lunar_next_prev_day();
    3436
     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    });
    3558});
    3659
    37 function lunar_next_prev() {
    38     jQuery('.lunar-next,.lunar-prev').click(function (e) {
     60/* Next month in widget */
     61function lunar_next_prev_month() {
     62    jQuery('.month .navi-right .lunar-next,.month .navi-left .lunar-prev').click(function (e) {
    3963        let lunar_month = jQuery(this).data('month');
    4064        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"]');
    4266        let data = {
    4367            _wp_nonce: wp_nonce.val(),
     
    5074            url: lvn_data.ajax_url,
    5175            data: data,
    52             dataType:'json',
     76            dataType: 'json',
    5377            success: function (data) {
    5478                switch (data.code) {
    5579                    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);
    5781                        jQuery('.search-month').val(lunar_month);
    5882                        jQuery('.search-year').val(lunar_year);
    5983                        wp_nonce.val(data._wp_nonce);
    60                         lunar_next_prev();
     84                        lunar_next_prev_month();
    6185                        break;
    6286                    case 404:
     
    6690                    default:
    6791                        alert('Có lỗi xảy ra. Vui lòng thử lại');
    68 
    6992                }
    7093            }
     
    7295    })
    7396}
     97
     98/* Next day in widget */
     99function 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 */
     120function 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  
    2121    function lvn_load_script() {
    2222        wp_enqueue_style( 'lvn-custom', LVN_URL . '/assets/css/custom.css' );
     23        wp_enqueue_script( 'jquery-ui-datepicker' );
    2324        wp_enqueue_script( 'lvn-custom', LVN_URL . '/assets/js/custom.js', '', '', true );
    2425        wp_localize_script( 'lvn-custom', 'lvn_data', array(
     
    2627            'nonce'    => wp_create_nonce( - 1 )
    2728        ) );
     29
    2830    }
    2931
     
    7476    add_action( 'wp_ajax_nopriv_lvn_find_month', 'lvn_find_month_callback' );
    7577}
     78
     79/* Ajax find day */
     80if ( ! 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
     129if ( ! 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 ===
    22Contributors: Cao Dat
    33Tags: lịch vạn niên, âm lịch, lịch vạn sự, lịch âm dương
     
    55Tested up to: 5.2
    66Requires PHP: 7.0
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Calendar Lunar allow you show calendar lunar on your website via widget, shortcode
     11Plugin 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
    1212
    13 == Description ==
     13== Mô tả ==
    1414
    15 Calendar Lunar allow you show calendar lunar on your website via widget, shortcode
     15Plugin 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
    1616
    17 Major features in Calendar Lunar include:
     17Nhữ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
    1822
    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 ==
     24Tả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ó
    2625
    2726== Hướng dẫn sử dụng ==
     
    3130
    3231[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). Defalt là month
    34 - year: Năm cần hiển thị. Default: năm hiện hành
    35 - month: Tháng cần hiển thị, Có hiệu lực khi view='month'. Default: tháng hiện hành
    36 - columns: Số cột hiển thị. Default: 2
     32- 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
    3736
    3837== Frequently Asked Questions ==
    39 * No question
     38
     39* Không có câu hỏi
     40
    4041== 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
    4246== Screenshots ==
    43 * No screenshot
     47
     481. Hiển thị lịch ngày
     492. Hiển thị lịch tháng
     503. Hiển thị lịch năm
     51
    4452== 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  
    11<?php
    2 if(!function_exists('show_lunar_callback')){
     2if ( ! function_exists( 'show_lunar_callback' ) ) {
    33    function show_lunar_callback( $atts ) {
    44        $params         = shortcode_atts( array(
     
    1010        $lunar          = new LVN_Lunar();
    1111        $lunar->columns = $params['columns'];
    12         $result = "";
     12        $result         = "";
    1313        switch ( $params['view'] ) {
    1414            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
    1819                return $result;
    1920                break;
    2021            case 'month':
    2122                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;
    2240                break;
    2341            default:
     
    2947}
    3048add_shortcode( 'show_lunar', 'show_lunar_callback' );
     49?>
     50
  • lich-van-nien/trunk/widget.php

    r2116699 r2119169  
    11<?php
    2 if(!class_exists('LVN_Widget_Lunar')){
     2if ( ! class_exists( 'LVN_Widget_Lunar' ) ) {
    33    Class LVN_Widget_Lunar extends WP_Widget {
    44        function __construct() {
     
    1414            echo $args['before_widget'];
    1515            echo $args['before_title'] . $instance['lunar_title'] . $args['after_title'];
    16             $this->lunar_search();
    17             wp_nonce_field('lvn-find-month');
    1816            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            }
    2028            echo "</div>";
     29
    2130            echo $args['after_widget'];
    2231
     
    3746
    3847            </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>
    3960            <?php
    4061        }
     
    4465
    4566            $instance['lunar_title'] = strip_tags( $new_instance['lunar_title'] );
     67            $instance['lunar_type']  = strip_tags( $new_instance['lunar_type'] );
    4668
    4769            return $instance;
     
    5274            <div class="lunar-search">
    5375                <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>
    5680                    <?php endfor; ?>
    5781                </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' ) ?>"/>
    5983                <button class="lunar-search-button lunar-search-item">Tìm</button>
    6084            </div>
    6185            <?php
    6286        }
     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        }
    63104    }
    64105}
    65106
    66 if(!function_exists('lvn_register_widget_lunar')){
     107if ( ! function_exists( 'lvn_register_widget_lunar' ) ) {
    67108    function lvn_register_widget_lunar() {
    68109        register_widget( 'LVN_Widget_Lunar' );
Note: See TracChangeset for help on using the changeset viewer.