From: <be...@us...> - 2014-10-02 23:09:02
|
Revision: 12807 http://sourceforge.net/p/xoops/svn/12807 Author: beckmi Date: 2014-10-02 23:08:57 +0000 (Thu, 02 Oct 2014) Log Message: ----------- redesigned archives section to have months horizontally, added count of articles Modified Paths: -------------- XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/archive.php XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/templates/publisher_archive.tpl Modified: XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/archive.php =================================================================== --- XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/archive.php 2014-10-02 23:07:10 UTC (rev 12806) +++ XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/archive.php 2014-10-02 23:08:57 UTC (rev 12807) @@ -68,46 +68,70 @@ $criteria->setSort('datesub'); $criteria->setOrder('DESC'); //Get all articles dates as an array to save memory -$items = $publisher->getHandler('item')->getAll($criteria, array('datesub'), false); +$items = $publisher->getHandler('item')->getAll($criteria, array('datesub'), false); $itemsCount = count($items); if (!($itemsCount > 0)) { redirect_header(XOOPS_URL, 2, _MD_PUBLISHER_NO_TOP_PERMISSIONS); exit; } else { - $years = array(); + $years = array(); $months = array(); - $i = 0; + $i = 0; foreach ($items as $item) { $time = XoopsLocal::formatTimestamp($item['datesub'], 'mysql', $useroffset); if (preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/", $time, $datetime)) { - $this_year = intval($datetime[1]); + $this_year = intval($datetime[1]); $this_month = intval($datetime[2]); + //first year if (empty($lastyear)) { - $lastyear = $this_year; + $lastyear = $this_year; + $articlesThisYear = 0; + $articlesThisMonth = 0; } + //first month of the year reset if ($lastmonth == 0) { - $lastmonth = $this_month; + $lastmonth = $this_month; $months[$lastmonth]['string'] = $months_arr[$lastmonth]; $months[$lastmonth]['number'] = $lastmonth; +// $months[$lastmonth]['articlesMonthCount'] = 1; + $articlesThisMonth = 0; } + //new year if ($lastyear != $this_year) { $years[$i]['number'] = $lastyear; $years[$i]['months'] = $months; - $months = array(); - $lastmonth = 0; - $lastyear = $this_year; + + $years[$i]['articlesYearCount'] = $articlesThisYear; + + $months = array(); + $lastmonth = 0; + $lastyear = $this_year; + $articlesThisYear = 0; + $articlesThisMonth = 0; ++$i; } + //new month if ($lastmonth != $this_month) { - $lastmonth = $this_month; - $months[$lastmonth]['string'] = $months_arr[$lastmonth]; - $months[$lastmonth]['number'] = $lastmonth; + if ($articlesThisMonth > 0) { + $months[$lastmonth]['articlesMonthCount'] = $articlesThisMonth; + } + $lastmonth = $this_month; + $months[$lastmonth]['string'] = $months_arr[$lastmonth]; + $months[$lastmonth]['number'] = $lastmonth; + $months[$lastmonth]['articlesMonthCount'] = 1; + $articlesThisMonth = 0; } + + ++$articlesThisMonth; + ++$articlesThisYear; } } $years[$i]['number'] = $this_year; $years[$i]['months'] = $months; + + $years[$i]['articlesYearCount'] = $articlesThisYear; + $xoopsTpl->assign('years', $years); } unset($items); @@ -124,19 +148,19 @@ // must adjust the selected time to server timestamp $timeoffset = $useroffset - $xoopsConfig['server_TZ']; $monthstart = mktime(0 - $timeoffset, 0, 0, $frommonth, 1, $fromyear); - $monthend = mktime(23 - $timeoffset, 59, 59, $frommonth + 1, 0, $fromyear); - $monthend = ($monthend > time()) ? time() : $monthend; + $monthend = mktime(23 - $timeoffset, 59, 59, $frommonth + 1, 0, $fromyear); + $monthend = ($monthend > time()) ? time() : $monthend; $count = 0; - $itemhandler = $publisher->getHandler('item'); - $itemhandler->table_link = $xoopsDB->prefix('publisher_categories'); - $itemhandler->field_link = 'categoryid'; + $itemhandler = $publisher->getHandler('item'); + $itemhandler->table_link = $xoopsDB->prefix('publisher_categories'); + $itemhandler->field_link = 'categoryid'; $itemhandler->field_object = 'categoryid'; // Categories for which user has access $categoriesGranted =& $publisher->getHandler('permission')->getGrantedItems('category_read'); $grantedCategories = new Criteria('l.categoryid', "(" . implode(',', $categoriesGranted) . ")", 'IN'); - $criteria = new CriteriaCompo(); + $criteria = new CriteriaCompo(); $criteria->add($grantedCategories, 'AND'); $criteria->add(new Criteria('o.status', 2), 'AND'); $critdatesub = new CriteriaCompo(); @@ -151,20 +175,17 @@ $count = count($storyarray); if (is_array($storyarray) && $count > 0) { foreach ($storyarray as $item) { - $story = array(); + $story = array(); $htmltitle = ''; - $story['title'] = "<a href='" . XOOPS_URL . '/modules/publisher/category.php?categoryid=' - . $item->categoryid() . "'>" - . $item->getCategoryName() . "</a>: <a href='" - . $item->getItemUrl() . "'" . $htmltitle . ">" - . $item->title() . "</a>"; - $story['counter'] = $item->counter(); - $story['date'] = $item->datesub(); + $story['title'] + = + "<a href='" . XOOPS_URL . '/modules/publisher/category.php?categoryid=' . $item->categoryid() . "'>" . $item->getCategoryName() . "</a>: <a href='" . $item->getItemUrl() . "'" + . $htmltitle . ">" . $item->title() . "</a>"; + $story['counter'] = $item->counter(); + $story['date'] = $item->datesub(); $story['print_link'] = XOOPS_URL . '/modules/publisher/print.php?itemid=' . $item->itemid(); - $story['mail_link'] = 'mailto:?subject=' - . sprintf(_CO_PUBLISHER_INTITEM, $xoopsConfig['sitename']) - . '&body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $xoopsConfig['sitename']) - . ': ' . $item->getItemUrl(); + $story['mail_link'] = 'mailto:?subject=' . sprintf(_CO_PUBLISHER_INTITEM, $xoopsConfig['sitename']) . '&body=' . sprintf(_CO_PUBLISHER_INTITEMFOUND, $xoopsConfig['sitename']) . ': ' + . $item->getItemUrl(); $xoopsTpl->append('stories', $story); } Modified: XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/templates/publisher_archive.tpl =================================================================== --- XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/templates/publisher_archive.tpl 2014-10-02 23:07:10 UTC (rev 12806) +++ XoopsModules/modulepacks/x257basicmodulepack/trunk/modules/publisher/templates/publisher_archive.tpl 2014-10-02 23:08:57 UTC (rev 12807) @@ -2,13 +2,19 @@ <tr> <th><{$lang_newsarchives}></th> </tr> - <{foreach item=year from=$years}> <{foreach item=month from=$year.months}> - <tr class="even"> - <td> - <a href="<{$xoops_url}>/modules/publisher/archive.php?year=<{$year.number}>&month=<{$month.number}>"><{$month.string}> <{$year.number}></a> - </td> - </tr> - <{/foreach}> <{/foreach}> + <{foreach item=year from=$years}> + <tr class="even"> + <td><{$year.number}> (<{$year.articlesYearCount}>)</td> + </tr> + <tr class="odd"> + <td> + <{foreach item=month from=$year.months}> + <a href="./archive.php?year=<{$year.number}>&month=<{$month.number}>"><{$month.string}> (<{$month.articlesMonthCount}>) </a> + + <{/foreach}> + </td> + </tr> + <{/foreach}> </table> <{if $show_articles == true}> |