Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.homepage.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2021-2024 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
18{
19 const PAGE_INDEX = 'index';
20 const PAGE_PHPINFO = 'phpinfo';
21
22 private $page;
23
27 private $pageList = array(
28 self::PAGE_INDEX,
29 self::PAGE_PHPINFO,
30 );
31
36 public function __construct()
37 {
38 Util::logInitClass($this);
39
41 $this->page = !empty($page) && in_array($page, $this->pageList) ? $page : self::PAGE_INDEX;
42 }
43
49 public function getPage()
50 {
51 return $this->page;
52 }
53
60 public function getPageQuery($query)
61 {
62 if (empty($query)) {
63 return '';
64 }
65
66 if (in_array($query, $this->pageList)) {
67 return $query !== self::PAGE_INDEX ? '?p=' . $query : 'index.php';
68 }
69
70 return '';
71 }
72
79 public function getPageUrl($query)
80 {
81 global $bearsamppRoot;
82 return $bearsamppRoot->getLocalUrl($this->getPageQuery($query));
83 }
84
90 public function getHomepagePath()
91 {
92 global $bearsamppCore;
93 return $bearsamppCore->getResourcesPath(false) . '/homepage';
94 }
95
101 public function getImagesPath()
102 {
103 return $this->getResourcesPath(false) . '/img/';
104 }
105
111 public function getIconsPath()
112 {
113 return $this->getResourcesPath(false) . '/img/icons/';
114 }
115
121 public function getResourcesPath()
122 {
123 global $bearsamppCore;
124 return md5(APP_TITLE);
125 }
126
132 public function getResourcesUrl()
133 {
134 global $bearsamppRoot;
135 return $bearsamppRoot->getLocalUrl($this->getResourcesPath());
136 }
137
143 public function refreshAliasContent()
144 {
145 global $bearsamppBins;
146
147 $result = $bearsamppBins->getApache()->getAliasContent(
148 $this->getResourcesPath(),
149 $this->getHomepagePath()
150 );
151
152 return file_put_contents($this->getHomepagePath() . '/alias.conf', $result) !== false;
153 }
154
158 public function refreshCommonsJsContent()
159 {
160 Util::replaceInFile($this->getHomepagePath() . '/js/_commons.js', array(
161 '/^\s\surl:.*/' => ' url: "' . $this->getResourcesPath() . '/ajax.php"',
162 '/AJAX_URL.*=.*/' => 'const AJAX_URL = "' . $this->getResourcesPath() . '/ajax.php"',
163 ));
164 }
165}
$result
global $bearsamppBins
global $bearsamppRoot
global $bearsamppCore
const PAGE_PHPINFO
getPageUrl($query)
refreshCommonsJsContent()
getPageQuery($query)
const PAGE_INDEX
static logInitClass($classInstance)
static cleanGetVar($name, $type='text')
static replaceInFile($path, $replaceList)
const APP_TITLE
Definition root.php:13