Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ONLYOFFICE/onlyoffice-nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/templatemanager.php')
-rw-r--r--lib/templatemanager.php60
1 files changed, 36 insertions, 24 deletions
diff --git a/lib/templatemanager.php b/lib/templatemanager.php
index 0dd1b3d..dcadfb0 100644
--- a/lib/templatemanager.php
+++ b/lib/templatemanager.php
@@ -19,6 +19,7 @@
namespace OCA\Onlyoffice;
+use OCP\Files\File;
/**
* Template manager
@@ -60,60 +61,51 @@ class TemplateManager {
/**
* Get global templates
*
- * @param string $type - template format type
+ * @param string $mimetype - mimetype of the template
*
* @return array
*/
- public static function GetGlobalTemplates($type = null) {
- $templates = [];
+ public static function GetGlobalTemplates($mimetype = null) {
$templateDir = self::GetGlobalTemplateDir();
- if (!empty($type)) {
- $mime = self::GetMimeTemplate($type);
- $templatesList = $templateDir->searchByMime($mime);
+ if (!empty($mimetype)) {
+ $templatesList = $templateDir->searchByMime($mimetype);
} else {
$templatesList = $templateDir->getDirectoryListing();
}
- foreach ($templatesList as $templatesItem) {
- $template = [
- "id" => $templatesItem->getId(),
- "name" => $templatesItem->getName(),
- "type" => TemplateManager::GetTypeTemplate($templatesItem->getMimeType())
- ];
- array_push($templates, $template);
- }
-
- return $templates;
+ return $templatesList;
}
/**
- * Get template content
+ * Get template file
*
- * @param string $templateId - identifier file template
+ * @param string $templateId - identifier of the template
*
- * @return string
+ * @return File
*/
public static function GetTemplate($templateId) {
$logger = \OC::$server->getLogger();
+ if (empty($templateId)) {
+ $logger->info("templateId is empty", ["app" => self::$appName]);
+ return null;
+ }
+
$templateDir = self::GetGlobalTemplateDir();
try {
$templates = $templateDir->getById($templateId);
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
$logger->logException($e, ["message" => "GetTemplate: $templateId", "app" => self::$appName]);
return null;
}
if (empty($templates)) {
- $logger->info("Template not found: $templateId", ["app" => self::$appName]);
return null;
}
- $content = $templates[0]->getContent();
-
- return $content;
+ return $templates[0];
}
/**
@@ -176,6 +168,23 @@ class TemplateManager {
}
/**
+ * Check file if it's template
+ *
+ * @param int $fileId - identifier file
+ *
+ * @return bool
+ */
+ public static function IsTemplate($fileId) {
+ $template = self::GetTemplate($fileId);
+
+ if (empty($template)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
* Get template
*
* @param string $name - file name
@@ -188,6 +197,9 @@ class TemplateManager {
$lang = \OC::$server->getL10NFactory("")->get("")->getLanguageCode();
$templatePath = self::GetEmptyTemplatePath($lang, $ext);
+ if (!file_exists($templatePath)) {
+ return false;
+ }
$template = file_get_contents($templatePath);
return $template;