-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Resolve endless loop when calling archive without params (#35)
Releases: master, 9.1, 9.0 Fixes: #27
- Loading branch information
1 parent
bceec79
commit a7cf507
Showing
6 changed files
with
147 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Utility; | ||
|
||
class ArchiveUtility | ||
{ | ||
/** | ||
* This method extracts and sorts the database result and create a nested array | ||
* in the form: | ||
* [ | ||
* 2015 => [ | ||
* [ | ||
* 'year' => 2015, | ||
* 'month' => 3, | ||
* 'count' => 9 | ||
* 'timestamp' => 123456789 | ||
* ] | ||
* ... | ||
* ] | ||
* ... | ||
* ] | ||
* | ||
* @param array $data | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public static function extractDataFromPosts(array $data): array | ||
{ | ||
$archiveData = []; | ||
foreach ($data as $result) { | ||
if (empty($archiveData[$result['year']])) { | ||
$archiveData[$result['year']] = []; | ||
} | ||
$dateTime = new \DateTimeImmutable(sprintf('%d-%d-1', (int)$result['year'], (int)$result['month'])); | ||
$result['timestamp'] = $dateTime->getTimestamp(); | ||
$archiveData[$result['year']][] = $result; | ||
} | ||
|
||
return $archiveData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:blog="http://typo3.org/ns/T3G/AgencyPack/Blog/ViewHelpers" data-namespace-typo3-fluid="true"> | ||
<f:if condition="{items}"> | ||
<ul class="archive"> | ||
<f:for each="{items}" as="months" key="year"> | ||
<f:if condition="{settings.widgets.archive.groupByYear} == 1"> | ||
<f:then> | ||
<li class="archive-item archive-item-year archive-item-{year}"> | ||
<blog:link.archive class="archive-item-year-link" year="{year}" title="{year}"> | ||
{year} | ||
</blog:link.archive> | ||
<blog:link.archive class="archive-item-year-rss" rss="true" year="{year}" title="{year}"> | ||
<i class="fa fa-rss-square"></i> | ||
</blog:link.archive> | ||
<f:if condition="{settings.widgets.archive.groupByMonth} == 1"> | ||
<ul> | ||
<f:for each="{months}" as="month"> | ||
<f:render section="Month" arguments="{settings: settings, year: year, month: month}" /> | ||
</f:for> | ||
</ul> | ||
</f:if> | ||
</li> | ||
</f:then> | ||
<f:else> | ||
<f:for each="{months}" as="month"> | ||
<f:render section="Month" arguments="{settings: settings, year: year, month: month}" /> | ||
</f:for> | ||
</f:else> | ||
</f:if> | ||
</f:for> | ||
</ul> | ||
</f:if> | ||
|
||
<f:section name="Month"> | ||
<li class="archive-item archive-item-month archive-item-{year}-{month.month}"> | ||
<blog:link.archive class="archive-item-month-link" year="{year}" month="{month.month}" title="{f:format.date(format: '{settings.widgets.archive.monthDateFormat} {settings.widgets.archive.yearDateFormat}', date: month.timestamp)}"> | ||
<f:if condition="{settings.widgets.archive.groupByYear} == 1"> | ||
<f:then> | ||
{f:format.date(format: '{settings.widgets.archive.monthDateFormat}', date: month.timestamp)} <f:if condition="{settings.widgets.archive.showCounter} == 1">({month.count})</f:if> | ||
</f:then> | ||
<f:else> | ||
{f:format.date(format: '{settings.widgets.archive.monthDateFormat} {settings.widgets.archive.yearDateFormat}', date: month.timestamp)} <f:if condition="{settings.widgets.archive.showCounter} == 1">({month.count})</f:if> | ||
</f:else> | ||
</f:if> | ||
</blog:link.archive> | ||
<blog:link.archive class="archive-item-month-rss" rss="true" year="{year}" month="{month.month}" title="{year}"> | ||
<i class="fa fa-rss-square"></i> | ||
</blog:link.archive> | ||
</li> | ||
</f:section> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,7 @@ | ||
{namespace blog=T3G\AgencyPack\Blog\ViewHelpers} | ||
<f:layout name="Widget" /> | ||
|
||
<f:section name="content"> | ||
|
||
<h3 class="widget-title"><f:translate key="headline.archive"/></h3> | ||
<ul class="archive"> | ||
<f:for each="{archiveData}" as="rows" key="year"> | ||
<f:if condition="{settings.widgets.archive.groupByYear} == 1"> | ||
<f:then> | ||
<li class="list-item archive-item archive-item-{year}"> | ||
<blog:link.archive year="{year}" title="{year}">{year}</blog:link.archive> <blog:link.archive rss="true" year="{year}" title="{year}"><i class="fa fa-rss-square"></i></blog:link.archive> | ||
<f:if condition="{settings.widgets.archive.groupByMonth} == 1"> | ||
<ul> | ||
<f:for each="{rows}" as="row"> | ||
<f:render section="monthLink" arguments="{settings: settings, year: year, row: row}" /> | ||
</f:for> | ||
</ul> | ||
</f:if> | ||
</li> | ||
</f:then> | ||
<f:else> | ||
<f:if condition="{settings.widgets.archive.groupByMonth} == 1"> | ||
<f:for each="{rows}" as="row"> | ||
<f:render section="monthLink" arguments="{settings: settings, year: year, row: row}" /> | ||
</f:for> | ||
</f:if> | ||
</f:else> | ||
</f:if> | ||
</f:for> | ||
</ul> | ||
</f:section> | ||
<f:render partial="Archive/Menu" arguments="{settings: settings, items: archiveData}" /> | ||
|
||
<f:section name="monthLink"> | ||
<li class="list-item archive-item archive-item-{year}-{row.month}"> | ||
<blog:link.archive year="{year}" month="{row.month}" title="{f:format.date(format: '{settings.widgets.archive.monthDateFormat} {settings.widgets.archive.yearDateFormat}', date: row.timestamp)}"> | ||
<f:if condition="{settings.widgets.archive.groupByYear} == 1"> | ||
<f:then> | ||
{f:format.date(format: '{settings.widgets.archive.monthDateFormat}', date: row.timestamp)} <f:if condition="{settings.widgets.archive.showCounter} == 1">({row.count})</f:if> | ||
</f:then> | ||
<f:else> | ||
{f:format.date(format: '{settings.widgets.archive.monthDateFormat} {settings.widgets.archive.yearDateFormat}', date: row.timestamp)} <f:if condition="{settings.widgets.archive.showCounter} == 1">({row.count})</f:if> | ||
</f:else> | ||
</f:if> | ||
</blog:link.archive> | ||
<blog:link.archive rss="true" year="{year}" month="{row.month}" title="{year}"><i class="fa fa-rss-square"></i></blog:link.archive> | ||
</li> | ||
</f:section> | ||
</f:section> |