diff --git a/app/Controllers/CLI/Yamap.php b/app/Controllers/CLI/Yamap.php
index 0a16f27..c14a27b 100644
--- a/app/Controllers/CLI/Yamap.php
+++ b/app/Controllers/CLI/Yamap.php
@@ -4,12 +4,13 @@ namespace App\Controllers\CLI;
use App\Controllers\BaseController;
-use App\Libraries\MyWebLibrary;
-use App\Libraries\MyStorage\MyStorageFileLibrary;
-use App\Libraries\MyCrawlerLibrary;
+use App\Entities\Mangboard\FreeboardEntity;
+use App\Libraries\Mangboard\FreeboardLibrary;
+use App\Libraries\MyCrawlerLibrary;
+use App\Libraries\MyStorage\MyStorageFileLibrary;
+use App\Libraries\MyWebLibrary;
use App\Libraries\YamapLibrary;
-use App\Libraries\Mangboard\UserLibrary;
class Yamap extends BaseController
{
@@ -21,12 +22,17 @@ class Yamap extends BaseController
$datas = [];
//Yamap사이트에서 자유게시판에서 최근 게시물 데이터 가져오기
if (!in_array("skip_build", $params)) {
+ $myWeb = new MyWebLibrary(getenv('yamap.host.url'));
+ $storage = new MyStorageFileLibrary(WRITEPATH . "uploads");
+ $storage->setPath("Yamap");
+ $crawler = new MyCrawlerLibrary();
+
$yamap = new YamapLibrary();
$yamap->setDebug($isDebug);
- $yamap->setMyWeb(new MyWebLibrary(getenv('yamap.host.url')));
- $yamap->setMyStorage(new MyStorageFileLibrary(WRITEPATH . "uploads" . DIRECTORY_SEPARATOR . "Yamap"));
- $yamap->setMyCrawler(new MyCrawlerLibrary());
- list($nickname, $datas) = $yamap->build();
+ $yamap->setMyWeb($myWeb);
+ $yamap->setMyStorage($storage);
+ $yamap->setMyCrawler($crawler);
+ list($nickname, $mediaInfos, $mediaTags) = $yamap->build();
}
//2. 사이트 로그인 처리
if (!in_array("skip_login", $params)) {
@@ -40,9 +46,14 @@ class Yamap extends BaseController
}
//3. 망보드 일반게시판에 게시물 등록 처리
if (!in_array("skip_create", $params)) {
- $mangboard = new UserLibrary();
+ $mangboard = new FreeboardLibrary();
$mangboard->setDebug($isDebug);
- // $mangboard->create();
+
+ $entity = new FreeboardEntity();
+ //미디어관련용
+ $entity->setTitle($nickname);
+ $entity->setContent(is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags);
+ $mangboard->create($entity);
}
log_message("notice", "완료되었습니다.");
return true;
diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php
index 625c06e..bb3c454 100644
--- a/app/Entities/CommonEntity.php
+++ b/app/Entities/CommonEntity.php
@@ -12,5 +12,5 @@ abstract class CommonEntity extends Entity
abstract public function __toString();
abstract public function getPK();
- abstract public function getName();
+ abstract public function getTitle();
}
diff --git a/app/Entities/Mangboard/FreeboardEntity.php b/app/Entities/Mangboard/FreeboardEntity.php
index cbccb4d..413f184 100644
--- a/app/Entities/Mangboard/FreeboardEntity.php
+++ b/app/Entities/Mangboard/FreeboardEntity.php
@@ -8,14 +8,30 @@ class FreeboardEntity extends CommonEntity
{
public function __toString(): string
{
- return "{$this->getPK()}:{$this->getName()}";
+ return "{$this->getPK()}:{$this->getTitle()}";
}
public function getPK(): int
{
return $this->attributes['pid'];
}
- public function getName(): string
+ public function getTitle(): string
{
- return $this->attributes['user_name'];
+ return $this->attributes['title'];
+ }
+ //Common Function
+
+ public function setTitle(string $title)
+ {
+ $this->attributes['title'] = $title;
+ }
+
+ public function getGID(): int
+ {
+ return $this->attributes['gid'];
+ }
+
+ public function setContent(string $content)
+ {
+ $this->attributes['content'] = $content;
}
}
diff --git a/app/Entities/Mangboard/UserEntity.php b/app/Entities/Mangboard/UserEntity.php
index 01b963c..0996307 100644
--- a/app/Entities/Mangboard/UserEntity.php
+++ b/app/Entities/Mangboard/UserEntity.php
@@ -8,16 +8,18 @@ class UserEntity extends CommonEntity
{
public function __toString(): string
{
- return "{$this->getPK()}:{$this->getID()}:{$this->getName()},{$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 getName(): string
+ public function getTitle(): string
{
return $this->attributes['user_name'];
}
+ //Common Function
+
public function getID(): string
{
return $this->attributes['user_id'];
diff --git a/app/Libraries/CommonLibrary.php b/app/Libraries/CommonLibrary.php
index 509b427..55ba6fb 100644
--- a/app/Libraries/CommonLibrary.php
+++ b/app/Libraries/CommonLibrary.php
@@ -15,4 +15,10 @@ abstract class CommonLibrary
{
$this->_debug = $debug;
}
+
+ //url에 http 나 https가 포함되어 있으면 true
+ final public function isContainsHttpOrHttps($url): bool
+ {
+ return strpos($url, 'http://') !== false || strpos($url, 'https://') !== false;
+ }
}
diff --git a/app/Libraries/Mangboard/FreeboardLibrary.php b/app/Libraries/Mangboard/FreeboardLibrary.php
index cd06f65..c454e32 100644
--- a/app/Libraries/Mangboard/FreeboardLibrary.php
+++ b/app/Libraries/Mangboard/FreeboardLibrary.php
@@ -2,8 +2,8 @@
namespace App\Libraries\Mangboard;
-use App\Entities\Mangboard\UserEntity;
-use App\Models\Mangboard\UserModel;
+use App\Entities\Mangboard\FreeboardEntity;
+use App\Models\Mangboard\FreeboardModel;
class FreeboardLibrary extends MangboardLibrary
{
@@ -13,22 +13,18 @@ class FreeboardLibrary extends MangboardLibrary
{
parent::__construct();
}
- private function getModel(): UserModel
+ private function getModel(): FreeboardModel
{
if ($this->_model === null) {
- $this->_model = new UserModel();
+ $this->_model = new FreeboardModel();
}
return $this->_model;
}
- public function create($id, int $point, $sign = '+'): UserEntity
+ public function create(FreeboardEntity $entity, array $formDatas = []): FreeboardEntity
{
- $entity = is_numeric($id) ? $this->getModel()->getEntityByPK(intval($id)) : $this->getModel()->getEntityByID($id);
- if (!$entity) {
- throw new \Exception("해당 회원[{$id}]이 없습니다.");
- }
- $entity = $this->getModel()->setPoint($entity, $point);
- log_message("debug", __FUNCTION__ . "=>[{$entity}] 회원님의 Level은 {$entity->getLevel()} 입니다.");
+ $entity = $this->getModel()->create($entity, $formDatas);
+ log_message("debug", __FUNCTION__ . "=>등록이 완료되었습니다.");
return $entity;
}
}
diff --git a/app/Libraries/MyStorage/MyStorageFileLibrary.php b/app/Libraries/MyStorage/MyStorageFileLibrary.php
index 514082e..0afc640 100644
--- a/app/Libraries/MyStorage/MyStorageFileLibrary.php
+++ b/app/Libraries/MyStorage/MyStorageFileLibrary.php
@@ -6,19 +6,18 @@ use App\Libraries\MyStorage\MyStorageLibrary;
class MyStorageFileLibrary extends MyStorageLibrary
{
- private $_defaultPath = "";
+ private $_uploadPath = "";
private $_path = "";
private $_fileName = "";
- private $_savePath = "";
- public function __construct($defaultPath)
+ public function __construct($uploadPath)
{
parent::__construct();
- $this->_defaultPath = $defaultPath;
+ $this->_uploadPath = $uploadPath;
}
- final public function getDefaultPath(): string
+ final public function getUploadPath(): string
{
- return $this->_defaultPath;
+ return $this->_uploadPath;
}
final public function getPath(): string
@@ -40,7 +39,7 @@ class MyStorageFileLibrary extends MyStorageLibrary
final public function save($content): bool
{
- $fullPath = $this->getDefaultPath() . DIRECTORY_SEPARATOR . $this->getPath();
+ $fullPath = $this->getUploadPath() . DIRECTORY_SEPARATOR . $this->getPath();
if (!is_dir($fullPath)) {
if (!mkdir($fullPath)) {
throw new \Exception("Make Directory Error:" . $fullPath);
diff --git a/app/Libraries/MyWebLibrary.php b/app/Libraries/MyWebLibrary.php
index f4e8386..9985a31 100644
--- a/app/Libraries/MyWebLibrary.php
+++ b/app/Libraries/MyWebLibrary.php
@@ -37,11 +37,6 @@ class MyWebLibrary extends CommonLibrary
return $this->_cookieJar;
}
- //url에 http 나 https가 포함되어 있으면 true
- private function isContainsHttpOrHttps($url): bool
- {
- return strpos($url, 'http://') !== false || strpos($url, 'https://') !== false;
- }
public function getContent(string $url, array $options = []): string
{
//url에 http 나 https가 포함되어 있지않으면
diff --git a/app/Libraries/YamapLibrary.php b/app/Libraries/YamapLibrary.php
index 07555a7..4a84eaf 100644
--- a/app/Libraries/YamapLibrary.php
+++ b/app/Libraries/YamapLibrary.php
@@ -92,13 +92,15 @@ class YamapLibrary extends CommonLibrary
log_message("debug", "download:{$options["tag"]},{$options["attr"]}");
$nodes = $this->getMyCrawler()->getNodes($crawler, $options);
foreach ($nodes as $node) {
- list($fileName, $content) = $this->getMyWeb()->download($node->attr($options["attr"]));
+ $original = $node->attr($options["attr"]);
+ list($fileName, $content) = $this->getMyWeb()->download($original);
$this->getMyStorage()->setFileName($fileName);
if (!$this->getMyStorage()->save($content)) {
continue;
}
$datas[] = [
- "path" => $this->getMyStorage()->getDefaultPath() . DIRECTORY_SEPARATOR . $this->getMyStorage()->getPath(),
+ "orignal" => $node->html(),
+ "path" => $this->getMyStorage()->getPath(),
"fileName" => $fileName,
"content" => $content
];
@@ -143,11 +145,27 @@ class YamapLibrary extends CommonLibrary
public function detailPage($url): array
{
$crawler = $this->getCrawler($url, getenv("yamap.view.content.tag"));
- //3. Image
+ $contents = [];
+ //3. Image 처리
$images = $this->download_process($crawler, ["tag" => "img", "attr" => "src"]);
- //4. Video
+ foreach ($images as $image) {
+ if ($this->isContainsHttpOrHttps($image['orignal'])) {
+ $contents[] = $images['orignal'];
+ } else {
+ $contents[] = sprintf("
", $image["path"], $image["fileName"], $image["fileName"]);
+ };
+ }
+
+ //4. Video(mp4) 처리
$videos = $this->download_process($crawler, ["tag" => "video", "attr" => "src"]);
- return array_merge($images, $videos);
+ foreach ($images as $image) {
+ if ($this->isContainsHttpOrHttps($image['orignal'])) {
+ $contents[] = $images['orignal'];
+ } else {
+ $contents[] = sprintf("