image/description replacement within file_list

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

image/description replacement within file_list

Post by pSouper »

Hey all,

I had a need to write this mod, I tihnk some of you may use it too....

I have modified the file_list (cnt7.article.inc.php) so that you may replace the file link with an image. the description is still available too should you need it.

to use it you should replace the code snippet that looks most like this one (between lines 51 and 80) with this one ;)

Code: Select all

//CODE SNIPPET DERIVED FROM VERSION V.1.2.6 - changes made to this file on later versions will not be included within this snippet.
// AUTHOR: pSouper
// MODIFICATION: modified to include 'bar seperated' file detail to image replacement similar to that within the images content part.
// INSTALATION: cut & paste to replace code between lines 51&80 of file: include\inc_front\content\cnt7.article.inc.php
// USAGE: add files to the file list then in the description filed type your caption then | filename.ext (files are reletive the the pictures dir)
// EXAMPLE: this is my description for file 1 | file1.gif		if($file_result = mysql_query($file_sql, $db) or die ("error while retrieving file list file's info")) {
			
			$file_text   = explode("\n", $crow["acontent_text"]);
			$file_class1 = get_class_attrib($template_default["article"]["file_name_cell_class"]);
			$file_class2 = get_class_attrib($template_default["article"]["file_size_cell_class"]);
			$file_class3 = get_class_attrib($template_default["article"]["file_size_info_class"]);

			while($file_row = mysql_fetch_assoc($file_result)) {
				
				foreach($fxb as $key => $value) {
					
					if($fxb[$key]["fid"] == $file_row["f_id"]) {
						if(isset($file_text[$key]) && trim($file_text[$key]) != '') {
							$str = trim(html_specialchars($file_text[$key]));
							$str = explode("|", $str);
							$file_text[$key] = $str[0];
							if (file_exists("./picture/".$str[1])){
							$img = '<img src="./picture/'.$str[1].'" border="0" alt="'.$str[1].'">';
							}
							else {
							$img ='>file: '.$str[1].'does not exist; in the ./picture directory.';
							}
							if (count($str) > 1) {
								$file_tmp  = '<tr><td>';
								$file_tmp .= spacer(3,1).'</td><td'.$file_class1.'>';
								$file_tmp .= '<a href="download.php?'.$file_row["f_hash"].'" title="'.$file_name.'" ';
								$file_tmp .= 'target="_blank"'.$img.'</a></td><td align="right"'.$file_class2."</td></tr>\n";//Jayenne: removed file size
								$file_tmp .= '<tr><td>'.spacer(1,1).'</td><td'.$file_class3.' colspan="2">'.$file_text[$key]."</td></tr><br>\n";						
							}
							else {
							$file_name = html_specialchars($file_row["f_name"]);
							$file_tmp  = '<tr><td><img src="img/icons/small_'.extimg($file_row["f_ext"]).'" border="0" alt="">';
							$file_tmp .= spacer(3,1).'</td><td'.$file_class1.'>';
							$file_tmp .= '<a href="download.php?'.$file_row["f_hash"].'" title="'.$file_name.'" ';
							$file_tmp .= 'target="_blank">'.$file_name.'</a></td><td align="right"'.$file_class2."</td></tr>\n";//Jayenne: removed file size
							}
							if(isset($file_text[$key]) && trim($file_text[$key]) != '') {
							$file_tmp .= '<tr><td>'.spacer(1,1).'</td><td'.$file_class3.' colspan="2">'.$file_text[$key]."</td></tr>\n";						
						}
						$fxc[$key] = $file_tmp;
						}
					}
				}
			}
			mysql_free_result($file_result);
		}
	}
//END OF MOD
(I know some guys will freak at my slack advice for adding &using this and others may freak at my code but I have other stuff to do too :)

if this is too tricky or you are feeling brave you can download the whole file and replace your current one cnt7.article.inc.php
rembembe this code was derived from that of version 1.2.6 so changes in later version installations are possible and likley.
Post Reply