From 82d40e32363c4e96996eca7ee44ade879589aa0e Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sun, 26 Apr 2020 16:33:36 +0200 Subject: Expand tabs and remove trailing whitespace --- ratatoeskr/backend.php | 3938 ++++++++++++------------- ratatoeskr/frontend.php | 1294 ++++----- ratatoeskr/js/backend.js | 32 +- ratatoeskr/languages.php | 374 +-- ratatoeskr/main.php | 160 +- ratatoeskr/setup/create_tables.php | 22 +- ratatoeskr/setup/setup.php | 312 +- ratatoeskr/sys/db.php | 150 +- ratatoeskr/sys/init_ste.php | 58 +- ratatoeskr/sys/models.php | 5652 ++++++++++++++++++------------------ ratatoeskr/sys/plugin_api.php | 462 +-- ratatoeskr/sys/pluginpackage.php | 458 +-- ratatoeskr/sys/pwhash.php | 106 +- ratatoeskr/sys/textprocessors.php | 62 +- ratatoeskr/sys/translation.php | 76 +- ratatoeskr/sys/urlprocess.php | 226 +- ratatoeskr/sys/utils.php | 216 +- ratatoeskr/translations/de.php | 556 ++-- ratatoeskr/translations/en.php | 556 ++-- 19 files changed, 7355 insertions(+), 7355 deletions(-) (limited to 'ratatoeskr') diff --git a/ratatoeskr/backend.php b/ratatoeskr/backend.php index 326d82c..a5d5155 100644 --- a/ratatoeskr/backend.php +++ b/ratatoeskr/backend.php @@ -2,7 +2,7 @@ /* * File: ratatoeskr/backend.php * The backend. - * + * * License: * This file is part of Ratatöskr. * Ratatöskr is licensed unter the MIT / X11 License. @@ -20,23 +20,23 @@ $admin_grp = NULL; /* Mass creation of tags. */ function maketags($tagnames, $lang) { - $rv = array(); - foreach($tagnames as $tagname) - { - if(empty($tagname)) - continue; - try - { - $tag = Tag::by_name($tagname); - } - catch(DoesNotExistError $e) - { - $tag = Tag::create($tagname); - $tag->title[$lang] = new Translation($tagname, ""); - } - $rv[] = $tag; - } - return $rv; + $rv = array(); + foreach($tagnames as $tagname) + { + if(empty($tagname)) + continue; + try + { + $tag = Tag::by_name($tagname); + } + catch(DoesNotExistError $e) + { + $tag = Tag::create($tagname); + $tag->title[$lang] = new Translation($tagname, ""); + } + $rv[] = $tag; + } + return $rv; } $backend_subactions = NULL; @@ -46,1957 +46,1957 @@ function build_backend_subactions() global $backend_subactions, $pluginpages_handlers; $backend_subactions = url_action_subactions(array( - "_index" => url_action_alias(array("login")), - "index" => url_action_alias(array("login")), - /* _prelude guarantees that the user is logged in properly, so we do not have to care about that later, and sets some STE vars. */ - "_prelude" => function(&$data, $url_now, &$url_next) - { - global $ratatoeskr_settings, $admin_grp, $ste, $languages; - - if($admin_grp === NULL) - $admin_grp = Group::by_name("admins"); - - $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"])) - { - try - { - $user = User::by_id($_SESSION["ratatoeskr_uid"]); - if(($user->pwhash == $_SESSION["ratatoeskr_pwhash"]) and $user->member_of($admin_grp)) - { - if(empty($user->language)) - { - $user->language = $ratatoeskr_settings["default_language"]; - $user->save(); - } - load_language($user->language); - - if($url_next[0] == "login") - $url_next = array("content", "write"); - $data["user"] = $user; - $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); - - return; /* Authentification successful, continue */ - } - else - unset($_SESSION["ratatoeskr_uid"]); - } - catch(DoesNotExistError $e) - { - unset($_SESSION["ratatoeskr_uid"]); - } - } - load_language(); - - /* If we are here, user is not logged in... */ - $url_next = array("login"); - }, - "login" => url_action_simple(function($data) - { - global $ste, $admin_grp; - if(!empty($_POST["user"])) - { - try - { - $user = User::by_name($_POST["user"]); - if(!PasswordHash::validate($_POST["password"], $user->pwhash)) - throw new Exception(); - if(!$user->member_of($admin_grp)) - throw new Exception(); - - /* Login successful. */ - $_SESSION["ratatoeskr_uid"] = $user->get_id(); - $_SESSION["ratatoeskr_pwhash"] = $user->pwhash; - load_language($user->language); - $data["user"] = $user; - $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); - } - catch(Exception $e) - { - $ste->vars["login_failed"] = True; - } - - if(isset($data["user"])) - throw new Redirect(array("content", "write")); - } - - echo $ste->exectemplate("/systemtemplates/backend_login.html"); - }), - "logout" => url_action_simple(function($data) - { - unset($_SESSION["ratatoeskr_uid"]); - unset($_SESSION["ratatoeskr_pwhash"]); - load_language(); - throw new Redirect(array("login")); - }), - "content" => url_action_subactions(array( - "write" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $textprocessors, $ratatoeskr_settings, $languages, $articleeditor_plugins; - - list($article, $editlang) = array_slice($url_next, 0); - if(!isset($editlang)) - $editlang = $data["user"]->language; - if(isset($article)) - $ste->vars["article_editurl"] = urlencode($article) . "/" . urlencode($editlang); - else - $ste->vars["article_editurl"] = ""; - - $url_next = array(); - - $default_section = Section::by_id($ratatoeskr_settings["default_section"]); - - $ste->vars["section"] = "content"; - $ste->vars["submenu"] = isset($article) ? "articles" : "newarticle"; - - $ste->vars["textprocessors"] = array(); - foreach($textprocessors as $txtproc => $properties) - if($properties[1]) - $ste->vars["textprocessors"][] = $txtproc; - - $ste->vars["sections"] = array(); - foreach(Section::all() as $section) - $ste->vars["sections"][] = $section->name; - $ste->vars["article_section"] = $default_section->name; - - /* Check Form */ - $fail_reasons = array(); - - if(isset($_POST["save_article"])) - { - if(!Article::test_urlname($_POST["urlname"])) - $fail_reasons[] = $translation["invalid_urlname"]; - else - $inputs["urlname"] = $_POST["urlname"]; - if(!Article::test_status(@$_POST["article_status"])) - $fail_reasons[] = $translation["invalid_article_status"]; - else - $inputs["article_status"] = (int) $_POST["article_status"]; - if(!isset($textprocessors[@$_POST["content_txtproc"]])) - $fail_reasons[] = $translation["unknown_txtproc"]; - else - $inputs["content_txtproc"] = $_POST["content_txtproc"]; - if(!isset($textprocessors[@$_POST["excerpt_txtproc"]])) - $fail_reasons[] = $translation["unknown_txtproc"]; - else - $inputs["excerpt_txtproc"] = $_POST["excerpt_txtproc"]; - if(!empty($_POST["date"])) - { - if(($time_tmp = @DateTime::createFromFormat("Y-m-d H:i:s", @$_POST["date"])) === False) - $fail_reasons[] = $translation["invalid_date"]; - else - $inputs["date"] = @$time_tmp->getTimestamp(); - } - else - $inputs["date"] = time(); - $inputs["allow_comments"] = !(empty($_POST["allow_comments"]) or ($_POST["allow_comments"] != "yes")); - - try - { - $inputs["article_section"] = Section::by_name($_POST["section"]); - } - catch(DoesNotExistError $e) - { - $fail_reasons[] = $translation["unknown_section"]; - } - - $inputs["title"] = $_POST["title"]; - $inputs["content"] = $_POST["content"]; - $inputs["excerpt"] = $_POST["excerpt"]; - $inputs["tags"] = array_filter(array_map("trim", explode(",", $_POST["tags"])), function($t) { return !empty($t); }); - if(isset($_POST["saveaslang"])) - $editlang = $_POST["saveaslang"]; - } - else - { - /* Call articleeditor plugins */ - $article = empty($article) ? NULL : Article::by_urlname($article); - foreach($articleeditor_plugins as $plugin) - call_user_func($plugin["fx"], $article, False); - } - - function fill_article(&$article, $inputs, $editlang) - { - $article->urlname = $inputs["urlname"]; - $article->status = $inputs["article_status"]; - $article->timestamp = $inputs["date"]; - $article->title[$editlang] = new Translation($inputs["title"], ""); - $article->text[$editlang] = new Translation($inputs["content"], $inputs["content_txtproc"]); - $article->excerpt[$editlang] = new Translation($inputs["excerpt"], $inputs["excerpt_txtproc"]); - $article->set_tags(maketags($inputs["tags"], $editlang)); - $article->set_section($inputs["article_section"]); - $article->allow_comments = $inputs["allow_comments"]; - } - - if(empty($article)) - { - /* New Article */ - $ste->vars["pagetitle"] = $translation["new_article"]; - if(empty($fail_reasons) and isset($_POST["save_article"])) - { - $article = Article::create($inputs["urlname"]); - fill_article($article, $inputs, $editlang); - - /* Calling articleeditor plugins */ - $call_after_save = array(); - foreach($articleeditor_plugins as $plugin) - { - $result = call_user_func($plugin["fx"], $article, True); - if(is_string($result)) - $fail_reasons[] = $result; - elseif($result !== NULL) - $call_after_save[] = $result; - } - - if(empty($fail_reasons)) - { - try - { - $article->save(); - foreach($call_after_save as $cb) - call_user_func($cb, $article); - $ste->vars["article_editurl"] = urlencode($article->urlname) . "/" . urlencode($editlang); - $ste->vars["success"] = htmlesc($translation["article_save_success"]); - } - catch(AlreadyExistsError $e) - { - $fail_reasons[] = $translation["article_name_already_in_use"]; - } - } - } - } - else - { - try - { - if(!($article instanceof Article)) - $article = Article::by_urlname($article); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - if(empty($fail_reasons) and isset($_POST["save_article"])) - { - fill_article($article, $inputs, $editlang); - - /* Calling articleeditor plugins */ - $call_after_save = array(); - foreach($articleeditor_plugins as $plugin) - { - $result = call_user_func($plugin["fx"], $article, True); - if(is_string($result)) - $fail_reasons[] = $result; - elseif($result !== NULL) - $call_after_save[] = $result; - } - - if(empty($fail_reasons)) - { - try - { - $article->save(); - foreach($call_after_save as $cb) - call_user_func($cb, $article); - $ste->vars["article_editurl"] = urlencode($article->urlname) . "/" . urlencode($editlang); - $ste->vars["success"] = htmlesc($translation["article_save_success"]); - } - catch(AlreadyExistsError $e) - { - $fail_reasons[] = $translation["article_name_already_in_use"]; - } - } - } - - if(!isset($article->title[$editlang])) - { - $langs_available = array(); - foreach($article->title as $lang => $_) - $langs_available[] = $lang; - $editlang = $langs_available[0]; - } - - foreach(array( - "urlname" => "urlname", - "status" => "article_status", - "timestamp" => "date", - "allow_comments" => "allow_comments" - ) as $prop => $k_out) - { - if(!isset($inputs[$k_out])) - $inputs[$k_out] = $article->$prop; - } - if(!isset($inputs["title"])) - $inputs["title"] = $article->title[$editlang]->text; - if(!isset($inputs["content"])) - { - $translation_obj = $article->text[$editlang]; - $inputs["content"] = $translation_obj->text; - $inputs["content_txtproc"] = $translation_obj->texttype; - } - if(!isset($inputs["excerpt"])) - { - $translation_obj = $article->excerpt[$editlang]; - $inputs["excerpt"] = $translation_obj->text; - $inputs["excerpt_txtproc"] = $translation_obj->texttype; - } - if(!isset($inputs["article_section"])) - $inputs["article_section"] = $article->get_section(); - if(!isset($inputs["tags"])) - $inputs["tags"] = array_map(function($tag) use ($editlang) { return $tag->name; }, $article->get_tags()); - $ste->vars["morelangs"] = array(); - $ste->vars["pagetitle"] = $article->title[$editlang]->text; - foreach($article->title as $lang => $_) - { - if($lang != $editlang) - $ste->vars["morelangs"][] = array("url" => urlencode($article->urlname) . "/$lang", "full" => "($lang) " . $languages[$lang]["language"]); - } - } - - if(!isset($inputs["date"])) - $inputs["date"] = time(); - if(!isset($inputs["article_status"])) - $inputs["article_status"] = ARTICLE_STATUS_LIVE; - - /* Push data back to template */ - if(isset($inputs["tags"])) - $ste->vars["tags"] = implode(", ", $inputs["tags"]); - if(isset($inputs["article_section"])) - $ste->vars["article_section"] = $inputs["article_section"]->name; - $ste->vars["editlang"] = $editlang; - foreach(array( - "urlname" => "urlname", - "article_status" => "article_status", - "title" => "title", - "content_txtproc" => "content_txtproc", - "content" => "content", - "excerpt_txtproc" => "excerpt_txtproc", - "excerpt" => "excerpt", - "date" => "date", - "allow_comments" => "allow_comments" - ) as $k_in => $k_out) - { - if(isset($inputs[$k_in])) - $ste->vars[$k_out] = $inputs[$k_in]; - } - - /* Displaying article editor plugins */ - $ste->vars["displayed_plugins"] = array_map(function($x) { return array("label" => $x["label"], "template" => $x["template"]); }, array_filter($articleeditor_plugins, function($x) { return $x["display"]; })); - - if(!empty($fail_reasons)) - $ste->vars["failed"] = $fail_reasons; - - echo $ste->exectemplate("/systemtemplates/content_write.html"); - }, - "tags" => function(&$data, $url_now, &$url_next) - { - global $translation, $languages, $ste, $rel_path_to_root; - - $url_next = array(); - - $ste->vars["section"] = "content"; - $ste->vars["submenu"] = "tags"; - $ste->vars["pagetitle"] = $translation["tags_overview"]; - - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["tag_multiselect"] as $tagid) - { - try - { - $tag = Tag::by_id($tagid); - $tag->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $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"])) - { - if(!Tag::test_name(@$_POST["newtagname"])) - $ste->vars["error"] = $translation["invalid_tag_name"]; - else - $newtag = $_POST["newtagname"]; - } - - if(($newlang !== NULL) and (!isset($languages[$newlang]))) - $newlang = NULL; - if($newtag !== NULL) - { - try - { - $newtag = Tag::create($newtag); - } - catch(AlreadyExistsError $e) - { - $newtag = NULL; - } - } - - $translations = array(); - foreach($_POST as $k => $v) - { - if(preg_match('/tagtrans_(NEW|[a-z]{2})_(.*)/', $k, $matches) == 1) - { - $lang = ($matches[1] == "NEW") ? $newlang : $matches[1]; - $tag = $matches[2]; - if($lang === NULL) - continue; - $translations[$tag][$lang] = $v; - } - } - - foreach($translations as $tag => $langmap) - { - if($tag == "NEW") - { - if($newtag === NULL) - continue; - $tag = $newtag; - } - else - { - try - { - $tag = Tag::by_id($tag); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - foreach($langmap as $l => $text) - { - if(empty($text)) - unset($tag->title[$l]); - else - $tag->title[$l] = new Translation($text, ""); - } - - $tag->save(); - } - - $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; - } - - $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) - { - 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"]; - - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["article_multiselect"] as $article_urlname) - { - try - { - $article = Article::by_urlname($article_urlname); - $article->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $ste->vars["success"] = $translation["articles_deleted"]; - } - - $articles = Article::all(); - - /* Filtering */ - $filterquery = array(); - if(!empty($_GET["filter_urlname"])) - { - $searchfor = strtolower($_GET["filter_urlname"]); - $articles = array_filter($articles, function($a) use ($searchfor) { return strpos(strtolower($a->urlname), $searchfor) !== False; }); - $filterquery[] = "filter_urlname=" . urlencode($_GET["filter_urlname"]); - $ste->vars["filter_urlname"] = $_GET["filter_urlname"]; - } - if(!empty($_GET["filter_tag"])) - { - $searchfor = $_GET["filter_tag"]; - $articles = array_filter($articles, function($a) use ($searchfor) { foreach($a->get_tags() as $t) { if($t->name==$searchfor) return True; } return False; }); - $filterquery[] = "filter_tag=" . urlencode($searchfor); - $ste->vars["filter_tag"] = $searchfor; - } - if(!empty($_GET["filter_section"])) - { - $searchfor = $_GET["filter_section"]; - $articles = array_filter($articles, function($a) use ($searchfor) { return $a->get_section()->name == $searchfor; }); - $filterquery[] = "filter_section=" . urlencode($searchfor); - $ste->vars["filter_section"] = $searchfor; - } - $ste->vars["filterquery"] = implode("&", $filterquery); - - /* Sorting */ - if(isset($_GET["sort_asc"])) - { - switch($_GET["sort_asc"]) - { - case "date": - $ste->vars["sortquery"] = "sort_asc=date"; - $ste->vars["sort_asc_date"] = True; - $ste->vars["sorting"] = array("dir" => "asc", "by" => "date"); - usort($articles, function($a, $b) { return intcmp($a->timestamp, $b->timestamp); }); - break; - case "section": - $ste->vars["sortquery"] = "sort_asc=section"; - $ste->vars["sort_asc_section"] = True; - $ste->vars["sorting"] = array("dir" => "asc", "by" => "section"); - usort($articles, function($a, $b) { return strcmp($a->get_section()->name, $b->get_section()->name); }); - break; - case "urlname": - $ste->vars["sortquery"] = "sort_asc=urlname"; - default: - $ste->vars["sort_asc_urlname"] = True; - $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); - usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); - break; - } - } - elseif(isset($_GET["sort_desc"])) - { - switch($_GET["sort_desc"]) - { - case "date": - $ste->vars["sortquery"] = "sort_desc=date"; - $ste->vars["sort_desc_date"] = True; - $ste->vars["sorting"] = array("dir" => "desc", "by" => "date"); - usort($articles, function($a, $b) { return intcmp($b->timestamp, $a->timestamp); }); - break; - case "section": - $ste->vars["sortquery"] = "sort_desc=section"; - $ste->vars["sort_desc_section"] = True; - $ste->vars["sorting"] = array("dir" => "desc", "by" => "section"); - usort($articles, function($a, $b) { return strcmp($b->get_section()->name, $a->get_section()->name); }); - break; - case "urlname": - $ste->vars["sortquery"] = "sort_desc=urlname"; - $ste->vars["sort_desc_urlname"] = True; - $ste->vars["sorting"] = array("dir" => "desc", "by" => "urlname"); - usort($articles, function($a, $b) { return strcmp($b->urlname, $a->urlname); }); - break; - default: - $ste->vars["sort_asc_urlname"] = True; - $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); - usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); - break; - } - } - else - { - $ste->vars["sort_asc_urlname"] = True; - $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); - usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); - } - - $ste->vars["articles"] = array_map(function($article) { - $avail_langs = array(); - foreach($article->title as $lang => $_) - $avail_langs[] = $lang; - sort($avail_langs); - $a_section = $article->get_section(); - return array( - "urlname" => $article->urlname, - "languages" => $avail_langs, - "date" => $article->timestamp, - "tags" => array_map(function($tag) { return $tag->name; }, $article->get_tags()), - "section" => array("id" => $a_section->get_id(), "name" => $a_section->name) - ); - }, $articles); - - echo $ste->exectemplate("/systemtemplates/articles.html"); - }, - "images" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - list($imgid, $imageaction) = $url_next; - - $url_next = array(); - - $ste->vars["section"] = "content"; - $ste->vars["submenu"] = "images"; - $ste->vars["pagetitle"] = $translation["menu_images"]; - - if(!empty($imgid) and is_numeric($imgid)) - { - try - { - $image = Image::by_id($imgid); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - if(empty($imageaction)) - throw new NotFoundError(); - else - { - if(($imageaction == "markdown") or ($imageaction == "html") or ($imageaction == "ste")) - { - $ste->vars["pagetitle"] = $translation["generate_embed_code"]; - $ste->vars["image_id"] = $image->get_id(); - $ste->vars["markup_variant"] = $imageaction; - if(isset($_POST["img_alt"])) - { - if($imageaction == "markdown") - $ste->vars["embed_code"] = "![" . str_replace("]", "\\]", $_POST["img_alt"]) . "](%root%/images/" . str_replace(")", "\\)", urlencode($image->get_filename())) . ")"; - elseif($imageaction == "html") - $ste->vars["embed_code"] = "get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; - elseif($imageaction == "ste") - $ste->vars["embed_code"] = "get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; - } - - echo $ste->exectemplate("/systemtemplates/image_embed.html"); - } - else - throw new NotFoundError(); - } - return; - } - - /* Upload Form */ - if(isset($_POST["upload"])) - { - try - { - $image = Image::create((!empty($_POST["upload_name"])) ? $_POST["upload_name"] : $_FILES["upload_img"]["name"], $_FILES["upload_img"]["tmp_name"]); - $image->save(); - $ste->vars["success"] = $translation["upload_success"]; - } - catch(IOError $e) - { - $ste->vars["error"] = $translation["upload_failed"]; - } - catch(UnknownFileFormat $e) - { - $ste->vars["error"] = $translation["unknown_file_format"]; - } - } - - /* Mass delete */ - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["image_multiselect"] as $image_id) - { - try - { - $image = Image::by_id($image_id); - $image->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $ste->vars["success"] = $translation["images_deleted"]; - } - - $images = Image::all(); - - $ste->vars["images"] = array_map(function($img) { return array( - "id" => $img->get_id(), - "name" => $img->name, - "file" => $img->get_filename() - ); }, $images); - - echo $ste->exectemplate("/systemtemplates/image_list.html"); - }, - "comments" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - list($comment_id) = $url_next; - - $url_next = array(); - - $ste->vars["section"] = "content"; - $ste->vars["submenu"] = "comments"; - $ste->vars["pagetitle"] = $translation["menu_comments"]; - - /* Single comment? */ - if(!empty($comment_id)) - { - try - { - $comment = Comment::by_id($comment_id); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - if(!$comment->read_by_admin) - { - $comment->read_by_admin = True; - $comment->save(); - } - - if(isset($_POST["action_on_comment"])) - { - switch($_POST["action_on_comment"]) - { - case "delete": - $comment->delete(); - $ste->vars["success"] = $translation["comment_successfully_deleted"]; - goto backend_content_comments_overview; - break; - case "make_visible": - $comment->visible = True; - $comment->save(); - $ste->vars["success"] = $translation["comment_successfully_made_visible"]; - break; - case "make_invisible": - $comment->visible = False; - $comment->save(); - $ste->vars["success"] = $translation["comment_successfully_made_invisible"]; - break; - } - } - - $ste->vars["id"] = $comment->get_id(); - $ste->vars["visible"] = $comment->visible; - $ste->vars["article"] = $comment->get_article()->urlname; - $ste->vars["language"] = $comment->get_language(); - $ste->vars["date"] = $comment->get_timestamp(); - $ste->vars["author"] = "\"{$comment->author_name}\" <{$comment->author_mail}>"; - $ste->vars["comment_text"] = $comment->create_html(); - $ste->vars["comment_raw"] = $comment->text; - - echo $ste->exectemplate("/systemtemplates/single_comment.html"); - return; - } - - backend_content_comments_overview: - - /* Perform an action on all selected comments */ - if(!empty($_POST["action_on_comments"])) - { - switch($_POST["action_on_comments"]) - { - case "delete": - $commentaction = function($c) { $c->delete(); }; - $ste->vars["success"] = $translation["comments_successfully_deleted"]; - break; - case "mark_read": - $commentaction = function($c) { $c->read_by_admin = True; $c->save(); }; - $ste->vars["success"] = $translation["comments_successfully_marked_read"]; - break; - case "mark_unread": - $commentaction = function($c) { $c->read_by_admin = False; $c->save(); }; - $ste->vars["success"] = $translation["comments_successfully_marked_unread"]; - break; - case "make_visible": - $commentaction = function($c) { $c->visible = True; $c->save(); }; - $ste->vars["success"] = $translation["comments_successfully_made_visible"]; - break; - case "make_invisible": - $commentaction = function($c) { $c->visible = False; $c->save(); }; - $ste->vars["success"] = $translation["comments_successfully_made_invisible"]; - break; - default; - $ste->vars["error"] = $translation["unknown_action"]; - break; - } - if(isset($commentaction)) - { - foreach($_POST["comment_multiselect"] as $c_id) - { - try - { - $comment = Comment::by_id($c_id); - $commentaction($comment); - } - catch(DoesNotExistError $e) - { - continue; - } - } - } - } - - $comments = Comment::all(); - - /* Filtering */ - $filterquery = array(); - if(!empty($_GET["filter_article"])) - { - $searchfor = strtolower($_GET["filter_article"]); - $comments = array_filter($comments, function($c) use ($searchfor) { return strpos(strtolower($c->get_article()->urlname), $searchfor) !== False; }); - $filterquery[] = "filter_article=" . urlencode($_GET["filter_article"]); - $ste->vars["filter_article"] = $_GET["filter_article"]; - } - $ste->vars["filterquery"] = implode("&", $filterquery); - - /* Sorting */ - if(isset($_GET["sort_asc"])) - { - $sort_dir = 1; - $sort_by = $_GET["sort_asc"]; - } - elseif(isset($_GET["sort_desc"])) - { - $sort_dir = -1; - $sort_by = $_GET["sort_desc"]; - } - else - { - $sort_dir = 1; - $sort_by = "was_read"; - } - - switch($sort_by) - { - case "language": - usort($comments, function($a, $b) use ($sort_dir) { return strcmp($a->get_language(), $b->get_language()) * $sort_dir; }); - break; - case "date": - usort($comments, function($a, $b) use ($sort_dir) { return intcmp($a->get_timestamp(), $b->get_timestamp()) * $sort_dir; }); - break; - case "was_read": - default: - usort($comments, function($a, $b) use ($sort_dir) { return intcmp((int) $a->read_by_admin, (int) $b->read_by_admin) * $sort_dir; }); - $sort_by = "was_read"; - break; - } - $ste->vars["sortquery"] = "sort_" . ($sort_dir == 1 ? "asc" : "desc") . "=$sort_by"; - $ste->vars["sorting"] = array("dir" => ($sort_dir == 1 ? "asc" : "desc"), "by" => $sort_by); - $ste->vars["sort_" . ($sort_dir == 1 ? "asc" : "desc") . "_$sort_by"] = True; - - $ste->vars["comments"] = array_map(function($c) { return array( - "id" => $c->get_id(), - "visible" => $c->visible, - "read_by_admin" => $c->read_by_admin, - "article" => $c->get_article()->urlname, - "excerpt" => substr(str_replace(array("\r\n", "\n", "\r"), " ", $c->text), 0, 50), - "language" => $c->get_language(), - "date" => $c->get_timestamp(), - "author" => "\"{$c->author_name}\" <{$c->author_mail}>" - ); }, $comments); - - echo $ste->exectemplate("/systemtemplates/comments_list.html"); - } - )), - "design" => url_action_subactions(array( - "templates" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - list($template) = $url_next; - - $url_next = array(); - - $ste->vars["section"] = "design"; - $ste->vars["submenu"] = "templates"; - $ste->vars["pagetitle"] = $translation["menu_templates"]; - - if(isset($template)) - { - if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $template) == 0) /* Prevent a possible LFI attack. */ - throw new NotFoundError(); - if(!is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template")) - throw new NotFoundError(); - $ste->vars["template_name"] = $template; - $ste->vars["template_code"] = file_get_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template"); - } - - /* Was there a delete request? */ - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["templates_multiselect"] as $tplname) - { - if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $tplname) == 0) /* Prevent a possible LFI attack. */ - continue; - if(is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname")) - @unlink(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname"); - } - $ste->vars["success"] = $translation["templates_successfully_deleted"]; - } - - /* A write request? */ - if(isset($_POST["save_template"])) - { - if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["template_name"]) == 1) - { - $ste->vars["template_name"] = $_POST["template_name"]; - $ste->vars["template_code"] = $_POST["template_code"]; - - try - { - \ste\transcompile(\ste\parse(\ste\precompile($_POST["template_code"]), $_POST["template_name"])); - file_put_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/" . $_POST["template_name"], $_POST["template_code"]); - $ste->vars["success"] = $translation["template_successfully_saved"]; - } - catch(\ste\ParseCompileError $e) - { - $e->rewrite($_POST["template_code"]); - $ste->vars["error"] = $translation["could_not_compile_template"] . $e->getMessage(); - } - } - else - $ste->vars["error"] = $translation["invalid_template_name"]; - } - - /* 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"]); - - echo $ste->exectemplate("/systemtemplates/templates.html"); - }, - "styles" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - list($style) = $url_next; - - $url_next = array(); - - $ste->vars["section"] = "design"; - $ste->vars["submenu"] = "styles"; - $ste->vars["pagetitle"] = $translation["menu_styles"]; - - if(isset($style)) - { - try - { - $style = Style::by_name($style); - $ste->vars["style_name"] = $style->name; - $ste->vars["style_code"] = $style->code; - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - } - - /* Was there a delete request? */ - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["styles_multiselect"] as $stylename) - { - try - { - $style = Style::by_name($stylename); - $style->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - $ste->vars["success"] = $translation["styles_successfully_deleted"]; - } - - /* A write request? */ - if(isset($_POST["save_style"])) - { - if(Style::test_name($_POST["style_name"])) - { - $ste->vars["style_name"] = $_POST["style_name"]; - $ste->vars["style_code"] = $_POST["style_code"]; - - try - { - $style = Style::by_name($_POST["style_name"]); - } - catch(DoesNotExistError $e) - { - $style = Style::create($_POST["style_name"]); - } - - $style->code = $_POST["style_code"]; - $style->save(); - - $ste->vars["success"] = $translation["style_successfully_saved"]; - } - else - $ste->vars["error"] = $translation["invalid_style_name"]; - } - - /* Get all styles */ - $ste->vars["styles"] = array_map(function($s) { return $s->name; }, Style::all()); - 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(!Section::test_name($_POST["section_name"])) - $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 = Style::by_name($_GET["rmstyle"]); - $section->remove_style($style); - $section->save(); - $ste->vars["success"] = $translation["style_removed"]; - } - catch(DoesNotExistError $e) - { - } - } - - /* 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->set_section($default_section); - $article->save(); - } - $section->delete(); - $ste->vars["success"] = $translation["section_successfully_deleted"]; - } - } - catch(DoesNotExistError $e) - { - } - } - - /* 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) - { - } - } - - /* 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) - { - } - } - - /* 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"]); - $section->add_style($style); - $ste->vars["success"] = $translation["successfully_added_style"]; - } - catch(DoesNotExistError $e) - { - } - } - - /* 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) - { - } - } - } - - /* 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->get_styles()), - "default" => ($section->get_id() == $ratatoeskr_settings["default_section"]) - ); - }, $sections); - - echo $ste->exectemplate("/systemtemplates/sections.html"); - } - )), - "admin" => url_action_subactions(array( - "settings" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; - - $url_next = array(); - - $ste->vars["section"] = "admin"; - $ste->vars["submenu"] = "settings"; - $ste->vars["pagetitle"] = $translation["menu_settings"]; - - $ste->vars["textprocessors"] = array(); - foreach($textprocessors as $txtproc => $properties) - if($properties[1]) - $ste->vars["textprocessors"][] = $txtproc; - - /* Toggle debugmode value? */ - if(isset($_POST["toggle_debugmode"])) - { - if(isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]) - { - $ratatoeskr_settings["debugmode"] = False; - $ste->vars["success"] = $translation["debugmode_now_disabled"]; - } - else - { - $ratatoeskr_settings["debugmode"] = True; - $ste->vars["success"] = $translation["debugmode_now_enabled"]; - } - } - - /* Save comment settings? */ - if(isset($_POST["save_comment_settings"])) - { - if(!in_array(@$_POST["comment_textprocessor"], $ste->vars["textprocessors"])) - $ste->vars["error"] = $translation["unknown_txtproc"]; - else - { - $ratatoeskr_settings["comment_textprocessor"] = $_POST["comment_textprocessor"]; - $ratatoeskr_settings["comment_visible_default"] = (isset($_POST["comment_auto_visible"]) and ($_POST["comment_auto_visible"] == "yes")); - $ste->vars["success"] = $translation["comment_settings_successfully_saved"]; - } - } - - /* Delete language? */ - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes") and isset($_POST["language_select"])) - { - if($ratatoeskr_settings["default_language"] == $_POST["language_select"]) - $ste->vars["error"] = $translation["cannot_delete_default_language"]; - else - { - $ratatoeskr_settings["languages"] = array_filter($ratatoeskr_settings["languages"], function($l) { return $l != $_POST["language_select"]; }); - $ste->vars["success"] = $translation["language_successfully_deleted"]; - } - } - - /* Set default language */ - if(isset($_POST["make_default"]) and isset($_POST["language_select"])) - { - if(in_array($_POST["language_select"], $ratatoeskr_settings["languages"])) - { - $ratatoeskr_settings["default_language"] = $_POST["language_select"]; - $ste->vars["success"] = $translation["successfully_set_default_language"]; - } - } - - /* Add a language */ - if(isset($_POST["add_language"])) - { - if(!isset($languages[$_POST["language_to_add"]])) - $ste->vars["error"] = $translation["language_unknown"]; - else - { - if(!in_array($_POST["language_to_add"], $ratatoeskr_settings["languages"])) - { - $ls = $ratatoeskr_settings["languages"]; - $ls[] = $_POST["language_to_add"]; - $ratatoeskr_settings["languages"] = $ls; - } - $ste->vars["success"] = $translation["language_successfully_added"]; - } - } - - $ste->vars["debugmode_enabled"] = (isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]); - $ste->vars["comment_auto_visible"] = $ratatoeskr_settings["comment_visible_default"]; - $ste->vars["comment_textprocessor"] = $ratatoeskr_settings["comment_textprocessor"]; - $ste->vars["used_langs"] = array_map(function ($l) use ($ratatoeskr_settings, $languages) { return array( - "code" => $l, - "name" => $languages[$l]["language"], - "default" => ($l == $ratatoeskr_settings["default_language"]) - );}, $ratatoeskr_settings["languages"]); - - echo $ste->exectemplate("/systemtemplates/settings.html"); - }, - "users" => url_action_subactions(array( - "_index" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; - - $url_next = array(); - - $ste->vars["section"] = "admin"; - $ste->vars["submenu"] = "users"; - $ste->vars["pagetitle"] = $translation["menu_users_groups"]; - - /* Add a new group? */ - if(isset($_POST["new_group"])) - { - if(empty($_POST["group_name"])) - $ste->vars["error"] = $translation["empty_group_name"]; - else - { - try - { - Group::by_name($_POST["group_name"]); - $ste->vars["error"] = $translation["group_already_exists"]; - } - catch(DoesNotExistError $e) - { - $group = Group::create($_POST["group_name"]); - $ste->vars["success"] = $translation["successfully_created_group"]; - } - } - } - - /* Add a new user? */ - if(isset($_POST["new_user"])) - { - if(empty($_POST["username"])) - $ste->vars["error"] = $translation["empty_username"]; - else - { - try - { - User::by_name($_POST["username"]); - $ste->vars["error"] = $translation["user_already_exists"]; - } - catch(DoesNotExistError $e) - { - $group = User::create($_POST["username"], PasswordHash::create($_POST["initial_password"])); - $ste->vars["success"] = $translation["successfully_created_user"]; - } - } - } - - /* Delete groups? */ - if(isset($_POST["delete_groups"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["groups_multiselect"]))) - { - $deleted = 0; - foreach($_POST["groups_multiselect"] as $gid) - { - try - { - $group = Group::by_id($gid); - if($group->name == "admins") - { - $ste->vars["error"] = $translation["cannot_delete_admin_group"]; - } - else - { - $group->delete(); - ++$deleted; - } - } - catch(DoesNotExistError $e) - { - continue; - } - } - if($deleted > 0) - $ste->vars["success"] = $translation["successfully_deleted_groups"]; - } - - /* Delete users? */ - if(isset($_POST["delete_users"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["users_multiselect"]))) - { - $deleted = 0; - foreach($_POST["users_multiselect"] as $uid) - { - if($uid == $data["user"]->get_id()) - $ste->vars["error"] = $translation["cannot_delete_yourself"]; - else - { - try - { - $user = User::by_id($uid); - $user->delete(); - ++$deleted; - } - catch(DoesNotExistError $e) - { - continue; - } - } - } - if($deleted > 0) - $ste->vars["success"] = $translation["successfully_deleted_users"]; - } - - /* Get all groups */ - $ste->vars["groups"] = array_map(function($g) { return array( - "id" => $g->get_id(), - "name" => $g->name - ); }, Group::all()); - - /* Get all users */ - $ste->vars["users"] = array_map(function($u) { return array( - "id" => $u->get_id(), - "name" => $u->username, - "memberof" => array_map(function($g) { return $g->name; }, $u->get_groups()), - "fullname" => $u->fullname, - "mail" => $u->mail - ); }, User::all()); - - echo $ste->exectemplate("/systemtemplates/users.html"); - }, - "u" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root, $admin_grp; - - try - { - $user = User::by_id($url_next[0]); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - $url_next = array(); - - $ste->vars["section"] = "admin"; - $ste->vars["submenu"] = "users"; - $ste->vars["pagetitle"] = $user->username; - - /* Modify data? */ - if(isset($_POST["change_data"])) - { - $user->fullname = $_POST["fullname"]; - $user->mail = $_POST["mail"]; - $user->language = $_POST["lang"]; - - $current_groups = array_map(function($g) { return $g->get_id(); }, $user->get_groups()); - $new_groups = empty($_POST[groups_multiselect]) ? array() : $_POST["groups_multiselect"]; - $groups_exclude = array_diff($current_groups, $new_groups); - $groups_include = array_diff($new_groups, $current_groups); - - foreach($groups_exclude as $gid) - { - try - { - $g = Group::by_id($gid); - $g->exclude_user($user); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - foreach($groups_include as $gid) - { - try - { - $g = Group::by_id($gid); - $g->include_user($user); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $user->save(); - - $ste->vars["success"] = $translation["successfully_modified_user"]; - } - - /* New Password? */ - if(isset($_POST["new_password"])) - { - $pwhash = PasswordHash::create($_POST["password"]); - $user->pwhash = $pwhash; - if($user->get_id() == $data["user"]->get_id()) - $_SESSION["ratatoeskr_pwhash"] = $pwhash; - $user->save(); - - $ste->vars["success"] = $translation["successfully_set_new_password"]; - } - - /* Put data to STE */ - $ste->vars["u"] = array( - "id" => $user->get_id(), - "name" => $user->username, - "fullname" => $user->fullname, - "mail" => $user->mail, - "lang" => $user->language - ); - $ste->vars["groups"] = array_map(function($g) use ($user) { return array( - "id" => $g->get_id(), - "name" => $g->name, - "member" => $user->member_of($g) - ); }, Group::all()); - - echo $ste->exectemplate("/systemtemplates/user.html"); - } - )), - "repos" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - $url_next = array(); - - $ste->vars["section"] = "admin"; - $ste->vars["submenu"] = "repos"; - $ste->vars["pagetitle"] = $translation["menu_plugin_repos"]; - - /* Add a repo? */ - if(isset($_POST["add_repo"])) - { - try - { - $repo = Repository::create($_POST["repo_baseurl"]); - $ste->vars["success"] = $translation["successfully_added_repo"]; - } - catch(RepositoryUnreachableOrInvalid $e) - { - $ste->vars["error"] = $translation["repository_unreachable_or_invalid"]; - } - } - - /* Delete repos? */ - if(isset($_POST["delete_repos"]) and ($_POST["really_delete"] == "yes")) - { - foreach($_POST["repos_multiselect"] as $repo_id) - { - try - { - $repo = Repository::by_id($repo_id); - $repo->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - $ste->vars["success"] = $translation["repos_deleted"]; - } - - /* Force refresh? */ - if(isset($_POST["force_repo_refresh"])) - { - $failed = array(); - foreach($_POST["repos_multiselect"] as $repo_id) - { - try - { - $repo = Repository::by_id($repo_id); - $repo->refresh(True); - } - catch(DoesNotExistError $e) - { - continue; - } - catch(RepositoryUnreachableOrInvalid $e) - { - $failed[] = $repo->get_name(); - } - } - $ste->vars["success"] = $translation["successfully_refreshed_repos"]; - if(!empty($failed)) - $ste->vars["error"] = str_replace("[[REPOS]]", implode(", ", $failed), $translation["repo_refresh_failed_on"]); - } - - /* Fill data */ - $all_repos = Repository::all(); - $ste->vars["repos"] = array_map( - function($r) - { - try - { - $r->refresh(); - } - catch(RepositoryUnreachableOrInvalid $e){} - return array( - "id" => $r->get_id(), - "name" => $r->get_name(), - "description" => $r->get_description(), - "baseurl" => $r->get_baseurl() - ); - }, $all_repos); - - echo $ste->exectemplate("/systemtemplates/repos.html"); - } - )), - "plugin" => url_action_subactions(array( - "list" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root, $plugin_objs, $api_compat; - - $url_next = array(); - - $ste->vars["section"] = "plugins"; - $ste->vars["submenu"] = "pluginlist"; - $ste->vars["pagetitle"] = $translation["menu_pluginlist"]; - - /* Delete plugins? */ - if(isset($_POST["delete"]) and (($_POST["really_delete"] == "yes") or ($_POST["really_delete"] == "force")) and (!empty($_POST["plugins_multiselect"]))) - { - foreach($_POST["plugins_multiselect"] as $pid) - { - try - { - $plugin = Plugin::by_id($pid); - if($_POST["really_delete"] != "force") - { - if(!isset($plugin_objs[$pid])) - { - eval($plugin->code); - $plugin_objs[$pid] = new $plugin->classname($pid); - } - $plugin_objs[$pid]->uninstall(); - } - $plugin->delete(); - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $ste->vars["success"] = $translation["successfully_deleted_plugins"]; - } - - /* Activate or deactivate plugins? */ - if((isset($_POST["activate"]) or isset($_POST["deactivate"])) and (!empty($_POST["plugins_multiselect"]))) - { - $api_incompat = array(); - $newstatus = isset($_POST["activate"]); - foreach($_POST["plugins_multiselect"] as $pid) - { - try - { - $plugin = Plugin::by_id($pid); - if(!$plugin->installed) - continue; - if($newstatus and (!in_array($plugin->api, $api_compat))) - { - $api_incompat[] = $plugin->name . ("(ID: " . $plugin->get_id() . ")"); - continue; - } - $plugin->active = $newstatus; - $plugin->save(); - if($newstatus and (!isset($plugin_objs[$pid]))) - { - eval($plugin->code); - $plugin_objs[$pid] = new $plugin->classname($pid); - $plugin_objs[$pid]->init(); - } - } - catch(DoesNotExistError $e) - { - continue; - } - } - - $ste->vars["success"] = $translation[$newstatus ? "plugins_activated" : "plugins_deactivated"]; - - if(!empty($api_incompat)) - $ste->vars["error"] = htmlesc(str_replace("[[PLUGINS]]", implode(", ", $api_incompat), $translation["could_not_activate_plugin_api_incompat"])); - } - - $stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); - - /* Update plugins? */ - if(isset($_POST["update"]) and (!empty($_POST["plugins_multiselect"]))) - { - $updated = array(); - foreach($_POST["plugins_multiselect"] as $pid) - { - try - { - $plugin = Plugin::by_id($pid); - if(!empty($plugin->updatepath)) - { - $update_info = @unserialize(@file_get_contents($plugin->updatepath, False, $stream_ctx)); - if(is_array($update_info) and (($update_info["current-version"]+0) > ($plugin->versioncount+0))) - { - $pkg = PluginPackage::load(@file_get_contents($update_info["dl-path"], False, $stream_ctx)); - $plugin->fill_from_pluginpackage($pkg); - $plugin->update = True; - $plugin->save(); - $updated[] = $plugin->name; - } - } - } - catch(DoesNotExistError $e) - { - continue; - } - catch(InvalidPackage $e) - { - continue; - } - } - - if(empty($updated)) - $ste->vars["success"] = $translation["nothing_to_update"]; - else - $ste->vars["success"] = str_replace("[[PLUGINS]]", implode(", ", $updated), $translation["successfully_updated_plugins"]); - } - - /* Load plugin data */ - $all_plugins = Plugin::all(); - $ste->vars["plugins"] = array(); - $api_incompat = array(); - foreach($all_plugins as $p) - { - if(!$p->installed) - continue; - - if(!in_array($p->api, $api_compat)) - $api_incompat[] = $p->name . ("(ID: " . $p->get_id() . ")"); - - $ste->vars["plugins"][] = array( - "id" => $p->get_id(), - "name" => $p->name, - "versiontext" => $p->versiontext, - "active" => $p->active, - "description" => $p->short_description, - "web" => $p->web, - "author" => $p->author, - "help" => !empty($p->help) - ); - } - - if(!empty($api_incompat)) - $ste->vars["notice"] = htmlesc(str_replace("[[PLUGINS]]", implode(", ", $api_incompat), $translation["plugins_incompat"])); - - echo $ste->exectemplate("/systemtemplates/pluginlist.html"); - }, - "help" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - try - { - $plugin = Plugin::by_id($url_next[0]); - if(empty($plugin->help)) - throw new NotFoundError(); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - $url_next = array(); - - $ste->vars["section"] = "plugins"; - $ste->vars["submenu"] = ""; - $ste->vars["pagetitle"] = $plugin->name; - $ste->vars["help"] = $plugin->help; - - echo $ste->exectemplate("/systemtemplates/pluginhelp.html"); - }, - "install" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root, $api_compat; - - $url_next = array(); - - $ste->vars["section"] = "plugins"; - $ste->vars["submenu"] = "installplugins"; - $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; - - $all_repos = Repository::all(); - foreach($all_repos as $repo) - { - try - { - $repo->refresh(); - } - catch(RepositoryUnreachableOrInvalid $e) - { - continue; - } - } - - if(isset($_POST["installpackage"])) - { - if(is_uploaded_file($_FILES["pluginpackage"]["tmp_name"])) - { - try - { - $package = PluginPackage::load(file_get_contents($_FILES["pluginpackage"]["tmp_name"])); - unlink($_FILES["pluginpackage"]["tmp_name"]); - if(in_array($package->api, $api_compat)) - { - $plugin = Plugin::create(); - $plugin->fill_from_pluginpackage($package); - $plugin->installed = False; - $plugin->active = False; - $plugin->save(); - $url_next = array("confirminstall", (string) $plugin->get_id()); - return; - } - else - $ste->vars["error"] = str_replace("[[API]]", $package->api, $translation["incompatible_plugin"]); - } - catch(InvalidPackage $e) - { - $ste->vars["error"] = $translation["invalid_package"]; - unlink($_FILES["pluginpackage"]["tmp_name"]); - } - } - else - $ste->vars["error"] = $translation["upload_failed"]; - } - - if(isset($_POST["search_in_repos"])) - { - $ste->vars["searchresults"] = array(); - $repos_to_scan = ($_POST["searchin"] == "*") ? $all_repos : Repository::by_id($_POST["searchin"]); - $searchfor = strtolower($_POST["searchfor"]); - foreach($repos_to_scan as $repo) - { - foreach($repo->packages as $pkg) - { - if(empty($searchfor) or (strpos(strtolower($pkg[0]), $searchfor) !== False) or (strpos(strtolower($pkg[2]), $searchfor) !== False)) - $ste->vars["searchresults"][] = array( - "name" => $pkg[0], - "description" => $pkg[2], - "reponame" => $repo->get_name(), - "repoid" => $repo->get_id() - ); - } - } - } - - $ste->vars["repos"] = array_map(function($r) { return array( - "id" => $r->get_id(), - "name" => $r->get_name() - ); }, $all_repos); - - echo $ste->exectemplate("/systemtemplates/plugininstall.html"); - }, - "repoinstall" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $rel_path_to_root; - - $stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); - - try - { - $repo = Repository::by_id($_GET["repo"]); - $pkg = $repo->download_package($_GET["pkg"]); - $plugin = Plugin::create(); - $plugin->fill_from_pluginpackage($pkg); - $plugin->installed = False; - $plugin->active = False; - $plugin->save(); - $url_next = array("confirminstall", (string) $plugin->get_id()); - } - catch(DoesNotExistError $e) - { - $ste->vars["error"] = $translation["package_or_repo_not_found"]; - $url_next = array("install"); - } - catch(InvalidPackage $e) - { - $ste->vars["error"] = $translation["invalid_package"]; - $url_next = array("install"); - } - }, - "confirminstall" => function(&$data, $url_now, &$url_next) - { - global $ste, $translation, $languages, $rel_path_to_root; - - list($plugin_id) = $url_next; - $url_next = array(); - - $ste->vars["section"] = "plugins"; - $ste->vars["submenu"] = "installplugins"; - $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; - - try - { - $plugin = Plugin::by_id($plugin_id); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - - if($plugin->installed) - throw new NotFoundError(); - - $ste->vars["plugin_id"] = $plugin->get_id(); - $ste->vars["name"] = $plugin->name; - $ste->vars["description"] = $plugin->short_description; - $ste->vars["code"] = $plugin->code; - $ste->vars["license"] = $plugin->license; - - if(isset($_POST["yes"])) - { - $plugin->installed = True; - $plugin->save(); - eval($plugin->code); - $plugin_instance = new $plugin->classname($plugin->get_id()); - $plugin_instance->install(); - $ste->vars["success"] = $translation["plugin_installed_successfully"]; - $url_next = array("list"); - return; - } - - if(isset($_POST["no"])) - { - $plugin->delete(); - $url_next = array("install"); - return; - } - - echo $ste->exectemplate("/systemtemplates/confirminstall.html"); - } - )), - "pluginpages" => url_action_subactions($pluginpages_handlers) + "_index" => url_action_alias(array("login")), + "index" => url_action_alias(array("login")), + /* _prelude guarantees that the user is logged in properly, so we do not have to care about that later, and sets some STE vars. */ + "_prelude" => function(&$data, $url_now, &$url_next) + { + global $ratatoeskr_settings, $admin_grp, $ste, $languages; + + if($admin_grp === NULL) + $admin_grp = Group::by_name("admins"); + + $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"])) + { + try + { + $user = User::by_id($_SESSION["ratatoeskr_uid"]); + if(($user->pwhash == $_SESSION["ratatoeskr_pwhash"]) and $user->member_of($admin_grp)) + { + if(empty($user->language)) + { + $user->language = $ratatoeskr_settings["default_language"]; + $user->save(); + } + load_language($user->language); + + if($url_next[0] == "login") + $url_next = array("content", "write"); + $data["user"] = $user; + $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); + + return; /* Authentification successful, continue */ + } + else + unset($_SESSION["ratatoeskr_uid"]); + } + catch(DoesNotExistError $e) + { + unset($_SESSION["ratatoeskr_uid"]); + } + } + load_language(); + + /* If we are here, user is not logged in... */ + $url_next = array("login"); + }, + "login" => url_action_simple(function($data) + { + global $ste, $admin_grp; + if(!empty($_POST["user"])) + { + try + { + $user = User::by_name($_POST["user"]); + if(!PasswordHash::validate($_POST["password"], $user->pwhash)) + throw new Exception(); + if(!$user->member_of($admin_grp)) + throw new Exception(); + + /* Login successful. */ + $_SESSION["ratatoeskr_uid"] = $user->get_id(); + $_SESSION["ratatoeskr_pwhash"] = $user->pwhash; + load_language($user->language); + $data["user"] = $user; + $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); + } + catch(Exception $e) + { + $ste->vars["login_failed"] = True; + } + + if(isset($data["user"])) + throw new Redirect(array("content", "write")); + } + + echo $ste->exectemplate("/systemtemplates/backend_login.html"); + }), + "logout" => url_action_simple(function($data) + { + unset($_SESSION["ratatoeskr_uid"]); + unset($_SESSION["ratatoeskr_pwhash"]); + load_language(); + throw new Redirect(array("login")); + }), + "content" => url_action_subactions(array( + "write" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $textprocessors, $ratatoeskr_settings, $languages, $articleeditor_plugins; + + list($article, $editlang) = array_slice($url_next, 0); + if(!isset($editlang)) + $editlang = $data["user"]->language; + if(isset($article)) + $ste->vars["article_editurl"] = urlencode($article) . "/" . urlencode($editlang); + else + $ste->vars["article_editurl"] = ""; + + $url_next = array(); + + $default_section = Section::by_id($ratatoeskr_settings["default_section"]); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = isset($article) ? "articles" : "newarticle"; + + $ste->vars["textprocessors"] = array(); + foreach($textprocessors as $txtproc => $properties) + if($properties[1]) + $ste->vars["textprocessors"][] = $txtproc; + + $ste->vars["sections"] = array(); + foreach(Section::all() as $section) + $ste->vars["sections"][] = $section->name; + $ste->vars["article_section"] = $default_section->name; + + /* Check Form */ + $fail_reasons = array(); + + if(isset($_POST["save_article"])) + { + if(!Article::test_urlname($_POST["urlname"])) + $fail_reasons[] = $translation["invalid_urlname"]; + else + $inputs["urlname"] = $_POST["urlname"]; + if(!Article::test_status(@$_POST["article_status"])) + $fail_reasons[] = $translation["invalid_article_status"]; + else + $inputs["article_status"] = (int) $_POST["article_status"]; + if(!isset($textprocessors[@$_POST["content_txtproc"]])) + $fail_reasons[] = $translation["unknown_txtproc"]; + else + $inputs["content_txtproc"] = $_POST["content_txtproc"]; + if(!isset($textprocessors[@$_POST["excerpt_txtproc"]])) + $fail_reasons[] = $translation["unknown_txtproc"]; + else + $inputs["excerpt_txtproc"] = $_POST["excerpt_txtproc"]; + if(!empty($_POST["date"])) + { + if(($time_tmp = @DateTime::createFromFormat("Y-m-d H:i:s", @$_POST["date"])) === False) + $fail_reasons[] = $translation["invalid_date"]; + else + $inputs["date"] = @$time_tmp->getTimestamp(); + } + else + $inputs["date"] = time(); + $inputs["allow_comments"] = !(empty($_POST["allow_comments"]) or ($_POST["allow_comments"] != "yes")); + + try + { + $inputs["article_section"] = Section::by_name($_POST["section"]); + } + catch(DoesNotExistError $e) + { + $fail_reasons[] = $translation["unknown_section"]; + } + + $inputs["title"] = $_POST["title"]; + $inputs["content"] = $_POST["content"]; + $inputs["excerpt"] = $_POST["excerpt"]; + $inputs["tags"] = array_filter(array_map("trim", explode(",", $_POST["tags"])), function($t) { return !empty($t); }); + if(isset($_POST["saveaslang"])) + $editlang = $_POST["saveaslang"]; + } + else + { + /* Call articleeditor plugins */ + $article = empty($article) ? NULL : Article::by_urlname($article); + foreach($articleeditor_plugins as $plugin) + call_user_func($plugin["fx"], $article, False); + } + + function fill_article(&$article, $inputs, $editlang) + { + $article->urlname = $inputs["urlname"]; + $article->status = $inputs["article_status"]; + $article->timestamp = $inputs["date"]; + $article->title[$editlang] = new Translation($inputs["title"], ""); + $article->text[$editlang] = new Translation($inputs["content"], $inputs["content_txtproc"]); + $article->excerpt[$editlang] = new Translation($inputs["excerpt"], $inputs["excerpt_txtproc"]); + $article->set_tags(maketags($inputs["tags"], $editlang)); + $article->set_section($inputs["article_section"]); + $article->allow_comments = $inputs["allow_comments"]; + } + + if(empty($article)) + { + /* New Article */ + $ste->vars["pagetitle"] = $translation["new_article"]; + if(empty($fail_reasons) and isset($_POST["save_article"])) + { + $article = Article::create($inputs["urlname"]); + fill_article($article, $inputs, $editlang); + + /* Calling articleeditor plugins */ + $call_after_save = array(); + foreach($articleeditor_plugins as $plugin) + { + $result = call_user_func($plugin["fx"], $article, True); + if(is_string($result)) + $fail_reasons[] = $result; + elseif($result !== NULL) + $call_after_save[] = $result; + } + + if(empty($fail_reasons)) + { + try + { + $article->save(); + foreach($call_after_save as $cb) + call_user_func($cb, $article); + $ste->vars["article_editurl"] = urlencode($article->urlname) . "/" . urlencode($editlang); + $ste->vars["success"] = htmlesc($translation["article_save_success"]); + } + catch(AlreadyExistsError $e) + { + $fail_reasons[] = $translation["article_name_already_in_use"]; + } + } + } + } + else + { + try + { + if(!($article instanceof Article)) + $article = Article::by_urlname($article); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if(empty($fail_reasons) and isset($_POST["save_article"])) + { + fill_article($article, $inputs, $editlang); + + /* Calling articleeditor plugins */ + $call_after_save = array(); + foreach($articleeditor_plugins as $plugin) + { + $result = call_user_func($plugin["fx"], $article, True); + if(is_string($result)) + $fail_reasons[] = $result; + elseif($result !== NULL) + $call_after_save[] = $result; + } + + if(empty($fail_reasons)) + { + try + { + $article->save(); + foreach($call_after_save as $cb) + call_user_func($cb, $article); + $ste->vars["article_editurl"] = urlencode($article->urlname) . "/" . urlencode($editlang); + $ste->vars["success"] = htmlesc($translation["article_save_success"]); + } + catch(AlreadyExistsError $e) + { + $fail_reasons[] = $translation["article_name_already_in_use"]; + } + } + } + + if(!isset($article->title[$editlang])) + { + $langs_available = array(); + foreach($article->title as $lang => $_) + $langs_available[] = $lang; + $editlang = $langs_available[0]; + } + + foreach(array( + "urlname" => "urlname", + "status" => "article_status", + "timestamp" => "date", + "allow_comments" => "allow_comments" + ) as $prop => $k_out) + { + if(!isset($inputs[$k_out])) + $inputs[$k_out] = $article->$prop; + } + if(!isset($inputs["title"])) + $inputs["title"] = $article->title[$editlang]->text; + if(!isset($inputs["content"])) + { + $translation_obj = $article->text[$editlang]; + $inputs["content"] = $translation_obj->text; + $inputs["content_txtproc"] = $translation_obj->texttype; + } + if(!isset($inputs["excerpt"])) + { + $translation_obj = $article->excerpt[$editlang]; + $inputs["excerpt"] = $translation_obj->text; + $inputs["excerpt_txtproc"] = $translation_obj->texttype; + } + if(!isset($inputs["article_section"])) + $inputs["article_section"] = $article->get_section(); + if(!isset($inputs["tags"])) + $inputs["tags"] = array_map(function($tag) use ($editlang) { return $tag->name; }, $article->get_tags()); + $ste->vars["morelangs"] = array(); + $ste->vars["pagetitle"] = $article->title[$editlang]->text; + foreach($article->title as $lang => $_) + { + if($lang != $editlang) + $ste->vars["morelangs"][] = array("url" => urlencode($article->urlname) . "/$lang", "full" => "($lang) " . $languages[$lang]["language"]); + } + } + + if(!isset($inputs["date"])) + $inputs["date"] = time(); + if(!isset($inputs["article_status"])) + $inputs["article_status"] = ARTICLE_STATUS_LIVE; + + /* Push data back to template */ + if(isset($inputs["tags"])) + $ste->vars["tags"] = implode(", ", $inputs["tags"]); + if(isset($inputs["article_section"])) + $ste->vars["article_section"] = $inputs["article_section"]->name; + $ste->vars["editlang"] = $editlang; + foreach(array( + "urlname" => "urlname", + "article_status" => "article_status", + "title" => "title", + "content_txtproc" => "content_txtproc", + "content" => "content", + "excerpt_txtproc" => "excerpt_txtproc", + "excerpt" => "excerpt", + "date" => "date", + "allow_comments" => "allow_comments" + ) as $k_in => $k_out) + { + if(isset($inputs[$k_in])) + $ste->vars[$k_out] = $inputs[$k_in]; + } + + /* Displaying article editor plugins */ + $ste->vars["displayed_plugins"] = array_map(function($x) { return array("label" => $x["label"], "template" => $x["template"]); }, array_filter($articleeditor_plugins, function($x) { return $x["display"]; })); + + if(!empty($fail_reasons)) + $ste->vars["failed"] = $fail_reasons; + + echo $ste->exectemplate("/systemtemplates/content_write.html"); + }, + "tags" => function(&$data, $url_now, &$url_next) + { + global $translation, $languages, $ste, $rel_path_to_root; + + $url_next = array(); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "tags"; + $ste->vars["pagetitle"] = $translation["tags_overview"]; + + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["tag_multiselect"] as $tagid) + { + try + { + $tag = Tag::by_id($tagid); + $tag->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $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"])) + { + if(!Tag::test_name(@$_POST["newtagname"])) + $ste->vars["error"] = $translation["invalid_tag_name"]; + else + $newtag = $_POST["newtagname"]; + } + + if(($newlang !== NULL) and (!isset($languages[$newlang]))) + $newlang = NULL; + if($newtag !== NULL) + { + try + { + $newtag = Tag::create($newtag); + } + catch(AlreadyExistsError $e) + { + $newtag = NULL; + } + } + + $translations = array(); + foreach($_POST as $k => $v) + { + if(preg_match('/tagtrans_(NEW|[a-z]{2})_(.*)/', $k, $matches) == 1) + { + $lang = ($matches[1] == "NEW") ? $newlang : $matches[1]; + $tag = $matches[2]; + if($lang === NULL) + continue; + $translations[$tag][$lang] = $v; + } + } + + foreach($translations as $tag => $langmap) + { + if($tag == "NEW") + { + if($newtag === NULL) + continue; + $tag = $newtag; + } + else + { + try + { + $tag = Tag::by_id($tag); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + foreach($langmap as $l => $text) + { + if(empty($text)) + unset($tag->title[$l]); + else + $tag->title[$l] = new Translation($text, ""); + } + + $tag->save(); + } + + $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; + } + + $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) + { + 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"]; + + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["article_multiselect"] as $article_urlname) + { + try + { + $article = Article::by_urlname($article_urlname); + $article->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $ste->vars["success"] = $translation["articles_deleted"]; + } + + $articles = Article::all(); + + /* Filtering */ + $filterquery = array(); + if(!empty($_GET["filter_urlname"])) + { + $searchfor = strtolower($_GET["filter_urlname"]); + $articles = array_filter($articles, function($a) use ($searchfor) { return strpos(strtolower($a->urlname), $searchfor) !== False; }); + $filterquery[] = "filter_urlname=" . urlencode($_GET["filter_urlname"]); + $ste->vars["filter_urlname"] = $_GET["filter_urlname"]; + } + if(!empty($_GET["filter_tag"])) + { + $searchfor = $_GET["filter_tag"]; + $articles = array_filter($articles, function($a) use ($searchfor) { foreach($a->get_tags() as $t) { if($t->name==$searchfor) return True; } return False; }); + $filterquery[] = "filter_tag=" . urlencode($searchfor); + $ste->vars["filter_tag"] = $searchfor; + } + if(!empty($_GET["filter_section"])) + { + $searchfor = $_GET["filter_section"]; + $articles = array_filter($articles, function($a) use ($searchfor) { return $a->get_section()->name == $searchfor; }); + $filterquery[] = "filter_section=" . urlencode($searchfor); + $ste->vars["filter_section"] = $searchfor; + } + $ste->vars["filterquery"] = implode("&", $filterquery); + + /* Sorting */ + if(isset($_GET["sort_asc"])) + { + switch($_GET["sort_asc"]) + { + case "date": + $ste->vars["sortquery"] = "sort_asc=date"; + $ste->vars["sort_asc_date"] = True; + $ste->vars["sorting"] = array("dir" => "asc", "by" => "date"); + usort($articles, function($a, $b) { return intcmp($a->timestamp, $b->timestamp); }); + break; + case "section": + $ste->vars["sortquery"] = "sort_asc=section"; + $ste->vars["sort_asc_section"] = True; + $ste->vars["sorting"] = array("dir" => "asc", "by" => "section"); + usort($articles, function($a, $b) { return strcmp($a->get_section()->name, $b->get_section()->name); }); + break; + case "urlname": + $ste->vars["sortquery"] = "sort_asc=urlname"; + default: + $ste->vars["sort_asc_urlname"] = True; + $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); + usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); + break; + } + } + elseif(isset($_GET["sort_desc"])) + { + switch($_GET["sort_desc"]) + { + case "date": + $ste->vars["sortquery"] = "sort_desc=date"; + $ste->vars["sort_desc_date"] = True; + $ste->vars["sorting"] = array("dir" => "desc", "by" => "date"); + usort($articles, function($a, $b) { return intcmp($b->timestamp, $a->timestamp); }); + break; + case "section": + $ste->vars["sortquery"] = "sort_desc=section"; + $ste->vars["sort_desc_section"] = True; + $ste->vars["sorting"] = array("dir" => "desc", "by" => "section"); + usort($articles, function($a, $b) { return strcmp($b->get_section()->name, $a->get_section()->name); }); + break; + case "urlname": + $ste->vars["sortquery"] = "sort_desc=urlname"; + $ste->vars["sort_desc_urlname"] = True; + $ste->vars["sorting"] = array("dir" => "desc", "by" => "urlname"); + usort($articles, function($a, $b) { return strcmp($b->urlname, $a->urlname); }); + break; + default: + $ste->vars["sort_asc_urlname"] = True; + $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); + usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); + break; + } + } + else + { + $ste->vars["sort_asc_urlname"] = True; + $ste->vars["sorting"] = array("dir" => "asc", "by" => "urlname"); + usort($articles, function($a, $b) { return strcmp($a->urlname, $b->urlname); }); + } + + $ste->vars["articles"] = array_map(function($article) { + $avail_langs = array(); + foreach($article->title as $lang => $_) + $avail_langs[] = $lang; + sort($avail_langs); + $a_section = $article->get_section(); + return array( + "urlname" => $article->urlname, + "languages" => $avail_langs, + "date" => $article->timestamp, + "tags" => array_map(function($tag) { return $tag->name; }, $article->get_tags()), + "section" => array("id" => $a_section->get_id(), "name" => $a_section->name) + ); + }, $articles); + + echo $ste->exectemplate("/systemtemplates/articles.html"); + }, + "images" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($imgid, $imageaction) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "images"; + $ste->vars["pagetitle"] = $translation["menu_images"]; + + if(!empty($imgid) and is_numeric($imgid)) + { + try + { + $image = Image::by_id($imgid); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if(empty($imageaction)) + throw new NotFoundError(); + else + { + if(($imageaction == "markdown") or ($imageaction == "html") or ($imageaction == "ste")) + { + $ste->vars["pagetitle"] = $translation["generate_embed_code"]; + $ste->vars["image_id"] = $image->get_id(); + $ste->vars["markup_variant"] = $imageaction; + if(isset($_POST["img_alt"])) + { + if($imageaction == "markdown") + $ste->vars["embed_code"] = "![" . str_replace("]", "\\]", $_POST["img_alt"]) . "](%root%/images/" . str_replace(")", "\\)", urlencode($image->get_filename())) . ")"; + elseif($imageaction == "html") + $ste->vars["embed_code"] = "get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; + elseif($imageaction == "ste") + $ste->vars["embed_code"] = "get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; + } + + echo $ste->exectemplate("/systemtemplates/image_embed.html"); + } + else + throw new NotFoundError(); + } + return; + } + + /* Upload Form */ + if(isset($_POST["upload"])) + { + try + { + $image = Image::create((!empty($_POST["upload_name"])) ? $_POST["upload_name"] : $_FILES["upload_img"]["name"], $_FILES["upload_img"]["tmp_name"]); + $image->save(); + $ste->vars["success"] = $translation["upload_success"]; + } + catch(IOError $e) + { + $ste->vars["error"] = $translation["upload_failed"]; + } + catch(UnknownFileFormat $e) + { + $ste->vars["error"] = $translation["unknown_file_format"]; + } + } + + /* Mass delete */ + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["image_multiselect"] as $image_id) + { + try + { + $image = Image::by_id($image_id); + $image->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $ste->vars["success"] = $translation["images_deleted"]; + } + + $images = Image::all(); + + $ste->vars["images"] = array_map(function($img) { return array( + "id" => $img->get_id(), + "name" => $img->name, + "file" => $img->get_filename() + ); }, $images); + + echo $ste->exectemplate("/systemtemplates/image_list.html"); + }, + "comments" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($comment_id) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "content"; + $ste->vars["submenu"] = "comments"; + $ste->vars["pagetitle"] = $translation["menu_comments"]; + + /* Single comment? */ + if(!empty($comment_id)) + { + try + { + $comment = Comment::by_id($comment_id); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if(!$comment->read_by_admin) + { + $comment->read_by_admin = True; + $comment->save(); + } + + if(isset($_POST["action_on_comment"])) + { + switch($_POST["action_on_comment"]) + { + case "delete": + $comment->delete(); + $ste->vars["success"] = $translation["comment_successfully_deleted"]; + goto backend_content_comments_overview; + break; + case "make_visible": + $comment->visible = True; + $comment->save(); + $ste->vars["success"] = $translation["comment_successfully_made_visible"]; + break; + case "make_invisible": + $comment->visible = False; + $comment->save(); + $ste->vars["success"] = $translation["comment_successfully_made_invisible"]; + break; + } + } + + $ste->vars["id"] = $comment->get_id(); + $ste->vars["visible"] = $comment->visible; + $ste->vars["article"] = $comment->get_article()->urlname; + $ste->vars["language"] = $comment->get_language(); + $ste->vars["date"] = $comment->get_timestamp(); + $ste->vars["author"] = "\"{$comment->author_name}\" <{$comment->author_mail}>"; + $ste->vars["comment_text"] = $comment->create_html(); + $ste->vars["comment_raw"] = $comment->text; + + echo $ste->exectemplate("/systemtemplates/single_comment.html"); + return; + } + + backend_content_comments_overview: + + /* Perform an action on all selected comments */ + if(!empty($_POST["action_on_comments"])) + { + switch($_POST["action_on_comments"]) + { + case "delete": + $commentaction = function($c) { $c->delete(); }; + $ste->vars["success"] = $translation["comments_successfully_deleted"]; + break; + case "mark_read": + $commentaction = function($c) { $c->read_by_admin = True; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_marked_read"]; + break; + case "mark_unread": + $commentaction = function($c) { $c->read_by_admin = False; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_marked_unread"]; + break; + case "make_visible": + $commentaction = function($c) { $c->visible = True; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_made_visible"]; + break; + case "make_invisible": + $commentaction = function($c) { $c->visible = False; $c->save(); }; + $ste->vars["success"] = $translation["comments_successfully_made_invisible"]; + break; + default; + $ste->vars["error"] = $translation["unknown_action"]; + break; + } + if(isset($commentaction)) + { + foreach($_POST["comment_multiselect"] as $c_id) + { + try + { + $comment = Comment::by_id($c_id); + $commentaction($comment); + } + catch(DoesNotExistError $e) + { + continue; + } + } + } + } + + $comments = Comment::all(); + + /* Filtering */ + $filterquery = array(); + if(!empty($_GET["filter_article"])) + { + $searchfor = strtolower($_GET["filter_article"]); + $comments = array_filter($comments, function($c) use ($searchfor) { return strpos(strtolower($c->get_article()->urlname), $searchfor) !== False; }); + $filterquery[] = "filter_article=" . urlencode($_GET["filter_article"]); + $ste->vars["filter_article"] = $_GET["filter_article"]; + } + $ste->vars["filterquery"] = implode("&", $filterquery); + + /* Sorting */ + if(isset($_GET["sort_asc"])) + { + $sort_dir = 1; + $sort_by = $_GET["sort_asc"]; + } + elseif(isset($_GET["sort_desc"])) + { + $sort_dir = -1; + $sort_by = $_GET["sort_desc"]; + } + else + { + $sort_dir = 1; + $sort_by = "was_read"; + } + + switch($sort_by) + { + case "language": + usort($comments, function($a, $b) use ($sort_dir) { return strcmp($a->get_language(), $b->get_language()) * $sort_dir; }); + break; + case "date": + usort($comments, function($a, $b) use ($sort_dir) { return intcmp($a->get_timestamp(), $b->get_timestamp()) * $sort_dir; }); + break; + case "was_read": + default: + usort($comments, function($a, $b) use ($sort_dir) { return intcmp((int) $a->read_by_admin, (int) $b->read_by_admin) * $sort_dir; }); + $sort_by = "was_read"; + break; + } + $ste->vars["sortquery"] = "sort_" . ($sort_dir == 1 ? "asc" : "desc") . "=$sort_by"; + $ste->vars["sorting"] = array("dir" => ($sort_dir == 1 ? "asc" : "desc"), "by" => $sort_by); + $ste->vars["sort_" . ($sort_dir == 1 ? "asc" : "desc") . "_$sort_by"] = True; + + $ste->vars["comments"] = array_map(function($c) { return array( + "id" => $c->get_id(), + "visible" => $c->visible, + "read_by_admin" => $c->read_by_admin, + "article" => $c->get_article()->urlname, + "excerpt" => substr(str_replace(array("\r\n", "\n", "\r"), " ", $c->text), 0, 50), + "language" => $c->get_language(), + "date" => $c->get_timestamp(), + "author" => "\"{$c->author_name}\" <{$c->author_mail}>" + ); }, $comments); + + echo $ste->exectemplate("/systemtemplates/comments_list.html"); + } + )), + "design" => url_action_subactions(array( + "templates" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($template) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "design"; + $ste->vars["submenu"] = "templates"; + $ste->vars["pagetitle"] = $translation["menu_templates"]; + + if(isset($template)) + { + if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $template) == 0) /* Prevent a possible LFI attack. */ + throw new NotFoundError(); + if(!is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template")) + throw new NotFoundError(); + $ste->vars["template_name"] = $template; + $ste->vars["template_code"] = file_get_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$template"); + } + + /* Was there a delete request? */ + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["templates_multiselect"] as $tplname) + { + if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $tplname) == 0) /* Prevent a possible LFI attack. */ + continue; + if(is_file(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname")) + @unlink(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/$tplname"); + } + $ste->vars["success"] = $translation["templates_successfully_deleted"]; + } + + /* A write request? */ + if(isset($_POST["save_template"])) + { + if(preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $_POST["template_name"]) == 1) + { + $ste->vars["template_name"] = $_POST["template_name"]; + $ste->vars["template_code"] = $_POST["template_code"]; + + try + { + \ste\transcompile(\ste\parse(\ste\precompile($_POST["template_code"]), $_POST["template_name"])); + file_put_contents(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates/" . $_POST["template_name"], $_POST["template_code"]); + $ste->vars["success"] = $translation["template_successfully_saved"]; + } + catch(\ste\ParseCompileError $e) + { + $e->rewrite($_POST["template_code"]); + $ste->vars["error"] = $translation["could_not_compile_template"] . $e->getMessage(); + } + } + else + $ste->vars["error"] = $translation["invalid_template_name"]; + } + + /* 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"]); + + echo $ste->exectemplate("/systemtemplates/templates.html"); + }, + "styles" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($style) = $url_next; + + $url_next = array(); + + $ste->vars["section"] = "design"; + $ste->vars["submenu"] = "styles"; + $ste->vars["pagetitle"] = $translation["menu_styles"]; + + if(isset($style)) + { + try + { + $style = Style::by_name($style); + $ste->vars["style_name"] = $style->name; + $ste->vars["style_code"] = $style->code; + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + } + + /* Was there a delete request? */ + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["styles_multiselect"] as $stylename) + { + try + { + $style = Style::by_name($stylename); + $style->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + $ste->vars["success"] = $translation["styles_successfully_deleted"]; + } + + /* A write request? */ + if(isset($_POST["save_style"])) + { + if(Style::test_name($_POST["style_name"])) + { + $ste->vars["style_name"] = $_POST["style_name"]; + $ste->vars["style_code"] = $_POST["style_code"]; + + try + { + $style = Style::by_name($_POST["style_name"]); + } + catch(DoesNotExistError $e) + { + $style = Style::create($_POST["style_name"]); + } + + $style->code = $_POST["style_code"]; + $style->save(); + + $ste->vars["success"] = $translation["style_successfully_saved"]; + } + else + $ste->vars["error"] = $translation["invalid_style_name"]; + } + + /* Get all styles */ + $ste->vars["styles"] = array_map(function($s) { return $s->name; }, Style::all()); + 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(!Section::test_name($_POST["section_name"])) + $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 = Style::by_name($_GET["rmstyle"]); + $section->remove_style($style); + $section->save(); + $ste->vars["success"] = $translation["style_removed"]; + } + catch(DoesNotExistError $e) + { + } + } + + /* 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->set_section($default_section); + $article->save(); + } + $section->delete(); + $ste->vars["success"] = $translation["section_successfully_deleted"]; + } + } + catch(DoesNotExistError $e) + { + } + } + + /* 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) + { + } + } + + /* 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) + { + } + } + + /* 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"]); + $section->add_style($style); + $ste->vars["success"] = $translation["successfully_added_style"]; + } + catch(DoesNotExistError $e) + { + } + } + + /* 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) + { + } + } + } + + /* 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->get_styles()), + "default" => ($section->get_id() == $ratatoeskr_settings["default_section"]) + ); + }, $sections); + + echo $ste->exectemplate("/systemtemplates/sections.html"); + } + )), + "admin" => url_action_subactions(array( + "settings" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "settings"; + $ste->vars["pagetitle"] = $translation["menu_settings"]; + + $ste->vars["textprocessors"] = array(); + foreach($textprocessors as $txtproc => $properties) + if($properties[1]) + $ste->vars["textprocessors"][] = $txtproc; + + /* Toggle debugmode value? */ + if(isset($_POST["toggle_debugmode"])) + { + if(isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]) + { + $ratatoeskr_settings["debugmode"] = False; + $ste->vars["success"] = $translation["debugmode_now_disabled"]; + } + else + { + $ratatoeskr_settings["debugmode"] = True; + $ste->vars["success"] = $translation["debugmode_now_enabled"]; + } + } + + /* Save comment settings? */ + if(isset($_POST["save_comment_settings"])) + { + if(!in_array(@$_POST["comment_textprocessor"], $ste->vars["textprocessors"])) + $ste->vars["error"] = $translation["unknown_txtproc"]; + else + { + $ratatoeskr_settings["comment_textprocessor"] = $_POST["comment_textprocessor"]; + $ratatoeskr_settings["comment_visible_default"] = (isset($_POST["comment_auto_visible"]) and ($_POST["comment_auto_visible"] == "yes")); + $ste->vars["success"] = $translation["comment_settings_successfully_saved"]; + } + } + + /* Delete language? */ + if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes") and isset($_POST["language_select"])) + { + if($ratatoeskr_settings["default_language"] == $_POST["language_select"]) + $ste->vars["error"] = $translation["cannot_delete_default_language"]; + else + { + $ratatoeskr_settings["languages"] = array_filter($ratatoeskr_settings["languages"], function($l) { return $l != $_POST["language_select"]; }); + $ste->vars["success"] = $translation["language_successfully_deleted"]; + } + } + + /* Set default language */ + if(isset($_POST["make_default"]) and isset($_POST["language_select"])) + { + if(in_array($_POST["language_select"], $ratatoeskr_settings["languages"])) + { + $ratatoeskr_settings["default_language"] = $_POST["language_select"]; + $ste->vars["success"] = $translation["successfully_set_default_language"]; + } + } + + /* Add a language */ + if(isset($_POST["add_language"])) + { + if(!isset($languages[$_POST["language_to_add"]])) + $ste->vars["error"] = $translation["language_unknown"]; + else + { + if(!in_array($_POST["language_to_add"], $ratatoeskr_settings["languages"])) + { + $ls = $ratatoeskr_settings["languages"]; + $ls[] = $_POST["language_to_add"]; + $ratatoeskr_settings["languages"] = $ls; + } + $ste->vars["success"] = $translation["language_successfully_added"]; + } + } + + $ste->vars["debugmode_enabled"] = (isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]); + $ste->vars["comment_auto_visible"] = $ratatoeskr_settings["comment_visible_default"]; + $ste->vars["comment_textprocessor"] = $ratatoeskr_settings["comment_textprocessor"]; + $ste->vars["used_langs"] = array_map(function ($l) use ($ratatoeskr_settings, $languages) { return array( + "code" => $l, + "name" => $languages[$l]["language"], + "default" => ($l == $ratatoeskr_settings["default_language"]) + );}, $ratatoeskr_settings["languages"]); + + echo $ste->exectemplate("/systemtemplates/settings.html"); + }, + "users" => url_action_subactions(array( + "_index" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "users"; + $ste->vars["pagetitle"] = $translation["menu_users_groups"]; + + /* Add a new group? */ + if(isset($_POST["new_group"])) + { + if(empty($_POST["group_name"])) + $ste->vars["error"] = $translation["empty_group_name"]; + else + { + try + { + Group::by_name($_POST["group_name"]); + $ste->vars["error"] = $translation["group_already_exists"]; + } + catch(DoesNotExistError $e) + { + $group = Group::create($_POST["group_name"]); + $ste->vars["success"] = $translation["successfully_created_group"]; + } + } + } + + /* Add a new user? */ + if(isset($_POST["new_user"])) + { + if(empty($_POST["username"])) + $ste->vars["error"] = $translation["empty_username"]; + else + { + try + { + User::by_name($_POST["username"]); + $ste->vars["error"] = $translation["user_already_exists"]; + } + catch(DoesNotExistError $e) + { + $group = User::create($_POST["username"], PasswordHash::create($_POST["initial_password"])); + $ste->vars["success"] = $translation["successfully_created_user"]; + } + } + } + + /* Delete groups? */ + if(isset($_POST["delete_groups"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["groups_multiselect"]))) + { + $deleted = 0; + foreach($_POST["groups_multiselect"] as $gid) + { + try + { + $group = Group::by_id($gid); + if($group->name == "admins") + { + $ste->vars["error"] = $translation["cannot_delete_admin_group"]; + } + else + { + $group->delete(); + ++$deleted; + } + } + catch(DoesNotExistError $e) + { + continue; + } + } + if($deleted > 0) + $ste->vars["success"] = $translation["successfully_deleted_groups"]; + } + + /* Delete users? */ + if(isset($_POST["delete_users"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["users_multiselect"]))) + { + $deleted = 0; + foreach($_POST["users_multiselect"] as $uid) + { + if($uid == $data["user"]->get_id()) + $ste->vars["error"] = $translation["cannot_delete_yourself"]; + else + { + try + { + $user = User::by_id($uid); + $user->delete(); + ++$deleted; + } + catch(DoesNotExistError $e) + { + continue; + } + } + } + if($deleted > 0) + $ste->vars["success"] = $translation["successfully_deleted_users"]; + } + + /* Get all groups */ + $ste->vars["groups"] = array_map(function($g) { return array( + "id" => $g->get_id(), + "name" => $g->name + ); }, Group::all()); + + /* Get all users */ + $ste->vars["users"] = array_map(function($u) { return array( + "id" => $u->get_id(), + "name" => $u->username, + "memberof" => array_map(function($g) { return $g->name; }, $u->get_groups()), + "fullname" => $u->fullname, + "mail" => $u->mail + ); }, User::all()); + + echo $ste->exectemplate("/systemtemplates/users.html"); + }, + "u" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $admin_grp; + + try + { + $user = User::by_id($url_next[0]); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "users"; + $ste->vars["pagetitle"] = $user->username; + + /* Modify data? */ + if(isset($_POST["change_data"])) + { + $user->fullname = $_POST["fullname"]; + $user->mail = $_POST["mail"]; + $user->language = $_POST["lang"]; + + $current_groups = array_map(function($g) { return $g->get_id(); }, $user->get_groups()); + $new_groups = empty($_POST[groups_multiselect]) ? array() : $_POST["groups_multiselect"]; + $groups_exclude = array_diff($current_groups, $new_groups); + $groups_include = array_diff($new_groups, $current_groups); + + foreach($groups_exclude as $gid) + { + try + { + $g = Group::by_id($gid); + $g->exclude_user($user); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + foreach($groups_include as $gid) + { + try + { + $g = Group::by_id($gid); + $g->include_user($user); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $user->save(); + + $ste->vars["success"] = $translation["successfully_modified_user"]; + } + + /* New Password? */ + if(isset($_POST["new_password"])) + { + $pwhash = PasswordHash::create($_POST["password"]); + $user->pwhash = $pwhash; + if($user->get_id() == $data["user"]->get_id()) + $_SESSION["ratatoeskr_pwhash"] = $pwhash; + $user->save(); + + $ste->vars["success"] = $translation["successfully_set_new_password"]; + } + + /* Put data to STE */ + $ste->vars["u"] = array( + "id" => $user->get_id(), + "name" => $user->username, + "fullname" => $user->fullname, + "mail" => $user->mail, + "lang" => $user->language + ); + $ste->vars["groups"] = array_map(function($g) use ($user) { return array( + "id" => $g->get_id(), + "name" => $g->name, + "member" => $user->member_of($g) + ); }, Group::all()); + + echo $ste->exectemplate("/systemtemplates/user.html"); + } + )), + "repos" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + $url_next = array(); + + $ste->vars["section"] = "admin"; + $ste->vars["submenu"] = "repos"; + $ste->vars["pagetitle"] = $translation["menu_plugin_repos"]; + + /* Add a repo? */ + if(isset($_POST["add_repo"])) + { + try + { + $repo = Repository::create($_POST["repo_baseurl"]); + $ste->vars["success"] = $translation["successfully_added_repo"]; + } + catch(RepositoryUnreachableOrInvalid $e) + { + $ste->vars["error"] = $translation["repository_unreachable_or_invalid"]; + } + } + + /* Delete repos? */ + if(isset($_POST["delete_repos"]) and ($_POST["really_delete"] == "yes")) + { + foreach($_POST["repos_multiselect"] as $repo_id) + { + try + { + $repo = Repository::by_id($repo_id); + $repo->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + $ste->vars["success"] = $translation["repos_deleted"]; + } + + /* Force refresh? */ + if(isset($_POST["force_repo_refresh"])) + { + $failed = array(); + foreach($_POST["repos_multiselect"] as $repo_id) + { + try + { + $repo = Repository::by_id($repo_id); + $repo->refresh(True); + } + catch(DoesNotExistError $e) + { + continue; + } + catch(RepositoryUnreachableOrInvalid $e) + { + $failed[] = $repo->get_name(); + } + } + $ste->vars["success"] = $translation["successfully_refreshed_repos"]; + if(!empty($failed)) + $ste->vars["error"] = str_replace("[[REPOS]]", implode(", ", $failed), $translation["repo_refresh_failed_on"]); + } + + /* Fill data */ + $all_repos = Repository::all(); + $ste->vars["repos"] = array_map( + function($r) + { + try + { + $r->refresh(); + } + catch(RepositoryUnreachableOrInvalid $e){} + return array( + "id" => $r->get_id(), + "name" => $r->get_name(), + "description" => $r->get_description(), + "baseurl" => $r->get_baseurl() + ); + }, $all_repos); + + echo $ste->exectemplate("/systemtemplates/repos.html"); + } + )), + "plugin" => url_action_subactions(array( + "list" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $plugin_objs, $api_compat; + + $url_next = array(); + + $ste->vars["section"] = "plugins"; + $ste->vars["submenu"] = "pluginlist"; + $ste->vars["pagetitle"] = $translation["menu_pluginlist"]; + + /* Delete plugins? */ + if(isset($_POST["delete"]) and (($_POST["really_delete"] == "yes") or ($_POST["really_delete"] == "force")) and (!empty($_POST["plugins_multiselect"]))) + { + foreach($_POST["plugins_multiselect"] as $pid) + { + try + { + $plugin = Plugin::by_id($pid); + if($_POST["really_delete"] != "force") + { + if(!isset($plugin_objs[$pid])) + { + eval($plugin->code); + $plugin_objs[$pid] = new $plugin->classname($pid); + } + $plugin_objs[$pid]->uninstall(); + } + $plugin->delete(); + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $ste->vars["success"] = $translation["successfully_deleted_plugins"]; + } + + /* Activate or deactivate plugins? */ + if((isset($_POST["activate"]) or isset($_POST["deactivate"])) and (!empty($_POST["plugins_multiselect"]))) + { + $api_incompat = array(); + $newstatus = isset($_POST["activate"]); + foreach($_POST["plugins_multiselect"] as $pid) + { + try + { + $plugin = Plugin::by_id($pid); + if(!$plugin->installed) + continue; + if($newstatus and (!in_array($plugin->api, $api_compat))) + { + $api_incompat[] = $plugin->name . ("(ID: " . $plugin->get_id() . ")"); + continue; + } + $plugin->active = $newstatus; + $plugin->save(); + if($newstatus and (!isset($plugin_objs[$pid]))) + { + eval($plugin->code); + $plugin_objs[$pid] = new $plugin->classname($pid); + $plugin_objs[$pid]->init(); + } + } + catch(DoesNotExistError $e) + { + continue; + } + } + + $ste->vars["success"] = $translation[$newstatus ? "plugins_activated" : "plugins_deactivated"]; + + if(!empty($api_incompat)) + $ste->vars["error"] = htmlesc(str_replace("[[PLUGINS]]", implode(", ", $api_incompat), $translation["could_not_activate_plugin_api_incompat"])); + } + + $stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); + + /* Update plugins? */ + if(isset($_POST["update"]) and (!empty($_POST["plugins_multiselect"]))) + { + $updated = array(); + foreach($_POST["plugins_multiselect"] as $pid) + { + try + { + $plugin = Plugin::by_id($pid); + if(!empty($plugin->updatepath)) + { + $update_info = @unserialize(@file_get_contents($plugin->updatepath, False, $stream_ctx)); + if(is_array($update_info) and (($update_info["current-version"]+0) > ($plugin->versioncount+0))) + { + $pkg = PluginPackage::load(@file_get_contents($update_info["dl-path"], False, $stream_ctx)); + $plugin->fill_from_pluginpackage($pkg); + $plugin->update = True; + $plugin->save(); + $updated[] = $plugin->name; + } + } + } + catch(DoesNotExistError $e) + { + continue; + } + catch(InvalidPackage $e) + { + continue; + } + } + + if(empty($updated)) + $ste->vars["success"] = $translation["nothing_to_update"]; + else + $ste->vars["success"] = str_replace("[[PLUGINS]]", implode(", ", $updated), $translation["successfully_updated_plugins"]); + } + + /* Load plugin data */ + $all_plugins = Plugin::all(); + $ste->vars["plugins"] = array(); + $api_incompat = array(); + foreach($all_plugins as $p) + { + if(!$p->installed) + continue; + + if(!in_array($p->api, $api_compat)) + $api_incompat[] = $p->name . ("(ID: " . $p->get_id() . ")"); + + $ste->vars["plugins"][] = array( + "id" => $p->get_id(), + "name" => $p->name, + "versiontext" => $p->versiontext, + "active" => $p->active, + "description" => $p->short_description, + "web" => $p->web, + "author" => $p->author, + "help" => !empty($p->help) + ); + } + + if(!empty($api_incompat)) + $ste->vars["notice"] = htmlesc(str_replace("[[PLUGINS]]", implode(", ", $api_incompat), $translation["plugins_incompat"])); + + echo $ste->exectemplate("/systemtemplates/pluginlist.html"); + }, + "help" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + try + { + $plugin = Plugin::by_id($url_next[0]); + if(empty($plugin->help)) + throw new NotFoundError(); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + $url_next = array(); + + $ste->vars["section"] = "plugins"; + $ste->vars["submenu"] = ""; + $ste->vars["pagetitle"] = $plugin->name; + $ste->vars["help"] = $plugin->help; + + echo $ste->exectemplate("/systemtemplates/pluginhelp.html"); + }, + "install" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root, $api_compat; + + $url_next = array(); + + $ste->vars["section"] = "plugins"; + $ste->vars["submenu"] = "installplugins"; + $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; + + $all_repos = Repository::all(); + foreach($all_repos as $repo) + { + try + { + $repo->refresh(); + } + catch(RepositoryUnreachableOrInvalid $e) + { + continue; + } + } + + if(isset($_POST["installpackage"])) + { + if(is_uploaded_file($_FILES["pluginpackage"]["tmp_name"])) + { + try + { + $package = PluginPackage::load(file_get_contents($_FILES["pluginpackage"]["tmp_name"])); + unlink($_FILES["pluginpackage"]["tmp_name"]); + if(in_array($package->api, $api_compat)) + { + $plugin = Plugin::create(); + $plugin->fill_from_pluginpackage($package); + $plugin->installed = False; + $plugin->active = False; + $plugin->save(); + $url_next = array("confirminstall", (string) $plugin->get_id()); + return; + } + else + $ste->vars["error"] = str_replace("[[API]]", $package->api, $translation["incompatible_plugin"]); + } + catch(InvalidPackage $e) + { + $ste->vars["error"] = $translation["invalid_package"]; + unlink($_FILES["pluginpackage"]["tmp_name"]); + } + } + else + $ste->vars["error"] = $translation["upload_failed"]; + } + + if(isset($_POST["search_in_repos"])) + { + $ste->vars["searchresults"] = array(); + $repos_to_scan = ($_POST["searchin"] == "*") ? $all_repos : Repository::by_id($_POST["searchin"]); + $searchfor = strtolower($_POST["searchfor"]); + foreach($repos_to_scan as $repo) + { + foreach($repo->packages as $pkg) + { + if(empty($searchfor) or (strpos(strtolower($pkg[0]), $searchfor) !== False) or (strpos(strtolower($pkg[2]), $searchfor) !== False)) + $ste->vars["searchresults"][] = array( + "name" => $pkg[0], + "description" => $pkg[2], + "reponame" => $repo->get_name(), + "repoid" => $repo->get_id() + ); + } + } + } + + $ste->vars["repos"] = array_map(function($r) { return array( + "id" => $r->get_id(), + "name" => $r->get_name() + ); }, $all_repos); + + echo $ste->exectemplate("/systemtemplates/plugininstall.html"); + }, + "repoinstall" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $rel_path_to_root; + + $stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); + + try + { + $repo = Repository::by_id($_GET["repo"]); + $pkg = $repo->download_package($_GET["pkg"]); + $plugin = Plugin::create(); + $plugin->fill_from_pluginpackage($pkg); + $plugin->installed = False; + $plugin->active = False; + $plugin->save(); + $url_next = array("confirminstall", (string) $plugin->get_id()); + } + catch(DoesNotExistError $e) + { + $ste->vars["error"] = $translation["package_or_repo_not_found"]; + $url_next = array("install"); + } + catch(InvalidPackage $e) + { + $ste->vars["error"] = $translation["invalid_package"]; + $url_next = array("install"); + } + }, + "confirminstall" => function(&$data, $url_now, &$url_next) + { + global $ste, $translation, $languages, $rel_path_to_root; + + list($plugin_id) = $url_next; + $url_next = array(); + + $ste->vars["section"] = "plugins"; + $ste->vars["submenu"] = "installplugins"; + $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; + + try + { + $plugin = Plugin::by_id($plugin_id); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + if($plugin->installed) + throw new NotFoundError(); + + $ste->vars["plugin_id"] = $plugin->get_id(); + $ste->vars["name"] = $plugin->name; + $ste->vars["description"] = $plugin->short_description; + $ste->vars["code"] = $plugin->code; + $ste->vars["license"] = $plugin->license; + + if(isset($_POST["yes"])) + { + $plugin->installed = True; + $plugin->save(); + eval($plugin->code); + $plugin_instance = new $plugin->classname($plugin->get_id()); + $plugin_instance->install(); + $ste->vars["success"] = $translation["plugin_installed_successfully"]; + $url_next = array("list"); + return; + } + + if(isset($_POST["no"])) + { + $plugin->delete(); + $url_next = array("install"); + return; + } + + echo $ste->exectemplate("/systemtemplates/confirminstall.html"); + } + )), + "pluginpages" => url_action_subactions($pluginpages_handlers) )); } diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php index 9c43ec5..71e940e 100644 --- a/ratatoeskr/frontend.php +++ b/ratatoeskr/frontend.php @@ -2,7 +2,7 @@ /* * File: ratatoeskr/frontend.php * All the stuff for the frontend (i.e. what the visitor of the website sees). - * + * * License: * This file is part of Ratatöskr. * Ratatöskr is licensed unter the MIT / X11 License. @@ -18,137 +18,137 @@ require_once(dirname(__FILE__) . "/libs/kses.php"); /* * Function: section_transform_ste * Transforms an
object to an array, so it can be accessed via a STE template. - * + * * Parameters: - * $section -
object. - * $lang - The current language. - * + * $section -
object. + * $lang - The current language. + * * Returns: - * Array with these fields: - * * id - The ID of the section. - * * name - The name of the section. - * * title - The title of the section in the current language - * * __obj - The
object. Useful for plugins, so they do not need to fetch the object from the database again. + * Array with these fields: + * * id - The ID of the section. + * * name - The name of the section. + * * title - The title of the section in the current language + * * __obj - The
object. Useful for plugins, so they do not need to fetch the object from the database again. */ function section_transform_ste($section, $lang) { - return array( - "id" => $section->get_id(), - "name" => $section->name, - "title" => $section->title[$lang]->text, - "__obj" => $section - ); + return array( + "id" => $section->get_id(), + "name" => $section->name, + "title" => $section->title[$lang]->text, + "__obj" => $section + ); } /* * Function: tag_transform_ste * Transforms an object to an array, so it can be accessed via a STE template. - * + * * Parameters: - * $section - object. - * $lang - The current language. - * + * $section - object. + * $lang - The current language. + * * Returns: - * Array with these fields: - * * id - The ID of the tag. - * * name - The name of the tag. - * * title - The title in the current language. - * * __obj - The object. Useful for plugins, so they do not need to fetch the object from the database again. + * Array with these fields: + * * id - The ID of the tag. + * * name - The name of the tag. + * * title - The title in the current language. + * * __obj - The object. Useful for plugins, so they do not need to fetch the object from the database again. */ function tag_transform_ste($tag, $lang) { - try - { - return array( - "id" => $tag->get_id(), - "name" => $tag->name, - "title" => $tag->title[$lang]->text, - "__obj" => $tag - ); - } - catch(DoesNotExistError $e) - { - return False; - } + try + { + return array( + "id" => $tag->get_id(), + "name" => $tag->name, + "title" => $tag->title[$lang]->text, + "__obj" => $tag + ); + } + catch(DoesNotExistError $e) + { + return False; + } } /* * Function: article_transform_ste * Transforms an
object to an array, so it can be accessed via a STE template. - * + * * Parameters: - * $article -
object. - * $lang - The current language. - * + * $article -
object. + * $lang - The current language. + * * Returns: - * Array with these fields: - * * id - * * urlname - * * fullurl - * * title - * * text - * * excerpt - * * custom (array: name=>value) - * * status (numeric) - * * section (sub-fields: ) - * * timestamp - * * tags (array(sub-fields: )) - * * languages (array: language name=>url) - * * comments_allowed - * * __obj - Useful for plugins, so they do not need to fetch the object from the database again. + * Array with these fields: + * * id + * * urlname + * * fullurl + * * title + * * text + * * excerpt + * * custom (array: name=>value) + * * status (numeric) + * * section (sub-fields: ) + * * timestamp + * * tags (array(sub-fields: )) + * * languages (array: language name=>url) + * * comments_allowed + * * __obj - Useful for plugins, so they do not need to fetch the object from the database again. */ function article_transform_ste($article, $lang) { - global $rel_path_to_root; - - $languages = array(); - $a_section = $article->get_section(); - foreach($article->title as $language => $_) - $languages[$language] = "$rel_path_to_root/$language/{$a_section->name}/{$article->urlname}"; - - return array( - "id" => $article->get_id(), - "urlname" => $article->urlname, - "fullurl" => htmlesc("$rel_path_to_root/$lang/{$a_section->name}/{$article->urlname}"), - "title" => htmlesc($article->title[$lang]->text), - "text" => textprocessor_apply(str_replace("%root%", $rel_path_to_root, $article->text[$lang]->text), $article->text[$lang]->texttype), - "excerpt" => textprocessor_apply(str_replace("%root%", $rel_path_to_root, $article->excerpt[$lang]->text), $article->excerpt[$lang]->texttype), - "custom" => $article->custom, - "status" => $article->status, - "section" => section_transform_ste($a_section, $lang), - "timestamp" => $article->timestamp, - "tags" => array_filter(array_map(function($tag) use ($lang) { return tag_transform_ste($tag, $lang); }, $article->get_tags())), - "languages" => $languages, - "comments_allowed" => $article->allow_comments, - "__obj" => $article - ); + global $rel_path_to_root; + + $languages = array(); + $a_section = $article->get_section(); + foreach($article->title as $language => $_) + $languages[$language] = "$rel_path_to_root/$language/{$a_section->name}/{$article->urlname}"; + + return array( + "id" => $article->get_id(), + "urlname" => $article->urlname, + "fullurl" => htmlesc("$rel_path_to_root/$lang/{$a_section->name}/{$article->urlname}"), + "title" => htmlesc($article->title[$lang]->text), + "text" => textprocessor_apply(str_replace("%root%", $rel_path_to_root, $article->text[$lang]->text), $article->text[$lang]->texttype), + "excerpt" => textprocessor_apply(str_replace("%root%", $rel_path_to_root, $article->excerpt[$lang]->text), $article->excerpt[$lang]->texttype), + "custom" => $article->custom, + "status" => $article->status, + "section" => section_transform_ste($a_section, $lang), + "timestamp" => $article->timestamp, + "tags" => array_filter(array_map(function($tag) use ($lang) { return tag_transform_ste($tag, $lang); }, $article->get_tags())), + "languages" => $languages, + "comments_allowed" => $article->allow_comments, + "__obj" => $article + ); } /* * Function: comment_transform_ste * Transforms an object to an array, so it can be accessed via a STE template. - * + * * Parameters: - * $comment - object. - * + * $comment - object. + * * Returns: - * Array with these fields: - * * id - * * text - * * author - * * timestamp + * Array with these fields: + * * id + * * text + * * author + * * timestamp */ function comment_transform_ste($comment) { - global $rel_path_to_root, $ratatoeskr_settings; - - return array( - "id" => $comment->get_id(), - "text" => $comment->create_html(), - "author" => htmlesc($comment->author_name), - "timestamp" => $comment->get_timestamp(), - "__obj" => $comment - ); + global $rel_path_to_root, $ratatoeskr_settings; + + return array( + "id" => $comment->get_id(), + "text" => $comment->create_html(), + "author" => htmlesc($comment->author_name), + "timestamp" => $comment->get_timestamp(), + "__obj" => $comment + ); } /* Register some tags for the template engine */ @@ -156,522 +156,522 @@ function comment_transform_ste($comment) * STETag: articles_get * Get articles by custom criterias. Will only get articles, that are available in the current language ($language). * The fields of an article can be looked up at . - * + * * Parameters: - * var - (mandatory) The name of the variable, where the current article should be stored at. - * id - (optional) Filter by ID. - * urlname - (optional) Filter by urlname. - * section - (optional) Filter by section (section name). - * sectionvar - (optional) Filter by section (Name of variable that contains a section). - * status - (optional) Filter by status (numeric, ). - * tag - (optional) Filter by tag (tag name). - * tagvar - (optional) Filter by tag (Name of variable that contains a tag). - * sort - (optional) How to sort. Format: "fieldname direction" where fieldname is one of [id, urlname, title, timestamp] and direction is one of [asc, desc]. - * perpage - (optional) How many articles should be shown per page (default unlimited). - * page - (optional) On which page are we (starting with 1). Useful in combination with $current[page], and . (Default: 1) - * maxpage - (optional) (variable name) If given, the number of pages are stored in this variable. - * skip - (optional) How many articles should be skipped? (Default: none) - * count - (optional) How many articles to output. (Default unlimited) + * var - (mandatory) The name of the variable, where the current article should be stored at. + * id - (optional) Filter by ID. + * urlname - (optional) Filter by urlname. + * section - (optional) Filter by section (section name). + * sectionvar - (optional) Filter by section (Name of variable that contains a section). + * status - (optional) Filter by status (numeric, ). + * tag - (optional) Filter by tag (tag name). + * tagvar - (optional) Filter by tag (Name of variable that contains a tag). + * sort - (optional) How to sort. Format: "fieldname direction" where fieldname is one of [id, urlname, title, timestamp] and direction is one of [asc, desc]. + * perpage - (optional) How many articles should be shown per page (default unlimited). + * page - (optional) On which page are we (starting with 1). Useful in combination with $current[page], and . (Default: 1) + * maxpage - (optional) (variable name) If given, the number of pages are stored in this variable. + * skip - (optional) How many articles should be skipped? (Default: none) + * count - (optional) How many articles to output. (Default unlimited) * * Tag Content: - * The tag's content will be executed for every article. The current article will be written to the variable specified by the var parameter before. + * The tag's content will be executed for every article. The current article will be written to the variable specified by the var parameter before. * * Returns: - * All results from the tag content. + * All results from the tag content. */ $ste->register_tag("articles_get", function($ste, $params, $sub) { - $lang = $ste->vars["language"]; - - if(!isset($params["var"])) - throw new \ste\RuntimeError("Parameter var is needed in article_get!"); - - $criterias = array("langavail" => $lang, "onlyvisible" => True); - if(isset($params["id"])) - $criterias["id"] = $params["id"]; - if(isset($params["urlname"])) - $criterias["urlname"]; - if(isset($params["status"])) - $criterias["status"] = $params["status"]; - if(isset($params["sectionvar"])) - { - $sectionvar = $ste->get_var_by_name($params["sectionvar"]); - $criterias["section"] = $sectionvar["__obj"]; - } - else if(isset($params["section"])) - { - try - { - $criterias["section"] = Section::by_name($params["section"]); - } - catch(DoesNotExistError $e) {} - } - if(isset($params["tagvar"])) - { - $tagvar = $ste->get_var_by_name($params["tagvar"]); - $criterias["tag"] = $tagvar["__obj"]; - } - if(isset($params["tag"])) - { - try - { - $criterias["tag"] = Tag::by_name($params["tag"]); - } - catch(DoesNotExistError $e) {} - } - - $field = NULL; - $direction = NULL; - if(isset($params["sort"])) - { - list($field, $direction) = explode(" ", $params["sort"]); - if($direction === NULL) - $field = NULL; - $direction = strtoupper($direction); - } - - $result = Article::by_multi($criterias, $field, $direction, @$params["count"], @$params["skip"], @$params["perpage"], @$params["page"], $maxpage); - - $result = array_map(function($article) use ($lang) { return article_transform_ste($article, $lang); }, $result); - - if(isset($params["perpage"]) and isset($params["maxpage"])) - $ste->set_var_by_name($params["maxpage"], $maxpage == 0 ? 1 : $maxpage); - - $output = ""; - foreach($result as $article) - { - $ste->set_var_by_name($params["var"], $article); - $output .= $sub($ste); - } - return $output; + $lang = $ste->vars["language"]; + + if(!isset($params["var"])) + throw new \ste\RuntimeError("Parameter var is needed in article_get!"); + + $criterias = array("langavail" => $lang, "onlyvisible" => True); + if(isset($params["id"])) + $criterias["id"] = $params["id"]; + if(isset($params["urlname"])) + $criterias["urlname"]; + if(isset($params["status"])) + $criterias["status"] = $params["status"]; + if(isset($params["sectionvar"])) + { + $sectionvar = $ste->get_var_by_name($params["sectionvar"]); + $criterias["section"] = $sectionvar["__obj"]; + } + else if(isset($params["section"])) + { + try + { + $criterias["section"] = Section::by_name($params["section"]); + } + catch(DoesNotExistError $e) {} + } + if(isset($params["tagvar"])) + { + $tagvar = $ste->get_var_by_name($params["tagvar"]); + $criterias["tag"] = $tagvar["__obj"]; + } + if(isset($params["tag"])) + { + try + { + $criterias["tag"] = Tag::by_name($params["tag"]); + } + catch(DoesNotExistError $e) {} + } + + $field = NULL; + $direction = NULL; + if(isset($params["sort"])) + { + list($field, $direction) = explode(" ", $params["sort"]); + if($direction === NULL) + $field = NULL; + $direction = strtoupper($direction); + } + + $result = Article::by_multi($criterias, $field, $direction, @$params["count"], @$params["skip"], @$params["perpage"], @$params["page"], $maxpage); + + $result = array_map(function($article) use ($lang) { return article_transform_ste($article, $lang); }, $result); + + if(isset($params["perpage"]) and isset($params["maxpage"])) + $ste->set_var_by_name($params["maxpage"], $maxpage == 0 ? 1 : $maxpage); + + $output = ""; + foreach($result as $article) + { + $ste->set_var_by_name($params["var"], $article); + $output .= $sub($ste); + } + return $output; }); /* * STETag: section_list * Iterate over all sections. * The fields of a section can be looked up at . - * + * * Parameters: - * var - (mandatory) The name of the variable, where the current section should be stored at. - * exclude - (optional) Sections to exclude - * include_default - (optional) Should the default section be included (default: No). - * + * var - (mandatory) The name of the variable, where the current section should be stored at. + * exclude - (optional) Sections to exclude + * include_default - (optional) Should the default section be included (default: No). + * * Tag Content: - * The tag's content will be executed for every section. The current section will be written to the variable specified by the var parameter before. + * The tag's content will be executed for every section. The current section will be written to the variable specified by the var parameter before. * * Returns: - * All results from the tag content. + * All results from the tag content. */ $ste->register_tag("section_list", function($ste, $params, $sub) { - global $ratatoeskr_settings; - $lang = $ste->vars["language"]; - - $default_section = $ratatoeskr_settings["default_section"]; - - if(!isset($params["var"])) - throw new \ste\RuntimeException("Parameter var is needed in article_get!"); - - $result = Section::all(); - - if(isset($params["exclude"])) - { - $exclude = explode(",", $params["exclude"]); - $result = array_filter($result, function($section) use ($exclude) { return !in_array($section->name, $exclude); }); - } - - $result = array_filter($result, function($section) use ($default_section) { return $section->get_id() != $default_section; }); - - $result = array_map(function($section) use ($lang) { return section_transform_ste($section, $lang); }, $result); - - if($ste->evalbool($params["include_default"])) - { - $default = section_transform_ste(Section::by_id($default_section), $lang); - array_unshift($result, $default); - } - - $output = ""; - foreach($result as $section) - { - $ste->set_var_by_name($params["var"], $section); - $output .= $sub($ste); - } - return $output; + global $ratatoeskr_settings; + $lang = $ste->vars["language"]; + + $default_section = $ratatoeskr_settings["default_section"]; + + if(!isset($params["var"])) + throw new \ste\RuntimeException("Parameter var is needed in article_get!"); + + $result = Section::all(); + + if(isset($params["exclude"])) + { + $exclude = explode(",", $params["exclude"]); + $result = array_filter($result, function($section) use ($exclude) { return !in_array($section->name, $exclude); }); + } + + $result = array_filter($result, function($section) use ($default_section) { return $section->get_id() != $default_section; }); + + $result = array_map(function($section) use ($lang) { return section_transform_ste($section, $lang); }, $result); + + if($ste->evalbool($params["include_default"])) + { + $default = section_transform_ste(Section::by_id($default_section), $lang); + array_unshift($result, $default); + } + + $output = ""; + foreach($result as $section) + { + $ste->set_var_by_name($params["var"], $section); + $output .= $sub($ste); + } + return $output; }); /* * STETag: article_comments_count * Get the number of comments for an article. - * + * * Parameters: - * article - (mandatory) The name of the variable, where the article is stored at. - * + * article - (mandatory) The name of the variable, where the article is stored at. + * * Returns: - * The number of comments. + * The number of comments. */ $ste->register_tag("article_comments_count", function($ste, $params, $sub) { - if(!isset($params["article"])) - throw new \ste\RuntimeException("Need parameter 'article' in ste:article_comments_count."); - $tpl_article = $ste->get_var_reference($params["article"], False); - $lang = $ste->vars["language"]; - - if(isset($tpl_article["__obj"])) - $article = $tpl_article["__obj"]; - else - { - try - { - $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { - return 0; - } - } - $comments = $article->get_comments($lang, True); - $tpl_article["__comments"] = $comments; - return count($comments); + if(!isset($params["article"])) + throw new \ste\RuntimeException("Need parameter 'article' in ste:article_comments_count."); + $tpl_article = $ste->get_var_reference($params["article"], False); + $lang = $ste->vars["language"]; + + if(isset($tpl_article["__obj"])) + $article = $tpl_article["__obj"]; + else + { + try + { + $article = Article::by_id(@$tpl_article["id"]); + } + catch(DoesNotExistError $e) + { + return 0; + } + } + $comments = $article->get_comments($lang, True); + $tpl_article["__comments"] = $comments; + return count($comments); }); /* * STETag: article_comments * List all comments for an article. * The fields of a comment can be looked up at . - * + * * Parameters: - * var - (mandatory) The name of the variable, where the current comment should be stored at. - * article - (mandatory) The name of the variable, where the article is stored at. - * sort - (optional) Should the comments be sorted chronologically (asc) or inverse (desc)? Default: asc - * + * var - (mandatory) The name of the variable, where the current comment should be stored at. + * article - (mandatory) The name of the variable, where the article is stored at. + * sort - (optional) Should the comments be sorted chronologically (asc) or inverse (desc)? Default: asc + * * Tag Content: - * The tag's content will be executed for every comment. The current comment will be written to the variable specified by the var parameter before. - * + * The tag's content will be executed for every comment. The current comment will be written to the variable specified by the var parameter before. + * * Returns: - * All results from the tag content. + * All results from the tag content. */ $ste->register_tag("article_comments", function($ste, $params, $sub) { - if(!isset($params["var"])) - throw new \ste\RuntimeException("Need parameter 'var' in ste:article_comments."); - if(!isset($params["article"])) - throw new \ste\RuntimeException("Need parameter 'article' in ste:article_comments."); - $tpl_article = $ste->get_var_reference($params["article"], False); - $lang = $ste->vars["language"]; - - if(isset($tpl_article["__comments"])) - $comments = $tpl_article["__comments"]; - else - { - if(isset($tpl_article["__obj"])) - $article = $tpl_article["__obj"]; - else - { - try - { - $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { - return ""; - } - } - - $comments = $article->get_comments($lang, True); - } - - $sortdir = (@$params["sort"] == "desc") ? -1 : 1; - usort($comments, function($a,$b) use ($sortdir) { return intcmp($a->get_timestamp(), $b->get_timestamp()) * $sortdir; }); - - $comments = array_map("comment_transform_ste", $comments); - - $output = ""; - foreach($comments as $comment) - { - $ste->set_var_by_name($params["var"], $comment); - $output .= $sub($ste); - } - return $output; + if(!isset($params["var"])) + throw new \ste\RuntimeException("Need parameter 'var' in ste:article_comments."); + if(!isset($params["article"])) + throw new \ste\RuntimeException("Need parameter 'article' in ste:article_comments."); + $tpl_article = $ste->get_var_reference($params["article"], False); + $lang = $ste->vars["language"]; + + if(isset($tpl_article["__comments"])) + $comments = $tpl_article["__comments"]; + else + { + if(isset($tpl_article["__obj"])) + $article = $tpl_article["__obj"]; + else + { + try + { + $article = Article::by_id(@$tpl_article["id"]); + } + catch(DoesNotExistError $e) + { + return ""; + } + } + + $comments = $article->get_comments($lang, True); + } + + $sortdir = (@$params["sort"] == "desc") ? -1 : 1; + usort($comments, function($a,$b) use ($sortdir) { return intcmp($a->get_timestamp(), $b->get_timestamp()) * $sortdir; }); + + $comments = array_map("comment_transform_ste", $comments); + + $output = ""; + foreach($comments as $comment) + { + $ste->set_var_by_name($params["var"], $comment); + $output .= $sub($ste); + } + return $output; }); /* * STETag: comment_form * Generates a HTML form tag that allows the visitor to write a comment. - * + * * Parameters: - * article - (mandatory) The name of the variable, where the article is stored at. - * default - (optional) If not empty, a default formular with the mandatory fields will be generated. - * previewbtn - (optional) If not empty and default form is choosen, a preview button will also be generated. - * + * article - (mandatory) The name of the variable, where the article is stored at. + * default - (optional) If not empty, a default formular with the mandatory fields will be generated. + * previewbtn - (optional) If not empty and default form is choosen, a preview button will also be generated. + * * Tag Content: - * The tag's content will be written into the HTML form tag. - * You have at least to define these fields: - * - * * - The Name of the author. - * * - The E-Mailaddress of the author. - * * - The Text of the comment. - * * - Submit button. - * - * You might also want to define this: - * - * * - For a preview of the comment. - * - * If the parameter default is not empty, the tag's content will be thrown away. - * + * The tag's content will be written into the HTML form tag. + * You have at least to define these fields: + * + * * - The Name of the author. + * * - The E-Mailaddress of the author. + * * - The Text of the comment. + * * - Submit button. + * + * You might also want to define this: + * + * * - For a preview of the comment. + * + * If the parameter default is not empty, the tag's content will be thrown away. + * * Returns: - * The finished HTML form. - * + * The finished HTML form. + * * See Also: - * The "prevcomment" field in <$current>. + * The "prevcomment" field in <$current>. */ $ste->register_tag("comment_form", function($ste, $params, $sub) { - global $translation; - if(!isset($params["article"])) - throw new \ste\RuntimeException("Need parameter 'article' in ste:comment_form."); - $tpl_article = $ste->get_var_reference($params["article"], False); - - if(isset($tpl_article["__obj"])) - $article = $tpl_article["__obj"]; - else - { - try - { - $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { - return ""; - } - } - - if(!$article->allow_comments) - return ""; - - /* A token protects from double sending of the same form and is also a simple protection from stupid spambots. */ - $token = uniqid("", True); - $_SESSION["ratatoeskr_comment_tokens"][$token] = time(); - - $form_header = "
"; - - $previewbtn = $ste->evalbool(@$params["previewbtn"]) ? " " : ""; - - if($ste->evalbool(@$params["default"])) - $form_body = "

{$translation["comment_form_name"]}:

+ global $translation; + if(!isset($params["article"])) + throw new \ste\RuntimeException("Need parameter 'article' in ste:comment_form."); + $tpl_article = $ste->get_var_reference($params["article"], False); + + if(isset($tpl_article["__obj"])) + $article = $tpl_article["__obj"]; + else + { + try + { + $article = Article::by_id(@$tpl_article["id"]); + } + catch(DoesNotExistError $e) + { + return ""; + } + } + + if(!$article->allow_comments) + return ""; + + /* A token protects from double sending of the same form and is also a simple protection from stupid spambots. */ + $token = uniqid("", True); + $_SESSION["ratatoeskr_comment_tokens"][$token] = time(); + + $form_header = ""; + + $previewbtn = $ste->evalbool(@$params["previewbtn"]) ? " " : ""; + + if($ste->evalbool(@$params["default"])) + $form_body = "

{$translation["comment_form_name"]}:

{$translation["comment_form_mail"]}:

{$translation["comment_form_text"]}:

$previewbtn

"; - else - { - $ste->vars["current"]["oldcomment"] = array( - "name" => @$_POST["author_name"], - "mail" => @$_POST["author_mail"], - "text" => @$_POST["comment_text"] - ); - $form_body = $sub($ste); - unset($ste->vars["current"]["oldcomment"]); - } - - return "$form_header\n$form_body\n
"; + else + { + $ste->vars["current"]["oldcomment"] = array( + "name" => @$_POST["author_name"], + "mail" => @$_POST["author_mail"], + "text" => @$_POST["comment_text"] + ); + $form_body = $sub($ste); + unset($ste->vars["current"]["oldcomment"]); + } + + return "$form_header\n$form_body\n"; }); /* * STETags: Page control * These tags can create links to the previous/next page. - * + * * page_prev - Link to the previous page (if available). * page_next - Link to the next page (if available). - * + * * Parameters: - * current - (mandatory) The current page number. - * maxpage - (mandatory) How many pages in total? - * default - (optional) If not empty, a default localized link text will be used. - * + * current - (mandatory) The current page number. + * maxpage - (mandatory) How many pages in total? + * default - (optional) If not empty, a default localized link text will be used. + * * Tag Content: - * The tag's content will be used as the link text. - * + * The tag's content will be used as the link text. + * * Returns: - * A Link to the previous / next page. + * A Link to the previous / next page. */ $ste->register_tag("page_prev", function($ste, $params, $sub) { - global $translation; - if(!isset($params["current"])) - throw new \ste\RuntimeException("Need parameter 'current' in ste:page_prev."); - if(!isset($params["maxpage"])) - throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_prev."); - - if($params["current"] == 1) - return ""; - - parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); - $query["page"] = $params["current"] - 1; - $url = $_SERVER["REDIRECT_URL"] . "?" . http_build_query($query); - return "" . (($ste->evalbool(@$params["default"])) ? $translation["page_prev"] : $sub($ste)) . ""; + global $translation; + if(!isset($params["current"])) + throw new \ste\RuntimeException("Need parameter 'current' in ste:page_prev."); + if(!isset($params["maxpage"])) + throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_prev."); + + if($params["current"] == 1) + return ""; + + parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); + $query["page"] = $params["current"] - 1; + $url = $_SERVER["REDIRECT_URL"] . "?" . http_build_query($query); + return "" . (($ste->evalbool(@$params["default"])) ? $translation["page_prev"] : $sub($ste)) . ""; }); $ste->register_tag("page_next", function($ste, $params, $sub) { - global $translation; - if(!isset($params["current"])) - throw new \ste\RuntimeException("Need parameter 'current' in ste:page_next."); - if(!isset($params["maxpage"])) - throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_next."); - - if($params["current"] == $params["maxpage"]) - return ""; - - parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); - $query["page"] = $params["current"] + 1; - $url = $_SERVER["REDIRECT_URL"] . "?" . http_build_query($query); - return "" . (($ste->evalbool(@$params["default"])) ? $translation["page_next"] : $sub($ste)) . ""; + global $translation; + if(!isset($params["current"])) + throw new \ste\RuntimeException("Need parameter 'current' in ste:page_next."); + if(!isset($params["maxpage"])) + throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_next."); + + if($params["current"] == $params["maxpage"]) + return ""; + + parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); + $query["page"] = $params["current"] + 1; + $url = $_SERVER["REDIRECT_URL"] . "?" . http_build_query($query); + return "" . (($ste->evalbool(@$params["default"])) ? $translation["page_next"] : $sub($ste)) . ""; }); /* * STETag: languages * List all languages available in the current context. - * + * * Parameters: - * var - (mandatory) The name of the variable, where the current language information should be stored at. - * + * var - (mandatory) The name of the variable, where the current language information should be stored at. + * * Sub-fields of var: - * short - 2 letter code of language - * fullname - The full name of the language - * url - URL to the current page in this language + * short - 2 letter code of language + * fullname - The full name of the language + * url - URL to the current page in this language * * Tag Content: - * The tag's content will be executed for every language. The current language will be written to the variable specified by the var parameter before. - * + * The tag's content will be executed for every language. The current language will be written to the variable specified by the var parameter before. + * * Returns: - * All results from the tag content. + * All results from the tag content. */ $ste->register_tag("languages", function($ste, $params, $sub) { - global $languages, $ratatoeskr_settings, $rel_path_to_root; - - if(!isset($params["var"])) - throw new Exception("Need parameter 'var' in ste:languages."); - - $langs = array(); - if(isset($ste->vars["current"]["article"])) - { - if(isset($ste->vars["current"]["article"]["__obj"])) - $article = $ste->vars["current"]["article"]["__obj"]; - else - { - try - { - $article = Article::by_id($ste->vars["current"]["article"]["id"]); - } - catch(DoesNotExistError $e) {} - } - foreach($article->title as $lang => $_) - $langs[] = $lang; - } - else - { - - foreach($ratatoeskr_settings["languages"] as $lang) - $langs[] = $lang; - } - - $output = ""; - foreach($langs as $lang) - { - $ste->set_var_by_name($params["var"], array( - "short" => $lang, - "fullname" => htmlesc($languages[$lang]["language"]), - "url" => htmlesc("$rel_path_to_root/$lang/" . implode("/", array_slice($ste->vars["current"]["url_fragments"], 1))) - )); - $output .= $sub($ste); - } - return $output; + global $languages, $ratatoeskr_settings, $rel_path_to_root; + + if(!isset($params["var"])) + throw new Exception("Need parameter 'var' in ste:languages."); + + $langs = array(); + if(isset($ste->vars["current"]["article"])) + { + if(isset($ste->vars["current"]["article"]["__obj"])) + $article = $ste->vars["current"]["article"]["__obj"]; + else + { + try + { + $article = Article::by_id($ste->vars["current"]["article"]["id"]); + } + catch(DoesNotExistError $e) {} + } + foreach($article->title as $lang => $_) + $langs[] = $lang; + } + else + { + + foreach($ratatoeskr_settings["languages"] as $lang) + $langs[] = $lang; + } + + $output = ""; + foreach($langs as $lang) + { + $ste->set_var_by_name($params["var"], array( + "short" => $lang, + "fullname" => htmlesc($languages[$lang]["language"]), + "url" => htmlesc("$rel_path_to_root/$lang/" . implode("/", array_slice($ste->vars["current"]["url_fragments"], 1))) + )); + $output .= $sub($ste); + } + return $output; }); /* * STETag: styles_load * Load all current styles. - * + * * Parameters: - * mode - (optional) Either "embed" or "link". Default: link - * + * mode - (optional) Either "embed" or "link". Default: link + * * Returns: - * The current styles (either linked or embedded) + * The current styles (either linked or embedded) */ $ste->register_tag("styles_load", function($ste, $params, $sub) { - global $rel_path_to_root; - if(isset($params["mode"]) and (($params["mode"] == "embed") or ($params["mode"] == "link"))) - $mode = $params["mode"]; - else - $mode = "link"; - - if($mode == "embed") - { - $output = ""; - if(isset($ste->vars["current"]["__style_objs"])) - { - foreach($ste->vars["current"]["__style_objs"] as $style) - $output .= "/* Style: {$style->name} */\n" . $style->code . "\n"; - } - else - { - foreach($ste->vars["current"]["styles"] as $stylename) - { - try - { - $style = Style::by_name($stylename); - $output .= "/* Style: $stylename */\n" . str_replace("%root%", $rel_path_to_root, $style->code) . "\n"; - } - catch(DoesNotExistError $e) - { - $output .= "/* Warning: Failed to load style: $stylename */\n"; - } - } - } - $output = ""; - } - else - { - $output = ""; - foreach($ste->vars["current"]["styles"] as $stylename) - $output .= "\n"; - } - return $output; + global $rel_path_to_root; + if(isset($params["mode"]) and (($params["mode"] == "embed") or ($params["mode"] == "link"))) + $mode = $params["mode"]; + else + $mode = "link"; + + if($mode == "embed") + { + $output = ""; + if(isset($ste->vars["current"]["__style_objs"])) + { + foreach($ste->vars["current"]["__style_objs"] as $style) + $output .= "/* Style: {$style->name} */\n" . $style->code . "\n"; + } + else + { + foreach($ste->vars["current"]["styles"] as $stylename) + { + try + { + $style = Style::by_name($stylename); + $output .= "/* Style: $stylename */\n" . str_replace("%root%", $rel_path_to_root, $style->code) . "\n"; + } + catch(DoesNotExistError $e) + { + $output .= "/* Warning: Failed to load style: $stylename */\n"; + } + } + } + $output = ""; + } + else + { + $output = ""; + foreach($ste->vars["current"]["styles"] as $stylename) + $output .= "\n"; + } + return $output; }); /* * STETag: title * Generate a HTML title tag for your site. - * + * * Tag Content: - * The name of your site. - * + * The name of your site. + * * Returns: - * A HTML title tag that describes the current (sub)page. + * A HTML title tag that describes the current (sub)page. */ $ste->register_tag("title", function($ste, $params, $sub) { - $pagetitle = $sub($ste); - if(isset($ste->vars["current"]["article"])) - return "" . htmlesc($ste->vars["current"]["article"]["title"]) . " – $pagetitle" . ""; - if(isset($ste->vars["current"]["section"])) - return "" . htmlesc($ste->vars["current"]["section"]["title"]) . " – $pagetitle" . ""; - return "$pagetitle"; + $pagetitle = $sub($ste); + if(isset($ste->vars["current"]["article"])) + return "" . htmlesc($ste->vars["current"]["article"]["title"]) . " – $pagetitle" . ""; + if(isset($ste->vars["current"]["section"])) + return "" . htmlesc($ste->vars["current"]["section"]["title"]) . " – $pagetitle" . ""; + return "$pagetitle"; }); function make_on_anything_tag($field) { - return function($ste, $params, $sub) use ($field) - { - if($ste->evalbool(@$ste->vars["current"][$field])) - { - if(!empty($params["var"])) - $ste->set_var_by_name($params["var"], $ste->vars["current"][$field]); - return $sub($ste); - } - }; + return function($ste, $params, $sub) use ($field) + { + if($ste->evalbool(@$ste->vars["current"][$field])) + { + if(!empty($params["var"])) + $ste->set_var_by_name($params["var"], $ste->vars["current"][$field]); + return $sub($ste); + } + }; } /* @@ -679,10 +679,10 @@ function make_on_anything_tag($field) * Execute tag content, if currently an article is requested. * * Parameters: - * var - (optional) If set, the article will be stored in the variable with that name (see for sub-fields). + * var - (optional) If set, the article will be stored in the variable with that name (see for sub-fields). * * Returns: - * The executed tag content, if an article was requested. + * The executed tag content, if an article was requested. */ $ste->register_tag("on_article", make_on_anything_tag("article")); @@ -691,10 +691,10 @@ $ste->register_tag("on_article", make_on_anything_tag("article")); * Execute tag content, if currently a tag is requested. * * Parameters: - * var - (optional) If set, the tag will be stored in the variable with that name (see for sub-fields). + * var - (optional) If set, the tag will be stored in the variable with that name (see for sub-fields). * * Returns: - * The executed tag content, if a tag was requested. + * The executed tag content, if a tag was requested. */ $ste->register_tag("on_tag", make_on_anything_tag("tag")); @@ -703,30 +703,30 @@ $ste->register_tag("on_tag", make_on_anything_tag("tag")); * Execute tag content, if currently a section is requested. * * Parameters: - * var - (optional) If set, the section will be stored in the variable with that name (see for sub-fields). + * var - (optional) If set, the section will be stored in the variable with that name (see for sub-fields). * * Returns: - * The executed tag content, if a section was requested. + * The executed tag content, if a section was requested. */ $ste->register_tag("on_section", make_on_anything_tag("section")); /* * STEVar: $current * Holds information about the current page in the frontend (the part of the webpage, the visitor sees). - * + * * $current has these fields: - * * article - Only set if a single article is shown. Holds information about an article. (sub-fields are described at ). - * * section - Only set if a whole section is shown. Holds information about an section. (sub-fields are described at ). - * * tag - Only set if all articles with the same tag should be shown (pseudo section _tags). Holds information about a tag. (sub-fields are described at ). - * * page - Which subpage is shown? Useful with , and the page parameter of . Default: 1 - * * commented - True, if the visitor has successfully written a comment. - * * comment_fail - If the user tried to comment, but the system rejected the comment, this will be set and will contain the error message. - * * comment_prev - If the user wanted to preview the article, this will be set and contain the HTML code of the comment. - * * styles - The styles, that should be loaded. You can also just use . - * * url_fragments - Array of URL parts. Mainly used internally, so you *really* should not modify this one... - * * oldcomment - The data of the previously sent formular (subfields: name, mail, text). Only set inside the tag. - * - * Plugins might insert their own $current fields. + * * article - Only set if a single article is shown. Holds information about an article. (sub-fields are described at ). + * * section - Only set if a whole section is shown. Holds information about an section. (sub-fields are described at ). + * * tag - Only set if all articles with the same tag should be shown (pseudo section _tags). Holds information about a tag. (sub-fields are described at ). + * * page - Which subpage is shown? Useful with , and the page parameter of . Default: 1 + * * commented - True, if the visitor has successfully written a comment. + * * comment_fail - If the user tried to comment, but the system rejected the comment, this will be set and will contain the error message. + * * comment_prev - If the user wanted to preview the article, this will be set and contain the HTML code of the comment. + * * styles - The styles, that should be loaded. You can also just use . + * * url_fragments - Array of URL parts. Mainly used internally, so you *really* should not modify this one... + * * oldcomment - The data of the previously sent formular (subfields: name, mail, text). Only set inside the tag. + * + * Plugins might insert their own $current fields. */ /* @@ -735,23 +735,23 @@ $ste->register_tag("on_section", make_on_anything_tag("section")); */ $comment_validators = array( - function() /* Basic validator. Checks, if all mandatory fields are set and if the form token is okay. Also provides some stupid spambot protection... */ - { - global $translation; - if(empty($_POST["author_name"])) - throw new CommentRejected($translation["author_name_missing"]); - if(empty($_POST["author_mail"])) - throw new CommentRejected($translation["author_email_missing"]); - if(empty($_POST["comment_text"])) - throw new CommentRejected($translation["comment_text_missing"]); - if(!isset($_POST["comment_token"])) - throw new CommentRejected($translation["comment_form_invalid"]); - if(!isset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]])) - throw new CommentRejected($translation["comment_form_invalid"]); - if(time() - $_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]] < 10) /* Comment filled in in under 10 seconds? Most likely a spambot. */ - throw new CommentRejected($translation["comment_too_fast"]); - unset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]]); - } + function() /* Basic validator. Checks, if all mandatory fields are set and if the form token is okay. Also provides some stupid spambot protection... */ + { + global $translation; + if(empty($_POST["author_name"])) + throw new CommentRejected($translation["author_name_missing"]); + if(empty($_POST["author_mail"])) + throw new CommentRejected($translation["author_email_missing"]); + if(empty($_POST["comment_text"])) + throw new CommentRejected($translation["comment_text_missing"]); + if(!isset($_POST["comment_token"])) + throw new CommentRejected($translation["comment_form_invalid"]); + if(!isset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]])) + throw new CommentRejected($translation["comment_form_invalid"]); + if(time() - $_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]] < 10) /* Comment filled in in under 10 seconds? Most likely a spambot. */ + throw new CommentRejected($translation["comment_too_fast"]); + unset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]]); + } ); $on_comment_store = array(); @@ -761,123 +761,123 @@ $on_comment_store = array(); */ function frontend_url_handler(&$data, $url_now, &$url_next) { - global $ste, $ratatoeskr_settings, $languages, $metasections, $comment_validators, $on_comment_store; - $path = array_merge(array($url_now), $url_next); - $url_next = array(); - - /* If no language or an invalid language was given, fix it. */ - if((count($path) == 0) or (!isset($languages[$path[0]]))) - { - if(count($path > 0)) - array_shift($path); - array_unshift($path, $ratatoeskr_settings["default_language"]); - } - - $ste->vars["current"]["url_fragments"] = $path; - - $lang = array_shift($path); - $ste->vars["language"] = $lang; - load_language($languages[$lang]["translation_exist"] ? $lang : "en"); /* English is always available */ - - if(count($path) != 0) - $section_name = array_shift($path); - else - $section_name = NULL; - - if($section_name == "_tags") - { - try - { - $tag = Tag::by_name(array_shift($path)); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - $ste->vars["current"]["tag"] = tag_transform_ste($tag, $lang); - } - else - { - if($section_name === NULL) - $section = Section::by_id($ratatoeskr_settings["default_section"]); - else - { - try - { - $section = Section::by_name($section_name); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - } - - if(count($path)== 0) - $ste->vars["current"]["section"] = section_transform_ste($section, $lang); - else - { - try - { - $article = Article::by_urlname(array_shift($path)); - } - catch(DoesNotExistError $e) - { - throw new NotFoundError(); - } - $ste->vars["current"]["article"] = article_transform_ste($article, $lang); - - if(isset($_GET["comment"])) - { - if(isset($_POST["preview_comment"])) - $ste->vars["current"]["comment_prev"] = Comment::htmlize_comment_text($_POST["comment_text"]); - else if(isset($_POST["post_comment"])) - { - $rejected = False; - try - { - foreach($comment_validators as $validator) - call_user_func($validator); - } - catch(CommentRejected $e) - { - $ste->vars["current"]["comment_fail"] = htmlesc($e->getMessage()); - $rejected = True; - } - if(!$rejected) - { - $comment = Comment::create($article, $lang); - $comment->author_name = $_POST["author_name"]; - $comment->author_mail = $_POST["author_mail"]; - $comment->text = $_POST["comment_text"]; - $comment->save(); - $ste->vars["current"]["commented"] = "Yes"; - foreach($on_comment_store as $ocs_fx) - call_user_func($ocs_fx, $comment); - } - } - } - } - } - - $ste->vars["current"]["page"] = (isset($_GET["page"]) and is_numeric($_GET["page"])) ? $_GET["page"] : 1; - - if(!isset($section)) - $section = Section::by_id($ratatoeskr_settings["default_section"]); - - foreach($section->get_styles() as $style) - { - $ste->vars["current"]["styles"][] = $style->name; - $ste->vars["current"]["__style_objs"][] = $style; - } - echo $ste->exectemplate("/usertemplates/" . $section->template); + global $ste, $ratatoeskr_settings, $languages, $metasections, $comment_validators, $on_comment_store; + $path = array_merge(array($url_now), $url_next); + $url_next = array(); + + /* If no language or an invalid language was given, fix it. */ + if((count($path) == 0) or (!isset($languages[$path[0]]))) + { + if(count($path > 0)) + array_shift($path); + array_unshift($path, $ratatoeskr_settings["default_language"]); + } + + $ste->vars["current"]["url_fragments"] = $path; + + $lang = array_shift($path); + $ste->vars["language"] = $lang; + load_language($languages[$lang]["translation_exist"] ? $lang : "en"); /* English is always available */ + + if(count($path) != 0) + $section_name = array_shift($path); + else + $section_name = NULL; + + if($section_name == "_tags") + { + try + { + $tag = Tag::by_name(array_shift($path)); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + $ste->vars["current"]["tag"] = tag_transform_ste($tag, $lang); + } + else + { + if($section_name === NULL) + $section = Section::by_id($ratatoeskr_settings["default_section"]); + else + { + try + { + $section = Section::by_name($section_name); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + } + + if(count($path)== 0) + $ste->vars["current"]["section"] = section_transform_ste($section, $lang); + else + { + try + { + $article = Article::by_urlname(array_shift($path)); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + $ste->vars["current"]["article"] = article_transform_ste($article, $lang); + + if(isset($_GET["comment"])) + { + if(isset($_POST["preview_comment"])) + $ste->vars["current"]["comment_prev"] = Comment::htmlize_comment_text($_POST["comment_text"]); + else if(isset($_POST["post_comment"])) + { + $rejected = False; + try + { + foreach($comment_validators as $validator) + call_user_func($validator); + } + catch(CommentRejected $e) + { + $ste->vars["current"]["comment_fail"] = htmlesc($e->getMessage()); + $rejected = True; + } + if(!$rejected) + { + $comment = Comment::create($article, $lang); + $comment->author_name = $_POST["author_name"]; + $comment->author_mail = $_POST["author_mail"]; + $comment->text = $_POST["comment_text"]; + $comment->save(); + $ste->vars["current"]["commented"] = "Yes"; + foreach($on_comment_store as $ocs_fx) + call_user_func($ocs_fx, $comment); + } + } + } + } + } + + $ste->vars["current"]["page"] = (isset($_GET["page"]) and is_numeric($_GET["page"])) ? $_GET["page"] : 1; + + if(!isset($section)) + $section = Section::by_id($ratatoeskr_settings["default_section"]); + + foreach($section->get_styles() as $style) + { + $ste->vars["current"]["styles"][] = $style->name; + $ste->vars["current"]["__style_objs"][] = $style; + } + echo $ste->exectemplate("/usertemplates/" . $section->template); } /* * Class: CommentRejected * An Exeption a comment validator can throw, if the validation failed. - * + * * See Also: - * + * */ class CommentRejected extends Exception {} diff --git a/ratatoeskr/js/backend.js b/ratatoeskr/js/backend.js index d131bfe..8b60c2d 100644 --- a/ratatoeskr/js/backend.js +++ b/ratatoeskr/js/backend.js @@ -1,19 +1,19 @@ $(function() { - $("div.articleeditor-metabar-element h2").addClass("metabar_element_expanded").click(function() - { - self = $(this); - if(self.hasClass("metabar_element_expanded")) - { - self.removeClass("metabar_element_expanded"); - self.addClass("metabar_element_collapsed"); - $("div.articleeditor-metabar-element-content", self.parent()).hide("fast"); - } - else - { - self.removeClass("metabar_element_collapsed"); - self.addClass("metabar_element_expanded"); - $("div.articleeditor-metabar-element-content", self.parent()).show("fast"); - } - }); + $("div.articleeditor-metabar-element h2").addClass("metabar_element_expanded").click(function() + { + self = $(this); + if(self.hasClass("metabar_element_expanded")) + { + self.removeClass("metabar_element_expanded"); + self.addClass("metabar_element_collapsed"); + $("div.articleeditor-metabar-element-content", self.parent()).hide("fast"); + } + else + { + self.removeClass("metabar_element_collapsed"); + self.addClass("metabar_element_expanded"); + $("div.articleeditor-metabar-element-content", self.parent()).show("fast"); + } + }); }); \ No newline at end of file diff --git a/ratatoeskr/languages.php b/ratatoeskr/languages.php index 7b2f515..be59e09 100644 --- a/ratatoeskr/languages.php +++ b/ratatoeskr/languages.php @@ -7,200 +7,200 @@ /* * Array: $languages * Information about a lot of languages. - * + * * $languages is a global array. The array keys represent the ISO 639-1 code of the language. * The values are arrays with these keys: - * + * * "language" - The Name of the language in this language (UTF-8 encoded) * "translation_exist" - True, if there is a translation file for this language. * * Source: - * http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes + * http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes */ $languages = array( - "aa" => array("language" => "Afaraf", "translation_exist" => False), - "ab" => array("language" => "аҧсуа", "translation_exist" => False), - "ae" => array("language" => "avesta", "translation_exist" => False), - "af" => array("language" => "Afrikaans", "translation_exist" => False), - "ak" => array("language" => "Akan", "translation_exist" => False), - "am" => array("language" => "አማርኛ", "translation_exist" => False), - "an" => array("language" => "Aragonés", "translation_exist" => False), - "ar" => array("language" => "العربية", "translation_exist" => False), - "as" => array("language" => "অসমীয়া", "translation_exist" => False), - "av" => array("language" => "авар мацӀ, магӀарул мацӀ", "translation_exist" => False), - "ay" => array("language" => "aymar aru", "translation_exist" => False), - "az" => array("language" => "azərbaycan dili", "translation_exist" => False), - "ba" => array("language" => "башҡорт теле", "translation_exist" => False), - "be" => array("language" => "Беларуская", "translation_exist" => False), - "bg" => array("language" => "български език", "translation_exist" => False), - "bh" => array("language" => "भोजपुरी", "translation_exist" => False), - "bi" => array("language" => "Bislama", "translation_exist" => False), - "bm" => array("language" => "bamanankan", "translation_exist" => False), - "bn" => array("language" => "বাংলা", "translation_exist" => False), - "bo" => array("language" => "བོད་ཡིག", "translation_exist" => False), - "br" => array("language" => "brezhoneg", "translation_exist" => False), - "bs" => array("language" => "bosanski jezik", "translation_exist" => False), - "ca" => array("language" => "Català", "translation_exist" => False), - "ce" => array("language" => "нохчийн мотт", "translation_exist" => False), - "ch" => array("language" => "Chamoru", "translation_exist" => False), - "co" => array("language" => "corsu, lingua corsa", "translation_exist" => False), - "cr" => array("language" => "ᓀᐦᐃᔭᐍᐏᐣ", "translation_exist" => False), - "cs" => array("language" => "česky, čeština", "translation_exist" => False), - "cu" => array("language" => "ѩзыкъ словѣньскъ", "translation_exist" => False), - "cv" => array("language" => "чӑваш чӗлхи", "translation_exist" => False), - "cy" => array("language" => "Cymraeg", "translation_exist" => False), - "da" => array("language" => "dansk", "translation_exist" => False), - "de" => array("language" => "Deutsch", "translation_exist" => True), - "dv" => array("language" => "ދިވެހި", "translation_exist" => False), - "dz" => array("language" => "རྫོང་ཁ", "translation_exist" => False), - "ee" => array("language" => "Eʋegbe", "translation_exist" => False), - "el" => array("language" => "Ελληνικά", "translation_exist" => False), - "en" => array("language" => "English", "translation_exist" => True), - "eo" => array("language" => "Esperanto", "translation_exist" => False), - "es" => array("language" => "español, castellano", "translation_exist" => False), - "et" => array("language" => "eesti, eesti keel", "translation_exist" => False), - "eu" => array("language" => "euskara, euskera", "translation_exist" => False), - "fa" => array("language" => "فارسی", "translation_exist" => False), - "ff" => array("language" => "Fulfulde, Pulaar, Pular", "translation_exist" => False), - "fi" => array("language" => "suomi, suomen kieli", "translation_exist" => False), - "fj" => array("language" => "vosa Vakaviti", "translation_exist" => False), - "fo" => array("language" => "føroyskt", "translation_exist" => False), - "fr" => array("language" => "français, langue française", "translation_exist" => False), - "fy" => array("language" => "Frysk", "translation_exist" => False), - "ga" => array("language" => "Gaeilge", "translation_exist" => False), - "gd" => array("language" => "Gàidhlig", "translation_exist" => False), - "gl" => array("language" => "Galego", "translation_exist" => False), - "gn" => array("language" => "Avañe'ẽ", "translation_exist" => False), - "gu" => array("language" => "ગુજરાતી", "translation_exist" => False), - "gv" => array("language" => "Gaelg, Gailck", "translation_exist" => False), - "ha" => array("language" => "Hausa, هَوُسَ", "translation_exist" => False), - "he" => array("language" => "עברית", "translation_exist" => False), - "hi" => array("language" => "हिन्दी, हिंदी", "translation_exist" => False), - "ho" => array("language" => "Hiri Motu", "translation_exist" => False), - "hr" => array("language" => "hrvatski", "translation_exist" => False), - "ht" => array("language" => "Kreyòl ayisyen", "translation_exist" => False), - "hu" => array("language" => "Magyar", "translation_exist" => False), - "hy" => array("language" => "Հայերեն", "translation_exist" => False), - "hz" => array("language" => "Otjiherero", "translation_exist" => False), - "ia" => array("language" => "Interlingua", "translation_exist" => False), - "id" => array("language" => "Bahasa Indonesia", "translation_exist" => False), - "ie" => array("language" => "Originally called ", "translation_exist" => False), - "ig" => array("language" => "Asụsụ Igbo", "translation_exist" => False), - "ii" => array("language" => "ꆈꌠ꒿ Nuosuhxop", "translation_exist" => False), - "ik" => array("language" => "Iñupiaq, Iñupiatun", "translation_exist" => False), - "io" => array("language" => "Ido", "translation_exist" => False), - "is" => array("language" => "Íslenska", "translation_exist" => False), - "it" => array("language" => "Italiano", "translation_exist" => False), - "iu" => array("language" => "ᐃᓄᒃᑎᑐᑦ", "translation_exist" => False), - "ja" => array("language" => "日本語 (にほんご)", "translation_exist" => False), - "jv" => array("language" => "basa Jawa", "translation_exist" => False), - "ka" => array("language" => "ქართული", "translation_exist" => False), - "kg" => array("language" => "KiKongo", "translation_exist" => False), - "ki" => array("language" => "Gĩkũyũ", "translation_exist" => False), - "kj" => array("language" => "Kuanyama", "translation_exist" => False), - "kk" => array("language" => "Қазақ тілі", "translation_exist" => False), - "kl" => array("language" => "kalaallisut, kalaallit oqaasii", "translation_exist" => False), - "km" => array("language" => "ភាសាខ្មែរ", "translation_exist" => False), - "kn" => array("language" => "ಕನ್ನಡ", "translation_exist" => False), - "ko" => array("language" => "한국어 (韓國語), 조선어 (朝鮮語)", "translation_exist" => False), - "kr" => array("language" => "Kanuri", "translation_exist" => False), - "ks" => array("language" => "कश्मीरी, كشميري‎", "translation_exist" => False), - "ku" => array("language" => "Kurdî, كوردی‎", "translation_exist" => False), - "kv" => array("language" => "коми кыв", "translation_exist" => False), - "kw" => array("language" => "Kernewek", "translation_exist" => False), - "ky" => array("language" => "кыргыз тили", "translation_exist" => False), - "la" => array("language" => "latine, lingua latina", "translation_exist" => False), - "lb" => array("language" => "Lëtzebuergesch", "translation_exist" => False), - "lg" => array("language" => "Luganda", "translation_exist" => False), - "li" => array("language" => "Limburgs", "translation_exist" => False), - "ln" => array("language" => "Lingála", "translation_exist" => False), - "lo" => array("language" => "ພາສາລາວ", "translation_exist" => False), - "lt" => array("language" => "lietuvių kalba", "translation_exist" => False), - "lu" => array("language" => "Luba-Katanga", "translation_exist" => False), - "lv" => array("language" => "latviešu valoda", "translation_exist" => False), - "mg" => array("language" => "Malagasy fiteny", "translation_exist" => False), - "mh" => array("language" => "Kajin M̧ajeļ", "translation_exist" => False), - "mi" => array("language" => "te reo Māori", "translation_exist" => False), - "mk" => array("language" => "македонски јазик", "translation_exist" => False), - "ml" => array("language" => "മലയാളം", "translation_exist" => False), - "mn" => array("language" => "монгол", "translation_exist" => False), - "mr" => array("language" => "मराठी", "translation_exist" => False), - "ms" => array("language" => "bahasa Melayu, بهاس ملايو‎", "translation_exist" => False), - "mt" => array("language" => "Malti", "translation_exist" => False), - "my" => array("language" => "ဗမာစာ", "translation_exist" => False), - "na" => array("language" => "Ekakairũ Naoero", "translation_exist" => False), - "nb" => array("language" => "Norsk bokmål", "translation_exist" => False), - "nd" => array("language" => "isiNdebele", "translation_exist" => False), - "ne" => array("language" => "नेपाली", "translation_exist" => False), - "ng" => array("language" => "Owambo", "translation_exist" => False), - "nl" => array("language" => "Nederlands, Vlaams", "translation_exist" => False), - "nn" => array("language" => "Norsk nynorsk", "translation_exist" => False), - "no" => array("language" => "Norsk", "translation_exist" => False), - "nr" => array("language" => "isiNdebele", "translation_exist" => False), - "nv" => array("language" => "Diné bizaad, Dinékʼehǰí", "translation_exist" => False), - "ny" => array("language" => "chiCheŵa, chinyanja", "translation_exist" => False), - "oc" => array("language" => "Occitan", "translation_exist" => False), - "oj" => array("language" => "ᐊᓂᔑᓈᐯᒧᐎᓐ", "translation_exist" => False), - "om" => array("language" => "Afaan Oromoo", "translation_exist" => False), - "or" => array("language" => "ଓଡ଼ିଆ", "translation_exist" => False), - "os" => array("language" => "ирон æвзаг", "translation_exist" => False), - "pa" => array("language" => "ਪੰਜਾਬੀ, پنجابی‎", "translation_exist" => False), - "pi" => array("language" => "पाऴि", "translation_exist" => False), - "pl" => array("language" => "polski", "translation_exist" => False), - "ps" => array("language" => "پښتو", "translation_exist" => False), - "pt" => array("language" => "Português", "translation_exist" => False), - "qu" => array("language" => "Runa Simi, Kichwa", "translation_exist" => False), - "rm" => array("language" => "rumantsch grischun", "translation_exist" => False), - "rn" => array("language" => "Ikirundi", "translation_exist" => False), - "ro" => array("language" => "română", "translation_exist" => False), - "ru" => array("language" => "русский язык", "translation_exist" => False), - "rw" => array("language" => "Ikinyarwanda", "translation_exist" => False), - "sa" => array("language" => "संस्कृतम्", "translation_exist" => False), - "sc" => array("language" => "sardu", "translation_exist" => False), - "sd" => array("language" => "yângâ tî sängö", "translation_exist" => False), - "se" => array("language" => "Davvisámegiella", "translation_exist" => False), - "sg" => array("language" => "yângâ tî sängö", "translation_exist" => False), - "si" => array("language" => "සිංහල", "translation_exist" => False), - "sk" => array("language" => "slovenčina", "translation_exist" => False), - "sl" => array("language" => "slovenščina", "translation_exist" => False), - "sm" => array("language" => "gagana fa'a Samoa", "translation_exist" => False), - "sn" => array("language" => "chiShona", "translation_exist" => False), - "so" => array("language" => "Soomaaliga, af Soomaali", "translation_exist" => False), - "sq" => array("language" => "Shqip", "translation_exist" => False), - "sr" => array("language" => "српски језик", "translation_exist" => False), - "ss" => array("language" => "SiSwati", "translation_exist" => False), - "st" => array("language" => "Sesotho", "translation_exist" => False), - "su" => array("language" => "Basa Sunda", "translation_exist" => False), - "sv" => array("language" => "svenska", "translation_exist" => False), - "sw" => array("language" => "Kiswahili", "translation_exist" => False), - "ta" => array("language" => "தமிழ்", "translation_exist" => False), - "te" => array("language" => "తెలుగు", "translation_exist" => False), - "tg" => array("language" => " тоҷикӣ, toğikī, تاجیکی‎", "translation_exist" => False), - "th" => array("language" => "ไทย", "translation_exist" => False), - "ti" => array("language" => "ትግርኛ", "translation_exist" => False), - "tk" => array("language" => "Türkmen, Түркмен", "translation_exist" => False), - "tl" => array("language" => "Wikang Tagalog", "translation_exist" => False), - "tn" => array("language" => "Setswana", "translation_exist" => False), - "to" => array("language" => "faka Tonga", "translation_exist" => False), - "tr" => array("language" => "Türkçe", "translation_exist" => False), - "ts" => array("language" => "Xitsonga", "translation_exist" => False), - "tt" => array("language" => "татарча, tatarça, تاتارچا‎", "translation_exist" => False), - "tw" => array("language" => "Twi", "translation_exist" => False), - "ty" => array("language" => "Reo Tahiti", "translation_exist" => False), - "ug" => array("language" => "Uyƣurqə, ئۇيغۇرچە‎", "translation_exist" => False), - "uk" => array("language" => "українська", "translation_exist" => False), - "ur" => array("language" => "اردو", "translation_exist" => False), - "uz" => array("language" => "O'zbek, Ўзбек, أۇزبېك‎", "translation_exist" => False), - "ve" => array("language" => "Tshivenḓa", "translation_exist" => False), - "vi" => array("language" => "Tiếng Việt", "translation_exist" => False), - "vo" => array("language" => "Volapük", "translation_exist" => False), - "wa" => array("language" => "Walon", "translation_exist" => False), - "wo" => array("language" => "Wollof", "translation_exist" => False), - "xh" => array("language" => "isiXhosa", "translation_exist" => False), - "yi" => array("language" => "ייִדיש", "translation_exist" => False), - "yo" => array("language" => "Yorùbá", "translation_exist" => False), - "za" => array("language" => "Saɯ cueŋƅ, Saw cuengh", "translation_exist" => False), - "zh" => array("language" => "中文, 汉语, 漢語", "translation_exist" => False), - "zu" => array("language" => "isiZulu", "translation_exist" => False) + "aa" => array("language" => "Afaraf", "translation_exist" => False), + "ab" => array("language" => "аҧсуа", "translation_exist" => False), + "ae" => array("language" => "avesta", "translation_exist" => False), + "af" => array("language" => "Afrikaans", "translation_exist" => False), + "ak" => array("language" => "Akan", "translation_exist" => False), + "am" => array("language" => "አማርኛ", "translation_exist" => False), + "an" => array("language" => "Aragonés", "translation_exist" => False), + "ar" => array("language" => "العربية", "translation_exist" => False), + "as" => array("language" => "অসমীয়া", "translation_exist" => False), + "av" => array("language" => "авар мацӀ, магӀарул мацӀ", "translation_exist" => False), + "ay" => array("language" => "aymar aru", "translation_exist" => False), + "az" => array("language" => "azərbaycan dili", "translation_exist" => False), + "ba" => array("language" => "башҡорт теле", "translation_exist" => False), + "be" => array("language" => "Беларуская", "translation_exist" => False), + "bg" => array("language" => "български език", "translation_exist" => False), + "bh" => array("language" => "भोजपुरी", "translation_exist" => False), + "bi" => array("language" => "Bislama", "translation_exist" => False), + "bm" => array("language" => "bamanankan", "translation_exist" => False), + "bn" => array("language" => "বাংলা", "translation_exist" => False), + "bo" => array("language" => "བོད་ཡིག", "translation_exist" => False), + "br" => array("language" => "brezhoneg", "translation_exist" => False), + "bs" => array("language" => "bosanski jezik", "translation_exist" => False), + "ca" => array("language" => "Català", "translation_exist" => False), + "ce" => array("language" => "нохчийн мотт", "translation_exist" => False), + "ch" => array("language" => "Chamoru", "translation_exist" => False), + "co" => array("language" => "corsu, lingua corsa", "translation_exist" => False), + "cr" => array("language" => "ᓀᐦᐃᔭᐍᐏᐣ", "translation_exist" => False), + "cs" => array("language" => "česky, čeština", "translation_exist" => False), + "cu" => array("language" => "ѩзыкъ словѣньскъ", "translation_exist" => False), + "cv" => array("language" => "чӑваш чӗлхи", "translation_exist" => False), + "cy" => array("language" => "Cymraeg", "translation_exist" => False), + "da" => array("language" => "dansk", "translation_exist" => False), + "de" => array("language" => "Deutsch", "translation_exist" => True), + "dv" => array("language" => "ދިވެހި", "translation_exist" => False), + "dz" => array("language" => "རྫོང་ཁ", "translation_exist" => False), + "ee" => array("language" => "Eʋegbe", "translation_exist" => False), + "el" => array("language" => "Ελληνικά", "translation_exist" => False), + "en" => array("language" => "English", "translation_exist" => True), + "eo" => array("language" => "Esperanto", "translation_exist" => False), + "es" => array("language" => "español, castellano", "translation_exist" => False), + "et" => array("language" => "eesti, eesti keel", "translation_exist" => False), + "eu" => array("language" => "euskara, euskera", "translation_exist" => False), + "fa" => array("language" => "فارسی", "translation_exist" => False), + "ff" => array("language" => "Fulfulde, Pulaar, Pular", "translation_exist" => False), + "fi" => array("language" => "suomi, suomen kieli", "translation_exist" => False), + "fj" => array("language" => "vosa Vakaviti", "translation_exist" => False), + "fo" => array("language" => "føroyskt", "translation_exist" => False), + "fr" => array("language" => "français, langue française", "translation_exist" => False), + "fy" => array("language" => "Frysk", "translation_exist" => False), + "ga" => array("language" => "Gaeilge", "translation_exist" => False), + "gd" => array("language" => "Gàidhlig", "translation_exist" => False), + "gl" => array("language" => "Galego", "translation_exist" => False), + "gn" => array("language" => "Avañe'ẽ", "translation_exist" => False), + "gu" => array("language" => "ગુજરાતી", "translation_exist" => False), + "gv" => array("language" => "Gaelg, Gailck", "translation_exist" => False), + "ha" => array("language" => "Hausa, هَوُسَ", "translation_exist" => False), + "he" => array("language" => "עברית", "translation_exist" => False), + "hi" => array("language" => "हिन्दी, हिंदी", "translation_exist" => False), + "ho" => array("language" => "Hiri Motu", "translation_exist" => False), + "hr" => array("language" => "hrvatski", "translation_exist" => False), + "ht" => array("language" => "Kreyòl ayisyen", "translation_exist" => False), + "hu" => array("language" => "Magyar", "translation_exist" => False), + "hy" => array("language" => "Հայերեն", "translation_exist" => False), + "hz" => array("language" => "Otjiherero", "translation_exist" => False), + "ia" => array("language" => "Interlingua", "translation_exist" => False), + "id" => array("language" => "Bahasa Indonesia", "translation_exist" => False), + "ie" => array("language" => "Originally called ", "translation_exist" => False), + "ig" => array("language" => "Asụsụ Igbo", "translation_exist" => False), + "ii" => array("language" => "ꆈꌠ꒿ Nuosuhxop", "translation_exist" => False), + "ik" => array("language" => "Iñupiaq, Iñupiatun", "translation_exist" => False), + "io" => array("language" => "Ido", "translation_exist" => False), + "is" => array("language" => "Íslenska", "translation_exist" => False), + "it" => array("language" => "Italiano", "translation_exist" => False), + "iu" => array("language" => "ᐃᓄᒃᑎᑐᑦ", "translation_exist" => False), + "ja" => array("language" => "日本語 (にほんご)", "translation_exist" => False), + "jv" => array("language" => "basa Jawa", "translation_exist" => False), + "ka" => array("language" => "ქართული", "translation_exist" => False), + "kg" => array("language" => "KiKongo", "translation_exist" => False), + "ki" => array("language" => "Gĩkũyũ", "translation_exist" => False), + "kj" => array("language" => "Kuanyama", "translation_exist" => False), + "kk" => array("language" => "Қазақ тілі", "translation_exist" => False), + "kl" => array("language" => "kalaallisut, kalaallit oqaasii", "translation_exist" => False), + "km" => array("language" => "ភាសាខ្មែរ", "translation_exist" => False), + "kn" => array("language" => "ಕನ್ನಡ", "translation_exist" => False), + "ko" => array("language" => "한국어 (韓國語), 조선어 (朝鮮語)", "translation_exist" => False), + "kr" => array("language" => "Kanuri", "translation_exist" => False), + "ks" => array("language" => "कश्मीरी, كشميري‎", "translation_exist" => False), + "ku" => array("language" => "Kurdî, كوردی‎", "translation_exist" => False), + "kv" => array("language" => "коми кыв", "translation_exist" => False), + "kw" => array("language" => "Kernewek", "translation_exist" => False), + "ky" => array("language" => "кыргыз тили", "translation_exist" => False), + "la" => array("language" => "latine, lingua latina", "translation_exist" => False), + "lb" => array("language" => "Lëtzebuergesch", "translation_exist" => False), + "lg" => array("language" => "Luganda", "translation_exist" => False), + "li" => array("language" => "Limburgs", "translation_exist" => False), + "ln" => array("language" => "Lingála", "translation_exist" => False), + "lo" => array("language" => "ພາສາລາວ", "translation_exist" => False), + "lt" => array("language" => "lietuvių kalba", "translation_exist" => False), + "lu" => array("language" => "Luba-Katanga", "translation_exist" => False), + "lv" => array("language" => "latviešu valoda", "translation_exist" => False), + "mg" => array("language" => "Malagasy fiteny", "translation_exist" => False), + "mh" => array("language" => "Kajin M̧ajeļ", "translation_exist" => False), + "mi" => array("language" => "te reo Māori", "translation_exist" => False), + "mk" => array("language" => "македонски јазик", "translation_exist" => False), + "ml" => array("language" => "മലയാളം", "translation_exist" => False), + "mn" => array("language" => "монгол", "translation_exist" => False), + "mr" => array("language" => "मराठी", "translation_exist" => False), + "ms" => array("language" => "bahasa Melayu, بهاس ملايو‎", "translation_exist" => False), + "mt" => array("language" => "Malti", "translation_exist" => False), + "my" => array("language" => "ဗမာစာ", "translation_exist" => False), + "na" => array("language" => "Ekakairũ Naoero", "translation_exist" => False), + "nb" => array("language" => "Norsk bokmål", "translation_exist" => False), + "nd" => array("language" => "isiNdebele", "translation_exist" => False), + "ne" => array("language" => "नेपाली", "translation_exist" => False), + "ng" => array("language" => "Owambo", "translation_exist" => False), + "nl" => array("language" => "Nederlands, Vlaams", "translation_exist" => False), + "nn" => array("language" => "Norsk nynorsk", "translation_exist" => False), + "no" => array("language" => "Norsk", "translation_exist" => False), + "nr" => array("language" => "isiNdebele", "translation_exist" => False), + "nv" => array("language" => "Diné bizaad, Dinékʼehǰí", "translation_exist" => False), + "ny" => array("language" => "chiCheŵa, chinyanja", "translation_exist" => False), + "oc" => array("language" => "Occitan", "translation_exist" => False), + "oj" => array("language" => "ᐊᓂᔑᓈᐯᒧᐎᓐ", "translation_exist" => False), + "om" => array("language" => "Afaan Oromoo", "translation_exist" => False), + "or" => array("language" => "ଓଡ଼ିଆ", "translation_exist" => False), + "os" => array("language" => "ирон æвзаг", "translation_exist" => False), + "pa" => array("language" => "ਪੰਜਾਬੀ, پنجابی‎", "translation_exist" => False), + "pi" => array("language" => "पाऴि", "translation_exist" => False), + "pl" => array("language" => "polski", "translation_exist" => False), + "ps" => array("language" => "پښتو", "translation_exist" => False), + "pt" => array("language" => "Português", "translation_exist" => False), + "qu" => array("language" => "Runa Simi, Kichwa", "translation_exist" => False), + "rm" => array("language" => "rumantsch grischun", "translation_exist" => False), + "rn" => array("language" => "Ikirundi", "translation_exist" => False), + "ro" => array("language" => "română", "translation_exist" => False), + "ru" => array("language" => "русский язык", "translation_exist" => False), + "rw" => array("language" => "Ikinyarwanda", "translation_exist" => False), + "sa" => array("language" => "संस्कृतम्", "translation_exist" => False), + "sc" => array("language" => "sardu", "translation_exist" => False), + "sd" => array("language" => "yângâ tî sängö", "translation_exist" => False), + "se" => array("language" => "Davvisámegiella", "translation_exist" => False), + "sg" => array("language" => "yângâ tî sängö", "translation_exist" => False), + "si" => array("language" => "සිංහල", "translation_exist" => False), + "sk" => array("language" => "slovenčina", "translation_exist" => False), + "sl" => array("language" => "slovenščina", "translation_exist" => False), + "sm" => array("language" => "gagana fa'a Samoa", "translation_exist" => False), + "sn" => array("language" => "chiShona", "translation_exist" => False), + "so" => array("language" => "Soomaaliga, af Soomaali", "translation_exist" => False), + "sq" => array("language" => "Shqip", "translation_exist" => False), + "sr" => array("language" => "српски језик", "translation_exist" => False), + "ss" => array("language" => "SiSwati", "translation_exist" => False), + "st" => array("language" => "Sesotho", "translation_exist" => False), + "su" => array("language" => "Basa Sunda", "translation_exist" => False), + "sv" => array("language" => "svenska", "translation_exist" => False), + "sw" => array("language" => "Kiswahili", "translation_exist" => False), + "ta" => array("language" => "தமிழ்", "translation_exist" => False), + "te" => array("language" => "తెలుగు", "translation_exist" => False), + "tg" => array("language" => " тоҷикӣ, toğikī, تاجیکی‎", "translation_exist" => False), + "th" => array("language" => "ไทย", "translation_exist" => False), + "ti" => array("language" => "ትግርኛ", "translation_exist" => False), + "tk" => array("language" => "Türkmen, Түркмен", "translation_exist" => False), + "tl" => array("language" => "Wikang Tagalog", "translation_exist" => False), + "tn" => array("language" => "Setswana", "translation_exist" => False), + "to" => array("language" => "faka Tonga", "translation_exist" => False), + "tr" => array("language" => "Türkçe", "translation_exist" => False), + "ts" => array("language" => "Xitsonga", "translation_exist" => False), + "tt" => array("language" => "татарча, tatarça, تاتارچا‎", "translation_exist" => False), + "tw" => array("language" => "Twi", "translation_exist" => False), + "ty" => array("language" => "Reo Tahiti", "translation_exist" => False), + "ug" => array("language" => "Uyƣurqə, ئۇيغۇرچە‎", "translation_exist" => False), + "uk" => array("language" => "українська", "translation_exist" => False), + "ur" => array("language" => "اردو", "translation_exist" => False), + "uz" => array("language" => "O'zbek, Ўзбек, أۇزبېك‎", "translation_exist" => False), + "ve" => array("language" => "Tshivenḓa", "translation_exist" => False), + "vi" => array("language" => "Tiếng Việt", "translation_exist" => False), + "vo" => array("language" => "Volapük", "translation_exist" => False), + "wa" => array("language" => "Walon", "translation_exist" => False), + "wo" => array("language" => "Wollof", "translation_exist" => False), + "xh" => array("language" => "isiXhosa", "translation_exist" => False), + "yi" => array("language" => "ייִדיש", "translation_exist" => False), + "yo" => array("language" => "Yorùbá", "translation_exist" => False), + "za" => array("language" => "Saɯ cueŋƅ, Saw cuengh", "translation_exist" => False), + "zh" => array("language" => "中文, 汉语, 漢語", "translation_exist" => False), + "zu" => array("language" => "isiZulu", "translation_exist" => False) ); ?> diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php index 4fd22de..9bcbb1d 100644 --- a/ratatoeskr/main.php +++ b/ratatoeskr/main.php @@ -2,7 +2,7 @@ /* * File: ratatoeskr/main.php * Initialize and launch Ratatöskr - * + * * License: * This file is part of Ratatöskr. * Ratatöskr is licensed unter the MIT / X11 License. @@ -11,7 +11,7 @@ require_once(dirname(__FILE__) . "/config.php"); if(!CONFIG_FILLED_OUT) - die("Config file not filled out!"); + die("Config file not filled out!"); require_once(dirname(__FILE__) . "/sys/db.php"); require_once(dirname(__FILE__) . "/sys/models.php"); @@ -26,88 +26,88 @@ $plugin_objs = array(); function ratatoeskr() { - global $ste; - try - { - _ratatoeskr(); - } - catch(Exception $e) - { - header("HTTP/1.1 500 Internal Server Error"); - $ste->vars["title"] = "500 Internal Server Error"; - if(__DEBUG__) - $ste->vars["details"] = $e->__toString(); - echo $ste->exectemplate("/systemtemplates/error.html"); - } + global $ste; + try + { + _ratatoeskr(); + } + catch(Exception $e) + { + header("HTTP/1.1 500 Internal Server Error"); + $ste->vars["title"] = "500 Internal Server Error"; + if(__DEBUG__) + $ste->vars["details"] = $e->__toString(); + echo $ste->exectemplate("/systemtemplates/error.html"); + } } function _ratatoeskr() { - global $backend_subactions, $ste, $url_handlers, $ratatoeskr_settings, $plugin_objs, $api_compat; - - $ts_start = microtime(True); - - session_start(); - db_connect(); - clean_database(); - - if(isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]) - define("__DEBUG__", True); - - if(PLUGINS_ENABLED) - { - $activeplugins = array_filter(Plugin::all(), function($plugin) { return $plugin->active; }); - foreach($activeplugins as $plugin) - { - if(!in_array($plugin->api, $api_compat)) - { - $plugin->active = False; - $plugin->save(); - continue; - } - - eval($plugin->code); - $plugin_obj = new $plugin->classname($plugin->get_id()); - if($plugin->update) - { - $plugin_obj->update(); - $plugin->update = False; - $plugin->save(); - } - $plugin_obj->init(); - $plugin_objs[$plugin->get_id()] = $plugin_obj; - } - } - - /* Register URL handlers */ - build_backend_subactions(); - register_url_handler("_default", "frontend_url_handler"); - register_url_handler("_index", "frontend_url_handler"); - register_url_handler("index", "frontend_url_handler"); - register_url_handler("backend", $backend_subactions); - register_url_handler("_notfound", url_action_simple(function($data) - { - global $ste; - header("HTTP/1.1 404 Not Found"); - $ste->vars["title"] = "404 Not Found"; - $ste->vars["details"] = str_replace("[[URL]]", $_SERVER["REQUEST_URI"], (isset($translation) ? $translation["e404_details"] : "The page [[URL]] could not be found. Sorry.")); - echo $ste->exectemplate("/systemtemplates/error.html"); - })); - - $urlpath = explode("/", @$_GET["action"]); - $rel_path_to_root = implode("/", array_merge(array("."), array_repeat("..", count($urlpath) - 1))); - $GLOBALS["rel_path_to_root"] = $rel_path_to_root; - $data = array("rel_path_to_root" => $rel_path_to_root); - $ste->vars["rel_path_to_root"] = $rel_path_to_root; - - url_process($urlpath, $url_handlers, $data); - - if(PLUGINS_ENABLED) - { - foreach($plugin_objs as $plugin_obj) - $plugin_obj->atexit(); - } - $ratatoeskr_settings->save(); + global $backend_subactions, $ste, $url_handlers, $ratatoeskr_settings, $plugin_objs, $api_compat; + + $ts_start = microtime(True); + + session_start(); + db_connect(); + clean_database(); + + if(isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]) + define("__DEBUG__", True); + + if(PLUGINS_ENABLED) + { + $activeplugins = array_filter(Plugin::all(), function($plugin) { return $plugin->active; }); + foreach($activeplugins as $plugin) + { + if(!in_array($plugin->api, $api_compat)) + { + $plugin->active = False; + $plugin->save(); + continue; + } + + eval($plugin->code); + $plugin_obj = new $plugin->classname($plugin->get_id()); + if($plugin->update) + { + $plugin_obj->update(); + $plugin->update = False; + $plugin->save(); + } + $plugin_obj->init(); + $plugin_objs[$plugin->get_id()] = $plugin_obj; + } + } + + /* Register URL handlers */ + build_backend_subactions(); + register_url_handler("_default", "frontend_url_handler"); + register_url_handler("_index", "frontend_url_handler"); + register_url_handler("index", "frontend_url_handler"); + register_url_handler("backend", $backend_subactions); + register_url_handler("_notfound", url_action_simple(function($data) + { + global $ste; + header("HTTP/1.1 404 Not Found"); + $ste->vars["title"] = "404 Not Found"; + $ste->vars["details"] = str_replace("[[URL]]", $_SERVER["REQUEST_URI"], (isset($translation) ? $translation["e404_details"] : "The page [[URL]] could not be found. Sorry.")); + echo $ste->exectemplate("/systemtemplates/error.html"); + })); + + $urlpath = explode("/", @$_GET["action"]); + $rel_path_to_root = implode("/", array_merge(array("."), array_repeat("..", count($urlpath) - 1))); + $GLOBALS["rel_path_to_root"] = $rel_path_to_root; + $data = array("rel_path_to_root" => $rel_path_to_root); + $ste->vars["rel_path_to_root"] = $rel_path_to_root; + + url_process($urlpath, $url_handlers, $data); + + if(PLUGINS_ENABLED) + { + foreach($plugin_objs as $plugin_obj) + $plugin_obj->atexit(); + } + $ratatoeskr_settings->save(); } ?> diff --git a/ratatoeskr/setup/create_tables.php b/ratatoeskr/setup/create_tables.php index ef226d8..b0c2075 100644 --- a/ratatoeskr/setup/create_tables.php +++ b/ratatoeskr/setup/create_tables.php @@ -1,7 +1,7 @@ diff --git a/ratatoeskr/setup/setup.php b/ratatoeskr/setup/setup.php index ef2c510..f51f1a9 100644 --- a/ratatoeskr/setup/setup.php +++ b/ratatoeskr/setup/setup.php @@ -15,240 +15,240 @@ $ste->vars["rel_path_to_root"] = $rel_path_to_root; $ste->vars["translations"] = array(); foreach($languages as $langcode => $langinfo) { - if($langinfo["translation_exist"]) - $ste->vars["translations"][$langcode] = $langinfo["language"]; + if($langinfo["translation_exist"]) + $ste->vars["translations"][$langcode] = $langinfo["language"]; } if(isset($_GET["lang"]) and (@$languages[$_GET["lang"]]["translation_exist"])) { - load_language($_GET["lang"]); - $lang = $_GET["lang"]; - $ste->vars["lang"] = $_GET["lang"]; + load_language($_GET["lang"]); + $lang = $_GET["lang"]; + $ste->vars["lang"] = $_GET["lang"]; } else - die($ste->exectemplate("/systemtemplates/setup_select_lang.html")); + die($ste->exectemplate("/systemtemplates/setup_select_lang.html")); if(isset($_POST["apply_setup"])) { - if(empty($_POST["admin_username"]) or empty($_POST["admin_init_password"])) - $ste->vars["error"] = $translation["admin_data_must_be_filled_out"]; - else - { - $config["mysql"]["server"] = $_POST["mysql_host"]; - $config["mysql"]["db"] = $_POST["mysql_database"]; - $config["mysql"]["user"] = $_POST["mysql_user"]; - $config["mysql"]["passwd"] = $_POST["mysql_password"]; - $config["mysql"]["prefix"] = $_POST["table_prefix"]; - - try - { - db_connect(); - create_mysql_tables(); - - /* Writing some demo data to database */ - require_once(dirname(__FILE__) . "/../sys/models.php"); - - $ratatoeskr_settings["default_language"] = $lang; - $ratatoeskr_settings["comment_visible_defaut"] = True; - $ratatoeskr_settings["allow_comments_default"] = True; - $ratatoeskr_settings["comment_textprocessor"] = "Markdown"; - $ratatoeskr_settings["languages"] = $lang == "en" ? array("en") : array($lang, "en"); - $ratatoeskr_settings["last_db_cleanup"] = time(); - $ratatoeskr_settings["debugmode"] = False; - - $style = Style::create("default"); - $style->code = <<