| @@ -1,135 +1,0 @@ | ||
| 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' => '1', | |
| 27 | - 'displayUserListOnly' => '1', | |
| 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 | - $valueParam = esc_attr($valueParam); | |
| 49 | - } | |
| 50 | - | |
| 51 | - echo '<div class="acyblock">'; | |
| 52 | - echo '<p><label class="acyWPconfig" for="'.$this->get_field_id('title').'">'.acym_translation('ACYM_TITLE').'</label> | |
| 53 | - <input type="text" class="widefat" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" value="'.$params['title'].'" /></p>'; | |
| 54 | - echo '<p><label class="acyWPconfig"> '.acym_translation('ACYM_WIDGET_CAMPAIGN_NUMBER_PER_PAGE').'</label> | |
| 55 | - '.acym_translationSprintf( | |
| 56 | - 'ACYM_X_NEWSLETTERS_PER_PAGE', | |
| 57 | - acym_select( | |
| 58 | - [ | |
| 59 | - '5' => '5', | |
| 60 | - '10' => '10', | |
| 61 | - '15' => '15', | |
| 62 | - '20' => '20', | |
| 63 | - '30' => '30', | |
| 64 | - '50' => '50', | |
| 65 | - '100' => '100', | |
| 66 | - '200' => '200', | |
| 67 | - ], | |
| 68 | - $this->get_field_name('nbNewslettersPerPage'), | |
| 69 | - $params['nbNewslettersPerPage'] | |
| 70 | - ) | |
| 71 | - ).'</p>'; | |
| 72 | - echo '<p><label class="acyWPconfig" title="'.acym_translation('ACYM_LISTS_ARCHIVE').'">'.acym_translation('ACYM_LISTS').'</label>'; | |
| 73 | - echo acym_selectMultiple( | |
| 74 | - $lists, | |
| 75 | - $this->get_field_name('lists'), | |
| 76 | - explode(',', $params['lists']), | |
| 77 | - [ | |
| 78 | - 'style' => 'width:100%;', | |
| 79 | - 'id' => $this->get_field_id('lists'), | |
| 80 | - ], | |
| 81 | - 'id', | |
| 82 | - 'name' | |
| 83 | - ); | |
| 84 | - | |
| 85 | - echo '<p><label class="acyWPconfig" title="'.acym_translation('ACYM_ARCHIVE_POPUP_DESC').'">'.acym_translation('ACYM_ARCHIVE_POPUP').'</label>'; | |
| 86 | - echo acym_boolean($this->get_field_name('popup'), $params['popup'], $this->get_field_id('popup')).'</p>'; | |
| 87 | - | |
| 88 | - echo '<p><label class="acyWPconfig" title="'.acym_translation('ACYM_ARCHIVE_ONLY_USER_LIST_DESC').'">'.acym_translation('ACYM_ARCHIVE_ONLY_USER_LIST').'</label>'; | |
| 89 | - echo acym_boolean($this->get_field_name('displayUserListOnly'), $params['displayUserListOnly'], $this->get_field_id('displayUserListOnly')).'</p>'; | |
| 90 | - | |
| 91 | - echo '</div>'; | |
| 92 | - } | |
| 93 | - | |
| 94 | - public function widget($args, $instance) | |
| 95 | - { | |
| 96 | - $this->loadAcyMailing(); | |
| 97 | - | |
| 98 | - if (!acym_isElementorEdition()) { | |
| 99 | - acym_loadAssets('archive', 'listing'); | |
| 100 | - } | |
| 101 | - | |
| 102 | - echo $args['before_widget']; | |
| 103 | - | |
| 104 | - if (!isset($instance['title'])) $instance['title'] = ''; | |
| 105 | - $title = apply_filters('widget_title', $instance['title'], $instance, $args['widget_id']); | |
| 106 | - if (!empty($title)) { | |
| 107 | - echo $args['before_title'].$title.$args['after_title']; | |
| 108 | - } | |
| 109 | - | |
| 110 | - acym_setVar('page', 'front'); | |
| 111 | - $searchs = acym_getVar('array', 'acym_search', []); | |
| 112 | - $search = ''; | |
| 113 | - if (!empty($searchs[$args['widget_id']])) $search = $searchs[$args['widget_id']]; | |
| 114 | - | |
| 115 | - $viewParams = [ | |
| 116 | - 'listsSent' => $instance['lists'] ?? [], | |
| 117 | - 'popup' => $instance['popup'] ?? '1', | |
| 118 | - 'displayUserListOnly' => $instance['displayUserListOnly'] ?? '1', | |
| 119 | - 'paramsCMS' => ['widget_id' => $args['widget_id'], 'suffix' => ''], | |
| 120 | - 'search' => $search, | |
| 121 | - 'nbNewslettersPerPage' => $instance['nbNewslettersPerPage'] ?? '', | |
| 122 | - ]; | |
| 123 | - | |
| 124 | - $archiveController = new ArchiveController(); | |
| 125 | - $archiveController->showArchive($viewParams); | |
| 126 | - | |
| 127 | - echo $args['after_widget']; | |
| 128 | - } | |
| 129 | - | |
| 130 | - private function loadAcyMailing(): void | |
| 131 | - { | |
| 132 | - $ds = DIRECTORY_SEPARATOR; | |
| 133 | - require_once rtrim(dirname(dirname(__DIR__)), $ds).$ds.'back'.$ds.'Core'.$ds.'init.php'; | |
| 134 | - } | |
| 135 | -} | |