mirror of
https://github.com/dwaxweiler/connector-mobilizon
synced 2025-06-05 21:59:25 +02:00
remove unneeded folder
This commit is contained in:
11
source/includes/constants.php
Normal file
11
source/includes/constants.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace MobilizonConnector;
|
||||
|
||||
// Exit if this file is called directly.
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
const DEFAULT_EVENTS_COUNT = 5;
|
||||
const NAME = '<wordpress-name>';
|
||||
const NICE_NAME = '<wordpress-nice-name>';
|
40
source/includes/events-list-shortcut.php
Normal file
40
source/includes/events-list-shortcut.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace MobilizonConnector;
|
||||
|
||||
// Exit if this file is called directly.
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class EventsListShortcut {
|
||||
|
||||
public static function init() {
|
||||
add_shortcode(NAME . '-events-list', 'MobilizonConnector\EventsListShortcut::inflate');
|
||||
}
|
||||
|
||||
public static function inflate($atts = [], $content = null) {
|
||||
// Normalize attribute keys, lowercase.
|
||||
$atts = array_change_key_case((array) $atts, CASE_LOWER);
|
||||
|
||||
// Override default attributes with user attributes.
|
||||
$atts_with_overriden_defaults = shortcode_atts(
|
||||
array(
|
||||
'events-count' => DEFAULT_EVENTS_COUNT,
|
||||
'group-name' => '',
|
||||
), $atts
|
||||
);
|
||||
|
||||
$classNamePrefix = NAME;
|
||||
$eventsCount = $atts_with_overriden_defaults['events-count'];
|
||||
$locale = str_replace('_', '-', get_locale());
|
||||
$groupName = $atts_with_overriden_defaults['group-name'];
|
||||
$url = Settings::getUrl();
|
||||
$timeZone = wp_timezone_string();
|
||||
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
|
||||
|
||||
ob_start();
|
||||
require dirname(__DIR__) . '/view/events-list.php';
|
||||
$output = ob_get_clean();
|
||||
return $output;
|
||||
}
|
||||
}
|
59
source/includes/events-list-widget.php
Normal file
59
source/includes/events-list-widget.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace MobilizonConnector;
|
||||
|
||||
// Exit if this file is called directly.
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class EventsListWidget extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
NAME . '-events-list',
|
||||
NICE_NAME . ' ' . __('Events List', 'connector-mobilizon'),
|
||||
array(
|
||||
'description' => __('A list of the upcoming events of the connected Mobilizon instance.', 'connector-mobilizon'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $options) {
|
||||
echo $args['before_widget'];
|
||||
|
||||
if (!empty($options['title'])) {
|
||||
echo $args['before_title'].apply_filters('widget_title', $options['title']).$args['after_title'];
|
||||
}
|
||||
|
||||
$classNamePrefix = NAME;
|
||||
$eventsCount = $options['eventsCount'];
|
||||
$locale = str_replace('_', '-', get_locale());
|
||||
$groupName = isset($options['groupName']) ? $options['groupName'] : '';
|
||||
$url = Settings::getUrl();
|
||||
$timeZone = wp_timezone_string();
|
||||
$isShortOffsetNameShown = Settings::isShortOffsetNameShown();
|
||||
|
||||
require dirname(__DIR__) . '/view/events-list.php';
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
public function form($options) {
|
||||
$title = !empty($options['title']) ? $options['title'] : __('Events', 'connector-mobilizon');
|
||||
$eventsCount = !empty($options['eventsCount']) ? $options['eventsCount'] : DEFAULT_EVENTS_COUNT;
|
||||
$groupName = !empty($options['groupName']) ? $options['groupName'] : '';
|
||||
|
||||
require dirname(__DIR__) . '/view/events-list-widget/form.php';
|
||||
}
|
||||
|
||||
public function update($new_options, $old_options) {
|
||||
if (!current_user_can('edit_theme_options')) {
|
||||
return;
|
||||
}
|
||||
$options = array();
|
||||
$options['title'] = !empty($new_options['title']) ? sanitize_text_field($new_options['title']) : '';
|
||||
$options['eventsCount'] = !empty($new_options['eventsCount']) ? sanitize_text_field($new_options['eventsCount']) : 5;
|
||||
$options['groupName'] = !empty($new_options['groupName']) ? sanitize_text_field($new_options['groupName']) : '';
|
||||
return $options;
|
||||
}
|
||||
}
|
127
source/includes/settings.php
Normal file
127
source/includes/settings.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace MobilizonConnector;
|
||||
|
||||
// Exit if this file is called directly.
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Settings {
|
||||
|
||||
private static $DEFAULT_OPTION_URL = 'https://mobilizon.fr';
|
||||
private static $DEFAULT_IS_SHORT_OFFSET_NAME_SHOWN = false;
|
||||
private static $PAGE_NAME = 'wordpress_mobilizon';
|
||||
private static $OPTIONS_GROUP_NAME = 'wordpress_mobilizon';
|
||||
private static $OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN = 'wordpress_mobilizon_is_short_offset_name_shown';
|
||||
private static $OPTION_NAME_URL = 'wordpress_mobilizon_url';
|
||||
private static $SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN = 'wordpress_mobilizon_field_is_short_offset_name_shown';
|
||||
private static $SETTING_FIELD_NAME_URL = 'wordpress_mobilizon_field_url';
|
||||
private static $SETTINGS_SECTION_NAME = 'wordpress_mobilizon_section_general';
|
||||
|
||||
public static function init() {
|
||||
add_action('admin_init', 'MobilizonConnector\Settings::init_settings');
|
||||
add_action('admin_menu', 'MobilizonConnector\Settings::register_settings_page');
|
||||
}
|
||||
|
||||
public static function init_settings() {
|
||||
register_setting(
|
||||
self::$OPTIONS_GROUP_NAME,
|
||||
self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN
|
||||
);
|
||||
register_setting(
|
||||
self::$OPTIONS_GROUP_NAME,
|
||||
self::$OPTION_NAME_URL,
|
||||
'MobilizonConnector\Settings::validate_field_url'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
self::$SETTINGS_SECTION_NAME,
|
||||
__('General Settings', 'connector-mobilizon'),
|
||||
'',
|
||||
self::$PAGE_NAME
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
self::$SETTING_FIELD_NAME_URL,
|
||||
__('URL', 'connector-mobilizon'),
|
||||
'MobilizonConnector\Settings::output_field_url',
|
||||
self::$PAGE_NAME,
|
||||
self::$SETTINGS_SECTION_NAME,
|
||||
array(
|
||||
'label_for' => self::$SETTING_FIELD_NAME_URL
|
||||
)
|
||||
);
|
||||
add_settings_field(
|
||||
self::$SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN,
|
||||
__('Display named offset', 'connector-mobilizon'),
|
||||
'MobilizonConnector\Settings::output_field_is_short_offset_name_shown',
|
||||
self::$PAGE_NAME,
|
||||
self::$SETTINGS_SECTION_NAME,
|
||||
array(
|
||||
'label_for' => self::$SETTING_FIELD_NAME_IS_SHORT_OFFSET_NAME_SHOWN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function output_field_is_short_offset_name_shown($args) {
|
||||
$isShortOffsetNameShown = self::isShortOffsetNameShown();
|
||||
require dirname(__DIR__) . '/view/settings/is-short-offset-name-shown-field.php';
|
||||
}
|
||||
|
||||
public static function output_field_url($args) {
|
||||
$url = self::getUrl();
|
||||
require dirname(__DIR__) . '/view/settings/url-field.php';
|
||||
}
|
||||
|
||||
public static function validate_field_url($input) {
|
||||
$validated = esc_url_raw($input);
|
||||
if ($validated !== $input) {
|
||||
add_settings_error(
|
||||
self::$OPTION_NAME_URL,
|
||||
'wordpress_mobilizon_field_url_error',
|
||||
__('The URL is invalid.', 'connector-mobilizon'),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
if(substr($validated, -1) == '/') {
|
||||
$validated = substr($validated, 0, strlen($validated) - 1);
|
||||
}
|
||||
return $validated;
|
||||
}
|
||||
|
||||
public static function register_settings_page() {
|
||||
add_options_page(
|
||||
NICE_NAME . ' ' . __('Settings', 'connector-mobilizon'),
|
||||
NICE_NAME,
|
||||
'manage_options',
|
||||
NAME . '-settings',
|
||||
'MobilizonConnector\Settings::output_settings_page'
|
||||
);
|
||||
}
|
||||
|
||||
public static function output_settings_page() {
|
||||
if (!current_user_can('manage_options')) {
|
||||
return;
|
||||
}
|
||||
require dirname(__DIR__) . '/view/settings/page.php';
|
||||
}
|
||||
|
||||
public static function isShortOffsetNameShown() {
|
||||
return get_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN);
|
||||
}
|
||||
|
||||
public static function getUrl() {
|
||||
return get_option(self::$OPTION_NAME_URL);
|
||||
}
|
||||
|
||||
public static function setDefaultOptions() {
|
||||
add_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN, self::$DEFAULT_IS_SHORT_OFFSET_NAME_SHOWN);
|
||||
add_option(self::$OPTION_NAME_URL, self::$DEFAULT_OPTION_URL);
|
||||
}
|
||||
|
||||
public static function deleteAllOptions() {
|
||||
delete_option(self::$OPTION_NAME_IS_SHORT_OFFSET_NAME_SHOWN);
|
||||
delete_option(self::$OPTION_NAME_URL);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user