2024.8.23
Loading...
Searching...
No Matches
class.homepage.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 Homepage
12
*
13
* This class handles the homepage functionalities of the Bearsampp application.
14
* It manages the page navigation, resource paths, and content refresh operations.
15
*/
16
class
Homepage
17
{
18
const
PAGE_INDEX
=
'index'
;
19
const
PAGE_PHPINFO
=
'phpinfo'
;
20
const
PAGE_STDL_APC
=
'apc.php'
;
21
22
private
$page
;
23
24
/**
25
* @var array List of valid pages for the homepage.
26
*/
27
private
$pageList
= array(
28
self::PAGE_INDEX,
29
self::PAGE_PHPINFO,
30
);
31
32
/**
33
* @var array List of standard pages for the homepage.
34
*/
35
private
$pageStdl
= array(
36
self::PAGE_STDL_APC
37
);
38
39
/**
40
* Homepage constructor.
41
* Initializes the homepage class and sets the current page based on the query parameter.
42
*/
43
public
function
__construct
()
44
{
45
Util::logInitClass
($this);
46
47
$page
=
Util::cleanGetVar
(
'p'
);
48
$this->page = !empty(
$page
) && in_array(
$page
, $this->pageList) ?
$page
:
self::PAGE_INDEX
;
49
}
50
51
/**
52
* Gets the current page.
53
*
54
* @return string The current page.
55
*/
56
public
function
getPage
()
57
{
58
return
$this->page
;
59
}
60
61
/**
62
* Constructs the page query string based on the provided query.
63
*
64
* @param string $query The query string to construct.
65
* @return string The constructed page query string.
66
*/
67
public
function
getPageQuery
($query)
68
{
69
$request =
''
;
70
if
(!empty($query) && in_array($query, $this->pageList) && $query != self::PAGE_INDEX) {
71
$request =
'?p='
. $query;
72
} elseif (!empty($query) && in_array($query, $this->pageStdl)) {
73
$request = $query;
74
} elseif (!empty($query) && self::PAGE_INDEX) {
75
$request =
"index.php"
;
76
}
77
return
$request;
78
}
79
80
/**
81
* Constructs the full URL for the given page query.
82
*
83
* @param string $query The query string to construct the URL for.
84
* @return string The constructed page URL.
85
*/
86
public
function
getPageUrl
($query)
87
{
88
global
$bearsamppRoot
;
89
return
$bearsamppRoot
->getLocalUrl($this->
getPageQuery
($query));
90
}
91
92
/**
93
* Gets the path to the homepage directory.
94
*
95
* @return string The homepage directory path.
96
*/
97
public
function
getHomepagePath
()
98
{
99
global
$bearsamppCore
;
100
return
$bearsamppCore
->getResourcesPath(
false
) .
'/homepage'
;
101
}
102
103
/**
104
* Gets the path to the images directory.
105
*
106
* @return string The images directory path.
107
*/
108
public
function
getImagesPath
()
109
{
110
return
$this->
getResourcesPath
(
false
) .
'/img/'
;
111
}
112
113
/**
114
* Gets the path to the icons directory.
115
*
116
* @return string The icons directory path.
117
*/
118
public
function
getIconsPath
()
119
{
120
return
$this->
getResourcesPath
(
false
) .
'/img/icons/'
;
121
}
122
123
/**
124
* Gets the path to the resources directory.
125
*
126
* @return string The resources directory path.
127
*/
128
public
function
getResourcesPath
()
129
{
130
global
$bearsamppCore
;
131
return
md5(
APP_TITLE
);
132
}
133
134
/**
135
* Gets the URL to the resources directory.
136
*
137
* @return string The resources directory URL.
138
*/
139
public
function
getResourcesUrl
()
140
{
141
global
$bearsamppRoot
;
142
return
$bearsamppRoot
->getLocalUrl($this->
getResourcesPath
());
143
}
144
145
/**
146
* Refreshes the alias content by updating the alias configuration file.
147
*
148
* @return bool True if the alias content was successfully refreshed, false otherwise.
149
*/
150
public
function
refreshAliasContent
()
151
{
152
global
$bearsamppBins
;
153
154
$result
=
$bearsamppBins
->getApache()->getAliasContent(
155
$this->
getResourcesPath
(),
156
$this->
getHomepagePath
()
157
);
158
159
return
file_put_contents($this->
getHomepagePath
() .
'/alias.conf'
,
$result
) !==
false
;
160
}
161
162
/**
163
* Refreshes the commons JavaScript content by updating the _commons.js file.
164
*/
165
public
function
refreshCommonsJsContent
()
166
{
167
Util::replaceInFile
($this->
getHomepagePath
() .
'/js/_commons.js'
, array(
168
'/^\s\surl:.*/'
=>
' url: "'
. $this->
getResourcesPath
() .
'/ajax.php"'
,
169
'/AJAX_URL.*=.*/'
=>
'const AJAX_URL = "'
. $this->
getResourcesPath
() .
'/ajax.php"'
,
170
));
171
}
172
}
$result
$result
Definition
ajax.apache.php:19
$bearsamppBins
global $bearsamppBins
Definition
ajax.apache.php:16
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
$bearsamppCore
global $bearsamppCore
Definition
ajax.latestversion.php:24
Homepage
Definition
class.homepage.php:17
Homepage\getPageQuery
getPageQuery($query)
Definition
class.homepage.php:67
Homepage\PAGE_STDL_APC
const PAGE_STDL_APC
Definition
class.homepage.php:20
Homepage\getResourcesPath
getResourcesPath()
Definition
class.homepage.php:128
Homepage\$pageList
$pageList
Definition
class.homepage.php:27
Homepage\refreshCommonsJsContent
refreshCommonsJsContent()
Definition
class.homepage.php:165
Homepage\PAGE_INDEX
const PAGE_INDEX
Definition
class.homepage.php:18
Homepage\refreshAliasContent
refreshAliasContent()
Definition
class.homepage.php:150
Homepage\PAGE_PHPINFO
const PAGE_PHPINFO
Definition
class.homepage.php:19
Homepage\getResourcesUrl
getResourcesUrl()
Definition
class.homepage.php:139
Homepage\getImagesPath
getImagesPath()
Definition
class.homepage.php:108
Homepage\$page
$page
Definition
class.homepage.php:22
Homepage\getPageUrl
getPageUrl($query)
Definition
class.homepage.php:86
Homepage\getPage
getPage()
Definition
class.homepage.php:56
Homepage\__construct
__construct()
Definition
class.homepage.php:43
Homepage\$pageStdl
$pageStdl
Definition
class.homepage.php:35
Homepage\getHomepagePath
getHomepagePath()
Definition
class.homepage.php:97
Homepage\getIconsPath
getIconsPath()
Definition
class.homepage.php:118
Util\replaceInFile
static replaceInFile($path, $replaceList)
Definition
class.util.php:389
Util\cleanGetVar
static cleanGetVar($name, $type='text')
Definition
class.util.php:80
Util\logInitClass
static logInitClass($classInstance)
Definition
class.util.php:812
APP_TITLE
const APP_TITLE
Definition
root.php:12
Bearsampp-development
sandbox
core
classes
class.homepage.php
Generated by
1.11.0