Feb 09, 2013; 13:53
Jussi Hirvi
Anybody willing to review this code?
I am still slowly developing LassoBlogger. For more info, see
https://github.com/jussihirvi/LassoBlogger
Right now I am refining the archive links. They are now supposed so show
this kind of list on the sidebar:
February 2013 (2)
January 2013 (5)
December 2012 (1)
October 2012 (4)
(...etc.)
February 2012 (3)
January 2012 (1)
2011 (17)
2010 (30)
2009 (31)
The number in parentheses is the blog-post count.
The code for this remains surprisingly long, and I would like to ask for
any ways to make this better. I use here only one simple ctag to display
the actual list item html. You can more or less guess what it does.
The links in the output are of the type
http://siteurl/?m1202
or...
http://siteurl/?y12
So, hopefully someone has time to check this out. It's meant to be L8
compatible. The code works ok, only it looks so clumsy to me.
If someone wants to run this code, you need only a series of MySQL type
dates as input, to mimic my database data. You could adapt this to use
almost any MySQL table.
'<h2>'; Str('Archives'); '</h2>';
'<ul>';
Inline(-search,$dbConfig,-Table=$table_prefix+'posts',
-eq, 'pos_status' = 'publish',
-SortField='pos_date',
-SortOrder='descending',
-MaxRecords='all',
-ReturnField='pos_date',
-InlineName='archiveSearch');
var( 'myDate' = date,
'myMonth' = string,
'myYear' = string,
'subheaMonth' = string,
'subheaYear' = string,
'href' = string,
'yearMode' = 'no',
'displaycount' = integer,
'monthly' = array
);
// 1) collect data (to the $monthly array)
records;
$myDate = date(field('pos_date'),-format='%Q %T');
$myMonth = string($myDate -> month);
$myMonth -> padleading(2,'0');
$myYear = string($myDate -> year);
if($monthly -> find($myYear+$myMonth) -> size);
$monthly -> find($myYear+$myMonth)->get(1)->get(2) += 1;
else;
$monthly -> insert(string($myYear+$myMonth) = 1);
/if;
/records;
/Inline;
// 2) display
var('postcount_yearly') = integer;
iterate($monthly,local('i'));
$href = $opts -> find('siteurl'); // reset
$myYear = #i->first->substring(1,4);
$myMonth = #i->first->substring(5,2);
if($displayCount > 6 && $myYear != $subheaYear); // year changed
if($yearMode == 'yes'); // ...but not for the first time
// show yearly link for previous year
$href += '?y=' + $subheaYear;
LB_sidebarItem($href,$subheaYear,' ('+$postcount_yearly+')');
$displayCount += 1;
$postcount_yearly = integer; // reset
else; // first year-change - start collecting yearly data
$yearMode = 'yes';
/if;
/if;
if($yearMode != 'yes'); // show monthly link
$href += '?m=' + #i -> first;
LB_sidebarItem($href,$aMonths->get(integer($myMonth))+'
'+$myYear,' ('+#i->second+')');
$displayCount += 1;
/if;
if($yearMode == 'yes');
$postcount_yearly += #i -> second; // collect yearly data
/if;
$subheaYear = #i->first->substring(1,4);
$subheaMonth = #i->first->substring(5,2);
/iterate;
// show the last yearly link, if there is any data
if($postcount_yearly);
$href = $opts -> find('siteurl'); // reset
$href += '?y=' + $subheaYear;
LB_sidebarItem($href,$subheaYear,' ('+$postcount_yearly+')');
/if;
'</ul>';
Thanks in advance,
Jussi
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso
Lasso@lists.lassosoft.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Feb 09, 2013; 12:22
Anibal Escobar
Re: Anybody willing to review this code?
Feb 09, 2013; 19:43
Jussi Hirvi
Re: Anybody willing to review this code?
Feb 10, 2013; 19:45
Jussi Hirvi
Re: Anybody willing to review this code?
Feb 10, 2013; 16:05
Anibal Escobar
Re: Anybody willing to review this code?