Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
define('ROOT', dirname(__DIR__));
define('IMG_BIG', $_SERVER['DOCUMENT_ROOT'] . '/images/gallery_img/big/');
define('IMG_SMALL', $_SERVER['DOCUMENT_ROOT'] . '/images/gallery_img/small/');
define('TEMPLATES_DIR', ROOT . '/templates/');
define('LAYOUTS_DIR', 'layouts/');

include ROOT . "/engine/functions.php";
include ROOT . "/engine/log.php";
include ROOT . "/engine/gallery.php";
include ROOT . "/engine/classSimpleImage.php";
85 changes: 85 additions & 0 deletions engine/classSimpleImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/

class SimpleImage {

var $image;
var $image_type;

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
26 changes: 26 additions & 0 deletions engine/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

function render($page, $params = [], $layout = 'main'){
return renderTemplate(LAYOUTS_DIR . $layout, [
'content' => renderTemplate($page, $params),
'menu' => renderTemplate('menu'),
]
);
}

function renderTemplate($page, $params = []){
ob_start();

if (!is_null($params))
extract($params);

$fileName = TEMPLATES_DIR . $page . ".php";

if (file_exists($fileName)) {
include $fileName;
} else {
Die("Страницы {$fileName} не существует.");
}

return ob_get_clean();
}
40 changes: 40 additions & 0 deletions engine/gallery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
function getGallery($path){
return $images = array_splice(scandir($path), 2);
}

function uploadImage(){
$path_big = IMG_BIG . $_FILES['image']['name'];
$path_small = IMG_SMALL . $_FILES['image']['name'];

$image_info = getimagesize($_FILES['image']['tmp_name']);

if ($image_info['mime'] != 'image/png' && $image_info['mime'] != 'image/gif' && $image_info['mime'] != 'image/jpeg') {
echo "Можно загружать только jpg/png/gif/jpeg - файлы<br>";
exit;
}

if ($_FILES['image']['size'] > 1024 * 5 * 1024) {
echo "Размер файла не более 5 Мб<br>";
exit;
}

$blacklist = ['.php', '.phtml', '.php3', '.php4'];
foreach ($blacklist as $item) {
if(preg_match("/$item\$/i", $_FILES['image']['name'])){
echo "Загрузка php-файлов запрещена<br>";
exit;
}
}

if (move_uploaded_file($_FILES['image']['tmp_name'], $path_big)) {

$image = new SimpleImage();
$image->load($path_big);
$image->resizeToWidth(250);
$image->save($path_small);
header("Location: /?page=gallery");
} else {
echo "Ошибка ресайза файла<br>";
}
}
Empty file added engine/log.php
Empty file.
Binary file added public/images/gallery_img/big/n_70.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/big/n_72.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/big/n_73.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/big/n_76.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/big/n_82.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/big/n_95.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_70.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_72.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_73.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_76.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_82.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/gallery_img/small/n_95.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

include $_SERVER['$DOCUMENT_ROOT'] . "../config/config.php";

if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 'index';
}

$params = [];
$layout = 'main';

switch ($page) {
case 'index':
break;
case 'gallery':

if(isset($_POST['load'])){
uploadImage();
}

$layout = 'gallery';
$params['gallery'] = getGallery(IMG_BIG);
break;
case 'homework_3':
$layout = 'homework_3';
break;
}
// _log($params, 'params');
echo render($page, $params, $layout);
10 changes: 10 additions & 0 deletions public/js/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const block = document.querySelector('.gallery_wrapper');

function handleEvents() {
block.addEventListener('click', (e) => {
if (e.target.classList.contains('gallery_img')) {
e.target.classList.toggle('active');
}
});
}
handleEvents();
Loading