Automation init...2
This commit is contained in:
parent
40e47b2815
commit
eaf7986815
@ -10,8 +10,12 @@ abstract class CommonEntity extends Entity
|
|||||||
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
|
||||||
protected $casts = [];
|
protected $casts = [];
|
||||||
|
|
||||||
|
public function __construct(array|null $data = null)
|
||||||
|
{
|
||||||
|
parent::__construct($data);
|
||||||
|
}
|
||||||
|
|
||||||
abstract public function __toString();
|
abstract public function __toString();
|
||||||
abstract public function getPK();
|
|
||||||
abstract public function getTitle();
|
abstract public function getTitle();
|
||||||
abstract public function setTitle(string $tile): void;
|
abstract public function setTitle(string $tile): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,6 @@ class BoardEntity extends CommonEntity
|
|||||||
{
|
{
|
||||||
return "{$this->getPK()}:{$this->getTitle()}";
|
return "{$this->getPK()}:{$this->getTitle()}";
|
||||||
}
|
}
|
||||||
public function getPK(): int
|
|
||||||
{
|
|
||||||
return $this->attributes['pid'];
|
|
||||||
}
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return $this->attributes['title'];
|
return $this->attributes['title'];
|
||||||
@ -23,4 +19,9 @@ class BoardEntity extends CommonEntity
|
|||||||
$this->attributes['title'] = $title;
|
$this->attributes['title'] = $title;
|
||||||
}
|
}
|
||||||
//Common Function
|
//Common Function
|
||||||
|
|
||||||
|
public function getPK(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['pid'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,25 +2,18 @@
|
|||||||
|
|
||||||
namespace App\Entities\Mangboard;
|
namespace App\Entities\Mangboard;
|
||||||
|
|
||||||
use App\Entities\CommonEntity;
|
use App\Entities\MyStorage\FileEntity as ParentEntity;
|
||||||
|
|
||||||
class FileEntity extends CommonEntity
|
class FileEntity extends ParentEntity
|
||||||
{
|
{
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return "{$this->getPK()}:{$this->getTitle()}";
|
return "{$this->getPK()}:{$this->getTitle()}";
|
||||||
}
|
}
|
||||||
|
//Common Function
|
||||||
|
|
||||||
public function getPK(): int
|
public function getPK(): int
|
||||||
{
|
{
|
||||||
return $this->attributes['pid'];
|
return $this->attributes['pid'];
|
||||||
}
|
}
|
||||||
public function getTitle(): string
|
|
||||||
{
|
|
||||||
return $this->attributes['file_name'];
|
|
||||||
}
|
|
||||||
public function setTitle(string $title): void
|
|
||||||
{
|
|
||||||
$this->attributes['file_name'] = $title;
|
|
||||||
}
|
|
||||||
//Common Function
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,6 @@ class UserEntity extends CommonEntity
|
|||||||
{
|
{
|
||||||
return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getLevel()}/{$this->getPoint()}";
|
return "{$this->getPK()}:{$this->getID()}:{$this->getTitle()},{$this->getLevel()}/{$this->getPoint()}";
|
||||||
}
|
}
|
||||||
public function getPK(): int
|
|
||||||
{
|
|
||||||
return $this->attributes['pid'];
|
|
||||||
}
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return $this->attributes['user_name'];
|
return $this->attributes['user_name'];
|
||||||
@ -24,6 +20,10 @@ class UserEntity extends CommonEntity
|
|||||||
}
|
}
|
||||||
//Common Function
|
//Common Function
|
||||||
|
|
||||||
|
public function getPK(): int
|
||||||
|
{
|
||||||
|
return $this->attributes['pid'];
|
||||||
|
}
|
||||||
public function getID(): string
|
public function getID(): string
|
||||||
{
|
{
|
||||||
return $this->attributes['user_id'];
|
return $this->attributes['user_id'];
|
||||||
|
|||||||
51
app/Entities/MyStorage/FileEntity.php
Normal file
51
app/Entities/MyStorage/FileEntity.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entities\MyStorage;
|
||||||
|
|
||||||
|
use App\Entities\CommonEntity;
|
||||||
|
|
||||||
|
class FileEntity extends CommonEntity
|
||||||
|
{
|
||||||
|
public function __construct(array|null $data = null)
|
||||||
|
{
|
||||||
|
parent::__construct($data);
|
||||||
|
}
|
||||||
|
public function __toString(): string
|
||||||
|
{
|
||||||
|
return "{$this->getTitle()}";
|
||||||
|
}
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return $this->attributes['file_name'];
|
||||||
|
}
|
||||||
|
public function setTitle(string $file_name): void
|
||||||
|
{
|
||||||
|
$this->attributes['file_name'] = $file_name;
|
||||||
|
}
|
||||||
|
//Common Function
|
||||||
|
|
||||||
|
public function getPath(): string
|
||||||
|
{
|
||||||
|
return $this->attributes['file_path'];
|
||||||
|
}
|
||||||
|
public function setPath(string $file_path): void
|
||||||
|
{
|
||||||
|
$this->attributes['file_path'] = $file_path;
|
||||||
|
}
|
||||||
|
final public function getMimeType(): string
|
||||||
|
{
|
||||||
|
return $this->attributes['file_type'];
|
||||||
|
}
|
||||||
|
public function setMimeType(string $mimetype): void
|
||||||
|
{
|
||||||
|
$this->attributes['file_type'] = $mimetype;
|
||||||
|
}
|
||||||
|
final public function getMediaHTML(): string
|
||||||
|
{
|
||||||
|
return $this->attributes['media_html'];
|
||||||
|
}
|
||||||
|
public function setMediaHTML(string $media_html): void
|
||||||
|
{
|
||||||
|
$this->attributes['media_html'] = $media_html;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,22 +3,39 @@
|
|||||||
namespace App\Libraries\Mangboard;
|
namespace App\Libraries\Mangboard;
|
||||||
|
|
||||||
|
|
||||||
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
|
use App\Libraries\MyStorage\FileLibrary as ParentLibrary;
|
||||||
use App\Models\Mangboard\FileModel;
|
use App\Models\Mangboard\FileModel;
|
||||||
use App\Entities\Mangboard\UserEntity;
|
use App\Entities\Mangboard\UserEntity;
|
||||||
use App\Entities\Mangboard\FileEntity;
|
use App\Entities\Mangboard\FileEntity;
|
||||||
|
|
||||||
class FileLibrary extends MyStorageLibrary
|
class FileLibrary extends ParentLibrary
|
||||||
{
|
{
|
||||||
private $_user = null;
|
private $_user = null;
|
||||||
private $_boardName = "";
|
private $_boardName = "";
|
||||||
private $_boardTable = "";
|
private $_boardTable = "";
|
||||||
private $_model = null;
|
private $_model = null;
|
||||||
private $_fileEntity = null;
|
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
parent::__construct($path);
|
parent::__construct($path);
|
||||||
}
|
}
|
||||||
|
public function getModel(): FileModel
|
||||||
|
{
|
||||||
|
if ($this->_model === null) {
|
||||||
|
return $this->_model = new FileModel();
|
||||||
|
}
|
||||||
|
return $this->_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
//override
|
||||||
|
public function getEntity(): FileEntity
|
||||||
|
{
|
||||||
|
if ($this->_entity === null) {
|
||||||
|
$this->_entity = new FileEntity();
|
||||||
|
$this->_entity->setPath($this->getPath());
|
||||||
|
}
|
||||||
|
return $this->_entity;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUser(): UserEntity
|
public function getUser(): UserEntity
|
||||||
{
|
{
|
||||||
if ($this->_user === null) {
|
if ($this->_user === null) {
|
||||||
@ -50,43 +67,26 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
}
|
}
|
||||||
public function setBoardTable(string $boardTable): void
|
public function setBoardTable(string $boardTable): void
|
||||||
{
|
{
|
||||||
$this->_boardName = $boardTable;
|
$this->_boardTable = $boardTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModel(): FileModel
|
public function save($content): null|FileEntity
|
||||||
{
|
{
|
||||||
if ($this->_model === null) {
|
|
||||||
return $this->_model = new FileModel();
|
|
||||||
}
|
|
||||||
return $this->_model;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFileEntity(): null|FileEntity
|
|
||||||
{
|
|
||||||
return $this->_fileEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save($content): bool
|
|
||||||
{
|
|
||||||
if (!parent::save($content)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//망보드 파일관리 table에 등록
|
//망보드 파일관리 table에 등록
|
||||||
try {
|
try {
|
||||||
//mb_files 모델작업
|
$entity = parent::save($content);
|
||||||
$entity = new FileEntity();
|
if ($entity === null) {
|
||||||
$entity->setTitle($this->getFileName());
|
return null;
|
||||||
|
}
|
||||||
$entity->user_pid = $this->getUser()->getPK();
|
$entity->user_pid = $this->getUser()->getPK();
|
||||||
$entity->user_name = $this->getUser()->getTitle();
|
$entity->user_name = $this->getUser()->getTitle();
|
||||||
$entity->board_name = $this->getBoardName();
|
$entity->board_name = $this->getBoardName();
|
||||||
$entity->table_name = $this->getBoardTable();
|
$entity->table_name = $this->getBoardTable();
|
||||||
$entity->file_path = $this->getPath();
|
|
||||||
$entity->file_type = $this->getMimeType();
|
|
||||||
$entity->reg_date = date("Y-m-d H:i:s");
|
$entity->reg_date = date("Y-m-d H:i:s");
|
||||||
$this->_fileEntity = $this->getModel()->create($entity);
|
return $this->getModel()->create($entity);
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
log_message("error", $e->getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,9 +43,9 @@ abstract class MyCrawlerLibrary extends CommonLibrary
|
|||||||
$mediaTag = sprintf(
|
$mediaTag = sprintf(
|
||||||
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
"<img src=\"/%s/%s/%s\" alt=\"%s\">",
|
||||||
$this->getMyStorage()->getUploadPath(),
|
$this->getMyStorage()->getUploadPath(),
|
||||||
$this->getMyStorage()->getPath(),
|
$this->getMyStorage()->getEntity()->getPath(),
|
||||||
$this->getMyStorage()->getFieName(),
|
$this->getMyStorage()->getEntity()->getTitle(),
|
||||||
$this->getMyStorage()->getFieName()
|
$this->getMyStorage()->getEntity()->getTitle()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "video":
|
case "video":
|
||||||
@ -54,11 +54,11 @@ abstract class MyCrawlerLibrary extends CommonLibrary
|
|||||||
<source src=\"/%s/%s/%s\" type=\"%s\">
|
<source src=\"/%s/%s/%s\" type=\"%s\">
|
||||||
Your browser does not support the video tag.
|
Your browser does not support the video tag.
|
||||||
</video>",
|
</video>",
|
||||||
$this->getMyStorage()->getFieName(),
|
$this->getMyStorage()->getEntity()->getTitle(),
|
||||||
$this->getMyStorage()->getUploadPath(),
|
$this->getMyStorage()->getUploadPath(),
|
||||||
$this->getMyStorage()->getPath(),
|
$this->getMyStorage()->getEntity()->getPath(),
|
||||||
$this->getMyStorage()->getFieName(),
|
$this->getMyStorage()->getEntity()->getTitle(),
|
||||||
$this->getMyStorage()->getFieMimeType(),
|
$this->getMyStorage()->getEntity()->getMimeType(),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -75,20 +75,17 @@ abstract class MyCrawlerLibrary extends CommonLibrary
|
|||||||
}
|
}
|
||||||
return $downloadInfos;
|
return $downloadInfos;
|
||||||
}
|
}
|
||||||
protected function save(string $mediaType, array $downloadInfos, $fileInfos = []): array
|
protected function save(string $mediaType, array $downloadInfos, $fileEntitys = []): array
|
||||||
{
|
{
|
||||||
foreach ($downloadInfos as $downloadInfo) {
|
foreach ($downloadInfos as $downloadInfo) {
|
||||||
$this->getMyStorage()->setFileName($downloadInfo['fileName']);
|
$entity = $this->getMyStorage()->getEntity();
|
||||||
|
$entity->setTitle($downloadInfo['fileName']);
|
||||||
if (!$this->getMyStorage()->save($downloadInfo['content'])) {
|
if (!$this->getMyStorage()->save($downloadInfo['content'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$fileInfos[] = [
|
$entity->setMediaHTML($this->getMediaTag($mediaType));
|
||||||
"mediatag" => $this->getMediaTag($mediaType),
|
$fileEntitys[] = $entity;
|
||||||
"path" => $this->getMyStorage()->getPath(),
|
|
||||||
"mimeType" => $this->getMyStorage()->getMimeType(),
|
|
||||||
"fileName" => $this->getMyStorage()->getFieName(),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
return $fileInfos;
|
return $fileEntitys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,13 @@ namespace App\Libraries\MyCrawler;
|
|||||||
|
|
||||||
|
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
use App\Libraries\MySocket\WebLibrary as MySocket;
|
|
||||||
use App\Libraries\Mangboard\FileLibrary as MyStorage;
|
|
||||||
use App\Libraries\Mangboard\BoardLibrary;
|
|
||||||
use App\Models\Mangboard\BoardModel;
|
|
||||||
use App\Entities\Mangboard\BoardEntity;
|
|
||||||
use App\Models\Mangboard\UserModel;
|
use App\Models\Mangboard\UserModel;
|
||||||
|
use App\Models\Mangboard\BoardModel;
|
||||||
|
use App\Libraries\MySocket\WebLibrary;
|
||||||
|
use App\Libraries\Mangboard\FileLibrary;
|
||||||
|
use App\Libraries\Mangboard\BoardLibrary;
|
||||||
|
use App\Entities\Mangboard\UserEntity;
|
||||||
|
use App\Entities\Mangboard\BoardEntity;
|
||||||
|
|
||||||
class YamapLibrary extends MyCrawlerLibrary
|
class YamapLibrary extends MyCrawlerLibrary
|
||||||
{
|
{
|
||||||
@ -21,36 +22,27 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getMySocket(): mixed
|
protected function getMySocket(): WebLibrary
|
||||||
{
|
{
|
||||||
if ($this->_mySocket === null) {
|
if ($this->_mySocket === null) {
|
||||||
$this->_mySocket = new MySocket(getenv('yamap.host.url'));
|
$this->_mySocket = new WebLibrary(getenv('yamap.host.url'));
|
||||||
}
|
}
|
||||||
return $this->_mySocket;
|
return $this->_mySocket;
|
||||||
}
|
}
|
||||||
final public function setMySocket($mySocket): void
|
|
||||||
{
|
|
||||||
$this->_mySocket = $mySocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
final public function getMyStorage(): mixed
|
protected function getMyStorage(): FileLibrary
|
||||||
{
|
{
|
||||||
if ($this->_myStorage === null) {
|
if ($this->_myStorage === null) {
|
||||||
$this->_myStorage = new MyStorage(getenv('yamap.storage.upload.path'));
|
$this->_myStorage = new FileLibrary(getenv('yamap.storage.upload.path'));
|
||||||
$this->_myStorage->setBoardName(getenv('crawler.yamap.registration.board'));
|
$this->_myStorage->setBoardName(getenv('yamap.storage.board.name'));
|
||||||
$this->_myStorage->setBoardTable($this->getBoardModel()->getTable());
|
$this->_myStorage->setBoardTable($this->getBoardModel()->getTable());
|
||||||
}
|
}
|
||||||
return $this->_myStorage;
|
return $this->_myStorage;
|
||||||
}
|
}
|
||||||
final public function setMyStorage($myStorage): void
|
|
||||||
{
|
|
||||||
$this->_myStorage = $myStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getBoardModel(): BoardModel
|
private function getBoardModel(): BoardModel
|
||||||
{
|
{
|
||||||
if ($this->_boardModel === null) {
|
if ($this->_boardModel === null) {
|
||||||
$this->_boardModel = new BoardModel(getenv("crawler.yamap.registration.table"));
|
$this->_boardModel = new BoardModel(getenv("yamap.storage.board.table"));
|
||||||
}
|
}
|
||||||
return $this->_boardModel;
|
return $this->_boardModel;
|
||||||
}
|
}
|
||||||
@ -64,14 +56,14 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
function (Crawler $node) use (&$items): void {
|
function (Crawler $node) use (&$items): void {
|
||||||
//bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool
|
//bbs_item에서 span.g_nickname 객체를 찾아서 작성자가 "관리자" 아닌지 확인 후 Return Bool
|
||||||
$nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text();
|
$nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text();
|
||||||
$time = date("Y-m-d") . " " . $node->filter(getenv("yamap.list.item.time.tag "))->text();
|
$hit = $node->filter(getenv("yamap.list.item.hit.tag"))->text();
|
||||||
$hit = intval($node->filter(getenv("yamap.list.item.hit.tag "))->text());
|
$date = $node->filter(getenv("yamap.list.item.date.tag"))->text();
|
||||||
if ($nickname != getenv("yamap.list.item.nickname.except")) {
|
if ($nickname != getenv("yamap.list.item.nickname.except")) {
|
||||||
//작성자가 "관리자"가 아니 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
|
//작성자가 "관리자"가 아니 게시물이면 해당 bbs_item에서 a.list_subject 객체를 찾아서
|
||||||
$link_node = $node->filter(getenv("yamap.list.item.link.tag"));
|
$link_node = $node->filter(getenv("yamap.list.item.link.tag"));
|
||||||
$detail_url = $link_node->attr("href");
|
$detail_url = $link_node->attr("href");
|
||||||
$title = $link_node->children()->last()->text();
|
$title = $link_node->children()->last()->text();
|
||||||
$items[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'time' => $time, 'hit' => $hit];
|
$items[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -81,18 +73,18 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function detailPage(string $url, array $fileInfos = []): array
|
private function detailPage(string $url, array $fileEntitys = []): array
|
||||||
{
|
{
|
||||||
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
|
$crawler = $this->getContent($url, getenv("yamap.view.content.tag"));
|
||||||
//3. Image 처리
|
//3. Image 처리
|
||||||
$downloadInfos = $this->download($crawler, ["tag" => "img", "attr" => "src"]);
|
$downloadInfos = $this->download($crawler, ["tag" => "img", "attr" => "src"]);
|
||||||
$fileInfos = $this->save("image", $downloadInfos);
|
$fileEntitys = $this->save("image", $downloadInfos);
|
||||||
//4. Video(mp4) 처리
|
//4. Video(mp4) 처리
|
||||||
$downloadInfos = $this->download($crawler, ["tag" => "video", "attr" => "src"]);
|
$downloadInfos = $this->download($crawler, ["tag" => "video", "attr" => "src"]);
|
||||||
return $this->save("video", $downloadInfos, $fileInfos);
|
return $this->save("video", $downloadInfos, $fileEntitys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createBoard(array $item, array $fileInfos): BoardEntity
|
private function createBoard(array $item, array $fileEntitys): BoardEntity
|
||||||
{
|
{
|
||||||
$board = new BoardLibrary($this->getBoardModel());
|
$board = new BoardLibrary($this->getBoardModel());
|
||||||
$board->setDebug($this->getDebug());
|
$board->setDebug($this->getDebug());
|
||||||
@ -100,14 +92,21 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
//미디어관련정보 entity에 넣기
|
//미디어관련정보 entity에 넣기
|
||||||
$entity = new BoardEntity();
|
$entity = new BoardEntity();
|
||||||
$entity->title = $item["title"];
|
$entity->title = $item["title"];
|
||||||
$entity->user_name = $item["nickname"];
|
$entity->user_pid = $this->getMyStorage()->getUser()->getPK();
|
||||||
$entity->reg_date = $item['time'];
|
$entity->user_id = $this->getMyStorage()->getUser()->getID();
|
||||||
|
$entity->user_name = $item["nickname"] != "" ? $item["nickname"] : $this->getMyStorage()->getUser()->getTitle();
|
||||||
$entity->hit = $item['hit'];
|
$entity->hit = $item['hit'];
|
||||||
|
$entity->reg_date = date("Y-m-d H:i:s", strtotime($item['date']));
|
||||||
$entity->data_type = "html";
|
$entity->data_type = "html";
|
||||||
$entity->editor_type = "S";
|
$entity->editor_type = "S";
|
||||||
foreach ($fileInfos as $fileInfo) {
|
foreach ($fileEntitys as $fileEntity) {
|
||||||
$entity->content .= $fileInfo["mediatag"];
|
$entity->content .= $fileEntity->getMediaHTML();
|
||||||
}
|
}
|
||||||
|
// echo $entity->title . "\n";
|
||||||
|
// echo $entity->user_name . "\n";
|
||||||
|
// echo $entity->hit . "\n";
|
||||||
|
// echo $entity->reg_date . "\n";
|
||||||
|
// exit;
|
||||||
//망보드에 넣기
|
//망보드에 넣기
|
||||||
return $board->create($entity);
|
return $board->create($entity);
|
||||||
}
|
}
|
||||||
@ -144,8 +143,8 @@ class YamapLibrary extends MyCrawlerLibrary
|
|||||||
//최초 게시물만 등록하기 위함
|
//최초 게시물만 등록하기 위함
|
||||||
$item = $items[0];
|
$item = $items[0];
|
||||||
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
|
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
|
||||||
$fileInfos = $this->detailPage($item["detail_url"]);
|
$fileEntitys = $this->detailPage($item["detail_url"]);
|
||||||
//4.망보드 일반게시판에 게시물 등록 처리
|
//4.망보드 일반게시판에 게시물 등록 처리
|
||||||
$this->createBoard($item, $fileInfos);
|
$this->createBoard($item, $fileEntitys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,36 +2,32 @@
|
|||||||
|
|
||||||
namespace App\Libraries\MyStorage;
|
namespace App\Libraries\MyStorage;
|
||||||
|
|
||||||
|
use App\Entities\MyStorage\FileEntity;
|
||||||
|
|
||||||
class FileLibrary extends MyStorageLibrary
|
class FileLibrary extends MyStorageLibrary
|
||||||
{
|
{
|
||||||
private $_path = "";
|
private $_path = "";
|
||||||
private $_fileName = "";
|
protected $_entity = null;
|
||||||
private $_mimeType = "";
|
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->_path = $path;
|
$this->_path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getPath(): string
|
final public function getPath(): string
|
||||||
{
|
{
|
||||||
return $this->_path;
|
return $this->_path;
|
||||||
}
|
}
|
||||||
final public function getFileName(): string
|
|
||||||
|
public function getEntity(): FileEntity
|
||||||
{
|
{
|
||||||
return $this->_fileName;
|
if ($this->_entity === null) {
|
||||||
}
|
$this->_entity = new FileEntity();
|
||||||
final public function setFileName(string $fileName): void
|
$this->_entity->setPath($this->getPath());
|
||||||
{
|
}
|
||||||
$this->_fileName = $fileName;
|
return $this->_entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getMimeType(): string
|
public function save($content): null|FileEntity
|
||||||
{
|
|
||||||
return $this->_mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save($content): bool
|
|
||||||
{
|
{
|
||||||
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
$fullPath = WRITEPATH . $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
|
||||||
if (!is_dir($fullPath)) {
|
if (!is_dir($fullPath)) {
|
||||||
@ -39,13 +35,14 @@ class FileLibrary extends MyStorageLibrary
|
|||||||
throw new \Exception("Make Directory Error:" . $fullPath);
|
throw new \Exception("Make Directory Error:" . $fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$saveFile = $fullPath . DIRECTORY_SEPARATOR . $this->getFileName();
|
$entity = $this->getEntity();
|
||||||
|
$saveFile = $fullPath . DIRECTORY_SEPARATOR . $entity->getTitle();
|
||||||
log_message("debug", "Storage Save-> " . $saveFile);
|
log_message("debug", "Storage Save-> " . $saveFile);
|
||||||
if (!file_put_contents($saveFile, $content)) {
|
if (!file_put_contents($saveFile, $content)) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
//File형식에 따른 MimeType 지정
|
//File형식에 따른 MimeType 지정
|
||||||
$this->_mimeType = mime_content_type($saveFile);
|
$entity->setMimeType(mime_content_type($saveFile));
|
||||||
return true;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Libraries\MyStorage;
|
namespace App\Libraries\MyStorage;
|
||||||
|
|
||||||
use App\Libraries\CommonLibrary;
|
use App\Libraries\CommonLibrary;
|
||||||
|
use App\Entities\MyStorage\FileEntity;
|
||||||
|
|
||||||
abstract class MyStorageLibrary extends CommonLibrary
|
abstract class MyStorageLibrary extends CommonLibrary
|
||||||
{
|
{
|
||||||
@ -12,7 +13,7 @@ abstract class MyStorageLibrary extends CommonLibrary
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function save($content): bool;
|
abstract public function save($content): null|FileEntity;
|
||||||
final public function getUploadPath(): string
|
final public function getUploadPath(): string
|
||||||
{
|
{
|
||||||
return $this->_uploadPath;
|
return $this->_uploadPath;
|
||||||
|
|||||||
@ -150,7 +150,9 @@ abstract class CommonModel extends Model
|
|||||||
$entity->$field = password_hash($entity->$field, PASSWORD_DEFAULT);
|
$entity->$field = password_hash($entity->$field, PASSWORD_DEFAULT);
|
||||||
break;
|
break;
|
||||||
case "content":
|
case "content":
|
||||||
$entity->$field = htmlentities($entity->$field, ENT_QUOTES);
|
if ($entity->$field !== null) {
|
||||||
|
$entity->$field = htmlentities($entity->$field, ENT_QUOTES);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $entity;
|
return $entity;
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class BoardModel extends CommonModel
|
|||||||
public function __construct(string $table)
|
public function __construct(string $table)
|
||||||
{
|
{
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
$fields = ["title", "user_name", "data_type", "editor_type", "reg_date", "hit", "content"];
|
$fields = ["title", "user_pid", "user_id", "user_name", "data_type", "editor_type", "reg_date", "hit", "content"];
|
||||||
parent::__construct($fields);
|
parent::__construct($fields);
|
||||||
}
|
}
|
||||||
public function getTitleField(): string
|
public function getTitleField(): string
|
||||||
@ -101,6 +101,7 @@ class BoardModel extends CommonModel
|
|||||||
$rules[$field] = "required|trim|string";
|
$rules[$field] = "required|trim|string";
|
||||||
break;
|
break;
|
||||||
case 'hit':
|
case 'hit':
|
||||||
|
case 'user_pid':
|
||||||
$rules[$field] = "if_exist|numeric";
|
$rules[$field] = "if_exist|numeric";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user