From 1235bfe0de652bbb9e473356205c33277638ddfe Mon Sep 17 00:00:00 2001
From: "Difrex(Denis Zheleztsov)"
Date: Tue, 12 Aug 2014 11:25:20 +0400
Subject: [PATCH] Initial search support. Only ASCII characters
---
II/DB.pm | 36 ++++++++++++++++++++++++++++++++++++
II/Render.pm | 22 ++++++++++++++++++++++
s/css/default.css | 14 ++++++++++++++
t/head.html | 6 ++++++
4 files changed, 78 insertions(+)
diff --git a/II/DB.pm b/II/DB.pm
index 01a6dce..74ecb45 100644
--- a/II/DB.pm
+++ b/II/DB.pm
@@ -2,6 +2,8 @@ package II::DB;
use SQL::Abstract;
use DBI;
+use Encode;
+use utf8;
use Data::Dumper;
@@ -49,6 +51,7 @@ sub begin {
$dbh->do('BEGIN');
}
+# Commit transaction
sub commit {
my ($self) = @_;
my $dbh = $self->{_dbh};
@@ -332,4 +335,37 @@ sub select_new {
return $data;
}
+# Search
+sub do_search {
+ my ( $self, $query ) = @_;
+ my $dbh = $self->{_dbh};
+
+ # $query = $query;
+
+ print "QUERY " . $query . "\n";
+
+ my $q
+ = "select from_user, to_user, subg, time, echo, post, hash from messages where subg like '\%$query\%' order by time";
+
+ my $sth = $dbh->prepare($q);
+ $sth->execute();
+
+ my @posts;
+ while ( my @hash = $sth->fetchrow_array() ) {
+ my ( $from, $to, $subg, $time, $echo, $post, $h ) = @hash;
+ my $data = {
+ from => "$from",
+ to => "$to",
+ subg => "$subg",
+ time => $time,
+ echo => "$echo",
+ post => "$post",
+ hash => "$h",
+ };
+ push( @posts, $data );
+ }
+
+ return @posts;
+}
+
1;
diff --git a/II/Render.pm b/II/Render.pm
index b2615e1..e31e7d5 100644
--- a/II/Render.pm
+++ b/II/Render.pm
@@ -263,4 +263,26 @@ sub new_mes {
return $render;
}
+# Search results
+sub search {
+ my ( $self, @post ) = @_;
+ my $t = $self->{_template};
+
+ # Render header
+ my $render
+ = $t->head(
+ "ii " . $config->{name} . " :: Результаты поиска" );
+
+ my $count = 0;
+ while ( $count < @post ) {
+
+ # Render post
+ $render .= $t->post( @post[$count] );
+ $count++;
+ }
+ $render .= $t->foot();
+
+ return $render;
+}
+
1;
diff --git a/s/css/default.css b/s/css/default.css
index fe5897c..e8cf7c9 100644
--- a/s/css/default.css
+++ b/s/css/default.css
@@ -174,4 +174,18 @@ margin-bottom: 0%;
padding: 0.2em;
margin-left: 45%;
margin-right: 55%;
+}
+/* Search */
+.search {
+ position: fixed;
+ top: 2em;
+ left: 0.5em;
+ opacity: 0.4;
+ transition-duration: 0.5s;
+ -webkit-transition-duration: 0.5s;
+}
+.search:hover {
+ opacity: 1;
+ transition-duration: 0.5s;
+ -webkit-transition-duration: 0.5s;
}
\ No newline at end of file
diff --git a/t/head.html b/t/head.html
index 3271403..3284d7f 100644
--- a/t/head.html
+++ b/t/head.html
@@ -15,4 +15,10 @@
[ неотправленные сообщения ] 
+
+
+