. */ require_once dirname(__FILE__) . '/include/init.php'; $url = ''; if (!empty($_SERVER['REDIRECT_URL'])) $url = $_SERVER['REDIRECT_URL']; elseif (!empty($_SERVER['REQUEST_URI'])) $url = $_SERVER['REQUEST_URI']; elseif (!empty($_SERVER['QUERY_STRING'])) $url = $_SERVER['QUERY_STRING']; if (!empty($url)) { $url = preg_replace('/^'.preg_quote(utils::getBaseUrlPath(), '/').'/', '', $url); } // Media redirect if (preg_match('!^media/-([a-z0-9A-Z]+)-/.*!', $url, $match)) { $id = utils::url2id($match[1]); utils::redirect($nk->getMediaUrl($id), 302); } $id = $rev = 0; $lang = $uri = $pages = false; $context = 'page'; if (empty($url)) { $uri = '_home'; } elseif (preg_match('!^-([0-9A-Za-z]+)-/(history|comments)$!', $url, $match)) { $id = utils::url2id($match[1]); $context = $match[2]; } elseif (preg_match('!(?P.+)(?:/(?P[a-z]{2}))?(?:/r(?P[0-9]+))?$!U', $url, $match) && $nk->isValidPageUri($match['uri']) && $pages = $nk->getPagesIdsFromUri($match['uri'])) { $uri = $match['uri']; $rev = !empty($match['rev']) ? (int) $match['rev'] : 0; $lang = !empty($match['lang']) ? $match['lang'] : false; if ($lang) { if (isset($pages[$lang])) $id = $pages[$lang]; else handlePageNotFound($uri, $lang, $rev); } elseif (count($pages) == 1) { $id = current($pages); } else { $langs = utils::getHttpLanguages(); foreach ($langs as $lang) { if (isset($pages[$lang])) { utils::redirect($nk->getPageUrl(false, $uri, $lang, $rev), 302); break; } } $lang = $nk->getConfig('default_lang'); if (isset($pages[$lang])) { utils::redirect($nk->getPageUrl(false, $uri, $lang, $rev), 302); } utils::redirect($nk->getPageUrl(false, $uri, current($pages), $rev), 302); } } elseif (!$nk->emitSignal('url.call', array(&$url, &$id))) { handlePageNotFound($url); } header('Status: 200 OK', true, 200); if (!$id) { if (!$pages) $pages = $nk->getPagesIdsFromUri($uri); if (count($pages) == 1) { $id = current($pages); } else { $langs = utils::getHttpLanguages(); foreach ($langs as $lang) { if (isset($pages[$lang])) { $id = $pages[$lang]; break; } } if (!$id) { $lang = $nk->getConfig('default_lang'); if (isset($pages[$lang])) { $id = $pages[$lang]; } } if (!$id) { $id = current($pages); } } } if (!$id) { handlePageNotFound($url); } require_once BASE_PATH . '/include/template.php'; define('CURRENT_PAGE_ID', $id); $page = $nk->getPage($id, $rev); tpl_assign('page', $page); if ($context == 'history') { tpl_assign('title', $page['title'] . ' - History'); tpl_assign('history', $nk->getPageRevisionsList($id)); inc('page_history'); } elseif ($context == 'comments') { } else { tpl_assign($page); inc('page'); } /* print_r($page); $page['content'] = time(); $revision = array( 'author_name' => 'bohwaz', 'author_url' => 'http://bohwaz.net/', 'comment' => 'mise à jour', ); $nk->editPage($id, $page, $revision); print_r($nk->comparePageRevisions($id, $page['revision'], $page['revision'] - 1)); exit; */ function handlePageNotFound($url) { global $nk; if ($nk->emitSignal('url.notfound', array(&$url))) exit; require_once BASE_PATH . '/include/template.php'; tpl_assign('title', 'Page not found'); tpl_assign('url', $url); inc('notfound'); } /* 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('formatHTML', 'nk_tpl_formatHTML'); */ ?>