PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...

This commit is contained in:
Shish
2019-05-28 17:59:38 +01:00
parent 5ec3e89884
commit 34b05cca7c
295 changed files with 27094 additions and 24632 deletions

View File

@@ -7,11 +7,13 @@
* Description: Add HTML to some space (News, Ads, etc)
*/
class Blocks extends Extension {
public function onInitExt(InitExtEvent $event) {
global $config, $database;
if($config->get_int("ext_blocks_version") < 1) {
$database->create_table("blocks", "
class Blocks extends Extension
{
public function onInitExt(InitExtEvent $event)
{
global $config, $database;
if ($config->get_int("ext_blocks_version") < 1) {
$database->create_table("blocks", "
id SCORE_AIPK,
pages VARCHAR(128) NOT NULL,
title VARCHAR(128) NOT NULL,
@@ -19,73 +21,72 @@ class Blocks extends Extension {
priority INTEGER NOT NULL,
content TEXT NOT NULL
");
$database->execute("CREATE INDEX blocks_pages_idx ON blocks(pages)", array());
$config->set_int("ext_blocks_version", 1);
}
}
$database->execute("CREATE INDEX blocks_pages_idx ON blocks(pages)", []);
$config->set_int("ext_blocks_version", 1);
}
}
public function onUserBlockBuilding(UserBlockBuildingEvent $event) {
global $user;
if($user->can("manage_blocks")) {
$event->add_link("Blocks Editor", make_link("blocks/list"));
}
}
public function onUserBlockBuilding(UserBlockBuildingEvent $event)
{
global $user;
if ($user->can("manage_blocks")) {
$event->add_link("Blocks Editor", make_link("blocks/list"));
}
}
public function onPageRequest(PageRequestEvent $event) {
global $database, $page, $user;
public function onPageRequest(PageRequestEvent $event)
{
global $database, $page, $user;
$blocks = $database->cache->get("blocks");
if($blocks === false) {
$blocks = $database->get_all("SELECT * FROM blocks");
$database->cache->set("blocks", $blocks, 600);
}
foreach($blocks as $block) {
$path = implode("/", $event->args);
if(strlen($path) < 4000 && fnmatch($block['pages'], $path)) {
$b = new Block($block['title'], $block['content'], $block['area'], $block['priority']);
$b->is_content = false;
$page->add_block($b);
}
}
$blocks = $database->cache->get("blocks");
if ($blocks === false) {
$blocks = $database->get_all("SELECT * FROM blocks");
$database->cache->set("blocks", $blocks, 600);
}
foreach ($blocks as $block) {
$path = implode("/", $event->args);
if (strlen($path) < 4000 && fnmatch($block['pages'], $path)) {
$b = new Block($block['title'], $block['content'], $block['area'], $block['priority']);
$b->is_content = false;
$page->add_block($b);
}
}
if($event->page_matches("blocks") && $user->can("manage_blocks")) {
if($event->get_arg(0) == "add") {
if($user->check_auth_token()) {
$database->execute("
if ($event->page_matches("blocks") && $user->can("manage_blocks")) {
if ($event->get_arg(0) == "add") {
if ($user->check_auth_token()) {
$database->execute("
INSERT INTO blocks (pages, title, area, priority, content)
VALUES (?, ?, ?, ?, ?)
", array($_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content']));
log_info("blocks", "Added Block #".($database->get_last_insert_id('blocks_id_seq'))." (".$_POST['title'].")");
$database->cache->delete("blocks");
$page->set_mode("redirect");
$page->set_redirect(make_link("blocks/list"));
}
}
if($event->get_arg(0) == "update") {
if($user->check_auth_token()) {
if(!empty($_POST['delete'])) {
$database->execute("
", [$_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content']]);
log_info("blocks", "Added Block #".($database->get_last_insert_id('blocks_id_seq'))." (".$_POST['title'].")");
$database->cache->delete("blocks");
$page->set_mode("redirect");
$page->set_redirect(make_link("blocks/list"));
}
}
if ($event->get_arg(0) == "update") {
if ($user->check_auth_token()) {
if (!empty($_POST['delete'])) {
$database->execute("
DELETE FROM blocks
WHERE id=?
", array($_POST['id']));
log_info("blocks", "Deleted Block #".$_POST['id']);
}
else {
$database->execute("
", [$_POST['id']]);
log_info("blocks", "Deleted Block #".$_POST['id']);
} else {
$database->execute("
UPDATE blocks SET pages=?, title=?, area=?, priority=?, content=?
WHERE id=?
", array($_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content'], $_POST['id']));
log_info("blocks", "Updated Block #".$_POST['id']." (".$_POST['title'].")");
}
$database->cache->delete("blocks");
$page->set_mode("redirect");
$page->set_redirect(make_link("blocks/list"));
}
}
else if($event->get_arg(0) == "list") {
$this->theme->display_blocks($database->get_all("SELECT * FROM blocks ORDER BY area, priority"));
}
}
}
", [$_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content'], $_POST['id']]);
log_info("blocks", "Updated Block #".$_POST['id']." (".$_POST['title'].")");
}
$database->cache->delete("blocks");
$page->set_mode("redirect");
$page->set_redirect(make_link("blocks/list"));
}
} elseif ($event->get_arg(0) == "list") {
$this->theme->display_blocks($database->get_all("SELECT * FROM blocks ORDER BY area, priority"));
}
}
}
}

View File

@@ -1,10 +1,11 @@
<?php
class BlocksTest extends ShimmiePHPUnitTestCase {
public function testBlocks() {
$this->log_in_as_admin();
$this->get_page("blocks/list");
$this->assert_response(200);
$this->assert_title("Blocks");
}
class BlocksTest extends ShimmiePHPUnitTestCase
{
public function testBlocks()
{
$this->log_in_as_admin();
$this->get_page("blocks/list");
$this->assert_response(200);
$this->assert_title("Blocks");
}
}

View File

@@ -1,46 +1,47 @@
<?php
class BlocksTheme extends Themelet {
public function display_blocks($blocks) {
global $page;
class BlocksTheme extends Themelet
{
public function display_blocks($blocks)
{
global $page;
$html = "<table class='form' style='width: 100%;'>";
foreach($blocks as $block) {
$html .= make_form(make_link("blocks/update"));
$html .= "<input type='hidden' name='id' value='".html_escape($block['id'])."'>";
$html .= "<tr>";
$html .= "<th>Title</th><td><input type='text' name='title' value='".html_escape($block['title'])."'></td>";
$html .= "<th>Area</th><td><input type='text' name='area' value='".html_escape($block['area'])."'></td>";
$html .= "<th>Priority</th><td><input type='text' name='priority' value='".html_escape($block['priority'])."'></td>";
$html .= "<th>Pages</th><td><input type='text' name='pages' value='".html_escape($block['pages'])."'></td>";
$html .= "<th>Delete</th><td><input type='checkbox' name='delete'></td>";
$html .= "<td><input type='submit' value='Save'></td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td colspan='11'><textarea rows='5' name='content'>".html_escape($block['content'])."</textarea></td>";
$html .= "</tr>\n";
$html .= "<tr>";
$html .= "<td colspan='11'>&nbsp;</td>";
$html .= "</tr>\n";
$html .= "</form>\n";
}
$html .= make_form(make_link("blocks/add"));
$html .= "<tr>";
$html .= "<th>Title</th><td><input type='text' name='title' value=''></td>";
$html .= "<th>Area</th><td><select name='area'><option>left<option>main</select></td>";
$html .= "<th>Priority</th><td><input type='text' name='priority' value='50'></td>";
$html .= "<th>Pages</th><td><input type='text' name='pages' value='post/list*'></td>";
$html .= "<td colspan='3'><input type='submit' value='Add'></td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td colspan='11'><textarea rows='5' name='content'></textarea></td>";
$html .= "</tr>\n";
$html .= "</form>";
$html .= "</table>";
$html = "<table class='form' style='width: 100%;'>";
foreach ($blocks as $block) {
$html .= make_form(make_link("blocks/update"));
$html .= "<input type='hidden' name='id' value='".html_escape($block['id'])."'>";
$html .= "<tr>";
$html .= "<th>Title</th><td><input type='text' name='title' value='".html_escape($block['title'])."'></td>";
$html .= "<th>Area</th><td><input type='text' name='area' value='".html_escape($block['area'])."'></td>";
$html .= "<th>Priority</th><td><input type='text' name='priority' value='".html_escape($block['priority'])."'></td>";
$html .= "<th>Pages</th><td><input type='text' name='pages' value='".html_escape($block['pages'])."'></td>";
$html .= "<th>Delete</th><td><input type='checkbox' name='delete'></td>";
$html .= "<td><input type='submit' value='Save'></td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td colspan='11'><textarea rows='5' name='content'>".html_escape($block['content'])."</textarea></td>";
$html .= "</tr>\n";
$html .= "<tr>";
$html .= "<td colspan='11'>&nbsp;</td>";
$html .= "</tr>\n";
$html .= "</form>\n";
}
$html .= make_form(make_link("blocks/add"));
$html .= "<tr>";
$html .= "<th>Title</th><td><input type='text' name='title' value=''></td>";
$html .= "<th>Area</th><td><select name='area'><option>left<option>main</select></td>";
$html .= "<th>Priority</th><td><input type='text' name='priority' value='50'></td>";
$html .= "<th>Pages</th><td><input type='text' name='pages' value='post/list*'></td>";
$html .= "<td colspan='3'><input type='submit' value='Add'></td>";
$html .= "</tr>";
$html .= "<tr>";
$html .= "<td colspan='11'><textarea rows='5' name='content'></textarea></td>";
$html .= "</tr>\n";
$html .= "</form>";
$html .= "</table>";
$page->set_title("Blocks");
$page->set_heading("Blocks");
$page->add_block(new NavBlock());
$page->add_block(new Block("Block Editor", $html));
}
$page->set_title("Blocks");
$page->set_heading("Blocks");
$page->add_block(new NavBlock());
$page->add_block(new Block("Block Editor", $html));
}
}