From 93909c74441677a4ae7038ccb5755970bdc81496 Mon Sep 17 00:00:00 2001 From: Jill Stingray Date: Tue, 16 Jun 2020 15:38:32 +0300 Subject: [PATCH] Add knowledgebase --- Web/Presenters/AboutPresenter.php | 6 +- Web/Presenters/SupportPresenter.php | 30 +++++++++- Web/Presenters/templates/Notes/Create.xml | 2 +- .../Support/KnowledgeBaseArticle.xml | 11 ++++ Web/routes.yml | 2 + composer.json | 3 +- composer.lock | 58 ++++++++++++++++++- data/knowledgebase/notes.ru.textile | 23 ++++++++ data/knowledgebase/notes.textile | 24 ++++++++ data/knowledgebase/privacy.ru.textile | 3 + data/knowledgebase/privacy.textile | 3 + data/knowledgebase/rules.ru.textile | 3 + data/knowledgebase/rules.textile | 3 + 13 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 Web/Presenters/templates/Support/KnowledgeBaseArticle.xml create mode 100644 data/knowledgebase/notes.ru.textile create mode 100644 data/knowledgebase/notes.textile create mode 100644 data/knowledgebase/privacy.ru.textile create mode 100644 data/knowledgebase/privacy.textile create mode 100644 data/knowledgebase/rules.ru.textile create mode 100644 data/knowledgebase/rules.textile diff --git a/Web/Presenters/AboutPresenter.php b/Web/Presenters/AboutPresenter.php index 00d035ed..b8b1bbe5 100644 --- a/Web/Presenters/AboutPresenter.php +++ b/Web/Presenters/AboutPresenter.php @@ -22,7 +22,7 @@ final class AboutPresenter extends OpenVKPresenter function renderRules(): void { - $this->template->rules = file_get_contents(__DIR__ . "/../../data/rules.xhtml"); + $this->pass("openvk!Support->knowledgeBaseArticle", "rules"); } function renderHelp(): void @@ -38,7 +38,9 @@ final class AboutPresenter extends OpenVKPresenter {} function renderPrivacy(): void - {} + { + $this->pass("openvk!Support->knowledgeBaseArticle", "privacy"); + } function renderVersion(): void { diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 255455d0..9c6ba41c 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -9,8 +9,8 @@ use openvk\Web\Models\Repositories\TicketComments; use openvk\Web\Models\RowModel; use Nette\Database\Table\ActiveRow; use Chandler\Database\DatabaseConnection; -use Composer\Factory; -use Composer\IO\NullIO; +use Chandler\Session\Session; +use Netcarver\Textile; final class SupportPresenter extends OpenVKPresenter { @@ -188,4 +188,30 @@ final class SupportPresenter extends OpenVKPresenter } } + + function renderKnowledgeBaseArticle(string $name): void + { + $lang = Session::i()->get("lang", "ru"); + $base = OPENVK_ROOT . "/data/knowledgebase"; + if(file_exists("$base/$name.$lang.textile")) + $file = "$base/$name.$lang.textile"; + else if(file_exists("$base/$name.textile")) + $file = "$base/$name.textile"; + else + $this->notFound(); + + $lines = file($file); + if(!preg_match("%^OpenVK-KB-Heading: (.+)$%", $lines[0], $matches)) { + $heading = "Article $name"; + } else { + $heading = $matches[1]; + array_shift($lines); + } + + $content = implode("\r\n", $lines); + + $parser = new Textile\Parser; + $this->template->heading = $heading; + $this->template->content = $parser->parse($content); + } } diff --git a/Web/Presenters/templates/Notes/Create.xml b/Web/Presenters/templates/Notes/Create.xml index cf5b3a16..2518c085 100644 --- a/Web/Presenters/templates/Notes/Create.xml +++ b/Web/Presenters/templates/Notes/Create.xml @@ -13,7 +13,7 @@
-

Кое-что из (X)HTML поддерживается.

+

Кое-что из (X)HTML поддерживается.

diff --git a/Web/Presenters/templates/Support/KnowledgeBaseArticle.xml b/Web/Presenters/templates/Support/KnowledgeBaseArticle.xml new file mode 100644 index 00000000..fe163ead --- /dev/null +++ b/Web/Presenters/templates/Support/KnowledgeBaseArticle.xml @@ -0,0 +1,11 @@ +{extends "../@layout.xml"} + +{block title}{$heading}{/block} + +{block header} + {$heading} +{/block} + +{block content} + {$content|noescape} +{/block} diff --git a/Web/routes.yml b/Web/routes.yml index c64d6b61..ca74dd44 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -25,6 +25,8 @@ routes: handler: "About->language" - url: "/donate" handler: "About->donate" + - url: "/kb/{slug}" + handler: "Support->knowledgeBaseArticle" - url: "/about:{?!productName}" handler: "About->version" placeholders: diff --git a/composer.json b/composer.json index f17368c8..b7cf6341 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "james-heinrich/getid3": "^1.9@dev", "rybakit/msgpack": "dev-master", "wapmorgan-alter/cab-archive": "0.0.7.1", - "wapmorgan/binary-stream": "dev-master" + "wapmorgan/binary-stream": "dev-master", + "netcarver/textile": "^3.7@dev" }, "minimum-stability": "dev" } diff --git a/composer.lock b/composer.lock index daa1e23e..552772fb 100644 --- a/composer.lock +++ b/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": "61c3f4330692983a999c84dee65684a2", + "content-hash": "cd5b144aeb47f3c9f8b3d4cf09cfad22", "packages": [ { "name": "guzzlehttp/guzzle", @@ -304,6 +304,59 @@ ], "time": "2019-04-20T16:06:47+00:00" }, + { + "name": "netcarver/textile", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/textile/php-textile.git", + "reference": "1651585b54bfaa8def9aff28c1b08437475791a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/textile/php-textile/zipball/1651585b54bfaa8def9aff28c1b08437475791a9", + "reference": "1651585b54bfaa8def9aff28c1b08437475791a9", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "php-coveralls/php-coveralls": "2.1.*", + "phpunit/phpunit": "5.7.*", + "squizlabs/php_codesniffer": "3.*", + "symfony/yaml": "2.4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-4": { + "Netcarver\\Textile\\": "src/Netcarver/Textile/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Textile markup language parser", + "homepage": "https://github.com/textile/php-textile", + "keywords": [ + "document", + "format", + "html", + "language", + "markup", + "parser", + "php-textile", + "plaintext", + "textile" + ], + "time": "2020-01-08T21:17:22+00:00" + }, { "name": "p3k/emoji-detector", "version": "0.2.1", @@ -696,7 +749,8 @@ "zadarma/user-api-v1": 20, "james-heinrich/getid3": 20, "rybakit/msgpack": 20, - "wapmorgan/binary-stream": 20 + "wapmorgan/binary-stream": 20, + "netcarver/textile": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/data/knowledgebase/notes.ru.textile b/data/knowledgebase/notes.ru.textile new file mode 100644 index 00000000..4296cdab --- /dev/null +++ b/data/knowledgebase/notes.ru.textile @@ -0,0 +1,23 @@ +OpenVK-KB-Heading: Справка по редактированию заметок + +Вики-разметка OpenVK это тоже самое, что и XHTML1.0 Transitional. Единственное изменение заключается в том, что мы убрали некоторые теги, которые могут принести вред OpenVK или не нужны. +Список разрешённых тегов: +* Все заголовки 3-6 уровней (h3-h6) +* Параграфы (<p>) +* Форматирование текста (<i>, <b>, <del>) +* <sup>, <sub>, <ins> +* Таблицы и всё, что с ними связано +* Изображения и ссылки (<a>, <img>) +* Списки (и <ol> и <ul>) +* Перевод строки и горизонтальная линия (hr) +* Цитаты (<blockquote> и <cite>) +* <acronym> +Обратите внимание, источником изображения могут быть только файлы из OpenVK. Это ограничение не распространяется на ссылки, где href может быть любой (в целях безопасности наших пользователей, ссылка будет автоматически заменена на редирект через away.php) +Вы могли заметить, что в списке разрешённых тегов нету <style>, но ничего страшного, вы можете применять аттрибут style к тегам <div> и <img>. В перечень поддерживаемых свойств CSS входят: +* float +* height +* width +* max-height +* max-width +* font-weight +Обратите внимание на то, что поддерживаются только значения в пикселях. diff --git a/data/knowledgebase/notes.textile b/data/knowledgebase/notes.textile new file mode 100644 index 00000000..d937f989 --- /dev/null +++ b/data/knowledgebase/notes.textile @@ -0,0 +1,24 @@ +OpenVK-KB-Heading: Editing notes + +OpenVK wiki-markup is basically XHTML1.0 Transitional. The only difference is that we removed tags that are not needed or may harm OpenVK and it's users. +Allowed tags: +* All headers from level 3 to 6 (h3-h6) +* Paragraphs (<p>) +* Text formatting (<i>, <b>, <del>) +* <sup>, <sub>, <ins> +* Everything related to tables +* Links and images (<a>, <img>) +* Lists (и <ol> и <ul>) +* Line feed and horizontal rule (hr) +* Blockquotes (<blockquote> и <cite>) +* <acronym> + +*Please note*: images can't have sourcemap and their source must be a file that is hosted on this OpenVK instance. This restrictions does not apply to links. Links can link to everything (except for data: and javascript: pseudoprotocols). They will be derefered though. +You may also have noticed, that <style> is note in the allowlist, however, we do support styling <div> and <img> tags using style attribute. This CSS properties are allowed: +* float +* height +* width +* max-height +* max-width +* font-weight +If property is a size property it can only accept pixels as value (no %, pt, pc, em, rem, vw or vh). diff --git a/data/knowledgebase/privacy.ru.textile b/data/knowledgebase/privacy.ru.textile new file mode 100644 index 00000000..6baefd9c --- /dev/null +++ b/data/knowledgebase/privacy.ru.textile @@ -0,0 +1,3 @@ +OpenVK-KB-Heading: Политика Конфиденциальности + +Пример политики конфиденциальности diff --git a/data/knowledgebase/privacy.textile b/data/knowledgebase/privacy.textile new file mode 100644 index 00000000..70b637b6 --- /dev/null +++ b/data/knowledgebase/privacy.textile @@ -0,0 +1,3 @@ +OpenVK-KB-Heading: Privacy Policy + +Example pricacy policy diff --git a/data/knowledgebase/rules.ru.textile b/data/knowledgebase/rules.ru.textile new file mode 100644 index 00000000..5f3ebb81 --- /dev/null +++ b/data/knowledgebase/rules.ru.textile @@ -0,0 +1,3 @@ +OpenVK-KB-Heading: Правила + +Пример правил diff --git a/data/knowledgebase/rules.textile b/data/knowledgebase/rules.textile new file mode 100644 index 00000000..dacf1de9 --- /dev/null +++ b/data/knowledgebase/rules.textile @@ -0,0 +1,3 @@ +OpenVK-KB-Heading: Rules + +Sample rules