PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 10.3.0 10.4.0 All 60 releases
acymailing / widgets / archive / widget.php

widget.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at widgets/archive/widget.php

163 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') || die('Restricted Access');
4
5 use AcyMailing\Classes\ListClass;
6 use AcyMailing\FrontControllers\ArchiveController;
7
8 class acym_archive_widget extends WP_Widget
9 {
10 public function __construct()
11 {
12 $this->loadAcyMailing();
13
14 parent::__construct(
15 'acym_archive_widget',
16 acym_translationSprintf('ACYM_MENU', acym_translation('ACYM_MENU_ARCHIVE')),
17 ['description' => acym_translation('ACYM_MENU_ARCHIVE_DESC')]
18 );
19 }
20
21 //Widget Configuration
22 public function form($instance)
23 {
24 $this->loadAcyMailing();
25
26 $params = [
27 'title' => 'See all newsletters',
28 'lists' => '',
29 'popup' => true,
30 'displayUserListOnly' => true,
31 'nbNewslettersPerPage' => '10',
32 ];
33
34 $listClass = new ListClass();
35 $lists = $listClass->getAllWithoutManagement();
36 foreach ($lists as $i => $oneList) {
37 if ($oneList->active == 0) {
38 unset($lists[$i]);
39 }
40 }
41
42 foreach ($params as $keyParam => &$valueParam) {
43 if (isset($instance[$keyParam])) {
44 $valueParam = $instance[$keyParam];
45 }
46
47 if (is_array($valueParam)) {
48 $valueParam = implode(',', $valueParam);
49 }
50
51 if (in_array($keyParam, ['popup', 'displayUserListOnly'])) {
52 $valueParam = (bool)$valueParam;
53 } else {
54 $valueParam = esc_attr($valueParam);
55 }
56 }
57
58 echo '<div class="acyblock">';
59 echo '<p><label class="acyWPconfig" for="'.esc_attr($this->get_field_id('title')).'">'.esc_html(acym_translation('ACYM_TITLE')).'</label>
60 <input type="text" class="widefat" id="'.esc_attr($this->get_field_id('title')).'" name="'.esc_attr($this->get_field_name('title')).'" value="'.esc_attr(
61 $params['title']
62 ).'" /></p>';
63 echo '<p><label class="acyWPconfig"> '.esc_html(acym_translation('ACYM_WIDGET_CAMPAIGN_NUMBER_PER_PAGE')).'</label>
64 '.wp_kses(
65 acym_translationSprintf(
66 'ACYM_X_NEWSLETTERS_PER_PAGE',
67 acym_select(
68 [
69 '5' => '5',
70 '10' => '10',
71 '15' => '15',
72 '20' => '20',
73 '30' => '30',
74 '50' => '50',
75 '100' => '100',
76 '200' => '200',
77 ],
78 $this->get_field_name('nbNewslettersPerPage'),
79 $params['nbNewslettersPerPage']
80 )
81 ),
82 [
83 'select' => [
84 'name' => true,
85 'id' => true,
86 ],
87 'option' => [
88 'value' => true,
89 'selected' => true,
90 ],
91 ]
92 ).'</p>';
93 echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_LISTS_ARCHIVE')).'">'.esc_html(acym_translation('ACYM_LISTS')).'</label>';
94 acym_selectMultiple(
95 $lists,
96 $this->get_field_name('lists'),
97 explode(',', $params['lists']),
98 [
99 'style' => 'width:100%;',
100 'id' => $this->get_field_id('lists'),
101 ],
102 'id',
103 'name',
104 true
105 );
106
107 echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_ARCHIVE_POPUP_DESC')).'">'.esc_html(acym_translation('ACYM_ARCHIVE_POPUP')).'</label>';
108 acym_boolean($this->get_field_name('popup'), $params['popup'], $this->get_field_id('popup')).'</p>';
109
110 echo '<p><label class="acyWPconfig" title="'.esc_attr(acym_translation('ACYM_ARCHIVE_ONLY_USER_LIST_DESC')).'">'.esc_html(
111 acym_translation('ACYM_ARCHIVE_ONLY_USER_LIST')
112 ).'</label>';
113 acym_boolean($this->get_field_name('displayUserListOnly'), $params['displayUserListOnly'], $this->get_field_id('displayUserListOnly')).'</p>';
114
115 echo '</div>';
116 }
117
118 // Widget's output
119 public function widget($args, $instance)
120 {
121 $this->loadAcyMailing();
122
123 if (!acym_isElementorEdition()) {
124 acym_loadAssets('archive', 'listing');
125 }
126
127 echo wp_kses_post($args['before_widget']);
128
129 if (!isset($instance['title'])) $instance['title'] = '';
130 $title = apply_filters('widget_title', $instance['title'], $instance, $args['widget_id']);
131 if (!empty($title)) {
132 echo wp_kses_post($args['before_title']);
133 echo esc_html($title);
134 echo wp_kses_post($args['after_title']);
135 }
136
137 acym_setVar('page', 'front');
138 $searchs = acym_getVar('array', 'acym_search', []);
139 $search = '';
140 if (!empty($searchs[$args['widget_id']])) $search = $searchs[$args['widget_id']];
141
142 $viewParams = [
143 'listsSent' => $instance['lists'] ?? [],
144 'popup' => $instance['popup'] ?? '1',
145 'displayUserListOnly' => $instance['displayUserListOnly'] ?? '1',
146 'paramsCMS' => ['widget_id' => $args['widget_id'], 'suffix' => ''],
147 'search' => $search,
148 'nbNewslettersPerPage' => $instance['nbNewslettersPerPage'] ?? '',
149 ];
150
151 $archiveController = new ArchiveController();
152 $archiveController->showArchive($viewParams);
153
154 echo wp_kses_post($args['after_widget']);
155 }
156
157 private function loadAcyMailing(): void
158 {
159 $ds = DIRECTORY_SEPARATOR;
160 require_once rtrim(dirname(dirname(__DIR__)), $ds).$ds.'back'.$ds.'Core'.$ds.'init.php';
161 }
162 }
163