1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
topiconformailtemplate.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\ICal\MailInvitation;
4
5use Bitrix\Calendar\Util;
6use Bitrix\Main\IO\File;
7use Bitrix\Main\Type\Date;
8
10{
11 protected const FILE_TYPE = '.png';
12 protected const MODULE_SUB_DIR = 'calendar';
13 protected const ICAL_SUB_DIR = 'ical';
14
18 private $date;
22 private $path;
26 private $fileName;
30 private $fontPath;
34 protected $filePath;
38 private $templatePath;
39
44 public static function fromDate(Date $date): TopIconForMailTemplate
45 {
46 $iconObject = new self();
47 $iconObject->date = $date;
48 $uploadDir = \COption::GetOptionString("main", "upload_dir", "upload");
49 $iconObject->path = "/".$uploadDir."/".self::MODULE_SUB_DIR."/".self::ICAL_SUB_DIR;
50 $iconObject->fileName = mb_strtolower($date->format('M')).self::FILE_TYPE;
51 $iconObject->filePath = $iconObject->path."/".$iconObject->fileName;
52 return $iconObject;
53 }
54
58 public function __construct()
59 {
60 $this->fontPath = $_SERVER['DOCUMENT_ROOT'] .BX_ROOT.'/modules/main/install/fonts/opensans-bold.ttf';
61 $this->templatePath = $_SERVER["DOCUMENT_ROOT"].BX_ROOT.'/components/bitrix/calendar.ical.mail/templates/.default/images/date-template-top.png';
62 }
63
68 public function setDate(Date $date): TopIconForMailTemplate
69 {
70 $this->date = $date;
71
72 return $this;
73 }
74
78 public function getPath(): string
79 {
80 return $this->filePath;
81 }
82
86 public function createImage(): bool
87 {
88 if (File::isFileExists($_SERVER["DOCUMENT_ROOT"].$this->path."/".$this->fileName))
89 {
90 return true;
91 }
92
93 $image = $this->getImage();
94 $tmpFile = $this->getTmpPath();
95
96 if (
97 is_resource($image)
98 && $tmpFile !== ''
99 && imagepng($image, $tmpFile, 0)
100 )
101 {
102 $fileData = $this->getFileData($tmpFile);
103 $fileId = \CFile::SaveFile($fileData, 'calendar', false, false, self::ICAL_SUB_DIR);
104 $fileArray = \CFile::GetFileArray($fileId);
105 if (is_array($fileArray))
106 {
107 if ($fileArray['SRC'] !== $this->filePath)
108 {
109 $this->filePath = $fileArray['SRC'];
110 }
111
112 return true;
113 }
114 }
115
116 return false;
117 }
118
122 protected function getMonthName(): string
123 {
124 $month = Util::checkRuZone()
125 ? mb_strtoupper(FormatDate('M', $this->date->getTimestamp()))
126 : mb_strtoupper($this->date->format('M'))
127 ;
128
129 return is_string($month)
130 ? $month
131 : $this->date->format('M')
132 ;
133 }
134
138 protected function getTmpPath(): string
139 {
140 $tmpFile = \CTempFile::getFileName($this->fileName);
141 return CheckDirPath($tmpFile)
142 ? $tmpFile
143 : ''
144 ;
145
146 }
147
151 protected function getImage()
152 {
153 if (!\Bitrix\Main\IO\File::isFileExists($this->templatePath))
154 {
155 return null;
156 }
157
158 $image = @imagecreatefrompng($this->templatePath);
159 $month = Helper::getShortMonthName($this->date);
160 $color = imagecolorallocate($image, 255, 255, 255);
161 imagettftext($image, 30, 0, 55, 57, $color, $this->fontPath, $month);
162
163 return $image;
164 }
165
170 protected function getFileData($tmpFile): array
171 {
172 return [
173 'name' => $this->fileName,
174 'type' => 'image/png',
175 'content' => File::getFileContents($tmpFile),
176 'MODULE_ID' => 'calendar',
177 ];
178 }
179}
static checkRuZone()
Определения util.php:129
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
CheckDirPath($path)
Определения tools.php:2707
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
Определения tools.php:871
Определения directory.php:3
$fileName
Определения quickway.php:305
path
Определения template_copy.php:201