[TYPO3] Problems with typoLink_URL
Stephen Bungert
s.bungert at metrinomics.de
Wed Mar 26 13:15:58 CET 2008
$conf = array('parameter' => $this->ttNewsSinglePid, 'additionalParams' =>
'&tx_ttnews[tt_news]=' . $this->matchingResult[$index]['uid'],
'useCacheHash' => true,); $url = $this->cObj->typoLink_URL($conf);
This should generate a url to a tt_news article. It's in a for loop, so that
I can output lots of tt_news articles.
$this->matchingResult[$index]['uid'] returns a different number in each
loop, so I know it hast he correct UID fro the article,
but when $url is outputed in an echo it is empty, so the link urls are tot
he current article being viewed instead oft eh article link I made.
When I display the content of $conf I see the correct info, such as:
title = 'Test Article NSN'
uid = '20'
pid = '47'
datetime = '21 March 2008'
author = 'Stephen Bungert'
Why then when I echo $url does it display nothing. Or if I use it in a links
href it links tot he current article being viewed (the current url).
Here is the full extension PHP (I know there are some problems with it - I'm
just trying to get used to writing them first)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008 Stephen Bungert <s.bungert at metrinomics.de>
* 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!
***************************************************************/
require_once(PATH_tslib.'class.tslib_pibase.php');
/**
* Plugin 'Related TT News' for the 'related_ttnews' extension.
*
* @author Stephen Bungert <s.bungert at metrinomics.de>
* @package TYPO3
* @subpackage tx_relatedttnews
*/
class tx_relatedttnews_pi1 extends tslib_pibase {
var $prefixId = 'tx_relatedttnews_pi1'; // Same as
class name
var $scriptRelPath = 'pi1/class.tx_relatedttnews_pi1.php'; //
Path to this script relative to the extension dir.
var $extKey = 'related_ttnews'; // The extension key.
var $pi_checkCHash = true;
var $conf;
var $url;
var $queryResult = undefined; // UID numbers of the related articles
var $matchingResult = undefined; // Textural date we are interested in
from the related articles (bodytext etc.)
var $result = undefined; // Stores the actual foreign_uids extracted
from the mutlti-dim. array $queryResult
var $newsId = undefined; // The news ID of the current
article (in single mode). Extracted from GET vars
var $tarGetVar = 'tx_ttnews';
var $tarSubGetVar = 'tt_news';
var $loopCount = undefined; // Used in loops, should be equal to the
number of related items
var $cropBodyAt = 30; // Default crop value
var $dateFormat = '%d %B %Y'; // Default date format
var $ttNewsSinglePid = 'none'; // Default tt_news SINGLE pid
var $showBodyTextSample = 'yes'; // Default settting to decide if
body text should be shown ('no' = show author)
var $limit = 10; // Default number of matches to get
var $hideWhenNoMatches = 'no'; // Default display status when there
are no matches
var $newsPid = undefined; // Default storage folder id for news
/**
* The main method of the PlugIn
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
* @return The content that is displayed on the website
*/
function main($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults(); // Get TypoScript for this
plugin if it exists in a template setup
$this->pi_loadLL(); // Get Local Language data
// Check if TypoScript properties should override defaults
$this->getTypoScriptVars();
// Retrieve the news ID from the GET vars
$this->newsId = $this->getNewsId();
// Get the DB data
$this->queryResult =
$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid_foreign',
'tt_news_related_mm', 'uid_local=' . intval($this->newsId), '', '',
$this->limit);
// Start output
if ($this->newsId == "No news ID found" ||
count($this->queryResult) <= 0) // There are no related records...
{
if ($this->newsId == "No news ID found" ||
$this->hideWhenNoMatches == 'yes')
{
$content .= '';
}
else
{
$content .= '
<div id="sidebarItem">
<p id="sbTitle">' .
$this->pi_getLL('titleText') . '</p>
<div id="sbArticle">
<p id="sbArtNoArticles">' .
$this->pi_getLL('noRelatedRecords') . '</p>
</div>
</div>';
}
}
else // There are related records, get the data, tidy it up
and output it
{
// Set count length for loops
$this->loopCount = count($this->queryResult);
// Put the results in a new empty array for easier
processing
$this->result =
$this->processResults($this->queryResult);
// Get the matching data from tt_news table
if ($this->showBodyTextSample == 'yes')
{
$this->matchingResult =
$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('title, uid, pid, datetime,
bodytext', 'tt_news', 'uid IN (' . implode(',', $this->result) . ') AND
pid=' . intval($this->newsPid) . $this->cObj->enableFields('tt_news'), '',
'datetime DESC', $this->limit);
$this->cropBodyText($this->cropBodyAt);
}
else
{
$this->matchingResult =
$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('title, uid, pid, datetime,
author', 'tt_news', 'uid IN (' . implode(',', $this->result) . ') AND pid='
. intval($this->newsPid) . $this->cObj->enableFields('tt_news'), '',
'datetime DESC', $this->limit);
}
$this->convertDatetime();
$this->outputData($this->matchingResult);
// Start displaying content
$content .= '
<div id="sidebarItem">
<p id="sbTitle">' .
$this->pi_getLL('titleText') . '</p>';
for ($index = 0; $index < $this->loopCount; $index
++)
{
$conf = array('parameter' =>
$this->ttNewsSinglePid, 'additionalParams' => '&tx_ttnews[tt_news]=' .
$this->matchingResult[$index]['uid'], 'useCacheHash' => true,);
$url = $this->cObj->typoLink_URL($conf);
foreach($conf as $name => $value)
{
print "$name : $value<br>";
}
if ($this->showBodyTextSample == 'yes')
{
if ($this->ttNewsSinglePid ==
'none')
{
$content .= '
<div id="sbArticle">
<p id="sbArtTitle">'
. $this->matchingResult[$index]['title'] . '<br />
<span
id="sbArtTimeStamp">' . $this->matchingResult[$index]['datetime'] .
'</span></p>
<p
id="sbArtSummary">' . $this->matchingResult[$index]['bodytext'] . '</p>
</div>';
}
else
{
$content .= '
<div id="sbArticle">
<p
id="sbArtTitle"><a href="' . $url . '" title="' .
$this->pi_getLL('titleAtr') . '">' . $this->matchingResult[$index]['title']
. '</a><br />
<span
id="sbArtTimeStamp">' . $this->matchingResult[$index]['datetime'] .
'</span></p>
<p
id="sbArtSummary">' . $this->matchingResult[$index]['bodytext'] . '<br /><a
class="articleLink" href="' . $url . '" title="' .
$this->pi_getLL('titleAtr') . '">' . $this->pi_getLL('moreLink') . '</a></p>
</div>';
}
}
else
{
if ($this->ttNewsSinglePid ==
'none')
{
$content .= '
<div id="sbArticle">
<p id="sbArtTitle">'
. $this->matchingResult[$index]['title'] . '<br />
<span
id="sbArtTimeStamp">' . $this->matchingResult[$index]['datetime'] .
'</span></p>
<p
id="sbArtSummary">' . $this->matchingResult[$index]['author'] . '</p>
</div>>';
}
else
{
$content .= '
<div id="sbArticle">
<p
id="sbArtTitle"><a href="' . $url . '" title="' .
$this->pi_getLL('titleAtr') . '">' . $this->matchingResult[$index]['title']
. '</a><br />
<span
id="sbArtTimeStamp">' . $this->matchingResult[$index]['datetime'] .
'</span></p>
<p
id="sbArtSummary">' . $this->matchingResult[$index]['author'] . '</p>
</div>';
}
}
}
$content .= '</div>';
}
return $this->pi_wrapInBaseClass($content);
}
function getTypoScriptVars()
{
if (isset($this->conf['cropBodyAt']))
{
$this->cropBodyAt = $this->conf['cropBodyAt'];
}
if (isset($this->conf['dateFormat']))
{
$this->dateFormat = $this->conf['dateFormat'];
}
if (isset($this->conf['ttNewsSinglePid']))
{
$this->ttNewsSinglePid =
$this->conf['ttNewsSinglePid'];
}
if (isset($this->conf['limit']))
{
if ($this->conf['limit'] == 'none')
{
$this->limit = '';
}
else
{
$this->limit = $this->conf['limit'];
}
}
if (isset($this->conf['showBodyTextSample']))
{
$this->showBodyTextSample =
$this->conf['showBodyTextSample'];
}
if (isset($this->conf['hideWhenNoMatches']))
{
$this->hideWhenNoMatches =
$this->conf['hideWhenNoMatches'];
}
if (isset($this->conf['newsPid']))
{
$this->newsPid = $this->conf['newsPid'];
}
}
function getNewsId()
{
$retrievedGet = t3lib_div::_GET($this->tarGetVar); //
tx_ttnews array
$nID = "No news ID found";
if ($retrievedGet == '' || $retrievedGet == false ||
$retrievedGet == undefined || $retrievedGet == null)
{
return $nID;
}
else
{
// Now look in th tx_ttnews array for the element
called tt_news
foreach($retrievedGet as $name => $value)
{
if ($name == $this->tarSubGetVar)
{
$nID = $value;
}
}
return $nID;
}
}
function processResults($queryReturns)
{
$foreignIds = array();
foreach($queryReturns as $value)
{
if (is_array($value) == true)
{
foreach($value as $value)
{
$foreignIds[count($foreignIds)] .=
intval($value);
}
}
}
return $foreignIds;
}
function cropBodyText($lengthReq)
{
$temp = undefined;
$spacePos = undefined;
for ($index = 0; $index < $this->loopCount; $index ++)
{
$temp = $this->matchingResult[$index]['bodytext'];
// If over maxLen, crop it
if (strlen($temp) > $lengthReq)
{
$temp = substr(strip_tags($temp), 0 ,
$this->cropBodyAt);
}
// Now make it look nice, find last space
$spacePos = strripos($temp, " ");
if ($spacePos)
{
// Crop temp from start until the last space
$temp = substr($temp, 0 , $spacePos);
}
// Overwrite full body text with cropped text and
add ...
$this->matchingResult[$index]['bodytext'] = $temp .
"...";
}
}
function convertDatetime()
{
$loopCount = count($this->matchingResult);
for ($index = 0; $index < $this->loopCount; $index ++)
{
$this->matchingResult[$index]['datetime'] =
strftime($this->dateFormat, $this->matchingResult[$index]['datetime']);
$temp = split(" ",
$this->matchingResult[$index]['datetime']);
$temp = join(" ", $temp);
$this->matchingResult[$index]['datetime'] = $temp;
}
}
// Output multi-dim. array ($array)
private function outputData($array)
{
foreach($array as $key => $value)
{
if (is_array($value))
{
$this->outputData($value);
}
else
{
echo "$key = <b>'" . $value . "'</b><br>";
}
}
}
}
if (defined('TYPO3_MODE') &&
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/related_ttnews/pi1/class.tx_rela
tedttnews_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/related_ttnews/pi1/
class.tx_relatedttnews_pi1.php']);
}
?>
More information about the TYPO3-english
mailing list