app->default["bordercolor"]; $thumbSize = $gallery->app->default["thumb_size"]; if ($gallery->app->showSearchEngine == 'no' && !$gallery->user->isAdmin()) { header('Location: ' . makeAlbumURL()); return; } if (!$GALLERY_EMBEDDED_INSIDE) { doctype(); ?> <?php echo $gallery->app->galleryTitle ?> :: <?php echo _("Search") ?> '. gTranslate('core', "Search") .''; $adminbox['commands'] = '['. _("Return to gallery") .'] '; $breadcrumb["text"][] = _("Gallery") .': '.$gallery->app->galleryTitle .''; includeLayout('navtablebegin.inc'); includeLayout('adminbox.inc'); includeLayout('navtablemiddle.inc'); includeLayout('breadcrumb.inc'); includeLayout('navtableend.inc'); echo languageSelector(); $albumDB = new AlbumDB(); $list = $albumDB->albumList; $numAlbums = count($list); $photoMatch = 0; $albumMatch = 0; $skip = array(); $text = array(); if (!empty($searchstring)) { $origstr = $searchstring; $searchstring = escapeEregChars($searchstring); $searchstring = str_replace ("\\*", ".*", $searchstring); $searchExpr = "{(]*{$searchstring}[^<>]*>)(.*(?=))()|({$searchstring})}Usi"; $searchRepl = '\1\2\4\3'; $uid = $gallery->user->getUid(); for ($i = 0; $i<$numAlbums; $i++) { $searchAlbum = $list[$i]; if (!$gallery->user->isAdmin() && $searchAlbum->isHiddenRecurse()) { // One of the parents of this album is hidden - do not show it to users continue; } if (!$gallery->user->isAdmin() && !$searchAlbum->canReadRecurse($uid)) { // User is not allowed to search through see album continue; } if ($searchAlbum->versionOutOfDate()) { $skip[] = $searchAlbum; continue; } // Build navigationslinks to the album. $parentNameArray = $searchAlbum->getParentAlbums(false); $parentURLString = ''; if(count($parentNameArray) != 0) { foreach($parentNameArray as $nr => $pAlbum) { $parentURLString .= '' .$pAlbum['title'] .' » '; } } // initialize values unset($text); $searchTitle = $searchAlbum->fields['title']; $searchDescription = $searchAlbum->fields['description']; $searchSummary = $searchAlbum->fields['summary']; $searchName = $searchAlbum->fields['name']; $matchTitle = eregi("$searchstring", $searchTitle); $matchDescription = eregi("$searchstring", $searchDescription); $matchSummary = eregi("$searchstring", $searchSummary); $matchName = eregi("$searchstring", $searchName); if ($matchTitle || $matchDescription || $matchSummary | $matchName) { $searchTitle = preg_replace($searchExpr, $searchRepl, $searchTitle); // cause search word to be bolded $searchDescription = preg_replace($searchExpr, $searchRepl, $searchDescription); // cause search word to be bolded $searchSummary = preg_replace($searchExpr, $searchRepl, $searchSummary); // cause search word to be bolded $photoURL = makeAlbumUrl($searchAlbum->fields['name']); $text[] = '
'. $searchTitle .'
'; if(!empty($searchDescription)) { $text[] = '
'. $searchDescription . '
'; } if ($matchSummary) { // only print summary if it matches $text[] = '
'. $searchSummary .'
'; } $searchResult['albums'][]=array( 'photolink' => $searchAlbum->getHighlightTag($thumbSize), 'photoURL' => $photoURL, 'Text' => $text ); } /* now search for photos .. */ $numPhotos = $searchAlbum->numPhotos(1); for ($j = 1; $j <= $numPhotos; $j++) { if ($searchAlbum->isHidden($j)) { continue; } $photo = $searchAlbum->getPhoto($j); /* Search through comments */ $commentMatch = 0; $commentText = ''; if ($searchAlbum->canViewComments($uid) || $gallery->user->isAdmin()) { for ($k = 1; $k <= $searchAlbum->numComments($j); $k++) { // check to see if there are any comment matches $comment = $searchAlbum->getComment($j, $k); $searchComment = $comment->getName(); if ($gallery->user->isAdmin()) { $searchComment .= " @ ".$comment->getIPNumber(); } $searchComment .= ": ".$comment->getCommentText(); if (eregi($searchstring, $searchComment)) { if (!$commentMatch) { $commentText = _("Matching Comments").":
"; $commentMatch = 1; } $searchComment = preg_replace($searchExpr, $searchRepl, $searchComment); $commentText .= "\n". $searchComment . "

"; } } } /* Search through extrafields */ $extraFieldsMatch = 0; $extraFieldsText = ''; foreach ($searchAlbum->getExtraFields() as $field) { $fieldValue=$searchAlbum->getExtraField($j, $field); if (eregi($searchstring, $fieldValue)) { $fieldValue = preg_replace($searchExpr, $searchRepl, $fieldValue); $extraFieldsText .= "$field: $fieldValue

"; $extraFieldsMatch = 1; } } /* Search through caption */ $searchCaption = _("Caption: ") . $photo->getCaption(); $searchCaption .= $searchAlbum->getCaptionName($j); $captionMatch = eregi($searchstring, $searchCaption); /* Search through keywords */ $searchKeywords = $photo->getKeywords(); if(!empty($searchKeywords)) { $keywordMatch = eregi($searchstring, $searchKeywords); } else { $keywordMatch = false; } /* Search through imagename */ if(!empty($photo->image->name)) { $searchName = $photo->image->name; $nameMatch = eregi($searchstring, $searchName); } else { $nameMatch = false; } unset($text); if ($captionMatch || $keywordMatch || $commentMatch || $extraFieldsMatch || $nameMatch) { $id = $searchAlbum->getPhotoId($j); // cause search word to be bolded $searchCaption = preg_replace($searchExpr, $searchRepl, $searchCaption); $searchKeywords = preg_replace($searchExpr, $searchRepl, $searchKeywords); $text[] = '
'. _("From Album") .":  ". $parentURLString . "fields['name']) . "\">" . $searchAlbum->fields['title'] . "
"; $text[] = '
'. $searchCaption .'
'; if ($keywordMatch) { // only display Keywords if there was a keyword match $text[] = '
'. _("KEYWORDS") .":   $searchKeywords

"; } $text[] = $commentText; $text[] = $extraFieldsText; $searchResult['images'][]=array( 'photolink' => $searchAlbum->getThumbnailTag($j, $thumbSize), 'photoURL' => makeAlbumUrl($searchAlbum->fields['name'], $id), 'Text' => $text ); } } } /* Now we show what we found ;) */ $resultTexts = array( 'albums' => array( 'found' => sprintf(_("Albums containing %s"), "\"$origstr\""), 'none' => _("No Album Matches") ), 'images' => array( 'found' => sprintf(_("Photos containing %s in caption, comment or name."), "\"$origstr\""), 'none' => _("No Photo Matches") ) ); foreach ($resultTexts as $key => $text) { if (!empty($searchResult[$key])) { echo '
' .$text['found'] . '
'; echo ''; foreach ($searchResult[$key] as $searchdraw) { $searchdraw["bordercolor"] = $borderColor; $searchdraw["top"] = true; includeLayout('searchdraw.inc'); } echo '
'; } else { echo '
'. $text['none'] . '
'; } } if (sizeof($skip) > 0) { echo gallery_error(sprintf(_("Some albums not searched as they require upgrading to the latest version of %s first."),Gallery())); if ($gallery->user->isAdmin()) { print "
"; echo popup_link(_("Upgrade all albums."), "upgrade_album.php"); print "
("; $join_text=''; foreach($skip as $album) { $link = makeGalleryUrl("view_album.php", array("set_albumName" => $album->fields["name"])); echo $join_text."".$album->fields["name"] .""; $join_text=", "; } print ")"; } echo "

"; } } else { /* No searchstring was given */ echo "\n

"; echo _("Search the Gallery's Album and Photo titles, descriptions and comments."); echo "\n
"; echo addSearchForm($searchstring, 'center'); echo "
"; } echo '
'; includeHtmlWrap("gallery.footer"); if (!$GALLERY_EMBEDDED_INSIDE) { ?>