Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Stripping table tags when using cpm_viewMediaByPid()  (Read 4222 times)

0 Members and 1 Guest are viewing this topic.

Texas Kelly

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Stripping table tags when using cpm_viewMediaByPid()
« on: February 03, 2008, 06:58:43 pm »

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:

Code: [Select]
{subtitle}<a {linktarget} href="{link to picture}"><img src="{thumbnail image}" alt="{alttag}" title="{title}" {imgoptions} /></a>
instead of:

Code: [Select]
<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:

Code: [Select]
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:

Code: [Select]
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?
« Last Edit: February 06, 2008, 11:45:55 pm by Nibbler »
Logged

Texas Kelly

  • Coppermine newbie
  • Offline Offline
  • Posts: 10
Re: Stripping table tags when using cpm_viewMediaByPid()
« Reply #1 on: February 06, 2008, 09:15:24 pm »

I'm such an idiot...

Once I changed this:

Code: [Select]
return $htmlOut = "";
to this:

Code: [Select]
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. :)
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 19 queries.