diff --git a/docker_dev/compose.yaml b/docker_dev/compose.yaml index e1a79b0..cbbec73 100644 --- a/docker_dev/compose.yaml +++ b/docker_dev/compose.yaml @@ -9,6 +9,8 @@ services: watch: - path: ./ action: rebuild + - path: ../www/composer.* + action: rebuild - path: ../www/ action: sync target: /var/www/html diff --git a/www/composer.json b/www/composer.json index 6130261..752d618 100644 --- a/www/composer.json +++ b/www/composer.json @@ -2,6 +2,7 @@ "require": { "twig/twig": "^3.0", "twig/markdown-extra": "^3.6", - "league/commonmark": "^2.4" + "league/commonmark": "^2.4", + "spatie/yaml-front-matter": "^2.0" } } diff --git a/www/composer.lock b/www/composer.lock index b8538ec..e227088 100644 --- a/www/composer.lock +++ b/www/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "785c1dec442cd0287ada9cb48a31d45c", + "content-hash": "ae80529cc2442878a51f38de1f7017a4", "packages": [ { "name": "dflydev/dot-access-data", @@ -83,16 +83,16 @@ }, { "name": "league/commonmark", - "version": "2.4.0", + "version": "2.4.1", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "d44a24690f16b8c1808bf13b1bd54ae4c63ea048" + "reference": "3669d6d5f7a47a93c08ddff335e6d945481a1dd5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d44a24690f16b8c1808bf13b1bd54ae4c63ea048", - "reference": "d44a24690f16b8c1808bf13b1bd54ae4c63ea048", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/3669d6d5f7a47a93c08ddff335e6d945481a1dd5", + "reference": "3669d6d5f7a47a93c08ddff335e6d945481a1dd5", "shasum": "" }, "require": { @@ -185,7 +185,7 @@ "type": "tidelift" } ], - "time": "2023-03-24T15:16:10+00:00" + "time": "2023-08-30T16:55:00+00:00" }, { "name": "league/config", @@ -271,21 +271,21 @@ }, { "name": "nette/schema", - "version": "v1.2.3", + "version": "v1.2.5", "source": { "type": "git", "url": "https://github.com/nette/schema.git", - "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f" + "reference": "0462f0166e823aad657c9224d0f849ecac1ba10a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/schema/zipball/abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", - "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", + "url": "https://api.github.com/repos/nette/schema/zipball/0462f0166e823aad657c9224d0f849ecac1ba10a", + "reference": "0462f0166e823aad657c9224d0f849ecac1ba10a", "shasum": "" }, "require": { "nette/utils": "^2.5.7 || ^3.1.5 || ^4.0", - "php": ">=7.1 <8.3" + "php": "7.1 - 8.3" }, "require-dev": { "nette/tester": "^2.3 || ^2.4", @@ -327,35 +327,36 @@ ], "support": { "issues": "https://github.com/nette/schema/issues", - "source": "https://github.com/nette/schema/tree/v1.2.3" + "source": "https://github.com/nette/schema/tree/v1.2.5" }, - "time": "2022-10-13T01:24:26+00:00" + "time": "2023-10-05T20:37:59+00:00" }, { "name": "nette/utils", - "version": "v3.2.9", + "version": "v4.0.2", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c" + "reference": "cead6637226456b35e1175cc53797dd585d85545" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", - "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", + "url": "https://api.github.com/repos/nette/utils/zipball/cead6637226456b35e1175cc53797dd585d85545", + "reference": "cead6637226456b35e1175cc53797dd585d85545", "shasum": "" }, "require": { - "php": ">=7.2 <8.3" + "php": ">=8.0 <8.4" }, "conflict": { - "nette/di": "<3.0.6" + "nette/finder": "<3", + "nette/schema": "<1.2.2" }, "require-dev": { "jetbrains/phpstorm-attributes": "dev-master", - "nette/tester": "~2.0", + "nette/tester": "^2.5", "phpstan/phpstan": "^1.0", - "tracy/tracy": "^2.3" + "tracy/tracy": "^2.9" }, "suggest": { "ext-gd": "to use Image", @@ -363,13 +364,12 @@ "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", "ext-json": "to use Nette\\Utils\\Json", "ext-mbstring": "to use Strings::lower() etc...", - "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()", - "ext-xml": "to use Strings::length() etc. when mbstring is not available" + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-master": "4.0-dev" } }, "autoload": { @@ -413,9 +413,9 @@ ], "support": { "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v3.2.9" + "source": "https://github.com/nette/utils/tree/v4.0.2" }, - "time": "2023-01-18T03:26:20+00:00" + "time": "2023-09-19T11:58:07+00:00" }, { "name": "psr/event-dispatcher", @@ -468,26 +468,88 @@ "time": "2019-01-08T18:20:26+00:00" }, { - "name": "symfony/deprecation-contracts", - "version": "v2.5.2", + "name": "spatie/yaml-front-matter", + "version": "2.0.7", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" + "url": "https://github.com/spatie/yaml-front-matter.git", + "reference": "f49f228994de70827ca857efffdd3bd7703aea34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", - "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "url": "https://api.github.com/repos/spatie/yaml-front-matter/zipball/f49f228994de70827ca857efffdd3bd7703aea34", + "reference": "f49f228994de70827ca857efffdd3bd7703aea34", "shasum": "" }, "require": { - "php": ">=7.1" + "php": "^7.0|^8.0", + "symfony/yaml": "^3.0|^4.0|^5.0|^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\YamlFrontMatter\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "A to the point yaml front matter parser", + "homepage": "https://github.com/sebastiandedeyne/yaml-front-matter", + "keywords": [ + "front matter", + "jekyll", + "spatie", + "yaml" + ], + "support": { + "source": "https://github.com/spatie/yaml-front-matter/tree/2.0.7" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-04-06T12:03:55+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "2.5-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -516,7 +578,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" }, "funding": [ { @@ -532,20 +594,20 @@ "type": "tidelift" } ], - "time": "2022-01-02T09:53:40+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "shasum": "" }, "require": { @@ -560,7 +622,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -598,7 +660,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" }, "funding": [ { @@ -614,20 +676,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + "reference": "42292d99c55abe617799667f454222c54c60e229" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", + "reference": "42292d99c55abe617799667f454222c54c60e229", "shasum": "" }, "require": { @@ -642,7 +704,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -681,7 +743,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" }, "funding": [ { @@ -697,20 +759,20 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-07-28T09:04:16+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.27.0", + "version": "v1.28.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", "shasum": "" }, "require": { @@ -719,7 +781,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -764,7 +826,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" }, "funding": [ { @@ -780,20 +842,92 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { - "name": "twig/markdown-extra", - "version": "v3.6.0", + "name": "symfony/yaml", + "version": "v6.3.3", "source": { "type": "git", - "url": "https://github.com/twigphp/markdown-extra.git", - "reference": "8f1179e279cea6ef14066a4560b859df58acd5d8" + "url": "https://github.com/symfony/yaml.git", + "reference": "e23292e8c07c85b971b44c1c4b87af52133e2add" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/markdown-extra/zipball/8f1179e279cea6ef14066a4560b859df58acd5d8", - "reference": "8f1179e279cea6ef14066a4560b859df58acd5d8", + "url": "https://api.github.com/repos/symfony/yaml/zipball/e23292e8c07c85b971b44c1c4b87af52133e2add", + "reference": "e23292e8c07c85b971b44c1c4b87af52133e2add", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<5.4" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v6.3.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-07-31T07:08:24+00:00" + }, + { + "name": "twig/markdown-extra", + "version": "v3.7.1", + "source": { + "type": "git", + "url": "https://github.com/twigphp/markdown-extra.git", + "reference": "83dfa86a0379f784ea30bdb9c15a356b8aabf780" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/markdown-extra/zipball/83dfa86a0379f784ea30bdb9c15a356b8aabf780", + "reference": "83dfa86a0379f784ea30bdb9c15a356b8aabf780", "shasum": "" }, "require": { @@ -805,7 +939,7 @@ "league/commonmark": "^1.0|^2.0", "league/html-to-markdown": "^4.8|^5.0", "michelf/php-markdown": "^1.8|^2.0", - "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" + "symfony/phpunit-bridge": "^5.4|^6.3" }, "type": "library", "autoload": { @@ -836,7 +970,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/markdown-extra/tree/v3.6.0" + "source": "https://github.com/twigphp/markdown-extra/tree/v3.7.1" }, "funding": [ { @@ -848,20 +982,20 @@ "type": "tidelift" } ], - "time": "2023-02-09T06:45:16+00:00" + "time": "2023-07-29T15:34:56+00:00" }, { "name": "twig/twig", - "version": "v3.6.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", - "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", + "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", "shasum": "" }, "require": { @@ -871,7 +1005,7 @@ }, "require-dev": { "psr/container": "^1.0|^2.0", - "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" + "symfony/phpunit-bridge": "^5.4.9|^6.3" }, "type": "library", "autoload": { @@ -907,7 +1041,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + "source": "https://github.com/twigphp/Twig/tree/v3.7.1" }, "funding": [ { @@ -919,7 +1053,7 @@ "type": "tidelift" } ], - "time": "2023-05-03T19:06:57+00:00" + "time": "2023-08-28T11:09:02+00:00" } ], "packages-dev": [], diff --git a/www/mysql_adapter.php b/www/mysql_adapter.php new file mode 100644 index 0000000..1a4402a --- /dev/null +++ b/www/mysql_adapter.php @@ -0,0 +1,80 @@ +raw = mysqli_connect('mysql', 'root', 'example', 'dragon_fire'); + + if (!$this->raw) + { + echo 'Connection failed
'; + echo 'Error number: ' . mysqli_connect_errno() . '
'; + echo 'Error message: ' . mysqli_connect_error() . '
'; + die(); + } + } + + function _exec($qery, $argtypes, ...$args) { + $stmt = $this->raw->prepare($qery); + $stmt->bind_param($argtypes, ...$args); + $stmt->execute(); + + return $stmt->get_result(); + } + + function _prepare_post_data($post_data) { + if($post_data == null) { + $post_data = [ + "found" => false + ]; + } + else { + $post_data["found"] = true; + $post_data["post_metadata"] = json_decode($post_data["post_metadata"]); + } + + return $post_data; + } + + function get_post_by_path($post_path, $with_subposts = true) { + $qry = "SELECT * FROM posts WHERE post_path = ?"; + + $post_path = chop($post_path, '/'); + + $post_data = $this->_prepare_post_data($this->_exec($qry, "s", $post_path)->fetch_assoc()); + + if($with_subposts) { + $post_data['subposts'] = $this->get_subposts_by_path($post_path); + } + + return $post_data; + } + + function get_subposts_by_path($path) { + global $sql; + + $path = chop($path, '/'); + + $path_depth = substr_count($path, "/"); + + $qry = "SELECT post_path, post_metadata + FROM posts + WHERE (post_path LIKE CONCAT(?,'/%')) + AND post_path_depth = ? + ORDER BY post_create_time DESC + LIMIT 10"; + + $post_data = $this->_exec($qry, "si", $path, $path_depth)->fetch_all(MYSQLI_ASSOC); + + $fn = function($data) { + return $this->_prepare_post_data($data); + }; + + $post_data = array_map($fn, $post_data); + + return $post_data; + } +} + +?> diff --git a/www/router.php b/www/router.php index 091897e..38fb670 100644 --- a/www/router.php +++ b/www/router.php @@ -1,64 +1,11 @@ false - ]; - } - else { - $post_data["found"] = true; - $post_data["post_metadata"] = json_decode($post_data["post_metadata"]); - } - - return $post_data; -} - -function get_post_by_path($path) { - global $sql; - - $path = chop($path, '/'); - - $qry = "SELECT * FROM posts WHERE post_path = ?"; - - $stmt = $sql->prepare($qry); - $stmt->bind_param("s", $path); - $stmt->execute(); - - $post_data = $stmt->get_result()->fetch_assoc(); - - return process_post_data($post_data); -} - -function get_subposts($path) { - global $sql; - - $path = chop($path, '/'); - - $path_depth = substr_count($path, "/"); - - $qry = "SELECT post_path, post_metadata - FROM posts - WHERE (post_path LIKE CONCAT(?,'/%')) - AND post_path_depth = ? - ORDER BY post_create_time DESC - LIMIT 10"; - - $stmt = $sql->prepare($qry); - $stmt->bind_param("si", $path, $path_depth); - $stmt->execute(); - - $post_data = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); - - $post_data = array_map('process_post_data', $post_data); - - return $post_data; -} +$adapter = new MySQLAdapter(); //if (!$sql) // { @@ -98,11 +45,11 @@ if($_SERVER['REQUEST_URI'] == '/') { echo json_encode(get_subposts($match[1])); } elseif(true) { - $post = get_post_by_path($_SERVER['REQUEST_URI']); + $post = $adapter->get_post_by_path($_SERVER['REQUEST_URI']); echo $twig->render('about.html', [ "post" => $post, - "subposts" => get_subposts($_SERVER['REQUEST_URI']) + "subposts" => $post['subposts'] ]); } elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) {