Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Fixes CSS & small/medium Size
Browse files Browse the repository at this point in the history
Fixes #154
Fixes #152
Fixes #149
Fixes #51
  • Loading branch information
ildyria committed Dec 26, 2018
1 parent 3499998 commit f6a1233
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ uploads/medium/*
uploads/small/*
uploads/thumb/*

dist/user.css

!uploads/big/index.html
!uploads/import/index.html
!uploads/medium/index.html
Expand Down
23 changes: 23 additions & 0 deletions php/Access/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static function init($fn) {
case 'Settings::setLogin': self::setLoginAction(); break;
case 'Settings::setSorting': self::setSortingAction(); break;
case 'Settings::setDropboxKey': self::setDropboxKeyAction(); break;
case 'Settings::setCSS': self::setCSS(); break;
case 'Settings::getAll': self::getAll(); break;
case 'Settings::saveAll': self::saveAll(); break;
case 'phpinfo': phpinfo(); exit;

// $_GET functions
Expand Down Expand Up @@ -400,4 +403,24 @@ private static function genSmall() {
Small::run($nb, $from, $timeout);

}

private static function setCSS() {

echo (Settings::setCSS($_POST['css']) ? 'true' : 'false');
exit();
}

private static function getAll() {

return Response::json(Settings::getAll());

}

private static function saveAll() {

echo (Settings::saveAll() ? 'true' : 'false');
exit();

}

}
4 changes: 2 additions & 2 deletions php/Modules/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ public function add(array $files, $albumID = 0, $returnOnError = false) {
}

// Create Medium
if (Photo::createMedium($path, $photo_name, $info['type'], $info['width'], $info['height'])) $medium = 1;
if (Photo::createMedium($path, $photo_name, $info['type'], $info['width'], $info['height'], Settings::get()['medium_max_width'], Settings::get()['medium_max_height'])) $medium = 1;
else $medium = 0;
// Create Small
if (Photo::createMedium($path, $photo_name, $info['type'], $info['width'], $info['height'], 0, 360, 'SMALL')) $small = 1;
if (Photo::createMedium($path, $photo_name, $info['type'], $info['width'], $info['height'], Settings::get()['small_max_width'], Settings::get()['small_max_height'], 'SMALL')) $small = 1;
else $small = 0;
}

Expand Down
46 changes: 46 additions & 0 deletions php/Modules/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,44 @@ public static function get() {

}

/**
* @return array Returns the settings of Lychee.
*/
public static function getAll() {

// Execute query
$query = Database::prepare(Database::get(), "SELECT * FROM ?", array(LYCHEE_TABLE_SETTINGS));
$settings = Database::execute(Database::get(), $query, __METHOD__, __LINE__);

// Add each to return
$return = array();
// while ($setting = $settings->fetch_object()) $return[$setting->key] = $setting->value;
while($setting = $settings->fetch_array())
{
$return[] = $setting;
}

return $return;

}


public static function saveAll() {

$no_error = true;
foreach ($_POST as $key => $value) {
if($key != 'function')
{
$no_error &= self::set($key,$value);
}
}

return $no_error;

}



/**
* @return boolean Returns true when successful.
*/
Expand Down Expand Up @@ -61,6 +99,14 @@ private static function set($key, $value, $row = false) {

}


public function setCSS($css)
{
file_put_contents(__DIR__ . '/../../dist/user.css',$css);
return true;
}


/**
* Sets the username and password when current password is correct.
* Exits on error.
Expand Down
55 changes: 55 additions & 0 deletions php/database/update_030208.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* Update to version 3.2.8
*/

use Lychee\Modules\Database;
use Lychee\Modules\Response;

$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'small_max_width' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not get current small_max_width from database!');
if ($result->num_rows===0) {
$query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('small_max_width', '0')", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not add small_max_width to database!');
}
if ($result===false) Response::error('Could not add small_max_width!');

$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'small_max_height' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not get current small_max_height from database!');
if ($result->num_rows===0) {
$query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('small_max_height', '360')", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not add small_max_height to database!');
}
if ($result===false) Response::error('Could not add small_max_height!');

$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'medium_max_width' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not get current medium_max_width from database!');
if ($result->num_rows===0) {
$query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('medium_max_width', '1920')", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not add medium_max_width to database!');
}
if ($result===false) Response::error('Could not add medium_max_width!');

$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'medium_max_height' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not get current medium_max_height from database!');
if ($result->num_rows===0) {
$query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('medium_max_height', '1080')", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030208', __LINE__);
if ($result===false) Response::error('Could not add medium_max_height to database!');
}
if ($result===false) Response::error('Could not add small_max_height!');

// and create the files :)
chmod(__DIR__ . '/../../dist/', 775);
touch(__DIR__ . '/../../dist/user.css');

// Set version
if (Database::setVersion($connection, 'update_030208')===false) Response::error('Could not update version of database!');

0 comments on commit f6a1233

Please sign in to comment.