Permalink
Browse files

Started working on the new frontpage structure

  • Loading branch information...
1 parent 906296f commit 2e94ed34cefd3a7749aa342c79fcb98c64fc2292 @cosimo committed Oct 24, 2010
View
@@ -11,6 +11,9 @@ root_dir = /home/cosimo/src/curvedicrescita/htdocs
# Where are templates stored
tmpl_path = /home/cosimo/src/curvedicrescita/templates
+# Enable templates caching
+tmpl_cache = 0
+
# Root path of CGIs
cgi_root = /exec
cgi_home = /exec/home
@@ -3,14 +3,17 @@
# $Id$
# Site root URL
-root_uri = http://localhost:8080/
+root_uri = http://localhost/
# Root directories of server
root_dir = /home/cosimo/src/curvedicrescita/htdocs
# Where are templates stored
tmpl_path = /home/cosimo/src/curvedicrescita/templates
+# Enable templates caching
+tmpl_cache = 0
+
# Root path of CGIs
cgi_root = /exec
cgi_home = /exec/home
View
@@ -11,6 +11,9 @@ root_dir = /var/www2/www.curvedicrescita.com/htdocs
# Where are templates stored
tmpl_path = /var/www2/www.curvedicrescita.com/templates
+# Enable templates caching
+tmpl_cache = 1
+
# Root path of CGIs
cgi_root = /exec
cgi_home = /exec/home
View
@@ -262,8 +262,12 @@ div#content {
display:block;
}
-#questions h1 {
- border-bottom: 1px solid;
+#article2col h1, #questions h1 {
+ border-bottom: 1px solid #888;
+}
+
+#article2col h2 {
+ padding-top: 20px;
}
#questions h3 {
@@ -590,3 +594,7 @@ div#notice_box_info h3, div#notice_box_info p {
color: #888;
}
+#cover_pic {
+ padding: 0px 10px 10px 10px;
+}
+
@@ -1,6 +1,6 @@
package BabyDiary::Application;
-$VERSION = '0.04';
+$VERSION = '0.05';
use strict;
use warnings;
@@ -92,7 +92,7 @@ sub setup
admin => \&BabyDiary::Application::Admin::front_page,
- homepage => \&BabyDiary::Application::default,
+ homepage => \&BabyDiary::Application::homepage,
articles => \&BabyDiary::Application::default,
article => \&BabyDiary::Application::Articles::view,
@@ -157,12 +157,7 @@ sub cgiapp_init
sub default
{
my $self = $_[0];
-
- # Load state params (n. of registered users, ...) to appear in application title.
- # Instance HTML::Template object and fills its parameters.
- my $tmpl = $self->fill_params();
-
- # Generate and return output from template
+ my $tmpl = $self->render_view();
return $tmpl->output();
}
@@ -221,6 +216,89 @@ sub fill_messages
return;
}
+#
+# Display a list of the latest articles with links
+#
+sub homepage
+{
+ my ($self) = @_;
+
+ my $tmpl = $self->fill_params();
+
+ $tmpl->param(
+ page_title => $self->msg(q(Ultimi articoli pubblicati)),
+ page_description => $self->msg(q(Questi sono gli ultimi articoli pubblicati su CurveDiCrescita)),
+ menu_articles => 1
+ );
+
+ my $art = BabyDiary::File::Articles->new();
+
+ # Make sure that only admins can see unpublished articles
+ my $is_admin = $self->session->param('admin');
+ my $admin_filter = $is_admin
+ ? {}
+ : { published => {'<>', 0} }
+ ;
+
+ my $art_list = $art->frontpage($admin_filter);
+
+ if (! $art_list || ref $art_list ne 'ARRAY') {
+ return $tmpl->output;
+ }
+
+ my $show_ads = $tmpl->param('show_ads');
+
+ # Process article data to be displayed
+ for my $art (@{ $art_list }) {
+ $art->{keywords} = BabyDiary::View::Articles::format_keywords($art);
+ $art->{author} = BabyDiary::View::Articles::format_author($art);
+ $art->{link} = BabyDiary::View::Articles::format_title_link($art);
+ # Prepare stripped down content for article summary
+ $art->{excerpt} = BabyDiary::View::Articles::format_article_excerpt($art);
+ $art->{avatar} = BabyDiary::View::Articles::format_author_avatar($art);
+ $art->{createdon} = Opera::Util::format_date($art->{createdon});
+ $art->{lastupdateon} = Opera::Util::format_date($art->{lastupdateon});
+
+ my $coverpic = BabyDiary::View::Articles::get_first_image($art->{content});
+ if ($coverpic) {
+ handle_coverpic_attributes($art, $coverpic);
+ }
+
+ # Global vars aren't replicated in TMPL_LOOPs
+ $art->{show_ads} = $show_ads;
+ }
+
+ $tmpl->param(articles => $art_list);
+
+ return $tmpl->output();
+}
+
+sub handle_coverpic_attributes {
+ my ($art, $coverpic) = @_;
+
+ $art->{coverpic} = $coverpic->{src};
+
+ my $max_size = 150;
+ my $width = $coverpic->{width};
+ my $height = $coverpic->{height};
+
+ $art->{coverpic_w} = $max_size;
+ $art->{coverpic_h} = $max_size;
+
+ if ($width && $height) {
+ my $aspect_ratio = $width / $height;
+ my $portrait_pic = ($aspect_ratio < 1.0);
+ if ($portrait_pic) {
+ $art->{coverpic_w} = $max_size * $aspect_ratio;
+ }
+ else {
+ $art->{coverpic_h} = $max_size / $aspect_ratio;
+ }
+ }
+
+ return;
+}
+
sub go_back_or_forward {
my ($self, $runmode) = @_;
@@ -252,7 +330,11 @@ sub render_view
# Load template object
my $tmpl;
eval {
- $tmpl = $self->load_tmpl($tmpl_file, die_on_bad_params => 0);
+ $tmpl = $self->load_tmpl($tmpl_file,
+ die_on_bad_params => 0,
+ loop_context_vars => 1,
+ cache => $self->config('tmpl_cache'),
+ );
};
if ($@) {
$self->log('error', 'Template [' . $tmpl_file . '] loading failed: ' . $@);
@@ -345,10 +345,13 @@ sub latest
my $tmpl = $self->fill_params();
my $title = $self->msg(q(Domande piu' recenti));
- $tmpl->param(page_title => $title);
- # Highlight menu section
- $tmpl->param(questions_latest => 1);
+ $tmpl->param(
+ page_title => $title,
+ page_description => $self->msg(q(Queste sono le ultime domande poste in ordine di tempo.)),
+ # Highlight menu section
+ questions_latest => 1,
+ );
# If some questions found, display them in a TMPL_LOOP
if ($list) {
@@ -111,6 +111,20 @@ sub post
return $id;
}
+sub frontpage {
+ my ($self, $where) = @_;
+
+ my $n = 10;
+ my $art_list = $self->list({
+ fields => ['id', 'title', 'keywords', 'content', 'createdby', 'createdon', 'views', 'published', 'lastupdateby', 'lastupdateon'],
+ where => $where,
+ limit => $n,
+ order => [ 'id DESC' ],
+ });
+
+ return $art_list;
+}
+
sub type {
return 'article'
}
@@ -7,6 +7,7 @@ use strict;
use CGI ();
use Digest::MD5 ();
use HTML::BBCode;
+use HTML::LinkExtor;
use HTML::Strip;
use BabyDiary::File::Articles;
use BabyDiary::File::Users;
@@ -57,7 +58,7 @@ sub format_article_excerpt
for (@lines) {
push @excerpt, $_;
$chars += length;
- last if $chars > 80;
+ last if $chars > 160;
}
# Add dots `...' to denote continued content
@@ -208,6 +209,55 @@ sub format_title
}
+#sub get_first_image {
+# my ($article_content) = @_;
+# my $lx = HTML::LinkExtor->new();
+# $lx->parse($article_content);
+# my @links = $lx->links();
+# my $pic;
+# for (@links) {
+# my ($tag, %attr) = @{ $_ };
+# if ($tag eq 'img' || $tag eq 'IMG') {
+# $pic = \%attr;
+# last;
+# }
+# }
+# return $pic;
+#}
+
+sub get_first_image {
+ my ($article_content) = @_;
+ if ($article_content !~ m{^<[iI][mM][gG] ([^>]+) >}x) {
+ return;
+ }
+
+ my $img_attr = $1;
+ my $width;
+ my $height;
+ my $src;
+
+ if ($img_attr !~ m{ src = " ([^"]+) " }xi) {
+ return;
+ }
+
+ $src = $1;
+
+ if ($img_attr =~ m{ width = "? (\d+) \D }xi) {
+ $width = $1;
+ }
+
+ if ($img_attr =~ m{ height = "? (\d+) \D }xi) {
+ $height = $1;
+ }
+
+ return {
+ src => $src,
+ width => $width,
+ height => $height,
+ };
+
+}
+
1;
#
@@ -241,3 +291,4 @@ author or title, to final user.
Cosimo Streppone L<cosimo@streppone.it>
=cut
+
@@ -4,10 +4,10 @@
</div>
<div id="menu">
<ul id="nav">
- <li id="domande"<tmpl_if menu_questions> class="activelink"</tmpl_if>><a href="<tmpl_var cgi_root>/question/latest/"><tmpl_var name="msg:domande"></a></li>
<li id="articoli"<tmpl_if menu_articles> class="activelink"</tmpl_if>><a href="<tmpl_var cgi_root>/home/"><tmpl_var name="msg:articoli"></a></li>
- <li id="curve"<tmpl_if menu_diary> class="activelink"</tmpl_if>><a href="<tmpl_var cgi_root>/user/charts/"><tmpl_var name="msg:curve"></a></li>
+ <li id="domande"<tmpl_if menu_questions> class="activelink"</tmpl_if>><a href="<tmpl_var cgi_root>/question/latest/"><tmpl_var name="msg:domande"></a></li>
<li id="tags"<tmpl_if menu_tags> class="activelink"</tmpl_if>><a href="<tmpl_var mycgi_path>/tags"><tmpl_var name="msg:tags"></a></li>
+ <li id="curve"<tmpl_if menu_diary> class="activelink"</tmpl_if>><a href="<tmpl_var cgi_root>/user/charts/"><tmpl_var name="msg:curve"></a></li>
<!--
<li id="ostetrica"<tmpl_if menu_ostetrica> class="activelink"</tmpl_if>><a href="<tmpl_var mycgi_path>/article_search?keyword=ostetrica"><tmpl_var name="msg:ostetrica"></a></li>
<li id="pediatra"<tmpl_if menu_pediatra> class="activelink"</tmpl_if>><a href="<tmpl_var mycgi_path>/article_search?keyword=pediatra"><tmpl_var name="msg:pediatra"></a></li>
@@ -32,10 +32,8 @@
</div>
</tmpl_if>
-<tmpl_if questions_latest>
+<tmpl_if page_description>
<div id="tab">
-<span>
-Queste sono le ultime domande poste in ordine di tempo.
-</span>
+<span><tmpl_var page_description></span>
</div>
</tmpl_if>
@@ -1,4 +1,3 @@
-<!-- Google Adsense -->
<div align="center" style="margin:20px 0 20px 0;">
<script type="text/javascript"><!--
google_ad_client = "pub-1461056359423577";
@@ -41,7 +41,7 @@
</tmpl_if>
</tmpl_unless>
-<tmpl_include name="shared/latest.html">
+<tmpl_include name="shared/most_popular.html">
<tmpl_include name="shared/cumulus_cloud.html">
View
@@ -1 +1,16 @@
-<tmpl_include name="master.html">
+<tmpl_include name="document/open.html">
+<tmpl_include name="document/header.html">
+
+<body>
+<tmpl_include name="components/signin.html">
+<tmpl_include name="components/header.html">
+
+<div id="content">
+ <!-- xmpl_include name="components/topics.html" -->
+ <tmpl_include name="latest_articles.html">
+ <tmpl_include name="components/sidebar.html">
+</div>
+
+<tmpl_include name="document/footer.html">
+<tmpl_include name="document/close.html">
+

0 comments on commit 2e94ed3

Please sign in to comment.