Prevent Search Engines from flooding the Encode Cache – using an XCLASS

The RealURL encode cache could get flooded with the URLs that are used by search engines like Google, Solr etc… If we know the exact parameter they use, we can prevent the flooding using this simple function given below

1.) Add this code to the file “Realurl.php” in the “Sconfig\Xclass” folder. Here “Sconfig” – is the name of our extension. “Xclass – folder may need to be created if not present”

CODE START
########################

<?php

namespace Scwebs\Sconfig\Xclass;

class Realurl extends \tx_realurl {
public function encodeSpURL(&$params) {
parent::encodeSpURL($params);
}

protected function encodeSpURL_encodeCache($urlData, $internalExtras, $setEncodedURL = ”) {
// \TYPO3\CMS\Core\Utility\GeneralUtility::devLog(‘Inside the hook now!’, ‘realurl’, 1, array($urlData));
if( isset($_GET[‘gclid’]) ){
$this->devLog(‘gclid detected. Not doing anything!’);
return ”;
}
parent::encodeSpURL_encodeCache($urlData, $internalExtras, $setEncodedURL);
}
}

########################
CODE END

2. Our Xclass needs to be registered, this can be done in the “Sconfig/ext_localconf.php” using the code below:

$GLOBALS[‘TYPO3_CONF_VARS’][‘SYS’][‘Objects’][‘tx_realurl’] = array(
‘className’ => Scwebs\\Sconfig\\Xclass\\Realurl’
);

Store a picture in FAL, and retrieve file name using standard sql statement

Scenario: store a picture in FAL, and retrieve file name using standard sql statement
A) TCA declaration is as follows:
‘news_picture’ => array(
‘exclude’ => 0,
‘label’ => ‘LLL:EXT:mynews/Resources/Private/Language/Database.xlf:tx_mynews.news_picture’,
‘config’ => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
‘news_picture’,
array(
‘appearance’ => array(
‘collapseAll’ => TRUE
),
‘maxitems’ => 1,
)
)
),
B) An SQL example:
SELECT * FROM (
SELECT 
tx_mynews.uid as news_uid,
tx_mynews.news_title,
tx_mynews.news_subtitle,
`sys_file`.name AS filename,
`sys_file`.uid AS fileuid,
`sys_file`.identifier
FROM `tx_mynews` 
LEFT JOIN `sys_file_reference` ON 
`tx_mynews`.`uid` = `sys_file_reference`.`uid_foreign`
AND 
 `sys_file_reference`.`tablenames` = ‘tx_mynews’ 
 AND 
 `sys_file_reference`.`fieldname` = ‘news_picture’
 AND 
 `sys_file_reference`.`table_local` = ‘sys_file’ AND
 `sys_file_reference`.`deleted` = 0
LEFT JOIN `sys_file` 
ON
`sys_file_reference`.`uid_local` = `sys_file`.`uid`)
AS docs where docs.filename <> ”
ORDER BY news_title
LIMIT 100

This snippet informs how to add or allow custom tags in RTE

PAGE TS CONFIG AS FOLLOWS:

# Allow embed, parm, object and iframe tags, also see RTE parser code added in config.ts
RTE.default.proc {
allowTags := addToList(object,param,embed,iframe)
allowTagsOutside := addToList(object,embed,iframe)
entryHTMLparser_db.allowTags < RTE.default.proc.allowTags
}

TYPOSCRIPT SETUP SHOULD BE AS FOLLOWS

# Allow embed, parm, object and iframe tags, also see RTE setup added in rte.ts
lib.parseFunc_RTE.allowTags := addToList(object,param,embed,iframe)

Open Graph Tags example for use with Facebook

page.headerData.120 = COA
page.headerData.120 {
10 = TEXT
10 {
typolink.parameter.data = TSFE:id
typolink.forceAbsoluteUrl = 1
typolink.returnLast = url
typolink.additionalParams.cObject = COA
typolink.additionalParams.cObject {
10 = TEXT
10.dataWrap = &tx_ttnews[tt_news]={GP:tx_ttnews|tt_news}
10.if.isTrue.data = GP:tx_ttnews|tt_news
20 = TEXT
20.dataWrap = &tx_ttnews[cat]={GP:tx_ttnews|cat}
20.if.isTrue.data = GP:tx_ttnews|cat
}
wrap = <meta property=”og:url” content=”|”/>
}
20 < page.headerData.1
20 {
wrap = <meta property=”og:title” content=”| {$siteTitle}”/>
}

30 = TEXT
30.value =
30.wrap = <meta property=”og:site_name” content=”|{$siteTitle}”/>

40 = TEXT
40.value = <meta property=”og:description” content=”” />
40.wrap = <meta property=”og:type” content=”website” />|

}

In additions to the above, we can also set the og:image property on a news detail page like given below:
This new updated Code also includes a default image when news has no image.

page.headerData.120.50 = COA
page.headerData.120.50 {
20 = CONTENT
20 {
table = tt_news
select {
pidInList = 18
andWhere = uid={GP:tx_ttnews|tt_news}
andWhere.insertData =1
selectFields = uid,pid,image
}
renderObj = COA
renderObj {
10 = TEXT
10.value =<meta property=”og:image” content=”http://www.mydomain.com/uploads/pics/
20 = TEXT
20 {
field = image
split {
token = ,
max = 1
cObjNum = 1
1.current = 1
}
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value = alt-image.jpg
}

}
30 = TEXT
30.value = ” />
}
}
}

Typoscript snippet for getting parent title, based on selected Templavoila Template Object

 

5 = TEXT
5 {
#first check with tx_templavoila_to
ifEmpty.cObject = TEXT
ifEmpty.cObject {
data = leveltitle:-2
stdWrap.case = upper
if {
value = 34
isInList.data = levelfield:-1, tx_templavoila_to, slide
}
}
#then check with tx_templavoila_next_to
ifEmpty.ifEmpty.cObject < .ifEmpty.cObject
ifEmpty.ifEmpty.cObject = TEXT
ifEmpty.ifEmpty.cObject.if.isInList.data = levelfield:-1, tx_templavoila_next_to, slide

noTrimWrap = || – |
}