commit 5e5f659777738e3da3b1b1e2a58f09b8434e14bd Author: Chicory Date: Sat Jul 13 19:19:16 2024 +0300 upload diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..67db858 --- /dev/null +++ b/LICENSE @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..2c5cb6e --- /dev/null +++ b/NOTICE @@ -0,0 +1,213 @@ +/*----------------------------------------------------------------------------- + + Roboto font + Copyright: Google Inc. 2015 + URL: https://github.com/googlefonts/roboto + License: http://www.apache.org/licenses/LICENSE-2.0 + +-----------------------------------------------------------------------------*/ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +/*----------------------------------------------------------------------------- + + Parsedown + Copyright: Emanuil Rusev http://erusev.com + URL: http://parsedown.org + License: The MIT License (MIT) + +-----------------------------------------------------------------------------*/ + +The MIT License (MIT) + +Copyright (c) 2013-2018 Emanuil Rusev, erusev.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2936a8b --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +## orblog (0.1.1) [Deprecated] +Simple blog for hidden services (like tor / i2p) with markdown support. + +## Comment +It was written in 2 evenings in 2020 to complete one small personal task. There will be no updating or development. +!**Use only at your own risk!** + +## Features +* Without JavaScript. +* Posts with markdown support. +* Comments with markdown support. +* Categories. +* View posts by tags. +* RSS feed + +## System requirements +* PHP 7.3 + +* GDLib +* SQLite3 + +## Run +``` +git clone https://code.fossee.net/chicory/orblog-legacy.git +cd orblog +php -S 127.0.0.1:8000 +``` +**Admin panel:** +``` +hostname/?view=admin +password: changeme +``` + +## Installation +* Edit config file (./config.php). +* Set permissions. + * For ./private/data 775 + * For ./private/data/data.sqlite 664 + * For other files 644 +* Deny access to ./private directory at web server. +* Open your_domain/?view=admin in web browser. + +## Screenshots + +### Main page +![Main page](./screeshots/main.png) +### Comment +![Comment](./screeshots/comment.png) +### Amin panel post adding +![Amin panel post adding](./screeshots/admin_add_post.png) +### Amin panel categories management +![Amin panel categories management](./screeshots/admin_category.png) +### Amin panel comments moderation +![Amin panel comments moderation](./screeshots/admin_comments.png) \ No newline at end of file diff --git a/captcha.php b/captcha.php new file mode 100644 index 0000000..3ece290 --- /dev/null +++ b/captcha.php @@ -0,0 +1,24 @@ +https://code.fossee.net/chicory/orblog-legacy'); + +// Copyright. + define('COPY', 'orblog 2020'); + +// Max. posts per page. + define('MAXPOSTS', 10); + +// Allow comments. + define('COMMENTS', true); + +// Antiflood. + define('ANTIFLOOD', 30); + diff --git a/index.php b/index.php new file mode 100644 index 0000000..e05c64b --- /dev/null +++ b/index.php @@ -0,0 +1,40 @@ + query('SELECT * FROM `categories` + ORDER BY `sort` ASC'); +if (!empty($_GET['view'])) { + $view = preg_replace("/[^a-zA-Z_\-\d]/ui", "", $_GET['view']); + + if (file_exists('private/pages/'.$view.'.php')) { + include 'private/pages/'.$view.'.php'; + } else { + include 'private/pages/404.php'; + } +} else { + include 'private/pages/index.php'; +} + +$_TPL['category_list'] = view_categories($category_dump); +include_template('footer'); diff --git a/private/data/data.sqlite b/private/data/data.sqlite new file mode 100644 index 0000000..1cb9f3e Binary files /dev/null and b/private/data/data.sqlite differ diff --git a/private/languages/en.php b/private/languages/en.php new file mode 100644 index 0000000..1ad9ccc --- /dev/null +++ b/private/languages/en.php @@ -0,0 +1,63 @@ + 'later', + 'next_page' => 'earlier', + + 'categories' => 'Categories', + 'without_cat' => 'Without category', + 'all_posts' => 'All posts', + 'comments' => 'Comments', + 'add_comment' => 'Add a comment', + + 'comment_text' => 'Comment text. Markdown is supported.', + 'by_guest' => 'by Guest', + 'by_admin' => 'by Administrator', + + 'input_captcha' => 'Enter captcha', + + 'submit' => 'Submit', + + 'empty_category' => 'There\'s nothing here', + + 'post_title' => 'Title', + 'post_desc' => 'Short description', + 'post_text' => 'Full text', + 'post_tags' => 'Tags separated by spaces', + 'tags' => 'Tags', + + 'error_404' => 'Page not found', + 'error_404_text' => '

The server could not find page.

Alternatively, you can visit the home page.', + 'error_sign_in' => 'Invalid captcha or password.', + 'flood_err' => 'You can add comments no more than once every '.ANTIFLOOD.' sec.', + 'comment_err' => 'Invalid captcha or empty comment form.', + + 'admin' => 'Admin panel', + 'input_pass' => 'Enter password', + 'sign_in' => 'Sign in', + 'sign_out' => 'Sign out', + 'add_post' => 'Add post', + 'edit_post' => 'Edit post', + + 'add_category' => 'New category', + 'sort_category' => 'Sort ID (integer, default: 0)', + 'category_name' => 'Category name', + + 'edit' => 'edit', + 'delete' => 'delete', + 'goto_post' => 'goto', + + 'stats' => 'Statistics', + 'all_posts_count' => 'Posts count', + 'all_comm_count' => 'Comments count', +]; diff --git a/private/languages/ru.php b/private/languages/ru.php new file mode 100644 index 0000000..cee36e1 --- /dev/null +++ b/private/languages/ru.php @@ -0,0 +1,63 @@ + 'позже', + 'next_page' => 'ранее', + + 'categories' => 'Категории', + 'without_cat' => 'Без категории', + 'all_posts' => 'Все сообщения', + 'comments' => 'Комментарии', + 'add_comment' => 'Добавить комментарий', + + 'comment_text' => 'Текст комментраия. Поддерживается markdown.', + 'by_guest' => 'Гость', + 'by_admin' => 'Администратор', + + 'input_captcha' => 'Введите капчу', + + 'submit' => 'Отправить', + + 'empty_category' => 'Здесь ничего нет.', + + 'post_title' => 'Заголовок', + 'post_desc' => 'Краткое описание', + 'post_text' => 'Полный текст', + 'post_tags' => 'Тэги через пробел', + 'tags' => 'Тэги', + + 'error_404' => 'Страница не найдена', + 'error_404_text' => '

Сервер не нашел страницу.

Попробуйте посетить домашнюю страницу.', + 'error_sign_in' => 'Неверная капча или пароль.', + 'flood_err' => 'Выможете добавлять сообщения раз в '.ANTIFLOOD.' сек.', + 'comment_err' => 'Неверная капча или пустое сообщение.', + + 'admin' => 'Админ панель', + 'input_pass' => 'Ввведите пароль', + 'sign_in' => 'Войти', + 'sign_out' => 'Выйти', + 'add_post' => 'Добавить сообщение', + 'edit_post' => 'Редактировать сообщение', + 'edit' => 'изменить', + + 'add_category' => 'Новая категория', + 'sort_category' => 'ID сортировки (число, по умолчанию: 0)', + 'category_name' => 'Название категории', + + 'delete' => 'удалить', + 'goto_post' => 'перейти', + + 'stats' => 'Статистика', + 'all_posts_count' => 'Всего сообщений', + 'all_comm_count' => 'Всего комментариев', +]; diff --git a/private/libs/functions.php b/private/libs/functions.php new file mode 100644 index 0000000..461363f --- /dev/null +++ b/private/libs/functions.php @@ -0,0 +1,130 @@ + text($string); + + return $string; +} + + +function category_name($category) +{ + global $sqlite; + + $query = 'SELECT `name` FROM `categories` WHERE id = '.$category; + $name = $sqlite -> querySingle($query); + + return $name; +} + +function select_categories($result) +{ + while ($cat = $result -> fetchArray()) + { + $return.= ' + '; + } + + return $return; +} + +function view_categories($result) +{ + while ($cat = $result -> fetchArray()) + { + $return.= ''.$cat['name'].' + '; + } + + return $return; +} + +function view_edit_categories($result) +{ + global $_LANG, $_TPL; + while ($cat = $result -> fetchArray()) + { + $_TPL['id'] = $cat['id']; + $_TPL['sort'] = $cat['sort']; + $_TPL['name'] = $cat['name']; + + include_template('edit_category'); + } +} + +function view_posts($result) +{ + global $_LANG, $_TPL, $parser; + while ($row = $result -> fetchArray()) + { + if(!$row['time']) return 0; + + $_TPL['id'] = $row['id']; + $_TPL['time'] = date("d.m.y", $row['time']); + $_TPL['title'] = $row['title']; + $_TPL['desc'] = parser($row['desc']); + $_TPL['text'] = parser($row['text']); + $_TPL['tags'] = separate_tags($row['tags']); + $_TPL['comments'] = $row['comments']; + + include_template('post_short'); + } +} + +function separate_tags($string) +{ + $tags = explode(' ', $string); + foreach ($tags as &$tag) + if(!empty($tag)) + $return.= '@'.$tag.' '; + + return $return; +} + +function view_comments($result) +{ + global $_LANG, $_TPL, $parser; + while ($row = $result -> fetchArray()) + { + if(!$row['time']) return 0; + + $_TPL['post_id'] = 0; + + if($_TPL['id'] != $row['id']) $_TPL['post_id'] = $row['id']; + $_TPL['pid'] = $row['id']; + $_TPL['cid'] = $row['cid']; + $_TPL['time'] = date("d.m.y h:i", $row['time']); + $_TPL['text'] = parser($row['text']); + $_TPL['admin'] = $row['admin']; + + include_template('comment'); + } +} + +function gen_captcha() +{ + $letters = '23456789abcdefghjkmnpqrstvwxyz'; + $return = substr(str_shuffle($letters), 0, 6); + + return $return; +} + +function include_template($template) +{ + global $_LANG, $_TPL, $parser; + include 'private/templates/'.$template.'.php'; +} diff --git a/private/libs/parsedown.php b/private/libs/parsedown.php new file mode 100644 index 0000000..49b1cae --- /dev/null +++ b/private/libs/parsedown.php @@ -0,0 +1,1995 @@ +textElements($text); + + # convert to markup + $markup = $this->elements($Elements); + + # trim line breaks + $markup = trim($markup, "\n"); + + return $markup; + } + + protected function textElements($text) + { + # make sure no definitions are set + $this->DefinitionData = array(); + + # standardize line breaks + $text = str_replace(array("\r\n", "\r"), "\n", $text); + + # remove surrounding line breaks + $text = trim($text, "\n"); + + # split text into lines + $lines = explode("\n", $text); + + # iterate through lines to identify blocks + return $this->linesElements($lines); + } + + # + # Setters + # + + function setBreaksEnabled($breaksEnabled) + { + $this->breaksEnabled = $breaksEnabled; + + return $this; + } + + protected $breaksEnabled; + + function setMarkupEscaped($markupEscaped) + { + $this->markupEscaped = $markupEscaped; + + return $this; + } + + protected $markupEscaped; + + function setUrlsLinked($urlsLinked) + { + $this->urlsLinked = $urlsLinked; + + return $this; + } + + protected $urlsLinked = true; + + function setSafeMode($safeMode) + { + $this->safeMode = (bool) $safeMode; + + return $this; + } + + protected $safeMode; + + function setStrictMode($strictMode) + { + $this->strictMode = (bool) $strictMode; + + return $this; + } + + protected $strictMode; + + protected $safeLinksWhitelist = array( + 'http://', + 'https://', + 'ftp://', + 'ftps://', + 'mailto:', + 'tel:', + 'data:image/png;base64,', + 'data:image/gif;base64,', + 'data:image/jpeg;base64,', + 'irc:', + 'ircs:', + 'git:', + 'ssh:', + 'news:', + 'steam:', + 'xmpp:', + ); + + # + # Lines + # + + protected $BlockTypes = array( + '#' => array('Header'), + '*' => array('Rule', 'List'), + '+' => array('List'), + '-' => array('SetextHeader', 'Table', 'Rule', 'List'), + '0' => array('List'), + '1' => array('List'), + '2' => array('List'), + '3' => array('List'), + '4' => array('List'), + '5' => array('List'), + '6' => array('List'), + '7' => array('List'), + '8' => array('List'), + '9' => array('List'), + ':' => array('Table'), + '<' => array('Comment', 'Markup'), + '=' => array('SetextHeader'), + '>' => array('Quote'), + '[' => array('Reference'), + '_' => array('Rule'), + '`' => array('FencedCode'), + '|' => array('Table'), + '~' => array('FencedCode'), + ); + + # ~ + + protected $unmarkedBlockTypes = array( + 'Code', + ); + + # + # Blocks + # + + protected function lines(array $lines) + { + return $this->elements($this->linesElements($lines)); + } + + protected function linesElements(array $lines) + { + $Elements = array(); + $CurrentBlock = null; + + foreach ($lines as $line) + { + if (chop($line) === '') + { + if (isset($CurrentBlock)) + { + $CurrentBlock['interrupted'] = (isset($CurrentBlock['interrupted']) + ? $CurrentBlock['interrupted'] + 1 : 1 + ); + } + + continue; + } + + while (($beforeTab = strstr($line, "\t", true)) !== false) + { + $shortage = 4 - mb_strlen($beforeTab, 'utf-8') % 4; + + $line = $beforeTab + . str_repeat(' ', $shortage) + . substr($line, strlen($beforeTab) + 1) + ; + } + + $indent = strspn($line, ' '); + + $text = $indent > 0 ? substr($line, $indent) : $line; + + # ~ + + $Line = array('body' => $line, 'indent' => $indent, 'text' => $text); + + # ~ + + if (isset($CurrentBlock['continuable'])) + { + $methodName = 'block' . $CurrentBlock['type'] . 'Continue'; + $Block = $this->$methodName($Line, $CurrentBlock); + + if (isset($Block)) + { + $CurrentBlock = $Block; + + continue; + } + else + { + if ($this->isBlockCompletable($CurrentBlock['type'])) + { + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; + $CurrentBlock = $this->$methodName($CurrentBlock); + } + } + } + + # ~ + + $marker = $text[0]; + + # ~ + + $blockTypes = $this->unmarkedBlockTypes; + + if (isset($this->BlockTypes[$marker])) + { + foreach ($this->BlockTypes[$marker] as $blockType) + { + $blockTypes []= $blockType; + } + } + + # + # ~ + + foreach ($blockTypes as $blockType) + { + $Block = $this->{"block$blockType"}($Line, $CurrentBlock); + + if (isset($Block)) + { + $Block['type'] = $blockType; + + if ( ! isset($Block['identified'])) + { + if (isset($CurrentBlock)) + { + $Elements[] = $this->extractElement($CurrentBlock); + } + + $Block['identified'] = true; + } + + if ($this->isBlockContinuable($blockType)) + { + $Block['continuable'] = true; + } + + $CurrentBlock = $Block; + + continue 2; + } + } + + # ~ + + if (isset($CurrentBlock) and $CurrentBlock['type'] === 'Paragraph') + { + $Block = $this->paragraphContinue($Line, $CurrentBlock); + } + + if (isset($Block)) + { + $CurrentBlock = $Block; + } + else + { + if (isset($CurrentBlock)) + { + $Elements[] = $this->extractElement($CurrentBlock); + } + + $CurrentBlock = $this->paragraph($Line); + + $CurrentBlock['identified'] = true; + } + } + + # ~ + + if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) + { + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; + $CurrentBlock = $this->$methodName($CurrentBlock); + } + + # ~ + + if (isset($CurrentBlock)) + { + $Elements[] = $this->extractElement($CurrentBlock); + } + + # ~ + + return $Elements; + } + + protected function extractElement(array $Component) + { + if ( ! isset($Component['element'])) + { + if (isset($Component['markup'])) + { + $Component['element'] = array('rawHtml' => $Component['markup']); + } + elseif (isset($Component['hidden'])) + { + $Component['element'] = array(); + } + } + + return $Component['element']; + } + + protected function isBlockContinuable($Type) + { + return method_exists($this, 'block' . $Type . 'Continue'); + } + + protected function isBlockCompletable($Type) + { + return method_exists($this, 'block' . $Type . 'Complete'); + } + + # + # Code + + protected function blockCode($Line, $Block = null) + { + if (isset($Block) and $Block['type'] === 'Paragraph' and ! isset($Block['interrupted'])) + { + return; + } + + if ($Line['indent'] >= 4) + { + $text = substr($Line['body'], 4); + + $Block = array( + 'element' => array( + 'name' => 'pre', + 'element' => array( + 'name' => 'code', + 'text' => $text, + ), + ), + ); + + return $Block; + } + } + + protected function blockCodeContinue($Line, $Block) + { + if ($Line['indent'] >= 4) + { + if (isset($Block['interrupted'])) + { + $Block['element']['element']['text'] .= str_repeat("\n", $Block['interrupted']); + + unset($Block['interrupted']); + } + + $Block['element']['element']['text'] .= "\n"; + + $text = substr($Line['body'], 4); + + $Block['element']['element']['text'] .= $text; + + return $Block; + } + } + + protected function blockCodeComplete($Block) + { + return $Block; + } + + # + # Comment + + protected function blockComment($Line) + { + if ($this->markupEscaped or $this->safeMode) + { + return; + } + + if (strpos($Line['text'], '') !== false) + { + $Block['closed'] = true; + } + + return $Block; + } + } + + protected function blockCommentContinue($Line, array $Block) + { + if (isset($Block['closed'])) + { + return; + } + + $Block['element']['rawHtml'] .= "\n" . $Line['body']; + + if (strpos($Line['text'], '-->') !== false) + { + $Block['closed'] = true; + } + + return $Block; + } + + # + # Fenced Code + + protected function blockFencedCode($Line) + { + $marker = $Line['text'][0]; + + $openerLength = strspn($Line['text'], $marker); + + if ($openerLength < 3) + { + return; + } + + $infostring = trim(substr($Line['text'], $openerLength), "\t "); + + if (strpos($infostring, '`') !== false) + { + return; + } + + $Element = array( + 'name' => 'code', + 'text' => '', + ); + + if ($infostring !== '') + { + /** + * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes + * Every HTML element may have a class attribute specified. + * The attribute, if specified, must have a value that is a set + * of space-separated tokens representing the various classes + * that the element belongs to. + * [...] + * The space characters, for the purposes of this specification, + * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), + * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and + * U+000D CARRIAGE RETURN (CR). + */ + $language = substr($infostring, 0, strcspn($infostring, " \t\n\f\r")); + + $Element['attributes'] = array('class' => "language-$language"); + } + + $Block = array( + 'char' => $marker, + 'openerLength' => $openerLength, + 'element' => array( + 'name' => 'pre', + 'element' => $Element, + ), + ); + + return $Block; + } + + protected function blockFencedCodeContinue($Line, $Block) + { + if (isset($Block['complete'])) + { + return; + } + + if (isset($Block['interrupted'])) + { + $Block['element']['element']['text'] .= str_repeat("\n", $Block['interrupted']); + + unset($Block['interrupted']); + } + + if (($len = strspn($Line['text'], $Block['char'])) >= $Block['openerLength'] + and chop(substr($Line['text'], $len), ' ') === '' + ) { + $Block['element']['element']['text'] = substr($Block['element']['element']['text'], 1); + + $Block['complete'] = true; + + return $Block; + } + + $Block['element']['element']['text'] .= "\n" . $Line['body']; + + return $Block; + } + + protected function blockFencedCodeComplete($Block) + { + return $Block; + } + + # + # Header + + protected function blockHeader($Line) + { + $level = strspn($Line['text'], '#'); + + if ($level > 6) + { + return; + } + + $text = trim($Line['text'], '#'); + + if ($this->strictMode and isset($text[0]) and $text[0] !== ' ') + { + return; + } + + $text = trim($text, ' '); + + $Block = array( + 'element' => array( + 'name' => 'h' . $level, + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $text, + 'destination' => 'elements', + ) + ), + ); + + return $Block; + } + + # + # List + + protected function blockList($Line, array $CurrentBlock = null) + { + list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]{1,9}+[.\)]'); + + if (preg_match('/^('.$pattern.'([ ]++|$))(.*+)/', $Line['text'], $matches)) + { + $contentIndent = strlen($matches[2]); + + if ($contentIndent >= 5) + { + $contentIndent -= 1; + $matches[1] = substr($matches[1], 0, -$contentIndent); + $matches[3] = str_repeat(' ', $contentIndent) . $matches[3]; + } + elseif ($contentIndent === 0) + { + $matches[1] .= ' '; + } + + $markerWithoutWhitespace = strstr($matches[1], ' ', true); + + $Block = array( + 'indent' => $Line['indent'], + 'pattern' => $pattern, + 'data' => array( + 'type' => $name, + 'marker' => $matches[1], + 'markerType' => ($name === 'ul' ? $markerWithoutWhitespace : substr($markerWithoutWhitespace, -1)), + ), + 'element' => array( + 'name' => $name, + 'elements' => array(), + ), + ); + $Block['data']['markerTypeRegex'] = preg_quote($Block['data']['markerType'], '/'); + + if ($name === 'ol') + { + $listStart = ltrim(strstr($matches[1], $Block['data']['markerType'], true), '0') ?: '0'; + + if ($listStart !== '1') + { + if ( + isset($CurrentBlock) + and $CurrentBlock['type'] === 'Paragraph' + and ! isset($CurrentBlock['interrupted']) + ) { + return; + } + + $Block['element']['attributes'] = array('start' => $listStart); + } + } + + $Block['li'] = array( + 'name' => 'li', + 'handler' => array( + 'function' => 'li', + 'argument' => !empty($matches[3]) ? array($matches[3]) : array(), + 'destination' => 'elements' + ) + ); + + $Block['element']['elements'] []= & $Block['li']; + + return $Block; + } + } + + protected function blockListContinue($Line, array $Block) + { + if (isset($Block['interrupted']) and empty($Block['li']['handler']['argument'])) + { + return null; + } + + $requiredIndent = ($Block['indent'] + strlen($Block['data']['marker'])); + + if ($Line['indent'] < $requiredIndent + and ( + ( + $Block['data']['type'] === 'ol' + and preg_match('/^[0-9]++'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', $Line['text'], $matches) + ) or ( + $Block['data']['type'] === 'ul' + and preg_match('/^'.$Block['data']['markerTypeRegex'].'(?:[ ]++(.*)|$)/', $Line['text'], $matches) + ) + ) + ) { + if (isset($Block['interrupted'])) + { + $Block['li']['handler']['argument'] []= ''; + + $Block['loose'] = true; + + unset($Block['interrupted']); + } + + unset($Block['li']); + + $text = isset($matches[1]) ? $matches[1] : ''; + + $Block['indent'] = $Line['indent']; + + $Block['li'] = array( + 'name' => 'li', + 'handler' => array( + 'function' => 'li', + 'argument' => array($text), + 'destination' => 'elements' + ) + ); + + $Block['element']['elements'] []= & $Block['li']; + + return $Block; + } + elseif ($Line['indent'] < $requiredIndent and $this->blockList($Line)) + { + return null; + } + + if ($Line['text'][0] === '[' and $this->blockReference($Line)) + { + return $Block; + } + + if ($Line['indent'] >= $requiredIndent) + { + if (isset($Block['interrupted'])) + { + $Block['li']['handler']['argument'] []= ''; + + $Block['loose'] = true; + + unset($Block['interrupted']); + } + + $text = substr($Line['body'], $requiredIndent); + + $Block['li']['handler']['argument'] []= $text; + + return $Block; + } + + if ( ! isset($Block['interrupted'])) + { + $text = preg_replace('/^[ ]{0,'.$requiredIndent.'}+/', '', $Line['body']); + + $Block['li']['handler']['argument'] []= $text; + + return $Block; + } + } + + protected function blockListComplete(array $Block) + { + if (isset($Block['loose'])) + { + foreach ($Block['element']['elements'] as &$li) + { + if (end($li['handler']['argument']) !== '') + { + $li['handler']['argument'] []= ''; + } + } + } + + return $Block; + } + + # + # Quote + + protected function blockQuote($Line) + { + if (preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches)) + { + $Block = array( + 'element' => array( + 'name' => 'blockquote', + 'handler' => array( + 'function' => 'linesElements', + 'argument' => (array) $matches[1], + 'destination' => 'elements', + ) + ), + ); + + return $Block; + } + } + + protected function blockQuoteContinue($Line, array $Block) + { + if (isset($Block['interrupted'])) + { + return; + } + + if ($Line['text'][0] === '>' and preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches)) + { + $Block['element']['handler']['argument'] []= $matches[1]; + + return $Block; + } + + if ( ! isset($Block['interrupted'])) + { + $Block['element']['handler']['argument'] []= $Line['text']; + + return $Block; + } + } + + # + # Rule + + protected function blockRule($Line) + { + $marker = $Line['text'][0]; + + if (substr_count($Line['text'], $marker) >= 3 and chop($Line['text'], " $marker") === '') + { + $Block = array( + 'element' => array( + 'name' => 'hr', + ), + ); + + return $Block; + } + } + + # + # Setext + + protected function blockSetextHeader($Line, array $Block = null) + { + if ( ! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) + { + return; + } + + if ($Line['indent'] < 4 and chop(chop($Line['text'], ' '), $Line['text'][0]) === '') + { + $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; + + return $Block; + } + } + + # + # Markup + + protected function blockMarkup($Line) + { + if ($this->markupEscaped or $this->safeMode) + { + return; + } + + if (preg_match('/^<[\/]?+(\w*)(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+(\/)?>/', $Line['text'], $matches)) + { + $element = strtolower($matches[1]); + + if (in_array($element, $this->textLevelElements)) + { + return; + } + + $Block = array( + 'name' => $matches[1], + 'element' => array( + 'rawHtml' => $Line['text'], + 'autobreak' => true, + ), + ); + + return $Block; + } + } + + protected function blockMarkupContinue($Line, array $Block) + { + if (isset($Block['closed']) or isset($Block['interrupted'])) + { + return; + } + + $Block['element']['rawHtml'] .= "\n" . $Line['body']; + + return $Block; + } + + # + # Reference + + protected function blockReference($Line) + { + if (strpos($Line['text'], ']') !== false + and preg_match('/^\[(.+?)\]:[ ]*+?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/', $Line['text'], $matches) + ) { + $id = strtolower($matches[1]); + + $Data = array( + 'url' => $matches[2], + 'title' => isset($matches[3]) ? $matches[3] : null, + ); + + $this->DefinitionData['Reference'][$id] = $Data; + + $Block = array( + 'element' => array(), + ); + + return $Block; + } + } + + # + # Table + + protected function blockTable($Line, array $Block = null) + { + if ( ! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted'])) + { + return; + } + + if ( + strpos($Block['element']['handler']['argument'], '|') === false + and strpos($Line['text'], '|') === false + and strpos($Line['text'], ':') === false + or strpos($Block['element']['handler']['argument'], "\n") !== false + ) { + return; + } + + if (chop($Line['text'], ' -:|') !== '') + { + return; + } + + $alignments = array(); + + $divider = $Line['text']; + + $divider = trim($divider); + $divider = trim($divider, '|'); + + $dividerCells = explode('|', $divider); + + foreach ($dividerCells as $dividerCell) + { + $dividerCell = trim($dividerCell); + + if ($dividerCell === '') + { + return; + } + + $alignment = null; + + if ($dividerCell[0] === ':') + { + $alignment = 'left'; + } + + if (substr($dividerCell, - 1) === ':') + { + $alignment = $alignment === 'left' ? 'center' : 'right'; + } + + $alignments []= $alignment; + } + + # ~ + + $HeaderElements = array(); + + $header = $Block['element']['handler']['argument']; + + $header = trim($header); + $header = trim($header, '|'); + + $headerCells = explode('|', $header); + + if (count($headerCells) !== count($alignments)) + { + return; + } + + foreach ($headerCells as $index => $headerCell) + { + $headerCell = trim($headerCell); + + $HeaderElement = array( + 'name' => 'th', + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $headerCell, + 'destination' => 'elements', + ) + ); + + if (isset($alignments[$index])) + { + $alignment = $alignments[$index]; + + $HeaderElement['attributes'] = array( + 'style' => "text-align: $alignment;", + ); + } + + $HeaderElements []= $HeaderElement; + } + + # ~ + + $Block = array( + 'alignments' => $alignments, + 'identified' => true, + 'element' => array( + 'name' => 'table', + 'elements' => array(), + ), + ); + + $Block['element']['elements'] []= array( + 'name' => 'thead', + ); + + $Block['element']['elements'] []= array( + 'name' => 'tbody', + 'elements' => array(), + ); + + $Block['element']['elements'][0]['elements'] []= array( + 'name' => 'tr', + 'elements' => $HeaderElements, + ); + + return $Block; + } + + protected function blockTableContinue($Line, array $Block) + { + if (isset($Block['interrupted'])) + { + return; + } + + if (count($Block['alignments']) === 1 or $Line['text'][0] === '|' or strpos($Line['text'], '|')) + { + $Elements = array(); + + $row = $Line['text']; + + $row = trim($row); + $row = trim($row, '|'); + + preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]++`|`)++/', $row, $matches); + + $cells = array_slice($matches[0], 0, count($Block['alignments'])); + + foreach ($cells as $index => $cell) + { + $cell = trim($cell); + + $Element = array( + 'name' => 'td', + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $cell, + 'destination' => 'elements', + ) + ); + + if (isset($Block['alignments'][$index])) + { + $Element['attributes'] = array( + 'style' => 'text-align: ' . $Block['alignments'][$index] . ';', + ); + } + + $Elements []= $Element; + } + + $Element = array( + 'name' => 'tr', + 'elements' => $Elements, + ); + + $Block['element']['elements'][1]['elements'] []= $Element; + + return $Block; + } + } + + # + # ~ + # + + protected function paragraph($Line) + { + return array( + 'type' => 'Paragraph', + 'element' => array( + 'name' => 'p', + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $Line['text'], + 'destination' => 'elements', + ), + ), + ); + } + + protected function paragraphContinue($Line, array $Block) + { + if (isset($Block['interrupted'])) + { + return; + } + + $Block['element']['handler']['argument'] .= "\n".$Line['text']; + + return $Block; + } + + # + # Inline Elements + # + + protected $InlineTypes = array( + '!' => array('Image'), + '&' => array('SpecialCharacter'), + '*' => array('Emphasis'), + ':' => array('Url'), + '<' => array('UrlTag', 'EmailTag', 'Markup'), + '[' => array('Link'), + '_' => array('Emphasis'), + '`' => array('Code'), + '~' => array('Strikethrough'), + '\\' => array('EscapeSequence'), + ); + + # ~ + + protected $inlineMarkerList = '!*_&[:<`~\\'; + + # + # ~ + # + + public function line($text, $nonNestables = array()) + { + return $this->elements($this->lineElements($text, $nonNestables)); + } + + protected function lineElements($text, $nonNestables = array()) + { + # standardize line breaks + $text = str_replace(array("\r\n", "\r"), "\n", $text); + + $Elements = array(); + + $nonNestables = (empty($nonNestables) + ? array() + : array_combine($nonNestables, $nonNestables) + ); + + # $excerpt is based on the first occurrence of a marker + + while ($excerpt = strpbrk($text, $this->inlineMarkerList)) + { + $marker = $excerpt[0]; + + $markerPosition = strlen($text) - strlen($excerpt); + + $Excerpt = array('text' => $excerpt, 'context' => $text); + + foreach ($this->InlineTypes[$marker] as $inlineType) + { + # check to see if the current inline type is nestable in the current context + + if (isset($nonNestables[$inlineType])) + { + continue; + } + + $Inline = $this->{"inline$inlineType"}($Excerpt); + + if ( ! isset($Inline)) + { + continue; + } + + # makes sure that the inline belongs to "our" marker + + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) + { + continue; + } + + # sets a default inline position + + if ( ! isset($Inline['position'])) + { + $Inline['position'] = $markerPosition; + } + + # cause the new element to 'inherit' our non nestables + + + $Inline['element']['nonNestables'] = isset($Inline['element']['nonNestables']) + ? array_merge($Inline['element']['nonNestables'], $nonNestables) + : $nonNestables + ; + + # the text that comes before the inline + $unmarkedText = substr($text, 0, $Inline['position']); + + # compile the unmarked text + $InlineText = $this->inlineText($unmarkedText); + $Elements[] = $InlineText['element']; + + # compile the inline + $Elements[] = $this->extractElement($Inline); + + # remove the examined text + $text = substr($text, $Inline['position'] + $Inline['extent']); + + continue 2; + } + + # the marker does not belong to an inline + + $unmarkedText = substr($text, 0, $markerPosition + 1); + + $InlineText = $this->inlineText($unmarkedText); + $Elements[] = $InlineText['element']; + + $text = substr($text, $markerPosition + 1); + } + + $InlineText = $this->inlineText($text); + $Elements[] = $InlineText['element']; + + foreach ($Elements as &$Element) + { + if ( ! isset($Element['autobreak'])) + { + $Element['autobreak'] = false; + } + } + + return $Elements; + } + + # + # ~ + # + + protected function inlineText($text) + { + $Inline = array( + 'extent' => strlen($text), + 'element' => array(), + ); + + $Inline['element']['elements'] = self::pregReplaceElements( + $this->breaksEnabled ? '/[ ]*+\n/' : '/(?:[ ]*+\\\\|[ ]{2,}+)\n/', + array( + array('name' => 'br'), + array('text' => "\n"), + ), + $text + ); + + return $Inline; + } + + protected function inlineCode($Excerpt) + { + $marker = $Excerpt['text'][0]; + + if (preg_match('/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(? strlen($matches[0]), + 'element' => array( + 'name' => 'code', + 'text' => $text, + ), + ); + } + } + + protected function inlineEmailTag($Excerpt) + { + $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'; + + $commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' + . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*'; + + if (strpos($Excerpt['text'], '>') !== false + and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches) + ){ + $url = $matches[1]; + + if ( ! isset($matches[2])) + { + $url = "mailto:$url"; + } + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $matches[1], + 'attributes' => array( + 'href' => $url, + ), + ), + ); + } + } + + protected function inlineEmphasis($Excerpt) + { + if ( ! isset($Excerpt['text'][1])) + { + return; + } + + $marker = $Excerpt['text'][0]; + + if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) + { + $emphasis = 'strong'; + } + elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) + { + $emphasis = 'em'; + } + else + { + return; + } + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => $emphasis, + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $matches[1], + 'destination' => 'elements', + ) + ), + ); + } + + protected function inlineEscapeSequence($Excerpt) + { + if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) + { + return array( + 'element' => array('rawHtml' => $Excerpt['text'][1]), + 'extent' => 2, + ); + } + } + + protected function inlineImage($Excerpt) + { + if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') + { + return; + } + + $Excerpt['text']= substr($Excerpt['text'], 1); + + $Link = $this->inlineLink($Excerpt); + + if ($Link === null) + { + return; + } + + $Inline = array( + 'extent' => $Link['extent'] + 1, + 'element' => array( + 'name' => 'img', + 'attributes' => array( + 'src' => $Link['element']['attributes']['href'], + 'alt' => $Link['element']['handler']['argument'], + ), + 'autobreak' => true, + ), + ); + + $Inline['element']['attributes'] += $Link['element']['attributes']; + + unset($Inline['element']['attributes']['href']); + + return $Inline; + } + + protected function inlineLink($Excerpt) + { + $Element = array( + 'name' => 'a', + 'handler' => array( + 'function' => 'lineElements', + 'argument' => null, + 'destination' => 'elements', + ), + 'nonNestables' => array('Url', 'Link'), + 'attributes' => array( + 'href' => null, + 'title' => null, + ), + ); + + $extent = 0; + + $remainder = $Excerpt['text']; + + if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) + { + $Element['handler']['argument'] = $matches[1]; + + $extent += strlen($matches[0]); + + $remainder = substr($remainder, $extent); + } + else + { + return; + } + + if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*+"|\'[^\']*+\'))?\s*+[)]/', $remainder, $matches)) + { + $Element['attributes']['href'] = $matches[1]; + + if (isset($matches[2])) + { + $Element['attributes']['title'] = substr($matches[2], 1, - 1); + } + + $extent += strlen($matches[0]); + } + else + { + if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) + { + $definition = strlen($matches[1]) ? $matches[1] : $Element['handler']['argument']; + $definition = strtolower($definition); + + $extent += strlen($matches[0]); + } + else + { + $definition = strtolower($Element['handler']['argument']); + } + + if ( ! isset($this->DefinitionData['Reference'][$definition])) + { + return; + } + + $Definition = $this->DefinitionData['Reference'][$definition]; + + $Element['attributes']['href'] = $Definition['url']; + $Element['attributes']['title'] = $Definition['title']; + } + + return array( + 'extent' => $extent, + 'element' => $Element, + ); + } + + protected function inlineMarkup($Excerpt) + { + if ($this->markupEscaped or $this->safeMode or strpos($Excerpt['text'], '>') === false) + { + return; + } + + if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt['text'], $matches)) + { + return array( + 'element' => array('rawHtml' => $matches[0]), + 'extent' => strlen($matches[0]), + ); + } + + if ($Excerpt['text'][1] === '!' and preg_match('/^/s', $Excerpt['text'], $matches)) + { + return array( + 'element' => array('rawHtml' => $matches[0]), + 'extent' => strlen($matches[0]), + ); + } + + if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w[\w-]*+(?:[ ]*+'.$this->regexHtmlAttribute.')*+[ ]*+\/?>/s', $Excerpt['text'], $matches)) + { + return array( + 'element' => array('rawHtml' => $matches[0]), + 'extent' => strlen($matches[0]), + ); + } + } + + protected function inlineSpecialCharacter($Excerpt) + { + if (substr($Excerpt['text'], 1, 1) !== ' ' and strpos($Excerpt['text'], ';') !== false + and preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches) + ) { + return array( + 'element' => array('rawHtml' => '&' . $matches[1] . ';'), + 'extent' => strlen($matches[0]), + ); + } + + return; + } + + protected function inlineStrikethrough($Excerpt) + { + if ( ! isset($Excerpt['text'][1])) + { + return; + } + + if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) + { + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'del', + 'handler' => array( + 'function' => 'lineElements', + 'argument' => $matches[1], + 'destination' => 'elements', + ) + ), + ); + } + } + + protected function inlineUrl($Excerpt) + { + if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') + { + return; + } + + if (strpos($Excerpt['context'], 'http') !== false + and preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE) + ) { + $url = $matches[0][0]; + + $Inline = array( + 'extent' => strlen($matches[0][0]), + 'position' => $matches[0][1], + 'element' => array( + 'name' => 'a', + 'text' => $url, + 'attributes' => array( + 'href' => $url, + ), + ), + ); + + return $Inline; + } + } + + protected function inlineUrlTag($Excerpt) + { + if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt['text'], $matches)) + { + $url = $matches[1]; + + return array( + 'extent' => strlen($matches[0]), + 'element' => array( + 'name' => 'a', + 'text' => $url, + 'attributes' => array( + 'href' => $url, + ), + ), + ); + } + } + + # ~ + + protected function unmarkedText($text) + { + $Inline = $this->inlineText($text); + return $this->element($Inline['element']); + } + + # + # Handlers + # + + protected function handle(array $Element) + { + if (isset($Element['handler'])) + { + if (!isset($Element['nonNestables'])) + { + $Element['nonNestables'] = array(); + } + + if (is_string($Element['handler'])) + { + $function = $Element['handler']; + $argument = $Element['text']; + unset($Element['text']); + $destination = 'rawHtml'; + } + else + { + $function = $Element['handler']['function']; + $argument = $Element['handler']['argument']; + $destination = $Element['handler']['destination']; + } + + $Element[$destination] = $this->{$function}($argument, $Element['nonNestables']); + + if ($destination === 'handler') + { + $Element = $this->handle($Element); + } + + unset($Element['handler']); + } + + return $Element; + } + + protected function handleElementRecursive(array $Element) + { + return $this->elementApplyRecursive(array($this, 'handle'), $Element); + } + + protected function handleElementsRecursive(array $Elements) + { + return $this->elementsApplyRecursive(array($this, 'handle'), $Elements); + } + + protected function elementApplyRecursive($closure, array $Element) + { + $Element = call_user_func($closure, $Element); + + if (isset($Element['elements'])) + { + $Element['elements'] = $this->elementsApplyRecursive($closure, $Element['elements']); + } + elseif (isset($Element['element'])) + { + $Element['element'] = $this->elementApplyRecursive($closure, $Element['element']); + } + + return $Element; + } + + protected function elementApplyRecursiveDepthFirst($closure, array $Element) + { + if (isset($Element['elements'])) + { + $Element['elements'] = $this->elementsApplyRecursiveDepthFirst($closure, $Element['elements']); + } + elseif (isset($Element['element'])) + { + $Element['element'] = $this->elementsApplyRecursiveDepthFirst($closure, $Element['element']); + } + + $Element = call_user_func($closure, $Element); + + return $Element; + } + + protected function elementsApplyRecursive($closure, array $Elements) + { + foreach ($Elements as &$Element) + { + $Element = $this->elementApplyRecursive($closure, $Element); + } + + return $Elements; + } + + protected function elementsApplyRecursiveDepthFirst($closure, array $Elements) + { + foreach ($Elements as &$Element) + { + $Element = $this->elementApplyRecursiveDepthFirst($closure, $Element); + } + + return $Elements; + } + + protected function element(array $Element) + { + if ($this->safeMode) + { + $Element = $this->sanitiseElement($Element); + } + + # identity map if element has no handler + $Element = $this->handle($Element); + + $hasName = isset($Element['name']); + + $markup = ''; + + if ($hasName) + { + $markup .= '<' . $Element['name']; + + if (isset($Element['attributes'])) + { + foreach ($Element['attributes'] as $name => $value) + { + if ($value === null) + { + continue; + } + + $markup .= " $name=\"".self::escape($value).'"'; + } + } + } + + $permitRawHtml = false; + + if (isset($Element['text'])) + { + $text = $Element['text']; + } + // very strongly consider an alternative if you're writing an + // extension + elseif (isset($Element['rawHtml'])) + { + $text = $Element['rawHtml']; + + $allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode']; + $permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode; + } + + $hasContent = isset($text) || isset($Element['element']) || isset($Element['elements']); + + if ($hasContent) + { + $markup .= $hasName ? '>' : ''; + + if (isset($Element['elements'])) + { + $markup .= $this->elements($Element['elements']); + } + elseif (isset($Element['element'])) + { + $markup .= $this->element($Element['element']); + } + else + { + if (!$permitRawHtml) + { + $markup .= self::escape($text, true); + } + else + { + $markup .= $text; + } + } + + $markup .= $hasName ? '' : ''; + } + elseif ($hasName) + { + $markup .= ' />'; + } + + return $markup; + } + + protected function elements(array $Elements) + { + $markup = ''; + + $autoBreak = true; + + foreach ($Elements as $Element) + { + if (empty($Element)) + { + continue; + } + + $autoBreakNext = (isset($Element['autobreak']) + ? $Element['autobreak'] : isset($Element['name']) + ); + // (autobreak === false) covers both sides of an element + $autoBreak = !$autoBreak ? $autoBreak : $autoBreakNext; + + $markup .= ($autoBreak ? "\n" : '') . $this->element($Element); + $autoBreak = $autoBreakNext; + } + + $markup .= $autoBreak ? "\n" : ''; + + return $markup; + } + + # ~ + + protected function li($lines) + { + $Elements = $this->linesElements($lines); + + if ( ! in_array('', $lines) + and isset($Elements[0]) and isset($Elements[0]['name']) + and $Elements[0]['name'] === 'p' + ) { + unset($Elements[0]['name']); + } + + return $Elements; + } + + # + # AST Convenience + # + + /** + * Replace occurrences $regexp with $Elements in $text. Return an array of + * elements representing the replacement. + */ + protected static function pregReplaceElements($regexp, $Elements, $text) + { + $newElements = array(); + + while (preg_match($regexp, $text, $matches, PREG_OFFSET_CAPTURE)) + { + $offset = $matches[0][1]; + $before = substr($text, 0, $offset); + $after = substr($text, $offset + strlen($matches[0][0])); + + $newElements[] = array('text' => $before); + + foreach ($Elements as $Element) + { + $newElements[] = $Element; + } + + $text = $after; + } + + $newElements[] = array('text' => $text); + + return $newElements; + } + + # + # Deprecated Methods + # + + function parse($text) + { + $markup = $this->text($text); + + return $markup; + } + + protected function sanitiseElement(array $Element) + { + static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; + static $safeUrlNameToAtt = array( + 'a' => 'href', + 'img' => 'src', + ); + + if ( ! isset($Element['name'])) + { + unset($Element['attributes']); + return $Element; + } + + if (isset($safeUrlNameToAtt[$Element['name']])) + { + $Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]); + } + + if ( ! empty($Element['attributes'])) + { + foreach ($Element['attributes'] as $att => $val) + { + # filter out badly parsed attribute + if ( ! preg_match($goodAttribute, $att)) + { + unset($Element['attributes'][$att]); + } + # dump onevent attribute + elseif (self::striAtStart($att, 'on')) + { + unset($Element['attributes'][$att]); + } + } + } + + return $Element; + } + + protected function filterUnsafeUrlInAttribute(array $Element, $attribute) + { + foreach ($this->safeLinksWhitelist as $scheme) + { + if (self::striAtStart($Element['attributes'][$attribute], $scheme)) + { + return $Element; + } + } + + $Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]); + + return $Element; + } + + # + # Static Methods + # + + protected static function escape($text, $allowQuotes = false) + { + return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8'); + } + + protected static function striAtStart($string, $needle) + { + $len = strlen($needle); + + if ($len > strlen($string)) + { + return false; + } + else + { + return strtolower(substr($string, 0, $len)) === strtolower($needle); + } + } + + static function instance($name = 'default') + { + if (isset(self::$instances[$name])) + { + return self::$instances[$name]; + } + + $instance = new static(); + + self::$instances[$name] = $instance; + + return $instance; + } + + private static $instances = array(); + + # + # Fields + # + + protected $DefinitionData; + + # + # Read-Only + + protected $specialCharacters = array( + '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', '~' + ); + + protected $StrongRegex = array( + '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*+[*])+?)[*]{2}(?![*])/s', + '_' => '/^__((?:\\\\_|[^_]|_[^_]*+_)+?)__(?!_)/us', + ); + + protected $EmRegex = array( + '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', + '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', + ); + + protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+'; + + protected $voidElements = array( + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', + ); + + protected $textLevelElements = array( + 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', + 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', + 'i', 'rp', 'del', 'code', 'strike', 'marquee', + 'q', 'rt', 'ins', 'font', 'strong', + 's', 'tt', 'kbd', 'mark', + 'u', 'xm', 'sub', 'nobr', + 'sup', 'ruby', + 'var', 'span', + 'wbr', 'time', + ); +} diff --git a/private/pages/404.php b/private/pages/404.php new file mode 100644 index 0000000..19e9784 --- /dev/null +++ b/private/pages/404.php @@ -0,0 +1,16 @@ + prepare($query); + + $stmt -> bindValue(':time', time(), SQLITE3_INTEGER); + $stmt -> bindValue(':cat', $_POST['category'], SQLITE3_INTEGER); + $stmt -> bindValue(':title', $_POST['title'], SQLITE3_TEXT); + $stmt -> bindValue(':desc', $_POST['desc'], SQLITE3_TEXT); + $stmt -> bindValue(':text', $_POST['text'], SQLITE3_TEXT); + $stmt -> bindValue(':tags', $_POST['tags'], SQLITE3_TEXT); + + $stmt->execute(); + + header('Location:'.URL); exit; +} + +if($_GET['action'] == 'edit_post' and $_SESSION['admin']) // Edit post +{ + $query = 'SELECT COUNT(*) FROM `comments` WHERE id = '.$_GET['post']; + $count = $sqlite -> querySingle($query); + + $query = 'UPDATE `posts` SET + category = :cat, + title = :title, + desc = :desc, + text = :text, + tags = :tags, + comments = :count + WHERE id = :id'; + + $stmt = $sqlite -> prepare($query); + + $stmt -> bindValue(':cat', $_POST['category'], SQLITE3_INTEGER); + $stmt -> bindValue(':title', $_POST['title'], SQLITE3_TEXT); + $stmt -> bindValue(':desc', $_POST['desc'], SQLITE3_TEXT); + $stmt -> bindValue(':text', $_POST['text'], SQLITE3_TEXT); + $stmt -> bindValue(':tags', $_POST['tags'], SQLITE3_TEXT); + $stmt -> bindValue(':count', $count, SQLITE3_INTEGER); + $stmt -> bindValue(':id', $_GET['post'], SQLITE3_INTEGER); + + $stmt->execute(); + + header('Location:'.URL.'/index.php?view=post&id='.$_GET['post']); exit; +} + +if($_GET['action'] == 'delete_post' and $_SESSION['admin']) // Del post +{ + $query = 'DELETE FROM `posts` WHERE id = '.$_GET['id']; + $sqlite -> exec($query); + + $query = 'DELETE FROM `comments` WHERE id = '.$_GET['id']; + $sqlite -> exec($query); + + header('Location:'.URL); exit; +} + +if($_GET['action'] == 'add_category' and $_SESSION['admin']) // Add category +{ + if (!$_POST['sort']) $_POST['sort'] = 0; + $query = 'INSERT INTO `categories` + (sort, name) + VALUES + ('.$_POST['sort'].', + "'.$_POST['name'].'")'; + + $sqlite -> exec($query); + header('Location:'.URL.'index.php?view=admin&page=categories'); exit; +} + +if($_GET['action'] == 'edit_category' and $_SESSION['admin']) // Edit category +{ + if($_POST['delete']) + { + $query = 'DELETE FROM `categories` WHERE id = '.$_GET['id']; + $sqlite -> exec($query); + + header('Location:'.URL.'index.php?view=admin&page=categories'); exit; + } + $query = 'UPDATE `categories` SET + sort = '.$_POST['sort'].', + name = "'.$_POST['name'].'" + WHERE id = '.$_GET['id']; + $sqlite -> exec($query); + + header('Location:'.URL.'index.php?view=admin&page=categories'); exit; +} + +if($_GET['action'] == 'delete_comment' and $_SESSION['admin']) // Del comment +{ + $query = 'DELETE FROM `comments` WHERE cid = '.$_GET['id']; + $sqlite -> exec($query); + + $query = 'SELECT COUNT(*) FROM `comments` WHERE id = '.$_GET['post']; + $count = $sqlite -> querySingle($query); + + $query = 'UPDATE `posts` SET comments = '.$count.' + WHERE id = '.$_GET['post']; + $sqlite -> exec($query); + + header('Location:'.$_SERVER['HTTP_REFERER']); exit; +} + +/*-- Pages ----------------------------------------------------------------*/ +$_TPL['title'] = $_LANG['admin'].' | '.TITLE; +include_template('header'); + +if(!$_SESSION['admin']) // Login +{ + $_SESSION['captcha'] = gen_captcha(); + include_template('sign_in'); +} +else if($_GET['page'] == 'add_post') // Add post +{ + $_TPL['category_select'] = select_categories($category_dump); + + include_template('admin_header'); + include_template('add_post'); +} +else if($_GET['page'] == 'categories') // Categories +{ + include_template('admin_header'); + include_template('categories_header'); + + view_edit_categories($category_dump); + + include_template('categories'); +} +else if($_GET['page'] == 'comments') // Comments +{ + $parser = new Parsedown(); + $parser -> setSafeMode(true); + + $query = 'SELECT * FROM `comments` LIMIT 50'; + $result = $sqlite -> query($query); + + include_template('admin_header'); + include_template('comments'); + view_comments($result); +} +else if($_GET['page'] == 'edit_post') // Edit post +{ + $result = $sqlite -> query('SELECT * FROM `posts` WHERE id='.$_GET['id']); + $post_data = $result -> fetchArray(SQLITE3_ASSOC); + + $_TPL['id'] = $post_data['id']; + $_TPL['category'] = $post_data['category']; + $_TPL['title'] = $post_data['title']; + $_TPL['title'] = $post_data['title']; + $_TPL['desc'] = $post_data['desc']; + $_TPL['text'] = $post_data['text']; + $_TPL['tags'] = $post_data['tags']; + + if($post_data['category']) + $_TPL['category_name'] = category_name($post_data['category']); + else $_TPL['category_name'] = $_LANG['without_cat']; + + $_TPL['category_select'] = select_categories($category_dump); + + include_template('admin_header'); + include_template('edit_post'); +} +else // Admin inddex +{ + $query = 'SELECT COUNT(*) FROM `posts`'; + $_TPL['posts'] = $sqlite -> querySingle($query); + + $query = 'SELECT COUNT(*) FROM `comments`'; + $_TPL['comments'] = $sqlite -> querySingle($query); + + include_template('admin_header'); + include_template('admin_index'); +} diff --git a/private/pages/index.php b/private/pages/index.php new file mode 100644 index 0000000..2aa9ed8 --- /dev/null +++ b/private/pages/index.php @@ -0,0 +1,100 @@ + querySingle($query); + +/*-- Pagination -----------------------------------------------------------*/ +if($count) +{ + if(!$_GET['page']) $page = 0; + else $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT); + + $start = $page * MAXPOSTS; + + if($page < 0 or ($page * MAXPOSTS) >= $count ) + { + header('Location:'.URL.'index.php?view=404'); exit; + } +} +/*-- Get posts and set pagination links -----------------------------------*/ +if(!isset($_GET['category']) and !isset($_GET['tag'])) +{ + $query = 'SELECT * FROM `posts` + ORDER BY `time` DESC + LIMIT '.$start.', '.MAXPOSTS; + + $_TPL['title'] = TITLE; + + if(($page - 1) >= 0) + $_TPL['prev_page'] = 'index.php?page='.($page - 1); + if((($page + 1) * MAXPOSTS) < $count) + $_TPL['next_page'] = 'index.php?page='.($page + 1); +} +else if(isset($cat)) // Categories +{ + $query = 'SELECT * FROM `posts` WHERE category = '.$cat.' + ORDER BY `time` DESC LIMIT '.$start.', '.MAXPOSTS; + + $_TPL['title'] = $name.' | '.TITLE; + if($cat == 0) $_TPL['title'] = $_LANG['without_cat'].' | '.TITLE; + + if(($page - 1) >= 0) + $_TPL['prev_page'] = 'index.php?category='.$cat.'&page='.($page - 1); + if((($page + 1) * MAXPOSTS) < $count) + $_TPL['next_page'] = 'index.php?category='.$cat.'&page='.($page + 1); +} +else if(isset($tag)) // Tags +{ + $query = 'SELECT * FROM `posts` WHERE tags LIKE "%'.$tag.'%" + ORDER BY `time` DESC LIMIT '.$start.', '.MAXPOSTS; + + $_TPL['title'] = '@'.$tag.' | '.TITLE; + + if(($page - 1) >= 0) + $_TPL['prev_page'] = 'index.php?tag='.$tag.'&page='.($page - 1); + if((($page + 1) * MAXPOSTS) < $count) + $_TPL['next_page'] = 'index.php?tag='.$tag.'&page='.($page + 1); +} +else +{ + header('Location:'.URL.'index.php'); exit; +} + +$result = $sqlite -> query($query); + +/*-- View posts -----------------------------------------------------------*/ +$parser = new Parsedown(); + +include_template('header'); + +if($count) view_posts($result); +else include_template('index_empty'); + +include_template('index_footer'); diff --git a/private/pages/post.php b/private/pages/post.php new file mode 100644 index 0000000..f54b787 --- /dev/null +++ b/private/pages/post.php @@ -0,0 +1,98 @@ + query('SELECT * FROM `posts` WHERE id='.$id); +$post_data = $result -> fetchArray(SQLITE3_ASSOC); + +if(!$post_data['time']) +{ + header('Location:'.URL.'index.php?view=404'); exit; +} + +$_TPL['title'] = $post_data['title'].' | '.TITLE; + +include_template('header'); + +/*-- View post contents ----------------------------------------------------*/ +$parser = new Parsedown(); + +$_TPL['id'] = $id; +$_TPL['time'] = date("d.m.y", $post_data['time']); +$_TPL['title'] = $post_data['title']; +$_TPL['desc'] = parser($post_data['desc']); +$_TPL['text'] = parser($post_data['text']); +$_TPL['tags'] = separate_tags($post_data['tags']); +$_TPL['comments'] = $post_data['comments']; + +include_template('post'); + +/*-- Add a comment --------------------------------------------------------*/ +if($_GET['action'] == 'add_comment' && COMMENTS) +{ + $post_url = URL.'index.php?view=post&id='.$_TPL['id']; + + if(empty($_POST['text']) or $_POST['captcha'] != $_SESSION['captcha']) + { + header('Location:'.$post_url.'&error=comment_err#add'); exit; + } + + if($_SESSION['flood'] and (time() - $_SESSION['flood']) < ANTIFLOOD) + { + header('Location:'.$post_url.'&error=antiflood#add'); exit; + } + + $_SESSION['flood'] = time(); + + $query = 'INSERT INTO `comments` (id, time, text, admin) + VALUES (:id, :time, :text, :admin)'; + + $stmt = $sqlite -> prepare($query); + + $stmt -> bindValue(':id', $id, SQLITE3_INTEGER); + $stmt -> bindValue(':time', time(), SQLITE3_INTEGER); + $stmt -> bindValue(':text', $_POST['text'], SQLITE3_TEXT); + $stmt -> bindValue(':admin', $_SESSION['admin'], SQLITE3_INTEGER); + + + $stmt->execute(); + + $query = 'UPDATE `posts` SET comments = '.($post_data['comments']+1).' + WHERE id = '.$id; + $sqlite -> exec($query); +} +/*-- View comments --------------------------------------------------------*/ + +$parser -> setSafeMode(true); + +$query = 'SELECT * FROM `comments` WHERE id='.$id; +$result = $sqlite -> query($query); + +view_comments($result); + +/*-- Comment form ---------------------------------------------------------*/ +if(COMMENTS) +{ + $_SESSION['captcha'] = gen_captcha(); + + if ($_GET['error'] == "comment_err") $_TPL['error'] = $_LANG['comment_err']; + if ($_GET['error'] == "antiflood") $_TPL['error'] = $_LANG['flood_err']; + + include_template('comment_form'); +} diff --git a/private/pages/rss.php b/private/pages/rss.php new file mode 100644 index 0000000..d9b34dc --- /dev/null +++ b/private/pages/rss.php @@ -0,0 +1,46 @@ +'; +?> + + + <?=TITLE?> + + + querySingle($query); +$query = 'SELECT * FROM `posts` ORDER BY `time` DESC LIMIT 0, '.MAXPOSTS; +$result = $sqlite -> query($query); + +if($count) +{ + $parser = new Parsedown(); + $parser -> setSafeMode(true); + + while ($row = $result -> fetchArray()) + { + if(!$row['time']) exit; + + $_TPL['id'] = $row['id']; + $_TPL['title'] = $row['title']; + $_TPL['desc'] = parser($row['desc']); + + include_template('rss'); + } +} +?> + + + +
+
+ +
+
+
+
+ diff --git a/private/templates/add_post.php b/private/templates/add_post.php new file mode 100644 index 0000000..187ffac --- /dev/null +++ b/private/templates/add_post.php @@ -0,0 +1,24 @@ + +

+
+ + + + + + +
diff --git a/private/templates/admin_header.php b/private/templates/admin_header.php new file mode 100644 index 0000000..f7560ea --- /dev/null +++ b/private/templates/admin_header.php @@ -0,0 +1,27 @@ + +
+
+ +
+
+ +
+
+
+
+
+ | + | + +
diff --git a/private/templates/admin_index.php b/private/templates/admin_index.php new file mode 100644 index 0000000..70042a4 --- /dev/null +++ b/private/templates/admin_index.php @@ -0,0 +1,18 @@ + +

+
    +
  • :
  • +
  • :
  • +
+ diff --git a/private/templates/categories.php b/private/templates/categories.php new file mode 100644 index 0000000..beb0fb8 --- /dev/null +++ b/private/templates/categories.php @@ -0,0 +1,26 @@ + +
+
+
+
+ +
+
+
+
+ + + +
+
diff --git a/private/templates/categories_header.php b/private/templates/categories_header.php new file mode 100644 index 0000000..0c6c8ac --- /dev/null +++ b/private/templates/categories_header.php @@ -0,0 +1,13 @@ + +

diff --git a/private/templates/comment.php b/private/templates/comment.php new file mode 100644 index 0000000..a9748de --- /dev/null +++ b/private/templates/comment.php @@ -0,0 +1,35 @@ + +
+
+ +
+
+ + + + + + + [ ] + + + [ ] + +
+
+
+
+ +
+ diff --git a/private/templates/comment_form.php b/private/templates/comment_form.php new file mode 100644 index 0000000..985bd5a --- /dev/null +++ b/private/templates/comment_form.php @@ -0,0 +1,24 @@ + +

+ +
+ +
+ +
+ + captcha
+ + +
diff --git a/private/templates/comments.php b/private/templates/comments.php new file mode 100644 index 0000000..be3b28a --- /dev/null +++ b/private/templates/comments.php @@ -0,0 +1,14 @@ + +

+ diff --git a/private/templates/edit_category.php b/private/templates/edit_category.php new file mode 100644 index 0000000..5656da3 --- /dev/null +++ b/private/templates/edit_category.php @@ -0,0 +1,18 @@ + +
+ + + + +
diff --git a/private/templates/edit_post.php b/private/templates/edit_post.php new file mode 100644 index 0000000..45049d9 --- /dev/null +++ b/private/templates/edit_post.php @@ -0,0 +1,27 @@ + +

+
+ + + + + + +
+ diff --git a/private/templates/footer.php b/private/templates/footer.php new file mode 100644 index 0000000..ae458df --- /dev/null +++ b/private/templates/footer.php @@ -0,0 +1,48 @@ + +
+ + +
+
+ + + diff --git a/private/templates/header.php b/private/templates/header.php new file mode 100644 index 0000000..b98c030 --- /dev/null +++ b/private/templates/header.php @@ -0,0 +1,36 @@ + + + + + + + + + <?=$_TPL['title']?> + + +
+
+ +
+
+ +
+
+
+
+
+
diff --git a/private/templates/index_empty.php b/private/templates/index_empty.php new file mode 100644 index 0000000..97d222e --- /dev/null +++ b/private/templates/index_empty.php @@ -0,0 +1,17 @@ + +
+

+
+

+
diff --git a/private/templates/index_footer.php b/private/templates/index_footer.php new file mode 100644 index 0000000..b767f5d --- /dev/null +++ b/private/templates/index_footer.php @@ -0,0 +1,22 @@ + +
+
+ + ⤽    + + +    ⤼ + +
+ diff --git a/private/templates/post.php b/private/templates/post.php new file mode 100644 index 0000000..dc73cf9 --- /dev/null +++ b/private/templates/post.php @@ -0,0 +1,33 @@ + +
+
+ +
+
+ + [ ] + + ( ) +
+
+
+
+

+ +
+ + :
+ +
+
diff --git a/private/templates/post_short.php b/private/templates/post_short.php new file mode 100644 index 0000000..4ef59c8 --- /dev/null +++ b/private/templates/post_short.php @@ -0,0 +1,32 @@ + +
+
+ +
+
+ + [ ] + + ( ) +
+
+
+
+

+ + + :
+ +
+
diff --git a/private/templates/rss.php b/private/templates/rss.php new file mode 100644 index 0000000..ac8b775 --- /dev/null +++ b/private/templates/rss.php @@ -0,0 +1,19 @@ + + + <?=$_TPL['title']?> + index.php?view=post&id= + + ]]> + + diff --git a/private/templates/sign_in.php b/private/templates/sign_in.php new file mode 100644 index 0000000..09b91d5 --- /dev/null +++ b/private/templates/sign_in.php @@ -0,0 +1,34 @@ + +
+
+ +
+
+
+
+
+

+ +
+ +
+ +
+
+ captcha
+
+
+
+
+ diff --git a/public/style/main.css b/public/style/main.css new file mode 100644 index 0000000..1eb993b --- /dev/null +++ b/public/style/main.css @@ -0,0 +1,286 @@ +/*----------------------------------------------------------------------------- + + orblog - Simple blog for hidden networks. + + Version: 0.1 + Git: https://code.fossee.net/chicory/orblog-legacy + Copyright: chicory@fossee.net 2020 + License: http://www.apache.org/licenses/LICENSE-2.0 + +-----------------------------------------------------------------------------*/ +@font-face +{ + font-family: roboto; + src: url(roboto.ttf); +} +* +{ + padding: 0; + margin: 0; + box-sizing: border-box; + font-family: roboto, sans; + line-height: 1.5; + outline: none; +} +.body +{ + max-width: 840px; + margin: auto; +} +a +{ + text-decoration: none; + color: #673ab7; +} +p, h1, h2, h3, h4, h5, h6, hr, ul, ol, blockquote, pre +{ + margin-bottom: 10px; +} +pre +{ + background: #ededfd; + padding: 10px; + padding-left: 14px; + border-left: 4px solid #607d8b; +} +code +{ + font-family: monospace; + font-size: 14px; +} +h1, h2 +{ + font-size: 20px; +} +h3, h4 +{ + font-size: 18px; +} +h5, h6 +{ + font-size: 16px; +} +blockquote +{ + font-style: italic; + border-left: 4px solid #607d8b; + padding-left: 14px; + margin-left: 20px; +} +li +{ + margin-left: 30px; +} +img +{ + max-width: 100%; +} +header +{ + background: #512da8; + color: #fff; + box-shadow: 2px 2px 2px #ccc; + margin-bottom: 10px; +} +header, .header_logo, .header_desc +{ + height: 60px; +} +.header_logo, .header_desc +{ + display: flex; + align-items: center; +} +.header_logo +{ + width: 30%; + font-size: 20px; + float: left; +} +.header_desc +{ + width: 70%; + font-size: 14px; + float: left; +} +header a +{ + color: #fff; +} +.main, .sidebar +{ + margin-bottom: 10px; +} +.main +{ + width: 70%; + float: left; + padding-right: 20px; +} +.sidebar +{ + width: 30%; + float: left; +} +.title +{ + width: 100%; + border-bottom: 3px solid #607d8b; + overflow: auto; +} +.title_tab +{ + background: #512da8; + padding: 10px; + float: left; + color: #fff; + font-size: 16px; +} +.title_etc +{ + float: right; + padding: 10px 0; + color: #757575; + font-size: 16px; +} +.title_etc a +{ + color: #757575; +} +.title_etc a:hover +{ + text-decoration: underline; +} +.post_title +{ + color: #333; +} +.categories a +{ + padding: 10px 0; + display: block; + border-bottom: 1px solid #b0cddb; + color: #607d8b; + transition: 0.2s linear; +} +.categories a:hover +{ + padding: 10px 5px; +} +.content +{ + padding: 10px 0; + color: #333; + font-size: 16px; +} +.comment_content +{ + padding-top: 10px; +} +input, textarea, select, option +{ + padding: 10px 18px 10px 18px; + margin: 10px 0; + border: 1px solid #607d8b; + font-size: 14px; + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + background: #fff; +} +.button +{ + background: #512da8; + color: #fff; + border: 2px solid #512da8; + transition: color 0.2s linear; +} +.editor +{ + width: 100%; +} +.button:hover +{ + background: #fff; + color: #512da8; + +} +.input_id, .input_name, .input_button +{ + display: flex; + float: left; +} +.input_id +{ + width: 10%; +} +.input_name +{ + width: 70%; + border-left: 0px; +} +.input_button +{ + width: 10%; + border: 1px solid #512da8; +} +.error +{ + color: #fd2d2d; +} +.captcha +{ + margin-bottom: 0; +} +.center +{ + text-align: center; +} +footer +{ + background: #607d8b; + color: #fff; + box-shadow: -2px -2px 2px #ccc; + font-size: 14px; + height: 80px; + padding-top: 10px; +} +.footer_copy +{ + width: 30%; + float: left; +} +.footer_text +{ + width: 70%; + float: left; + text-align: right; +} +footer a +{ + color: #fff; + text-decoration: underline; +} +.clear +{ + clear: both; +} +@media only screen and (max-width: 860px) +{ + .body + { + padding: 0 10px; + } + .header_logo, .footer_copy, .main, .sidebar + { + width: 100%; + } + .header_desc, .footer_text + { + display: none; + } + .main + { + padding: 0; + } +} diff --git a/public/style/roboto.ttf b/public/style/roboto.ttf new file mode 100644 index 0000000..3526798 Binary files /dev/null and b/public/style/roboto.ttf differ diff --git a/screeshots/admin_add_post.png b/screeshots/admin_add_post.png new file mode 100644 index 0000000..452e136 Binary files /dev/null and b/screeshots/admin_add_post.png differ diff --git a/screeshots/admin_category.png b/screeshots/admin_category.png new file mode 100644 index 0000000..399539a Binary files /dev/null and b/screeshots/admin_category.png differ diff --git a/screeshots/admin_comments.png b/screeshots/admin_comments.png new file mode 100644 index 0000000..e311244 Binary files /dev/null and b/screeshots/admin_comments.png differ diff --git a/screeshots/comment.png b/screeshots/comment.png new file mode 100644 index 0000000..3890410 Binary files /dev/null and b/screeshots/comment.png differ diff --git a/screeshots/main.png b/screeshots/main.png new file mode 100644 index 0000000..435f015 Binary files /dev/null and b/screeshots/main.png differ