Stripping table tags when using cpm_viewMediaByPid() Stripping table tags when using cpm_viewMediaByPid()
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Stripping table tags when using cpm_viewMediaByPid()

Started by Texas Kelly, February 03, 2008, 06:58:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Texas Kelly

Hi, it's me again. :)

I've furthered my cpmFetch/vBulletin work by creating a [thumb] BBCode to work with the cpmFetch function cpm_viewMediaByPid(). Something I find frustrating about it though is that when the BBCode renders the cpmFetch output, the table tags only allow you to list one thumbnail in a row. (If I try putting two of the [thumb] tags next to each other, the second thumbnail ends up underneath the first.) So I'm trying to compensate by creating a function that strips the table tags when cpm_viewMediaByPid() is used. In other words, I'm trying to get vBulletin to display:

{subtitle}<a {linktarget} href="{link to picture}"><img src="{thumbnail image}" alt="{alttag}" title="{title}" {imgoptions} /></a>

instead of:

<table>
<tr>
<td><a {linktarget} href="{link to picture}"><img src="{thumbnail image}" alt="{alttag}" title="{title}" {imgoptions} /></a><br />{subtitle}</td>
</tr>
</table>


I created the following function which I call createThumb(), which is essentially a copy of createTable(), except for as many parts related to table tags and rows and columns as I could find being stripped out. The code, as best as I can determine it, should be this:

function createThumb ($resultset) {

$optionshash = $this->optionHash;
$htmlOut = "";
$alttag = "";
$subtitle = "";
$cell = $resultset[0];

if (array_key_exists('alttag',$this->optionHash)) {
$alttag = $this->createDescription($this->optionHash['alttag'],$cell);
} else {
$alttag = $this->createDescription("{{pFilename}}",$cell);
}

$attributes = 'alt="' . $alttag . '" title="' . $alttag . '"';

$imgfile = $this->getImageToUse($cell['pFilepath'], $cell['pFilename'], $this->getPrefixToUse());
$imgfile = $this->cfg['cpg_url'] . $this->urlEncodeImagePath($imgfile);

if (array_key_exists('linktemplate',$this->optionHash)) {
$link = $this->createDescription($this->optionHash['linktemplate'],$cell);
} else {
$link = $this->createlink($cell['pFilepath'], rawurlencode($cell['pFilename']),$cell['pAid'],$cell['pPid'],$this->getoption('imagelink'));
}

if (!array_key_exists('noimage',$this->optionHash)) {
$subtitle = "";
}

if (array_key_exists('subtitle',$this->optionHash) && array_key_exists('subtitlelink',$this->optionHash)) {
$subtitle = $this->htmlTagAHREF($link, $this->createDescription($this->optionHash['subtitle'],$cell));
} elseif (array_key_exists('subtitle',$this->optionHash)) {
$subtitle = $this->createDescription($this->optionHash['subtitle'],$cell);
} else {
$subtitle = "";
}

if ($link != "" && !(array_key_exists('noimage',$this->optionHash))) {
$htmlOut .= $subtitle . $this->htmlTagAHREF($link,$this->htmlTagIMG($imgfile,$attributes));
} else {
$htmlOut .= $subtitle . $this->htmlTagIMG($imgfile,$attributes);
}

return $htmlOut = "";

}


To invoke it, one would then modify cpm_viewMediaByPid() to:

function cpm_viewMediaByPid($pid, $options="") {
$this->loadOptions($options);
$resultset = $this->getMediaByPid($pid);
$this->addDescriptionsToResultSet($resultset);

$retval = "";
switch ($this->returntype) {
case ('resultset'):
$retval = $resultset;
break;
case ('html'):
$retval = $this->createThumb($resultset);
break;
case ('print'):
default:
print $this->createThumb($resultset);
}

$this->clearOptions();
return ($retval);
}


Of course, when I try to run this (either using my BBCode or using a test file with PHP code that calls the cpm_viewMediaByPid() function), I get a big chunk of blank screen in return. Obviously, something's wrong with the code I've written, but I've got no clue what. Are there any eagle eyes out there that could spot any errors or problems with this code, or could help me figure out a way to debug it so I can see where it's blowing up?

Texas Kelly

I'm such an idiot...

Once I changed this:

return $htmlOut = "";

to this:

return $htmlOut;

it worked precisely the way I thought it would.

I'm going to post a new thread with the final code; if a mod could lock this one up I'd appreciate it. :)