2024.8.23
Loading...
Searching...
No Matches
class.app.webgrind.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 AppWebgrind
12 *
13 * This class represents the Webgrind application module within the Bearsampp application.
14 * It extends the Module class and provides functionalities specific to Webgrind, such as
15 * configuration management and version handling.
16 */
17class AppWebgrind extends Module
18{
19 /**
20 * Constant for the root configuration version key.
21 */
22 const ROOT_CFG_VERSION = 'webgrindVersion';
23
24 /**
25 * Constant for the local configuration file key.
26 */
27 const LOCAL_CFG_CONF = 'webgrindConf';
28
29 /**
30 * @var string The path to the Webgrind configuration file.
31 */
32 private $conf;
33
34 /**
35 * Constructor for the AppWebgrind class.
36 *
37 * @param string $id The ID of the module.
38 * @param string $type The type of the module.
39 */
40 public function __construct($id, $type) {
41 Util::logInitClass($this);
42 $this->reload($id, $type);
43 }
44
45 /**
46 * Reloads the Webgrind module configuration based on the provided ID and type.
47 *
48 * @param string|null $id The ID of the module. If null, the current ID is used.
49 * @param string|null $type The type of the module. If null, the current type is used.
50 */
51 public function reload($id = null, $type = null) {
54
55 $this->name = $bearsamppLang->getValue(Lang::WEBGRIND);
56 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
57 parent::reload($id, $type);
58
59 if ($this->bearsamppConfRaw !== false) {
60 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
61 }
62
63 if (!$this->enable) {
64 Util::logInfo($this->name . ' is not enabled!');
65 return;
66 }
67 if (!is_dir($this->currentPath)) {
68 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
69 }
70 if (!is_dir($this->symlinkPath)) {
71 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
72 return;
73 }
74 if (!is_file($this->bearsamppConf)) {
75 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
76 }
77 if (!is_file($this->conf)) {
78 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
79 }
80 }
81
82 /**
83 * Updates the Webgrind module configuration.
84 *
85 * @param string|null $version The version to update to. If null, the current version is used.
86 * @param int $sub The sub-level for logging indentation.
87 * @param bool $showWindow Whether to show a window during the update process.
88 * @return bool True if the update was successful, false otherwise.
89 */
90 protected function updateConfig($version = null, $sub = 0, $showWindow = false) {
91 global $bearsamppRoot;
92
93 if (!$this->enable) {
94 return true;
95 }
96
97 $version = $version == null ? $this->version : $version;
98 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
99
100 $alias = $bearsamppRoot->getAliasPath() . '/webgrind.conf';
101 if (is_file($alias)) {
102 Util::replaceInFile($alias, array(
103 '/^Alias\s\/webgrind\s.*/' => 'Alias /webgrind "' . $this->getSymlinkPath() . '/"',
104 '/^<Directory\s.*/' => '<Directory "' . $this->getSymlinkPath() . '/">',
105 ));
106 } else {
107 Util::logError($this->getName() . ' alias not found : ' . $alias);
108 }
109
110 return true;
111 }
112
113 /**
114 * Sets the version of the Webgrind module.
115 *
116 * @param string $version The version to set.
117 */
118 public function setVersion($version) {
119 global $bearsamppConfig;
120 $this->version = $version;
121 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
122 $this->reload();
123 }
124
125 /**
126 * Gets the path to the Webgrind configuration file.
127 *
128 * @return string The path to the Webgrind configuration file.
129 */
130 public function getConf() {
131 return $this->conf;
132 }
133}
global $bearsamppLang
global $bearsamppRoot
updateConfig($version=null, $sub=0, $showWindow=false)
reload($id=null, $type=null)
__construct($id, $type)
const ERROR_FILE_NOT_FOUND
const WEBGRIND
const ERROR_CONF_NOT_FOUND
static logReloadClass($classInstance)
static replaceInFile($path, $replaceList)
static logError($data, $file=null)
static logDebug($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26