Automation init...3
This commit is contained in:
parent
d74dcd8e1d
commit
b5c4ae1877
@ -21,11 +21,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->get('', 'UserController::index');
|
||||
});
|
||||
});
|
||||
$routes->group('crawler', ['namespace' => 'App\Controllers'], function ($routes) {
|
||||
$routes->cli('yamap', 'CrawlerController::yamap');
|
||||
$routes->cli('yamap/(:alphanum)/(:any)', 'CrawlerController::yamap/$1/$2');
|
||||
$routes->cli('yamap/(:alphanum)/(:any)/(:any)', 'CrawlerController::yamap/$1/$2/$3');
|
||||
});
|
||||
$routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], function ($routes) {
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->get('/', 'UserController::index');
|
||||
@ -35,8 +30,9 @@ $routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], functi
|
||||
$routes->cli('check_level', 'UserController::check_level');
|
||||
$routes->cli('check_level/(:alpha)', 'UserController::check_level/$1');
|
||||
});
|
||||
$routes->group('image', function ($routes) {
|
||||
$routes->cli('yamap', 'ImageController::yamap');
|
||||
$routes->cli('yamap/(:any)', 'ImageController::yamap/$1');
|
||||
$routes->group('craawler', function ($routes) {
|
||||
$routes->cli('yamap/(:alpha)', 'CrawlerController::yamap/$1');
|
||||
$routes->cli('yamap/(:alpha)/(:any)', 'CrawlerController::yamap/$1/$2');
|
||||
$routes->cli('yamap/(:alpha)/(:alphanum)/(:any)', 'CrawlerController::yamap/$1/$2/$3');
|
||||
});
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ class UserController extends CommonController
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->session = $this->login_check();
|
||||
$this->session = $this->loginCheck_AuthTrait();
|
||||
}
|
||||
private function getModel(): UserModel
|
||||
{
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
namespace App\Controllers\Mangboard;
|
||||
|
||||
use App\Libraries\MyCrawler\YamapLibrary as MyCrawler;
|
||||
use App\Libraries\MyCrawler\YamapCrawler;
|
||||
use App\Controllers\CommonController;
|
||||
use App\Libraries\Mangboard\UserLibrary;
|
||||
|
||||
class CrawlerController extends CommonController
|
||||
{
|
||||
public function yamap(string $id = "", string $password = "", string $debug = "false"): string
|
||||
public function yamap(string $category, string $id = "", string $debug = "false"): string
|
||||
{
|
||||
try {
|
||||
$id = $id === "" ? getenv("mangboard.login.default.id") : $id;
|
||||
$password = $password === "" ? getenv("mangboard.login.default.password") : $password;
|
||||
$id = $id == "" ? getenv("mangboard.login.default.id") : $id;
|
||||
$password = getenv("mangboard.login.default.password");
|
||||
//1. 사이트 로그인 처리
|
||||
$user_library = new UserLibrary();
|
||||
$user_entity = $user_library->login(getenv("mangboard.host.url"), $id, $password);
|
||||
//2. 필요한 로그인한 사용자정보,Socket,Storage 정의후 Crawler에게 전달.
|
||||
$crawler = new MyCrawler();
|
||||
$crawler = new YamapCrawler($category);
|
||||
$crawler->setUserEntity($user_entity);
|
||||
$crawler->setDebug($debug === "true" ? true : false);
|
||||
$crawler->execute();
|
||||
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use App\Libraries\MyUtil\ImageLibrary;
|
||||
|
||||
class ImageController extends CommonController
|
||||
{
|
||||
public function yamap(...$params)
|
||||
{
|
||||
try {
|
||||
$fullPath = WRITEPATH . "uploads" . DIRECTORY_SEPARATOR . getenv('yamap.storage.upload.path');
|
||||
$image = new ImageLibrary();
|
||||
if (in_array("debug", $params)) {
|
||||
$image->setDebug(true);
|
||||
}
|
||||
$image->setSourcePath($fullPath);
|
||||
$image->setDestinationPath($fullPath);
|
||||
foreach ($image->getFilesByExtentionType($image->getSourcePath()) as $file) {
|
||||
//저장파일명
|
||||
$fileInfos = pathinfo($image->getDestinationPath() . DIRECTORY_SEPARATOR . $file, PATHINFO_ALL);
|
||||
$dstFile = $fileInfos['filename'] . "_small." . $fileInfos['extension'];
|
||||
$image->setDestinationFile($dstFile);
|
||||
$image->create($file);
|
||||
}
|
||||
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return "완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,18 +2,20 @@
|
||||
|
||||
namespace App\Libraries\Mangboard;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Models\Mangboard\BoardModel;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\BoardEntity;
|
||||
|
||||
class BoardLibrary
|
||||
class BoardLibrary extends CommonLibrary
|
||||
{
|
||||
private $_model = null;
|
||||
private $_boards_entity = null;
|
||||
private $_user_entity = null;
|
||||
public function __construct(BoardsEntity $boards_entity, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_boards_entity = $boards_entity;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
@ -33,7 +35,8 @@ class BoardLibrary
|
||||
{
|
||||
return $this->_user_entity;
|
||||
}
|
||||
public function create(int $cnt, array $listInfo, array $file_librarys): BoardEntity
|
||||
|
||||
public function createByCrawler(int $cnt, array $listInfo, array $storages): BoardEntity
|
||||
{
|
||||
$formDatas = [];
|
||||
//미디어관련정보 entity에 넣기
|
||||
@ -48,11 +51,11 @@ class BoardLibrary
|
||||
$formDatas['editor_type'] = "S";
|
||||
$formDatas['image_path'] = "";
|
||||
$formDatas['content'] = "";
|
||||
foreach ($file_librarys as $file_library) {
|
||||
foreach ($storages as $storage) {
|
||||
if ($formDatas['image_path'] == "") {
|
||||
$formDatas['image_path'] = sprintf("%s/%s", $file_library->getPath(), $file_library->getOriginName());
|
||||
$formDatas['image_path'] = sprintf("%s/%s/%s", $storage->getBasePath(), $storage->getPath(), $storage->getOriginName());
|
||||
}
|
||||
$formDatas['content'] .= $file_library->getHTMLTag();
|
||||
$formDatas['content'] .= $storage->getHTMLTag();
|
||||
}
|
||||
//망보드 게시판에 등록
|
||||
if ($formDatas['content'] == "") {
|
||||
@ -65,10 +68,6 @@ class BoardLibrary
|
||||
));
|
||||
}
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
//망보드 파일관리툴 등록
|
||||
foreach ($file_librarys as $file_library) {
|
||||
$file_library->createByBoardLibrary($entity, $cnt, $listInfo);
|
||||
}
|
||||
log_message("notice", sprintf(
|
||||
"%s=>%s번째 %s => %s 등록 완료",
|
||||
__FUNCTION__,
|
||||
|
||||
@ -2,19 +2,21 @@
|
||||
|
||||
namespace App\Libraries\Mangboard;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Models\Mangboard\BoardsModel;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
|
||||
class BoardsLibrary
|
||||
class BoardsLibrary extends CommonLibrary
|
||||
{
|
||||
private $_model = null;
|
||||
private $_entity = null;
|
||||
private $_board_name = null;
|
||||
private $_category = null;
|
||||
private $_user_entity = null;
|
||||
public function __construct(string $board_name, UserEntity $uer_entity)
|
||||
public function __construct(string $category, UserEntity $uer_entity)
|
||||
{
|
||||
$this->_board_name = $board_name;
|
||||
parent::__construct();
|
||||
$this->_category = $category;
|
||||
$this->_user_entity = $uer_entity;
|
||||
}
|
||||
public function getModel(): BoardsModel
|
||||
@ -27,14 +29,14 @@ class BoardsLibrary
|
||||
public function getEntity(): BoardsEntity
|
||||
{
|
||||
if ($this->_entity === null) {
|
||||
$this->_entity = $this->getModel()->getEntityByID($this->getBoardName());
|
||||
$this->_entity = $this->getModel()->getEntityByID("board_" . $this->getCategory());
|
||||
}
|
||||
return $this->_entity;
|
||||
}
|
||||
//---------------------------------------------------------------------//
|
||||
public function getBoardName(): string
|
||||
public function getCategory(): string
|
||||
{
|
||||
return $this->_board_name;
|
||||
return $this->_category;
|
||||
}
|
||||
public function getUserEntity(): UserEntity
|
||||
{
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\Mangboard\File;
|
||||
|
||||
use App\Libraries\MyUtil\ImageLibrary as MyUtilLibrary;
|
||||
|
||||
class ImageLibrary extends MyUtilLibrary
|
||||
{
|
||||
public function __construct() {}
|
||||
public function create(string $file_name, int $width = 480, int $height = 319): bool|string
|
||||
{
|
||||
try {
|
||||
$file_ext = pathinfo($this->getSourcePath() . DIRECTORY_SEPARATOR . $file_name, PATHINFO_EXTENSION);
|
||||
if (!$this->isFileType($file_ext)) {
|
||||
throw new \Exception("{$file_name} Image 형식파일이 아닙니다.");
|
||||
}
|
||||
//저장할 디렉토리 생성
|
||||
$this->makeDirectory($this->getDestinationPath());
|
||||
// 이미지 파일 로드
|
||||
$this->load($this->getSourcePath() . DIRECTORY_SEPARATOR . $file_name);
|
||||
// 200x200으로 이미지 크기 조정
|
||||
$this->resize($width, $height);
|
||||
// 파일 저장
|
||||
$this->save($this->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getDestinationFile());
|
||||
// 메모리 해제
|
||||
$this->destroy();
|
||||
log_message("debug", sprintf(
|
||||
"%s %s->%s(W:%s,H:%s) 작업완료)",
|
||||
__FUNCTION__,
|
||||
$file_name,
|
||||
$this->getDestinationFile(),
|
||||
$width,
|
||||
$height
|
||||
));
|
||||
return $file_name;
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,21 +2,24 @@
|
||||
|
||||
namespace App\Libraries\Mangboard;
|
||||
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Libraries\MyStorage\MangboardStorage;
|
||||
use App\Models\Mangboard\FileModel;
|
||||
use App\Libraries\Mangboard\File\ImageLibrary;
|
||||
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Entities\Mangboard\FileEntity;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\BoardEntity;
|
||||
|
||||
class FileLibrary extends MyStorageLibrary
|
||||
class FileLibrary extends CommonLibrary
|
||||
{
|
||||
private $_model = null;
|
||||
private $_boards_entity = null;
|
||||
private $_user_entity = null;
|
||||
public function __construct(string $path)
|
||||
public function __construct(BoardsEntity $boards_entity, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($path);
|
||||
parent::__construct();
|
||||
$this->_boards_entity = $boards_entity;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
public function getModel(): FileModel
|
||||
{
|
||||
@ -27,116 +30,55 @@ class FileLibrary extends MyStorageLibrary
|
||||
}
|
||||
public function getBoardsEntity(): BoardsEntity
|
||||
{
|
||||
if ($this->_boards_entity === null) {
|
||||
throw new \Exception("Board Library가 정의되지 않았습니다.");
|
||||
}
|
||||
return $this->_boards_entity;
|
||||
}
|
||||
public function setBoardsEntity(BoardsEntity $boards_entity): void
|
||||
{
|
||||
$this->_boards_entity = $boards_entity;
|
||||
}
|
||||
public function setUserEntity(UserEntity $user_entity): void
|
||||
{
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
public function getUserEntity(): UserEntity
|
||||
{
|
||||
if ($this->_user_entity === null) {
|
||||
throw new \Exception("User Entity가 정의되지 않았습니다.");
|
||||
}
|
||||
return $this->_user_entity;
|
||||
}
|
||||
final public function getHTMLTag(string $content = ""): string
|
||||
public function create(BoardEntity $board_entity, MangboardStorage $storage): FileEntity
|
||||
{
|
||||
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
|
||||
switch ($this->getOrintginType()) {
|
||||
case "image":
|
||||
$content = sprintf(
|
||||
"<img src=\"%s/%s/%s\" alt=\"%s\">",
|
||||
getenv("mangboard.uloads.url"),
|
||||
$this->getPath(),
|
||||
$this->getOriginName(),
|
||||
$this->getOriginName()
|
||||
);
|
||||
break;
|
||||
case "video":
|
||||
$content = sprintf(
|
||||
"<video alt=\"%s\" controls autoplay>
|
||||
<source src=\"%s/%s/%s\" type=\"%s\">
|
||||
Your browser does not support the video tag.
|
||||
</video>",
|
||||
$this->getOriginName(),
|
||||
getenv("mangboard.uloads.url"),
|
||||
$this->getPath(),
|
||||
$this->getOriginName(),
|
||||
$this->getMimeType(),
|
||||
);
|
||||
break;
|
||||
}
|
||||
log_message("debug", sprintf(
|
||||
"\n--------%s--------\n%s\n--------------------\n",
|
||||
__FUNCTION__,
|
||||
$content
|
||||
));
|
||||
return $content;
|
||||
//파일관리 table에 등록
|
||||
$formDatas = [];
|
||||
//Board PID 넣기
|
||||
$formDatas['board_pid'] = $board_entity->getPk();
|
||||
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
|
||||
$formDatas['user_name'] = $this->getUserEntity()->getTitle();
|
||||
$formDatas['board_name'] = $this->getBoardsEntity()->getTitle();
|
||||
$formDatas['table_name'] = $this->getModel()->getTable();
|
||||
$formDatas['file_path'] = $storage->getBasePath() . DIRECTORY_SEPARATOR . $storage->getPath() . DIRECTORY_SEPARATOR . $storage->getOriginName();
|
||||
$formDatas['file_name'] = $storage->getOriginName();
|
||||
$formDatas['file_type'] = $storage->getMimeType();
|
||||
$formDatas['file_caption'] = $storage->getOriginName();
|
||||
$formDatas['file_alt'] = $storage->getOriginName();
|
||||
$formDatas['file_description'] = "Filedata";
|
||||
$formDatas['file_size'] = $storage->getFileSize();
|
||||
$formDatas['file_sequence'] = $storage->getOriginSequence();
|
||||
$formDatas['reg_date'] = date("Y-m-d H:i:s");
|
||||
return $this->getModel()->create($formDatas);
|
||||
}
|
||||
public function createByBoardLibrary(BoardEntity $board_entity, int $cnt, array $listInfos): void
|
||||
public function createByCrawler(BoardEntity $board_entity, array $storages): void
|
||||
{
|
||||
try {
|
||||
//파일관리 table에 등록
|
||||
$formDatas = [];
|
||||
//Board PID 넣기
|
||||
$formDatas['board_pid'] = $board_entity->getPk();
|
||||
$formDatas['user_pid'] = $this->getUserEntity()->getPK();
|
||||
$formDatas['user_name'] = $this->getUserEntity()->getTitle();
|
||||
$formDatas['board_name'] = $this->getBoardsEntity()->getTitle();
|
||||
$formDatas['table_name'] = $this->getModel()->getTable();
|
||||
$formDatas['file_path'] = sprintf("%s/%s", $this->getPath(), $this->getOriginName());
|
||||
$formDatas['file_name'] = $this->getOriginName();
|
||||
$formDatas['file_type'] = $this->getMimeType();
|
||||
$formDatas['file_caption'] = $this->getOriginName();
|
||||
$formDatas['file_alt'] = $this->getOriginName();
|
||||
$formDatas['file_description'] = "Filedata";
|
||||
$formDatas['file_size'] = $this->getFileSize();
|
||||
$formDatas['file_sequence'] = $this->getOriginSequence();
|
||||
$formDatas['reg_date'] = date("Y-m-d H:i:s");
|
||||
$entity = $this->getModel()->create($formDatas);
|
||||
log_message("notice", sprintf(
|
||||
"게시물 %s번째[%s]의 %s번째용 파일 등록 완료",
|
||||
$cnt,
|
||||
$listInfos['title'],
|
||||
__FUNCTION__,
|
||||
$this->getOriginSequence()
|
||||
));
|
||||
foreach ($storages as $storage) {
|
||||
$entity = $this->create($board_entity, $storage);
|
||||
log_message("notice", sprintf(
|
||||
"%s -> %s 게시물의 %s번째:%s 파일 등록 완료",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$entity->getTitle()
|
||||
));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message("notice", sprintf(
|
||||
"\n---%s 게시물 %s번째[%s]의 %s번째용 파일 등록 오류---\n%s\n--------------------------------\n",
|
||||
"\n---%s -> %s 게시물의 %s번째:%s 파일 등록 오류---\n%s\n--------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$cnt,
|
||||
$listInfos['title'],
|
||||
__FUNCTION__,
|
||||
$this->getOriginSequence(),
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$storage->getOriginName(),
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
private function save_smallImage(): string
|
||||
{
|
||||
$imageLibrary = new ImageLibrary();
|
||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||
$imageLibrary->setDebug($this->getDebug());
|
||||
$imageLibrary->setSourcePath($fullPath);
|
||||
$imageLibrary->setDestinationPath($fullPath);
|
||||
//작은이미지생성후 Path/파일명 넣기
|
||||
$fileInfos = pathinfo($imageLibrary->getDestinationPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
|
||||
$imageLibrary->setDestinationFile($fileInfos['filename'] . "_small." . $fileInfos['extension']);
|
||||
return $imageLibrary->create($this->getOriginName());
|
||||
}
|
||||
public function save(): static
|
||||
{
|
||||
parent::save();
|
||||
$this->save_smallImage();
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
68
app/Libraries/Mangboard/ImageLibrary.php
Normal file
68
app/Libraries/Mangboard/ImageLibrary.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\Mangboard;
|
||||
|
||||
use App\Traits\ImageTrait;
|
||||
use App\Traits\FileTrait;
|
||||
use App\Libraries\MyStorage\MangboardStorage;
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Entities\Mangboard\BoardEntity;
|
||||
|
||||
class ImageLibrary extends CommonLibrary
|
||||
{
|
||||
use FileTrait, ImageTrait;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function create(MangboardStorage $storage, $target = "small", int $width = 480, int $height = 319): string
|
||||
{
|
||||
$fileInfo = pathinfo($storage->getFullPath() . DIRECTORY_SEPARATOR . $storage->getOriginName(), PATHINFO_ALL);
|
||||
$target_file_name = sprintf("%s_%s.%s", $fileInfo['filename'], $target, $fileInfo['extension']);
|
||||
|
||||
if (!$this->isFileType_FileTrait($fileInfo['extension'])) {
|
||||
throw new \Exception("{$storage->getOriginName()} Image 형식파일이 아닙니다.");
|
||||
}
|
||||
// 이미지 파일 로드
|
||||
$this->load_ImageTrait($storage->getFullPath() . DIRECTORY_SEPARATOR . $storage->getOriginName());
|
||||
// 200x200으로 이미지 크기 조정
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
// 파일 저장
|
||||
$this->save_ImageTrait($storage->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name);
|
||||
// 메모리 해제
|
||||
$this->destroy_ImageTrait();
|
||||
log_message("debug", sprintf(
|
||||
"%s %s->%s(W:%s,H:%s) 작업완료)",
|
||||
__FUNCTION__,
|
||||
$storage->getOriginName(),
|
||||
$target_file_name,
|
||||
$width,
|
||||
$height
|
||||
));
|
||||
return $target_file_name;
|
||||
}
|
||||
public function createByCrawler(BoardEntity $board_entity, array $storages): void
|
||||
{
|
||||
try {
|
||||
foreach ($storages as $storage) {
|
||||
$file_name = $this->create($storage);
|
||||
log_message("notice", sprintf(
|
||||
"%s -> %s 게시물의 %s번째:%s 작은이미지 생성 완료",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$file_name
|
||||
));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message("notice", sprintf(
|
||||
"\n---%s -> %s 게시물의 %s번째:%s 작은이미지 생성 오류---\n%s\n--------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$storage->getOriginSequence(),
|
||||
$storage->getOriginName(),
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,14 +2,17 @@
|
||||
|
||||
namespace App\Libraries\Mangboard;
|
||||
|
||||
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
|
||||
use App\Models\Mangboard\UserModel;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\CommonLibrary;
|
||||
|
||||
class UserLibrary extends MySocketLibrary
|
||||
class UserLibrary extends CommonLibrary
|
||||
{
|
||||
private $_user_model = null;
|
||||
public function __construct() {}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getUserModel(): UserModel
|
||||
{
|
||||
if ($this->_user_model === null) {
|
||||
|
||||
@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Libraries\MyAuth;
|
||||
|
||||
use App\Libraries\MySocket\GoogleLibrary as MySocketLibrary;
|
||||
use App\Libraries\MySocket\Web\GoogleSocket;
|
||||
use App\Libraries\MyAuthLibrary;
|
||||
use App\Entities\UserEntity;
|
||||
use App\Entities\SNSUserEntity;
|
||||
|
||||
class GoogleLibrary extends MyAuthLibrary
|
||||
class GoogleAuth extends MyAuthLibrary
|
||||
{
|
||||
private $_mySocket = null;
|
||||
private $_site = "GOOGLE";
|
||||
@ -16,10 +16,10 @@ class GoogleLibrary extends MyAuthLibrary
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getMySocket(): MySocketLibrary
|
||||
public function getMySocket(): GoogleSocket
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new MySocketLibrary(getenv('yamap.host.url'));
|
||||
$this->_mySocket = new GoogleSocket(getenv('yamap.host.url'));
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
@ -5,7 +5,7 @@ namespace App\Libraries\MyAuth;
|
||||
use App\Libraries\MyAuthLibrary;
|
||||
use App\Entities\UserEntity;
|
||||
|
||||
class LocalLibrary extends MyAuthLibrary
|
||||
class LocalAuth extends MyAuthLibrary
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@ -4,46 +4,57 @@ namespace App\Libraries\MyCrawler;
|
||||
|
||||
|
||||
use App\Libraries\MyCrawlerLibrary;
|
||||
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
|
||||
use App\Libraries\Mangboard\FileLibrary as MyStorageLibrary;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\MyStorage\MangboardStorage;
|
||||
use App\Libraries\Mangboard\BoardsLibrary;
|
||||
use App\Libraries\Mangboard\BoardLibrary;
|
||||
use App\Libraries\Mangboard\FileLibrary;
|
||||
use App\Libraries\Mangboard\ImageLibrary;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use App\Traits\FileTrait;
|
||||
|
||||
class YamapLibrary extends MyCrawlerLibrary
|
||||
class YamapCrawler extends MyCrawlerLibrary
|
||||
{
|
||||
use FileTrait;
|
||||
private $_mySocket = null;
|
||||
private $_myStorage = null;
|
||||
private $_storages = [];
|
||||
private $_category = "";
|
||||
private $_user_entity = null;
|
||||
private $_boards_library = null;
|
||||
private $_board_library = null;
|
||||
private $_file_librarys = [];
|
||||
public function __construct()
|
||||
private $_file_library = null;
|
||||
private $_image_library = null;
|
||||
public function __construct(string $category)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_category = $category;
|
||||
}
|
||||
final protected function getMySocket(): mixed
|
||||
public function getMySocket()
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new MySocketLibrary(getenv('yamap.host.url'));
|
||||
$this->_mySocket = new WebSocket(getenv('yamap.host.url'));
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
final protected function getMyStorage(): mixed
|
||||
public function getMyStorage()
|
||||
{
|
||||
if ($this->_myStorage === null) {
|
||||
$this->_myStorage = new MyStorageLibrary(getenv('yamap.storage.upload.path'));
|
||||
$this->_myStorage->setBoardsEntity($this->getBoardsLibrary()->getEntity());
|
||||
$this->_myStorage->setUserEntity($this->getUserEntity());
|
||||
$this->_myStorage = new MangboardStorage($this->getCategory());
|
||||
}
|
||||
return $this->_myStorage;
|
||||
}
|
||||
public function getBoardsLibrary(): BoardsLibrary
|
||||
{
|
||||
// $test = $this->getBoard();
|
||||
// echo "TEST:{$test}\n";
|
||||
// $temp = getenv("mangboard.storage.{$this->getBoard()}.name");
|
||||
// echo "Temp:{$temp}\n";
|
||||
// exit;
|
||||
if ($this->_boards_library === null) {
|
||||
$this->_boards_library = new BoardsLibrary(
|
||||
getenv('yamap.storage.board.name'),
|
||||
$this->getCategory(),
|
||||
$this->getUserEntity()
|
||||
);
|
||||
}
|
||||
@ -59,6 +70,23 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
}
|
||||
return $this->_board_library;
|
||||
}
|
||||
public function getFileLibrary(): FileLibrary
|
||||
{
|
||||
if ($this->_file_library === null) {
|
||||
$this->_file_library = new FileLibrary(
|
||||
$this->getBoardsLibrary()->getEntity(),
|
||||
$this->getUserEntity()
|
||||
);
|
||||
}
|
||||
return $this->_file_library;
|
||||
}
|
||||
public function getImageLibrary(): ImageLibrary
|
||||
{
|
||||
if ($this->_image_library === null) {
|
||||
$this->_image_library = new ImageLibrary();
|
||||
}
|
||||
return $this->_image_library;
|
||||
}
|
||||
public function getUserEntity(): UserEntity
|
||||
{
|
||||
if ($this->_user_entity === null) {
|
||||
@ -66,18 +94,25 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
}
|
||||
return $this->_user_entity;
|
||||
}
|
||||
public function setUserEntity(UserEntity $_user_entity): void
|
||||
public function setUserEntity(UserEntity $user_entity): void
|
||||
{
|
||||
$this->_user_entity = $_user_entity;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
public function getCategory(): string
|
||||
{
|
||||
if ($this->_category == "") {
|
||||
throw new \Exception("저장할 Category가 정의되지 않았습니다.");
|
||||
}
|
||||
return $this->_category;
|
||||
}
|
||||
|
||||
private function save(int $file_sequence, string $mediaType, string $file_name, string $content): void
|
||||
{
|
||||
log_message("debug", __FUNCTION__ . " 원본파일 {$file_name} 작업 시작");
|
||||
$this->getMyStorage()->setOriginName($file_name);
|
||||
$this->getMyStorage()->setOriginContent($content);
|
||||
$this->getMyStorage()->setOriginType($mediaType);
|
||||
$this->getMyStorage()->setOriginSequence($file_sequence);
|
||||
$this->_file_librarys[] = $this->getMyStorage()->save();
|
||||
$this->_storages[] = $this->getMyStorage()->save();
|
||||
}
|
||||
//Yamap ViewPage의 이미지나영상데이터가 있으면 Dodownload 한다.
|
||||
private function download(string $mediaType, string $url): array
|
||||
@ -89,7 +124,7 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
$file_name = array_pop($file_names);
|
||||
$temps = explode(".", $file_name);
|
||||
$file_ext = array_pop($temps);
|
||||
if (!$this->isFileType($file_ext, $mediaType)) {
|
||||
if (!$this->isFileType_FileTrait($file_ext, $mediaType)) {
|
||||
throw new \Exception("파일명 형식이 {$mediaType}가 아닙니다");
|
||||
}
|
||||
$content = $this->getMySocket()->getContent($url);
|
||||
@ -99,7 +134,7 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
private function mediaContent(array $urls): void
|
||||
{
|
||||
$file_sequence = 1;
|
||||
$this->_file_librarys = []; //CreateBoard에서 사용을 위해 DetailPage마다 초기화
|
||||
$this->_storages = []; //CreateBoard에서 사용을 위해 DetailPage마다 초기화
|
||||
foreach ($urls as $mediaType => $url) {
|
||||
try {
|
||||
list($file_name, $content) = $this->download($mediaType, $url);
|
||||
@ -115,7 +150,7 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
));
|
||||
}
|
||||
}
|
||||
if (!count($this->_file_librarys)) {
|
||||
if (!count($this->_storages)) {
|
||||
throw new \Exception("Download된 Content가 없습니다.");
|
||||
}
|
||||
}
|
||||
@ -182,7 +217,7 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
'hit' => 1,
|
||||
];
|
||||
} else {
|
||||
$listInfos = $this->mainPage(getenv("yamap.list.url"));
|
||||
$listInfos = $this->mainPage(getenv("yamap.list.url." . $this->getCategory()));
|
||||
}
|
||||
//Limit가 0이면 $listInfos 갯수만큼 다하고, LIMIT 갯수 혹은 item의 갯수중 작은수만큼 한다.
|
||||
$max_limit = intval(getenv("yamap.list.max_limit"));
|
||||
@ -198,7 +233,9 @@ class YamapLibrary extends MyCrawlerLibrary
|
||||
log_message("notice", "게시물 {$i}번째 {$listInfo["nickname"]} 작업시작");
|
||||
$this->mediaContent($this->detailPage($listInfo));
|
||||
//File DB 및 Board DB 등록작업
|
||||
$this->getBoardLibrary()->create($i, $listInfo, $this->_file_librarys);
|
||||
$board_entity = $this->getBoardLibrary()->createByCrawler($i, $listInfo, $this->_storages);
|
||||
$this->getFileLibrary()->createByCrawler($board_entity, $this->_storages);
|
||||
$this->getImageLibrary()->createByCrawler($board_entity, $this->_storages);
|
||||
log_message("notice", "게시물 {$i}번째 {$listInfo["nickname"]} 작업완료.");
|
||||
$i++;
|
||||
} catch (\Exception $e) {
|
||||
@ -7,15 +7,13 @@ use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
abstract class MyCrawlerLibrary extends CommonLibrary
|
||||
{
|
||||
protected $_mySocket = null;
|
||||
protected $_myStorage = null;
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
abstract public function getMySocket();
|
||||
abstract public function getMyStorage();
|
||||
abstract public function execute(): void;
|
||||
abstract protected function getMySocket(): mixed;
|
||||
abstract protected function getMyStorage(): mixed;
|
||||
final protected function getSelector(string $content, string $tag): Crawler
|
||||
{
|
||||
$crawler = new Crawler($content);
|
||||
|
||||
@ -4,9 +4,9 @@ namespace App\Libraries\MySocket\Web;
|
||||
|
||||
use Cloudflare\API\Auth\APIKey;
|
||||
use Cloudflare\API\Adapter\Guzzle;
|
||||
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
|
||||
class CloudflareLibrary extends MySocketLibrary
|
||||
class CloudflareSocket extends WebSocket
|
||||
{
|
||||
private static int $_request_count = 1;
|
||||
private static int $_request_max = 100;
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Libraries\MySocket\Web;
|
||||
|
||||
use App\Libraries\MySocket\WebLibrary as MySocketLibrary;
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
|
||||
class GoogleLibrary extends MySocketLibrary
|
||||
class GoogleSocket extends WebSocket
|
||||
{
|
||||
private $_client = null;
|
||||
private $_session = null;
|
||||
@ -6,7 +6,7 @@ use GuzzleHttp\Cookie\CookieJar;
|
||||
use GuzzleHttp\Client;
|
||||
use App\Libraries\MySocketLibrary;
|
||||
|
||||
class WebLibrary extends MySocketLibrary
|
||||
class WebSocket extends MySocketLibrary
|
||||
{
|
||||
private $_client = null;
|
||||
private $_cookieJar = null;
|
||||
@ -5,10 +5,9 @@ namespace App\Libraries\MyStorage;
|
||||
use App\Libraries\MyStorageLibrary;
|
||||
use App\Traits\FileTrait;
|
||||
|
||||
class FileLibrary extends MyStorageLibrary
|
||||
class FileStorage extends MyStorageLibrary
|
||||
{
|
||||
use FileTrait;
|
||||
private $_uploadPath = "uploads";
|
||||
private $_path = "";
|
||||
private $_mimeType = "";
|
||||
private $_fileSize = 0;
|
||||
@ -19,14 +18,25 @@ class FileLibrary extends MyStorageLibrary
|
||||
parent::__construct();
|
||||
$this->_path = $path;
|
||||
}
|
||||
final public function getUploadPath(): string
|
||||
{
|
||||
return $this->_uploadPath;
|
||||
}
|
||||
final public function getPath(): string
|
||||
{
|
||||
return $this->_path;
|
||||
}
|
||||
public function getUploadPath(): string
|
||||
{
|
||||
return "uploads";
|
||||
}
|
||||
final public function getFullPath(): string
|
||||
{
|
||||
$full_path = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||
$this->mkdir_FileTrait($full_path);
|
||||
return $full_path;
|
||||
}
|
||||
public function getUploadURL(): string
|
||||
{
|
||||
return "uploads";
|
||||
}
|
||||
|
||||
final public function getMimeType(): string
|
||||
{
|
||||
return $this->_mimeType;
|
||||
@ -42,30 +52,30 @@ class FileLibrary extends MyStorageLibrary
|
||||
|
||||
public function save(): static
|
||||
{
|
||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||
$this->makeDirectory($fullPath);
|
||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||
// log_message("notice", __FUNCTION__ . " 원본파일 {$this->getOriginName()} 작업 시작 2");
|
||||
$save_file = $this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||
log_message("debug", __FUNCTION__ . " {$save_file} 작업 시작");
|
||||
//중복된 파일명인지 확인후 새로운 이름으로 저장
|
||||
if (file_exists($saveFilePath)) {
|
||||
switch (getenv("mangboard.uloads.file.collision")) {
|
||||
if (file_exists($save_file)) {
|
||||
switch (getenv("mangboard.uploads.file.collision")) {
|
||||
case "unique":
|
||||
$saveFile = $this->getUniqueFilename($fullPath, $this->getOriginName());
|
||||
$saveFilePath = $fullPath . DIRECTORY_SEPARATOR . $saveFile;
|
||||
log_message("notice", __FUNCTION__ . "파일명 변경 : 원본파일 {$this->getOriginName()}->저장파일 {$saveFile}");
|
||||
$this->setOriginName($saveFile);
|
||||
$file_name = $this->getUniqueName_FileTrait($this->getFullPath(), $this->getOriginName());
|
||||
log_message("notice", __FUNCTION__ . "파일명 변경 : 원본파일 {$this->getOriginName()}->저장파일 {$file_name}");
|
||||
$this->setOriginName($file_name);
|
||||
$save_file = $this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||
break;
|
||||
case "notallow":
|
||||
default:
|
||||
throw new \Exception(__FUNCTION__ . "{$saveFilePath}는 이미 존재하는 파일입니다.");
|
||||
throw new \Exception(__FUNCTION__ . "{$this->getOriginName()}는 이미 존재하는 파일입니다.");
|
||||
// break;
|
||||
}
|
||||
}
|
||||
//원본이미지 저장
|
||||
if (!file_put_contents($saveFilePath, $this->getOriginContent())) {
|
||||
throw new \Exception(__FUNCTION__ . " 파일저장 실패:{$saveFilePath}");
|
||||
if (!file_put_contents($save_file, $this->getOriginContent())) {
|
||||
throw new \Exception(__FUNCTION__ . " 파일저장 실패:{$save_file}");
|
||||
}
|
||||
$this->_mimeType = mime_content_type($saveFilePath);
|
||||
$this->_fileSize = filesize($saveFilePath);
|
||||
$this->_mimeType = mime_content_type($save_file);
|
||||
$this->_fileSize = filesize($save_file);
|
||||
log_message("notice", __FUNCTION__ . " 원본파일 {$this->getOriginName()} 작업 완료");
|
||||
return $this;
|
||||
}
|
||||
67
app/Libraries/MyStorage/MangboardStorage.php
Normal file
67
app/Libraries/MyStorage/MangboardStorage.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyStorage;
|
||||
|
||||
use App\Models\Mangboard\FileModel;
|
||||
|
||||
class MangboardStorage extends FileStorage
|
||||
{
|
||||
private $_model = null;
|
||||
public function __construct(string $path)
|
||||
{
|
||||
parent::__construct($path);
|
||||
}
|
||||
public function getBasePath(): string
|
||||
{
|
||||
return getenv("mangboard.uploads.path");
|
||||
}
|
||||
public function getUploadPath(): string
|
||||
{
|
||||
return parent::getUploadPath() . DIRECTORY_SEPARATOR . $this->getBasePath();
|
||||
}
|
||||
public function getUploadURL(): string
|
||||
{
|
||||
return sprintf("/wp-content/%s/%s", parent::getUploadURL(), $this->getBasePath());
|
||||
}
|
||||
public function getModel(): FileModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
return $this->_model = new FileModel();
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
final public function getHTMLTag(string $content = ""): string
|
||||
{
|
||||
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
|
||||
switch ($this->getOrintginType()) {
|
||||
case "image":
|
||||
$content = sprintf(
|
||||
"<img src=\"%s/%s/%s\" alt=\"%s\">",
|
||||
$this->getUploadURL(),
|
||||
$this->getPath(),
|
||||
$this->getOriginName(),
|
||||
$this->getOriginName()
|
||||
);
|
||||
break;
|
||||
case "video":
|
||||
$content = sprintf(
|
||||
"<video alt=\"%s\" controls autoplay>
|
||||
<source src=\"%s/%s/%s\" type=\"%s\">
|
||||
Your browser does not support the video tag.
|
||||
</video>",
|
||||
$this->getOriginName(),
|
||||
$this->getUploadURL(),
|
||||
$this->getPath(),
|
||||
$this->getOriginName(),
|
||||
$this->getMimeType(),
|
||||
);
|
||||
break;
|
||||
}
|
||||
log_message("debug", sprintf(
|
||||
"\n--------%s--------\n%s\n--------------------\n",
|
||||
__FUNCTION__,
|
||||
$content
|
||||
));
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyUtil;
|
||||
|
||||
use App\Libraries\MyUtilLibrary;
|
||||
use App\Traits\FileTrait;
|
||||
|
||||
class ImageLibrary extends MyUtilLibrary
|
||||
{
|
||||
use FileTrait;
|
||||
private $_srcPath = "";
|
||||
private $_dstPath = "";
|
||||
private $_dstFile = "";
|
||||
private $_image;
|
||||
private $_imageType;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
// 이미지의 현재 너비를 반환하는 메소드
|
||||
final public function getSourcePath(): string
|
||||
{
|
||||
return $this->_srcPath;
|
||||
}
|
||||
final public function setSourcePath(string $srcPath): void
|
||||
{
|
||||
$this->_srcPath = $srcPath;
|
||||
}
|
||||
final public function getDestinationPath(): string
|
||||
{
|
||||
return $this->_dstPath;
|
||||
}
|
||||
final public function setDestinationPath(string $dstPath): void
|
||||
{
|
||||
$this->_dstPath = $dstPath;
|
||||
}
|
||||
final public function getDestinationFile(): string
|
||||
{
|
||||
return $this->_dstFile;
|
||||
}
|
||||
final public function setDestinationFile(string $dstFile): void
|
||||
{
|
||||
$this->_dstFile = $dstFile;
|
||||
}
|
||||
|
||||
final public function getWidth()
|
||||
{
|
||||
return imagesx($this->_image);
|
||||
}
|
||||
// 이미지의 현재 높이를 반환하는 메소드
|
||||
final public function getHeight()
|
||||
{
|
||||
return imagesy($this->_image);
|
||||
}
|
||||
// 이미지 파일을 로드하는 메소드
|
||||
final protected function load($file)
|
||||
{
|
||||
$imageInfo = getimagesize($file);
|
||||
$this->_imageType = $imageInfo[2];
|
||||
switch ($this->_imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$this->_image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$this->_image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$this->_image = imagecreatefrompng($file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$this->_image = imagecreatefromwebp($file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 이미지 크기를 지정된 너비, 높이로 변경하는 메소드
|
||||
final protected function resize($width, $height)
|
||||
{
|
||||
$newImage = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled($newImage, $this->_image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
|
||||
$this->_image = $newImage;
|
||||
}
|
||||
// 이미지 비율을 유지하면서 크기를 조정하는 메소드
|
||||
final protected function resizeToWidth($width)
|
||||
{
|
||||
$ratio = $width / $this->getWidth();
|
||||
$height = $this->getHeight() * $ratio;
|
||||
$this->resize($width, $height);
|
||||
}
|
||||
final protected function resizeToHeight($height)
|
||||
{
|
||||
$ratio = $height / $this->getHeight();
|
||||
$width = $this->getWidth() * $ratio;
|
||||
$this->resize($width, $height);
|
||||
}
|
||||
final protected function scale($scale)
|
||||
{
|
||||
$width = $this->getWidth() * ($scale / 100);
|
||||
$height = $this->getHeight() * ($scale / 100);
|
||||
$this->resize($width, $height);
|
||||
}
|
||||
// 이미지를 저장하는 메소드
|
||||
final protected function save($file, $imageType = IMAGETYPE_WEBP, $compression = 75)
|
||||
{
|
||||
switch ($imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($this->_image, $file, $compression);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
imagegif($this->_image, $file);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($this->_image, $file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
default:
|
||||
imagewebp($this->_image, $file, $compression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 메모리 해제를 위한 메소드
|
||||
final protected function destroy()
|
||||
{
|
||||
imagedestroy($this->_image);
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ namespace App\Traits;
|
||||
|
||||
trait AuthTrait
|
||||
{
|
||||
final public function login_check(): array
|
||||
final protected function loginCheck_AuthTrait(): array
|
||||
{
|
||||
//사용자 기본 Role 지정
|
||||
$session[SESSION_NAMES['ISLOGIN']] = false;
|
||||
|
||||
@ -4,16 +4,16 @@ namespace App\Traits;
|
||||
|
||||
trait FileTrait
|
||||
{
|
||||
final public function makeDirectory(string $path)
|
||||
final protected function mkdir_FileTrait(string $path)
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
if (!mkdir($path)) {
|
||||
if (!mkdir($path, 0644, true)) {
|
||||
throw new \Exception("디렉토리 생성 실패:{$path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final public function isFileType(string $file_ext, $type = "image"): bool
|
||||
final protected function isFileType_FileTrait(string $file_ext, $type = "image"): bool
|
||||
{
|
||||
switch ($type) {
|
||||
case "audio":
|
||||
@ -31,21 +31,21 @@ trait FileTrait
|
||||
}
|
||||
|
||||
//디렉토리에 속한 파일 List
|
||||
final public function getFilesByExtentionType(string $path, string $type = "image"): array
|
||||
final protected function getFiles_FileTrait(string $path, string $type = "image"): array
|
||||
{
|
||||
// 디렉토리에서 파일 목록 가져오기
|
||||
$files = [];
|
||||
foreach (scandir($path) as $file_name) {
|
||||
// 확장자가 이미지 형식인지 확인
|
||||
$file_ext = pathinfo($path . DIRECTORY_SEPARATOR . $file_name, PATHINFO_EXTENSION);
|
||||
if ($this->isFileType($file_ext, $type)) {
|
||||
if ($this->isFileType_FileTrait($file_ext, $type)) {
|
||||
$files[] = $file_name;
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
final public function getUniqueFilename($path, $file_name)
|
||||
final protected function getUniqueName_FileTrait($path, $file_name)
|
||||
{
|
||||
$fileExtension = pathinfo($file_name, PATHINFO_EXTENSION);
|
||||
$fileBaseName = pathinfo($file_name, PATHINFO_FILENAME);
|
||||
|
||||
100
app/Traits/ImageTrait.php
Normal file
100
app/Traits/ImageTrait.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait ImageTrait
|
||||
{
|
||||
private $_image;
|
||||
private $_imageType;
|
||||
|
||||
final protected function getWidth_ImageTrait()
|
||||
{
|
||||
return imagesx($this->_image);
|
||||
}
|
||||
// 이미지의 현재 높이를 반환하는 메소드
|
||||
final protected function getHeight_ImageTrait()
|
||||
{
|
||||
return imagesy($this->_image);
|
||||
}
|
||||
// 이미지 파일을 로드하는 메소드
|
||||
final protected function load_ImageTrait($file)
|
||||
{
|
||||
$imageInfo = getimagesize($file);
|
||||
$this->_imageType = $imageInfo[2];
|
||||
switch ($this->_imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$this->_image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
$this->_image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$this->_image = imagecreatefrompng($file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$this->_image = imagecreatefromwebp($file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 이미지 크기를 지정된 너비, 높이로 변경하는 메소드
|
||||
final protected function resize_ImageTrait($width, $height)
|
||||
{
|
||||
$newImage = imagecreatetruecolor($width, $height);
|
||||
imagecopyresampled(
|
||||
$newImage,
|
||||
$this->_image,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$width,
|
||||
$height,
|
||||
$this->getWidth_ImageTrait(),
|
||||
$this->getHeight_ImageTrait()
|
||||
);
|
||||
$this->_image = $newImage;
|
||||
}
|
||||
// 이미지 비율을 유지하면서 크기를 조정하는 메소드
|
||||
final protected function resizeToWidth_ImageTrait($width)
|
||||
{
|
||||
$ratio = $width / $this->getWidth_ImageTrait();
|
||||
$height = $this->getHeight_ImageTrait() * $ratio;
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
final protected function resizeToHeight_ImageTrait($height)
|
||||
{
|
||||
$ratio = $height / $this->getHeight_ImageTrait();
|
||||
$width = $this->getWidth_ImageTrait() * $ratio;
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
final protected function scale($scale)
|
||||
{
|
||||
$width = $this->getWidth_ImageTrait() * ($scale / 100);
|
||||
$height = $this->getHeight_ImageTrait() * ($scale / 100);
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
}
|
||||
// 이미지를 저장하는 메소드
|
||||
final protected function save_ImageTrait($file, $imageType = IMAGETYPE_WEBP, $compression = 75)
|
||||
{
|
||||
switch ($imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($this->_image, $file, $compression);
|
||||
break;
|
||||
case IMAGETYPE_GIF:
|
||||
imagegif($this->_image, $file);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($this->_image, $file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
default:
|
||||
imagewebp($this->_image, $file, $compression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 메모리 해제를 위한 메소드
|
||||
final protected function destroy_ImageTrait()
|
||||
{
|
||||
imagedestroy($this->_image);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user