2024.8.23
Loading...
Searching...
No Matches
class.tpl.aestan.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
10/**
11 * Class TplAestan
12 *
13 * This class provides various methods to generate configuration strings for the Bearsampp application.
14 * It includes methods to create items for ConsoleZ, links, Notepad, executables, and explorer actions.
15 * Additionally, it handles service actions such as start, stop, and restart, and generates configuration
16 * sections for messages, config, and menu settings.
17 *
18 * Constants:
19 * - Glyph constants for various icons used in the application.
20 * - Service actions for starting, stopping, and restarting services.
21 * - Image files used in the application.
22 *
23 * Methods:
24 * - getGlyphFlah($lang): Retrieves the glyph flag for a given language.
25 * - getItemSeparator(): Returns a string representing a separator item.
26 * - getItemConsoleZ($caption, $glyph, $id, $title, $initDir, $command): Returns a string representing a ConsoleZ item.
27 * - getItemLink($caption, $link, $local, $glyph): Returns a string representing a link item.
28 * - getItemNotepad($caption, $path): Returns a string representing a Notepad item.
29 * - getItemExe($caption, $exe, $glyph, $params): Returns a string representing an executable item.
30 * - getItemExplore($caption, $path): Returns a string representing an explorer item.
31 * - getActionService($service, $action, $item): Returns a string representing a service action.
32 * - getActionServiceStart($service): Returns a string representing a service start action.
33 * - getItemActionServiceStart($service): Returns a string representing a service start item.
34 * - getActionServiceStop($service): Returns a string representing a service stop action.
35 * - getItemActionServiceStop($service): Returns a string representing a service stop item.
36 * - getActionServiceRestart($service): Returns a string representing a service restart action.
37 * - getItemActionServiceRestart($service): Returns a string representing a service restart item.
38 * - getActionServicesClose(): Returns a string representing a close services action.
39 * - getItemActionServicesClose(): Returns a string representing a close services item.
40 * - getSectionMessages(): Returns a string representing the messages section.
41 * - getSectionConfig(): Returns a string representing the config section.
42 * - getSectionMenuRightSettings(): Returns a string representing the right menu settings section.
43 * - getSectionMenuLeftSettings($caption): Returns a string representing the left menu settings section.
44 */
46{
47 // Glyph constants
48 const GLYPH_CONSOLEZ = 0;
49 const GLYPH_ADD = 1;
52 const GLYPH_BROWSER = 5;
53 const GLYPH_FILE = 6;
56 const GLYPH_START = 9;
57 const GLYPH_PAUSE = 10;
58 const GLYPH_STOP = 11;
59 const GLYPH_RELOAD = 12;
60 const GLYPH_CHECK = 13;
64 const GLYPH_WARNING = 19;
65 const GLYPH_EXIT = 20;
66 const GLYPH_ABOUT = 21;
70 const GLYPH_LIGHT = 25;
71 const GLYPH_GIT = 26;
72 const GLYPH_NODEJS = 28;
73 const GLYPH_NETWORK = 29;
74 const GLYPH_WEB_PAGE = 30;
75 const GLYPH_DEBUG = 31;
76 const GLYPH_TRASHCAN = 32;
77 const GLYPH_UPDATE = 33;
78 const GLYPH_RESTART = 34;
80 const GLYPH_RED_LIGHT = 36;
81 const GLYPH_COMPOSER = 37;
82 const GLYPH_PEAR = 38;
85 const GLYPH_NOTEPAD2 = 42;
86 const GLYPH_PASSWORD = 45;
87 const GLYPH_FILEZILLA = 47;
90 const GLYPH_PYTHON = 50;
91 const GLYPH_PYTHON_CP = 51;
92 const GLYPH_RUBY = 52;
93 const GLYPH_YARN = 54;
94 const GLYPH_PERL = 55;
96 const GLYPH_NGROK = 57;
97 const GLYPH_PWGEN = 58;
98 const GLYPH_XLIGHT = 59;
100
101 // Service actions
102 const SERVICE_START = 'startresume';
103 const SERVICE_STOP = 'stop';
104 const SERVICE_RESTART = 'restart';
105 const SERVICES_CLOSE = 'closeservices';
106
107 // Image files
108 const IMG_BAR_PICTURE = 'bar.dat';
109 const IMG_GLYPH_SPRITES = 'sprites.dat';
110
111 /**
112 * Retrieves the glyph flag for a given language.
113 *
114 * @param string $lang The language code.
115 * @return void
116 */
117 public static function getGlyphFlah($lang)
118 {
119 }
120
121 /**
122 * Returns a string representing a separator item.
123 *
124 * @return string The separator item string.
125 */
126 public static function getItemSeparator()
127 {
128 return 'Type: separator';
129 }
130
131 /**
132 * Returns a string representing a ConsoleZ item.
133 *
134 * @param string $caption The caption for the item.
135 * @param int $glyph The glyph index.
136 * @param string|null $id The ID for the item.
137 * @param string|null $title The title for the item.
138 * @param string|null $initDir The initial directory for the item.
139 * @param string|null $command The command to execute.
140 * @return string The ConsoleZ item string.
141 */
142 public static function getItemConsoleZ($caption, $glyph, $id = null, $title = null, $initDir = null, $command = null)
143 {
144 global $bearsamppTools;
145
146 $args = '';
147 if ($id != null) {
148 $args .= ' -t ""' . $id . '""';
149 }
150 if ($title != null) {
151 $args .= ' -w ""' . $title . '""';
152 }
153 if ($initDir != null) {
154 $args .= ' -d ""' . $initDir . '""';
155 }
156 if ($command != null) {
157 $args .= ' -r ""' . $command . '""';
158 }
159
160 return self::getItemExe(
161 $caption,
162 $bearsamppTools->getConsoleZ()->getExe(),
163 $glyph,
164 $args
165 );
166 }
167
168 /**
169 * Returns a string representing a link item.
170 *
171 * @param string $caption The caption for the item.
172 * @param string $link The URL for the link.
173 * @param bool $local Whether the link is local.
174 * @param int $glyph The glyph index.
175 * @return string The link item string.
176 */
177 public static function getItemLink($caption, $link, $local = false, $glyph = self::GLYPH_WEB_PAGE)
178 {
180
181 if ($local) {
182 $link = $bearsamppRoot->getLocalUrl($link);
183 }
184
185 return self::getItemExe(
186 $caption,
187 $bearsamppConfig->getBrowser(),
188 $glyph,
189 $link
190 );
191 }
192
193 /**
194 * Returns a string representing a Notepad item.
195 *
196 * @param string $caption The caption for the item.
197 * @param string $path The path to the file.
198 * @return string The Notepad item string.
199 */
200 public static function getItemNotepad($caption, $path)
201 {
202 global $bearsamppConfig;
203
204 return self::getItemExe(
205 $caption,
206 $bearsamppConfig->getNotepad(),
207 self::GLYPH_FILE,
208 $path
209 );
210 }
211
212 /**
213 * Returns a string representing an executable item.
214 *
215 * @param string $caption The caption for the item.
216 * @param string $exe The path to the executable.
217 * @param int $glyph The glyph index.
218 * @param string|null $params The parameters for the executable.
219 * @return string The executable item string.
220 */
221 public static function getItemExe($caption, $exe, $glyph, $params = null)
222 {
223 return 'Type: item; ' .
224 'Caption: "' . $caption . '"; ' .
225 'Action: run; ' .
226 'FileName: "' . $exe . '"; ' .
227 (!empty($params) ? 'Parameters: "' . $params . '"; ' : '') .
228 'Glyph: ' . $glyph;
229 }
230
231 /**
232 * Returns a string representing an explorer item.
233 *
234 * @param string $caption The caption for the item.
235 * @param string $path The path to explore.
236 * @return string The explorer item string.
237 */
238 public static function getItemExplore($caption, $path)
239 {
240 return 'Type: item; ' .
241 'Caption: "' . $caption . '"; ' .
242 'Action: shellexecute; ' .
243 'FileName: "' . $path . '"; ' .
244 'Glyph: ' . self::GLYPH_FOLDER_OPEN;
245 }
246
247 /**
248 * Returns a string representing a service action.
249 *
250 * @param string|null $service The service name.
251 * @param string $action The action to perform.
252 * @param bool $item Whether to return as an item.
253 * @return string The service action string.
254 */
255 private static function getActionService($service, $action, $item = false)
256 {
257 global $bearsamppLang;
258 $result = 'Action: ' . $action;
259
260 if ($service != null) {
261 $result = 'Action: service; ' .
262 'Service: ' . $service . '; ' .
263 'ServiceAction: ' . $action;
264 }
265
266 if ($item) {
267 $result = 'Type: item; ' . $result;
268 if ($action == self::SERVICE_START) {
269 $result .= '; Caption: "' . $bearsamppLang->getValue(Lang::MENU_START_SERVICE) . '"' .
270 '; Glyph: ' . self::GLYPH_START;
271 } elseif ($action == self::SERVICE_STOP) {
272 $result .= '; Caption: "' . $bearsamppLang->getValue(Lang::MENU_STOP_SERVICE) . '"' .
273 '; Glyph: ' . self::GLYPH_STOP;
274 } elseif ($action == self::SERVICE_RESTART) {
275 $result .= '; Caption: "' . $bearsamppLang->getValue(Lang::MENU_RESTART_SERVICE) . '"' .
276 '; Glyph: ' . self::GLYPH_RELOAD;
277 }
278 } elseif ($action != self::SERVICES_CLOSE) {
279 $result .= '; Flags: ignoreerrors waituntilterminated';
280 }
281
282 return $result;
283 }
284
285 /**
286 * Returns a string representing a service start action.
287 *
288 * @param string $service The service name.
289 * @return string The service start action string.
290 */
291 public static function getActionServiceStart($service)
292 {
293 return self::getActionService($service, self::SERVICE_START, false);
294 }
295
296 /**
297 * Returns a string representing a service start item.
298 *
299 * @param string $service The service name.
300 * @return string The service start item string.
301 */
302 public static function getItemActionServiceStart($service)
303 {
304 return self::getActionService($service, self::SERVICE_STOP, true);
305 }
306
307 /**
308 * Returns a string representing a service stop action.
309 *
310 * @param string $service The service name.
311 * @return string The service stop action string.
312 */
313 public static function getActionServiceStop($service)
314 {
315 return self::getActionService($service, self::SERVICE_STOP, false);
316 }
317
318 /**
319 * Returns a string representing a service stop item.
320 *
321 * @param string $service The service name.
322 * @return string The service stop item string.
323 */
324 public static function getItemActionServiceStop($service)
325 {
326 return self::getActionService($service, self::SERVICE_START, true);
327 }
328
329 /**
330 * Returns a string representing a service restart action.
331 *
332 * @param string $service The service name.
333 * @return string The service restart action string.
334 */
335 public static function getActionServiceRestart($service)
336 {
337 return self::getActionService($service, self::SERVICE_RESTART, false);
338 }
339
340 /**
341 * Returns a string representing a service restart item.
342 *
343 * @param string $service The service name.
344 * @return string The service restart item string.
345 */
346 public static function getItemActionServiceRestart($service)
347 {
348 return self::getActionService($service, self::SERVICE_RESTART, true);
349 }
350
351 /**
352 * Returns a string representing a close services action.
353 *
354 * @return string The close services action string.
355 */
356 public static function getActionServicesClose()
357 {
358 return self::getActionService(null, self::SERVICES_CLOSE, false);
359 }
360
361 /**
362 * Returns a string representing a close services item.
363 *
364 * @return string The close services item string.
365 */
366 public static function getItemActionServicesClose()
367 {
368 return self::getActionService(null, self::SERVICES_CLOSE, true);
369 }
370
371 /**
372 * Returns a string representing the messages section.
373 *
374 * @return string The messages section string.
375 */
376 public static function getSectionMessages()
377 {
378 global $bearsamppLang;
379
380 return '[Messages]' . PHP_EOL .
381 'AllRunningHint=' . $bearsamppLang->getValue(Lang::ALL_RUNNING_HINT) . PHP_EOL .
382 'SomeRunningHint=' . $bearsamppLang->getValue(Lang::SOME_RUNNING_HINT) . PHP_EOL .
383 'NoneRunningHint=' . $bearsamppLang->getValue(Lang::NONE_RUNNING_HINT) . PHP_EOL;
384 }
385
386 /**
387 * Returns a string representing the config section.
388 *
389 * @return string The config section string.
390 */
391 public static function getSectionConfig()
392 {
393 global $bearsamppCore;
394 return '[Config]' . PHP_EOL .
395 'ImageList=' . self::IMG_GLYPH_SPRITES . PHP_EOL .
396 'ServiceCheckInterval=1' . PHP_EOL .
397 'TrayIconAllRunning=' . self::GLYPH_SERVICE_ALL_RUNNING . PHP_EOL .
398 'TrayIconSomeRunning=' . self::GLYPH_SERVICE_SOME_RUNNING . PHP_EOL .
399 'TrayIconNoneRunning=' . self::GLYPH_SERVICE_NONE_RUNNING . PHP_EOL .
400 'ID={' . strtolower(APP_TITLE) . '}' . PHP_EOL .
401 'AboutHeader=' . APP_TITLE . PHP_EOL .
402 'AboutVersion=Version ' . $bearsamppCore->getAppVersion() . PHP_EOL;
403 }
404
405 /**
406 * Returns a string representing the right menu settings section.
407 *
408 * @return string The right menu settings section string.
409 */
410 public static function getSectionMenuRightSettings()
411 {
412 return '[Menu.Right.Settings]' . PHP_EOL .
413 'BarVisible=no' . PHP_EOL .
414 'SeparatorsAlignment=center' . PHP_EOL .
415 'SeparatorsFade=yes' . PHP_EOL .
416 'SeparatorsFadeColor=clBtnShadow' . PHP_EOL .
417 'SeparatorsFlatLines=yes' . PHP_EOL .
418 'SeparatorsGradientEnd=clSilver' . PHP_EOL .
419 'SeparatorsGradientStart=clGray' . PHP_EOL .
420 'SeparatorsGradientStyle=horizontal' . PHP_EOL .
421 'SeparatorsSeparatorStyle=shortline' . PHP_EOL;
422 }
423
424 /**
425 * Returns a string representing the left menu settings section.
426 *
427 * @param string $caption The caption for the left menu.
428 * @return string The left menu settings section string.
429 */
430 public static function getSectionMenuLeftSettings($caption)
431 {
432 return '[Menu.Left.Settings]' . PHP_EOL .
433 'AutoLineReduction=no' . PHP_EOL .
434 'BarVisible=yes' . PHP_EOL .
435 'BarCaptionAlignment=bottom' . PHP_EOL .
436 'BarCaptionCaption=' . $caption . PHP_EOL .
437 'BarCaptionDepth=1' . PHP_EOL .
438 'BarCaptionDirection=downtoup' . PHP_EOL .
439 'BarCaptionFont=Tahoma,14,clWhite' . PHP_EOL .
440 'BarCaptionHighlightColor=clNone' . PHP_EOL .
441 'BarCaptionOffsetY=0' . PHP_EOL .
442 'BarCaptionShadowColor=clNone' . PHP_EOL .
443 'BarPictureHorzAlignment=center' . PHP_EOL .
444 'BarPictureOffsetX=0' . PHP_EOL .
445 'BarPictureOffsetY=0' . PHP_EOL .
446 'BarPicturePicture=' . self::IMG_BAR_PICTURE . PHP_EOL .
447 'BarPictureTransparent=yes' . PHP_EOL .
448 'BarPictureVertAlignment=bottom' . PHP_EOL .
449 'BarBorder=clNone' . PHP_EOL .
450 'BarGradientEnd=$00c07840' . PHP_EOL .
451 'BarGradientStart=$00c07840' . PHP_EOL .
452 'BarGradientStyle=horizontal' . PHP_EOL .
453 'BarSide=left' . PHP_EOL .
454 'BarSpace=0' . PHP_EOL .
455 'BarWidth=32' . PHP_EOL .
456 'SeparatorsAlignment=center' . PHP_EOL .
457 'SeparatorsFade=yes' . PHP_EOL .
458 'SeparatorsFadeColor=clBtnShadow' . PHP_EOL .
459 'SeparatorsFlatLines=yes' . PHP_EOL .
460 'SeparatorsFont=Arial,8,clWhite,bold' . PHP_EOL .
461 'SeparatorsGradientEnd=$00FFAA55' . PHP_EOL .
462 'SeparatorsGradientStart=$00550000' . PHP_EOL .
463 'SeparatorsGradientStyle=horizontal' . PHP_EOL .
464 'SeparatorsSeparatorStyle=caption' . PHP_EOL;
465 }
466}
$result
global $bearsamppLang
global $bearsamppRoot
global $bearsamppCore
const SOME_RUNNING_HINT
const ALL_RUNNING_HINT
const MENU_STOP_SERVICE
const NONE_RUNNING_HINT
const MENU_RESTART_SERVICE
const MENU_START_SERVICE
static getItemActionServicesClose()
const GLYPH_REBUILD_INI
const GLYPH_SERVICES_START
const GLYPH_SERVICES_STOP
const GLYPH_GHOSTSCRIPT
const GLYPH_FOLDER_DISABLED
const GLYPH_SERVICE_REMOVE
static getSectionMessages()
const GLYPH_FOLDER_CLOSE
static getItemActionServiceStop($service)
const GLYPH_IMAGEMAGICK
static getItemSeparator()
static getActionService($service, $action, $item=false)
const GLYPH_PYTHON_CP
static getItemActionServiceStart($service)
static getItemConsoleZ($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
const GLYPH_SERVICE_NONE_RUNNING
static getActionServiceRestart($service)
const GLYPH_FOLDER_OPEN
const GLYPH_RED_LIGHT
static getItemActionServiceRestart($service)
const GLYPH_HOSTSEDITOR
static getSectionMenuLeftSettings($caption)
static getActionServiceStart($service)
static getGlyphFlah($lang)
const GLYPH_SERVICES_RESTART
const IMG_GLYPH_SPRITES
const GLYPH_FILEZILLA
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
const GLYPH_SSL_CERTIFICATE
static getSectionConfig()
static getActionServiceStop($service)
const GLYPH_SERVICE_ALL_RUNNING
static getActionServicesClose()
const GLYPH_FOLDER_ENABLED
static getItemExplore($caption, $path)
const GLYPH_SERVICE_SOME_RUNNING
static getSectionMenuRightSettings()
static getItemExe($caption, $exe, $glyph, $params=null)
const GLYPH_SERVICE_INSTALL
static getItemNotepad($caption, $path)
global $bearsamppConfig
Definition homepage.php:26
const APP_TITLE
Definition root.php:12