Initial commit
This commit is contained in:
79
typo3conf/ext/metaseo/Classes/Utility/BackendUtility.php
Normal file
79
typo3conf/ext/metaseo/Classes/Utility/BackendUtility.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
/**
|
||||
* Backend utility
|
||||
*/
|
||||
class BackendUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Fetch list of root pages (is_siteroot) in TYPO3 (cached)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRootPageList()
|
||||
{
|
||||
static $cache = null;
|
||||
|
||||
if ($cache === null) {
|
||||
$query = 'SELECT uid,
|
||||
pid,
|
||||
title
|
||||
FROM pages
|
||||
WHERE is_siteroot = 1
|
||||
AND deleted = 0';
|
||||
$cache = DatabaseUtility::getAllWithIndex($query, 'uid');
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch list of setting entries
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRootPageSettingList()
|
||||
{
|
||||
static $cache = null;
|
||||
|
||||
if ($cache === null) {
|
||||
$query = 'SELECT seosr.*
|
||||
FROM tx_metaseo_setting_root seosr
|
||||
INNER JOIN pages p
|
||||
ON p.uid = seosr.pid
|
||||
AND p.is_siteroot = 1
|
||||
AND p.deleted = 0
|
||||
WHERE seosr.deleted = 0';
|
||||
$cache = DatabaseUtility::getAllWithIndex($query, 'pid');
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
122
typo3conf/ext/metaseo/Classes/Utility/ConsoleUtility.php
Normal file
122
typo3conf/ext/metaseo/Classes/Utility/ConsoleUtility.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
/**
|
||||
* Console utility
|
||||
*/
|
||||
class ConsoleUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Write output (without forcing newline)
|
||||
*
|
||||
* @param string $message Message text
|
||||
* @param integer $padding Pad message
|
||||
*/
|
||||
public static function write($message = null, $padding = null)
|
||||
{
|
||||
if ($padding > 0) {
|
||||
$message = str_pad($message, $padding, ' ');
|
||||
}
|
||||
|
||||
self::stdOut($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output to STD_OUT
|
||||
*
|
||||
* @param string $message Message text
|
||||
*/
|
||||
public static function stdOut($message = null)
|
||||
{
|
||||
if (defined('TYPO3_cliMode')) {
|
||||
file_put_contents('php://stdout', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write output (forcing newline)
|
||||
*
|
||||
* @param string $message Message text
|
||||
*/
|
||||
public static function writeLine($message = null)
|
||||
{
|
||||
self::stdOut($message . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write error (without forcing newline)
|
||||
*
|
||||
* @param string $message Message text
|
||||
* @param integer $padding Pad message
|
||||
*/
|
||||
public static function writeError($message = null, $padding = null)
|
||||
{
|
||||
if ($padding > 0) {
|
||||
$message = str_pad($message, $padding, ' ');
|
||||
}
|
||||
|
||||
self::stdError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send output to STD_ERR
|
||||
*
|
||||
* @param string $message Message text
|
||||
*/
|
||||
public static function stdError($message = null)
|
||||
{
|
||||
if (defined('TYPO3_cliMode')) {
|
||||
file_put_contents('php://stderr', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write error (forcing newline)
|
||||
*
|
||||
* @param string $message Message
|
||||
*/
|
||||
public static function writeErrorLine($message = null)
|
||||
{
|
||||
$message .= "\n";
|
||||
|
||||
self::stdError($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit cli script with return code
|
||||
*
|
||||
* @param integer $exitCode Exit code (0 = success)
|
||||
*/
|
||||
public static function terminate($exitCode)
|
||||
{
|
||||
if (defined('TYPO3_cliMode')) {
|
||||
exit($exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
456
typo3conf/ext/metaseo/Classes/Utility/DatabaseUtility.php
Normal file
456
typo3conf/ext/metaseo/Classes/Utility/DatabaseUtility.php
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
/**
|
||||
* Database utility
|
||||
*/
|
||||
class DatabaseUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* relation we know of that it exists and which we can use for database vendor determination
|
||||
*/
|
||||
const TYPO3_DEFAULT_TABLE = 'pages';
|
||||
|
||||
###########################################################################
|
||||
# Query functions
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Get row
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRow($query)
|
||||
{
|
||||
$ret = null;
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
if ($row = self::connection()->sql_fetch_assoc($res)) {
|
||||
$ret = $row;
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute sql query
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return \mysqli_result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function query($query)
|
||||
{
|
||||
$res = self::connection()->sql_query($query);
|
||||
|
||||
if (!$res || self::connection()->sql_errno()) {
|
||||
// SQL statement failed
|
||||
$errorMsg = sprintf(
|
||||
'SQL Error: %s [errno: %s]',
|
||||
self::connection()->sql_error(),
|
||||
self::connection()->sql_errno()
|
||||
);
|
||||
|
||||
if (defined('TYPO3_cliMode')) {
|
||||
throw new \Exception($errorMsg);
|
||||
} else {
|
||||
debug('SQL-QUERY: ' . $query, $errorMsg, __LINE__, __FILE__);
|
||||
}
|
||||
|
||||
$res = null;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current database connection
|
||||
*
|
||||
* @return \TYPO3\CMS\Core\Database\DatabaseConnection
|
||||
*/
|
||||
public static function connection()
|
||||
{
|
||||
return $GLOBALS['TYPO3_DB'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Free sql result
|
||||
*
|
||||
* @param boolean|\mysqli_result|object $res SQL result
|
||||
*/
|
||||
public static function free($res)
|
||||
{
|
||||
if ($res && $res !== true) {
|
||||
self::connection()->sql_free_result($res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll($query)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
while ($row = self::connection()->sql_fetch_assoc($res)) {
|
||||
$ret[] = $row;
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All with index (first value)
|
||||
*
|
||||
* @param string $query SQL query
|
||||
* @param string $indexCol Index column name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllWithIndex($query, $indexCol = null)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
while ($row = self::connection()->sql_fetch_assoc($res)) {
|
||||
if ($indexCol === null) {
|
||||
// use first key as index
|
||||
$index = reset($row);
|
||||
} else {
|
||||
$index = $row[$indexCol];
|
||||
}
|
||||
|
||||
$ret[$index] = $row;
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get List
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getList($query)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
while ($row = self::connection()->sql_fetch_row($res)) {
|
||||
$ret[$row[0]] = $row[1];
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCol($query)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
while ($row = self::connection()->sql_fetch_row($res)) {
|
||||
$ret[] = $row[0];
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getColWithIndex($query)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
while ($row = self::connection()->sql_fetch_row($res)) {
|
||||
$ret[$row[0]] = $row[0];
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count (from query)
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getCount($query)
|
||||
{
|
||||
$query = 'SELECT COUNT(*) FROM (' . $query . ') tmp';
|
||||
|
||||
return self::getOne($query);
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
# Quote functions
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Get one
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOne($query)
|
||||
{
|
||||
$ret = null;
|
||||
|
||||
$res = self::query($query);
|
||||
if ($res) {
|
||||
if ($row = self::connection()->sql_fetch_assoc($res)) {
|
||||
$ret = reset($row);
|
||||
}
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec query (INSERT)
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return integer Last insert id
|
||||
*/
|
||||
public static function execInsert($query)
|
||||
{
|
||||
$ret = false;
|
||||
|
||||
$res = self::query($query);
|
||||
|
||||
if ($res) {
|
||||
$ret = self::connection()->sql_insert_id();
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec query (DELETE, UPDATE etc)
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return integer Affected rows
|
||||
*/
|
||||
public static function exec($query)
|
||||
{
|
||||
$ret = false;
|
||||
|
||||
$res = self::query($query);
|
||||
|
||||
if ($res) {
|
||||
$ret = self::connection()->sql_affected_rows();
|
||||
self::free($res);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
# Helper functions
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Add condition to query
|
||||
*
|
||||
* @param array|string $condition Condition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function addCondition($condition)
|
||||
{
|
||||
$ret = ' ';
|
||||
|
||||
if (!empty($condition)) {
|
||||
if (is_array($condition)) {
|
||||
$ret .= ' AND (( ' . implode(" )\nAND (", $condition) . ' ))';
|
||||
} else {
|
||||
$ret .= ' AND ( ' . $condition . ' )';
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create condition 'field IN (1,2,3,4)'
|
||||
*
|
||||
* @param string $field SQL field
|
||||
* @param array $values Values
|
||||
* @param boolean $required Required
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function conditionIn($field, array $values, $required = true)
|
||||
{
|
||||
return self::buildConditionIn($field, $values, $required, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create condition 'field NOT IN (1,2,3,4)'
|
||||
*
|
||||
* @param string $field SQL field
|
||||
* @param array $values Values
|
||||
* @param boolean $required Required
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function conditionNotIn($field, array $values, $required = true)
|
||||
{
|
||||
return self::buildConditionIn($field, $values, $required, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create condition 'field [NOT] IN (1,2,3,4)'
|
||||
*
|
||||
* @param string $field SQL field
|
||||
* @param array $values Values
|
||||
* @param boolean $required Required
|
||||
* @param boolean $negate use true for a NOT IN clause, use false for an IN clause (default)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function buildConditionIn($field, array $values, $required = true, $negate = false)
|
||||
{
|
||||
if (empty($values)) {
|
||||
return $required ? '1=0' : '1=1';
|
||||
}
|
||||
|
||||
$not = $negate ? ' NOT' : '';
|
||||
$quotedValues = self::quoteArray($values);
|
||||
|
||||
return $field . $not . ' IN (' . implode(',', $quotedValues) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote array with values
|
||||
*
|
||||
* @param array $valueList Values
|
||||
* @param string $table Table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function quoteArray(array $valueList, $table = null)
|
||||
{
|
||||
$ret = array();
|
||||
foreach ($valueList as $k => $v) {
|
||||
$ret[$k] = self::quote($v, $table);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
# SQL wrapper functions
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Quote value
|
||||
*
|
||||
* @param string $value Value
|
||||
* @param string $table Table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function quote($value, $table = null)
|
||||
{
|
||||
if ($table === null) {
|
||||
$table = self::TYPO3_DEFAULT_TABLE;
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
return self::connection()->fullQuoteStr($value, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build condition
|
||||
*
|
||||
* @param array $where Where condition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function buildCondition(array $where)
|
||||
{
|
||||
$ret = ' ';
|
||||
|
||||
if (!empty($where)) {
|
||||
$ret = ' ( ' . implode(' ) AND ( ', $where) . ' ) ';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
use ReflectionMethod;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility as Typo3ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility as Typo3GeneralUtility;
|
||||
|
||||
class ExtensionManagementUtility
|
||||
{
|
||||
const AJAX_METHOD_NAME_SUFFIX = 'Action';
|
||||
const AJAX_METHOD_DELIMITER = '::';
|
||||
|
||||
/**
|
||||
* Registers all public methods of a specified class with method name suffix 'Action' as ajax actions
|
||||
* The ajax method names have the form <ajaxPrefix>::<ajaxMethod> (with 'Action' removed from the method)
|
||||
* or <ajaxMethod> for empty/unspecified <ajaxPrefix>
|
||||
*
|
||||
* @param string $qualifiedClassName
|
||||
* @param string $ajaxPrefix
|
||||
*/
|
||||
public static function registerAjaxClass($qualifiedClassName, $ajaxPrefix = '')
|
||||
{
|
||||
if (!empty($ajaxPrefix)) {
|
||||
$ajaxPrefix = $ajaxPrefix . self::AJAX_METHOD_DELIMITER;
|
||||
}
|
||||
self::removeBeginningBackslash($qualifiedClassName);
|
||||
$reflectionClass = self::getReflectionClass($qualifiedClassName);
|
||||
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||
foreach ($methods as $method) {
|
||||
$methodName = $method->getName();
|
||||
if (self::isAjaxMethod($methodName)) {
|
||||
$ajaxMethodName = self::extractAjaxMethod($methodName);
|
||||
Typo3ExtensionManagementUtility::registerAjaxHandler(
|
||||
$ajaxPrefix . $ajaxMethodName,
|
||||
$qualifiedClassName . '->' . $methodName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $qualifiedClassNames
|
||||
*/
|
||||
public static function registerAjaxClasses(array $qualifiedClassNames)
|
||||
{
|
||||
foreach ($qualifiedClassNames as $ajaxPrefix => $qualifiedClassName) {
|
||||
self::registerAjaxClass($qualifiedClassName, $ajaxPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isAjaxMethod($methodName)
|
||||
{
|
||||
$suffixLength = strlen(self::AJAX_METHOD_NAME_SUFFIX);
|
||||
|
||||
return strlen($methodName) > $suffixLength
|
||||
&& self::AJAX_METHOD_NAME_SUFFIX === substr($methodName, -1 * $suffixLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function extractAjaxMethod($methodName)
|
||||
{
|
||||
$suffixLength = strlen(self::AJAX_METHOD_NAME_SUFFIX);
|
||||
|
||||
return substr(
|
||||
$methodName,
|
||||
0,
|
||||
strlen($methodName) - $suffixLength
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $qualifiedClassName
|
||||
*/
|
||||
protected static function removeBeginningBackslash(&$qualifiedClassName)
|
||||
{
|
||||
if ($qualifiedClassName[0] === '\\') {
|
||||
$qualifiedClassName = substr($qualifiedClassName, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $qualifiedClassName
|
||||
*
|
||||
* @return \ReflectionClass
|
||||
*/
|
||||
protected static function getReflectionClass($qualifiedClassName)
|
||||
{
|
||||
return Typo3GeneralUtility::makeInstance('ReflectionClass', $qualifiedClassName);
|
||||
}
|
||||
}
|
||||
212
typo3conf/ext/metaseo/Classes/Utility/FrontendUtility.php
Normal file
212
typo3conf/ext/metaseo/Classes/Utility/FrontendUtility.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility as Typo3GeneralUtility;
|
||||
|
||||
/**
|
||||
* General utility
|
||||
*/
|
||||
class FrontendUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Init TSFE with all needed classes eg. for backend usage ($GLOBALS['TSFE'])
|
||||
*
|
||||
* @param integer $pageUid PageUID
|
||||
* @param null|array $rootLine Rootline
|
||||
* @param null|array $pageData Page data array
|
||||
* @param null|array $rootlineFull Full rootline
|
||||
* @param null|integer $sysLanguage Sys language uid
|
||||
*/
|
||||
public static function init(
|
||||
$pageUid,
|
||||
$rootLine = null,
|
||||
$pageData = null,
|
||||
$rootlineFull = null,
|
||||
$sysLanguage = null
|
||||
) {
|
||||
static $cacheTSFE = array();
|
||||
static $lastTsSetupPid = null;
|
||||
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = Typo3GeneralUtility::makeInstance(
|
||||
'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
|
||||
);
|
||||
|
||||
// Fetch page if needed
|
||||
if ($pageData === null) {
|
||||
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPageObj */
|
||||
$sysPageObj = $objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
|
||||
$sysPageObj->sys_language_uid = $sysLanguage;
|
||||
|
||||
$pageData = $sysPageObj->getPage_noCheck($pageUid);
|
||||
}
|
||||
|
||||
// create time tracker if needed
|
||||
if (empty($GLOBALS['TT'])) {
|
||||
/** @var \TYPO3\CMS\Core\TimeTracker\NullTimeTracker $timeTracker */
|
||||
$timeTracker = $objectManager->get('TYPO3\\CMS\\Core\\TimeTracker\\NullTimeTracker');
|
||||
|
||||
$GLOBALS['TT'] = $timeTracker;
|
||||
$GLOBALS['TT']->start();
|
||||
}
|
||||
|
||||
if ($rootLine === null) {
|
||||
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPageObj */
|
||||
$sysPageObj = $objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
|
||||
$sysPageObj->sys_language_uid = $sysLanguage;
|
||||
$rootLine = $sysPageObj->getRootLine($pageUid);
|
||||
|
||||
// save full rootline, we need it in TSFE
|
||||
$rootlineFull = $rootLine;
|
||||
}
|
||||
|
||||
// Only setup tsfe if current instance must be changed
|
||||
if ($lastTsSetupPid !== $pageUid) {
|
||||
// Cache TSFE if possible to prevent reinit (is still slow but we need the TSFE)
|
||||
if (empty($cacheTSFE[$pageUid])) {
|
||||
/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfeController */
|
||||
$tsfeController = $objectManager->get(
|
||||
'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
|
||||
$GLOBALS['TYPO3_CONF_VARS'],
|
||||
$pageUid,
|
||||
0
|
||||
);
|
||||
$tsfeController->sys_language_uid = $sysLanguage;
|
||||
|
||||
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObjRenderer */
|
||||
$cObjRenderer = $objectManager->get('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
|
||||
|
||||
/** @var \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService $TSObj */
|
||||
$TSObj = $objectManager->get('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
|
||||
|
||||
$TSObj->tt_track = 0;
|
||||
$TSObj->init();
|
||||
$TSObj->runThroughTemplates($rootLine);
|
||||
$TSObj->generateConfig();
|
||||
|
||||
$_GET['id'] = $pageUid;
|
||||
|
||||
// Init TSFE
|
||||
$GLOBALS['TSFE'] = $tsfeController;
|
||||
$GLOBALS['TSFE']->cObj = $cObjRenderer;
|
||||
$GLOBALS['TSFE']->initFEuser();
|
||||
$GLOBALS['TSFE']->determineId();
|
||||
|
||||
if (empty($GLOBALS['TSFE']->tmpl)) {
|
||||
$GLOBALS['TSFE']->tmpl = new \stdClass();
|
||||
}
|
||||
|
||||
$GLOBALS['TSFE']->tmpl->setup = $TSObj->setup;
|
||||
$GLOBALS['TSFE']->initTemplate();
|
||||
$GLOBALS['TSFE']->getConfigArray();
|
||||
|
||||
$GLOBALS['TSFE']->baseUrl = $GLOBALS['TSFE']->config['config']['baseURL'];
|
||||
|
||||
$cacheTSFE[$pageUid] = $GLOBALS['TSFE'];
|
||||
}
|
||||
|
||||
$GLOBALS['TSFE'] = $cacheTSFE[$pageUid];
|
||||
|
||||
$lastTsSetupPid = $pageUid;
|
||||
}
|
||||
|
||||
$GLOBALS['TSFE']->page = $pageData;
|
||||
$GLOBALS['TSFE']->rootLine = $rootlineFull;
|
||||
$GLOBALS['TSFE']->cObj->data = $pageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check current page for blacklisting
|
||||
*
|
||||
* @param array $blacklist Blacklist configuration
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkPageForBlacklist(array $blacklist)
|
||||
{
|
||||
return GeneralUtility::checkUrlForBlacklisting(self::getCurrentUrl(), $blacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if frontend page is cacheable
|
||||
*
|
||||
* @param array|null $conf Configuration
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCacheable($conf = null)
|
||||
{
|
||||
$TSFE = self::getTsfe();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET' || !empty($TSFE->fe_user->user['uid'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// don't parse if page is not cacheable
|
||||
if (empty($conf['allowNoStaticCachable']) && !$TSFE->isStaticCacheble()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip no_cache-pages
|
||||
if (empty($conf['allowNoCache']) && !empty($TSFE->no_cache)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current URL
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function getCurrentUrl()
|
||||
{
|
||||
$ret = null;
|
||||
|
||||
$TSFE = self::getTsfe();
|
||||
|
||||
if (!empty($TSFE->anchorPrefix)) {
|
||||
$ret = (string)$TSFE->anchorPrefix;
|
||||
} else {
|
||||
$ret = (string)$TSFE->siteScript;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TSFE
|
||||
*
|
||||
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
|
||||
*/
|
||||
public static function getTsfe()
|
||||
{
|
||||
return $GLOBALS['TSFE'];
|
||||
}
|
||||
}
|
||||
463
typo3conf/ext/metaseo/Classes/Utility/GeneralUtility.php
Normal file
463
typo3conf/ext/metaseo/Classes/Utility/GeneralUtility.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
/**
|
||||
* General utility
|
||||
*/
|
||||
class GeneralUtility
|
||||
{
|
||||
|
||||
// ########################################################################
|
||||
// Attributes
|
||||
// ########################################################################
|
||||
|
||||
/**
|
||||
* Page Select
|
||||
*
|
||||
* @var \TYPO3\CMS\Frontend\Page\PageRepository
|
||||
*/
|
||||
protected static $sysPageObj;
|
||||
|
||||
/**
|
||||
* Rootline cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $rootlineCache = array();
|
||||
|
||||
|
||||
// ########################################################################
|
||||
// Public methods
|
||||
// ########################################################################
|
||||
|
||||
/**
|
||||
* Get current language id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getLanguageId()
|
||||
{
|
||||
$ret = 0;
|
||||
|
||||
if (!empty($GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'])) {
|
||||
$ret = (int)$GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current pid
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getCurrentPid()
|
||||
{
|
||||
return $GLOBALS['TSFE']->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is any mountpoint in rootline
|
||||
*
|
||||
* @param integer|null $uid Page UID
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isMountpointInRootLine($uid = null)
|
||||
{
|
||||
$ret = false;
|
||||
|
||||
// Performance check, there must be an MP-GET value
|
||||
if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('MP')) {
|
||||
// Possible mount point detected, let's check the rootline
|
||||
foreach (self::getRootLine($uid) as $page) {
|
||||
if (!empty($page['_MOUNT_OL'])) {
|
||||
// Mountpoint detected in rootline
|
||||
$ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current root line
|
||||
*
|
||||
* @param integer|null $uid Page UID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRootLine($uid = null)
|
||||
{
|
||||
if ($uid === null) {
|
||||
#################
|
||||
# Current rootline
|
||||
#################
|
||||
if (empty(self::$rootlineCache['__CURRENT__'])) {
|
||||
// Current rootline
|
||||
$rootline = $GLOBALS['TSFE']->tmpl->rootLine;
|
||||
|
||||
// Filter rootline by siteroot
|
||||
$rootline = self::filterRootlineBySiteroot((array)$rootline);
|
||||
|
||||
self::$rootlineCache['__CURRENT__'] = $rootline;
|
||||
}
|
||||
|
||||
$ret = self::$rootlineCache['__CURRENT__'];
|
||||
} else {
|
||||
#################
|
||||
# Other rootline
|
||||
#################
|
||||
if (empty(self::$rootlineCache[$uid])) {
|
||||
// Fetch full rootline to TYPO3 root (0)
|
||||
$rootline = self::getSysPageObj()->getRootLine($uid);
|
||||
|
||||
// Filter rootline by siteroot
|
||||
$rootline = self::filterRootlineBySiteroot((array)$rootline);
|
||||
|
||||
self::$rootlineCache[$uid] = $rootline;
|
||||
}
|
||||
|
||||
$ret = self::$rootlineCache[$uid];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter rootline to get the real one up to siteroot page
|
||||
*
|
||||
* @param $rootline
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function filterRootlineBySiteroot(array $rootline)
|
||||
{
|
||||
$ret = array();
|
||||
|
||||
// Make sure sorting is right (first root, last page)
|
||||
ksort($rootline, SORT_NUMERIC);
|
||||
|
||||
//reverse rootline
|
||||
$rootline = array_reverse($rootline);
|
||||
|
||||
foreach ($rootline as $page) {
|
||||
$ret[] = $page;
|
||||
if (!empty($page['is_siteroot'])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$ret = array_reverse($ret);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sys page object
|
||||
*
|
||||
* @return \TYPO3\CMS\Frontend\Page\PageRepository
|
||||
*/
|
||||
protected static function getSysPageObj()
|
||||
{
|
||||
if (self::$sysPageObj === null) {
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
|
||||
'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
|
||||
);
|
||||
|
||||
/** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPageObj */
|
||||
$sysPageObj = $objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
|
||||
|
||||
self::$sysPageObj = $sysPageObj;
|
||||
}
|
||||
|
||||
return self::$sysPageObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get domain
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSysDomain()
|
||||
{
|
||||
static $ret = null;
|
||||
|
||||
if ($ret !== null) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$host = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
|
||||
$rootPid = self::getRootPid();
|
||||
|
||||
$query = 'SELECT *
|
||||
FROM sys_domain
|
||||
WHERE pid = ' . (int)$rootPid . '
|
||||
AND domainName = ' . DatabaseUtility::quote($host, 'sys_domain') . '
|
||||
AND hidden = 0';
|
||||
$ret = DatabaseUtility::getRow($query);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current root pid
|
||||
*
|
||||
* @param integer|null $uid Page UID
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getRootPid($uid = null)
|
||||
{
|
||||
static $cache = array();
|
||||
$ret = null;
|
||||
|
||||
if ($uid === null) {
|
||||
#################
|
||||
# Current root PID
|
||||
#################
|
||||
$rootline = self::getRootLine();
|
||||
if (!empty($rootline[0])) {
|
||||
$ret = $rootline[0]['uid'];
|
||||
}
|
||||
} else {
|
||||
#################
|
||||
# Other root PID
|
||||
#################
|
||||
if (!isset($cache[$uid])) {
|
||||
$cache[$uid] = null;
|
||||
$rootline = self::getRootLine($uid);
|
||||
|
||||
if (!empty($rootline[0])) {
|
||||
$cache[$uid] = $rootline[0]['uid'];
|
||||
}
|
||||
}
|
||||
|
||||
$ret = $cache[$uid];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get root setting value
|
||||
*
|
||||
* @param string $name Name of configuration
|
||||
* @param mixed|NULL $defaultValue Default value
|
||||
* @param integer|NULL $rootPid Root Page Id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRootSettingValue($name, $defaultValue = null, $rootPid = null)
|
||||
{
|
||||
$setting = self::getRootSetting($rootPid);
|
||||
|
||||
if (isset($setting[$name])) {
|
||||
$ret = $setting[$name];
|
||||
} else {
|
||||
$ret = $defaultValue;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get root setting row
|
||||
*
|
||||
* @param integer $rootPid Root Page Id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRootSetting($rootPid = null)
|
||||
{
|
||||
static $ret = null;
|
||||
|
||||
if ($ret !== null) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if ($rootPid === null) {
|
||||
$rootPid = self::getRootPid();
|
||||
}
|
||||
|
||||
$query = 'SELECT *
|
||||
FROM tx_metaseo_setting_root
|
||||
WHERE pid = ' . (int)$rootPid . '
|
||||
AND deleted = 0
|
||||
LIMIT 1';
|
||||
$ret = DatabaseUtility::getRow($query);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension configuration
|
||||
*
|
||||
* @param string $name Name of config
|
||||
* @param boolean $default Default value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getExtConf($name, $default = null)
|
||||
{
|
||||
static $conf = null;
|
||||
$ret = $default;
|
||||
|
||||
if ($conf === null) {
|
||||
// Load ext conf
|
||||
$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['metaseo']);
|
||||
if (!is_array($conf)) {
|
||||
$conf = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($conf[$name])) {
|
||||
$ret = $conf[$name];
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call hook and signal
|
||||
*
|
||||
* @param string $class Name of the class containing the signal
|
||||
* @param string $name Name of hook
|
||||
* @param mixed $obj Reference to be passed along (typically "$this"
|
||||
* - being a reference to the calling object) (REFERENCE!)
|
||||
* @param mixed|NULL $args Args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function callHookAndSignal($class, $name, $obj, &$args = null)
|
||||
{
|
||||
static $hookConf = null;
|
||||
static $signalSlotDispatcher = null;
|
||||
|
||||
// Fetch hooks config for metaseo, minimize array lookups
|
||||
if ($hookConf === null) {
|
||||
$hookConf = array();
|
||||
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['metaseo']['hooks'])
|
||||
&& is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['metaseo']['hooks'])
|
||||
) {
|
||||
$hookConf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['metaseo']['hooks'];
|
||||
}
|
||||
}
|
||||
|
||||
// Call hooks
|
||||
if (!empty($hookConf[$name]) && is_array($hookConf[$name])) {
|
||||
foreach ($hookConf[$name] as $_funcRef) {
|
||||
if ($_funcRef) {
|
||||
\TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $args, $obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call signal
|
||||
if ($signalSlotDispatcher === null) {
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
|
||||
'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'
|
||||
);
|
||||
|
||||
/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
|
||||
$signalSlotDispatcher = $objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
|
||||
}
|
||||
$signalSlotDispatcher->dispatch($class, $name, array($args, $obj));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate full url
|
||||
*
|
||||
* Makes sure the url is absolute (http://....)
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param string $domain Domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function fullUrl($url, $domain = null)
|
||||
{
|
||||
if (!preg_match('/^https?:\/\//i', $url)) {
|
||||
// Fix for root page link
|
||||
if ($url === '/') {
|
||||
$url = '';
|
||||
}
|
||||
|
||||
// remove first /
|
||||
if (strpos($url, '/') === 0) {
|
||||
$url = substr($url, 1);
|
||||
}
|
||||
|
||||
if ($domain !== null) {
|
||||
// specified domain
|
||||
$url = 'http://' . $domain . '/' . $url;
|
||||
} else {
|
||||
// domain from env
|
||||
$url = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $url;
|
||||
}
|
||||
}
|
||||
|
||||
// Fix url stuff
|
||||
$url = str_replace('?&', '?', $url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
// ########################################################################
|
||||
// Protected methods
|
||||
// ########################################################################
|
||||
|
||||
/**
|
||||
* Check if url is blacklisted
|
||||
*
|
||||
* @param string $url URL
|
||||
* @param array $blacklistConf Blacklist configuration (list of regexp)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkUrlForBlacklisting($url, array $blacklistConf)
|
||||
{
|
||||
// check for valid url
|
||||
if (empty($url)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$blacklistConf = (array)$blacklistConf;
|
||||
foreach ($blacklistConf as $blacklistRegExp) {
|
||||
if (preg_match($blacklistRegExp, $url)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
126
typo3conf/ext/metaseo/Classes/Utility/RootPageUtility.php
Normal file
126
typo3conf/ext/metaseo/Classes/Utility/RootPageUtility.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility as Typo3GeneralUtility;
|
||||
|
||||
/**
|
||||
* Root page utility
|
||||
*/
|
||||
class RootPageUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Domain cache
|
||||
*
|
||||
* array(
|
||||
* rootPid => domainName
|
||||
* );
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $domainCache = array();
|
||||
|
||||
/**
|
||||
* Get sitemap index url
|
||||
*
|
||||
* @param integer $rootPid Root PID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSitemapIndexUrl($rootPid)
|
||||
{
|
||||
return self::getFrontendUrl($rootPid, SitemapUtility::PAGE_TYPE_SITEMAP_XML);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a frontend url
|
||||
*
|
||||
* @param integer $rootPid Root Page ID
|
||||
* @param integer $typeNum Type num
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFrontendUrl($rootPid, $typeNum)
|
||||
{
|
||||
$domain = self::getDomain($rootPid);
|
||||
if (!empty($domain)) {
|
||||
$domain = 'http://' . $domain . '/';
|
||||
} else {
|
||||
$domain = Typo3GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
|
||||
}
|
||||
// "build", TODO: use typolink to use TYPO3 internals
|
||||
$url = $domain . 'index.php?id=' . (int)$rootPid . '&type=' . (int)$typeNum;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get domain
|
||||
*
|
||||
* @param integer $rootPid Root PID
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function getDomain($rootPid)
|
||||
{
|
||||
// Use cached one if exists
|
||||
if (isset(self::$domainCache[$rootPid])) {
|
||||
return self::$domainCache[$rootPid];
|
||||
}
|
||||
|
||||
// Fetch domain name
|
||||
$query = 'SELECT domainName
|
||||
FROM sys_domain
|
||||
WHERE pid = ' . (int)$rootPid . '
|
||||
AND hidden = 0
|
||||
ORDER BY forced DESC,
|
||||
sorting
|
||||
LIMIT 1';
|
||||
$ret = DatabaseUtility::getOne($query);
|
||||
|
||||
// Remove possible slash at the end
|
||||
$ret = rtrim($ret, '/');
|
||||
|
||||
// Cache entry
|
||||
self::$domainCache[$rootPid] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get robots.txt url
|
||||
*
|
||||
* @param integer $rootPid Root PID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getRobotsTxtUrl($rootPid)
|
||||
{
|
||||
return self::getFrontendUrl($rootPid, SitemapUtility::PAGE_TYPE_ROBOTS_TXT);
|
||||
}
|
||||
}
|
||||
298
typo3conf/ext/metaseo/Classes/Utility/SitemapUtility.php
Normal file
298
typo3conf/ext/metaseo/Classes/Utility/SitemapUtility.php
Normal file
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* (c) 2013 Markus Blaschke (TEQneers GmbH & Co. KG) <blaschke@teqneers.de> (tq_seo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility as Typo3GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Page\PageRepository;
|
||||
|
||||
/**
|
||||
* Sitemap utility
|
||||
*/
|
||||
class SitemapUtility
|
||||
{
|
||||
|
||||
const SITEMAP_TYPE_PAGE = 0;
|
||||
const SITEMAP_TYPE_FILE = 1;
|
||||
|
||||
/* apply changes in Configuration/TypoScript/setup.txt */
|
||||
const PAGE_TYPE_SITEMAP_TXT = 841131; // sitemap.txt (EXT:metaseo)
|
||||
const PAGE_TYPE_SITEMAP_XML = 841132; // sitemap.xml (EXT:metaseo)
|
||||
const PAGE_TYPE_ROBOTS_TXT = 841133; // robots.txt (EXT:metaseo)
|
||||
|
||||
// ########################################################################
|
||||
// Attributes
|
||||
// ########################################################################
|
||||
|
||||
/**
|
||||
* List of blacklisted doktypes (from table pages)
|
||||
* @var array
|
||||
*/
|
||||
protected static $doktypeBlacklist = array(
|
||||
PageRepository::DOKTYPE_BE_USER_SECTION, // Backend Section (TYPO3 CMS)
|
||||
PageRepository::DOKTYPE_SPACER, // Menu separator (TYPO3 CMS)
|
||||
PageRepository::DOKTYPE_SYSFOLDER, // Folder (TYPO3 CMS)
|
||||
PageRepository::DOKTYPE_RECYCLER, // Recycler (TYPO3 CMS)
|
||||
);
|
||||
|
||||
/**
|
||||
* List of blacklisted rendering PAGE typenum (typoscript object)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $pagetypeBlacklist = array(
|
||||
self::PAGE_TYPE_SITEMAP_TXT, // sitemap.txt (EXT:metaseo)
|
||||
self::PAGE_TYPE_SITEMAP_XML, // sitemap.xml (EXT:metaseo)
|
||||
self::PAGE_TYPE_ROBOTS_TXT, // robots.txt (EXT:metaseo)
|
||||
);
|
||||
|
||||
|
||||
// ########################################################################
|
||||
// Public methods
|
||||
// ########################################################################
|
||||
|
||||
/**
|
||||
* Insert into sitemap
|
||||
*
|
||||
* @param array $pageData page information
|
||||
*/
|
||||
public static function index(array $pageData)
|
||||
{
|
||||
static $cache = array();
|
||||
|
||||
// do not index empty urls
|
||||
if (empty($pageData['page_url'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trim url
|
||||
$pageData['page_url'] = trim($pageData['page_url']);
|
||||
|
||||
// calc page hash
|
||||
$pageData['page_hash'] = md5($pageData['page_url']);
|
||||
$pageHash = $pageData['page_hash'];
|
||||
|
||||
// set default type if not set
|
||||
if (!isset($pageData['page_type'])) {
|
||||
$pageData['page_type'] = self::SITEMAP_TYPE_PAGE;
|
||||
}
|
||||
|
||||
// Escape/Quote data
|
||||
unset($pageDataValue);
|
||||
foreach ($pageData as &$pageDataValue) {
|
||||
if ($pageDataValue === null) {
|
||||
$pageDataValue = 'NULL';
|
||||
} elseif (is_int($pageDataValue) || is_numeric($pageDataValue)) {
|
||||
// Don't quote numeric/integers
|
||||
$pageDataValue = (int)$pageDataValue;
|
||||
} else {
|
||||
// String
|
||||
$pageDataValue = DatabaseUtility::quote($pageDataValue, 'tx_metaseo_sitemap');
|
||||
}
|
||||
}
|
||||
unset($pageDataValue);
|
||||
|
||||
// only process each page once to keep sql-statements at a normal level
|
||||
if (empty($cache[$pageHash])) {
|
||||
// $pageData is already quoted
|
||||
// TODO: INSERT INTO ... ON DUPLICATE KEY UPDATE?
|
||||
|
||||
$query = 'SELECT uid
|
||||
FROM tx_metaseo_sitemap
|
||||
WHERE page_uid = ' . $pageData['page_uid'] . '
|
||||
AND page_language = ' . $pageData['page_language'] . '
|
||||
AND page_hash = ' . $pageData['page_hash'] . '
|
||||
AND page_type = ' . $pageData['page_type'];
|
||||
$sitemapUid = DatabaseUtility::getOne($query);
|
||||
|
||||
if (!empty($sitemapUid)) {
|
||||
$query = 'UPDATE tx_metaseo_sitemap
|
||||
SET tstamp = ' . $pageData['tstamp'] . ',
|
||||
page_rootpid = ' . $pageData['page_rootpid'] . ',
|
||||
page_language = ' . $pageData['page_language'] . ',
|
||||
page_url = ' . $pageData['page_url'] . ',
|
||||
page_depth = ' . $pageData['page_depth'] . ',
|
||||
page_change_frequency = ' . $pageData['page_change_frequency'] . ',
|
||||
page_type = ' . $pageData['page_type'] . ',
|
||||
expire = ' . $pageData['expire'] . '
|
||||
WHERE uid = ' . (int)$sitemapUid;
|
||||
DatabaseUtility::exec($query);
|
||||
} else {
|
||||
// #####################################
|
||||
// INSERT
|
||||
// #####################################
|
||||
DatabaseUtility::connection()->exec_INSERTquery(
|
||||
'tx_metaseo_sitemap',
|
||||
$pageData,
|
||||
array_keys($pageData)
|
||||
);
|
||||
}
|
||||
|
||||
$cache[$pageHash] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear outdated and invalid pages from sitemap table
|
||||
*/
|
||||
public static function expire()
|
||||
{
|
||||
// #####################
|
||||
// Delete expired entries
|
||||
// #####################
|
||||
|
||||
$query = 'DELETE FROM tx_metaseo_sitemap
|
||||
WHERE is_blacklisted = 0
|
||||
AND expire <= ' . (int)time();
|
||||
DatabaseUtility::exec($query);
|
||||
|
||||
// #####################
|
||||
// Deleted or
|
||||
// excluded pages
|
||||
// #####################
|
||||
$query = 'SELECT ts.uid
|
||||
FROM tx_metaseo_sitemap ts
|
||||
LEFT JOIN pages p
|
||||
ON p.uid = ts.page_uid
|
||||
AND p.deleted = 0
|
||||
AND p.hidden = 0
|
||||
AND p.tx_metaseo_is_exclude = 0
|
||||
AND ' . DatabaseUtility::conditionNotIn('p.doktype', self::getDoktypeBlacklist()) . '
|
||||
WHERE p.uid IS NULL';
|
||||
|
||||
$deletedSitemapPages = DatabaseUtility::getColWithIndex($query);
|
||||
|
||||
// delete pages
|
||||
if (!empty($deletedSitemapPages)) {
|
||||
$query = 'DELETE FROM tx_metaseo_sitemap
|
||||
WHERE uid IN (' . implode(',', $deletedSitemapPages) . ')
|
||||
AND is_blacklisted = 0';
|
||||
DatabaseUtility::exec($query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of blacklisted doktypes (from table pages)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDoktypeBlacklist()
|
||||
{
|
||||
return self::$doktypeBlacklist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of blacklisted PAGE typenum (typoscript object)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPageTypeBlacklist()
|
||||
{
|
||||
$ret = self::$pagetypeBlacklist;
|
||||
|
||||
// Fetch from SetupTS (comma separated list)
|
||||
if (isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['metaseo.']['sitemap.']['index.']['pageTypeBlacklist'])
|
||||
&& strlen(
|
||||
$GLOBALS['TSFE']
|
||||
->tmpl
|
||||
->setup['plugin.']['metaseo.']['sitemap.']['index.']['pageTypeBlacklist']
|
||||
) >= 1
|
||||
) {
|
||||
$pageTypeBlacklist = $GLOBALS['TSFE']->tmpl
|
||||
->setup['plugin.']['metaseo.']['sitemap.']['index.']['pageTypeBlacklist'];
|
||||
$pageTypeBlacklist = Typo3GeneralUtility::trimExplode(',', $pageTypeBlacklist);
|
||||
|
||||
$ret = array_merge($ret, $pageTypeBlacklist);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of sitemap pages
|
||||
*
|
||||
* @param integer $rootPid Root page id of tree
|
||||
* @param integer $languageId Limit to language id
|
||||
*
|
||||
* @return boolean|array
|
||||
*/
|
||||
public static function getList($rootPid, $languageId = null)
|
||||
{
|
||||
$sitemapList = array();
|
||||
$pageList = array();
|
||||
|
||||
$typo3Pids = array();
|
||||
|
||||
$query = 'SELECT ts.*
|
||||
FROM tx_metaseo_sitemap ts
|
||||
INNER JOIN pages p
|
||||
ON p.uid = ts.page_uid
|
||||
AND p.deleted = 0
|
||||
AND p.hidden = 0
|
||||
AND p.tx_metaseo_is_exclude = 0
|
||||
AND ' . DatabaseUtility::conditionNotIn('p.doktype', self::getDoktypeBlacklist()) . '
|
||||
WHERE ts.page_rootpid = ' . (int)$rootPid . '
|
||||
AND ts.is_blacklisted = 0';
|
||||
|
||||
if ($languageId !== null) {
|
||||
$query .= ' AND ts.page_language = ' . (int)$languageId;
|
||||
}
|
||||
$query .= ' ORDER BY
|
||||
ts.page_depth ASC,
|
||||
p.pid ASC,
|
||||
p.sorting ASC';
|
||||
$resultRows = DatabaseUtility::getAll($query);
|
||||
|
||||
if (!$resultRows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($resultRows as $row) {
|
||||
$sitemapList[] = $row;
|
||||
|
||||
$sitemapPageId = $row['page_uid'];
|
||||
$typo3Pids[$sitemapPageId] = (int)$sitemapPageId;
|
||||
}
|
||||
|
||||
if (!empty($typo3Pids)) {
|
||||
$query = 'SELECT *
|
||||
FROM pages
|
||||
WHERE ' . DatabaseUtility::conditionIn('uid', $typo3Pids);
|
||||
$pageList = DatabaseUtility::getAllWithIndex($query, 'uid');
|
||||
|
||||
if (empty($pageList)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
'tx_metaseo_sitemap' => $sitemapList,
|
||||
'pages' => $pageList
|
||||
);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
365
typo3conf/ext/metaseo/Classes/Utility/TypoScript.php
Normal file
365
typo3conf/ext/metaseo/Classes/Utility/TypoScript.php
Normal file
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2015 Markus Blaschke <typo3@markus-blaschke.de> (metaseo)
|
||||
* 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 3 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!
|
||||
*/
|
||||
|
||||
namespace Metaseo\Metaseo\Utility;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility as Typo3GeneralUtility;
|
||||
|
||||
class TypoScript implements \Iterator
|
||||
{
|
||||
###########################################################################
|
||||
## Attributes
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* TYPO3 TypoScript Data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tsData;
|
||||
|
||||
/**
|
||||
* TYPO3 TypoScript Data Type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tsType;
|
||||
|
||||
/**
|
||||
* Iterator position
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $iteratorPosition = false;
|
||||
|
||||
/**
|
||||
* cObj
|
||||
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
|
||||
*/
|
||||
protected $cObj;
|
||||
|
||||
###########################################################################
|
||||
## Constructor
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param NULL|array $conf TypoScript node configuration
|
||||
* @param NULL|string $type TypoScript node type
|
||||
*/
|
||||
public function __construct($conf = null, $type = null)
|
||||
{
|
||||
if ($conf !== null) {
|
||||
$this->tsData = $conf;
|
||||
}
|
||||
|
||||
if ($type !== null) {
|
||||
$this->tsType = $type;
|
||||
}
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Iterator methods
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Rewind iterator position
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->tsData);
|
||||
$this->iteratorNextNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current node is a valid node
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return $this->iteratorPosition && array_key_exists($this->iteratorPosition, $this->tsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current iterator key
|
||||
*
|
||||
* @return string TypoScript path-node-key
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return substr($this->iteratorPosition, 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current iterator node
|
||||
*
|
||||
* @return TypoScript
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$nodePath = substr($this->iteratorPosition, 0, -1);
|
||||
|
||||
return $this->getNode($nodePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TypoScript subnode
|
||||
*
|
||||
* @param string $tsNodePath TypoScript node-path
|
||||
*
|
||||
* @return TypoScript TypoScript subnode-object
|
||||
*/
|
||||
public function getNode($tsNodePath)
|
||||
{
|
||||
$ret = null;
|
||||
|
||||
// extract TypoScript-path information
|
||||
$nodeSections = explode('.', $tsNodePath);
|
||||
$nodeValueType = end($nodeSections);
|
||||
$nodeValueName = end($nodeSections) . '.';
|
||||
|
||||
// remove last node from sections because we already got the node name
|
||||
unset($nodeSections[key($nodeSections)]);
|
||||
|
||||
// walk though array to find node
|
||||
$nodeData = $this->tsData;
|
||||
if (!empty($nodeSections) && is_array($nodeSections)) {
|
||||
foreach ($nodeSections as $sectionName) {
|
||||
$sectionName .= '.';
|
||||
|
||||
if (is_array($nodeData) && array_key_exists($sectionName, $nodeData)) {
|
||||
$nodeData = $nodeData[$sectionName];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch TypoScript configuration data
|
||||
$tsData = array();
|
||||
if (is_array($nodeData) && array_key_exists($nodeValueName, $nodeData)) {
|
||||
$tsData = $nodeData[$nodeValueName];
|
||||
}
|
||||
|
||||
// Fetch TypoScript configuration type
|
||||
$tsType = null;
|
||||
if (is_array($nodeData) && array_key_exists($nodeValueType, $nodeData)) {
|
||||
$tsType = $nodeData[$nodeValueType];
|
||||
}
|
||||
|
||||
// Clone object and set values
|
||||
$ret = clone $this;
|
||||
$ret->tsData = $tsData;
|
||||
$ret->tsType = $tsType;
|
||||
$ret->iteratorPosition = false;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Next iterator node
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
next($this->tsData);
|
||||
$this->iteratorNextNode();
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Public methods
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Search next iterator node
|
||||
*/
|
||||
public function iteratorNextNode()
|
||||
{
|
||||
// INIT
|
||||
$iteratorPosition = null;
|
||||
$this->iteratorPosition = false;
|
||||
$nextNode = false;
|
||||
|
||||
do {
|
||||
if ($nextNode) {
|
||||
next($this->tsData);
|
||||
}
|
||||
|
||||
$currentNode = current($this->tsData);
|
||||
|
||||
if ($currentNode !== false) {
|
||||
// get key
|
||||
$iteratorPosition = key($this->tsData);
|
||||
|
||||
// check if node is subnode or value
|
||||
if (substr($iteratorPosition, -1) == '.') {
|
||||
// next subnode fond
|
||||
$this->iteratorPosition = $iteratorPosition;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$iteratorPosition = false;
|
||||
$this->iteratorPosition = false;
|
||||
}
|
||||
|
||||
$nextNode = true;
|
||||
} while ($iteratorPosition !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value from node
|
||||
*
|
||||
* @param string $tsNodePath TypoScript node-path
|
||||
* @param mixed $defaultValue Default value
|
||||
*
|
||||
* @return mixed Node value (or default value)
|
||||
*/
|
||||
public function getValue($tsNodePath, $defaultValue = null)
|
||||
{
|
||||
$ret = $defaultValue;
|
||||
|
||||
// extract TypoScript-path information
|
||||
$nodeFound = true;
|
||||
$nodeSections = explode('.', $tsNodePath);
|
||||
$nodeValueName = end($nodeSections);
|
||||
|
||||
// remove last node from sections because we already got the node name
|
||||
unset($nodeSections[key($nodeSections)]);
|
||||
|
||||
// walk though array to find node
|
||||
$nodeData = $this->tsData;
|
||||
if (!empty($nodeSections) && is_array($nodeSections)) {
|
||||
foreach ($nodeSections as $sectionName) {
|
||||
$sectionName .= '.';
|
||||
|
||||
if (is_array($nodeData) && array_key_exists($sectionName, $nodeData)) {
|
||||
$nodeData = $nodeData[$sectionName];
|
||||
} else {
|
||||
$nodeFound = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if we got the value of the node
|
||||
if ($nodeFound && is_array($nodeData) && array_key_exists($nodeValueName, $nodeData)) {
|
||||
$ret = $nodeData[$nodeValueName];
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert TypoScript to original array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->tsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if TypoScript is empty/not set
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->tsData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render TypoScript Config
|
||||
*
|
||||
* @return mixed Result of cObj
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return $this->getCObj()->cObjGetSingle($this->tsType, $this->tsData);
|
||||
}
|
||||
|
||||
/**
|
||||
* StdWrap with TypoScript Configuration
|
||||
*
|
||||
* @param mixed $value Value for stdWrap
|
||||
*
|
||||
* @return mixed Result of stdWrap
|
||||
*/
|
||||
public function stdWrap($value = null)
|
||||
{
|
||||
return $this->getCObj()->stdWrap($value, $this->tsData);
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Protected methods
|
||||
###########################################################################
|
||||
|
||||
/**
|
||||
* Return instance of \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
|
||||
*
|
||||
* @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
|
||||
*/
|
||||
protected function getCObj()
|
||||
{
|
||||
if ($this->cObj === null) {
|
||||
$this->cObj = Typo3GeneralUtility::makeInstance(
|
||||
'TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->cObj;
|
||||
}
|
||||
|
||||
###########################################################################
|
||||
## Private methods
|
||||
###########################################################################
|
||||
|
||||
###########################################################################
|
||||
## Accessors
|
||||
###########################################################################
|
||||
|
||||
public function setTypoScript(Array $conf)
|
||||
{
|
||||
$this->tsData = $conf;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTypoScriptType()
|
||||
{
|
||||
return $this->tsType;
|
||||
}
|
||||
|
||||
public function setTypoScriptType($value)
|
||||
{
|
||||
$this->tsType = (string)$value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user