Automation init...1

This commit is contained in:
최준흠 2024-09-05 21:45:59 +09:00
parent 41f83d2234
commit 3b912875c3
6 changed files with 112 additions and 94 deletions

View File

@ -18,7 +18,7 @@ $routes->get('/', 'Home::index');
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) { $routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
$routes->cli('mangboard/level', 'Mangboard::level'); $routes->cli('mangboard/level', 'Mangboard::level');
$routes->cli('yamap/crawler', 'Yamap::crawler'); $routes->cli('yamap/crawler', 'Yamap::crawler');
$routes->cli('yamap/crawler(:any)', 'Yamap::crawler/$1'); $routes->cli('yamap/crawler/(:any)', 'Yamap::crawler/$1');
}); });
$routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) { $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'authFilter:manager'], function ($routes) {

View File

@ -34,26 +34,29 @@ class Yamap extends BaseController
$yamap->setMyCrawler($crawler); $yamap->setMyCrawler($crawler);
list($nickname, $mediaInfos, $mediaTags) = $yamap->build(); list($nickname, $mediaInfos, $mediaTags) = $yamap->build();
} }
//2. 사이트 로그인 처리 // //2. 사이트 로그인 처리
if (!in_array("skip_login", $params)) { // if (!in_array("skip_login", $params)) {
$myWeb = new MyWebLibrary(getenv('daemonidc.host.url')); // $daemonidc = new MyWebLibrary(getenv('daemonidc.host.url'));
$myWeb->setDebug($isDebug); // $daemonidc->setDebug($isDebug);
$myWeb->login( // $daemonidc->login(
getenv('daemonidc.login.url'), // getenv('daemonidc.login.url'),
getenv('daemonidc.login.user_id'), // getenv('daemonidc.login.user_id'),
getenv('daemonidc.login.user_password') // getenv('daemonidc.login.user_password')
); // );
} // }
//3. 망보드 일반게시판에 게시물 등록 처리 //3. 망보드 일반게시판에 게시물 등록 처리
if (!in_array("skip_create", $params)) { if (!in_array("skip_create", $params)) {
$mangboard = new FreeboardLibrary(); $board = new FreeboardLibrary();
$mangboard->setDebug($isDebug); $board->setDebug($isDebug);
//미디어관련정보 entity에 넣기
$entity = new FreeboardEntity(); $entity = new FreeboardEntity();
//미디어관련용
$entity->setTitle($nickname); $entity->setTitle($nickname);
$entity->setText($nickname);
$entity->setContent(is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags); $entity->setContent(is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags);
$mangboard->create($entity);
//망보드에 넣기
$board->create($entity);
} }
log_message("notice", "완료되었습니다."); log_message("notice", "완료되었습니다.");
return true; return true;

View File

@ -20,18 +20,27 @@ class FreeboardEntity extends CommonEntity
} }
//Common Function //Common Function
public function setTitle(string $title) public function setTitle(string $value)
{ {
$this->attributes['title'] = $title; $this->attributes['title'] = $value;
} }
public function getGID(): int public function getGID(): int
{ {
return $this->attributes['gid']; return $this->attributes['gid'];
} }
public function setGID(int $value)
public function setContent(string $content)
{ {
$this->attributes['content'] = $content; $this->attributes['gid'] = $value;
}
public function setText(string $value)
{
$this->attributes['text'] = $value;
}
public function setContent(string $value)
{
$this->attributes['content'] = $value;
} }
} }

View File

@ -38,8 +38,8 @@ class UserEntity extends CommonEntity
{ {
return $this->attributes['user_level']; return $this->attributes['user_level'];
} }
public function setLevel(int $level): void public function setLevel(int $value): void
{ {
$this->attributes['user_level'] = $level; $this->attributes['user_level'] = $value;
} }
} }

View File

@ -88,7 +88,7 @@ class YamapLibrary extends CommonLibrary
private function download_process(Crawler $crawler, array $options): array private function download_process(Crawler $crawler, array $options): array
{ {
$datas = []; $mediaInfos = [];
log_message("debug", "download:{$options["tag"]},{$options["attr"]}"); log_message("debug", "download:{$options["tag"]},{$options["attr"]}");
$nodes = $this->getMyCrawler()->getNodes($crawler, $options); $nodes = $this->getMyCrawler()->getNodes($crawler, $options);
foreach ($nodes as $node) { foreach ($nodes as $node) {
@ -98,14 +98,14 @@ class YamapLibrary extends CommonLibrary
if (!$this->getMyStorage()->save($content)) { if (!$this->getMyStorage()->save($content)) {
continue; continue;
} }
$datas[] = [ $mediaInfos[] = [
"orignal" => $node->html(), "orignal" => $node->html(),
"path" => $this->getMyStorage()->getPath(), "path" => $this->getMyStorage()->getPath(),
"fileName" => $fileName, "fileName" => $fileName,
"content" => $content "content" => $content
]; ];
} }
return $datas; return $mediaInfos;
} }
public function mainPage(): array public function mainPage(): array
@ -145,27 +145,34 @@ class YamapLibrary extends CommonLibrary
public function detailPage($url): array public function detailPage($url): array
{ {
$crawler = $this->getCrawler($url, getenv("yamap.view.content.tag")); $crawler = $this->getCrawler($url, getenv("yamap.view.content.tag"));
$contents = []; $mediaTags = [];
//3. Image 처리 //3. Image 처리
$images = $this->download_process($crawler, ["tag" => "img", "attr" => "src"]); $images = $this->download_process($crawler, ["tag" => "img", "attr" => "src"]);
foreach ($images as $image) { foreach ($images as $image) {
if ($this->isContainsHttpOrHttps($image['orignal'])) { if ($this->isContainsHttpOrHttps($image['orignal'])) {
$contents[] = $images['orignal']; $mediaTags[] = $images['orignal'];
} else { } else {
$contents[] = sprintf("<img src=\"%s\" alt=\"%s\">", $image["path"], $image["fileName"], $image["fileName"]); $mediaTags[] = sprintf("<img src=\"%s/%s\" alt=\"%s\">", $image["path"], $image["fileName"], $image["fileName"]);
}; };
} }
//4. Video(mp4) 처리 //4. Video(mp4) 처리
$videos = $this->download_process($crawler, ["tag" => "video", "attr" => "src"]); $videos = $this->download_process($crawler, ["tag" => "video", "attr" => "src"]);
foreach ($images as $image) { foreach ($videos as $video) {
if ($this->isContainsHttpOrHttps($image['orignal'])) { if ($this->isContainsHttpOrHttps($video['orignal'])) {
$contents[] = $images['orignal']; $mediaTags[] = $videos['orignal'];
} else { } else {
$contents[] = sprintf("<video src=\"%s\" alt=\"%s\">", $image["path"], $image["fileName"], $image["fileName"]); $mediaTags[] = sprintf("<video src=\"%s/%s\" alt=\"%s\">", $video["path"], $video["fileName"], $video["fileName"]);
}; };
} }
return array(array_merge($images, $videos), $contents); $mediaInfos = array_merge($images, $videos);
log_message("debug", "-----mediaInfos-----");
foreach ($mediaInfos as $mediaInfo) {
log_message("debug", "fileName: " . $mediaInfo["path"] . DIRECTORY_SEPARATOR . $mediaInfo['fileName']);
}
log_message("debug", "-----mediaTags-----");
log_message("debug", var_export($mediaTags, true));
return array($mediaInfos, $mediaTags);
} }
public function build(): array public function build(): array

View File

@ -7,67 +7,66 @@ use App\Models\CommonModel;
class FreeboardModel extends CommonModel class FreeboardModel extends CommonModel
{ {
protected $table = 'mb_board_free;'; protected $table = 'mb_board_free';
protected $primaryKey = 'pid'; protected $primaryKey = 'pid';
protected $useAutoIncrement = true; protected $useAutoIncrement = true;
protected $returnType = FreeboardEntity::class;
protected $allowedFields = [ protected $allowedFields = [
// 'pid', // // 'pid',
// 'gid', // // 'gid',
'reply', // 'reply',
'depth', // 'depth',
'user_id', // 'user_id',
'user_name', // 'user_name',
'title', 'title',
'passwd', // 'passwd',
'homepage', // 'homepage',
'email', // 'email',
'address', // 'address',
'phone', // 'phone',
'reg_date', // 'reg_date',
'modify_date', // 'modify_date',
'calendar_date', // 'calendar_date',
'hit', // 'hit',
'user_pid', // 'user_pid',
'parent_pid', // 'parent_pid',
'parent_user_pid', // 'parent_user_pid',
'level', // 'level',
'file_count', // 'file_count',
'comment_count', // 'comment_count',
'vote_good_count', // 'vote_good_count',
'vote_bad_count', // 'vote_bad_count',
'vote_type', // 'vote_type',
'ip', // 'ip',
'agent', // 'agent',
'is_notice', // 'is_notice',
'is_secret', // 'is_secret',
'status', // 'status',
'is_show', // 'is_show',
'reply_email', // 'reply_email',
'text', 'text',
'content', 'content',
'content_type', // 'content_type',
'data_type', // 'data_type',
'editor_type', // 'editor_type',
'tag', // 'tag',
'category1', // 'category1',
'category2', // 'category2',
'category3', // 'category3',
'image_path', // 'image_path',
'site_link1', // 'site_link1',
'site_link2', // 'site_link2',
'gps_latitude', // 'gps_latitude',
'gps_longitude', // 'gps_longitude',
'ext1', // 'ext1',
'ext2', // 'ext2',
'ext3', // 'ext3',
'ext4', // 'ext4',
'ext5', // 'ext5',
'ext6', // 'ext6',
'ext7', // 'ext7',
'ext8', // 'ext8',
'ext9', // 'ext9',
'ext10', // 'ext10',
]; ];
// Validation // Validation
@ -85,12 +84,12 @@ class FreeboardModel extends CommonModel
'email' => 'if_exist|trim|valid_email', 'email' => 'if_exist|trim|valid_email',
'address' => 'if_exist|trim|string', 'address' => 'if_exist|trim|string',
'phone' => 'if_exist|trim|string', 'phone' => 'if_exist|trim|string',
// 'reg_date' => 'if_exist|valid_date[Y-m-d hh:ii:dd]', 'reg_date' => 'if_exist|valid_date[Y-m-d H:i:s]',
// 'modify_date' => 'if_exist|valid_date[Y-m-d hh:ii:dd]', 'modify_date' => 'if_exist|valid_date[Y-m-d h:i:s]',
// 'calendar_date' => 'if_exist|valid_date[Y-m-d hh:ii:dd]', 'calendar_date' => 'if_exist|valid_date[Y-m-d H:i:s]',
'reg_date' => 'if_exist|string', // 'reg_date' => 'if_exist|string',
'modify_date' => 'if_exist|string', // 'modify_date' => 'if_exist|string',
'calendar_date' => 'if_exist|string', // 'calendar_date' => 'if_exist|string',
'hit' => 'if_exist|trim|numeric', 'hit' => 'if_exist|trim|numeric',
'user_pid' => 'if_exist|trim|numeric', 'user_pid' => 'if_exist|trim|numeric',
'parent_pid' => 'if_exist|trim|numeric', 'parent_pid' => 'if_exist|trim|numeric',