summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-08-27 21:50:15 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-08-27 21:50:15 +1000
commit913010cff5d09311ca6c8bc7a139d5deee82ba38 (patch)
treecbd95c15bde1c684d4e6a960e41a934c77764f31 /inc
parenteb146d92015e3bfe7b2fad68dd4b8c29542a31b3 (diff)
minor consistency cleanup
Diffstat (limited to 'inc')
-rw-r--r--inc/cache.php4
-rw-r--r--inc/database.php4
-rw-r--r--inc/display.php16
-rw-r--r--inc/events.php4
-rw-r--r--inc/image.php4
-rw-r--r--inc/mod-old.php287
-rw-r--r--inc/mod/auth.php8
-rw-r--r--inc/mod/pages.php22
-rw-r--r--inc/remote.php2
9 files changed, 32 insertions, 319 deletions
diff --git a/inc/cache.php b/inc/cache.php
index 0bb73589..2d376b70 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -20,7 +20,7 @@ class Cache {
self::$cache->addServers($config['cache']['memcached']);
break;
case 'php':
- self::$cache = Array();
+ self::$cache = array();
break;
}
}
@@ -112,7 +112,7 @@ class Cache {
case 'apc':
return apc_clear_cache('user');
case 'php':
- self::$cache[$key] = Array();
+ self::$cache[$key] = array();
break;
}
diff --git a/inc/database.php b/inc/database.php
index 6f68e7e4..50b4754d 100644
--- a/inc/database.php
+++ b/inc/database.php
@@ -30,7 +30,7 @@ class PreparedQueryDebug {
if ($config['debug'] && $function == 'execute') {
$time = round((microtime(true) - $start) * 1000, 2) . 'ms';
- $debug['sql'][] = Array(
+ $debug['sql'][] = array(
'query' => $this->query->queryString,
'rows' => $this->query->rowCount(),
'time' => '~' . $time
@@ -91,7 +91,7 @@ function query($query) {
if (!$query)
return false;
$time = round((microtime(true) - $start) * 1000, 2) . 'ms';
- $debug['sql'][] = Array(
+ $debug['sql'][] = array(
'query' => $query->queryString,
'rows' => $query->rowCount(),
'time' => '~' . $time
diff --git a/inc/display.php b/inc/display.php
index 1be066c2..706905b0 100644
--- a/inc/display.php
+++ b/inc/display.php
@@ -42,7 +42,7 @@ function doBoardListPart($list, $root) {
function createBoardlist($mod=false) {
global $config;
- if (!isset($config['boards'])) return Array('top'=>'','bottom'=>'');
+ if (!isset($config['boards'])) return array('top'=>'','bottom'=>'');
$body = doBoardListPart($config['boards'], $mod?'?/':$config['root']);
if (!preg_match('/\] $/', $body))
@@ -50,7 +50,7 @@ function createBoardlist($mod=false) {
$body = trim($body);
- return Array(
+ return array(
'top' => '<div class="boardlist">' . $body . '</div>',
'bottom' => '<div class="boardlist bottom">' . $body . '</div>'
);
@@ -69,7 +69,7 @@ function error($message, $priority = true) {
die('Error: ' . $message . "\n");
}
- die(Element('page.html', Array(
+ die(Element('page.html', array(
'config'=>$config,
'title'=>'Error',
'subtitle'=>'An error has occured.',
@@ -130,7 +130,7 @@ function capcode($cap) {
if (!$cap)
return false;
- $capcode = Array();
+ $capcode = array();
if (isset($config['custom_capcode'][$cap])) {
if (is_array($config['custom_capcode'][$cap])) {
$capcode['cap'] = sprintf($config['custom_capcode'][$cap][0], $cap);
@@ -174,7 +174,7 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) {
// Open tags
if (preg_match_all('/<([\w]+)[^>]*>/', $body, $open_tags)) {
- $tags = Array();
+ $tags = array();
for ($x=0;$x<count($open_tags[0]);$x++) {
if (!preg_match('/\/(\s+)?>$/', $open_tags[0][$x]))
$tags[] = $open_tags[1][$x];
@@ -300,7 +300,7 @@ class Post {
public function build($index=false) {
global $board, $config;
- return Element('post_reply.html', Array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
+ return Element('post_reply.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
}
};
@@ -328,7 +328,7 @@ class Thread {
$this->filename = $filename;
$this->omitted = 0;
$this->omitted_images = 0;
- $this->posts = Array();
+ $this->posts = array();
$this->ip = $ip;
$this->sticky = $sticky;
$this->locked = $locked;
@@ -425,7 +425,7 @@ class Thread {
public function build($index=false) {
global $board, $config, $debug;
- $built = Element('post_thread.html', Array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
+ $built = Element('post_thread.html', array('config' => $config, 'board' => $board, 'post' => &$this, 'index' => $index));
if (!$this->mod && $index && $config['cache']['enabled']) {
cache::set($this->cache_key($index), $built);
diff --git a/inc/events.php b/inc/events.php
index 5360a6a9..b825b570 100644
--- a/inc/events.php
+++ b/inc/events.php
@@ -35,7 +35,7 @@ function event_handler($event, $callback) {
global $events;
if (!isset($events[$event]))
- $events[$event] = Array();
+ $events[$event] = array();
$events[$event][] = $callback;
}
@@ -43,6 +43,6 @@ function event_handler($event, $callback) {
function reset_events() {
global $events;
- $events = Array();
+ $events = array();
}
diff --git a/inc/image.php b/inc/image.php
index 28242946..860dd4d8 100644
--- a/inc/image.php
+++ b/inc/image.php
@@ -34,7 +34,7 @@ class Image {
error($config['error']['invalidimg']);
}
- $this->size = (object)Array('width' => $this->image->_width(), 'height' => $this->image->_height());
+ $this->size = (object)array('width' => $this->image->_width(), 'height' => $this->image->_height());
if ($this->size->width < 1 || $this->size->height < 1) {
$this->delete();
error($config['error']['invalidimg']);
@@ -187,7 +187,7 @@ class ImageImagick extends ImageBase {
$this->image = new Imagick();
$this->image->setFormat('gif');
- $keep_frames = Array();
+ $keep_frames = array();
for ($i = 0; $i < $this->original->getNumberImages(); $i += floor($this->original->getNumberImages() / $config['thumb_keep_animation_frames']))
$keep_frames[] = $i;
diff --git a/inc/mod-old.php b/inc/mod-old.php
deleted file mode 100644
index 9065bb82..00000000
--- a/inc/mod-old.php
+++ /dev/null
@@ -1,287 +0,0 @@
-<?php
-
-/*
- * Copyright (c) 2010-2012 Tinyboard Development Group
- */
-
-if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
- // You cannot request this file directly.
- exit;
-}
-
-// create a hash/salt pair for validate logins
-function mkhash($username, $password, $salt = false) {
- global $config;
-
- if (!$salt) {
- // create some sort of salt for the hash
- $salt = substr(base64_encode(sha1(rand() . time(), true) . $config['cookies']['salt']), 0, 15);
-
- $generated_salt = true;
- }
-
- // generate hash (method is not important as long as it's strong)
- $hash = substr(base64_encode(md5($username . sha1($username . $password . $salt . ($config['mod']['lock_ip'] ? $_SERVER['REMOTE_ADDR'] : ''), true), true)), 0, 20);
-
- if (isset($generated_salt))
- return Array($hash, $salt);
- else
- return $hash;
-}
-
-function login($username, $password, $makehash=true) {
- global $mod;
-
- // SHA1 password
- if ($makehash) {
- $password = sha1($password);
- }
-
- $query = prepare("SELECT `id`,`type`,`boards` FROM `mods` WHERE `username` = :username AND `password` = :password LIMIT 1");
- $query->bindValue(':username', $username);
- $query->bindValue(':password', $password);
- $query->execute() or error(db_error($query));
-
- if ($user = $query->fetch()) {
- return $mod = Array(
- 'id' => $user['id'],
- 'type' => $user['type'],
- 'username' => $username,
- 'hash' => mkhash($username, $password),
- 'boards' => explode(',', $user['boards'])
- );
- } else return false;
-}
-
-function setCookies() {
- global $mod, $config;
- if (!$mod)
- error('setCookies() was called for a non-moderator!');
-
- setcookie($config['cookies']['mod'],
- $mod['username'] . // username
- ':' .
- $mod['hash'][0] . // password
- ':' .
- $mod['hash'][1], // salt
- time() + $config['cookies']['expire'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, true);
-}
-
-function destroyCookies() {
- global $config;
- // Delete the cookies
- setcookie($config['cookies']['mod'], 'deleted', time() - $config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path'] : '/', null, false, true);
-}
-
-function create_pm_header() {
- global $mod;
- $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1");
- $query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
-
- if ($pm = $query->fetch()) {
- return Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
- }
-
- return false;
-}
-
-function modLog($action, $_board=null) {
- global $mod, $board, $config;
- $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :board, :time, :text)");
- $query->bindValue(':id', $mod['id'], PDO::PARAM_INT);
- $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']);
- $query->bindValue(':time', time(), PDO::PARAM_INT);
- $query->bindValue(':text', $action);
- if (isset($_board))
- $query->bindValue(':board', $_board);
- elseif (isset($board))
- $query->bindValue(':board', $board['uri']);
- else
- $query->bindValue(':board', null, PDO::PARAM_NULL);
- $query->execute() or error(db_error($query));
-
- if ($config['syslog'])
- _syslog(LOG_INFO, '[mod/' . $mod['username'] . ']: ' . $action);
-}
-
-// Generates a <ul> element with a list of linked
-// boards and their subtitles. (without the <ul> opening and ending tags)
-function ulBoards() {
- global $mod, $config;
-
- $body = '';
-
- // List of boards
- $boards = listBoards();
-
- foreach ($boards as &$b) {
- $body .= '<li>' .
- '<a href="?/' .
- sprintf($config['board_path'], $b['uri']) . $config['file_index'] .
- '">' .
- sprintf($config['board_abbreviation'], $b['uri']) .
- '</a> - ' .
- $b['title'] .
- (isset($b['subtitle']) ? '<span class="unimportant"> — ' . $b['subtitle'] . '</span>' : '') .
- ($mod['type'] >= $config['mod']['manageboards'] ?
- ' <a href="?/' . $b['uri'] . '/edit" class="unimportant">[manage]</a>' : '') .
- '</li>';
- }
-
- if ($mod['type'] >= $config['mod']['newboard']) {
- $body .= '<li style="margin-top:15px;"><a href="?/new"><strong>' . _('Create new board') . '</strong></a></li>';
- }
- return $body;
-}
-
-function form_newBan($ip=null, $reason='', $continue=false, $delete=false, $board=false, $allow_public = false) {
- global $config, $mod;
-
- $boards = listBoards();
- $__boards = '<li><input type="radio" checked="checked" name="board" id="board_*" value=""/> <label style="display:inline" for="board_*"><em>' . _('all boards') . '</em></label></li>';
- foreach ($boards as &$_board) {
- $__boards .= '<li>' .
- '<input type="radio" name="board" id="board_' . $_board['uri'] . '" value="' . $_board['uri'] . '">' .
- '<label style="display:inline" for="board_' . $_board['uri'] . '"> ' .
- ($_board['uri'] == '*' ?
- '<em>"*"</em>'
- :
- sprintf($config['board_abbreviation'], $_board['uri'])
- ) .
- ' - ' . $_board['title'] .
- '</label>' .
- '</li>';
- }
-
- return '<fieldset><legend>New ban</legend>' .
- '<form action="?/ban" method="post">' .
- ($continue ? '<input type="hidden" name="continue" value="' . htmlentities($continue) . '" />' : '') .
- ($delete || $allow_public ? '<input type="hidden" name="' . (!$allow_public ? 'delete' : 'post') . '" value="' . htmlentities($delete) . '" />' : '') .
- ($board ? '<input type="hidden" name="board" value="' . htmlentities($board) . '" />' : '') .
- '<table>' .
- '<tr>' .
- '<th><label for="ip">IP ' .
- ($config['ban_cidr'] ? '<span class="unimportant">(or subnet)' : '') .
- '</span></label></th>' .
- '<td><input type="text" name="ip" id="ip" size="30" maxlength="30" ' .
- (isset($ip) ?
- 'value="' . htmlentities($ip) . '" ' : ''
- ) .
- '/></td>' .
- '</tr>' .
- '<tr>' .
- '<th><label for="reason">Reason</label></th>' .
- '<td><textarea name="reason" id="reason" rows="5" cols="30">' .
- htmlentities($reason) .
- '</textarea></td>' .
- '</tr>' .
- ($mod['type'] >= $config['mod']['public_ban'] && $allow_public ?
- '<tr>' .
- '<th><label for="message">Message</label></th>' .
- '<td><input type="checkbox" id="public_message" name="public_message"/>' .
- ' <input type="text" name="message" id="message" size="35" maxlength="200" value="' . htmlentities($config['mod']['default_ban_message']) . '" />' .
- ' <span class="unimportant">(public; attached to post)</span></td>' .
- '<script type="text/javascript">' .
- 'document.getElementById(\'message\').disabled = true;' .
- 'document.getElementById(\'public_message\').onchange = function() {' .
- 'document.getElementById(\'message\').disabled = !this.checked;' .
- '}' .
-
- '</script>' .
- '</tr>'
- : '') .
- '<tr>' .
- '<th><label for="length">Length</label></th>' .
- '<td><input type="text" name="length" id="length" size="20" maxlength="40" />' .
- ' <span class="unimportant">(eg. "2d1h30m" or "2 days")</span></td>' .
- '</tr>' .
-
- '<tr>' .
- '<th>Board</th>' .
- '<td><ul style="list-style:none;padding:2px 5px">' . $__boards . '</tl></td>' .
- '</tr>' .
-
- '<tr>' .
- '<td></td>' .
- '<td><input name="new_ban" type="submit" value="New Ban" /></td>' .
- '</tr>' .
- '</table>' .
- '</form>' .
- '</fieldset>';
-}
-
-function form_newBoard() {
- return '<fieldset><legend>New board</legend>' .
- '<form action="?/new" method="post">' .
- '<table>' .
- '<tr>' .
- '<th><label for="board">URI</label></th>' .
- '<td><input type="text" name="uri" id="board" size="10" />' .
- ' <span class="unimportant">(eg. "b"; "mu")</span></td>' .
- '</tr>' .
- '<tr>' .
- '<th><label for="title">Title</label></th>' .
- '<td><input type="text" name="title" id="title" size="25" />' .
- ' <span class="unimportant">(eg. "Random")</span></td>' .
- '</tr>' .
- '<tr>' .
- '<th><label for="subtitle">Subtitle</label></th>' .
- '<td><input type="text" name="subtitle" id="subtitle" size="25" />' .
- ' <span class="unimportant">(optional)</span></td>' .
- '</tr>' .
- '<tr>' .
- '<td></td>' .
- '<td><input name="new_board" type="submit" value="New Board" /></td>' .
- '</tr>' .
- '</table>' .
- '</form>' .
- '</fieldset>';
-}
-
-
-function removeBan($id) {
- global $config, $memcached;
-
- $query = prepare("DELETE FROM `bans` WHERE `id` = :id");
- $query->bindValue(':id', $id, PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
-
- //if ($config['memcached']['enabled']) {
- // Remove cached ban
- // TODO
- // $memcached->delete("ban_{$id}");
- //}
-}
-
-
-// Validate session
-
-if (isset($_COOKIE[$config['cookies']['mod']])) {
- // Should be username:hash:salt
- $cookie = explode(':', $_COOKIE[$config['cookies']['mod']]);
- if (count($cookie) != 3) {
- destroyCookies();
- error($config['error']['malformed']);
- }
-
- $query = prepare("SELECT `id`, `type`, `boards`, `password` FROM `mods` WHERE `username` = :username LIMIT 1");
- $query->bindValue(':username', $cookie[0]);
- $query->execute() or error(db_error($query));
- $user = $query->fetch();
-
- // validate password hash
- if ($cookie[1] != mkhash($cookie[0], $user['password'], $cookie[2])) {
- // Malformed cookies
- destroyCookies();
- error($config['error']['malformed']);
- }
-
- $mod = Array(
- 'id' => $user['id'],
- 'type' => $user['type'],
- 'username' => $cookie[0],
- 'boards' => explode(',', $user['boards'])
- );
-}
-
diff --git a/inc/mod/auth.php b/inc/mod/auth.php
index 6144a17d..9a13b3bb 100644
--- a/inc/mod/auth.php
+++ b/inc/mod/auth.php
@@ -24,7 +24,7 @@ function mkhash($username, $password, $salt = false) {
$hash = substr(base64_encode(md5($username . $config['cookies']['salt'] . sha1($username . $password . $salt . ($config['mod']['lock_ip'] ? $_SERVER['REMOTE_ADDR'] : ''), true), true)), 0, 20);
if (isset($generated_salt))
- return Array($hash, $salt);
+ return array($hash, $salt);
else
return $hash;
}
@@ -43,7 +43,7 @@ function login($username, $password, $makehash=true) {
$query->execute() or error(db_error($query));
if ($user = $query->fetch()) {
- return $mod = Array(
+ return $mod = array(
'id' => $user['id'],
'type' => $user['type'],
'username' => $username,
@@ -114,7 +114,7 @@ if (isset($_COOKIE[$config['cookies']['mod']])) {
error($config['error']['malformed']);
}
- $mod = Array(
+ $mod = array(
'id' => $user['id'],
'type' => $user['type'],
'username' => $cookie[0],
@@ -137,7 +137,7 @@ function create_pm_header() {
$query->execute() or error(db_error($query));
if ($pm = $query->fetch())
- $header = Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
+ $header = array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1);
else
$header = true;
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index 19ff8806..88ff3dd5 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -1678,9 +1678,9 @@ function mod_themes_list() {
if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']);
- if(!is_dir($config['dir']['themes']))
+ if (!is_dir($config['dir']['themes']))
error(_('Themes directory doesn\'t exist!'));
- if(!$dir = opendir($config['dir']['themes']))
+ if (!$dir = opendir($config['dir']['themes']))
error(_('Cannot open themes directory; check permissions.'));
$query = query('SELECT `theme` FROM `theme_settings` WHERE `name` IS NULL AND `value` IS NULL') or error(db_error());
@@ -1707,14 +1707,14 @@ function mod_theme_configure($theme_name) {
if (!hasPermission($config['mod']['themes']))
error($config['error']['noaccess']);
- if(!$theme = loadThemeConfig($theme_name)) {
+ if (!$theme = loadThemeConfig($theme_name)) {
error($config['error']['invalidtheme']);
}
- if(isset($_POST['install'])) {
+ if (isset($_POST['install'])) {
// Check if everything is submitted
- foreach($theme['config'] as &$conf) {
- if(!isset($_POST[$conf['name']]) && $conf['type'] != 'checkbox')
+ foreach ($theme['config'] as &$conf) {
+ if (!isset($_POST[$conf['name']]) && $conf['type'] != 'checkbox')
error(sprintf($config['error']['required'], $c['title']));
}
@@ -1723,7 +1723,7 @@ function mod_theme_configure($theme_name) {
$query->bindValue(':theme', $theme_name);
$query->execute() or error(db_error($query));
- foreach($theme['config'] as &$conf) {
+ foreach ($theme['config'] as &$conf) {
$query = prepare("INSERT INTO `theme_settings` VALUES(:theme, :name, :value)");
$query->bindValue(':theme', $theme_name);
$query->bindValue(':name', $conf['name']);
@@ -1737,17 +1737,17 @@ function mod_theme_configure($theme_name) {
$result = true;
$message = false;
- if(isset($theme['install_callback'])) {
+ if (isset($theme['install_callback'])) {
$ret = $theme['install_callback'](themeSettings($theme_name));
- if($ret && !empty($ret)) {
- if(is_array($ret) && count($ret) == 2) {
+ if ($ret && !empty($ret)) {
+ if (is_array($ret) && count($ret) == 2) {
$result = $ret[0];
$message = $ret[1];
}
}
}
- if(!$result) {
+ if (!$result) {
// Install failed
$query = prepare("DELETE FROM `theme_settings` WHERE `theme` = :theme");
$query->bindValue(':theme', $theme_name);
diff --git a/inc/remote.php b/inc/remote.php
index fe00373b..2afb1973 100644
--- a/inc/remote.php
+++ b/inc/remote.php
@@ -15,7 +15,7 @@ class Remote {
$this->{$name} = $value;
}
- $methods = Array();
+ $methods = array();
if (!isset($this->auth['method']))
error('Unspecified authentication method.');