Empty ALT description not working in 1.28?

Use GitHub to post bug reports and error descriptions for phpwcms. Describe your problem detailed!
Locked
Peekay
Posts: 286
Joined: Sun 25. Jul 2004, 23:24
Location: UK

Empty ALT description not working in 1.28?

Post by Peekay »

In 1.25 dev you could create an empty ALT description for unimportant images by using two pipes in the caption field (||). This doesn't seem to work in 1.28. Is there a file I can hack to get this function back?
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

NOT a "bug" by the way! :wink:
"1.2.8 changelog.txt"
[ADD] New function getImageCaption($caption[, $array_index='NUM'||'STRING']): returns an array containing all caption elements.
"front.func.inc.php"

Code: Select all

function getImageCaption($caption='', $array_index='NUM') {
	// splits given image caption and returns an array
	$caption	= explode('|', $caption);
	
	// following is default for the exploded $caption
	// [0] caption text
	// [1] alt text for image
	// [2] link -> array(0 => link, 1 => target)
	// [3] title text -> if empty alt text will be used
	$caption[0]			= trim($caption[0]);
	$caption[1]			= isset($caption[1]) ? trim($caption[1]) : '';
	$caption[2]			= isset($caption[2]) ? explode(' ', trim($caption[2])) : array(0 => '', 1 => '');
	$caption[2][0]		= trim($caption[2][0]);
	if(empty($caption[2][0]) || empty($caption[2][1])) {
		$caption[2][1]	= '';
	} else {
		$caption[2][1]	= trim($caption[2][1]);
		$caption[2][1]	= empty($caption[2][1]) ? '' : ' target="'.$caption[2][1].'"';
	}
	$caption[3]			= isset($caption[3]) ? trim($caption[3]) : $caption[1];
	if($array_index == 'NUM') {
		return $caption;
	} else {
		return array(	'caption_text'		=> $caption[0],		'caption_alt'		=> $caption[1],
						'caption_link'		=> $caption[2][0],	'caption_target'	=> $caption[2][1],
						'caption_title'		=> $caption[3]		);
	}
	
}
Untested - But removing "comment" characters ( // ) from -old- function and adding to -new- MAY work:

"content.article.inc.php"
1.2.6

Code: Select all

		//retrieve image info
		$row["article_image"] = unserialize($row["article_image"]);
		$caption	= explode('|', $row["article_image"]["caption"]);
		$row["article_image"]["caption"] = $caption[0]; //$caption[0]
1.2.8

Code: Select all

		//retrieve image info
		$row["article_image"] = unserialize($row["article_image"]);
		//$caption	= explode('|', $row["article_image"]["caption"]);
		$caption = getImageCaption($row["article_image"]["caption"]);
		$row["article_image"]["caption"] = $caption[0]; //$caption[0]
Peekay
Posts: 286
Joined: Sun 25. Jul 2004, 23:24
Location: UK

Post by Peekay »

Thx DeXXus, but that change alone doesn't work. :(
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Yeah, looking further shows MANY changes in 1.2.8's "front.func.inc.php" regarding all the aspects surrounding captions.
Peekay
Posts: 286
Joined: Sun 25. Jul 2004, 23:24
Location: UK

Post by Peekay »

OK. Fixed it. I modified the conditional statement(s) that use the filename for the 'alt' description if left blank. With the following hack, if you don't enter a specific description you now get alt="".

front.func.inc.php

line 251 replace:

Code: Select all

$caption[1] = empty($caption[1]) ? html_specialchars($image[1]) : html_specialchars($caption[1]);
with:

Code: Select all

$caption[1] = empty($caption[1]) ? html_specialchars($caption[1]) : html_specialchars($caption[1]);
line 418 replace:

Code: Select all

$caption[1] = empty($caption[1]) ? htmlentities($imagelist['images'][$key][1]) : html_specialchars($caption[1]);
with:

Code: Select all

$caption[1] = empty($caption[1]) ?  html_specialchars($caption[1]) : html_specialchars($caption[1]);
I appreciate there may be a better way of changing those functions, but this seems to work (for those that prefer it).
Locked