Skip to content

Commit

Permalink
[TASK] PSR-2 code style
Browse files Browse the repository at this point in the history
reformat PHP code to conform with PSR-2 code style

Resolves: #73588
Releases: master
Change-Id: If766df3a3acaf95d820baa43781621c78725de7a
Reviewed-on: https://review.typo3.org/46861
Reviewed-by: Ivan Dharma Kartolo <[email protected]>
Tested-by: Ivan Dharma Kartolo <[email protected]>
  • Loading branch information
kartolo committed Feb 23, 2016
1 parent 16229fd commit a2aa64c
Show file tree
Hide file tree
Showing 37 changed files with 13,060 additions and 12,847 deletions.
254 changes: 128 additions & 126 deletions Classes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use TYPO3\CMS\Core\Utility\MailUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
/**
* Container class for auxilliary functions of tx_directmail
*
* @author Kasper Sk�rh�j <kasperYYYY>@typo3.com>
Expand All @@ -26,129 +26,131 @@
* @package TYPO3
* @subpackage tx_directmail
*/
class Container {

var $boundaryStartWrap = '<!--DMAILER_SECTION_BOUNDARY_ | -->';
var $boundaryEnd = '<!--DMAILER_SECTION_BOUNDARY_END-->';

/**
* @var TypoScriptFrontendController
*/
var $cObj;

/**
* This function wraps HTML comments around the content.
* The comments contain the uids of assigned direct mail categories.
* It is called as "USER_FUNC" from TS.
*
* @param string $content Incoming HTML code which will be wrapped
* @param array|null $conf Pointer to the conf array (TS)
*
* @return string content of the email with dmail boundaries
*/
function insert_dMailer_boundaries($content, $conf = array()) {

if (isset($conf['useParentCObj']) && $conf['useParentCObj']) {
$this->cObj = $conf['parentObj']->cObj;
}

// this check could probably be moved to TS
if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) {
if ($content != '') {
// setting the default
$categoryList = '';
if (intval($this->cObj->data['module_sys_dmail_category']) >= 1) {
// if content type "RECORDS" we have to strip off
// boundaries from indcluded records
if ($this->cObj->data['CType'] == 'shortcut') {
$content = $this->stripInnerBoundaries($content);
}

// get categories of tt_content element
$foreignTable = 'sys_dmail_category';
$select = "$foreignTable.uid";
$localTableUidList = intval($this->cObj->data['uid']);
$mmTable = 'sys_dmail_ttcontent_category_mm';
$whereClause = '';
$orderBy = $foreignTable . '.uid';
$res = $this->cObj->exec_mm_query_uidList(
$select,
$localTableUidList,
$mmTable,
$foreignTable,
$whereClause,
'',
$orderBy);

if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
$categoryList .= $row['uid'] . ',';
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
$categoryList = rtrim($categoryList, ",");
}
}
// wrap boundaries around content
$content = $this->cObj->wrap($categoryList, $this->boundaryStartWrap) . $content . $this->boundaryEnd;
}
}
return $content;
}

/**
* Remove boundaries from TYPO3 content
*
* @param string $content the content with boundaries in comment
*
* @return string the content without boundaries
*/
function stripInnerBoundaries($content) {
// only dummy code at the moment
$searchString = $this->cObj->wrap('[\d,]*', $this->boundaryStartWrap);
$content = preg_replace('/' . $searchString . '/', '', $content);
$content = preg_replace('/' . $this->boundaryEnd . '/', '', $content);
return $content;
}

/**
* Breaking lines into fixed length lines, using GeneralUtility::breakLinesForEmail()
*
* @param string $content The string to break
* @param array $conf Configuration options: linebreak, charWidth; stdWrap enabled
*
* @return string Processed string
* @see GeneralUtility::breakLinesForEmail()
*/
function breakLines($content, array $conf) {
$linebreak = $GLOBALS['TSFE']->cObj->stdWrap(($conf['linebreak'] ? $conf['linebreak'] : chr(32) . LF), $conf['linebreak.']);
$charWidth = $GLOBALS['TSFE']->cObj->stdWrap(($conf['charWidth'] ? intval($conf['charWidth']) : 76), $conf['charWidth.']);

return MailUtility::breakLinesForEmail($content, $linebreak, $charWidth);
}

/**
* Inserting boundaries for each sitemap point.
*
* @param string $content The content string
* @param array $conf The TS conf
*
* @return string $content: the string wrapped with boundaries
*/
public function insertSitemapBoundaries($content, array $conf) {
$uid = $this->cObj->data['uid'];
$content = '';

$categories = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_dmail_ttcontent_category_mm', 'uid_local=' . (int)$uid, '', 'sorting');
if (count($categories) > 0) {
$categoryList = array();
foreach ($categories as $category) {
$categoryList[] = $category['uid_foreign'];
}
$content = '<!--DMAILER_SECTION_BOUNDARY_' . implode(',', $categoryList) . '-->|<!--DMAILER_SECTION_BOUNDARY_END-->';
}

return $content;
}
class Container
{

public $boundaryStartWrap = '<!--DMAILER_SECTION_BOUNDARY_ | -->';
public $boundaryEnd = '<!--DMAILER_SECTION_BOUNDARY_END-->';

/**
* @var TypoScriptFrontendController
*/
public $cObj;

/**
* This function wraps HTML comments around the content.
* The comments contain the uids of assigned direct mail categories.
* It is called as "USER_FUNC" from TS.
*
* @param string $content Incoming HTML code which will be wrapped
* @param array|null $conf Pointer to the conf array (TS)
*
* @return string content of the email with dmail boundaries
*/
public function insert_dMailer_boundaries($content, $conf = array())
{
if (isset($conf['useParentCObj']) && $conf['useParentCObj']) {
$this->cObj = $conf['parentObj']->cObj;
}

// this check could probably be moved to TS
if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) {
if ($content != '') {
// setting the default
$categoryList = '';
if (intval($this->cObj->data['module_sys_dmail_category']) >= 1) {
// if content type "RECORDS" we have to strip off
// boundaries from indcluded records
if ($this->cObj->data['CType'] == 'shortcut') {
$content = $this->stripInnerBoundaries($content);
}

// get categories of tt_content element
$foreignTable = 'sys_dmail_category';
$select = "$foreignTable.uid";
$localTableUidList = intval($this->cObj->data['uid']);
$mmTable = 'sys_dmail_ttcontent_category_mm';
$whereClause = '';
$orderBy = $foreignTable . '.uid';
$res = $this->cObj->exec_mm_query_uidList(
$select,
$localTableUidList,
$mmTable,
$foreignTable,
$whereClause,
'',
$orderBy);

if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
$categoryList .= $row['uid'] . ',';
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
$categoryList = rtrim($categoryList, ",");
}
}
// wrap boundaries around content
$content = $this->cObj->wrap($categoryList, $this->boundaryStartWrap) . $content . $this->boundaryEnd;
}
}
return $content;
}

/**
* Remove boundaries from TYPO3 content
*
* @param string $content the content with boundaries in comment
*
* @return string the content without boundaries
*/
public function stripInnerBoundaries($content)
{
// only dummy code at the moment
$searchString = $this->cObj->wrap('[\d,]*', $this->boundaryStartWrap);
$content = preg_replace('/' . $searchString . '/', '', $content);
$content = preg_replace('/' . $this->boundaryEnd . '/', '', $content);
return $content;
}

/**
* Breaking lines into fixed length lines, using GeneralUtility::breakLinesForEmail()
*
* @param string $content The string to break
* @param array $conf Configuration options: linebreak, charWidth; stdWrap enabled
*
* @return string Processed string
* @see GeneralUtility::breakLinesForEmail()
*/
public function breakLines($content, array $conf)
{
$linebreak = $GLOBALS['TSFE']->cObj->stdWrap(($conf['linebreak'] ? $conf['linebreak'] : chr(32) . LF), $conf['linebreak.']);
$charWidth = $GLOBALS['TSFE']->cObj->stdWrap(($conf['charWidth'] ? intval($conf['charWidth']) : 76), $conf['charWidth.']);

return MailUtility::breakLinesForEmail($content, $linebreak, $charWidth);
}

/**
* Inserting boundaries for each sitemap point.
*
* @param string $content The content string
* @param array $conf The TS conf
*
* @return string $content: the string wrapped with boundaries
*/
public function insertSitemapBoundaries($content, array $conf)
{
$uid = $this->cObj->data['uid'];
$content = '';

$categories = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_dmail_ttcontent_category_mm', 'uid_local=' . (int)$uid, '', 'sorting');
if (count($categories) > 0) {
$categoryList = array();
foreach ($categories as $category) {
$categoryList[] = $category['uid_foreign'];
}
$content = '<!--DMAILER_SECTION_BOUNDARY_' . implode(',', $categoryList) . '-->|<!--DMAILER_SECTION_BOUNDARY_END-->';
}

return $content;
}
}

?>
Loading

0 comments on commit a2aa64c

Please sign in to comment.