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->cli('mangboard/level', 'Mangboard::level');
$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) {

View File

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

View File

@ -20,18 +20,27 @@ class FreeboardEntity extends CommonEntity
}
//Common Function
public function setTitle(string $title)
public function setTitle(string $value)
{
$this->attributes['title'] = $title;
$this->attributes['title'] = $value;
}
public function getGID(): int
{
return $this->attributes['gid'];
}
public function setContent(string $content)
public function setGID(int $value)
{
$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'];
}
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
{
$datas = [];
$mediaInfos = [];
log_message("debug", "download:{$options["tag"]},{$options["attr"]}");
$nodes = $this->getMyCrawler()->getNodes($crawler, $options);
foreach ($nodes as $node) {
@ -98,14 +98,14 @@ class YamapLibrary extends CommonLibrary
if (!$this->getMyStorage()->save($content)) {
continue;
}
$datas[] = [
$mediaInfos[] = [
"orignal" => $node->html(),
"path" => $this->getMyStorage()->getPath(),
"fileName" => $fileName,
"content" => $content
];
}
return $datas;
return $mediaInfos;
}
public function mainPage(): array
@ -145,27 +145,34 @@ class YamapLibrary extends CommonLibrary
public function detailPage($url): array
{
$crawler = $this->getCrawler($url, getenv("yamap.view.content.tag"));
$contents = [];
$mediaTags = [];
//3. Image 처리
$images = $this->download_process($crawler, ["tag" => "img", "attr" => "src"]);
foreach ($images as $image) {
if ($this->isContainsHttpOrHttps($image['orignal'])) {
$contents[] = $images['orignal'];
$mediaTags[] = $images['orignal'];
} 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) 처리
$videos = $this->download_process($crawler, ["tag" => "video", "attr" => "src"]);
foreach ($images as $image) {
if ($this->isContainsHttpOrHttps($image['orignal'])) {
$contents[] = $images['orignal'];
foreach ($videos as $video) {
if ($this->isContainsHttpOrHttps($video['orignal'])) {
$mediaTags[] = $videos['orignal'];
} 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

View File

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