Skip to content

Commit

Permalink
Merge pull request #15 from jonathanheilmann/releaseCandidate_v1.1.0-rc1
Browse files Browse the repository at this point in the history
[RELEASE] Release of version 1.1.0
  • Loading branch information
jonathanheilmann committed Oct 20, 2015
2 parents 71dfff0 + 8c30dec commit b895ae2
Show file tree
Hide file tree
Showing 38 changed files with 689 additions and 825 deletions.
1 change: 0 additions & 1 deletion ChangeLog

This file was deleted.

60 changes: 38 additions & 22 deletions Classes/Service/OgRendererService.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace Heilmann\JhOpengraphprotocol\Service;

/***************************************************************
* Copyright notice
*
* (c) 2014 Jonathan Heilmann <[email protected]>
* (c) 2014-2015 Jonathan Heilmann <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand All @@ -22,12 +24,13 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use \TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @author Jonathan Heilmann <[email protected]>
* @package TYPO3
* @subpackage tx_jhopengraphprotocol2
* @package tx_jhopengraphprotocol
*/
class tx_jhopengraphprotocol_service_ogrenderer {
class OgRendererService {

/**
* content Object
Expand All @@ -49,7 +52,7 @@ public function main($content, $conf){
// 2013-04-22 [email protected]
// Check if the tt_news "displaySingle" method has been called before
if(class_exists('tx_jhopengraphttnews_displaySingleHook')) {
$hookObject = t3lib_div::makeInstance('tx_jhopengraphttnews_displaySingleHook');
$hookObject = GeneralUtility::makeInstance('tx_jhopengraphttnews_displaySingleHook');
if ($hookObject->singleViewDisplayed()) {
return $content;
}
Expand All @@ -63,37 +66,47 @@ public function main($content, $conf){
} else {
$og['title'] = $GLOBALS['TSFE']->page['title'];
}
$og['title'] = htmlentities($og['title']);
$og['title'] = htmlspecialchars($og['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'] = htmlentities($og['type']);
$og['type'] = htmlspecialchars($og['type']);

// Get image
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogimage'])) {
$images = explode(',', $this->cObj->data['tx_jhopengraphprotocol_ogimage']);
foreach ($images as $key => $image) {
$og['image'][$key] = t3lib_div::locationHeaderUrl($GLOBALS['TSFE']->tmpl->getFileName('uploads/tx_jhopengraphprotocol/' . $image));
$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) {
$og['image'][] = GeneralUtility::locationHeaderUrl($fileObject->getPublicUrl());
}
} else {
$fileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']);
$og['image'] = (!empty($fileName)) ? t3lib_div::locationHeaderUrl($fileName) : $og['image'] = '';
// 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) {
$og['image'][] = GeneralUtility::locationHeaderUrl($fileObject->getPublicUrl());
}
} else {
if (!empty($GLOBALS['TSFE']->tmpl->getFileName($conf['image']))) {
$og['image'][] = GeneralUtility::locationHeaderUrl($GLOBALS['TSFE']->tmpl->getFileName($conf['image']));
}
}
}

// Get url
$og['url'] = htmlentities(t3lib_div::getIndpEnv('TYPO3_REQUEST_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'] = htmlentities($og['site_name']);
$og['site_name'] = htmlspecialchars($og['site_name']);

// Get description
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogdescription'])) {
Expand All @@ -105,10 +118,13 @@ public function main($content, $conf){
$og['description'] = $conf['description'];
}
}
$og['description'] = htmlentities($og['description']);
$og['description'] = htmlspecialchars($og['description']);

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

//add tags to html-header
$GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og);
Expand All @@ -123,7 +139,7 @@ public function main($content, $conf){
* @return string
*/
private function renderHeaderLines($array) {
$res = '';
$res = array();
foreach ($array as $key => $value) {
if (!empty($value )) { // Skip empty values to prevent from empty og property
if (is_array($value)) {
Expand All @@ -132,19 +148,19 @@ private 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
$res .= '<meta property="og:'.$key.'" content="'.$multiPropertyValue.'" />';
$res[] = '<meta property="og:'.$key.'" content="'.$multiPropertyValue.'" />';
}
} else {
// A og property with child-properties
$res .= $this->renderHeaderLines($this->remapArray($key, $value));
}
} else {
// A singe og property to be rendered
$res .= '<meta property="og:'.$key.'" content="'.$value.'" />';
$res[] = '<meta property="og:'.$key.'" content="'.$value.'" />';
}
}
}
return $res;
return implode(chr(10), $res);
}

/**
Expand Down
116 changes: 0 additions & 116 deletions Classes/Service/user.tx_jhopengraphprotocol.php

This file was deleted.

Loading

0 comments on commit b895ae2

Please sign in to comment.