forked from cydemo/rx-module-preview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.view.php
More file actions
169 lines (150 loc) · 4.64 KB
/
preview.view.php
File metadata and controls
169 lines (150 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* 링크 프리뷰
* Copyright (c) 윤삼
* Generated with https://www.poesis.org/tools/modulegen/
*/
class PreviewView extends Preview
{
public function init()
{
Context::setResponseMethod('RAW');
// 스킨 템플릿의 경로와 스킨
$this->setTemplatePath($this->module_path . 'skins/' . ($this->module_config->skin ?: 'default'));
$this->setTemplateFile('preview_card');
}
public function dispPreviewCard()
{
$url = Context::get('url');
if ( !$url )
{
return;
}
if ( Rhymix\Framework\URL::isInternalURL($url) )
{
$this->dispPreviewCardBySelf();
return;
}
$flag = false;
$links = [
'naver.me', 'cafe.naver.com/ca-fe/town-talks', 'ogqmarket.naver.com/creators', 'dict.naver.com', 'map.naver.com', 'game.naver.com', 'movie.naver.com', 'jr.naver.com',
'finance.daum.net', 'dic.daum.net', 'wordbook.daum.net', 'melon.com/artist', 'webtoon.kakao.com',
'namu.wiki', 'fmkorea.com', 'soccerline.kr', 'coupang.com', '.tistory.com', '.gettyimages.com', '.aliexpress.com'
];
foreach ( $links as $link )
{
if ( strpos($url, $link) !== false )
{
$flag = true;
break;
}
}
$preview_info = PreviewModel::getPreviewInfo($url);
Context::set('preview_info', $preview_info);
}
public function dispPreviewCardByData()
{
$url = Context::get('url');
$data = Context::get('data');
if ( !$url || !$data )
{
return;
}
$preview_info = json_decode(html_entity_decode($data));
$preview_info->url = urldecode($url);
Context::set('preview_info', $preview_info);
}
public function dispPreviewCardBySelf()
{
$url = Context::get('url');
if ( !$url )
{
return;
}
$preview_info = new stdClass();
$preview_info->url = urldecode($url);
$_length = strlen(RX_BASEURL);
$rewrite_level = Rhymix\Framework\Router::getRewriteLevel();
$url_info = parse_url($url, PHP_URL_PATH);
$url_info = substr($url_info, $_length);
$result = Rhymix\Framework\Router::parseUrl('GET', $url_info, $rewrite_level);
$mid = $result->mid ?: null;
if ( $mid )
{
$module_info = ModuleModel::getModuleInfoByMid($mid);
}
$document_srl = $result->args['document_srl'] ?: null;
$site_config = ModuleModel::getModuleConfig('module');
$default_image = getAdminModel('admin')->getSiteDefaultImageUrl();
// url 접근 및 열람 권한 확인
$permitted = false;
if ( $this->user->is_admin === 'Y' )
{
$permitted = true;
}
else
{
if ( $mid )
{
$grant = ModuleModel::getGrant($module_info, $this->user);
if ( $grant->manager )
{
$permitted = true;
}
else
{
if ( $document_srl )
{
$permitted = ( $module_info->consultation === 'Y' ) ? $grant->consultation_read : $permitted = $grant->view;
}
else
{
$permitted = $grant->access;
}
}
}
else
{
$permitted = true;
}
}
// 권한 및 url 정보에 따라 프리뷰 정보를 차별적으로 배분
if ( $permitted )
{
if ( $mid && !$document_srl)
{
$preview_info->title = $module_info->browser_title;
$preview_info->description = Context::getSiteTitle() . ' - ' . ($site_config->meta_description ?: ($site_config->meta_keywords ?: $site_config->siteSubtitle));
$preview_info->image = $default_image ?: null;
}
else if ( $document_srl )
{
$oDocument = DocumentModel::getDocument($document_srl);
if ( $oDocument->isExists() )
{
$config = $this->getConfig();
$width = is_numeric($config->max_image_width) ? intval($config->max_image_width) : 160;
$height = is_numeric($config->max_image_height) ? intval($config->max_image_height) : 160;
$preview_info->title = $oDocument->getTitle();
$preview_info->description = $oDocument->getContentText(200);
$preview_info->author = $oDocument->getNickName();
$preview_info->image = $oDocument->thumbnailExists() ? $oDocument->getThumbnail($width, $height, 'fill') : $default_image;
}
}
else
{
$preview_info->title = Context::getSiteTitle();
$preview_info->description = $site_config->meta_description ?: ($site_config->meta_keywords ?: $site_config->siteSubtitle);
$preview_info->image = $default_image ?: null;
}
}
else
{
$preview_info->title = lang('msg_not_permitted');
$preview_info->description = $site_config->meta_description ?: ($site_config->meta_keywords ?: $site_config->siteSubtitle);
$preview_info->image = $default_image ?: null;
}
$preview_info->site_name = Context::getSiteTitle();
Context::set('preview_info', $preview_info);
}
}