diff --git a/contrib/admin/main.php b/contrib/admin/main.php index 64298022..3d03915d 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -131,10 +131,8 @@ class AdminPage extends SimpleExtension { } private function dbdump($page) { - include "config.php"; - $matches = array(); - preg_match("#(\w+)://(\w+):(\w+)@([\w\.\-]+)/([\w_]+)(\?.*)?#", $database_dsn, $matches); + preg_match("#(\w+)://(\w+):(\w+)@([\w\.\-]+)/([\w_]+)(\?.*)?#", DATABASE_DSN, $matches); $software = $matches[1]; $username = $matches[2]; $password = $matches[3]; diff --git a/contrib/emoticons/main.php b/contrib/emoticons/main.php index b7b9e82f..67d14e29 100644 --- a/contrib/emoticons/main.php +++ b/contrib/emoticons/main.php @@ -23,7 +23,6 @@ class Emoticons extends FormatterExtension { return $text; } } -add_event_listener(new Emoticons()); class EmoticonList extends SimpleExtension { public function onPageRequest($event) { diff --git a/contrib/et/main.php b/contrib/et/main.php index 46065d95..dd6babe2 100644 --- a/contrib/et/main.php +++ b/contrib/et/main.php @@ -41,6 +41,7 @@ class ET extends SimpleExtension { $info['sys_shimmie'] = VERSION; $info['sys_schema'] = $config->get_string("db_version"); $info['sys_php'] = phpversion(); + $info['sys_db'] = $database->db->getAttribute(PDO::ATTR_DRIVER_NAME); $info['sys_os'] = php_uname(); $info['sys_disk'] = to_shorthand_int(disk_total_space("./") - disk_free_space("./")) . " / " . to_shorthand_int(disk_total_space("./")); @@ -56,8 +57,14 @@ class ET extends SimpleExtension { $info['stat_image_tags'] = $database->get_one("SELECT COUNT(*) FROM image_tags"); $els = array(); - foreach($_event_listeners as $el) { - $els[] = get_class($el); + foreach(get_declared_classes() as $class) { + $rclass = new ReflectionClass($class); + if($rclass->isAbstract()) { + // don't do anything + } + elseif(is_subclass_of($class, "Extension")) { + $els[] = $class; + } } $info['sys_extensions'] = join(', ', $els); diff --git a/contrib/et/theme.php b/contrib/et/theme.php index 4df216c1..1c5b00ae 100644 --- a/contrib/et/theme.php +++ b/contrib/et/theme.php @@ -28,6 +28,7 @@ Shimmie: {$info['sys_shimmie']} Schema: {$info['sys_schema']} PHP: {$info['sys_php']} OS: {$info['sys_os']} +Database: {$info['sys_db']} Server: {$info['sys_server']} Disk use: {$info['sys_disk']} diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 6bfa1928..40835fc3 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -18,7 +18,7 @@ class Tag_History extends SimpleExtension { $this->install(); } } - + public function onAdminBuildingEvent($event) { global $user; @@ -251,6 +251,18 @@ class Tag_History extends SimpleExtension { return ($row ? $row : array()); } + /* This doesn't actually get _ALL_ IPs as it limits to 1000. */ + public function get_all_user_ips() + { + global $database; + $row = $database->get_all(" + SELECT DISTINCT user_ip + FROM tag_histories + ORDER BY tag_histories.user_ip DESC + LIMIT 1000"); + return ($row ? $row : array()); + } + /* * This function attempts to revert all changes by a given IP within an (optional) timeframe. */ diff --git a/core/block.class.php b/core/block.class.php index aa2b3465..0beab722 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -31,7 +31,7 @@ class Block { */ var $position; - public function __construct($header, $body, $section="main", $position=50) { + public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50) { $this->header = $header; $this->body = $body; $this->section = $section; diff --git a/core/compat.inc.php b/core/compat.inc.php deleted file mode 100644 index 8975f587..00000000 --- a/core/compat.inc.php +++ /dev/null @@ -1,95 +0,0 @@ -= 5.2.1) -# Based on http://www.phpit.net/ -# article/creating-zip-tar-archives-dynamically-php/2/ -if(!function_exists('sys_get_temp_dir')) { -function sys_get_temp_dir() { - // Try to get from environment variable - if(!empty($_ENV['TMP'])) { - return realpath($_ENV['TMP']); - } - else if(!empty($_ENV['TMPDIR'])) { - return realpath($_ENV['TMPDIR']); - } - else if(!empty($_ENV['TEMP'])) { - return realpath($_ENV['TEMP']); - } - - // Detect by creating a temporary file - else { - // Try to use system's temporary directory - // as random name shouldn't exist - $temp_file = tempnam(md5(uniqid(rand(), TRUE)), ''); - if($temp_file) { - $temp_dir = realpath(dirname($temp_file)); - unlink($temp_file); - return $temp_dir; - } - else { - return FALSE; - } - } -} -} - -# (PHP >= 5.1) -# from http://www.php.net/inet_pton -if(!function_exists('inet_pton')) { -function inet_pton($ip) { - # ipv4 - if(strpos($ip, '.') !== FALSE) { - $ip = pack('N',ip2long($ip)); - } - # ipv6 - else if(strpos($ip, ':') !== FALSE) { - $ip = explode(':', $ip); - $res = str_pad('', (4*(8-count($ip))), '0000', STR_PAD_LEFT); - foreach($ip as $seg) { - $res .= str_pad($seg, 4, '0', STR_PAD_LEFT); - } - $ip = pack('H'.strlen($res), $res); - } - return $ip; -} -} - -# (PHP >= 5.1) -# from http://www.php.net/inet_ntop -if(!function_exists('inet_ntop')) { -function inet_ntop($ip) { - if (strlen($ip)==4) { - // ipv4 - list(,$ip)=unpack('N',$ip); - $ip=long2ip($ip); - } elseif(strlen($ip)==16) { - // ipv6 - $ip=bin2hex($ip); - $ip=substr(chunk_split($ip,4,':'),0,-1); - $ip=explode(':',$ip); - $res=''; - foreach($ip as $seg) { - while($seg{0}=='0') $seg=substr($seg,1); - if ($seg!='') { - $res.=($res==''?'':':').$seg; - } else { - if (strpos($res,'::')===false) { - if (substr($res,-1)==':') continue; - $res.=':'; - continue; - } - $res.=($res==''?'':':').'0'; - } - } - $ip=$res; - } - return $ip; -} -} -?> diff --git a/core/database.class.php b/core/database.class.php index 7a065c3a..27805521 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -1,6 +1,4 @@ db = new PDO(DATABASE_DSN, $db_user, $db_pass, array( + $db_params = array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - )); + ); + if(defined("HIPHOP")) $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass); + else $this->db = new PDO(DATABASE_DSN, $db_user, $db_pass, $db_params); $db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME); if($db_proto === "mysql") { diff --git a/core/default_config.inc.php b/core/default_config.inc.php new file mode 100644 index 00000000..2f3003ca --- /dev/null +++ b/core/default_config.inc.php @@ -0,0 +1,21 @@ + diff --git a/core/event.class.php b/core/event.class.php index 69a93175..cbff2fcf 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -40,7 +40,7 @@ class PageRequestEvent extends Event { * * If it matches, store the remaining path elements in $args */ - public function page_matches($name) { + public function page_matches(/*string*/ $name) { $parts = explode("/", $name); $this->part_count = count($parts); @@ -57,7 +57,7 @@ class PageRequestEvent extends Event { return true; } - public function get_arg($n) { + public function get_arg(/*int*/ $n) { $offset = $this->part_count + $n; if($offset >= 0 && $offset < $this->arg_count) { return $this->args[$offset]; @@ -120,7 +120,7 @@ class TextFormattingEvent extends Event { */ var $stripped; - public function __construct($text) { + public function __construct(/*string*/ $text) { $h_text = html_escape(trim($text)); $this->original = $h_text; $this->formatted = $h_text; diff --git a/core/extension.class.php b/core/extension.class.php index 98d6bc15..e5ce13d2 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -92,7 +92,10 @@ abstract class SimpleExtension implements Extension { var $theme; var $_child; - public function i_am($child) { + // in PHP5.3, late static bindings can take care of this; __CLASS__ + // used here will refer to the subclass + // http://php.net/manual/en/language.oop5.late-static-bindings.php + public function i_am(Extension $child) { $this->_child = $child; if(is_null($this->theme)) $this->theme = get_theme_object($child, false); } @@ -115,13 +118,13 @@ abstract class SimpleExtension implements Extension { * Several extensions have this in common, make a common API */ abstract class FormatterExtension extends SimpleExtension { - public function onTextFormatting($event) { + public function onTextFormatting(TextFormattingEvent $event) { $event->formatted = $this->format($event->formatted); $event->stripped = $this->strip($event->stripped); } - abstract public function format($text); - abstract public function strip($text); + abstract public function format(/*string*/ $text); + abstract public function strip(/*string*/ $text); } /** @@ -129,7 +132,7 @@ abstract class FormatterExtension extends SimpleExtension { * so we have a base class to extend from */ abstract class DataHandlerExtension extends SimpleExtension { - public function onDataUpload($event) { + public function onDataUpload(DataUploadEvent $event) { if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if(!move_upload_to_archive($event)) return; send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); @@ -188,7 +191,7 @@ abstract class DataHandlerExtension extends SimpleExtension { } } - public function onThumbnailGeneration($event) { + public function onThumnbnailGeneration(ThumbnailGenerationEvent $event) { if($this->supported_ext($event->type)) { if (method_exists($this, 'create_thumb_force') && $event->force == true) { $this->create_thumb_force($event->hash); @@ -199,14 +202,14 @@ abstract class DataHandlerExtension extends SimpleExtension { } } - public function onDisplayingImage($event) { + public function onDisplayingImage(DisplayingImageEvent $event) { global $page; if($this->supported_ext($event->image->ext)) { $this->theme->display_image($page, $event->image); } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = $this->setup(); if($sb) $event->panel->add_block($sb); } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 97ff62a8..73eb31f3 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -27,6 +27,8 @@ $tag_n = 0; // temp hack $_flexihash = null; $_fh_last_opts = null; +require_once "lib/flexihash.php"; + /** * An object representing an entry in the images table. As of 2.2, this no * longer necessarily represents an image per se, but could be a video, @@ -66,7 +68,7 @@ class Image { * * @retval Image */ - public static function by_id($id) { + public static function by_id(/*int*/ $id) { assert(is_numeric($id)); global $database; $image = null; @@ -79,7 +81,7 @@ class Image { * * @retval Image */ - public static function by_hash($hash) { + public static function by_hash(/*string*/ $hash) { assert(is_string($hash)); global $database; $image = null; @@ -540,7 +542,6 @@ class Image { if($opts != $_fh_last_opts) { $_fh_last_opts = $opts; - require_once("lib/flexihash.php"); $_flexihash = new Flexihash(); foreach(explode(",", $opts) as $opt) { $parts = explode("=", $opt); @@ -1031,7 +1032,7 @@ class Tag { * Move a file from PHP's temporary area into shimmie's image storage * heirachy, or throw an exception trying */ -function move_upload_to_archive($event) { +function move_upload_to_archive(DataUploadEvent $event) { $target = warehouse_path("images", $event->hash); if(!file_exists(dirname($target))) mkdir(dirname($target), 0755, true); if(!@copy($event->tmpname, $target)) { @@ -1046,7 +1047,7 @@ function move_upload_to_archive($event) { * Given a full size pair of dimentions, return a pair scaled down to fit * into the configured thumbnail square, with ratio intact */ -function get_thumbnail_size($orig_width, $orig_height) { +function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) { global $config; if($orig_width == 0) $orig_width = 192; diff --git a/core/user.class.php b/core/user.class.php index 0220ef23..85d90df5 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -38,7 +38,7 @@ class User { $this->passhash = $row['pass']; } - public static function by_session($name, $session) { + public static function by_session(/*string*/ $name, /*string*/ $session) { global $config, $database; if($database->engine->name === "mysql") { $query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess"; @@ -50,7 +50,7 @@ class User { return is_null($row) ? null : new User($row); } - public static function by_id($id) { + public static function by_id(/*int*/ $id) { assert(is_numeric($id)); global $database; if($id === 1) { @@ -62,14 +62,14 @@ class User { return is_null($row) ? null : new User($row); } - public static function by_name($name) { + public static function by_name(/*string*/ $name) { assert(is_string($name)); global $database; $row = $database->get_row("SELECT * FROM users WHERE name = :name", array("name"=>$name)); return is_null($row) ? null : new User($row); } - public static function by_name_and_hash($name, $hash) { + public static function by_name_and_hash(/*string*/ $name, /*string*/ $hash) { assert(is_string($name)); assert(is_string($hash)); assert(strlen($hash) == 32); @@ -78,7 +78,7 @@ class User { return is_null($row) ? null : new User($row); } - public static function by_list($offset, $limit=50) { + public static function by_list(/*int*/ $offset, /*int*/ $limit=50) { assert(is_numeric($offset)); assert(is_numeric($limit)); global $database; @@ -120,7 +120,7 @@ class User { return $this->admin; } - public function set_admin($admin) { + public function set_admin(/*bool*/ $admin) { assert(is_bool($admin)); global $database; $yn = $admin ? 'Y' : 'N'; @@ -128,14 +128,14 @@ class User { log_info("core-user", 'Made '.$this->name.' admin='.$yn); } - public function set_password($password) { + public function set_password(/*string*/ $password) { global $database; $hash = md5(strtolower($this->name) . $password); $database->Execute("UPDATE users SET pass=:hash WHERE id=:id", array("hash"=>$hash, "id"=>$this->id)); log_info("core-user", 'Set password for '.$this->name); } - public function set_email($address) { + public function set_email(/*string*/ $address) { global $database; $database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id)); log_info("core-user", 'Set email for '.$this->name); @@ -173,7 +173,7 @@ class User { */ public function get_auth_token() { global $config; - $salt = file_get_contents("config.php"); + $salt = DATABASE_DSN; $addr = get_session_ip($config); return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt); } diff --git a/core/util.inc.php b/core/util.inc.php index e7563d6c..882c8560 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -222,10 +222,10 @@ function make_link($page=null, $query=null) { if(NICE_URLS || $config->get_bool('nice_urls', false)) { #$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; $full = $_SERVER["PHP_SELF"]; - $base = str_replace("/index.php", "", $full); + $base = str_replace("/".basename($_SERVER["SCRIPT_FILENAME"]), "", $full); } else { - $base = "./index.php?q="; + $base = "./".basename($_SERVER["SCRIPT_FILENAME"])."?q="; } if(is_null($query)) { @@ -291,7 +291,7 @@ function modify_url($url, $changes) { * * @retval string */ -function make_http($link) { +function make_http(/*string*/ $link) { if(strpos($link, "ttp://") > 0) return $link; if(strlen($link) > 0 && $link[0] != '/') $link = get_base_href().'/'.$link; $link = "http://".$_SERVER["HTTP_HOST"].$link; @@ -396,11 +396,11 @@ function captcha_check() { * @private */ function _version_check() { - if(version_compare(PHP_VERSION, "5.0.0") == -1) { + if(version_compare(PHP_VERSION, "5.2.6") == -1) { print " -Currently SCore Engine doesn't support versions of PHP lower than 5.0.0 -- -PHP4 and earlier are officially dead according to their creators, -please tell your host to upgrade. +Currently SCore Engine doesn't support versions of PHP lower than 5.2.6 -- +if your web host is running an older version, they are dangerously out of +date and you should plan on moving elsewhere. "; exit; } @@ -519,7 +519,7 @@ function get_memory_limit() { * * @retval string */ -function get_session_ip($config) { +function get_session_ip(Config $config) { $mask = $config->get_string("session_hash_mask", "255.255.0.0"); $addr = $_SERVER['REMOTE_ADDR']; $addr = inet_ntop(inet_pton($addr) & inet_pton($mask)); @@ -531,7 +531,7 @@ function get_session_ip($config) { * prefix prepended to it, eg username -> shm_username, to prevent * conflicts from multiple installs within one domain. */ -function get_prefixed_cookie($name) { +function get_prefixed_cookie(/*string*/ $name) { global $config; $full_name = COOKIE_PREFIX."_".$name; if(isset($_COOKIE[$full_name])) { @@ -584,13 +584,13 @@ function get_base_href() { * * @retval string */ -function format_text($string) { +function format_text(/*string*/ $string) { $tfe = new TextFormattingEvent($string); send_event($tfe); return $tfe->formatted; } -function warehouse_path($base, $hash, $create=true) { +function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=true) { $ab = substr($hash, 0, 2); $cd = substr($hash, 2, 2); if(WH_SPLITS == 2) { @@ -935,6 +935,10 @@ function _stripslashes_r($arr) { } function _sanitise_environment() { + if(TIMEZONE) { + date_default_timezone_set(TIMEZONE); + } + if(DEBUG) { error_reporting(E_ALL); } @@ -951,6 +955,120 @@ function _sanitise_environment() { } } +function _get_themelet_files($_theme) { + $themelets = array(); + + if(file_exists('themes/'.$_theme.'/custompage.class.php')) $themelets[] = 'themes/'.$_theme.'/custompage.class.php'; + $themelets[] = 'themes/'.$_theme.'/layout.class.php'; + $themelets[] = 'themes/'.$_theme.'/themelet.class.php'; + + $themelet_files = glob("ext/*/theme.php"); + foreach($themelet_files as $filename) { + $themelets[] = $filename; + } + + $custom_themelets = glob('themes/'.$_theme.'/*.theme.php'); + if($custom_themelets) { + $m = array(); + foreach($custom_themelets as $filename) { + if(preg_match('/themes\/'.$_theme.'\/(.*)\.theme\.php/',$filename,$m) + && in_array('ext/'.$m[1].'/theme.php', $themelets)) { + $themelets[] = $filename; + } + } + } + + return $themelets; +} + +function _load_extensions() { + global $_event_listeners; + + ctx_log_start("Loading extensions"); + + if(COMPILE_ELS && file_exists("data/event_listeners.php")) { + require_once("data/event_listeners.php"); + } + else { + $all_events = array(); + foreach(get_declared_classes() as $class) { + if(is_subclass_of($class, "Event")) { + $all_events[] = $class; + } + } + foreach(get_declared_classes() as $class) { + $rclass = new ReflectionClass($class); + if($rclass->isAbstract()) { + // don't do anything + } + elseif(is_subclass_of($class, "SimpleExtension")) { + $c = new $class(); + $c->i_am($c); + $my_events = array(); + foreach(get_class_methods($c) as $method) { + if(substr($method, 0, 2) == "on") { + $my_events[] = substr($method, 2) . "Event"; + } + } + add_event_listener($c, $c->get_priority(), $my_events); + } + elseif(is_subclass_of($class, "Extension")) { + $c = new $class(); + add_event_listener($c, $c->get_priority(), $all_events); + } + } + + if(COMPILE_ELS) { + $p = "<"."?php\n"; + + foreach(get_declared_classes() as $class) { + $rclass = new ReflectionClass($class); + if($rclass->isAbstract()) {} + elseif(is_subclass_of($class, "SimpleExtension")) { + $p .= "\$$class = new $class(); "; + $p .= "\${$class}->i_am(\$$class);\n"; + } + elseif(is_subclass_of($class, "Extension")) { + $p .= "\$$class = new $class();\n"; + } + } + + $p .= "\$_event_listeners = array(\n"; + foreach($_event_listeners as $event => $listeners) { + $p .= "\t'$event' => array(\n"; + foreach($listeners as $id => $listener) { + $p .= "\t\t$id => \$".get_class($listener).",\n"; + } + $p .= "\t),\n"; + } + $p .= ");\n"; + + $p .= "?".">"; + file_put_contents("data/event_listeners.php", $p); + } + } + + ctx_log_endok(); +} + +function _fatal_error(Exception $e) { + $version = VERSION; + $message = $e->getMessage(); + //$trace = var_dump($e->getTrace()); + header("HTTP/1.0 500 Internal Error"); + echo ' + + + Internal error - SCore-'.$version.' + + +

Internal Error

+

'.$message.' + + +'; +} + /** * Turn ^^ into ^ and ^s into / * diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 6ef31bee..2942809d 100755 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -120,7 +120,7 @@ class AliasEditor extends SimpleExtension { } } - private function get_alias_csv($database) { + private function get_alias_csv(Database $database) { $csv = ""; $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases"); foreach($aliases as $old => $new) { @@ -129,7 +129,7 @@ class AliasEditor extends SimpleExtension { return $csv; } - private function add_alias_csv($database, $csv) { + private function add_alias_csv(Database $database, /*string*/ $csv) { $csv = str_replace("\r", "\n", $csv); foreach(explode("\n", $csv) as $line) { $parts = explode(",", $line); diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index 732d3b35..239f06c2 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -24,7 +24,7 @@ */ class BBCode extends FormatterExtension { - public function format($text) { + public function format(/*string*/ $text) { global $config; if($config->get_bool("word_wrap", true)) { $text = wordwrap($text, 80, " ", true); @@ -73,7 +73,7 @@ class BBCode extends FormatterExtension { return str_replace(' ', '', $matches[1]); } - public function strip($text) { + public function strip(/*string*/ $text) { global $config; if($config->get_bool("word_wrap", true)) { $text = wordwrap($text, 80, " ", true); @@ -103,14 +103,14 @@ class BBCode extends FormatterExtension { } - private function filter_spoiler($text) { + private function filter_spoiler(/*string*/ $text) { return str_replace( array("[spoiler]","[/spoiler]"), array("",""), $text); } - private function strip_spoiler($text) { + private function strip_spoiler(/*string*/ $text) { $l1 = strlen("[spoiler]"); $l2 = strlen("[/spoiler]"); while(true) { @@ -129,7 +129,7 @@ class BBCode extends FormatterExtension { return $text; } - private function extract_code($text) { + private function extract_code(/*string*/ $text) { # at the end of this function, the only code! blocks should be # the ones we've added -- others may contain malicious content, # which would only appear after decoding @@ -154,7 +154,7 @@ class BBCode extends FormatterExtension { return $text; } - private function insert_code($text) { + private function insert_code(/*string*/ $text) { $l1 = strlen("[code!]"); $l2 = strlen("[/code!]"); while(true) { @@ -173,5 +173,4 @@ class BBCode extends FormatterExtension { return $text; } } -add_event_listener(new BBCode()); ?> diff --git a/ext/comment/main.php b/ext/comment/main.php index d2d7f32b..0a1aaebf 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -61,7 +61,7 @@ class Comment { } class CommentList extends SimpleExtension { - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config, $database; $config->set_default_bool('comment_anon', true); $config->set_default_int('comment_window', 5); @@ -194,7 +194,7 @@ class CommentList extends SimpleExtension { // TODO: split akismet into a separate class, which can veto the event public function onCommentPosting(CommentPostingEvent $event) { - $this->add_comment_wrapper($event->image_id, $event->user, $event->comment, $event); + $this->add_comment_wrapper($event->image_id, $event->user, $event->comment); } public function onCommentDeletion(CommentDeletionEvent $event) { @@ -247,7 +247,7 @@ class CommentList extends SimpleExtension { } // page building {{{ - private function build_page($current_page) { + private function build_page(/*int*/ $current_page) { global $page; global $config; global $database; @@ -296,7 +296,7 @@ class CommentList extends SimpleExtension { } // }}} // get comments {{{ - private function get_recent_comments() { + private function get_recent_comments($count) { global $config; global $database; $rows = $database->get_all(" @@ -309,7 +309,7 @@ class CommentList extends SimpleExtension { LEFT JOIN users ON comments.owner_id=users.id ORDER BY comments.id DESC LIMIT :limit - ", array("limit"=>$config->get_int('comment_count'))); + ", array("limit"=>$count)); $comments = array(); foreach($rows as $row) { $comments[] = new Comment($row); @@ -317,7 +317,7 @@ class CommentList extends SimpleExtension { return $comments; } - private function get_user_recent_comments($user_id, $count) { + private function get_user_recent_comments(/*int*/ $user_id, /*int*/ $count) { global $config; global $database; $rows = $database->get_all(" @@ -339,7 +339,7 @@ class CommentList extends SimpleExtension { return $comments; } - private function get_comments($image_id) { + private function get_comments(/*int*/ $image_id) { global $config; global $database; $i_image_id = int_escape($image_id); @@ -399,7 +399,7 @@ class CommentList extends SimpleExtension { return md5($_SERVER['REMOTE_ADDR'] . date("%Y%m%d")); } - private function is_spam_akismet($text) { + private function is_spam_akismet(/*string*/ $text) { global $config, $user; if(strlen($config->get_string('comment_wordpress_key')) > 0) { $comment = array( @@ -443,12 +443,12 @@ class CommentList extends SimpleExtension { return ($config->get_bool('comment_anon') || !$user->is_anonymous()); } - private function is_dupe($image_id, $comment) { + private function is_dupe(/*int*/ $image_id, /*string*/ $comment) { global $database; return ($database->get_row("SELECT * FROM comments WHERE image_id=:image_id AND comment=:comment", array("image_id"=>$image_id, "comment"=>$comment))); } - private function add_comment_wrapper($image_id, $user, $comment, $event) { + private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { global $database; global $config; diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 1e24b794..1b90ef0a 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -80,7 +80,7 @@ class ExtensionInfo { } } - private function is_enabled($fname) { + private function is_enabled(/*string*/ $fname) { if(file_exists("ext/$fname") && file_exists("contrib/$fname")) return true; // both if(file_exists("contrib/$fname")) return false; // only disabled (optional) return null; // only active (core) @@ -139,7 +139,7 @@ class ExtManager extends SimpleExtension { } - private function get_extensions($all) { + private function get_extensions(/*bool*/ $all) { $extensions = array(); if($all) { $exts = glob("ext/*/main.php"); @@ -170,7 +170,7 @@ class ExtManager extends SimpleExtension { } } - private function set_enabled($fname, $enabled) { + private function set_enabled(/*string*/ $fname, /*bool*/ $enabled) { if($enabled) { // enable if currently disabled if(!file_exists("ext/$fname")) { diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 2e4cd734..2904ed0f 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -176,5 +176,4 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} } -add_event_listener(new PixelFileHandler()); ?> diff --git a/ext/image/main.php b/ext/image/main.php index 210e81d8..0fde1e24 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -130,7 +130,7 @@ class ParseLinkTemplateEvent extends Event { * A class to handle adding / getting / removing image files from the disk. */ class ImageIO extends SimpleExtension { - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_int('thumb_width', 192); $config->set_default_int('thumb_height', 192); @@ -147,7 +147,7 @@ class ImageIO extends SimpleExtension { $config->set_default_int('image_expires', (60*60*24*365) ); // defaults to one year } - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { $num = $event->get_arg(0); $matches = array(); if(!is_null($num) && preg_match("/(\d+)/", $num, $matches)) { @@ -186,7 +186,7 @@ class ImageIO extends SimpleExtension { } } - public function onImageAdminBlockBuilding($event) { + public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { global $user; global $config; @@ -199,7 +199,7 @@ class ImageIO extends SimpleExtension { } } - public function onImageAddition($event) { + public function onImageAddition(ImageAdditionEvent $event) { try { $this->add_image($event->image); } @@ -208,11 +208,11 @@ class ImageIO extends SimpleExtension { } } - public function onImageDeletion($event) { + public function onImageDeletion(ImageDeletionEvent $event) { $event->image->delete(); } - public function onImageReplace($event) { + public function onImageReplace(ImageReplaceEvent $event) { try { $this->replace_image($event->id, $event->image); } @@ -221,7 +221,7 @@ class ImageIO extends SimpleExtension { } } - public function onUserPageBuilding($event) { + public function onUserPageBuilding(UserPageBuildingEvent $event) { global $user; global $config; @@ -233,7 +233,7 @@ class ImageIO extends SimpleExtension { $event->add_stats("Images uploaded: $i_image_count, $h_image_rate per day"); } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Image Options"); $sb->position = 30; // advanced only diff --git a/ext/index/main.php b/ext/index/main.php index 5e2dc5cd..14a0ac5c 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -129,14 +129,14 @@ class PostListBuildingEvent extends Event { } class Index extends SimpleExtension { - public function onInitExt($event) { + public function onInitExt(InitExtEvent $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 onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; if($event->page_matches("post/list")) { if(isset($_GET['search'])) { @@ -182,7 +182,7 @@ class Index extends SimpleExtension { } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Index Options"); $sb->position = 20; @@ -195,7 +195,7 @@ class Index extends SimpleExtension { $event->panel->add_block($sb); } - public function onSearchTermParse($event) { + public function onSearchTermParse(SearchTermParseEvent $event) { $matches = array(); // check for tags first as tag based searches are more common. if(preg_match("/tags(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) { diff --git a/ext/index/theme.php b/ext/index/theme.php index 2263d3db..c7d2cb95 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -8,8 +8,8 @@ class IndexTheme extends Themelet { } public function display_intro(Page $page) { - $text = << + $text = " +

The first thing you'll probably want to do is create a new account; note that the first account you create will by default be marked as the board's administrator, and any further accounts will be regular users. @@ -19,7 +19,7 @@ and of course start organising your images :-)

This message will go away once your first image is uploaded~

-EOD; +"; $page->set_title("Welcome to Shimmie ".VERSION); $page->set_heading("Welcome to Shimmie"); $page->add_block(new Block("Installation Succeeded!", $text, "main", 0)); diff --git a/ext/mail/main.php b/ext/mail/main.php index 1a02c3a8..9bf09169 100644 --- a/ext/mail/main.php +++ b/ext/mail/main.php @@ -8,7 +8,7 @@ */ class Mail extends SimpleExtension { - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Mailing Options"); $sb->add_text_option("mail_sub", "
Subject prefix: "); $sb->add_text_option("mail_img", "
Banner Image URL: "); @@ -18,7 +18,7 @@ class Mail extends SimpleExtension { $event->panel->add_block($sb); } - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_string("mail_sub", $config->get_string("site_title")." - "); $config->set_default_string("mail_img", make_http("ext/mail/banner.png")); @@ -27,7 +27,7 @@ class Mail extends SimpleExtension { } } class MailTest extends SimpleExtension { - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("mail/test")) { global $page; $page->set_mode("data"); @@ -42,4 +42,4 @@ class MailTest extends SimpleExtension { } } } -?> \ No newline at end of file +?> diff --git a/ext/setup/main.php b/ext/setup/main.php index c2f47f73..f93ac7fa 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -14,7 +14,7 @@ class ConfigSaveEvent extends Event { var $config; - public function ConfigSaveEvent($config) { + public function ConfigSaveEvent(Config $config) { $this->config = $config; } } @@ -26,7 +26,7 @@ class ConfigSaveEvent extends Event { class SetupBuildingEvent extends Event { var $panel; - public function SetupBuildingEvent($panel) { + public function SetupBuildingEvent(SetupPanel $panel) { $this->panel = $panel; } @@ -41,7 +41,7 @@ class SetupBuildingEvent extends Event { class SetupPanel { var $blocks = array(); - public function add_block($block) { + public function add_block(SetupBlock $block) { $this->blocks[] = $block; } } @@ -162,7 +162,7 @@ class SetupBlock extends Block { // }}} class Setup extends SimpleExtension { - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_string("title", "Shimmie"); $config->set_default_string("front_page", "post/list"); @@ -178,7 +178,7 @@ class Setup extends SimpleExtension { $config->set_default_bool("autocache_min_js", false); } - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; if($event->page_matches("nicetest")) { @@ -210,7 +210,7 @@ class Setup extends SimpleExtension { } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $themes = array(); foreach(glob("themes/*") as $theme_dirname) { $name = str_replace("themes/", "", $theme_dirname); @@ -309,7 +309,7 @@ class Setup extends SimpleExtension { $event->panel->add_block($sb); } - public function onConfigSave($event) { + public function onConfigSave(ConfigSaveEvent $event) { global $config; foreach($_POST as $_name => $junk) { if(substr($_name, 0, 6) == "_type_") { @@ -327,7 +327,7 @@ class Setup extends SimpleExtension { log_warning("setup", "Configuration updated"); } - public function onUserBlockBuilding($event) { + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; if($user->is_admin()) { $event->add_link("Board Config", make_link("setup")); diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index e909d179..a06425c1 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -56,7 +56,7 @@ class LockSetEvent extends Event { } class TagEdit extends SimpleExtension { - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { global $user, $page; if($event->page_matches("tag_edit")) { if($event->get_arg(0) == "replace") { @@ -71,8 +71,8 @@ class TagEdit extends SimpleExtension { } } - public function onImageInfoSet($event) { - global $user; + public function onImageInfoSet(ImageInfoSetEvent $event) { + global $user, $page; if($this->can_tag($event->image)) { send_event(new TagSetEvent($event->image, $_POST['tag_edit__tags'])); if($this->can_source($event->image)) { @@ -88,41 +88,41 @@ class TagEdit extends SimpleExtension { } } - public function onTagSet($event) { + public function onTagSet(TagSetEvent $event) { global $user; if($user->is_admin() || !$event->image->is_locked()) { $event->image->set_tags($event->tags); } } - public function onSourceSet($event) { + public function onSourceSet(SourceSetEvent $event) { global $user; if($user->is_admin() || !$event->image->is_locked()) { $event->image->set_source($event->source); } } - public function onLockSet($event) { + public function onLockSet(LockSetEvent $event) { global $user; if($user->is_admin()) { $event->image->set_locked($event->locked); } } - public function onImageDeletion($event) { + public function onImageDeletion(ImageDeletionEvent $event) { $event->image->delete_tags_from_image(); } - public function onAdminBuilding($event) { + public function onAdminBuilding(AdminBuildingEvent $event) { $this->theme->display_mass_editor(); } // When an alias is added, oldtag becomes inaccessable - public function onAddAlias($event) { + public function onAddAlias(AddAliasEvent $event) { $this->mass_tag_edit($event->oldtag, $event->newtag); } - public function onImageInfoBoxBuilding($event) { + public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { global $user; if($this->can_tag($event->image)) { $event->add_part($this->theme->get_tag_editor_html($event->image), 40); @@ -135,7 +135,7 @@ class TagEdit extends SimpleExtension { } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Tag Editing"); $sb->add_bool_option("tag_edit_anon", "Allow anonymous tag editing: "); $sb->add_bool_option("source_edit_anon", "
Allow anonymous source editing: "); @@ -143,7 +143,7 @@ class TagEdit extends SimpleExtension { } - private function can_tag($image) { + private function can_tag(Image $image) { global $config, $user; return ( ($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) && @@ -151,7 +151,7 @@ class TagEdit extends SimpleExtension { ); } - private function can_source($image) { + private function can_source(Image $image) { global $config, $user; return ( ($config->get_bool("source_edit_anon") || !$user->is_anonymous()) && diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 6edab5e8..c30aacb6 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -6,7 +6,7 @@ */ class TagList extends SimpleExtension { - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_int("tag_list_length", 15); $config->set_default_int("popular_tag_list_length", 15); @@ -16,7 +16,7 @@ class TagList extends SimpleExtension { $config->set_default_bool("tag_list_pages", false); } - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { global $page, $database; if($event->page_matches("tags")) { @@ -59,7 +59,7 @@ class TagList extends SimpleExtension { } } - public function onPostListBuilding($event) { + public function onPostListBuilding(PostListBuildingEvent $event) { global $config, $page; if($config->get_int('tag_list_length') > 0) { if(!empty($event->search_terms)) { @@ -71,7 +71,7 @@ class TagList extends SimpleExtension { } } - public function onDisplayingImage($event) { + public function onDisplayingImage(DisplayingImageEvent $event) { global $config, $page; if($config->get_int('tag_list_length') > 0) { if($config->get_string('tag_list_image_type') == 'related') { @@ -83,7 +83,7 @@ class TagList extends SimpleExtension { } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Tag Map Options"); $sb->add_int_option("tags_min", "Only show tags used at least "); $sb->add_label(" times"); $sb->add_bool_option("tag_list_pages", "
Paged tag lists: "); @@ -102,7 +102,7 @@ class TagList extends SimpleExtension { } // }}} // misc {{{ - private function tag_link($tag) { + private function tag_link(/*string*/ $tag) { $u_tag = url_escape($tag); return make_link("post/list/$u_tag/1"); } @@ -294,7 +294,7 @@ class TagList extends SimpleExtension { } // }}} // blocks {{{ - private function add_related_block($page, $image) { + private function add_related_block(Page $page, Image $image) { global $database; global $config; @@ -326,7 +326,7 @@ class TagList extends SimpleExtension { } } - private function add_tags_block($page, $image) { + private function add_tags_block(Page $page, Image $image) { global $database; global $config; @@ -345,7 +345,7 @@ class TagList extends SimpleExtension { } } - private function add_popular_block($page) { + private function add_popular_block(Page $page) { global $database; global $config; @@ -368,7 +368,7 @@ class TagList extends SimpleExtension { } } - private function add_refine_block($page, $search) { + private function add_refine_block(Page $page, /*string*/ $search) { global $database; global $config; diff --git a/ext/upload/main.php b/ext/upload/main.php index 8090a08e..979ab413 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -45,7 +45,7 @@ class Upload extends SimpleExtension { // early, so it can stop the DataUploadEvent before any data handlers see it public function get_priority() {return 40;} - public function onInitExt($event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_int('upload_count', 3); $config->set_default_int('upload_size', '1MB'); @@ -63,7 +63,7 @@ class Upload extends SimpleExtension { } - public function onPostListBuilding($event) { + public function onPostListBuilding(PostListBuildingEvent $event) { global $user, $page; if($this->can_upload($user)) { if($this->is_full) { @@ -75,7 +75,7 @@ class Upload extends SimpleExtension { } } - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $tes = array(); $tes["Disabled"] = "none"; if(function_exists("curl_init")) { @@ -97,7 +97,7 @@ class Upload extends SimpleExtension { $event->panel->add_block($sb); } - public function onDataUpload($event) { + public function onDataUpload(DataUploadEvent $event) { global $config; if($this->is_full) { throw new UploadException("Upload failed; disk nearly full"); @@ -218,7 +218,7 @@ class Upload extends SimpleExtension { } // }}} // do things {{{ - private function can_upload($user) { + private function can_upload(User $user) { global $config; return ($config->get_bool("upload_anon") || !$user->is_anonymous()); } diff --git a/ext/user/main.php b/ext/user/main.php index 7348b490..b5c9dc64 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -43,7 +43,7 @@ class UserCreationEvent extends Event { class UserCreationException extends SCoreException {} class UserPage extends SimpleExtension { - public function onInitExt(Event $event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_bool("login_signup_enabled", true); $config->set_default_int("login_memory", 365); @@ -54,7 +54,7 @@ class UserPage extends SimpleExtension { $config->set_default_bool("login_tac_bbcode", true); } - public function onPageRequest(Event $event) { + public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; // user info is shown on all pages @@ -152,7 +152,7 @@ class UserPage extends SimpleExtension { } } - if(($event instanceof PageRequestEvent) && $event->page_matches("user")) { + if($event->page_matches("user")) { $display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0)); if($event->count_args() == 0 && $user->is_anonymous()) { $this->theme->display_error($page, "Not Logged In", @@ -169,7 +169,7 @@ class UserPage extends SimpleExtension { } } - public function onUserPageBuilding(Event $event) { + public function onUserPageBuilding(UserPageBuildingEvent $event) { global $page, $user, $config; $h_join_date = autodate($event->display_user->join_date); @@ -197,7 +197,7 @@ class UserPage extends SimpleExtension { } } - public function onSetupBuilding(Event $event) { + public function onSetupBuilding(SetupBuildingEvent $event) { global $config; $hosts = array( @@ -228,17 +228,17 @@ class UserPage extends SimpleExtension { $event->panel->add_block($sb); } - public function onUserBlockBuilding(Event $event) { + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { $event->add_link("My Profile", make_link("user")); $event->add_link("Log Out", make_link("user_admin/logout"), 99); } - public function onUserCreation(Event $event) { + public function onUserCreation(UserCreationEvent $event) { $this->check_user_creation($event); $this->create_user($event); } - public function onSearchTermParse(Event $event) { + public function onSearchTermParse(SearchTermParseEvent $event) { global $user; $matches = array(); @@ -263,7 +263,7 @@ class UserPage extends SimpleExtension { } // }}} // Things done *with* the user {{{ - private function login($page) { + private function login(Page $page) { global $user; $name = $_POST['user']; @@ -289,7 +289,7 @@ class UserPage extends SimpleExtension { } } - private function check_user_creation($event) { + private function check_user_creation($event) { // FIXME type $name = $event->username; $pass = $event->password; $email = $event->email; @@ -309,7 +309,7 @@ class UserPage extends SimpleExtension { } } - private function create_user($event) { + private function create_user($event) { // FIXME type global $database; $hash = md5(strtolower($event->username) . $event->password); @@ -326,7 +326,7 @@ class UserPage extends SimpleExtension { log_info("user", "Created User #$uid ({$event->username})"); } - private function set_login_cookie($name, $pass) { + private function set_login_cookie(/*string*/ $name, /*string*/ $pass) { global $config; $addr = get_session_ip($config); @@ -339,7 +339,7 @@ class UserPage extends SimpleExtension { } //}}} // Things done *to* the user {{{ - private function change_password_wrapper($page) { + private function change_password_wrapper(Page $page) { global $user; global $config; global $database; @@ -378,7 +378,7 @@ class UserPage extends SimpleExtension { } } - private function change_email_wrapper($page) { + private function change_email_wrapper(Page $page) { global $user; global $config; global $database; @@ -411,7 +411,7 @@ class UserPage extends SimpleExtension { } } - private function set_more_wrapper($page) { + private function set_more_wrapper(Page $page) { global $user; global $config; global $database; @@ -443,7 +443,7 @@ class UserPage extends SimpleExtension { } // }}} // ips {{{ - private function count_upload_ips($duser) { + private function count_upload_ips(User $duser) { global $database; $rows = $database->get_pairs(" SELECT @@ -456,7 +456,7 @@ class UserPage extends SimpleExtension { ORDER BY most_recent DESC", array("id"=>$duser->id)); return $rows; } - private function count_comment_ips($duser) { + private function count_comment_ips(User $duser) { global $database; $rows = $database->get_pairs(" SELECT @@ -470,7 +470,7 @@ class UserPage extends SimpleExtension { return $rows; } - private function delete_user($page) { + private function delete_user(Page $page) { global $user; global $config; global $database; @@ -501,7 +501,7 @@ class UserPage extends SimpleExtension { } } - private function delete_user_with_images($page) { + private function delete_user_with_images(Page $page) { global $user; global $config; global $database; @@ -537,5 +537,4 @@ class UserPage extends SimpleExtension { // }}} } -add_event_listener(new UserPage()); ?> diff --git a/ext/view/main.php b/ext/view/main.php index 58399b1c..3fa700f6 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -60,7 +60,7 @@ class ImageAdminBlockBuildingEvent extends Event { $this->user = $user; } - public function add_part($html, $position=50) { + public function add_part(/*string*/ $html, /*int*/ $position=50) { while(isset($this->parts[$position])) $position++; $this->parts[$position] = $html; } diff --git a/index.php b/index.php index 46132b2e..8bd09936 100644 --- a/index.php +++ b/index.php @@ -55,32 +55,11 @@ if(empty($database_dsn) && !file_exists("config.php")) { exit; } require_once "config.php"; - -// to change these system-level settings, do define("FOO", 123); in config.php -function _d($name, $value) {if(!defined($name)) define($name, $value);} -_d("DATABASE_DSN", null); // string PDO database connection details -_d("CACHE_DSN", null); // string cache connection details -_d("DEBUG", false); // boolean print various debugging details -_d("DEBUG_SQL", false); // boolean dump SQL queries to data/sql.log -_d("COVERAGE", false); // boolean activate xdebug coverage monitor -_d("CONTEXT", null); // string file to log performance data into -_d("CACHE_MEMCACHE", false); // boolean store complete rendered pages in memcache -_d("CACHE_DIR", false); // boolean store complete rendered pages on disk -_d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers -_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes -_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance -_d("COMPILE_ELS", false); // boolean pre-build the list of event listeners -_d("NICE_URLS", false); // boolean force niceurl mode -_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse -_d("VERSION", 'trunk'); // string shimmie version -_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version -_d("TIMEZONE", 'UTC'); // string timezone - -// set up and purify the environment -date_default_timezone_set(TIMEZONE); - +require_once "core/default_config.inc.php"; require_once "core/util.inc.php"; require_once "lib/context.php"; + +// set up and purify the environment if(CONTEXT) { ctx_set_log(CONTEXT); } @@ -103,7 +82,6 @@ try { } ctx_log_endok(); - ctx_log_start("Connecting to DB"); // connect to the database $database = new Database(); @@ -111,105 +89,22 @@ try { $config = new DatabaseConfig($database); ctx_log_endok(); - - ctx_log_start("Loading themelets"); // load the theme parts + ctx_log_start("Loading themelets"); $_theme = $config->get_string("theme", "default"); - if(!file_exists('themes/'.$_theme)) $_theme = "default"; - if(file_exists('themes/'.$_theme.'/custompage.class.php')) require_once 'themes/'.$_theme.'/custompage.class.php'; - require_once 'themes/'.$_theme.'/layout.class.php'; - require_once 'themes/'.$_theme.'/themelet.class.php'; - - $themelets = glob("ext/*/theme.php"); - foreach($themelets as $filename) { - require_once $filename; - } - - $custom_themelets = glob('themes/'.$_theme.'/*.theme.php'); - if($custom_themelets) { - $m = array(); - foreach($custom_themelets as $filename) { - if(preg_match('/themes\/'.$_theme.'\/(.*)\.theme\.php/',$filename,$m) - && in_array('ext/'.$m[1].'/theme.php', $themelets)) { - require_once $filename; - } - } + if(!file_exists("themes/$_theme")) $_theme = "default"; + foreach(_get_themelet_files($_theme) as $themelet) { + require_once $themelet; } ctx_log_endok(); - - ctx_log_start("Loading extensions"); - // initialise the extensions - global $_event_listeners; - if(COMPILE_ELS && file_exists("data/event_listeners.php")) { - require_once("data/event_listeners.php"); - } - else { - $all_events = array(); - foreach(get_declared_classes() as $class) { - if(is_subclass_of($class, "Event")) { - $all_events[] = $class; - } - } - foreach(get_declared_classes() as $class) { - $rclass = new ReflectionClass($class); - if($rclass->isAbstract()) { - // don't do anything - } - elseif(is_subclass_of($class, "SimpleExtension")) { - $c = new $class(); - $c->i_am($c); - $my_events = array(); - foreach(get_class_methods($c) as $method) { - if(substr($method, 0, 2) == "on") { - $my_events[] = substr($method, 2) . "Event"; - } - } - add_event_listener($c, $c->get_priority(), $my_events); - } - elseif(is_subclass_of($class, "Extension")) { - $c = new $class(); - add_event_listener($c, $c->get_priority(), $all_events); - } - } - - if(COMPILE_ELS) { - $p = "<"."?php\n"; - - foreach(get_declared_classes() as $class) { - $rclass = new ReflectionClass($class); - if($rclass->isAbstract()) {} - elseif(is_subclass_of($class, "SimpleExtension")) { - $p .= "\$$class = new $class(); "; - $p .= "\${$class}->i_am(\$$class);\n"; - } - elseif(is_subclass_of($class, "Extension")) { - $p .= "\$$class = new $class();\n"; - } - } - - $p .= "\$_event_listeners = array(\n"; - foreach($_event_listeners as $event => $listeners) { - $p .= "\t'$event' => array(\n"; - foreach($listeners as $id => $listener) { - $p .= "\t\t$id => \$".get_class($listener).",\n"; - } - $p .= "\t),\n"; - } - $p .= ");\n"; - - $p .= "?".">"; - file_put_contents("data/event_listeners.php", $p); - } - } - ctx_log_endok(); + _load_extensions(); ctx_log_endok("Initialisation"); - ctx_log_start("Page generation"); // start the page generation waterfall $page = class_exists("CustomPage") ? new CustomPage() : new Page(); - $user = _get_user($config, $database); + $user = _get_user(); send_event(new InitExtEvent()); send_event(_get_page_request()); $page->display(); @@ -220,22 +115,8 @@ try { ctx_log_endok(); } catch(Exception $e) { - $version = VERSION; - $message = $e->getMessage(); - //$trace = var_dump($e->getTrace()); - header("HTTP/1.0 500 Internal Error"); - echo ' - - - Internal error - SCore-'.$version.' - - -

Internal Error

-

'.$message.' - - -'; if($database && $database->db) $database->db->rollback(); + _fatal_error($e); ctx_log_ender(); } ?>