LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.page_content.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
39function page_content(int $block = 1)
40{
41 // Get outside objects
42 global $TEXT, $MENU, $HEADING, $MESSAGE, $section_id;
44 $oLEPTON = LEPTON_frontend::getInstance();
45
46 // [0.1]
47 if ($oLEPTON->page_access_denied === true)
48 {
49 echo $MESSAGE['FRONTEND_SORRY_NO_VIEWING_PERMISSIONS'];
50 return;
51 }
52
53 // [0.2]
54 if ($oLEPTON->page_no_active_sections === true)
55 {
56 echo $MESSAGE['FRONTEND_SORRY_NO_ACTIVE_SECTIONS'];
57 return;
58 }
59
60 // [0.3]
61 $sFrontendMessage = LEPTON_core::getValue("page_content", "string", "session") ?? "";
62 if (str_starts_with($sFrontendMessage, "@LEPTON_FE_"))
63 {
64 unset($_SESSION['PAGE_CONTENT']);
65 echo LEPTON_frontend::displayMessage();
66 return;
67 }
68
69 // [1] Include page content
70 if (!defined('PAGE_CONTENT') || $block != 1)
71 {
72 $page_id = intval( $oLEPTON->page_id );
73
74 // [1.0.1] Set session variable to save page_id only if PAGE_CONTENT is empty
75 $_SESSION[ 'PAGE_ID' ] = !isset( $_SESSION[ 'PAGE_ID' ] ) ? $page_id : $_SESSION[ 'PAGE_ID' ];
76
77 // [1.0.2] Set to new value if page_id changed and not 0
78 if (($page_id != 0 ) && ($_SESSION[ 'PAGE_ID' ] <> $page_id))
79 {
80 $_SESSION[ 'PAGE_ID' ] = $page_id;
81 }
82
83 // [1.2] First get all sections for this page
84 $aSections = [];
85 $database->execute_query(
86 "SELECT section_id, module, publ_start, publ_end from ".TABLE_PREFIX."sections WHERE page_id = ".$page_id." AND block = '".$block."' ORDER BY position",
87 true,
88 $aSections,
89 true
90 );
91
92 // [2] We have get valid sections! Loop through the sections and include their module files.
93 foreach ($aSections as $section)
94 {
95 // skip this section if it is out of publication-date
96 $now = time();
97 if ( !( ( $now <= $section[ 'publ_end' ] || $section[ 'publ_end' ] == 0 ) && ( $now >= $section[ 'publ_start' ] || $section[ 'publ_start' ] == 0 ) ) )
98 {
99 continue;
100 }
101 $section_id = $section[ 'section_id' ];
102 $module = $section[ 'module' ];
103
104 // make a anchor for every section.
105 if ( defined( 'SEC_ANCHOR' ) && SEC_ANCHOR != '' )
106 {
107 echo '<a class="section_anchor" id="' . SEC_ANCHOR . $section_id . '"></a>';
108 }
109 // check if module exists
110 if ( file_exists( LEPTON_PATH . '/modules/' . $module . '/view.php' ) )
111 {
112 // fetch content -- this is where to place possible output-filters (before highlighting)
113 ob_start();
114 require LEPTON_PATH . '/modules/' . $module . '/view.php';
115 $content = ob_get_clean();
116 }
117 else
118 {
119 continue;
120 }
121
122 // [2] highlights search-results
123 LEPTON_handle::register("search_highlight");
124 $sSearchResult = (LEPTON_request::getRequest("searchresult") ?? NULL);
125 $sString = (LEPTON_request::getRequest("sstring") ?? "");
126 $sNoHighlight = (LEPTON_request::getRequest("nohighlight") ?? NULL);
127
128 if (!is_null($sSearchResult) && is_null($sNoHighlight) && $sString != "" )
129 {
130 $arr_string = explode( " ", $sString );
131 if ( intval($sSearchResult) == 2 ) // exact match
132 {
133 $arr_string[ 0 ] = str_replace( "_", " ", $arr_string[ 0 ] );
134 }
135 echo search_highlight( $content, $arr_string );
136 }
137 else
138 {
139 echo $content;
140 }
141 }
142 }
143 else
144 {
145 require PAGE_CONTENT;
146 }
147}
static getInstance(array &$settings=[])
static getRequest(string $sField="")
$database
Definition constants.php:52
page_content(int $block=1)
search_highlight(string $sContent='', array $aTermsToMark=array())