diff --git a/.gitignore b/.gitignore index 9a3d92c4..0323182e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Ignore data/, tmp/ and vendor/ data/ +!lib/data/ tmp/ vendor/ # Ignore for safety diff --git a/composer.json b/composer.json index 1280da37..bd94adf4 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,14 @@ { "name": "privatebin/privatebin", "description": "PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted in the browser using 256 bit AES in Galois Counter mode (GCM).", - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/PrivateBin/PrivateBin" - } - ], "license":"zlib-acknowledgement", "require-dev": { "codacy/coverage": "dev-master", "codeclimate/php-test-reporter": "dev-master" + }, + "autoload": { + "psr-4": { + "PrivateBin\\": "lib/" + } } } diff --git a/index.php b/index.php index 06c3617d..ec404979 100644 --- a/index.php +++ b/index.php @@ -14,5 +14,5 @@ define('PATH', ''); define('PUBLIC_PATH', dirname(__FILE__)); -require PATH . 'lib/auto.php'; -new privatebin; +require __DIR__ . '/vendor/autoload.php'; +new PrivateBin\privatebin; diff --git a/lib/auto.php b/lib/auto.php deleted file mode 100644 index 30ef778b..00000000 --- a/lib/auto.php +++ /dev/null @@ -1,38 +0,0 @@ -_conf, $this->_getStore()); + $paste = new paste($this->_conf, $this->_getStore()); if ($pasteId !== null) $paste->setId($pasteId); return $paste; } @@ -76,10 +80,18 @@ class model */ private function _getStore() { + // FIXME + // Workaround so that config value don't need to be changed + $callable = str_replace( + array('privatebin_data', 'privatebin_db'), + array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'), + $this->_conf->getKey('class', 'model') + ); + if ($this->_store === null) { $this->_store = forward_static_call( - array($this->_conf->getKey('class', 'model'), 'getInstance'), + array($callable, 'getInstance'), $this->_conf->getSection('model_options') ); } diff --git a/lib/model/abstract.php b/lib/model/AbstractModel.php similarity index 91% rename from lib/model/abstract.php rename to lib/model/AbstractModel.php index 5e0435d1..c7979b2c 100644 --- a/lib/model/abstract.php +++ b/lib/model/AbstractModel.php @@ -10,12 +10,20 @@ * @version 0.22 */ +namespace PrivateBin\Model; + +use Exception; +use PrivateBin\configuration; +use PrivateBin\data\AbstractData; +use PrivateBin\sjcl; +use stdClass; + /** * model_abstract * * Abstract model for PrivateBin objects. */ -abstract class model_abstract +abstract class AbstractModel { /** * Instance ID. @@ -57,7 +65,7 @@ abstract class model_abstract * @param privatebin_abstract $storage * @return void */ - public function __construct(configuration $configuration, privatebin_abstract $storage) + public function __construct(configuration $configuration, AbstractData $storage) { $this->_conf = $configuration; $this->_store = $storage; diff --git a/lib/model/comment.php b/lib/model/comment.php index 011649d3..42057ab1 100644 --- a/lib/model/comment.php +++ b/lib/model/comment.php @@ -10,12 +10,19 @@ * @version 0.22 */ +namespace PrivateBin\model; + +use Exception; +use PrivateBin\sjcl; +use PrivateBin\trafficlimiter; +use PrivateBin\vizhash16x16; + /** * model_comment * * Model of a PrivateBin comment. */ -class model_comment extends model_abstract +class comment extends AbstractModel { /** * Instance's parent. @@ -118,7 +125,7 @@ class model_comment extends model_abstract * @throws Exception * @return void */ - public function setPaste(model_paste $paste) + public function setPaste(paste $paste) { $this->_paste = $paste; $this->_data->meta->pasteid = $paste->getId(); diff --git a/lib/model/paste.php b/lib/model/paste.php index 57b86b6f..42946144 100644 --- a/lib/model/paste.php +++ b/lib/model/paste.php @@ -10,12 +10,19 @@ * @version 0.22 */ +namespace PrivateBin\model; + +use Exception; +use PrivateBin\privatebin; +use PrivateBin\serversalt; +use PrivateBin\sjcl; + /** * model_paste * * Model of a PrivateBin paste. */ -class model_paste extends model_abstract +class paste extends AbstractModel { /** * Get paste data. @@ -130,7 +137,7 @@ class model_paste extends model_abstract { throw new Exception('Invalid data.', 62); } - $comment = new model_comment($this->_conf, $this->_store); + $comment = new comment($this->_conf, $this->_store); $comment->setPaste($this); $comment->setParentId($parentId); if ($commentId !== null) $comment->setId($commentId); diff --git a/lib/persistence.php b/lib/persistence.php index d65f8440..28259def 100644 --- a/lib/persistence.php +++ b/lib/persistence.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * persistence * diff --git a/lib/privatebin.php b/lib/privatebin.php index eb6f9cbd..f1f15a84 100644 --- a/lib/privatebin.php +++ b/lib/privatebin.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * privatebin * @@ -419,7 +423,7 @@ class privatebin } // translate all the formatter options - $formatters = array_map(array('i18n', 'translate'), $this->_conf->getSection('formatter_options')); + $formatters = array_map(array('PrivateBin\\i18n', 'translate'), $this->_conf->getSection('formatter_options')); // set language cookie if that functionality was enabled $languageselection = ''; diff --git a/lib/purgelimiter.php b/lib/purgelimiter.php index d8c595aa..36fa9ce8 100644 --- a/lib/purgelimiter.php +++ b/lib/purgelimiter.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * purgelimiter * diff --git a/lib/request.php b/lib/request.php index 1339e842..d5d9c9d5 100644 --- a/lib/request.php +++ b/lib/request.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * request * diff --git a/lib/serversalt.php b/lib/serversalt.php index 91cfcdc3..fe28fefb 100644 --- a/lib/serversalt.php +++ b/lib/serversalt.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * serversalt * diff --git a/lib/sjcl.php b/lib/sjcl.php index ae09c9c7..cc79cea4 100644 --- a/lib/sjcl.php +++ b/lib/sjcl.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * sjcl * diff --git a/lib/trafficlimiter.php b/lib/trafficlimiter.php index b0fc5a77..ed1f5345 100644 --- a/lib/trafficlimiter.php +++ b/lib/trafficlimiter.php @@ -10,6 +10,8 @@ * @version 0.22 */ +namespace PrivateBin; + /** * trafficlimiter * diff --git a/lib/view.php b/lib/view.php index 45952006..a63c2d2e 100644 --- a/lib/view.php +++ b/lib/view.php @@ -10,6 +10,10 @@ * @version 0.22 */ +namespace PrivateBin; + +use Exception; + /** * view * diff --git a/lib/vizhash16x16.php b/lib/vizhash16x16.php index 47b725d2..314a3997 100644 --- a/lib/vizhash16x16.php +++ b/lib/vizhash16x16.php @@ -11,6 +11,8 @@ * @version 0.0.4 beta PrivateBin 0.22 */ +namespace PrivateBin; + /** * vizhash16x16 * diff --git a/tpl/bootstrap-compact.php b/tpl/bootstrap-compact.php index e39652e0..7d299add 100644 --- a/tpl/bootstrap-compact.php +++ b/tpl/bootstrap-compact.php @@ -5,7 +5,7 @@ - <?php echo i18n::_('PrivateBin'); ?> + <?php echo PrivateBin\i18n::_('PrivateBin'); ?>
@@ -202,9 +202,9 @@ endif; ?> - - -
@@ -238,16 +238,16 @@ endif; ?>
diff --git a/tpl/bootstrap-dark-page.php b/tpl/bootstrap-dark-page.php index 8f264cda..10cb75d0 100644 --- a/tpl/bootstrap-dark-page.php +++ b/tpl/bootstrap-dark-page.php @@ -5,7 +5,7 @@ - <?php echo i18n::_('PrivateBin'); ?> + <?php echo PrivateBin\i18n::_('PrivateBin'); ?>
  • checked="checked" /> - +
  • checked="checked" /> - +
  • checked="checked" /> - +