* @license GPL-2.0+
* @link https://arlo.co
* @copyright 2018 Arlo
*/
use Arlo\Logger;
use Arlo\VersionHandler;
use Arlo\NoticeHandler;
use Arlo\SystemRequirements;
use Arlo\Utilities;
use Arlo\Importer\ImportRequest;
class Arlo_For_Wordpress_Settings {
public function __construct() {
if (!session_id()) {
session_start();
}
// allocates the wp-options option key value pair that will store the plugin settings
register_setting( 'arlo_settings', 'arlo_settings', array(
'sanitize_callback' => function($input) {
$region_id = (isset($input['regionid']) && is_array($input['regionid']) ? $input['regionid'] : []);
$input['regionid'] = array_map('strtoupper', $region_id);
return $input;
}
));
$plugin = Arlo_For_Wordpress::get_instance();
$settings_object = get_option('arlo_settings');
$message_handler = $plugin->get_message_handler();
$notice_handler = $plugin->get_notice_handler();
$this->plugin_slug = $plugin->get_plugin_slug();
if (isset($_GET['page']) && $_GET['page'] == 'arlo-for-wordpress' && get_option('permalink_structure') != "/%postname%/") {
add_action( 'admin_notices', array($notice_handler, "permalink_notice") );
}
add_action( 'admin_notices', array($notice_handler, "global_notices") );
if (get_option('arlo_plugin_disabled', '0') == '1') {
add_action( 'admin_notices', array($notice_handler, "plugin_disabled") );
} else if (get_option('arlo_import_disabled', '0') == '1') {
add_action( 'admin_notices', array($notice_handler, "import_disabled") );
}
if(isset($_GET['page']) && $_GET['page'] == 'arlo-for-wordpress') {
add_action( 'admin_notices', array($notice_handler, "arlo_notices") );
add_action( 'admin_notices', array($notice_handler, "welcome_notice") );
if (!empty($settings_object['platform_name'])) {
$show_notice = false;
foreach (Arlo_For_Wordpress::$post_types as $id => $post_type) {
if (empty($settings_object['post_types'][$id]['posts_page'])) {
$show_notice = true;
break;
}
}
if ($show_notice) {
add_action( 'admin_notices', array($notice_handler, "posttype_notice") );
}
add_action( 'admin_notices', array($notice_handler, "connected_platform_notice") );
}
if (isset($_GET['arlo-donwload-sync-log'])) {
Logger::download_log();
}
if (isset($_GET['arlo-import'])) {
if (get_option('arlo_import_disabled', '0') != '1')
$plugin->get_scheduler()->set_task("import", -1);
//do_action('arlo_scheduler');
//$plugin->import();
//die('import');
wp_redirect( admin_url( 'admin.php?page=arlo-for-wordpress'));
exit;
}
if (isset($_GET['arlo-run-scheduler'])) {
do_action('arlo_scheduler');
wp_redirect( admin_url( 'admin.php?page=arlo-for-wordpress'));
exit;
}
if (isset($_GET['load-demo'])) {
$plugin->load_demo();
wp_redirect( admin_url( 'admin.php?page=arlo-for-wordpress'));
exit;
}
$apply_theme = filter_input(INPUT_GET, 'apply-theme', FILTER_SANITIZE_STRING);
$wpnonce = filter_input(INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING);
$reset = filter_input(INPUT_GET, 'reset', FILTER_SANITIZE_STRING);
if (!empty($apply_theme) && !empty($wpnonce) && wp_verify_nonce($wpnonce, 'arlo-apply-theme-nonce')) {
$theme_id = $apply_theme;
$theme_manager = $plugin->get_theme_manager();
if ($theme_manager->is_theme_valid($theme_id)) {
$theme_settings = $theme_manager->get_themes_settings();
$stored_themes_settings = get_option( 'arlo_themes_settings', [] );
//check if there is already a stored settings for the theme, or need to be reset
if ((!empty($reset) && $reset == 1) || empty($stored_themes_settings[$theme_id])) {
$stored_themes_settings[$theme_id] = $theme_settings[$theme_id];
$stored_themes_settings[$theme_id]->templates = $theme_manager->load_default_templates($theme_id);
}
if ($stored_themes_settings[$theme_id]->templates === false && $theme_id === "custom") {
$stored_themes_settings[$theme_id] = $theme_settings['basic.list'];
$stored_themes_settings[$theme_id]->templates = $theme_manager->load_default_templates('basic.list');
}
if ($stored_themes_settings[$theme_id]->templates !== false) {
//update the main setting with the stored theme
foreach ($settings_object['templates'] as $page => $template) {
if (isset($stored_themes_settings[$theme_id]->templates[$page]['html'])) {
$settings_object['templates'][$page]['html'] = $stored_themes_settings[$theme_id]->templates[$page]['html'];
}
}
update_option('arlo_settings', $settings_object, 1);
update_option('arlo_themes_settings', $stored_themes_settings, 1);
update_option('arlo_theme', $theme_id, 1);
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress#pages') );
}
}
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress') );
}
$urlparts = parse_url(site_url());
$domain = $urlparts['host'];
$delete_shortcode = filter_input(INPUT_GET, 'delete-shortcode', FILTER_SANITIZE_STRING);
if (!empty($delete_shortcode) && !empty($wpnonce) && wp_verify_nonce($wpnonce, 'arlo-delete-shortcode-nonce')) {
unset( $_COOKIE['arlo-vertical-tab'] );
setcookie('arlo-vertical-tab', null, -1, '/', $domain);
$settings_object["delete_shortcode"] = $delete_shortcode;
update_option('arlo_settings', $settings_object);
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress#pages') );
}
if ( array_key_exists('arlo-new-custom-shortcode', $_COOKIE) ) {
$custom_shortcode = $_COOKIE['arlo-new-custom-shortcode'];
unset( $_COOKIE['arlo-new-custom-shortcode'] );
setcookie('arlo-new-custom-shortcode', null, -1, '/', $domain);
//some shared hosting doesn't delete the cookie properly
if (!isset($_SESSION['arlo-new-custom-shortcode'])) {
$_SESSION['arlo-new-custom-shortcode'] = true;
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress#pages/' . $custom_shortcode) );
} else {
unset($_SESSION['arlo-new-custom-shortcode']);
}
}
if ( array_key_exists('arlo-nav-tab', $_COOKIE) ) {
$nav_tab = $_COOKIE['arlo-nav-tab'];
unset( $_COOKIE['arlo-nav-tab'] );
setcookie('arlo-nav-tab', null, -1, '/', $domain);
//some shared hosting doesn't delete the cookie properly
if (!isset($_SESSION['arlo-nav-tab'])) {
$_SESSION['arlo-nav-tab'] = true;
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress#' . $nav_tab) );
} else {
unset($_SESSION['arlo-nav-tab']);
}
}
if ( array_key_exists('arlo-vertical-tab', $_COOKIE) ) {
$page = $_COOKIE['arlo-vertical-tab'];
unset( $_COOKIE['arlo-vertical-tab'] );
setcookie('arlo-vertical-tab', null, -1, '/', $domain);
//some shared hosting doesn't delete the cookie properly
if (!isset($_SESSION['arlo-vertical-tab'])) {
$_SESSION['arlo-vertical-tab'] = true;
wp_redirect( admin_url('admin.php?page=arlo-for-wordpress#pages/' . $page) );
} else {
unset($_SESSION['arlo-vertical-tab']);
}
}
add_action( 'admin_print_scripts', array($this, "arlo_check_current_tasks") );
}
/*
*
* General Settings
*
*/
// create a section for the API Endpoint
add_settings_section( 'arlo_general_section', __('General Settings', 'arlo-for-wordpress' ), null, 'arlo-for-wordpress' );
// create API Endpoint field
add_settings_field(
'arlo_platform_name',
''.__('Arlo domain', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'platform_name',
'label_for' => 'arlo_platform_name',
'before_html' => '
https://
',
'after_html' => '.arlo.co
',
)
);
if (!empty($settings_object['platform_name'])) {
// create last import text
add_settings_field(
'arlo_last_import',
''.__('Last import', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_text_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'html' => '' . $plugin->get_importer()->get_last_import_date() . ' UTC ' . (get_option('arlo_import_disabled', '0') != '1' ? '' . __('Synchronize now', 'arlo-for-wordpress' ) . ' ' : '' )
)
);
}
// create price settings dropdown
add_settings_field('arlo_price_setting', ''.__('Price shown', 'arlo-for-wordpress' ).' ', array($this, 'arlo_price_setting_callback'), $this->plugin_slug, 'arlo_general_section');
// create Free text field
add_settings_field(
'arlo_free_text',
''.__('"Free" text', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'free_text',
'label_for' => 'arlo_free_text',
'default_val' => __('Free', 'arlo-for-wordpress' ),
)
);
// create No events to show text field
add_settings_field(
'arlo_noevent_text',
''.__('"No events to show" text', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'noevent_text',
'label_for' => 'arlo_noevent_text',
'default_val' => __('No events to show', 'arlo-for-wordpress' ),
)
);
// create No events to show text field
add_settings_field(
'arlo_noeventontemplate_text',
''.__('No event on a template text', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'noeventontemplate_text',
'label_for' => 'arlo_noeventontemplate_text',
'default_val' => __('Interested in attending? Have a suggestion about running this event near you?', 'arlo-for-wordpress' ),
)
);
add_settings_field(
'arlo_googlemaps_api_key',
''.__('GoogleMaps API Key', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'googlemaps_api_key',
'label_for' => 'googlemaps_api_key',
)
);
add_settings_field(
'arlo_import_callback_host',
''.__('Import callback host', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'import_callback_host',
'label_for' => 'import_callback_host',
)
);
add_settings_field(
'arlo_taxexempt_tag',
''.__('Tax exempt tag', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug, 'arlo_general_section',
array(
'id' => 'taxexempt_tag',
'label_for' => 'taxexempt_tag',
)
);
add_settings_field('arlo_filters', null, array($this, 'arlo_filter_settings_callback'), $this->plugin_slug, 'arlo_general_section', array('id'=>'filters'));
/*
*
* Page Section Settings
*
*/
add_settings_section('arlo_pages_section', null, array($this, 'arlo_pages_section_callback'), $this->plugin_slug );
// loop though slug array and create each required slug field
foreach(Arlo_For_Wordpress::$templates as $id => $template) {
$name = __($template['name'], 'arlo-for-wordpress' );
add_settings_field( $id, ''.$name.' ', array($this, 'arlo_template_callback'), $this->plugin_slug, 'arlo_pages_section', array('id'=>$id,'label_for'=>$id, 'type'=> isset($template["type"]) ? $template["type"] : null) );
}
/*
*
* Regions Section Settings
*
*/
add_settings_section('arlo_regions_section', null, null, $this->plugin_slug );
add_settings_field( 'arlo_regions', null, array($this, 'arlo_regions_callback'), $this->plugin_slug, 'arlo_regions_section', array('id'=>'regions') );
/*
*
* CustomCSS Section Settings
*
*/
add_settings_section('arlo_customcss_section', null, null, $this->plugin_slug );
add_settings_field( 'arlo_customcss', null, array($this, 'arlo_simple_textarea_callback'), $this->plugin_slug, 'arlo_customcss_section', array('id'=>'customcss', 'after_html' => 'Learn how to override existing styles by adding Custom CSS
') );
/*
*
* Misc Section Settings
*
*/
add_settings_section('arlo_misc_section', __('Miscellaneous', 'arlo-for-wordpress' ), null, 'arlo-for-wordpress' );
add_settings_field(
'arlo_send_data_setting',
''.__('Allow to send data to Arlo', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_checkbox_callback'),
$this->plugin_slug,
'arlo_misc_section',
['option_name' => 'arlo_send_data']);
add_settings_field(
'arlo_keep_settings_on_delete_setting',
''.__('Keep settings when deleting the plugin (highly recommended)', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_checkbox_callback'),
$this->plugin_slug,
'arlo_misc_section',
['option_name' => 'keep_settings']);
add_settings_field(
'arlo_fragmented_import_setting',
''.__('Import fragment size (in bytes, max 10 MB)', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug,
'arlo_misc_section',
array(
'id' => 'import_fragment_size',
'label_for' => 'arlo_import_fragment_size',
'class' => 'arlo-only-numeric',
'default_val' => ImportRequest::FRAGMENT_DEFAULT_BYTE_SIZE,
));
add_settings_field(
'arlo_sleep_between_import_tasks_setting',
'' . sprintf(__('Wait between import tasks (seconds, max %s sec)', 'arlo-for-wordpress' ), \Arlo\Scheduler::MAX_SLEEP_BETWEEN_TASKS).' ',
array($this, 'arlo_simple_input_callback'),
$this->plugin_slug,
'arlo_misc_section',
array(
'id' => 'sleep_between_import_tasks',
'label_for' => 'arlo_sleep_between_import_tasks',
'class' => 'arlo-only-numeric',
'default_val' => 0,
));
add_settings_field(
'arlo_disable_ssl_verification_setting',
''.__('Disable SSL verification for import (not recommended)', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_checkbox_callback'),
$this->plugin_slug,
'arlo_misc_section',
['option_name' => 'disable_ssl_verification']);
add_settings_field(
'arlo_download_log_setting',
''.__('Download log', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_text_callback'),
$this->plugin_slug,
'arlo_misc_section',
['html' => 'Download ']);
add_settings_field(
'arlo_wp_newsletter',
''.__('Subscribe to our WP newsletter', 'arlo-for-wordpress' ).' ',
array($this, 'arlo_simple_text_callback'),
$this->plugin_slug,
'arlo_misc_section',
['html' => 'Subscribe ']);
/*
*
* Changelog Section Settings
*
*/
add_settings_section('arlo_changelog_section', null, null, $this->plugin_slug );
add_settings_field( 'arlo_changelog', null, array($this, 'arlo_changelog_callback'), $this->plugin_slug, 'arlo_changelog_section', array('id'=>'welcome') );
/* Theme Section Settings */
add_settings_section('arlo_theme_section', null, null, $this->plugin_slug );
add_settings_field( 'arlo_theme', null, array($this, 'arlo_theme_callback'), $this->plugin_slug, 'arlo_theme_section', array('id'=>'theme') );
/* Theme Section Settings */
add_settings_section('arlo_support_section', null, null, $this->plugin_slug );
add_settings_field( 'arlo_support', null, array($this, 'arlo_support_callback'), $this->plugin_slug, 'arlo_support_section', array('id'=>'support') );
/* System requirements */
add_settings_section('arlo_systemrequirements_section', __('System requirements', 'arlo-for-wordpress' ), null, 'arlo-for-wordpress' );
add_settings_field( 'arlo_systemrequirements', null, array($this, 'arlo_systemrequirements_callback'), $this->plugin_slug, 'arlo_systemrequirements_section', array('id'=>'systemrequirements') );
}
/*
*
* SECTION CALLBACKS
*
*/
function arlo_pages_section_callback() {
echo '
';
}
/*
*
* FIELD CALLBACKS
*
*/
function arlo_simple_textarea_callback($args) {
$settings_object = get_option('arlo_settings');
$val = (isset($settings_object[$args['id']])) ? esc_attr($settings_object[$args['id']]) : (!empty($args['default_val']) ? $args['default_val'] : '' );
$html = '';
if (!empty($args['before_html'])) {
$html .= $args['before_html'];
}
$html .= '';
if (!empty($args['after_html'])) {
$html .= $args['after_html'];
}
echo $html;
}
function arlo_price_setting_callback() {
$settings_object = get_option('arlo_settings');
$setting_id = 'price_setting';
$output = '';
$output .= '';
$val = (isset($settings_object[$setting_id])) ? esc_attr($settings_object[$setting_id]) : ARLO_PLUGIN_PREFIX . '-exclgst';
foreach(Arlo_For_Wordpress::$price_settings as $key => $value) {
$key = ARLO_PLUGIN_PREFIX . '-' . $key;
$selected = $key == $val ? 'selected="selected"' : '';
$output .= ''.$value.' ';
}
$output .= '
';
echo $output;
}
function arlo_filter_settings_callback() {
$filter_actions = [
'rename' => __('Rename', 'arlo-for-wordpress'),
'exclude' => __('Exclude', 'arlo-for-wordpress')
];
$output = '';
$output .= '
Filter terminology ';
$available_page_filters = array(
'generic' => array(
'name' => 'Generic',
'filters' => array(
'delivery' => 'Delivery',
)
)
);
$output .= $this->arlo_output_filter_editor('arlo_filter_settings', $available_page_filters, 'generic', 'generic', $filter_actions, '', 'arlo-always-visible');
$output .= '';
echo $output;
}
function get_select_filter_options(&$item, $key, $options = []) {
if (empty($item['string']) && empty($item['value'])) {
$item = array(
'string' => $item,
'value' => $key,
'id' => $key
);
}
extract($options);
$value = (isset($value_field) && isset($item[$value_field]) ? $item[$value_field] : $item["string"]);
$selected = (isset($selected_value) && ($value == htmlentities($selected_value) || !strcmp($value, $selected_value)) ? ' selected="selected" ' : '');
$item = "" . esc_html($item["string"]) . " ";
}
function arlo_checkbox_callback($args) {
if (empty($args['option_name'])) return;
$option_name = $args['option_name'];
$settings_object = get_option('arlo_settings');
$output = '';
$output .= ' ';
$output .= '
';
echo $output;
}
function arlo_simple_input_callback($args) {
$settings_object = get_option('arlo_settings');
$val = (isset($settings_object[$args['id']])) ? esc_attr($settings_object[$args['id']]) : (!empty($args['default_val']) ? $args['default_val'] : '' );
$html = '';
if (!empty($args['before_html'])) {
$html .= $args['before_html'];
}
$html .= ' ';
if (!empty($args['after_html'])) {
$html .= $args['after_html'];
}
echo $html;
}
function arlo_simple_text_callback($args) {
$html = '';
if (!empty($args['html'])) {
$html .= $args['html'];
}
echo $html;
}
function arlo_template_callback($args) {
$id = $args['id'];
$type = isset($args['type']) ? $args['type'] : $args['id'];
$settings_object = get_option('arlo_settings');
$is_new_shortcode_page = $id == 'new_custom';
$is_custom_shortcode = isset( $args['type'] );
echo '';
if ($is_new_shortcode_page) {
echo 'New custom shortcode';
} else {
echo sprintf(__('%s page', 'arlo-for-wordpress' ), Arlo_For_Wordpress::$templates[$id]['name']);
if ($is_custom_shortcode) {
echo ' Delete ';
}
}
echo ' ';
if ($is_custom_shortcode) {
$type_name = ($type == 'events' ? 'catalogue' : $type);
echo '
' . __("Shortcode type", 'arlo-for-wordpress' ) . '
'.ucfirst($type_name).' '.__('page', 'arlo-for-wordpress' ).'
';
}
/*
HACK because the keys in the $post_types arrays are bad, couldn't change because backward comp.
*/
if (!in_array($id, array('event', 'presenter', 'venue'))) {
$post_type_id = in_array($id, array('events','presenters', 'venues')) ? substr($id, 0, strlen($id)-1) : $id;
}
if (!empty($post_type_id) && !empty(Arlo_For_Wordpress::$post_types[$post_type_id])) {
$post_type = Arlo_For_Wordpress::$post_types[$post_type_id];
$val = isset($settings_object['post_types'][$post_type_id]['posts_page']) ? esc_attr($settings_object['post_types'][$post_type_id]['posts_page']) : 0;
$select = wp_dropdown_pages(array(
'id' => 'arlo_'.$post_type_id.'_posts_page',
'selected' => $val,
'echo' => 0,
'name' => 'arlo_settings[post_types]['.$post_type_id.'][posts_page]',
'show_option_none' => '-- Select --',
'option_none_value' => 0
));
$shortcode_documentation_url = "https://developer.arlo.co/doc/wordpress/shortcodes/globalshortcodes#" . str_replace( "]", "", str_replace( "[", "", Arlo_For_Wordpress::$templates[$type]['shortcode'] ) );
echo '
' . __("Host page", 'arlo-for-wordpress' ) . '
' . $select . '
' . sprintf(__('Page must contain the %s shortcode. Shortcode customisation options. ', 'arlo-for-wordpress' ), Arlo_For_Wordpress::$templates[$id]['shortcode'], $shortcode_documentation_url) . '
';
}
if ($is_new_shortcode_page) {
$this->arlo_output_new_shortcode_page();
} else {
$this->arlo_output_template_page($settings_object, $id, $type);
}
}
function arlo_output_template_page($settings_object, $id, $type) {
$val = isset($settings_object['templates'][$id]['html']) ? $settings_object['templates'][$id]['html'] : '';
$this->arlo_reload_template($id);
if ( isset(Arlo_For_Wordpress::$templates[$id]['shortcode']) ) {
echo '
'
. sprintf(__('%s page ', 'arlo-for-wordpress' ), Arlo_For_Wordpress::$templates[$id]['name'])
. 'shortcode ' . Arlo_For_Wordpress::$templates[$id]['shortcode'] . ' '
. ' content
';
}
echo '
';
wp_editor($val, $id, array('textarea_name'=>'arlo_settings[templates]['.$id.'][html]','textarea_rows'=>'20'));
echo '
' . __('Page filtered by ', 'arlo-for-wordpress' ) . '
' . $this->arlo_output_filter_editor('arlo_page_filter_settings', Arlo_For_Wordpress::$available_page_filters, $type, $id, Arlo_For_Wordpress::$page_filter_options, 'page', 'arlo-always-visible') . '
';
}
function arlo_output_new_shortcode_page() {
echo '
' . __("Shortcode name", 'arlo-for-wordpress' ) . '
[arlo_ ]
';
echo '
' . __("Shortcode type", 'arlo-for-wordpress' ) . '
';
echo ' ';
foreach (Arlo_For_Wordpress::$shortcode_types as $shortcode_type => $shortcode_type_name) {
echo ''.$shortcode_type_name.' ';
}
echo '
';
echo '
';
}
function arlo_reload_template($template) {
$selected_theme_id = get_option('arlo_theme', Arlo_For_Wordpress::DEFAULT_THEME);
if ($selected_theme_id != 'custom') {
echo '
'. __('Template', 'arlo-for-wordpress' ) . '
';
}
}
function arlo_output_filter_editor($setting_name, $available_page_filters, $filter_type, $filter_group, $actions = [], $id_prefix = '', $class = '') {
$filters_settings_html = '';
$filter_settings = get_option($setting_name, array());
//hack, because the key in the templates are not the same as in the filters
$filter_type = ($filter_type == 'events' ? 'template' : $filter_type);
$filter_group_values = (isset($available_page_filters[$filter_type]) ? $available_page_filters[$filter_type] : []);
$available_filters = [];
if (isset($filter_group_values['filters']) && is_array($filter_group_values['filters'])) {;
$available_filters = $filter_group_values['filters'];
}
$filters_settings_html .= '';
$import_id = Arlo_For_Wordpress::get_instance()->get_importer()->get_current_import_id();
if (count($available_filters) && !empty($import_id)) {
foreach($available_filters as $filter_key => $filter) {
$filter_options = \Arlo\Shortcodes\Filters::get_filter_options($filter_key, $import_id);
$default_filter_options = $filter_options;
array_walk($default_filter_options, 'self::get_select_filter_options', ['value_field' => 'id']);
$expand_filter = (!empty($filter_settings[$filter_group][$filter_key]) && count($filter_settings[$filter_group][$filter_key]))
|| (!empty($filter_settings["hiddenfilters"][$filter_group][$filter_key]))
|| (!empty($filter_settings["showonlyfilters"][$filter_group][$filter_key]));
$filters_settings_html .= '
' . __($filter,'arlo-for-wordpress') . '
' . $this->arlo_output_filter_actions($actions, $setting_name, $default_filter_options, $filter_group, $filter_key, '', 'setting_id') . '
';
if (is_array($filter_settings)) {
if (!empty($filter_settings[$filter_group][$filter_key]) && count($filter_settings[$filter_group][$filter_key])) {
foreach($filter_settings[$filter_group][$filter_key] as $old_value => $new_value) {
/* rename entries */
$filter_rename_setting_options = $filter_options;
array_walk($filter_rename_setting_options, 'self::get_select_filter_options', ['selected_value' => $old_value, 'value_field' => 'id']);
$filters_settings_html .= $this->arlo_output_filter_actions($actions, $setting_name, $filter_rename_setting_options, $filter_group, $filter_key, $new_value, rand(), 'rename');
}
}
if (!empty($filter_settings["hiddenfilters"][$filter_group][$filter_key])) {
foreach($filter_settings["hiddenfilters"][$filter_group][$filter_key] as $old_value) {
/* hidden/exclude entries */
$filter_hidden_setting_options = $filter_options;
array_walk($filter_hidden_setting_options, 'self::get_select_filter_options', ['selected_value' => $old_value, 'value_field' => 'id']);
$filters_settings_html .= $this->arlo_output_filter_actions($actions, $setting_name, $filter_hidden_setting_options, $filter_group, $filter_key, '', rand(), 'exclude');
}
}
if (!empty($filter_settings["showonlyfilters"][$filter_group][$filter_key])) {
foreach($filter_settings["showonlyfilters"][$filter_group][$filter_key] as $old_value) {
/* show only entries */
$filter_hidden_setting_options = $filter_options;
array_walk($filter_hidden_setting_options, 'self::get_select_filter_options', ['selected_value' => $old_value, 'value_field' => 'id']);
$filters_settings_html .= $this->arlo_output_filter_actions($actions, $setting_name, $filter_hidden_setting_options, $filter_group, $filter_key, '', rand(), 'showonly');
}
}
}
/* Empty entry */
array_walk($filter_options, 'self::get_select_filter_options', ['value_field' => 'id']);
$filters_settings_html .= $this->arlo_output_filter_actions($actions, $setting_name, $filter_options, $filter_group, $filter_key, '', rand());
$filters_settings_html .= ' ';
}
} else {
$filters_settings_html .= '
' . __('No filter option available', 'arlo-for-wordpress') . '
';
}
$filters_settings_html .= '
';
return $filters_settings_html;
}
function arlo_output_filter_actions($actions, $setting_name, $filter_options_array = [], $filter_group, $filter_key, $filter_new_value, $settings_id, $selected_action = '') {
$option_html = '
';
if (is_array($actions) && count($actions)) {
$actions = array_merge(['' => __('Select an action', 'arlo-for-wordpress')], $actions);
$option_html .= '
';
foreach ($actions as $value => $text) {
$selected = ($value == $selected_action ? 'selected="selected"' : '');
$option_html .= sprintf('%s ', esc_attr($value), $selected, esc_html($text));
}
$option_html .= '
';
}
$option_html .= '
Select an option ' .
implode($filter_options_array, '')
. '
';
return $option_html;
}
function arlo_check_current_tasks() {
global $wpdb;
$plugin = Arlo_For_Wordpress::get_instance();
$scheduler = $plugin->get_scheduler();
$next_immediate_task = $scheduler->get_next_immediate_tasks();
$next_immediate_task_ids = [];
$running_task = $scheduler->get_running_tasks();
$running_task_ids = [];
$running_task = array_merge($running_task, $scheduler->get_paused_tasks());
foreach ($next_immediate_task as $task) {
$next_immediate_task_ids[] = $task->task_id;
}
foreach ($running_task as $task) {
$running_task_ids[] = $task->task_id;
}
echo "
";
}
function arlo_regions_callback($args) {
$regions = get_option('arlo_regions', array());
echo '
Regions
Please specify your available regions in Arlo.
Please note, when you change the regions, you have to re-synchronize the data.
For more information, please visit our documentation
';
}
function arlo_changelog_callback($args) {
echo '
What\'s new in this release
If you are experiencing problems after an update, please deactivate and re-activate the plugin and re-synchronize the data.
Version ' . VersionHandler::VERSION . '
Version 3.9
Version 3.8.1
Load balanced architectures do not allow the import to run correctly
Version 3.8
More change log
';
}
function arlo_systemrequirements_callback () {
$good = ' ';
$bad = ' ';
echo '
Setting
Expected
Current
';
foreach (SystemRequirements::get_system_requirements() as $req) {
$current_value = $req['current_value']();
$check = $req['check']($current_value, $req['expected_value']);
$good_or_bad = ($check === null ? '' : ($check ? $good : $bad));
$green_or_red = ($check === null ? '' : ($check ? 'green' : 'red'));
echo '
' . $good_or_bad . '
' . $req['name'] . '
' . $req['expected_value'] . '
' . $current_value . '
';
}
echo '
';
}
function arlo_support_callback () {
echo '
' . __('Support', 'arlo-for-wordpress') . '
';
}
function arlo_theme_callback($args) {
$plugin = Arlo_For_Wordpress::get_instance();
$theme_manager = $plugin->get_theme_manager();
$themes = $theme_manager->get_themes_settings();
$selected_theme_id = get_option('arlo_theme', Arlo_For_Wordpress::DEFAULT_THEME);
echo '
Select Arlo for WordPress control theme
' . __('Arlo powered pages will be updated to match the Arlo control theme selected.', 'arlo-for-wordpress' ) . '
Learn about themes "For designers" .
Learn how to override existing styles by adding Custom CSS
';
foreach ($themes as $theme_num => $theme_data) {
$desc = $images = [];
if (!empty($theme_data->images) && is_array($theme_data->images)) {
foreach ($theme_data->images as $image) {
$images[] = ' ';
}
}
$overlay = '
' . (!empty($theme_data->icon) ? '
' : '') . '
' . htmlentities(strip_tags($theme_data->name)) . '
' . $theme_data->description . '
' . (!empty($theme_data->forDesigners) && $theme_data->forDesigners ? '
' : '') . '
';
$desc = array_merge($desc, $images);
if (!count($desc)) {
$desc[] = $overlay;
}
echo '
' . (!empty($theme_data->forDesigners) && $theme_data->forDesigners ? '
For designers
' : '') . '
' . $desc[0] . '
' . $overlay . '
';
}
echo '
' . __('Themes that include "For designers" label provide maximum flexibility as they inherit some of the main website’s styles. They will however require additional work by a web designer to fix any inadvertent styling issues.', 'arlo-for-wordpress' ) . '
' . __('Learn more', 'arlo-for-wordpress') . '
';
}
}