- {if $is_search eq true}
Search results for "{$searchTerm}"
diff --git a/config.php b/config.php
index b84f056..3a46ebc 100644
--- a/config.php
+++ b/config.php
@@ -1,14 +1,41 @@
'start page'
+
+
+// ----------------------------------------------------
+// access code
+// ----------------------------------------------------
+$restrictAccess = true; // if set to true, then the site is blocked until you have an URL-Parameter with the accessKey like 'https://youn2website.com?accesskey=PutYourAccesKeyHere
+$accessKey = 'PutYourAccesKeyHere'; // the accesskey
+$saveInBrowser = true; // tells if n2web should set a cookie to save the information, that the user is authenticated
+$saveInBrowserForRestart = false; // set to true, if you want to save the login also if the users browsers was restarted. Saves the cookie for 30 days
+$cookieName = 'myNotionPageName'; // if you allow to save authentication to cookies, then we have to make sure that it is only for you instance
+$noAccessMessage = '
+
+ ✋ The access is restricted by the page owner
+
+
+ Sorry,
you need special access rights to enter this page.
+
Please contact the page owner for more informations.
+
+';
+
+// ----------------------------------------------------
// display settings
-$theme = 'sidebar_light'; // the theme name which should be used to render the page.
+// ----------------------------------------------------
+
+$theme = 'sidebar_light';
+// $theme = 'onepage_light'; // the theme name which should be used to render the page.
// $theme = 'sidebar_light_full_width';
// $theme = 'sidebar_dark';
// $theme = 'sidebar_dark_full_width';
@@ -34,12 +61,14 @@
];
-// END OF CHANGEABLE THINGS
+
+
+// ----------------------------------------------------
+// END OF CHANGEABLE THINGS
+// ----------------------------------------------------
// set up templating engine
$smarty->setTemplateDir('app/themes');
$smarty->setConfigDir('app/smarty/config');
$smarty->setCompileDir('app/smarty/compile');
$smarty->setCacheDir('app/smarty/cache');
-
-?>
diff --git a/index.php b/index.php
index 183ef9b..4a8518a 100644
--- a/index.php
+++ b/index.php
@@ -7,33 +7,45 @@
include('config.php');
include('app/functions.php');
-// $document_tree = getfolder('content');
-$document_tree = new N2webFolderItem('content', 'content', 0);
+// look for access
+$canAccess = false;
+if ($restrictAccess) {
+ // access can be restricted
+ $cookieName = "n2web_accessKey_" . $cookieName;
+ $parameterName = "accesskey";
+
+ //check url parameter 'accesskey'
+ if (isset($_GET[$parameterName]) && $_GET[$parameterName] == $accessKey) {
+ $canAccess = true;
+ }
-// URL-Parameter
-$selectedPath;
-$selectedName;
-$selectedItem;
+ // check cookie "n2web_accessKey_" . $cookieName
+ if (isset($_COOKIE[$cookieName]) && $_COOKIE[$cookieName] == $accessKey) {
+ $canAccess = true;
+ }
-if (isset($_GET['path']) && isset($_GET['name'])) {
- $selectedPath = urldecode($_GET['path']);
- $selectedName = urldecode($_GET['name']);
+ // if save cookie turned on, save cookie
+ if ($canAccess && $saveInBrowser) {
+ $exp = 0;
+ if ($saveInBrowserForRestart) {
+ $exp = time() + 60 * 60 * 24 * 30;
+ }
+ setcookie(
+ $cookieName,
+ $accessKey,
+ $expires_or_options = $exp,
+ $path = "",
+ $domain = "",
+ $secure = false,
+ $httponly = true
+ );
+ }
} else {
- $selectedPath = "";
- $selectedName = "";
+ $canAccess = true;
}
-if ($selectedPath != "") {
- $selectedItem = new N2webFolderItem($selectedPath, $selectedName, 1, true);
-} else {
- $firstItem = $document_tree->children[1];
-
- $selectedItem = new N2webFolderItem($firstItem->path, $firstItem->fileName, 1, true);
-}
-$breadcrumbs = $selectedItem->getBreadcrumbs();
-// themes
// header and basic informations
$smarty->assign('language', $language);
@@ -43,14 +55,6 @@
$smarty->assign('seo_robots', $seo_robots);
$smarty->assign('domain', getDomain());
$smarty->assign('theme', $theme);
-
-// the page contents
-$smarty->assign('document_tree', $document_tree->getFileTree());
-$smarty->assign('selectedItem', $selectedItem);
-$smarty->assign('selectedItemPath', $selectedItem->path . "/" . $selectedItem->fileName);
-$smarty->assign('selectedId', $selectedItem->id);
-$smarty->assign('breadcrumbs', $breadcrumbs);
-
// the menus
$smarty->assign('menu_left', $menu_left);
$smarty->assign('menu_right', $menu_right);
@@ -59,34 +63,73 @@
$smarty->assign('main_logo_light', $main_logo_light);
$smarty->assign('main_logo_dark', $main_logo_dark);
-
-// compile
-if (isset($_POST["search"]) || isset($_GET['q'])) {
- // search was made->get results
- $searchString = '';
- if (isset($_POST["search"])){
- //search over post object (search field)
- $searchString = $_POST["search"];
- }
- if (isset($_GET['q'])){
- //search over parameter
- $searchString = $_GET["q"];
+if ($canAccess) {
+ // $document_tree = getfolder('content');
+ $document_tree = new N2webFolderItem('content', 'content', 0);
+
+ // URL-Parameter
+ $selectedPath;
+ $selectedName;
+ $selectedItem;
+
+ if (isset($_GET['path']) && isset($_GET['name'])) {
+ $selectedPath = urldecode($_GET['path']);
+ $selectedName = urldecode($_GET['name']);
+ } else {
+ $selectedPath = "";
+ $selectedName = "";
}
-
- $search = $document_tree->getSearchResults($searchString);
- $rank = array_column($search, 'rank');
+ if ($selectedPath != "") {
+ $selectedItem = new N2webFolderItem($selectedPath, $selectedName, 1, true);
+ } else {
+ $firstItem = $document_tree->children[1];
- array_multisort($rank, SORT_DESC, $search);
+ $selectedItem = new N2webFolderItem($firstItem->path, $firstItem->fileName, 1, true);
+ }
- $smarty->assign('is_search', true);
- $smarty->assign('searchResults', $search);
- $smarty->assign('searchTerm', $searchString);
- $smarty->assign('searchBreadcrumbs', searchBreadcrumbs($searchString));
+ $breadcrumbs = $selectedItem->getBreadcrumbs();
+
+ // the page contents
+ $smarty->assign('document_tree', $document_tree->getFileTree());
+ $smarty->assign('selectedItem', $selectedItem);
+ $smarty->assign('selectedItemPath', $selectedItem->path . "/" . $selectedItem->fileName);
+ $smarty->assign('selectedId', $selectedItem->id);
+ $smarty->assign('breadcrumbs', $breadcrumbs);
+
+ // compile
+ if (isset($_POST["search"]) || isset($_GET['q'])) {
+ // search was made->get results
+ $searchString = '';
+ if (isset($_POST["search"])) {
+ //search over post object (search field)
+ $searchString = $_POST["search"];
+ }
+ if (isset($_GET['q'])) {
+ //search over parameter
+ $searchString = $_GET["q"];
+ }
+
+ $search = $document_tree->getSearchResults($searchString);
+
+ $rank = array_column($search, 'rank');
+
+ array_multisort($rank, SORT_DESC, $search);
+
+ $smarty->assign('is_search', true);
+ $smarty->assign('searchResults', $search);
+ $smarty->assign('searchTerm', $searchString);
+ $smarty->assign('searchBreadcrumbs', searchBreadcrumbs($searchString));
+ } else {
+ // normal page call
+ $smarty->assign('searchTerm', '');
+ $smarty->assign('is_search', false);
+ }
+
+ $smarty->display('app/themes/' . $theme . '/index.tpl');
} else {
- // normal page call
- $smarty->assign('searchTerm', '');
- $smarty->assign('is_search', false);
-}
+ // access not allowed
+ $smarty->assign('noAccessMessage', $noAccessMessage);
-$smarty->display('app/themes/' . $theme . '/index.tpl');
+ $smarty->display('app/no_access.tpl');
+}