Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.tpl.app.mailpit.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
18{
19 const MENU = 'mailpit';
20 const MENU_VERSIONS = 'mailpitVersions';
21 const MENU_SERVICE = 'mailpitService';
22
23 const ACTION_ENABLE = 'enableMailpit';
24 const ACTION_SWITCH_VERSION = 'switchMailpitVersion';
25 const ACTION_CHANGE_PORT = 'changeMailpitPort';
26 const ACTION_INSTALL_SERVICE = 'installMailpitService';
27 const ACTION_REMOVE_SERVICE = 'removeMailpitService';
28
40 public static function process()
41 {
43
44 return TplApp::getMenuEnable($bearsamppLang->getValue(Lang::MAILPIT), self::MENU, get_called_class(), $bearsamppBins->getMailpit()->isEnable());
45 }
46
60 public static function getMenuMailpit()
61 {
63 $resultItems = $resultActions = '';
64
65 $isEnabled = $bearsamppBins->getMailpit()->isEnable();
66
67 // Download
68 $resultItems .= TplAestan::getItemLink(
70 Util::getWebsiteUrl('module/mailpit', '#releases'),
71 false,
73 ) . PHP_EOL;
74
75 // Enable
76 $tplEnable = TplApp::getActionMulti(
77 self::ACTION_ENABLE, array($isEnabled ? Config::DISABLED : Config::ENABLED),
78 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
79 false, get_called_class()
80 );
81 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
82 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
83
84 if ($isEnabled) {
85 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
86
87 // Versions
88 $tplVersions = TplApp::getMenu($bearsamppLang->getValue(Lang::VERSIONS), self::MENU_VERSIONS, get_called_class());
89 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
90 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT] . PHP_EOL;
91
92 // Service
93 $tplService = TplApp::getMenu($bearsamppLang->getValue(Lang::SERVICE), self::MENU_SERVICE, get_called_class());
94 $resultItems .= $tplService[TplApp::SECTION_CALL] . PHP_EOL;
95 $resultActions .= $tplService[TplApp::SECTION_CONTENT] . PHP_EOL;
96
97 // Web page
98 $resultItems .= TplAestan::getItemExe(
100 $bearsamppConfig->getBrowser(),
102 $bearsamppRoot->getLocalUrl() . ':' . $bearsamppBins->getMailpit()->getUiPort() . '/' . $bearsamppBins->getMailpit()->getWebRoot()
103 ) . PHP_EOL;
104
105 // Log
106 $resultItems .= TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_LOGS), $bearsamppBins->getMailpit()->getLog()) . PHP_EOL;
107 }
108
109 return $resultItems . PHP_EOL . $resultActions;
110 }
111
121 public static function getMenuMailpitVersions()
122 {
123 global $bearsamppBins;
124 $items = '';
125 $actions = '';
126
127 foreach ($bearsamppBins->getMailpit()->getVersionList() as $version) {
128 $tplSwitchMailpitVersion = TplApp::getActionMulti(
129 self::ACTION_SWITCH_VERSION, array($version),
130 array($version, $version == $bearsamppBins->getMailpit()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
131 false, get_called_class()
132 );
133
134 // Item
135 $items .= $tplSwitchMailpitVersion[TplApp::SECTION_CALL] . PHP_EOL;
136
137 // Action
138 $actions .= PHP_EOL . $tplSwitchMailpitVersion[TplApp::SECTION_CONTENT];
139 }
140
141 return $items . $actions;
142 }
143
154 public static function getActionEnableMailpit($enable)
155 {
156 global $bearsamppBins;
157
158 return TplApp::getActionRun(Action::ENABLE, array($bearsamppBins->getMailpit()->getName(), $enable)) . PHP_EOL .
160 }
161
172 public static function getActionSwitchMailpitVersion($version)
173 {
174 global $bearsamppBins;
175
176 return TplApp::getActionRun(Action::SWITCH_VERSION, array($bearsamppBins->getMailpit()->getName(), $version)) . PHP_EOL .
178 }
179
192 public static function getMenuMailpitService()
193 {
195
196 $tplChangePort = TplApp::getActionMulti(
197 self::ACTION_CHANGE_PORT, null,
199 false, get_called_class()
200 );
201
202 $isInstalled = $bearsamppBins->getMailpit()->getService()->isInstalled();
203
204 $result = TplAestan::getItemActionServiceStart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
205 TplAestan::getItemActionServiceStop($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
206 TplAestan::getItemActionServiceRestart($bearsamppBins->getMailpit()->getService()->getName()) . PHP_EOL .
207 TplAestan::getItemSeparator() . PHP_EOL .
209 Action::CHECK_PORT, array($bearsamppBins->getMailpit()->getName(), $bearsamppBins->getMailpit()->getSmtpPort()),
210 array(sprintf($bearsamppLang->getValue(Lang::MENU_CHECK_PORT), $bearsamppBins->getMailpit()->getSmtpPort()), TplAestan::GLYPH_LIGHT)
211 ) . PHP_EOL .
212 $tplChangePort[TplApp::SECTION_CALL] . PHP_EOL .
213 TplAestan::getItemNotepad($bearsamppLang->getValue(Lang::MENU_UPDATE_ENV_PATH), $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat') . PHP_EOL;
214
215 if (!$isInstalled) {
216 $tplInstallService = TplApp::getActionMulti(
217 self::ACTION_INSTALL_SERVICE, null,
219 $isInstalled, get_called_class()
220 );
221
222 $result .= $tplInstallService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
223 $tplInstallService[TplApp::SECTION_CONTENT] . PHP_EOL;
224 } else {
225 $tplRemoveService = TplApp::getActionMulti(
226 self::ACTION_REMOVE_SERVICE, null,
228 !$isInstalled, get_called_class()
229 );
230
231 $result .= $tplRemoveService[TplApp::SECTION_CALL] . PHP_EOL . PHP_EOL .
232 $tplRemoveService[TplApp::SECTION_CONTENT] . PHP_EOL;
233 }
234
235 $result .= $tplChangePort[TplApp::SECTION_CONTENT] . PHP_EOL;
236
237 return $result;
238 }
239
249 public static function getActionChangeMailpitPort()
250 {
251 global $bearsamppBins;
252
253 return TplApp::getActionRun(Action::CHANGE_PORT, array($bearsamppBins->getMailpit()->getName())) . PHP_EOL .
255 }
256
269
282}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const SWITCH_VERSION
const SERVICE
const CHANGE_PORT
const CHECK_PORT
const ENABLE
const DISABLED
const ENABLED
const MENU_ENABLE
const SERVICE
const DOWNLOAD_MORE
const MENU_CHANGE_PORT
const MENU_INSTALL_SERVICE
const MENU_UPDATE_ENV_PATH
const MENU_LOGS
const MENU_REMOVE_SERVICE
const MENU_CHECK_PORT
const MAILPIT
const VERSIONS
static getItemExe($caption, $exe, $glyph, $params=null)
const GLYPH_SERVICE_REMOVE
static getItemActionServiceStop($service)
const GLYPH_SERVICE_INSTALL
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemActionServiceStart($service)
static getItemSeparator()
static getItemActionServiceRestart($service)
static getActionMulti($action, $args=array(), $item=array(), $disabled=false, $class=false)
static getMenu($caption, $menu, $class)
static getActionRun($action, $args=array(), $item=array(), $waitUntilTerminated=true)
const SECTION_CALL
const SECTION_CONTENT
static getMenuEnable($caption, $menu, $class, $enabled=true)
static getActionInstallMailpitService()
static getActionEnableMailpit($enable)
static getActionChangeMailpitPort()
static getActionRemoveMailpitService()
static getActionSwitchMailpitVersion($version)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
global $bearsamppConfig
Definition homepage.php:27