aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2011-11-20 21:20:36 +0100
committerKevin Chabowski <kevin@kch42.de>2011-11-20 21:20:36 +0100
commit791ae7f8dcc2f01f452c5f41ce484118820db585 (patch)
treefbf96c01e1b72b0e254cc59c28e26f6b56770292 /ratatoeskr
parent08f8737a13a14530e53426aa1ee9959de6d2c8ca (diff)
downloadratatoeskr-cms-791ae7f8dcc2f01f452c5f41ce484118820db585.tar.gz
ratatoeskr-cms-791ae7f8dcc2f01f452c5f41ce484118820db585.tar.bz2
ratatoeskr-cms-791ae7f8dcc2f01f452c5f41ce484118820db585.zip
Added template and style management to the backend.
Diffstat (limited to 'ratatoeskr')
-rw-r--r--ratatoeskr/backend/main.php151
-rw-r--r--ratatoeskr/cms_style/layout.css4
-rw-r--r--ratatoeskr/templates/src/systemtemplates/content_write.html4
-rw-r--r--ratatoeskr/templates/src/systemtemplates/styles.html60
-rw-r--r--ratatoeskr/templates/src/systemtemplates/templates.html60
-rw-r--r--ratatoeskr/translations/en.php17
6 files changed, 293 insertions, 3 deletions
diff --git a/ratatoeskr/backend/main.php b/ratatoeskr/backend/main.php
index cf1f5c3..05513b1 100644
--- a/ratatoeskr/backend/main.php
+++ b/ratatoeskr/backend/main.php
@@ -897,6 +897,157 @@ $backend_subactions = url_action_subactions(array(
echo $ste->exectemplate("systemtemplates/comments_list.html");
}
+ )),
+ "design" => url_action_subactions(array(
+ "templates" => function(&$data, $url_now, &$url_next)
+ {
+ global $ste, $translation, $languages, $rel_path_to_root;
+
+ list($template) = $url_next;
+
+ $url_next = array();
+
+ $ste->vars["section"] = "design";
+ $ste->vars["submenu"] = "templates";
+ $ste->vars["pagetitle"] = $translation["menu_templates"];
+
+ if(isset($template))
+ {
+ if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $template) == 0) /* Prevent a possible LFI attack. */
+ throw new NotFoundError();
+ if(!is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template"))
+ throw new NotFoundError();
+ $ste->vars["template_name"] = $template;
+ $ste->vars["template_code"] = file_get_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template");
+ }
+
+ /* Was there a delete request? */
+ if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes"))
+ {
+ foreach($_POST["templates_multiselect"] as $tplname)
+ {
+ if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $tplname) == 0) /* Prevent a possible LFI attack. */
+ continue;
+ if(is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname"))
+ @unlink(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname");
+ }
+ $ste->vars["success"] = $translation["templates_successfully_deleted"];
+ }
+
+ /* A write request? */
+ if(isset($_POST["save_template"]))
+ {
+ if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["template_name"]) == 1)
+ {
+ $ste->vars["template_name"] = $_POST["template_name"];
+ $ste->vars["template_code"] = $_POST["template_code"];
+
+ try
+ {
+ \ste\transcompile(\ste\parse(\ste\precompile($_POST["template_code"]), $_POST["template_name"]));
+ file_put_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/" . $_POST["template_name"], $_POST["template_code"]);
+ $ste->vars["success"] = $translation["template_successfully_saved"];
+ }
+ catch(\ste\ParseCompileError $e)
+ {
+ $e->rewrite($_POST["template_code"]);
+ $ste->vars["error"] = $translation["could_not_compile_template"] . $e->getMessage();
+ }
+ }
+ else
+ $ste->vars["error"] = $translation["invalid_template_name"];
+ }
+
+ /* Get all templates */
+ $ste->vars["templates"] = array();
+ $tpldir = new DirectoryIterator(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates");
+ foreach($tpldir as $fo)
+ {
+ if($fo->isFile())
+ $ste->vars["templates"][] = $fo->getFilename();
+ }
+
+ sort($ste->vars["templates"]);
+
+ echo $ste->exectemplate("systemtemplates/templates.html");
+ },
+ "styles" => function(&$data, $url_now, &$url_next)
+ {
+ global $ste, $translation, $languages, $rel_path_to_root;
+
+ list($style) = $url_next;
+
+ $url_next = array();
+
+ $ste->vars["section"] = "design";
+ $ste->vars["submenu"] = "styles";
+ $ste->vars["pagetitle"] = $translation["menu_styles"];
+
+ if(isset($style))
+ {
+ try
+ {
+ $style = Style::by_name($style);
+ $ste->vars["style_name"] = $style->name;
+ $ste->vars["style_code"] = $style->code;
+ }
+ catch(DoesNotExistError $e)
+ {
+ throw new NotFoundError();
+ }
+ }
+
+ /* Was there a delete request? */
+ if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes"))
+ {
+ foreach($_POST["styles_multiselect"] as $stylename)
+ {
+ try
+ {
+ $style = Style::by_name($stylename);
+ $style->delete();
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+ $ste->vars["success"] = $translation["styles_successfully_deleted"];
+ }
+
+ /* A write request? */
+ if(isset($_POST["save_style"]))
+ {
+ if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["style_name"]) == 1)
+ {
+ $ste->vars["style_name"] = $_POST["style_name"];
+ $ste->vars["style_code"] = $_POST["style_code"];
+
+ try
+ {
+ $style = Style::by_name($_POST["style_name"]);
+ }
+ catch(DoesNotExistError $e)
+ {
+ $style = Style::create($_POST["style_name"]);
+ }
+
+ $style->code = $_POST["style_code"];
+ $style->save();
+
+ $ste->vars["success"] = $translation["style_successfully_saved"];
+ }
+ else
+ $ste->vars["error"] = $translation["invalid_style_name"];
+ }
+
+ /* Get all styles */
+ $ste->vars["styles"] = array_map(function($s) { return $s->name; }, Style::all());
+
+ sort($ste->vars["styles"]);
+
+ echo $ste->exectemplate("systemtemplates/styles.html");
+ }
))
));
diff --git a/ratatoeskr/cms_style/layout.css b/ratatoeskr/cms_style/layout.css
index 00e41cb..c704961 100644
--- a/ratatoeskr/cms_style/layout.css
+++ b/ratatoeskr/cms_style/layout.css
@@ -241,3 +241,7 @@ table.listtab tr:first-child td {
table.listtab tbody tr:hover {
background: #eee;
}
+
+textarea.codeedit {
+ font-family: monospace;
+}
diff --git a/ratatoeskr/templates/src/systemtemplates/content_write.html b/ratatoeskr/templates/src/systemtemplates/content_write.html
index 9ec9548..fb30aa4 100644
--- a/ratatoeskr/templates/src/systemtemplates/content_write.html
+++ b/ratatoeskr/templates/src/systemtemplates/content_write.html
@@ -148,11 +148,11 @@ Header 2<br />
</p>
<p>
<ste:get_translation for="articleedit_content" />: <select name="content_txtproc"><ste:textprocessor_options>$content_txtproc</ste:textprocessor_options></select>
- <textarea name="content" cols="80" rows="20" class="fullwidth"><ste:escape>$content</ste:escape></textarea>
+ <textarea name="content" cols="80" rows="20" class="fullwidth codeedit"><ste:escape>$content</ste:escape></textarea>
</p>
<p>
<ste:get_translation for="articleedit_excerpt" />: <select name="excerpt_txtproc"><ste:textprocessor_options>$excerpt_txtproc</ste:textprocessor_options></select>
- <textarea name="excerpt" cols="80" rows="10" class="fullwidth"><ste:escape>$excerpt</ste:escape></textarea>
+ <textarea name="excerpt" cols="80" rows="10" class="fullwidth codeedit"><ste:escape>$excerpt</ste:escape></textarea>
</p>
<p style="text-align: center;">
<ste:get_translation for="save_texts_as_lang" />: <select name="saveaslang">
diff --git a/ratatoeskr/templates/src/systemtemplates/styles.html b/ratatoeskr/templates/src/systemtemplates/styles.html
new file mode 100644
index 0000000..bacd2c0
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/styles.html
@@ -0,0 +1,60 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:if>$success
+ <ste:then>
+ <div class="success"><ste:escape>$success</ste:escape></div>
+ </ste:then>
+ </ste:if>
+ <ste:if>$error
+ <ste:then>
+ <div class="error"><ste:escape>$error</ste:escape></div>
+ </ste:then>
+ </ste:if>
+ <div class="dualcolumns">
+ <div class="column_left">
+ <form action="$rel_path_to_root/backend/design/styles" method="POST">
+ <table class="fullwidth listtab">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th><ste:get_translation for="style" /></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>&nbsp;</td>
+ <td><a href="$rel_path_to_root/backend/design/styles"><em><ste:get_translation for="new_style" /></em></a></td>
+ </tr>
+ <ste:foreach array="styles" value="style">
+ <tr>
+ <td><input type="checkbox" name="styles_multiselect[]" value="$style" /></td>
+ <td><a href="$rel_path_to_root/backend/design/styles/$style">$style</a></td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ <div>
+ <input type="submit" name="delete" value="<ste:get_translation for='delete' />" />
+ <select name="really_delete">
+ <option value="no" selected="selected"><ste:get_translation for="no" /></option>
+ <option value="yes"><ste:get_translation for="yes" /></option>
+ </select>
+ </div>
+ </form>
+ </div>
+ <div class="column_main">
+ <form action="$rel_path_to_root/backend/design/styles" method="POST" accept-charset="UTF-8">
+ <p>
+ <strong><ste:get_translation for="style_name" />:</strong><br />
+ <input type="text" name="style_name" value="<ste:escape>$style_name</ste:escape>" />
+ </p>
+ <p>
+ <strong><ste:get_translation for="style_code" />:</strong><br />
+ <textarea name="style_code" class="fullwidth codeedit" cols="80" rows="20"><ste:escape>$style_code</ste:escape></textarea>
+ </p>
+ <p><input type="submit" name="save_style" /></p>
+ </form>
+ </div>
+ </div>
+ <div class="dualcolumns_stop"></div>
+</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/templates.html b/ratatoeskr/templates/src/systemtemplates/templates.html
new file mode 100644
index 0000000..1d15967
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/templates.html
@@ -0,0 +1,60 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:if>$success
+ <ste:then>
+ <div class="success"><ste:escape>$success</ste:escape></div>
+ </ste:then>
+ </ste:if>
+ <ste:if>$error
+ <ste:then>
+ <div class="error"><ste:escape>$error</ste:escape></div>
+ </ste:then>
+ </ste:if>
+ <div class="dualcolumns">
+ <div class="column_left">
+ <form action="$rel_path_to_root/backend/design/templates" method="POST">
+ <table class="fullwidth listtab">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th><ste:get_translation for="template" /></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>&nbsp;</td>
+ <td><a href="$rel_path_to_root/backend/design/templates"><em><ste:get_translation for="new_template" /></em></a></td>
+ </tr>
+ <ste:foreach array="templates" value="template">
+ <tr>
+ <td><input type="checkbox" name="templates_multiselect[]" value="$template" /></td>
+ <td><a href="$rel_path_to_root/backend/design/templates/$template">$template</a></td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ <div>
+ <input type="submit" name="delete" value="<ste:get_translation for='delete' />" />
+ <select name="really_delete">
+ <option value="no" selected="selected"><ste:get_translation for="no" /></option>
+ <option value="yes"><ste:get_translation for="yes" /></option>
+ </select>
+ </div>
+ </form>
+ </div>
+ <div class="column_main">
+ <form action="$rel_path_to_root/backend/design/templates" method="POST" accept-charset="UTF-8">
+ <p>
+ <strong><ste:get_translation for="template_name" />:</strong><br />
+ <input type="text" name="template_name" value="<ste:escape>$template_name</ste:escape>" />
+ </p>
+ <p>
+ <strong><ste:get_translation for="template_code" />:</strong><br />
+ <textarea name="template_code" class="fullwidth codeedit" cols="80" rows="20"><ste:escape>$template_code</ste:escape></textarea>
+ </p>
+ <p><input type="submit" name="save_template" /></p>
+ </form>
+ </div>
+ </div>
+ <div class="dualcolumns_stop"></div>
+</ste:block>
diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php
index 9f1401e..440306d 100644
--- a/ratatoeskr/translations/en.php
+++ b/ratatoeskr/translations/en.php
@@ -130,7 +130,22 @@ $translation = array(
"comment_successfully_made_invisible" => "Comment successfully made invisible.",
"comment_perform_action" => "Perform an action on this comment",
"comment_text" => "Comment Text",
- "comment_text_raw" => "Comment Text (raw)"
+ "comment_text_raw" => "Comment Text (raw)",
+ "new_template" => "New Template",
+ "template" => "Template",
+ "template_name" => "Template name",
+ "template_code" => "Template code",
+ "templates_successfully_deleted" => "Templates successfully deleted",
+ "invalid_template_name" => "Invalid template name. Valid template names are at least 1 character long and only contains letters, numbers, underscores(_), hyphens(-) and dots(.)",
+ "could_not_compile_template" => "Could not compile template. Reason: ",
+ "template_successfully_saved" => "Template successfully saved.",
+ "style" => "Style",
+ "new_style" => "New style",
+ "style_name" => "Style name",
+ "style_code" => "Style code",
+ "styles_successfully_deleted" => "Styles successfully deleted",
+ "invalid_style_name" => "Invalid style name. Valid style names are at least 1 character long and only contains letters, numbers, underscores(_), hyphens(-) and dots(.)",
+ "style_successfully_saved" => "Style successfully saved."
);
?>