make things use SimpleExtension
This commit is contained in:
parent
8dd3f8cbc0
commit
389eed5867
@ -13,27 +13,25 @@
|
||||
* tagged "holiday 2008")
|
||||
*/
|
||||
|
||||
class BulkAdd implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("bulk_add")) {
|
||||
if($event->user->is_admin() && isset($_POST['dir'])) {
|
||||
class BulkAdd extends SimpleExtension {
|
||||
public function onPageRequest($event) {
|
||||
global $page, $user;
|
||||
if($event->page_matches("bulk_add")) {
|
||||
if($user->is_admin() && isset($_POST['dir'])) {
|
||||
set_time_limit(0);
|
||||
|
||||
$this->add_dir($_POST['dir']);
|
||||
$this->theme->display_upload_results($event->page);
|
||||
$this->theme->display_upload_results($page);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof AdminBuildingEvent) {
|
||||
global $page;
|
||||
$this->theme->display_admin_block($page);
|
||||
}
|
||||
}
|
||||
|
||||
public function onAdminBuilding($event) {
|
||||
global $page;
|
||||
$this->theme->display_admin_block($page);
|
||||
}
|
||||
|
||||
|
||||
private function add_image($tmpname, $filename, $tags) {
|
||||
if(file_exists($tmpname)) {
|
||||
global $user;
|
||||
@ -97,5 +95,4 @@ class BulkAdd implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new BulkAdd());
|
||||
?>
|
||||
|
@ -10,22 +10,22 @@
|
||||
* <br>7-zip: <code>7zr x -o"%d" "%f"</code>
|
||||
*/
|
||||
|
||||
class ArchiveFileHandler implements Extension {
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof InitExtEvent) {
|
||||
global $config;
|
||||
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');
|
||||
}
|
||||
class ArchiveFileHandler extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config;
|
||||
$config->set_default_string('archive_extract_command', 'unzip -d "%d" "%f"');
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("Archive Handler Options");
|
||||
$sb->add_text_option("archive_tmp_dir", "Temporary folder: ");
|
||||
$sb->add_text_option("archive_extract_command", "<br>Extraction command: ");
|
||||
$sb->add_label("<br>%f for archive, %d for temporary directory");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Archive Handler Options");
|
||||
$sb->add_text_option("archive_tmp_dir", "Temporary folder: ");
|
||||
$sb->add_text_option("archive_extract_command", "<br>Extraction command: ");
|
||||
$sb->add_label("<br>%f for archive, %d for temporary directory");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type)) {
|
||||
public function onDataUpload($event) {
|
||||
if($this->supported_ext($event->type)) {
|
||||
global $config;
|
||||
$tmp = sys_get_temp_dir();
|
||||
$tmpdir = "$tmp/shimmie-archive-{$event->hash}";
|
||||
@ -38,6 +38,7 @@ class ArchiveFileHandler implements Extension {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function supported_ext($ext) {
|
||||
$exts = array("zip");
|
||||
return array_contains($exts, strtolower($ext));
|
||||
@ -100,5 +101,4 @@ class ArchiveFileHandler implements Extension {
|
||||
// $this->theme->add_status("Adding $subdir", $list);
|
||||
}
|
||||
}
|
||||
add_event_listener(new ArchiveFileHandler());
|
||||
?>
|
||||
|
@ -5,13 +5,9 @@
|
||||
* Description: Handle Flash files
|
||||
*/
|
||||
|
||||
class FlashFileHandler implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
class FlashFileHandler extends SimpleExtension {
|
||||
public function onDataUpload($event) {
|
||||
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
$hash = $event->hash;
|
||||
$ha = substr($hash, 0, 2);
|
||||
if(!move_upload_to_archive($event)) return;
|
||||
@ -24,19 +20,25 @@ class FlashFileHandler implements Extension {
|
||||
}
|
||||
send_event(new ImageAdditionEvent($event->user, $image));
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
|
||||
public function onThumbnailGeneration($event) {
|
||||
if($this->supported_ext($event->type)) {
|
||||
$hash = $event->hash;
|
||||
$ha = substr($hash, 0, 2);
|
||||
// FIXME: scale image, as not all boards use 192x192
|
||||
copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash");
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
|
||||
public function onDisplayingImage($event) {
|
||||
global $page;
|
||||
if($this->supported_ext($event->image->ext)) {
|
||||
$this->theme->display_image($event->page, $event->image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function supported_ext($ext) {
|
||||
$exts = array("swf");
|
||||
return array_contains($exts, strtolower($ext));
|
||||
@ -127,5 +129,4 @@ class FlashFileHandler implements Extension {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
add_event_listener(new FlashFileHandler());
|
||||
?>
|
||||
|
@ -5,13 +5,9 @@
|
||||
* Description: Handle windows icons
|
||||
*/
|
||||
|
||||
class IcoFileHandler implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
class IcoFileHandler extends SimpleExtension {
|
||||
public function onDataUpload($event) {
|
||||
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
|
||||
$hash = $event->hash;
|
||||
$ha = substr($hash, 0, 2);
|
||||
if(!move_upload_to_archive($event)) return;
|
||||
@ -22,29 +18,35 @@ class IcoFileHandler implements Extension {
|
||||
}
|
||||
send_event(new ImageAdditionEvent($event->user, $image));
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
|
||||
public function onThumbnailGeneration($event) {
|
||||
if($this->supported_ext($event->type)) {
|
||||
$this->create_thumb($event->hash);
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
|
||||
public function onDisplayingImage($event) {
|
||||
if($this->supported_ext($event->image->ext)) {
|
||||
$this->theme->display_image($event->page, $event->image);
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("get_ico")) {
|
||||
global $config;
|
||||
global $database;
|
||||
public function onPageRequest($event) {
|
||||
global $config, $database;
|
||||
if($event->page_matches("get_ico")) {
|
||||
$id = int_escape($event->get_arg(0));
|
||||
$image = Image::by_id($id);
|
||||
$hash = $image->hash;
|
||||
$ha = substr($hash, 0, 2);
|
||||
|
||||
$event->page->set_type("image/x-icon");
|
||||
$event->page->set_mode("data");
|
||||
$event->page->set_data(file_get_contents("images/$ha/$hash"));
|
||||
$page->set_type("image/x-icon");
|
||||
$page->set_mode("data");
|
||||
$page->set_data(file_get_contents("images/$ha/$hash"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function supported_ext($ext) {
|
||||
$exts = array("ico", "ani", "cur");
|
||||
return array_contains($exts, strtolower($ext));
|
||||
@ -106,5 +108,4 @@ class IcoFileHandler implements Extension {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
add_event_listener(new IcoFileHandler());
|
||||
?>
|
||||
|
@ -14,35 +14,37 @@
|
||||
* alongside the default choices.
|
||||
*/
|
||||
|
||||
class Home implements Extension {
|
||||
var $theme;
|
||||
class Home extends SimpleExtension {
|
||||
public function onPageRequest($event) {
|
||||
global $config, $page;
|
||||
if($event->page_matches("home")) {
|
||||
$base_href = $config->get_string('base_href');
|
||||
$data_href = get_base_href();
|
||||
$sitename = $config->get_string('title');
|
||||
$theme_name = $config->get_string('theme');
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
$body = $this->get_body();
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("home"))
|
||||
{
|
||||
// this is a request to display this page so output the page.
|
||||
$this->output_pages($page);
|
||||
}
|
||||
if($event instanceof SetupBuildingEvent)
|
||||
{
|
||||
$counters = array();
|
||||
foreach(glob("ext/home/counters/*") as $counter_dirname) {
|
||||
$name = str_replace("ext/home/counters/", "", $counter_dirname);
|
||||
$counters[ucfirst($name)] = $name;
|
||||
}
|
||||
|
||||
$sb = new SetupBlock("Home Page");
|
||||
$sb->add_label("Page Links - Example: [$"."base/index|Posts]");
|
||||
$sb->add_longtext_option("home_links", "<br>");
|
||||
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
|
||||
$sb->add_label("<br>Note: page accessed via /home");
|
||||
$event->panel->add_block($sb);
|
||||
$this->theme->display_page($page, $sitename, $data_href, $theme_name, $body);
|
||||
}
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$counters = array();
|
||||
foreach(glob("ext/home/counters/*") as $counter_dirname) {
|
||||
$name = str_replace("ext/home/counters/", "", $counter_dirname);
|
||||
$counters[ucfirst($name)] = $name;
|
||||
}
|
||||
|
||||
$sb = new SetupBlock("Home Page");
|
||||
$sb->add_label("Page Links - Example: [$"."base/index|Posts]");
|
||||
$sb->add_longtext_option("home_links", "<br>");
|
||||
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
|
||||
$sb->add_label("<br>Note: page accessed via /home");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
|
||||
private function get_body()
|
||||
{
|
||||
// returns just the contents of the body
|
||||
@ -75,21 +77,5 @@ class Home implements Extension {
|
||||
|
||||
return $this->theme->build_body($sitename, $main_links, $contact_link, $num_comma, $counter_text);
|
||||
}
|
||||
|
||||
private function output_pages($page)
|
||||
{
|
||||
// output a sectionalised list of all the main pages on the site.
|
||||
global $config;
|
||||
$base_href = $config->get_string('base_href');
|
||||
$data_href = get_base_href();
|
||||
$sitename = $config->get_string('title');
|
||||
$theme_name = $config->get_string('theme');
|
||||
|
||||
$body = $this->get_body();
|
||||
|
||||
$this->theme->display_page($page, $sitename, $data_href, $theme_name, $body);
|
||||
}
|
||||
|
||||
}
|
||||
add_event_listener(new Home());
|
||||
?>
|
||||
|
@ -8,25 +8,18 @@
|
||||
* Any HTML is allowed
|
||||
*/
|
||||
|
||||
class News implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if($event instanceof PostListBuildingEvent) {
|
||||
if(strlen($config->get_string("news_text")) > 0) {
|
||||
$this->theme->display_news($page, $config->get_string("news_text"));
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("News");
|
||||
$sb->add_longtext_option("news_text");
|
||||
$event->panel->add_block($sb);
|
||||
class News extends SimpleExtension {
|
||||
public function onPostListBuilding($event) {
|
||||
global $config, $page;
|
||||
if(strlen($config->get_string("news_text")) > 0) {
|
||||
$this->theme->display_news($page, $config->get_string("news_text"));
|
||||
}
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("News");
|
||||
$sb->add_longtext_option("news_text");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
add_event_listener(new News());
|
||||
?>
|
||||
|
@ -14,47 +14,58 @@ class SendPMEvent extends Event {
|
||||
public function __construct($from_id, $from_ip, $to_id, $subject, $message) {
|
||||
$this->from_id = $from_id;
|
||||
$this->from_ip = $from_ip;
|
||||
$this->to_id = $to_id;
|
||||
$this->to_id = $to_id;
|
||||
$this->subject = $subject;
|
||||
$this->message = $message;
|
||||
}
|
||||
}
|
||||
|
||||
class PM implements Extension {
|
||||
var $theme;
|
||||
class PM extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config, $database;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
// shortcut to latest
|
||||
if($config->get_int("pm_version") < 1) {
|
||||
$database->create_table("private_message", "
|
||||
id SCORE_AIPK,
|
||||
from_id INTEGER NOT NULL,
|
||||
from_ip SCORE_INET NOT NULL,
|
||||
to_id INTEGER NOT NULL,
|
||||
sent_date DATETIME NOT NULL,
|
||||
subject VARCHAR(64) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
||||
INDEX (to_id)
|
||||
");
|
||||
$config->set_int("pm_version", 1);
|
||||
log_info("pm", "extension installed");
|
||||
}
|
||||
}
|
||||
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
/*
|
||||
public function onUserBlockBuilding($event) {
|
||||
global $user;
|
||||
if(!$user->is_anonymous()) {
|
||||
$event->add_link("Private Messages", make_link("pm"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if($event instanceof InitExtEvent) {
|
||||
if($config->get_int("pm_version") < 1) {
|
||||
$this->install();
|
||||
public function onUserPageBuilding($event) {
|
||||
global $page, $user;
|
||||
$duser = $event->display_user;
|
||||
if(!$user->is_anonymous() && !$duser->is_anonymous()) {
|
||||
if(($user->id == $duser->id) || $user->is_admin()) {
|
||||
$this->theme->display_pms($page, $this->get_pms($duser));
|
||||
}
|
||||
if($user->id != $duser->id) {
|
||||
$this->theme->display_composer($page, $user, $duser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if($event instanceof UserBlockBuildingEvent) {
|
||||
if(!$user->is_anonymous()) {
|
||||
$event->add_link("Private Messages", make_link("pm"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if($event instanceof UserPageBuildingEvent) {
|
||||
$duser = $event->display_user;
|
||||
if(!$user->is_anonymous() && !$duser->is_anonymous()) {
|
||||
if(($user->id == $duser->id) || $user->is_admin()) {
|
||||
$this->theme->display_pms($page, $this->get_pms($duser));
|
||||
}
|
||||
if($user->id != $duser->id) {
|
||||
$this->theme->display_composer($page, $user, $duser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) {
|
||||
public function onPageRequest($event) {
|
||||
if($event->page_matches("pm")) {
|
||||
if(!$user->is_anonymous()) {
|
||||
switch($event->get_arg(0)) {
|
||||
case "read":
|
||||
@ -100,42 +111,21 @@ class PM implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SendPMEvent) {
|
||||
$database->execute("
|
||||
INSERT INTO private_message(
|
||||
from_id, from_ip, to_id,
|
||||
sent_date, subject, message)
|
||||
VALUES(?, ?, ?, now(), ?, ?)",
|
||||
array($event->from_id, $event->from_ip,
|
||||
$event->to_id, $event->subject, $event->message)
|
||||
);
|
||||
log_info("pm", "Sent PM to User #$to_id");
|
||||
}
|
||||
}
|
||||
|
||||
protected function install() {
|
||||
global $config, $database;
|
||||
|
||||
// shortcut to latest
|
||||
if($config->get_int("pm_version") < 1) {
|
||||
$database->create_table("private_message", "
|
||||
id SCORE_AIPK,
|
||||
from_id INTEGER NOT NULL,
|
||||
from_ip SCORE_INET NOT NULL,
|
||||
to_id INTEGER NOT NULL,
|
||||
sent_date DATETIME NOT NULL,
|
||||
subject VARCHAR(64) NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
||||
INDEX (to_id)
|
||||
");
|
||||
$config->set_int("pm_version", 1);
|
||||
}
|
||||
|
||||
log_info("pm", "extension installed");
|
||||
public function onSendPM($event) {
|
||||
$database->execute("
|
||||
INSERT INTO private_message(
|
||||
from_id, from_ip, to_id,
|
||||
sent_date, subject, message)
|
||||
VALUES(?, ?, ?, now(), ?, ?)",
|
||||
array($event->from_id, $event->from_ip,
|
||||
$event->to_id, $event->subject, $event->message)
|
||||
);
|
||||
log_info("pm", "Sent PM to User #$to_id");
|
||||
}
|
||||
|
||||
|
||||
private function get_pms(User $user) {
|
||||
global $database;
|
||||
|
||||
@ -147,5 +137,4 @@ class PM implements Extension {
|
||||
", array($user->id));
|
||||
}
|
||||
}
|
||||
add_event_listener(new PM());
|
||||
?>
|
||||
|
@ -6,74 +6,63 @@
|
||||
* Description: Self explanitory
|
||||
*/
|
||||
|
||||
class RSS_Comments implements Extension {
|
||||
// event handling {{{
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof PostListBuildingEvent) {
|
||||
global $page;
|
||||
global $config;
|
||||
$title = $config->get_string('title');
|
||||
|
||||
$page->add_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
|
||||
}
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("rss")) {
|
||||
if($event->get_arg(0) == 'comments') {
|
||||
global $database;
|
||||
$this->do_rss($database);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
// output {{{
|
||||
private function do_rss($database) {
|
||||
global $page;
|
||||
global $config;
|
||||
$page->set_mode("data");
|
||||
$page->set_type("application/rss+xml");
|
||||
|
||||
$comments = $database->get_all("
|
||||
SELECT
|
||||
users.id as user_id, users.name as user_name,
|
||||
comments.comment as comment, comments.id as comment_id,
|
||||
comments.image_id as image_id, comments.owner_ip as poster_ip,
|
||||
UNIX_TIMESTAMP(posted) AS posted_timestamp
|
||||
FROM comments
|
||||
LEFT JOIN users ON comments.owner_id=users.id
|
||||
ORDER BY comments.id DESC
|
||||
LIMIT 10
|
||||
");
|
||||
|
||||
$data = "";
|
||||
foreach($comments as $comment) {
|
||||
$image_id = $comment['image_id'];
|
||||
$comment_id = $comment['comment_id'];
|
||||
$link = make_link("post/view/$image_id");
|
||||
$owner = html_escape($comment['user_name']);
|
||||
$posted = date(DATE_RSS, $comment['posted_timestamp']);
|
||||
$comment = html_escape($comment['comment']);
|
||||
$content = html_escape("$owner: $comment");
|
||||
|
||||
$data .= "
|
||||
<item>
|
||||
<title>$owner comments on $image_id</title>
|
||||
<link>$link</link>
|
||||
<guid isPermaLink=\"false\">$comment_id</guid>
|
||||
<pubDate>$posted</pubDate>
|
||||
<description>$content</description>
|
||||
</item>
|
||||
";
|
||||
}
|
||||
|
||||
class RSS_Comments extends SimpleExtension {
|
||||
public function onPostListBuilding($event) {
|
||||
global $config, $page;
|
||||
$title = $config->get_string('title');
|
||||
$base_href = $config->get_string('base_href');
|
||||
$version = $config->get_string('version');
|
||||
$xml = <<<EOD
|
||||
|
||||
$page->add_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
|
||||
}
|
||||
|
||||
public function onPageRequest($event) {
|
||||
global $config, $database, $page;
|
||||
if($event->page_matches("rss/comments")) {
|
||||
$page->set_mode("data");
|
||||
$page->set_type("application/rss+xml");
|
||||
|
||||
$comments = $database->get_all("
|
||||
SELECT
|
||||
users.id as user_id, users.name as user_name,
|
||||
comments.comment as comment, comments.id as comment_id,
|
||||
comments.image_id as image_id, comments.owner_ip as poster_ip,
|
||||
UNIX_TIMESTAMP(posted) AS posted_timestamp
|
||||
FROM comments
|
||||
LEFT JOIN users ON comments.owner_id=users.id
|
||||
ORDER BY comments.id DESC
|
||||
LIMIT 10
|
||||
");
|
||||
|
||||
$data = "";
|
||||
foreach($comments as $comment) {
|
||||
$image_id = $comment['image_id'];
|
||||
$comment_id = $comment['comment_id'];
|
||||
$link = make_link("post/view/$image_id");
|
||||
$owner = html_escape($comment['user_name']);
|
||||
$posted = date(DATE_RSS, $comment['posted_timestamp']);
|
||||
$comment = html_escape($comment['comment']);
|
||||
$content = html_escape("$owner: $comment");
|
||||
|
||||
$data .= "
|
||||
<item>
|
||||
<title>$owner comments on $image_id</title>
|
||||
<link>$link</link>
|
||||
<guid isPermaLink=\"false\">$comment_id</guid>
|
||||
<pubDate>$posted</pubDate>
|
||||
<description>$content</description>
|
||||
</item>
|
||||
";
|
||||
}
|
||||
|
||||
$title = $config->get_string('title');
|
||||
$base_href = $config->get_string('base_href');
|
||||
$version = $config->get_string('version');
|
||||
$xml = <<<EOD
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>$title</title>
|
||||
<description>The latest comments on the image board</description>
|
||||
<channel>
|
||||
<title>$title</title>
|
||||
<description>The latest comments on the image board</description>
|
||||
<link>$base_href</link>
|
||||
<generator>$version</generator>
|
||||
<copyright>(c) 2007 Shish</copyright>
|
||||
@ -81,9 +70,8 @@ class RSS_Comments implements Extension {
|
||||
</channel>
|
||||
</rss>
|
||||
EOD;
|
||||
$page->set_data($xml);
|
||||
$page->set_data($xml);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new RSS_Comments());
|
||||
?>
|
||||
|
@ -6,26 +6,24 @@
|
||||
* Description: Self explanitory
|
||||
*/
|
||||
|
||||
class RSS_Images implements Extension {
|
||||
// event handling {{{
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
class RSS_Images extends SimpleExtension {
|
||||
public function onPostListBuilding($event) {
|
||||
global $config, $page;
|
||||
$title = $config->get_string('title');
|
||||
|
||||
if($event instanceof PostListBuildingEvent) {
|
||||
$title = $config->get_string('title');
|
||||
|
||||
if(count($event->search_terms) > 0) {
|
||||
$search = implode(' ', $event->search_terms);
|
||||
$page->add_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images with tags: $search\" href=\"".make_link("rss/images/$search/1")."\" />");
|
||||
}
|
||||
else {
|
||||
$page->add_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images\" href=\"".make_link("rss/images/1")."\" />");
|
||||
}
|
||||
if(count($event->search_terms) > 0) {
|
||||
$search = implode(' ', $event->search_terms);
|
||||
$page->add_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images with tags: $search\" href=\"".make_link("rss/images/$search/1")."\" />");
|
||||
}
|
||||
else {
|
||||
$page->add_header("<link id=\"images\" rel=\"alternate\" type=\"application/rss+xml\" ".
|
||||
"title=\"$title - Images\" href=\"".make_link("rss/images/1")."\" />");
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) {
|
||||
public function onPageRequest($event) {
|
||||
if($event->page_matches("rss/images")) {
|
||||
$page_number = 0;
|
||||
$search_terms = array();
|
||||
|
||||
@ -46,8 +44,8 @@ class RSS_Images implements Extension {
|
||||
$this->do_rss($images, $search_terms, $page_number);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
// output {{{
|
||||
|
||||
|
||||
private function do_rss($images, $search_terms, $page_number) {
|
||||
global $page;
|
||||
global $config;
|
||||
@ -113,7 +111,5 @@ class RSS_Images implements Extension {
|
||||
</rss>";
|
||||
$page->set_data($xml);
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new RSS_Images());
|
||||
?>
|
||||
|
@ -21,14 +21,10 @@ class TestFinder extends TestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleSCoreTest implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
|
||||
class SimpleSCoreTest extends SimpleExtension {
|
||||
public function onPageRequest($event) {
|
||||
global $page;
|
||||
if($event->page_matches("test")) {
|
||||
$page->set_title("Test Results");
|
||||
$page->set_heading("Test Results");
|
||||
$page->add_block(new NavBlock());
|
||||
@ -36,13 +32,13 @@ class SimpleSCoreTest implements Extension {
|
||||
$all = new TestFinder($event->get_arg(0));
|
||||
$all->run(new SCoreReporter($page));
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof UserBlockBuildingEvent) {
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Run Tests", make_link("test/all"));
|
||||
}
|
||||
public function onUserBlockBuilding($event) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Run Tests", make_link("test/all"));
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new SimpleSCoreTest());
|
||||
?>
|
||||
|
@ -6,24 +6,16 @@
|
||||
* Description: Scales down too-large images using browser based scaling
|
||||
*/
|
||||
|
||||
class Zoom implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if($this->theme == null) $this->theme = get_theme_object($this);
|
||||
|
||||
if($event instanceof DisplayingImageEvent) {
|
||||
$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("Image Zoom");
|
||||
$sb->add_bool_option("image_zoom", "Zoom by default: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
class Zoom extends SimpleExtension {
|
||||
public function onDisplayingImage($event) {
|
||||
global $config, $page;
|
||||
$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Image Zoom");
|
||||
$sb->add_bool_option("image_zoom", "Zoom by default: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
add_event_listener(new Zoom());
|
||||
?>
|
||||
|
@ -1,14 +1,7 @@
|
||||
<?php
|
||||
|
||||
class BBCode implements Extension {
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof TextFormattingEvent) {
|
||||
$event->formatted = $this->bbcode_to_html($event->formatted);
|
||||
$event->stripped = $this->bbcode_to_text($event->stripped);
|
||||
}
|
||||
}
|
||||
|
||||
private function bbcode_to_html($text) {
|
||||
class BBCode extends FormatterExtension {
|
||||
public function format($text) {
|
||||
$text = $this->extract_code($text);
|
||||
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $text);
|
||||
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
|
||||
@ -42,7 +35,7 @@ class BBCode implements Extension {
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function bbcode_to_text($text) {
|
||||
public function strip($text) {
|
||||
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text);
|
||||
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text);
|
||||
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text);
|
||||
@ -65,6 +58,7 @@ class BBCode implements Extension {
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
private function filter_spoiler($text) {
|
||||
return str_replace(
|
||||
array("[spoiler]","[/spoiler]"),
|
||||
|
@ -68,14 +68,10 @@ class ExtensionInfo { // {{{
|
||||
}
|
||||
} // }}}
|
||||
|
||||
class ExtManager implements Extension {
|
||||
var $theme;
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_manager")) {
|
||||
class ExtManager extends SimpleExtension {
|
||||
public function onPageRequest($event) {
|
||||
global $page, $user;
|
||||
if($event->page_matches("ext_manager")) {
|
||||
if($user->is_admin()) {
|
||||
if($event->get_arg(0) == "set") {
|
||||
if(is_writable("ext")) {
|
||||
@ -97,19 +93,21 @@ class ExtManager implements Extension {
|
||||
}
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) {
|
||||
if($event->page_matches("ext_doc")) {
|
||||
$ext = $event->get_arg(0);
|
||||
$info = new ExtensionInfo("contrib/$ext/main.php");
|
||||
$this->theme->display_doc($page, $info);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof UserBlockBuildingEvent) {
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Extension Manager", make_link("ext_manager"));
|
||||
}
|
||||
public function onUserBlockBuilding($event) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Extension Manager", make_link("ext_manager"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function get_extensions() {
|
||||
$extensions = array();
|
||||
foreach(glob("contrib/*/main.php") as $main) {
|
||||
@ -152,5 +150,4 @@ class ExtManager implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new ExtManager());
|
||||
?>
|
||||
|
@ -74,77 +74,75 @@ class ParseLinkTemplateEvent extends Event {
|
||||
* A class to handle adding / getting / removing image
|
||||
* files from the disk
|
||||
*/
|
||||
class ImageIO implements Extension {
|
||||
// event handling {{{
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof InitExtEvent) {
|
||||
global $config;
|
||||
$config->set_default_int('thumb_width', 192);
|
||||
$config->set_default_int('thumb_height', 192);
|
||||
$config->set_default_int('thumb_quality', 75);
|
||||
$config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
|
||||
class ImageIO extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config;
|
||||
$config->set_default_int('thumb_width', 192);
|
||||
$config->set_default_int('thumb_height', 192);
|
||||
$config->set_default_int('thumb_quality', 75);
|
||||
$config->set_default_int('thumb_mem_limit', parse_shorthand_int('8MB'));
|
||||
|
||||
$config->set_default_string('image_ilink', '');
|
||||
$config->set_default_string('image_tlink', '');
|
||||
$config->set_default_string('image_tip', '$tags // $size // $filesize');
|
||||
$config->set_default_string('upload_collision_handler', 'error');
|
||||
}
|
||||
$config->set_default_string('image_ilink', '');
|
||||
$config->set_default_string('image_tlink', '');
|
||||
$config->set_default_string('image_tip', '$tags // $size // $filesize');
|
||||
$config->set_default_string('upload_collision_handler', 'error');
|
||||
}
|
||||
|
||||
if($event instanceof PageRequestEvent) {
|
||||
$num = $event->get_arg(0);
|
||||
$matches = array();
|
||||
if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) {
|
||||
$num = $matches[1];
|
||||
public function onPageRequest($event) {
|
||||
$num = $event->get_arg(0);
|
||||
$matches = array();
|
||||
if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) {
|
||||
$num = $matches[1];
|
||||
|
||||
if($event->page_matches("image")) {
|
||||
$this->send_file($num, "image");
|
||||
}
|
||||
else if($event->page_matches("thumb")) {
|
||||
$this->send_file($num, "thumb");
|
||||
}
|
||||
if($event->page_matches("image")) {
|
||||
$this->send_file($num, "image");
|
||||
}
|
||||
else if($event->page_matches("thumb")) {
|
||||
$this->send_file($num, "thumb");
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof ImageAdditionEvent) {
|
||||
$error = $this->add_image($event->image);
|
||||
if(!empty($error)) throw new UploadException($error);
|
||||
}
|
||||
|
||||
if($event instanceof ImageDeletionEvent) {
|
||||
$event->image->delete();
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("Image Options");
|
||||
$sb->position = 30;
|
||||
// advanced only
|
||||
//$sb->add_text_option("image_ilink", "Image link: ");
|
||||
//$sb->add_text_option("image_tlink", "<br>Thumbnail link: ");
|
||||
$sb->add_text_option("image_tip", "Image tooltip: ");
|
||||
$sb->add_choice_option("upload_collision_handler", array('Error'=>'error', 'Merge'=>'merge'), "<br>Upload collision handler: ");
|
||||
$event->panel->add_block($sb);
|
||||
|
||||
$thumbers = array();
|
||||
$thumbers['Built-in GD'] = "gd";
|
||||
$thumbers['ImageMagick'] = "convert";
|
||||
|
||||
$sb = new SetupBlock("Thumbnailing");
|
||||
$sb->add_choice_option("thumb_engine", $thumbers, "Engine: ");
|
||||
|
||||
$sb->add_label("<br>Size ");
|
||||
$sb->add_int_option("thumb_width");
|
||||
$sb->add_label(" x ");
|
||||
$sb->add_int_option("thumb_height");
|
||||
$sb->add_label(" px at ");
|
||||
$sb->add_int_option("thumb_quality");
|
||||
$sb->add_label(" % quality ");
|
||||
|
||||
$sb->add_shorthand_int_option("thumb_mem_limit", "<br>Max memory use: ");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
public function onImageAddition($event) {
|
||||
$error = $this->add_image($event->image);
|
||||
if(!empty($error)) throw new UploadException($error);
|
||||
}
|
||||
|
||||
public function onImageDeletion($event) {
|
||||
$event->image->delete();
|
||||
}
|
||||
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Image Options");
|
||||
$sb->position = 30;
|
||||
// advanced only
|
||||
//$sb->add_text_option("image_ilink", "Image link: ");
|
||||
//$sb->add_text_option("image_tlink", "<br>Thumbnail link: ");
|
||||
$sb->add_text_option("image_tip", "Image tooltip: ");
|
||||
$sb->add_choice_option("upload_collision_handler", array('Error'=>'error', 'Merge'=>'merge'), "<br>Upload collision handler: ");
|
||||
$event->panel->add_block($sb);
|
||||
|
||||
$thumbers = array();
|
||||
$thumbers['Built-in GD'] = "gd";
|
||||
$thumbers['ImageMagick'] = "convert";
|
||||
|
||||
$sb = new SetupBlock("Thumbnailing");
|
||||
$sb->add_choice_option("thumb_engine", $thumbers, "Engine: ");
|
||||
|
||||
$sb->add_label("<br>Size ");
|
||||
$sb->add_int_option("thumb_width");
|
||||
$sb->add_label(" x ");
|
||||
$sb->add_int_option("thumb_height");
|
||||
$sb->add_label(" px at ");
|
||||
$sb->add_int_option("thumb_quality");
|
||||
$sb->add_label(" % quality ");
|
||||
|
||||
$sb->add_shorthand_int_option("thumb_mem_limit", "<br>Max memory use: ");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
|
||||
// add image {{{
|
||||
private function add_image($image) {
|
||||
global $page;
|
||||
@ -247,5 +245,4 @@ class ImageIO implements Extension {
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new ImageIO());
|
||||
?>
|
||||
|
@ -34,20 +34,17 @@ class PostListBuildingEvent extends Event {
|
||||
}
|
||||
}
|
||||
|
||||
class Index implements Extension {
|
||||
var $theme;
|
||||
class Index extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config;
|
||||
$config->set_default_int("index_width", 3);
|
||||
$config->set_default_int("index_height", 4);
|
||||
$config->set_default_bool("index_tips", true);
|
||||
}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
public function onPageRequest($event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
|
||||
if($event instanceof InitExtEvent) {
|
||||
$config->set_default_int("index_width", 3);
|
||||
$config->set_default_int("index_height", 4);
|
||||
$config->set_default_bool("index_tips", true);
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("post/list")) {
|
||||
if($event->page_matches("post/list")) {
|
||||
if(isset($_GET['search'])) {
|
||||
$search = url_escape(trim($_GET['search']));
|
||||
if(empty($search)) {
|
||||
@ -92,56 +89,55 @@ class Index implements Extension {
|
||||
$this->theme->display_page($page, $images);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$sb = new SetupBlock("Index Options");
|
||||
$sb->position = 20;
|
||||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Index Options");
|
||||
$sb->position = 20;
|
||||
|
||||
$sb->add_label("Index table size ");
|
||||
$sb->add_int_option("index_width");
|
||||
$sb->add_label(" x ");
|
||||
$sb->add_int_option("index_height");
|
||||
$sb->add_label(" images");
|
||||
$sb->add_label("Index table size ");
|
||||
$sb->add_int_option("index_width");
|
||||
$sb->add_label(" x ");
|
||||
$sb->add_int_option("index_height");
|
||||
$sb->add_label(" images");
|
||||
|
||||
$event->panel->add_block($sb);
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onSearchTermParse($event) {
|
||||
$matches = array();
|
||||
if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$args = array(int_escape($matches[2]), int_escape($matches[3]));
|
||||
$event->add_querylet(new Querylet("width $cmp ? AND height $cmp ?", $args));
|
||||
}
|
||||
|
||||
if($event instanceof SearchTermParseEvent) {
|
||||
$matches = array();
|
||||
if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$args = array(int_escape($matches[2]), int_escape($matches[3]));
|
||||
$event->add_querylet(new Querylet("width $cmp ? AND height $cmp ?", $args));
|
||||
}
|
||||
else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$args = array(int_escape($matches[2]), int_escape($matches[3]));
|
||||
$event->add_querylet(new Querylet("width / height $cmp ? / ?", $args));
|
||||
}
|
||||
else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) {
|
||||
$col = $matches[1];
|
||||
$cmp = $matches[2];
|
||||
$val = parse_shorthand_int($matches[3]);
|
||||
$event->add_querylet(new Querylet("images.$col $cmp ?", array($val)));
|
||||
}
|
||||
else if(preg_match("/^hash=([0-9a-fA-F]*)$/i", $event->term, $matches)) {
|
||||
$hash = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.hash = '$hash'"));
|
||||
}
|
||||
else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$ext = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.ext = '$ext'"));
|
||||
}
|
||||
else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$filename = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.filename LIKE '%$filename%'"));
|
||||
}
|
||||
else if(preg_match("/^posted=(([0-9\*]*)?(-[0-9\*]*)?(-[0-9\*]*)?)$/", $event->term, $matches)) {
|
||||
$val = str_replace("*", "%", $matches[1]);
|
||||
$img_search->append(new Querylet("images.posted LIKE '%$val%'"));
|
||||
}
|
||||
else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) {
|
||||
$cmp = $matches[1];
|
||||
$args = array(int_escape($matches[2]), int_escape($matches[3]));
|
||||
$event->add_querylet(new Querylet("width / height $cmp ? / ?", $args));
|
||||
}
|
||||
else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) {
|
||||
$col = $matches[1];
|
||||
$cmp = $matches[2];
|
||||
$val = parse_shorthand_int($matches[3]);
|
||||
$event->add_querylet(new Querylet("images.$col $cmp ?", array($val)));
|
||||
}
|
||||
else if(preg_match("/^hash=([0-9a-fA-F]*)$/i", $event->term, $matches)) {
|
||||
$hash = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.hash = '$hash'"));
|
||||
}
|
||||
else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$ext = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.ext = '$ext'"));
|
||||
}
|
||||
else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
|
||||
$filename = strtolower($matches[2]);
|
||||
$event->add_querylet(new Querylet("images.filename LIKE '%$filename%'"));
|
||||
}
|
||||
else if(preg_match("/^posted=(([0-9\*]*)?(-[0-9\*]*)?(-[0-9\*]*)?)$/", $event->term, $matches)) {
|
||||
$val = str_replace("*", "%", $matches[1]);
|
||||
$img_search->append(new Querylet("images.posted LIKE '%$val%'"));
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new Index());
|
||||
?>
|
||||
|
@ -1,26 +1,22 @@
|
||||
<?php
|
||||
class LoadExtData implements Extension {
|
||||
public function receive_event(Event $event) {
|
||||
if($event instanceof PageRequestEvent) {
|
||||
global $page, $config;
|
||||
class LoadExtData extends SimpleExtension {
|
||||
public function onPageRequest($event) {
|
||||
global $page;
|
||||
$data_href = get_base_href();
|
||||
|
||||
$data_href = get_base_href();
|
||||
|
||||
$css_files = glob("ext/*/style.css");
|
||||
if($css_files) {
|
||||
foreach($css_files as $css_file) {
|
||||
$page->add_header("<link rel='stylesheet' href='$data_href/$css_file' type='text/css'>");
|
||||
}
|
||||
$css_files = glob("ext/*/style.css");
|
||||
if($css_files) {
|
||||
foreach($css_files as $css_file) {
|
||||
$page->add_header("<link rel='stylesheet' href='$data_href/$css_file' type='text/css'>");
|
||||
}
|
||||
}
|
||||
|
||||
$js_files = glob("ext/*/script.js");
|
||||
if($js_files) {
|
||||
foreach($js_files as $js_file) {
|
||||
$page->add_header("<script src='$data_href/$js_file' type='text/javascript'></script>");
|
||||
}
|
||||
$js_files = glob("ext/*/script.js");
|
||||
if($js_files) {
|
||||
foreach($js_files as $js_file) {
|
||||
$page->add_header("<script src='$data_href/$js_file' type='text/javascript'></script>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new LoadExtData());
|
||||
?>
|
||||
|
@ -135,27 +135,25 @@ class SetupBlock extends Block {
|
||||
}
|
||||
// }}}
|
||||
|
||||
class Setup implements Extension {
|
||||
var $theme;
|
||||
class Setup extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config;
|
||||
$config->set_default_string("title", "Shimmie");
|
||||
$config->set_default_string("front_page", "post/list");
|
||||
$config->set_default_string("main_page", "post/list");
|
||||
$config->set_default_string("base_href", "./index.php?q=");
|
||||
$config->set_default_string("theme", "default");
|
||||
}
|
||||
|
||||
public function receive_event(Event $event) {
|
||||
global $config, $database, $page, $user;
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
||||
public function onPageRequest($event) {
|
||||
global $config, $page, $user;
|
||||
|
||||
if($event instanceof InitExtEvent) {
|
||||
$config->set_default_string("title", "Shimmie");
|
||||
$config->set_default_string("front_page", "post/list");
|
||||
$config->set_default_string("main_page", "post/list");
|
||||
$config->set_default_string("base_href", "./index.php?q=");
|
||||
$config->set_default_string("theme", "default");
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) {
|
||||
if($event->page_matches("nicetest")) {
|
||||
$page->set_mode("data");
|
||||
$page->set_data("ok");
|
||||
}
|
||||
|
||||
if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) {
|
||||
if($event->page_matches("setup")) {
|
||||
if(!$user->is_admin()) {
|
||||
$this->theme->display_permission_denied($page);
|
||||
}
|
||||
@ -177,80 +175,80 @@ class Setup implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$themes = array();
|
||||
foreach(glob("themes/*") as $theme_dirname) {
|
||||
$name = str_replace("themes/", "", $theme_dirname);
|
||||
$themes[ucfirst($name)] = $name;
|
||||
public function onSetupBuilding($event) {
|
||||
$themes = array();
|
||||
foreach(glob("themes/*") as $theme_dirname) {
|
||||
$name = str_replace("themes/", "", $theme_dirname);
|
||||
$themes[ucfirst($name)] = $name;
|
||||
}
|
||||
|
||||
$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
|
||||
$test_url = str_replace("/index.php", "/nicetest", $full);
|
||||
|
||||
$nicescript = "<script language='javascript'>
|
||||
function getHTTPObject() {
|
||||
if (window.XMLHttpRequest){
|
||||
return new XMLHttpRequest();
|
||||
}
|
||||
else if(window.ActiveXObject){
|
||||
return new ActiveXObject('Microsoft.XMLHTTP');
|
||||
}
|
||||
}
|
||||
|
||||
$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
|
||||
$test_url = str_replace("/index.php", "/nicetest", $full);
|
||||
checkbox = document.getElementById('nice_urls');
|
||||
out_span = document.getElementById('nicetest');
|
||||
|
||||
$nicescript = "<script language='javascript'>
|
||||
function getHTTPObject() {
|
||||
if (window.XMLHttpRequest){
|
||||
return new XMLHttpRequest();
|
||||
}
|
||||
else if(window.ActiveXObject){
|
||||
return new ActiveXObject('Microsoft.XMLHTTP');
|
||||
}
|
||||
}
|
||||
checkbox.disabled = true;
|
||||
out_span.innerHTML = '(testing...)';
|
||||
|
||||
checkbox = document.getElementById('nice_urls');
|
||||
out_span = document.getElementById('nicetest');
|
||||
http_request = getHTTPObject();
|
||||
http_request.open('GET', '$test_url', false);
|
||||
http_request.send(null);
|
||||
|
||||
if(http_request.status == 200 && http_request.responseText == 'ok') {
|
||||
checkbox.disabled = false;
|
||||
out_span.innerHTML = '(tested ok)';
|
||||
}
|
||||
else {
|
||||
checkbox.disabled = true;
|
||||
out_span.innerHTML = '(testing...)';
|
||||
|
||||
http_request = getHTTPObject();
|
||||
http_request.open('GET', '$test_url', false);
|
||||
http_request.send(null);
|
||||
|
||||
if(http_request.status == 200 && http_request.responseText == 'ok') {
|
||||
checkbox.disabled = false;
|
||||
out_span.innerHTML = '(tested ok)';
|
||||
}
|
||||
else {
|
||||
checkbox.disabled = true;
|
||||
out_span.innerHTML = '(test failed)';
|
||||
}
|
||||
</script>";
|
||||
$sb = new SetupBlock("General");
|
||||
$sb->position = 0;
|
||||
$sb->add_text_option("title", "Site title: ");
|
||||
$sb->add_text_option("front_page", "<br>Front page: ");
|
||||
$sb->add_text_option("main_page", "<br>Main page: ");
|
||||
$sb->add_text_option("contact_link", "<br>Contact URL: ");
|
||||
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
|
||||
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
|
||||
$sb->add_label("<span id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if($event instanceof ConfigSaveEvent) {
|
||||
global $config;
|
||||
foreach($_POST as $_name => $junk) {
|
||||
if(substr($_name, 0, 6) == "_type_") {
|
||||
$name = substr($_name, 6);
|
||||
$type = $_POST["_type_$name"];
|
||||
$value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null;
|
||||
switch($type) {
|
||||
case "string": $config->set_string($name, $value); break;
|
||||
case "int": $config->set_int($name, $value); break;
|
||||
case "bool": $config->set_bool($name, $value); break;
|
||||
}
|
||||
}
|
||||
out_span.innerHTML = '(test failed)';
|
||||
}
|
||||
}
|
||||
</script>";
|
||||
$sb = new SetupBlock("General");
|
||||
$sb->position = 0;
|
||||
$sb->add_text_option("title", "Site title: ");
|
||||
$sb->add_text_option("front_page", "<br>Front page: ");
|
||||
$sb->add_text_option("main_page", "<br>Main page: ");
|
||||
$sb->add_text_option("contact_link", "<br>Contact URL: ");
|
||||
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
|
||||
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
|
||||
$sb->add_label("<span id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if($event instanceof UserBlockBuildingEvent) {
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Board Config", make_link("setup"));
|
||||
public function onConfigSave($event) {
|
||||
global $config;
|
||||
foreach($_POST as $_name => $junk) {
|
||||
if(substr($_name, 0, 6) == "_type_") {
|
||||
$name = substr($_name, 6);
|
||||
$type = $_POST["_type_$name"];
|
||||
$value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null;
|
||||
switch($type) {
|
||||
case "string": $config->set_string($name, $value); break;
|
||||
case "int": $config->set_int($name, $value); break;
|
||||
case "bool": $config->set_bool($name, $value); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onUserBlockBuilding($event) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
$event->add_link("Board Config", make_link("setup"));
|
||||
}
|
||||
}
|
||||
}
|
||||
add_event_listener(new Setup());
|
||||
?>
|
||||
|
@ -101,6 +101,7 @@ class TagEdit implements Extension {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function can_tag() {
|
||||
global $config, $user;
|
||||
return $config->get_bool("tag_edit_anon") || !$user->is_anonymous();
|
||||
|
@ -59,6 +59,7 @@ class ImageAdminBlockBuildingEvent extends Event {
|
||||
$this->parts[$position] = $html;
|
||||
}
|
||||
}
|
||||
|
||||
class ViewImage implements Extension {
|
||||
var $theme;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user