| @@ -1,0 +1,173 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\ListClass; | |
| 6 | +use AcyMailing\FrontControllers\FrontusersController; | |
| 7 | +use AcyMailing\Core\AcymParameter; | |
| 8 | + | |
| 9 | +class acym_profile_widget extends WP_Widget | |
| 10 | +{ | |
| 11 | + public function __construct() | |
| 12 | + { | |
| 13 | + $this->loadAcyMailing(); | |
| 14 | + | |
| 15 | + parent::__construct( | |
| 16 | + 'acym_profile_widget', | |
| 17 | + acym_translationSprintf('ACYM_MENU', acym_translation('ACYM_MENU_PROFILE')), | |
| 18 | + ['description' => acym_translation('ACYM_MENU_PROFILE_DESC')] | |
| 19 | + ); | |
| 20 | + } | |
| 21 | + | |
| 22 | + // Configuration | |
| 23 | + public function form($instance) | |
| 24 | + { | |
| 25 | + $this->loadAcyMailing(); | |
| 26 | + | |
| 27 | + acym_addStyle(false, ACYM_CSS.'widget.min.css?v='.filemtime(ACYM_MEDIA.'css'.DS.'widget.min.css')); | |
| 28 | + | |
| 29 | + $listClass = new ListClass(); | |
| 30 | + $lists = $listClass->getAllWithoutManagement(); | |
| 31 | + foreach ($lists as $i => $oneList) { | |
| 32 | + if ($oneList->active == 0) { | |
| 33 | + unset($lists[$i]); | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + $params = [ | |
| 38 | + 'title' => 'Your profile', | |
| 39 | + 'lists' => 'All', | |
| 40 | + 'listschecked' => 'None', | |
| 41 | + 'dropdown' => false, | |
| 42 | + 'hiddenlists' => 'None', | |
| 43 | + 'fields' => '1', | |
| 44 | + 'introtext' => '', | |
| 45 | + 'posttext' => '', | |
| 46 | + 'source' => 'profile __i__', | |
| 47 | + ]; | |
| 48 | + | |
| 49 | + foreach ($params as $oneParam => &$value) { | |
| 50 | + if (!empty($instance)) { | |
| 51 | + $value = $instance[$oneParam] ?? ''; | |
| 52 | + } | |
| 53 | + | |
| 54 | + if (is_array($value)) { | |
| 55 | + $value = implode(',', $value); | |
| 56 | + } | |
| 57 | + | |
| 58 | + if (in_array($oneParam, ['dropdown'])) { | |
| 59 | + $value = (bool)$value; | |
| 60 | + } else { | |
| 61 | + $value = esc_attr($value); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + | |
| 65 | + if (!isset($instance['hiddenlists']) && !empty($params['lists'])) { | |
| 66 | + $params['hiddenlists'] = ''; | |
| 67 | + } | |
| 68 | + | |
| 69 | + echo '<div class="acym_toggle_zone"> | |
| 70 | + <div class="acyblock" id="mainopt_profilewidget"> | |
| 71 | + <div class="acym_toggle_div_title"> | |
| 72 | + <h3>'.esc_html(acym_translation('ACYM_MAIN_OPTIONS')).'</h3> | |
| 73 | + </div> | |
| 74 | + <div class="acym_toggle_div" style="display: none;">'; | |
| 75 | + | |
| 76 | + echo '<p><label class="acyWPconfig" for="'.esc_attr($this->get_field_id('title')).'">'.esc_html(acym_translation('ACYM_TITLE')).'</label> | |
| 77 | + <input type="text" class="widefat" id="'.esc_attr($this->get_field_id('title')).'" name="'.esc_attr($this->get_field_name('title')).'" value="'.esc_attr( | |
| 78 | + $params['title'] | |
| 79 | + ).'" /></p>'; | |
| 80 | + | |
| 81 | + | |
| 82 | + echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_VISIBLE_LISTS_DESC')).'">'.esc_html(acym_translation('ACYM_VISIBLE_LISTS')).'</label>'; | |
| 83 | + acym_displayParam('lists', $params['lists'], $this->get_field_name('lists')).'</p>'; | |
| 84 | + | |
| 85 | + echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_DROPDOWN_LISTS_DESC')).'">'.esc_html(acym_translation('ACYM_DROPDOWN_LISTS')).'</label>'; | |
| 86 | + acym_boolean($this->get_field_name('dropdown'), $params['dropdown'], $this->get_field_id('dropdown')).'</p>'; | |
| 87 | + | |
| 88 | + echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_LISTS_CHECKED_DEFAULT_DESC')).'">'.esc_html( | |
| 89 | + acym_translation('ACYM_LISTS_CHECKED_DEFAULT') | |
| 90 | + ).'</label>'; | |
| 91 | + acym_displayParam('lists', $params['listschecked'], $this->get_field_name('listschecked')).'</p>'; | |
| 92 | + | |
| 93 | + echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_AUTO_SUBSCRIBE_TO_DESC')).'">'.esc_html(acym_translation('ACYM_AUTO_SUBSCRIBE_TO')).'</label>'; | |
| 94 | + acym_displayParam('lists', $params['hiddenlists'], $this->get_field_name('hiddenlists')).'</p>'; | |
| 95 | + | |
| 96 | + echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_FIELDS_TO_DISPLAY_DESC')).'">'.esc_html(acym_translation('ACYM_FIELDS_TO_DISPLAY')).'</label>'; | |
| 97 | + acym_displayParam('fields', $params['fields'], $this->get_field_name('fields')).'</p>'; | |
| 98 | + | |
| 99 | + echo '</div> | |
| 100 | + </div> | |
| 101 | + <div class="acyblock" id="advopt_profilewidget"> | |
| 102 | + <div class="acym_toggle_div_title"> | |
| 103 | + <h3>'.esc_html(acym_translation('ACYM_ADVANCED_OPTIONS')).'</h3> | |
| 104 | + </div> | |
| 105 | + <div class="acym_toggle_div" style="display: none;">'; | |
| 106 | + | |
| 107 | + echo '<p><label class="acyWPconfig" for="'.esc_attr($this->get_field_id('introtext')).'" title="'.esc_attr(acym_translation('ACYM_INTRO_TEXT_DESC')).'">'.esc_html( | |
| 108 | + acym_translation('ACYM_INTRO_TEXT') | |
| 109 | + ).'</label> | |
| 110 | + <textarea class="widefat" id="'.esc_attr($this->get_field_id('introtext')).'" name="'.esc_attr($this->get_field_name('introtext')).'" >'.esc_html( | |
| 111 | + $params['introtext'] | |
| 112 | + ).'</textarea></p>'; | |
| 113 | + | |
| 114 | + echo '<p><label class="acyWPconfig" for="'.esc_attr($this->get_field_id('posttext')).'" title="'.esc_attr(acym_translation('ACYM_POST_TEXT_DESC')).'">'.esc_html( | |
| 115 | + acym_translation('ACYM_POST_TEXT') | |
| 116 | + ).'</label> | |
| 117 | + <textarea class="widefat" id="'.esc_attr($this->get_field_id('posttext')).'" name="'.esc_attr($this->get_field_name('posttext')).'" >'.esc_html( | |
| 118 | + $params['posttext'] | |
| 119 | + ).'</textarea></p>'; | |
| 120 | + | |
| 121 | + echo '<p><label class="acyWPconfig" for="'.esc_attr($this->get_field_id('source')).'" title="'.esc_attr(acym_translation('ACYM_SOURCE_DESC')).'">'.esc_html( | |
| 122 | + acym_translation('ACYM_SOURCE') | |
| 123 | + ).'</label> | |
| 124 | + <input type="text" class="widefat" id="'.esc_attr($this->get_field_id('source')).'" name="'.esc_attr($this->get_field_name('source')).'" value="'.esc_attr( | |
| 125 | + $params['source'] | |
| 126 | + ).'" /></p>'; | |
| 127 | + | |
| 128 | + echo '</div></div></div>'; | |
| 129 | + } | |
| 130 | + | |
| 131 | + // Widget's output | |
| 132 | + public function widget($args, $instance) | |
| 133 | + { | |
| 134 | + $this->loadAcyMailing(); | |
| 135 | + | |
| 136 | + if (!acym_isElementorEdition()) { | |
| 137 | + acym_loadAssets('frontusers', 'profile'); | |
| 138 | + } | |
| 139 | + | |
| 140 | + echo wp_kses_post($args['before_widget']); | |
| 141 | + | |
| 142 | + if (!isset($instance['title'])) $instance['title'] = ''; | |
| 143 | + $title = apply_filters('widget_title', $instance['title'], $instance, $args['widget_id']); | |
| 144 | + if (!empty($title)) { | |
| 145 | + echo wp_kses_post($args['before_title']); | |
| 146 | + echo esc_html($title); | |
| 147 | + echo wp_kses_post($args['after_title']); | |
| 148 | + } | |
| 149 | + | |
| 150 | + acym_setVar('page', ACYM_COMPONENT.'_front'); | |
| 151 | + $params = new AcymParameter($instance); | |
| 152 | + acym_initModule($params); | |
| 153 | + | |
| 154 | + $userController = new FrontusersController(); | |
| 155 | + $data = $userController->prepareParams((object)$instance); | |
| 156 | + | |
| 157 | + if (empty($data['user']->language)) { | |
| 158 | + $cmsUserLanguage = acym_getCmsUserLanguage(); | |
| 159 | + $data['user']->language = empty($cmsUserLanguage) ? acym_getLanguageTag() : $cmsUserLanguage; | |
| 160 | + } | |
| 161 | + | |
| 162 | + acym_setVar('layout', 'profile'); | |
| 163 | + $userController->display($data); | |
| 164 | + | |
| 165 | + echo wp_kses_post($args['after_widget']); | |
| 166 | + } | |
| 167 | + | |
| 168 | + private function loadAcyMailing(): void | |
| 169 | + { | |
| 170 | + $ds = DIRECTORY_SEPARATOR; | |
| 171 | + require_once rtrim(dirname(dirname(__DIR__)), $ds).$ds.'back'.$ds.'Core'.$ds.'init.php'; | |
| 172 | + } | |
| 173 | +} | |