mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 01:39:22 +02:00
New functions: getCustomPage() and getCustomPageInfo()
This commit is contained in:
parent
8345b839e7
commit
1ab32ca3ba
65
index.php
65
index.php
@ -335,68 +335,17 @@ if($load_it)
|
|||||||
$logged_access = $account_logged->getAccess();
|
$logged_access = $account_logged->getAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
$query =
|
$success = false;
|
||||||
$db->query(
|
$tmp_content = getCustomPage($page, $success);
|
||||||
'SELECT `id`, `title`, `body`, `php`, `hidden`' .
|
if($success) {
|
||||||
' FROM `' . TABLE_PREFIX . 'pages`' .
|
$content .= $tmp_content;
|
||||||
' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access));
|
|
||||||
if($query->rowCount() > 0) // found page
|
|
||||||
{
|
|
||||||
$ignore = true;
|
|
||||||
$query = $query->fetch();
|
|
||||||
$title = $query['title'];
|
|
||||||
|
|
||||||
if($query['php'] == '1') // execute it as php code
|
|
||||||
{
|
|
||||||
$tmp = substr($query['body'], 0, 10);
|
|
||||||
if(($pos = strpos($tmp, '<?php')) !== false) {
|
|
||||||
$tmp = preg_replace('/<\?php/', '', $query['body'], 1);
|
|
||||||
}
|
|
||||||
else if(($pos = strpos($tmp, '<?')) !== false) {
|
|
||||||
$tmp = preg_replace('/<\?/', '', $query['body'], 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$tmp = $query['body'];
|
|
||||||
|
|
||||||
$php_errors = array();
|
|
||||||
function error_handler($errno, $errstr) {
|
|
||||||
global $php_errors;
|
|
||||||
$php_errors[] = array('errno' => $errno, 'errstr' => $errstr);
|
|
||||||
}
|
|
||||||
set_error_handler('error_handler');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
eval($tmp);
|
|
||||||
$content .= ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
|
|
||||||
restore_error_handler();
|
|
||||||
if(isset($php_errors[0]) && superAdmin()) {
|
|
||||||
var_dump($php_errors);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$oldLoader = $twig->getLoader();
|
|
||||||
|
|
||||||
$twig_loader_array = new Twig_Loader_Array(array(
|
|
||||||
'content.html' => $query['body']
|
|
||||||
));
|
|
||||||
|
|
||||||
$twig->setLoader($twig_loader_array);
|
|
||||||
|
|
||||||
$content .= $twig->render('content.html');
|
|
||||||
|
|
||||||
$twig->setLoader($oldLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) {
|
if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) {
|
||||||
|
$pageInfo = getCustomPageInfo($page);
|
||||||
$content = $twig->render('admin.pages.links.html.twig', array(
|
$content = $twig->render('admin.pages.links.html.twig', array(
|
||||||
'page' => array('id' => $query['id'], 'hidden' => $query['hidden'])
|
'page' => array('id' => $pageInfo !== null ? $pageInfo['id'] : 0, 'hidden' => $pageInfo !== null ? $pageInfo['hidden'] : '0')
|
||||||
)) . $content;
|
)) . $content;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$file = SYSTEM . 'pages/' . $page . '.php';
|
$file = SYSTEM . 'pages/' . $page . '.php';
|
||||||
if(!@file_exists($file))
|
if(!@file_exists($file))
|
||||||
{
|
{
|
||||||
|
@ -1129,6 +1129,85 @@ function clearCache()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCustomPageInfo($page)
|
||||||
|
{
|
||||||
|
global $db, $logged_access;
|
||||||
|
$query =
|
||||||
|
$db->query(
|
||||||
|
'SELECT `id`, `title`, `body`, `php`, `hidden`' .
|
||||||
|
' FROM `' . TABLE_PREFIX . 'pages`' .
|
||||||
|
' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access));
|
||||||
|
if($query->rowCount() > 0) // found page
|
||||||
|
{
|
||||||
|
return $query->fetch(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
function getCustomPage($page, &$success)
|
||||||
|
{
|
||||||
|
global $db, $twig, $title, $ignore, $logged_access;
|
||||||
|
|
||||||
|
$success = false;
|
||||||
|
$content = '';
|
||||||
|
$query =
|
||||||
|
$db->query(
|
||||||
|
'SELECT `id`, `title`, `body`, `php`, `hidden`' .
|
||||||
|
' FROM `' . TABLE_PREFIX . 'pages`' .
|
||||||
|
' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access));
|
||||||
|
if($query->rowCount() > 0) // found page
|
||||||
|
{
|
||||||
|
$success = $ignore = true;
|
||||||
|
$query = $query->fetch();
|
||||||
|
$title = $query['title'];
|
||||||
|
|
||||||
|
if($query['php'] == '1') // execute it as php code
|
||||||
|
{
|
||||||
|
$tmp = substr($query['body'], 0, 10);
|
||||||
|
if(($pos = strpos($tmp, '<?php')) !== false) {
|
||||||
|
$tmp = preg_replace('/<\?php/', '', $query['body'], 1);
|
||||||
|
}
|
||||||
|
else if(($pos = strpos($tmp, '<?')) !== false) {
|
||||||
|
$tmp = preg_replace('/<\?/', '', $query['body'], 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$tmp = $query['body'];
|
||||||
|
|
||||||
|
$php_errors = array();
|
||||||
|
function error_handler($errno, $errstr) {
|
||||||
|
global $php_errors;
|
||||||
|
$php_errors[] = array('errno' => $errno, 'errstr' => $errstr);
|
||||||
|
}
|
||||||
|
set_error_handler('error_handler');
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
eval($tmp);
|
||||||
|
$content .= ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
restore_error_handler();
|
||||||
|
if(isset($php_errors[0]) && superAdmin()) {
|
||||||
|
var_dump($php_errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$oldLoader = $twig->getLoader();
|
||||||
|
|
||||||
|
$twig_loader_array = new Twig_Loader_Array(array(
|
||||||
|
'content.html' => $query['body']
|
||||||
|
));
|
||||||
|
|
||||||
|
$twig->setLoader($twig_loader_array);
|
||||||
|
|
||||||
|
$content .= $twig->render('content.html');
|
||||||
|
|
||||||
|
$twig->setLoader($oldLoader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
// validator functions
|
// validator functions
|
||||||
require_once LIBS . 'validator.php';
|
require_once LIBS . 'validator.php';
|
||||||
require_once SYSTEM . 'compat.php';
|
require_once SYSTEM . 'compat.php';
|
||||||
|
@ -52,8 +52,15 @@ $function = new Twig_SimpleFunction('config', function ($key) {
|
|||||||
});
|
});
|
||||||
$twig->addFunction($function);
|
$twig->addFunction($function);
|
||||||
|
|
||||||
|
$function = new Twig_SimpleFunction('getCustomPage', function ($name) {
|
||||||
|
$success = false;
|
||||||
|
return getCustomPage($name, $success);
|
||||||
|
});
|
||||||
|
$twig->addFunction($function);
|
||||||
|
|
||||||
$filter = new Twig_SimpleFilter('urlencode', function ($s) {
|
$filter = new Twig_SimpleFilter('urlencode', function ($s) {
|
||||||
return urlencode($s);
|
return urlencode($s);
|
||||||
});
|
});
|
||||||
|
|
||||||
$twig->addFilter($filter);
|
$twig->addFilter($filter);
|
||||||
unset($function, $filter);
|
unset($function, $filter);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user