diff --git a/docker_dev/compose.yaml b/docker_dev/compose.yaml index cbbec73..e1a79b0 100644 --- a/docker_dev/compose.yaml +++ b/docker_dev/compose.yaml @@ -9,8 +9,6 @@ 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 752d618..6130261 100644 --- a/www/composer.json +++ b/www/composer.json @@ -2,7 +2,6 @@ "require": { "twig/twig": "^3.0", "twig/markdown-extra": "^3.6", - "league/commonmark": "^2.4", - "spatie/yaml-front-matter": "^2.0" + "league/commonmark": "^2.4" } } diff --git a/www/composer.lock b/www/composer.lock index e227088..b8538ec 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": "ae80529cc2442878a51f38de1f7017a4", + "content-hash": "785c1dec442cd0287ada9cb48a31d45c", "packages": [ { "name": "dflydev/dot-access-data", @@ -83,16 +83,16 @@ }, { "name": "league/commonmark", - "version": "2.4.1", + "version": "2.4.0", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "3669d6d5f7a47a93c08ddff335e6d945481a1dd5" + "reference": "d44a24690f16b8c1808bf13b1bd54ae4c63ea048" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/3669d6d5f7a47a93c08ddff335e6d945481a1dd5", - "reference": "3669d6d5f7a47a93c08ddff335e6d945481a1dd5", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d44a24690f16b8c1808bf13b1bd54ae4c63ea048", + "reference": "d44a24690f16b8c1808bf13b1bd54ae4c63ea048", "shasum": "" }, "require": { @@ -185,7 +185,7 @@ "type": "tidelift" } ], - "time": "2023-08-30T16:55:00+00:00" + "time": "2023-03-24T15:16:10+00:00" }, { "name": "league/config", @@ -271,21 +271,21 @@ }, { "name": "nette/schema", - "version": "v1.2.5", + "version": "v1.2.3", "source": { "type": "git", "url": "https://github.com/nette/schema.git", - "reference": "0462f0166e823aad657c9224d0f849ecac1ba10a" + "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/schema/zipball/0462f0166e823aad657c9224d0f849ecac1ba10a", - "reference": "0462f0166e823aad657c9224d0f849ecac1ba10a", + "url": "https://api.github.com/repos/nette/schema/zipball/abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", + "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", "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,36 +327,35 @@ ], "support": { "issues": "https://github.com/nette/schema/issues", - "source": "https://github.com/nette/schema/tree/v1.2.5" + "source": "https://github.com/nette/schema/tree/v1.2.3" }, - "time": "2023-10-05T20:37:59+00:00" + "time": "2022-10-13T01:24:26+00:00" }, { "name": "nette/utils", - "version": "v4.0.2", + "version": "v3.2.9", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "cead6637226456b35e1175cc53797dd585d85545" + "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/cead6637226456b35e1175cc53797dd585d85545", - "reference": "cead6637226456b35e1175cc53797dd585d85545", + "url": "https://api.github.com/repos/nette/utils/zipball/c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", + "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", "shasum": "" }, "require": { - "php": ">=8.0 <8.4" + "php": ">=7.2 <8.3" }, "conflict": { - "nette/finder": "<3", - "nette/schema": "<1.2.2" + "nette/di": "<3.0.6" }, "require-dev": { "jetbrains/phpstorm-attributes": "dev-master", - "nette/tester": "^2.5", + "nette/tester": "~2.0", "phpstan/phpstan": "^1.0", - "tracy/tracy": "^2.9" + "tracy/tracy": "^2.3" }, "suggest": { "ext-gd": "to use Image", @@ -364,12 +363,13 @@ "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-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()", + "ext-xml": "to use Strings::length() etc. when mbstring is not available" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -413,9 +413,9 @@ ], "support": { "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v4.0.2" + "source": "https://github.com/nette/utils/tree/v3.2.9" }, - "time": "2023-09-19T11:58:07+00:00" + "time": "2023-01-18T03:26:20+00:00" }, { "name": "psr/event-dispatcher", @@ -467,89 +467,27 @@ }, "time": "2019-01-08T18:20:26+00:00" }, - { - "name": "spatie/yaml-front-matter", - "version": "2.0.7", - "source": { - "type": "git", - "url": "https://github.com/spatie/yaml-front-matter.git", - "reference": "f49f228994de70827ca857efffdd3bd7703aea34" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/yaml-front-matter/zipball/f49f228994de70827ca857efffdd3bd7703aea34", - "reference": "f49f228994de70827ca857efffdd3bd7703aea34", - "shasum": "" - }, - "require": { - "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", + "version": "v2.5.2", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.4-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -578,7 +516,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" }, "funding": [ { @@ -594,20 +532,20 @@ "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" + "time": "2022-01-02T09:53:40+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.28.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", - "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", "shasum": "" }, "require": { @@ -622,7 +560,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.28-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -660,7 +598,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" }, "funding": [ { @@ -676,20 +614,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.28.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "42292d99c55abe617799667f454222c54c60e229" + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", - "reference": "42292d99c55abe617799667f454222c54c60e229", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", "shasum": "" }, "require": { @@ -704,7 +642,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.28-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -743,7 +681,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" }, "funding": [ { @@ -759,20 +697,20 @@ "type": "tidelift" } ], - "time": "2023-07-28T09:04:16+00:00" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.28.0", + "version": "v1.27.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", - "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", "shasum": "" }, "require": { @@ -781,7 +719,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.28-dev" + "dev-main": "1.27-dev" }, "thanks": { "name": "symfony/polyfill", @@ -826,7 +764,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0" }, "funding": [ { @@ -842,92 +780,20 @@ "type": "tidelift" } ], - "time": "2023-01-26T09:26:14+00:00" - }, - { - "name": "symfony/yaml", - "version": "v6.3.3", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "e23292e8c07c85b971b44c1c4b87af52133e2add" - }, - "dist": { - "type": "zip", - "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" + "time": "2022-11-03T14:55:06+00:00" }, { "name": "twig/markdown-extra", - "version": "v3.7.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/twigphp/markdown-extra.git", - "reference": "83dfa86a0379f784ea30bdb9c15a356b8aabf780" + "reference": "8f1179e279cea6ef14066a4560b859df58acd5d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/markdown-extra/zipball/83dfa86a0379f784ea30bdb9c15a356b8aabf780", - "reference": "83dfa86a0379f784ea30bdb9c15a356b8aabf780", + "url": "https://api.github.com/repos/twigphp/markdown-extra/zipball/8f1179e279cea6ef14066a4560b859df58acd5d8", + "reference": "8f1179e279cea6ef14066a4560b859df58acd5d8", "shasum": "" }, "require": { @@ -939,7 +805,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": "^5.4|^6.3" + "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" }, "type": "library", "autoload": { @@ -970,7 +836,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/markdown-extra/tree/v3.7.1" + "source": "https://github.com/twigphp/markdown-extra/tree/v3.6.0" }, "funding": [ { @@ -982,20 +848,20 @@ "type": "tidelift" } ], - "time": "2023-07-29T15:34:56+00:00" + "time": "2023-02-09T06:45:16+00:00" }, { "name": "twig/twig", - "version": "v3.7.1", + "version": "v3.6.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554" + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", - "reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", "shasum": "" }, "require": { @@ -1005,7 +871,7 @@ }, "require-dev": { "psr/container": "^1.0|^2.0", - "symfony/phpunit-bridge": "^5.4.9|^6.3" + "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" }, "type": "library", "autoload": { @@ -1041,7 +907,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.7.1" + "source": "https://github.com/twigphp/Twig/tree/v3.6.0" }, "funding": [ { @@ -1053,7 +919,7 @@ "type": "tidelift" } ], - "time": "2023-08-28T11:09:02+00:00" + "time": "2023-05-03T19:06:57+00:00" } ], "packages-dev": [], diff --git a/www/mysql_adapter.php b/www/mysql_adapter.php deleted file mode 100644 index 1a4402a..0000000 --- a/www/mysql_adapter.php +++ /dev/null @@ -1,80 +0,0 @@ -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 38fb670..091897e 100644 --- a/www/router.php +++ b/www/router.php @@ -1,11 +1,64 @@ 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; +} //if (!$sql) // { @@ -45,11 +98,11 @@ if($_SERVER['REQUEST_URI'] == '/') { echo json_encode(get_subposts($match[1])); } elseif(true) { - $post = $adapter->get_post_by_path($_SERVER['REQUEST_URI']); + $post = get_post_by_path($_SERVER['REQUEST_URI']); echo $twig->render('about.html', [ "post" => $post, - "subposts" => $post['subposts'] + "subposts" => get_subposts($_SERVER['REQUEST_URI']) ]); } elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) {