diff --git a/Dockerfile b/Dockerfile index a6b7060..502e4ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,4 +19,9 @@ RUN chown -R www-data:www-data /var/www EXPOSE 80 RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/ RUN rm /var/www/html/index.html -RUN service apache2 restart \ No newline at end of file +RUN service apache2 restart + +# docker build -t n2web-arm:latest.arm -f ./Dockerfile-arm . +# docker build -t n2web:latest -f ./Dockerfile . +#docker push vanderlars/notion2web:latest; +#docker push vanderlars/notion2web-arm:latest; \ No newline at end of file diff --git a/app/functions.php b/app/functions.php index 452e005..f0af6a7 100644 --- a/app/functions.php +++ b/app/functions.php @@ -59,6 +59,9 @@ function __construct($path_, $name_, $type_, $loadHtml = false, $parent_ = NULL) } else { } + if ($this->objectType == 1 && $loadHtml == true) { + $this->html = str_replace($this->title, $this->removePrefixesAtBeginning($this->title), $this->html); + } // load children when directory $childrenWrongOrder = []; @@ -124,15 +127,72 @@ private function getPageTitle() $this->loadHTML(); } $cnt = $this->html; + $sanitizeTitle = ''; preg_match('~(?s)(?<=)(.+?)(?=<\/h1>)~', $cnt, $title_match); if (count($title_match) > 0) { $sanitizeTitle = preg_replace('~<[^>]*>~', '', $title_match[0]); - return $sanitizeTitle; } else { - return $this->name; + $sanitizeTitle = $this->name; + } + $title_with_numbers = $sanitizeTitle; + // remove numbers from titles (if set in config) + global $remove_beginning_numbers; + if ($remove_beginning_numbers == true && $this->startsWithNumber($sanitizeTitle)) { + //change title + $sanitizeTitle = $this->removeNumbersAtBeginning($sanitizeTitle); + + //replace it also in the html + $this->html = str_replace($title_with_numbers, $sanitizeTitle, $this->html); + } + + return $sanitizeTitle; + } + } + private function startsWithNumber($str) + { + $nbrs = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; + $ret = false; + foreach ($nbrs as $nbr) { + if (str_starts_with($str, $nbr)) { + $ret = true; + } + } + return $ret; + } + private function removeNumbersAtBeginning($str) + { + $spl = explode(' ', $str); + array_splice($spl, 0, 1); + $ret = implode(' ', $spl); + return $ret; + } + private function removePrefixesAtBeginning($str) + { + global $hide_from_navigation_with_prefix; + if (count($hide_from_navigation_with_prefix) > 0) { + foreach ($hide_from_navigation_with_prefix as $prefix) { + if (str_starts_with($str, $prefix)) { + $str = str_replace($prefix, '', $str); + } + } + } + + return $str; + } + private function displayPageInNavigation() + { + //tells you weather a page with a specific prefix should be displayed in the navigation or not + global $hide_from_navigation_with_prefix; + $ret = true; + if (count($hide_from_navigation_with_prefix) > 0) { + foreach ($hide_from_navigation_with_prefix as $prefix) { + if (str_starts_with($this->fileName, $prefix)) { + $ret = false; + } } } + return $ret; } public function getBreadcrumbs() @@ -246,7 +306,7 @@ public function getFileTree() foreach ($theNewOrder as $child) { if ($child->objectType == 1) { // file - if (str_ends_with($child->fileName, '.html') == true) { + if (str_ends_with($child->fileName, '.html') == true && $child->displayPageInNavigation()) { $class_has_children = ''; $div_has_children = ''; if ($child->hasSubItems()) { @@ -259,7 +319,9 @@ public function getFileTree() } } else { // directory - $ret .= ''; + if ($child->displayPageInNavigation()) { + $ret .= ''; + } } } $ret .= ''; @@ -329,8 +391,8 @@ function sanitizeNotionHtml($html) // 3.replace hyperlinks preg_match_all('/]* href="([^"]*)"/im', $html, $link_match); $this_match = $link_match[1]; - $imageFormats = ['.png','.svg','.bmp','.jpg','.jpeg','.webp', '.tif', '.tiff', '.gif', '.eps', '.apng', '.avif', '.jpg', '.jpeg', '.jfif', '.pjpeg', '.pjp', '.ico', '.cur']; - + $imageFormats = ['.png', '.svg', '.bmp', '.jpg', '.jpeg', '.webp', '.tif', '.tiff', '.gif', '.eps', '.apng', '.avif', '.jpg', '.jpeg', '.jfif', '.pjpeg', '.pjp', '.ico', '.cur']; + if ($this_match) { $arr_length = count($this_match); for ($i = 0; $i < $arr_length; $i++) { @@ -340,8 +402,8 @@ function sanitizeNotionHtml($html) // check if url is an image $isImage = false; - foreach($imageFormats as $format){ - if (str_ends_with($workUrl, $format)){ + foreach ($imageFormats as $format) { + if (str_ends_with($workUrl, $format)) { $isImage = true; } } @@ -382,9 +444,9 @@ function sanitizeNotionHtml($html) $newStr = 'href="' . $oldUrl; } - if(str_contains($newStr, 'class="')){ - $newStr = str_replace('class="', 'class="n2web_external_link ', $newStr); - }else{ + if (str_contains($newStr, 'class="')) { + $newStr = str_replace('class="', 'class="n2web_external_link ', $newStr); + } else { $newStr = str_replace('href="', 'class="n2web_external_link" href="', $newStr); } $html = str_replace($replaceStr, $newStr, $html); @@ -396,6 +458,18 @@ function sanitizeNotionHtml($html) } } + // replace prefix for hidden pages + preg_match_all('/(.+?)<\/a>/im', $html, $output_array); + $this_match_2 = $output_array[1]; + + if ($this_match_2) { + $arr_length = count($this_match_2); + for ($i = 0; $i < $arr_length; $i++) { + $oldUrl = $this_match_2[$i]; + $html = str_replace($oldUrl, $this->removePrefixesAtBeginning($oldUrl), $html); + } + } + return $html; } @@ -479,7 +553,6 @@ private function getMySeachResult() // search functions function get_corpus_index($corpus = array(), $separator = ' ') { - $dictionary = array(); $doc_count = array(); @@ -502,9 +575,7 @@ function get_corpus_index($corpus = array(), $separator = ' ') $dictionary[$term]['postings'][$doc_id]['term_frequency']++; } - //from http://phpir.com/simple-search-the-vector-space-model/ - } return array('doc_count' => $doc_count, 'dictionary' => $dictionary); @@ -553,15 +624,6 @@ function get_similar_documents($query = '', $corpus = array(), $separator = ' ') return $similar_documents; } - - -function build_sorter($key) -{ - return function ($a, $b) use ($key) { - return strnatcmp($a[$key], $b[$key]); - }; -} - function searchBreadcrumbs($searchTerm) { $ret = ''; diff --git a/app/no_access.tpl b/app/no_access.tpl new file mode 100644 index 0000000..f02877b --- /dev/null +++ b/app/no_access.tpl @@ -0,0 +1,99 @@ +{* Smarty *} + + + + + + + + + + {$seo_title} + + + + + + + + + + + + +
+
+ +
+ ☰ +
+ + +
+
+
+
+
+ +
+ +
+ +
+ +
+
+ +
+ {$noAccessMessage} +
+ +
+
+
+ + + + \ No newline at end of file diff --git a/app/themes/onepage_light/index.tpl b/app/themes/onepage_light/index.tpl new file mode 100644 index 0000000..d9bbaa8 --- /dev/null +++ b/app/themes/onepage_light/index.tpl @@ -0,0 +1,136 @@ +{* Smarty *} + + + + + + + + + + {$seo_title} + + + + + + + + + + + + + + + + +
+
+ +
+ ☰ +
+ + +
+
+ +
+
+ {*
+ +
+ {$document_tree} +
+ +
*} + +
+
+ {*
+ {if $is_search eq true} + {$searchBreadcrumbs} + {else} + {$breadcrumbs} + {/if} +
*} +
+ + {if $is_search eq true} + +

Search results for "{$searchTerm}"

+ + +
+ + {else} + +
+ {$selectedItem->html} +
+ {/if} + +
+
+
+ + + + \ No newline at end of file diff --git a/app/themes/onepage_light/theme.css b/app/themes/onepage_light/theme.css new file mode 100644 index 0000000..2d9f674 --- /dev/null +++ b/app/themes/onepage_light/theme.css @@ -0,0 +1,579 @@ +html, body { + font-family: "Nunito Sans"; + margin: 0; + color: #111111; + background: #fff; + font-size: 14pt; + font-weight: 100; +} + +body { + height: 100%; + min-height: 100vH; +} + +* { + box-sizing: border-box; + -webkit-print-color-adjust: exact; +} + +ol, ul { + padding-left: 0; + margin-top: 0; +} + +h1, h2, h3, h4, h5, h6 { + margin: 0; + padding: 0; +} + +.n2web_structure { + width: 80%; + margin: 0 auto; + max-width: 1080px; +} + +.n2web_header { + margin: 0 auto; + width: 100%; + position: sticky; + top: 0; + background: #ffffffbf; + backdrop-filter: blur(10px); + -webkit-backdrop-filter: blur(10px); + border-bottom: 1px solid transparent; + border-bottom: 1px solid #e7f3f8; +} + +.n2web_header_inner { + width: 80%; + margin: 0 auto; + max-width: 1080px; + height: 60px; + /* background: #fbfaf9; */ + border-radius: 10px; + /* box-shadow: 0 5px 15px #00000026; */ + margin-top: 20px; +} + +.n2web_content { + padding-top: 15px; + min-height: calc(100vH - 100px); +} + +/* .n2web_content_inner { + margin-left: 265px; + overflow: scroll; +} */ + +.n2web_sidebar { + height: calc(100vH - 50px); + border-right: 1px solid #eeedeb; + position: fixed; + top: 50px; +} + +.n2web_search { + height: 60px; + border-bottom: 1px solid #eeedeb; + padding: 15px; + width: 100%; + background-color: #fff; + float: left; +} +.n2web_search_result hr { + background-color: #eeedeb; + color: #eeedeb; + border: 0; + height: 1px; + background-image: none; +} +.n2web_search .n2web_search_box:before { + content: "🔍︎"; + position: absolute; + margin-left: 8px; + margin-top: 4px; + font-size: 12px; +} + +.n2web_search input { + width: 100%; + border: 1px solid #eeedeb; + border-radius: 5px; + line-height: 17px; + padding: 6px 5px 4px 5px; + padding-left: 30px; + transition: all 0.3s ease; + background: #fff; +} + +.n2web_search input:hover { + border: 1px solid #a9d2f3; + outline: none; +} + +.n2web_search input:focus { + border: 1px solid #2196f3; + outline: none; +} + +.n2web_documenttree { + float: left; + height: calc(100% - 110px); + overflow: scroll; + /* border: 1px solid; */ + width: 100%; +} + + + +/* search */ +.n2web_searchResults{ + margin-top: 65px; +} +.n2web_searchResults_inner{ + margin-top: 15px; +} +.n2web_search_result { + border: 1px solid #eeedeb; + border-radius: 5px; + padding: 15px; + margin-bottom: 15px; + color: #111; + background: #fff; + transition: all 0.3s ease; + /* box-shadow: 0 2px 4px #d3cfc6; */ +} + +.n2web_search_result p { + color: rgba(0, 0, 0, 0.6); +} + +.n2web_search_result:hover { + background: #0000000f; + border: 1px solid #e5e4e3; + /* box-shadow: 0 2px 4px #d3cfc6; */ +} + +.n2web_search_result p, +.n2web_searchResults a { + text-decoration: none; + color: #111; + display: inline-block; + margin-right: 0px; + margin-left: 0px; +} +a.n2web_external_link::after { + content: " ↗"; +} + +.n2web_footer { + left: 0px; + /* width: 80%; */ + height: 50px; + border-top: 1px solid #0000000f; + top: 100vH; + position: sticky; + margin: 0 auto; + max-width: 1080px; + background: #fff; +} + + + + + + +/* sidebar */ +.n2web_file { + margin: 10px; +} + +.n2web_group { + height: 0px; + overflow: hidden; + width: 100%; + margin-left: 10px; + opacity: 0; +} + +.n2web_group.manual { + transition: all 0.8s ease; +} + +.manual .n2web_show_children::before { + transition: all 0.3s ease; +} + +.n2web_group.opened { + height: auto; + overflow: hidden; + opacity: 1; + width: auto; +} + +.n2web_show_children::before { + content: "→"; + width: 16px; + float: left; + line-height: 22px; + cursor: pointer; + padding: 0 3px; + margin-top: 0px; + border-radius: 3px; + text-align: center; +} + +.n2web_show_children:hover:before { + background: #d9d9d9; +} + +.opened>.n2web_show_children::before { + transform: rotate(90deg); +} + +.n2web_file.no_children { + margin-left: 28px; +} + +.n2web_breadcrumbs { + border-bottom: 1px solid #0000000f; + padding-bottom: 14px; + width: 100%; + background-color: #fff; + float: left; + margin-bottom: 10px; + padding-top: 2px; +} + +.n2web_breadcrumb_devider, +.n2web_breadcrumb_item { + float: left; + margin: 5px 7px 5px 0; +} + +.n2web_breadcrumb_devider { + color: rgb(229 228 226); +} + +.n2web_breadcrumb_devider:after { + content: "/"; +} + +.n2web_breadcrumbs:nth-last-child() { + transition: all 0.3s ease; +} + +.n2web_breadcrumbs a { + color: #666; + font-size: 14px; + text-decoration: none; + transition: all 0.3s ease; + padding: 2px 4px; + border-radius: 3px; +} + +.n2web_breadcrumbs a:hover { + font-size: 14px; + text-decoration: none; + color: rgba(17, 17, 17, 1); + background: #0000000f; +} + +a.table_of_contents-link { + transition: all 0.3s ease; + font-size: 14px; + border-bottom: none; +} + +a.table_of_contents-link:hover { + background: #e5e4e2; +} + + +.n2web_jumpmark_selected { + /* color: rgb(47, 165, 125); */ + transition: all 0.3s ease; + animation: color-fade 5s; + border-radius: 3px; + padding-left: 5px; + margin-left: -5px; +} + +@keyframes color-fade { + 0% { + background: transparent; + } + + 15% { + background: #0000000f; + + } + + 75% { + background: #0000000f; + } + + 100% { + background: transparent; + } +} + +@keyframes opacity-fade { + 0% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} + +/* Menu */ +.n2web_menu_item { + float: left; + padding: 6px 8px; + margin: 10px 3px; + border-radius: 5px; +} + +.menu_right { + float: right; +} + +.n2web_menu_item:hover { + background: #0000000f; + color: #1c1b1b; +} + +a .n2web_menu_item { + color: #111111; + text-decoration: none; + transition: all 0.3s ease; +} + +.footer_menu .n2web_menu_item { + font-size: 14px; +} + + + +.table_of_contents { + float: right; + padding: 15px; + margin-left: 15px; + border-radius: 5px; + transition: all 0.8s ease; +} + +.table_of_contents:hover { + background: #f7f7f6; +} + +.n2web_header_main_logo { + float: left; +} + +.n2web_header_main_logo img, .n2web_header_main_logo a { + height: 40px; + margin-top: 5px; +} + +.n2web_header_main_title { + float: right; +} + +.n2web_header_main_title h1 { + color: #111; + font-weight: 200; + font-size: 28px; + padding: 8px; +} + + +.n2web_sidebar ul, +.n2web_sidebar ul ul, +.n2web_sidebar li { + font-size: 12px; +} + +li.n2web_file { + list-style: none; + padding: 2px 5px; + margin: 2px 5px; + border-radius: 3px; +} + +li.n2web_file a { + color: rgba(0, 0, 0, 0.6); + font-size: 15px; + line-height: 22px; + text-decoration: none; + font-weight: 430; + padding: 0px 4px; + border-radius: 3px; + display: inline-block; +} + +article a, +summary { + transition: all 0.3s ease; +} +article a{ + background: #f9f2e5; +} +article figure.image a, article a.bookmark{ + background: transparent; +} + +article a { + padding: 3px 4px; + margin: 0 -4px; + border-radius: 3px; + color: #656564; +} + +article img.page-cover-image { + border-radius: 15px; + box-shadow: 0 30px 40px #c1c1c1; + width: calc(100% - 6px); + margin: 3px; +} + +article .table_of_contents-link { + opacity: 1; +} + +li.n2web_file a:hover, +article a:hover, +summary:hover, +a.table_of_contents-link:hover { + color: rgba(17, 17, 17, 1); + background: #0000000f; +} + +figure.image a:hover { + background: transparent; +} + +article img { + opacity: 0; +} + +article { + animation: opacity-fade 0.5s; +} +article img { + animation: opacity-fade 1s; +} + +article img { + opacity: 1; +} + +.callout a:hover { + color: rgba(17, 17, 17, 1); + background: #fff; +} + +li.n2web_file a, +.n2web_file.has_children a { + max-width: calc(100% - 22px); + transition: background 0.3s ease, color 0.3s ease; +} + +li.n2web_file.selected a, +.n2web_file.has_children.opened a { + font-weight: 600; + color: rgba(17, 17, 17, 1); +} + +figure:not(.image) a[target=_blank]:not(.bookmark-image):not(.bookmark)::after{ + content: ' ↗'; + left: 0; +} + +article .code, article code { + font-size: 100%; +} + +article li, article ul, article p, .callout { + line-height: 24px; +} + +article p { + margin-top: 0px; + margin-bottom: 15px; +} + +article .code, +article .bookmark-info { + overflow: scroll; +} + +summary { + cursor: pointer; + padding: 3px 3px 3px 6px; + margin: -3px -3px -3px -6px; + border-radius: 3px; +} + +article ul.toggle>li { + list-style: none; + overflow: scroll; +} + +article figure.image img { + border-radius: 15px; + box-shadow: 0 5px 20px #85858587; +} +article a span.icon { + line-height: 18px; +} + +article .block-color-red_background, +article .block-color-blue_background, +article .block-color-teal_background, +article .block-color-orange_background { + border-radius: 5px; +} +.highlight-teal_background, +.highlight-blue_background, +.highlight-yellow_background{ + padding: 5px 10px; + border-radius: 5px; + margin-right: 10px; +} + +.block-color-teal_background a { + background: #bbd9b6; +} +.block-color-blue_background a { + background: #add2e1; +} +.block-color-red_background a { + background: #e9c4c7; +} +.block-color-orange_background a { + background: #e3ccb6; +} + + + +.block-color-gray_background { + width: auto; + float: left; + padding: 15px; + margin-right: 15px; +} +article .block-color-gray_background { + background: rgb(255 255 255); + box-shadow: 0 5px 20px #85858540; + border-radius: 10px; +} +figure .source { + border-radius: 15px; + background: #f1f1ef; + border: none; + box-shadow: 0 5px 20px #85858587; +} \ No newline at end of file diff --git a/app/themes/onepage_light/theme.js b/app/themes/onepage_light/theme.js new file mode 100644 index 0000000..f9cdd78 --- /dev/null +++ b/app/themes/onepage_light/theme.js @@ -0,0 +1,101 @@ + +// document loaded +$(document).ready(function () { + // highlight selected page in sidebar + let currentLocation = document.location.href; + let cl_split = currentLocation.split("&id="); + + if (cl_split.length > 1) { + let cl_splithash = cl_split[1].split("#"); + let elementid = cl_splithash[0] + "_file"; + let menuelem = $('#' + elementid); + $(menuelem).addClass('selected'); + openParentMenu($(menuelem).parent(), false); + + // jump to selected page in sidebar + document.getElementById(elementid).scrollIntoView(); + + if(cl_splithash.length > 1){ + // when internal jumo mark clicked also jump to this position + let elementid2 = cl_splithash[1]; + document.getElementById(elementid2).scrollIntoView(); + $('#' + elementid2).addClass('n2web_jumpmark_selected'); + } + } + + $( ".n2web_group" ).first().addClass('opened'); + $( ".n2web_file.has_children" ).first().addClass('opened'); + + + // menu functionality + $(".n2web_show_children").click(function () { + let n2webid = $(this).data( "n2webid" ); + toggleMenuOpen(n2webid, true); + }); + $("a.table_of_contents-link").click(function () { + let n2webid = $(this).attr('href'); + let element = $(n2webid); + highlightJumpMark(element); + }); + $(".n2web_header_mobile_menu_button").click(function (){ + var element = $(".n2web_header_menu.menu_right"); + if($(element).hasClass('opened')){ + $(element).removeClass('opened'); + $(element).removeClass('opened'); + }else{ + $(element).addClass('opened'); + $(element).addClass('opened'); + } + }) + +}); + + + +function toggleMenuOpen(n2webid, manual){ + var cl = ''; + if (manual == true){ + $('#'+n2webid+'_dir').addClass('manual'); + $('#'+n2webid+'_file').addClass('manual'); + }else{ + // cl = 'opened'; + } + + if($('#'+n2webid+'_dir').hasClass('opened')){ + $('#'+n2webid+'_dir').removeClass('opened'); + $('#'+n2webid+'_file').removeClass('opened'); + }else{ + $('#'+n2webid+'_dir').addClass('opened'); + $('#'+n2webid+'_file').addClass('opened'); + } +} + +function openParentMenu(element, manual){ + if ($(element).hasClass('n2web_group')){ + let n2webid = $(element).data( "n2webid" ); + toggleMenuOpen(n2webid, manual); + openParentMenu($(element).parent(), manual); + } +} + +function highlightJumpMark(element){ + $('a').removeClass('n2web_jumpmark_selected'); + $(element).addClass('n2web_jumpmark_selected'); +} + +//Smooth-Scrolling +$(function() { + $('a[href*="#"]:not([href="#"])').click(function() { + if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { + var target = $(this.hash); + target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); + if (target.length) { + $('html, body').animate({ + scrollTop: target.offset().top + }, 1000); + return false; + } + } + }); + }); + diff --git a/app/themes/onepage_light/theme_mobile.css b/app/themes/onepage_light/theme_mobile.css new file mode 100644 index 0000000..f40763b --- /dev/null +++ b/app/themes/onepage_light/theme_mobile.css @@ -0,0 +1,78 @@ + +.n2web_header_mobile_menu_button { + display: none; +} +@media screen and (max-width:1024px) { + .n2web_structure{ + width: 100%; + } + .n2web_header_inner{ + width: 100%; + padding-left: 15px; + padding-right: 15px; + } + .n2web_content_inner{ + padding-right: 15px; + } + + .n2web_header_menu.menu_right { + background: #fff; + box-shadow: 0px 3px 5px #00000038; + border-radius: 5px; + top: 45px; + position: absolute; + right: 15px; + display: none; + } + .n2web_header_menu.menu_right.opened{ + display: block; + } + .menu_right .n2web_menu_item { + float: none; + } + .n2web_header_menu a{ + text-decoration: none; + } + .n2web_header_mobile_menu_button { + float: right; + font-size: 24px; + padding: 0px 8px; + display: block; + } + .column, .column-list { + width: 100% !important; + display: block !important; + padding-left: 0 !important; + padding-right: 0 !important; + } +} + +@media screen and (max-width:425px) { + .n2web_content_inner { + width: 100%; + margin: 0; + padding: 15px; + } + .n2web_sidebar { + width: 100%; + height: auto; + border-right: 1px solid #eeedeb; + position: initial; + z-index: 5; + } + .n2web_documenttree { + box-shadow: 0px 2px 2px #00000038; + } + .n2web_header { + box-shadow: 0px 3px 4px #00000038; + } + .n2web_header_inner{ + border: none; + } + .n2web_breadcrumbs{ + display: none; + } + .n2web_searchResults{ + margin-top: 0; + } +} \ No newline at end of file diff --git a/app/themes/sidebar_light/index.tpl b/app/themes/sidebar_light/index.tpl index b6fe189..42c38bd 100644 --- a/app/themes/sidebar_light/index.tpl +++ b/app/themes/sidebar_light/index.tpl @@ -78,9 +78,9 @@ {$breadcrumbs} {/if} + {if $is_search eq true}
- {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'); +}