This repository has been archived by the owner on May 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
executable file
·66 lines (62 loc) · 2.25 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This file is part of the Knob-mvc package.
*
* (c) José María Valera Reales <chemaclass@outlook.es>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* ==============================================
* Search the kind of file we are looking for.
* ==============================================
* If we're in this file means the original file doesn't exists
* on the root directory. So come on and looking into Knob default files.
*/
$wp_the_query = $GLOBALS['wp_the_query'];
$query = $wp_the_query->query;
if (isset($query) && isset($query['pagename'])) {
// =============== Page ======================
$kindFile = 'page';
$fileName = $query['pagename'] . '.php';
} elseif (isset($wp_the_query->is_author) && $wp_the_query->is_author) {
// =============== Author ====================
$kindFile = 'author';
$fileName = 'author.php';
} elseif (isset($wp_the_query->is_tag) && $wp_the_query->is_tag) {
// =============== Tag =======================
$kindFile = 'tag';
$fileName = 'tag.php';
} elseif (isset($wp_the_query->is_category) && $wp_the_query->is_category) {
// =============== Category ==================
$kindFile = 'category';
$fileName = 'category.php';
} else {
// =============== Others ====================
foreach ($wp_the_query as $k => $v) {
if ('is_' == (substr($k, 0, 3)) && $v) {
$kindFile = substr($k, 3);
$fileName = $kindFile . '.php';
break;
}
}
}
$fileNameInBase = VENDOR_KNOB_BASE_WP_DIR . '/' . $fileName;
$fileNameInPages = PAGES_DIR . '/' . $fileName;
if (file_exists($fileName)) {
// get the file from the "knob-mvc/$fileName"
require_once $fileName;
} elseif (file_exists($fileNameInPages)) {
// get the file from the "knob-mvc/app/pages/$fileName"
require_once $fileNameInPages;
} elseif (file_exists($fileNameInBase)) {
// get the file from the "knob-base/wp/$fileNameInBase"
require_once $fileNameInBase;
} elseif ('page' == $kindFile) {
// get the file from the "knob-base/page.php"
require_once VENDOR_KNOB_BASE_WP_DIR . '/page.php';
} else {
// the file doesn't exists
die('the file doesn\'t exists');
}