cfmgrv4 init...1
This commit is contained in:
parent
ff65eb98a2
commit
531d0d3384
@ -18,20 +18,6 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
|
||||
$routes->get('/', 'UserController::index');
|
||||
});
|
||||
});
|
||||
$routes->group('mangboard', ['namespace' => 'App\Controllers\Mangboard'], function ($routes) {
|
||||
$routes->group('user', function ($routes) {
|
||||
$routes->get('/', 'UserController::index');
|
||||
$routes->cli('point/(:alpha)/(:num)', 'UserController::point/$1/$2');
|
||||
$routes->cli('point/(:alpha)/(:num)/(:any)', 'UserController::point/$1/$2/$3');
|
||||
$routes->cli('level/(:alpha)/(:num)', 'UserController::level/$1/$2');
|
||||
$routes->cli('check_level', 'UserController::check_level');
|
||||
$routes->cli('check_level/(:alpha)', 'UserController::check_level/$1');
|
||||
});
|
||||
$routes->group('crawler', function ($routes) {
|
||||
$routes->cli('(:alpha)/(:any)', 'CrawlerController::$1/$2');
|
||||
$routes->cli('(:alpha)/(:any)/(:any)', 'CrawlerController::$1/$2');
|
||||
});
|
||||
});
|
||||
$routes->group('cloudflare', ['namespace' => 'App\Controllers\Cloudflare'], function ($routes) {
|
||||
$routes->group('account', function ($routes) {
|
||||
$routes->get('/', 'AccountController::index');
|
||||
|
||||
@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
|
||||
use App\Libraries\MyCrawler\Yamap;
|
||||
use App\Libraries\MyCrawler\Yamoon;
|
||||
use App\Libraries\MyCrawler\Sir;
|
||||
use App\Libraries\MyCrawler\Inven;
|
||||
use App\Models\Mangboard\UserModel;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
|
||||
|
||||
class CrawlerController extends CommonController
|
||||
{
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
final protected function getUserModel(): UserModel
|
||||
{
|
||||
if ($this->_user_model === null) {
|
||||
return $this->_user_model = new UserModel();
|
||||
}
|
||||
return $this->_user_model;
|
||||
}
|
||||
final protected function login_process(string $user_id = null): UserEntity
|
||||
{
|
||||
$user_id = $user_id ?? getenv("mangboard.login.default.id");
|
||||
$password = getenv("mangboard.login.default.password");
|
||||
// $response = $this->getWebLibrary($host)->getResponse(
|
||||
// getenv("mangboard.host.url") . getenv("mangboard.login.url"),
|
||||
// "post",
|
||||
// [
|
||||
// 'form_params' => [
|
||||
// 'user_id' => $id,
|
||||
// 'password' => $password,
|
||||
// ],
|
||||
// ]
|
||||
// );
|
||||
// if ($response->getStatusCode() == 200) {
|
||||
// $entity = $this->getUserModel()->getEntityByLoginCheck($id, $password);
|
||||
// if ($entity === null) {
|
||||
// throw new \Exception("{$id}는 회원이 아니거나 암호가 맞지 않습니다.");
|
||||
// }
|
||||
// } else {
|
||||
// throw new \Exception("연결실패:" . $response->getStatusCode());
|
||||
// }
|
||||
$entity = $this->getUserModel()->getEntityByID($user_id);
|
||||
if ($entity === null) {
|
||||
throw new \Exception("{$user_id}로 로그인 실패");
|
||||
}
|
||||
log_message("notice", "{$user_id}로 로그인 성공");
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function yamap(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
try {
|
||||
$user_entity = $this->login_process($user_id);
|
||||
$myCrawler = new Yamap(getenv("yamap.host.url"), $board_name, $user_entity);
|
||||
//추가옵션
|
||||
$myCrawler->isDebug = in_array('debug', $params);
|
||||
$myCrawler->isCopy = in_array('copy', $params);
|
||||
$myCrawler->execute();
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
public function yamoon(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
try {
|
||||
$user_entity = $this->login_process($user_id);
|
||||
$myCrawler = new Yamoon(getenv("yamoon.host.url"), $board_name, $user_entity);
|
||||
//추가옵션
|
||||
$myCrawler->isDebug = in_array('debug', $params);
|
||||
$myCrawler->isCopy = in_array('copy', $params);
|
||||
$myCrawler->execute();
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
public function sir(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
try {
|
||||
$user_entity = $this->login_process($user_id);
|
||||
$myCrawler = new Sir(getenv("sir.host.url"), $board_name, $user_entity);
|
||||
//추가옵션
|
||||
$myCrawler->isDebug = in_array('debug', $params);
|
||||
$myCrawler->isCopy = in_array('copy', $params);
|
||||
$myCrawler->execute();
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
public function inven(string $board_name, string $user_id = null, ...$params): void
|
||||
{
|
||||
// echo "{$board_name}|{$user_id}|", implode("|", $params);
|
||||
// exit;
|
||||
try {
|
||||
$user_entity = $this->login_process($user_id);
|
||||
$myCrawler = new Inven(getenv("inven.host.url"), $board_name, $user_entity);
|
||||
//추가옵션
|
||||
$myCrawler->isDebug = in_array('debug', $params);
|
||||
$myCrawler->isCopy = in_array('copy', $params);
|
||||
$myCrawler->execute();
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mangboard\Admin;
|
||||
|
||||
use App\Controllers\CommonController;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Models\Mangboard\UserModel;
|
||||
|
||||
class UserController extends CommonController
|
||||
{
|
||||
private $_model = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
private function getModel(): UserModel
|
||||
{
|
||||
if ($this->_model === null) {
|
||||
$this->_model = new UserModel();
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
public function point(string $id, string $point, string $sign = "+"): string
|
||||
{
|
||||
try {
|
||||
$entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id);
|
||||
if (!$entity) {
|
||||
throw new \Exception("해당 {$id}의 회원이 없습니다.");
|
||||
}
|
||||
$this->getModel()->setPoint($entity, intval($point), $sign);
|
||||
return __FUNCTION__ . " 작업이 완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
public function level(string $id, string $level): string
|
||||
{
|
||||
try {
|
||||
$entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id);
|
||||
if (!$entity) {
|
||||
throw new \Exception("해당 {$id}의 회원이 없습니다.");
|
||||
}
|
||||
$this->getModel()->setLevel($entity, intval($level));
|
||||
log_message("notice", "Mangboard->level 작업이 완료되었습니다.");
|
||||
return __FUNCTION__ . " 작업이 완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public function check_level($id = false): string
|
||||
{
|
||||
try {
|
||||
if (!$id) {
|
||||
foreach ($this->getModel()->getEntitys() as $entity) {
|
||||
$level = $this->getModel->checkLevel($entity);
|
||||
$this->getModel()->setLevel($entity, intval($level));
|
||||
}
|
||||
} else {
|
||||
$entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id);
|
||||
if (!$entity) {
|
||||
throw new \Exception("해당 {$id}의 회원이 없습니다.");
|
||||
}
|
||||
$level = $this->getModel->checkLevel($entity);
|
||||
$this->getModel()->setLevel($entity, intval($level));
|
||||
}
|
||||
return __FUNCTION__ . " 작업이 완료되었습니다.";
|
||||
} catch (\Exception $e) {
|
||||
log_message("error", $e->getMessage());
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Mangboard;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
use App\Models\Mangboard\BoardModel;
|
||||
|
||||
class BoardEntity extends CommonEntity
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getTitle()}";
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes[BoardModel::TITLE];
|
||||
}
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->attributes[BoardModel::TITLE] = $title;
|
||||
}
|
||||
//Common Function
|
||||
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes[BoardModel::PK];
|
||||
}
|
||||
public function getImagePath(): string
|
||||
{
|
||||
return $this->attributes['image_path'];
|
||||
}
|
||||
public function setImagePath(string $image_path): void
|
||||
{
|
||||
$this->attributes['image_path'] = $image_path;
|
||||
}
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->attributes['content'];
|
||||
}
|
||||
public function setContent(string $content): void
|
||||
{
|
||||
$this->attributes['content'] = $content;
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Mangboard;
|
||||
|
||||
use App\Entities\CommonEntity;
|
||||
use App\Models\Mangboard\BoardsModel;
|
||||
|
||||
class BoardsEntity extends CommonEntity
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getTitle()}";
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes[BoardsModel::TITLE];
|
||||
}
|
||||
public function setTitle(string $board_name): void
|
||||
{
|
||||
$this->attributes[BoardsModel::TITLE] = $board_name;
|
||||
}
|
||||
//Common Function
|
||||
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes[BoardsModel::PK];
|
||||
}
|
||||
public function getListLevel(): int
|
||||
{
|
||||
return $this->attributes['list_level'];
|
||||
}
|
||||
}
|
||||
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Mangboard;
|
||||
|
||||
use App\Models\Mangboard\FileModel;
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
class FileEntity extends CommonEntity
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getPath()}|{$this->getTitle()}|{$this->getMimeType()}}|{$this->getSequence()}번째";
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes[FileModel::TITLE];
|
||||
}
|
||||
public function setTitle(string $file_name): void
|
||||
{
|
||||
$this->attributes[FileModel::TITLE] = $file_name;
|
||||
}
|
||||
//Common Function
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes[FileModel::PK];
|
||||
}
|
||||
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 getSize(): int
|
||||
{
|
||||
return $this->attributes['file_size'];
|
||||
}
|
||||
public function setSize(int $file_size): void
|
||||
{
|
||||
$this->attributes['file_size'] = $file_size;
|
||||
}
|
||||
//한게시물에 여러개가 있을경우 번호
|
||||
final public function getSequence(): int
|
||||
{
|
||||
return $this->attributes['file_sequence'];
|
||||
}
|
||||
public function setSequence(int $file_sequence): void
|
||||
{
|
||||
$this->attributes['file_sequence'] = $file_sequence;
|
||||
}
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Mangboard;
|
||||
|
||||
use App\Models\Mangboard\UserModel;
|
||||
use App\Entities\CommonEntity;
|
||||
|
||||
class UserEntity extends CommonEntity
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return "{$this->getPK()}|{$this->getID()}|{$this->getTitle()}|lvl:{$this->getLevel()},point:{$this->getPoint()}";
|
||||
}
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->attributes[UserModel::TITLE];
|
||||
}
|
||||
public function setTitle(string $title): void
|
||||
{
|
||||
$this->attributes[UserModel::TITLE] = $title;
|
||||
}
|
||||
//Common Function
|
||||
|
||||
public function getPK(): int
|
||||
{
|
||||
return $this->attributes[UserModel::PK];
|
||||
}
|
||||
public function getID(): string
|
||||
{
|
||||
return $this->attributes['user_id'];
|
||||
}
|
||||
public function getPoint(): int
|
||||
{
|
||||
return $this->attributes['user_point'];
|
||||
}
|
||||
public function setPoint(int $point): void
|
||||
{
|
||||
|
||||
$this->attributes['user_point'] = $point;
|
||||
}
|
||||
|
||||
public function getLevel(): int
|
||||
{
|
||||
return $this->attributes['user_level'];
|
||||
}
|
||||
public function setLevel(int $value): void
|
||||
{
|
||||
$this->attributes['user_level'] = $value;
|
||||
}
|
||||
}
|
||||
@ -1,120 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler;
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
|
||||
class Inven extends MyCrawler
|
||||
{
|
||||
public function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($host, $board_name, $user_entity);
|
||||
}
|
||||
protected function getUrlByMediaType(Crawler $node, string $media_type, string $attr): null|string
|
||||
{
|
||||
switch ($media_type) {
|
||||
case 'video':
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
//그래도 null이면 data-src로 추출해본다.
|
||||
if ($url === null) {
|
||||
$attributes = $node->extract(['data-src']);
|
||||
if (count($attributes)) {
|
||||
$url = $attributes[0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
default:
|
||||
$url = parent::getUrlByMediaType($node, $media_type, $attr);
|
||||
break;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
//작성내용
|
||||
// <div class="articleContent">
|
||||
// <div id="imageCollectDiv" class="contentBody">
|
||||
// <!-- ============== CONTENT ============== -->
|
||||
// <div id="powerbbsContent">
|
||||
// <div id="BBSImageHolderTop" style="text-align:center;">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1620925350.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1587803007.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1134295360.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1481352611.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 1080 / 1350;" loading="lazy" />
|
||||
// <br><br><img src="https://upload3.inven.co.kr/upload/2024/09/15/bbs/i1878651605.jpg?MW=800" style="max-width: 100%; width: 800px; aspect-ratio: 850 / 1063;" loading="lazy" />
|
||||
// <br><br>
|
||||
// </div>
|
||||
// <div>^^</div>
|
||||
// </div>
|
||||
// <!-- ============== End CONTENT ============== -->
|
||||
// </div>
|
||||
protected function getDetailSelector(array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
return array($this->getSelector($response, getenv("inven.view.content.tag")), $listInfo);
|
||||
}
|
||||
//리스트내용
|
||||
// <div class="board-list">
|
||||
// <table>
|
||||
// <tr class="lgtm">
|
||||
// <td class="num"><span>1589</span></td>
|
||||
// <td class="tit">
|
||||
// <div class="text-wrap">
|
||||
// <div>
|
||||
// <span class="user-icon">
|
||||
// <img src="https://upload3.inven.co.kr/upload/2024/06/12/icon/i1237935053.jpg" alt="유저 아이콘" loading="lazy">
|
||||
// </span>
|
||||
// <a class="subject-link" href="https://www.inven.co.kr/board/party/5951/1589">
|
||||
// <span class="board_name">[사진&움짤]</span>스테이씨 윤
|
||||
// </a>
|
||||
// </div>
|
||||
// <span data-opinion-bbs-comeidx="5951" data-opinion-bbs-uid="1589" data-opinion-bbs-opi="1" class="con-comment">[1]</span>
|
||||
// <span class="con-icon board-img photo">사진</span>
|
||||
// </div>
|
||||
// </td>
|
||||
// <td class="user">
|
||||
// <img src="https://static.inven.co.kr/image_2011/member/level/1202/lv32.gif" alt="레벨 아이콘">
|
||||
// <span class="layerNickName" onclick="layerNickName('배수민', 'pbNickNameHandler'); ">배수민</span>
|
||||
// </td>
|
||||
// <td class="date">09-15</td>
|
||||
// <td class="view">1,502</td>
|
||||
// <td class="reco">1</td>
|
||||
// </tr>
|
||||
// </table>
|
||||
// </div>
|
||||
public function execute(): void
|
||||
{
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("inven.view.test.url.{$this->getMyStorage()->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("inven.list.url.{$this->getMyStorage()->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("inven.list.tag.{$this->getMyStorage()->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$nickname = $node->filter(getenv("inven.list.item.nickname.tag"))->text();
|
||||
$hit = $node->filter(getenv("inven.list.item.hit.tag"))->text();
|
||||
$date = date("Y") . "-" . $node->filter(getenv("inven.list.item.date.tag"))->text();
|
||||
//title및 detail url
|
||||
$link_node = $node->filter(getenv("inven.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->text();
|
||||
//title에서 예외사항비교
|
||||
if (strpos($title, getenv("inven.list.tag.except.{$this->getMyStorage()->getBoardName()}")) === false) {
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("inven.list.max_limit.{$this->getMyStorage()->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -1,310 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler;
|
||||
|
||||
use App\Libraries\MySocket\WebSocket;
|
||||
use App\Libraries\MyMangboard\Storage;
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use App\Traits\FileTrait;
|
||||
use App\Models\Mangboard\BoardsModel;
|
||||
use App\Models\Mangboard\BoardModel;
|
||||
use App\Libraries\CommonLibrary;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\BoardEntity;
|
||||
|
||||
abstract class MyCrawler extends CommonLibrary
|
||||
{
|
||||
use FileTrait;
|
||||
private $_host = "";
|
||||
private $_board_name = "";
|
||||
private $_user_entity = null;
|
||||
private $_mySocket = null;
|
||||
private $_myStorage = null;
|
||||
private $_board_model = null;
|
||||
private $_user_model = null;
|
||||
private $_boards_entity = null;
|
||||
protected function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_host = $host;
|
||||
$this->_board_name = $board_name;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
abstract protected function getDetailSelector(array $listInfo): array;
|
||||
//-----------------------필수항목-------------------//
|
||||
final protected function getMySocket(): WebSocket
|
||||
{
|
||||
if ($this->_mySocket === null) {
|
||||
$this->_mySocket = new WebSocket($this->_host);
|
||||
}
|
||||
return $this->_mySocket;
|
||||
}
|
||||
final protected function getMyStorage(): Storage
|
||||
{
|
||||
if ($this->_myStorage === null) {
|
||||
$this->_myStorage = new Storage($this->_board_name, $this->_user_entity);
|
||||
}
|
||||
return $this->_myStorage;
|
||||
}
|
||||
final protected function getBoardsEntity(): BoardsEntity
|
||||
{
|
||||
if ($this->_boards_entity === null) {
|
||||
$boardsModel = new BoardsModel();
|
||||
$this->_boards_entity = $boardsModel->getEntityByID($this->getMyStorage()->getBoardName());
|
||||
if ($this->_boards_entity === null) {
|
||||
throw new \Exception(__FUNCTION__ . "=> {$this->getMyStorage()->getBoardName()}에 해당 Board 정보가 존재하지 않습니다.");
|
||||
}
|
||||
}
|
||||
return $this->_boards_entity;
|
||||
}
|
||||
final protected function getBoardModel(): BoardModel
|
||||
{
|
||||
if ($this->_board_model === null) {
|
||||
$this->_board_model = new BoardModel("mb_" . $this->getMyStorage()->getBoardName());
|
||||
}
|
||||
return $this->_board_model;
|
||||
}
|
||||
final protected function getSelector(string $content, string $tag): Crawler
|
||||
{
|
||||
$crawler = new Crawler($content);
|
||||
if ($this->isDebug) {
|
||||
log_message("debug", __FUNCTION__ . "=> " . $tag);
|
||||
}
|
||||
$crawler->filter($tag);
|
||||
if ($this->isDebug) {
|
||||
log_message("debug", sprintf(
|
||||
"\n------------%s HTML-------------\n%s\n-----------------------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$crawler->filter($tag)->html()
|
||||
));
|
||||
}
|
||||
return $crawler->filter($tag);
|
||||
}
|
||||
protected function changeURLByCrawler(string $url): string
|
||||
{
|
||||
return preg_match('/^[^?]+/', $url, $matches) ? $matches[0] : null;
|
||||
}
|
||||
protected function getUrlByMediaType(Crawler $node, string $media_tag, string $attr): null|string
|
||||
{
|
||||
switch ($media_tag) {
|
||||
case 'video':
|
||||
$url = $node->attr($attr); //<video src="test.mp4"></video> 또는 <video data-src="test.mp4"></video>
|
||||
if ($url === null) {
|
||||
$url = $node->children()->attr("src"); //<video><source src="test.mp4"></source</video>
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
default:
|
||||
$url = $node->attr($attr);
|
||||
break;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
private function getUrlsByMediaType(Crawler $selector, string $media_tag, string $attr, array $urls = []): array
|
||||
{
|
||||
log_message("notice", "-----------" . __FUNCTION__ . "=> {$media_tag} 작업시작--------");
|
||||
$urls[$media_tag] = [];
|
||||
$selector->filter($media_tag)->each(
|
||||
function (Crawler $node) use (&$media_tag, &$attr, &$urls): void {
|
||||
$url = $this->getUrlByMediaType($node, $media_tag, $attr);
|
||||
if ($url !== null && preg_match('/^[^?]+/', $url, $matches)) {
|
||||
$urls[$media_tag][] = $this->changeURLByCrawler($matches[0]);
|
||||
} else {
|
||||
log_message("debug", __FUNCTION__ . "-> {$media_tag}:{$attr}\n");
|
||||
//Node 모든 속성은 DOMElement 변환 후 반환가능
|
||||
$domNode = $node->getNode(0);
|
||||
if ($domNode->hasAttributes()) {
|
||||
foreach ($domNode->attributes as $attr) {
|
||||
log_message("debug", "{$attr->nodeName} = {$attr->nodeValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
log_message("notice", "-----------" . __FUNCTION__ . "=> {$media_tag} 작업완료--------");
|
||||
return $urls;
|
||||
}
|
||||
private function media_save(int $file_sequence, string $media_tag, string $file_name, string $content): mixed
|
||||
{
|
||||
log_message("debug", __FUNCTION__ . " 원본파일 {$file_name} 작업 시작");
|
||||
$storage = clone $this->getMyStorage();
|
||||
$storage->setOriginName($file_name);
|
||||
$storage->setOriginContent($content);
|
||||
$storage->setOriginMediaTag($media_tag);
|
||||
$storage->setOriginSequence($file_sequence);
|
||||
return $storage->save();
|
||||
}
|
||||
//ViewPage의 이미지나영상데이터가 있으면 Dodownload 한다.
|
||||
private function media_download(string $media_tag, string $url): array
|
||||
{
|
||||
$file_names = explode('/', $url);
|
||||
if (!is_array($file_names) || !count($file_names)) {
|
||||
throw new \Exception("URL이 파일명 형식이 아닙니다 : " . $this->getMySocket()->getHost() . $url);
|
||||
}
|
||||
$file_name = array_pop($file_names);
|
||||
$temps = explode(".", $file_name);
|
||||
$file_ext = array_pop($temps);
|
||||
if (!$this->isFileType_FileTrait($file_ext, $media_tag)) {
|
||||
throw new \Exception("파일명 형식이 {$media_tag}가 아닙니다");
|
||||
}
|
||||
$content = $this->getMySocket()->getContent($url);
|
||||
log_message("notice", "{$file_name} 파일이 다운로드되었습니다!");
|
||||
return array($file_name, $content);
|
||||
}
|
||||
private function media_process(array $media_urls): array
|
||||
{
|
||||
$file_sequence = 1;
|
||||
$storages = []; //CreateBoard에서 사용을 위해 DetailPage마다 초기화
|
||||
foreach ($media_urls as $media_tag => $urls) {
|
||||
$total = count($urls);
|
||||
foreach ($urls as $url) {
|
||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째/총:{$total} MediaType->{$media_tag} 작업 시작");
|
||||
try {
|
||||
list($file_name, $content) = $this->media_download($media_tag, $url);
|
||||
$storage = $this->media_save($file_sequence, $media_tag, $file_name, $content);
|
||||
log_message("debug", __FUNCTION__ . " {$file_sequence}번째/총:{$total} 결과=>" . $storage->getOriginName());
|
||||
$storages[] = $storage;
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s MediaType->%s {$file_sequence}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$media_tag,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " {$file_sequence}번째/총:{$total} MediaType->{$media_tag} 작업 완료");
|
||||
$file_sequence++;
|
||||
}
|
||||
}
|
||||
return $storages;
|
||||
}
|
||||
|
||||
//Board 등록작업
|
||||
private function create_board(int $cnt, array $listInfo, array $storages, array $formDatas = ['image_path' => "", 'content' => ""]): BoardEntity
|
||||
{
|
||||
//Board DB 등록작업등
|
||||
//미디어관련정보 entity에 넣기
|
||||
$formDatas[BoardModel::TITLE] = $listInfo["title"];
|
||||
$formDatas['user_pid'] = $this->getMyStorage()->getUserEntity()->getPK();
|
||||
$formDatas['user_id'] = $this->getMyStorage()->getUserEntity()->getID();
|
||||
$formDatas['user_name'] = $listInfo["nickname"] != "" ? $listInfo["nickname"] : $this->getMyStorage()->getUserEntity()->getTitle();
|
||||
$formDatas['level'] = $this->getBoardsEntity()->getListLevel();
|
||||
$formDatas['hit'] = intval($listInfo['hit']);
|
||||
$formDatas['reg_date'] = date("Y-m-d H:i:s", strtotime($listInfo['date']));
|
||||
$formDatas['data_type'] = "html";
|
||||
$formDatas['editor_type'] = "S";
|
||||
foreach ($storages as $storage) {
|
||||
if ($formDatas['image_path'] == "") {
|
||||
$formDatas['image_path'] = $storage->getBasePath() . DIRECTORY_SEPARATOR . $storage->getPath() . DIRECTORY_SEPARATOR . $storage->getOriginName();
|
||||
}
|
||||
$formDatas['content'] .= $storage->getHTMLTag();
|
||||
}
|
||||
//망보드 게시판에 등록
|
||||
if ($formDatas['content'] == "") {
|
||||
throw new \Exception(sprintf(
|
||||
"%s=>%s번째 %s 내용이 없어 => %s 등록 안함 : storage->%s",
|
||||
__FUNCTION__,
|
||||
$cnt,
|
||||
$listInfo["title"],
|
||||
$this->getBoardModel()->getTable(),
|
||||
count($storages)
|
||||
));
|
||||
}
|
||||
$board_entity = $this->getBoardModel()->create($formDatas);
|
||||
log_message("notice", sprintf(
|
||||
"%s=>%s번째 %s => %s 등록 완료 : storage->%s",
|
||||
__FUNCTION__,
|
||||
$cnt,
|
||||
$listInfo["title"],
|
||||
$this->getBoardModel()->getTable(),
|
||||
count($storages)
|
||||
));
|
||||
return $board_entity;
|
||||
}
|
||||
//File DB 등록작업, 작은이미지 생성
|
||||
private function create_storages(BoardEntity $board_entity, array $storages)
|
||||
{
|
||||
foreach ($storages as $storage) {
|
||||
try {
|
||||
$storage->create($this->getBoardsEntity(), $board_entity, $this->getBoardModel()->getTable());
|
||||
} 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()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
private function detail_copy_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
list($selector, $listInfo) = $this->getDetailSelector($listInfo);
|
||||
$formDatas = [];
|
||||
$formDatas['image_path'] = "";
|
||||
$formDatas['content'] = $selector->html();
|
||||
//Board 등록작업등
|
||||
$this->create_board($cnt, $listInfo, [], $formDatas);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
private function detail_download_process(int $cnt, array $listInfo): array
|
||||
{
|
||||
list($selector, $listInfo) = $this->getDetailSelector($listInfo);
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "img", "src");
|
||||
$media_urls = $this->getUrlsByMediaType($selector, "video", "src", $media_urls);
|
||||
if ($this->isDebug) {
|
||||
throw new \Exception(sprintf(
|
||||
"\n--------------%s Debug--------------\n%s%s\n---------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
var_export($listInfo, true),
|
||||
var_export($media_urls, true)
|
||||
));
|
||||
} else {
|
||||
// Image 나 Video 소스들의 url을 가져와서 실제 다운받는 처리
|
||||
$storages = $this->media_process($media_urls);
|
||||
if (!count($storages)) {
|
||||
throw new \Exception("등록할 자료가 없습니다.");
|
||||
}
|
||||
//Board 등록작업등
|
||||
$board_entity = $this->create_board($cnt, $listInfo, $storages);
|
||||
//File DB 등록작업, 작은이미지 생성
|
||||
$this->create_storages($board_entity, $storages);
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
return $listInfo;
|
||||
}
|
||||
protected function list_process(int $max_limit, array $listInfos): void
|
||||
{
|
||||
//Limit가 0이면 $listInfos 갯수만큼 다하고, LIMIT 갯수 혹은 item의 갯수중 작은수만큼 한다.
|
||||
$max_limit = !$max_limit || count($listInfos) <= $max_limit ? count($listInfos) : $max_limit;
|
||||
$total = count($listInfos);
|
||||
$i = 1;
|
||||
foreach ($listInfos as $listInfo) {
|
||||
if ($i <= $max_limit) {
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업시작");
|
||||
try {
|
||||
if ($this->isCopy) {
|
||||
$listInfo = $this->detail_copy_process($i, $listInfo);
|
||||
} else {
|
||||
//listInfo는 title,작성자,작성시간등등의 정보를 가지고 있어 detail_process 처리 안에서 바뀔 수 있으므로 다시 반환 받는다.
|
||||
$listInfo = $this->detail_download_process($i, $listInfo);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
log_message("warning", sprintf(
|
||||
"\n---%s {$i}번째/총:{$total} 오류---\n%s\n-----------------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 게시물 {$i}번째/총:{$total} {$listInfo["nickname"]} 작업완료.");
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler;
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use DateTime;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
|
||||
class Sir extends MyCrawler
|
||||
{
|
||||
public function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($host, $board_name, $user_entity);
|
||||
}
|
||||
protected function changeURLByCrawler(string $url): string
|
||||
{
|
||||
return str_replace("/sir.kr/", "", parent::changeURLByCrawler($url));
|
||||
}
|
||||
//작성내용
|
||||
// <article class="sir_vbo ">
|
||||
// <header class="vbo_head">
|
||||
// <h2 class="head_h2">할아버지의 마술 정보</h2>
|
||||
// <strong id="head_title">
|
||||
// 할아버지의 마술 </strong>
|
||||
// <ul id="head_info">
|
||||
// <li id="info_name"><span class="sv_wrap">
|
||||
// <a href="//sir.kr/bbs/profile.php?mb_id=hadirector" class="sv_member" title="감독님 자기소개" target="_blank" rel="nofollow" onclick="return false;"><span class="sir_mb_icon"></span> <span class="member">감독님</span></a>
|
||||
// <span class="sv">
|
||||
// <a href="//sir.kr/bbs/profile.php?mb_id=hadirector" onclick="win_profile(this.href); return false;"><i class="fa fa-user" aria-hidden="true"></i> 자기소개</a>
|
||||
// <a href="//sir.kr/cm_humor?sca=&sfl=mb_id,1&stx=hadirector"><i class="fa fa-search" aria-hidden="true"></i> 아이디로 검색</a>
|
||||
// <a href="//sir.kr/main/member/?mb_id=hadirector"><i class="fa fa-file-text-o" aria-hidden="true"></i> 회원게시물</a>
|
||||
// </span>
|
||||
// <noscript class="sv_nojs"><span class="sv">
|
||||
// <a href="//sir.kr/bbs/profile.php?mb_id=hadirector" onclick="win_profile(this.href); return false;"><i class="fa fa-user" aria-hidden="true"></i> 자기소개</a>
|
||||
// <a href="//sir.kr/cm_humor?sca=&sfl=mb_id,1&stx=hadirector"><i class="fa fa-search" aria-hidden="true"></i> 아이디로 검색</a>
|
||||
// <a href="//sir.kr/main/member/?mb_id=hadirector"><i class="fa fa-file-text-o" aria-hidden="true"></i> 회원게시물</a>
|
||||
// </span>
|
||||
// </noscript></span> (210.♡.♡.13)</li>
|
||||
// <li id="info_date"><time datetime='2024-09-13T00:24:04+09:00'>2024.09.13 00:24:04</time></li>
|
||||
// <li id="info_hit"> 조회 <span>245</span>
|
||||
// </li>
|
||||
// <li id="info_cmt">
|
||||
// <a href="#vcmt_anchor" class="comment">댓글 <span>3</span></a>
|
||||
// </li>
|
||||
// </ul>
|
||||
// <div id="head_img"><span class='sir_mb_img' title='회원정보에 사진을 올려주세요.'></span></div>
|
||||
// </header>
|
||||
// <script>
|
||||
// $(".vcmt-btn").click(function() {
|
||||
// $('html, body').animate({
|
||||
// scrollTop: $("#vcmt_anchor").offset().top - 100
|
||||
// }, 300);
|
||||
// });
|
||||
// </script>
|
||||
// <ul class="sir_vbo_cmd link">
|
||||
// <li><a href="javascript:void(0)" class="sir_b01 sir_prev"><span class="sound_only">이전 게시글</span><i class="fa fa-angle-left"></i></a></li>
|
||||
// <li><a href="//sir.kr/cm_humor/191445" class="sir_b01 sir_next"><span class="sound_only">다음 게시글</span><i class="fa fa-angle-right"></i></a></li>
|
||||
// </ul>
|
||||
// <ul class="sir_vbo_com" >
|
||||
// <li><a href="//sir.kr/cm_humor" class="sir_b01">목록</a></li>
|
||||
// </ul>
|
||||
// <section id="vbo_con">
|
||||
// <h2 class="con_h2">본문</h2>
|
||||
// <div class="con_inner">
|
||||
// <div id="con_pix">
|
||||
// <video autoplay="autoplay" loop="loop" preload="auto" playsinline webkit-playsinline muted>
|
||||
// <source src="//sir.kr/data/file/cm_humor/3535243533_CiH6Iv9O_ee170eeec15e748d9bfcc895836c71d9829c07fb.mp4" type="video/mp4" />
|
||||
// </video>
|
||||
// </div>
|
||||
//
|
||||
protected function getDetailSelector(array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
//작성시간
|
||||
$selector = $this->getSelector($response, getenv("sir.view.date.tag"));
|
||||
//Date Format이 맞지않아 변경해주기위함 : 2024.09.13 00:24:04 -> 2024-09-13 00:24:04
|
||||
$listInfo['date'] = trim($selector->text());
|
||||
$listInfo['date'] = DateTime::createFromFormat('Y.m.d H:i:s', $listInfo['date']);
|
||||
$listInfo['date'] = $listInfo['date']->format('Y-m-d H:i:s');
|
||||
return array($this->getSelector($response, tag: getenv("sir.view.content.tag")), $listInfo);
|
||||
}
|
||||
//리스트 내용
|
||||
// <td class="listvisited mobile-td subject-view">
|
||||
// <a href="board-read.asp?fullboardname=yamoonfreeboard&mtablename=humor&num=89372&ref=85575&page=1" class="ya-tooltip mobile-bold mobile-height" title="<p><br><br><video autoplay="autoplay" loop="loop" muted="" controls="controls" width="560"" height=" "> <source src=" https://files.bepick.net/bbs/2024/09/c2a20ab5771cbb934940551859fce1c8_769966583.mp4 "> </video><br><br><br></p">
|
||||
// 졸고 있는 여군</a>
|
||||
// <i class="fa fa-commenting-o" aria-hidden="true"></i> <span class="color-red small">6</span>
|
||||
// <span class="visible-xs visible-sm small"><i class="fa fa-user-o" aria-hidden="true"></i> yeeyuu | <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> 6 | <i class="fa fa-eye" aria-hidden="true"></i> 369 | No 89372 | 2024-09-13</span>
|
||||
// </td>
|
||||
public function execute(): void
|
||||
{
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("sir.view.test.url.{$this->getMyStorage()->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("sir.list.url.{$this->getMyStorage()->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("sir.list.tag.{$this->getMyStorage()->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$nickname = $node->filter(getenv("sir.list.item.nickname.tag"))->text();
|
||||
$hit = $node->filter(getenv("sir.list.item.hit.tag"))->text();
|
||||
// 작성시간은 detail에서 정의
|
||||
// $date = $node->filter(getenv("sir.list.item.date.tag"))->text();
|
||||
//title및 detail url
|
||||
$link_node = $node->filter(getenv("sir.list.item.link.tag"));
|
||||
// href url의 맨 앞이 /sir.kr가 빼기
|
||||
$detail_url = $this->changeURLByCrawler($link_node->attr("href"));
|
||||
$title = $link_node->text();
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => "", 'hit' => $hit];
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("sir.list.max_limit.{$this->getMyStorage()->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler;
|
||||
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class Yamap extends MyCrawler
|
||||
{
|
||||
public function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($host, $board_name, $user_entity);
|
||||
}
|
||||
protected function getDetailSelector(array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent($listInfo['detail_url']);
|
||||
return array($this->getSelector($response, getenv("yamap.view.content.tag")), $listInfo);
|
||||
}
|
||||
//리스트내용
|
||||
// <div class="panel panel-default">
|
||||
// <div class="text-center panel-heading-local-title text-bold">요즘 패션</div>
|
||||
// <div style="margin:5px 10px;">
|
||||
// <span class="pull-left dropdown">
|
||||
// 괴강고귀
|
||||
// </span>
|
||||
// <span class="pull-right">
|
||||
// | 추천 (14) | 조회 (432)
|
||||
// </span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="hr-xs-xs">
|
||||
// <span>
|
||||
// <a href="javascript:void(0);" id="incfont"><i class="fa fa-plus fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" id="decfont"><i class="fa fa-minus fa-fw margin-left-5" aria-hidden="true"></i></a>
|
||||
// </span>
|
||||
// <span class="pull-right">2024-09-14 01:53:45
|
||||
// </span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="margin-top-5 margin-bottom-20">
|
||||
// <div class="fr-view margin-bottom-30" id="read-content" style="word-break:break-all;">
|
||||
// <p><img title="" class="cloudzoom" data-cloudzoom="zoomImage:'/newboard/yamoonfreeboard/uploads/humor/mceu_86177012011726246415487.jpg'" class="fr-fic fr-dii" src="/newboard/yamoonfreeboard/uploads/humor/mceu_86177012011726246415487.jpg" alt=""></p>
|
||||
// <p> </p>
|
||||
// </div>
|
||||
// </div>
|
||||
// <div class="margin-10">
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://twitter.com/intent/tweet?text='+encodeURIComponent(document.title)+'%20-%20'+encodeURIComponent(document.URL), 'twittersharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-twitter-square fa-lg ya-tooltip" title="트위터 공유하기"></i></a>
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(document.URL)+'&t='+encodeURIComponent(document.title), 'facebooksharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-facebook-square fa-lg ya-tooltip" title="페이스북 공유하기"></i></a>
|
||||
// </div>
|
||||
// <div id="freesubframe"></div>
|
||||
// </div>
|
||||
|
||||
final public function execute(): void
|
||||
{
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("yamap.view.test.url.{$this->getMyStorage()->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("yamap.list.url.{$this->getMyStorage()->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("yamap.list.tag.{$this->getMyStorage()->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
$nickname = $node->filter(getenv("yamap.list.item.nickname.tag"))->text();
|
||||
$hit = $node->filter(getenv("yamap.list.item.hit.tag"))->text();
|
||||
$date = $node->filter(getenv("yamap.list.item.date.tag"))->text();
|
||||
//title및 detail url
|
||||
$link_node = $node->filter(getenv("yamap.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->children()->last()->text();
|
||||
//title에서 예외사항비교
|
||||
if (strpos($title, getenv("yamap.list.tag.except.{$this->getMyStorage()->getBoardName()}")) === false) {
|
||||
$listInfos[] = ['title' => $title, 'nickname' => $nickname, 'detail_url' => $detail_url, 'date' => $date, 'hit' => $hit];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("yamap.list.max_limit.{$this->getMyStorage()->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyCrawler;
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
|
||||
class Yamoon extends MyCrawler
|
||||
{
|
||||
public function __construct(string $host, string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($host, $board_name, $user_entity);
|
||||
}
|
||||
//작성내용
|
||||
// <div class="panel panel-default">
|
||||
// <div class="text-center panel-heading-local-title text-bold">요즘 화제라는 명품 목걸이</div>
|
||||
// <div style="margin:5px 10px;">
|
||||
// <span class="pull-left dropdown">CAT7478</span>
|
||||
// <span class="pull-right">| 추천 (8) | 조회 (268)</span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="hr-xs-xs">
|
||||
// <span>
|
||||
// <a href="javascript:void(0);" id="incfont"><i class="fa fa-plus fa-fw" aria-hidden="true"></i></a><a href="javascript:void(0);" id="decfont"><i class="fa fa-minus fa-fw margin-left-5" aria-hidden="true"></i></a>
|
||||
// </span>
|
||||
// <span class="pull-right">2024-09-16 09:52:39</span>
|
||||
// <div class="clearfix"></div>
|
||||
// <hr class="margin-top-5 margin-bottom-20">
|
||||
// <div class="fr-view margin-bottom-30" id="read-content" style="word-break:break-all;">
|
||||
// <p><img title="" class="cloudzoom" data-cloudzoom="zoomImage:'/newboard/yamoonfreeboard/uploads/humor/mceu_18297097311726447898684.webp'" class="fr-fic fr-dii" src="/newboard/yamoonfreeboard/uploads/humor/mceu_18297097311726447898684.webp" alt=""></p>
|
||||
// <p><img title="" class="cloudzoom" data-cloudzoom="zoomImage:'/newboard/yamoonfreeboard/uploads/humor/mceu_41105156321726447902977.png'" class="fr-fic fr-dii" src="/newboard/yamoonfreeboard/uploads/humor/mceu_41105156321726447902977.png" alt=""></p>
|
||||
// <p> </p>
|
||||
// <p> </p>
|
||||
// <p>전화기선 짤라서 목걸이 만들어도 위화감이 전혀 없을것같은</p>
|
||||
// <p> </p>
|
||||
// <p>디자인이군요</p>
|
||||
// <p> </p>
|
||||
// </div>
|
||||
// </div>
|
||||
// <div class="margin-10">
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://twitter.com/intent/tweet?text='+encodeURIComponent(document.title)+'%20-%20'+encodeURIComponent(document.URL), 'twittersharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-twitter-square fa-lg ya-tooltip" title="트위터 공유하기"></i></a>
|
||||
// <a href="javascript:void(0)" onclick="javascript:window.open('https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(document.URL)+'&t='+encodeURIComponent(document.title), 'facebooksharedialog', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank"> <i class="fa fa-facebook-square fa-lg ya-tooltip" title="페이스북 공유하기"></i></a>
|
||||
// </div>
|
||||
// <div id="freesubframe"></div>
|
||||
// </div>
|
||||
protected function getDetailSelector(array $listInfo): array
|
||||
{
|
||||
$response = $this->getMySocket()->getContent("/newboard/yamoonboard/" . $listInfo['detail_url']);
|
||||
return array($this->getSelector($response, getenv("yamoon.view.content.tag")), $listInfo);
|
||||
}
|
||||
//리스트 내용
|
||||
// <td class="listvisited mobile-td subject-view">
|
||||
// <a href="board-read.asp?fullboardname=yamoonfreeboard&mtablename=humor&num=89372&ref=85575&page=1" class="ya-tooltip mobile-bold mobile-height" title="<p><br><br><video autoplay="autoplay" loop="loop" muted="" controls="controls" width="560"" height=" "> <source src=" https://files.bepick.net/bbs/2024/09/c2a20ab5771cbb934940551859fce1c8_769966583.mp4 "> </video><br><br><br></p">
|
||||
// 졸고 있는 여군</a>
|
||||
// <i class="fa fa-commenting-o" aria-hidden="true"></i> <span class="color-red small">6</span>
|
||||
// <span class="visible-xs visible-sm small"><i class="fa fa-user-o" aria-hidden="true"></i> yeeyuu | <i class="fa fa-thumbs-o-up" aria-hidden="true"></i> 6 | <i class="fa fa-eye" aria-hidden="true"></i> 369 | No 89372 | 2024-09-13</span>
|
||||
// </td>
|
||||
public function execute(): void
|
||||
{
|
||||
$listInfos = [];
|
||||
if ($this->isDebug) {
|
||||
$listInfo = [];
|
||||
$listInfo['title'] = 'test_title';
|
||||
$listInfo['nickname'] = 'test_name';
|
||||
$listInfo['hit'] = 1;
|
||||
$listInfo['date'] = date("Y-m-d H:i:s");
|
||||
$listInfo['detail_url'] = getenv("yamoon.view.test.url.{$this->getMyStorage()->getBoardName()}");
|
||||
$listInfos[] = $listInfo;
|
||||
} else {
|
||||
$response = $this->getMySocket()->getContent(getenv("yamoon.list.url.{$this->getMyStorage()->getBoardName()}"));
|
||||
$this->getSelector($response, getenv("yamoon.list.tag.{$this->getMyStorage()->getBoardName()}"))->each(
|
||||
function (Crawler $node) use (&$listInfos): void {
|
||||
//title및 detail url
|
||||
$link_node = $node->filter(getenv("yamoon.list.item.link.tag"));
|
||||
$detail_url = $link_node->attr("href");
|
||||
$title = $link_node->text();
|
||||
//기타정보기 |로 구분되어 있어 작업
|
||||
$info_node = $node->filter(getenv("yamoon.list.item.info.tag"));
|
||||
$infos = explode("|", $info_node->text());
|
||||
$listInfos[] = ['title' => $title, 'detail_url' => $detail_url, 'nickname' => trim($infos[0]), 'hit' => trim($infos[2]), 'date' => trim($infos[4])];
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!count($listInfos)) {
|
||||
throw new \Exception("Target URL이 없습니다.");
|
||||
}
|
||||
$this->list_process(intval(getenv("yamoon.list.max_limit.{$this->getMyStorage()->getBoardName()}")), $listInfos);
|
||||
log_message("notice", __FUNCTION__ . " 작업이 완료되었습니다.");
|
||||
}
|
||||
}
|
||||
@ -1,155 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\MyMangboard;
|
||||
|
||||
use App\Entities\Mangboard\BoardEntity;
|
||||
use App\Entities\Mangboard\BoardsEntity;
|
||||
use App\Entities\Mangboard\FileEntity;
|
||||
use App\Entities\Mangboard\UserEntity;
|
||||
use App\Libraries\MyStorage\FileStorage;
|
||||
use App\Models\Mangboard\FileModel;
|
||||
use App\Traits\ImageTrait;
|
||||
|
||||
class Storage extends FileStorage
|
||||
{
|
||||
use ImageTrait;
|
||||
private $_board_name = "";
|
||||
private $_user_entity = null;
|
||||
private $_fileModel = null;
|
||||
public function __construct(string $board_name, UserEntity $user_entity)
|
||||
{
|
||||
parent::__construct($board_name);
|
||||
$this->_board_name = $board_name;
|
||||
$this->_user_entity = $user_entity;
|
||||
}
|
||||
final public function getBoardName(): string
|
||||
{
|
||||
if ($this->_board_name === "") {
|
||||
throw new \Exception("BoardName이 정의되지 않았습니다.");
|
||||
}
|
||||
return $this->_board_name;
|
||||
}
|
||||
final public function getUserEntity(): UserEntity
|
||||
{
|
||||
if ($this->_user_entity === null) {
|
||||
throw new \Exception("UserEntity가 정의되지 않았습니다.");
|
||||
}
|
||||
return $this->_user_entity;
|
||||
}
|
||||
final protected function getFileModel(): FileModel
|
||||
{
|
||||
if ($this->_fileModel === null) {
|
||||
$this->_fileModel = new FileModel();
|
||||
}
|
||||
return $this->_fileModel;
|
||||
}
|
||||
final public function getBasePath(): string
|
||||
{
|
||||
return getenv("mangboard.uploads.path");
|
||||
}
|
||||
final public function getUploadPath(): string
|
||||
{
|
||||
return parent::getUploadPath() . DIRECTORY_SEPARATOR . $this->getBasePath();
|
||||
}
|
||||
final public function getUploadURL(): string
|
||||
{
|
||||
return sprintf("/wp-content/%s/%s/%s", parent::getUploadURL(), $this->getBasePath(), $this->getBasePath());
|
||||
}
|
||||
final public function getHTMLTag(string $content = ""): string
|
||||
{
|
||||
//Board 게시판 image_path , content용 데이터 배열에 추가 후 modifyBoard에서 처리
|
||||
switch ($this->getOriginMediaTag()) {
|
||||
case "img":
|
||||
$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;
|
||||
}
|
||||
|
||||
private function create_file(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): FileEntity
|
||||
{
|
||||
|
||||
$formDatas['board_pid'] = $board_entity->getPk();
|
||||
$formDatas['user_pid'] = $this->_user_entity->getPK();
|
||||
$formDatas['user_name'] = $this->_user_entity->getTitle();
|
||||
$formDatas['board_name'] = $boards_entity->getTitle();
|
||||
$formDatas['table_name'] = $board_table;
|
||||
$formDatas['file_path'] = $this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath() . DIRECTORY_SEPARATOR . $this->getOriginName();
|
||||
$formDatas[FileModel::TITLE] = $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->getFileModel()->create($formDatas);
|
||||
log_message("notice", sprintf(
|
||||
"%s -> %s 게시물의 %s번째:%s 파일 등록 완료",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$this->getOriginSequence(),
|
||||
$entity->getTitle()
|
||||
));
|
||||
return $entity;
|
||||
}
|
||||
|
||||
private function create_small_image(BoardEntity $board_entity, $target_name = "small", int $width = 480, int $height = 319): void
|
||||
{
|
||||
$fileInfo = pathinfo($this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName(), PATHINFO_ALL);
|
||||
$target_file_name = sprintf("%s_%s.%s", $fileInfo['filename'], $target_name, $fileInfo['extension']);
|
||||
if (!$this->isFileType_FileTrait($fileInfo['extension'])) {
|
||||
throw new \Exception("{$this->getOriginName()} Image 형식파일이 아닙니다.");
|
||||
}
|
||||
// 이미지 파일 로드
|
||||
$this->load_ImageTrait($this->getFullPath() . DIRECTORY_SEPARATOR . $this->getOriginName());
|
||||
// 200x200으로 이미지 크기 조정
|
||||
$this->resize_ImageTrait($width, $height);
|
||||
// 파일 저장
|
||||
$this->save_ImageTrait($this->getFullPath() . DIRECTORY_SEPARATOR . $target_file_name);
|
||||
// 메모리 해제
|
||||
$this->destroy_ImageTrait();
|
||||
log_message("notice", sprintf(
|
||||
"%s -> %s 게시물의 %s번째:%s->%s 작은이미지(W:%s,H:%s) 생성 완료",
|
||||
__FUNCTION__,
|
||||
$board_entity->getTitle(),
|
||||
$this->getOriginSequence(),
|
||||
$this->getOriginName(),
|
||||
$target_file_name,
|
||||
$width,
|
||||
$height
|
||||
));
|
||||
}
|
||||
|
||||
final public function create(BoardsEntity $boards_entity, BoardEntity $board_entity, string $board_table): void
|
||||
{
|
||||
//File DB에 넣기
|
||||
$this->create_file($boards_entity, $board_entity, $board_table);
|
||||
//작은이미지 만들기
|
||||
$this->create_small_image($board_entity);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user