diff options
-rw-r--r-- | ratatoeskr/backend.php | 232 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/areyousure.html | 11 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/tags_overview.html | 45 | ||||
-rw-r--r-- | ratatoeskr/translations/de.php | 13 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 13 |
5 files changed, 134 insertions, 180 deletions
diff --git a/ratatoeskr/backend.php b/ratatoeskr/backend.php index a1ab570..3670137 100644 --- a/ratatoeskr/backend.php +++ b/ratatoeskr/backend.php @@ -39,25 +39,6 @@ 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 = NULL; function build_backend_subactions() @@ -421,149 +402,136 @@ $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)) + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "tags"; + $ste->vars["pagetitle"] = $translation["tags_overview"]; + + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) { - try + foreach($_POST["tag_multiselect"] as $tagid) { - $tag = Tag::by_name($tagname); + try + { + $tag = Tag::by_id($tagid); + $tag->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } } - catch(DoesNotExistError $e) + + $ste->vars["success"] = $translation["tags_successfully_deleted"]; + } + + if(isset($_POST["save_changes"])) + { + $newlang = (!empty($_POST["new_language"])) ? $_POST["new_language"] : NULL; + $newtag = NULL; + + if(!empty($_POST["newtagname"])) { - throw new NotFoundError(); + if((strpos(@$_POST["new_tag_name"], ",") !== False) or (strpos(@$_POST["new_tag_name"], " ") !== False)) + $ste->vars["error"] = $translation["invalid_tag_name"]; + else + $newtag = $_POST["newtagname"]; } - if(isset($tagaction)) + if(($newlang !== NULL) and (!isset($languages[$newlang]))) + $newlang = NULL; + if($newtag !== NULL) { - switch($tagaction) + try { - 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; + $newtag = Tag::create($newtag); + } + catch(AlreadyExistsError $e) + { + $newtag = NULL; } } - } - else - { - backend_content_tags_overview: - if(isset($_POST["create_new_tag"])) + $translations = array(); + foreach($_POST as $k => $v) { - 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 + if(preg_match('/tagtrans_(NEW|[a-z]{2})_(.*)/', $k, $matches) == 1) { - 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"]; - } + $lang = ($matches[1] == "NEW") ? $newlang : $matches[1]; + $tag = $matches[2]; + if($lang === NULL) + continue; + $translations[$tag][$lang] = $v; } } - if(isset($_POST["edit_translations"])) + foreach($translations as $tag => $langmap) { - $tagbuffer = array(); - foreach($_POST as $k => $v) + if($tag == "NEW") + { + if($newtag === NULL) + continue; + $tag = $newtag; + } + else { - if(preg_match("/^tagtrans_(.*?)_(.*)$/", $k, $matches)) + try { - 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, ""); + $tag = Tag::by_id($tag); + } + catch(DoesNotExistError $e) + { + continue; } } - foreach($tagbuffer as $tag) - $tag->save(); + foreach($langmap as $l => $text) + { + if(empty($text)) + unset($tag->title[$l]); + else + $tag->title[$l] = new Translation($text, ""); + } - $ste->vars["success"] = $translation["tag_titles_edited_successfully"]; + $tag->save(); } - $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; + $ste->vars["success"] = $translation["tags_successfully_edited"]; + } + + $ste->vars["alltags"] = array(); + $taglangs = array(); + + $alltags = Tag::all(); + foreach($alltags as $tag) + { + $transls = array(); + foreach($tag->title as $l => $t) + { + if(!in_array($l, $taglangs)) + $taglangs[] = $l; + $transls[$l] = $t->text; } - echo $ste->exectemplate("/systemtemplates/tags_overview.html"); + + $ste->vars["alltags"][] = array( + "id" => $tag->get_id(), + "name" => $tag->name, + "translations" => $transls + ); } + + $unused_langs = array_diff(array_keys($languages), $taglangs); + + $ste->vars["all_tag_langs"] = array(); + foreach($taglangs as $l) + $ste->vars["all_tag_langs"][$l] = $languages[$l]["language"]; + $ste->vars["unused_languages"] = array(); + foreach($unused_langs as $l) + $ste->vars["unused_languages"][$l] = $languages[$l]["language"]; + + echo $ste->exectemplate("/systemtemplates/tags_overview.html"); }, "articles" => function(&$data, $url_now, &$url_next) { diff --git a/ratatoeskr/templates/src/systemtemplates/areyousure.html b/ratatoeskr/templates/src/systemtemplates/areyousure.html deleted file mode 100644 index 0d40585..0000000 --- a/ratatoeskr/templates/src/systemtemplates/areyousure.html +++ /dev/null @@ -1,11 +0,0 @@ -<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='yes' raw='y' />}</ste:escape>" /> - <input type="submit" class="no_btn" name="no" value="<ste:escape>?{$notext|$notext|<ste:get_translation for='no' raw='y' />}</ste:escape>" /> - </form> - </div> -</ste:block> diff --git a/ratatoeskr/templates/src/systemtemplates/tags_overview.html b/ratatoeskr/templates/src/systemtemplates/tags_overview.html index 1f5b8d5..e82fd61 100644 --- a/ratatoeskr/templates/src/systemtemplates/tags_overview.html +++ b/ratatoeskr/templates/src/systemtemplates/tags_overview.html @@ -7,41 +7,52 @@ <table class="listtab"> <thead> <tr> + <th> </th> <th><ste:get_translation for="tag_name" /></th> - <th><ste:get_translation for="delete" /></th> <ste:foreach array="all_tag_langs" key="langcode" value="langname"> <th>($langcode) <ste:escape>$langname</ste:escape></th> </ste:foreach> - <th><ste:get_translation for="tag_add_lang" /></th> + <th> + <select name="new_language"> + <option value="" selected="selected"><ste:get_translation for="tag_add_lang" /></option> + <ste:foreach array="unused_languages" key="langcode" value="langname"> + <option value="$langcode">$langcode: <ste:escape>$langname</ste:escape></option> + </ste:foreach> + </select> + </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> + <td><input type="checkbox" name="tag_multiselect[]" value="$tagdata[id]" /></td> + <td><ste:escape>$tagdata[name]</ste:escape></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>" /> + <input type="text" name="tagtrans_${langcode}_${tagdata[id]}" 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:get_translation for='tag_add_lang' />" /></a> + <input type="text" name="tagtrans_NEW_${tagdata[id]}" /> </td> </tr> </ste:foreach> + <tr> + <td> </td> + <td><input type="text" name="newtagname" /></td> + <ste:foreach array="all_tag_langs" key="langcode" value="_"> + <td> + <input type="text" name="tagtrans_${langcode}_NEW" /> + </td> + </ste:foreach> + <td> + <input type="text" name="tagtrans_NEW_NEW" /> + </td> + </tr> </tbody> </table> - <div><input type="submit" name="edit_translations" /></div> + <div> + <ste:default_delete_yesno /> | <input type="submit" name="save_changes" value="<ste:get_translation for='save_changes' />"> + </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:get_translation for="new_tag_name" />: <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/de.php b/ratatoeskr/translations/de.php index 66c68d8..ae909b1 100644 --- a/ratatoeskr/translations/de.php +++ b/ratatoeskr/translations/de.php @@ -61,25 +61,18 @@ $translation = array( "allow_comments" => "Kommentare erlauben?", "article_name_already_in_use" => "Artikelname bereits vergeben.", "article_save_success" => "Artikel erfolgreich abgespeichert.", - "delete_tag_pagetitle" => "\"[[TAGNAME]]\" löschen", - "delete_comment_question" => "Möchtest du diesen Tag löschen?", - "tag_deleted" => "Tag gelöscht.", - "back_to_tags" => "Zurück zu Inhalt::Tags", - "create_new_tag" => "Neuen Tag erstellen", + "tags_successfully_deleted" => "Tags erfolgreich gelöscht.", "new_tag_name" => "Name", + "tags_successfully_edited" => "Tags erfolgreich bearbeitet." "tags_overview" => "Tag Übersicht", "tag_name" => "Tag Name", "yes" => "Ja", "no" => "Nein", "tag_add_lang" => "Übersetzung hinzufügen", + "save_changes" => "Änderungen speichern", "language_unknown" => "Unbekannte Sprache", - "no_translation_text_given" => "Kein Übersetzungstext angegeben.", "translation_added_successfully" => "Übersetzung erfolgreich hinzufügefügt.", - "tag_translation_added" => "Übersetzung hinzugefügt.", "invalid_tag_name" => "Ungülter Tagname. Ein Tagname darf keine Kommas (,) oder Leerzeichen ( ) enthalten und darf nicht leer sein.", - "tag_name_already_in_use" => "Tagname bereits vergeben.", - "tag_created_successfully" => "Tag erfolgreich erstellt.", - "tag_titles_edited_successfully" => "Tagtitel erfolgreich geändert.", "available_languages" => "Verfügbare Sprachen", "tags" => "Tags", "section" => "Sektion", diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 27374c6..86e17a2 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -61,25 +61,18 @@ $translation = array( "allow_comments" => "Allow comments?", "article_name_already_in_use" => "Article name is already in use.", "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", + "tags_successfully_deleted" => "Tags successfully deleted.", "new_tag_name" => "Name", + "tags_successfully_edited" => "Successfully edited tags.", "tags_overview" => "Tag Overview", "tag_name" => "Tag name", "yes" => "Yes", "no" => "No", "tag_add_lang" => "Add translation", + "save_changes" => "Save changes", "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", |