diff --git a/index.php b/index.php index 8b907d21..40ef9dfc 100644 --- a/index.php +++ b/index.php @@ -335,68 +335,17 @@ if($load_it) $logged_access = $account_logged->getAccess(); } - $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 - { - $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, ' $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); - } - + $success = false; + $tmp_content = getCustomPage($page, $success); + if($success) { + $content .= $tmp_content; if(hasFlag(FLAG_CONTENT_PAGES) || superAdmin()) { + $pageInfo = getCustomPageInfo($page); $content = $twig->render('admin.pages.links.html.twig', array( - 'page' => array('id' => $query['id'], 'hidden' => $query['hidden']) - )) . $content; + 'page' => array('id' => $pageInfo !== null ? $pageInfo['id'] : 0, 'hidden' => $pageInfo !== null ? $pageInfo['hidden'] : '0') + )) . $content; } - } - else - { + } else { $file = SYSTEM . 'pages/' . $page . '.php'; if(!@file_exists($file)) { @@ -443,4 +392,4 @@ if(superAdmin()) { } } -$hooks->trigger(HOOK_FINISH); \ No newline at end of file +$hooks->trigger(HOOK_FINISH); diff --git a/system/functions.php b/system/functions.php index 5fa343fe..f64c785a 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1129,6 +1129,85 @@ function clearCache() 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, ' $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 require_once LIBS . 'validator.php'; require_once SYSTEM . 'compat.php'; diff --git a/system/twig.php b/system/twig.php index 8d8790d3..9f484c7d 100644 --- a/system/twig.php +++ b/system/twig.php @@ -52,8 +52,15 @@ $function = new Twig_SimpleFunction('config', function ($key) { }); $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) { return urlencode($s); }); + $twig->addFilter($filter); unset($function, $filter);