Smartor Album: Bildersuche erweitern?

Du hast Probleme beim Einbau oder bei der Benutzung eines Mods? In diesem Forum bist du richtig.
Forumsregeln
phpBB 2.0 hat das Ende seiner Lebenszeit überschritten
phpBB 2.0 wird nicht mehr aktiv unterstützt. Insbesondere werden - auch bei Sicherheitslücken - keine Patches mehr bereitgestellt. Der Einsatz von phpBB 2.0 erfolgt daher auf eigene Gefahr. Wir empfehlen einen Umstieg auf phpBB 3.0, welches aktiv weiterentwickelt wird und für welches regelmäßig Updates zur Verfügung gestellt werden.
Antworten
Benutzeravatar
Dungeonwatcher
Mitglied
Beiträge: 635
Registriert: 11.07.2004 10:04
Wohnort: Berlin

Smartor Album: Bildersuche erweitern?

Beitrag von Dungeonwatcher » 11.12.2009 13:20

Moin! 8)

Mit folgendem Code habe ich mir eine Bildersuche im original Smartor Album 2.0.56a gebaut. Das funktioniert auch bestens. Nun möchte ich aber auch in den Kommentaren suchen lassen.

Dazu muss in der Tabelle album_comment im Tabellenfeld comment_text gesucht werden.

Code: Alles auswählen

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
$album_root_path = $phpbb_root_path . 'album_mod/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_ALBUM);
init_userprefs($userdata);
//
// End session management

if (!$userdata['session_logged_in'] )
{
	redirect(append_sid("login.$phpEx?redirect=album_search.$phpEx", true));
}

$page_title = "Album Search";	
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
include($album_root_path . 'album_common.'.$phpEx);

$template->set_filenames(array(
	'body' =>	'album_search_body.tpl')
);


if (( isset($HTTP_POST_VARS['search']) || isset($HTTP_GET_VARS['search']) ) && ( $HTTP_POST_VARS['search'] != '' || $HTTP_GET_VARS['search'] != '' ))
{
	$template->assign_block_vars('switch_search_results', array());
		
	if ( isset($HTTP_POST_VARS['mode']) )
		$m = $HTTP_POST_VARS['mode'];
	else if ( isset($HTTP_GET_VARS['mode']) )
		$m = $HTTP_GET_VARS['mode'];
	else
		message_die(GENERAL_ERROR, 'Bad request');
			
	if ( isset($HTTP_POST_VARS['search']) )
		$s = $HTTP_POST_VARS['search'];
	else if ( isset($HTTP_GET_VARS['search']) )
		$s = $HTTP_GET_VARS['search'];

	if ($m == 'user')
	{
		$where =    "AND p.pic_username LIKE '%" . $s . "%'";
	}
	elseif ($m == 'name')
	{
		$where =    "AND p.pic_title LIKE '%" . $s . "%'";
	}
	elseif ($m == 'desc')
	{
		$where =    "AND p.pic_desc LIKE '%" . $s . "%'";
	}
	else
	{
		message_die(GENERAL_ERROR, 'Bad request');
	}

	// --------------------------------
	// Pagination
	// --------------------------------

	// Number of matches displayed
	$pics_per_page = $album_config['rows_per_page'] * $album_config['cols_per_page'];

	if (isset ($HTTP_GET_VARS['start']))
	{
		$start = intval($HTTP_GET_VARS['start']);
	}
	elseif (isset ($HTTP_POST_VARS['start']))
	{
		$start = intval($HTTP_POST_VARS['start']);
	}
	else
	{
		$start = 0;
	}	

	// ------------------------------------
	// Count pic matches
	// ------------------------------------

	if ( ($album_config['personal_gallery_view'] == -1) || ($userdata['user_level'] == ADMIN))
	{
		$search_pg = '';
	}
	else
	{
		$search_pg = 'AND c.cat_user_id = 0';
	}
	$limit_sql = ($start == 0) ? $pics_per_page : $start . ',' . $pics_per_page;
	
	$count_sql = "SELECT COUNT(pic_id) AS count
				FROM " . ALBUM_TABLE . ' AS p,' . ALBUM_CAT_TABLE . " AS c
				WHERE p.pic_approval = 1
					" . $where . $search_pg . "
					AND p.pic_cat_id = c.cat_id";

	if( !($result = $db->sql_query($count_sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not count pics'.$m, '', __LINE__, __FILE__, $count_sql);
	}

	$row = $db->sql_fetchrow($result);
	$total_pics = $row['count'];

	$sql = "SELECT p.pic_id, p.pic_title, p.pic_desc, p.pic_user_id, p.pic_user_ip, p.pic_username, p.pic_time, p.pic_cat_id, p.pic_view_count, p.pic_approval, c.cat_id, c.cat_title, c.cat_user_id, p.pic_filename as picfilename, r.rate_pic_id, AVG(r.rate_point) AS rating, COUNT(DISTINCT ct.comment_id) AS comments
			FROM " . ALBUM_TABLE ." AS p
				LEFT JOIN ". ALBUM_CAT_TABLE ." AS c ON p.pic_cat_id = c.cat_id
				LEFT JOIN ". ALBUM_RATE_TABLE ." AS r ON p.pic_id = r.rate_pic_id
				LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS ct ON p.pic_id = ct.comment_pic_id
			WHERE p.pic_approval = 1
				" . $where . "
				AND p.pic_cat_id = c.cat_id
				" . $search_pg . "
				GROUP BY p.pic_id
			ORDER BY p.pic_time ASC LIMIT ".$limit_sql."";
//echo $sql;
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't obtain a list of matching information (searching for: $search)", "", __LINE__, __FILE__, $sql);
	}
		
	$numres = 0;
	
	if ( $picrow = $db->sql_fetchrow($result) )
	{
		$in = array();
		do
		{
			if ( ! in_array($picrow['pic_id'], $in) ) 
			{
			
				// Start add - Pics Dimension/Size Add-on
				$pic_size = getimagesize(ALBUM_UPLOAD_PATH . $picrow['picfilename']);
				$pic_width = $pic_size[0];
				$pic_height = $pic_size[1];

				$pic_size = round(((filesize(ALBUM_UPLOAD_PATH . $picrow['picfilename'])) / 1024), 2) . ' ' . $lang['Kb'];
				// End add - Pics Dimension/Size Add-on
				
				if(!$picrow['rating'])
				{
					$picrow['rating'] = $lang['Not_rated'];
				}
				else
				{
					$picrow['rating'] = round($picrow['rating'], 2);
				}

				$template->assign_block_vars('switch_search_results.pic_detail', array(
					'L_USERNAME'		=> $picrow['pic_username'],
					'U_PROFILE'			=> append_sid('profile.php?mode=viewprofile&u=' . $picrow['pic_user_id']),
					'L_CAT'				=> ($picrow['cat_user_id'] != ALBUM_PUBLIC_GALLERY ) ? 'User personal' : $picrow['cat_title'],
					'VIEW'				=> $picrow['pic_view_count'],
					'PIC_ID'			=> $picrow['pic_id'],
					'SIZE'				=> $pic_size,
					'DIMENSIONS'		=> $pic_width . ' x ' . $pic_height,
					'TITLE'				=> $picrow['pic_title'],
					'U_PIC'				=> append_sid('album_page.php?pic_id=' . $picrow['pic_id']),
					'THUMBNAIL'			=> append_sid('album_thumbnail.'. $phpEx . '?pic_id=' . $picrow['pic_id']),
					'DESC'				=> $picrow['pic_desc'],
					'TIME'				=> create_date($board_config['default_dateformat'], $picrow['pic_time'], $board_config['board_timezone'], 0),
					'RATING'			=> ($album_config['rate'] == 1) ? ( '<a href="'. append_sid("album_rate.$phpEx?pic_id=". $picrow['pic_id']) . '">' . $lang['Rating'] . '</a>: ' . $picrow['rating'] . '<br />') : '',
					'COMMENTS'			=> ($album_config['comment'] == 1) ? ( '<a href="'. append_sid("album_comment.$phpEx?pic_id=". $picrow['pic_id']) . '">' . $lang['Comments'] . '</a>: ' . $picrow['comments'] . '<br />') : '',
					'IP'				=> ($userdata['user_level'] == ADMIN) ? $lang['IP_Address'] . ': <a href="http://www.ripe.net/fcgi-bin/whois?form_type=simple&full_query_string=&searchtext=' . decode_ip($picrow['pic_user_ip']) . '" target="_blank">' . decode_ip($picrow['pic_user_ip']) .'</a><br />' : '',
					'EDIT'				=> ( ($userdata['user_level'] == ADMIN) or ($userdata['user_id'] == $picrow['pic_user_id']) ) ? '<a href="'. append_sid("album_edit.$phpEx?pic_id=". $picrow['pic_id']) . '">' . $lang['Edit_pic'] . '</a>' : '',
					'DELETE'			=> ( ($userdata['user_level'] == ADMIN) or ($userdata['user_id'] == $picrow['pic_user_id']) ) ? '<a href="'. append_sid("album_delete.$phpEx?pic_id=". $picrow['pic_id']) . '">' . $lang['Delete_pic'] . '</a>' : '',
					'MOVE'				=> ( ($userdata['user_level'] == ADMIN) or ($userdata['user_id'] == $picrow['pic_user_id']) ) ? '<a href="'. append_sid("album_modcp.$phpEx?mode=move&pic_id=". $picrow['pic_id']) .'">' . $lang['Move'] . '</a>' : '',
					'LOCK'				=> ($userdata['user_level'] == ADMIN) ? '<a href="'. append_sid("album_modcp.$phpEx?mode=". (($picrow['pic_lock'] == 0) ? 'lock' : 'unlock') ."&pic_id=". $picrow['pic_id']) .'">'. (($picrow['pic_lock'] == 0) ? $lang['Lock'] : $lang['Unlock']) .'</a>' : '',
				));
					
				$in[$numres] = $picrow['pic_id'];
				$numres++;
			}
		}
		while( $picrow = $db->sql_fetchrow($result) );

		$template->assign_vars(array(
			'L_RESULTS'			=> $lang['Results'],
			'L_NRESULTS'		=> $total_pics,
			'L_CATEGORY'		=> $lang['Category'],
			'L_PIC_TITLE'		=> $lang['Pic_Title'],
			'L_PICS'			=> $lang['Pics'],
			'L_POSTER'			=> $lang['Poster'],
			'L_POSTED'			=> $lang['Posted'],
			'L_SIZE'			=> $lang['Size'],
			'L_VIEW'			=> $lang['View'],
			'L_DIMENSION'		=> $lang['Dimension'],
			'SIZE'				=> $pic_size,
			'DIMENSIONS'		=> $pic_width . ' x ' . $pic_height,
			'L_ALBUM_SEARCH'	=> $lang['Album_Search'],
			'U_ALBUM_SEARCH'	=> append_sid("album_search.$phpEx"),
		));
		
		$template->assign_vars(array(
			'PAGINATION'	=> generate_pagination(append_sid("album_search." . $phpEx . "?mode=" . $m . "&search=" . $s), $total_pics, $pics_per_page, $start),
			'PAGE_NUMBER'	=> sprintf($lang['Page_of'], (floor($start / $pics_per_page) + 1), ceil($total_pics / $pics_per_page))
		));
	}
	else
	{
		message_die(GENERAL_MESSAGE, $lang['No_search_match_album'] . '<br /><br />' . sprintf($lang['Click_return_album_search'], "<a href=\"" . append_sid("album_search.$phpEx") . "\">", "</a>"));
	}
}
else
{
	$template->assign_block_vars('switch_search', array());
}

$template->assign_vars(array(
	'L_ALBUM_SEARCH'	=> $lang['Album_Search'],
	'L_USER_NAME'		=> $lang['User_Name'],
	'L_PIC_DESC'		=> $lang['Pic_Desc'],
	'L_PIC_NAME'		=> $lang['Pic_Name'],
	'L_PIC_COMMENT'		=> $lang['Comments'],
	'L_PIC_ID'			=> $lang['Pic_id'],
	'L_PIC_TITLE_DESC'	=> $lang['Pic_Title_Desc'],
	'L_SEARCH_1'		=> $lang['Search_Text_1'],
	'L_SEARCH_2'		=> $lang['Search_Text_2'],
	'L_SEARCH_3'		=> $lang['Search_Text_3'],
	'S_COLS'			=> $album_config['cols_per_page'],
	'S_COL_WIDTH'		=> (100/$album_config['cols_per_page']) . '%'
));


$template->pparse('body');
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
	
// +-------------------------------------------------------------+
// |  Powered by Photo Album 2.x.x (c) 2002-2003 Smartor         |
// |  with Volodymyr (CLowN) Skoryk's Service Pack 1 © 2003-2004 |
// +-------------------------------------------------------------+
		
?>
Dazu habe ich folgendes versucht:

Code: Alles auswählen

	if ($m == 'user')
	{
		$where =    "AND p.pic_username LIKE '%" . $s . "%'";
	}
	elseif ($m == 'name')
	{
		$where =    "AND p.pic_title LIKE '%" . $s . "%'";
	}
	elseif ($m == 'desc')
	{
		$where =    "AND p.pic_desc LIKE '%" . $s . "%'";
	}
	{
		$where =    "AND ct.comment_text LIKE '%" . $s . "%'";
	}
	else
	{
		message_die(GENERAL_ERROR, 'Bad request');
	}
Damit wird dann aber nicht in den Kommentaren sondern in der Bildbeschreibung, dem Bildernamen und den Usernamen gesucht. :-?

Was mache ich falsch bzw. habe ich vergessen?

Bye

Antworten

Zurück zu „phpBB 2.0: Mod Support“