Skip to content

Commit

Permalink
- reworked language files
Browse files Browse the repository at this point in the history
- set minimum version to Contao 4.13
- added support for contao/faq-bundle
  • Loading branch information
bennyborn committed May 10, 2023
1 parent 3724be0 commit 5c39726
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 381 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ Implementation of OpenGraph tags and Twitter Cards for Contao. [Read more](https
System requirements
--

* [Contao 4.9 or newer](https://github.com/contao/contao)
* [Contao 4.13 or newer](https://github.com/contao/contao)

Compatible modules
Compatible bundles
--

By default the OpenGraph fields are attached to the site structure. Furthermore OpenGraph3 is compatible with the following Contao modules:
By default the OpenGraph fields are attached to the site structure. Furthermore OpenGraph3 is compatible with the following Contao bundles:


* [news](https://github.com/contao/news-bundle)
* [faq](https://github.com/contao/faq-bundle)
* [calendar](https://github.com/contao/calendar-bundle)
* [isotope](https://github.com/isotope/core)
* [storelocator](https://github.com/numero2/contao-storelocator)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"contao/core-bundle": "^4.9 || ^5.0"
"contao/core-bundle": "^4.13 || ^5.0"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
Expand Down
14 changes: 6 additions & 8 deletions src/Resources/contao/classes/OpenGraphCalendarEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2022 Leo Feyer
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2022 numero2 - Agentur für digitales Marketing GbR
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/


Expand All @@ -34,12 +34,10 @@ public static function addModuleData( $objModule ): void {
$event = CalendarEventsModel::findPublishedByParentAndIdOrAlias((Input::get('auto_item') ?? ''), $calendars);

// Check if the calendar event could get loaded from the database
if (null === $event) {
return;
}

OpenGraph3::addProperty('og_type', 'website', $event);
if( null !== $event ) {

OpenGraph3::addTagsToPage($event);
OpenGraph3::addProperty('og_type', 'website', $event);
OpenGraph3::addTagsToPage($event);
}
}
}
58 changes: 58 additions & 0 deletions src/Resources/contao/classes/OpenGraphFaq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/


namespace numero2\OpenGraph3;

use Contao\Config;
use Contao\FaqModel;
use Contao\Input;
use Contao\StringUtil;
use DateTime;


class OpenGraphFaq {


/**
* Appends OpenGraph data from FAQ articles
*
* @param $objModule
*/
public static function addModuleData( $objModule ): void {

$faqCategories = [];
$faqCategories = StringUtil::deserialize($objModule->faq_categories);

$objArticle = null;
$objArticle = FaqModel::findPublishedByParentAndIdOrAlias((Input::get('auto_item') ?? ''), $faqCategories);

if( null !== $objArticle ) {

OpenGraph3::addProperty('og_type','article',$objArticle);

// add modified time
if( $objArticle->tstamp ) {

$date = new DateTime();
$date->setTimestamp($objArticle->tstamp);
$date = $date->format(Config::get('datimFormat'));

OpenGraph3::addProperty('og_article_modified_time',$date,$objArticle);
}

OpenGraph3::addTagsToPage( $objArticle );
}
}
}
6 changes: 3 additions & 3 deletions src/Resources/contao/classes/OpenGraphIsotope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2021 Leo Feyer
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2021 numero2 - Agentur für digitales Marketing GbR
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/


Expand All @@ -34,7 +34,7 @@ class OpenGraphIsotope {
*/
public static function addModuleData( $objModule ): void {

$objProduct = NULL;
$objProduct = null;
$objProduct = Product::findAvailableByIdOrAlias( (Input::get('auto_item') ?? '') );

if( null !== $objProduct ) {
Expand Down
11 changes: 6 additions & 5 deletions src/Resources/contao/classes/OpenGraphNews.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2022 Leo Feyer
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2022 numero2 - Agentur für digitales Marketing GbR
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/


Expand All @@ -19,6 +19,7 @@
use Contao\Input;
use Contao\NewsModel;
use Contao\StringUtil;
use DateTime;


class OpenGraphNews {
Expand All @@ -34,7 +35,7 @@ public static function addModuleData( $objModule ): void {
$newsArchives = [];
$newsArchives = StringUtil::deserialize($objModule->news_archives);

$objArticle = NULL;
$objArticle = null;
$objArticle = NewsModel::findPublishedByParentAndIdOrAlias((Input::get('auto_item') ?? ''), $newsArchives);

if( null !== $objArticle ) {
Expand All @@ -44,7 +45,7 @@ public static function addModuleData( $objModule ): void {
// add published time
if( $objArticle->time ) {

$date = new \DateTime();
$date = new DateTime();
$date->setTimestamp($objArticle->time);
$date = $date->format(Config::get('datimFormat'));

Expand All @@ -54,7 +55,7 @@ public static function addModuleData( $objModule ): void {
// add modified time
if( $objArticle->tstamp ) {

$date = new \DateTime();
$date = new DateTime();
$date->setTimestamp($objArticle->tstamp);
$date = $date->format(Config::get('datimFormat'));

Expand Down
8 changes: 4 additions & 4 deletions src/Resources/contao/classes/OpenGraphStoreLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2021 Leo Feyer
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2021 numero2 - Agentur für digitales Marketing GbR
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/


Expand All @@ -29,10 +29,10 @@ class OpenGraphStoreLocator {
*/
public static function addModuleData( $objModule ): void {

$alias = NULL;
$alias = null;
$alias = Input::get('auto_item') ? Input::get('auto_item') : Input::get('store');

$objStore = NULL;
$objStore = null;
$objStore = StoresModel::findByIdOrAlias( ($alias ?? '') );

if( null !== $objStore ) {
Expand Down
5 changes: 5 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
, 'numero2\StoreLocator\ModuleStoreLocatorDetails'
, 'numero2\OpenGraph3\OpenGraphStoreLocator'
]
, [
'faqreader'
, 'Contao\ModuleFaqReader'
, 'numero2\OpenGraph3\OpenGraphFaq'
]
];


Expand Down
50 changes: 50 additions & 0 deletions src/Resources/contao/dca/tl_faq.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2023 Leo Feyer
*
* @package Opengraph3
* @author Benny Born <[email protected]>
* @author Michael Bösherz <[email protected]>
* @license LGPL
* @copyright 2023 numero2 - Agentur für digitales Marketing GbR
*/

use Contao\Controller;
use Contao\System;


if( !empty($GLOBALS['TL_DCA']['tl_faq']) ) {

System::loadLanguageFile('opengraph_fields');
Controller::loadDataContainer('opengraph_fields');

/**
* Modify palettes
*/
$GLOBALS['TL_DCA']['tl_faq']['palettes']['default'] = str_replace(
'{answer_legend'
, $GLOBALS['TL_DCA']['opengraph_fields']['palettes']['default'].'{answer_legend'
, $GLOBALS['TL_DCA']['tl_faq']['palettes']['default']
);

/**
* Modify fields
*/
$GLOBALS['TL_DCA']['tl_faq']['fields'] = array_merge(
$GLOBALS['TL_DCA']['tl_faq']['fields']
, $GLOBALS['TL_DCA']['opengraph_fields']['fields']
);

/**
* Add legends
*/
array_walk(
$GLOBALS['TL_LANG']['opengraph_fields']['legends']
, function( $translation, $key ) {
$GLOBALS['TL_LANG']['tl_faq'][$key] = $translation;
}
);
}
Loading

0 comments on commit 5c39726

Please sign in to comment.