|
@@ -14,11 +14,11 @@ class TemplateController extends BaseController {
|
|
|
* Show all the available templates.
|
|
|
*/
|
|
|
public function show() {
|
|
|
- $templates = $this->getEditableTemplates();
|
|
|
- $missingTemplates = array_diff($this->getCoreTemplates(), $this->getPluginTemplates());
|
|
|
- $extraTemplates = array_diff($this->getPluginTemplates(), $this->getCoreTemplates());
|
|
|
- $modifiedStatus = $this->getModifiedStatus();
|
|
|
-
|
|
|
+ $templates = $this->getEditableTemplates();
|
|
|
+ $missingTemplates = array_diff($this->getCoreTemplates(), $this->getPluginTemplates());
|
|
|
+ $extraTemplates = array_diff($this->getPluginTemplates(), $this->getCoreTemplates());
|
|
|
+ $modifiedStatus = $this->getModifiedStatus();
|
|
|
+
|
|
|
$this->response->html($this->helper->layout->config("OMITemplateModder:config/index", [
|
|
|
"title" => t("OMI - Notification Template Modder"),
|
|
|
"templates" => $templates,
|
|
@@ -35,7 +35,7 @@ class TemplateController extends BaseController {
|
|
|
*/
|
|
|
private function getEditableTemplates() {
|
|
|
$templates = [];
|
|
|
- $templateDir = ETM_PLUGIN_ROOT_DIR . "/Template/notification";
|
|
|
+ $templateDir = \ETM_PLUGIN_ROOT_DIR . "/Template/notification";
|
|
|
|
|
|
foreach (glob($templateDir . "/*.php") as $filename) {
|
|
|
$templateName = basename($filename, ".php");
|
|
@@ -45,6 +45,7 @@ class TemplateController extends BaseController {
|
|
|
return $templates;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Get a list of core notification templates.
|
|
|
*
|
|
@@ -52,8 +53,7 @@ class TemplateController extends BaseController {
|
|
|
*/
|
|
|
private function getCoreTemplates() {
|
|
|
$templates = [];
|
|
|
- // Use the new custom constant defined in Plugin.php
|
|
|
- $templateDir = KB_APP_DIR . "/Template/notification";
|
|
|
+ $templateDir = \KB_APP_DIR . "/Template/notification";
|
|
|
|
|
|
foreach (glob($templateDir . "/*.php") as $filename) {
|
|
|
$templates[] = basename($filename, ".php");
|
|
@@ -69,7 +69,7 @@ class TemplateController extends BaseController {
|
|
|
*/
|
|
|
private function getPluginTemplates() {
|
|
|
$templates = [];
|
|
|
- $templateDir = ETM_PLUGIN_ROOT_DIR . "/Template/notification";
|
|
|
+ $templateDir = \ETM_PLUGIN_ROOT_DIR . "/Template/notification";
|
|
|
|
|
|
foreach (glob($templateDir . "/*.php") as $filename) {
|
|
|
$templates[] = basename($filename, ".php");
|
|
@@ -78,45 +78,69 @@ class TemplateController extends BaseController {
|
|
|
return $templates;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Compares core and plugin templates by file content to check for modifications.
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function getModifiedStatus()
|
|
|
- {
|
|
|
- $modified = [];
|
|
|
- $pluginTemplateDir = ETM_PLUGIN_ROOT_DIR . '/Template/notification';
|
|
|
- $coreTemplateDir = KB_APP_DIR . '/Template/notification';
|
|
|
-
|
|
|
- foreach (glob($pluginTemplateDir . '/*.php') as $filename) {
|
|
|
- $templateName = basename($filename);
|
|
|
- $pluginFile = $pluginTemplateDir . '/' . $templateName;
|
|
|
- $coreFile = $coreTemplateDir . '/' . $templateName;
|
|
|
-
|
|
|
- // Only compare if the core file exists
|
|
|
- if (file_exists($coreFile)) {
|
|
|
- $pluginContent = file_get_contents($pluginFile);
|
|
|
- $coreContent = file_get_contents($coreFile);
|
|
|
-
|
|
|
- // Compare the file contents
|
|
|
- if ($pluginContent !== $coreContent) {
|
|
|
- $modified[$templateName] = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Compares core and plugin templates by file content to check for modifications.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function getModifiedStatus() {
|
|
|
+ $modified = [];
|
|
|
+ $pluginTemplateDir = \ETM_PLUGIN_ROOT_DIR . "/Template/notification";
|
|
|
+ $coreTemplateDir = \KB_APP_DIR . "/Template/notification";
|
|
|
+
|
|
|
+ foreach (glob($pluginTemplateDir . "/*.php") as $filename) {
|
|
|
+ $templateName = basename($filename);
|
|
|
+ $pluginFile = $pluginTemplateDir . "/" . $templateName;
|
|
|
+ $coreFile = $coreTemplateDir . "/" . $templateName;
|
|
|
+
|
|
|
+ // Only compare if the core file exists
|
|
|
+ if (file_exists($coreFile)) {
|
|
|
+ $pluginContent = file_get_contents($pluginFile);
|
|
|
+ $coreContent = file_get_contents($coreFile);
|
|
|
+
|
|
|
+ // Compare the file contents
|
|
|
+ if ($pluginContent !== $coreContent) {
|
|
|
+ $modified[$templateName] = true;
|
|
|
}
|
|
|
- return $modified;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $modified;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a missing template from the core version.
|
|
|
+ */
|
|
|
+ public function create() {
|
|
|
+ $templateName = $this->request->getStringParam("template_name");
|
|
|
+
|
|
|
+ $coreTemplateFile = \KB_APP_DIR . "/Template/notification/" . $templateName . ".php";
|
|
|
+ $pluginTemplateFile = \ETM_PLUGIN_ROOT_DIR . "/Template/notification/" . $templateName . ".php";
|
|
|
+
|
|
|
+ if (file_exists($coreTemplateFile)) {
|
|
|
+ if (!file_exists(dirname($pluginTemplateFile))) {
|
|
|
+ mkdir(dirname($pluginTemplateFile), 0755, true);
|
|
|
+ }
|
|
|
+ if (copy($coreTemplateFile, $pluginTemplateFile)) {
|
|
|
+ $this->flash->success(t("Template created successfully!"));
|
|
|
+ } else {
|
|
|
+ $this->flash->failure(t("Unable to create template. Check folder permissions."));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->flash->failure(t("Core template not found."));
|
|
|
}
|
|
|
+
|
|
|
+ return $this->response->redirect($this->helper->url->to("TemplateController", "show", ["plugin" => "OMITemplateModder"]));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * Show the form to edit a template
|
|
|
- */
|
|
|
+ * Show the form to edit a template
|
|
|
+ */
|
|
|
public function edit() {
|
|
|
$templateIndex = $this->request->getIntegerParam("template_index");
|
|
|
$templates = $this->getEditableTemplates();
|
|
|
|
|
|
if (!isset($templates[$templateIndex])) {
|
|
|
- $this->flash->failure(t("Template not found!"));
|
|
|
+ $this->flash->failure(t("Template not found."));
|
|
|
return $this->response->redirect($this->helper->url->to("TemplateController", "show", ["plugin" => "OMITemplateModder"]));
|
|
|
}
|
|
|
|
|
@@ -124,7 +148,7 @@ class TemplateController extends BaseController {
|
|
|
$templatePath = $this->getTemplatePath($templateName);
|
|
|
|
|
|
if (!file_exists($templatePath)) {
|
|
|
- $this->flash->failure(t("Template file not found!"));
|
|
|
+ $this->flash->failure(t("Template file not found."));
|
|
|
return $this->response->redirect($this->helper->url->to("TemplateController", "show", ["plugin" => "OMITemplateModder"]));
|
|
|
}
|
|
|
|
|
@@ -134,22 +158,22 @@ class TemplateController extends BaseController {
|
|
|
$this->response->html($this->helper->layout->config("OMITemplateModder:config/edit", [
|
|
|
"title" => t("OMI - Notification Template Modder"),
|
|
|
"subtitle" => t("Edit Template: %s", $templateName),
|
|
|
- "templateName" => $templateName,
|
|
|
- "templateContent" => htmlspecialchars($templateContent),
|
|
|
- "templateIndex" => $templateIndex // Pass the index for the form action
|
|
|
+ "template_name" => $templateName,
|
|
|
+ "template_content" => htmlspecialchars($templateContent),
|
|
|
+ "template_index" => $templateIndex // Pass the index for the form action
|
|
|
]));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Save the edited template
|
|
|
- */
|
|
|
+ * Save the edited template
|
|
|
+ */
|
|
|
public function save() {
|
|
|
|
|
|
$templateIndex = $this->request->getIntegerParam("template_index");
|
|
|
$templates = $this->getEditableTemplates();
|
|
|
|
|
|
if (!isset($templates[$templateIndex])) {
|
|
|
- $this->flash->failure(t("Template not found! Check your Kanboard version is compatible with this plugin."));
|
|
|
+ $this->flash->failure(t("Template not found. Check your Kanboard version is compatible with this plugin."));
|
|
|
return $this->response->redirect($this->helper->url->to("TemplateController", "show", ["plugin" => "OMITemplateModder"]));
|
|
|
}
|
|
|
|
|
@@ -177,11 +201,11 @@ class TemplateController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the full path to a template file
|
|
|
- *
|
|
|
- * @param string $templateName
|
|
|
- * @return string
|
|
|
- */
|
|
|
+ * Get the full path to a template file
|
|
|
+ *
|
|
|
+ * @param string $templateName
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
private function getTemplatePath($templateName) {
|
|
|
return \ETM_PLUGIN_ROOT_DIR . "/Template/" . $templateName . ".php";
|
|
|
}
|