aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/page/search.php52
-rw-r--r--admin/post/search.php52
-rw-r--r--core/language/de.php12
-rw-r--r--core/language/en.php12
-rw-r--r--core/namespace/Page/Item.php14
-rw-r--r--template/admin/html/home.php20
-rw-r--r--template/admin/html/page/index.php5
-rw-r--r--template/admin/html/page/search.php20
-rw-r--r--template/admin/html/post/index.php5
-rw-r--r--template/admin/html/post/search.php20
-rw-r--r--template/admin/html/user/index.php5
-rw-r--r--template/admin/lang/de.php11
-rw-r--r--template/admin/lang/en.php11
-rw-r--r--template/admin/rsrc/main.css5
14 files changed, 238 insertions, 6 deletions
diff --git a/admin/page/search.php b/admin/page/search.php
new file mode 100644
index 0000000..c718caa
--- /dev/null
+++ b/admin/page/search.php
@@ -0,0 +1,52 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require '../../core/application.php';
+
+#===============================================================================
+# IF: Handle search request
+#===============================================================================
+if($search = HTTP::GET('q')) {
+ if($pageIDs = Page\Item::getSearchResultIDs($search, $Database)) {
+ foreach($pageIDs as $pageID) {
+ try {
+ $Page = Page\Factory::build($pageID);
+ $User = User\Factory::build($Page->attr('user'));
+
+ $pages[] = generatePageItemTemplate($Page, $User);
+ }
+ catch(Page\Exception $Exception){}
+ catch(User\Exception $Exception){}
+ }
+ }
+}
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+try {
+ $SearchTemplate = Template\Factory::build('page/search');
+ $SearchTemplate->set('QUERY', $search);
+ $SearchTemplate->set('PAGES', $pages ?? []);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_page_search'));
+ $MainTemplate->set('HTML', $SearchTemplate);
+
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ Application::exit($Exception->getMessage());
+}
+?> \ No newline at end of file
diff --git a/admin/post/search.php b/admin/post/search.php
new file mode 100644
index 0000000..3369be2
--- /dev/null
+++ b/admin/post/search.php
@@ -0,0 +1,52 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require '../../core/application.php';
+
+#===============================================================================
+# IF: Handle search request
+#===============================================================================
+if($search = HTTP::GET('q')) {
+ if($postIDs = Post\Item::getSearchResultIDs($search, [NULL, NULL, NULL], $Database)) {
+ foreach($postIDs as $postID) {
+ try {
+ $Post = Post\Factory::build($postID);
+ $User = User\Factory::build($Post->attr('user'));
+
+ $posts[] = generatePostItemTemplate($Post, $User);
+ }
+ catch(Post\Exception $Exception){}
+ catch(User\Exception $Exception){}
+ }
+ }
+}
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+try {
+ $SearchTemplate = Template\Factory::build('post/search');
+ $SearchTemplate->set('QUERY', $search);
+ $SearchTemplate->set('POSTS', $posts ?? []);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_post_search'));
+ $MainTemplate->set('HTML', $SearchTemplate);
+
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ Application::exit($Exception->getMessage());
+}
+?> \ No newline at end of file
diff --git a/core/language/de.php b/core/language/de.php
index a1f8060..5d29d5d 100644
--- a/core/language/de.php
+++ b/core/language/de.php
@@ -159,6 +159,12 @@ $LANGUAGE['delete_post'] = 'Beitrag löschen';
$LANGUAGE['delete_user'] = 'Benutzer löschen';
#===============================================================================
+# Items search
+#===============================================================================
+$LANGUAGE['search_page'] = 'Seiten durchsuchen';
+$LANGUAGE['search_post'] = 'Beiträge durchsuchen';
+
+#===============================================================================
# Item insert titles
#===============================================================================
$LANGUAGE['title_page_insert'] = $LANGUAGE['insert_page'];
@@ -180,6 +186,12 @@ $LANGUAGE['title_post_delete'] = $LANGUAGE['delete_post'];
$LANGUAGE['title_user_delete'] = $LANGUAGE['delete_user'];
#===============================================================================
+# Item search titles
+#===============================================================================
+$LANGUAGE['title_page_search'] = $LANGUAGE['search_page'];
+$LANGUAGE['title_post_search'] = $LANGUAGE['search_post'];
+
+#===============================================================================
# Item overview titles
#===============================================================================
$LANGUAGE['title_page_overview'] = "{$LANGUAGE['page_overview']} [%d]";
diff --git a/core/language/en.php b/core/language/en.php
index 55c0ce3..dc70154 100644
--- a/core/language/en.php
+++ b/core/language/en.php
@@ -159,6 +159,12 @@ $LANGUAGE['delete_post'] = 'Delete post';
$LANGUAGE['delete_user'] = 'Delete user';
#===============================================================================
+# Items search
+#===============================================================================
+$LANGUAGE['search_page'] = 'Search in pages';
+$LANGUAGE['search_post'] = 'Search in posts';
+
+#===============================================================================
# Item insert titles
#===============================================================================
$LANGUAGE['title_page_insert'] = $LANGUAGE['insert_page'];
@@ -180,6 +186,12 @@ $LANGUAGE['title_post_delete'] = $LANGUAGE['delete_post'];
$LANGUAGE['title_user_delete'] = $LANGUAGE['delete_user'];
#===============================================================================
+# Item search titles
+#===============================================================================
+$LANGUAGE['title_page_search'] = $LANGUAGE['search_page'];
+$LANGUAGE['title_post_search'] = $LANGUAGE['search_post'];
+
+#===============================================================================
# Item overview titles
#===============================================================================
$LANGUAGE['title_page_overview'] = "{$LANGUAGE['page_overview']} [%d]";
diff --git a/core/namespace/Page/Item.php b/core/namespace/Page/Item.php
index c6cece7..e3bf6a3 100644
--- a/core/namespace/Page/Item.php
+++ b/core/namespace/Page/Item.php
@@ -25,5 +25,19 @@ class Item extends \Item {
return sha1(implode(NULL, $attributes));
}
+
+ #===============================================================================
+ # Return unique page IDs for search results
+ #===============================================================================
+ public static function getSearchResultIDs($search, \Database $Database): array {
+ $Statement = $Database->prepare(sprintf("SELECT id FROM %s WHERE
+ MATCH(name, body) AGAINST(? IN BOOLEAN MODE) LIMIT 20", Attribute::TABLE));
+
+ if($Statement->execute([$search])) {
+ return $Statement->fetchAll($Database::FETCH_COLUMN);
+ }
+
+ return [];
+ }
}
?> \ No newline at end of file
diff --git a/template/admin/html/home.php b/template/admin/html/home.php
index f8a45c5..7698035 100644
--- a/template/admin/html/home.php
+++ b/template/admin/html/home.php
@@ -2,7 +2,12 @@
<p><?=$Language->text('overview_dashboard_desc')?></p>
<h2><i class="fa fa-newspaper-o"></i><?=$Language->text('last_post')?></h2>
-<p><strong><?=$Language->text('posts')?>:</strong> <?=$COUNT['POST']?> | <a href="<?=Application::getAdminURL('post/')?>"><?=$Language->text('post_overview')?></a> | <a href="<?=Application::getAdminURL('post/insert.php')?>"><?=$Language->text('insert')?></a></p>
+<p>
+ <strong><?=$Language->text('posts')?>:</strong> <?=$COUNT['POST']?>
+ | <a href="<?=Application::getAdminURL('post/')?>"><?=$Language->text('post_overview')?></a>
+ | <a href="<?=Application::getAdminURL('post/insert.php')?>"><?=$Language->text('insert')?></a>
+ | <a href="<?=Application::getAdminURL('post/search.php')?>"><?=$Language->text('search')?></a>
+</p>
<?php if(!empty($LAST['POST'])): ?>
<div class="item-container post">
<?=$LAST['POST']?>
@@ -12,7 +17,12 @@
<?php endif; ?>
<h2><i class="fa fa-file-text-o"></i><?=$Language->text('last_page')?></h2>
-<p><strong><?=$Language->text('pages')?>:</strong> <?=$COUNT['PAGE']?> | <a href="<?=Application::getAdminURL('page/')?>"><?=$Language->text('page_overview')?></a> | <a href="<?=Application::getAdminURL('page/insert.php')?>"><?=$Language->text('insert')?></a></p>
+<p>
+ <strong><?=$Language->text('pages')?>:</strong> <?=$COUNT['PAGE']?>
+ | <a href="<?=Application::getAdminURL('page/')?>"><?=$Language->text('page_overview')?></a>
+ | <a href="<?=Application::getAdminURL('page/insert.php')?>"><?=$Language->text('insert')?></a>
+ | <a href="<?=Application::getAdminURL('page/search.php')?>"><?=$Language->text('search')?></a>
+</p>
<?php if(!empty($LAST['PAGE'])): ?>
<div class="item-container page">
@@ -23,7 +33,11 @@
<?php endif; ?>
<h2><i class="fa fa-user"></i><?=$Language->text('last_user')?></h2>
-<p><strong><?=$Language->text('users')?>:</strong> <?=$COUNT['USER']?> | <a href="<?=Application::getAdminURL('user/')?>"><?=$Language->text('user_overview')?></a> | <a href="<?=Application::getAdminURL('user/insert.php')?>"><?=$Language->text('insert')?></a></p>
+<p>
+ <strong><?=$Language->text('users')?>:</strong> <?=$COUNT['USER']?>
+ | <a href="<?=Application::getAdminURL('user/')?>"><?=$Language->text('user_overview')?></a>
+ | <a href="<?=Application::getAdminURL('user/insert.php')?>"><?=$Language->text('insert')?></a>
+</p>
<?php if(!empty($LAST['USER'])): ?>
<div class="item-container user">
diff --git a/template/admin/html/page/index.php b/template/admin/html/page/index.php
index dbd5144..1027996 100644
--- a/template/admin/html/page/index.php
+++ b/template/admin/html/page/index.php
@@ -1,4 +1,7 @@
-<h1><i class="fa fa-file-text-o"></i><?=$Language->text('page_overview')?><a class="brackets" href="<?=Application::getAdminURL("page/insert.php")?>"><?=$Language->text('insert')?></a></h1>
+<h1>
+ <i class="fa fa-file-text-o"></i><?=$Language->text('page_overview')?>
+ <a class="brackets" href="<?=Application::getAdminURL("page/insert.php")?>"><?=$Language->text('insert')?></a>
+</h1>
<p><?=$Language->text('overview_page_desc')?></p>
<div class="item-container page">
diff --git a/template/admin/html/page/search.php b/template/admin/html/page/search.php
new file mode 100644
index 0000000..1a43bf7
--- /dev/null
+++ b/template/admin/html/page/search.php
@@ -0,0 +1,20 @@
+<h1>
+ <i class="fa fa-search"></i><?=$Language->text('title_page_search')?>
+ <a class="brackets" href="<?=Application::getAdminURL("page/insert.php")?>"><?=$Language->text('insert')?></a>
+</h1>
+<p><?=$Language->text('search_page_desc')?></p>
+
+<form id="search-form" method="GET">
+ <div class="flex flex-padding background">
+ <input id="search-text" type="search" name="q" placeholder="<?=$Language->text('placeholder_search')?>" value="<?=escapeHTML($QUERY)?>" />
+ </div>
+ <div class="flex flex-padding background">
+ <input id="update-button" type="submit" value="<?=$Language->text('search')?>" />
+ </div>
+</form>
+
+<div class="item-container post">
+ <?php foreach($PAGES as $page): ?>
+ <?php echo $page; ?>
+ <?php endforeach; ?>
+</div> \ No newline at end of file
diff --git a/template/admin/html/post/index.php b/template/admin/html/post/index.php
index a78076e..1ae8471 100644
--- a/template/admin/html/post/index.php
+++ b/template/admin/html/post/index.php
@@ -1,4 +1,7 @@
-<h1><i class="fa fa-newspaper-o"></i><?=$Language->text('post_overview')?><a class="brackets" href="<?=Application::getAdminURL("post/insert.php")?>"><?=$Language->text('insert')?></a></h1>
+<h1>
+ <i class="fa fa-newspaper-o"></i><?=$Language->text('post_overview')?>
+ <a class="brackets" href="<?=Application::getAdminURL("post/insert.php")?>"><?=$Language->text('insert')?></a>
+</h1>
<p><?=$Language->text('overview_post_desc')?></p>
<div class="item-container post">
diff --git a/template/admin/html/post/search.php b/template/admin/html/post/search.php
new file mode 100644
index 0000000..ab021b9
--- /dev/null
+++ b/template/admin/html/post/search.php
@@ -0,0 +1,20 @@
+<h1>
+ <i class="fa fa-search"></i><?=$Language->text('title_post_search')?>
+ <a class="brackets" href="<?=Application::getAdminURL("post/insert.php")?>"><?=$Language->text('insert')?></a>
+</h1>
+<p><?=$Language->text('search_post_desc')?></p>
+
+<form id="search-form" method="GET">
+ <div class="flex flex-padding background">
+ <input id="search-text" type="search" name="q" placeholder="<?=$Language->text('placeholder_search')?>" value="<?=escapeHTML($QUERY)?>" />
+ </div>
+ <div class="flex flex-padding background">
+ <input id="update-button" type="submit" value="<?=$Language->text('search')?>" />
+ </div>
+</form>
+
+<div class="item-container post">
+ <?php foreach($POSTS as $post): ?>
+ <?php echo $post; ?>
+ <?php endforeach; ?>
+</div> \ No newline at end of file
diff --git a/template/admin/html/user/index.php b/template/admin/html/user/index.php
index b1b4463..e1e24ef 100644
--- a/template/admin/html/user/index.php
+++ b/template/admin/html/user/index.php
@@ -1,4 +1,7 @@
-<h1><i class="fa fa-user"></i><?=$Language->text('user_overview')?><a class="brackets" href="<?=Application::getAdminURL("user/insert.php")?>"><?=$Language->text('insert')?></a></h1>
+<h1>
+ <i class="fa fa-user"></i><?=$Language->text('user_overview')?>
+ <a class="brackets" href="<?=Application::getAdminURL("user/insert.php")?>"><?=$Language->text('insert')?></a>
+</h1>
<p><?=$Language->text('overview_user_desc')?></p>
<div class="item-container user">
diff --git a/template/admin/lang/de.php b/template/admin/lang/de.php
index ec79d0a..7591a8f 100644
--- a/template/admin/lang/de.php
+++ b/template/admin/lang/de.php
@@ -42,6 +42,12 @@ $LANGUAGE['delete_post_desc'] = 'Falls du diesen Beitrag nicht mehr benötigst k
$LANGUAGE['delete_user_desc'] = 'Falls du diesen Benutzer nicht mehr benötigst kannst du ihn über den folgenden Button permanent löschen.';
#===============================================================================
+# Search item description
+#===============================================================================
+$LANGUAGE['search_page_desc'] = 'Hier kannst du mit der <em>booleschen Volltextsuche</em> eine Seite suchen (siehe <a href="https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html">MySQL-Dokumentation</a>).';
+$LANGUAGE['search_post_desc'] = 'Hier kannst du mit der <em>booleschen Volltextsuche</em> einen Beitrag suchen (siehe <a href="https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html">MySQL-Dokumentation</a>).';
+
+#===============================================================================
# Item overview description
#===============================================================================
$LANGUAGE['overview_page_desc'] = 'Hier siehst du alle vorhandenen Seiten.';
@@ -107,6 +113,11 @@ $LANGUAGE['login'] = 'Einloggen';
$LANGUAGE['logout'] = 'Ausloggen';
#===============================================================================
+# Placeholders
+#===============================================================================
+$LANGUAGE['placeholder_search'] = 'Suchbegriff eingeben …';
+
+#===============================================================================
# Labels
#===============================================================================
$LANGUAGE['label_slug'] = 'Slug';
diff --git a/template/admin/lang/en.php b/template/admin/lang/en.php
index d5c189a..63a18f5 100644
--- a/template/admin/lang/en.php
+++ b/template/admin/lang/en.php
@@ -42,6 +42,12 @@ $LANGUAGE['delete_post_desc'] = 'If you do not need this post anymore, you can p
$LANGUAGE['delete_user_desc'] = 'If you do not need this user anymore, you can permanently delete it by clicking the following button.';
#===============================================================================
+# Search item description
+#===============================================================================
+$LANGUAGE['search_page_desc'] = 'Here you can search a page with the <em>boolean full-text search</em> (see <a href="https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html">MySQL documentation</a>).';
+$LANGUAGE['search_post_desc'] = 'Here you can search a post with the <em>boolean full-text search</em> (see <a href="https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html">MySQL documentation</a>).';
+
+#===============================================================================
# Item overview description
#===============================================================================
$LANGUAGE['overview_page_desc'] = 'Here you can see all existing pages.';
@@ -107,6 +113,11 @@ $LANGUAGE['login'] = 'Login';
$LANGUAGE['logout'] = 'Logout';
#===============================================================================
+# Placeholders
+#===============================================================================
+$LANGUAGE['placeholder_search'] = 'Enter search term …';
+
+#===============================================================================
# Labels
#===============================================================================
$LANGUAGE['label_slug'] = 'Slug';
diff --git a/template/admin/rsrc/main.css b/template/admin/rsrc/main.css
index fb6a882..0086fbc 100644
--- a/template/admin/rsrc/main.css
+++ b/template/admin/rsrc/main.css
@@ -217,6 +217,11 @@ label:after{content:":";}
#message-list{margin:0;padding:0.5rem;list-style:none;background:#C45C66;color:#EEE;font-size:0.6rem;}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
+/* Search form
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
+#search-form{margin-bottom:1rem;}
+
+/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* FontAwesome Main
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
.fa{font:normal normal normal 14px/1 FontAwesome;font-size:inherit;speak:none;display:inline-block;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}