1
0
Fork 0

Adds folder creation to new post/media flows if the folder doesn't exist. Updates readme.

This commit is contained in:
sloum 2023-12-21 20:09:03 -08:00
parent e7560519dc
commit 990ba199e4
3 changed files with 39 additions and 27 deletions

View File

@ -46,7 +46,7 @@ Likely just me and a few friends. That said, anyone wanting a simple and lightwe
- `POST_HEAD`, injects additional tags at the end of the `<head>` element for `post.php`
## Installation and usage
## Installation
_chickadee_ requires php and a php capable web server (we use apache2, but whatever floats your boat and also runs php should be fine). There are no other requirements. _chickadee_ is a flat file blog system and no database is required.
@ -58,11 +58,15 @@ git clone https://tildegit.org/sloum/chickadee myawesomeblog
cd myawesomeblog
vim config.php
```
Certainly replace `myawesomeblog` with the name of your folder. This may be `blog` if integrating into an existing site, or may be the name of the website. While I use `vim`, use whatever you like to edit `config.php`. It is a well commented file and should direct you to some good defaults for your use case.
Replace `myawesomeblog` with the name of your folder. This may be `blog` if integrating into an existing site, or may be the name of the website. While I use `vim`, use whatever you like to edit `config.php`. It is a well commented file and should direct you to some good defaults for your use case. Once you update it you may want to `git add config.php && git commit "Updated config"` so that you can still pull down updates of Chickadee if you want (without being hassled by notifications that you have uncommited changes).
Lastly, you need to set up your login information. This is easy, so long as your server is now exposing the paths and you can access the site: go to `/blog_log.php`. Enter a username and password of your choosing. Once you do so, you should see the admin area. The username and password you entered are now your username and password (the first ones entered are the ones used). If you ever need to reset your username/password you can go to the web root for the blog on your server and change the `BLOG_HASH` constant in `pass_hash.php` to `null` or `false` . This will reset the password without deleting any other data. You can then set a new one by going to the login page and entering new credentials.
Depending on your server setup, you may need to change the owner of the files. On Linux with Apache2 I do something like (from inside the repo dir root folder): `sudo chown -R myuser:www-data .`. That should make the files writable by the server.
## Usage
Having installed, you need to set up your login information. This is easy, so long as your server is now exposing the paths and you can access the site: go to `/blog_log.php`. Enter a username and password of your choosing. Once you do so, you should see the admin area. The username and password you entered are now your username and password (the first ones entered are the ones used). If you ever need to reset your username/password you can go to the web root for the blog on your server and change the `BLOG_HASH` constant in `pass_hash.php` to `null` or `false` . This will reset the password without deleting any other data. You can then set a new one by going to the login page and entering new credentials.
Cookies are required to use the system, but only one cookie is ever set and no tracking or phoning home are done. When you log in the system will keep you logged in for 30 days unless you explicitly log out (or clear your cookies). If you aren't on your own machine and want to log in we recommend a private browsing window/tab that will clear the cookies automatically when closed.
Actual usage of the amin area is pretty self explanatory and mostly reflects the `Admin Area` part of `Current Capabilities` (above).

View File

@ -16,6 +16,12 @@
die();
}
if (!file_exists("posts")) {
if (!mkdir("posts", 0775)) {
die("Server configuration does not allow for writing files");
}
}
// Try to write the file
$success = file_put_contents( "./posts/" . $ts . "_" . urlencode( $title ) . ".md", $body );
if ( $success ) {

View File

@ -6,35 +6,37 @@ if ( !$f ) {
header("Location: admin.php?success=0");
die();
}
error_log("Got file");
$target_dir = "media/";
$target_file = $target_dir . urlencode(basename( $f["name"] ) );
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($f["tmp_name"]);
if($check !== false) {
if ( file_exists( $target_file ) ) {
// Check if file already exists
$uploadOk = "0";
} else if ($f["size"] > 1500000) {
// Check file size
$uploadOk = "4";
} else if(
!in_array(
$imageFileType,
["svg", "jpg", "jpeg", "png", "gif", "pdf",
"epub", "azw3", "mobi", "html", "css" ]
)){
$uploadOk = 5;
if (!file_exists("media")) {
if (!mkdir("media", 0775)) {
die("Server configuration does not allow for writing files");
}
}
if ( file_exists( $target_file ) ) {
// Check if file already exists
$uploadOk = "0";
} else if ($f["size"] > 1500000) {
// Check file size
$uploadOk = "4";
} else if(
!in_array(
$imageFileType,
["svg", "jpg", "jpeg", "png", "gif", "pdf",
"epub", "azw3", "mobi", "html", "css" ]
)){
$uploadOk = 5;
} else {
$done = move_uploaded_file($f["tmp_name"], $target_file);
if ( $done ) {
$uploadOk = "3";
} else {
$done = move_uploaded_file($f["tmp_name"], $target_file);
if ( $done ) {
$uploadOk = "3";
} else {
$uploadOk = "0";
}
$uploadOk = "0";
}
}