Merge pull request #54 from Sobak/coding-style

Coding style
This commit is contained in:
El RIDO 2016-08-04 15:58:46 +02:00 committed by GitHub
commit 9bde729cb5
55 changed files with 990 additions and 911 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Ignore data/, tmp/ and vendor/
data/
!lib/data/
tmp/
vendor/
# Ignore for safety

View file

@ -9,7 +9,7 @@ instance.
### Requirements
- PHP version 5.2.6 or above
- PHP version 5.3.0 or above
- GD extension
- mcrypt extension (recommended)
- some disk space or (optional) a database supported by PDO

View file

@ -23,5 +23,10 @@
"require-dev": {
"codacy/coverage": "dev-master",
"codeclimate/php-test-reporter": "dev-master"
},
"autoload": {
"psr-4": {
"PrivateBin\\": "lib/"
}
}
}

View file

@ -2,8 +2,8 @@
"en": "de",
"Paste does not exist, has expired or has been deleted.":
"Diesen Text gibt es nicht, er ist abgelaufen oder wurde gelöscht.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.":
"PrivateBin benötigt PHP 5.2.6 oder höher, um zu funktionieren. Sorry.",
"PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin benötigt PHP 5.3.0 oder höher, um zu funktionieren. Sorry.",
"PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin benötigt den Konfigurationsabschnitt [%s] in der Konfigurationsdatei um zu funktionieren.",
"Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "fr",
"Paste does not exist, has expired or has been deleted.":
"Le paste n'existe pas, a expiré, ou a été supprimé.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.":
"Désolé, PrivateBin nécessite php 5.2.6 ou supérieur pour fonctionner.",
"PrivateBin requires php 5.3.0 or above to work. Sorry.":
"Désolé, PrivateBin nécessite php 5.3.0 ou supérieur pour fonctionner.",
"PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin a besoin de la section de configuration [%s] dans le fichier de configuration pour fonctionner.",
"Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "pl",
"Paste does not exist, has expired or has been deleted.":
"Wklejka nie istnieje, wygasła albo została usunięta.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.":
"PrivateBin wymaga PHP w wersji 5.2.6 lub nowszej, sorry.",
"PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin wymaga PHP w wersji 5.3.0 lub nowszej, sorry.",
"PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin wymaga obecności sekcji [%s] w pliku konfiguracyjnym.",
"Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "sl",
"Paste does not exist, has expired or has been deleted.":
"Prilepek ne obstaja, mu je potekla življenjska doba, ali pa je izbrisan.",
"PrivateBin requires php 5.2.6 or above to work. Sorry.":
"Oprosti, PrivateBin za delovanje potrebuje vsaj php 5.2.6.",
"PrivateBin requires php 5.3.0 or above to work. Sorry.":
"Oprosti, PrivateBin za delovanje potrebuje vsaj php 5.3.0.",
"PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin potrebuje sekcijo konfiguracij [%s] v konfiguracijski datoteki.",
"Please wait %d seconds between each post.":

View file

@ -2,8 +2,8 @@
"en": "zh",
"Paste does not exist, has expired or has been deleted.":
"粘贴不存在,已过期或者已被删除。",
"PrivateBin requires php 5.2.6 or above to work. Sorry.":
"PrivateBin需要工作于PHP 5.2.6及以上版本,抱歉。",
"PrivateBin requires php 5.3.0 or above to work. Sorry.":
"PrivateBin需要工作于PHP 5.3.0及以上版本,抱歉。",
"PrivateBin requires configuration section [%s] to be present in configuration file.":
"PrivateBin需要设置配置文件中 [%s] 的部分。",
"Please wait %d seconds between each post.":

View file

@ -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;

View file

@ -1,38 +0,0 @@
<?php
/**
* PrivateBin
*
* a zero-knowledge paste bin
*
* @link https://github.com/PrivateBin/PrivateBin
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
* @version 0.22
*/
spl_autoload_register('auto::loader');
/**
* auto
*
* provides autoloading functionality
*/
class auto
{
/**
* includes file for given class name
*
* @access public
* @static
* @param string $class_name
* @return mixed
*/
public static function loader($class_name)
{
$filename = PATH . 'lib/' . str_replace('_', '/', $class_name) . '.php';
if(is_readable($filename)) {
return include $filename;
}
return false;
}
}

View file

@ -10,6 +10,11 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
use PDO;
/**
* configuration
*
@ -77,7 +82,7 @@ class configuration
'dir' => 'data',
),
'model' => array(
'class' => 'privatebin_data',
'class' => 'PrivateBin\data\data',
),
'model_options' => array(
'dir' => 'data',
@ -93,8 +98,7 @@ class configuration
{
$config = array();
$configFile = PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini';
if (is_readable($configFile))
{
if (is_readable($configFile)) {
$config = parse_ini_file($configFile, true);
foreach (array('main', 'model', 'model_options') as $section) {
if (!array_key_exists($section, $config)) {
@ -103,14 +107,11 @@ class configuration
}
}
$opts = '_options';
foreach (self::getDefaults() as $section => $values)
{
foreach (self::getDefaults() as $section => $values) {
// fill missing sections with default values
if (!array_key_exists($section, $config) || count($config[$section]) == 0)
{
if (!array_key_exists($section, $config) || count($config[$section]) == 0) {
$this->_configuration[$section] = $values;
if (array_key_exists('dir', $this->_configuration[$section]))
{
if (array_key_exists('dir', $this->_configuration[$section])) {
$this->_configuration[$section]['dir'] = PATH . $this->_configuration[$section]['dir'];
}
continue;
@ -121,8 +122,7 @@ class configuration
$this->_configuration['model']['class'],
array('privatebin_db', 'zerobin_db')
)
)
{
) {
$values = array(
'dsn' => 'sqlite:' . PATH . 'data/db.sq3',
'tbl' => null,
@ -137,52 +137,34 @@ class configuration
$section !== 'model_options' &&
($from = strlen($section) - strlen($opts)) >= 0 &&
strpos($section, $opts, $from) !== false
)
{
if (is_int(current($values)))
{
) {
if (is_int(current($values))) {
$config[$section] = array_map('intval', $config[$section]);
}
$this->_configuration[$section] = $config[$section];
}
// check for missing keys and set defaults if necessary
else
{
foreach ($values as $key => $val)
{
if ($key == 'dir')
{
else {
foreach ($values as $key => $val) {
if ($key == 'dir') {
$val = PATH . $val;
}
$result = $val;
if (array_key_exists($key, $config[$section]))
{
if ($val === null)
{
if (array_key_exists($key, $config[$section])) {
if ($val === null) {
$result = $config[$section][$key];
}
elseif (is_bool($val))
{
} elseif (is_bool($val)) {
$val = strtolower($config[$section][$key]);
if (in_array($val, array('true', 'yes', 'on')))
{
if (in_array($val, array('true', 'yes', 'on'))) {
$result = true;
}
elseif (in_array($val, array('false', 'no', 'off')))
{
} elseif (in_array($val, array('false', 'no', 'off'))) {
$result = false;
}
else
{
} else {
$result = (bool) $config[$section][$key];
}
}
elseif (is_int($val))
{
} elseif (is_int($val)) {
$result = (int) $config[$section][$key];
}
elseif (is_string($val) && !empty($config[$section][$key]))
{
} elseif (is_string($val) && !empty($config[$section][$key])) {
$result = (string) $config[$section][$key];
}
}
@ -191,15 +173,20 @@ class configuration
}
}
// support for old config file format, before the fork was renamed
// support for old config file format, before the fork was renamed and PSR-4 introduced
$this->_configuration['model']['class'] = str_replace(
'zerobin_', 'privatebin_',
$this->_configuration['model']['class']
);
$this->_configuration['model']['class'] = str_replace(
array('privatebin_data', 'privatebin_db'),
array('PrivateBin\\data\\data', 'PrivateBin\\data\\db'),
$this->_configuration['model']['class']
);
// ensure a valid expire default key is set
if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options']))
{
if (!array_key_exists($this->_configuration['expire']['default'], $this->_configuration['expire_options'])) {
$this->_configuration['expire']['default'] = key($this->_configuration['expire_options']);
}
}
@ -235,8 +222,7 @@ class configuration
public function getKey($key, $section = 'main')
{
$options = $this->getSection($section);
if (!array_key_exists($key, $options))
{
if (!array_key_exists($key, $options)) {
throw new Exception(i18n::_('Invalid data.') . " $section / $key", 4);
}
return $this->_configuration[$section][$key];
@ -251,8 +237,7 @@ class configuration
*/
public function getSection($section)
{
if (!array_key_exists($section, $this->_configuration))
{
if (!array_key_exists($section, $this->_configuration)) {
throw new Exception(i18n::_('PrivateBin requires configuration section [%s] to be present in configuration file.', $section), 3);
}
return $this->_configuration[$section];

View file

@ -10,12 +10,14 @@
* @version 0.22
*/
namespace PrivateBin\data;
/**
* privatebin_abstract
*
* Abstract model for PrivateBin data access, implemented as a singleton.
*/
abstract class privatebin_abstract
abstract class AbstractData
{
/**
* singleton instance
@ -33,7 +35,9 @@ abstract class privatebin_abstract
*
* @access protected
*/
protected function __construct() {}
protected function __construct()
{
}
/**
* enforce singleton, disable cloning
@ -42,7 +46,9 @@ abstract class privatebin_abstract
*
* @access private
*/
private function __clone() {}
private function __clone()
{
}
/**
* get instance of singleton
@ -52,7 +58,9 @@ abstract class privatebin_abstract
* @param array $options
* @return privatebin_abstract
*/
public static function getInstance($options) {}
public static function getInstance($options)
{
}
/**
* Create a paste.
@ -141,12 +149,12 @@ abstract class privatebin_abstract
*/
public function purge($batchsize)
{
if ($batchsize < 1) return;
if ($batchsize < 1) {
return;
}
$pastes = $this->_getExpiredPastes($batchsize);
if (count($pastes))
{
foreach ($pastes as $pasteid)
{
if (count($pastes)) {
foreach ($pastes as $pasteid) {
$this->delete($pasteid);
}
}
@ -162,10 +170,11 @@ abstract class privatebin_abstract
*/
protected function getOpenSlot(&$comments, $postdate)
{
if (array_key_exists($postdate, $comments))
{
if (array_key_exists($postdate, $comments)) {
$parts = explode('.', $postdate, 2);
if (!array_key_exists(1, $parts)) $parts[1] = 0;
if (!array_key_exists(1, $parts)) {
$parts[1] = 0;
}
++$parts[1];
return $this->getOpenSlot($comments, implode('.', $parts));
}

View file

@ -10,12 +10,14 @@
* @version 0.22
*/
namespace PrivateBin\data;
/**
* privatebin_data
*
* Model for data access, implemented as a singleton.
*/
class privatebin_data extends privatebin_abstract
class data extends AbstractData
{
/**
* directory where data is stored
@ -40,7 +42,9 @@ class privatebin_data extends privatebin_abstract
if (
is_array($options) &&
array_key_exists('dir', $options)
) self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
) {
self::$_dir = $options['dir'] . DIRECTORY_SEPARATOR;
}
// if needed initialize the singleton
if (!(self::$_instance instanceof privatebin_data)) {
self::$_instance = new self;
@ -60,8 +64,12 @@ class privatebin_data extends privatebin_abstract
public function create($pasteid, $paste)
{
$storagedir = self::_dataid2path($pasteid);
if (is_file($storagedir . $pasteid)) return false;
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
if (is_file($storagedir . $pasteid)) {
return false;
}
if (!is_dir($storagedir)) {
mkdir($storagedir, 0705, true);
}
return (bool) @file_put_contents($storagedir . $pasteid, json_encode($paste));
}
@ -74,16 +82,16 @@ class privatebin_data extends privatebin_abstract
*/
public function read($pasteid)
{
if (!$this->exists($pasteid)) return false;
if (!$this->exists($pasteid)) {
return false;
}
$paste = json_decode(
file_get_contents(self::_dataid2path($pasteid) . $pasteid)
);
if (property_exists($paste->meta, 'attachment'))
{
if (property_exists($paste->meta, 'attachment')) {
$paste->attachment = $paste->meta->attachment;
unset($paste->meta->attachment);
if (property_exists($paste->meta, 'attachmentname'))
{
if (property_exists($paste->meta, 'attachmentname')) {
$paste->attachmentname = $paste->meta->attachmentname;
unset($paste->meta->attachmentname);
}
@ -105,13 +113,13 @@ class privatebin_data extends privatebin_abstract
// Delete discussion if it exists.
$discdir = self::_dataid2discussionpath($pasteid);
if (is_dir($discdir))
{
if (is_dir($discdir)) {
// Delete all files in discussion directory
$dir = dir($discdir);
while (false !== ($filename = $dir->read()))
{
if (is_file($discdir . $filename)) @unlink($discdir . $filename);
while (false !== ($filename = $dir->read())) {
if (is_file($discdir . $filename)) {
@unlink($discdir . $filename);
}
}
$dir->close();
@ -146,8 +154,12 @@ class privatebin_data extends privatebin_abstract
{
$storagedir = self::_dataid2discussionpath($pasteid);
$filename = $pasteid . '.' . $commentid . '.' . $parentid;
if (is_file($storagedir . $filename)) return false;
if (!is_dir($storagedir)) mkdir($storagedir, 0705, true);
if (is_file($storagedir . $filename)) {
return false;
}
if (!is_dir($storagedir)) {
mkdir($storagedir, 0705, true);
}
return (bool) @file_put_contents($storagedir . $filename, json_encode($comment));
}
@ -162,18 +174,15 @@ class privatebin_data extends privatebin_abstract
{
$comments = array();
$discdir = self::_dataid2discussionpath($pasteid);
if (is_dir($discdir))
{
if (is_dir($discdir)) {
// Delete all files in discussion directory
$dir = dir($discdir);
while (false !== ($filename = $dir->read()))
{
while (false !== ($filename = $dir->read())) {
// Filename is in the form pasteid.commentid.parentid:
// - pasteid is the paste this reply belongs to.
// - commentid is the comment identifier itself.
// - parentid is the comment this comment replies to (It can be pasteid)
if (is_file($discdir . $filename))
{
if (is_file($discdir . $filename)) {
$comment = json_decode(file_get_contents($discdir . $filename));
$items = explode('.', $filename);
// Add some meta information not contained in file.
@ -224,11 +233,9 @@ class privatebin_data extends privatebin_abstract
scandir(self::$_dir),
array('self', '_isFirstLevelDir')
);
if (count($firstLevel) > 0)
{
if (count($firstLevel) > 0) {
// try at most 10 times the $batchsize pastes before giving up
for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i)
{
for ($i = 0, $max = $batchsize * 10; $i < $max; ++$i) {
$firstKey = array_rand($firstLevel);
$secondLevel = array_filter(
scandir(self::$_dir . $firstLevel[$firstKey]),
@ -236,8 +243,7 @@ class privatebin_data extends privatebin_abstract
);
// skip this folder in the next checks if it is empty
if (count($secondLevel) == 0)
{
if (count($secondLevel) == 0) {
unset($firstLevel[$firstKey]);
continue;
}
@ -245,26 +251,32 @@ class privatebin_data extends privatebin_abstract
$secondKey = array_rand($secondLevel);
$path = self::$_dir . $firstLevel[$firstKey] .
DIRECTORY_SEPARATOR . $secondLevel[$secondKey];
if (!is_dir($path)) continue;
if (!is_dir($path)) {
continue;
}
$thirdLevel = array_filter(
scandir($path),
array('model_paste', 'isValidId')
array('PrivateBin\\model\\paste', 'isValidId')
);
if (count($thirdLevel) == 0) continue;
if (count($thirdLevel) == 0) {
continue;
}
$thirdKey = array_rand($thirdLevel);
$pasteid = $thirdLevel[$thirdKey];
if (in_array($pasteid, $pastes)) continue;
if (in_array($pasteid, $pastes)) {
continue;
}
if ($this->exists($pasteid))
{
if ($this->exists($pasteid)) {
$data = $this->read($pasteid);
if (
property_exists($data->meta, 'expire_date') &&
$data->meta->expire_date < time()
)
{
) {
$pastes[] = $pasteid;
if (count($pastes) >= $batchsize) break;
if (count($pastes) >= $batchsize) {
break;
}
}
}
}
@ -282,10 +294,11 @@ class privatebin_data extends privatebin_abstract
private static function _init()
{
// Create storage directory if it does not exist.
if (!is_dir(self::$_dir)) mkdir(self::$_dir, 0705);
if (!is_dir(self::$_dir)) {
mkdir(self::$_dir, 0705);
}
// Create .htaccess file if it does not exist.
if (!is_file(self::$_dir . '.htaccess'))
{
if (!is_file(self::$_dir . '.htaccess')) {
file_put_contents(
self::$_dir . '.htaccess',
'Allow from none' . PHP_EOL .

View file

@ -10,12 +10,20 @@
* @version 0.22
*/
namespace PrivateBin\data;
use Exception;
use PDO;
use PDOException;
use PrivateBin\privatebin;
use stdClass;
/**
* privatebin_db
*
* Model for DB access, implemented as a singleton.
*/
class privatebin_db extends privatebin_abstract
class db extends AbstractData
{
/**
* cache for select queries
@ -63,14 +71,15 @@ class privatebin_db extends privatebin_abstract
public static function getInstance($options = null)
{
// if needed initialize the singleton
if(!(self::$_instance instanceof privatebin_db)) {
if (!(self::$_instance instanceof privatebin_db)) {
self::$_instance = new self;
}
if (is_array($options))
{
if (is_array($options)) {
// set table prefix if given
if (array_key_exists('tbl', $options)) self::$_prefix = $options['tbl'];
if (array_key_exists('tbl', $options)) {
self::$_prefix = $options['tbl'];
}
// initialize the db connection with new options
if (
@ -78,8 +87,7 @@ class privatebin_db extends privatebin_abstract
array_key_exists('usr', $options) &&
array_key_exists('pwd', $options) &&
array_key_exists('opt', $options)
)
{
) {
// set default options
$options['opt'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$options['opt'][PDO::ATTR_EMULATE_PREPARES] = false;
@ -102,40 +110,34 @@ class privatebin_db extends privatebin_abstract
$tables = self::$_db->query($tableQuery)->fetchAll(PDO::FETCH_COLUMN, 0);
// create paste table if necessary
if (!in_array(self::_sanitizeIdentifier('paste'), $tables))
{
if (!in_array(self::_sanitizeIdentifier('paste'), $tables)) {
self::_createPasteTable();
$db_tables_exist = false;
}
// create comment table if necessary
if (!in_array(self::_sanitizeIdentifier('comment'), $tables))
{
if (!in_array(self::_sanitizeIdentifier('comment'), $tables)) {
self::_createCommentTable();
$db_tables_exist = false;
}
// create config table if necessary
$db_version = privatebin::VERSION;
if (!in_array(self::_sanitizeIdentifier('config'), $tables))
{
if (!in_array(self::_sanitizeIdentifier('config'), $tables)) {
self::_createConfigTable();
// if we only needed to create the config table, the DB is older then 0.22
if ($db_tables_exist) $db_version = '0.21';
}
else
{
if ($db_tables_exist) {
$db_version = '0.21';
}
} else {
$db_version = self::_getConfig('VERSION');
}
// update database structure if necessary
if (version_compare($db_version, privatebin::VERSION, '<'))
{
if (version_compare($db_version, privatebin::VERSION, '<')) {
self::_upgradeDatabase($db_version);
}
}
else
{
} else {
throw new Exception(
'Missing configuration for key dsn, usr, pwd or opt in the section model_options, please check your configuration file', 6
);
@ -158,7 +160,7 @@ class privatebin_db extends privatebin_abstract
if (
array_key_exists($pasteid, self::$_cache)
) {
if(false !== self::$_cache[$pasteid]) {
if (false !== self::$_cache[$pasteid]) {
return false;
} else {
unset(self::$_cache[$pasteid]);
@ -170,28 +172,23 @@ class privatebin_db extends privatebin_abstract
$meta = $paste['meta'];
unset($meta['postdate']);
$expire_date = 0;
if (array_key_exists('expire_date', $paste['meta']))
{
if (array_key_exists('expire_date', $paste['meta'])) {
$expire_date = (int) $paste['meta']['expire_date'];
unset($meta['expire_date']);
}
if (array_key_exists('opendiscussion', $paste['meta']))
{
if (array_key_exists('opendiscussion', $paste['meta'])) {
$opendiscussion = (bool) $paste['meta']['opendiscussion'];
unset($meta['opendiscussion']);
}
if (array_key_exists('burnafterreading', $paste['meta']))
{
if (array_key_exists('burnafterreading', $paste['meta'])) {
$burnafterreading = (bool) $paste['meta']['burnafterreading'];
unset($meta['burnafterreading']);
}
if (array_key_exists('attachment', $paste['meta']))
{
if (array_key_exists('attachment', $paste['meta'])) {
$attachment = $paste['meta']['attachment'];
unset($meta['attachment']);
}
if (array_key_exists('attachmentname', $paste['meta']))
{
if (array_key_exists('attachmentname', $paste['meta'])) {
$attachmentname = $paste['meta']['attachmentname'];
unset($meta['attachmentname']);
}
@ -230,31 +227,29 @@ class privatebin_db extends privatebin_abstract
' WHERE dataid = ?', array($pasteid), true
);
if(false !== $paste) {
if (false !== $paste) {
// create object
self::$_cache[$pasteid] = new stdClass;
self::$_cache[$pasteid]->data = $paste['data'];
$meta = json_decode($paste['meta']);
if (!is_object($meta)) $meta = new stdClass;
if (!is_object($meta)) {
$meta = new stdClass;
}
// support older attachments
if (property_exists($meta, 'attachment'))
{
if (property_exists($meta, 'attachment')) {
self::$_cache[$pasteid]->attachment = $meta->attachment;
unset($meta->attachment);
if (property_exists($meta, 'attachmentname'))
{
if (property_exists($meta, 'attachmentname')) {
self::$_cache[$pasteid]->attachmentname = $meta->attachmentname;
unset($meta->attachmentname);
}
}
// support current attachments
elseif (array_key_exists('attachment', $paste) && strlen($paste['attachment']))
{
elseif (array_key_exists('attachment', $paste) && strlen($paste['attachment'])) {
self::$_cache[$pasteid]->attachment = $paste['attachment'];
if (array_key_exists('attachmentname', $paste) && strlen($paste['attachmentname']))
{
if (array_key_exists('attachmentname', $paste) && strlen($paste['attachmentname'])) {
self::$_cache[$pasteid]->attachmentname = $paste['attachmentname'];
}
}
@ -263,13 +258,19 @@ class privatebin_db extends privatebin_abstract
$expire_date = (int) $paste['expiredate'];
if (
$expire_date > 0
) self::$_cache[$pasteid]->meta->expire_date = $expire_date;
) {
self::$_cache[$pasteid]->meta->expire_date = $expire_date;
}
if (
$paste['opendiscussion']
) self::$_cache[$pasteid]->meta->opendiscussion = true;
) {
self::$_cache[$pasteid]->meta->opendiscussion = true;
}
if (
$paste['burnafterreading']
) self::$_cache[$pasteid]->meta->burnafterreading = true;
) {
self::$_cache[$pasteid]->meta->burnafterreading = true;
}
}
}
@ -295,7 +296,9 @@ class privatebin_db extends privatebin_abstract
);
if (
array_key_exists($pasteid, self::$_cache)
) unset(self::$_cache[$pasteid]);
) {
unset(self::$_cache[$pasteid]);
}
}
/**
@ -309,7 +312,9 @@ class privatebin_db extends privatebin_abstract
{
if (
!array_key_exists($pasteid, self::$_cache)
) self::$_cache[$pasteid] = $this->read($pasteid);
) {
self::$_cache[$pasteid] = $this->read($pasteid);
}
return (bool) self::$_cache[$pasteid];
}
@ -325,10 +330,8 @@ class privatebin_db extends privatebin_abstract
*/
public function createComment($pasteid, $parentid, $commentid, $comment)
{
foreach (array('nickname', 'vizhash') as $key)
{
if (!array_key_exists($key, $comment['meta']))
{
foreach (array('nickname', 'vizhash') as $key) {
if (!array_key_exists($key, $comment['meta'])) {
$comment['meta'][$key] = null;
}
}
@ -363,10 +366,8 @@ class privatebin_db extends privatebin_abstract
// create comment list
$comments = array();
if (count($rows))
{
foreach ($rows as $row)
{
if (count($rows)) {
foreach ($rows as $row) {
$i = $this->getOpenSlot($comments, (int) $row['postdate']);
$comments[$i] = new stdClass;
$comments[$i]->id = $row['dataid'];
@ -374,10 +375,12 @@ class privatebin_db extends privatebin_abstract
$comments[$i]->data = $row['data'];
$comments[$i]->meta = new stdClass;
$comments[$i]->meta->postdate = (int) $row['postdate'];
if (array_key_exists('nickname', $row) && !empty($row['nickname']))
if (array_key_exists('nickname', $row) && !empty($row['nickname'])) {
$comments[$i]->meta->nickname = $row['nickname'];
if (array_key_exists('vizhash', $row) && !empty($row['vizhash']))
}
if (array_key_exists('vizhash', $row) && !empty($row['vizhash'])) {
$comments[$i]->meta->vizhash = $row['vizhash'];
}
}
ksort($comments);
}
@ -416,10 +419,8 @@ class privatebin_db extends privatebin_abstract
'SELECT dataid FROM ' . self::_sanitizeIdentifier('paste') .
' WHERE expiredate < ? LIMIT ?', array(time(), $batchsize)
);
if (count($rows))
{
foreach ($rows as $row)
{
if (count($rows)) {
foreach ($rows as $row) {
$pastes[] = $row['dataid'];
}
}
@ -477,8 +478,7 @@ class privatebin_db extends privatebin_abstract
*/
private static function _getTableQuery($type)
{
switch($type)
{
switch ($type) {
case 'ibm':
$sql = 'SELECT tabname FROM SYSCAT.TABLES ';
break;
@ -551,12 +551,9 @@ class privatebin_db extends privatebin_abstract
private static function _getPrimaryKeyClauses($key = 'dataid')
{
$main_key = $after_key = '';
if (self::$_type === 'mysql')
{
if (self::$_type === 'mysql') {
$after_key = ", PRIMARY KEY ($key)";
}
else
{
} else {
$main_key = ' PRIMARY KEY';
}
return array($main_key, $after_key);
@ -659,8 +656,7 @@ class privatebin_db extends privatebin_abstract
private static function _upgradeDatabase($oldversion)
{
$dataType = self::$_type === 'pgsql' ? 'TEXT' : 'BLOB';
switch ($oldversion)
{
switch ($oldversion) {
case '0.21':
// create the meta column if necessary (pre 0.21 change)
try {
@ -679,8 +675,7 @@ class privatebin_db extends privatebin_abstract
);
// SQLite doesn't support MODIFY, but it allows TEXT of similar
// size as BLOB, so there is no need to change it there
if (self::$_type !== 'sqlite')
{
if (self::$_type !== 'sqlite') {
self::$_db->exec(
'ALTER TABLE ' . self::_sanitizeIdentifier('paste') .
' ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType;'
@ -690,9 +685,7 @@ class privatebin_db extends privatebin_abstract
" ADD PRIMARY KEY (dataid), MODIFY COLUMN data $dataType, " .
"MODIFY COLUMN nickname $dataType, MODIFY COLUMN vizhash $dataType;"
);
}
else
{
} else {
self::$_db->exec(
'CREATE UNIQUE INDEX IF NOT EXISTS paste_dataid ON ' .
self::_sanitizeIdentifier('paste') . '(dataid);'

View file

@ -10,6 +10,11 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
use PrivateBin\i18n;
/**
* filter
*
@ -28,7 +33,7 @@ class filter
public static function stripslashes_deep($value)
{
return is_array($value) ?
array_map('filter::stripslashes_deep', $value) :
array_map('PrivateBin\\filter::stripslashes_deep', $value) :
stripslashes($value);
}
@ -73,9 +78,9 @@ class filter
{
$iec = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
$i = 0;
while ( ( $size / 1024 ) >= 1 ) {
$size = $size / 1024;
$i++;
while (($size / 1024) >= 1) {
$size = $size / 1024;
$i++;
}
return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . i18n::_($iec[$i]);
}
@ -93,10 +98,9 @@ class filter
public static function slow_equals($a, $b)
{
$diff = strlen($a) ^ strlen($b);
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++)
{
for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
$diff |= ord($a[$i]) ^ ord($b[$i]);
}
return $diff === 0;
}
}
}

View file

@ -10,6 +10,8 @@
* @version 0.22
*/
namespace PrivateBin;
/**
* i18n
*
@ -82,7 +84,7 @@ class i18n
*/
public static function _($messageId)
{
return call_user_func_array(array('i18n', 'translate'), func_get_args());
return call_user_func_array(array('self', 'translate'), func_get_args());
}
/**
@ -96,30 +98,31 @@ class i18n
*/
public static function translate($messageId)
{
if (empty($messageId)) return $messageId;
if (count(self::$_translations) === 0) self::loadTranslations();
if (empty($messageId)) {
return $messageId;
}
if (count(self::$_translations) === 0) {
self::loadTranslations();
}
$messages = $messageId;
if (is_array($messageId))
{
if (is_array($messageId)) {
$messageId = count($messageId) > 1 ? $messageId[1] : $messageId[0];
}
if (!array_key_exists($messageId, self::$_translations))
{
if (!array_key_exists($messageId, self::$_translations)) {
self::$_translations[$messageId] = $messages;
}
$args = func_get_args();
if (is_array(self::$_translations[$messageId]))
{
if (is_array(self::$_translations[$messageId])) {
$number = (int) $args[1];
$key = self::_getPluralForm($number);
$max = count(self::$_translations[$messageId]) - 1;
if ($key > $max) $key = $max;
if ($key > $max) {
$key = $max;
}
$args[0] = self::$_translations[$messageId][$key];
$args[1] = $number;
}
else
{
} else {
$args[0] = self::$_translations[$messageId];
}
return call_user_func_array('sprintf', $args);
@ -139,13 +142,11 @@ class i18n
$availableLanguages = self::getAvailableLanguages();
// check if the lang cookie was set and that language exists
if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages))
{
if (array_key_exists('lang', $_COOKIE) && in_array($_COOKIE['lang'], $availableLanguages)) {
$match = $availableLanguages[array_search($_COOKIE['lang'], $availableLanguages)];
}
// find a translation file matching the browsers language preferences
else
{
else {
$match = self::_getMatchingLanguage(
self::getBrowserLanguages(), $availableLanguages
);
@ -168,13 +169,10 @@ class i18n
*/
public static function getAvailableLanguages()
{
if (count(self::$_availableLanguages) == 0)
{
if (count(self::$_availableLanguages) == 0) {
$i18n = dir(self::_getPath());
while (false !== ($file = $i18n->read()))
{
if (preg_match('/^([a-z]{2}).json$/', $file, $match) === 1)
{
while (false !== ($file = $i18n->read())) {
if (preg_match('/^([a-z]{2}).json$/', $file, $match) === 1) {
self::$_availableLanguages[] = $match[1];
}
}
@ -195,26 +193,19 @@ class i18n
public static function getBrowserLanguages()
{
$languages = array();
if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER))
{
if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
$languageRanges = explode(',', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']));
foreach ($languageRanges as $languageRange)
{
foreach ($languageRanges as $languageRange) {
if (preg_match(
'/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/',
trim($languageRange), $match
))
{
if (!isset($match[2]))
{
)) {
if (!isset($match[2])) {
$match[2] = '1.0';
}
else
{
} else {
$match[2] = (string) floatval($match[2]);
}
if (!isset($languages[$match[2]]))
{
if (!isset($languages[$match[2]])) {
$languages[$match[2]] = array();
}
$languages[$match[2]][] = strtolower($match[1]);
@ -250,11 +241,12 @@ class i18n
public static function getLanguageLabels($languages = array())
{
$file = self::_getPath('languages.json');
if (count(self::$_languageLabels) == 0 && is_readable($file))
{
if (count(self::$_languageLabels) == 0 && is_readable($file)) {
self::$_languageLabels = json_decode(file_get_contents($file), true);
}
if (count($languages) == 0) return self::$_languageLabels;
if (count($languages) == 0) {
return self::$_languageLabels;
}
return array_intersect_key(self::$_languageLabels, array_flip($languages));
}
@ -268,8 +260,9 @@ class i18n
*/
public static function setLanguageFallback($lang)
{
if (in_array($lang, self::getAvailableLanguages()))
if (in_array($lang, self::getAvailableLanguages())) {
self::$_languageFallback = $lang;
}
}
/**
@ -282,8 +275,7 @@ class i18n
*/
protected static function _getPath($file = '')
{
if (strlen(self::$_path) == 0)
{
if (strlen(self::$_path) == 0) {
self::$_path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'i18n';
}
return self::$_path . (strlen($file) ? DIRECTORY_SEPARATOR . $file : '');
@ -324,47 +316,40 @@ class i18n
* @param array $availableLanguages
* @return string
*/
protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages) {
protected static function _getMatchingLanguage($acceptedLanguages, $availableLanguages)
{
$matches = array();
$any = false;
foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues)
{
foreach ($acceptedLanguages as $acceptedQuality => $acceptedValues) {
$acceptedQuality = floatval($acceptedQuality);
if ($acceptedQuality === 0.0) continue;
foreach ($availableLanguages as $availableValue)
{
if ($acceptedQuality === 0.0) {
continue;
}
foreach ($availableLanguages as $availableValue) {
$availableQuality = 1.0;
foreach ($acceptedValues as $acceptedValue)
{
if ($acceptedValue === '*')
{
foreach ($acceptedValues as $acceptedValue) {
if ($acceptedValue === '*') {
$any = true;
}
$matchingGrade = self::_matchLanguage($acceptedValue, $availableValue);
if ($matchingGrade > 0)
{
if ($matchingGrade > 0) {
$q = (string) ($acceptedQuality * $availableQuality * $matchingGrade);
if (!isset($matches[$q]))
{
if (!isset($matches[$q])) {
$matches[$q] = array();
}
if (!in_array($availableValue, $matches[$q]))
{
if (!in_array($availableValue, $matches[$q])) {
$matches[$q][] = $availableValue;
}
}
}
}
}
if (count($matches) === 0 && $any)
{
if (count($availableLanguages) > 0)
{
if (count($matches) === 0 && $any) {
if (count($availableLanguages) > 0) {
$matches['1.0'] = $availableLanguages;
}
}
if (count($matches) === 0)
{
if (count($matches) === 0) {
return self::$_languageFallback;
}
krsort($matches);
@ -383,12 +368,14 @@ class i18n
* @param string $b
* @return float
*/
protected static function _matchLanguage($a, $b) {
protected static function _matchLanguage($a, $b)
{
$a = explode('-', $a);
$b = explode('-', $b);
for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i)
{
if ($a[$i] !== $b[$i]) break;
for ($i=0, $n = min(count($a), count($b)); $i < $n; ++$i) {
if ($a[$i] !== $b[$i]) {
break;
}
}
return $i === 0 ? 0 : (float) $i / count($a);
}

View file

@ -10,6 +10,10 @@
* @version 0.22
*/
namespace PrivateBin;
use PrivateBin\model\paste;
/**
* model
*
@ -50,8 +54,10 @@ class model
*/
public function getPaste($pasteId = null)
{
$paste = new model_paste($this->_conf, $this->_getStore());
if ($pasteId !== null) $paste->setId($pasteId);
$paste = new paste($this->_conf, $this->_getStore());
if ($pasteId !== null) {
$paste->setId($pasteId);
}
return $paste;
}
@ -63,8 +69,7 @@ class model
public function purge()
{
purgelimiter::setConfiguration($this->_conf);
if (purgelimiter::canPurge())
{
if (purgelimiter::canPurge()) {
$this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
}
}
@ -76,8 +81,7 @@ class model
*/
private function _getStore()
{
if ($this->_store === null)
{
if ($this->_store === null) {
$this->_store = forward_static_call(
array($this->_conf->getKey('class', 'model'), 'getInstance'),
$this->_conf->getSection('model_options')

View file

@ -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;
@ -86,7 +94,9 @@ abstract class model_abstract
*/
public function setId($id)
{
if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 60);
if (!self::isValidId($id)) {
throw new Exception('Invalid paste ID.', 60);
}
$this->_id = $id;
}
@ -100,7 +110,9 @@ abstract class model_abstract
*/
public function setData($data)
{
if (!sjcl::isValid($data)) throw new Exception('Invalid data.', 61);
if (!sjcl::isValid($data)) {
throw new Exception('Invalid data.', 61);
}
$this->_data->data = $data;
// We just want a small hash to avoid collisions:

View file

@ -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.
@ -59,16 +66,19 @@ class model_comment extends model_abstract
{
// Make sure paste exists.
$pasteid = $this->getPaste()->getId();
if (!$this->getPaste()->exists())
if (!$this->getPaste()->exists()) {
throw new Exception('Invalid data.', 67);
}
// Make sure the discussion is opened in this paste and in configuration.
if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion'))
if (!$this->getPaste()->isOpendiscussion() || !$this->_conf->getKey('discussion')) {
throw new Exception('Invalid data.', 68);
}
// Check for improbable collision.
if ($this->exists())
if ($this->exists()) {
throw new Exception('You are unlucky. Try again.', 69);
}
$this->_data->meta->postdate = time();
@ -80,7 +90,9 @@ class model_comment extends model_abstract
$this->getId(),
json_decode(json_encode($this->_data), true)
) === false
) throw new Exception('Error saving comment. Sorry.', 70);
) {
throw new Exception('Error saving comment. Sorry.', 70);
}
}
/**
@ -118,7 +130,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();
@ -145,7 +157,9 @@ class model_comment extends model_abstract
*/
public function setParentId($id)
{
if (!self::isValidId($id)) throw new Exception('Invalid paste ID.', 65);
if (!self::isValidId($id)) {
throw new Exception('Invalid paste ID.', 65);
}
$this->_data->meta->parentid = $id;
}
@ -157,7 +171,9 @@ class model_comment extends model_abstract
*/
public function getParentId()
{
if (!property_exists($this->_data->meta, 'parentid')) $this->_data->meta->parentid = '';
if (!property_exists($this->_data->meta, 'parentid')) {
$this->_data->meta->parentid = '';
}
return $this->_data->meta->parentid;
}
@ -171,19 +187,19 @@ class model_comment extends model_abstract
*/
public function setNickname($nickname)
{
if (!sjcl::isValid($nickname)) throw new Exception('Invalid data.', 66);
if (!sjcl::isValid($nickname)) {
throw new Exception('Invalid data.', 66);
}
$this->_data->meta->nickname = $nickname;
if ($this->_conf->getKey('vizhash'))
{
if ($this->_conf->getKey('vizhash')) {
// Generation of the anonymous avatar (Vizhash):
// If a nickname is provided, we generate a Vizhash.
// (We assume that if the user did not enter a nickname, he/she wants
// to be anonymous and we will not generate the vizhash.)
$vh = new vizhash16x16();
$pngdata = $vh->generate(trafficlimiter::getIp());
if ($pngdata != '')
{
if ($pngdata != '') {
$this->_data->meta->vizhash = 'data:image/png;base64,' . base64_encode($pngdata);
}
// Once the avatar is generated, we do not keep the IP address, nor its hash.

View file

@ -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.
@ -27,13 +34,13 @@ class model_paste extends model_abstract
public function get()
{
$this->_data = $this->_store->read($this->getId());
if ($this->_data === false) throw new Exception(privatebin::GENERIC_ERROR, 64);
if ($this->_data === false) {
throw new Exception(privatebin::GENERIC_ERROR, 64);
}
// check if paste has expired and delete it if neccessary.
if (property_exists($this->_data->meta, 'expire_date'))
{
if ($this->_data->meta->expire_date < time())
{
if (property_exists($this->_data->meta, 'expire_date')) {
if ($this->_data->meta->expire_date < time()) {
$this->delete();
throw new Exception(privatebin::GENERIC_ERROR, 63);
}
@ -42,22 +49,17 @@ class model_paste extends model_abstract
}
// set formatter for for the view.
if (!property_exists($this->_data->meta, 'formatter'))
{
if (!property_exists($this->_data->meta, 'formatter')) {
// support < 0.21 syntax highlighting
if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true)
{
if (property_exists($this->_data->meta, 'syntaxcoloring') && $this->_data->meta->syntaxcoloring === true) {
$this->_data->meta->formatter = 'syntaxhighlighting';
}
else
{
} else {
$this->_data->meta->formatter = $this->_conf->getKey('defaultformatter');
}
}
// support old paste format with server wide salt
if (!property_exists($this->_data->meta, 'salt'))
{
if (!property_exists($this->_data->meta, 'salt')) {
$this->_data->meta->salt = serversalt::get();
}
$this->_data->comments = array_values($this->getComments());
@ -77,8 +79,9 @@ class model_paste extends model_abstract
public function store()
{
// Check for improbable collision.
if ($this->exists())
if ($this->exists()) {
throw new Exception('You are unlucky. Try again.', 75);
}
$this->_data->meta->postdate = time();
$this->_data->meta->salt = serversalt::generate();
@ -89,7 +92,9 @@ class model_paste extends model_abstract
$this->getId(),
json_decode(json_encode($this->_data), true)
) === false
) throw new Exception('Error saving paste. Sorry.', 76);
) {
throw new Exception('Error saving paste. Sorry.', 76);
}
}
/**
@ -126,14 +131,15 @@ class model_paste extends model_abstract
*/
public function getComment($parentId, $commentId = null)
{
if (!$this->exists())
{
if (!$this->exists()) {
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);
if ($commentId !== null) {
$comment->setId($commentId);
}
return $comment;
}
@ -160,7 +166,9 @@ class model_paste extends model_abstract
*/
public function getDeleteToken()
{
if (!property_exists($this->_data->meta, 'salt')) $this->get();
if (!property_exists($this->_data->meta, 'salt')) {
$this->get();
}
return hash_hmac(
$this->_conf->getKey('zerobincompatibility') ? 'sha1' : 'sha256',
$this->getId(),
@ -178,8 +186,9 @@ class model_paste extends model_abstract
*/
public function setAttachment($attachment)
{
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment))
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachment)) {
throw new Exception('Invalid attachment.', 71);
}
$this->_data->meta->attachment = $attachment;
}
@ -193,8 +202,9 @@ class model_paste extends model_abstract
*/
public function setAttachmentName($attachmentname)
{
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname))
if (!$this->_conf->getKey('fileupload') || !sjcl::isValid($attachmentname)) {
throw new Exception('Invalid attachment.', 72);
}
$this->_data->meta->attachmentname = $attachmentname;
}
@ -208,16 +218,15 @@ class model_paste extends model_abstract
public function setExpiration($expiration)
{
$expire_options = $this->_conf->getSection('expire_options');
if (array_key_exists($expiration, $expire_options))
{
if (array_key_exists($expiration, $expire_options)) {
$expire = $expire_options[$expiration];
}
else
{
} else {
// using getKey() to ensure a default value is present
$expire = $this->_conf->getKey($this->_conf->getKey('default', 'expire'), 'expire_options');
}
if ($expire > 0) $this->_data->meta->expire_date = time() + $expire;
if ($expire > 0) {
$this->_data->meta->expire_date = time() + $expire;
}
}
/**
@ -230,14 +239,12 @@ class model_paste extends model_abstract
*/
public function setBurnafterreading($burnafterreading = '1')
{
if ($burnafterreading === '0')
{
if ($burnafterreading === '0') {
$this->_data->meta->burnafterreading = false;
}
else
{
if ($burnafterreading !== '1')
} else {
if ($burnafterreading !== '1') {
throw new Exception('Invalid data.', 73);
}
$this->_data->meta->burnafterreading = true;
$this->_data->meta->opendiscussion = false;
}
@ -257,14 +264,12 @@ class model_paste extends model_abstract
!$this->_conf->getKey('discussion') ||
$this->isBurnafterreading() ||
$opendiscussion === '0'
)
{
) {
$this->_data->meta->opendiscussion = false;
}
else
{
if ($opendiscussion !== '1')
} else {
if ($opendiscussion !== '1') {
throw new Exception('Invalid data.', 74);
}
$this->_data->meta->opendiscussion = true;
}
}
@ -279,8 +284,7 @@ class model_paste extends model_abstract
*/
public function setFormatter($format)
{
if (!array_key_exists($format, $this->_conf->getSection('formatter_options')))
{
if (!array_key_exists($format, $this->_conf->getSection('formatter_options'))) {
$format = $this->_conf->getKey('defaultformatter');
}
$this->_data->meta->formatter = $format;
@ -295,7 +299,9 @@ class model_paste extends model_abstract
*/
public function isBurnafterreading()
{
if (!property_exists($this->_data, 'data')) $this->get();
if (!property_exists($this->_data, 'data')) {
$this->get();
}
return property_exists($this->_data->meta, 'burnafterreading') &&
$this->_data->meta->burnafterreading === true;
}
@ -310,7 +316,9 @@ class model_paste extends model_abstract
*/
public function isOpendiscussion()
{
if (!property_exists($this->_data, 'data')) $this->get();
if (!property_exists($this->_data, 'data')) {
$this->get();
}
return property_exists($this->_data->meta, 'opendiscussion') &&
$this->_data->meta->opendiscussion === true;
}

View file

@ -10,6 +10,10 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
/**
* persistence
*
@ -49,12 +53,9 @@ abstract class persistence
*/
public static function getPath($filename = null)
{
if (strlen($filename))
{
if (strlen($filename)) {
return self::$_path . DIRECTORY_SEPARATOR . $filename;
}
else
{
} else {
return self::$_path;
}
}
@ -84,14 +85,15 @@ abstract class persistence
protected static function _initialize()
{
// Create storage directory if it does not exist.
if (!is_dir(self::$_path))
if (!@mkdir(self::$_path))
if (!is_dir(self::$_path)) {
if (!@mkdir(self::$_path)) {
throw new Exception('unable to create directory ' . self::$_path, 10);
}
}
// Create .htaccess file if it does not exist.
$file = self::$_path . DIRECTORY_SEPARATOR . '.htaccess';
if (!is_file($file))
{
if (!is_file($file)) {
$writtenBytes = @file_put_contents(
$file,
'Allow from none' . PHP_EOL .
@ -119,8 +121,7 @@ abstract class persistence
self::_initialize();
$file = self::$_path . DIRECTORY_SEPARATOR . $filename;
$writtenBytes = @file_put_contents($file, $data, LOCK_EX);
if ($writtenBytes === false || $writtenBytes < strlen($data))
{
if ($writtenBytes === false || $writtenBytes < strlen($data)) {
throw new Exception('unable to write to file ' . $file, 13);
}
@chmod($file, 0640); // protect file access

View file

@ -10,6 +10,10 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
/**
* privatebin
*
@ -113,16 +117,14 @@ class privatebin
*/
public function __construct()
{
if (version_compare(PHP_VERSION, '5.2.6') < 0)
{
throw new Exception(i18n::_('PrivateBin requires php 5.2.6 or above to work. Sorry.'), 1);
if (version_compare(PHP_VERSION, '5.3.0') < 0) {
throw new Exception(i18n::_('PrivateBin requires php 5.3.0 or above to work. Sorry.'), 1);
}
// load config from ini file
$this->_init();
switch ($this->_request->getOperation())
{
switch ($this->_request->getOperation()) {
case 'create':
$this->_create();
break;
@ -141,16 +143,13 @@ class privatebin
}
// output JSON or HTML
if ($this->_request->isJsonApiCall())
{
if ($this->_request->isJsonApiCall()) {
header('Content-type: ' . request::MIME_JSON);
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
echo $this->_json;
}
else
{
} else {
$this->_view();
}
}
@ -163,14 +162,15 @@ class privatebin
*/
private function _init()
{
foreach (array('cfg', 'lib') as $dir)
{
if (!is_file(PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess')) file_put_contents(
foreach (array('cfg', 'lib') as $dir) {
if (!is_file(PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess')) {
file_put_contents(
PATH . $dir . DIRECTORY_SEPARATOR . '.htaccess',
'Allow from none' . PHP_EOL .
'Deny from all'. PHP_EOL,
LOCK_EX
);
}
}
$this->_conf = new configuration;
@ -183,8 +183,7 @@ class privatebin
$lang = $this->_conf->getKey('languagedefault');
i18n::setLanguageFallback($lang);
// force default language, if language selection is disabled and a default is set
if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2)
{
if (!$this->_conf->getKey('languageselection') && strlen($lang) == 2) {
$_COOKIE['lang'] = $lang;
setcookie('lang', $lang);
}
@ -214,12 +213,14 @@ class privatebin
{
// Ensure last paste from visitors IP address was more than configured amount of seconds ago.
trafficlimiter::setConfiguration($this->_conf);
if (!trafficlimiter::canPass()) return $this->_return_message(
if (!trafficlimiter::canPass()) {
return $this->_return_message(
1, i18n::_(
'Please wait %d seconds between each post.',
$this->_conf->getKey('limit', 'traffic')
)
);
}
$data = $this->_request->getParam('data');
$attachment = $this->_request->getParam('attachment');
@ -229,71 +230,78 @@ class privatebin
$sizelimit = $this->_conf->getKey('sizelimit');
if (
strlen($data) + strlen($attachment) + strlen($attachmentname) > $sizelimit
) return $this->_return_message(
) {
return $this->_return_message(
1,
i18n::_(
'Paste is limited to %s of encrypted data.',
filter::size_humanreadable($sizelimit)
)
);
}
// Ensure attachment did not get lost due to webserver limits or Suhosin
if (strlen($attachmentname) > 0 && strlen($attachment) == 0)
{
if (strlen($attachmentname) > 0 && strlen($attachment) == 0) {
return $this->_return_message(1, 'Attachment missing in data received by server. Please check your webserver or suhosin configuration for maximum POST parameter limitations.');
}
// The user posts a comment.
$pasteid = $this->_request->getParam('pasteid');
$parentid = $this->_request->getParam('parentid');
if (!empty($pasteid) && !empty($parentid))
{
if (!empty($pasteid) && !empty($parentid)) {
$paste = $this->_model->getPaste($pasteid);
if ($paste->exists()) {
try {
$comment = $paste->getComment($parentid);
$nickname = $this->_request->getParam('nickname');
if (!empty($nickname)) $comment->setNickname($nickname);
if (!empty($nickname)) {
$comment->setNickname($nickname);
}
$comment->setData($data);
$comment->store();
} catch(Exception $e) {
} catch (Exception $e) {
return $this->_return_message(1, $e->getMessage());
}
$this->_return_message(0, $comment->getId());
}
else
{
} else {
$this->_return_message(1, 'Invalid data.');
}
}
// The user posts a standard paste.
else
{
else {
$this->_model->purge();
$paste = $this->_model->getPaste();
try {
$paste->setData($data);
if (!empty($attachment))
{
if (!empty($attachment)) {
$paste->setAttachment($attachment);
if (!empty($attachmentname))
if (!empty($attachmentname)) {
$paste->setAttachmentName($attachmentname);
}
}
$expire = $this->_request->getParam('expire');
if (!empty($expire)) $paste->setExpiration($expire);
if (!empty($expire)) {
$paste->setExpiration($expire);
}
$burnafterreading = $this->_request->getParam('burnafterreading');
if (!empty($burnafterreading)) $paste->setBurnafterreading($burnafterreading);
if (!empty($burnafterreading)) {
$paste->setBurnafterreading($burnafterreading);
}
$opendiscussion = $this->_request->getParam('opendiscussion');
if (!empty($opendiscussion)) $paste->setOpendiscussion($opendiscussion);
if (!empty($opendiscussion)) {
$paste->setOpendiscussion($opendiscussion);
}
$formatter = $this->_request->getParam('formatter');
if (!empty($formatter)) $paste->setFormatter($formatter);
if (!empty($formatter)) {
$paste->setFormatter($formatter);
}
$paste->store();
} catch (Exception $e) {
@ -315,40 +323,28 @@ class privatebin
{
try {
$paste = $this->_model->getPaste($dataid);
if ($paste->exists())
{
if ($paste->exists()) {
// accessing this property ensures that the paste would be
// deleted if it has already expired
$burnafterreading = $paste->isBurnafterreading();
if ($deletetoken == 'burnafterreading')
{
if ($burnafterreading)
{
if ($deletetoken == 'burnafterreading') {
if ($burnafterreading) {
$paste->delete();
$this->_return_message(0, $dataid);
}
else
{
} else {
$this->_return_message(1, 'Paste is not of burn-after-reading type.');
}
}
else
{
} else {
// Make sure the token is valid.
if (filter::slow_equals($deletetoken, $paste->getDeleteToken()))
{
if (filter::slow_equals($deletetoken, $paste->getDeleteToken())) {
// Paste exists and deletion token is valid: Delete the paste.
$paste->delete();
$this->_status = 'Paste was properly deleted.';
}
else
{
} else {
$this->_error = 'Wrong deletion token. Paste was not deleted.';
}
}
}
else
{
} else {
$this->_error = self::GENERIC_ERROR;
}
} catch (Exception $e) {
@ -367,29 +363,24 @@ class privatebin
{
try {
$paste = $this->_model->getPaste($dataid);
if ($paste->exists())
{
if ($paste->exists()) {
$data = $paste->get();
$this->_doesExpire = property_exists($data, 'meta') && property_exists($data->meta, 'expire_date');
if (property_exists($data->meta, 'salt')) unset($data->meta->salt);
if (property_exists($data->meta, 'salt')) {
unset($data->meta->salt);
}
$this->_data = json_encode($data);
}
else
{
} else {
$this->_error = self::GENERIC_ERROR;
}
} catch (Exception $e) {
$this->_error = $e->getMessage();
}
if ($this->_request->isJsonApiCall())
{
if (strlen($this->_error))
{
if ($this->_request->isJsonApiCall()) {
if (strlen($this->_error)) {
$this->_return_message(1, $this->_error);
}
else
{
} else {
$this->_return_message(0, $dataid, json_decode($this->_data, true));
}
}
@ -413,18 +404,16 @@ class privatebin
// label all the expiration options
$expire = array();
foreach ($this->_conf->getSection('expire_options') as $time => $seconds)
{
foreach ($this->_conf->getSection('expire_options') as $time => $seconds) {
$expire[$time] = ($seconds == 0) ? i18n::_(ucfirst($time)): filter::time_humanreadable($time);
}
// 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 = '';
if ($this->_conf->getKey('languageselection'))
{
if ($this->_conf->getKey('languageselection')) {
$languageselection = i18n::getLanguage();
setcookie('lang', $languageselection);
}
@ -467,14 +456,12 @@ class privatebin
if (
$type !== 'paste' && $type !== 'comment' &&
$type !== 'pastemeta' && $type !== 'commentmeta'
)
{
) {
$type = '';
}
$content = '{}';
$file = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $type . '.jsonld';
if (is_readable($file))
{
if (is_readable($file)) {
$content = str_replace(
'?jsonld=',
$this->_urlbase . '?jsonld=',
@ -500,12 +487,9 @@ class privatebin
private function _return_message($status, $message, $other = array())
{
$result = array('status' => $status);
if ($status)
{
if ($status) {
$result['message'] = i18n::_($message);
}
else
{
} else {
$result['id'] = $message;
$result['url'] = $this->_urlbase . '?' . $message;
}

View file

@ -10,6 +10,8 @@
* @version 0.22
*/
namespace PrivateBin;
/**
* purgelimiter
*
@ -64,12 +66,13 @@ class purgelimiter extends persistence
public static function canPurge()
{
// disable limits if set to less then 1
if (self::$_limit < 1) return true;
if (self::$_limit < 1) {
return true;
}
$file = 'purge_limiter.php';
$now = time();
if (!self::_exists($file))
{
if (!self::_exists($file)) {
self::_store(
$file,
'<?php' . PHP_EOL .
@ -81,12 +84,9 @@ class purgelimiter extends persistence
require $path;
$pl = $GLOBALS['purge_limiter'];
if ($pl + self::$_limit >= $now)
{
if ($pl + self::$_limit >= $now) {
$result = false;
}
else
{
} else {
$result = true;
self::_store(
$file,

View file

@ -10,6 +10,8 @@
* @version 0.22
*/
namespace PrivateBin;
/**
* request
*
@ -79,8 +81,7 @@ class request
public function __construct()
{
// in case stupid admin has left magic_quotes enabled in php.ini (for PHP < 5.4)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_POST = array_map('filter::stripslashes_deep', $_POST);
$_GET = array_map('filter::stripslashes_deep', $_GET);
$_COOKIE = array_map('filter::stripslashes_deep', $_COOKIE);
@ -90,8 +91,7 @@ class request
$this->_isJsonApi = $this->_detectJsonRequest();
// parse parameters, depending on request type
switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET')
{
switch (array_key_exists('REQUEST_METHOD', $_SERVER) ? $_SERVER['REQUEST_METHOD'] : 'GET') {
case 'DELETE':
case 'PUT':
parse_str(file_get_contents(self::$_inputStream), $this->_params);
@ -107,8 +107,7 @@ class request
!array_key_exists('jsonld', $this->_params) &&
array_key_exists('QUERY_STRING', $_SERVER) &&
!empty($_SERVER['QUERY_STRING'])
)
{
) {
$this->_params['pasteid'] = $_SERVER['QUERY_STRING'];
}
@ -116,23 +115,15 @@ class request
if (
(array_key_exists('data', $this->_params) && !empty($this->_params['data'])) ||
(array_key_exists('attachment', $this->_params) && !empty($this->_params['attachment']))
)
{
) {
$this->_operation = 'create';
}
elseif (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid']))
{
if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken']))
{
} elseif (array_key_exists('pasteid', $this->_params) && !empty($this->_params['pasteid'])) {
if (array_key_exists('deletetoken', $this->_params) && !empty($this->_params['deletetoken'])) {
$this->_operation = 'delete';
}
else
{
} else {
$this->_operation = 'read';
}
}
elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld']))
{
} elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld'])) {
$this->_operation = 'jsonld';
}
}
@ -203,53 +194,42 @@ class request
strpos($acceptHeader, self::MIME_JSON) !== false &&
strpos($acceptHeader, self::MIME_HTML) === false &&
strpos($acceptHeader, self::MIME_XHTML) === false)
)
{
) {
return true;
}
// advanced case: media type negotiation
$mediaTypes = array();
if ($hasAcceptHeader)
{
if ($hasAcceptHeader) {
$mediaTypeRanges = explode(',', trim($acceptHeader));
foreach ($mediaTypeRanges as $mediaTypeRange)
{
foreach ($mediaTypeRanges as $mediaTypeRange) {
if (preg_match(
'#(\*/\*|[a-z\-]+/[a-z\-+*]+(?:\s*;\s*[^q]\S*)*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?#',
trim($mediaTypeRange), $match
))
{
if (!isset($match[2]))
{
)) {
if (!isset($match[2])) {
$match[2] = '1.0';
}
else
{
} else {
$match[2] = (string) floatval($match[2]);
}
if (!isset($mediaTypes[$match[2]]))
{
if (!isset($mediaTypes[$match[2]])) {
$mediaTypes[$match[2]] = array();
}
$mediaTypes[$match[2]][] = strtolower($match[1]);
}
}
krsort($mediaTypes);
foreach ($mediaTypes as $acceptedQuality => $acceptedValues)
{
if ($acceptedQuality === 0.0) continue;
foreach ($acceptedValues as $acceptedValue)
{
foreach ($mediaTypes as $acceptedQuality => $acceptedValues) {
if ($acceptedQuality === 0.0) {
continue;
}
foreach ($acceptedValues as $acceptedValue) {
if (
strpos($acceptedValue, self::MIME_HTML) === 0 ||
strpos($acceptedValue, self::MIME_XHTML) === 0
)
{
) {
return false;
}
elseif (strpos($acceptedValue, self::MIME_JSON) === 0)
{
} elseif (strpos($acceptedValue, self::MIME_JSON) === 0) {
return true;
}
}

View file

@ -10,6 +10,10 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
/**
* serversalt
*
@ -41,13 +45,12 @@ class serversalt extends persistence
public static function generate()
{
$randomSalt = '';
if (function_exists('mcrypt_create_iv'))
{
if (function_exists('mcrypt_create_iv')) {
$randomSalt = bin2hex(mcrypt_create_iv(256, MCRYPT_DEV_URANDOM));
}
else // fallback to mt_rand()
{
for($i = 0; $i < 256; ++$i) {
} else {
// fallback to mt_rand()
for ($i = 0; $i < 256; ++$i) {
$randomSalt .= base_convert(mt_rand(), 10, 16);
}
}
@ -64,7 +67,9 @@ class serversalt extends persistence
*/
public static function get()
{
if (strlen(self::$_salt)) return self::$_salt;
if (strlen(self::$_salt)) {
return self::$_salt;
}
$file = 'salt.php';
if (self::_exists($file)) {
@ -93,7 +98,7 @@ class serversalt extends persistence
*/
public static function setPath($path)
{
self::$_salt = '';
self::$_salt = '';
parent::setPath($path);
}
}

View file

@ -10,6 +10,8 @@
* @version 0.22
*/
namespace PrivateBin;
/**
* sjcl
*
@ -33,39 +35,68 @@ class sjcl
// Make sure content is valid json
$decoded = json_decode($encoded);
if (is_null($decoded)) return false;
if (is_null($decoded)) {
return false;
}
$decoded = (array) $decoded;
// Make sure no additionnal keys were added.
if (
count(array_keys($decoded)) != count($accepted_keys)
) return false;
) {
return false;
}
// Make sure required fields are present and contain base64 data.
foreach($accepted_keys as $k)
{
if (!array_key_exists($k, $decoded)) return false;
foreach ($accepted_keys as $k) {
if (!array_key_exists($k, $decoded)) {
return false;
}
}
// Make sure some fields are base64 data.
if (!base64_decode($decoded['iv'], true)) return false;
if (!base64_decode($decoded['salt'], true)) return false;
if (!($ct = base64_decode($decoded['ct'], true))) return false;
if (!base64_decode($decoded['iv'], true)) {
return false;
}
if (!base64_decode($decoded['salt'], true)) {
return false;
}
if (!($ct = base64_decode($decoded['ct'], true))) {
return false;
}
// Make sure some fields have a reasonable size.
if (strlen($decoded['iv']) > 24) return false;
if (strlen($decoded['salt']) > 14) return false;
if (strlen($decoded['iv']) > 24) {
return false;
}
if (strlen($decoded['salt']) > 14) {
return false;
}
// Make sure some fields contain no unsupported values.
if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) return false;
if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) return false;
if (!in_array($decoded['ks'], array(128, 192, 256), true)) return false;
if (!in_array($decoded['ts'], array(64, 96, 128), true)) return false;
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) return false;
if ($decoded['cipher'] !== 'aes') return false;
if (!(is_int($decoded['v']) || is_float($decoded['v'])) || (float) $decoded['v'] < 1) {
return false;
}
if (!is_int($decoded['iter']) || $decoded['iter'] <= 100) {
return false;
}
if (!in_array($decoded['ks'], array(128, 192, 256), true)) {
return false;
}
if (!in_array($decoded['ts'], array(64, 96, 128), true)) {
return false;
}
if (!in_array($decoded['mode'], array('ccm', 'ocb2', 'gcm'), true)) {
return false;
}
if ($decoded['cipher'] !== 'aes') {
return false;
}
// Reject data if entropy is too low
if (strlen($ct) > strlen(gzdeflate($ct))) return false;
if (strlen($ct) > strlen(gzdeflate($ct))) {
return false;
}
return true;
}

View file

@ -10,6 +10,8 @@
* @version 0.22
*/
namespace PrivateBin;
/**
* trafficlimiter
*
@ -60,11 +62,9 @@ class trafficlimiter extends persistence
{
self::setLimit($conf->getKey('limit', 'traffic'));
self::setPath($conf->getKey('dir', 'traffic'));
if (($option = $conf->getKey('header', 'traffic')) !== null)
{
if (($option = $conf->getKey('header', 'traffic')) !== null) {
$httpHeader = 'HTTP_' . $option;
if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader]))
{
if (array_key_exists($httpHeader, $_SERVER) && !empty($_SERVER[$httpHeader])) {
self::$_ipKey = $httpHeader;
}
}
@ -95,13 +95,14 @@ class trafficlimiter extends persistence
public static function canPass()
{
// disable limits if set to less then 1
if (self::$_limit < 1) return true;
if (self::$_limit < 1) {
return true;
}
$ip = hash_hmac('sha256', self::getIp(), serversalt::get());
$file = 'traffic_limiter.php';
if (!self::_exists($file))
{
if (!self::_exists($file)) {
self::_store(
$file,
'<?php' . PHP_EOL .
@ -115,16 +116,13 @@ class trafficlimiter extends persistence
$tl = $GLOBALS['traffic_limiter'];
// purge file of expired IPs to keep it small
foreach ($tl as $key => $time)
{
if ($time + self::$_limit < $now)
{
foreach ($tl as $key => $time) {
if ($time + self::$_limit < $now) {
unset($tl[$key]);
}
}
if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now))
{
if (array_key_exists($ip, $tl) && ($tl[$ip] + self::$_limit >= $now)) {
$result = false;
} else {
$tl[$ip] = time();

View file

@ -10,6 +10,10 @@
* @version 0.22
*/
namespace PrivateBin;
use Exception;
/**
* view
*
@ -49,8 +53,7 @@ class view
public function draw($template)
{
$path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $template . '.php';
if (!file_exists($path))
{
if (!file_exists($path)) {
throw new Exception('Template ' . $template . ' not found!', 80);
}
extract($this->_variables);

View file

@ -11,6 +11,8 @@
* @version 0.0.4 beta PrivateBin 0.22
*/
namespace PrivateBin;
/**
* vizhash16x16
*
@ -86,42 +88,53 @@ class vizhash16x16
*/
public function generate($text)
{
if (!function_exists('gd_info')) return '';
if (!function_exists('gd_info')) {
return '';
}
// We hash the input string.
$hash=hash('sha1',$text.$this->salt).hash('md5',$text.$this->salt);
$hash=hash('sha1', $text.$this->salt).hash('md5', $text.$this->salt);
$hash=$hash.strrev($hash); # more data to make graphics
$hashlen=strlen($hash);
// We convert the hash into an array of integers.
$this->VALUES=array();
for($i=0; $i<$hashlen; $i=$i+2){ array_push($this->VALUES,hexdec(substr($hash,$i,2))); }
for ($i=0; $i<$hashlen; $i=$i+2) {
array_push($this->VALUES, hexdec(substr($hash, $i, 2)));
}
$this->VALUES_INDEX=0; // to walk the array.
// Then use these integers to drive the creation of an image.
$image = imagecreatetruecolor($this->width,$this->height);
$image = imagecreatetruecolor($this->width, $this->height);
$r0 = $this->getInt();$r=$r0;
$g0 = $this->getInt();$g=$g0;
$b0 = $this->getInt();$b=$b0;
$r0 = $this->getInt();
$r=$r0;
$g0 = $this->getInt();
$g=$g0;
$b0 = $this->getInt();
$b=$b0;
// First, create an image with a specific gradient background.
$op='v'; if (($this->getInt()%2)==0) { $op='h'; };
$image = $this->degrade($image,$op,array($r0,$g0,$b0),array(0,0,0));
$op='v';
if (($this->getInt()%2)==0) {
$op='h';
};
$image = $this->degrade($image, $op, array($r0, $g0, $b0), array(0, 0, 0));
for($i=0; $i<7; $i=$i+1)
{
for ($i=0; $i<7; $i=$i+1) {
$action=$this->getInt();
$color = imagecolorallocate($image, $r,$g,$b);
$color = imagecolorallocate($image, $r, $g, $b);
$r = ($r0 + $this->getInt()/25)%256;
$g = ($g0 + $this->getInt()/25)%256;
$b = ($b0 + $this->getInt()/25)%256;
$r0=$r; $g0=$g; $b0=$b;
$this->drawshape($image,$action,$color);
$r0=$r;
$g0=$g;
$b0=$b;
$this->drawshape($image, $action, $color);
}
$color = imagecolorallocate($image,$this->getInt(),$this->getInt(),$this->getInt());
$this->drawshape($image,$this->getInt(),$color);
$color = imagecolorallocate($image, $this->getInt(), $this->getInt(), $this->getInt());
$this->drawshape($image, $this->getInt(), $color);
ob_start();
imagepng($image);
$imagedata = ob_get_contents();
@ -180,24 +193,31 @@ class vizhash16x16
* @param array $color2
* @return resource
*/
private function degrade($img,$direction,$color1,$color2)
private function degrade($img, $direction, $color1, $color2)
{
if($direction=='h') { $size = imagesx($img); $sizeinv = imagesy($img); }
else { $size = imagesy($img); $sizeinv = imagesx($img);}
$diffs = array(
if ($direction=='h') {
$size = imagesx($img);
$sizeinv = imagesy($img);
} else {
$size = imagesy($img);
$sizeinv = imagesx($img);
}
$diffs = array(
(($color2[0]-$color1[0])/$size),
(($color2[1]-$color1[1])/$size),
(($color2[2]-$color1[2])/$size)
);
for($i=0;$i<$size;$i++)
{
$r = $color1[0]+($diffs[0]*$i);
$g = $color1[1]+($diffs[1]*$i);
$b = $color1[2]+($diffs[2]*$i);
if($direction=='h') { imageline($img,$i,0,$i,$sizeinv,imagecolorallocate($img,$r,$g,$b)); }
else { imageline($img,0,$i,$sizeinv,$i,imagecolorallocate($img,$r,$g,$b)); }
for ($i=0;$i<$size;$i++) {
$r = $color1[0]+($diffs[0]*$i);
$g = $color1[1]+($diffs[1]*$i);
$b = $color1[2]+($diffs[2]*$i);
if ($direction=='h') {
imageline($img, $i, 0, $i, $sizeinv, imagecolorallocate($img, $r, $g, $b));
} else {
imageline($img, 0, $i, $sizeinv, $i, imagecolorallocate($img, $r, $g, $b));
}
return $img;
}
return $img;
}
/**
@ -209,24 +229,23 @@ class vizhash16x16
* @param int $color
* @return void
*/
private function drawshape($image,$action,$color)
private function drawshape($image, $action, $color)
{
switch($action%7)
{
switch ($action%7) {
case 0:
ImageFilledRectangle ($image,$this->getX(),$this->getY(),$this->getX(),$this->getY(),$color);
ImageFilledRectangle($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break;
case 1:
case 2:
ImageFilledEllipse ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
ImageFilledEllipse($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $color);
break;
case 3:
$points = array($this->getX(), $this->getY(), $this->getX(), $this->getY(), $this->getX(), $this->getY(),$this->getX(), $this->getY());
ImageFilledPolygon ($image, $points, 4, $color);
ImageFilledPolygon($image, $points, 4, $color);
break;
default:
$start=$this->getInt()*360/256; $end=$start+$this->getInt()*180/256;
ImageFilledArc ($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(),$start,$end,$color,IMG_ARC_PIE);
ImageFilledArc($image, $this->getX(), $this->getY(), $this->getX(), $this->getY(), $start, $end, $color, IMG_ARC_PIE);
}
}
}

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -45,39 +45,39 @@ endif; ?>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span>
<span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
<img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<button id="sendbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?>
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php
endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?>
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button>
</li>
<li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?>
<li>
@ -89,30 +89,30 @@ endforeach; ?>
</ul>
</li>
<li id="formatter" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Options'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Options'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="burnafterreadingoption" class="checkbox hidden">
<label>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Burn after reading'); ?>
<?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label>
</li><?php
if ($DISCUSSION): ?>
<li id="opendisc" class="checkbox hidden">
<label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Open discussion'); ?>
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label>
</li><?php
endif; ?>
<li role="separator" class="divider"></li>
<li>
<div>
<?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span>
<?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span>
</div>
</li><?php
foreach ($FORMATTER as $key => $value): ?>
@ -126,21 +126,21 @@ endforeach; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
</li><?php
if ($PASSWORD): ?>
<li>
<div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19"/>
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19"/>
</div>
</li><?php
endif;
if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="filewrap">
<div>
@ -149,7 +149,7 @@ if ($FILEUPLOAD): ?>
</li>
<li>
<a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?>
<?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a>
</li>
</ul>
@ -161,19 +161,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<li>
<a href="#" class="reloadlink" onclick="document.cookie='lang={$key}';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a>
</li><?php
endforeach; ?>
endforeach; ?>
</ul>
</li><?php
endif; ?>
<li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?>
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button>
</li>
</ul>
@ -191,7 +191,7 @@ endif; ?>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php
endif;
if (strlen($STATUS)): ?>
@ -202,9 +202,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -216,14 +216,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?>
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php
endif; ?>
</div>
</div>
<ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li>
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul>
</header>
<section class="container">
@ -238,16 +238,16 @@ endif; ?>
</section>
<section class="container">
<div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4>
<h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>
<footer class="container">
<div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4>
<h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p>
</div>
</footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-inverse navbar-static-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span>
<span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
<img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?>
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php
endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?>
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button>
</li>
<li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?>
<li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Burn after reading'); ?>
<?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label>
</div>
</li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden">
<label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Open discussion'); ?>
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label>
</div>
</li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?>
<li>
<div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div>
</li><?php
endif;
if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="filewrap">
<div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li>
<li>
<a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?>
<?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a>
</li>
</ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?>
<li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a>
</li><?php
endforeach; ?>
endforeach; ?>
</ul>
</li><?php
endif; ?>
<li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?>
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button>
</li>
</ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php
endif;
if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?>
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php
endif; ?>
</div>
</div>
<ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li>
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul>
</header>
<section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section>
<section class="container">
<div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4>
<h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>
<footer class="container">
<div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4>
<h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p>
</div>
</footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/darkstrap-0.9.3.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-inverse navbar-static-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span>
<span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
<img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?>
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?>
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php
endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?>
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button>
</li>
<li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?>
<li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Burn after reading'); ?>
<?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label>
</div>
</li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden">
<label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Open discussion'); ?>
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label>
</div>
</li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?>
<li>
<div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div>
</li><?php
endif;
if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="filewrap">
<div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li>
<li>
<a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?>
<?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a>
</li>
</ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?>
<li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a>
</li><?php
endforeach; ?>
endforeach; ?>
</ul>
</li><?php
endif; ?>
<li>
<button id="sendbutton" type="button" class="hidden btn btn-warning navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button>
</li>
</ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php
endif;
if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-error"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-error"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-warning">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?>
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php
endif; ?>
</div>
</div>
<ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li>
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul>
</header>
<section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section>
<section class="container">
<div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4>
<h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>
<footer class="container">
<div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4>
<h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p>
</div>
</footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-default navbar-static-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span>
<span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
<img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?>
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php
endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?>
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button>
</li>
<li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?>
<li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Burn after reading'); ?>
<?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label>
</div>
</li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden">
<label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Open discussion'); ?>
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label>
</div>
</li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?>
<li>
<div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div>
</li><?php
endif;
if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="filewrap">
<div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li>
<li>
<a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?>
<?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a>
</li>
</ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?>
<li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a>
</li><?php
endforeach; ?>
endforeach; ?>
</ul>
</li><?php
endif; ?>
<li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?>
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button>
</li>
</ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php
endif;
if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?>
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php
endif; ?>
</div>
</div>
<ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li>
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul>
</header>
<section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section>
<section class="container">
<div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4>
<h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>
<footer class="container">
<div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4>
<h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p>
</div>
</footer>

View file

@ -5,15 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/bootstrap-theme-3.3.5.css" />
<link type="text/css" rel="stylesheet" href="css/bootstrap/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -44,39 +44,39 @@ endif; ?>
<nav class="navbar navbar-default navbar-static-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only"><?php echo i18n::_('Toggle navigation'); ?></span>
<span class="sr-only"><?php echo PrivateBin\i18n::_('Toggle navigation'); ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="reloadlink navbar-brand" href="/">
<img alt="<?php echo i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
<img alt="<?php echo PrivateBin\i18n::_('PrivateBin'); ?>" src="img/icon.svg" width="20" />
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<button id="newbutton" type="button" class="reloadlink hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo i18n::_('New'); ?>
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('New'); ?>
</button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo i18n::_('Clone'); ?>
<span class="glyphicon glyphicon-duplicate" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Clone'); ?>
</button><?php
endif; ?>
<button id="rawtextbutton" type="button" class="hidden btn btn-default navbar-btn">
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo i18n::_('Raw text'); ?>
<span class="glyphicon glyphicon-text-background" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Raw text'); ?>
</button>
</li>
<li class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="expiration" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Expires'); ?>: <span id="pasteExpirationDisplay"><?php echo $EXPIRE[$EXPIREDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($EXPIRE as $key => $value): ?>
<li>
@ -93,7 +93,7 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Burn after reading'); ?>
<?php echo PrivateBin\i18n::_('Burn after reading'); ?>
</label>
</div>
</li><?php
@ -102,9 +102,9 @@ if ($DISCUSSION): ?>
<div id="opendisc" class="navbar-text checkbox hidden">
<label>
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo i18n::_('Open discussion'); ?>
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<?php echo PrivateBin\i18n::_('Open discussion'); ?>
</label>
</div>
</li><?php
@ -112,13 +112,13 @@ endif;
if ($PASSWORD): ?>
<li>
<div id="password" class="navbar-form hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" class="form-control" size="19" />
</div>
</li><?php
endif;
if ($FILEUPLOAD): ?>
<li id="attach" class="hidden dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Attach a file'); ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
<li id="filewrap">
<div>
@ -127,7 +127,7 @@ if ($FILEUPLOAD): ?>
</li>
<li>
<a id="fileremovebutton" href="#">
<?php echo i18n::_('Remove attachment'); ?>
<?php echo PrivateBin\i18n::_('Remove attachment'); ?>
</a>
</li>
</ul>
@ -137,11 +137,11 @@ endif; ?>
<select id="pasteFormatter" name="pasteFormatter" class="hidden"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<a id="formatter" href="#" class="hidden dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo PrivateBin\i18n::_('Format'); ?>: <span id="pasteFormatterDisplay"><?php echo $FORMATTER[$FORMATTERDEFAULT]; ?></span> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($FORMATTER as $key => $value): ?>
<li>
@ -158,19 +158,19 @@ if (strlen($LANGUAGESELECTION)): ?>
<li id="language" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-flag" aria-hidden="true"></span> <?php echo $LANGUAGES[$LANGUAGESELECTION][0]; ?> <span class="caret"></span></a>
<ul class="dropdown-menu"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<li>
<a href="#" class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';">
<?php echo $value[0]; ?> (<?php echo $value[1]; ?>)
</a>
</li><?php
endforeach; ?>
endforeach; ?>
</ul>
</li><?php
endif; ?>
<li>
<button id="sendbutton" type="button" class="hidden btn btn-primary navbar-btn">
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo i18n::_('Send'); ?>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Send'); ?>
</button>
</li>
</ul>
@ -187,7 +187,7 @@ endif; ?>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" role="alert" class="hidden alert alert-info">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a> <span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
</div><?php
endif;
if (strlen($STATUS)): ?>
@ -198,9 +198,9 @@ endif; ?>
<div id="errormessage" role="alert" class="<?php
if (!strlen($ERROR)): ?>hidden <?php
endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo htmlspecialchars($ERROR); ?></div>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" role="alert" class="nonworking alert alert-warning"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" role="alert" class="hidden nonworking alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice" role="alert" class="hidden alert alert-warning"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -212,14 +212,14 @@ endif; ?>alert alert-danger"><span class="glyphicon glyphicon-alert" aria-hidden
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>" type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo i18n::_('Shorten URL'); ?>
<span class="glyphicon glyphicon-send" aria-hidden="true"></span> <?php echo PrivateBin\i18n::_('Shorten URL'); ?>
</button><?php
endif; ?>
</div>
</div>
<ul id="preview" class="nav nav-tabs hidden">
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo i18n::_('Preview'); ?></a></li>
<li role="presentation" class="active"><a id="messageedit" href="#"><?php echo PrivateBin\i18n::_('Editor'); ?></a></li>
<li role="presentation"><a id="messagepreview" href="#"><?php echo PrivateBin\i18n::_('Preview'); ?></a></li>
</ul>
</header>
<section class="container">
@ -234,16 +234,16 @@ endif; ?>
</section>
<section class="container">
<div id="discussion" class="hidden">
<h4><?php echo i18n::_('Discussion'); ?></h4>
<h4><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>
<footer class="container">
<div class="row">
<h4 class="col-md-5 col-xs-8"><?php echo i18n::_('PrivateBin'); ?> <small>- <?php echo i18n::_('Because ignorance is bliss'); ?></small></h4>
<h4 class="col-md-5 col-xs-8"><?php echo PrivateBin\i18n::_('PrivateBin'); ?> <small>- <?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></small></h4>
<p class="col-md-1 col-xs-4 text-center"><?php echo $VERSION; ?></p>
<p id="aboutbox" class="col-md-6 col-xs-12">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?>
</p>
</div>
</footer>

View file

@ -3,13 +3,13 @@
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<title><?php echo i18n::_('PrivateBin'); ?></title>
<title><?php echo PrivateBin\i18n::_('PrivateBin'); ?></title>
<link type="text/css" rel="stylesheet" href="css/privatebin.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if ($SYNTAXHIGHLIGHTING): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/prettify.css?<?php echo rawurlencode($VERSION); ?>" /><?php
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
if (strlen($SYNTAXHIGHLIGHTINGTHEME)): ?>
<link type="text/css" rel="stylesheet" href="css/prettify/<?php echo rawurlencode($SYNTAXHIGHLIGHTINGTHEME); ?>.css?<?php echo rawurlencode($VERSION); ?>" /><?php
endif;
endif;
endif; ?>
<script type="text/javascript" src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="js/sjcl-1.0.4.js"></script>
@ -38,17 +38,17 @@ endif; ?>
<body>
<header>
<div id="aboutbox">
<?php echo i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?><br /><?php
<?php echo PrivateBin\i18n::_('PrivateBin is a minimalist, open source online pastebin where the server has zero knowledge of pasted data. Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES. More information on the <a href="https://github.com/PrivateBin/PrivateBin/wiki">project page</a>.'); ?><br /><?php
if (strlen($NOTICE)): ?>
<span class="blink"></span> <?php echo htmlspecialchars($NOTICE);
endif; ?>
</div>
<h1 class="title reloadlink"><?php echo i18n::_('PrivateBin'); ?></h1><br />
<h2 class="title"><?php echo i18n::_('Because ignorance is bliss'); ?></h2><br />
<h1 class="title reloadlink"><?php echo PrivateBin\i18n::_('PrivateBin'); ?></h1><br />
<h2 class="title"><?php echo PrivateBin\i18n::_('Because ignorance is bliss'); ?></h2><br />
<h3 class="title"><?php echo $VERSION; ?></h3>
<noscript><div id="noscript" class="nonworking"><?php echo i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" class="nonworking"><?php echo i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice"><?php echo i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<noscript><div id="noscript" class="nonworking"><?php echo PrivateBin\i18n::_('Javascript is required for PrivateBin to work.<br />Sorry for the inconvenience.'); ?></div></noscript>
<div id="oldienotice" class="nonworking"><?php echo PrivateBin\i18n::_('PrivateBin requires a modern browser to work.'); ?></div>
<div id="ienotice"><?php echo PrivateBin\i18n::_('Still using Internet Explorer? Do yourself a favor, switch to a modern browser:'); ?>
<a href="https://www.mozilla.org/firefox/">Firefox</a>,
<a href="https://www.opera.com/">Opera</a>,
<a href="https://www.google.com/chrome">Chrome</a>,
@ -60,18 +60,18 @@ endif; ?>
<div id="status"><?php echo htmlspecialchars($STATUS); ?></div>
<div id="errormessage" class="hidden"><?php echo htmlspecialchars($ERROR); ?></div>
<div id="toolbar">
<button id="newbutton" class="reloadlink hidden"><img src="img/icon_new.png" width="11" height="15" alt="" /><?php echo i18n::_('New'); ?></button>
<button id="sendbutton" class="hidden"><img src="img/icon_send.png" width="18" height="15" alt="" /><?php echo i18n::_('Send'); ?></button><?php
<button id="newbutton" class="reloadlink hidden"><img src="img/icon_new.png" width="11" height="15" alt="" /><?php echo PrivateBin\i18n::_('New'); ?></button>
<button id="sendbutton" class="hidden"><img src="img/icon_send.png" width="18" height="15" alt="" /><?php echo PrivateBin\i18n::_('Send'); ?></button><?php
if ($EXPIRECLONE): ?>
<button id="clonebutton" class="hidden"><img src="img/icon_clone.png" width="15" height="17" alt="" /><?php echo i18n::_('Clone'); ?></button><?php
<button id="clonebutton" class="hidden"><img src="img/icon_clone.png" width="15" height="17" alt="" /><?php echo PrivateBin\i18n::_('Clone'); ?></button><?php
endif; ?>
<button id="rawtextbutton" class="hidden"><img src="img/icon_raw.png" width="15" height="15" alt="" /><?php echo i18n::_('Raw text'); ?></button>
<div id="expiration" class="hidden button"><?php echo i18n::_('Expires'); ?>:
<button id="rawtextbutton" class="hidden"><img src="img/icon_raw.png" width="15" height="15" alt="" /><?php echo PrivateBin\i18n::_('Raw text'); ?></button>
<div id="expiration" class="hidden button"><?php echo PrivateBin\i18n::_('Expires'); ?>:
<select id="pasteExpiration" name="pasteExpiration"><?php
foreach ($EXPIRE as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $EXPIREDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
</div>
@ -80,40 +80,40 @@ endforeach; ?>
<input type="checkbox" id="burnafterreading" name="burnafterreading" <?php
if ($BURNAFTERREADINGSELECTED): ?> checked="checked"<?php
endif; ?> />
<label for="burnafterreading"><?php echo i18n::_('Burn after reading'); ?></label>
<label for="burnafterreading"><?php echo PrivateBin\i18n::_('Burn after reading'); ?></label>
</div><?php
if ($DISCUSSION): ?>
<div id="opendisc" class="button hidden">
<input type="checkbox" id="opendiscussion" name="opendiscussion" <?php
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
if ($OPENDISCUSSION): ?> checked="checked"<?php
endif; ?> />
<label for="opendiscussion" <?php
if (!$OPENDISCUSSION): ?> style="color: #BBBBBB;"<?php
endif; ?>><?php echo i18n::_('Open discussion'); ?></label>
if (!$OPENDISCUSSION): ?> style="color: #BBBBBB;"<?php
endif; ?>><?php echo PrivateBin\i18n::_('Open discussion'); ?></label>
</div><?php
endif;
if ($PASSWORD): ?>
<div id="password" class="hidden">
<input type="password" id="passwordinput" placeholder="<?php echo i18n::_('Password (recommended)'); ?>" size="32" />
<input type="password" id="passwordinput" placeholder="<?php echo PrivateBin\i18n::_('Password (recommended)'); ?>" size="32" />
</div><?php
endif; ?>
<div id="formatter" class="button hidden"><?php echo i18n::_('Format'); ?>:
<div id="formatter" class="button hidden"><?php echo PrivateBin\i18n::_('Format'); ?>:
<select id="pasteFormatter" name="pasteFormatter"><?php
foreach ($FORMATTER as $key => $value): ?>
<option value="<?php echo $key; ?>"<?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
if ($key == $FORMATTERDEFAULT): ?> selected="selected"<?php
endif; ?>><?php echo $value; ?></option><?php
endforeach; ?>
</select>
</div><?php
if (strlen($LANGUAGESELECTION)): ?>
<div id="language" class="button">
<select name="lang"><?php
foreach ($LANGUAGES as $key => $value): ?>
foreach ($LANGUAGES as $key => $value): ?>
<option class="reloadlink" onclick="document.cookie='lang=<?php echo $key; ?>';" value="<?php echo $key; ?>"<?php
if ($key == $LANGUAGESELECTION): ?> selected="selected"<?php
endif; ?>><?php echo $value[0]; ?> (<?php echo $value[1]; ?>)</option><?php
endforeach; ?>
if ($key == $LANGUAGESELECTION): ?> selected="selected"<?php
endif; ?>><?php echo $value[0]; ?> (<?php echo $value[1]; ?>)</option><?php
endforeach; ?>
</select>
</div><?php
endif; ?>
@ -122,21 +122,21 @@ endif; ?>
<div id="deletelink"></div>
<div id="pastelink"><?php
if (strlen($URLSHORTENER)): ?>
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>"><img src="img/icon_shorten.png" width="13" height="15" /><?php echo i18n::_('Shorten URL'); ?></button><?php
<button id="shortenbutton" data-shortener="<?php echo htmlspecialchars($URLSHORTENER); ?>"><img src="img/icon_shorten.png" width="13" height="15" /><?php echo PrivateBin\i18n::_('Shorten URL'); ?></button><?php
endif; ?>
</div>
</div><?php
if ($FILEUPLOAD): ?>
<div id="attachment" class="hidden"><a><?php echo i18n::_('Download attachment'); ?></a></div>
<div id="attachment" class="hidden"><a><?php echo PrivateBin\i18n::_('Download attachment'); ?></a></div>
<div id="attach" class="hidden">
<span id="clonedfile" class="hidden"><?php echo i18n::_('Cloned file attached.'); ?></span>
<span id="filewrap"><?php echo i18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span>
<button id="fileremovebutton"><?php echo i18n::_('Remove attachment'); ?></button>
<span id="clonedfile" class="hidden"><?php echo PrivateBin\i18n::_('Cloned file attached.'); ?></span>
<span id="filewrap"><?php echo PrivateBin\i18n::_('Attach a file'); ?>: <input type="file" id="file" name="file" /></span>
<button id="fileremovebutton"><?php echo PrivateBin\i18n::_('Remove attachment'); ?></button>
</div><?php
endif; ?>
<div id="preview" class="hidden">
<button id="messageedit"><?php echo i18n::_('Editor'); ?></button>
<button id="messagepreview"><?php echo i18n::_('Preview'); ?></button>
<button id="messageedit"><?php echo PrivateBin\i18n::_('Editor'); ?></button>
<button id="messagepreview"><?php echo PrivateBin\i18n::_('Preview'); ?></button>
</div>
<div id="image" class="hidden"></div>
<div id="prettymessage" class="hidden">
@ -148,7 +148,7 @@ endif; ?>
</section>
<section>
<div id="discussion" class="hidden">
<h4 class="title"><?php echo i18n::_('Discussion'); ?></h4>
<h4 class="title"><?php echo PrivateBin\i18n::_('Discussion'); ?></h4>
<div id="comments"></div>
</div>
</section>

View file

@ -1,8 +0,0 @@
<?php
class autoTest extends PHPUnit_Framework_TestCase
{
public function testAutoloaderReturnsFalseWhenCallingNonExistingClass()
{
$this->assertFalse(auto::loader('foo2501bar42'), 'calling non existent class');
}
}

View file

@ -1,13 +1,24 @@
<?php
error_reporting( E_ALL | E_STRICT );
use PrivateBin\serversalt;
error_reporting(E_ALL | E_STRICT);
// change this, if your php files and data is outside of your webservers document root
if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..');
if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
if (!is_file(CONF)) copy(CONF . '.sample', CONF);
if (!defined('PUBLIC_PATH')) {
define('PUBLIC_PATH', '..');
}
if (!defined('PATH')) {
define('PATH', '..' . DIRECTORY_SEPARATOR);
}
if (!defined('CONF')) {
define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
}
if (!is_file(CONF)) {
copy(CONF . '.sample', CONF);
}
require PATH . 'lib/auto.php';
require PATH . 'vendor/autoload.php';
class helper
{
@ -100,8 +111,9 @@ class helper
$example = self::getPaste();
// the JSON shouldn't contain the salt
unset($example['meta']['salt']);
if (count($meta))
if (count($meta)) {
$example['meta'] = $meta;
}
$example['comments'] = array();
$example['comment_count'] = 0;
$example['comment_offset'] = 0;
@ -154,19 +166,19 @@ class helper
{
$path .= DIRECTORY_SEPARATOR;
$dir = dir($path);
while(false !== ($file = $dir->read())) {
if($file != '.' && $file != '..') {
if(is_dir($path . $file)) {
while (false !== ($file = $dir->read())) {
if ($file != '.' && $file != '..') {
if (is_dir($path . $file)) {
self::rmdir($path . $file);
} elseif(is_file($path . $file)) {
if(!@unlink($path . $file)) {
} elseif (is_file($path . $file)) {
if (!@unlink($path . $file)) {
throw new Exception('Error deleting file "' . $path . $file . '".');
}
}
}
}
$dir->close();
if(!@rmdir($path)) {
if (!@rmdir($path)) {
throw new Exception('Error deleting directory "' . $path . '".');
}
}
@ -178,8 +190,9 @@ class helper
*/
public static function confBackup()
{
if (!is_file(CONF . '.bak') && is_file(CONF))
if (!is_file(CONF . '.bak') && is_file(CONF)) {
rename(CONF, CONF . '.bak');
}
}
/**
@ -189,8 +202,9 @@ class helper
*/
public static function confRestore()
{
if (is_file(CONF . '.bak'))
if (is_file(CONF . '.bak')) {
rename(CONF . '.bak', CONF);
}
}
/**
@ -206,7 +220,7 @@ class helper
$ini = fopen($pathToFile, 'a');
foreach ($values as $section => $options) {
fwrite($ini, "[$section]" . PHP_EOL);
foreach($options as $option => $setting) {
foreach ($options as $option => $setting) {
if (is_null($setting)) {
continue;
} elseif (is_string($setting)) {

View file

@ -388,7 +388,8 @@ class configurationTestGenerator
* constructor, generates the configuration test
* @param array $options
*/
public function __construct($options) {
public function __construct($options)
{
$this->_options = $options;
// generate all possible combinations of options: options^settings
$this->_generateConfigurations();
@ -418,7 +419,7 @@ class configurationTestGenerator
while (list($path, $setting) = each($test['conditions'])) {
if ($path == 'steps' && !in_array($step, $setting)) {
continue 2;
} elseif($path != 'steps') {
} elseif ($path != 'steps') {
list($section, $option) = explode('/', $path);
if ($fullOptions[$section][$option] !== $setting) {
continue 2;
@ -653,7 +654,8 @@ EOT;
* @throws Exception
* @return array
*/
private function _addSetting(&$configuration, &$setting, &$section, &$option) {
private function _addSetting(&$configuration, &$setting, &$section, &$option)
{
if (++$this->_iterationCount > self::MAX_ITERATIONS) {
echo 'max iterations reached, stopping', PHP_EOL;
return $configuration;

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\configuration;
class configurationTest extends PHPUnit_Framework_TestCase
{
private $_options;
@ -125,12 +128,11 @@ class configurationTest extends PHPUnit_Framework_TestCase
$options['model']['class'] = 'zerobin_data';
helper::createIniFile(CONF, $options);
$conf = new configuration;
$this->assertEquals('privatebin_data', $conf->getKey('class', 'model'), 'old data class gets renamed');
$this->assertEquals('PrivateBin\data\data', $conf->getKey('class', 'model'), 'old data class gets renamed');
$options['model']['class'] = 'zerobin_db';
helper::createIniFile(CONF, $options);
$conf = new configuration;
$this->assertEquals('privatebin_db', $conf->getKey('class', 'model'), 'old db class gets renamed');
$this->assertEquals('PrivateBin\data\db', $conf->getKey('class', 'model'), 'old db class gets renamed');
}
}

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\filter;
class filterTest extends PHPUnit_Framework_TestCase
{
public function testFilterStripsSlashesDeeply()

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\i18n;
class i18nTest extends PHPUnit_Framework_TestCase
{
private $_translations = array();

View file

@ -1,4 +1,10 @@
<?php
use PrivateBin\data\data;
use PrivateBin\privatebin;
use PrivateBin\request;
use PrivateBin\serversalt;
class jsonApiTest extends PHPUnit_Framework_TestCase
{
protected $_model;
@ -6,7 +12,7 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
public function setUp()
{
/* Setup Routine */
$this->_model = privatebin_data::getInstance(array('dir' => PATH . 'data'));
$this->_model = data::getInstance(array('dir' => PATH . 'data'));
serversalt::setPath(PATH . 'data');
$this->reset();
}
@ -22,8 +28,9 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
$_POST = array();
$_GET = array();
$_SERVER = array();
if ($this->_model->exists(helper::getPasteId()))
if ($this->_model->exists(helper::getPasteId())) {
$this->_model->delete(helper::getPasteId());
}
helper::confRestore();
}
@ -267,5 +274,4 @@ class jsonApiTest extends PHPUnit_Framework_TestCase
ob_end_clean();
$this->assertEquals('{}', $content, 'does not output nasty data');
}
}

View file

@ -1,4 +1,11 @@
<?php
use PrivateBin\configuration;
use PrivateBin\data\db;
use PrivateBin\model;
use PrivateBin\model\paste;
use PrivateBin\vizhash16x16;
class modelTest extends PHPUnit_Framework_TestCase
{
private $_conf;
@ -165,9 +172,9 @@ class modelTest extends PHPUnit_Framework_TestCase
public function testPasteIdValidation()
{
$this->assertTrue(model_paste::isValidId('a242ab7bdfb2581a'), 'valid paste id');
$this->assertFalse(model_paste::isValidId('foo'), 'invalid hex values');
$this->assertFalse(model_paste::isValidId('../bar/baz'), 'path attack');
$this->assertTrue(paste::isValidId('a242ab7bdfb2581a'), 'valid paste id');
$this->assertFalse(paste::isValidId('foo'), 'invalid hex values');
$this->assertFalse(paste::isValidId('../bar/baz'), 'path attack');
}
/**
@ -214,37 +221,29 @@ class modelTest extends PHPUnit_Framework_TestCase
public function testPurge()
{
$conf = new configuration;
$store = privatebin_db::getInstance($conf->getSection('model_options'));
$store = db::getInstance($conf->getSection('model_options'));
$store->delete(helper::getPasteId());
$expired = helper::getPaste(array('expire_date' => 1344803344));
$paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array();
foreach ($keys as $key)
{
foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16);
$store->delete($ids[$key]);
$this->assertFalse($store->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z')))
{
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($store->create($ids[$key], $paste), "store $key paste");
}
else
{
} else {
$this->assertTrue($store->create($ids[$key], $expired), "store $key paste");
}
$this->assertTrue($store->exists($ids[$key]), "paste $key exists after storing it");
}
$this->_model->purge(10);
foreach ($ids as $key => $id)
{
if (in_array($key, array('x', 'y', 'z')))
{
foreach ($ids as $key => $id) {
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($this->_model->getPaste($id)->exists(), "paste $key exists after purge");
$this->_model->getPaste($id)->delete();
}
else
{
} else {
$this->assertFalse($this->_model->getPaste($id)->exists(), "paste $key was purged");
}
}

View file

@ -7,7 +7,7 @@
<whitelist>
<directory suffix=".php">../lib</directory>
<exclude>
<file>../lib/privatebin/abstract.php</file>
<file>../lib/data/AbstractData.php</file>
</exclude>
</whitelist>
</filter>

View file

@ -1,4 +1,10 @@
<?php
use PrivateBin\data\data;
use PrivateBin\privatebin;
use PrivateBin\serversalt;
use PrivateBin\trafficlimiter;
class privatebinTest extends PHPUnit_Framework_TestCase
{
protected $_model;
@ -6,7 +12,7 @@ class privatebinTest extends PHPUnit_Framework_TestCase
public function setUp()
{
/* Setup Routine */
$this->_model = privatebin_data::getInstance(array('dir' => PATH . 'data'));
$this->_model = data::getInstance(array('dir' => PATH . 'data'));
$this->reset();
}
@ -21,8 +27,9 @@ class privatebinTest extends PHPUnit_Framework_TestCase
$_POST = array();
$_GET = array();
$_SERVER = array();
if ($this->_model->exists(helper::getPasteId()))
if ($this->_model->exists(helper::getPasteId())) {
$this->_model->delete(helper::getPasteId());
}
helper::confRestore();
}

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\data\data;
class privatebin_dataTest extends PHPUnit_Framework_TestCase
{
private $_model;
@ -9,7 +12,7 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
$this->_model = privatebin_data::getInstance(array('dir' => $this->_path));
$this->_model = data::getInstance(array('dir' => $this->_path));
}
public function tearDown()
@ -70,30 +73,22 @@ class privatebin_dataTest extends PHPUnit_Framework_TestCase
$paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array();
foreach ($keys as $key)
{
foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z')))
{
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
}
else
{
} else {
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
}
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
}
$this->_model->purge(10);
foreach ($ids as $key => $id)
{
if (in_array($key, array('x', 'y', 'z')))
{
foreach ($ids as $key => $id) {
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($this->_model->exists($id), "paste $key exists after purge");
$this->_model->delete($id);
}
else
{
} else {
$this->assertFalse($this->_model->exists($id), "paste $key was purged");
}
}

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\data\db;
class privatebin_dbTest extends PHPUnit_Framework_TestCase
{
private $_model;
@ -13,13 +16,15 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
public function setUp()
{
/* Setup Routine */
$this->_model = privatebin_db::getInstance($this->_options);
$this->_model = db::getInstance($this->_options);
}
public function tearDown()
{
/* Tear Down Routine */
if (is_dir(PATH . 'data')) helper::rmdir(PATH . 'data');
if (is_dir(PATH . 'data')) {
helper::rmdir(PATH . 'data');
}
}
public function testDatabaseBasedDataStoreWorks()
@ -75,31 +80,23 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
$paste = helper::getPaste(array('expire_date' => time() + 3600));
$keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z');
$ids = array();
foreach ($keys as $key)
{
foreach ($keys as $key) {
$ids[$key] = substr(md5($key), 0, 16);
$this->_model->delete($ids[$key]);
$this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist");
if (in_array($key, array('x', 'y', 'z')))
{
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste");
}
else
{
} else {
$this->assertTrue($this->_model->create($ids[$key], $expired), "store $key paste");
}
$this->assertTrue($this->_model->exists($ids[$key]), "paste $key exists after storing it");
}
$this->_model->purge(10);
foreach ($ids as $key => $id)
{
if (in_array($key, array('x', 'y', 'z')))
{
foreach ($ids as $key => $id) {
if (in_array($key, array('x', 'y', 'z'))) {
$this->assertTrue($this->_model->exists($id), "paste $key exists after purge");
$this->_model->delete($id);
}
else
{
} else {
$this->assertFalse($this->_model->exists($id), "paste $key was purged");
}
}
@ -110,7 +107,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetIbmInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'ibm:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -121,7 +118,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetInformixInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'informix:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -132,7 +129,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetMssqlInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'mssql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -143,7 +140,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetMysqlInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'mysql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -154,7 +151,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetOciInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'oci:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -165,7 +162,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetPgsqlInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'pgsql:', 'usr' => null, 'pwd' => null,
'opt' => array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
));
@ -177,7 +174,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
*/
public function testGetFooInstance()
{
privatebin_db::getInstance(array(
db::getInstance(array(
'dsn' => 'foo:', 'usr' => null, 'pwd' => null, 'opt' => null
));
}
@ -190,7 +187,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{
$options = $this->_options;
unset($options['dsn']);
privatebin_db::getInstance($options);
db::getInstance($options);
}
/**
@ -201,7 +198,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{
$options = $this->_options;
unset($options['usr']);
privatebin_db::getInstance($options);
db::getInstance($options);
}
/**
@ -212,7 +209,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{
$options = $this->_options;
unset($options['pwd']);
privatebin_db::getInstance($options);
db::getInstance($options);
}
/**
@ -223,7 +220,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
{
$options = $this->_options;
unset($options['opt']);
privatebin_db::getInstance($options);
db::getInstance($options);
}
public function testOldAttachments()
@ -233,7 +230,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
@unlink($path);
$this->_options['dsn'] = 'sqlite:' . $path;
$this->_options['tbl'] = 'bar_';
$model = privatebin_db::getInstance($this->_options);
$model = db::getInstance($this->_options);
$original = $paste = helper::getPasteWithAttachment(array('expire_date' => 1344803344));
$paste['meta']['attachment'] = $paste['attachment'];
@ -301,7 +298,7 @@ class privatebin_dbTest extends PHPUnit_Framework_TestCase
'vizhash BLOB, ' .
"postdate INT );"
);
privatebin_db::getInstance($this->_options);
db::getInstance($this->_options);
helper::rmdir(PATH . 'data');
}
}

View file

@ -1,4 +1,10 @@
<?php
use PrivateBin\data\db;
use PrivateBin\privatebin;
use PrivateBin\serversalt;
use PrivateBin\trafficlimiter;
require_once 'privatebin.php';
class privatebinWithDbTest extends privatebinTest
@ -18,9 +24,11 @@ class privatebinWithDbTest extends privatebinTest
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
if(!is_dir($this->_path)) mkdir($this->_path);
if (!is_dir($this->_path)) {
mkdir($this->_path);
}
$this->_options['dsn'] = 'sqlite:' . $this->_path . DIRECTORY_SEPARATOR . 'tst.sq3';
$this->_model = privatebin_db::getInstance($this->_options);
$this->_model = db::getInstance($this->_options);
$this->reset();
}

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\purgelimiter;
class purgelimiterTest extends PHPUnit_Framework_TestCase
{
private $_path;
@ -7,7 +10,9 @@ class purgelimiterTest extends PHPUnit_Framework_TestCase
{
/* Setup Routine */
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_data';
if(!is_dir($this->_path)) mkdir($this->_path);
if (!is_dir($this->_path)) {
mkdir($this->_path);
}
purgelimiter::setPath($this->_path);
}

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\request;
class requestTest extends PHPUnit_Framework_TestCase
{
public function setUp()

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\serversalt;
class serversaltTest extends PHPUnit_Framework_TestCase
{
private $_path;
@ -13,13 +16,17 @@ class serversaltTest extends PHPUnit_Framework_TestCase
{
/* Setup Routine */
$this->_path = PATH . 'data';
if(!is_dir($this->_path)) mkdir($this->_path);
if (!is_dir($this->_path)) {
mkdir($this->_path);
}
serversalt::setPath($this->_path);
$this->_otherPath = $this->_path . DIRECTORY_SEPARATOR . 'foo';
$this->_invalidPath = $this->_path . DIRECTORY_SEPARATOR . 'bar';
if(!is_dir($this->_invalidPath)) mkdir($this->_invalidPath);
if (!is_dir($this->_invalidPath)) {
mkdir($this->_invalidPath);
}
$this->_invalidFile = $this->_invalidPath . DIRECTORY_SEPARATOR . 'salt.php';
}
@ -37,18 +44,18 @@ class serversaltTest extends PHPUnit_Framework_TestCase
$salt = serversalt::get();
// mcrypt mock
if (!function_exists('mcrypt_create_iv'))
{
if (!defined('MCRYPT_DEV_URANDOM')) define('MCRYPT_DEV_URANDOM', 1);
if (!function_exists('mcrypt_create_iv')) {
if (!defined('MCRYPT_DEV_URANDOM')) {
define('MCRYPT_DEV_URANDOM', 1);
}
function mcrypt_create_iv($int, $flag)
{
$randomSalt = '';
for($i = 0; $i < $int; ++$i) {
for ($i = 0; $i < $int; ++$i) {
$randomSalt .= base_convert(mt_rand(), 10, 16);
}
// hex2bin requires an even length, pad if necessary
if (strlen($randomSalt) % 2)
{
if (strlen($randomSalt) % 2) {
$randomSalt = '0' . $randomSalt;
}
return hex2bin($randomSalt);

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\sjcl;
class sjclTest extends PHPUnit_Framework_TestCase
{
public function testSjclValidatorValidatesCorrectly()

View file

@ -1,4 +1,7 @@
<?php
use PrivateBin\trafficlimiter;
class trafficlimiterTest extends PHPUnit_Framework_TestCase
{
private $_path;

View file

@ -1,4 +1,8 @@
<?php
use PrivateBin\i18n;
use PrivateBin\view;
class viewTest extends PHPUnit_Framework_TestCase
{
private static $error = 'foo bar';

View file

@ -1,4 +1,8 @@
<?php
use PrivateBin\serversalt;
use PrivateBin\vizhash16x16;
class vizhash16x16Test extends PHPUnit_Framework_TestCase
{
private $_file;
@ -9,7 +13,9 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase
{
/* Setup Routine */
$this->_path = PATH . 'data';
if(!is_dir($this->_path)) mkdir($this->_path);
if (!is_dir($this->_path)) {
mkdir($this->_path);
}
$this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
serversalt::setPath($this->_path);
}
@ -18,7 +24,7 @@ class vizhash16x16Test extends PHPUnit_Framework_TestCase
{
/* Tear Down Routine */
chmod($this->_path, 0700);
if(!@unlink($this->_file)) {
if (!@unlink($this->_file)) {
throw new Exception('Error deleting file "' . $this->_file . '".');
}
helper::rmdir($this->_path);