Bearsampp 2026.3.26
API documentation
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, $bearsamppRoot;
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::getItemPowerShell(
101 null,
102 $bearsamppTools->getPowerShell()->getTabTitleNodejs(),
103 $bearsamppRoot->getWwwPath(),
104 null
105 ) . PHP_EOL;
106
107 // Conf
108 $resultItems .= TplAestan::getItemNotepad(
109 basename($bearsamppBins->getNodejs()->getConf()),
110 $bearsamppBins->getNodejs()->getConf()
111 ) . PHP_EOL;
112 }
113
114 return $resultItems . PHP_EOL . $resultActions;
115 }
116
126 public static function getMenuNodejsVersions()
127 {
128 global $bearsamppBins;
129 $items = '';
130 $actions = '';
131
132 foreach ($bearsamppBins->getNodejs()->getVersionList() as $version) {
133 $tplSwitchNodejsVersion = TplApp::getActionMulti(
134 self::ACTION_SWITCH_VERSION,
135 array($version),
136 array($version, $version == $bearsamppBins->getNodejs()->getVersion() ? TplAestan::GLYPH_CHECK : ''),
137 false,
138 get_called_class()
139 );
140
141 // Item
142 $items .= $tplSwitchNodejsVersion[TplApp::SECTION_CALL] . PHP_EOL;
143
144 // Action
145 $actions .= PHP_EOL . $tplSwitchNodejsVersion[TplApp::SECTION_CONTENT];
146 }
147
148 return $items . $actions;
149 }
150
162 public static function getActionEnableNodejs($enable)
163 {
164 global $bearsamppBins;
165
168 array($bearsamppBins->getNodejs()->getName(), $enable)
169 ) . PHP_EOL . TplAppReload::getActionReload();
170 }
171
183 public static function getActionSwitchNodejsVersion($version)
184 {
185 global $bearsamppBins;
186
189 array($bearsamppBins->getNodejs()->getName(), $version)
190 ) . PHP_EOL . TplAppReload::getActionReload() . PHP_EOL;
191 }
192}
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
const SWITCH_VERSION
const ENABLE
const DISABLED
const ENABLED
const NODEJS
const MENU_ENABLE
const DOWNLOAD_MORE
const CONSOLE
const VERSIONS
static getItemPowerShell($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)