[TYPO3] [RealUrl] userFunc in fixedPostVars
Daniel
daniel.rampanelli at gmail.com
Tue Jul 11 09:00:15 CEST 2006
hi to everybody,
I'm using RealUrl on my t3 website and I have defined a custom
"alias:id mapper" with the following piece of conf
<conf-snippet>
...
'fixedPostVars' => array(
'49' => array(
array(
'GETvar' => 'tx_ppm[pid]',
'userFunc' =>
'EXT:realurl/class.tx_realurl_userfunctest.php:&tx_realurl_userfunctest->main'
)
)
)
...
</conf-snipper>
which is used for one parameter. Basically the script does collect a
little more information and put it together exactly like RealUrl.
Everything works really fine and I'm happy.
But now a problem arise. If I use linking functions (typolink,
typolink_url, etc.) I get a
<strange-error>
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
result resource in /typo3_src-3.8.0/t3lib/class.t3lib_db.php on line
741
Warning: Cannot modify header information - headers already sent by
(output started at /typo3_src-3.8.0/t3lib/class.t3lib_db.php:741)
in/typo3_src-3.8.0/typo3/sysext/cms/tslib/class.tslib_fe.php on line
2612
</strange-error>
and, additonally, this happens using linking functions with
"additionalParameters" (for example, $cObj->currentPageUrl() works).
Finally, this is my custom script to handle the alias:id bidirectional mapping
<custom-script>
class tx_realurl_userfunctest {
var $params;
var $segmentChunks;
var $sys_language_uid;
var $localizedStrings = array(...);
function main(&$params, $ref) {
$this->params = $params;
$this->sys_language_uid = $params['pObj']->pObj->sys_language_uid;
if ($this->params['decodeAlias']) {
return $this->alias2id($this->params['value']);
} else {
return $this->id2alias($this->params['value']);
}
}
function id2alias($value) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_ppm_products.*',
'tx_ppm_products',
'uid = '.$value
);
if($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
$this->encodeRecord($row);
return $this->getSegment();
}
function alias2id($value) {
$additionalWhere = '';
$matches = array();
// little performance kick
if(preg_match('/-([0-9]+|[0-9]+[x]{1}[0-9]+)g$/', $value, &$matches))
$additionalWhere = " AND tx_ppm_products.weight =
'".$matches[1]."'";
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_ppm_products.*',
'tx_ppm_products',
'deleted = 0 AND hidden = 0'.$additionalWhere
);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
foreach($this->localizedStrings as $uid => $strings) {
$this->sys_language_uid = intval($uid);
$this->encodeRecord($row);
if($this->getSegment() == $value)
return $row['uid'];
}
}
}
function encodeRecord(&$record) {
$this->segmentChunks = array();
// product name
$this->addToSegment($record[$this->localizedStrings[$this->sys_language_uid]['name']]);
// product state
$this->addToSegment($this->localizedStrings[$this->sys_language_uid]['state'][intval($record['state'])]);
// product weight
$this->addToSegment($record['weight'].'g');
}
function getSegment() {
return implode('-', $this->segmentChunks);
}
function addToSegment($chunk) {
// trim and lower everything
$chunk = strtolower(trim($chunk));
// translate all characters to ascii equivalents
$chunk = strtr($chunk,
"àáâãçèéêëìíîïñòóôõùúû",
"aaaaceeeeiiiinoooouuu"
);
$chunk = preg_replace(
array('/ä/', '/å/', '/ö/', '/ü/'),
array( 'ae', 'aa', 'oe', 'ue'),
$chunk
);
// cut off not desired characters
$chunk = preg_replace('/[^a-z0-9\s\-\_]/', '', $chunk);
// replace - and _ by spaces
$chunk = preg_replace('/[\-\_]/', ' ', $chunk);
// make multiple spaces to one single
$chunk = preg_replace('/\s\s+/', ' ', $chunk);
// place a space character insted of spaces and assign the chunk
$chunk = preg_replace('/\s/', '-', $chunk);
$this->segmentChunks[] = $chunk;
}
?>
</custom-script>
Thank you in advance,
Daniel
More information about the TYPO3-english
mailing list