From 52503dfebf31ef731719a7abcc062628107bf0ba Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Tue, 12 Aug 2014 10:42:27 +0400 Subject: [PATCH 1/9] search route --- II/DB.pm | 2 ++ iiplc.app | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/II/DB.pm b/II/DB.pm index 7b2ad43..01a6dce 100644 --- a/II/DB.pm +++ b/II/DB.pm @@ -20,6 +20,7 @@ sub new { return $self; } +# Check message hash sub check_hash { my ( $self, $hash, $echo ) = @_; my $dbh = $self->{_dbh}; @@ -39,6 +40,7 @@ sub check_hash { } } +# Begin transaction sub begin { my ($self) = @_; my $dbh = $self->{_dbh}; diff --git a/iiplc.app b/iiplc.app index 0c146b3..2b1a8ea 100644 --- a/iiplc.app +++ b/iiplc.app @@ -19,6 +19,7 @@ use warnings; use Plack::Builder; use Plack::Request; use Plack::Response; + # Static files use Plack::App::File; @@ -65,7 +66,7 @@ my $thread = sub { my $get = sub { $config = $c->reload(); - my $GET = II::Get->new($config); + my $GET = II::Get->new($config); my $msgs = $GET->get_echo(); my $new_mes = $render->new_mes($msgs); return [ 200, [ 'Content-type' => 'text/html' ], ["$new_mes"], ]; @@ -176,19 +177,34 @@ my $user = sub { return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ]; }; +# Search +######## +my $search = sub { + my $env = shift; + + my $req = Plack::Request->new($env); + my $query = $req->param('q'); + + my $db = II::DB->new(); + my $result = $db->do_search($q); + + return [ 200, [ 'Content-type' => 'text/html' ], [$result], ]; +}; + # Mountpoints builder { - mount "/static" => Plack::App::File->new(root => './s/')->to_app; - mount '/' => $root; - mount '/e' => $echo; - mount '/s' => $thread; - mount '/u' => $user; - mount '/me' => $me; - mount '/tree' => $tree; - mount '/get/' => $get; - mount '/send' => $send; - mount '/enc' => $enc; - mount '/out' => $out; - mount '/push' => $push; - mount '/new' => $new; + mount "/static" => Plack::App::File->new( root => './s/' )->to_app; + mount "/search" => $search; + mount '/' => $root; + mount '/e' => $echo; + mount '/s' => $thread; + mount '/u' => $user; + mount '/me' => $me; + mount '/tree' => $tree; + mount '/get' => $get; + mount '/send' => $send; + mount '/enc' => $enc; + mount '/out' => $out; + mount '/push' => $push; + mount '/new' => $new; }; From fa55cd636bd5674c406a1db12c3e5fbb196e9db8 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Tue, 12 Aug 2014 10:46:30 +0400 Subject: [PATCH 2/9] Notify config --- II/Config.pm | 8 +++++--- II/Get.pm | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/II/Config.pm b/II/Config.pm index c6c89cd..7a5ed39 100644 --- a/II/Config.pm +++ b/II/Config.pm @@ -15,15 +15,16 @@ sub new { sub load { my ($self) = @_; my $file = $self->{_file}; - + my $tiny = Config::Tiny->new(); $config = $tiny->read($file); - + my $key = $config->{auth}->{key}; my $nick = $config->{auth}->{nick}; my $host = $config->{node}->{host}; my @echoareas = split /,/, $config->{node}->{echoareas}; my $name = $config->{node}->{name}; + my $notify = $config->{notify}->{enabled}; $c = { nick => $nick, @@ -31,6 +32,7 @@ sub load { host => $host, echoareas => [@echoareas], name => $name, + notify => $notify, }; return $c; @@ -40,7 +42,7 @@ sub load { sub reload { my ($self) = @_; - my $c = II::Config->new(); + my $c = II::Config->new(); my $config = $c->load(); return $config; diff --git a/II/Get.pm b/II/Get.pm index 539e749..fd1bfe9 100644 --- a/II/Get.pm +++ b/II/Get.pm @@ -148,7 +148,9 @@ sub get_echo { # Notify my @notify_cmd = ('notify-send', 'Сеть ii', 'Есть новые сообщения'); - system(@notify_cmd) == 0 or warn "Cannot send notify: $!\n"; + if ($notify == 1) { + system(@notify_cmd) == 0 or warn "Cannot send notify: $!\n"; + } } return $msgs; } From 1235bfe0de652bbb9e473356205c33277638ddfe Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Tue, 12 Aug 2014 11:25:20 +0400 Subject: [PATCH 3/9] 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 @@ [ неотправленные сообщения ] 

+ From e7c0716a6749741164bc345dc59f8636022695a4 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Tue, 12 Aug 2014 11:46:13 +0400 Subject: [PATCH 4/9] Search is working. But it is case sensitive --- II/DB.pm | 12 +++++------- iiplc.app | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/II/DB.pm b/II/DB.pm index 74ecb45..6da6ed0 100644 --- a/II/DB.pm +++ b/II/DB.pm @@ -2,7 +2,6 @@ package II::DB; use SQL::Abstract; use DBI; -use Encode; use utf8; use Data::Dumper; @@ -340,13 +339,12 @@ 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 $q = "select from_user, to_user, subg, time, echo, post, hash + from messages where subg + like '\%$query\%' COLLATE NOCASE + order by time"; + print "SQL: " . $q . "\n"; my $sth = $dbh->prepare($q); $sth->execute(); diff --git a/iiplc.app b/iiplc.app index 2b1a8ea..6b93116 100644 --- a/iiplc.app +++ b/iiplc.app @@ -186,7 +186,9 @@ my $search = sub { my $query = $req->param('q'); my $db = II::DB->new(); - my $result = $db->do_search($q); + my @post = $db->do_search($query); + + my $result = $render->search(@post); return [ 200, [ 'Content-type' => 'text/html' ], [$result], ]; }; From 1bc343fe5a941093d6ee7a0bd337d57c7dfbb5fa Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Wed, 13 Aug 2014 13:12:49 +0400 Subject: [PATCH 5/9] @users link --- II/T.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/II/T.pm b/II/T.pm index 328ea1d..99a2a99 100644 --- a/II/T.pm +++ b/II/T.pm @@ -193,6 +193,9 @@ sub pre { $post =~ s/ii:\/\/(\w+(\.)?\w+\.\d{2,4})/$1<\/a>/g; $post =~ s/ii:\/\/(\w{20})/$1<\/a>/g; + # Users + $post =~ s/@(\w+)(\s|,)/$1<\/a>$2/g; + # Not are regexp parsing my $pre = 0; my $txt; From 013caee157a0e5749269339f1f7bcb9b1e7c1d2f Mon Sep 17 00:00:00 2001 From: "Denis(dzhel) Zheleztsov" Date: Wed, 8 Oct 2014 14:43:41 +0400 Subject: [PATCH 6/9] @user parsing fix --- II/T.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/II/T.pm b/II/T.pm index 99a2a99..deb535d 100644 --- a/II/T.pm +++ b/II/T.pm @@ -194,7 +194,7 @@ sub pre { $post =~ s/ii:\/\/(\w{20})/$1<\/a>/g; # Users - $post =~ s/@(\w+)(\s|,)/$1<\/a>$2/g; + $post =~ s/.+? \@(\w+)(.?.+)/$1<\/a>$2/g; # Not are regexp parsing my $pre = 0; From 3c932e6294c79fad1effeb667b20b1ad7a0d3154 Mon Sep 17 00:00:00 2001 From: "Denis(Difrex) Zheleztsov" Date: Thu, 6 Nov 2014 11:24:03 +0300 Subject: [PATCH 7/9] Initial multihosts support --- iiplc.app | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/iiplc.app b/iiplc.app index 6b93116..aab6029 100644 --- a/iiplc.app +++ b/iiplc.app @@ -64,10 +64,22 @@ my $thread = sub { return [ 200, [ 'Content-type' => 'text/html' ], ["$thread"], ]; }; +# Get new messages my $get = sub { $config = $c->reload(); - my $GET = II::Get->new($config); - my $msgs = $GET->get_echo(); + my $msgs; + if ( $config->{host} =~ m/.+\,.+/ ) { + my @hosts = split( /,/, $config->{host} ); + foreach my $host (@hosts) { + $config->{host} = $host; + my $GET = II::Get->new($config); + $msgs .= $GET->get_echo(); + } + } + else { + my $GET = II::Get->new($config); + $msgs .= $GET->get_echo(); + } my $new_mes = $render->new_mes($msgs); return [ 200, [ 'Content-type' => 'text/html' ], ["$new_mes"], ]; }; From f090414dc8f5350aeeb2c853a7b4caddfa722cd2 Mon Sep 17 00:00:00 2001 From: "Denis(Difrex) Zheleztsov" Date: Thu, 6 Nov 2014 12:45:38 +0300 Subject: [PATCH 8/9] Send fix --- iiplc.app | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iiplc.app b/iiplc.app index aab6029..94aa20c 100644 --- a/iiplc.app +++ b/iiplc.app @@ -169,6 +169,10 @@ my $push = sub { my $hash = $req->param('hash'); $config = $c->reload(); + if ( $config->{host} =~ m/.+\,.+/ ) { + my @hosts = split( /,/, $config->{host} ); + $config->{host} = $hosts[0]; + } my $s = II::Send->new( $config, $echo, $base64 ); $s->send($hash); From 1a0448afc12dfbb11a2f90a31876c0e304768725 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Thu, 6 Nov 2014 18:22:30 +0300 Subject: [PATCH 9/9] crontab file removed --- crontab | 2 -- 1 file changed, 2 deletions(-) delete mode 100755 crontab diff --git a/crontab b/crontab deleted file mode 100755 index e9262d4..0000000 --- a/crontab +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo "1 * * * * `whoami` wget -O /dev/null http://127.0.0.1/get" >> /etc/crontab