aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ratatoeskr/backend/main.php196
-rw-r--r--ratatoeskr/templates/src/systemtemplates/areyousure.html11
-rw-r--r--ratatoeskr/templates/src/systemtemplates/articles.html44
-rw-r--r--ratatoeskr/templates/src/systemtemplates/tag_addtranslation.html22
-rw-r--r--ratatoeskr/templates/src/systemtemplates/tag_deleted.html7
-rw-r--r--ratatoeskr/templates/src/systemtemplates/tags_overview.html55
-rw-r--r--ratatoeskr/translations/en.php26
7 files changed, 360 insertions, 1 deletions
diff --git a/ratatoeskr/backend/main.php b/ratatoeskr/backend/main.php
index 737ffab..4caa654 100644
--- a/ratatoeskr/backend/main.php
+++ b/ratatoeskr/backend/main.php
@@ -38,6 +38,25 @@ function maketags($tagnames, $lang)
return $rv;
}
+/* Generates Yes/No form / checks it. */
+function askyesno($ste, $callback, $question, $yes=NULL, $no=NULL, $moredetails="")
+{
+ if(isset($_POST["yes"]))
+ return True;
+ if(isset($_POST["no"]))
+ return False;
+
+ $ste->vars["callback"] = $callback;
+ $ste->vars["question"] = $question;
+ if($yes !== NULL)
+ $ste->vars["yestext"] = $yes;
+ if($no !== NULL)
+ $ste->vars["notext"] = $no;
+ if($moredetails !== NULL)
+ $ste->vars["moredetails"] = $moredetails;
+ return $ste->exectemplate("systemtemplates/areyousure.html");
+}
+
$backend_subactions = url_action_subactions(array(
"_index" => url_action_alias(array("login")),
"index" => url_action_alias(array("login")),
@@ -49,6 +68,7 @@ $backend_subactions = url_action_subactions(array(
$ste->vars["all_languages"] = array();
foreach($languages as $code => $data)
$ste->vars["all_languages"][$code] = $data["language"];
+ ksort($ste->vars["all_languages"]);
/* Check authentification */
if(isset($_SESSION["ratatoeskr_uid"]))
@@ -329,7 +349,183 @@ $backend_subactions = url_action_subactions(array(
},
"tags" => function(&$data, $url_now, &$url_next)
{
+ global $translation, $languages, $ste, $rel_path_to_root;
+ $ste->vars["section"] = "content";
+ $ste->vars["submenu"] = "tags";
+
+ list($tagname, $tagaction) = $url_next;
+ $url_next = array();
+
+ if(isset($tagname))
+ {
+ try
+ {
+ $tag = Tag::by_name($tagname);
+ }
+ catch(DoesNotExistError $e)
+ {
+ throw new NotFoundError();
+ }
+
+ if(isset($tagaction))
+ {
+ switch($tagaction)
+ {
+ case "delete":
+ $ste->vars["pagetitle"] = str_replace("[[TAGNAME]]", $tag->name, $translation["delete_tag_pagetitle"]);
+ $yesnoresp = askyesno($ste, "$rel_path_to_root/backend/content/tags/{$tag->name}/delete", $translation["delete_comment_question"]);
+ if(is_string($yesnoresp))
+ {
+ echo $yesnoresp;
+ return;
+ }
+
+ if($yesnoresp)
+ {
+ $tag->delete();
+ echo $ste->exectemplate("systemtemplates/tag_deleted.html");
+ }
+ else
+ goto backend_content_tags_overview; /* Hopefully no dinosaur will attack me: http://xkcd.com/292/ :-) */
+ break;
+ case "addtranslation":
+ $ste->vars["pagetitle"] = $translation["tag_add_lang"];
+ $ste->vars["tagname"] = $tag->name;
+ if(isset($_POST["addtranslation"]))
+ {
+ $errors = array();
+ if(!isset($languages[@$_POST["language"]]))
+ $errors[] = $translation["language_unknown"];
+ if(empty($_POST["translation"]))
+ $errors[] = $translation["no_translation_text_given"];
+ if(empty($errors))
+ {
+ $tag->title[$_POST["language"]] = new Translation($_POST["translation"], "");
+ $tag->save();
+ $ste->vars["success"] = $translation["tag_translation_added"];
+ goto backend_content_tags_overview;
+ }
+ else
+ $ste->vars["errors"] = $errors;
+ }
+ echo $ste->exectemplate("systemtemplates/tag_addtranslation.html");
+ break;
+ }
+ }
+ }
+ else
+ {
+ backend_content_tags_overview:
+
+ if(isset($_POST["create_new_tag"]))
+ {
+ if((strpos(@$_POST["new_tag_name"], ",") !== False) or (strpos(@$_POST["new_tag_name"], " ") !== False) or (strlen(@$_POST["new_tag_name"]) == 0))
+ $ste->vars["error"] = $translation["invalid_tag_name"];
+ else
+ {
+ try
+ {
+ $tag = Tag::create($_POST["new_tag_name"]);
+ $tag->title[$data["user"]->language] = new Translation($_POST["new_tag_name"], "");
+ $tag->save();
+ $ste->vars["success"] = $translation["tag_created_successfully"];
+ }
+ catch(AlreadyExistsError $e)
+ {
+ $ste->vars["error"] = $translation["tag_name_already_in_use"];
+ }
+ }
+ }
+
+ if(isset($_POST["edit_translations"]))
+ {
+ $tagbuffer = array();
+ foreach($_POST as $k => $v)
+ {
+ if(preg_match("/^tagtrans_(.*?)_(.*)$/", $k, $matches))
+ {
+ if(!isset($languages[$matches[1]]))
+ continue;
+
+ if(!isset($tagbuffer[$matches[2]]))
+ {
+ try
+ {
+ $tagbuffer[$matches[2]] = Tag::by_name($matches[2]);
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+
+ if(empty($v) and isset($tagbuffer[$matches[2]]->title[$matches[1]]))
+ unset($tagbuffer[$matches[2]]->title[$matches[1]]);
+ elseif(empty($v))
+ continue;
+ else
+ $tagbuffer[$matches[2]]->title[$matches[1]] = new Translation($v, "");
+ }
+ }
+
+ foreach($tagbuffer as $tag)
+ $tag->save();
+
+ $ste->vars["success"] = $translation["tag_titles_edited_successfully"];
+ }
+
+ $ste->vars["pagetitle"] = $translation["tags_overview"];
+
+ $alltags = Tag::all();
+ usort($alltags, function($a, $b) { return strcmp($a->name, $b->name); });
+ $ste->vars["all_tag_langs"] = array();
+ $ste->vars["alltags"] = array();
+ foreach($alltags as $tag)
+ {
+ $tag_pre = array("name" => $tag->name, "translations" => array());
+ foreach($tag->title as $langcode => $translation_obj)
+ {
+ $tag_pre["translations"][$langcode] = $translation_obj->text;
+ if(!isset($ste->vars["all_tag_langs"][$langcode]))
+ $ste->vars["all_tag_langs"][$langcode] = $languages[$langcode]["language"];
+ }
+ $ste->vars["alltags"][] = $tag_pre;
+ }
+ echo $ste->exectemplate("systemtemplates/tags_overview.html");
+ }
+ },
+ "articles" => function(&$data, $url_now, &$url_next)
+ {
+ global $ste, $translation, $languages, $rel_path_to_root;
+
+ $url_next = array();
+
+ $ste->vars["section"] = "content";
+ $ste->vars["submenu"] = "articles";
+ $ste->vars["pagetitle"] = $translation["menu_articles"];
+
+
+
+ $articles = Article::all();
+
+ /* Filtering */
+ #if(isset)
+
+ $ste->vars["articles"] = array_map(function($article) {
+ $avail_langs = array();
+ foreach($article->title as $lang => $_)
+ $avail_langs[] = $lang;
+ sort($avail_langs);
+ return array(
+ "urlname" => $article->urlname,
+ "languages" => $avail_langs,
+ "date" => $article->timestamp,
+ "tags" => array_map(function($tag) { return $tag->name; }, $article->tags),
+ "section" => array("id" => $article->section->get_id(), "name" => $article->section->name)
+ );
+ }, $articles);
+ echo $ste->exectemplate("systemtemplates/articles.html");
}
))
));
diff --git a/ratatoeskr/templates/src/systemtemplates/areyousure.html b/ratatoeskr/templates/src/systemtemplates/areyousure.html
new file mode 100644
index 0000000..7a5ef82
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/areyousure.html
@@ -0,0 +1,11 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <div class="pos_center">
+ <h2><ste:escape>$question</ste:escape></h2>
+ ?{$moredetails|<p><ste:escape>$moredetails</ste:escape></p>|}
+ <form action="$callback" method="POST">
+ <input type="submit" class="yes_btn" name="yes" value="<ste:escape>?{$yestext|$yestext|<ste:get_translation for='yestext_default' />}</ste:escape>" />
+ <input type="submit" class="no_btn" name="no" value="<ste:escape>?{$notext|$notext|<ste:get_translation for='notext_default' />}</ste:escape>" />
+ </form>
+ </div>
+</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/articles.html b/ratatoeskr/templates/src/systemtemplates/articles.html
new file mode 100644
index 0000000..051f3ff
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/articles.html
@@ -0,0 +1,44 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <div class="error">Example for errors</div>
+ <div class="notice">Example for notice</div>
+ <div class="success">Example for success</div>
+
+ <table class="fullwidth listtab">
+ <thead><tr>
+ <th>&nbsp;</th>
+ <th><ste:get_translation for="urlname" /></th>
+ <th><ste:get_translation for="available_languages" /></th>
+ <th><ste:get_translation for="date_time" /></th>
+ <th><ste:get_translation for="tags" /></th>
+ <th><ste:get_translation for="section" /></th>
+ </tr></thead>
+ <tbody>
+ <ste:if>$articles
+ <ste:then>
+ <ste:foreach array="articles" value="article">
+ <tr>
+ <td><input type="checkbox" name="article_multiselect[]" value="$article[urlname]" /></td>
+ <td><a href="$rel_path_to_root/backend/content/write/$article[urlname]">$article[urlname]</a></td>
+ <td>
+ <ste:foreach array="article[languages]" value="lang" counter="i">
+ ?{~{$i|eq|0}||, }<a href="$rel_path_to_root/backend/content/write/$article[urlname]/$lang">$lang</a>
+ </ste:foreach>
+ </td>
+ <td><ste:date timestamp="$article[date]">%Y-%m-%d %H:%M:%S</ste:date></td>
+ <td>
+ <ste:foreach array="article[tags]" value="tag" counter="i">
+ ?{~{$i|eq|0}||, } <ste:escape>$tag</ste:escape>
+ </ste:foreach>
+ </td>
+ <td><a href="$rel_path_to_root/backend/design/sections/$article[section][id]"><ste:escape>$article[section][name]</ste:escape></a></td>
+ </tr>
+ </ste:foreach>
+ </ste:then>
+ <ste:else>
+ <tr><td colspan="6" style="text-align: center;"><em><ste:escape><ste:get_translation for="no_articles" /></ste:escape></em></td></tr>
+ </ste:else>
+ </ste:if>
+ </tbody>
+ </table>
+</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/tag_addtranslation.html b/ratatoeskr/templates/src/systemtemplates/tag_addtranslation.html
new file mode 100644
index 0000000..b7dd466
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/tag_addtranslation.html
@@ -0,0 +1,22 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:if>$errors
+ <ste:then>
+ <div class="error">
+ <ul>
+ <ste:foreach array="errors" value="error">
+ <li><ste:escape>$error</ste:escape></li>
+ </ste:foreach>
+ </ul>
+ </div>
+ </ste:then>
+ </ste:if>
+
+ <form action="$rel_path_to_root/backend/content/tags/$tagname/addtranslation" method="POST" accept_charset="UTF-8">
+ <select name="language">
+ <ste:foreach array="all_languages" key="code" value="name">
+ <option value="$code">($code) $name</option>
+ </ste:foreach>
+ </select>: <input type="text" name="translation" /> <input type="submit" name="addtranslation" />
+ </form>
+</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/tag_deleted.html b/ratatoeskr/templates/src/systemtemplates/tag_deleted.html
new file mode 100644
index 0000000..641b06c
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/tag_deleted.html
@@ -0,0 +1,7 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <div class="success">
+ <ste:escape><ste:get_translation for="tag_deleted" /></ste:escape><br />
+ <a href="$rel_path_to_root/backend/content/tags"><ste:escape><ste:get_translation for="back_to_tags" /></ste:escape></a>
+ </div>
+</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/tags_overview.html b/ratatoeskr/templates/src/systemtemplates/tags_overview.html
new file mode 100644
index 0000000..29288e7
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/tags_overview.html
@@ -0,0 +1,55 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:if>$error
+ <ste:then>
+ <div class="error">$error</div>
+ </ste:then>
+ </ste:if>
+ <ste:if>$success
+ <ste:then>
+ <div class="success">$success</div>
+ </ste:then>
+ </ste:if>
+
+ <form action="$rel_path_to_root/backend/content/tags" method="POST" accept-charset="UTF-8">
+ <table>
+ <thead>
+ <tr>
+ <th><ste:escape><ste:get_translation for="tag_name" /></ste:escape></th>
+ <th><ste:escape><ste:get_translation for="delete" /></ste:escape></th>
+ <ste:foreach array="all_tag_langs" key="langcode" value="langname">
+ <th>($langcode) <ste:escape>$langname</ste:escape></th>
+ </ste:foreach>
+ <th><ste:escape><ste:get_translation for="tag_add_lang" /></ste:escape></th>
+ </tr>
+ </thead>
+ <tbody>
+ <ste:foreach array="alltags" value="tagdata">
+ <tr>
+ <td>$tagdata[name]</td>
+ <td>
+ <a href="$rel_path_to_root/backend/content/tags/$tagdata[name]/delete"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/delete.png" alt="<ste:get_translation for='delete' />" /></a>
+ </td>
+ <ste:foreach array="all_tag_langs" key="langcode" value="_">
+ <td>
+ <input type="text" name="tagtrans_${langcode}_${tagdata[name]}" value="<ste:escape>$tagdata[translations][$langcode]</ste:escape>" />
+ </td>
+ </ste:foreach>
+ <td>
+ <a href="$rel_path_to_root/backend/content/tags/$tagdata[name]/addtranslation"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/add.png" alt="<ste:escape><ste:get_translation for='tag_add_lang' /></ste:escape>" /></a>
+ </td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ <div><input type="submit" name="edit_translations" /></div>
+ </form>
+
+ <div>
+ <h2><ste:get_translation for="create_new_tag" /></h2>
+ <form action="$rel_path_to_root/backend/content/tags" method="POST" accept-charset="UTF-8">
+ <p><ste:escape><ste:get_translation for="new_tag_name" /></ste:escape>: <input type="text" name="new_tag_name" /></p>
+ <p><input type="submit" name="create_new_tag" /></p>
+ </form>
+ </div>
+</ste:block>
diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php
index 31d0944..7cf3d51 100644
--- a/ratatoeskr/translations/en.php
+++ b/ratatoeskr/translations/en.php
@@ -60,7 +60,31 @@ $translation = array(
"unknown_section" => "Unknown section",
"allow_comments" => "Allow comments?",
"article_name_already_in_use" => "Article name is already in use.",
- "article_save_success" => "Article successfully saved."
+ "article_save_success" => "Article successfully saved.",
+ "delete_tag_pagetitle" => "Delete \"[[TAGNAME]]\"",
+ "delete_comment_question" => "Do you want to delete this tag?",
+ "tag_deleted" => "Tag was deleted.",
+ "back_to_tags" => "Go back to Content::Tags",
+ "create_new_tag" => "Create a new Tag",
+ "new_tag_name" => "Name",
+ "tags_overview" => "Tag Overview",
+ "tag_name" => "Tag name",
+ "delete" => "Delete",
+ "yestext_default" => "Yes",
+ "notext_default" => "No",
+ "tag_add_lang" => "Add translation",
+ "language_unknown" => "Unknown language",
+ "no_translation_text_given" => "No translation text given.",
+ "translation_added_successfully" => "Translation added successfully.",
+ "tag_translation_added" => "Translation added.",
+ "invalid_tag_name" => "Invalid tag name. A tag name can not contain commas (,) or spaces ( ) and must not be empty.",
+ "tag_name_already_in_use" => "Tag name already in use.",
+ "tag_created_successfully" => "Tag created successfully.",
+ "tag_titles_edited_successfully" => "Tag titles changed successfully.",
+ "available_languages" => "Available languages",
+ "tags" => "Tags",
+ "section" => "Section",
+ "no_articles" => "No articles stored."
);
?>