Skip to content

Commit

Permalink
Merge pull request #44 from jonathanheilmann/develop_v1.2.2
Browse files Browse the repository at this point in the history
Develop v1.2.2
  • Loading branch information
jonathanheilmann authored Sep 10, 2016
2 parents 1ceb8a9 + 65dc268 commit 09214c3
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 100 deletions.
56 changes: 38 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
## TYPO3 v4
# Ignore serveral upload and file directories.
/fileadmin/user_upload/
/fileadmin/_temp_/
/uploads/
# Ignore cache
/typo3conf/temp_CACHED*
/typo3conf/temp_fieldInfo.php
# Ignore local config which overrides typo3 config.
# You should include your local stuff with `@include('localconf_local.php');` at the end of localconf.php.
# See http://stackoverflow.com/questions/11905360/how-best-to-manage-typo3-installations-using-git for details.
/typo3conf/localconf_local.php
# Ignore system folders, you should have them symlinked.
# If not comment out the following two entries.
/typo3
/t3lib
# Ignore temp directory.
/typo3temp/
##
# Local
##
.idea/*

##
# https://gist.github.com/jonathanheilmann/79228adada3521a90a54
##

##
# OSX
##
.DS_Store
.AppleDouble
.LSOverride

##
# Windows
##
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk

##
# all OS
##
*.bak
150 changes: 75 additions & 75 deletions Classes/Service/OgRendererService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
***************************************************************/

use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
* Class OgRendererService
Expand Down Expand Up @@ -64,20 +64,23 @@ public function main($content, $conf)
$content = '';
$og = array();

if ($this->signalSlotDispatcher == null) {
if ($this->signalSlotDispatcher == null)
{
/* @var \TYPO3\CMS\Extbase\Object\ObjectManager */
$objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$this->signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
}

// 2013-04-22 [email protected]
// Check if the tt_news "displaySingle" method has been called before
if (class_exists('tx_jhopengraphttnews_displaySingleHook')) {
if (class_exists('tx_jhopengraphttnews_displaySingleHook'))
{
$hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook');
if ($hookObject->singleViewDisplayed())
return $content;
}
if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class)) {
if (class_exists(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class))
{
$hookObject = GeneralUtility::makeInstance(\Heilmann\JhOpengraphTtnews\Hooks\DisplaySingle::class);
if ($hookObject->singleViewDisplayed())
return $content;
Expand All @@ -86,76 +89,82 @@ public function main($content, $conf)
//if there has been no return, get og properties and render output

// Get title
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtitle'])) {
$og['title'] = $this->cObj->data['tx_jhopengraphprotocol_ogtitle'];
} else {
$og['title'] = $GLOBALS['TSFE']->page['title'];
}
$og['title'] = htmlspecialchars($og['title']);
$og['title'] = htmlspecialchars(!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle']) ?
$GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtitle'] :
$GLOBALS['TSFE']->page['title']);

// Get type
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtype'])) {
$og['type'] = $this->cObj->data['tx_jhopengraphprotocol_ogtype'];
} else {
$og['type'] = $conf['type'];
}
$og['type'] = htmlspecialchars($og['type']);

// Get image
/** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */
$fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
$fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id);
if (count($fileObjects)) {
foreach ($fileObjects as $key => $fileObject) {
/** @var FileReference $fileObject */
$og['image'][] = $fileObject;
}
} else {
$og['type'] = htmlspecialchars(!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype']) ?
$GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] :
$conf['type']);

// Get images
/** @var FileRepository $fileRepository */
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);

$fileObjects = array();
if ($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'])
{
// Get images if there is a language overlay
// This is somehow a hack, as l10n_mode 'mergeIfNotBlack' does not work in this case.
// PageRepository->shouldFieldBeOverlaid does not work for config type 'inline' with "DEFAULT '0'" database config,
// as an empty inline field is '0', and '0' is treated as not empty.
// Setting 'Default NULL' in database config won't work, too, as it isn't easier to check, if value in
// $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogtype'] is related to table 'pages' or 'pages_language_overlay'.

$overlayFileObjects = $fileRepository->findByRelation('pages_language_overlay', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID']);
if (count($overlayFileObjects) > 0)
$fileObjects = $overlayFileObjects;
else if (isset($GLOBALS['TCA']['pages_language_overlay']['columns']['tx_jhopengraphprotocol_ogfalimages']['l10n_mode']) &&
$GLOBALS['TCA']['pages_language_overlay']['columns']['tx_jhopengraphprotocol_ogfalimages']['l10n_mode'] === 'mergeIfNotBlank')
$fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id);
} else
$fileObjects = $fileRepository->findByRelation('pages', 'tx_jhopengraphprotocol_ogfalimages', $GLOBALS['TSFE']->id);

if (count($fileObjects) === 0)
{
// check if an image is given in page --> media, if not use default image
$fileObjects = $fileRepository->findByRelation('pages', 'media', $GLOBALS['TSFE']->id);
if (count($fileObjects)) {
foreach ($fileObjects as $key => $fileObject) {
/** @var FileReference $fileObject */
$og['image'][] = $fileObject;
}
} else {
$fileObjects = $fileRepository->findByRelation(
($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ? 'pages_language_overlay' : 'pages'),
'media',
($GLOBALS['TSFE']->page['_PAGES_OVERLAY_UID'] ?:$GLOBALS['TSFE']->id)
);
if (count($fileObjects) === 0)
{
$imageFileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']);
if (!empty($imageFileName)) {
if (!empty($imageFileName))
$og['image'][] = $imageFileName;
}
}
}

} else
$og['image'] = $fileObjects;
} else
$og['image'] = $fileObjects;

// Get url
$og['url'] = htmlentities(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));

// Get site_name
if (!empty($conf['sitename'])) {
$og['site_name'] = $conf['sitename'];
} else {
$og['site_name'] = $GLOBALS['TSFE']->tmpl->setup['sitetitle'];
}
$og['site_name'] = htmlspecialchars($og['site_name']);
$og['site_name'] = htmlspecialchars(!empty($conf['sitename']) ?
$conf['sitename'] :
$GLOBALS['TSFE']->tmpl->setup['sitetitle']);

// Get description
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogdescription'])) {
$og['description'] = $this->cObj->data['tx_jhopengraphprotocol_ogdescription'];
} else {
if (!empty($GLOBALS['TSFE']->page['description'])) {
$og['description'] = $GLOBALS['TSFE']->page['description'];
} else {
$og['description'] = $conf['description'];
}
}
if (!empty($GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription']))
$og['description'] = $GLOBALS['TSFE']->page['tx_jhopengraphprotocol_ogdescription'];
else
$og['description'] = !empty($GLOBALS['TSFE']->page['description']) ?
$GLOBALS['TSFE']->page['description'] :
$conf['description'];

$og['description'] = htmlspecialchars($og['description']);

// Get locale
$localeParts = explode('.', $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all']);
if (isset($localeParts[0])) {
if (isset($localeParts[0]))
$og['locale'] = str_replace('-', '_', $localeParts[0]);
}

// Signal to manipulate og-properties before header creation
// Please do not use the second parameter ($this->cObj) in your dispatcher, but $GLOBALS['TSFE']->page instead.
// This allows you to use the advantage of easy multilingual page handling.
$this->signalSlotDispatcher->dispatch(
__CLASS__,
'beforeHeaderCreation',
Expand Down Expand Up @@ -189,22 +198,13 @@ protected function renderHeaderLines($array)
{
// A og property that accepts more than one value
foreach ($value as $multiPropertyValue)
{
// Render each value to a new og property meta-tag
if ($key == 'image')
{
// Add image details
$res[] = $this->buildOgImageProperties($key, $multiPropertyValue);
} else
{
$res[] = $this->buildProperty($key, $multiPropertyValue);
}
}
$res[] = $key == 'image' ?
$this->buildOgImageProperties($key, $multiPropertyValue) :
$this->buildProperty($key, $multiPropertyValue);
} else
{
// A og property with child-properties
$res .= $this->renderHeaderLines($this->remapArray($key, $value));
}
} else
{
// A single og property to be rendered
Expand All @@ -229,13 +229,13 @@ protected function buildOgImageProperties($key, $value)
if (is_object($value) && $value instanceOf FileReference)
{
/** @var FileReference $value */
$res[] = $this->buildProperty($key,
GeneralUtility::locationHeaderUrl($value->getPublicUrl()));
$res[] = $this->buildProperty($key . ':type', $value->getMimeType());
$res[] = $this->buildProperty($key . ':width',
$value->getProperty('width'));
$res[] = $this->buildProperty($key . ':height',
$value->getProperty('height'));
$res[] = $this->buildProperty($key, GeneralUtility::locationHeaderUrl($value->getPublicUrl()));
if ($value->getMimeType())
$res[] = $this->buildProperty($key . ':type', $value->getMimeType());
if ($value->getProperty('width'))
$res[] = $this->buildProperty($key . ':width', $value->getProperty('width'));
if ($value->getProperty('height'))
$res[] = $this->buildProperty($key . ':height', $value->getProperty('height'));
} else if (is_string($value))
{
$imageSize = array();
Expand Down
13 changes: 13 additions & 0 deletions Documentation/Administrator/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ Installation

- import and install the extension

- configure extension in Extension Manager

- include static template “Open Graph protocol”

- use the Constant-Editor to edit the global Open Graph properties

- use the page-settings for setting the local Open Graph properties


.. _admin-extConfiguration:

Extension configuration
-----------------------

Since version 1.2.2 you are able to control the localization mode of each field.

By default localized pages do not inherit fields from default language if they are empty/blank.
If you want to enable this behavior, configure extension jh_opengraphprotocol and set
">FieldToInheritFromDefaultLanguage< mergeIfNotBlank".


.. _admin-updating:

Expand Down
8 changes: 8 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ ChangeLog
:Changes:
Changes

- :Version:
1.2.2

:Changes:
\* [TASK] Change description field to textarea

\* [BUGFIX] #37 Not localized og tag on FE

- :Version:
1.2.1

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ conf.py:
copyright: 2012-2016
project: Open Graph protocol
version: 1.2
release: 1.2.1
release: 1.2.2
intersphinx_mapping:
t3tsref:
- http://docs.typo3.org/typo3cms/TyposcriptReference/
Expand Down
2 changes: 2 additions & 0 deletions Resources/Private/Language/locallang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<label index="pages.tx_jhopengraphprotocol_ogtitle">Title</label>
<label index="pages.tx_jhopengraphprotocol_ogtype">Type</label>
<label index="pages.tx_jhopengraphprotocol_ogimage">Image</label>
<label index="pages.tx_jhopengraphprotocol_ogimage.mergeIfNotBlank">Image (The image(s) of the default language will be used if this field is left empty in the translation.)</label>
<label index="pages.tx_jhopengraphprotocol_ogdescription">Description</label>
</languageKey>
<languageKey index="de" type="array">
Expand All @@ -19,6 +20,7 @@
<label index="pages.tx_jhopengraphprotocol_ogtitle">Titel</label>
<label index="pages.tx_jhopengraphprotocol_ogtype">Typ</label>
<label index="pages.tx_jhopengraphprotocol_ogimage">Bild</label>
<label index="pages.tx_jhopengraphprotocol_ogimage.mergeIfNotBlank">Bild (Das Bild/die Bilder der Standardsprache wird/werden verwendet, wenn dieses Feld in der Übersetzung leer ist.)</label>
<label index="pages.tx_jhopengraphprotocol_ogdescription">Beschreibung</label>
</languageKey>
</data>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"support": {
"issues": "https://github.com/jonathanheilmann/ext-jh_opengraphprotocol/issues"
},
"version": "1.2.1",
"version": "1.2.2",
"require": {
"typo3/cms": "~6.2,~7.6"
},
Expand Down
11 changes: 11 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# cat=basic/enable/100; type=boolean; label=Title mergeIfNotBlank: Use title of default language if localized title is empty
languageOverlay.tx_jhopengraphprotocol_ogtitle.mergeIfNotBlank = 0

# cat=basic/enable/101; type=boolean; label=Type mergeIfNotBlank: Use type of default language if localized type is empty
languageOverlay.tx_jhopengraphprotocol_ogtype.mergeIfNotBlank = 0

# cat=basic/enable/102; type=boolean; label=Image(s) mergeIfNotBlank: Use image(s) of default language if localized image(s) is empty
languageOverlay.tx_jhopengraphprotocol_ogfalimages.mergeIfNotBlank = 0

# cat=basic/enable/103; type=boolean; label=Description mergeIfNotBlank: Use description of default language if localized description is empty
languageOverlay.tx_jhopengraphprotocol_ogdescription.mergeIfNotBlank = 0
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'description' => 'Adds the Open Graph protocol properties in meta-tags to the html-header supporting multilingual-websites.',
'category' => 'plugin',
'shy' => 0,
'version' => '1.2.1',
'version' => '1.2.2',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
Expand Down
Loading

0 comments on commit 09214c3

Please sign in to comment.