Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.tpl.app.nodejs.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
17{
18 // Constants for menu and action identifiers
19 const MENU = 'nodejs';
20 const MENU_VERSIONS = 'nodejsVersions';
21
22 const ACTION_ENABLE = 'enableNodejs';
23 const ACTION_SWITCH_VERSION = 'switchNodejsVersion';
24
35 public static function process()
36 {
38
41 self::MENU,
42 get_called_class(),
43 $bearsamppBins->getNodejs()->isEnable()
44 );
45 }
46
59 public static function getMenuNodejs()
60 {
61 global $bearsamppBins, $bearsamppLang, $bearsamppTools;
62 $resultItems = $resultActions = '';
63
64 $isEnabled = $bearsamppBins->getNodejs()->isEnable();
65
66 // Download
67 $resultItems .= TplAestan::getItemLink(
69 Util::getWebsiteUrl('module/nodejs', '#releases'),
70 false,
72 ) . PHP_EOL;
73
74 // Enable
75 $tplEnable = TplApp::getActionMulti(
76 self::ACTION_ENABLE,
77 array($isEnabled ? Config::DISABLED : Config::ENABLED),
78 array($bearsamppLang->getValue(Lang::MENU_ENABLE), $isEnabled ? TplAestan::GLYPH_CHECK : ''),
79 false,
80 get_called_class()
81 );
82 $resultItems .= $tplEnable[TplApp::SECTION_CALL] . PHP_EOL;
83 $resultActions .= $tplEnable[TplApp::SECTION_CONTENT] . PHP_EOL;
84
85 if ($isEnabled) {
86 $resultItems .= TplAestan::getItemSeparator() . PHP_EOL;
87
88 // Versions
89 $tplVersions = TplApp::getMenu(
91 self::MENU_VERSIONS,
92 get_called_class()
93 );
94 $resultItems .= $tplVersions[TplApp::SECTION_CALL] . PHP_EOL;
95 $resultActions .= $tplVersions[TplApp::SECTION_CONTENT];
96
97 // Console
98 $resultItems .= TplAestan::getItemConsoleZ(
101 $bearsamppTools->getConsoleZ()->getTabTitleNodejs()
102 ) . PHP_EOL;
103
104 // Conf
105 $resultItems .= TplAestan::getItemNotepad(
106 basename($bearsamppBins->getNodejs()->getConf()),
107 $bearsamppBins->getNodejs()->getConf()
108 ) . PHP_EOL;
109 }
110
111 return $resultItems . PHP_EOL . $resultActions;
112 }
113
123 public static function getMenuNodejsVersions()
124 {
125 global $bearsamppBins;
126 $items = '';
127 $actions = '';
128
129 foreach ($bearsamppBins->getNodejs()->getVersionList() as $version) {
130 $tplSwitchNodejsVersion = TplApp::getActionMulti(
131 self::ACTION_SWITCH_VERSION,
132 array($version),
133 array($version, $version == $bearsamppBins->getNodejs()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
134 false,
135 get_called_class()
136 );
137
138 // Item
139 $items .= $tplSwitchNodejsVersion[TplApp::SECTION_CALL] . PHP_EOL;
140
141 // Action
142 $actions .= PHP_EOL . $tplSwitchNodejsVersion[TplApp::SECTION_CONTENT];
143 }
144
145 return $items . $actions;
146 }
147
159 public static function getActionEnableNodejs($enable)
160 {
161 global $bearsamppBins;
162
165 array($bearsamppBins->getNodejs()->getName(), $enable)
166 ) . PHP_EOL . TplAppReload::getActionReload();
167 }
168
180 public static function getActionSwitchNodejsVersion($version)
181 {
182 global $bearsamppBins;
183
186 array($bearsamppBins->getNodejs()->getName(), $version)
187 ) . PHP_EOL . TplAppReload::getActionReload() . PHP_EOL;
188 }
189}
global $bearsamppBins
global $bearsamppLang
const SWITCH_VERSION
const ENABLE
const DISABLED
const ENABLED
const NODEJS
const MENU_ENABLE
const DOWNLOAD_MORE
const CONSOLE
const VERSIONS
static getItemConsoleZ($caption, $glyph, $id=null, $title=null, $initDir=null, $command=null)
static getItemLink($caption, $link, $local=false, $glyph=self::GLYPH_WEB_PAGE)
static getItemNotepad($caption, $path)
static getItemSeparator()
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 getActionSwitchNodejsVersion($version)
static getActionEnableNodejs($enable)
static getWebsiteUrl($path='', $fragment='', $utmSource=true)