Skip to content

Commit

Permalink
Initial commit of version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanheilmann committed Apr 12, 2015
1 parent 3fce499 commit 82da757
Show file tree
Hide file tree
Showing 48 changed files with 1,713 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please see manual.
158 changes: 158 additions & 0 deletions Classes/Service/OgRendererService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2014 Jonathan Heilmann <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* @author Jonathan Heilmann <[email protected]>
* @package TYPO3
* @subpackage tx_jhopengraphprotocol2
*/
class tx_jhopengraphprotocol_service_ogrenderer {
var $cObj;

/**
* Main-function to render the Open Grapg protocol content.
*
* @param string $content
* @param array $conf
* @return string
*/
public function main($content, $conf){
$extKey = 'tx_jhopengraphprotocol';
$content = '';
$og = array();

// 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');
if ($hookObject->singleViewDisplayed()) {
return $content;
}
}

//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'];
}

// Get type
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtype'])) {
$og['type'] = $this->cObj->data['tx_jhopengraphprotocol_ogtype'];
} else {
$og['type'] = $conf['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));
}
} else {
$fileName = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']);
$og['image'] = (!empty($fileName)) ? t3lib_div::locationHeaderUrl($fileName) : $og['image'] = '';
}

// Get url
$og['url'] = htmlentities(t3lib_div::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'];
}

// 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'];
}
}

// Get locale
$og['locale'] = $GLOBALS['TSFE']->tmpl->setup['config.']['locale_all'];

//add tags to html-header
$GLOBALS['TSFE']->additionalHeaderData[$extKey] = $this->renderHeaderLines($og);

return $content;
}

/**
* Render the header lines to be added from array
*
* @param array $array
* @return string
*/
private function renderHeaderLines($array) {
$res = '';
foreach ($array as $key => $value) {
if (!empty($value )) { // Skip empty values to prevent from empty og property
if (is_array($value)) {
// A op property with multiple values or child-properties
if(array_key_exists('0', $value)) {
// 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.'" />';
}
} 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.'" />';
}
}
}
return $res;
}

/**
* Remap an array: Add $prefixKey to keys of $array
*
* @param string $prefixKey
* @param array $array
* @return array
*/
private function remapArray($prefixKey, $array) {
$res = array();
foreach ($array as $key => $value) {
$res[$prefixKey.':'.$key] = $value;
}

return $res;
}
}
?>
108 changes: 108 additions & 0 deletions Classes/Service/user.tx_jhopengraphprotocol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012-2014 Jonathan Heilmann <[email protected]>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* @author Jonathan Heilmann <[email protected]>
* @package TYPO3
* @subpackage tx_jhopengraphprotocol
*/
class user_jhopengraphprotocol {
var $cObj;

function main($content, $conf){
$extKey = 'tx_jhopengraphprotocol';
$content = '';

// 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');
if ($hookObject->singleViewDisplayed()) {
return $content;
}
}

//if there has been no return, render output

//render title
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogtitle'])) {
$title = $this->cObj->data['tx_jhopengraphprotocol_ogtitle'];
} else {
if (!empty($conf['title'])) {
$title = $conf['title'];
} else {
$title = $GLOBALS['TSFE']->page['title'];
}
}

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

//render image
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogimage'])) {
$images = explode(',', $this->cObj->data['tx_jhopengraphprotocol_ogimage']);
$image = $GLOBALS['TSFE']->tmpl->getFileName('uploads/tx_jhopengraphprotocol/' . $images[0]);// Since version 1.0.0: only render first image
} else {
$image = $GLOBALS['TSFE']->tmpl->getFileName($conf['image']);
}

//render link
$link = htmlentities(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL')); //now compatibel with CoolURI - thanks to [email protected]

//render sitename
if (!empty($conf['sitename'])) {
$sitename = $conf['sitename'];
} else {
$sitename = $GLOBALS['TSFE']->tmpl->setup['sitetitle'];
}

//render description
if (!empty($this->cObj->data['tx_jhopengraphprotocol_ogdescription'])) {
$description = $this->cObj->data['tx_jhopengraphprotocol_ogdescription'];
} else {
//2013-12-29 http://www.shentao.de/
//use description of page if available
if (!empty($GLOBALS['TSFE']->page['description'])) {
$description = $GLOBALS['TSFE']->page['description'];
} else {
$description = $conf['description'];
}
}

//render output to html-header
if ($title != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'1'] = '<meta property="og:title" content="'.$title.'" />';}
if ($type != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'2'] = '<meta property="og:type" content="'.$type.'" />';}
if ($image != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'3'] = '<meta property="og:image" content="'.t3lib_div::locationHeaderUrl($image).'" />';}
if ($link != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'4'] = '<meta property="og:url" content="'.$link.'" />';}
if ($sitename != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'5'] = '<meta property="og:site_name" content="'.$sitename.'" />';}
if ($description != '') {$GLOBALS['TSFE']->additionalHeaderData[$extKey.'6'] = '<meta property="og:description" content="'.$description.'" />';}

return $content;
}
}
?>
12 changes: 12 additions & 0 deletions Configuration/TypoScript/constants.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

#cat=plugin.tx_jhopengraphprotocol/type/010; type=string; label=Type;
plugin.tx_jhopengraphprotocol.type = website

#cat=plugin.tx_jhopengraphprotocol/image/020; type=string; label=Image;
plugin.tx_jhopengraphprotocol.image = EXT:jh_opengraphprotocol/Resources/Public/Images/nopic.jpg

#cat=plugin.tx_jhopengraphprotocol/sitename/030; type=string; label=Sitename;
plugin.tx_jhopengraphprotocol.sitename =

#cat=plugin.tx_jhopengraphprotocol/description/040; type=string; label=Description;
plugin.tx_jhopengraphprotocol.description =
12 changes: 12 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config.htmlTag_setParams := appendString(xmlns:og="http://ogp.me/ns#")

includeLibs.tx_jhopengraphprotocol = EXT:jh_opengraphprotocol/Classes/Service/OgRendererService.php
temp.tx_jhopengraphprotocol = USER
temp.tx_jhopengraphprotocol {
userFunc = tx_jhopengraphprotocol_service_ogrenderer->main
type = {$plugin.tx_jhopengraphprotocol.type}
image = {$plugin.tx_jhopengraphprotocol.image}
sitename = {$plugin.tx_jhopengraphprotocol.sitename}
description = {$plugin.tx_jhopengraphprotocol.description}
}
page.669 < temp.tx_jhopengraphprotocol
28 changes: 28 additions & 0 deletions Documentation/ExtOpenGraphProtocol/Administration/Index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. ==================================================
.. DEFINE SOME TEXTROLES
.. --------------------------------------------------
.. role:: underline
.. role:: typoscript(code)
.. role:: ts(typoscript)
:class: typoscript
.. role:: php(code)


Administration
--------------


.. toctree::
:maxdepth: 5
:titlesonly:
:glob:

UpdatingToVersion100BreakingChanges/Index

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@


.. ==================================================
.. FOR YOUR INFORMATION
.. --------------------------------------------------
.. -*- coding: utf-8 -*- with BOM.
.. ==================================================
.. DEFINE SOME TEXTROLES
.. --------------------------------------------------
.. role:: underline
.. role:: typoscript(code)
.. role:: ts(typoscript)
:class: typoscript
.. role:: php(code)


Updating to version 1.0.0 – Breaking changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

With version 1.0.0 some changes has been done.To still provide the old
behavior, functionalities and support TYPO3 CMS 4.5 the old code is
available through the template “Open Graph protocol v0.3.0”.

If you use a TYPO3 CMS installation at version 4.5 or 4.7 nothing
changed except the included template title (now “Open Graph protocol
v0.3.0”)

If you use a TYPO3 CMS installation at version 6.0 to 6.1 you could
still use the included template “Open Graph protocol v0.3.0”, and
everything works as in past.

**Breaking changes apply to two cases:**

- You updated your TYPO3 CMS installation to version 6.2: you will need
to re-include the template “Open Graph protocol”

- You removed the included template “Open Graph protocol v0.3.0” and add
the new template “Open Graph protocol v0.3.0” in TYPO3 CMS version 6.0
to 6.1.

**In these both cases you may respect some breaking changes:**

- Constants changed from “plugin.jh\_opengraphprotocol” to
“plugin.tx\_jhopengraphprotocol”

- Constant “plugin.tx\_jhopengraphprotocol.title” has been removed.
There is no sense of a global title.

- Constants default of Open Graph property
“plugin.tx\_jhopengraphprotocol.type” has been set to “website”

- Priority of Open Graph property “title” has changed (see chapter
“Users manual” → “Operating Instructions”)

Loading

0 comments on commit 82da757

Please sign in to comment.