This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
func_get_content.php
174 lines (122 loc) · 3.68 KB
/
func_get_content.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* get contents of the current page (default by (int) $p)
* get contents for navigation
*
* @return array
*/
function fc_get_content($page, $mode = 'p') {
global $db_content;
global $languagePack;
if($mode == 'permalink') {
$page_contents = $db_content->get("fc_pages", "*", [
"page_permalink" => $page
]);
} elseif ($mode == 'type_of_use') {
$page_contents = $db_content->get("fc_pages", "*", [
"AND" => [
"page_type_of_use" => $page,
"page_language" => "$languagePack"
]
]);
} elseif ($mode == 'page_sort') {
$page_contents = $db_content->get("fc_pages", "*", [
"AND" => [
"page_sort" => "$page",
"page_language" => "$languagePack"
]
]);
} elseif ($mode == 'preview') {
$page_contents = $db_content->get("fc_pages_cache", "*", [
"AND" => [
"page_id_original" => "$page",
"page_language" => "$languagePack"
],
"ORDER" => ["page_id" => "DESC"]
]);
} else {
$page_contents = $db_content->get("fc_pages", "*", [
"page_id" => $page
]);
}
if($page_contents['page_language'] == '') {
$page_contents['page_language'] = $languagePack;
} else {
$languagePack = $page_contents['page_language'];
}
if(empty($_SESSION['user_class']) && $_SESSION['user_class'] != 'administrator') {
$fc_nav = $db_content->select("fc_pages", ['page_id', 'page_classes', 'page_hash', 'page_language', 'page_linkname', 'page_permalink', 'page_target', 'page_title', 'page_sort', 'page_status'], [
"AND" => [
"OR" => [
"page_status[!]" => ["draft","ghost"]
],
"page_language" => $languagePack
],
"ORDER" => ["page_sort" => "DESC"]
]);
} else {
$fc_nav = $db_content->select("fc_pages", ['page_id', 'page_classes', 'page_hash', 'page_language', 'page_linkname', 'page_permalink', 'page_target', 'page_title', 'page_sort', 'page_status'], [
"page_language" => $languagePack
],[
"ORDER" => ["page_sort" => "DESC"]
]);
}
$fc_nav = fc_array_multisort($fc_nav, 'page_language', SORT_ASC, 'page_sort', SORT_ASC, SORT_NATURAL);
$contents = array($page_contents,$fc_nav);
return $contents;
}
/**
* check if given url is a shortlink
* if applicable, immediately redirect to page permalink
*/
function fc_check_shortlinks($shortlink) {
global $db_content;
$page = $db_content->get("fc_pages", ["page_permalink", "page_permalink_short_cnt"], [
"page_permalink_short" => $shortlink
]);
/* increase page_permalink_short_cnt
redirect to page_permalink */
if($page['page_permalink'] != '') {
$page_permalink_short_cnt = $page['page_permalink_short_cnt'] +1;
$db_content->update("fc_pages", [
"page_permalink_short_cnt" => $page_permalink_short_cnt
], [
"page_permalink_short" => $shortlink
]);
$redirect = '/'.$page['page_permalink'];
header("location: $redirect",TRUE,301);
exit;
}
}
/**
* check if given url is a funnel uri
* if applicable, immediately redirect to page permalink
*/
function fc_check_funnel_uri($uri) {
global $db_content;
$pages = $db_content->select("fc_pages", ["page_permalink", "page_funnel_uri"], [
"page_funnel_uri[~]" => "%$uri%"
]);
foreach($pages as $page) {
$page_funnel_uri = explode(',', $page['page_funnel_uri']);
foreach($page_funnel_uri as $u) {
if($u == $uri) {
$redirect = '/'.$page['page_permalink'];
header("location: $redirect",TRUE,301);
exit;
}
}
}
}
function fc_get_type_of_use_pages($type) {
global $db_content;
global $languagePack;
$page = $db_content->get("fc_pages", ["page_permalink", "page_funnel_uri"], [
"AND" => [
"page_type_of_use" => "$type",
"page_language" => "$languagePack"
]
]);
return $page;
}
?>