diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-04-26 21:03:08 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-04-26 21:13:51 +0200 |
commit | ade9edeb849803082856f7633194913ad4df93a0 (patch) | |
tree | a864c593f92851678d7ab9fe4e7e9cfdefb539c8 /ratatoeskr | |
parent | c3cc300a952a793b9655226db1aad050daaa3803 (diff) | |
download | ratatoeskr-cms-ade9edeb849803082856f7633194913ad4df93a0.tar.gz ratatoeskr-cms-ade9edeb849803082856f7633194913ad4df93a0.tar.bz2 ratatoeskr-cms-ade9edeb849803082856f7633194913ad4df93a0.zip |
Automatic code formatting
Diffstat (limited to 'ratatoeskr')
-rw-r--r-- | ratatoeskr/backend.php | 1589 | ||||
-rw-r--r-- | ratatoeskr/config.php | 6 | ||||
-rw-r--r-- | ratatoeskr/frontend.php | 457 | ||||
-rw-r--r-- | ratatoeskr/languages.php | 372 | ||||
-rw-r--r-- | ratatoeskr/main.php | 55 | ||||
-rw-r--r-- | ratatoeskr/setup/create_tables.php | 10 | ||||
-rw-r--r-- | ratatoeskr/setup/setup.php | 52 | ||||
-rw-r--r-- | ratatoeskr/sys/db.php | 22 | ||||
-rw-r--r-- | ratatoeskr/sys/init_ste.php | 20 | ||||
-rw-r--r-- | ratatoeskr/sys/models.php | 1162 | ||||
-rw-r--r-- | ratatoeskr/sys/plugin_api.php | 66 | ||||
-rw-r--r-- | ratatoeskr/sys/pluginpackage.php | 163 | ||||
-rw-r--r-- | ratatoeskr/sys/pwhash.php | 12 | ||||
-rw-r--r-- | ratatoeskr/sys/textprocessors.php | 27 | ||||
-rw-r--r-- | ratatoeskr/sys/translation.php | 29 | ||||
-rw-r--r-- | ratatoeskr/sys/urlprocess.php | 97 | ||||
-rw-r--r-- | ratatoeskr/sys/utils.php | 66 | ||||
-rw-r--r-- | ratatoeskr/translations/de.php | 4 | ||||
-rw-r--r-- | ratatoeskr/translations/en.php | 4 |
19 files changed, 2137 insertions, 2076 deletions
diff --git a/ratatoeskr/backend.php b/ratatoeskr/backend.php index ac43f75..ab18ce1 100644 --- a/ratatoeskr/backend.php +++ b/ratatoeskr/backend.php @@ -15,22 +15,19 @@ require_once(dirname(__FILE__) . "/sys/textprocessors.php"); require_once(dirname(__FILE__) . "/sys/plugin_api.php"); require_once(dirname(__FILE__) . "/languages.php"); -$admin_grp = NULL; +$admin_grp = null; /* Mass creation of tags. */ function maketags($tagnames, $lang) { - $rv = array(); - foreach($tagnames as $tagname) - { - if(empty($tagname)) + $rv = []; + foreach ($tagnames as $tagname) { + if (empty($tagname)) { continue; - try - { - $tag = Tag::by_name($tagname); } - catch(DoesNotExistError $e) - { + try { + $tag = Tag::by_name($tagname); + } catch (DoesNotExistError $e) { $tag = Tag::create($tagname); $tag->title[$lang] = new Translation($tagname, ""); } @@ -39,27 +36,26 @@ function maketags($tagnames, $lang) return $rv; } -$backend_subactions = NULL; +$backend_subactions = null; function build_backend_subactions() { -global $backend_subactions, $pluginpages_handlers; + global $backend_subactions, $pluginpages_handlers; -$backend_subactions = url_action_subactions(array( - "_index" => url_action_alias(array("login")), - "index" => url_action_alias(array("login")), + $backend_subactions = url_action_subactions([ + "_index" => url_action_alias(["login"]), + "index" => url_action_alias(["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) - { + "_prelude" => function (&$data, $url_now, &$url_next) { global $ratatoeskr_settings, $admin_grp, $ste, $languages; - if($admin_grp === NULL) + 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"] = []; + $ste->vars["all_langcodes"] = []; + foreach ($languages as $code => $data) { $ste->vars["all_languages"][$code] = $data["language"]; $ste->vars["all_langcodes"][] = $code; } @@ -68,162 +64,160 @@ $backend_subactions = url_action_subactions(array( /* Check authentification */ - if(isset($_SESSION["ratatoeskr_uid"])) - { - try - { + 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)) - { + 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"); + if ($url_next[0] == "login") { + $url_next = ["content", "write"]; + } $data["user"] = $user; - $ste->vars["user"] = array("id" => $user->get_id(), "name" => $user->username, "lang" => $user->language); + $ste->vars["user"] = ["id" => $user->get_id(), "name" => $user->username, "lang" => $user->language]; return; /* Authentification successful, continue */ - } - else + } else { unset($_SESSION["ratatoeskr_uid"]); - } - catch(DoesNotExistError $e) - { + } + } catch (DoesNotExistError $e) { unset($_SESSION["ratatoeskr_uid"]); } } load_language(); /* If we are here, user is not logged in... */ - $url_next = array("login"); + $url_next = ["login"]; }, - "login" => url_action_simple(function($data) - { + "login" => url_action_simple(function ($data) { global $ste, $admin_grp; - if(!empty($_POST["user"])) - { - try - { + if (!empty($_POST["user"])) { + try { $user = User::by_name($_POST["user"]); - if(!PasswordHash::validate($_POST["password"], $user->pwhash)) + if (!PasswordHash::validate($_POST["password"], $user->pwhash)) { throw new Exception(); - if(!$user->member_of($admin_grp)) + } + 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; + $ste->vars["user"] = ["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")); + if (isset($data["user"])) { + throw new Redirect(["content", "write"]); + } } echo $ste->exectemplate("/systemtemplates/backend_login.html"); }), - "logout" => url_action_simple(function($data) - { + "logout" => url_action_simple(function ($data) { unset($_SESSION["ratatoeskr_uid"]); unset($_SESSION["ratatoeskr_pwhash"]); load_language(); - throw new Redirect(array("login")); + throw new Redirect(["login"]); }), - "content" => url_action_subactions(array( - "write" => function(&$data, $url_now, &$url_next) - { + "content" => url_action_subactions([ + "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)) + if (!isset($editlang)) { $editlang = $data["user"]->language; - if(isset($article)) + } + if (isset($article)) { $ste->vars["article_editurl"] = urlencode($article) . "/" . urlencode($editlang); - else + } else { $ste->vars["article_editurl"] = ""; + } - $url_next = array(); + $url_next = []; $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"] = []; + foreach ($textprocessors as $txtproc => $properties) { + if ($properties[1]) { $ste->vars["textprocessors"][] = $txtproc; + } + } - $ste->vars["sections"] = array(); - foreach(Section::all() as $section) + $ste->vars["sections"] = []; + foreach (Section::all() as $section) { $ste->vars["sections"][] = $section->name; + } $ste->vars["article_section"] = $default_section->name; /* Check Form */ - $fail_reasons = array(); + $fail_reasons = []; - if(isset($_POST["save_article"])) - { - if(!Article::test_urlname($_POST["urlname"])) + if (isset($_POST["save_article"])) { + if (!Article::test_urlname($_POST["urlname"])) { $fail_reasons[] = $translation["invalid_urlname"]; - else + } else { $inputs["urlname"] = $_POST["urlname"]; - if(!Article::test_status(@$_POST["article_status"])) + } + if (!Article::test_status(@$_POST["article_status"])) { $fail_reasons[] = $translation["invalid_article_status"]; - else + } else { $inputs["article_status"] = (int) $_POST["article_status"]; - if(!isset($textprocessors[@$_POST["content_txtproc"]])) + } + if (!isset($textprocessors[@$_POST["content_txtproc"]])) { $fail_reasons[] = $translation["unknown_txtproc"]; - else + } else { $inputs["content_txtproc"] = $_POST["content_txtproc"]; - if(!isset($textprocessors[@$_POST["excerpt_txtproc"]])) + } + if (!isset($textprocessors[@$_POST["excerpt_txtproc"]])) { $fail_reasons[] = $translation["unknown_txtproc"]; - else + } 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) + } + if (!empty($_POST["date"])) { + if (($time_tmp = @DateTime::createFromFormat("Y-m-d H:i:s", @$_POST["date"])) === false) { $fail_reasons[] = $translation["invalid_date"]; - else + } else { $inputs["date"] = @$time_tmp->getTimestamp(); - } - else + } + } else { $inputs["date"] = time(); + } $inputs["allow_comments"] = !(empty($_POST["allow_comments"]) or ($_POST["allow_comments"] != "yes")); - try - { + try { $inputs["article_section"] = Section::by_name($_POST["section"]); - } - catch(DoesNotExistError $e) - { + } 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"])) + $inputs["tags"] = array_filter(array_map("trim", explode(",", $_POST["tags"])), function ($t) { + return !empty($t); + }); + if (isset($_POST["saveaslang"])) { $editlang = $_POST["saveaslang"]; - } - else - { + } + } else { /* Call articleeditor plugins */ - $article = empty($article) ? NULL : Article::by_urlname($article); - foreach($articleeditor_plugins as $plugin) - call_user_func($plugin["fx"], $article, False); + $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) @@ -239,144 +233,138 @@ $backend_subactions = url_action_subactions(array( $article->allow_comments = $inputs["allow_comments"]; } - if(empty($article)) - { + if (empty($article)) { /* New Article */ $ste->vars["pagetitle"] = $translation["new_article"]; - if(empty($fail_reasons) and isset($_POST["save_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)) + $call_after_save = []; + foreach ($articleeditor_plugins as $plugin) { + $result = call_user_func($plugin["fx"], $article, true); + if (is_string($result)) { $fail_reasons[] = $result; - elseif($result !== NULL) + } elseif ($result !== null) { $call_after_save[] = $result; + } } - if(empty($fail_reasons)) - { - try - { + if (empty($fail_reasons)) { + try { $article->save(); - foreach($call_after_save as $cb) + 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) - { + } catch (AlreadyExistsError $e) { $fail_reasons[] = $translation["article_name_already_in_use"]; } } } - } - else - { - try - { - if(!($article instanceof Article)) + } else { + try { + if (!($article instanceof Article)) { $article = Article::by_urlname($article); - } - catch(DoesNotExistError $e) - { + } + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - if(empty($fail_reasons) and isset($_POST["save_article"])) - { + 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)) + $call_after_save = []; + foreach ($articleeditor_plugins as $plugin) { + $result = call_user_func($plugin["fx"], $article, true); + if (is_string($result)) { $fail_reasons[] = $result; - elseif($result !== NULL) + } elseif ($result !== null) { $call_after_save[] = $result; + } } - if(empty($fail_reasons)) - { - try - { + if (empty($fail_reasons)) { + try { $article->save(); - foreach($call_after_save as $cb) - call_user_func($cb, $article); + 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) - { + } catch (AlreadyExistsError $e) { $fail_reasons[] = $translation["article_name_already_in_use"]; } } } - if(!isset($article->title[$editlang])) - { - $langs_available = array(); - foreach($article->title as $lang => $_) + if (!isset($article->title[$editlang])) { + $langs_available = []; + foreach ($article->title as $lang => $_) { $langs_available[] = $lang; + } $editlang = $langs_available[0]; } - foreach(array( + foreach ([ "urlname" => "urlname", "status" => "article_status", "timestamp" => "date", "allow_comments" => "allow_comments" - ) as $prop => $k_out) - { - if(!isset($inputs[$k_out])) + ] as $prop => $k_out) { + if (!isset($inputs[$k_out])) { $inputs[$k_out] = $article->$prop; + } } - if(!isset($inputs["title"])) + if (!isset($inputs["title"])) { $inputs["title"] = $article->title[$editlang]->text; - if(!isset($inputs["content"])) - { + } + if (!isset($inputs["content"])) { $translation_obj = $article->text[$editlang]; $inputs["content"] = $translation_obj->text; $inputs["content_txtproc"] = $translation_obj->texttype; } - if(!isset($inputs["excerpt"])) - { + 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"])) + 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(); + } + if (!isset($inputs["tags"])) { + $inputs["tags"] = array_map(function ($tag) use ($editlang) { + return $tag->name; + }, $article->get_tags()); + } + $ste->vars["morelangs"] = []; $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"]); + foreach ($article->title as $lang => $_) { + if ($lang != $editlang) { + $ste->vars["morelangs"][] = ["url" => urlencode($article->urlname) . "/$lang", "full" => "($lang) " . $languages[$lang]["language"]]; + } } } - if(!isset($inputs["date"])) + if (!isset($inputs["date"])) { $inputs["date"] = time(); - if(!isset($inputs["article_status"])) + } + if (!isset($inputs["article_status"])) { $inputs["article_status"] = ARTICLE_STATUS_LIVE; + } /* Push data back to template */ - if(isset($inputs["tags"])) + if (isset($inputs["tags"])) { $ste->vars["tags"] = implode(", ", $inputs["tags"]); - if(isset($inputs["article_section"])) + } + if (isset($inputs["article_section"])) { $ste->vars["article_section"] = $inputs["article_section"]->name; + } $ste->vars["editlang"] = $editlang; - foreach(array( + foreach ([ "urlname" => "urlname", "article_status" => "article_status", "title" => "title", @@ -386,41 +374,40 @@ $backend_subactions = url_action_subactions(array( "excerpt" => "excerpt", "date" => "date", "allow_comments" => "allow_comments" - ) as $k_in => $k_out) - { - if(isset($inputs[$k_in])) + ] 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"]; })); + $ste->vars["displayed_plugins"] = array_map(function ($x) { + return ["label" => $x["label"], "template" => $x["template"]]; + }, array_filter($articleeditor_plugins, function ($x) { + return $x["display"]; + })); - if(!empty($fail_reasons)) + if (!empty($fail_reasons)) { $ste->vars["failed"] = $fail_reasons; + } echo $ste->exectemplate("/systemtemplates/content_write.html"); }, - "tags" => function(&$data, $url_now, &$url_next) - { + "tags" => function (&$data, $url_now, &$url_next) { global $translation, $languages, $ste, $rel_path_to_root; - $url_next = array(); + $url_next = []; $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 - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -428,72 +415,61 @@ $backend_subactions = url_action_subactions(array( $ste->vars["success"] = $translation["tags_successfully_deleted"]; } - if(isset($_POST["save_changes"])) - { - $newlang = (!empty($_POST["new_language"])) ? $_POST["new_language"] : NULL; - $newtag = NULL; + 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"])) + if (!empty($_POST["newtagname"])) { + if (!Tag::test_name(@$_POST["newtagname"])) { $ste->vars["error"] = $translation["invalid_tag_name"]; - else + } else { $newtag = $_POST["newtagname"]; + } } - if(($newlang !== NULL) and (!isset($languages[$newlang]))) - $newlang = NULL; - if($newtag !== NULL) - { - try - { + if (($newlang !== null) and (!isset($languages[$newlang]))) { + $newlang = null; + } + if ($newtag !== null) { + try { $newtag = Tag::create($newtag); - } - catch(AlreadyExistsError $e) - { - $newtag = NULL; + } catch (AlreadyExistsError $e) { + $newtag = null; } } - $translations = array(); - foreach($_POST as $k => $v) - { - if(preg_match('/tagtrans_(NEW|[a-z]{2})_(.*)/', $k, $matches) == 1) - { + $translations = []; + 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) + if ($lang === null) { continue; + } $translations[$tag][$lang] = $v; } } - foreach($translations as $tag => $langmap) - { - if($tag == "NEW") - { - if($newtag === NULL) + foreach ($translations as $tag => $langmap) { + if ($tag == "NEW") { + if ($newtag === null) { continue; + } $tag = $newtag; - } - else - { - try - { + } else { + try { $tag = Tag::by_id($tag); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } - foreach($langmap as $l => $text) - { - if(empty($text)) + foreach ($langmap as $l => $text) { + if (empty($text)) { unset($tag->title[$l]); - else + } else { $tag->title[$l] = new Translation($text, ""); + } } $tag->save(); @@ -502,59 +478,54 @@ $backend_subactions = url_action_subactions(array( $ste->vars["success"] = $translation["tags_successfully_edited"]; } - $ste->vars["alltags"] = array(); - $taglangs = array(); + $ste->vars["alltags"] = []; + $taglangs = []; $alltags = Tag::all(); - foreach($alltags as $tag) - { - $transls = array(); - foreach($tag->title as $l => $t) - { - if(!in_array($l, $taglangs)) + foreach ($alltags as $tag) { + $transls = []; + foreach ($tag->title as $l => $t) { + if (!in_array($l, $taglangs)) { $taglangs[] = $l; + } $transls[$l] = $t->text; } - $ste->vars["alltags"][] = array( + $ste->vars["alltags"][] = [ "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"] = []; + 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"] = []; + 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) - { + "articles" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; - $url_next = array(); + $url_next = []; $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 - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -565,190 +536,193 @@ $backend_subactions = url_action_subactions(array( $articles = Article::all(); /* Filtering */ - $filterquery = array(); - if(!empty($_GET["filter_urlname"])) - { + $filterquery = []; + 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; }); + $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"])) - { + 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; }); + $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"])) - { + if (!empty($_GET["filter_section"])) { $searchfor = $_GET["filter_section"]; - $articles = array_filter($articles, function($a) use ($searchfor) { return $a->get_section()->name == $searchfor; }); + $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"]) - { + 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); }); + $ste->vars["sort_asc_date"] = true; + $ste->vars["sorting"] = ["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); }); + $ste->vars["sort_asc_section"] = true; + $ste->vars["sorting"] = ["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"; + // no 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); }); + $ste->vars["sort_asc_urlname"] = true; + $ste->vars["sorting"] = ["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"]) - { + } 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); }); + $ste->vars["sort_desc_date"] = true; + $ste->vars["sorting"] = ["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); }); + $ste->vars["sort_desc_section"] = true; + $ste->vars["sorting"] = ["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); }); + $ste->vars["sort_desc_urlname"] = true; + $ste->vars["sorting"] = ["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); }); + $ste->vars["sort_asc_urlname"] = true; + $ste->vars["sorting"] = ["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); }); + } else { + $ste->vars["sort_asc_urlname"] = true; + $ste->vars["sorting"] = ["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 => $_) + $ste->vars["articles"] = array_map(function ($article) { + $avail_langs = []; + foreach ($article->title as $lang => $_) { $avail_langs[] = $lang; + } sort($avail_langs); $a_section = $article->get_section(); - return array( + return [ "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) - ); + "tags" => array_map(function ($tag) { + return $tag->name; + }, $article->get_tags()), + "section" => ["id" => $a_section->get_id(), "name" => $a_section->name] + ]; }, $articles); echo $ste->exectemplate("/systemtemplates/articles.html"); }, - "images" => function(&$data, $url_now, &$url_next) - { + "images" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; list($imgid, $imageaction) = $url_next; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "content"; $ste->vars["submenu"] = "images"; $ste->vars["pagetitle"] = $translation["menu_images"]; - if(!empty($imgid) and is_numeric($imgid)) - { - try - { + if (!empty($imgid) and is_numeric($imgid)) { + try { $image = Image::by_id($imgid); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - if(empty($imageaction)) + if (empty($imageaction)) { throw new NotFoundError(); - else - { - if(($imageaction == "markdown") or ($imageaction == "html") or ($imageaction == "ste")) - { + } 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") + 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") + } elseif ($imageaction == "html") { $ste->vars["embed_code"] = "<img src=\"%root%/images/" . htmlesc(urlencode($image->get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; - elseif($imageaction == "ste") + } elseif ($imageaction == "ste") { $ste->vars["embed_code"] = "<img src=\"\$rel_path_to_root/images/" . htmlesc(urlencode($image->get_filename())) . "\" alt=\"" . htmlesc($_POST["img_alt"]) . "\" />"; + } } echo $ste->exectemplate("/systemtemplates/image_embed.html"); - } - else + } else { throw new NotFoundError(); + } } return; } /* Upload Form */ - if(isset($_POST["upload"])) - { - try - { + 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) - { + } catch (IOError $e) { $ste->vars["error"] = $translation["upload_failed"]; - } - catch(UnknownFileFormat $e) - { + } 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 - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -758,60 +732,54 @@ $backend_subactions = url_action_subactions(array( $images = Image::all(); - $ste->vars["images"] = array_map(function($img) { return array( + $ste->vars["images"] = array_map(function ($img) { + return [ "id" => $img->get_id(), "name" => $img->name, "file" => $img->get_filename() - ); }, $images); + ]; + }, $images); echo $ste->exectemplate("/systemtemplates/image_list.html"); }, - "comments" => function(&$data, $url_now, &$url_next) - { + "comments" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; list($comment_id) = $url_next; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "content"; $ste->vars["submenu"] = "comments"; $ste->vars["pagetitle"] = $translation["menu_comments"]; /* Single comment? */ - if(!empty($comment_id)) - { - try - { + if (!empty($comment_id)) { + try { $comment = Comment::by_id($comment_id); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - if(!$comment->read_by_admin) - { - $comment->read_by_admin = True; + if (!$comment->read_by_admin) { + $comment->read_by_admin = true; $comment->save(); } - if(isset($_POST["action_on_comment"])) - { - switch($_POST["action_on_comment"]) - { + 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->visible = true; $comment->save(); $ste->vars["success"] = $translation["comment_successfully_made_visible"]; break; case "make_invisible": - $comment->visible = False; + $comment->visible = false; $comment->save(); $ste->vars["success"] = $translation["comment_successfully_made_invisible"]; break; @@ -834,45 +802,52 @@ $backend_subactions = url_action_subactions(array( backend_content_comments_overview: /* Perform an action on all selected comments */ - if(!empty($_POST["action_on_comments"])) - { - switch($_POST["action_on_comments"]) - { + if (!empty($_POST["action_on_comments"])) { + switch ($_POST["action_on_comments"]) { case "delete": - $commentaction = function($c) { $c->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(); }; + $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(); }; + $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(); }; + $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(); }; + $commentaction = function ($c) { + $c->visible = false; + $c->save(); + }; $ste->vars["success"] = $translation["comments_successfully_made_invisible"]; break; - default; + default: $ste->vars["error"] = $translation["unknown_action"]; break; } - if(isset($commentaction)) - { - foreach($_POST["comment_multiselect"] as $c_id) - { - try - { + if (isset($commentaction)) { + foreach ($_POST["comment_multiselect"] as $c_id) { + try { $comment = Comment::by_id($c_id); $commentaction($comment); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } @@ -882,175 +857,163 @@ $backend_subactions = url_action_subactions(array( $comments = Comment::all(); /* Filtering */ - $filterquery = array(); - if(!empty($_GET["filter_article"])) - { + $filterquery = []; + 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; }); + $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"])) - { + if (isset($_GET["sort_asc"])) { $sort_dir = 1; $sort_by = $_GET["sort_asc"]; - } - elseif(isset($_GET["sort_desc"])) - { + } elseif (isset($_GET["sort_desc"])) { $sort_dir = -1; $sort_by = $_GET["sort_desc"]; - } - else - { + } else { $sort_dir = 1; $sort_by = "was_read"; } - switch($sort_by) - { + switch ($sort_by) { case "language": - usort($comments, function($a, $b) use ($sort_dir) { return strcmp($a->get_language(), $b->get_language()) * $sort_dir; }); + 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; }); + 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; }); + 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["sorting"] = ["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( + $ste->vars["comments"] = array_map(function ($c) { + return [ "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), + "excerpt" => substr(str_replace(["\r\n", "\n", "\r"], " ", $c->text), 0, 50), "language" => $c->get_language(), "date" => $c->get_timestamp(), "author" => "\"{$c->author_name}\" <{$c->author_mail}>" - ); }, $comments); + ]; + }, $comments); echo $ste->exectemplate("/systemtemplates/comments_list.html"); } - )), - "design" => url_action_subactions(array( - "templates" => function(&$data, $url_now, &$url_next) - { + ]), + "design" => url_action_subactions([ + "templates" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; list($template) = $url_next; - $url_next = array(); + $url_next = []; $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. */ + 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")) + } + 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. */ + 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")) + } + 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) - { + 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 - { + 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) - { + } catch (\ste\ParseCompileError $e) { $e->rewrite($_POST["template_code"]); $ste->vars["error"] = $translation["could_not_compile_template"] . $e->getMessage(); } - } - else + } else { $ste->vars["error"] = $translation["invalid_template_name"]; + } } /* Get all templates */ - $ste->vars["templates"] = array(); + $ste->vars["templates"] = []; $tpldir = new DirectoryIterator(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates"); - foreach($tpldir as $fo) - { - if($fo->isFile()) + 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) - { + "styles" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; list($style) = $url_next; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "design"; $ste->vars["submenu"] = "styles"; $ste->vars["pagetitle"] = $translation["menu_styles"]; - if(isset($style)) - { - try - { + if (isset($style)) { + try { $style = Style::by_name($style); $ste->vars["style_name"] = $style->name; $ste->vars["style_code"] = $style->code; - } - catch(DoesNotExistError $e) - { + } 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 - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -1058,19 +1021,14 @@ $backend_subactions = url_action_subactions(array( } /* A write request? */ - if(isset($_POST["save_style"])) - { - if(Style::test_name($_POST["style_name"])) - { + 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 - { + try { $style = Style::by_name($_POST["style_name"]); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $style = Style::create($_POST["style_name"]); } @@ -1078,45 +1036,41 @@ $backend_subactions = url_action_subactions(array( $style->save(); $ste->vars["success"] = $translation["style_successfully_saved"]; - } - else + } else { $ste->vars["error"] = $translation["invalid_style_name"]; + } } /* Get all styles */ - $ste->vars["styles"] = array_map(function($s) { return $s->name; }, Style::all()); + $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) - { + "sections" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings; list($style) = $url_next; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "design"; $ste->vars["submenu"] = "sections"; $ste->vars["pagetitle"] = $translation["menu_pagesections"]; /* New section? */ - if(isset($_POST["new_section"])) - { - try - { + 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']}"))) + } 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"])) + } elseif (!Section::test_name($_POST["section_name"])) { $ste->vars["error"] = $translation["invalid_section_name"]; - else - { + } else { $section = Section::create($_POST["section_name"]); $section->template = $_POST["template"]; $section->title[$data["user"]->language] = new Translation($_POST["section_name"], ""); @@ -1127,188 +1081,161 @@ $backend_subactions = url_action_subactions(array( } /* Remove a style? */ - if(isset($_GET["rmstyle"]) and isset($_GET["rmfrom"])) - { - try - { + 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) - { + } catch (DoesNotExistError $e) { } } /* Delete a section? */ - if(isset($_POST["delete"]) and (@$_POST["really_delete"] == "yes") and isset($_POST["section_select"])) - { - try - { + 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"]) + if ($section->get_id() == $ratatoeskr_settings["default_section"]) { $ste->vars["error"] = $translation["cannot_delete_default_section"]; - else - { + } else { $default_section = Section::by_id($ratatoeskr_settings["default_section"]); - foreach($section->get_articles() as $article) - { + 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) - { + } catch (DoesNotExistError $e) { } } /* Make section default? */ - if(isset($_POST["make_default"]) and isset($_POST["section_select"])) - { - try - { + 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) - { + } catch (DoesNotExistError $e) { } } /* Set template? */ - if(isset($_POST["set_template"]) and isset($_POST["section_select"])) - { - try - { + 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']}"))) + 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 - { + } else { $section->template = $_POST["set_template_to"]; $section->save(); $ste->vars["success"] = $translation["successfully_set_template"]; } - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { } } /* Adding a style? */ - if(isset($_POST["add_style"]) and isset($_POST["section_select"])) - { - try - { + 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) - { + } catch (DoesNotExistError $e) { } } /* Set/unset title? */ - if(isset($_POST["set_title"]) and isset($_POST["section_select"])) - { - if(!isset($languages[$_POST["set_title_lang"]])) + 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 - { + } else { + try { $section = Section::by_name($_POST["section_select"]); - if(!empty($_POST["set_title_text"])) + 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"]])) + } elseif (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) - { + } catch (DoesNotExistError $e) { } } } /* Get all templates */ - $ste->vars["templates"] = array(); + $ste->vars["templates"] = []; $tpldir = new DirectoryIterator(SITE_BASE_PATH . "/ratatoeskr/templates/src/usertemplates"); - foreach($tpldir as $fo) - { - if($fo->isFile()) + 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()); + $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) + $ste->vars["sections"] = array_map(function ($section) use ($ratatoeskr_settings) { + $titles = []; + foreach ($section->title as $l => $t) { $titles[$l] = $t->text; - return array( + } + return [ "name" => $section->name, "title" => $titles, "template" => $section->template, - "styles" => array_map(function($style) { return $style->name; }, $section->get_styles()), + "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) - { + ]), + "admin" => url_action_subactions([ + "settings" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; - $url_next = array(); + $url_next = []; $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"] = []; + 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; + 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; + } 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"])) + if (isset($_POST["save_comment_settings"])) { + if (!in_array(@$_POST["comment_textprocessor"], $ste->vars["textprocessors"])) { $ste->vars["error"] = $translation["unknown_txtproc"]; - else - { + } 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"]; @@ -1316,36 +1243,31 @@ $backend_subactions = url_action_subactions(array( } /* Delete language? */ - if(isset($_POST["delete"]) and ($_POST["really_delete"] == "yes") and isset($_POST["language_select"])) - { - if($ratatoeskr_settings["default_language"] == $_POST["language_select"]) + 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"]; }); + } 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"])) - { + 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"]])) + 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"])) - { + } else { + if (!in_array($_POST["language_to_add"], $ratatoeskr_settings["languages"])) { $ls = $ratatoeskr_settings["languages"]; $ls[] = $_POST["language_to_add"]; $ratatoeskr_settings["languages"] = $ls; @@ -1357,39 +1279,35 @@ $backend_subactions = url_action_subactions(array( $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( + $ste->vars["used_langs"] = array_map(function ($l) use ($ratatoeskr_settings, $languages) { + return [ "code" => $l, "name" => $languages[$l]["language"], "default" => ($l == $ratatoeskr_settings["default_language"]) - );}, $ratatoeskr_settings["languages"]); + ]; + }, $ratatoeskr_settings["languages"]); echo $ste->exectemplate("/systemtemplates/settings.html"); }, - "users" => url_action_subactions(array( - "_index" => function(&$data, $url_now, &$url_next) - { + "users" => url_action_subactions([ + "_index" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $ratatoeskr_settings, $textprocessors; - $url_next = array(); + $url_next = []; $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"])) + if (isset($_POST["new_group"])) { + if (empty($_POST["group_name"])) { $ste->vars["error"] = $translation["empty_group_name"]; - else - { - try - { + } else { + try { Group::by_name($_POST["group_name"]); $ste->vars["error"] = $translation["group_already_exists"]; - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $group = Group::create($_POST["group_name"]); $ste->vars["success"] = $translation["successfully_created_group"]; } @@ -1397,19 +1315,14 @@ $backend_subactions = url_action_subactions(array( } /* Add a new user? */ - if(isset($_POST["new_user"])) - { - if(empty($_POST["username"])) + if (isset($_POST["new_user"])) { + if (empty($_POST["username"])) { $ste->vars["error"] = $translation["empty_username"]; - else - { - try - { + } else { + try { User::by_name($_POST["username"]); $ste->vars["error"] = $translation["user_already_exists"]; - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $group = User::create($_POST["username"], PasswordHash::create($_POST["initial_password"])); $ste->vars["success"] = $translation["successfully_created_user"]; } @@ -1417,129 +1330,112 @@ $backend_subactions = url_action_subactions(array( } /* Delete groups? */ - if(isset($_POST["delete_groups"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["groups_multiselect"]))) - { + if (isset($_POST["delete_groups"]) and ($_POST["really_delete"] == "yes") and (!empty($_POST["groups_multiselect"]))) { $deleted = 0; - foreach($_POST["groups_multiselect"] as $gid) - { - try - { + foreach ($_POST["groups_multiselect"] as $gid) { + try { $group = Group::by_id($gid); - if($group->name == "admins") - { + if ($group->name == "admins") { $ste->vars["error"] = $translation["cannot_delete_admin_group"]; - } - else - { + } else { $group->delete(); ++$deleted; } - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } - if($deleted > 0) + 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"]))) - { + 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()) + foreach ($_POST["users_multiselect"] as $uid) { + if ($uid == $data["user"]->get_id()) { $ste->vars["error"] = $translation["cannot_delete_yourself"]; - else - { - try - { + } else { + try { $user = User::by_id($uid); $user->delete(); ++$deleted; - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } } - if($deleted > 0) + if ($deleted > 0) { $ste->vars["success"] = $translation["successfully_deleted_users"]; + } } /* Get all groups */ - $ste->vars["groups"] = array_map(function($g) { return array( + $ste->vars["groups"] = array_map(function ($g) { + return [ "id" => $g->get_id(), "name" => $g->name - ); }, Group::all()); + ]; + }, Group::all()); /* Get all users */ - $ste->vars["users"] = array_map(function($u) { return array( + $ste->vars["users"] = array_map(function ($u) { + return [ "id" => $u->get_id(), "name" => $u->username, - "memberof" => array_map(function($g) { return $g->name; }, $u->get_groups()), + "memberof" => array_map(function ($g) { + return $g->name; + }, $u->get_groups()), "fullname" => $u->fullname, "mail" => $u->mail - ); }, User::all()); + ]; + }, User::all()); echo $ste->exectemplate("/systemtemplates/users.html"); }, - "u" => function(&$data, $url_now, &$url_next) - { + "u" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $admin_grp; - try - { + try { $user = User::by_id($url_next[0]); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - $url_next = array(); + $url_next = []; $ste->vars["section"] = "admin"; $ste->vars["submenu"] = "users"; $ste->vars["pagetitle"] = $user->username; /* Modify data? */ - if(isset($_POST["change_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"]; + $current_groups = array_map(function ($g) { + return $g->get_id(); + }, $user->get_groups()); + $new_groups = empty($_POST[groups_multiselect]) ? [] : $_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 - { + foreach ($groups_exclude as $gid) { + try { $g = Group::by_id($gid); $g->exclude_user($user); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } - foreach($groups_include as $gid) - { - try - { + foreach ($groups_include as $gid) { + try { $g = Group::by_id($gid); $g->include_user($user); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } @@ -1550,70 +1446,62 @@ $backend_subactions = url_action_subactions(array( } /* New Password? */ - if(isset($_POST["new_password"])) - { + if (isset($_POST["new_password"])) { $pwhash = PasswordHash::create($_POST["password"]); $user->pwhash = $pwhash; - if($user->get_id() == $data["user"]->get_id()) + 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( + $ste->vars["u"] = [ "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( + ]; + $ste->vars["groups"] = array_map(function ($g) use ($user) { + return [ "id" => $g->get_id(), "name" => $g->name, "member" => $user->member_of($g) - ); }, Group::all()); + ]; + }, Group::all()); echo $ste->exectemplate("/systemtemplates/user.html"); } - )), - "repos" => function(&$data, $url_now, &$url_next) - { + ]), + "repos" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "admin"; $ste->vars["submenu"] = "repos"; $ste->vars["pagetitle"] = $translation["menu_plugin_repos"]; /* Add a repo? */ - if(isset($_POST["add_repo"])) - { - try - { + if (isset($_POST["add_repo"])) { + try { $repo = Repository::create($_POST["repo_baseurl"]); $ste->vars["success"] = $translation["successfully_added_repo"]; - } - catch(RepositoryUnreachableOrInvalid $e) - { + } 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 - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -1621,83 +1509,69 @@ $backend_subactions = url_action_subactions(array( } /* Force refresh? */ - if(isset($_POST["force_repo_refresh"])) - { - $failed = array(); - foreach($_POST["repos_multiselect"] as $repo_id) - { - try - { + if (isset($_POST["force_repo_refresh"])) { + $failed = []; + foreach ($_POST["repos_multiselect"] as $repo_id) { + try { $repo = Repository::by_id($repo_id); - $repo->refresh(True); - } - catch(DoesNotExistError $e) - { + $repo->refresh(true); + } catch (DoesNotExistError $e) { continue; - } - catch(RepositoryUnreachableOrInvalid $e) - { + } catch (RepositoryUnreachableOrInvalid $e) { $failed[] = $repo->get_name(); } } $ste->vars["success"] = $translation["successfully_refreshed_repos"]; - if(!empty($failed)) + 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( + function ($r) { + try { + $r->refresh(); + } catch (RepositoryUnreachableOrInvalid $e) { + } + return [ "id" => $r->get_id(), "name" => $r->get_name(), "description" => $r->get_description(), "baseurl" => $r->get_baseurl() - ); - }, $all_repos); + ]; + }, + $all_repos + ); echo $ste->exectemplate("/systemtemplates/repos.html"); } - )), - "plugin" => url_action_subactions(array( - "list" => function(&$data, $url_now, &$url_next) - { + ]), + "plugin" => url_action_subactions([ + "list" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $plugin_objs, $api_compat; - $url_next = array(); + $url_next = []; $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 - { + 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])) - { + 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) - { + } catch (DoesNotExistError $e) { continue; } } @@ -1706,96 +1580,84 @@ $backend_subactions = url_action_subactions(array( } /* Activate or deactivate plugins? */ - if((isset($_POST["activate"]) or isset($_POST["deactivate"])) and (!empty($_POST["plugins_multiselect"]))) - { - $api_incompat = array(); + if ((isset($_POST["activate"]) or isset($_POST["deactivate"])) and (!empty($_POST["plugins_multiselect"]))) { + $api_incompat = []; $newstatus = isset($_POST["activate"]); - foreach($_POST["plugins_multiselect"] as $pid) - { - try - { + foreach ($_POST["plugins_multiselect"] as $pid) { + try { $plugin = Plugin::by_id($pid); - if(!$plugin->installed) + if (!$plugin->installed) { continue; - if($newstatus and (!in_array($plugin->api, $api_compat))) - { + } + 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]))) - { + if ($newstatus and (!isset($plugin_objs[$pid]))) { eval($plugin->code); $plugin_objs[$pid] = new $plugin->classname($pid); $plugin_objs[$pid]->init(); } - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; } } $ste->vars["success"] = $translation[$newstatus ? "plugins_activated" : "plugins_deactivated"]; - if(!empty($api_incompat)) + 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))); + $stream_ctx = stream_context_create(["http" => ["timeout" => 5]]); /* Update plugins? */ - if(isset($_POST["update"]) and (!empty($_POST["plugins_multiselect"]))) - { - $updated = array(); - foreach($_POST["plugins_multiselect"] as $pid) - { - try - { + if (isset($_POST["update"]) and (!empty($_POST["plugins_multiselect"]))) { + $updated = []; + 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)); + 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->update = true; $plugin->save(); $updated[] = $plugin->name; } } - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { continue; - } - catch(InvalidPackage $e) - { + } catch (InvalidPackage $e) { continue; } } - if(empty($updated)) + if (empty($updated)) { $ste->vars["success"] = $translation["nothing_to_update"]; - else + } 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) + $ste->vars["plugins"] = []; + $api_incompat = []; + foreach ($all_plugins as $p) { + if (!$p->installed) { continue; + } - if(!in_array($p->api, $api_compat)) + if (!in_array($p->api, $api_compat)) { $api_incompat[] = $p->name . ("(ID: " . $p->get_id() . ")"); + } - $ste->vars["plugins"][] = array( + $ste->vars["plugins"][] = [ "id" => $p->get_id(), "name" => $p->name, "versiontext" => $p->versiontext, @@ -1804,30 +1666,28 @@ $backend_subactions = url_action_subactions(array( "web" => $p->web, "author" => $p->author, "help" => !empty($p->help) - ); + ]; } - if(!empty($api_incompat)) + 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) - { + "help" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; - try - { + try { $plugin = Plugin::by_id($url_next[0]); - if(empty($plugin->help)) + if (empty($plugin->help)) { throw new NotFoundError(); - } - catch(DoesNotExistError $e) - { + } + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - $url_next = array(); + $url_next = []; $ste->vars["section"] = "plugins"; $ste->vars["submenu"] = ""; @@ -1836,137 +1696,117 @@ $backend_subactions = url_action_subactions(array( echo $ste->exectemplate("/systemtemplates/pluginhelp.html"); }, - "install" => function(&$data, $url_now, &$url_next) - { + "install" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root, $api_compat; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "plugins"; $ste->vars["submenu"] = "installplugins"; $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; $all_repos = Repository::all(); - foreach($all_repos as $repo) - { - try - { + foreach ($all_repos as $repo) { + try { $repo->refresh(); - } - catch(RepositoryUnreachableOrInvalid $e) - { + } catch (RepositoryUnreachableOrInvalid $e) { continue; } } - if(isset($_POST["installpackage"])) - { - if(is_uploaded_file($_FILES["pluginpackage"]["tmp_name"])) - { - try - { + 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)) - { + if (in_array($package->api, $api_compat)) { $plugin = Plugin::create(); $plugin->fill_from_pluginpackage($package); - $plugin->installed = False; - $plugin->active = False; + $plugin->installed = false; + $plugin->active = false; $plugin->save(); - $url_next = array("confirminstall", (string) $plugin->get_id()); + $url_next = ["confirminstall", (string) $plugin->get_id()]; return; - } - else + } else { $ste->vars["error"] = str_replace("[[API]]", $package->api, $translation["incompatible_plugin"]); - } - catch(InvalidPackage $e) - { + } + } catch (InvalidPackage $e) { $ste->vars["error"] = $translation["invalid_package"]; unlink($_FILES["pluginpackage"]["tmp_name"]); } - } - else + } else { $ste->vars["error"] = $translation["upload_failed"]; + } } - if(isset($_POST["search_in_repos"])) - { - $ste->vars["searchresults"] = array(); + if (isset($_POST["search_in_repos"])) { + $ste->vars["searchresults"] = []; $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( + 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"][] = [ "name" => $pkg[0], "description" => $pkg[2], "reponame" => $repo->get_name(), "repoid" => $repo->get_id() - ); + ]; + } } } } - $ste->vars["repos"] = array_map(function($r) { return array( + $ste->vars["repos"] = array_map(function ($r) { + return [ "id" => $r->get_id(), "name" => $r->get_name() - ); }, $all_repos); + ]; + }, $all_repos); echo $ste->exectemplate("/systemtemplates/plugininstall.html"); }, - "repoinstall" => function(&$data, $url_now, &$url_next) - { + "repoinstall" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $rel_path_to_root; - $stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); + $stream_ctx = stream_context_create(["http" => ["timeout" => 5]]); - try - { + 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->installed = false; + $plugin->active = false; $plugin->save(); - $url_next = array("confirminstall", (string) $plugin->get_id()); - } - catch(DoesNotExistError $e) - { + $url_next = ["confirminstall", (string) $plugin->get_id()]; + } catch (DoesNotExistError $e) { $ste->vars["error"] = $translation["package_or_repo_not_found"]; - $url_next = array("install"); - } - catch(InvalidPackage $e) - { + $url_next = ["install"]; + } catch (InvalidPackage $e) { $ste->vars["error"] = $translation["invalid_package"]; - $url_next = array("install"); + $url_next = ["install"]; } }, - "confirminstall" => function(&$data, $url_now, &$url_next) - { + "confirminstall" => function (&$data, $url_now, &$url_next) { global $ste, $translation, $languages, $rel_path_to_root; list($plugin_id) = $url_next; - $url_next = array(); + $url_next = []; $ste->vars["section"] = "plugins"; $ste->vars["submenu"] = "installplugins"; $ste->vars["pagetitle"] = $translation["menu_plugininstall"]; - try - { + try { $plugin = Plugin::by_id($plugin_id); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } - if($plugin->installed) + if ($plugin->installed) { throw new NotFoundError(); + } $ste->vars["plugin_id"] = $plugin->get_id(); $ste->vars["name"] = $plugin->name; @@ -1974,29 +1814,26 @@ $backend_subactions = url_action_subactions(array( $ste->vars["code"] = $plugin->code; $ste->vars["license"] = $plugin->license; - if(isset($_POST["yes"])) - { - $plugin->installed = True; + 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"); + $url_next = ["list"]; return; } - if(isset($_POST["no"])) - { + if (isset($_POST["no"])) { $plugin->delete(); - $url_next = array("install"); + $url_next = ["install"]; return; } echo $ste->exectemplate("/systemtemplates/confirminstall.html"); } - )), + ]), "pluginpages" => url_action_subactions($pluginpages_handlers) -)); - +]); } diff --git a/ratatoeskr/config.php b/ratatoeskr/config.php index 51ec257..db2d6e5 100644 --- a/ratatoeskr/config.php +++ b/ratatoeskr/config.php @@ -1,8 +1,8 @@ <?php -define("__DEBUG__", False); -define("CONFIG_FILLED_OUT", False); -define("PLUGINS_ENABLED", True); +define("__DEBUG__", false); +define("CONFIG_FILLED_OUT", false); +define("PLUGINS_ENABLED", true); $config["mysql"]["server"] = 'localhost'; $config["mysql"]["db"] = ''; diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php index 1103e59..51e13f7 100644 --- a/ratatoeskr/frontend.php +++ b/ratatoeskr/frontend.php @@ -32,12 +32,12 @@ require_once(dirname(__FILE__) . "/libs/kses.php"); */ function section_transform_ste($section, $lang) { - return array( + return [ "id" => $section->get_id(), "name" => $section->name, "title" => $section->title[$lang]->text, "__obj" => $section - ); + ]; } /* @@ -57,18 +57,15 @@ function section_transform_ste($section, $lang) */ function tag_transform_ste($tag, $lang) { - try - { - return array( + try { + return [ "id" => $tag->get_id(), "name" => $tag->name, "title" => $tag->title[$lang]->text, "__obj" => $tag - ); - } - catch(DoesNotExistError $e) - { - return False; + ]; + } catch (DoesNotExistError $e) { + return false; } } @@ -101,12 +98,13 @@ function article_transform_ste($article, $lang) { global $rel_path_to_root; - $languages = array(); + $languages = []; $a_section = $article->get_section(); - foreach($article->title as $language => $_) + foreach ($article->title as $language => $_) { $languages[$language] = "$rel_path_to_root/$language/{$a_section->name}/{$article->urlname}"; + } - return array( + return [ "id" => $article->get_id(), "urlname" => $article->urlname, "fullurl" => htmlesc("$rel_path_to_root/$lang/{$a_section->name}/{$article->urlname}"), @@ -117,11 +115,13 @@ function article_transform_ste($article, $lang) "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())), + "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 - ); + ]; } /* @@ -142,13 +142,13 @@ function comment_transform_ste($comment) { global $rel_path_to_root, $ratatoeskr_settings; - return array( + return [ "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 */ @@ -179,67 +179,65 @@ function comment_transform_ste($comment) * Returns: * All results from the tag content. */ -$ste->register_tag("articles_get", function($ste, $params, $sub) -{ +$ste->register_tag("articles_get", function ($ste, $params, $sub) { $lang = $ste->vars["language"]; - if(!isset($params["var"])) + 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 = ["langavail" => $lang, "onlyvisible" => true]; + if (isset($params["id"])) { $criterias["id"] = $params["id"]; - if(isset($params["urlname"])) + } + if (isset($params["urlname"])) { $criterias["urlname"]; - if(isset($params["status"])) + } + if (isset($params["status"])) { $criterias["status"] = $params["status"]; - if(isset($params["sectionvar"])) - { + } + if (isset($params["sectionvar"])) { $sectionvar = $ste->get_var_by_name($params["sectionvar"]); $criterias["section"] = $sectionvar["__obj"]; - } - else if(isset($params["section"])) - { - try - { + } elseif (isset($params["section"])) { + try { $criterias["section"] = Section::by_name($params["section"]); + } catch (DoesNotExistError $e) { } - catch(DoesNotExistError $e) {} } - if(isset($params["tagvar"])) - { + if (isset($params["tagvar"])) { $tagvar = $ste->get_var_by_name($params["tagvar"]); $criterias["tag"] = $tagvar["__obj"]; } - if(isset($params["tag"])) - { - try - { + if (isset($params["tag"])) { + try { $criterias["tag"] = Tag::by_name($params["tag"]); + } catch (DoesNotExistError $e) { } - catch(DoesNotExistError $e) {} } - $field = NULL; - $direction = NULL; - if(isset($params["sort"])) - { + $field = null; + $direction = null; + if (isset($params["sort"])) { list($field, $direction) = explode(" ", $params["sort"]); - if($direction === NULL) - $field = NULL; + 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); + $result = array_map(function ($article) use ($lang) { + return article_transform_ste($article, $lang); + }, $result); - if(isset($params["perpage"]) and isset($params["maxpage"])) + if (isset($params["perpage"]) and isset($params["maxpage"])) { $ste->set_var_by_name($params["maxpage"], $maxpage == 0 ? 1 : $maxpage); + } $output = ""; - foreach($result as $article) - { + foreach ($result as $article) { $ste->set_var_by_name($params["var"], $article); $output .= $sub($ste); } @@ -262,37 +260,40 @@ $ste->register_tag("articles_get", function($ste, $params, $sub) * Returns: * All results from the tag content. */ -$ste->register_tag("section_list", function($ste, $params, $sub) -{ +$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"])) + if (!isset($params["var"])) { throw new \ste\RuntimeException("Parameter var is needed in article_get!"); + } $result = Section::all(); - if(isset($params["exclude"])) - { + 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 ($exclude) { + return !in_array($section->name, $exclude); + }); } - $result = array_filter($result, function($section) use ($default_section) { return $section->get_id() != $default_section; }); + $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); + $result = array_map(function ($section) use ($lang) { + return section_transform_ste($section, $lang); + }, $result); - if($ste->evalbool($params["include_default"])) - { + 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) - { + foreach ($result as $section) { $ste->set_var_by_name($params["var"], $section); $output .= $sub($ste); } @@ -309,27 +310,23 @@ $ste->register_tag("section_list", function($ste, $params, $sub) * Returns: * The number of comments. */ -$ste->register_tag("article_comments_count", function($ste, $params, $sub) -{ - if(!isset($params["article"])) +$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); + } + $tpl_article = $ste->get_var_reference($params["article"], false); $lang = $ste->vars["language"]; - if(isset($tpl_article["__obj"])) + if (isset($tpl_article["__obj"])) { $article = $tpl_article["__obj"]; - else - { - try - { + } else { + try { $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { return 0; } } - $comments = $article->get_comments($lang, True); + $comments = $article->get_comments($lang, true); $tpl_article["__comments"] = $comments; return count($comments); }); @@ -350,44 +347,41 @@ $ste->register_tag("article_comments_count", function($ste, $params, $sub) * Returns: * All results from the tag content. */ -$ste->register_tag("article_comments", function($ste, $params, $sub) -{ - if(!isset($params["var"])) +$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"])) + } + if (!isset($params["article"])) { throw new \ste\RuntimeException("Need parameter 'article' in ste:article_comments."); - $tpl_article = $ste->get_var_reference($params["article"], False); + } + $tpl_article = $ste->get_var_reference($params["article"], false); $lang = $ste->vars["language"]; - if(isset($tpl_article["__comments"])) + if (isset($tpl_article["__comments"])) { $comments = $tpl_article["__comments"]; - else - { - if(isset($tpl_article["__obj"])) + } else { + if (isset($tpl_article["__obj"])) { $article = $tpl_article["__obj"]; - else - { - try - { + } else { + try { $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { return ""; } } - $comments = $article->get_comments($lang, True); + $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; }); + 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) - { + foreach ($comments as $comment) { $ste->set_var_by_name($params["var"], $comment); $output .= $sub($ste); } @@ -424,50 +418,46 @@ $ste->register_tag("article_comments", function($ste, $params, $sub) * See Also: * The "prevcomment" field in <$current>. */ -$ste->register_tag("comment_form", function($ste, $params, $sub) -{ +$ste->register_tag("comment_form", function ($ste, $params, $sub) { global $translation; - if(!isset($params["article"])) + if (!isset($params["article"])) { throw new \ste\RuntimeException("Need parameter 'article' in ste:comment_form."); - $tpl_article = $ste->get_var_reference($params["article"], False); + } + $tpl_article = $ste->get_var_reference($params["article"], false); - if(isset($tpl_article["__obj"])) - $article = $tpl_article["__obj"]; - else - { - try - { + if (isset($tpl_article["__obj"])) { + $article = $tpl_article["__obj"]; + } else { + try { $article = Article::by_id(@$tpl_article["id"]); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { return ""; } } - if(!$article->allow_comments) + 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); + $token = uniqid("", true); $_SESSION["ratatoeskr_comment_tokens"][$token] = time(); $form_header = "<form action=\"{$tpl_article["fullurl"]}?comment\" method=\"post\" accept-charset=\"UTF-8\"><input type=\"hidden\" name=\"comment_token\" value=\"$token\" />"; $previewbtn = $ste->evalbool(@$params["previewbtn"]) ? " <input type=\"submit\" name=\"preview_comment\" value=\"{$translation["comment_form_preview"]}\" />" : ""; - if($ste->evalbool(@$params["default"])) + if ($ste->evalbool(@$params["default"])) { $form_body = "<p>{$translation["comment_form_name"]}: <input type=\"text\" name=\"author_name\" value=\"" . htmlesc(@$_POST["author_name"]) . "\" /></p> <p>{$translation["comment_form_mail"]}: <input type=\"text\" name=\"author_mail\" value=\"" . htmlesc(@$_POST["author_mail"]) . "\" /></p> <p>{$translation["comment_form_text"]}:<br /><textarea name=\"comment_text\" cols=\"50\" rows=\"10\">" . htmlesc(@$_POST["comment_text"]) . "</textarea></p> <p><input type=\"submit\" name=\"post_comment\" value=\"{$translation["comment_form_submit"]}\" />$previewbtn</p>"; - else - { - $ste->vars["current"]["oldcomment"] = array( + } else { + $ste->vars["current"]["oldcomment"] = [ "name" => @$_POST["author_name"], "mail" => @$_POST["author_mail"], "text" => @$_POST["comment_text"] - ); + ]; $form_body = $sub($ste); unset($ste->vars["current"]["oldcomment"]); } @@ -494,16 +484,18 @@ $ste->register_tag("comment_form", function($ste, $params, $sub) * A Link to the previous / next page. */ -$ste->register_tag("page_prev", function($ste, $params, $sub) -{ +$ste->register_tag("page_prev", function ($ste, $params, $sub) { global $translation; - if(!isset($params["current"])) + if (!isset($params["current"])) { throw new \ste\RuntimeException("Need parameter 'current' in ste:page_prev."); - if(!isset($params["maxpage"])) + } + if (!isset($params["maxpage"])) { throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_prev."); + } - if($params["current"] == 1) + if ($params["current"] == 1) { return ""; + } parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); $query["page"] = $params["current"] - 1; @@ -511,16 +503,18 @@ $ste->register_tag("page_prev", function($ste, $params, $sub) return "<a href=\"" . htmlesc($url) . "\">" . (($ste->evalbool(@$params["default"])) ? $translation["page_prev"] : $sub($ste)) . "</a>"; }); -$ste->register_tag("page_next", function($ste, $params, $sub) -{ +$ste->register_tag("page_next", function ($ste, $params, $sub) { global $translation; - if(!isset($params["current"])) + if (!isset($params["current"])) { throw new \ste\RuntimeException("Need parameter 'current' in ste:page_next."); - if(!isset($params["maxpage"])) + } + if (!isset($params["maxpage"])) { throw new \ste\RuntimeException("Need parameter 'maxpage' in ste:page_next."); + } - if($params["current"] == $params["maxpage"]) + if ($params["current"] == $params["maxpage"]) { return ""; + } parse_str(parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY), $query); $query["page"] = $params["current"] + 1; @@ -546,44 +540,39 @@ $ste->register_tag("page_next", function($ste, $params, $sub) * Returns: * All results from the tag content. */ -$ste->register_tag("languages", function($ste, $params, $sub) -{ +$ste->register_tag("languages", function ($ste, $params, $sub) { global $languages, $ratatoeskr_settings, $rel_path_to_root; - if(!isset($params["var"])) + 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"])) + $langs = []; + if (isset($ste->vars["current"]["article"])) { + if (isset($ste->vars["current"]["article"]["__obj"])) { $article = $ste->vars["current"]["article"]["__obj"]; - else - { - try - { + } else { + try { $article = Article::by_id($ste->vars["current"]["article"]["id"]); + } catch (DoesNotExistError $e) { } - catch(DoesNotExistError $e) {} } - foreach($article->title as $lang => $_) + foreach ($article->title as $lang => $_) { $langs[] = $lang; - } - else - { - - foreach($ratatoeskr_settings["languages"] as $lang) + } + } else { + foreach ($ratatoeskr_settings["languages"] as $lang) { $langs[] = $lang; + } } $output = ""; - foreach($langs as $lang) - { - $ste->set_var_by_name($params["var"], array( + foreach ($langs as $lang) { + $ste->set_var_by_name($params["var"], [ "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; @@ -599,44 +588,36 @@ $ste->register_tag("languages", function($ste, $params, $sub) * Returns: * The current styles (either linked or embedded) */ -$ste->register_tag("styles_load", function($ste, $params, $sub) -{ +$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"))) + if (isset($params["mode"]) and (($params["mode"] == "embed") or ($params["mode"] == "link"))) { $mode = $params["mode"]; - else + } else { $mode = "link"; + } - if($mode == "embed") - { + if ($mode == "embed") { $output = ""; - if(isset($ste->vars["current"]["__style_objs"])) - { - foreach($ste->vars["current"]["__style_objs"] as $style) + 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 - { + } + } 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) - { + } catch (DoesNotExistError $e) { $output .= "/* Warning: Failed to load style: $stylename */\n"; } } } $output = "<style type=\"text/css\">\n" . htmlesc($output) . "</style>"; - } - else - { + } else { $output = ""; - foreach($ste->vars["current"]["styles"] as $stylename) + foreach ($ste->vars["current"]["styles"] as $stylename) { $output .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$rel_path_to_root/css.php?name=" . htmlesc($stylename) . "\" />\n"; + } } return $output; }); @@ -651,24 +632,24 @@ $ste->register_tag("styles_load", function($ste, $params, $sub) * Returns: * A HTML title tag that describes the current (sub)page. */ -$ste->register_tag("title", function($ste, $params, $sub) -{ +$ste->register_tag("title", function ($ste, $params, $sub) { $pagetitle = $sub($ste); - if(isset($ste->vars["current"]["article"])) + if (isset($ste->vars["current"]["article"])) { return "<title>" . htmlesc($ste->vars["current"]["article"]["title"]) . " – $pagetitle" . "</title>"; - if(isset($ste->vars["current"]["section"])) + } + if (isset($ste->vars["current"]["section"])) { return "<title>" . htmlesc($ste->vars["current"]["section"]["title"]) . " – $pagetitle" . "</title>"; + } return "<title>$pagetitle</title>"; }); function make_on_anything_tag($field) { - return function($ste, $params, $sub) use ($field) - { - if($ste->evalbool(@$ste->vars["current"][$field])) - { - if(!empty($params["var"])) + 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); } }; @@ -734,27 +715,32 @@ $ste->register_tag("on_section", make_on_anything_tag("section")); * The short form (e.g. "en" for English, "de" for German, ...) of the current language. */ -$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... */ - { +$comment_validators = [ + 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"])) + if (empty($_POST["author_name"])) { throw new CommentRejected($translation["author_name_missing"]); - if(empty($_POST["author_mail"])) + } + if (empty($_POST["author_mail"])) { throw new CommentRejected($translation["author_email_missing"]); - if(empty($_POST["comment_text"])) + } + if (empty($_POST["comment_text"])) { throw new CommentRejected($translation["comment_text_missing"]); - if(!isset($_POST["comment_token"])) + } + if (!isset($_POST["comment_token"])) { throw new CommentRejected($translation["comment_form_invalid"]); - if(!isset($_SESSION["ratatoeskr_comment_tokens"][$_POST["comment_token"]])) + } + 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. */ + } + 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(); +$on_comment_store = []; /* * Function: frontend_url_handler @@ -762,14 +748,14 @@ $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(); + $path = array_merge([$url_now], $url_next); + $url_next = []; /* If no language or an invalid language was given, fix it. */ - if((count($path) == 0) or (!isset($languages[$path[0]]))) - { - if(count($path > 0)) + if ((count($path) == 0) or (!isset($languages[$path[0]]))) { + if (count($path > 0)) { array_shift($path); + } array_unshift($path, $ratatoeskr_settings["default_language"]); } @@ -779,80 +765,63 @@ function frontend_url_handler(&$data, $url_now, &$url_next) $ste->vars["language"] = $lang; load_language($languages[$lang]["translation_exist"] ? $lang : "en"); /* English is always available */ - if(count($path) != 0) + if (count($path) != 0) { $section_name = array_shift($path); - else - $section_name = NULL; + } else { + $section_name = null; + } - if($section_name == "_tags") - { - try - { + if ($section_name == "_tags") { + try { $tag = Tag::by_name(array_shift($path)); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } $ste->vars["current"]["tag"] = tag_transform_ste($tag, $lang); - } - else - { - if($section_name === NULL) + } else { + if ($section_name === null) { $section = Section::by_id($ratatoeskr_settings["default_section"]); - else - { - try - { + } else { + try { $section = Section::by_name($section_name); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } } - if(count($path)== 0) + if (count($path)== 0) { $ste->vars["current"]["section"] = section_transform_ste($section, $lang); - else - { - try - { + } else { + try { $article = Article::by_urlname(array_shift($path)); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { throw new NotFoundError(); } $ste->vars["current"]["article"] = article_transform_ste($article, $lang); - if(isset($_GET["comment"])) - { - if(isset($_POST["preview_comment"])) + 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) + } elseif (isset($_POST["post_comment"])) { + $rejected = false; + try { + foreach ($comment_validators as $validator) { call_user_func($validator); - } - catch(CommentRejected $e) - { + } + } catch (CommentRejected $e) { $ste->vars["current"]["comment_fail"] = htmlesc($e->getMessage()); - $rejected = True; + $rejected = true; } - if(!$rejected) - { + 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) + foreach ($on_comment_store as $ocs_fx) { call_user_func($ocs_fx, $comment); + } } } } @@ -861,11 +830,11 @@ function frontend_url_handler(&$data, $url_now, &$url_next) $ste->vars["current"]["page"] = (isset($_GET["page"]) and is_numeric($_GET["page"])) ? $_GET["page"] : 1; - if(!isset($section)) + if (!isset($section)) { $section = Section::by_id($ratatoeskr_settings["default_section"]); + } - foreach($section->get_styles() as $style) - { + foreach ($section->get_styles() as $style) { $ste->vars["current"]["styles"][] = $style->name; $ste->vars["current"]["__style_objs"][] = $style; } @@ -879,4 +848,6 @@ function frontend_url_handler(&$data, $url_now, &$url_next) * See Also: * <register_comment_validator> */ -class CommentRejected extends Exception {} +class CommentRejected extends Exception +{ +} diff --git a/ratatoeskr/languages.php b/ratatoeskr/languages.php index 31b504e..2c31aa4 100644 --- a/ratatoeskr/languages.php +++ b/ratatoeskr/languages.php @@ -17,189 +17,189 @@ * Source: * 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) -); +$languages = [ + "aa" => ["language" => "Afaraf", "translation_exist" => false], + "ab" => ["language" => "аҧсуа", "translation_exist" => false], + "ae" => ["language" => "avesta", "translation_exist" => false], + "af" => ["language" => "Afrikaans", "translation_exist" => false], + "ak" => ["language" => "Akan", "translation_exist" => false], + "am" => ["language" => "አማርኛ", "translation_exist" => false], + "an" => ["language" => "Aragonés", "translation_exist" => false], + "ar" => ["language" => "العربية", "translation_exist" => false], + "as" => ["language" => "অসমীয়া", "translation_exist" => false], + "av" => ["language" => "авар мацӀ, магӀарул мацӀ", "translation_exist" => false], + "ay" => ["language" => "aymar aru", "translation_exist" => false], + "az" => ["language" => "azərbaycan dili", "translation_exist" => false], + "ba" => ["language" => "башҡорт теле", "translation_exist" => false], + "be" => ["language" => "Беларуская", "translation_exist" => false], + "bg" => ["language" => "български език", "translation_exist" => false], + "bh" => ["language" => "भोजपुरी", "translation_exist" => false], + "bi" => ["language" => "Bislama", "translation_exist" => false], + "bm" => ["language" => "bamanankan", "translation_exist" => false], + "bn" => ["language" => "বাংলা", "translation_exist" => false], + "bo" => ["language" => "བོད་ཡིག", "translation_exist" => false], + "br" => ["language" => "brezhoneg", "translation_exist" => false], + "bs" => ["language" => "bosanski jezik", "translation_exist" => false], + "ca" => ["language" => "Català", "translation_exist" => false], + "ce" => ["language" => "нохчийн мотт", "translation_exist" => false], + "ch" => ["language" => "Chamoru", "translation_exist" => false], + "co" => ["language" => "corsu, lingua corsa", "translation_exist" => false], + "cr" => ["language" => "ᓀᐦᐃᔭᐍᐏᐣ", "translation_exist" => false], + "cs" => ["language" => "česky, čeština", "translation_exist" => false], + "cu" => ["language" => "ѩзыкъ словѣньскъ", "translation_exist" => false], + "cv" => ["language" => "чӑваш чӗлхи", "translation_exist" => false], + "cy" => ["language" => "Cymraeg", "translation_exist" => false], + "da" => ["language" => "dansk", "translation_exist" => false], + "de" => ["language" => "Deutsch", "translation_exist" => true], + "dv" => ["language" => "ދިވެހި", "translation_exist" => false], + "dz" => ["language" => "རྫོང་ཁ", "translation_exist" => false], + "ee" => ["language" => "Eʋegbe", "translation_exist" => false], + "el" => ["language" => "Ελληνικά", "translation_exist" => false], + "en" => ["language" => "English", "translation_exist" => true], + "eo" => ["language" => "Esperanto", "translation_exist" => false], + "es" => ["language" => "español, castellano", "translation_exist" => false], + "et" => ["language" => "eesti, eesti keel", "translation_exist" => false], + "eu" => ["language" => "euskara, euskera", "translation_exist" => false], + "fa" => ["language" => "فارسی", "translation_exist" => false], + "ff" => ["language" => "Fulfulde, Pulaar, Pular", "translation_exist" => false], + "fi" => ["language" => "suomi, suomen kieli", "translation_exist" => false], + "fj" => ["language" => "vosa Vakaviti", "translation_exist" => false], + "fo" => ["language" => "føroyskt", "translation_exist" => false], + "fr" => ["language" => "français, langue française", "translation_exist" => false], + "fy" => ["language" => "Frysk", "translation_exist" => false], + "ga" => ["language" => "Gaeilge", "translation_exist" => false], + "gd" => ["language" => "Gàidhlig", "translation_exist" => false], + "gl" => ["language" => "Galego", "translation_exist" => false], + "gn" => ["language" => "Avañe'ẽ", "translation_exist" => false], + "gu" => ["language" => "ગુજરાતી", "translation_exist" => false], + "gv" => ["language" => "Gaelg, Gailck", "translation_exist" => false], + "ha" => ["language" => "Hausa, هَوُسَ", "translation_exist" => false], + "he" => ["language" => "עברית", "translation_exist" => false], + "hi" => ["language" => "हिन्दी, हिंदी", "translation_exist" => false], + "ho" => ["language" => "Hiri Motu", "translation_exist" => false], + "hr" => ["language" => "hrvatski", "translation_exist" => false], + "ht" => ["language" => "Kreyòl ayisyen", "translation_exist" => false], + "hu" => ["language" => "Magyar", "translation_exist" => false], + "hy" => ["language" => "Հայերեն", "translation_exist" => false], + "hz" => ["language" => "Otjiherero", "translation_exist" => false], + "ia" => ["language" => "Interlingua", "translation_exist" => false], + "id" => ["language" => "Bahasa Indonesia", "translation_exist" => false], + "ie" => ["language" => "Originally called ", "translation_exist" => false], + "ig" => ["language" => "Asụsụ Igbo", "translation_exist" => false], + "ii" => ["language" => "ꆈꌠ꒿ Nuosuhxop", "translation_exist" => false], + "ik" => ["language" => "Iñupiaq, Iñupiatun", "translation_exist" => false], + "io" => ["language" => "Ido", "translation_exist" => false], + "is" => ["language" => "Íslenska", "translation_exist" => false], + "it" => ["language" => "Italiano", "translation_exist" => false], + "iu" => ["language" => "ᐃᓄᒃᑎᑐᑦ", "translation_exist" => false], + "ja" => ["language" => "日本語 (にほんご)", "translation_exist" => false], + "jv" => ["language" => "basa Jawa", "translation_exist" => false], + "ka" => ["language" => "ქართული", "translation_exist" => false], + "kg" => ["language" => "KiKongo", "translation_exist" => false], + "ki" => ["language" => "Gĩkũyũ", "translation_exist" => false], + "kj" => ["language" => "Kuanyama", "translation_exist" => false], + "kk" => ["language" => "Қазақ тілі", "translation_exist" => false], + "kl" => ["language" => "kalaallisut, kalaallit oqaasii", "translation_exist" => false], + "km" => ["language" => "ភាសាខ្មែរ", "translation_exist" => false], + "kn" => ["language" => "ಕನ್ನಡ", "translation_exist" => false], + "ko" => ["language" => "한국어 (韓國語), 조선어 (朝鮮語)", "translation_exist" => false], + "kr" => ["language" => "Kanuri", "translation_exist" => false], + "ks" => ["language" => "कश्मीरी, كشميري", "translation_exist" => false], + "ku" => ["language" => "Kurdî, كوردی", "translation_exist" => false], + "kv" => ["language" => "коми кыв", "translation_exist" => false], + "kw" => ["language" => "Kernewek", "translation_exist" => false], + "ky" => ["language" => "кыргыз тили", "translation_exist" => false], + "la" => ["language" => "latine, lingua latina", "translation_exist" => false], + "lb" => ["language" => "Lëtzebuergesch", "translation_exist" => false], + "lg" => ["language" => "Luganda", "translation_exist" => false], + "li" => ["language" => "Limburgs", "translation_exist" => false], + "ln" => ["language" => "Lingála", "translation_exist" => false], + "lo" => ["language" => "ພາສາລາວ", "translation_exist" => false], + "lt" => ["language" => "lietuvių kalba", "translation_exist" => false], + "lu" => ["language" => "Luba-Katanga", "translation_exist" => false], + "lv" => ["language" => "latviešu valoda", "translation_exist" => false], + "mg" => ["language" => "Malagasy fiteny", "translation_exist" => false], + "mh" => ["language" => "Kajin M̧ajeļ", "translation_exist" => false], + "mi" => ["language" => "te reo Māori", "translation_exist" => false], + "mk" => ["language" => "македонски јазик", "translation_exist" => false], + "ml" => ["language" => "മലയാളം", "translation_exist" => false], + "mn" => ["language" => "монгол", "translation_exist" => false], + "mr" => ["language" => "मराठी", "translation_exist" => false], + "ms" => ["language" => "bahasa Melayu, بهاس ملايو", "translation_exist" => false], + "mt" => ["language" => "Malti", "translation_exist" => false], + "my" => ["language" => "ဗမာစာ", "translation_exist" => false], + "na" => ["language" => "Ekakairũ Naoero", "translation_exist" => false], + "nb" => ["language" => "Norsk bokmål", "translation_exist" => false], + "nd" => ["language" => "isiNdebele", "translation_exist" => false], + "ne" => ["language" => "नेपाली", "translation_exist" => false], + "ng" => ["language" => "Owambo", "translation_exist" => false], + "nl" => ["language" => "Nederlands, Vlaams", "translation_exist" => false], + "nn" => ["language" => "Norsk nynorsk", "translation_exist" => false], + "no" => ["language" => "Norsk", "translation_exist" => false], + "nr" => ["language" => "isiNdebele", "translation_exist" => false], + "nv" => ["language" => "Diné bizaad, Dinékʼehǰí", "translation_exist" => false], + "ny" => ["language" => "chiCheŵa, chinyanja", "translation_exist" => false], + "oc" => ["language" => "Occitan", "translation_exist" => false], + "oj" => ["language" => "ᐊᓂᔑᓈᐯᒧᐎᓐ", "translation_exist" => false], + "om" => ["language" => "Afaan Oromoo", "translation_exist" => false], + "or" => ["language" => "ଓଡ଼ିଆ", "translation_exist" => false], + "os" => ["language" => "ирон æвзаг", "translation_exist" => false], + "pa" => ["language" => "ਪੰਜਾਬੀ, پنجابی", "translation_exist" => false], + "pi" => ["language" => "पाऴि", "translation_exist" => false], + "pl" => ["language" => "polski", "translation_exist" => false], + "ps" => ["language" => "پښتو", "translation_exist" => false], + "pt" => ["language" => "Português", "translation_exist" => false], + "qu" => ["language" => "Runa Simi, Kichwa", "translation_exist" => false], + "rm" => ["language" => "rumantsch grischun", "translation_exist" => false], + "rn" => ["language" => "Ikirundi", "translation_exist" => false], + "ro" => ["language" => "română", "translation_exist" => false], + "ru" => ["language" => "русский язык", "translation_exist" => false], + "rw" => ["language" => "Ikinyarwanda", "translation_exist" => false], + "sa" => ["language" => "संस्कृतम्", "translation_exist" => false], + "sc" => ["language" => "sardu", "translation_exist" => false], + "sd" => ["language" => "yângâ tî sängö", "translation_exist" => false], + "se" => ["language" => "Davvisámegiella", "translation_exist" => false], + "sg" => ["language" => "yângâ tî sängö", "translation_exist" => false], + "si" => ["language" => "සිංහල", "translation_exist" => false], + "sk" => ["language" => "slovenčina", "translation_exist" => false], + "sl" => ["language" => "slovenščina", "translation_exist" => false], + "sm" => ["language" => "gagana fa'a Samoa", "translation_exist" => false], + "sn" => ["language" => "chiShona", "translation_exist" => false], + "so" => ["language" => "Soomaaliga, af Soomaali", "translation_exist" => false], + "sq" => ["language" => "Shqip", "translation_exist" => false], + "sr" => ["language" => "српски језик", "translation_exist" => false], + "ss" => ["language" => "SiSwati", "translation_exist" => false], + "st" => ["language" => "Sesotho", "translation_exist" => false], + "su" => ["language" => "Basa Sunda", "translation_exist" => false], + "sv" => ["language" => "svenska", "translation_exist" => false], + "sw" => ["language" => "Kiswahili", "translation_exist" => false], + "ta" => ["language" => "தமிழ்", "translation_exist" => false], + "te" => ["language" => "తెలుగు", "translation_exist" => false], + "tg" => ["language" => " тоҷикӣ, toğikī, تاجیکی", "translation_exist" => false], + "th" => ["language" => "ไทย", "translation_exist" => false], + "ti" => ["language" => "ትግርኛ", "translation_exist" => false], + "tk" => ["language" => "Türkmen, Түркмен", "translation_exist" => false], + "tl" => ["language" => "Wikang Tagalog", "translation_exist" => false], + "tn" => ["language" => "Setswana", "translation_exist" => false], + "to" => ["language" => "faka Tonga", "translation_exist" => false], + "tr" => ["language" => "Türkçe", "translation_exist" => false], + "ts" => ["language" => "Xitsonga", "translation_exist" => false], + "tt" => ["language" => "татарча, tatarça, تاتارچا", "translation_exist" => false], + "tw" => ["language" => "Twi", "translation_exist" => false], + "ty" => ["language" => "Reo Tahiti", "translation_exist" => false], + "ug" => ["language" => "Uyƣurqə, ئۇيغۇرچە", "translation_exist" => false], + "uk" => ["language" => "українська", "translation_exist" => false], + "ur" => ["language" => "اردو", "translation_exist" => false], + "uz" => ["language" => "O'zbek, Ўзбек, أۇزبېك", "translation_exist" => false], + "ve" => ["language" => "Tshivenḓa", "translation_exist" => false], + "vi" => ["language" => "Tiếng Việt", "translation_exist" => false], + "vo" => ["language" => "Volapük", "translation_exist" => false], + "wa" => ["language" => "Walon", "translation_exist" => false], + "wo" => ["language" => "Wollof", "translation_exist" => false], + "xh" => ["language" => "isiXhosa", "translation_exist" => false], + "yi" => ["language" => "ייִדיש", "translation_exist" => false], + "yo" => ["language" => "Yorùbá", "translation_exist" => false], + "za" => ["language" => "Saɯ cueŋƅ, Saw cuengh", "translation_exist" => false], + "zh" => ["language" => "中文, 汉语, 漢語", "translation_exist" => false], + "zu" => ["language" => "isiZulu", "translation_exist" => false] +]; diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php index cbeeb29..7599231 100644 --- a/ratatoeskr/main.php +++ b/ratatoeskr/main.php @@ -10,8 +10,9 @@ */ require_once(dirname(__FILE__) . "/config.php"); -if(!CONFIG_FILLED_OUT) +if (!CONFIG_FILLED_OUT) { die("Config file not filled out!"); +} require_once(dirname(__FILE__) . "/sys/db.php"); require_once(dirname(__FILE__) . "/sys/models.php"); @@ -22,21 +23,19 @@ require_once(dirname(__FILE__) . "/sys/plugin_api.php"); require_once(dirname(__FILE__) . "/frontend.php"); require_once(dirname(__FILE__) . "/backend.php"); -$plugin_objs = array(); +$plugin_objs = []; function ratatoeskr() { global $ste; - try - { + try { _ratatoeskr(); - } - catch(Exception $e) - { + } catch (Exception $e) { header("HTTP/1.1 500 Internal Server Error"); $ste->vars["title"] = "500 Internal Server Error"; - if(__DEBUG__) + if (__DEBUG__) { $ste->vars["details"] = $e->__toString(); + } echo $ste->exectemplate("/systemtemplates/error.html"); } } @@ -45,33 +44,32 @@ function _ratatoeskr() { global $backend_subactions, $ste, $url_handlers, $ratatoeskr_settings, $plugin_objs, $api_compat; - $ts_start = microtime(True); + $ts_start = microtime(true); session_start(); db_connect(); clean_database(); - if(isset($ratatoeskr_settings["debugmode"]) and $ratatoeskr_settings["debugmode"]) - define("__DEBUG__", True); + 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; + 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) - { + if ($plugin->update) { $plugin_obj->update(); - $plugin->update = False; + $plugin->update = false; $plugin->save(); } $plugin_obj->init(); @@ -85,8 +83,7 @@ function _ratatoeskr() 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) - { + register_url_handler("_notfound", url_action_simple(function ($data) { global $ste; header("HTTP/1.1 404 Not Found"); $ste->vars["title"] = "404 Not Found"; @@ -95,17 +92,17 @@ function _ratatoeskr() })); $urlpath = explode("/", @$_GET["action"]); - $rel_path_to_root = implode("/", array_merge(array("."), array_repeat("..", count($urlpath) - 1))); + $rel_path_to_root = implode("/", array_merge(["."], array_repeat("..", count($urlpath) - 1))); $GLOBALS["rel_path_to_root"] = $rel_path_to_root; - $data = array("rel_path_to_root" => $rel_path_to_root); + $data = ["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) + 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 9b330fe..4898e84 100644 --- a/ratatoeskr/setup/create_tables.php +++ b/ratatoeskr/setup/create_tables.php @@ -1,7 +1,8 @@ <?php -if(!defined("SETUP")) +if (!defined("SETUP")) { die(); +} require_once(dirname(__FILE__) . "/../sys/db.php"); @@ -105,7 +106,6 @@ CREATE TABLE IF NOT EXISTS `PREFIX_sections` ( `name` text COLLATE utf8_unicode_ci NOT NULL, `title` int(11) NOT NULL, `template` text COLLATE utf8_unicode_ci NOT NULL, - `styles` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -169,10 +169,10 @@ function create_mysql_tables() global $sql_tables; $queries = explode(";", $sql_tables); - foreach($queries as $q) - { - if(!empty($q)) + foreach ($queries as $q) { + if (!empty($q)) { qdb($q); + } } qdb("INSERT INTO `PREFIX_meta` (`key`, `value`) VALUES ('dbversion', ?)", base64_encode(serialize(1))); diff --git a/ratatoeskr/setup/setup.php b/ratatoeskr/setup/setup.php index e1dbacd..a5ebba2 100644 --- a/ratatoeskr/setup/setup.php +++ b/ratatoeskr/setup/setup.php @@ -1,6 +1,6 @@ <?php -define("SETUP", True); +define("SETUP", true); require_once(dirname(__FILE__) . "/../sys/init_ste.php"); require_once(dirname(__FILE__) . "/../sys/translation.php"); @@ -12,36 +12,32 @@ require_once(dirname(__FILE__) . "/create_tables.php"); $rel_path_to_root = "."; $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"] = []; +foreach ($languages as $langcode => $langinfo) { + if ($langinfo["translation_exist"]) { $ste->vars["translations"][$langcode] = $langinfo["language"]; + } } -if(isset($_GET["lang"]) and (@$languages[$_GET["lang"]]["translation_exist"])) -{ +if (isset($_GET["lang"]) and (@$languages[$_GET["lang"]]["translation_exist"])) { load_language($_GET["lang"]); $lang = $_GET["lang"]; $ste->vars["lang"] = $_GET["lang"]; -} -else +} else { die($ste->exectemplate("/systemtemplates/setup_select_lang.html")); +} -if(isset($_POST["apply_setup"])) -{ - if(empty($_POST["admin_username"]) or empty($_POST["admin_init_password"])) +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 - { + } 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 - { + try { db_connect(); create_mysql_tables(); @@ -49,12 +45,12 @@ if(isset($_POST["apply_setup"])) 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_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["languages"] = $lang == "en" ? ["en"] : [$lang, "en"]; $ratatoeskr_settings["last_db_cleanup"] = time(); - $ratatoeskr_settings["debugmode"] = False; + $ratatoeskr_settings["debugmode"] = false; $style = Style::create("default"); $style->code = <<<STYLE @@ -204,8 +200,9 @@ STYLE; $section = Section::create("home"); $section->title["en"] = new Translation("Home", ""); - if($lang != "en") + if ($lang != "en") { $section->title[$lang] = new Translation("Home", ""); + } $section->template = "standard.html"; $section->add_style($style); $section->save(); @@ -225,17 +222,14 @@ STYLE; $article->excerpt["en"] = new Translation("Congratulations! You have just installed Ratatöskr!", "Markdown"); $article->status = ARTICLE_STATUS_LIVE; $article->timestamp = time(); - $article->allow_comments = True; + $article->allow_comments = true; $article->set_section($section); $article->save(); - try - { + try { Repository::create("http://r7r-repo-community.silvasur.net/"); Repository::create("http://r7r-repo-official.silvasur.net/"); - } - catch(RepositoryUnreachableOrInvalid $e) - { + } catch (RepositoryUnreachableOrInvalid $e) { $ste->vars["notice"] = $translation["could_not_initialize_repos"]; } @@ -243,9 +237,7 @@ STYLE; $config = "<?php\n\ndefine(\"__DEBUG__\", False);\ndefine(\"CONFIG_FILLED_OUT\", True);\ndefine(\"PLUGINS_ENABLED\", True);\n\n\$config[\"mysql\"][\"server\"] = '" . addcslashes($config["mysql"]["server"], "'") . "';\n\$config[\"mysql\"][\"db\"] = '" . addcslashes($config["mysql"]["db"], "'") . "';\n\$config[\"mysql\"][\"user\"] = '" . addcslashes($config["mysql"]["user"], "'") . "';\n\$config[\"mysql\"][\"passwd\"] = '" . addcslashes($config["mysql"]["passwd"], "'") . "';\n\$config[\"mysql\"][\"prefix\"] = '" . addcslashes($config["mysql"]["prefix"], "'") . "';\n\n?>"; $ste->vars["config"] = $config; die($ste->exectemplate("/systemtemplates/setup_done.html")); - } - catch(MySQLException $e) - { + } catch (MySQLException $e) { $ste->vars["error"] = $e->getMessage(); } } diff --git a/ratatoeskr/sys/db.php b/ratatoeskr/sys/db.php index a833cd6..17a8b8a 100644 --- a/ratatoeskr/sys/db.php +++ b/ratatoeskr/sys/db.php @@ -10,12 +10,13 @@ * See "ratatoeskr/licenses/ratatoeskr" for more information. */ -if(!defined("SETUP")) +if (!defined("SETUP")) { require_once(dirname(__FILE__) . "/../config.php"); +} require_once(dirname(__FILE__) . "/utils.php"); -$db_con = Null; +$db_con = null; /* * Function: db_connect @@ -31,9 +32,10 @@ function db_connect() "mysql:host=" . $config["mysql"]["server"] . ";dbname=" . $config["mysql"]["db"] . ";charset=utf8", $config["mysql"]["user"], $config["mysql"]["passwd"], - array( + [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', - )); + ] + ); $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } @@ -78,8 +80,9 @@ function prep_stmt($q) function qdb() { $args = func_get_args(); - if(count($args) < 1) + if (count($args) < 1) { throw new InvalidArgumentException("qdb needs at least 1 argument"); + } $stmt = prep_stmt($args[0]); $stmt->execute(array_slice($args, 1)); @@ -104,8 +107,9 @@ class Transaction { global $db_con; $this->startedhere = !($db_con->inTransaction()); - if($this->startedhere) + if ($this->startedhere) { $db_con->beginTransaction(); + } } /* @@ -117,8 +121,9 @@ class Transaction { global $db_con; - if($this->startedhere) + if ($this->startedhere) { $db_con->commit(); + } } /* @@ -130,7 +135,8 @@ class Transaction { global $db_con; - if($this->startedhere) + if ($this->startedhere) { $db_con->rollBack(); + } } } diff --git a/ratatoeskr/sys/init_ste.php b/ratatoeskr/sys/init_ste.php index d01458b..b422046 100644 --- a/ratatoeskr/sys/init_ste.php +++ b/ratatoeskr/sys/init_ste.php @@ -15,39 +15,37 @@ require_once(dirname(__FILE__) . "/../libs/ste/ste.php"); $tpl_basedir = dirname(__FILE__) . "/../templates"; -if(!isset($ste)) -{ +if (!isset($ste)) { /* * Variable: $ste * * The global STECore instance. */ $ste = new \ste\STECore(new \ste\FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc")); - if(defined("__DEBUG__") && __DEBUG__) - $ste->mute_runtime_errors = False; + if (defined("__DEBUG__") && __DEBUG__) { + $ste->mute_runtime_errors = false; + } } $ste->register_tag( "l10n_replace", - function($ste, $params, $sub) - { + function ($ste, $params, $sub) { $content = $sub($ste); - foreach($params as $name => $replace) + foreach ($params as $name => $replace) { $content = str_replace("[[$name]]", $replace, $content); + } return $content; } ); $ste->register_tag( "capitalize", - function($ste, $params, $sub) - { + function ($ste, $params, $sub) { return ucwords($sub($ste)); } ); $ste->register_tag( "loremipsum", - function($ste, $params, $sub) - { + function ($ste, $params, $sub) { $repeats = empty($params["repeat"]) ? 1 : $params["repeat"] + 0; return implode("\n\n", array_repeat("<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>\n\n<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>\n\n<p>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.</p>\n\n<p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.</p>\n\n<p>Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>", $repeats)); } diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index 86b73b9..8f40dd7 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -21,14 +21,14 @@ db_connect(); * Array: $imagetype_file_extensions * Array of default file extensions for most IMAGETYPE_* constants */ -$imagetype_file_extensions = array( +$imagetype_file_extensions = [ IMAGETYPE_GIF => "gif", IMAGETYPE_JPEG => "jpg", IMAGETYPE_PNG => "png", IMAGETYPE_BMP => "bmp", IMAGETYPE_TIFF_II => "tif", IMAGETYPE_TIFF_MM => "tif", -); +]; /* * Variable: $ratatoeskr_settings @@ -43,7 +43,7 @@ $imagetype_file_extensions = array( * "languages" - Array of activated languages. * "last_db_cleanup" - Timestamp of the last database cleanup. */ -$ratatoeskr_settings = NULL; +$ratatoeskr_settings = null; /* * Constants: ARTICLE_STATUS_ @@ -54,36 +54,46 @@ $ratatoeskr_settings = NULL; * ARTICLE_STATUS_STICKY - Article is sticky (Numeric: 2) */ define("ARTICLE_STATUS_HIDDEN", 0); -define("ARTICLE_STATUS_LIVE", 1); +define("ARTICLE_STATUS_LIVE", 1); define("ARTICLE_STATUS_STICKY", 2); /* * Class: DoesNotExistError * This Exception is thrown by an ::by_*-constructor or any array-like object if the desired object is not present in the database. */ -class DoesNotExistError extends Exception { } +class DoesNotExistError extends Exception +{ +} /* * Class: AlreadyExistsError * This Exception is thrown by an ::create-constructor or a save-method, if the creation/modification of the object would result in duplicates. */ -class AlreadyExistsError extends Exception { } +class AlreadyExistsError extends Exception +{ +} /* * Class: NotAllowedError */ -class NotAllowedError extends Exception { } +class NotAllowedError extends Exception +{ +} /* * Class: InvalidDataError * Exception that will be thrown, if a object with invalid data (e.g. urlname in this form not allowed) should have been saved / created. * Unless something else is said at a function, the exception message is a translation key. */ -class InvalidDataError extends Exception { } +class InvalidDataError extends Exception +{ +} abstract class BySQLRowEnabled { - protected function __construct() { } + protected function __construct() + { + } abstract protected function populate_by_sqlrow($sqlrow); @@ -119,13 +129,12 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator { $sqltable = sub_prefix($sqltable); - $this->silent_mode = False; - $this->keybuffer = array(); + $this->silent_mode = false; + $this->keybuffer = []; $selector = "WHERE "; $fields = ""; - foreach($common as $field => $val) - { + foreach ($common as $field => $val) { $selector .= "`$field` = ? AND "; $fields .= ", `$field`"; $this->common_vals[] = $val; @@ -138,8 +147,9 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator $get_keys = prep_stmt("SELECT `key` FROM `$sqltable` $selector 1"); $get_keys->execute($this->common_vals); - while($sqlrow = $get_keys->fetch()) + while ($sqlrow = $get_keys->fetch()) { $this->keybuffer[] = $sqlrow["key"]; + } $this->counter = 0; } @@ -152,59 +162,81 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator * enable_silent_mode - Enable the silent mode. * disable_silent_mode - Disable the silent mode (default). */ - final public function enable_silent_mode() { $this->silent_mode = True; } - final public function disable_silent_mode() { $this->silent_mode = False; } + final public function enable_silent_mode() + { + $this->silent_mode = true; + } + final public function disable_silent_mode() + { + $this->silent_mode = false; + } /* Countable interface implementation */ - final public function count() { return count($this->keybuffer); } + final public function count() + { + return count($this->keybuffer); + } /* ArrayAccess interface implementation */ - final public function offsetExists($offset) { return in_array($offset, $this->keybuffer); } + final public function offsetExists($offset) + { + return in_array($offset, $this->keybuffer); + } final public function offsetGet($offset) { - if($this->offsetExists($offset)) - { - $this->stmt_get->execute(array_merge($this->common_vals, array($offset))); + if ($this->offsetExists($offset)) { + $this->stmt_get->execute(array_merge($this->common_vals, [$offset])); $sqlrow = $this->stmt_get->fetch(); $this->stmt_get->closeCursor(); return unserialize(base64_decode($sqlrow["value"])); - } - elseif($this->silent_mode) - return NULL; - else + } elseif ($this->silent_mode) { + return null; + } else { throw new DoesNotExistError(); + } } final public function offsetUnset($offset) { - if($this->offsetExists($offset)) - { + if ($this->offsetExists($offset)) { unset($this->keybuffer[array_search($offset, $this->keybuffer)]); $this->keybuffer = array_merge($this->keybuffer); - $this->stmt_unset->execute(array_merge($this->common_vals, array($offset))); + $this->stmt_unset->execute(array_merge($this->common_vals, [$offset])); $this->stmt_unset->closeCursor(); } } final public function offsetSet($offset, $value) { - if($this->offsetExists($offset)) - { - $this->stmt_update->execute(array_merge(array(base64_encode(serialize($value))), $this->common_vals, array($offset))); + if ($this->offsetExists($offset)) { + $this->stmt_update->execute(array_merge([base64_encode(serialize($value))], $this->common_vals, [$offset])); $this->stmt_update->closeCursor(); - } - else - { - $this->stmt_create->execute(array_merge(array($offset, base64_encode(serialize($value))), $this->common_vals)); + } else { + $this->stmt_create->execute(array_merge([$offset, base64_encode(serialize($value))], $this->common_vals)); $this->stmt_create->closeCursor(); $this->keybuffer[] = $offset; } } /* Iterator interface implementation */ - final public function rewind() { return $this->counter = 0; } - final public function current() { return $this->offsetGet($this->keybuffer[$this->counter]); } - final public function key() { return $this->keybuffer[$this->counter]; } - final public function next() { ++$this->counter; } - final public function valid() { return isset($this->keybuffer[$this->counter]); } + final public function rewind() + { + return $this->counter = 0; + } + final public function current() + { + return $this->offsetGet($this->keybuffer[$this->counter]); + } + final public function key() + { + return $this->keybuffer[$this->counter]; + } + final public function next() + { + ++$this->counter; + } + final public function valid() + { + return isset($this->keybuffer[$this->counter]); + } } /* @@ -248,15 +280,16 @@ class User extends BySQLRowEnabled { global $ratatoeskr_settings; global $db_con; - try - { + try { $obj = self::by_name($username); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { global $ratatoeskr_settings; - qdb("INSERT INTO `PREFIX_users` (`username`, `pwhash`, `mail`, `fullname`, `language`) VALUES (?, ?, '', '', ?)", - $username, $pwhash, $ratatoeskr_settings["default_language"]); + qdb( + "INSERT INTO `PREFIX_users` (`username`, `pwhash`, `mail`, `fullname`, `language`) VALUES (?, ?, '', '', ?)", + $username, + $pwhash, + $ratatoeskr_settings["default_language"] + ); $obj = new self(); $obj->id = $db_con->lastInsertId(); @@ -298,8 +331,9 @@ class User extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -321,8 +355,9 @@ class User extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `username` = ?", $username); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -333,11 +368,12 @@ class User extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -362,19 +398,24 @@ class User extends BySQLRowEnabled public function save() { $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_users` WHERE `username` = ? AND `id` != ?", $this->username, $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] > 0) + if ($sqlrow["n"] > 0) { throw new AlreadyExistsError(); + } - qdb("UPDATE `PREFIX_users` SET `username` = ?, `pwhash` = ?, `mail` = ?, `fullname` = ?, `language` = ? WHERE `id` = ?", - $this->username, $this->pwhash, $this->mail, $this->fullname, $this->language, $this->id); + qdb( + "UPDATE `PREFIX_users` SET `username` = ?, `pwhash` = ?, `mail` = ?, `fullname` = ?, `language` = ? WHERE `id` = ?", + $this->username, + $this->pwhash, + $this->mail, + $this->fullname, + $this->language, + $this->id + ); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -388,14 +429,11 @@ class User extends BySQLRowEnabled public function delete() { $tx = new Transaction(); - try - { + try { qdb("DELETE FROM `PREFIX_group_members` WHERE `user` = ?", $this->id); qdb("DELETE FROM `PREFIX_users` WHERE `id` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -408,10 +446,11 @@ class User extends BySQLRowEnabled */ public function get_groups() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name` FROM `PREFIX_groups` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`group` WHERE `b`.`user` = ?", $this->id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = Group::by_sqlrow($sqlrow); + } return $rv; } @@ -464,12 +503,9 @@ class Group extends BySQLRowEnabled public static function create($name) { global $db_con; - try - { + try { $obj = self::by_name($name); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { qdb("INSERT INTO `PREFIX_groups` (`name`) VALUES (?)", $name); $obj = new self(); @@ -504,8 +540,9 @@ class Group extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -527,8 +564,9 @@ class Group extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `name` = ?", $name); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -539,11 +577,12 @@ class Group extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -565,14 +604,11 @@ class Group extends BySQLRowEnabled public function delete() { $tx = new Transaction(); - try - { + try { qdb("DELETE FROM `PREFIX_group_members` WHERE `group` = ?", $this->id); qdb("DELETE FROM `PREFIX_groups` WHERE `id` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -587,12 +623,13 @@ class Group extends BySQLRowEnabled */ public function get_members() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`username` AS `username`, `a`.`pwhash` AS `pwhash`, `a`.`mail` AS `mail`, `a`.`fullname` AS `fullname`, `a`.`language` AS `language` FROM `PREFIX_users` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`user` WHERE `b`.`group` = ?", $this->id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = User::by_sqlrow($sqlrow); + } return $rv; } @@ -617,8 +654,9 @@ WHERE `b`.`group` = ?", $this->id); */ public function include_user($user) { - if(!$user->member_of($this)) + if (!$user->member_of($this)) { qdb("INSERT INTO `PREFIX_group_members` (`user`, `group`) VALUES (?, ?)", $user->get_id(), $this->id); + } } } @@ -673,9 +711,9 @@ class Multilingual implements Countable, ArrayAccess, IteratorAggregate private function __construct() { - $this->translations = array(); - $this->to_be_deleted = array(); - $this->to_be_created = array(); + $this->translations = []; + $this->to_be_deleted = []; + $this->to_be_created = []; } /* @@ -722,13 +760,15 @@ class Multilingual implements Countable, ArrayAccess, IteratorAggregate $obj = new self(); $stmt = qdb("SELECT `id` FROM `PREFIX_multilingual` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow == False) + if ($sqlrow == false) { throw new DoesNotExistError(); + } $obj->id = $id; $stmt = qdb("SELECT `language`, `text`, `texttype` FROM `PREFIX_translations` WHERE `multilingual` = ?", $id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $obj->translations[$sqlrow["language"]] = new Translation($sqlrow["text"], $sqlrow["texttype"]); + } return $obj; } @@ -740,28 +780,37 @@ class Multilingual implements Countable, ArrayAccess, IteratorAggregate public function save() { $tx = new Transaction(); - try - { - foreach($this->to_be_deleted as $deletelang) + try { + foreach ($this->to_be_deleted as $deletelang) { qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ? AND `language` = ?", $this->id, $deletelang); + } - foreach($this->to_be_created as $lang) - qdb("INSERT INTO `PREFIX_translations` (`multilingual`, `language`, `text`, `texttype`) VALUES (?, ?, ?, ?)", - $this->id, $lang, $this->translations[$lang]->text, $this->translations[$lang]->texttype); + foreach ($this->to_be_created as $lang) { + qdb( + "INSERT INTO `PREFIX_translations` (`multilingual`, `language`, `text`, `texttype`) VALUES (?, ?, ?, ?)", + $this->id, + $lang, + $this->translations[$lang]->text, + $this->translations[$lang]->texttype + ); + } - foreach($this->translations as $lang => $translation) - { - if(!in_array($lang, $this->to_be_created)) - qdb("UPDATE `PREFIX_translations` SET `text` = ?, `texttype` = ? WHERE `multilingual` = ? AND `language` = ?", - $translation->text, $translation->texttype, $this->id, $lang); + foreach ($this->translations as $lang => $translation) { + if (!in_array($lang, $this->to_be_created)) { + qdb( + "UPDATE `PREFIX_translations` SET `text` = ?, `texttype` = ? WHERE `multilingual` = ? AND `language` = ?", + $translation->text, + $translation->texttype, + $this->id, + $lang + ); + } } - $this->to_be_deleted = array(); - $this->to_be_created = array(); + $this->to_be_deleted = []; + $this->to_be_created = []; $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -774,53 +823,61 @@ class Multilingual implements Countable, ArrayAccess, IteratorAggregate public function delete() { $tx = new Transaction(); - try - { + try { qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ?", $this->id); qdb("DELETE FROM `PREFIX_multilingual` WHERE `id` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } } /* Countable interface implementation */ - public function count() { return count($this->languages); } + public function count() + { + return count($this->languages); + } /* ArrayAccess interface implementation */ - public function offsetExists($offset) { return isset($this->translations[$offset]); } + public function offsetExists($offset) + { + return isset($this->translations[$offset]); + } public function offsetGet($offset) { - if(isset($this->translations[$offset])) + if (isset($this->translations[$offset])) { return $this->translations[$offset]; - else + } else { throw new DoesNotExistError(); + } } public function offsetUnset($offset) { unset($this->translations[$offset]); - if(in_array($offset, $this->to_be_created)) + if (in_array($offset, $this->to_be_created)) { unset($this->to_be_created[array_search($offset, $this->to_be_created)]); - else + } else { $this->to_be_deleted[] = $offset; + } } public function offsetSet($offset, $value) { - if(!isset($this->translations[$offset])) - { - if(in_array($offset, $this->to_be_deleted)) + if (!isset($this->translations[$offset])) { + if (in_array($offset, $this->to_be_deleted)) { unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]); - else + } else { $this->to_be_created[] = $offset; + } } $this->translations[$offset] = $value; } /* IteratorAggregate interface implementation */ - public function getIterator() { return new ArrayIterator($this->translations); } + public function getIterator() + { + return new ArrayIterator($this->translations); + } } class SettingsIterator implements Iterator @@ -837,11 +894,26 @@ class SettingsIterator implements Iterator } /* Iterator implementation */ - public function current() { return $this->settings_obj[$this->keys[$this->index]]; } - public function key() { return $this->keys[$this->index]; } - public function next() { ++$this->index; } - public function rewind() { $this->index = 0; } - public function valid() { return $this->index < count($this->keys); } + public function current() + { + return $this->settings_obj[$this->keys[$this->index]]; + } + public function key() + { + return $this->keys[$this->index]; + } + public function next() + { + ++$this->index; + } + public function rewind() + { + $this->index = 0; + } + public function valid() + { + return $this->index < count($this->keys); + } } /* @@ -852,8 +924,10 @@ class SettingsIterator implements Iterator class Settings implements ArrayAccess, IteratorAggregate, Countable { /* Singleton implementation */ - private function __copy() {} - private static $instance = NULL; + private function __copy() + { + } + private static $instance = null; /* * Constructor: get_instance * Get an instance of this class. @@ -862,8 +936,9 @@ class Settings implements ArrayAccess, IteratorAggregate, Countable */ public static function get_instance() { - if(self::$instance === NULL) + if (self::$instance === null) { self::$instance = new self; + } return self::$instance; } @@ -874,35 +949,36 @@ class Settings implements ArrayAccess, IteratorAggregate, Countable private function __construct() { - $this->buffer = array(); + $this->buffer = []; $stmt = qdb("SELECT `key`, `value` FROM `PREFIX_settings_kvstorage` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $this->buffer[$sqlrow["key"]] = unserialize(base64_decode($sqlrow["value"])); + } - $this->to_be_created = array(); - $this->to_be_deleted = array(); - $this->to_be_updated = array(); + $this->to_be_created = []; + $this->to_be_deleted = []; + $this->to_be_updated = []; } public function save() { $tx = new Transaction(); - try - { - foreach($this->to_be_deleted as $k) + try { + foreach ($this->to_be_deleted as $k) { qdb("DELETE FROM `PREFIX_settings_kvstorage` WHERE `key` = ?", $k); - foreach($this->to_be_updated as $k) + } + foreach ($this->to_be_updated as $k) { qdb("UPDATE `PREFIX_settings_kvstorage` SET `value` = ? WHERE `key` = ?", base64_encode(serialize($this->buffer[$k])), $k); - foreach($this->to_be_created as $k) + } + foreach ($this->to_be_created as $k) { qdb("INSERT INTO `PREFIX_settings_kvstorage` (`key`, `value`) VALUES (?, ?)", $k, base64_encode(serialize($this->buffer[$k]))); + } - $this->to_be_created = array(); - $this->to_be_deleted = array(); - $this->to_be_updated = array(); + $this->to_be_created = []; + $this->to_be_deleted = []; + $this->to_be_updated = []; $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -917,36 +993,41 @@ class Settings implements ArrayAccess, IteratorAggregate, Countable { return $this->buffer[$offset]; } - public function offsetSet ($offset, $value) + public function offsetSet($offset, $value) { - if(!$this->offsetExists($offset)) - { - if(in_array($offset, $this->to_be_deleted)) - { + if (!$this->offsetExists($offset)) { + if (in_array($offset, $this->to_be_deleted)) { $this->to_be_updated[] = $offset; unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]); - } - else + } else { $this->to_be_created[] = $offset; - } - elseif((!in_array($offset, $this->to_be_created)) and (!in_array($offset, $this->to_be_updated))) + } + } elseif ((!in_array($offset, $this->to_be_created)) and (!in_array($offset, $this->to_be_updated))) { $this->to_be_updated[] = $offset; + } $this->buffer[$offset] = $value; } public function offsetUnset($offset) { - if(in_array($offset, $this->to_be_created)) + if (in_array($offset, $this->to_be_created)) { unset($this->to_be_created[array_search($offset, $this->to_be_created)]); - else + } else { $this->to_be_deleted[] = $offset; + } unset($this->buffer[$offset]); } /* IteratorAggregate implementation */ - public function getIterator() { return new SettingsIterator($this, array_keys($this->buffer)); } + public function getIterator() + { + return new SettingsIterator($this, array_keys($this->buffer)); + } /* Countable implementation */ - public function count() { return count($this->buffer); } + public function count() + { + return count($this->buffer); + } } $ratatoeskr_settings = Settings::get_instance(); @@ -969,7 +1050,7 @@ class PluginKVStorage extends KVStorage */ public function __construct($plugin_id) { - $this->init("PREFIX_plugin_kvstorage", array("plugin" => $plugin_id)); + $this->init("PREFIX_plugin_kvstorage", ["plugin" => $plugin_id]); } } @@ -1007,10 +1088,22 @@ class Comment extends BySQLRowEnabled * get_language - Gets the language. * get_timestamp - Gets the timestamp. */ - public function get_id() { return $this->id; } - public function get_article() { return Article::by_id($this->article_id); } - public function get_language() { return $this->language; } - public function get_timestamp() { return $this->timestamp; } + public function get_id() + { + return $this->id; + } + public function get_article() + { + return Article::by_id($this->article_id); + } + public function get_language() + { + return $this->language; + } + public function get_timestamp() + { + return $this->timestamp; + } /* * Constructor: create @@ -1029,8 +1122,13 @@ class Comment extends BySQLRowEnabled $obj = new self(); $obj->timestamp = time(); - qdb("INSERT INTO `PREFIX_comments` (`article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin`) VALUES (?, ?, '', '', '', ?, ?, 0)", - $article->get_id(), $language, $obj->timestamp, $ratatoeskr_settings["comment_visible_default"] ? 1 : 0); + qdb( + "INSERT INTO `PREFIX_comments` (`article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin`) VALUES (?, ?, '', '', '', ?, ?, 0)", + $article->get_id(), + $language, + $obj->timestamp, + $ratatoeskr_settings["comment_visible_default"] ? 1 : 0 + ); $obj->id = $db_con->lastInsertId(); $obj->article_id = $article->get_id(); @@ -1039,7 +1137,7 @@ class Comment extends BySQLRowEnabled $obj->author_mail = ""; $obj->text = ""; $obj->visible = $ratatoeskr_settings["comment_visible_default"]; - $obj->read_by_admin = False; + $obj->read_by_admin = false; return $obj; } @@ -1071,8 +1169,9 @@ class Comment extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1086,10 +1185,11 @@ class Comment extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -1108,53 +1208,53 @@ class Comment extends BySQLRowEnabled { global $ratatoeskr_settings; - return kses(textprocessor_apply($text, $ratatoeskr_settings["comment_textprocessor"]), array( - "a" => array("href" => 1, "hreflang" => 1, "title" => 1, "rel" => 1, "rev" => 1), - "b" => array(), - "i" => array(), - "u" => array(), - "strong" => array(), - "em" => array(), - "p" => array("align" => 1), - "br" => array(), - "abbr" => array(), - "acronym" => array(), - "code" => array(), - "pre" => array(), - "blockquote" => array("cite" => 1), - "h1" => array(), - "h2" => array(), - "h3" => array(), - "h4" => array(), - "h5" => array(), - "h6" => array(), - "img" => array("src" => 1, "alt" => 1, "width" => 1, "height" => 1), - "s" => array(), - "q" => array("cite" => 1), - "samp" => array(), - "ul" => array(), - "ol" => array(), - "li" => array(), - "del" => array(), - "ins" => array(), - "dl" => array(), - "dd" => array(), - "dt" => array(), - "dfn" => array(), - "div" => array(), - "dir" => array(), - "kbd" => array("prompt" => 1), - "strike" => array(), - "sub" => array(), - "sup" => array(), - "table" => array("style" => 1), - "tbody" => array(), "thead" => array(), "tfoot" => array(), - "tr" => array(), - "td" => array("colspan" => 1, "rowspan" => 1), - "th" => array("colspan" => 1, "rowspan" => 1), - "tt" => array(), - "var" => array() - )); + return kses(textprocessor_apply($text, $ratatoeskr_settings["comment_textprocessor"]), [ + "a" => ["href" => 1, "hreflang" => 1, "title" => 1, "rel" => 1, "rev" => 1], + "b" => [], + "i" => [], + "u" => [], + "strong" => [], + "em" => [], + "p" => ["align" => 1], + "br" => [], + "abbr" => [], + "acronym" => [], + "code" => [], + "pre" => [], + "blockquote" => ["cite" => 1], + "h1" => [], + "h2" => [], + "h3" => [], + "h4" => [], + "h5" => [], + "h6" => [], + "img" => ["src" => 1, "alt" => 1, "width" => 1, "height" => 1], + "s" => [], + "q" => ["cite" => 1], + "samp" => [], + "ul" => [], + "ol" => [], + "li" => [], + "del" => [], + "ins" => [], + "dl" => [], + "dd" => [], + "dt" => [], + "dfn" => [], + "div" => [], + "dir" => [], + "kbd" => ["prompt" => 1], + "strike" => [], + "sub" => [], + "sup" => [], + "table" => ["style" => 1], + "tbody" => [], "thead" => [], "tfoot" => [], + "tr" => [], + "td" => ["colspan" => 1, "rowspan" => 1], + "th" => ["colspan" => 1, "rowspan" => 1], + "tt" => [], + "var" => [] + ]); } /* @@ -1175,8 +1275,15 @@ class Comment extends BySQLRowEnabled */ public function save() { - qdb("UPDATE `PREFIX_comments` SET `author_name` = ?, `author_mail` = ?, `text` = ?, `visible` = ?, `read_by_admin` = ? WHERE `id` = ?", - $this->author_name, $this->author_mail, $this->text, ($this->visible ? 1 : 0), ($this->read_by_admin ? 1 : 0), $this->id); + qdb( + "UPDATE `PREFIX_comments` SET `author_name` = ?, `author_mail` = ?, `text` = ?, `visible` = ?, `read_by_admin` = ? WHERE `id` = ?", + $this->author_name, + $this->author_mail, + $this->text, + ($this->visible ? 1 : 0), + ($this->read_by_admin ? 1 : 0), + $this->id + ); } /* @@ -1230,7 +1337,10 @@ class Style extends BySQLRowEnabled /* * Function: get_id */ - public function get_id() { return $this->id; } + public function get_id() + { + return $this->id; + } /* * Constructor: create @@ -1246,15 +1356,13 @@ class Style extends BySQLRowEnabled { global $db_con; - if(!self::test_name($name)) + if (!self::test_name($name)) { throw new InvalidDataError("invalid_style_name"); + } - try - { + try { self::by_name($name); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $obj = new self(); $obj->name = $name; $obj->code = ""; @@ -1282,8 +1390,9 @@ class Style extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1302,8 +1411,9 @@ class Style extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `name` = ?", $name); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1317,10 +1427,11 @@ class Style extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -1333,23 +1444,26 @@ class Style extends BySQLRowEnabled */ public function save() { - if(!self::test_name($this->name)) + if (!self::test_name($this->name)) { throw new InvalidDataError("invalid_style_name"); + } $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_styles` WHERE `name` = ? AND `id` != ?", $this->name, $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] > 0) + if ($sqlrow["n"] > 0) { throw new AlreadyExistsError(); + } - qdb("UPDATE `PREFIX_styles` SET `name` = ?, `code` = ? WHERE `id` = ?", - $this->name, $this->code, $this->id); + qdb( + "UPDATE `PREFIX_styles` SET `name` = ?, `code` = ? WHERE `id` = ?", + $this->name, + $this->code, + $this->id + ); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -1361,14 +1475,11 @@ class Style extends BySQLRowEnabled public function delete() { $tx = new Transaction(); - try - { + try { qdb("DELETE FROM `PREFIX_styles` WHERE `id` = ?", $this->id); qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `style` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -1431,7 +1542,10 @@ class Plugin extends BySQLRowEnabled /* * Function: get_id */ - public function get_id() { return $this->id; } + public function get_id() + { + return $this->id; + } /* * Constructor: create @@ -1469,12 +1583,15 @@ class Plugin extends BySQLRowEnabled $this->help = $pkg->help; $this->api = $pkg->api; - if(!empty($pkg->custompub)) + if (!empty($pkg->custompub)) { array2dir($pkg->custompub, dirname(__FILE__) . "/../plugin_extradata/public/" . $this->get_id()); - if(!empty($pkg->custompriv)) + } + if (!empty($pkg->custompriv)) { array2dir($pkg->custompriv, dirname(__FILE__) . "/../plugin_extradata/private/" . $this->get_id()); - if(!empty($pkg->tpls)) + } + if (!empty($pkg->tpls)) { array2dir($pkg->tpls, dirname(__FILE__) . "/../templates/src/plugintemplates/" . $this->get_id()); + } } protected function populate_by_sqlrow($sqlrow) @@ -1511,8 +1628,9 @@ class Plugin extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1526,10 +1644,11 @@ class Plugin extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -1538,8 +1657,25 @@ class Plugin extends BySQLRowEnabled */ public function save() { - qdb("UPDATE `PREFIX_plugins` SET `name` = ?, `author` = ?, `code` = ?, `classname` = ?, `active` = ?, `versiontext` = ?, `versioncount` = ?, `short_description` = ?, `updatepath` = ?, `web` = ?, `help` = ?, `installed` = ?, `update` = ?, `license` = ?, `api` = ? WHERE `id` = ?", - $this->name, $this->author, $this->code, $this->classname, ($this->active ? 1 : 0), $this->versiontext, $this->versioncount, $this->short_description, $this->updatepath, $this->web, $this->help, ($this->installed ? 1 : 0), ($this->update ? 1 : 0), $this->license, $this->api, $this->id); + qdb( + "UPDATE `PREFIX_plugins` SET `name` = ?, `author` = ?, `code` = ?, `classname` = ?, `active` = ?, `versiontext` = ?, `versioncount` = ?, `short_description` = ?, `updatepath` = ?, `web` = ?, `help` = ?, `installed` = ?, `update` = ?, `license` = ?, `api` = ? WHERE `id` = ?", + $this->name, + $this->author, + $this->code, + $this->classname, + ($this->active ? 1 : 0), + $this->versiontext, + $this->versioncount, + $this->short_description, + $this->updatepath, + $this->web, + $this->help, + ($this->installed ? 1 : 0), + ($this->update ? 1 : 0), + $this->license, + $this->api, + $this->id + ); } /* @@ -1548,25 +1684,25 @@ class Plugin extends BySQLRowEnabled public function delete() { $tx = new Transaction(); - try - { + try { qdb("DELETE FROM `PREFIX_plugins` WHERE `id` = ?", $this->id); qdb("DELETE FROM `PREFIX_plugin_kvstorage` WHERE `plugin` = ?", $this->id); qdb("DELETE FROM `PREFIX_article_extradata` WHERE `plugin` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } - if(is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id)) + if (is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id)) { delete_directory(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id); - if(is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id)) + } + if (is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id)) { delete_directory(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id); - if(is_dir(SITE_BASE_PATH . "/ratatoeskr/templates/src/plugintemplates/" . $this->id)) + } + if (is_dir(SITE_BASE_PATH . "/ratatoeskr/templates/src/plugintemplates/" . $this->id)) { delete_directory(SITE_BASE_PATH . "/ratatoeskr/templates/src/plugintemplates/" . $this->id); + } } /* @@ -1627,7 +1763,10 @@ class Section extends BySQLRowEnabled /* * Function: get_id */ - public function get_id() { return $this->id; } + public function get_id() + { + return $this->id; + } /* * Constructor: create @@ -1643,15 +1782,13 @@ class Section extends BySQLRowEnabled { global $db_con; - if(!self::test_name($name)) + if (!self::test_name($name)) { throw new InvalidDataError("invalid_section_name"); + } - try - { + try { $obj = self::by_name($name); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $obj = new self(); $obj->name = $name; $obj->title = Multilingual::create(); @@ -1684,8 +1821,9 @@ class Section extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1707,8 +1845,9 @@ class Section extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `name` = ?", $name); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1722,10 +1861,11 @@ class Section extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -1738,10 +1878,11 @@ class Section extends BySQLRowEnabled */ public function get_styles() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`code` AS `code` FROM `PREFIX_styles` `a` INNER JOIN `PREFIX_section_style_relations` `b` ON `a`.`id` = `b`.`style` WHERE `b`.`section` = ?", $this->id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = Style::by_sqlrow($sqlrow); + } return $rv; } @@ -1755,16 +1896,14 @@ class Section extends BySQLRowEnabled public function add_style($style) { $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_section_style_relations` WHERE `style` = ? AND `section` = ?", $style->get_id(), $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] == 0) + if ($sqlrow["n"] == 0) { qdb("INSERT INTO `PREFIX_section_style_relations` (`section`, `style`) VALUES (?, ?)", $this->id, $style->get_id()); + } $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -1790,24 +1929,28 @@ class Section extends BySQLRowEnabled */ public function save() { - if(!self::test_name($this->name)) + if (!self::test_name($this->name)) { throw new InvalidDataError("invalid_section_name"); + } $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_sections` WHERE `name` = ? AND `id` != ?", $this->name, $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] > 0) + if ($sqlrow["n"] > 0) { throw new AlreadyExistsError(); + } $this->title->save(); - qdb("UPDATE `PREFIX_sections` SET `name` = ?, `title` = ?, `template` = ? WHERE `id` = ?", - $this->name, $this->title->get_id(), $this->template, $this->id); + qdb( + "UPDATE `PREFIX_sections` SET `name` = ?, `title` = ?, `template` = ? WHERE `id` = ?", + $this->name, + $this->title->get_id(), + $this->template, + $this->id + ); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -1819,15 +1962,12 @@ class Section extends BySQLRowEnabled public function delete() { $tx = new Transaction(); - try - { + try { $this->title->delete(); qdb("DELETE FROM `PREFIX_sections` WHERE `id` = ?", $this->id); qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `section` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -1842,10 +1982,11 @@ class Section extends BySQLRowEnabled */ public function get_articles() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `section` = ?", $this->id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = Article::by_sqlrow($sqlrow); + } return $rv; } } @@ -1879,13 +2020,16 @@ class Tag extends BySQLRowEnabled */ public static function test_name($name) { - return (strpos($name, ",") === False) and (strpos($name, " ") === False); + return (strpos($name, ",") === false) and (strpos($name, " ") === false); } /* * Function: get_id */ - public function get_id() { return $this->id; } + public function get_id() + { + return $this->id; + } protected function populate_by_sqlrow($sqlrow) { @@ -1907,22 +2051,23 @@ class Tag extends BySQLRowEnabled public static function create($name) { global $db_con; - if(!self::test_name($name)) + if (!self::test_name($name)) { throw new InvalidDataError("invalid_tag_name"); + } - try - { + try { $obj = self::by_name($name); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $obj = new self(); $obj->name = $name; $obj->title = Multilingual::create(); - qdb("INSERT INTO `PREFIX_tags` (`name`, `title`) VALUES (?, ?)", - $name, $obj->title->get_id()); + qdb( + "INSERT INTO `PREFIX_tags` (`name`, `title`) VALUES (?, ?)", + $name, + $obj->title->get_id() + ); $obj->id = $db_con->lastInsertId(); return $obj; @@ -1944,8 +2089,9 @@ class Tag extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1964,8 +2110,9 @@ class Tag extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `name` = ?", $name); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -1979,10 +2126,11 @@ class Tag extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -1995,14 +2143,17 @@ class Tag extends BySQLRowEnabled */ public function get_articles() { - $rv = array(); + $rv = []; $stmt = qdb( -"SELECT `a`.`id` AS `id`, `a`.`urlname` AS `urlname`, `a`.`title` AS `title`, `a`.`text` AS `text`, `a`.`excerpt` AS `excerpt`, `a`.`meta` AS `meta`, `a`.`custom` AS `custom`, `a`.`article_image` AS `article_image`, `a`.`status` AS `status`, `a`.`section` AS `section`, `a`.`timestamp` AS `timestamp`, `a`.`allow_comments` AS `allow_comments` + "SELECT `a`.`id` AS `id`, `a`.`urlname` AS `urlname`, `a`.`title` AS `title`, `a`.`text` AS `text`, `a`.`excerpt` AS `excerpt`, `a`.`meta` AS `meta`, `a`.`custom` AS `custom`, `a`.`article_image` AS `article_image`, `a`.`status` AS `status`, `a`.`section` AS `section`, `a`.`timestamp` AS `timestamp`, `a`.`allow_comments` AS `allow_comments` FROM `PREFIX_articles` `a` INNER JOIN `PREFIX_article_tag_relations` `b` ON `a`.`id` = `b`.`article` -WHERE `b`.`tag` = ?" , $this->id); - while($sqlrow = $stmt->fetch()) +WHERE `b`.`tag` = ?", + $this->id + ); + while ($sqlrow = $stmt->fetch()) { $rv[] = Article::by_sqlrow($sqlrow); + } return $rv; } @@ -2027,24 +2178,27 @@ WHERE `b`.`tag` = ?" , $this->id); */ public function save() { - if(!self::test_name($this->name)) + if (!self::test_name($this->name)) { throw new InvalidDataError("invalid_tag_name"); + } $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_tags` WHERE `name` = ? AND `id` != ?", $this->name, $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] > 0) + if ($sqlrow["n"] > 0) { throw new AlreadyExistsError(); + } $this->title->save(); - qdb("UPDATE `PREFIX_tags` SET `name` = ?, `title` = ? WHERE `id` = ?", - $this->name, $this->title->get_id(), $this->id); + qdb( + "UPDATE `PREFIX_tags` SET `name` = ?, `title` = ? WHERE `id` = ?", + $this->name, + $this->title->get_id(), + $this->id + ); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -2056,15 +2210,12 @@ WHERE `b`.`tag` = ?" , $this->id); public function delete() { $tx = new Transaction(); - try - { + try { $this->title->delete(); qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `tag` = ?", $this->id); qdb("DELETE FROM `PREFIX_tags` WHERE `id` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -2075,13 +2226,17 @@ WHERE `b`.`tag` = ?" , $this->id); * Class: UnknownFileFormat * Exception that will be thrown, if a input file has an unsupported file format. */ -class UnknownFileFormat extends Exception { } +class UnknownFileFormat extends Exception +{ +} /* * Class: IOError * This Exception is thrown, if a IO-Error occurs (file not available, no read/write acccess...). */ -class IOError extends Exception { } +class IOError extends Exception +{ +} /* * Class: Image @@ -2115,8 +2270,14 @@ class Image extends BySQLRowEnabled * get_id - Get the ID * get_filename - Get the filename */ - public function get_id() { return $this->id; } - public function get_filename() { return $this->file; } + public function get_id() + { + return $this->id; + } + public function get_filename() + { + return $this->file; + } /* * Constructor: create @@ -2136,17 +2297,14 @@ class Image extends BySQLRowEnabled $obj->file = "0"; $tx = new Transaction(); - try - { + try { global $db_con; qdb("INSERT INTO `PREFIX_images` (`name`, `file`) VALUES (?, '0')", $name); $obj->id = $db_con->lastInsertId(); $obj->exchange_image($file); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -2167,8 +2325,9 @@ class Image extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -2182,10 +2341,11 @@ class Image extends BySQLRowEnabled */ public function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -2202,50 +2362,50 @@ class Image extends BySQLRowEnabled public function exchange_image($file) { global $imagetype_file_extensions; - if(!is_file($file)) + if (!is_file($file)) { throw new IOError("\"$file\" is not available"); + } $imageinfo = getimagesize($file); - if($imageinfo === False) + if ($imageinfo === false) { throw new UnknownFileFormat(); - if(!isset($imagetype_file_extensions[$imageinfo[2]])) + } + if (!isset($imagetype_file_extensions[$imageinfo[2]])) { throw new UnknownFileFormat(); - if(is_file(SITE_BASE_PATH . "/images/" . $this->file)) + } + if (is_file(SITE_BASE_PATH . "/images/" . $this->file)) { unlink(SITE_BASE_PATH . "/images/" . $this->file); + } $new_fn = $this->id . "." . $imagetype_file_extensions[$imageinfo[2]]; - if(!move_uploaded_file($file, SITE_BASE_PATH . "/images/" . $new_fn)) + if (!move_uploaded_file($file, SITE_BASE_PATH . "/images/" . $new_fn)) { throw new IOError("Can not move file."); + } $this->file = $new_fn; $this->save(); /* make preview image */ - switch($imageinfo[2]) - { - case IMAGETYPE_GIF: $img = imagecreatefromgif (SITE_BASE_PATH . "/images/" . $new_fn); break; + switch ($imageinfo[2]) { + case IMAGETYPE_GIF: $img = imagecreatefromgif(SITE_BASE_PATH . "/images/" . $new_fn); break; case IMAGETYPE_JPEG: $img = imagecreatefromjpeg(SITE_BASE_PATH . "/images/" . $new_fn); break; - case IMAGETYPE_PNG: $img = imagecreatefrompng (SITE_BASE_PATH . "/images/" . $new_fn); break; + case IMAGETYPE_PNG: $img = imagecreatefrompng(SITE_BASE_PATH . "/images/" . $new_fn); break; default: $img = imagecreatetruecolor(40, 40); imagefill($img, 1, 1, imagecolorallocate($img, 127, 127, 127)); break; } $w_orig = imagesx($img); $h_orig = imagesy($img); - if(($w_orig > self::$pre_maxw) or ($h_orig > self::$pre_maxh)) - { + if (($w_orig > self::$pre_maxw) or ($h_orig > self::$pre_maxh)) { $ratio = $w_orig / $h_orig; - if($ratio > 1) - { + if ($ratio > 1) { $w_new = round(self::$pre_maxw); $h_new = round(self::$pre_maxw / $ratio); - } - else - { + } else { $h_new = round(self::$pre_maxh); $w_new = round(self::$pre_maxh * $ratio); } $preview = imagecreatetruecolor($w_new, $h_new); imagecopyresized($preview, $img, 0, 0, 0, 0, $w_new, $h_new, $w_orig, $h_orig); imagepng($preview, SITE_BASE_PATH . "/images/previews/{$this->id}.png"); - } - else + } else { imagepng($img, SITE_BASE_PATH . "/images/previews/{$this->id}.png"); + } } /* @@ -2253,8 +2413,12 @@ class Image extends BySQLRowEnabled */ public function save() { - qdb("UPDATE `PREFIX_images` SET `name` = ?, `file` = ? WHERE `id` = ?", - $this->name, $this->file, $this->id); + qdb( + "UPDATE `PREFIX_images` SET `name` = ?, `file` = ? WHERE `id` = ?", + $this->name, + $this->file, + $this->id + ); } /* @@ -2263,10 +2427,12 @@ class Image extends BySQLRowEnabled public function delete() { qdb("DELETE FROM `PREFIX_images` WHERE `id` = ?", $this->id); - if(is_file(SITE_BASE_PATH . "/images/" . $this->file)) + if (is_file(SITE_BASE_PATH . "/images/" . $this->file)) { unlink(SITE_BASE_PATH . "/images/" . $this->file); - if(is_file(SITE_BASE_PATH . "/images/previews/{$this->id}.png")) + } + if (is_file(SITE_BASE_PATH . "/images/previews/{$this->id}.png")) { unlink(SITE_BASE_PATH . "/images/previews/{$this->id}.png"); + } } } @@ -2274,7 +2440,9 @@ class Image extends BySQLRowEnabled * Class: RepositoryUnreachableOrInvalid * A Exception that will be thrown, if the repository is unreachable or seems to be an invalid repository. */ -class RepositoryUnreachableOrInvalid extends Exception { } +class RepositoryUnreachableOrInvalid extends Exception +{ +} /* * Class: Repository @@ -2298,7 +2466,7 @@ class Repository extends BySQLRowEnabled protected function __construct() { - $this->stream_ctx = stream_context_create(array("http" => array("timeout" => 5))); + $this->stream_ctx = stream_context_create(["http" => ["timeout" => 5]]); } /* @@ -2308,10 +2476,22 @@ class Repository extends BySQLRowEnabled * get_name - Get repository name. * get_description - Get repository description. */ - public function get_id() { return $this->id; } - public function get_baseurl() { return $this->baseurl; } - public function get_name() { return $this->name; } - public function get_description() { return $this->description; } + public function get_id() + { + return $this->id; + } + public function get_baseurl() + { + return $this->baseurl; + } + public function get_name() + { + return $this->name; + } + public function get_description() + { + return $this->description; + } /* * Constructor: create @@ -2327,24 +2507,22 @@ class Repository extends BySQLRowEnabled { $obj = new self(); - if(preg_match('/^(http[s]?:\\/\\/.*?)[\\/]?$/', $baseurl, $matches) == 0) + if (preg_match('/^(http[s]?:\\/\\/.*?)[\\/]?$/', $baseurl, $matches) == 0) { throw new RepositoryUnreachableOrInvalid(); + } $obj->baseurl = $matches[1]; - $obj->refresh(True); + $obj->refresh(true); $tx = new Transaction(); - try - { + try { global $db_con; - qdb("INSERT INTO `ratatoeskr_repositories` () VALUES ()"); + qdb("INSERT INTO `ratatoeskr_repositories` ( baseurl, name, description, pkgcache, lastrefresh ) VALUES ()"); $obj->id = $db_con->lastInsertId(); $obj->save(); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -2376,8 +2554,9 @@ class Repository extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if(!$sqlrow) + if (!$sqlrow) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -2391,22 +2570,25 @@ class Repository extends BySQLRowEnabled */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } private function save() { - qdb("UPDATE `PREFIX_repositories` SET `baseurl` = ?, `name` = ?, `description` = ?, `pkgcache` = ?, `lastrefresh` = ? WHERE `id` = ?", + qdb( + "UPDATE `PREFIX_repositories` SET `baseurl` = ?, `name` = ?, `description` = ?, `pkgcache` = ?, `lastrefresh` = ? WHERE `id` = ?", $this->baseurl, $this->name, $this->description, base64_encode(serialize($this->packages)), $this->lastrefresh, - $this->id); + $this->id + ); } /* @@ -2428,21 +2610,24 @@ class Repository extends BySQLRowEnabled * Throws: * <RepositoryUnreachableOrInvalid> */ - public function refresh($force = False) + public function refresh($force = false) { - if(($this->lastrefresh > (time() - (60*60*4))) and (!$force)) + if (($this->lastrefresh > (time() - (60*60*4))) and (!$force)) { return; + } - $repometa = @file_get_contents($this->baseurl . "/repometa", False, $this->stream_ctx); - if($repometa === FALSE) + $repometa = @file_get_contents($this->baseurl . "/repometa", false, $this->stream_ctx); + if ($repometa === false) { throw new RepositoryUnreachableOrInvalid(); + } $repometa = @unserialize($repometa); - if((!is_array($repometa)) or (!isset($repometa["name"])) or (!isset($repometa["description"]))) + if ((!is_array($repometa)) or (!isset($repometa["name"])) or (!isset($repometa["description"]))) { throw new RepositoryUnreachableOrInvalid(); + } $this->name = $repometa["name"]; $this->description = $repometa["description"]; - $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", False, $ctx)); + $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", false, $ctx)); $this->lastrefresh = time(); @@ -2464,22 +2649,22 @@ class Repository extends BySQLRowEnabled */ public function get_package_meta($pkgname) { - $found = False; - foreach($this->packages as $p) - { - if($p[0] == $pkgname) - { - $found = True; + $found = false; + foreach ($this->packages as $p) { + if ($p[0] == $pkgname) { + $found = true; break; } } - if(!$found) + if (!$found) { throw new DoesNotExistError("Package not in package cache."); + } - $pkgmeta = @unserialize(@file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/meta", False, $this->stream_ctx)); + $pkgmeta = @unserialize(@file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/meta", false, $this->stream_ctx)); - if(!($pkgmeta instanceof PluginPackageMeta)) + if (!($pkgmeta instanceof PluginPackageMeta)) { throw new DoesNotExistError(); + } return $pkgmeta; } @@ -2501,21 +2686,21 @@ class Repository extends BySQLRowEnabled */ public function download_package($pkgname, $version = "current") { - $found = False; - foreach($this->packages as $p) - { - if($p[0] == $pkgname) - { - $found = True; + $found = false; + foreach ($this->packages as $p) { + if ($p[0] == $pkgname) { + $found = true; break; } } - if(!$found) + if (!$found) { throw new DoesNotExistError("Package not in package cache."); + } - $raw = @file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/versions/" . urlencode($version), False, $this->stream_ctx); - if($raw === False) + $raw = @file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/versions/" . urlencode($version), false, $this->stream_ctx); + if ($raw === false) { throw new DoesNotExistError(); + } return PluginPackage::load($raw); } @@ -2559,7 +2744,7 @@ class Article extends BySQLRowEnabled protected function __construct() { - $this->section_obj = NULL; + $this->section_obj = null; } protected function populate_by_sqlrow($sqlrow) @@ -2571,7 +2756,7 @@ class Article extends BySQLRowEnabled $this->excerpt = Multilingual::by_id($sqlrow["excerpt"]); $this->meta = $sqlrow["meta"]; $this->custom = unserialize(base64_decode($sqlrow["custom"])); - $this->article_image = $sqlrow["article_image"] == 0 ? NULL : Image::by_id($sqlrow["article_image"]); + $this->article_image = $sqlrow["article_image"] == 0 ? null : Image::by_id($sqlrow["article_image"]); $this->status = $sqlrow["status"]; $this->section_id = $sqlrow["section"]; $this->timestamp = $sqlrow["timestamp"]; @@ -2581,7 +2766,10 @@ class Article extends BySQLRowEnabled /* * Function: get_id */ - public function get_id() { return $this->id; } + public function get_id() + { + return $this->id; + } /* * Function: test_urlname @@ -2628,29 +2816,28 @@ class Article extends BySQLRowEnabled global $ratatoeskr_settings; global $db_con; - if(!self::test_urlname($urlname)) + if (!self::test_urlname($urlname)) { throw new InvalidDataError("invalid_urlname"); + } - try - { + try { self::by_urlname($urlname); - } - catch(DoesNotExistError $e) - { + } catch (DoesNotExistError $e) { $obj = new self(); $obj->urlname = $urlname; $obj->title = Multilingual::create(); $obj->text = Multilingual::create(); $obj->excerpt = Multilingual::create(); $obj->meta = ""; - $obj->custom = array(); - $obj->article_image = NULL; + $obj->custom = []; + $obj->article_image = null; $obj->status = ARTICLE_STATUS_HIDDEN; $obj->section_id = $ratatoeskr_settings["default_section"]; $obj->timestamp = time(); $obj->allow_comments = $ratatoeskr_settings["allow_comments_default"]; - qdb("INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)", + qdb( + "INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)", $obj->title->get_id(), $obj->text->get_id(), $obj->excerpt->get_id(), @@ -2658,7 +2845,8 @@ class Article extends BySQLRowEnabled $obj->status, $obj->section_id, $obj->timestamp, - $obj->allow_comments ? 1 : 0); + $obj->allow_comments ? 1 : 0 + ); $obj->id = $db_con->lastInsertId(); return $obj; } @@ -2680,8 +2868,9 @@ class Article extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `id` = ?", $id); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -2700,8 +2889,9 @@ class Article extends BySQLRowEnabled { $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `urlname` = ?", $urlname); $sqlrow = $stmt->fetch(); - if($sqlrow === False) + if ($sqlrow === false) { throw new DoesNotExistError(); + } return self::by_sqlrow($sqlrow); } @@ -2725,12 +2915,10 @@ class Article extends BySQLRowEnabled */ public static function by_multi($criterias, $sortby, $sortdir, $count, $offset, $perpage, $page, &$maxpage) { - $subqueries = array(); - $subparams = array(); - foreach($criterias as $k => $v) - { - switch($k) - { + $subqueries = []; + $subparams = []; + foreach ($criterias as $k => $v) { + switch ($k) { case "id": $subqueries[] = "`a`.`id` = ?"; $subparams[] = $v; @@ -2762,11 +2950,11 @@ class Article extends BySQLRowEnabled } } - if(($sortdir != "ASC") and ($sortdir != "DESC")) + if (($sortdir != "ASC") and ($sortdir != "DESC")) { $sortdir = "ASC"; + } $sorting = ""; - switch($sortby) - { + switch ($sortby) { case "id": $sorting = "ORDER BY `a`.`id` $sortdir"; break; case "urlname": $sorting = "ORDER BY `a`.`urlname` $sortdir"; break; case "timestamp": $sorting = "ORDER BY `a`.`timestamp` $sortdir"; break; @@ -2780,30 +2968,30 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); $stmt->execute($subparams); - $rows = array(); - $fetched_ids = array(); - while($sqlrow = $stmt->fetch()) - { - if(!in_array($sqlrow["id"], $fetched_ids)) - { + $rows = []; + $fetched_ids = []; + while ($sqlrow = $stmt->fetch()) { + if (!in_array($sqlrow["id"], $fetched_ids)) { $rows[] = $sqlrow; $fetched_ids[] = $sqlrow["id"]; } } - if($count !== NULL) + if ($count !== null) { $rows = array_slice($rows, 0, $count); - if($offset !== NULL) + } + if ($offset !== null) { $rows = array_slice($rows, $offset); - if(($perpage !== NULL) and ($page !== NULL)) - { + } + if (($perpage !== null) and ($page !== null)) { $maxpage = ceil(count($rows) / $perpage); $rows = array_slice($rows, $perpage * ($page - 1), $perpage); } - $rv = array(); - foreach($rows as $r) + $rv = []; + foreach ($rows as $r) { $rv[] = self::by_sqlrow($r); + } return $rv; } @@ -2816,10 +3004,11 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); */ public static function all() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE 1"); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = self::by_sqlrow($sqlrow); + } return $rv; } @@ -2834,24 +3023,25 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); * Returns: * Array of <Comment> objects. */ - public function get_comments($limit_lang = "", $only_visible = False) + public function get_comments($limit_lang = "", $only_visible = false) { - $rv = array(); + $rv = []; - $conditions = array("`article` = ?"); - $arguments = array($this->id); - if($limit_lang != "") - { + $conditions = ["`article` = ?"]; + $arguments = [$this->id]; + if ($limit_lang != "") { $conditions[] = "`language` = ?"; $arguments[] = $limit_lang; } - if($only_visible) + if ($only_visible) { $conditions[] = "`visible` = 1"; + } $stmt = prep_stmt("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE " . implode(" AND ", $conditions)); $stmt->execute($arguments); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = Comment::by_sqlrow($sqlrow); + } return $rv; } @@ -2864,10 +3054,11 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); */ public function get_tags() { - $rv = array(); + $rv = []; $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`title` AS `title` FROM `PREFIX_tags` `a` INNER JOIN `PREFIX_article_tag_relations` `b` ON `a`.`id` = `b`.`tag` WHERE `b`.`article` = ?", $this->id); - while($sqlrow = $stmt->fetch()) + while ($sqlrow = $stmt->fetch()) { $rv[] = Tag::by_sqlrow($sqlrow); + } return $rv; } @@ -2881,32 +3072,28 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); public function set_tags($tags) { $tx = new Transaction(); - try - { - foreach($tags as $tag) + try { + foreach ($tags as $tag) { $tag->save(); + } qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article`= ?", $this->id); $articleid = $this->id; - if(!empty($tags)) - { + if (!empty($tags)) { $stmt = prep_stmt( "INSERT INTO `PREFIX_article_tag_relations` (`article`, `tag`) VALUES " . implode(",", array_fill(0, count($tags), "(?,?)")) ); - $args = array(); - foreach($tags as $tag) - { + $args = []; + foreach ($tags as $tag) { $args[] = $articleid; $args[] = $tag->get_id(); } $stmt->execute($args); } $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -2921,8 +3108,9 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); */ public function get_section() { - if($this->section_obj === NULL) + if ($this->section_obj === null) { $this->section_obj = Section::by_id($this->section_id); + } return $this->section_obj; } @@ -2962,32 +3150,35 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); */ public function save() { - if(!self::test_urlname($this->urlname)) + if (!self::test_urlname($this->urlname)) { throw new InvalidDataError("invalid_urlname"); + } - if(!self::test_status($this->status)) + if (!self::test_status($this->status)) { throw new InvalidDataError("invalid_article_status"); + } $tx = new Transaction(); - try - { + try { $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_articles` WHERE `urlname` = ? AND `id` != ?", $this->urlname, $this->id); $sqlrow = $stmt->fetch(); - if($sqlrow["n"] > 0) + if ($sqlrow["n"] > 0) { throw new AlreadyExistsError(); + } $this->title->save(); $this->text->save(); $this->excerpt->save(); - qdb("UPDATE `PREFIX_articles` SET `urlname` = ?, `title` = ?, `text` = ?, `excerpt` = ?, `meta` = ?, `custom` = ?, `article_image` = ?, `status` = ?, `section` = ?, `timestamp` = ?, `allow_comments` = ? WHERE `id` = ?", + qdb( + "UPDATE `PREFIX_articles` SET `urlname` = ?, `title` = ?, `text` = ?, `excerpt` = ?, `meta` = ?, `custom` = ?, `article_image` = ?, `status` = ?, `section` = ?, `timestamp` = ?, `allow_comments` = ? WHERE `id` = ?", $this->urlname, $this->title->get_id(), $this->text->get_id(), $this->excerpt->get_id(), $this->meta, base64_encode(serialize($this->custom)), - $this->article_image === NULL ? 0 : $this->article_image->get_id(), + $this->article_image === null ? 0 : $this->article_image->get_id(), $this->status, $this->section_id, $this->timestamp, @@ -2995,9 +3186,7 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); $this->id ); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -3009,22 +3198,20 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting"); public function delete() { $tx = new Transaction(); - try - { + try { $this->title->delete(); $this->text->delete(); $this->excerpt->delete(); - foreach($this->get_comments() as $comment) + foreach ($this->get_comments() as $comment) { $comment->delete(); + } qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article` = ?", $this->id); qdb("DELETE FROM `PREFIX_article_extradata` WHERE `article` = ?", $this->id); qdb("DELETE FROM `PREFIX_articles` WHERE `id` = ?", $this->id); $tx->commit(); - } - catch(Exception $e) - { + } catch (Exception $e) { $tx->rollback(); throw $e; } @@ -3050,10 +3237,10 @@ class ArticleExtradata extends KVStorage */ public function __construct($article_id, $plugin_id) { - $this->init("PREFIX_article_extradata", array( + $this->init("PREFIX_article_extradata", [ "article" => $article_id, "plugin" => $plugin_id, - )); + ]); } } @@ -3067,11 +3254,15 @@ class ArticleExtradata extends KVStorage function dbversion() { /* Is the meta table present? If no, the version is 0. */ - $stmt = qdb("SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?", - $config["mysql"]["db"], sub_prefix("PREFIX_meta")); + $stmt = qdb( + "SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?", + $config["mysql"]["db"], + sub_prefix("PREFIX_meta") + ); list($n) = $stmt->fetch(); - if($n == 0) + if ($n == 0) { return 0; + } $stmt = qdb("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'"); $sqlrow = $stmt->fetch(); @@ -3085,8 +3276,7 @@ function dbversion() function clean_database() { global $ratatoeskr_settings; - if((!isset($ratatoeskr_settings["last_db_cleanup"])) or ($ratatoeskr_settings["last_db_cleanup"] < (time() - 86400))) - { + if ((!isset($ratatoeskr_settings["last_db_cleanup"])) or ($ratatoeskr_settings["last_db_cleanup"] < (time() - 86400))) { Plugin::clean_db(); $ratatoeskr_settings["last_db_cleanup"] = time(); } diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php index 2e539c8..65b43e2 100644 --- a/ratatoeskr/sys/plugin_api.php +++ b/ratatoeskr/sys/plugin_api.php @@ -23,9 +23,9 @@ define("APIVERSION", 6); * Array: $api_compat * Array of API versions, this version is compatible to (including itself). */ -$api_compat = array(3, 4, 5, 6); +$api_compat = [3, 4, 5, 6]; -$url_handlers = array(); /* master URL handler */ +$url_handlers = []; /* master URL handler */ /* * Function: register_url_handler @@ -41,9 +41,9 @@ function register_url_handler($name, $callback) $url_handlers[$name] = $callback; } -$pluginpages_handlers = array(); +$pluginpages_handlers = []; -$articleeditor_plugins = array(); +$articleeditor_plugins = []; /* * Class: RatatoeskrPlugin @@ -91,11 +91,26 @@ abstract class RatatoeskrPlugin * get_custompub_url - Get URL (can be accessed from the web) to the custompub directory of your plugin. * get_template_dir - Get path to your template directory to be used with STE. */ - final public function get_id() { return $this->id; } - final protected function get_custompriv_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id; } - final protected function get_custompub_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id; } - final protected function get_custompub_url() { return $GLOBALS["rel_path_to_root"] . "/ratatoeskr/plugin_extradata/public/" . $this->id; } - final protected function get_template_dir() { return "/plugintemplates/" . $this->id; } + final public function get_id() + { + return $this->id; + } + final protected function get_custompriv_dir() + { + return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id; + } + final protected function get_custompub_dir() + { + return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id; + } + final protected function get_custompub_url() + { + return $GLOBALS["rel_path_to_root"] . "/ratatoeskr/plugin_extradata/public/" . $this->id; + } + final protected function get_template_dir() + { + return "/plugintemplates/" . $this->id; + } /* * Function: register_url_handler @@ -132,7 +147,7 @@ abstract class RatatoeskrPlugin * $fx - Function to register (function($input), returns HTML). * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True. */ - final protected function register_textprocessor($name, $fx, $visible_in_backend=True) + final protected function register_textprocessor($name, $fx, $visible_in_backend=true) { textprocessor_register($name, $fx, $visible_in_backend); } @@ -186,11 +201,10 @@ abstract class RatatoeskrPlugin $this->ste->vars["pluginpages"][$this->id] = $label; asort($this->ste->vars["pluginpages"]); $pluginid = $this->id; - $pluginpages_handlers["p{$this->id}"] = function(&$data, $url_now, &$url_next) use($pluginid, $fx) - { + $pluginpages_handlers["p{$this->id}"] = function (&$data, $url_now, &$url_next) use ($pluginid, $fx) { global $ste, $rel_path_to_root; $ste->vars["rel_path_to_pluginpage"] = "$rel_path_to_root/backend/pluginpages/p$pluginid"; - $rv = call_user_func_array($fx, array(&$data, $url_now, &$url_next)); + $rv = call_user_func_array($fx, [&$data, $url_now, &$url_next]); unset($ste->vars["rel_path_to_pluginpage"]); return $rv; }; @@ -215,12 +229,12 @@ abstract class RatatoeskrPlugin { global $articleeditor_plugins; - $articleeditor_plugins[] = array( + $articleeditor_plugins[] = [ "label" => $label, "fx" => $fx, "template" => $this->get_template_dir() . "/" . $template, - "display" => $template != NULL - ); + "display" => $template != null + ]; } /* @@ -271,9 +285,19 @@ abstract class RatatoeskrPlugin * uninstall - Will be called during uninstallation. If you used the install function you should undo your custom installation stuff. * update - Will be called after your plugin was updated to a new version. */ - public function init() {} - public function atexit() {} - public function install() {} - public function uninstall() {} - public function update() {} + public function init() + { + } + public function atexit() + { + } + public function install() + { + } + public function uninstall() + { + } + public function update() + { + } } diff --git a/ratatoeskr/sys/pluginpackage.php b/ratatoeskr/sys/pluginpackage.php index c027c87..3e2c5f9 100644 --- a/ratatoeskr/sys/pluginpackage.php +++ b/ratatoeskr/sys/pluginpackage.php @@ -24,16 +24,17 @@ */ function dir2array($dir) { - $rv = array(); - foreach(scandir($dir) as $fn) - { - if(($fn == ".") or ($fn == "..")) + $rv = []; + foreach (scandir($dir) as $fn) { + if (($fn == ".") or ($fn == "..")) { continue; + } $fn_new = $dir . "/" . $fn; - if(is_dir($fn_new)) + if (is_dir($fn_new)) { $rv[$fn] = dir2array($fn_new); - elseif(is_file($fn_new)) + } elseif (is_file($fn_new)) { $rv[$fn] = file_get_contents($fn_new); + } } return $rv; } @@ -48,41 +49,49 @@ function dir2array($dir) */ function array2dir($a, $dir) { - if(!is_dir($dir)) + if (!is_dir($dir)) { mkdir($dir); + } - foreach($a as $k => $v) - { + foreach ($a as $k => $v) { $k = "$dir/$k"; - if(is_array($v)) + if (is_array($v)) { array2dir($v, $k); - else + } else { file_put_contents($k, $v); + } } } -function validate_url ($u) { return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; } +function validate_url($u) +{ + return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; +} function validate_arraydir($a) { - if(!is_array($a)) - return False; - foreach($a as $k=>$v) - { - if(!is_string($k)) - return False; - if(is_array($v) and (!validate_arraydir($v))) - return False; - elseif(!is_string($v)) - return False; + if (!is_array($a)) { + return false; + } + foreach ($a as $k=>$v) { + if (!is_string($k)) { + return false; + } + if (is_array($v) and (!validate_arraydir($v))) { + return false; + } elseif (!is_string($v)) { + return false; + } } - return True; + return true; } /* * Class: InvalidPackage * An Exception that <PluginPackage>'s function can throw, if the package is invalid. */ -class InvalidPackage extends Exception {} +class InvalidPackage extends Exception +{ +} /* * Class: PluginPackage @@ -104,14 +113,14 @@ class PluginPackage * $api - The used API version * $short_description - A short description. */ - public $code = NULL; - public $classname = NULL; - public $name = NULL; - public $author = NULL; - public $versiontext = NULL; - public $versioncount = NULL; - public $api = NULL; - public $short_description = NULL; + public $code = null; + public $classname = null; + public $name = null; + public $author = null; + public $versiontext = null; + public $versioncount = null; + public $api = null; + public $short_description = null; /* * Variables: Optional values @@ -124,13 +133,13 @@ class PluginPackage * $custompriv - <dir2array> 'd directory that contains custom private data. * $tpls - <dir2array> 'd directory containing custom STE templates. */ - public $updatepath = NULL; - public $web = NULL; - public $license = NULL; - public $help = NULL; - public $custompub = NULL; - public $custompriv = NULL; - public $tpls = NULL; + public $updatepath = null; + public $web = null; + public $license = null; + public $help = null; + public $custompub = null; + public $custompriv = null; + public $tpls = null; /* * Function: validate @@ -139,38 +148,53 @@ class PluginPackage */ public function validate() { - if(!is_string($this->code)) + if (!is_string($this->code)) { throw new InvalidPackage("Invalid code value."); - if(!is_string($this->classname)) + } + if (!is_string($this->classname)) { throw new InvalidPackage("Invalid classname value."); - if(preg_match("/^[a-zA-Z0-9_\\-]+$/", $this->name) == 0) + } + if (preg_match("/^[a-zA-Z0-9_\\-]+$/", $this->name) == 0) { throw new InvalidPackage("Invalid name value (must be at least 1 character, accepted chars: a-z A-Z 0-9 - _)."); - if(!is_string($this->author)) + } + if (!is_string($this->author)) { throw new InvalidPackage("Invalid author value."); - if(!is_string($this->versiontext)) + } + if (!is_string($this->versiontext)) { throw new InvalidPackage("Invalid versiontext value."); - if(!is_numeric($this->versioncount)) + } + if (!is_numeric($this->versioncount)) { throw new InvalidPackage("Invalid versioncount value. Must be a number."); - if(!is_numeric($this->api)) + } + if (!is_numeric($this->api)) { throw new InvalidPackage("Invalid api value. Must be a number."); - if(!is_string($this->short_description)) + } + if (!is_string($this->short_description)) { throw new InvalidPackage("Invalid short_description value."); + } - if((!empty($this->updatepath)) and (!validate_url($this->updatepath))) + if ((!empty($this->updatepath)) and (!validate_url($this->updatepath))) { throw new InvalidPackage("Invalid updatepath value. Must be an URL. " .$this->updatepath); - if((!empty($this->web)) and (!validate_url($this->web))) + } + if ((!empty($this->web)) and (!validate_url($this->web))) { throw new InvalidPackage("Invalid web value. Must be an URL."); - if(($this->license !== NULL) and (!is_string($this->license))) + } + if (($this->license !== null) and (!is_string($this->license))) { throw new InvalidPackage("Invalid license value."); - if(($this->help !== NULL) and (!is_string($this->help))) + } + if (($this->help !== null) and (!is_string($this->help))) { throw new InvalidPackage("Invalid help value."); - if(($this->custompub !== NULL) and (!validate_arraydir($this->custompub))) + } + if (($this->custompub !== null) and (!validate_arraydir($this->custompub))) { throw new InvalidPackage("Invalid custompub value."); - if(($this->custompriv !== NULL) and (!validate_arraydir($this->custompriv))) + } + if (($this->custompriv !== null) and (!validate_arraydir($this->custompriv))) { throw new InvalidPackage("Invalid custompriv value."); - if(($this->tpls !== NULL) and (!validate_arraydir($this->tpls))) + } + if (($this->tpls !== null) and (!validate_arraydir($this->tpls))) { throw new InvalidPackage("Invalid tpls value."); - return True; + } + return true; } /* @@ -190,18 +214,21 @@ class PluginPackage { /* Read and compare magic number */ $magic = substr($plugin_raw, 0, strlen(self::$magic)); - if($magic != self::$magic) + if ($magic != self::$magic) { throw new InvalidPackage("Wrong magic number"); + } /* Read sha1sum and uncompress serialized plugin, then compare the hash */ $sha1sum = substr($plugin_raw, strlen(self::$magic), 20); $pluginser = gzuncompress(substr($plugin_raw, strlen(self::$magic) + 20)); - if(sha1($pluginser, True) != $sha1sum) + if (sha1($pluginser, true) != $sha1sum) { throw new InvalidPackage("Wrong SHA1 hash"); + } $plugin = @unserialize($pluginser); - if(!($plugin instanceof self)) + if (!($plugin instanceof self)) { throw new InvalidPackage("Not the correct class or not unserializeable."); + } $plugin->validate(); @@ -222,7 +249,7 @@ class PluginPackage { $this->validate(); $ser = serialize($this); - return self::$magic . sha1($ser, True) . gzcompress($ser, 9); + return self::$magic . sha1($ser, true) . gzcompress($ser, 9); } /* @@ -266,12 +293,12 @@ class PluginPackageMeta * $api - The used API version * $short_description - A short description. */ - public $name = NULL; - public $author = NULL; - public $versiontext = NULL; - public $versioncount = NULL; - public $api = NULL; - public $short_description = NULL; + public $name = null; + public $author = null; + public $versiontext = null; + public $versioncount = null; + public $api = null; + public $short_description = null; /* * Variables: Optional values @@ -280,7 +307,7 @@ class PluginPackageMeta * $web - A URL to the webpage for the plugin. If left empty, the default repository software will set this to the description page of your plugin. * $license - The license text of your plugin. */ - public $updatepath = NULL; - public $web = NULL; - public $license = NULL; + public $updatepath = null; + public $web = null; + public $license = null; } diff --git a/ratatoeskr/sys/pwhash.php b/ratatoeskr/sys/pwhash.php index 78c3d33..3d3c589 100644 --- a/ratatoeskr/sys/pwhash.php +++ b/ratatoeskr/sys/pwhash.php @@ -19,7 +19,9 @@ */ class PasswordHash { - private function __construct() {} /* Prevent construction */ + private function __construct() + { + } /* Prevent construction */ private static $saltlen_min = 20; private static $saltlen_max = 30; @@ -29,8 +31,9 @@ class PasswordHash private static function hash($data, $salt, $iterations) { $hash = $data . $salt; - for($i = $iterations ;$i--;) + for ($i = $iterations ;$i--;) { $hash = sha1($data . $hash . $salt, (bool) $i); + } return $iterations . '$' . bin2hex($salt) . '$' . $hash; } @@ -48,8 +51,9 @@ class PasswordHash { $salt = ""; $saltlen = mt_rand(self::$saltlen_min, self::$saltlen_max); - for($i = 0; $i < $saltlen; $i++) - $salt .= chr(mt_rand(0,255)); + for ($i = 0; $i < $saltlen; $i++) { + $salt .= chr(mt_rand(0, 255)); + } return self::hash($password, $salt, mt_rand(self::$iterations_min, self::$iterations_max)); } diff --git a/ratatoeskr/sys/textprocessors.php b/ratatoeskr/sys/textprocessors.php index d5d959d..7ff3bbb 100644 --- a/ratatoeskr/sys/textprocessors.php +++ b/ratatoeskr/sys/textprocessors.php @@ -21,10 +21,10 @@ require_once(dirname(__FILE__) . "/utils.php"); * $fx - The textprocessor function (function($input), returns HTML) * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True. */ -function textprocessor_register($name, $fx, $visible_in_backend=True) +function textprocessor_register($name, $fx, $visible_in_backend=true) { global $textprocessors; - $textprocessors[$name] = array($fx, $visible_in_backend); + $textprocessors[$name] = [$fx, $visible_in_backend]; } /* @@ -41,12 +41,14 @@ function textprocessor_register($name, $fx, $visible_in_backend=True) function textprocessor_apply($text, $textprocessor) { global $textprocessors; - if(!isset($textprocessors[$textprocessor])) + if (!isset($textprocessors[$textprocessor])) { throw new Exception("Unknown Textprocessor: $textprocessor"); + } $fx = @$textprocessors[$textprocessor][0]; - if(!is_callable($fx)) + if (!is_callable($fx)) { throw new Exception("Invalid Textprocessor: $textprocessor"); + } return call_user_func($fx, $text); } @@ -66,11 +68,14 @@ function textprocessor_apply_translation($translationobj) return textprocessor_apply($translationobj->text, $translationobj->texttype); } -if(!isset($textprocessors)) -{ - $textprocessors = array( - "Markdown" => array("Markdown", True), - "Plain Text" => array(function($text) { return str_replace(array("\r\n", "\n"), array("<br />", "<br />"), htmlesc($text)); }, True), - "HTML" => array(function($text) { return $text; }, True) - ); +if (!isset($textprocessors)) { + $textprocessors = [ + "Markdown" => ["Markdown", true], + "Plain Text" => [function ($text) { + return str_replace(["\r\n", "\n"], ["<br />", "<br />"], htmlesc($text)); + }, true], + "HTML" => [function ($text) { + return $text; + }, true] + ]; } diff --git a/ratatoeskr/sys/translation.php b/ratatoeskr/sys/translation.php index 1506543..30f32e3 100644 --- a/ratatoeskr/sys/translation.php +++ b/ratatoeskr/sys/translation.php @@ -12,23 +12,23 @@ require_once(dirname(__FILE__) . "/utils.php"); require_once(dirname(__FILE__) . "/init_ste.php"); -if(!defined("SETUP")) +if (!defined("SETUP")) { require_once(dirname(__FILE__) . "/models.php"); +} -if(!defined("TRANSLATION_PLUGIN_LOADED")) -{ +if (!defined("TRANSLATION_PLUGIN_LOADED")) { $ste->register_tag( "get_translation", - function($ste, $params, $sub) - { + function ($ste, $params, $sub) { global $translation; - if((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]]))) + if ((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]]))) { return ""; + } $rv = $translation[$params["for"]]; return (!empty($params["raw"])) ? $rv : htmlesc($rv); } ); - define("TRANSLATION_PLUGIN_LOADED", True); + define("TRANSLATION_PLUGIN_LOADED", true); } /* @@ -38,18 +38,17 @@ if(!defined("TRANSLATION_PLUGIN_LOADED")) * Parameters: * $lang - The language (2-Letter code, e.g. "en", "de", "it" ...) to load. NULL for default (from database). */ -function load_language($lang=NULL) +function load_language($lang=null) { - if(!defined("SETUP")) - { + if (!defined("SETUP")) { global $ratatoeskr_settings; - if($lang === NULL) + if ($lang === null) { $lang = $ratatoeskr_settings["default_language"]; - } - else - { - if($lang === NULL) + } + } else { + if ($lang === null) { $lang = "en"; + } } /* diff --git a/ratatoeskr/sys/urlprocess.php b/ratatoeskr/sys/urlprocess.php index 4582a7e..89beb70 100644 --- a/ratatoeskr/sys/urlprocess.php +++ b/ratatoeskr/sys/urlprocess.php @@ -22,15 +22,11 @@ */ function url_action_simple($function) { - return function(&$data, $url_now, &$url_next) use ($function) - { - try - { + return function (&$data, $url_now, &$url_next) use ($function) { + try { $data = call_user_func($function, $data); - $url_next = array(); - } - catch(Redirect $e) - { + $url_next = []; + } catch (Redirect $e) { $url_next = $e->nextpath; } }; @@ -48,13 +44,13 @@ function url_action_simple($function) */ function url_action_subactions($actions) { - return function(&$data, $url_now, &$url_next) use ($actions) - { + return function (&$data, $url_now, &$url_next) use ($actions) { $result = url_process($url_next, $actions, $data); - if($result !== NULL) + if ($result !== null) { $url_next = $result; - else - $url_next = array(); + } else { + $url_next = []; + } }; } @@ -70,8 +66,7 @@ function url_action_subactions($actions) */ function url_action_alias($for) { - return function(&$data, $url_now, &$url_next) use($for) - { + return function (&$data, $url_now, &$url_next) use ($for) { $url_next = array_merge($for, $url_next); }; } @@ -96,64 +91,66 @@ function url_action_alias($for) function url_process($url, $actions, &$data) { $epilog_running = 0; - if(is_string($url)) + if (is_string($url)) { $url = explode("/", $url); - $url = array_filter($url, function($x) { return !empty($x); }); - if(count($url) == 0) - $url = array("_index"); + } + $url = array_filter($url, function ($x) { + return !empty($x); + }); + if (count($url) == 0) { + $url = ["_index"]; + } - if(isset($actions["_prelude"])) - $url = array_merge(array("_prelude"), $url); + if (isset($actions["_prelude"])) { + $url = array_merge(["_prelude"], $url); + } $url_now = $url[0]; $url_next = array_slice($url, 1); - while(is_string($url_now) and ($url_now != "") and ($url_now != "..")) - { - $cb = NULL; - if(empty($url_now)) + while (is_string($url_now) and ($url_now != "") and ($url_now != "..")) { + $cb = null; + if (empty($url_now)) { $url_now = "_index"; - if(isset($actions[$url_now])) + } + if (isset($actions[$url_now])) { $cb = $actions[$url_now]; - else if(isset($actions["_default"])) + } elseif (isset($actions["_default"])) { $cb = $actions["_default"]; - else if(isset($actions["_notfound"])) + } elseif (isset($actions["_notfound"])) { $cb = $actions["_notfound"]; - else + } else { throw new NotFoundError(); - - try - { - call_user_func_array($cb, array(&$data, $url_now, &$url_next)); } - catch(NotFoundError $e) - { - if(isset($actions["_notfound"])) - $url_next = array("_notfound"); - else + + try { + call_user_func_array($cb, [&$data, $url_now, &$url_next]); + } catch (NotFoundError $e) { + if (isset($actions["_notfound"])) { + $url_next = ["_notfound"]; + } else { throw $e; + } } - if(count($url_next) > 0) - { + if (count($url_next) > 0) { $url_now = $url_next[0]; $url_next = array_slice($url_next, 1); - } - else if(isset($actions["_epilog"]) and ($epilog_running <= 0)) - { + } elseif (isset($actions["_epilog"]) and ($epilog_running <= 0)) { $epilog_running = 2; $url_now = "_epilog"; - } - else + } else { $url_now = ""; + } --$epilog_running; } - if($url_now == "..") + if ($url_now == "..") { return $url_next; - else - return NULL; + } else { + return null; + } } /* @@ -174,4 +171,6 @@ class Redirect extends Exception * Class: NotFoundError * An Exception */ -class NotFoundError extends Exception { } +class NotFoundError extends Exception +{ +} diff --git a/ratatoeskr/sys/utils.php b/ratatoeskr/sys/utils.php index dd330c6..89f779d 100644 --- a/ratatoeskr/sys/utils.php +++ b/ratatoeskr/sys/utils.php @@ -24,9 +24,10 @@ */ function array_repeat($val, $n) { - $rv = array(); - for($i = 0; $i < $n; ++$i) + $rv = []; + for ($i = 0; $i < $n; ++$i) { array_push($rv, $val); + } return $rv; } @@ -44,19 +45,17 @@ function array_blend() { $arrays = array_filter(func_get_args(), "is_array"); - switch(count($arrays)) - { - case 0: return array(); break; + switch (count($arrays)) { + case 0: return []; break; case 1: return $arrays[0]; break; default: - $rv = array(); - while(array_sum(array_map("count", $arrays)) > 0) - { - for($i = 0; $i < count($arrays); ++$i) - { + $rv = []; + while (array_sum(array_map("count", $arrays)) > 0) { + for ($i = 0; $i < count($arrays); ++$i) { $val = array_shift($arrays[$i]); - if($val === NULL) + if ($val === null) { continue; + } array_push($rv, $val); } } @@ -80,7 +79,9 @@ function array_blend() */ function array_filter_empty($input) { - return array_filter($input, function($x){return !empty($x);}); + return array_filter($input, function ($x) { + return !empty($x); + }); } /* @@ -90,13 +91,18 @@ function array_filter_empty($input) */ function array_filter_keys($input, $callback) { - if(!is_array($input)) + if (!is_array($input)) { throw new InvalidArgumentException("Argument 1 must be an array"); - if(empty($input)) - return array(); - $delete_keys = array_filter(array_keys($input), function ($x) use ($callback) { return !$callback($x);}); - foreach($delete_keys as $key) + } + if (empty($input)) { + return []; + } + $delete_keys = array_filter(array_keys($input), function ($x) use ($callback) { + return !$callback($x); + }); + foreach ($delete_keys as $key) { unset($input[$key]); + } return $input; } @@ -112,9 +118,10 @@ function array_filter_keys($input, $callback) */ function array_kvpairs_to_assoc($input) { - $rv = array(); - foreach($input as $kvpair) + $rv = []; + foreach ($input as $kvpair) { $rv[$kvpair[0]] = $kvpair[1]; + } return $rv; } @@ -161,7 +168,9 @@ function ucount($array, $callback) */ function vcount($array, $value) { - return ucount($array, function($x){return $x===$value;}); + return ucount($array, function ($x) { + return $x===$value; + }); } /* @@ -171,7 +180,8 @@ function vcount($array, $value) * * From: http://dev.kanngard.net/Permalinks/ID_20050507183447.html */ -function self_url() { +function self_url() +{ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; @@ -180,7 +190,8 @@ function self_url() { : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } -function strleft($s1, $s2) { +function strleft($s1, $s2) +{ return substr($s1, 0, strpos($s1, $s2)); } @@ -206,17 +217,18 @@ function htmlesc($text) function delete_directory($dir) { $dir_content = scandir($dir); - foreach($dir_content as $f) - { - if(($f == "..") or ($f == ".")) + foreach ($dir_content as $f) { + if (($f == "..") or ($f == ".")) { continue; + } $f = "$dir/$f"; - if(is_dir($f)) + if (is_dir($f)) { delete_directory($f); - else + } else { unlink($f); + } } rmdir($dir); } diff --git a/ratatoeskr/translations/de.php b/ratatoeskr/translations/de.php index 6792060..114fc58 100644 --- a/ratatoeskr/translations/de.php +++ b/ratatoeskr/translations/de.php @@ -1,6 +1,6 @@ <?php -$translation = array( +$translation = [ "username" => "Benutzername", "password" => "Passwort", "login_form_header" => "Login", @@ -347,4 +347,4 @@ mit zweil Leerzeichen ab.</code> <a href="http://daringfireball.net/projects/markdown/dingus">Markdown testen</a> </p> CHEATSHEET -); +]; diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php index 792401d..7c49533 100644 --- a/ratatoeskr/translations/en.php +++ b/ratatoeskr/translations/en.php @@ -1,6 +1,6 @@ <?php -$translation = array( +$translation = [ "username" => "Username", "password" => "Password", "login_form_header" => "Login", @@ -346,4 +346,4 @@ Header 2<br /> <a href="http://daringfireball.net/projects/markdown/dingus">Test Markdown</a> </p> CHEATSHEET -); +]; |