Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Blogs sidebar

  • Loading branch information...
commit 0f7e5ae26f8a00509eb5df5e21416f01e23df85a 1 parent 5b5ae5a
Zbigniew Lukasiak authored
View
88 lib/Nblog/Controller/Blog.pm
@@ -43,23 +43,83 @@ sub index_action {
return $self->render( site_name => $self->blog->title, articles => $articles );
}
-sub login_action {
- my $self = shift;
- my $env = $self->env;
- return $self->render(
- template => 'login.tt',
- redir_to => $env->{'psgix.session'}{redir_to},
- );
+sub myroot { $_[0]->self_url }
+
+sub calendar {
+ my ( $self ) = @_;
+
+ my $dt = DateTime->now();
+ my $cal = new Nblog::Calendar(
+ 'year' => $dt->year,
+ 'month' => $dt->month
+ );
+ $cal->border(0);
+ $cal->width(50);
+ $cal->headerclass('month_date');
+ $cal->showweekdayheaders(0);
+
+ my @articles = $self->app->schema->resultset('Article')->search( { blog_id => $self->blog->blog_id } )->from_month( $dt->month );
+
+ foreach my $article (@articles)
+ {
+ my $location =
+ $self->self_url
+ . 'archived/'
+ . $article->created_at->year() . '/'
+ . $article->created_at->month() . '/'
+ . $article->created_at->mday();
+ $cal->setdatehref( $article->created_at->mday(), $location );
+ }
+
+ return $cal->as_HTML;
}
+sub archives
+{
+ my ( $self ) = @_;
+
+ my @articles = $self->app->schema->resultset('Article')->search( { blog_id => $self->blog->blog_id } )->all();
+
+ unless (@articles)
+ {
+ return "<p>No Articles in Archive!</p>";
+ }
+
+ my $months;
+ foreach my $article (@articles)
+ {
+ my $month = $article->created_at()->month_name();
+ my $year = $article->created_at()->year();
+ my $key = "$year $month";
+ if ( ( defined $months->{$key}->{count} ) && ( $months->{$key}->{count} > 0 ) )
+ {
+ $months->{$key}->{count} += 1;
+ }
+ else
+ {
+ $months->{$key}->{count} = 1;
+ $months->{$key}->{year} = $year;
+ $months->{$key}->{month} = $article->created_at()->month();
+ }
+ }
+
+ my @out;
+ while ( my ( $key, $value ) = each( %{$months} ) )
+ {
+ push @out,
+ "<li><a href='" . $self->self_url . "archived/$value->{year}/$value->{month}'>$key</a> <span class='special_text'>($value->{count})</span></li>";
+ }
+ return join( ' ', @out );
+}
sub archived_action {
my ( $self, $year, $month, $day ) = @_;
- my $articles = $self->app->schema->resultset('Article')->archived( year => $year, month => $month, day => $day );
+ my $articles = $self->app->schema->resultset('Article')->search( { blog_id => $self->blog->blog_id } )->archived( year => $year, month => $month, day => $day );
return $self->render(
- template => 'blog_index.tt',
+ template => 'index.tt',
articles => $articles,
+ site_name => $self->blog->title,
);
}
@@ -72,7 +132,7 @@ sub search_action {
$phrase = $self->req->param( 'phrase' );
}
- my $articles = $self->app->schema->resultset('Article')->search(
+ my $articles = $self->app->schema->resultset('Article')->search( { blog_id => $self->blog->blog_id } )->search(
[
subject => { like => "%$phrase%" },
body => { like => "%$phrase%" },
@@ -80,8 +140,9 @@ sub search_action {
);
return $self->render(
- template => 'blog_index.tt',
+ template => 'index.tt',
articles => $articles,
+ site_name => $self->blog->title,
)
}
@@ -93,9 +154,10 @@ sub tag_action {
->search( { name => { like => $self->app->ravlog_url_to_query($tag) } } )->first();
warn $db_tag->id;
return $self->render(
- template => 'blog_index.tt',
- articles => scalar $db_tag->articles,
+ template => 'index.tt',
+ articles => scalar $db_tag->articles->search( { blog_id => $self->blog->blog_id } ),
rss => $db_tag->name,
+ site_name => $self->blog->title,
);
}
View
7 lib/Nblog/Schema.pm
@@ -13,11 +13,14 @@ sub new_from_config {
if( $config->{deploy_on_start} ){
$schema->deploy();
my $user = $schema->resultset( 'User' )->create( { username => 'test', password => 'pass_for_test', email => 'root@localhost', is_admin => 1, about_me => 'This is the test user with admin privileges' } );
- $schema->resultset( 'User' )->create( { username => 'test2', password => 'pass_for_test', email => 'root@localhost', about_me => 'This is the test user without admin privileges' } );
+ my $user2 = $schema->resultset( 'User' )->create( { username => 'test2', password => 'pass_for_test', email => 'root@localhost', about_me => 'This is the test user without admin privileges' } );
my $blog = $user->create_blog( title => 'Test blog' );
$blog->add_to_articles( { subject => 'test test', body => 'test', } );
- $schema->resultset( 'Tag' )->create( { name => 'test' } );
+ my $blog2 = $user2->create_blog( title => 'Test blog 2' );
+ my $article = $blog2->add_to_articles( { subject => 'test2 test2', body => 'test2', } );
+ my $tag = $schema->resultset( 'Tag' )->create( { name => 'test' } );
+ $article->add_to_tags( $tag );
}
return $schema;
}
View
67 share/templates/Blog/blog_index.tt
@@ -1,67 +0,0 @@
-<br />
-[% IF articles.count == 0 %]
-<p>No matching articles found</p>
-[% END %]
-[% WHILE ( article = articles.next ) %]
- <div class="post">
- [% url = '/Article/' _ c.app.ravlog_txt_to_url(article.subject, article.id) %]
- <div class="post-info">
- <h2 class="post-title">
- <a title="[% url %]" href="[% url %]">[% article.subject %]</a>
- </h2>
- <a href="[% c.base_uri %]/Feed/comments/[% c.app.ravlog_txt_to_url(article.subject) %]"><img src="/static/images/rss.png" alt="RSS" /></a> &nbsp;
- <br/>
- [% article.blog %]
- <span>Posted by [% article.blog.user.username %]&nbsp;&nbsp;&nbsp;</span>
- <p class="post-date">
- [% c.app.render_ravlog_date(article.created_at) %]
- </p>
- </div>
-
- <div class="post-content">
- [% article.formatted_body %]
- </div>
- <div class="post-footer">&nbsp;
- [% IF article.tags %]
- <span>Tags:</span>
- [% FOREACH tag = article.tags %]
- <a href="/tag/[% c.app.ravlog_txt_to_url(tag.name) %]">[% tag.name %]</a>
- [% END %]
- [% END %]
- &nbsp;&nbsp;<a href="[% url %]">[[% article.comments_rs.count %]] comments</a>
- </div>
- </div>
- <br />
- <br />
-[% END %]
-<div id="comments"></div>
-
-<ol class="commentlist">
-[% FOREACH comment = comments %]
- <li class="alt">
- [% IF loop.index % 2 %]
- <div class="comment">
- [% ELSE %]
- <div class="comment_alt">
- [% END %]
- [% IF comment.user %]
- [% SET url = comment.user.website; SET name = comment.user.username; %]
- [% ELSE %]
- [% SET url = comment.url; SET name = comment.name; %]
- [% END %]
- <h3><a title="[% url %]" href="[% url %]">[% name %]</a></h3>
- <small class="commentmetadata">Posted [% c.render_ravlog_date(comment.created_at) %]</small>
- <p>[% comment.formatted_body %]</p>
- </div>
- </li>
-[% END %]
-</ol>
-
-[% IF comment_form %]
-<h3 id="respond">Comment</h3>
-[% comment_form.render %]
-[% IF never %]
-<p>Type the following in the verification box</p>
-<img src="/submit/captcha" alt="" />
-[% END %]
-[% END %]
View
2  share/templates/globals/elements/archives_list.tt
@@ -1,4 +1,4 @@
<h2>Archives</h2>
<ul>
-[% c.app.archives %]
+[% c.archives || c.app.archives %]
</ul>
View
2  share/templates/globals/elements/tags_list.tt
@@ -3,7 +3,7 @@
<div id="tag_list">
<ul>
[% FOREACH tag = c.app.tags %]
- <li><a title="[% tag.name %]" href="/tag/[% c.app.ravlog_txt_to_url(tag.name) %]">[% tag.name %]</a></li>
+ <li><a title="[% tag.name %]" href="[% c.myroot || '/' %]tag/[% c.app.ravlog_txt_to_url(tag.name) %]">[% tag.name %]</a></li>
[% END %]
<script type="text/javascript" charset="utf-8">
toggle_tag_list();
View
2  share/templates/globals/sidebar.tt
@@ -14,7 +14,7 @@
[% PROCESS 'elements/login_list.tt' %]
<h3>Calendar</h3>
<div id="calendar">
- [% c.app.calendar %]
+ [% c.calendar OR c.app.calendar %]
</div>
<h3>Tags</h3>
[% PROCESS 'elements/tags_list.tt' %]
Please sign in to comment.
Something went wrong with that request. Please try again.