本文整理汇总了PHP中add_event_listener函数的典型用法代码示例。如果您正苦于以下问题:PHP add_event_listener函数的具体用法?PHP add_event_listener怎么用?PHP add_event_listener使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_event_listener函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: phpversion
$info['sys_shimmie'] = VERSION;
$info['sys_schema'] = $config->get_string("db_version");
$info['sys_php'] = phpversion();
$info['sys_os'] = php_uname();
$info['sys_disk'] = to_shorthand_int(disk_total_space("./") - disk_free_space("./")) . " / " . to_shorthand_int(disk_total_space("./"));
$info['sys_server'] = $_SERVER["SERVER_SOFTWARE"];
include "config.php";
// more magical hax
$proto = preg_replace("#(.*)://.*#", "\$1", $database_dsn);
$db = $database->db->ServerInfo();
$info['sys_db'] = "{$proto} / {$db['version']}";
$info['stat_images'] = $database->db->GetOne("SELECT COUNT(*) FROM images");
$info['stat_comments'] = $database->db->GetOne("SELECT COUNT(*) FROM comments");
$info['stat_users'] = $database->db->GetOne("SELECT COUNT(*) FROM users");
$info['stat_tags'] = $database->db->GetOne("SELECT COUNT(*) FROM tags");
$info['stat_image_tags'] = $database->db->GetOne("SELECT COUNT(*) FROM image_tags");
$els = array();
foreach ($_event_listeners as $el) {
$els[] = get_class($el);
}
$info['sys_extensions'] = join(', ', $els);
//$cfs = array();
//foreach($database->get_all("SELECT name, value FROM config") as $pair) {
// $cfs[] = $pair['name']."=".$pair['value'];
//}
//$info[''] = "Config: ".join(", ", $cfs);
return $info;
}
}
add_event_listener(new ET());
示例2: Block
$page->add_block(new Block("No ID Specified", "You need to specify the account number to edit"));
} else {
$admin = isset($_POST['admin']) && $_POST['admin'] == "on";
$duser = User::by_id($_POST['id']);
$duser->set_admin($admin);
$page->set_mode("redirect");
if ($duser->id == $user->id) {
$page->set_redirect(make_link("user"));
} else {
$page->set_redirect(make_link("user/{$duser->name}"));
}
}
}
}
// }}}
// ips {{{
private function count_upload_ips($duser)
{
global $database;
$rows = $database->get_pairs("\n\t\t\t\tSELECT\n\t\t\t\t\towner_ip,\n\t\t\t\t\tCOUNT(images.id) AS count,\n\t\t\t\t\tMAX(posted) AS most_recent\n\t\t\t\tFROM images\n\t\t\t\tWHERE owner_id=:id\n\t\t\t\tGROUP BY owner_ip\n\t\t\t\tORDER BY most_recent DESC", array("id" => $duser->id));
return $rows;
}
private function count_comment_ips($duser)
{
global $database;
$rows = $database->get_pairs("\n\t\t\t\tSELECT\n\t\t\t\t\towner_ip,\n\t\t\t\t\tCOUNT(comments.id) AS count,\n\t\t\t\t\tMAX(posted) AS most_recent\n\t\t\t\tFROM comments\n\t\t\t\tWHERE owner_id=:id\n\t\t\t\tGROUP BY owner_ip\n\t\t\t\tORDER BY most_recent DESC", array("id" => $duser->id));
return $rows;
}
}
add_event_listener(new UserPage());
示例3: Querylet
$event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", array($iid)));
}
}
}
private function install()
{
global $database;
global $config;
if ($config->get_int("ext_numeric_score_version") < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN numeric_score INTEGER NOT NULL DEFAULT 0");
$database->Execute("CREATE INDEX images__numeric_score ON images(numeric_score)");
$database->create_table("numeric_score_votes", "\n\t\t\t\timage_id INTEGER NOT NULL,\n\t\t\t\tuser_id INTEGER NOT NULL,\n\t\t\t\tscore INTEGER NOT NULL,\n\t\t\t\tUNIQUE(image_id, user_id),\n\t\t\t\tINDEX(image_id),\n\t\t\t\tFOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,\n\t\t\t\tFOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\n\t\t\t");
$config->set_int("ext_numeric_score_version", 1);
}
if ($config->get_int("ext_numeric_score_version") < 2) {
$database->Execute("CREATE INDEX numeric_score_votes__user_votes ON numeric_score_votes(user_id, score)");
$config->set_int("ext_numeric_score_version", 2);
}
}
private function add_vote($image_id, $user_id, $score)
{
global $database;
$database->Execute("DELETE FROM numeric_score_votes WHERE image_id=? AND user_id=?", array($image_id, $user_id));
if ($score != 0) {
$database->Execute("INSERT INTO numeric_score_votes(image_id, user_id, score) VALUES(?, ?, ?)", array($image_id, $user_id, $score));
}
$database->Execute("UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=?) WHERE id=?", array($image_id, $image_id));
}
}
add_event_listener(new NumericScore());
示例4: tag_to_xml
}
return $result . "</list>";
}
private function tag_to_xml($tag)
{
return "<tag " . "id=\"" . $tag['id'] . "\" " . "count=\"" . $tag['count'] . "\">" . html_escape($tag['tag']) . "</tag>";
}
private function count($query, $values)
{
global $database;
return $database->Execute("SELECT COUNT(*) FROM `tags` {$query}", $values)->fields['COUNT(*)'];
}
private function image_tags($image_id)
{
global $database;
$list = "(";
$i_tags = $database->Execute("SELECT tag_id FROM `image_tags` WHERE image_id=?", array($image_id));
$b = false;
foreach ($i_tags as $tag) {
if ($b) {
$list .= ",";
}
$b = true;
$list .= $tag['tag_id'];
}
$list .= ")";
return $list;
}
}
add_event_listener(new taggerXML(), 10);
示例5: substr
}
$beginning = substr($text, 0, $start);
$middle = base64_encode(substr($text, $start + $l1, $end - $start - $l1));
$ending = substr($text, $end + $l2, strlen($text) - $end + $l2);
$text = $beginning . "[code!]" . $middle . "[/code!]" . $ending;
}
return $text;
}
private function insert_code($text)
{
$l1 = strlen("[code!]");
$l2 = strlen("[/code!]");
while (true) {
$start = strpos($text, "[code!]");
if ($start === false) {
break;
}
$end = strpos($text, "[/code!]");
if ($end === false) {
break;
}
$beginning = substr($text, 0, $start);
$middle = base64_decode(substr($text, $start + $l1, $end - $start - $l1));
$ending = substr($text, $end + $l2, strlen($text) - $end + $l2);
$text = $beginning . "<pre>" . $middle . "</pre>" . $ending;
}
return $text;
}
}
add_event_listener(new BBCode());
示例6: COUNT
global $database;
$result = $database->get_one("SELECT COUNT(1) FROM artist_members WHERE artist_id = ? AND name = ?", array($artistID, mysql_real_escape_string($member)));
return $result != 0;
}
private function url_exists($artistID, $url)
{
if (!is_numeric($artistID)) {
return;
}
global $database;
$result = $database->get_one("SELECT COUNT(1) FROM artist_urls WHERE artist_id = ? AND url = ?", array($artistID, mysql_real_escape_string($url)));
return $result != 0;
}
/*
* HERE WE GET THE INFO OF THE ALIAS
*/
private function get_alias($artistID)
{
if (!is_numeric($artistID)) {
return;
}
global $database;
$result = $database->get_all("SELECT id AS alias_id, alias AS alias_name " . "FROM artist_alias " . "WHERE artist_id = ? " . "ORDER BY alias ASC", array($artistID));
for ($i = 0; $i < count($result); $i++) {
$result[$i]["alias_name"] = stripslashes($result[$i]["alias_name"]);
}
return $result;
}
}
add_event_listener(new Artists());
示例7: add_tag_history
private function add_tag_history($image, $tags)
{
global $database;
global $config;
global $user;
$new_tags = Tag::implode($tags);
$old_tags = Tag::implode($image->get_tag_array());
log_debug("tag_history", "adding tag history: [{$old_tags}] -> [{$new_tags}]");
if ($new_tags == $old_tags) {
return;
}
// add a history entry
$allowed = $config->get_int("history_limit");
if ($allowed == 0) {
return;
}
$row = $database->execute("\n\t\t\t\tINSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)\n\t\t\t\tVALUES (?, ?, ?, ?, now())", array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
// if needed remove oldest one
if ($allowed == -1) {
return;
}
$entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
if ($entries > $allowed) {
// TODO: Make these queries better
$min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id));
$database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id));
}
}
}
add_event_listener(new Tag_History(), 40);
// in before tags are actually set, so that "get current tags" works
示例8: filter
$event->panel->add_block($sb);
}
}
private function filter($text)
{
$map = $this->get_map();
foreach ($map as $search => $replace) {
$search = trim($search);
$replace = trim($replace);
$search = "/\\b{$search}\\b/i";
$text = preg_replace($search, $replace, $text);
}
return $text;
}
private function get_map()
{
global $config;
$raw = $config->get_string("word_filter");
$lines = explode("\n", $raw);
$map = array();
foreach ($lines as $line) {
$parts = explode(",", $line);
if (count($parts) == 2) {
$map[$parts[0]] = $parts[1];
}
}
return $map;
}
}
add_event_listener(new WordFilter(), 40);
// before emoticon filter
示例9: install
}
}
protected function install()
{
global $database;
global $config;
// shortcut to latest
if ($config->get_int("ext_bookmarks_version") < 1) {
$database->create_table("bookmark", "\n\t\t\t\tid SCORE_AIPK,\n\t\t\t\towner_id INTEGER NOT NULL,\n\t\t\t\turl TEXT NOT NULL,\n\t\t\t\ttitle TET NOT NULL,\n\t\t\t\tINDEX (owner_id),\n\t\t\t\tFOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE\n\t\t\t");
$config->set_int("ext_bookmarks_version", 1);
}
}
private function get_bookmarks()
{
global $database;
$bms = $database->get_all("\n\t\t\tSELECT *\n\t\t\tFROM bookmark\n\t\t\tWHERE bookmark.owner_id = ?\n\t\t");
if ($bms) {
return $bms;
} else {
return array();
}
}
private function add_bookmark($url, $title)
{
global $database;
$sql = "INSERT INTO bookmark(owner_id, url, title) VALUES (?, ?, ?)";
$database->Execute($sql, array($user->id, $url, $title));
}
}
add_event_listener(new Bookmarks());
示例10: glob
}
$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;
}
}
}
// initialise the extensions
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, "SimpleExtension")) {
$c = new $class();
$c->i_am($c);
add_event_listener($c);
}
}
// start the page generation waterfall
$page = class_exists("CustomPage") ? new CustomPage() : new Page();
$user = _get_user($config, $database);
send_event(new InitExtEvent());
send_event(_get_page_request());
$page->display();
// for databases which support transactions
if ($database->engine->name != "sqlite") {
$database->db->CommitTrans(true);
}
_end_cache();
} catch (Exception $e) {
$version = VERSION;
示例11: authenticate_user
// Turns out I use this a couple times so let's make it a utility function
// Authenticates a user based on the contents of the login and password parameters
// or makes them anonymous. Does not set any cookies or anything permanent.
private function authenticate_user()
{
global $config;
global $database;
global $user;
if (isset($_REQUEST['login']) && isset($_REQUEST['password'])) {
// Get this user from the db, if it fails the user becomes anonymous
// Code borrowed from /ext/user
$name = $_REQUEST['login'];
$pass = $_REQUEST['password'];
$hash = md5(strtolower($name) . $pass);
$duser = User::by_name_and_hash($name, $hash);
if (!is_null($duser)) {
$user = $duser;
} else {
$user = User::by_id($config->get_int("anon_id", 0));
}
}
}
// From htmlspecialchars man page on php.net comments
// If tags contain quotes they need to be htmlified
private function xmlspecialchars($text)
{
return str_replace(''', ''', htmlspecialchars($text, ENT_QUOTES));
}
}
add_event_listener(new DanbooruApi());
示例12: copy
{
copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
}
protected function supported_ext($ext)
{
$exts = array("mp3");
return in_array(strtolower($ext), $exts);
}
protected function create_image_from_data($filename, $metadata)
{
global $config;
$image = new Image();
// FIXME: need more flash format specs :|
$image->width = 0;
$image->height = 0;
$image->filesize = $metadata['size'];
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
return $image;
}
protected function check_contents($file)
{
// FIXME: mp3 magic header?
return file_exists($file);
}
}
add_event_listener(new MP3FileHandler());
示例13: foreach
{
global $config, $database;
if (!is_numeric($config->get_string("db_version"))) {
$config->set_int("db_version", 2);
}
if ($config->get_int("db_version") < 6) {
// cry :S
}
if ($config->get_int("db_version") < 7) {
if ($database->engine->name == "mysql") {
$tables = $database->db->MetaTables();
foreach ($tables as $table) {
log_info("upgrade", "converting {$table} to innodb");
$database->execute("ALTER TABLE {$table} TYPE=INNODB");
}
}
$config->set_int("db_version", 7);
log_info("upgrade", "Database at version 7");
}
// TODO:
// add column image->locked
if ($config->get_int("db_version") < 8) {
// if this fails, don't try again
$config->set_int("db_version", 8);
$database->execute($database->engine->scoreql_to_sql("ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"));
log_info("upgrade", "Database at version 8");
}
}
}
add_event_listener(new Upgrade(), 5);
示例14: date
$page->set_mode("data");
$page->set_type("application/x-unknown");
$page->set_filename('shimmie-' . date('Ymd') . '.sql');
$page->set_data(shell_exec($cmd));
}
private function check_for_orphanned_images()
{
$orphans = array();
foreach (glob("images/*") as $dir) {
foreach (glob("{$dir}/*") as $file) {
$hash = str_replace("{$dir}/", "", $file);
if (!$this->db_has_hash($hash)) {
$orphans[] = $hash;
}
}
}
}
private function convert_to_innodb()
{
global $database;
if ($database->engine->name == "mysql") {
$tables = $database->db->MetaTables();
foreach ($tables as $table) {
log_info("upgrade", "converting {$table} to innodb");
$database->execute("ALTER TABLE {$table} TYPE=INNODB");
}
}
}
}
add_event_listener(new AdminPage());
示例15: SetupBlock
$sb = new SetupBlock("Downtime");
$sb->add_bool_option("downtime", "Disable non-admin access: ");
$sb->add_longtext_option("downtime_message", "<br>");
$event->panel->add_block($sb);
}
if ($event instanceof PageRequestEvent) {
if ($config->get_bool("downtime")) {
$this->check_downtime($event);
$this->theme->display_notification($page);
}
}
}
private function check_downtime(PageRequestEvent $event)
{
global $user, $config;
if ($config->get_bool("downtime") && !$user->is_admin() && $event instanceof PageRequestEvent && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
$this->theme->display_message($msg);
}
}
private function is_safe_page(PageRequestEvent $event)
{
if ($event->page_matches("user_admin/login")) {
return true;
} else {
return false;
}
}
}
add_event_listener(new Downtime(), 10);