/** * @param $templateName * @return array|null */ public static function getById($templateName) { $result = null; $localPathOfIcon = static::LOCAL_DIR_IMG . bx_basename($templateName) . '.png'; $fullPathOfIcon = \Bitrix\Main\Loader::getLocal($localPathOfIcon); $fullPathOfFile = \Bitrix\Main\Loader::getLocal(static::LOCAL_DIR_TMPL . bx_basename($templateName) . '.php'); if ($fullPathOfFile) { $fileContent = File::getFileContents($fullPathOfFile); } else { $fileContent = ''; } if (!empty($fileContent) || $templateName == 'empty') { $fileContent = str_replace(array('%TEXT_UNSUB_TEXT%', '%TEXT_UNSUB_LINK%'), array(Loc::getMessage('PRESET_MAILBLOCK_unsub_TEXT_UNSUB_TEXT'), Loc::getMessage('PRESET_MAILBLOCK_unsub_TEXT_UNSUB_LINK')), $fileContent); $result = array('TYPE' => 'BASE', 'NAME' => Loc::getMessage('PRESET_TEMPLATE_' . $templateName), 'ICON' => !empty($fullPathOfIcon) ? '/bitrix' . $localPathOfIcon : '', 'HTML' => $fileContent); } return $result; }
/** * Binds (and creates if it's necessary) template to the application folder * * @param $templateId - symbolic code of the template * @param $folder - the application folder * @param bool $createNew - flag of the necessity of creating a new template */ public static function bindTemplate($templateId, $folder, $createNew) { $arFields = array("TEMPLATE" => array()); if ($createNew) { CopyDirFiles(Application::getDocumentRoot() . "/bitrix/modules/mobileapp/templates/default_app/", Application::getDocumentRoot() . "/bitrix/templates/" . $templateId, True, True); File::putFileContents(Application::getDocumentRoot() . "/bitrix/templates/" . $templateId . "/description.php", str_replace(array("#mobile_template_name#"), array($templateId), File::getFileContents(Application::getDocumentRoot() . "/bitrix/templates/" . $templateId . "/description.php"))); $arFields["TEMPLATE"][] = array("SORT" => 1, "CONDITION" => "CSite::InDir('/" . $folder . "/')", "TEMPLATE" => $templateId); } $default_site_id = \CSite::GetDefSite(); if ($default_site_id) { $dbTemplates = \CSite::GetTemplateList($default_site_id); $arFields["LID"] = $default_site_id; $isTemplateFound = false; while ($template = $dbTemplates->Fetch()) { $arFields["TEMPLATE"][] = array("TEMPLATE" => $template['TEMPLATE'], "SORT" => $template['SORT'], "CONDITION" => $template['CONDITION']); if ($template["TEMPLATE"] == $templateId && !$createNew && !$isTemplateFound) { $isTemplateFound = true; $arFields["TEMPLATE"][] = array("SORT" => 1, "CONDITION" => "CSite::InDir('/" . $folder . "/')", "TEMPLATE" => $templateId); } } $obSite = new \CSite(); $obSite->Update($default_site_id, $arFields); } }
protected function setTheme($site_template_id) { if (strlen($site_template_id) > 0) { $result = \CSiteTemplate::GetByID($site_template_id); if ($templateFields = $result->Fetch()) { $template_path_header = \Bitrix\Main\Application::getDocumentRoot() . $templateFields['PATH'] . '/header.php'; $template_path_footer = \Bitrix\Main\Application::getDocumentRoot() . $templateFields['PATH'] . '/footer.php'; if ($templateFields['PATH'] != '' && IO\File::isFileExists($template_path_footer) && IO\File::isFileExists($template_path_header)) { $this->themeStylesString .= $templateFields['TEMPLATE_STYLES'] . "\r\n"; $this->themeStylesString .= $templateFields['STYLES'] . "\r\n"; $this->setThemeProlog(IO\File::getFileContents($template_path_header)); $this->setThemeEpilog(IO\File::getFileContents($template_path_footer)); } } } }
/** * Creates first part of file in bucket. * @param array $fileData Array like as $_FILE. * @param array $data Additional fields to TmpFile. * @param \CCloudStorageBucket $bucket Cloud bucket. * @param array $params Parameters (startRange, endRange, fileSize). * @param ErrorCollection $errorCollection Error collection. * @return Model|null|static */ public static function createInBucketFirstPartFromFileArray(array $fileData, array $data, \CCloudStorageBucket $bucket, array $params, ErrorCollection $errorCollection) { $data = static::prepareDataToInsertFromFileArray($fileData, $data, $errorCollection); $data['IS_CLOUD'] = 1; /** @noinspection PhpUndefinedFieldInspection */ $data['BUCKET_ID'] = $bucket->ID; $model = static::add($data, $errorCollection); if (!$model) { return null; } $uploadStatus = $model->appendContentCloud(IO\File::getFileContents($model->getAbsoluteNonCloudPath()), $params['startRange'], $params['endRange'], $params['fileSize']); if (!$uploadStatus) { $errorCollection->add($model->getErrors()); //todo Are we right? $model->delete(); unset($model); return null; } return $model; }
/** * */ public function setAttachment() { $files = $this->attachment; if (is_array($this->filesReplacedFromBody)) { $files = array_merge($files, array_values($this->filesReplacedFromBody)); } if (count($files) > 0) { $eol = $this->eol; $charset = $this->charset; $bodyPart = ''; foreach ($files as $attachment) { try { $fileContent = File::getFileContents($attachment["PATH"]); } catch (\Exception $exception) { $fileContent = ''; } $attachment_name = $this->encodeSubject($attachment["NAME"], $charset); $bodyPart .= $eol . "--" . $this->boundary . $eol; $bodyPart .= "Content-Type: " . $attachment["CONTENT_TYPE"] . "; name=\"" . $attachment_name . "\"" . $eol; $bodyPart .= "Content-Transfer-Encoding: base64" . $eol; $bodyPart .= "Content-ID: <" . $attachment["ID"] . ">" . $eol . $eol; $bodyPart .= chunk_split(base64_encode($fileContent), 72, $eol); } $this->body .= $bodyPart; } }
/** * @param $blockName * @return array|null */ public static function getById($blockName) { $result = null; $type = null; $arBlockByType = static::getBlockListByType(); foreach ($arBlockByType as $searchType => $arBlock) { foreach ($arBlock as $searchBlockName) { if ($blockName == $searchBlockName) { $type = $searchType; break; } } } $fullPathOfFile = \Bitrix\Main\Loader::getLocal(static::LOCAL_DIR_BLOCK . bx_basename($blockName) . '.html'); if ($fullPathOfFile) { $fileContent = File::getFileContents($fullPathOfFile); if ($blockName == 'unsub') { $fileContent = str_replace(array('%TEXT_UNSUB_TEXT%', '%TEXT_UNSUB_LINK%'), array(Loc::getMessage('PRESET_MAILBLOCK_' . $blockName . '_TEXT_UNSUB_TEXT'), Loc::getMessage('PRESET_MAILBLOCK_' . $blockName . '_TEXT_UNSUB_LINK')), $fileContent); } $result = array('TYPE' => Loc::getMessage('TYPE_PRESET_MAILBLOCK_' . $type), 'CODE' => $blockName, 'NAME' => Loc::getMessage('PRESET_MAILBLOCK_' . $blockName), 'ICON' => '', 'HTML' => $fileContent); } return $result; }
public function upload($filename, array $fileData) { $tmpFileClass = $this->tmpFileClass; list($startRange, $endRange) = $this->getContentRange(); $fileSize = $this->getFileSize(); if ($startRange === null) { $fileData['name'] = $filename; list($fileData['width'], $fileData['height']) = CFile::getImageSize($fileData['tmp_name']); $tmpFile = $tmpFileClass::createFromFileArray($fileData, array('CREATED_BY' => $this->getUserId()), $this->errorCollection); if (!$tmpFile) { $this->errorCollection->addOne(new Error("Could not create tmpFile model (simple mode)", self::ERROR_CREATE_TMP_FILE_NON_BUCKET)); return false; } $this->token = $tmpFile->getToken(); return true; } if ($endRange - $startRange + 1 != $fileData['size']) { $this->errorCollection->addOne(new Error('Size of file: ' . $fileData['size'] . ' not equals size of chunk: ' . ($endRange - $startRange + 1), self::ERROR_CHUNK_ERROR)); return false; } if ($this->isFirstChunk($startRange)) { $fileData['name'] = $filename; list($fileData['width'], $fileData['height']) = \CFile::getImageSize($fileData['tmp_name']); //attempt to decide: cloud? not cloud? $bucket = $this->findBucketForFile(array('name' => $filename, 'fileSize' => $fileSize)); if ($bucket) { /** @var TmpFile $tmpFile */ $tmpFile = $tmpFileClass::createInBucketFirstPartFromFileArray($fileData, array('CREATED_BY' => $this->getUserId()), $bucket, compact('startRange', 'endRange', 'fileSize'), $this->errorCollection); if (!$tmpFile) { $this->errorCollection->addOne(new Error("Could not create tmpFile model (cloud bucket {$bucket->ID})", self::ERROR_CREATE_TMP_FILE_BUCKET)); return false; } } else { $tmpFile = $tmpFileClass::createFromFileArray($fileData, array('CREATED_BY' => $this->getUserId()), $this->errorCollection); if (!$tmpFile) { $this->errorCollection->addOne(new Error("Could not create tmpFile model (simple mode)", self::ERROR_CREATE_TMP_FILE_NON_BUCKET)); return false; } } $this->token = $tmpFile->getToken(); return true; } //if run resumable upload we needed token. if (!$this->hasToken()) { $this->errorCollection->addOne(new Error("Could not append content to file. Have to set token parameter.", self::ERROR_EMPTY_TOKEN)); return false; } $tmpFile = $this->findUserSpecificTmpFileByToken(); if (!$tmpFile) { $this->errorCollection->addOne(new Error("Could not find file by token", self::ERROR_UNKNOWN_TOKEN)); return false; } $success = $tmpFile->append(IO\File::getFileContents($fileData['tmp_name']), compact('startRange', 'endRange', 'fileSize')); if (!$success) { $this->errorCollection->add($tmpFile->getErrors()); return false; } $this->token = $tmpFile->getToken(); return true; }
/** * @param string $template * @return string */ protected static function replaceTemplateByDefaultData($template) { $phone = '8 495 212-85-06'; $phonePath = Application::getDocumentRoot() . '/include/telephone.php'; $logoHeader = '/include/logo.png'; $logoFooter = '/include/logo_mobile.png'; if (!File::isFileExists(Application::getDocumentRoot() . $logoHeader)) { $logoHeader = '/bitrix/images/sender/preset/blocked1/logo.png'; } if (!File::isFileExists(Application::getDocumentRoot() . $logoFooter)) { $logoFooter = '/bitrix/images/sender/preset/blocked1/logo_m.png'; } if (File::isFileExists($phonePath)) { $phone = File::getFileContents($phonePath); } $themeContent = File::getFileContents(\Bitrix\Main\Loader::getLocal(static::LOCAL_DIR_TMPL . 'theme.php')); return str_replace(array('%TEMPLATE_CONTENT%', '%LOGO_PATH_HEADER%', '%LOGO_PATH_FOOTER%', '%PHONE%', '%UNSUB_LINK%', '%MENU_CONTACTS%', '%MENU_HOWTO%', '%MENU_DELIVERY%', '%MENU_ABOUT%', '%MENU_GUARANTEE%', '%SCHEDULE_NAME%', '%SCHEDULE_DETAIL%', '%BUTTON%', '%HEADER%', '%TEXT1%', '%TEXT2%', '%TEXT3%', '%TEXT4%', '%TEXT5%', '%TEXT6%'), array($template, $logoHeader, $logoFooter, $phone, Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_UNSUB_LINK'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_CONTACTS'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_HOWTO'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_DELIVERY'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_ABOUT'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_GUARANTEE'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_SCHEDULE_NAME'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_SCHEDULE_DETAIL'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_BUTTON'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_HEADER'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT1'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT2'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT3'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT4'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT5'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT6')), $themeContent); }
protected function createFileInternal(FileData $fileData) { if (!$this->checkRequiredInputParams($fileData->toArray(), array('name', 'src'))) { return null; } $accessToken = $this->getAccessToken(); $fileName = $fileData->getName(); $fileName = $this->convertToUtf8($fileName); $http = new HttpClient(array('redirect' => false, 'socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1)); $fileName = urlencode($fileName); $accessToken = urlencode($accessToken); if ($http->query('PUT', "https://apis.live.net/v5.0/me/skydrive/files/{$fileName}?access_token={$accessToken}", IO\File::getFileContents(IO\Path::convertPhysicalToLogical($fileData->getSrc()))) === false) { $errorString = implode('; ', array_keys($http->getError())); $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_FILE_INTERNAL))); return null; } if (!$this->checkHttpResponse($http)) { return null; } $finalOutput = Json::decode($http->getResult()); if ($finalOutput === null) { $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON))); return null; } $fileData->setId($finalOutput['id']); $props = $this->getFileData($fileData); if ($props === null) { return null; } $fileData->setLinkInService($props['link']); return $fileData; }