2014-01-22 10:12:51 +00:00
< ? php
/**
2014-02-17 16:01:46 +00:00
* @ name Misc Module
* @ author Philipp Maurer
* @ author Tobias Reich
* @ copyright 2014 by Philipp Maurer , Tobias Reich
2014-01-22 10:12:51 +00:00
*/
if ( ! defined ( 'LYCHEE' )) exit ( 'Error: Direct access is not allowed!' );
function openGraphHeader ( $photoID ) {
global $database ;
2014-02-17 16:01:46 +00:00
2014-02-09 21:30:16 +00:00
$photoID = mysqli_real_escape_string ( $database , $photoID );
2014-02-17 16:01:46 +00:00
2014-02-10 17:04:34 +00:00
$result = $database -> query ( " SELECT title, description, url FROM lychee_photos WHERE id = ' $photoID '; " );
2014-02-09 21:30:16 +00:00
$row = $result -> fetch_object ();
2014-02-17 16:01:46 +00:00
2014-02-27 20:51:12 +00:00
$parseUrl = parse_url ( " http:// " . $_SERVER [ 'HTTP_HOST' ] . $_SERVER [ 'REQUEST_URI' ]);
$picture = $parseUrl [ 'scheme' ] . " :// " . $parseUrl [ 'host' ] . $parseUrl [ 'path' ] . " /../uploads/big/ " . $row -> url ;
2014-02-17 16:01:46 +00:00
$return = '<!-- General Meta Data -->' ;
2014-01-22 10:12:51 +00:00
$return .= '<meta name="title" content="' . $row -> title . '" />' ;
$return .= '<meta name="description" content="' . $row -> description . ' - via Lychee" />' ;
2014-02-17 16:01:46 +00:00
$return .= '<link rel="image_src" type="image/jpeg" href="' . $picture . '" />' ;
2014-01-22 10:12:51 +00:00
$return .= '<!-- Twitter Meta Data -->' ;
$return .= '<meta name="twitter:card" content="photo">' ;
$return .= '<meta name="twitter:title" content="' . $row -> title . '">' ;
$return .= '<meta name="twitter:image:src" content="' . $picture . '">' ;
2014-02-17 16:01:46 +00:00
2014-01-22 10:12:51 +00:00
$return .= '<!-- Facebook Meta Data -->' ;
$return .= '<meta property="og:title" content="' . $row -> title . '">' ;
$return .= '<meta property="og:image" content="' . $picture . '">' ;
2014-02-17 16:01:46 +00:00
2014-02-09 21:30:16 +00:00
return $return ;
2014-01-22 10:12:51 +00:00
}
function search ( $term ) {
global $database , $settings ;
2014-02-09 21:30:16 +00:00
$return [ 'albums' ] = '' ;
2014-01-22 10:12:51 +00:00
2014-02-09 21:30:16 +00:00
// Photos
2014-02-17 16:01:46 +00:00
$result = $database -> query ( " SELECT id, title, tags, sysdate, public, star, album, thumbUrl FROM lychee_photos WHERE title like '% $term %' OR description like '% $term %' OR tags like '% $term %'; " );
2014-03-20 13:52:54 +00:00
while ( $row = $result -> fetch_assoc ()) {
2014-02-17 16:01:46 +00:00
$return [ 'photos' ][ $row [ 'id' ]] = $row ;
$return [ 'photos' ][ $row [ 'id' ]][ 'sysdate' ] = date ( 'd F Y' , strtotime ( $row [ 'sysdate' ]));
}
2014-01-22 10:12:51 +00:00
2014-02-09 21:30:16 +00:00
// Albums
2014-02-17 16:01:46 +00:00
$result = $database -> query ( " SELECT id, title, public, sysdate, password FROM lychee_albums WHERE title like '% $term %' OR description like '% $term %'; " );
$i = 0 ;
while ( $row = $result -> fetch_object ()) {
2014-01-22 10:12:51 +00:00
2014-02-09 21:30:16 +00:00
// Info
2014-02-17 16:01:46 +00:00
$return [ 'albums' ][ $row -> id ][ 'id' ] = $row -> id ;
$return [ 'albums' ][ $row -> id ][ 'title' ] = $row -> title ;
$return [ 'albums' ][ $row -> id ][ 'public' ] = $row -> public ;
$return [ 'albums' ][ $row -> id ][ 'sysdate' ] = date ( 'F Y' , strtotime ( $row -> sysdate ));
$return [ 'albums' ][ $row -> id ][ 'password' ] = ( $row -> password == '' ? false : true );
2014-01-22 10:12:51 +00:00
2014-02-09 21:30:16 +00:00
// Thumbs
2014-02-17 16:01:46 +00:00
$result2 = $database -> query ( " SELECT thumbUrl FROM lychee_photos WHERE album = ' " . $row -> id . " ' " . $settings [ 'sorting' ] . " LIMIT 0, 3; " );
$k = 0 ;
while ( $row2 = $result2 -> fetch_object ()){
$return [ 'albums' ][ $row -> id ][ " thumb $k " ] = $row2 -> thumbUrl ;
$k ++ ;
}
2014-01-22 10:12:51 +00:00
2014-02-17 16:01:46 +00:00
$i ++ ;
2014-01-22 10:12:51 +00:00
2014-02-17 16:01:46 +00:00
}
return $return ;
2014-01-22 10:12:51 +00:00
}
2014-02-23 18:41:12 +00:00
function update ( $version = '' ) {
2014-01-22 10:12:51 +00:00
2014-02-23 18:41:12 +00:00
global $database , $configVersion ;
2014-01-22 10:12:51 +00:00
2014-02-23 18:41:12 +00:00
// Albums
2014-02-17 16:01:46 +00:00
if ( ! $database -> query ( " SELECT `public` FROM `lychee_albums` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_albums` ADD `public` TINYINT( 1 ) NOT NULL DEFAULT '0' " );
if ( ! $database -> query ( " SELECT `password` FROM `lychee_albums` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_albums` ADD `password` VARCHAR( 100 ) NULL DEFAULT '' " );
if ( ! $database -> query ( " SELECT `description` FROM `lychee_albums` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_albums` ADD `description` VARCHAR( 1000 ) NULL DEFAULT '' " );
if ( $database -> query ( " SELECT `password` FROM `lychee_albums` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_albums` CHANGE `password` `password` VARCHAR( 100 ) NULL DEFAULT '' " );
2014-01-22 10:12:51 +00:00
2014-02-23 18:41:12 +00:00
// Photos
2014-02-17 16:01:46 +00:00
if ( $database -> query ( " SELECT `description` FROM `lychee_photos` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_photos` CHANGE `description` `description` VARCHAR( 1000 ) NULL DEFAULT '' " );
if ( ! $database -> query ( " SELECT `tags` FROM `lychee_photos` LIMIT 1; " )) $database -> query ( " ALTER TABLE `lychee_photos` ADD `tags` VARCHAR( 1000 ) NULL DEFAULT '' " );
2014-01-22 10:12:51 +00:00
$database -> query ( " UPDATE `lychee_photos` SET url = replace(url, 'uploads/big/', ''), thumbUrl = replace(thumbUrl, 'uploads/thumb/', '') " );
2014-02-23 18:41:12 +00:00
// Settings
$result = $database -> query ( " SELECT `key` FROM `lychee_settings` WHERE `key` = 'dropboxKey' LIMIT 1; " );
if ( $result -> num_rows === 0 ) $database -> query ( " INSERT INTO `lychee_settings` (`key`, `value`) VALUES ('dropboxKey', '') " );
// Config
if ( $version !== '' && $configVersion !== $version ) {
$data = file_get_contents ( '../data/config.php' );
$data = preg_replace ( '/\$configVersion = \'[\w. ]*\';/' , " \$ configVersion = ' $version '; " , $data );
2014-02-27 20:51:12 +00:00
if ( file_put_contents ( '../data/config.php' , $data ) === false ) return 'Error: Could not save updated config!' ;
2014-02-23 18:41:12 +00:00
}
2014-01-22 10:12:51 +00:00
return true ;
}
?>