widget_calendar.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 4 | |
| 5 | /** |
| 6 | * @author lord_viper |
| 7 | * @copyright 2013 |
| 8 | */ |
| 9 | class parsidate_calendar extends WP_Widget { |
| 10 | public function __construct() { |
| 11 | global $wp_version; |
| 12 | |
| 13 | if ( version_compare( $wp_version, '4.3', '>=' ) ) { |
| 14 | parent::__construct( false, __( 'Jalali Date Calender', 'wp-parsidate' ), 'description=' . __( 'Jalali Date Calender', 'wp-parsidate' ) ); |
| 15 | } else { |
| 16 | parent::WP_Widget( false, __( 'Jalali Date Calender', 'wp-parsidate' ), 'description=' . __( 'Jalali Date Calender', 'wp-parsidate' ) ); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Outputs the settings update form. |
| 22 | * |
| 23 | * @param array $instance Current settings. |
| 24 | * |
| 25 | * @return void Default return is 'noform'. |
| 26 | * @since 2.8.0 |
| 27 | * |
| 28 | */ |
| 29 | public function form( $instance ) { |
| 30 | $title = ! empty( $instance['parsidate_calendar_title'] ) ? $instance['parsidate_calendar_title'] : __( 'Jalali Date Calender', 'wp-parsidate' ); |
| 31 | $theme = ! empty( $instance['theme_color'] ) ? $instance['theme_color'] : 'light-mode'; |
| 32 | |
| 33 | if ( ! wpp_is_active( 'conv_permalinks' ) ) { |
| 34 | echo "<p style='color: #ff8153'>" . __( 'For use widget, active "Fix permalinks dates" option in plugin settings.', 'wp-parsidate' ) . "</p>"; |
| 35 | } |
| 36 | ?> |
| 37 | <p style="text-align:right; direction:rtl"> |
| 38 | <label for="<?php echo $this->get_field_id( 'parsidate_calendar_title' ); ?>"> |
| 39 | <?php _e( 'Title:', 'wp-parsidate' ) ?></label> |
| 40 | |
| 41 | <input style="width:calc(100% - 120px);float:left" id="<?php echo $this->get_field_id( 'parsidate_calendar_title' ); ?>" |
| 42 | name="<?php echo $this->get_field_name( 'parsidate_calendar_title' ); ?>" type="text" |
| 43 | value="<?php echo esc_attr( $title ); ?>"/> |
| 44 | </p> |
| 45 | |
| 46 | <p style="text-align:right; direction:rtl"> |
| 47 | <label for="<?php echo $this->get_field_id( 'theme-color' ); ?>"> |
| 48 | <?php _e( 'Theme color:', 'wp-parsidate' ) ?></label> |
| 49 | |
| 50 | <select style="width:calc(100% - 120px);float:left" id="<?php echo $this->get_field_id( 'theme-color' ); ?>" |
| 51 | name="<?php echo $this->get_field_name( 'theme-color' ); ?>"> |
| 52 | <option value="light-mode" <?php selected( $theme, 'light-mode' ); ?>> |
| 53 | <?php _e( 'Light Mode', 'wp-parsidate' ) ?> |
| 54 | </option> |
| 55 | <option value="dark-mode" <?php selected( $theme, 'dark-mode' ); ?>> |
| 56 | <?php _e( 'Dark Mode', 'wp-parsidate' ) ?> |
| 57 | </option> |
| 58 | </select> |
| 59 | </p> |
| 60 | <?php |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Updates a particular instance of a widget. |
| 65 | * |
| 66 | * This function should check that `$new_instance` is set correctly. The newly-calculated |
| 67 | * value of `$instance` should be returned. If false is returned, the instance won't be |
| 68 | * saved/updated. |
| 69 | * |
| 70 | * @param array $new_instance New settings for this instance as input by the user via |
| 71 | * WP_Widget::form(). |
| 72 | * @param array $old_instance Old settings for this instance. |
| 73 | * |
| 74 | * @return array Settings to save or bool false to cancel saving. |
| 75 | * @since 2.8.0 |
| 76 | * |
| 77 | */ |
| 78 | public function update( $new_instance, $old_instance ) { |
| 79 | $instance = $old_instance; |
| 80 | $instance['parsidate_calendar_title'] = esc_html( $new_instance['parsidate_calendar_title'] ); |
| 81 | $instance['theme_color'] = esc_attr( $new_instance['theme-color'] ); |
| 82 | |
| 83 | return $instance; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Echoes the widget content. |
| 88 | * |
| 89 | * Subclasses should override this function to generate their widget code. |
| 90 | * |
| 91 | * @param array $args Display arguments including 'before_title', 'after_title', |
| 92 | * 'before_widget', and 'after_widget'. |
| 93 | * @param array $instance The settings for the particular instance of the widget. |
| 94 | * |
| 95 | * @since 2.8.0 |
| 96 | * |
| 97 | */ |
| 98 | public function widget( $args, $instance ) { |
| 99 | if ( ! wpp_is_active( 'conv_permalinks' ) ) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | $theme = ! empty( $instance['theme_color'] ) ? $instance['theme_color'] : 'light-mode'; |
| 104 | |
| 105 | echo $args['before_widget']; |
| 106 | |
| 107 | if ( ! empty( $instance['parsidate_calendar_title'] ) ) { |
| 108 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['parsidate_calendar_title'] ) . $args['after_title']; |
| 109 | } |
| 110 | |
| 111 | wpp_get_calendar(); |
| 112 | |
| 113 | echo $args['after_widget']; |
| 114 | |
| 115 | if ( $theme === 'dark-mode' ) { |
| 116 | echo '<style>.widget_parsidate_calendar{background:#141414;border-radius:8px 8px 4px 4px;' . |
| 117 | 'overflow:hidden;box-shadow:0 0 5px 0 #000;text-align:center;padding-top:15px;color:#dcdcdc}'. |
| 118 | '.widget_parsidate_calendar table{direction:rtl;border-radius:12px;overflow:hidden;'. |
| 119 | 'background:#1d1d1d;box-shadow:inset 0 0 0 6px #141414}.widget_parsidate_calendar table th,'. |
| 120 | '.widget_parsidate_calendar table td{border:0}.widget_parsidate_calendar table th:last-child,'. |
| 121 | '.widget_parsidate_calendar table tr td:last-child{color:#f28a8a}</style>'; |
| 122 | } else { |
| 123 | echo '<style>.widget_parsidate_calendar{background:#dbdbdb;border-radius:12px;overflow:hidden;'. |
| 124 | 'box-shadow:0 0 15px 0 #0000004f,inset 0 0 0 1px #8080806e;text-align:center;padding-top:15px;'. |
| 125 | 'color:#1e1e1e}.widget_parsidate_calendar table{direction:rtl;border-radius:9px;overflow:hidden;'. |
| 126 | 'background:#fdfdfd;box-shadow:0 -13px 14px 0 #8080801a}.widget_parsidate_calendar table th,'. |
| 127 | '.widget_parsidate_calendar table td{border:0}.widget_parsidate_calendar table th:last-child,'. |
| 128 | '.widget_parsidate_calendar table tr td:last-child{color:#bf4a4a}</style>'; |
| 129 | } |
| 130 | } |
| 131 | } |