. */ require_once dirname(__FILE__) . '/include/init.php'; function page_not_found($page, $create=false) { global $nk; if ($nk->checkPageName($page)) { if ($create && $nk->is_logged()) { header("Location: ".$nk->webPath."admin/create_page.php?page=".$page); exit; } global $tpl; $tpl->template_dir = BASE_PATH . '/admin/templates'; $tpl->compile_dir = BASE_PATH . '/cache/compiled_admin'; $tpl->cache = 0; $tpl->assign('page', $page); $tpl->display('not_found.tpl'); } else { echo '

404 Not Found

Back to homepage

'; } exit; } function nk_tpl_getPage($page) { global $nk; $content = $nk->getPage($page); $nk->setCurrentPage($page); if (empty($content)) return "Cette page n'existe pas, décrivez son contenu ici."; return $content; } function parsePluginParams($str) { $attributes = array(); $last_value = ''; $state = 0; // matches double quoted strings: // "foobar" // "foo\"bar" // "foobar" . "foo\"bar" $_db_qstr_regexp = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; // matches single quoted strings: // 'foobar' // 'foo\'bar' $_si_qstr_regexp = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\''; // matches single or double quoted strings $_qstr_regexp = '(?:' . $_db_qstr_regexp . '|' . $_si_qstr_regexp . ')'; preg_match_all('/(?:' . $_qstr_regexp . ' | (?>[^"\'=\s]+))+|[=]/x', $str, $match); foreach ($match[0] as $value) { if ($state == 0) { if (!is_string($value)) return "Invalid attribute name '".$value."'."; $attr_name = $value; $state = 1; } elseif ($state == 1) { if ($value != '=') return "Expecting '=' after '".$last_value."'"; $state = 2; } elseif ($state == 2) { if ($value == '=') return "Unexpected '=' after '".$last_value."'"; if ($value == 'yes' || $value == 'on' || $value == 'true') $value = true; elseif ($value == 'no' || $value == 'off' || $value == 'false') $value = false; elseif ($value == 'null') $value = null; elseif ($value[0] == '"' || $value[0] == "'") $value = trim(substr($value, 1, -1)); $attributes[$attr_name] = $value; $state = 0; } $last_value = $value; } if ($state == 1) return "Expecting '=' after '".$last_value."'"; elseif ($state == 2) return "Missing attribute value after '".$last_value."'"; return $attributes; } function nk_plugin_error($txt) { return '

Erreur plugin : '.htmlspecialchars($txt).'

'; } function nk_tpl_formatHTML($content) { global $nk, $tpl; $plugins = array(); $i = 1; while (preg_match('!\{([^\s\}]+)\s*([^\}]*)\}!', $content, $match)) { $plugins[$i] = array(strtolower(trim($match[1])), $match[2]); $content = str_replace($match[0], '', $content); $i++; } require_once BASE_PATH . '/include/garbage2xhtml/class.blockformat.php'; require_once BASE_PATH . '/include/garbage2xhtml/class.garbage2xhtml.php'; $g2x = new Garbage2xhtml(); $g2x->allowed_tags = $nk->allowed_html; $g2x->allowed_tags['nkplugin'] = array('id'); $g2x->remove_forbidden_tags = false; $content = $g2x->Process($content); // Make paragraphs $block_format = new BlockFormat(); $block_format->blockElements = '(h[1-6]|ol|ul|pre|blockquote|p|dl|object|table|div|nkplugin)'; $content = $block_format->Process($content); // Internal links $content = preg_replace( '/href=(["\']?):([a-z0-9_\/-]+)(\\1)/i', 'href="'.$nk->webPath.'\\2"', $content); // NK documents $content = preg_replace( '/src=(["\']?):([^\\1 ]+)(\\1)/i', 'src="'.$nk->webDocumentsPath.'\\2"', $content); $content = preg_replace( '/href=(["\']?)doc:([^\\1 ]+)(\\1)/i', 'href="'.$nk->webDocumentsPath . '\\2"', $content); unset($block_format); unset($g2x); foreach ($plugins as $key=>$plugin) { $name = $plugin[0]; $params = parsePluginParams($plugin[1]); if (!is_array($params)) { $plugin_out = '

Error in arguments of plugin '.$name.' : '.$params.'

'; } elseif (!file_exists(BASE_PATH . '/datas/plugins/function.' . $name . '.php')) { $plugin_out = '

There is no plugin named '.$name.'

'; } else { require_once BASE_PATH . '/datas/plugins/function.' . $name . '.php'; $function_name = 'tpl_function_'.$name; $plugin_out = $function_name($params, &$tpl, &$content); } $content = preg_replace('![^<]*!s', $plugin_out, $content); } unset($plugins); return $content; } $tpl->register_modifier('getPageContent', 'nk_tpl_getPage'); $tpl->register_modifier('formatHTML', 'nk_tpl_formatHTML'); $url = false; if (!empty($_SERVER['REDIRECT_URL'])) $url = $_SERVER['REDIRECT_URL']; elseif (!empty($_SERVER['REQUEST_URI'])) $url = $_SERVER['REQUEST_URI']; if (!empty($url)) { $url = preg_replace('/^'.preg_quote($nk->webPath, '/').'/', '', $url); if (empty($url)) { $page = 'Home'; } elseif (preg_match('/^([a-zA-Z0-9_\/-]+)$/', $url, $match)) { $page = $match[1]; $page = preg_replace('/\/{1,}/', '/' ,$page); } else { page_not_found($url); } header("Status: 200 OK", true, 200); } elseif (!empty($_GET['page'])) { $page = $_GET['page']; } if (empty($page)) { $page = 'Home'; } $cache_name = md5($page); if (!$tpl->is_cached('', $cache_name)) { $page = $nk->getValidPageName($page); if (!$page) { page_not_found($page); } if (!$nk->pageExists($page)) { page_not_found($page, true); } if ($nk->pageHaveMetas($page)) { $metas = $nk->getPageMetas($page); $tpl->assign('metas', $metas); if (!empty($metas['no_cache'])) { $tpl->cache = 0; $tpl->assign('is_logged', $nk->is_logged()); } } $tpl->assign('last_modification', $nk->getPageModifiedTimestamp($page)); $tpl->assign('page', $page); $tpl->assign('web_path', $nk->webPath); $tpl->assign('documents_path', $nk->webPath . 'datas/documents/'); } $display = $tpl->fetch('page.tpl', $cache_name); if ($nk->is_logged()) { $display = str_replace('var is_logged = 0;', 'var is_logged = 1;', $display); } echo $display; ?>