PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
11.1.1 11.1.0 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 All 62 releases
acymailing / widgets / archive / widget.php

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

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