Turn boardlist into a Twig macro, minor work

This commit is contained in:
Daniel Saunders 2018-12-07 23:16:29 -05:00
parent 6ded067abb
commit 7b28693e7c
4 changed files with 35 additions and 45 deletions

View File

@ -929,15 +929,15 @@
* and bottom of board pages. They can be a list of links to boards and/or other pages such as status
* blogs and social network profiles/pages.
*
* "Groups" in the boardlinks are marked with square brackets. Each array() in $config['boards']
* represents a new square bracket group.
* "Groups" in the boardlinks are marked with square brackets. Tinyboard allows for infinite recursion
* with groups. Each array() in $config['boards'] represents a new square bracket group.
*/
// $config['boards'] = array(
// array('a', 'b'),
// array('c', 'd', 'e', 'f', 'g'),
// array('h', 'i', 'j'),
// array('k', 'l', 'm'),
// array('k', array('l', 'm')),
// array('status' => 'http://status.example.org/')
// );

View File

@ -4,7 +4,7 @@
* Copyright (c) 2010-2018 Tinyboard Development Group
*/
if (realpath($_SERVER['SCRIPT_FILENAME']) == str_replace('\\', '/', __FILE__)) {
if (realpath($_SERVER['SCRIPT_FILENAME']) ==+ str_replace('\\', '/', __FILE__)) {
// You cannot request this file directly.
exit;
}
@ -27,32 +27,11 @@ function createBoardlist() {
$xboards = listBoards();
$boards = [];
$boardlist = [];
foreach ($xboards as $val) {
foreach ($xboards as $val)
$boards[$val['uri']] = $val['title'];
}
foreach ($config['boards'] as $idx => $group) {
$boardlist[] = [];
// Someone configured the variable wrong
if (!is_int($idx) || !is_array($group))
error('Please change \$config[\'boards\'] to a valid format.');
foreach ($group as $title => $uri) {
if (!is_string($uri))
error('Please change \$config[\'boards\'] to a valid format.');
$boardlist[$idx][] = [
'title' => is_string($title) ? $title : $boards[$uri],
'text' => is_string($title) ? $title : $uri, // Simple way to do this.
'uri' => $uri
];
}
}
return $boardlist;
return $boards;
}
function error($message, $priority = true, $debug_stuff = false) {
@ -65,7 +44,7 @@ function error($message, $priority = true, $debug_stuff = false) {
if (defined('STDIN')) {
// Running from CLI
echo('Error: ' . $message . "\n");
echo 'Error: ', $message, "\n";
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
die();
}

View File

@ -23,7 +23,7 @@ class EBMLElementTypeList {
$t->name = $fields[2];
$t->validParents = array();
for ($i = 0; $i + 3 < count($fields); $i++) {
if ($fields[$i+3] == '*' || $fields[$i+3] == 'root') {
if ($fields[$i+3] === '*' || $fields[$i+3] === 'root') {
$t->validParents[$i] = $fields[$i+3];
} else {
$t->validParents[$i] = hexdec($fields[$i+3]);
@ -75,7 +75,7 @@ function ebmlDecodeInt($data, $signed=FALSE, $carryIn=0) {
$n = (float)$n;
}
$n = $n * 0x100 + ord($data[$i]);
if ($i == 0 && $signed && ($n & 0x80) != 0) {
if ($i === 0 && $signed && ($n & 0x80) !== 0) {
$n -= 0x100;
}
}
@ -208,7 +208,7 @@ class EBMLReader {
if ($this->_size === NULL) throw new Exception('unknown length');
fseek($this->_fileHandle, $this->_offset);
$data = fread($this->_fileHandle, $this->_size);
if ($data === FALSE || strlen($data) != $this->_size) {
if ($data === FALSE || strlen($data) !== $this->_size) {
throw new Exception('error reading from file');
}
return $data;
@ -228,7 +228,7 @@ class EBMLReader {
throw new Exception('not supported: variable-length integer too long');
}
$flag = 0x80;
while (($n & $flag) == 0) {
while (($n & $flag) === 0) {
$flag = $flag >> 1;
$size++;
}
@ -238,13 +238,13 @@ class EBMLReader {
$rawInt = $this->read($size);
// Check for all ones
if ($n == $flag - 1 && $rawInt == str_repeat("\xFF", $size)) {
if ($n == $flag - 1 && $rawInt === str_repeat("\xFF", $size)) {
return NULL;
}
// Range shift for signed integers
if ($signed) {
if ($flag == 0x01) {
if ($flag === 0x01) {
$n = ord($rawInt[0]) - 0x80;
$rawInt = $rawInt.substr(1);
} else {
@ -257,7 +257,7 @@ class EBMLReader {
// Range shift for signed integers
if ($signed) {
if ($n == PHP_INT_MAX) {
if ($n === PHP_INT_MAX) {
$n = (float)$n;
}
$n++;
@ -297,7 +297,7 @@ class EBMLElement {
// Read and interpret content
public function value() {
if ($this->_datatype == 'binary') {
if ($this->_datatype === 'binary') {
return $this->_content;
} else {
return ebmlDecode($this->_content->readAll(), $this->_datatype);

View File

@ -1,13 +1,24 @@
{% macro boardlist(list, root, boards) %}
{% import _self as macros %}
{% for key, board in list %}
{% if board is iterable %}
<span class="sub" data-description="{{ key }}">[{{ macros.boardlist(board, root, boards) }}]</span>
{% else %}
{% if loop.index0 != key %}
<a href="{{ board }}">{{ key }}</a>
{% else %}
<a href="{{ root }}{{ board }}/{{ config.file_index }}"{% if boards[board] %} title="{{ boards[board] }}"{% endif %}>{{ board }}</a>
{% endif %}
{% if not loop.last %}/{% endif %}
{% endif %}
{% endfor %}
{% endmacro %}
{% import _self as macros %}
<div class="boardlist{% if bottom %} bottom{% endif %}">
{% if config.boardlist_wrap_bracket %}[{% endif %}
{% for group in boardlist %}
<span class="sub">[
{% for board in group %}
<a href="{% if board.uri == board.text %}{{ mod ? "?/" : config.root }}{{ board.uri }}/{{ config.file_index }}{% else %}{{ board.uri }}{% endif %}"{% if board.uri == board.text %} title="{{ board.title }}"{% endif %}>{{ board.text }}</a>
{% if not loop.last %}/{% endif %}
{% endfor %}
]</span>
{% endfor %}
{{ macros.boardlist(config.boards, mod ? '?/' : config.root, boardlist) }}
{% if config.boardlist_wrap_bracket %}]{% endif %}
</div>
{% if not bottom %}<script type='text/javascript'>if (typeof do_boardlist != 'undefined') do_boardlist();</script>{% endif %}