// All rights reserved.
This script is part of PHPWCMS. The PHPWCMS web content management system is
free software; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
A copy is found in the textfile GPL.txt and important notices to the license
from the author is found in LICENSE.txt distributed with these scripts.
This script is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------
//predefine values
$content['cat'] = '';
$content['metakey'] = '';
$content['struct'] = get_struct_data(); //reads the complete structure as array
$content['article_date'] = time();
$content['redirect'] = array('code' => '');
$content['all_keywords'] = '';
$content['globalRT'] = array();
$content['aId_CpPage'] = 0; // set default content part pagination page (0 and 1) are the same
$content['CpTrigger'] = array(); // array to hold content part trigger functions
$content['404error'] = false;
$content['set_canonical'] = false;
$content['cptab'] = array(); // array to hold content part based tabs
$pagelayout = array();
$no_content_for_this_page = 0;
$alias = '';
$PERMIT_ACCESS = true; // by default set all content without permissions
$CUSTOM = array(); // var that holds result of content part "php var"
//method to get the right action values
//if there is only the ?alias try to find the right category
if(isset($_GET["id"])) {
$aktion = explode(',', $_GET["id"], 6);
$aktion[0] = intval($aktion[0]); //$aktion[0] will be always available
$aktion[1] = isset($aktion[1]) ? intval($aktion[1]) : 0;
$aktion[2] = isset($aktion[2]) ? intval($aktion[2]) : 0;
$aktion[3] = isset($aktion[3]) ? intval($aktion[3]) : 1;
$aktion[4] = isset($aktion[4]) ? intval($aktion[4]) : 0;
$aktion[5] = isset($aktion[5]) ? intval($aktion[5]) : 0;
// check if article category is given and available
if(!isset($content['struct'][ $aktion[0] ])) {
$aktion[0] = 0;
// OK in case not we should check if given article ID is correct
if($aktion[1]) {
$sql = 'SELECT article_id, article_cid FROM '.DB_PREPEND.'phpwcms_article WHERE ';
$sql .= 'article_deleted=0 AND article_aktiv=1 AND article_id='.$aktion[1].' LIMIT 1';
$aktion[1] = 0; //reset
if($result = mysql_query($sql, $db)) {
if($row = mysql_fetch_row($result)) {
$aktion[0] = $row[1];
$aktion[1] = $row[0];
}
mysql_free_result($result);
}
}
$GLOBALS['_getVar']['id'] = implode(',', $aktion);
headerRedirect(PHPWCMS_URL.'index.php'.returnGlobalGET_QueryString(), 404);
}
} elseif(isset($_GET['aid'])) {
// try to find correct structure
$aktion = array(0,0,0,0,1,0);
$_GET['aid'] = explode('-', $_GET['aid'], 2); // now check for cp pagination
$content['aId_CpPage'] = isset($_GET['aid'][1]) ? intval($_GET['aid'][1]) : 0; // set cp paginate page
$_GET['aid'] = intval($_GET['aid'][0]);
if($_GET['aid']) {
$sql = 'SELECT article_cid FROM '.DB_PREPEND.'phpwcms_article WHERE ';
$sql .= 'article_deleted=0 ';
if(VISIBLE_MODE !== 2) {
$sql .= 'AND article_aktiv=1 AND article_public=1 ';
} elseif(VISIBLE_MODE === 1) {
$sql .= 'AND article_uid='.intval($_SESSION["wcs_user_id"]).' ';
}
$sql .= 'AND article_id='.$_GET['aid'].' LIMIT 1';
if($result = mysql_query($sql, $db)) {
if($row = mysql_fetch_row($result)) {
$aktion[0] = $row[0];
$aktion[1] = $_GET['aid'];
} else {
$content['404error'] = true;
}
mysql_free_result($result);
} else {
$content['404error'] = true;
}
}
if(!$aktion[1]) {
$content['aId_CpPage'] = 0; // no article = no pagination
}
} else {
// check the alias
$aktion = array(0,0,0,1,0,0);
if(count($GLOBALS['_getVar'])) {
reset($GLOBALS['_getVar']);
$alias = trim(key($GLOBALS['_getVar']));
if($alias && $GLOBALS['_getVar'][$alias] === '') { // alias must be empty ""
$where_alias = aporeplace($alias);
// we have to check against MySQL < 4.0 -> UNION unknown
// so use a workaround
if(PHPWCMS_DB_VERSION < 40000) {
$sql = "SELECT acat_id, (0) AS article_id, 1 AS aktion3, 0 AS aktion4 FROM " . DB_PREPEND . "phpwcms_articlecat ";
$sql .= "WHERE acat_trash=0 AND acat_aktiv=1 AND acat_alias='" . $where_alias . "' LIMIT 1";
$row = _dbQuery($sql);
if(!isset($row[0]['acat_id'])) {
$sql = "SELECT article_cid AS acat_id, article_id, 0 AS aktion3, 1 AS aktion4 FROM " . DB_PREPEND . "phpwcms_article ";
$sql .= "WHERE article_deleted=0 AND article_aktiv=1 AND article_alias='" . $where_alias . "' LIMIT 1";
$row = _dbQuery($sql);
}
} else {
$sql = "(SELECT acat_id, (0) AS article_id, 1 AS aktion3, 0 AS aktion4 FROM " . DB_PREPEND . "phpwcms_articlecat ";
$sql .= "WHERE acat_trash=0 AND acat_aktiv=1 AND acat_alias='" . $where_alias . "')";
$sql .= " UNION ";
$sql .= "(SELECT article_cid AS acat_id, article_id, 0 AS aktion3, 1 AS aktion4 FROM " . DB_PREPEND . "phpwcms_article ";
$sql .= "WHERE article_deleted=0 AND article_aktiv=1 AND article_alias='" . $where_alias . "') ";
$sql .= "LIMIT 1";
$row = _dbQuery($sql);
}
if(isset($row[0]['acat_id'])) {
$aktion[0] = $row[0]['acat_id'];
$aktion[1] = $row[0]['article_id'];
$aktion[3] = $row[0]['aktion3'];
$aktion[4] = $row[0]['aktion4'];
define('PHPWCMS_ALIAS', $alias);
} elseif($alias == $indexpage['acat_alias']) {
define('PHPWCMS_ALIAS', $alias);
} else {
$content['404error'] = true;
}
}
}
}
if(isset($_GET['print'])) {
$aktion[2] = 1;
define('PRINT_PDF', intval($_GET['print']) == 2 ? true : false);
unset($_getVar['print'], $_GET['print']);
}
// define special OUTPUT format/action
$phpwcms['output_action'] = false;
if(!empty($_GET['phpwcms_output_action']) || !empty($_POST['phpwcms_output_action'])) {
// split by function - value: F-function1|function2|function3--S-SECT1|SECT2|SECT3
$phpwcms['output_action'] = explode('--', clean_slweg( empty($_GET['phpwcms_output_action']) ? $_POST['phpwcms_output_action'] : $_GET['phpwcms_output_action'] ));
unset(
$_GET['phpwcms_output_action'],
$_POST['phpwcms_output_action'],
$_getVar['phpwcms_output_action']
);
if(is_array($phpwcms['output_action'])) {
$phpwcms['output_function'] = array();
$phpwcms['output_section'] = array();
foreach($phpwcms['output_action'] as $value) {
$value = trim($value);
if($value{0} == 'F') {
$value = explode('|', substr($value, 2));
$output_key = 'output_function';
} elseif($value{0} == 'S') {
$value = explode('|', substr($value, 2));
$output_key = 'output_section';
} else {
continue;
}
if(is_array($value)) {
foreach($value as $_value) {
$_value = trim($_value);
if($_value != '') {
$phpwcms[$output_key][$_value] = $_value;
}
}
}
}
$phpwcms['output_action'] = count($phpwcms['output_function']) || count($phpwcms['output_section']) ? true : false;
} else {
$phpwcms['output_action'] = false;
}
}
//define the current article category ID
$content["cat_id"] = $aktion[0];
$content['body_id'] = $content["cat_id"];
// check if current level is a redirect level
if(!empty($content['struct'][ $content["cat_id"] ]['acat_redirect'])) {
$redirect = get_redirect_link( $content['struct'][ $content["cat_id"] ]['acat_redirect'] );
headerRedirect($redirect['link'], 301);
}
//try to find current tree depth
$LEVEL_ID = array();
$LEVEL_KEY = array();
$LEVEL_STRUCT = array();
$level_ID_array = get_breadcrumb($content["cat_id"], $content['struct']);
$level_count = 0;
foreach($level_ID_array as $key => $value) {
$LEVEL_ID[$level_count] = $key;
$LEVEL_KEY[$key] = $level_count;
$LEVEL_STRUCT[$level_count] = $content['struct'][$key]['acat_name'];
if($PERMIT_ACCESS && $content['struct'][$key]['acat_regonly']) {
$PERMIT_ACCESS = false; // only users have been logged in get access
}
$level_count++;
}
define('PERMIT_ACCESS', $PERMIT_ACCESS);
// frontend login check
_checkFrontendUserAutoLogin();
// -------------------------------------------------------------
// read the template information for page based on structure
if($content["struct"][ $content["cat_id"] ]["acat_template"]) {
//if there is a template defined for this structure level
//then choose the template information based on this ID
$sql = "SELECT template_var FROM ".DB_PREPEND."phpwcms_template WHERE template_trash=0 AND ";
$sql .= "template_id=".$content["struct"][ $content["cat_id"] ]["acat_template"]." LIMIT 1;";
if($result = mysql_query($sql, $db)) {
if($row = mysql_fetch_row($result)) {
$block = unserialize($row[0]);
}
mysql_free_result($result);
}
}
if(!isset($block)) {
// if template ID is not defined or the were a problem with level's template ID then
// choose the default template or if no default template defined choose the next one
$sql = "SELECT template_var FROM ".DB_PREPEND."phpwcms_template ";
$sql .= "WHERE template_trash=0 ORDER BY template_default DESC LIMIT 1;";
if($result = mysql_query($sql, $db)) {
if($row = mysql_fetch_row($result)) {
$block = unserialize($row[0]);
}
mysql_free_result($result);
}
}
// compatibility for older releases where only
// 1 css file could be stored per template
if(is_string($block['css'])) {
$block['css'] = array($block['css']);
}
// check if template_defaults should be overwritten
if(!empty($block['overwrite'])) {
$block['overwrite'] = str_replace('/', '', $block['overwrite']);
@include(PHPWCMS_TEMPLATE.'inc_settings/template_default/'.$block['overwrite']);
}
if(!empty($content['struct'][ $content['cat_id'] ]['acat_overwrite'])) {
$block['overwrite'] = str_replace('/', '', $content['struct'][ $content['cat_id'] ]['acat_overwrite']);
@include(PHPWCMS_TEMPLATE.'inc_settings/template_default/'.$block['overwrite']);
}
// load frontend JavaScript lib file
require PHPWCMS_ROOT.'/include/inc_front/js.inc.php';
// -------------------------------------------------------------
// retrieve pagelayout info
// check how the content should be rendered based on pagelayout render value
$block["layout"] = intval($block["layout"]);
$sql = "SELECT pagelayout_var FROM ".DB_PREPEND."phpwcms_pagelayout WHERE pagelayout_trash=0 ";
$sql .= $block["layout"] ? "AND pagelayout_id=".$block["layout"] : "ORDER BY pagelayout_default DESC";
$sql .= " LIMIT 1";
$result = _dbQuery($sql);
if(isset($result[0]['pagelayout_var'])) {
$pagelayout = @unserialize($result[0]['pagelayout_var']);
// if print action
if($aktion[2] === 1) {
$pagelayout = array('layout_title' => $pagelayout['layout_title'], 'layout_customblocks' => $pagelayout['layout_customblocks']);
}
}
if(empty($pagelayout)) {
// if no pagelayout could be found
die('There is no pagelayout available. Please login to the admin section and create one here!');
}
// Pagetitle
$content["pagetitle"] = empty($pagelayout["layout_title"]) ? '' : $pagelayout["layout_title"];
//generate the colspan attribute
$colspan = get_colspan($pagelayout);
// -------------------------------------------------------------
// now initialize content blocks like CONTENT, HEADER, LEFT, RIGHT, FOOTER
$content['main'] = ''; // {CONTENT}
$content['CB']['LEFT'] = ''; // {LEFT}
$content['CB']['RIGHT'] = ''; // {RIGHT}
$content['CB']['HEADER'] = ''; // {HEADER}
$content['CB']['FOOTER'] = ''; // {FOOTER}
// and try to add and initialize custom blocks
if(!empty($pagelayout['layout_customblocks'])) {
$custom_blocks = explode(', ', $pagelayout['layout_customblocks']);
foreach($custom_blocks as $value) {
if($value != '') $content['CB'][$value] = '';
}
unset($custom_blocks);
}
// -------------------------------------------------------------
// try to include custom functions or what ever you want to do at this point of the script
// default dir: "phpwcms_template/inc_script/frontend_init"; only *.php files are allowed there
if($phpwcms["allow_ext_init"]) {
if(count($custom_includes = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_script/frontend_init', 'php'))) {
foreach($custom_includes as $value) {
include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_init/'.$value);
}
}
}
// include custom frontend init scripts based on module definitions
if(count($phpwcms['modules_fe_init'])) {
foreach($phpwcms['modules_fe_init'] as $value) {
include_once($value);
}
}
// redirect to login form if user is not logged in and has no permission to access level
if(!PERMIT_ACCESS && !_getFeUserLoginStatus()) {
if(!empty($block['feloginurl'])) {
$template_default['login_form_url'] = str_replace('{SITE}', PHPWCMS_URL, $block['feloginurl']);
} elseif(empty($template_default['login_form_url'])) {
$template_default['login_form_url'] = PHPWCMS_URL;
}
// store current URL
$_SESSION['LOGIN_REDIRECT'] = decode_entities(FE_CURRENT_URL);
// redirect to login form
headerRedirect($template_default['login_form_url'], 401);
}
// -------------------------------------------------------------
//reads all articles for active cat into array
$content["articles"] = get_actcat_articles_data($content["cat_id"]);
$content["article_list_count"] = count($content["articles"]);
// -------------------------------------------------------------
// generating a list of articles inside the current article category
if(!$aktion[4]) {
if(!$content['404error'] && ($content["article_list_count"] || $content['struct'][ $content['cat_id'] ]['acat_topcount'] == -1)) {
if($content["article_list_count"] == 1 || $content['struct'][ $content['cat_id'] ]['acat_topcount'] == -1) {
// if($temp_counter == 1) {
// if only 1 article for this category available
// then show this article directly
// sets article ID to this only 1 article
foreach($content["articles"] as $key => $value) {
$aktion[1] = intval($key);
break;
}
$aktion[4] = 1; // this needs to be set to 1 for showing the article
// enable canonical tag
$content['set_canonical'] = true;
} else {
// there is more than 1 article inside this category
// -> list all - the 1st will be shown with summary and such stuff
$content["main"] .= list_articles_summary();
}
} else {
$no_content_for_this_page = 1;
}
} elseif($content["article_list_count"] === 1) {
// enable canonical tag
$content['set_canonical'] = true;
}
// -------------------------------------------------------------
// check if current category should be cached
if($content['struct'][$content['cat_id']]['acat_timeout'] != '') {
$phpwcms['cache_timeout'] = $content['struct'][$content['cat_id']]['acat_timeout'];
}
// set search status for current category
$cache_searchable = $content['struct'][$content['cat_id']]['acat_nosearch'];
// -------------------------------------------------------------
$content['list_mode'] = true;
if($aktion[1]) {
// render page based on article
include_once(PHPWCMS_ROOT."/include/inc_front/content.article.inc.php");
$content['list_mode'] = false;
} elseif(!empty($content['struct'][$content['cat_id']]['acat_pagetitle'])) {
// a custom pagetitle for structure level exists
$content["pagetitle"] = $content['struct'][$content['cat_id']]['acat_pagetitle'];
} else {
$content["pagetitle"] = setPageTitle($content["pagetitle"], $content['struct'][$content['cat_id']]['acat_name'], '');
}
// -------------------------------------------------------------
//check for no content error
$content["main"] = trim($content["main"]);
if($content['404error'] || $no_content_for_this_page || $content["main"] == '') {
header('HTTP/1.0 404 Not Found');
$content["main"] .= $block["errortext"];
}
// -------------------------------------------------------------
//check if one of needed block texts and values are empty and if then fill with content
if(!$block["maintext"]) {
$block["maintext"] = $content["main"];
}
// -------------------------------------------------------------
//normal page operation
if($aktion[2] == 0) {
switch($pagelayout["layout_render"]) {
case 0: //create the page layout table (header, left, content, right, footer)
$content["all"] = "
'.LF; //end main table
break;
case 1: //create the page layout based on DIV (layer)
//contentContainer DIV start
$content["all"] = '';
$pagelayout['additional_wrap_div'] = false;
switch($pagelayout["layout_align"]) {
case 1: $content["all"] .= '
';
$pagelayout['additional_wrap_div'] = true;
break;
case 2: $content["all"] .= '