<?php
/* ---
Copyright (C) 2008-2009 Frank Smit
http://shinobu.61924.nl/
This file is part of Shinobu.
Shinobu 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 3 of the License, or
(at your option) any later version.
Shinobu 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.
You should have received a copy of the GNU General Public License
along with Shinobu. If not, see <http://www.gnu.org/licenses/>.
--- */
(!defined('SHINOBU')) ? exit : null;
$sys_request[2] = isset($sys_request[2]) && !empty($sys_request[2]) ? intval($sys_request[2]) : 0;
$language = isset($sys_user['language']) ? $sys_user['language'] : $sys_config['language'];
$cache_file_name = '.cache_page_'.$sys_request[2];
if (file_exists(SYS_CACHE_DIR.$cache_file_name) && file_exists(SYS_CACHE_DIR.$cache_file_name.'_info_'.$language))
{
$result = $sys_db->query('SELECT title, show_extra_info, private FROM '.DB_PREFIX.'pages WHERE id='.$sys_request[2].' AND status=1 LIMIT 1') or error($sys_db->error(), __FILE__, __LINE__);
$page = $sys_db->fetch_assoc($result);
if($page['private'] && (!$sys_user['logged'] || !$sys_user['p_access_private']))
{
send_403();
}
else
{
$sys_tpl->assign('page_title', $page['title'].' - '.$sys_config['website_title']);
require SYS_CACHE_DIR.$cache_file_name;
if ($page['show_extra_info'] == 1)
require SYS_CACHE_DIR.$cache_file_name.'_info_'.$language;
}
}
else
{
$result = $sys_db->query('
SELECT p.id, p.title, p.content, p.parser, p.create_date, p.edit_date, p.show_extra_info, p.private, u.id AS uid, u.username
FROM '.DB_PREFIX.'pages AS p
LEFT JOIN '.DB_PREFIX.'users AS u ON p.author=u.id
WHERE p.id='.$sys_request[2].' AND p.status=1 LIMIT 1') or error($sys_db->error(), __FILE__, __LINE__);
// Check if page exists
if ($sys_db->num_rows($result) > 0)
{
$page = $sys_db->fetch_assoc($result);
if($page['private'] && (!$sys_user['logged'] || !$sys_user['p_access_private']))
{
send_403();
}
else
{
$sys_tpl->assign('page_title', $page['title'].' - '.$sys_config['website_title']);
ob_start();
echo '<h2><span>', $page['title'], '</span></h2>', "\n";
if($page['parser'] === 'xhtml')
echo $page['content'];
else if (file_exists(SYS_LIBRARY_DIR.'markup_parsers/'.$page['parser'].'.php'))
{
require SYS_LIBRARY_DIR.'markup_parsers/'.$page['parser'].'.php';
echo parse($page['content']);
}
cache_data($cache_file_name, ob_get_clean());
require SYS_CACHE_DIR.$cache_file_name;
if ($page['show_extra_info'] == 1)
{
ob_start();
?>
<div class="page-toolbox">
<?php echo sprintf($sys_lang['d_page_created_by'], '<a href="'.WEBSITE_URL.URI_PREFIX.'profile/'.$page['uid'].URI_SUFFIX.'">'.utf8_htmlencode($page['username']).'</a>', format_time($page['create_date']));
echo $page['edit_date'] == 0 ? "\n" : sprintf($sys_lang['d_page_edited_on'], format_time($page['edit_date']))."\n" ?>
</div>
<?php
cache_data($cache_file_name.'_info_'.$language, ob_get_clean());
require SYS_CACHE_DIR.$cache_file_name.'_info_'.$language;
}
else
{
cache_data($cache_file_name.'_info_'.$language, '');
}
}
}
else
send_404();
}
?>