diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6cbc618 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.php] +indent_size = 4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a52dbb2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: fix-byte-order-marker + - id: end-of-file-fixer + - id: trailing-whitespace + + - id: mixed-line-ending + args: [--fix=lf] diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..65c7ac0 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## 1.0.0 - 2020-12-03 + +- Initial release. + +[Unreleased]: https://github.com/Calinou/q2a-prefill-fields/compare/v1.0.0...HEAD diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..149ba76 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright © 2020 Hugo Locurcio and contributors + +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..d05482d --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Pre-fill form fields for Question2Answer + +A Question2Answer plugin to pre-fill form fields on the *Ask a question* page +using GET parameters. + +## Features + +Supported fields are: + +- `title` +- `content` **(only when not using a rich/WYSIWYG editor)** +- `tags` + +Since the user can input arbitrary values as GET parameters, the values are +escaped using PHP's `htmlspecialchars()` function. You can use multiple tags by +separating each tag with a `+` or `%20` in the URL. + +## Example + +The following URL, when entered in the browser address bar: + +```text +http://localhost:8000/index.php?qa=ask&title=Hello+world&content=something&tags=one%20two%20three +``` + +Will result in: + +- **Title:** Hello world +- **Content:** something +- **Tags:** one two three *(as 3 separate tags, since Q2A separates tags with spaces)* + +## Installation + +- Clone this repository or + [download a ZIP archive](https://github.com/Calinou/q2a-prefill-fields/archive/master.zip). +- Move the extracted folder to the `qa-plugin/` folder of your Question2Answer + installation. +- Log in as administrator on your Question2Answer instance, navigate to + **Admin > Plugins** and make sure the **Prefill Fields** plugin is visible + and enabled. + +## License + +Copyright © 2020 Hugo Locurcio and contributors + +Unless otherwise specified, files in this repository are licensed under the +MIT license. See [LICENSE.md](LICENSE.md) for more information. diff --git a/qa-plugin.php b/qa-plugin.php new file mode 100644 index 0000000..bf45f85 --- /dev/null +++ b/qa-plugin.php @@ -0,0 +1,40 @@ +template === 'ask') { + $this->content['script'][] = ''; + } + + parent::head_script(); + } +}