From 767b3ebdd83bfd49d82438711f2e240f505a27c5 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 23 Nov 2011 18:17:52 +0100 Subject: Added page section management to backend. --- ratatoeskr/backend/main.php | 199 ++++++++++++++++++++- .../templates/src/systemtemplates/articles.html | 2 +- .../templates/src/systemtemplates/sections.html | 87 +++++++++ ratatoeskr/translations/en.php | 23 ++- 4 files changed, 308 insertions(+), 3 deletions(-) create mode 100644 ratatoeskr/templates/src/systemtemplates/sections.html 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}||, } $tag - $article[section][name] + $article[section][name] 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 @@ + + + + $success + +
$success
+
+
+ $error + +
$error
+
+
+
+
+

+
+

+ :
+ +

+

+ :
+ +

+

+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
 
$section[name] + + ?{~{$ti|eq|0}||
} + ($langcode) $title +
+
?{$section[default]||}$section[template] + + ?{~{$si|eq|0}||
} + <ste:get_translation for='remove' /> $style +
+
+
+   + | + + | +   + | +   + | +    +
+
+
+
+
+
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." ); ?> -- cgit v1.2.3-70-g09d2