From 608605cd54bac34a28ceca3e0977e979e22c140b Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 19 Sep 2015 17:23:10 +0200 Subject: [PATCH] incrementing version number, updating docs --- CHANGELOG.md | 21 ++++++- CREDITS.md | 2 +- INSTALL.md | 116 +++++++++++++++++------------------ README.md | 68 +++++++++------------ cfg/conf.ini | 5 +- css/bootstrap/zerobin.css | 2 +- css/zerobin.css | 2 +- index.php | 2 +- js/zerobin.js | 2 +- lib/RainTPL.php | 11 +++- lib/auto.php | 2 +- lib/filter.php | 2 +- lib/i18n.php | 2 +- lib/persistence.php | 2 +- lib/serversalt.php | 2 +- lib/sjcl.php | 2 +- lib/trafficlimiter.php | 2 +- lib/vizhash16x16.php | 2 +- lib/zerobin.php | 4 +- lib/zerobin/abstract.php | 2 +- lib/zerobin/data.php | 2 +- lib/zerobin/db.php | 2 +- tst/RainTPL.php | 2 + tst/i18n.php | 12 +++- tst/zerobin.php | 124 ++++++++++++++++++++++++++++++++++++++ 25 files changed, 271 insertions(+), 124 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 341fd6dd..a5faebfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,29 @@ # ZeroBin version history # + * **0.21 (2015-09-19)**: + * ADDED: Translations for German, French and Polish, language selection menu (optional) + * ADDED: File upload and image display support (optional) + * ADDED: Markdown format support + * ADDED: "bootstrap-compact" template that hides some of the options in a drop down menu to ensure the nav bar fitting on one line on smaller screen sizes + * FIXING: Various usability issues with different screen sizes / device types in the "bootstrap" template + * CHANGED: Instead of having different options to enable and preselect certain formats there is now a generic `[formatter_options]` section where formats can be added to the displayed format drop down menu. A `defaultformatter` can be set, it defaults to "plaintext". The `syntaxhighlighting` configuration got deprecated. + * `zerobin.js` got a major refactoring: + * moved from global namespace into anonymous function + * events are no longer set via "onclick" attributes in the templates, but bound by from JS side + * for simpler maintenance the functions were grouped into objects: zerobin (display logic, event handling), filter (compression, +encryption), i18n (translation, counterpart of i18n.php) and helper (stateless utilities) + * Wiki pages were added to address common topics: + * [Upgrading from ZeroBin 0.19 Alpha](https://github.com/elrido/ZeroBin/wiki/Upgrading-from-ZeroBin-0.19-Alpha) + * [ZeroBin Directory of public servers](https://github.com/elrido/ZeroBin/wiki/ZeroBin-Directory) + * [Translation](https://github.com/elrido/ZeroBin/wiki/Translation) + * [Templates](https://github.com/elrido/ZeroBin/wiki/Templates) * **0.20 (2015-09-03)**: * ADDED: Password protected pastes (optional) * ADDED: configuration options for highlighting, password, discussions, expiration times, rate limiting * ADDED: JSON-only retrieval of paste incl. discussion, used to be able to refresh paste when posting a comment * ADDED: bootstrap CSS based template - * CHANGE: "Burn after reading" pastes are now deleted only after the paste was successfully decrypted via callback. This prevents accidental deletion by chatbots following URLs and the like. Usage of a password is suggested to ensure only the desired recipient is able to encrypt it. - * CHANGE: the "opendiscussion" option now only controls if the discussion checkbox is preselected. Use "discussion = false" to disable the discussion feature completely (which also removes the checkbox from the template). + * CHANGED: "Burn after reading" pastes are now deleted only after the paste was successfully decrypted via callback. This prevents accidental deletion by chatbots following URLs and the like. Usage of a password is suggested to ensure only the desired recipient is able to encrypt it. + * CHANGED: the "opendiscussion" option now only controls if the discussion checkbox is preselected. Use "discussion = false" to disable the discussion feature completely (which also removes the checkbox from the template). * FIXING: Behaviour of several conflicting configuration options. As a general measure unit tests for 9 of the options and all their possible configurations were added via a unit test generator. * updated JS libraries: jquery to 1.11.3, sjcl to 1.0.2, base64.js to 2.1.9, deflate to 0.5, inflate to 0.3 and prettify to latest * generally improved documentation, both inline phpdoc / JSdoc source code documentation, as well as Wiki pages on installation, configuration, development and JSON-API diff --git a/CREDITS.md b/CREDITS.md index 1cec65ec..58d5db30 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -5,7 +5,7 @@ Sébastien Sauvage - original idea and main developer Alexey Gladkov - syntax highlighting Greg Knaddison - robots.txt MrKooky - HTML5 markup, CSS cleanup -Simon Rupf - MVC refactoring, configuration support and unit tests +Simon Rupf - MVC refactoring, configuration, i18n and unit tests Hexalyse - Password protection Viktor Stanchev - File upload support diff --git a/INSTALL.md b/INSTALL.md index ae35c5ce..caca1cfd 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,20 +1,47 @@ Installation ============ -For Administrators ------------------- +## Basic installation -In the index.php in the main folder you can define a different PATH. This is -useful if you want to secure your installation and want to move the -configuration, data files, templates and PHP libraries (directories cfg, data, -lib, tpl and tst) outside of your document root. This new location must still -be accessible to your webserver / PHP process. +**TL;DR:** Download the [latest release archive](https://github.com/elrido/ZeroBin/releases/latest) +and extract it in your web hosts folder were you want to install your ZeroBin instance. -> ### PATH Example ### -> Your zerobin installation lives in a subfolder called "paste" inside of your +### Requirements + +- PHP version 5.2.6 or above +- GD extension +- mcrypt extension (recommended) +- some disk space or (optional) a database supported by PDO +- A web browser with javascript support + +### Configuration + +In the file `cfg/conf.ini` you can configure ZeroBin. The config file is divided +into multiple sections, which are enclosed in square brackets. + +In the `[main]` section you can enable or disable the discussion feature, set the +limit of stored pastes and comments in bytes. The `[traffic]` section lets you +set a time limit in seconds. Users may not post more often then this limit to +your ZeroBin installation. + +More details can be found in the +[configuration documentation](https://github.com/elrido/ZeroBin/wiki/Configuration). + +## Advanced installation + +### Changing the path + +In the index.php you can define a different `PATH`. This is useful to secure your +installation. You can move the configuration, data files, templates and PHP +libraries (directories cfg, data, lib, tpl, tmp and tst) outside of your document +root. This new location must still be accessible to your webserver / PHP process +([open_basedir setting](http://php.net/manual/en/ini.core.php#ini.open-basedir)). + +> #### PATH Example +> Your zerobin installation lives in a subfolder called "paste" inside of your > document root. The URL looks like this: > http://example.com/paste/ -> The ZeroBin folder on your webserver is really: +> The full path of ZeroBin on your webserver is: > /home/example.com/htdocs/paste > > When setting the path like this: @@ -22,29 +49,27 @@ be accessible to your webserver / PHP process. > ZeroBin will look for your includes here: > /home/example.com/secret/zerobin -In the file "cfg/conf.ini" you can configure ZeroBin. The config file is -divided into multiple sections, which are enclosed in square brackets. In the -"[main]" section you can enable or disable the discussion feature, set the -limit of stored pastes and comments in bytes. The "[traffic]" section lets you -set a time limit in seconds. Users may not post more often then this limit to -your ZeroBin. +### Using a database instead of flat files -Finally the "[model]" and "[model_options]" sections let you configure your -favourite way of storing the pastes and discussions on your server. -"zerobin_data" is the default model, which stores everything in files in the -data folder. This is the recommended setup for low traffic sites. Under high -load, in distributed setups or if you are not allowed to store files locally, -you might want to switch to the "zerobin_db" model. This lets you store your -data in a database. Basically all databases that are supported by PDO (PHP -data objects) may be used. Automatic table creation is provided for pdo_ibm, -pdo_informix, pdo_mssql, pdo_mysql, pdo_oci, pdo_pgsql and pdo_sqlite. You may -want to provide a table prefix, if you have to share the zerobin database with -another application. The table prefix option is called "tbl". +In the configuration file the `[model]` and `[model_options]` sections let you +configure your favourite way of storing the pastes and discussions on your server. -> ### Note ### -> The "zerobin_db" model has only been tested with SQLite and MySQL, although -> it would not be recommended to use SQLite in a production environment. If you -> gain any experience running ZeroBin on other RDBMS, please let us know. +`zerobin_data` is the default model, which stores everything in files in the data +folder. This is the recommended setup for most sites. + +Under high load, in distributed setups or if you are not allowed to store files +locally, you might want to switch to the `zerobin_db` model. This lets you store +your data in a database. Basically all databases that are supported by +[PDO](http://php.net/manual/en/book.pdo.php) may be used. Automatic table +creation is provided for `pdo_ibm`, `pdo_informix`, `pdo_mssql`, `pdo_mysql`, +`pdo_oci`, `pdo_pgsql` and `pdo_sqlite`. You may want to provide a table prefix, +if you have to share the zerobin database with another application. The table +prefix option is called `tbl`. + +> #### Note +> The "zerobin_db" model has only been tested with SQLite and MySQL, although it +would not be recommended to use SQLite in a production environment. If you gain +any experience running ZeroBin on other RDBMS, please let us know. For reference or if you want to create the table schema for yourself: @@ -66,32 +91,3 @@ For reference or if you want to create the table schema for yourself: vizhash TEXT, postdate INT ); - -For Developers --------------- -If you want to create your own data models, you might want to know how the -arrays, that you have to store, look like: - - public function create($pasteid, $paste) - { - $pasteid = substr(hash('md5', $paste['data']), 0, 16); - - $paste['data'] // text - $paste['meta']['postdate'] // int UNIX timestamp - $paste['meta']['expire_date'] // int UNIX timestamp - $paste['meta']['opendiscussion'] // true (if false it is unset) - $paste['meta']['burnafterreading'] // true (if false it is unset; if true, then opendiscussion is unset) - } - - public function createComment($pasteid, $parentid, $commentid, $comment) - { - $pasteid // the id of the paste this comment belongs to - $parentid // the id of the parent of this comment, may be the paste id itself - $commentid = substr(hash('md5', $paste['data']), 0, 16); - - $comment['data'] // text - $comment['meta']['nickname'] // text or null (if anonymous) - $comment['meta']['vizhash'] // text or null (if anonymous) - $comment['meta']['postdate'] // int UNIX timestamp - } - diff --git a/README.md b/README.md index c6304806..921cd459 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ZeroBin 0.20 +# ZeroBin 0.21 ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data. @@ -12,16 +12,16 @@ without loosing any data. ## What ZeroBin provides -- As a server administrator you don't have to worry if your users post content ++ As a server administrator you don't have to worry if your users post content that is considered illegal in your country. You have no knowledge of any - pastes content. If requested or enforced, you can delete any paste from your - system. + of the pastes content. If requested or enforced, you can delete any paste from + your system. -- Pastebin like system to store text documents, code samples, etc. ++ Pastebin-like system to store text documents, code samples, etc. -- Encryption of data sent to server, even if it does not provide HTTPS. ++ Encryption of data sent to server, even if it does not provide HTTPS. -- Possibility to set a password which is required to read the paste. It further ++ Possibility to set a password which is required to read the paste. It further protects a paste and prevents people stumbling upon your paste's link from being able to read it without the password. @@ -43,48 +43,38 @@ without loosing any data. Some features are optional and can be enabled or disabled in the [configuration file](https://github.com/elrido/ZeroBin/wiki/Configuration): -- Password protection +* Password protection -- Discussions +* Discussions -- Expiration times, including a "forever" and "burn after reading" option +* Expiration times, including a "forever" and "burn after reading" option -- Syntax highlighting using prettify.js, including 4 prettify themes +* Markdown format support for HTML formatted pastes -- Templates: By default there is a bootstrap based and a "classic ZeroBin" theme +* Syntax highlighting for source code using prettify.js, including 4 prettify themes + +* File upload support, images get displayed (disabled by default, possibility to adjust size limit) + +* Templates: By default there is a bootstrap CSS and a "classic ZeroBin" theme and it is easy to adapt these to your own websites layout or create your own. +* Translation system and automatic browser language detection (if enabled in browser) + +* Language selection (disabled by default, as it uses a session cookie) + ## Further resources -- [Installation guide](https://github.com/elrido/ZeroBin/wiki/Installation) +* [Installation guide](https://github.com/elrido/ZeroBin/wiki/Installation) -- [Configuration guide](https://github.com/elrido/ZeroBin/wiki/Configuration) +* [Upgrading from 0.19 Alpha](https://github.com/elrido/ZeroBin/wiki/Upgrading-from-ZeroBin-0.19-Alpha) -- [Developer guide](https://github.com/elrido/ZeroBin/wiki/Development) +* [Configuration guide](https://github.com/elrido/ZeroBin/wiki/Configuration) + +* [Templates](https://github.com/elrido/ZeroBin/wiki/Templates) + +* [Translation guide](https://github.com/elrido/ZeroBin/wiki/Translation) + +* [Developer guide](https://github.com/elrido/ZeroBin/wiki/Development) Run into any issues? Have ideas for further developments? Please [report](https://github.com/elrido/ZeroBin/issues) them! - ------------------------------------------------------------------------------- - -Copyright (c) 2012 Sébastien SAUVAGE (sebsauvage.net) - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from -the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product documentation - would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. - ------------------------------------------------------------------------------- diff --git a/cfg/conf.ini b/cfg/conf.ini index 20e9c93a..56a9ca7d 100644 --- a/cfg/conf.ini +++ b/cfg/conf.ini @@ -5,7 +5,7 @@ ; @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin ; @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) ; @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License -; @version 0.20 +; @version 0.21 [main] ; enable or disable the discussion feature, defaults to true @@ -108,5 +108,4 @@ dir = PATH "data" ;dsn = "sqlite:" PATH "data/db.sq3" ;usr = null ;pwd = null -;opt[12] = true ; PDO::ATTR_PERSISTENT - +;opt[12] = true ; PDO::ATTR_PERSISTENT \ No newline at end of file diff --git a/css/bootstrap/zerobin.css b/css/bootstrap/zerobin.css index 69c4844e..38939b42 100644 --- a/css/bootstrap/zerobin.css +++ b/css/bootstrap/zerobin.css @@ -1,4 +1,4 @@ -/* ZeroBin 0.20 - http://sebsauvage.net/wiki/doku.php?id=php:zerobin */ +/* ZeroBin 0.21 - http://sebsauvage.net/wiki/doku.php?id=php:zerobin */ body { diff --git a/css/zerobin.css b/css/zerobin.css index c252d264..f7825057 100644 --- a/css/zerobin.css +++ b/css/zerobin.css @@ -1,4 +1,4 @@ -/* ZeroBin 0.20 - http://sebsauvage.net/wiki/doku.php?id=php:zerobin */ +/* ZeroBin 0.21 - http://sebsauvage.net/wiki/doku.php?id=php:zerobin */ /* CSS Reset from YUI 3.4.1 (build 4118) - Copyright 2011 Yahoo! Inc. All rights reserved. diff --git a/index.php b/index.php index 5ad75f73..0c15ad2e 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ // change this, if your php files and data is outside of your webservers document root diff --git a/js/zerobin.js b/js/zerobin.js index 22689c96..8e46ee16 100644 --- a/js/zerobin.js +++ b/js/zerobin.js @@ -6,7 +6,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ 'use strict'; diff --git a/lib/RainTPL.php b/lib/RainTPL.php index 2250b1d6..3e45536b 100644 --- a/lib/RainTPL.php +++ b/lib/RainTPL.php @@ -1162,7 +1162,16 @@ class RainTpl_SyntaxException extends RainTpl_Exception{ } } -// shorthand translate function for use in templates +/** + * shorthand translate function for use in templates + * + * alias for i18n::translate() + * + * @access public + * @param string $messageId + * @param mixed $args one or multiple parameters injected into placeholders + * @return string + */ function t() { return call_user_func_array(array('i18n', 'translate'), func_get_args()); } diff --git a/lib/auto.php b/lib/auto.php index ed0c906a..01b30192 100644 --- a/lib/auto.php +++ b/lib/auto.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ spl_autoload_register('auto::loader'); diff --git a/lib/filter.php b/lib/filter.php index c4bd95d4..804d3753 100644 --- a/lib/filter.php +++ b/lib/filter.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/i18n.php b/lib/i18n.php index 9861db72..795f3f4c 100644 --- a/lib/i18n.php +++ b/lib/i18n.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/persistence.php b/lib/persistence.php index 3e4186b3..197ede0c 100644 --- a/lib/persistence.php +++ b/lib/persistence.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/serversalt.php b/lib/serversalt.php index 4238eacf..e3aeecb4 100644 --- a/lib/serversalt.php +++ b/lib/serversalt.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/sjcl.php b/lib/sjcl.php index baa5fe50..467959d1 100644 --- a/lib/sjcl.php +++ b/lib/sjcl.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/trafficlimiter.php b/lib/trafficlimiter.php index f61b35b7..cd05dfd1 100644 --- a/lib/trafficlimiter.php +++ b/lib/trafficlimiter.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/vizhash16x16.php b/lib/vizhash16x16.php index c486ecf6..ca9b5eae 100644 --- a/lib/vizhash16x16.php +++ b/lib/vizhash16x16.php @@ -8,7 +8,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:vizhash_gd * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.0.4 beta ZeroBin 0.20 + * @version 0.0.4 beta ZeroBin 0.21 */ /** diff --git a/lib/zerobin.php b/lib/zerobin.php index 6cda9b64..f35dc5fa 100644 --- a/lib/zerobin.php +++ b/lib/zerobin.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** @@ -22,7 +22,7 @@ class zerobin * * @const string */ - const VERSION = '0.20'; + const VERSION = '0.21'; /** * show the same error message if the paste expired or does not exist diff --git a/lib/zerobin/abstract.php b/lib/zerobin/abstract.php index 2ca12ba3..23552eef 100644 --- a/lib/zerobin/abstract.php +++ b/lib/zerobin/abstract.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/zerobin/data.php b/lib/zerobin/data.php index a1b4f7a3..6d21a29f 100644 --- a/lib/zerobin/data.php +++ b/lib/zerobin/data.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/lib/zerobin/db.php b/lib/zerobin/db.php index 2f3efe67..96e673ae 100644 --- a/lib/zerobin/db.php +++ b/lib/zerobin/db.php @@ -7,7 +7,7 @@ * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net) * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License - * @version 0.20 + * @version 0.21 */ /** diff --git a/tst/RainTPL.php b/tst/RainTPL.php index 86db1148..fa9a91b5 100644 --- a/tst/RainTPL.php +++ b/tst/RainTPL.php @@ -41,6 +41,8 @@ class RainTPLTest extends PHPUnit_Framework_TestCase $page->assign('FILEUPLOAD', false); $page->assign('BASE64JSVERSION', '2.1.9'); $page->assign('NOTICE', 'example'); + $page->assign('LANGUAGESELECTION', ''); + $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages())); $page->assign('EXPIRE', self::$expire); $page->assign('EXPIREDEFAULT', self::$expire_default); ob_start(); diff --git a/tst/i18n.php b/tst/i18n.php index 78ed3f0f..a8bee91a 100644 --- a/tst/i18n.php +++ b/tst/i18n.php @@ -25,6 +25,16 @@ class i18nTest extends PHPUnit_Framework_TestCase $this->assertEquals($messageId, i18n::_($messageId), 'fallback to en'); } + public function testCookieLanguageDeDetection() + { + $_COOKIE['lang'] = 'de'; + i18n::loadTranslations(); + $this->assertEquals($this->_translations['en'], i18n::_('en'), 'browser language de'); + $this->assertEquals('0 Stunden', i18n::_('%d hours', 0), '0 hours in german'); + $this->assertEquals('1 Stunde', i18n::_('%d hours', 1), '1 hour in german'); + $this->assertEquals('2 Stunden', i18n::_('%d hours', 2), '2 hours in french'); + } + public function testBrowserLanguageDeDetection() { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-CH,de;q=0.8,en-GB;q=0.6,en-US;q=0.4,en;q=0.2'; @@ -64,6 +74,6 @@ class i18nTest extends PHPUnit_Framework_TestCase { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'foobar'; i18n::loadTranslations(); - $this->assertEquals('some string + 1', i18n::_('some %s + %d', 'string', 1), 'browser language de'); + $this->assertEquals('some string + 1', i18n::_('some %s + %d', 'string', 1), 'browser language en'); } } diff --git a/tst/zerobin.php b/tst/zerobin.php index 924fc5f6..fe77b1a7 100644 --- a/tst/zerobin.php +++ b/tst/zerobin.php @@ -71,6 +71,31 @@ class zerobinTest extends PHPUnit_Framework_TestCase ); } + /** + * @runInSeparateProcess + */ + public function testViewLanguageSelection() + { + $this->reset(); + $options = parse_ini_file($this->_conf, true); + $options['main']['languageselection'] = true; + if (!is_file($this->_conf . '.bak') && is_file($this->_conf)) + rename($this->_conf, $this->_conf . '.bak'); + helper::createIniFile($this->_conf, $options); + $_COOKIE['lang'] = 'de'; + ob_start(); + new zerobin; + $content = ob_get_contents(); + $this->assertTag( + array( + 'tag' => 'title', + 'content' => 'ZeroBin' + ), + $content, + 'outputs title correctly' + ); + } + /** * @runInSeparateProcess */ @@ -168,6 +193,27 @@ class zerobinTest extends PHPUnit_Framework_TestCase $this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data'); } + /** + * @runInSeparateProcess + */ + public function testCreateProxyHeader() + { + $this->reset(); + $options = parse_ini_file($this->_conf, true); + $options['traffic']['header'] = 'X_FORWARDED_FOR'; + if (!is_file($this->_conf . '.bak') && is_file($this->_conf)) + rename($this->_conf, $this->_conf . '.bak'); + helper::createIniFile($this->_conf, $options); + $_POST = self::$paste; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '::1'; + ob_start(); + new zerobin; + $content = ob_get_contents(); + $response = json_decode($content, true); + $this->assertEquals(1, $response['status'], 'outputs error status'); + $this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data'); + } + /** * @runInSeparateProcess */ @@ -289,6 +335,35 @@ class zerobinTest extends PHPUnit_Framework_TestCase $this->assertFalse($this->_model->exists(self::$pasteid), 'paste exists after posting data'); } + /** + * @runInSeparateProcess + */ + public function testCreateAttachment() + { + $this->reset(); + $options = parse_ini_file($this->_conf, true); + $options['traffic']['limit'] = 0; + $options['main']['fileupload'] = true; + if (!is_file($this->_conf . '.bak') && is_file($this->_conf)) + rename($this->_conf, $this->_conf . '.bak'); + helper::createIniFile($this->_conf, $options); + $_POST = self::$paste; + $_POST['attachment'] = self::$comment['data']; + $_POST['attachmentname'] = self::$comment['meta']['nickname']; + $_SERVER['REMOTE_ADDR'] = '::1'; + ob_start(); + new zerobin; + $content = ob_get_contents(); + $response = json_decode($content, true); + $this->assertEquals(0, $response['status'], 'outputs status'); + $this->assertEquals( + hash_hmac('sha1', $response['id'], serversalt::get()), + $response['deletetoken'], + 'outputs valid delete token' + ); + $this->assertTrue($this->_model->exists($response['id']), 'paste exists after posting data'); + } + /** * @runInSeparateProcess */ @@ -598,6 +673,55 @@ class zerobinTest extends PHPUnit_Framework_TestCase $this->assertEquals(1, $response['status'], 'outputs error status'); } + /** + * @runInSeparateProcess + */ + public function testReadOldSyntax() + { + $this->reset(); + $oldPaste = self::$paste; + $oldPaste['meta']['syntaxcoloring'] = true; + unset($oldPaste['meta']['formatter']); + $this->_model->create(self::$pasteid, $oldPaste); + $_SERVER['QUERY_STRING'] = self::$pasteid; + ob_start(); + new zerobin; + $content = ob_get_contents(); + $oldPaste['meta']['formatter'] = 'syntaxhighlighting'; + $this->assertTag( + array( + 'id' => 'cipherdata', + 'content' => htmlspecialchars(json_encode($oldPaste), ENT_NOQUOTES) + ), + $content, + 'outputs data correctly' + ); + } + + /** + * @runInSeparateProcess + */ + public function testReadOldFormat() + { + $this->reset(); + $oldPaste = self::$paste; + unset($oldPaste['meta']['formatter']); + $this->_model->create(self::$pasteid, $oldPaste); + $_SERVER['QUERY_STRING'] = self::$pasteid; + ob_start(); + new zerobin; + $content = ob_get_contents(); + $oldPaste['meta']['formatter'] = 'plaintext'; + $this->assertTag( + array( + 'id' => 'cipherdata', + 'content' => htmlspecialchars(json_encode($oldPaste), ENT_NOQUOTES) + ), + $content, + 'outputs data correctly' + ); + } + /** * @runInSeparateProcess */