LEPTON CMS 7.4.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.modify_page_trail.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
39// function to modify page trail of subs
40function modify_page_trail($iOldRootParent,$iNewRootParent)
41{
42 // Get objects and vars from outside this function
43 global $admin, $database, $TEXT, $MESSAGE;
44
45 // Get page list from database
46 $aAllPages = [];
47 $database->execute_query(
48 "SELECT * FROM `".TABLE_PREFIX."pages` WHERE `root_parent` = ".$iOldRootParent." AND page_id != ".$iOldRootParent ,
49 true,
50 $aAllPages,
51 true
52 );
53
54 // Insert correct values into page list
55 foreach ($aAllPages as &$page)
56 {
57 $sCurrentPageTrail = $page['page_trail'];
58 $aCurrentPageTrail = explode(',',$sCurrentPageTrail);
59
60 if($page['root_parent'] == $page['parent'])
61 {
62 // add element as index[0]
63 array_unshift($aCurrentPageTrail,$iNewRootParent);
64 $sNewPageTrail = implode(',',$aCurrentPageTrail);
65 }
66 else
67 {
68 // replace first element
69 $aCurrentPageTrail[0] = $iNewRootParent;
70 $aCurrentPageTrail = array_unique($aCurrentPageTrail);
71 $sNewPageTrail = implode(',',$aCurrentPageTrail);
72 }
73
74 // Save new page trail
75 $database->simple_query("UPDATE ".TABLE_PREFIX."pages SET root_parent = ".$iNewRootParent.", page_trail = '".$sNewPageTrail."' WHERE `page_id` = ".$page['page_id']);
76 }
77}
78
$database
Definition constants.php:52
modify_page_trail($iOldRootParent, $iNewRootParent)