From 89a19766be822f9d0c7f9d44096a33c5e5f03d27 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 13 Nov 2011 00:33:38 +0100 Subject: Added tag editing for backend and started work on article list. --- ratatoeskr/backend/main.php | 196 +++++++++++++++++++++ .../templates/src/systemtemplates/areyousure.html | 11 ++ .../templates/src/systemtemplates/articles.html | 44 +++++ .../src/systemtemplates/tag_addtranslation.html | 22 +++ .../templates/src/systemtemplates/tag_deleted.html | 7 + .../src/systemtemplates/tags_overview.html | 55 ++++++ ratatoeskr/translations/en.php | 26 ++- 7 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 ratatoeskr/templates/src/systemtemplates/areyousure.html create mode 100644 ratatoeskr/templates/src/systemtemplates/articles.html create mode 100644 ratatoeskr/templates/src/systemtemplates/tag_addtranslation.html create mode 100644 ratatoeskr/templates/src/systemtemplates/tag_deleted.html create mode 100644 ratatoeskr/templates/src/systemtemplates/tags_overview.html 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 @@ + + +
+

$question

+ ?{$moredetails|

$moredetails

|} +
+ + +
+
+
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 @@ + + +
Example for errors
+
Example for notice
+
Example for success
+ + + + + + + + + + + + $articles + + + + + + + + + + + + + + + + + +
 
$article[urlname] + + ?{~{$i|eq|0}||, }$lang + + %Y-%m-%d %H:%M:%S + + ?{~{$i|eq|0}||, } $tag + + $article[section][name]
+
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 @@ + + + $errors + +
+
    + +
  • $error
  • +
    +
+
+
+
+ +
+ : +
+
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 @@ + + +
+
+ +
+
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 @@ + + + $error + +
$error
+
+
+ $success + +
$success
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
($langcode) $langname
$tagdata[name] + <ste:get_translation for='delete' /> + + + + <ste:escape><ste:get_translation for='tag_add_lang' /></ste:escape> +
+
+
+ +
+

+
+

:

+

+
+
+
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." ); ?> -- cgit v1.2.3-70-g09d2