diff options
author | Kevin Chabowski <kevin@kch42.de> | 2011-11-23 18:17:52 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2011-11-23 18:17:52 +0100 |
commit | 767b3ebdd83bfd49d82438711f2e240f505a27c5 (patch) | |
tree | a7216ef528efc159df181dd26a250cbfda232d5c | |
parent | 57feb6e59f414026e1367146d89a9b5ff8f066ad (diff) | |
download | ratatoeskr-cms-767b3ebdd83bfd49d82438711f2e240f505a27c5.tar.gz ratatoeskr-cms-767b3ebdd83bfd49d82438711f2e240f505a27c5.tar.bz2 ratatoeskr-cms-767b3ebdd83bfd49d82438711f2e240f505a27c5.zip |
Added page section management to backend.
-rw-r--r-- | ratatoeskr/backend/main.php | 199 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/articles.html | 2 | ||||
-rw-r--r-- | ratatoeskr/templates/src/systemtemplates/sections.html | 87 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 23 |
4 files changed, 308 insertions, 3 deletions
diff --git a/ratatoeskr/backend/main.php b/ratatoeskr/backend/main.php index 83ca013..e8ed80c 100644 --- a/ratatoeskr/backend/main.php +++ b/ratatoeskr/backend/main.php @@ -66,9 +66,15 @@ $backend_subactions = url_action_subactions(array( global $ratatoeskr_settings, $admin_grp, $ste, $languages; $ste->vars["all_languages"] = array(); + $ste->vars["all_langcodes"] = array(); foreach($languages as $code => $data) + { $ste->vars["all_languages"][$code] = $data["language"]; + $ste->vars["all_langcodes"][] = $code; + } ksort($ste->vars["all_languages"]); + sort($ste->vars["all_langcodes"]); + /* Check authentification */ if(isset($_SESSION["ratatoeskr_uid"])) @@ -159,7 +165,7 @@ $backend_subactions = url_action_subactions(array( $default_section = Section::by_id($ratatoeskr_settings["default_section"]); $ste->vars["section"] = "content"; - $ste->vars["submenu"] = "newarticle"; + $ste->vars["submenu"] = isset($article) ? "articles" : "newarticle"; $ste->vars["textprocessors"] = array(); foreach($textprocessors as $txtproc => $properties) @@ -1045,6 +1051,197 @@ $backend_subactions = url_action_subactions(array( sort($ste->vars["styles"]); echo $ste->exectemplate("systemtemplates/styles.html"); + }, + "sections" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings; + + list($style) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "design"; + $ste->vars["submenu"] = "sections"; + $ste->vars["pagetitle"] = $translation["menu_pagesections"]; + + /* New section? */ + if(isset($_POST["new_section"])) + { + try + { + Section::by_name($_POST["section_name"]); + $ste->vars["error"] = $translation["section_already_exists"]; + } + catch(DoesNotExistError $e) + { + if((preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["template"]) == 0) or (!is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/{$_POST['template']}"))) + $ste->vars["error"] = $translation["unknown_template"]; + else if(preg_match("/^[a-zA-Z0-9\\-_]+$/", $_POST["section_name"]) == 0) + $ste->vars["error"] = $translation["invalid_section_name"]; + else + { + $section = Section::create($_POST["section_name"]); + $section->template = $_POST["template"]; + $section->title[$data["user"]->language] = new Translation($_POST["section_name"], ""); + $section->save(); + $ste->vars["success"] = $translation["section_created_successfully"]; + } + } + } + + /* Remove a style? */ + if(isset($_GET["rmstyle"]) and isset($_GET["rmfrom"])) + { + try + { + $section = Section::by_name($_GET["rmfrom"]); + $style = $_GET["rmstyle"]; + $section->styles = array_filter($section->styles, function($s) use ($style) { return $s->name != $style; }); + $section->save(); + $ste->vars["success"] = $translation["style_removed"]; + } + catch(DoesNotExistError $e) + { + continue; + } + } + + /* Delete a section? */ + if(isset($_POST["delete"]) and (@$_POST["really_delete"] == "yes") and isset($_POST["section_select"])) + { + try + { + $section = Section::by_name($_POST["section_select"]); + if($section->get_id() == $ratatoeskr_settings["default_section"]) + $ste->vars["error"] = $translation["cannot_delete_default_section"]; + else + { + $default_section = Section::by_id($ratatoeskr_settings["default_section"]); + foreach($section->get_articles() as $article) + { + $article->section = $default_section; + $article->save(); + } + $section->delete(); + $ste->vars["success"] = $translation["section_successfully_deleted"]; + } + } + catch(DoesNotExistError $e) + { + continue; + } + } + + /* Make section default? */ + if(isset($_POST["make_default"]) and isset($_POST["section_select"])) + { + try + { + $section = Section::by_name($_POST["section_select"]); + $ratatoeskr_settings["default_section"] = $section->get_id(); + $ste->vars["success"] = $translation["default_section_changed_successfully"]; + } + catch(DoesNotExistError $e) + { + continue; + } + } + + /* Set template? */ + if(isset($_POST["set_template"]) and isset($_POST["section_select"])) + { + try + { + $section = Section::by_name($_POST["section_select"]); + if((preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["set_template_to"]) == 0) or (!is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/{$_POST['set_template_to']}"))) + $ste->vars["error"] = $translation["unknown_template"]; + else + { + $section->template = $_POST["set_template_to"]; + $section->save(); + $ste->vars["success"] = $translation["successfully_set_template"]; + } + } + catch(DoesNotExistError $e) + { + continue; + } + } + + /* Adding a style? */ + if(isset($_POST["add_style"]) and isset($_POST["section_select"])) + { + try + { + $section = Section::by_name($_POST["section_select"]); + $style = Style::by_name($_POST["style_to_add"]); + if(!in_array($style, $section->styles)) + { + $section->styles[] = $style; + $section->save(); + } + $ste->vars["success"] = $translation["successfully_added_style"]; + } + catch(DoesNotExistError $e) + { + continue; + } + } + + /* Set/unset title? */ + if(isset($_POST["set_title"]) and isset($_POST["section_select"])) + { + if(!isset($languages[$_POST["set_title_lang"]])) + $ste->vars["error"] = $translation["language_unknown"]; + else + { + try + { + $section = Section::by_name($_POST["section_select"]); + if(!empty($_POST["set_title_text"])) + $section->title[$_POST["set_title_lang"]] = new Translation($_POST["set_title_text"], ""); + else if(isset($section->title[$_POST["set_title_lang"]])) + unset($section->title[$_POST["set_title_lang"]]); + $section->save(); + $ste->vars["success"] = $translation["successfully_set_section_title"]; + } + catch(DoesNotExistError $e) + { + continue; + } + } + } + + /* 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"]); + + /* Get all styles */ + $ste->vars["styles"] = array_map(function($s) { return $s->name; }, Style::all()); + sort($ste->vars["styles"]); + + /* Get all sections */ + $sections = Section::all(); + $ste->vars["sections"] = array_map(function($section) use ($ratatoeskr_settings) { + $titles = array(); + foreach($section->title as $l => $t) + $titles[$l] = $t->text; + return array( + "name" => $section->name, + "title" => $titles, + "template" => $section->template, + "styles" => array_map(function($style) { return $style->name; }, $section->styles), + "default" => ($section->get_id() == $ratatoeskr_settings["default_section"]) + ); + }, $sections); + + echo $ste->exectemplate("systemtemplates/sections.html"); } )) )); diff --git a/ratatoeskr/templates/src/systemtemplates/articles.html b/ratatoeskr/templates/src/systemtemplates/articles.html index 0742726..4d9c2ff 100644 --- a/ratatoeskr/templates/src/systemtemplates/articles.html +++ b/ratatoeskr/templates/src/systemtemplates/articles.html @@ -63,7 +63,7 @@ ?{~{$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> + <td><ste:escape>$article[section][name]</ste:escape></td> </tr> </ste:foreach> </ste:then> diff --git a/ratatoeskr/templates/src/systemtemplates/sections.html b/ratatoeskr/templates/src/systemtemplates/sections.html new file mode 100644 index 0000000..1228933 --- /dev/null +++ b/ratatoeskr/templates/src/systemtemplates/sections.html @@ -0,0 +1,87 @@ +<ste:load name="master.html" /> +<ste:mktag name="instant_select" mandatory="name|array"><select name="$_tag_parameters[name]"> + <ste:foreach array="$_tag_parameters[array]" value="instant_select_v"> + <option value="$instant_select_v"?{~{$_tag_parameters[selected]|eq|$instant_select_v}| selected="selected"|}>$instant_select_v</option> + </ste:foreach> +</select></ste:mktag> +<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"> + <h2><ste:get_translation for="new_section" /></h2> + <form action="$rel_path_to_root/backend/design/sections" method="POST" accept-charset="UTF-8"> + <p> + <strong><ste:get_translation for="section_name" />:</strong><br /> + <input type="text" name="section_name" /> + </p> + <p> + <strong><ste:get_translation for="template" />:</strong><br /> + <ste:instant_select name="template" array="templates" /> + </p> + <p><input type="submit" name="new_section" /></p> + </form> + </div> + <div class="column_main"> + <form action="$rel_path_to_root/backend/design/sections" method="POST" accept-charset="UTF-8"> + <table class="listtab fullwidth"> + <thead> + <tr> + <th> </th> + <th><ste:get_translation for="section" /></th> + <th><ste:get_translation for="section_title" /></th> + <th><ste:get_translation for="section_is_default" /></th> + <th><ste:get_translation for="template" /></th> + <th><ste:get_translation for="styles" /></th> + </tr> + </thead> + <tbody> + <ste:foreach array="sections" value="section"> + <tr> + <td><input type="radio" name="section_select" value="$section[name]" /></td> + <td><ste:escape>$section[name]</ste:escape></td> + <td> + <ste:foreach array="section[title]" key="langcode" value="title" counter="ti"> + ?{~{$ti|eq|0}||<br />} + ($langcode) <ste:escape>$title</ste:escape> + </ste:foreach> + </td> + <td>?{$section[default]|<strong><ste:get_translation for="yes" /></strong>|<ste:get_translation for="no" />}</td> + <td><a href="$rel_path_to_root/backend/design/templates/<ste:escape>$section[template]</ste:escape>"><ste:escape>$section[template]</ste:escape></a></td> + <td> + <ste:foreach array="section[styles]" value="style" counter="si"> + ?{~{$si|eq|0}||<br />} + <a href="$rel_path_to_root/backend/design/sections?rmstyle=${style}&rmfrom=${section[name]}"><img src="$rel_path_to_root/ratatoeskr/cms_style/images/delete.png" alt="<ste:get_translation for='remove' />" /></a> <a href="$rel_path_to_root/backend/design/styles/$style">$style</a> + </ste:foreach> + </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> + | + <input type="submit" name="make_default" value="<ste:get_translation for='make_default' />" /> + | + <input type="submit" name="set_template" value="<ste:get_translation for='set_template' />" /> <ste:instant_select name="set_template_to" array="templates" /> + | + <input type="submit" name="add_style" value="<ste:get_translation for='add_style' />" /> <ste:instant_select name="style_to_add" array="styles" /> + | + <input type="submit" name="set_title" value="<ste:get_translation for='set_title' />" /> <ste:instant_select name="set_title_lang" array="all_langcodes" /> <input type="text" name="set_title_text" /> + </div> + </form> + </div> + </div> + <div class="dualcolumns_stop"></div> +</ste:block> diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 440306d..5a4d1c4 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -145,7 +145,28 @@ $translation = array( "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." + "style_successfully_saved" => "Style successfully saved.", + "new_section" => "New Section", + "section_name" => "Section name", + "section_is_default" => "Is default", + "styles" => "Styles", + "make_default" => "Make default", + "set_template" => "Set template", + "add_style" => "Add style", + "section_already_exists" => "Section already exists.", + "unknown_template" => "Unknown template", + "invalid_section_name" => "Invalid section name. Valid section names are at least 1 character long and only contains letters, numbers, underscores(_) and hyphens(-)", + "section_title" => "Title", + "set_title" => "Set Title", + "section_created_successfully" => "Section created", + "style_removed" => "Style removed", + "remove" => "Remove", + "cannot_delete_default_section" => "Can not delete default section.", + "section_successfully_deleted" => "Section successfully deleted.", + "default_section_changed_successfully" => "Default section changed successfully.", + "successfully_added_style" => "Successfully added style.", + "successfully_set_section_title" => "Successfully set title.", + "successfully_set_template" => "Successfully set template." ); ?> |