Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
urlpreviewusertype.php
1<?php
2
4
8
9Loc::loadMessages(__FILE__);
10
12{
18 public static function getUserTypeDescription()
19 {
20 return array(
21 "USER_TYPE_ID" => "url_preview",
22 "CLASS_NAME" => __CLASS__,
23 "DESCRIPTION" => Loc::getMessage('MAIN_URL_PREVIEW_USER_TYPE_NAME'),
24 "BASE_TYPE" => "int"
25 );
26 }
27
34 public static function getDBColumnType($userField)
35 {
36 $connection = \Bitrix\Main\Application::getConnection();
37 $helper = $connection->getSqlHelper();
38 return $helper->getColumnTypeByField(new \Bitrix\Main\ORM\Fields\IntegerField('x'));
39 }
40
45 public static function prepareSettings($userField)
46 {
47 //this usertype does not support setting yet
48 return array();
49 }
50
57 public static function getSettingsHTML($userField, $htmlControl, $varsFromForm)
58 {
59 return "&nbsp;";
60 }
61
67 public static function getEditFormHTML($userField, $htmlControl)
68 {
69 return UrlPreview::showEdit($userField, array());
70 }
71
77 public static function getFilterHTML($userField, $htmlControl)
78 {
79 return '&nbsp;';
80 }
81
87 public static function getAdminListViewHTML($userField, $htmlControl)
88 {
89 return "&nbsp;";
90 }
91
97 public static function getAdminListEditHTML($userField, $htmlControl)
98 {
99 return "&nbsp;";
100 }
101
107 public static function getAdminListEditHTMLMulty($userField, $htmlControl)
108 {
109 return "&nbsp;";
110 }
111
118 public static function getPublicViewHTML($userField, $id, $params = "", $settings = array())
119 {
120 return UrlPreview::showView($userField, $params, $cacheTag);
121 }
122
130 public static function checkfields($userField, $value)
131 {
132 $result = array();
133
134 $signer = new Signer();
135 try
136 {
137 $value = $signer->unsign($value, UrlPreview::SIGN_SALT);
138 }
139 catch (SystemException $e)
140 {
141 return $result;
142 }
143
144 $value = (int)$value;
145
146 if($value === 0)
147 return $result;
148
149 $metadata = UrlMetadataTable::getById($value)->fetch();
150 if(!is_array($metadata))
151 {
152 $result[] = array(
153 "id" => $userField["FIELD_NAME"],
154 "text" => GetMessage("MAIN_URL_PREVIEW_VALUE_NOT_FOUND")
155 );
156 }
157 else if($metadata['TYPE'] === UrlMetadataTable::TYPE_DYNAMIC
158 && !UrlPreview::checkDynamicPreviewAccess($metadata['URL']))
159 {
160 $result[] = array(
161 "id" => $userField["FIELD_NAME"],
162 "text" => GetMessage("MAIN_URL_PREVIEW_VALUE_NO_ACCESS",
163 array('#URL#' => $metadata['URL'])
164 )
165 );
166 }
167
168 return $result;
169 }
170
179 public static function onBeforeSave($userField, $value)
180 {
181 $imageUrl = null;
182 if(strpos($value, ';') !== false)
183 {
184 list($value, $imageUrl) = explode(';', $value);
185 }
186
187 $signer = new Signer();
188 try
189 {
190 $value = $signer->unsign($value, UrlPreview::SIGN_SALT);
191 }
192 catch (SystemException $e)
193 {
194 return null;
195 }
196 $metadata = UrlMetadataTable::getById($value)->fetch();
197 if(!is_array($metadata))
198 return null;
199
200 if($metadata['TYPE'] === UrlMetadataTable::TYPE_STATIC)
201 {
202 if($imageUrl && is_array($metadata['EXTRA']['IMAGES']) && in_array($imageUrl, $metadata['EXTRA']['IMAGES']))
203 {
204 UrlPreview::setMetadataImage((int)$value, $imageUrl);
205 }
206 return $value;
207 }
208 else if($metadata['TYPE'] === UrlMetadataTable::TYPE_DYNAMIC
209 && UrlPreview::checkDynamicPreviewAccess($metadata['URL']))
210 {
211 return $value;
212 }
213
214 return null;
215 }
216}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static showView($userField, $userFieldParams, &$cacheTag, $edit=false)
static checkDynamicPreviewAccess($url, $userId=0)
static showEdit($userField, $userFieldParams)
static setMetadataImage($id, $imageUrl)
static getSettingsHTML($userField, $htmlControl, $varsFromForm)
static getFilterHTML($userField, $htmlControl)
static getAdminListEditHTMLMulty($userField, $htmlControl)
static getAdminListEditHTML($userField, $htmlControl)
static getAdminListViewHTML($userField, $htmlControl)
static getEditFormHTML($userField, $htmlControl)
static getPublicViewHTML($userField, $id, $params="", $settings=array())