Issues (994)

index-cache-mode.php (2 issues)

1
<?php
2
3
/*if (count($_COOKIE) <= 50) {
4
  foreach ($_COOKIE as $key => $val) {
5
  if (!is_numeric($key) || !is_string($key)) {
6
  continue;
7
  }
8
  setcookie('same-site-cookie', $key, ['samesite' => 'Lax']);
9
  setcookie('cross-site-cookie', $key, ['samesite' => 'None', 'secure' => true]);
10
  }
11
}*/
12
13
header('X-Powered-By: L3n4r0x');
14
15
//import configuration
16
include_once __DIR__ . '/config.php';
17
18
use MVC\helper;
19
use MVC\router;
20
use MVC\themes;
21
22
// force redirect, this is our project, you can remove this
23
if ('103.146.203.101' == $_SERVER['HTTP_HOST'] && !LOCAL) {
24
  header('Location: http://ns.webmanajemen.com' . $_SERVER['REQUEST_URI']);
25
  // force https
26
  if (isset($_SERVER['HTTPS']) && 'on' != $_SERVER['HTTPS']) {
27
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
28
  } else {
29
    // tell browser to access https only
30
    header('Strict-Transport-Security: max-age=31536000');
31
  }
32
}
33
34
// run DDOS protector
35
new \DDOS\runner();
36
37
// start theme
38
$theme = new themes();
39
40
////// Custom maintenance start
41
//@todo disable maintenance mode for admin
42
//this maintenance applied on production mode (NON LOCALHOST)
43
if (!LOCAL) { //change this
44
  if (isset($_REQUEST['release'])) {
45
    \Cookie\helper::hours('release-maintenance', 'true', 1);
46
  }
47
  if (!isset($_COOKIE['release-maintenance'])) {
48
    //maintenance(); //uncomment this to enable
49
  }
50
}
51
////// Custom maintenance end
52
53
////// Zone Shutdown Start
54
$shut = get_conf()['app']['shutdown'];
55
if (!LOCAL) { // do shutdown if not localhost
56
  $theme->shutdown($shut);
57
}
58
////// Zone Shutdown End
59
60
////// build template start
61
62
/**
63
 * Template configuration.
64
 */
65
$template = get_conf()['app']['theme'];
66
/**
67
 * Template stack builder.
68
 *
69
 * @todo exclude default template from scopes
70
 */
71
$template_stack = [];
72
if (!empty($template)) {
73
  foreach ($template as $key => $value) {
74
    if ('default' == $key) {
75
      continue;
76
    }
77
    $template_stack[$key] = $value;
78
  }
79
}
80
81
// Set template by zone divider
82
$theme->setThemeByZones(
83
  $template_stack,
84
  get_conf()['app']['theme']['default']
85
);
86
87
////// build template end
88
89
$application_folder = empty(CONFIG['app']['root']) ? __DIR__ : ROOT;
90
$view_folder = CONFIG['app']['views'];
91
// special access
92
switch (get_zone()) {
93
  case 'load-asset':
94
    // load static asset by ?src=
95
    $parse = helper::parse_url2(helper::geturl());
96
    if (isset($parse['query']['src'])) {
97
      helper::load_asset($parse['query']['src']);
98
      exit;
99
    }
100
    break;
101
  case 'superuser': // superuser framework
102
  case 'server': //server framework
103
    //set folder etc for root views
104
    $view_folder = 'etc';
105
    break;
106
}
107
$view_folder = "{$application_folder}/{$view_folder}/";
108
define('VIEWPATH', $view_folder);
109
110
$rc = new router();
111
$view = helper::fixSlash(VIEWPATH . $rc->findRoute() . '.php');
0 ignored issues
show
Are you sure the usage of $rc->findRoute() targeting MVC\router::findRoute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
112
113
// glype proxy
114
if ('index/bot/glype/admin' == str_replace('.php', '', $view)) {
115
  include __DIR__ . '/bot/glype/admin.php';
116
  exit;
117
}
118
119
// start output buffering
120
ob_start();
121
122
// default router
123
if (!realpath($view)) {
124
  // if file not exists return 400 bad request
125
  http_response_code(400);
126
  $basename = basename($view, '.php');
127
  /**
128
   * next index finder.
129
   */
130
  $check_next_index = preg_replace('/\.php$/s', '', $view) . '/index.php';
131
  if ($check_next_index = realpath($check_next_index)) {
132
    $check_next_index = \MVC\helper::fixSlash($check_next_index);
133
    $check_next_index = preg_replace('/\.php$/s', '', $check_next_index);
134
    if ($pos_views = strpos($check_next_index, '/views')) {
135
      $check_next_index = substr($check_next_index, $pos_views + strlen('/views'));
136
    } else if ($pos_views = strpos($check_next_index, '/etc')) {
137
      $check_next_index = substr($check_next_index, $pos_views + strlen('/etc'));
138
    }
139
    die($router->redirect($check_next_index));
140
  }
141
142
  ////// if router ended with slash (/) below codes will find next index.php or previous file php
143
  ////// dashboard/ maybe to dashboard/index or dashboard.php if exists
144
145
  /**
146
   * Previous index finder.
147
   */
148
  $check_prev_index = preg_replace('/\/index\.php$/s', '', $view) . '.php';
149
  if ($check_prev_index = realpath($check_prev_index)) {
150
    $check_prev_index = \MVC\helper::fixSlash($check_prev_index);
151
    $check_prev_index = preg_replace('/\.php$/s', '', $check_prev_index);
152
    if ($pos_views = strpos($check_prev_index, '/views')) {
153
      $check_prev_index = substr($check_prev_index, $pos_views + strlen('/views'));
154
    } else if ($pos_views = strpos($check_prev_index, '/etc')) {
155
      $check_prev_index = substr($check_prev_index, $pos_views + strlen('/etc'));
156
    }
157
    die($router->redirect($check_prev_index));
158
  }
159
160
  // exit now
161
  if ('development' != get_env()) {
162
    // skip debug if environtment not development
163
    $view = '';
164
  }
165
  http_response_code(404);
166
  include __DIR__ . '/404.php';
167
  // @todo if not found auto remove config meta
168
  //
169
} elseif ($view = realpath($view)) {
170
  // if file exists, set as view
171
  $theme->view($view);
172
  /**
173
   * @var bool render if Disabled Cache on browser
174
   */
175
  $is_hard_reload = $router->is_hard_reload();
176
  /**
177
   * @var bool force render if page cache not exists / expired
178
   */
179
  $cache_expired = cache_expired(2);
180
  /**
181
   * @var bool disable cache based on meta
182
   */
183
  $no_cache = !$theme->meta['cache'];
184
  /**
185
   * @var bool disable cache on CORS
186
   */
187
  $cors = CORS;
188
  /**
189
   * @var bool temporarily disable on production
190
   */
191
  $production = ('production' == get_env());
192
  /**
193
   * @var bool Is refresh cache request
194
   */
195
  $refreshCache = $router->is_header('Refresh-Cache');
196
197
  // set all indicator to integer for convert into boolean on next event
198
  settype($is_hard_reload, 'integer');
199
  settype($no_cache, 'integer');
200
  settype($cache_expired, 'integer');
201
  settype($cors, 'integer');
202
203
  if ('development' == get_env()) {
204
    // noindex on development mode, for SEO reasons
205
    header('X-Robots-Tag: noindex, nofollow', true);
206
  }
207
  if (!CORS) {
208
    //echo showAlert('bottom');
209
  }
210
  if ($no_cache || $cors || $refreshCache || $is_hard_reload || $cache_expired) {
211
    // disabled cache mode
212
    header('Cache-Status: no-cache(' . __LINE__ . "), hard({$is_hard_reload}), cache_expired({$cache_expired}), no_cache({$no_cache}), cors({$cors})", true);
213
214
    return render($theme);
215
  } else {
216
    // enabled cache mode
217
    header('Cache-Status: true(' . __LINE__ . "), hard({$is_hard_reload}), cache_expired({$cache_expired}), no_cache({$no_cache}), cors({$cors})", true);
218
219
    return load_cache(page_cache(), $theme);
220
  }
221
}
222
223
/**
224
 * Get current theme instance
225
 *
226
 * @return \MVC\themes
227
 */
228
function theme()
229
{
230
  global $theme;
231
  return $theme;
232
}
233
234
function showAlert($position)
235
{
236
  return '<div class="alert-' . $position . ' alert alert-danger">
237
	<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
238
	<strong>Sorry!</strong> Jika anda melihat tulisan ini, kami sedang melakukan pemeliharaan sistem. Jangan melakukan transaksi apapun sebelum tulisan ini <b>menghilang</b>. Agar tidak terjadi hal yang tidak diinginkan
239
  </div>';
240
}
241
242
243
244
245
246
247
248
249
250
251
252
/**
253
 * Load page cached
254
 *
255
 * @param string $page_cache
256
 * @return void
257
 */
258
function load_cache(string $page_cache, \MVC\themes $theme)
259
{
260
  //global $theme, $alert;
261
  $optimized_buffer = \Filemanager\file::get($page_cache);
262
  $add = trim('<script>async_process(location.href);</script>');
263
  /**
264
   * @var string Load admin toolbox
265
   */
266
  $optimized_buffer = str_replace('</html>', $add, $optimized_buffer);
267
  echo $optimized_buffer;
268
  $theme->load_admin_tools();
0 ignored issues
show
The method load_admin_tools() does not exist on MVC\themes. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

268
  $theme->/** @scrutinizer ignore-call */ 
269
          load_admin_tools();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
269
270
  echo '</html>';
271
}
272