2016-01-26 14:31:53 +00:00
< ? php
2016-01-30 23:01:42 +00:00
use Lychee\Modules\Album ;
2016-01-30 22:16:42 +00:00
use Lychee\Modules\Database ;
2016-01-30 23:01:42 +00:00
use Lychee\Modules\Photo ;
2016-01-30 22:16:42 +00:00
2016-02-13 16:32:44 +00:00
/**
* @ return array | false Returns an array with albums and photos .
*/
2016-01-26 14:31:53 +00:00
function search ( $term ) {
2016-01-30 20:43:57 +00:00
// Initialize return var
2016-01-26 14:31:53 +00:00
$return = array (
2016-01-30 20:43:57 +00:00
'photos' => null ,
'albums' => null ,
'hash' => ''
2016-01-26 14:31:53 +00:00
);
2016-01-30 20:43:57 +00:00
/**
* Photos
*/
2016-01-26 14:31:53 +00:00
2016-01-30 20:43:57 +00:00
$query = Database :: prepare ( Database :: get (), " SELECT id, title, tags, public, star, album, thumbUrl, takestamp, url FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%' " , array ( LYCHEE_TABLE_PHOTOS , $term , $term , $term ));
2016-01-31 17:49:31 +00:00
$result = Database :: execute ( Database :: get (), $query , __METHOD__ , __LINE__ );
if ( $result === false ) return false ;
2016-01-26 14:31:53 +00:00
while ( $photo = $result -> fetch_assoc ()) {
$photo = Photo :: prepareData ( $photo );
$return [ 'photos' ][ $photo [ 'id' ]] = $photo ;
}
2016-01-30 20:43:57 +00:00
/**
* Albums
*/
2016-01-26 14:31:53 +00:00
2016-01-30 20:43:57 +00:00
$query = Database :: prepare ( Database :: get (), " SELECT id, title, public, sysstamp, password FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' " , array ( LYCHEE_TABLE_ALBUMS , $term , $term ));
2016-01-31 17:49:31 +00:00
$result = Database :: execute ( Database :: get (), $query , __METHOD__ , __LINE__ );
if ( $result === false ) return false ;
2016-01-26 14:31:53 +00:00
while ( $album = $result -> fetch_assoc ()) {
2016-01-30 20:43:57 +00:00
// Turn data from the database into a front-end friendly format
2016-01-26 14:31:53 +00:00
$album = Album :: prepareData ( $album );
2016-01-30 20:43:57 +00:00
// Thumbs
$query = Database :: prepare ( Database :: get (), " SELECT thumbUrl FROM ? WHERE album = '?' " . Settings :: get ()[ 'sortingPhotos' ] . " LIMIT 0, 3 " , array ( LYCHEE_TABLE_PHOTOS , $album [ 'id' ]));
2016-01-31 17:49:31 +00:00
$thumbs = Database :: execute ( Database :: get (), $query , __METHOD__ , __LINE__ );
if ( $thumbs === false ) return false ;
2016-01-26 14:31:53 +00:00
2016-01-30 20:43:57 +00:00
// For each thumb
2016-01-26 14:31:53 +00:00
$k = 0 ;
while ( $thumb = $thumbs -> fetch_object ()) {
$album [ 'thumbs' ][ $k ] = LYCHEE_URL_UPLOADS_THUMB . $thumb -> thumbUrl ;
$k ++ ;
}
2016-01-30 20:43:57 +00:00
// Add to return
2016-01-26 14:31:53 +00:00
$return [ 'albums' ][ $album [ 'id' ]] = $album ;
}
2016-01-30 20:43:57 +00:00
// Hash
2016-01-26 14:31:53 +00:00
$return [ 'hash' ] = md5 ( json_encode ( $return ));
return $return ;
}
?>