93 lines
3.8 KiB
PHP
93 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Crawler;
|
|
|
|
use App\Controllers\CommonController;
|
|
use App\Libraries\MyCrawler\YamapLibrary as MyCrawler;
|
|
use App\Libraries\MyUtil\ImageLibrary;
|
|
|
|
class YamapController extends CommonController
|
|
{
|
|
public function small_image(...$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();
|
|
}
|
|
}
|
|
public function crawling(...$params): string
|
|
{
|
|
try {
|
|
$crawler = new MyCrawler();
|
|
if (in_array("debug", $params)) {
|
|
$crawler->setDebug(true);
|
|
}
|
|
//1. 사이트 로그인 처리
|
|
$user = $crawler->login();
|
|
$crawler->getMyStorage()->setUser($user);
|
|
$items = [];
|
|
//2. 해당사이트 MainPage 처리
|
|
if ($crawler->getDebug()) {
|
|
$items[] = [
|
|
'title' => getenv("yamap.view.test.title"),
|
|
'nickname' => getenv("yamap.view.test.nickname"),
|
|
'detail_url' => getenv("yamap.view.test.url"),
|
|
'time' => date("Y-m-d H:i:s"),
|
|
'hit' => 1
|
|
];
|
|
} else {
|
|
$items = $crawler->mainPage(getenv("yamap.list.url"));
|
|
}
|
|
if (!count($items)) {
|
|
throw new \Exception("Yamap 사이트에서 게시물이 존재하지 않습니다.");
|
|
}
|
|
//Limit가 0이면 $items 갯수만큼 다하고, LIMIT 갯수 혹은 $items의 갯수중 작은수만큼 한다.
|
|
$max_limit = intval(getenv("yamap.list.max_limit"));
|
|
if ($max_limit) {
|
|
$max_limit = count($items) <= $max_limit ? count($items) : $max_limit;
|
|
} else {
|
|
$max_limit = count($items);
|
|
}
|
|
$i = 0;
|
|
foreach ($items as $item) {
|
|
if ($i <= $max_limit) {
|
|
try {
|
|
//3. DetailPage 처리 : bbs_view > div.contents 가진 객체를 찾아서 처리
|
|
$fileEntitys = $crawler->detailPage($item["detail_url"]);
|
|
//4.망보드 일반게시판에 게시물 등록 처리
|
|
if (count($fileEntitys)) {
|
|
$crawler->createBoard($item, $fileEntitys);
|
|
}
|
|
$i++;
|
|
log_message("notice", "게시물 {$i}번째 {$item["nickname"]} 작업완료.");
|
|
} catch (\Exception $e) {
|
|
log_message("debug", $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
|
|
return "완료되었습니다.";
|
|
} catch (\Exception $e) {
|
|
log_message("error", $e->getMessage());
|
|
return $e->getMessage();
|
|
}
|
|
}
|
|
}
|