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
21 changes: 21 additions & 0 deletions php1.loc/.idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions php1.loc/HW_5/.idea/HW_4.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions php1.loc/HW_5/.idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions php1.loc/HW_5/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
define('DIR_ROOT', $_SERVER['DOCUMENT_ROOT']);
define('TEMPLATES_DIR', DIR_ROOT . '/../templates/');
define('LAYOUTS_DIR', TEMPLATES_DIR . 'layouts/');
define('IMAGES_DIR', './images/');
define('GALLERY_NAME', 'gallery_img');
define('HOW_MANY_IMAGES_TO_SHOW', 4);

/* DB config */
define('HOST', 'localhost');
define('USER', 'batov_test');
define('PASS', '12345');
define('DB', 'batov_test');

require_once DIR_ROOT . "/../engine/functions.php";
require_once DIR_ROOT . "/../engine/log.php";
require_once DIR_ROOT . "/../engine/gallery.php";
require_once DIR_ROOT . "/../engine/img_edit.php";
require_once DIR_ROOT . "/../engine/db.php";
87 changes: 87 additions & 0 deletions php1.loc/HW_5/engine/classSimpleImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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;
}
}
?>

71 changes: 71 additions & 0 deletions php1.loc/HW_5/engine/db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/*
* Функция, осуществляющая соединение с базой данных и возвращающее его
* static позволяет сохранить состояние и вернуть уже текущее соединение
* чтобы не делать нового
*/

function dumpLoad() {
//Автоматическая загрузка дампа в БД
$db = getDb();
$result = mysqli_query($db, "SHOW TABLES FROM " . DB);
if (mysqli_num_rows($result) === 0) {
$dump = file_get_contents("batov_test.sql");

$a = 0;
while ($b = strpos($dump, ";", $a + 1)) {
$a = substr($dump, $a + 1, $b - $a);
mysqli_query($db, $a);
$a = $b;
}
var_dump("Дамп загружен!");
}
}

function getDb() {

static $db = null;

if (is_null($db)) {
$db = @mysqli_connect(HOST, USER, PASS, DB) or die("Could not connect: " . mysqli_connect_error());
}

return $db;
}

//При желании можно закрыть соединение (если уж и вызывать, то после render на главной)
function closeDb() {
mysqli_close(getDb());
}

/*
* Обертка для выполнения любого запроса
* Передаем в параметре текст sql-запроса
* Возвращаем результат, в основном использовать для
* операций update и delete, которые не требуют возврата данных
*/
function executeQuery($sql)
{
$db = getDb();

$result = @mysqli_query($db, $sql) or die(mysqli_error($db));
return $result;
}

/*
* Обертка для выполнения запроса на получение данных
* Данные возвращаются в виде ассоциативного массива
* Цикл по получению данных уже реализован в этой функции
*/
function getAssocResult($sql)
{
$db = getDb();
$result = @mysqli_query($db, $sql) or die(mysqli_error($db));
$array_result = [];
while ($row = mysqli_fetch_assoc($result))
$array_result[] = $row;
return $array_result;
}



Loading