Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18n #461

Merged
merged 3 commits into from Apr 18, 2021
Merged

I18n #461

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
@@ -0,0 +1,10 @@
FROM php:7.4-apache

RUN a2enmod rewrite ssl proxy proxy_http headers

RUN apt-get update && apt-get install -y \
git \
bash \
curl \
unzip \
vim
10 changes: 10 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,10 @@
version: '3'
services:
php:
container_name: dropplets
build: .
volumes:
- .:/var/www/html
ports:
- "3000:80"
restart: unless-stopped
36 changes: 23 additions & 13 deletions index.php
Expand Up @@ -23,9 +23,12 @@
"template" => "liquid",
"basePath" => $URI,
"timezone" => "America/New_York",
"I18N" => "us_EN",
];
}

require_once "./internal/i18n.php";

date_default_timezone_set($siteConfig['timezone']);

$Extra = new ParsedownExtra();
Expand Down Expand Up @@ -79,7 +82,7 @@
}
}, 'posts');

$router->map('GET', '/post/[i:id]', function ($id) {
$router->map('GET|POST', '/post/[i:id]', function ($id) {
global $router;
if (file_exists("config.php")) {
global $siteConfig;
Expand Down Expand Up @@ -211,21 +214,28 @@
global $router;
if (isset($_SESSION['isAuthenticated']) || !file_exists("config.php")) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["blogName"]) && isset($_POST["blogTimezone"]) && isset($_POST["blogTemplate"])) {
if (isset($_POST["blogName"]) && isset($_POST["blogTimezone"]) && isset($_POST["blogTemplate"])&& isset($_POST["blogI18N"])) {
if (!file_exists("config.php")) {
$password_hashed = password_hash(test_input($_POST["blogPassword"]), PASSWORD_BCRYPT);
$config_content = "<?php\n\$siteConfig = ['name'=>'" . test_input($_POST["blogName"]) . "',\n'info' => '" . test_input($_POST["blogInfo"]) . "',\n'footer' => '" . test_input($_POST["blogFooter"]) . "',\n'headerInject' => '" . base64_encode($_POST["blogHeaderInject"]) . "',\n'password' => '" . $password_hashed . "',\n'template' => '" . test_input($_POST["blogTemplate"]) . "',\n'basePath' => '" . test_input($_POST["blogBase"]) . "',\n'timezone' => '" . test_input($_POST["blogTimezone"]) . "',\n]\n?>";
$config = fopen("config.php", 'w') or die("Unable to set up needed files! Please make sure index.php has write permissions and that the folder it is in has write permissions. This is usally 755.");
fwrite($config, $config_content);
fclose($config);
header("Location: " . $router->generate('home'));
} else {
$config_content = "<?php\n\$siteConfig = ['name'=>'" . test_input($_POST["blogName"]) . "',\n'info' => '" . test_input($_POST["blogInfo"]) . "',\n'footer' => '" . test_input($_POST["blogFooter"]) . "',\n'headerInject' => '" . base64_encode($_POST["blogHeaderInject"]) . "',\n'password' => '" . $siteConfig['password'] . "',\n'template' => '" . test_input($_POST["blogTemplate"]) . "',\n'basePath' => '" . test_input($_POST["blogBase"]) . "',\n'timezone' => '" . test_input($_POST["blogTimezone"]) . "',\n]\n?>";
$config = fopen("config.php", 'w') or die("Unable to set up needed files! Please make sure index.php has write permissions and that the folder it is in has write permissions. This is usally 755.");
fwrite($config, $config_content);
fclose($config);
header("Location: " . $router->generate('home'));
}
else{
$password_hashed = $siteConfig['password'];
}
$config_content = "<?php\n\$siteConfig = [ \n"
."'name'=>'" . test_input($_POST["blogName"]) . "',\n"
."'info' => '" . test_input($_POST["blogInfo"]) . "',\n"
."'footer' => '" . test_input($_POST["blogFooter"]) . "',\n"
."'headerInject' => '" . base64_encode($_POST["blogHeaderInject"]) . "',\n"
."'password' => '" . $password_hashed . "',\n"
."'template' => '" . test_input($_POST["blogTemplate"]) . "',\n"
."'basePath' => '" . test_input($_POST["blogBase"]) . "',\n"
."'timezone' => '" . test_input($_POST["blogTimezone"]) . "',\n"
."'I18N' => '" . test_input($_POST["blogI18N"]) . "',\n"
."]\n?>";
$config = fopen("config.php", 'w') or die("Unable to set up needed files! Please make sure index.php has write permissions and that the folder it is in has write permissions. This is usally 755.");
fwrite($config, $config_content);
fclose($config);
header("Location: " . $router->generate('home'));
} else {
header("Location: " . $router->generate('settings'));
}
Expand Down
26 changes: 15 additions & 11 deletions internal/dashboard.php
@@ -1,31 +1,35 @@
<?php
require "header.php";

setlocale(LC_ALL, i18n('locale',false));
?>
<h1 class="setupH1 setup">Your Blog Dashboard</h1>
<h1 class="setupH1 setup"><?php i18n("dashboard_title"); ?></h1>
<div style="text-align: center;">
<a href="<?php echo $router->generate('write'); ?>" class="btn">Write A Blog Post</a>
<a href="<?php echo $router->generate('settings'); ?>" class="btn btn-secondary">Edit The Site Settings</a>
<a href="<?php echo $router->generate('logout'); ?>" class="btn btn-danger">Log Out</a>
<a href="<?php echo $router->generate('write'); ?>" class="btn"><?php i18n("dashboard_write_post"); ?></a>
<a href="<?php echo $router->generate('settings'); ?>" class="btn btn-secondary"><?php i18n("dashboard_settings"); ?></a>
<a href="<?php echo $router->generate('logout'); ?>" class="btn btn-danger"><?php i18n("dashboard_logout"); ?></a>
</div>
<div style="margin-top: 35px;">
<?php if ($postCount > 0) { ?>
<h1>All Posts:</h1>
<h1><?php i18n("dashboard_all_post"); ?></h1>
<?php
}
foreach ($allPosts as $post) {
?>
<div class="post">
<div class="postText">
<h2 id="postTitle"><a href="<?php echo $router->generate('post', ['id' => $post['_id']]); ?>"><?php echo $post['title']; ?></a></h2>
Posted by <?php echo $post['author']; ?> <?php echo date('F j, Y, g:i A', $post['date']); ?>
<h2 id="postTitle">
<a href="<?php echo $router->generate('post', ['id' => $post['_id']]); ?>"><?php echo $post['title']; ?></a>
</h2>
<?php i18n("dashboard_posted_by"); ?> <?php echo $post['author']; ?> - <?php echo strftime(i18n('dashboard_post_fulldate',false), $post['date']); ?>
<br>
<?php if ($post['draft'] == true) { ?>
<a href="<?php echo $router->generate('publish', ['id' => $post['_id']]); ?>" class="btn btn-sm">Publish</a>
<a href="<?php echo $router->generate('publish', ['id' => $post['_id']]); ?>" class="btn btn-sm"><?php i18n("dashboard_publish"); ?></a>
<?php } else { ?>
<a href="<?php echo $router->generate('hide', ['id' => $post['_id']]); ?>" class="btn btn-sm">Make Draft</a>
<a href="<?php echo $router->generate('hide', ['id' => $post['_id']]); ?>" class="btn btn-sm"><?php i18n("dashboard_draft"); ?></a>
<?php } ?>
<a href="<?php echo $router->generate('editPost', ['id' => $post['_id']]); ?>" class="btn btn-sm btn-secondary">Edit</a>
<a href="<?php echo $router->generate('deletePost', ['id' => $post['_id']]); ?>" class="btn btn-sm btn-danger">Delete</a>
<a href="<?php echo $router->generate('editPost', ['id' => $post['_id']]); ?>" class="btn btn-sm btn-secondary"><?php i18n("dashboard_edit"); ?></a>
<a href="<?php echo $router->generate('deletePost', ['id' => $post['_id']]); ?>" class="btn btn-sm btn-danger"><?php i18n("dashboard_delete"); ?></a>
</div>
</div>
<?php
Expand Down
140 changes: 140 additions & 0 deletions internal/i18n.php
@@ -0,0 +1,140 @@
<?php

$language = [
"en_US" => [
"locale" => "us_EN",
"dateformat" => "%B %d, %Y",
"settings_i18n" => "Internationalization:",
"settings_blog_creation" => "Let's create your blog",
"settings_blog_edition" => "Edit your blog's settings",
"settings_legend" => "First, some details:",
"settings_blog_name" => "Blog Name:",
"settings_blog_name_placeholder" => "Enter your blog's name",
"settings_blog_info" => "Blog Info:",
"settings_blog_info_placeholder" => "Enter an optional info message",
"settings_footer_message" => "Footer Message:",
"settings_footer_message_placeholder" => "Enter an optional footer message",
"settings_header_inject" => "Header Injection Code:",
"settings_header_inject_placeholder" => "Enter an optional header injection, ie. analytics",
"settings_template" => "Site Template Name:",
"settings_template_placeholder" => "Enter the name of a template",
"settings_timezone" => "Post Timezone:",
"settings_timezone_placeholder" => "Enter a timezone",
"settings_basepath" => "Site Base Path:",
"settings_basepath_placeholder" => "Enter the base path",
"settings_password_legend" => "Last but not least, the password:",
"settings_password_placeholder" => "Choose a good password",
"settings_password_legend_update" => "Type your password to update your blog:",
"settings_password_placeholder_update" => "Management password",
"settings_submit_creation" => "Create Your Blog",
"settings_submit_update" => "Update Your Blog",
"settings_dashboard_return" => "Return To Dashboard",
"dashboard_title" => "Your Blog Dashboard",
"dashboard_write_post" => "Write A Blog Post",
"dashboard_settings" => "Edit The Site Settings",
"dashboard_logout" => "Log Out",
"dashboard_all_post" => "All Posts:",
"dashboard_posted_by" => "Posted by",
"dashboard_post_fulldate" => "%B %d, %Y, %I:%M %p",
"dashboard_publish" => "Publish",
"dashboard_draft" => "Make Draft",
"dashboard_edit" => "Edit",
"dashboard_delete" => "Delete",
"login_title" => "Log Into Your Blog",
"login_password_legend" => "Type your password to update your blog:",
"login_password_placeholder" => "Management password",
"login_submit" => "Log In",
"private_title" => "Private Post",
"private_password_legend" => "Type your password to access private post:",
"private_password_placeholder" => "Post password",
"private_submit" => "Unlock",
"write_title" => "Time to write your prose",
"write_post_title_placeholder" => "The post title",
"write_post_author_placeholder" => "The post author",
"write_post_image_placeholder" => "A featured image for this post",
"write_post_password_placeholder" => "Password if you want to hide the post",
"write_post_markdown_placeholder" => "Write your post here, you can use Markdown",
"liquid_home_postedby" => "Posted by",
"liquid_home_date" => "%B %d, %Y",
"liquid_home_newer" => "Newer Posts",
"liquid_home_older" => "Older Posts",
"liquid_post_date" => "%B %d, %Y",

],
"fr_FR" => [
"locale" => "fr_FR",
"dateformat" => "%A %d %B %G",
"settings_i18n" => "Internationalisation:",
"settings_blog_creation" => "Création du blog",
"settings_blog_edition" => "Edition des paramétres",
"settings_legend" => "D'abord, quelques infos:",
"settings_blog_name" => "Nom du blog:",
"settings_blog_name_placeholder" => "Entrez un nom pour votre blog",
"settings_blog_info" => "Description:",
"settings_blog_info_placeholder" => "Entrez la description du blog",
"settings_footer_message" => "Pied de page:",
"settings_footer_message_placeholder" => "Entrez un message de pied de page",
"settings_header_inject" => "Injection de Code en En-tête:",
"settings_header_inject_placeholder" => "Entrez un code d'en-tête, ex: statistique",
"settings_template" => "Template du site:",
"settings_template_placeholder" => "Entrez le nom du template",
"settings_timezone" => "Fuseau horaire:",
"settings_timezone_placeholder" => "Entrez une timezone",
"settings_basepath" => "Dossier du site:",
"settings_basepath_placeholder" => "Entrez le dossier de base du site",
"settings_password_legend" => "Le dernier mais non le moindre, votre mot de passe",
"settings_password_placeholder" => "Choisissez un bon mot de passe",
"settings_password_legend_update" => "Entrez votre mot de passe pour mettre à jour le blog:",
"settings_password_placeholder_update" => "Mot de passe d'administration",
"settings_submit_creation" => "Créez votre blog",
"settings_submit_update" => "Mettre à jour",
"settings_dashboard_return" => "Retour au tableau de bord",
"dashboard_title" => "Votre tableau de bord",
"dashboard_write_post" => "Ecrire un article",
"dashboard_settings" => "Paramètres du site",
"dashboard_logout" => "Déconnexion",
"dashboard_all_post" => "Tous les articles:",
"dashboard_posted_by" => "Publié par",
"dashboard_post_fulldate" => "%A %d %B %G à %H:%M",
"dashboard_publish" => "Publier",
"dashboard_draft" => "Passer en Brouillon",
"dashboard_edit" => "Editer",
"dashboard_delete" => "Supprimer",
"login_title" => "Connecter vous à votre blog",
"login_password_legend" => "Taper votre mot de passe:",
"login_password_placeholder" => "Mot de passe d'administration",
"login_submit" => "Connexion",
"private_title" => "Article privé",
"private_password_legend" => "Tapez le mot de passe pour accèder à cet article:",
"private_password_placeholder" => "Mot de passe de l'article",
"private_submit" => "Déverouiller",
"write_title" => "C'est le moment de composer",
"write_post_title_placeholder" => "Titre de l'article",
"write_post_author_placeholder" => "Nom de l'auteur",
"write_post_image_placeholder" => "Image de description",
"write_post_password_placeholder" => "Mot de passe, pour rendre l'article privée",
"write_post_markdown_placeholder" => "Ecrivez votre article ici en markdown",
"liquid_home_postedby" => "Publié par",
"liquid_home_date" => "%A %d %B %G",
"liquid_home_newer" => "Articles récents",
"liquid_home_older" => "Articles anciens",
"liquid_post_date" => "%A %d %B %G",
]
];

function i18n($index, $echo = true){
global $siteConfig;
global $language;
$en = "en_US";
$i18n = empty($siteConfig['I18N'])?$en:$siteConfig['I18N'];
$default_value = isset($language[$en][$index])?$language[$en][$index]:$index;
$value = isset($language[$i18n][$index])?$language[$i18n][$index]:$default_value;
if($echo){
echo $value;
}
return $value;
}

setlocale(LC_ALL, i18n('locale',false));

?>
8 changes: 4 additions & 4 deletions internal/login.php
@@ -1,13 +1,13 @@
<?php
require "header.php";
?>
<h1 class="setupH1 setup">Log Into Your Blog</h1>
<h1 class="setupH1 setup"><?php i18n("login_title"); ?></h1>
<form method="post" action="<?php echo $router->generate('login'); ?>">
<fieldset>
<legend>Type your password to update your blog:</legend>
<input type="password" name="blogPassword" placeholder="Management password" required />
<legend><?php i18n("login_password_legend"); ?></legend>
<input type="password" name="blogPassword" placeholder="<?php i18n("login_password_placeholder"); ?>" required />
</fieldset>
<input class="btn" type="submit" value="Log In" />
<input class="btn" type="submit" value="<?php i18n("login_submit"); ?>" />
</form>
<?php
require "footer.php";
Expand Down
10 changes: 5 additions & 5 deletions internal/private.php
@@ -1,13 +1,13 @@
<?php
require "header.php";
?>
<h1 class="setupH1 setup">Private Post</h1>
<form method="get" action="">
<h1 class="setupH1 setup"><?php i18n("private_title"); ?></h1>
<form method="post" action="">
<fieldset>
<legend>Type the password to access this private post:</legend>
<input type="password" name="password" placeholder="Post password" required />
<legend><?php i18n("private_password_legend"); ?></legend>
<input type="password" name="password" placeholder="<?php i18n("private_password_placeholder"); ?>" required />
</fieldset>
<input class="btn" type="submit" value="Unlock" />
<input class="btn" type="submit" value="<?php i18n("private_submit"); ?>" />
</form>
<?php
require "footer.php";
Expand Down