| 1 |
<?php |
| 2 |
/* Copyright 2014-2020 Baptiste Placé |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License, version 2, as |
| 6 |
published by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, |
| 9 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License |
| 14 |
along with this program; if not, write to the Free Software |
| 15 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 |
*/ |
| 17 |
/** |
| 18 |
* Plugin Name: iCalendrier |
| 19 |
* Plugin URI: https://icalendrier.fr/widget/wordpress-plugin |
| 20 |
* Description: Un simple calendrier qui affiche des infos du jour, comme le numéro de semaine, la date, la fête du jour et la phase de lune. |
| 21 |
* Version: 1.75 |
| 22 |
* Author: Baptiste Placé |
| 23 |
* Author URI: https://icalendrier.fr/ |
| 24 |
* License: GNU General Public License, version 2 |
| 25 |
*/ |
| 26 |
|
| 27 |
defined('ABSPATH') or die("No script kiddies please!"); |
| 28 |
|
| 29 |
// Include lib |
| 30 |
require_once(dirname(__FILE__) . '/lib/Icalendrier.php'); |
| 31 |
|
| 32 |
// Add localized strings |
| 33 |
load_plugin_textdomain('icalendrier', false, basename(dirname(__FILE__)) . '/languages'); |
| 34 |
|
| 35 |
// Enqueue CSS |
| 36 |
function icalendrier_wp_head() |
| 37 |
{ |
| 38 |
wp_register_style('icalendrier-default', plugins_url('/css/icalendrier.css', __FILE__), '', null, 'all'); |
| 39 |
wp_register_style('icalendrier-alt-1', plugins_url('/css/themes/icalendrier-alt-1.css', __FILE__), array(), null, 'all'); |
| 40 |
wp_enqueue_style('icalendrier-default'); |
| 41 |
wp_enqueue_style('icalendrier-alt-1'); |
| 42 |
} |
| 43 |
|
| 44 |
function icalendrier_wp_admin_head() |
| 45 |
{ |
| 46 |
wp_enqueue_style('icalendrier', plugins_url('/css/icalendrier-admin.css', __FILE__)); |
| 47 |
} |
| 48 |
|
| 49 |
add_action('wp_enqueue_scripts', 'icalendrier_wp_head'); |
| 50 |
|
| 51 |
add_action('admin_enqueue_scripts', 'icalendrier_wp_admin_head'); |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Parse attributes + set theme or default CSS |
| 56 |
* |
| 57 |
* @param $atts |
| 58 |
* |
| 59 |
* @return array |
| 60 |
*/ |
| 61 |
function getAttibutes($atts) |
| 62 |
{ |
| 63 |
$calType = isset($atts['type']) ? $atts['type'] : 'comp175'; |
| 64 |
$language = isset($atts['language']) ? $atts['language'] : 'en'; |
| 65 |
$timezone = isset($atts['timezone']) ? $atts['timezone'] : 0; |
| 66 |
$showLink = ((isset($atts['showLink']) AND $atts['showLink'] == 'on') OR ! isset($atts['showLink'])) ? 1 : 0; |
| 67 |
$bgColor = isset($atts['bgColor']) ? $atts['bgColor'] : false; |
| 68 |
$style = isset($atts['style']) ? $atts['style'] : 'default'; |
| 69 |
|
| 70 |
return [ |
| 71 |
'calType' => $calType, |
| 72 |
'language' => $language, |
| 73 |
'timezone' => $timezone, |
| 74 |
'showLink' => $showLink, |
| 75 |
'bgColor' => $bgColor, |
| 76 |
'style' => $style |
| 77 |
]; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
// Shortcode |
| 82 |
add_shortcode('icalendrier', 'icalendrier_shortcode'); |
| 83 |
function icalendrier_shortcode($atts) |
| 84 |
{ |
| 85 |
$attributes = getAttibutes($atts); |
| 86 |
|
| 87 |
$iCalendrier = new Icalendrier($attributes['language'], $attributes['timezone']); |
| 88 |
|
| 89 |
if ('comp175' === $attributes['calType']) { |
| 90 |
echo $iCalendrier->iCalendrierComp($attributes); |
| 91 |
} elseif ('wide300' === $attributes['calType']) { |
| 92 |
echo $iCalendrier->iCalendrierWide($attributes); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
/** |
| 98 |
* Class ICalendrier |
| 99 |
*/ |
| 100 |
class ICalendrierWidget extends WP_Widget |
| 101 |
{ |
| 102 |
|
| 103 |
/** |
| 104 |
* ICalendrierWidget constructor. |
| 105 |
*/ |
| 106 |
public function __construct() |
| 107 |
{ |
| 108 |
parent::__construct('icalendrier_widget', 'iCalendrier Widget', [ |
| 109 |
'classname' => 'calendar', |
| 110 |
'description' => 'Simple daily calendar' |
| 111 |
]); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* @param $args |
| 116 |
* @param $instance |
| 117 |
*/ |
| 118 |
public function widget($args, $instance) |
| 119 |
{ |
| 120 |
/** |
| 121 |
* @var $before_widget |
| 122 |
* @var $widgetTitle |
| 123 |
* @var $before_title |
| 124 |
* @var $after_title |
| 125 |
* @var $after_widget |
| 126 |
*/ |
| 127 |
extract($args); |
| 128 |
|
| 129 |
$attributes = getAttibutes($instance); |
| 130 |
|
| 131 |
echo $before_widget; |
| 132 |
|
| 133 |
if ($widgetTitle != "") { |
| 134 |
echo $before_title . $widgetTitle . $after_title; |
| 135 |
} |
| 136 |
|
| 137 |
$iCalendrier = new Icalendrier($attributes['language'], $attributes['timezone']); |
| 138 |
|
| 139 |
if ('comp175' === $attributes['calType']) { |
| 140 |
echo $iCalendrier->iCalendrierComp($attributes); |
| 141 |
} elseif ('wide300' === $attributes['calType']) { |
| 142 |
echo $iCalendrier->iCalendrierWide($attributes); |
| 143 |
} |
| 144 |
|
| 145 |
echo $after_widget; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* @param $new_instance |
| 150 |
* @param $old_instance |
| 151 |
* |
| 152 |
* @return mixed |
| 153 |
*/ |
| 154 |
public function update($new_instance, $old_instance) |
| 155 |
{ |
| 156 |
$instance = $old_instance; |
| 157 |
$instance['type'] = strip_tags($new_instance['type']); |
| 158 |
$instance['language'] = strip_tags($new_instance['language']); |
| 159 |
$instance['timezone'] = strip_tags($new_instance['timezone']); |
| 160 |
$instance['widgetTitle'] = strip_tags($new_instance['widgetTitle']); |
| 161 |
$instance['bgColor'] = strip_tags($new_instance['bgColor']); |
| 162 |
$instance['showLink'] = ((isset($instance['showLink']) AND $instance['showLink'] == 'on') OR ! isset($instance['showLink'])) ? 1 : 0; |
| 163 |
$instance['style'] = strip_tags($new_instance['style']); |
| 164 |
|
| 165 |
return $instance; |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* @param $instance |
| 170 |
*/ |
| 171 |
public function form($instance) |
| 172 |
{ |
| 173 |
$type = isset($instance['type']) ? esc_attr($instance['type']) : "comp175"; |
| 174 |
$language = isset($instance['language']) ? esc_attr($instance['language']) : "en"; |
| 175 |
$timezone = isset($instance['timezone']) ? esc_attr($instance['timezone']) : 5; |
| 176 |
$widgetTitle = isset($instance['widgetTitle']) ? esc_attr($instance['widgetTitle']) : ""; |
| 177 |
$showLink = ((isset($instance['showLink']) AND $instance['showLink'] == 'on') OR ! isset($instance['showLink'])) ? 1 : 0; |
| 178 |
$bgColor = isset($instance['bgColor']) ? esc_attr($instance['bgColor']) : ""; |
| 179 |
$style = isset($instance['style']) ? esc_attr($instance['style']) : "default"; |
| 180 |
?> |
| 181 |
|
| 182 |
<p> |
| 183 |
<label for="<?php echo $this->get_field_id('type'); ?>"><?php _e('MOD_ICAL_CALTYPE_LABEL', 'icalendrier'); ?></label> |
| 184 |
<select class="widefat" id="<?php echo $this->get_field_id('type'); ?>" name="<?php echo $this->get_field_name('type'); ?>"> |
| 185 |
<option value="comp175"<?php if ($type == 'comp175') { |
| 186 |
echo " selected=\"selected\""; |
| 187 |
} ?>><?php _e('MOD_ICAL_CALTYPE_COMP175', 'icalendrier'); ?></option> |
| 188 |
<option value="wide300"<?php if ($type == 'wide300') { |
| 189 |
echo " selected=\"selected\""; |
| 190 |
} ?>><?php _e('MOD_ICAL_CALTYPE_COMP300', 'icalendrier'); ?></option> |
| 191 |
</select> |
| 192 |
</p> |
| 193 |
|
| 194 |
<p> |
| 195 |
<label for="<?php echo $this->get_field_id('style'); ?>"><?php _e('MOD_ICAL_STYLE_LABEL', 'icalendrier'); ?></label> |
| 196 |
<select class="widefat" id="<?php echo $this->get_field_id('style'); ?>" name="<?php echo $this->get_field_name('style'); ?>"> |
| 197 |
<option value="default"<?php if ($style == 'default') { |
| 198 |
echo " selected=\"selected\""; |
| 199 |
} ?>><?php _e('MOD_ICAL_STYLE_DEFAULT', 'icalendrier'); ?></option> |
| 200 |
<option value="alt-1"<?php if ($style == 'alt-1') { |
| 201 |
echo " selected=\"selected\""; |
| 202 |
} ?>><?php _e('MOD_ICAL_STYLE_ALT_1', 'icalendrier'); ?></option> |
| 203 |
</select> |
| 204 |
</p> |
| 205 |
|
| 206 |
<p> |
| 207 |
<label for="<?php echo $this->get_field_id('language'); ?>"><?php _e('MOD_ICAL_LANGUAGE_LABEL', 'icalendrier'); ?></label> |
| 208 |
<select class="widefat" id="<?php echo $this->get_field_id('language'); ?>" name="<?php echo $this->get_field_name('language'); ?>"> |
| 209 |
<option value="de"<?php if ($language == 'de') { |
| 210 |
echo " selected=\"selected\""; |
| 211 |
} ?>>Deutsch |
| 212 |
</option> |
| 213 |
<option value="en"<?php if ($language == 'en') { |
| 214 |
echo " selected=\"selected\""; |
| 215 |
} ?>>English |
| 216 |
</option> |
| 217 |
<option value="es"<?php if ($language == 'es') { |
| 218 |
echo " selected=\"selected\""; |
| 219 |
} ?>>Español |
| 220 |
</option> |
| 221 |
<option value="fr"<?php if ($language == 'fr') { |
| 222 |
echo " selected=\"selected\""; |
| 223 |
} ?>>Français |
| 224 |
</option> |
| 225 |
<option value="it"<?php if ($language == 'it') { |
| 226 |
echo " selected=\"selected\""; |
| 227 |
} ?>>Italiano |
| 228 |
</option> |
| 229 |
<option value="ro"<?php if ($language == 'ro') { |
| 230 |
echo " selected=\"selected\""; |
| 231 |
} ?>>Română |
| 232 |
</option> |
| 233 |
<option value="pt"<?php if ($language == 'pt') { |
| 234 |
echo " selected=\"selected\""; |
| 235 |
} ?>>Português |
| 236 |
</option> |
| 237 |
<option value="pt-BR"<?php if ($language == 'pt-BR') { |
| 238 |
echo " selected=\"selected\""; |
| 239 |
} ?>>Português (Brasil) |
| 240 |
</option> |
| 241 |
</select> |
| 242 |
</p> |
| 243 |
|
| 244 |
<p> |
| 245 |
<label for="<?php echo $this->get_field_id('timezone'); ?>"><?php _e('MOD_ICAL_TIMEZONE_LABEL', 'icalendrier'); ?></label> |
| 246 |
<select class="widefat" id="<?php echo $this->get_field_id('timezone'); ?>" name="<?php echo $this->get_field_name('timezone'); ?>"> |
| 247 |
<option value="0"<?php if ($timezone === 0) { |
| 248 |
echo " selected=\"selected\""; |
| 249 |
} ?>><?php _e('MOD_ICAL_TIMEZONE_AUTO', 'icalendrier'); ?></option> |
| 250 |
|
| 251 |
<?php |
| 252 |
$timezone_identifiers = DateTimeZone::listIdentifiers(); |
| 253 |
preg_match("#^(.+?)/#", $timezone_identifiers[count($timezone_identifiers) - 1], $m); |
| 254 |
$optGroup = $m[1]; |
| 255 |
echo '<optgroup label="' . $optGroup . '">' . PHP_EOL; |
| 256 |
foreach ($timezone_identifiers as $timezone_identifier) { |
| 257 |
preg_match("#^(.+?)/#", $timezone_identifier, $m); |
| 258 |
if ($optGroup != $m[1]) { |
| 259 |
echo '</optgroup>' . PHP_EOL; |
| 260 |
$optGroup = $m[1]; |
| 261 |
echo '<optgroup label="' . $optGroup . '">' . PHP_EOL; |
| 262 |
} |
| 263 |
echo '<option value="' . $timezone_identifier . '" ' . ($timezone === $timezone_identifier ? 'selected="selected"' : '') . '>' . $timezone_identifier . '</option>'; |
| 264 |
} |
| 265 |
echo '</optgroup>'; |
| 266 |
?> |
| 267 |
<option value="UTC"<?php if ($timezone == 'UTC') { |
| 268 |
echo " selected=\"selected\""; |
| 269 |
} ?>>UTC |
| 270 |
</option> |
| 271 |
</select> |
| 272 |
</p> |
| 273 |
|
| 274 |
<p> |
| 275 |
<label for="<?php echo $this->get_field_id('showLink'); ?>"><?php _e('MOD_ICAL_SHOWLINK_LABEL', 'icalendrier'); ?></label> |
| 276 |
<input id="<?php echo $this->get_field_id('showLink'); ?>" name="<?php echo $this->get_field_name('showLink'); ?>" type="checkbox" <?php if ($showLink) { |
| 277 |
echo ' checked="checked"'; |
| 278 |
} ?> /> |
| 279 |
</p> |
| 280 |
|
| 281 |
<p> |
| 282 |
<label for="<?php echo $this->get_field_id('widgetTitle'); ?>"><?php _e('MOD_ICAL_WIDGET_TITLE_LABEL', 'icalendrier'); ?></label> |
| 283 |
<input class="widefat" id="<?php echo $this->get_field_id('widgetTitle'); ?>" name="<?php echo $this->get_field_name('widgetTitle'); ?>" type="text" |
| 284 |
value="<?php echo $widgetTitle; ?>"/> |
| 285 |
</p> |
| 286 |
|
| 287 |
<p> |
| 288 |
<label for="<?php echo $this->get_field_id('bgColor'); ?>"><?php _e('MOD_ICAL_BGCOLOR_LABEL', 'icalendrier'); ?></label><br/> |
| 289 |
<input class="widefat" id="<?php echo $this->get_field_id('bgColor'); ?>" name="<?php echo $this->get_field_name('bgColor'); ?>" type="text" |
| 290 |
value="<?php echo $bgColor; ?>"/> |
| 291 |
</p> |
| 292 |
|
| 293 |
<?php |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
add_action('widgets_init', function () { |
| 298 |
register_widget('ICalendrierWidget'); |
| 299 |
}); |