Skip to content

Commit

Permalink
see cl 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Patzer committed Sep 24, 2019
1 parent 34fc665 commit d2bdb60
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
25 changes: 19 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.0.0] - 2019-09-24

### Added
- {{strtotime}} inserttag

### Changed
- refactoring

## [0.3.0] - 2019-08-23

- added amp support for download inserttag
### Added
- amp support for download inserttag

## [0.2.0] - 2019-08-22

- added small and endsmall insert tags
### Added
- small and endsmall insert tags
- some smaller refactoring

## [0.1.2] - 2018-08-02

- fixed download tag css class and id parameter not working
### Fixed
- download tag css class and id parameter not working

## [0.1.1] - 2018-08-02

- fixed missing type for content download element
- updated documentation
### Fixed
- missing type for content download element
- documentation

## [0.1.0] - 2018-07-31

Initial commit
### Added
- Initial commit
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The download inserttag template is already prepared for [AMP Bundle](https://git

Inserttag | Example | Description
--------------|----------------------|-------------
strtotime | `{{strtotime::midnight}}` | Returns supported return values of strtotime() (see [php docs](https://www.php.net/manual/de/datetime.formats.relative.php)). Also possible: `{{strtotime::+ 1 day::\<timestamp\>}}`
link_url_abs | `{{link_url_abs::92}}` | Get the absolute url of an page.
email_label | `{{email_label::info@example.org::E-Mail}}` | Generate an e-mail link with custom label. Custom classes and id are also possile: (`{{email_label::info@example.org::E-Mail::btn btn-default::my_custom_email_link}}`)
download | `{{download::9263228b-9577-11e8-abd4-a08cfddc0261}}` | Generate an download link to the file with file name as label and download size. File parameter can be file uuid or file path. Optional parameter for custom label, link css class and link css id.
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
"autoload": {
"psr-4": {
"HeimrichHannot\\ContaoInserttagCollectionBundle\\": "src/"
}
},
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
48 changes: 29 additions & 19 deletions src/EventListener/InserttagListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,35 @@ public function onReplaceInsertTags(string $tag)
{
$tag = trim($tag, '{}');
$tag = explode('::', $tag);

if (empty($tag)) {
return false;
}

switch ($tag[0]) {
case 'link_url_abs':
return $this->linkAbsoluteUrl($tag);
return $this->generateLinkAbsoluteUrl($tag);
case 'email_label':
return $this->emailLabel($tag);
return $this->generateEmailLabel($tag);
case 'download':
return $this->download($tag);
return $this->generateDownload($tag);
case 'download_link':
return $this->downloadLink($tag);
return $this->generateDownloadLink($tag);
case 'download_size':
return $this->downloadSize($tag);
return $this->generateDownloadSize($tag);
case 'small':
return $this->smallStartTag($tag);
return $this->generateSmallStartTag($tag);
case 'endsmall':
return $this->smallEndTag($tag);
return $this->generateSmallEndTag($tag);
case 'strtotime':
return $this->generateStrToTime($tag);
break;
}

return false;
}

public function linkAbsoluteUrl(array $tag)
public function generateLinkAbsoluteUrl(array $tag)
{
if (isset($tag[1])) {
$pageModel = $this->container->get('huh.utils.url')->getJumpToPageObject($tag[1]);
Expand All @@ -80,7 +85,7 @@ public function linkAbsoluteUrl(array $tag)
*
* @return string mailto-Link or empty string, if no valid mail adress given
*/
public function emailLabel(array $tag)
public function generateEmailLabel(array $tag)
{
if (!isset($tag[1]) || !Validator::isEmail($tag[1])) {
return '';
Expand All @@ -97,42 +102,47 @@ public function emailLabel(array $tag)
return $link;
}

public function download(array $tag)
public function generateDownload(array $tag)
{
$download = $this->generateDownload($tag);
$download = $this->doGenerateDownload($tag);

return $download->generate();
}

public function downloadLink(array $tag)
public function generateDownloadLink(array $tag)
{
$download = $this->generateDownload($tag);
$download = $this->doGenerateDownload($tag);
$download->generate();

return $download->Template->href;
}

public function downloadSize(array $tag)
public function generateDownloadSize(array $tag)
{
$download = $this->generateDownload($tag);
$download = $this->doGenerateDownload($tag);
$download->generate();

return $download->Template->filesize;
}

public function smallStartTag($tag)
public function generateSmallStartTag($tag)
{
return '<small>';
}

public function smallEndTag($tag)
public function generateSmallEndTag($tag)
{
return '</small>';
}

private function generateDownload(array $tag)
public function generateStrToTime($tag)
{
return strtotime($tag[1], $tag[2] ?? time());
}

private function doGenerateDownload(array $tag)
{
$source = strip_tags(($tag[1])); // remove <span> etc, otherwise Validator::isuuid fail
$source = strip_tags($tag[1]); // remove <span> etc, otherwise Validator::isuuid fail

$file = null;
if (Validator::isUuid($source)) {
Expand Down

0 comments on commit d2bdb60

Please sign in to comment.