LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.page_tree.php
Go to the documentation of this file.
1<?php
2
18// include secure.php to protect this file and the whole CMS!
19if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
20if (defined('LEPTON_PATH')) {
21 include LEPTON_PATH.SEC_FILE;
22} else {
23 $oneback = "../";
24 $root = $oneback;
25 $level = 1;
26 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
27 $root .= $oneback;
28 $level += 1;
29 }
30 if (file_exists($root.SEC_FILE)) {
31 include $root.SEC_FILE;
32 } else {
33 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
34 }
35}
36// end include secure file
37
38
52function page_tree(
53 int $root_id = 0,
54 array &$page_storage = [],
55 array $fields = ['page_id', 'page_title', 'menu_title', 'parent','position', 'visibility', 'admin_groups']
56 ): void
57{
58 global $LEPTON_CORE_all_pages;
60
61 // [1.0.2]
62 $bUserHasAdminRights = LEPTON_core::userHasAdminRights();
63 // [1.0.3]
64 $aUserGroups = LEPTON_CORE::getValue("groups_id", "string", "session", ",");
65
66 // [1.1] make sure that required fields are in list
67 $aRequiredKeys = ['page_id', 'parent', 'visibility', 'admin_groups'];
68
69 foreach ($aRequiredKeys as $mustBe)
70 {
71 if (!in_array($mustBe, $fields))
72 {
73 $fields[] = $mustBe;
74 }
75 }
76
77 $select_fields = "`".implode("`,`", $fields)."`";
78
79 $LEPTON_CORE_all_pages = [];
80 $database->execute_query(
81 "SELECT ".$select_fields." FROM `".TABLE_PREFIX."pages` ORDER BY `parent`,`position`",
82 true,
83 $LEPTON_CORE_all_pages
84 );
85
86 // [2.1]
87 foreach ($LEPTON_CORE_all_pages as &$ref)
88 {
89 $ref['admin_groups'] = explode(",", $ref['admin_groups']);
90 }
91
92 // [2.2]
93 if ($bUserHasAdminRights == true)
94 {
95 foreach ($LEPTON_CORE_all_pages as &$ref)
96 {
97 $ref['userAllowed'] = true;
98 }
99 }
100 else
101 {
102 foreach ($LEPTON_CORE_all_pages as &$ref)
103 {
104 $ref['userAllowed'] = !empty(array_intersect($aUserGroups, $ref['admin_groups']));
105 }
106 }
107
108 if (in_array("viewing_groups", $fields))
109 {
110 foreach ($LEPTON_CORE_all_pages as &$ref)
111 {
112 $ref['viewing_groups'] = explode(",", $ref['viewing_groups']);
113 }
114 }
115
116 LEPTON_CORE_make_list( $root_id, $page_storage );
117 }
118
126function LEPTON_CORE_make_list(int $aNum, array &$aRefArray ): void
127{
128 global $LEPTON_CORE_all_pages, $TEXT;
129
130 foreach($LEPTON_CORE_all_pages as &$ref) {
131
132 if ($ref['parent'] > $aNum)
133 {
134 break;
135 }
136
137 if ($ref['parent'] == $aNum)
138 {
139
140 switch( $ref['visibility'] )
141 {
142
143 case 'public':
144 $ref['status_icon'] = "visible_16.png";
145 $ref['status_text'] = $TEXT['PUBLIC'];
146 $ref['status_uiicon'] = 'unhide';
147 break;
148
149 case 'private':
150 $ref['status_icon'] = "private_16.png";
151 $ref['status_text'] = $TEXT['PRIVATE'];
152 $ref['status_uiicon'] = 'user';
153 break;
154
155 case 'registered':
156 $ref['status_icon'] = "keys_16.png";
157 $ref['status_text'] = $TEXT['REGISTERED'];
158 $ref['status_uiicon'] = 'sign in';
159 break;
160
161 case 'hidden':
162 $ref['status_icon'] = "hidden_16.png";
163 $ref['status_text'] = $TEXT['HIDDEN'];
164 $ref['status_uiicon'] = 'hide';
165 break;
166
167 case 'none':
168 $ref['status_icon'] = "none_16.png";
169 $ref['status_text'] = $TEXT['NONE'];
170 $ref['status_uiicon'] = 'lock';
171 break;
172
173 case 'deleted':
174 $ref['status_icon'] = "deleted_16.png";
175 $ref['status_text'] = $TEXT['DELETED'];
176 $ref['status_uiicon'] = 'recycle red';
177 break;
178
179 default:
180 die(LEPTON_tools::display("Error: [20012] ".$ref['visibility']. " unknown!", "pre", "ui message red"));
181 break;
182
183 }
184
185 $ref['subpages'] = [];
186 LEPTON_CORE_make_list( $ref['page_id'], $ref['subpages'] );
187
188 if (isset($ref['link']))
189 {
190 $ref['link'] = PAGES_DIRECTORY.$ref['link'].PAGE_EXTENSION; // show link also in overview, therefore no additional LEPTON_URL
191 }
192
193 $aRefArray[] = &$ref;
194 }
195 }
196}
static getInstance(array &$settings=[])
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null, bool|null $useVarDump=null)
$database
Definition constants.php:52
page_tree(int $root_id=0, array &$page_storage=[], array $fields=['page_id', 'page_title', 'menu_title', 'parent', 'position', 'visibility', 'admin_groups'])
LEPTON_CORE_make_list(int $aNum, array &$aRefArray)