Example #1
0
        $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());
Example #2
0
                $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());
Example #3
0
                $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());
Example #4
0
        }
        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);
Example #5
0
            }
            $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());
Example #6
0
        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());
Example #7
0
    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
Example #8
0
            $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
Example #9
0
        }
    }
    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());
Example #10
0
    }
    $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;
Example #11
0
    // 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('&#039;', '&apos;', htmlspecialchars($text, ENT_QUOTES));
    }
}
add_event_listener(new DanbooruApi());
Example #12
0
    {
        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());
Example #13
0
    {
        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);
Example #14
0
        $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());
Example #15
0
            $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);
Example #16
0
    {
        if (!file_exists($file)) {
            return false;
        }
        $msp = new MiniSVGParser($file);
        return $msp->valid;
    }
}
class MiniSVGParser
{
    var $valid = false, $width = 0, $height = 0;
    function MiniSVGParser($file)
    {
        $xml_parser = xml_parser_create();
        xml_set_element_handler($xml_parser, array($this, "startElement"), array($this, "endElement"));
        $this->valid = xml_parse($xml_parser, file_get_contents($file), true);
        xml_parser_free($xml_parser);
    }
    function startElement($parser, $name, $attrs)
    {
        if ($name == "SVG") {
            $this->width = int_escape($attrs["WIDTH"]);
            $this->height = int_escape($attrs["HEIGHT"]);
        }
    }
    function endElement($parser, $name)
    {
    }
}
add_event_listener(new SVGFileHandler());
Example #17
0
function _set_event_listeners($classes)
{
    global $_event_listeners;
    $_event_listeners = array();
    foreach ($classes as $class) {
        $rclass = new ReflectionClass($class);
        if ($rclass->isAbstract()) {
            // don't do anything
        } elseif (is_subclass_of($class, "Extension")) {
            $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);
        }
    }
}
Example #18
0
{
    public function receive_event(Event $event)
    {
        if ($event instanceof PageRequestEvent) {
            global $page;
            // hax.
            if ($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
                $h_pagename = html_escape(implode('/', $event->args));
                header("HTTP/1.0 404 Page Not Found");
                log_debug("handle_404", "Hit 404: {$h_pagename}");
                $page->set_title("404");
                $page->set_heading("404 - No Handler Found");
                $page->add_block(new NavBlock());
                $page->add_block(new Block("Explanation", "No handler could be found for the page '{$h_pagename}'"));
            }
        }
    }
    private function count_main($blocks)
    {
        $n = 0;
        foreach ($blocks as $block) {
            if ($block->section == "main") {
                $n++;
            }
            // more hax.
        }
        return $n;
    }
}
add_event_listener(new Handle404(), 99);
// hax++
Example #19
0
                }
                // And to do stuff with it. We want our output to look like:
                // ["shimmie",["shimmies","shimmy","shimmie","21 shimmies","hip shimmies","skea shimmies"],[],[]]
                $json_tag_list = "";
                $tags_array = array();
                foreach ($tags as $tag) {
                    array_push($tags_array, $tag['tag']);
                }
                $json_tag_list .= implode("\",\"", $tags_array);
                //			$json_tag_list = implode($tags_array,", ");
                //			$json_tag_list = "\"".implode($tags_array,"\", \"")."\"";
                // And now for the final output
                $json_string = "[\"{$tag_search}\",[\"{$json_tag_list}\"],[],[]]";
                $page->set_mode("data");
                $page->set_data($json_string);
            }
        }
        if ($event instanceof SetupBuildingEvent) {
            $sort_by = array();
            $sort_by['Alphabetical'] = 'a';
            $sort_by['Tag Count'] = 't';
            $sb = new SetupBlock("Browser Search");
            $sb->add_bool_option("disable_search_suggestions", "Disable search suggestions: ");
            $sb->add_label("<br>");
            $sb->add_choice_option("search_suggestions_results_order", $sort_by, "Sort the suggestions by:");
            $event->panel->add_block($sb);
        }
    }
}
add_event_listener(new BrowserSearch());
Example #20
0
    $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;
            }
        }
    }
    ctx_log_endok();
    // 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, $c->get_priority());
        }
    }
    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);
    send_event(new InitExtEvent());
    send_event(_get_page_request());
    $page->display();
    ctx_log_endok("Page generation");
    $database->db->commit();
    _end_cache();
    ctx_log_endok();
} catch (Exception $e) {
Example #21
0
            // search returns high-ids first, so we want to look
            // at images with lower IDs than the previous.
            $search_forward = $search_set;
            if ($last_id >= 0) {
                $search_forward[] = "id<{$last_id}";
            }
            $images = Image::find_images(0, 100, $search_forward);
            if (count($images) == 0) {
                break;
            }
            foreach ($images as $image) {
                // remove the search'ed tags
                $before = $image->get_tag_array();
                $after = array();
                foreach ($before as $tag) {
                    if (!in_array($tag, $search_set)) {
                        $after[] = $tag;
                    }
                }
                // add the replace'd tags
                foreach ($replace_set as $tag) {
                    $after[] = $tag;
                }
                $image->set_tags($after);
                $last_id = $image->id;
            }
        }
    }
}
add_event_listener(new TagEdit());
Example #22
0
                if ($usedfirst) {
                    $precloud .= "&nbsp;<span onclick=\"tageditcloud_toggle_tag(this)\" class=\"tag-selected\" style='font-size: {$size}em' title='{$usecount}'>{$h_tag}</span>&nbsp;\n";
                } else {
                    $counter++;
                    $cloud .= "&nbsp;<span onclick=\"tageditcloud_toggle_tag(this)\" class=\"tag-selected\" style='font-size: {$size}em' title='{$usecount}'>{$h_tag}</span>&nbsp;\n";
                }
            } else {
                $counter++;
                $cloud .= "&nbsp;<span onclick=\"tageditcloud_toggle_tag(this)\" style='font-size: {$size}em' title='{$usecount}'>{$h_tag}</span>&nbsp;\n";
            }
        }
        if ($precloud != '') {
            $html .= "<div id=\"tagcloud_set\">{$precloud}</div>";
        }
        $html .= "<div id=\"tagcloud_unset\">{$cloud}</div>";
        $rem = count($tag_data) - $defcount;
        if (!$alphasort && $counter >= $defcount) {
            $html .= "</div><br>[<span onclick=\"tageditcloud_toggle_extra('tagcloud_extra',this);\" style=\"color: #0000EF; font-weight:bold;\">show {$rem} more tags</span>]";
        }
        //		$html.='<pre>'.var_export($itags,true).'</pre>';
        return "<div id=\"tageditcloud\" class=\"tageditcloud\">{$html}</div>";
        // FIXME: stupidasallhell
    }
    private function can_tag($image)
    {
        global $config, $user;
        return ($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) && ($user->is_admin() || !$image->is_locked());
    }
}
add_event_listener(new TagEditCloud());
Example #23
0
            $pathinfo = pathinfo($url);
            $metadata['filename'] = $pathinfo['basename'];
            $metadata['extension'] = $pathinfo['extension'];
            $metadata['tags'] = $tags;
            $metadata['source'] = $source;
            /* check for locked > adds to metadata if it has */
            if (!empty($locked)) {
                $metadata['locked'] = $locked ? "on" : "";
            }
            /* check for rating > adds to metadata if it has */
            if (!empty($rating)) {
                $metadata['rating'] = $rating;
            }
            /* check if we have been given an image ID to replace */
            if (!empty($replace)) {
                $metadata['replace'] = $replace;
            }
            $event = new DataUploadEvent($user, $tmp_filename, $metadata);
            try {
                send_event($event);
            } catch (UploadException $ex) {
                $this->theme->display_upload_error($page, "Error with " . html_escape($url), $ex->getMessage());
                $ok = false;
            }
        }
        unlink($tmp_filename);
        return $ok;
    }
}
add_event_listener(new Upload(), 40);
// early, so it can stop the DataUploadEvent before any data handlers see it
Example #24
0
        $memory_limit = get_memory_limit();
        if ($memory_use > $memory_limit) {
            $w = $config->get_int('thumb_width');
            $h = $config->get_int('thumb_height');
            $thumb = imagecreatetruecolor($w, min($h, 64));
            $white = imagecolorallocate($thumb, 255, 255, 255);
            $black = imagecolorallocate($thumb, 0, 0, 0);
            imagefill($thumb, 0, 0, $white);
            imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
            return $thumb;
        } else {
            $image = imagecreatefromstring($this->read_file($tmpname));
            $tsize = get_thumbnail_size($width, $height);
            $thumb = imagecreatetruecolor($tsize[0], $tsize[1]);
            imagecopyresampled($thumb, $image, 0, 0, 0, 0, $tsize[0], $tsize[1], $width, $height);
            return $thumb;
        }
    }
    private function read_file($fname)
    {
        $fp = fopen($fname, "r");
        if (!$fp) {
            return false;
        }
        $data = fread($fp, filesize($fname));
        fclose($fp);
        return $data;
    }
}
add_event_listener(new PixelFileHandler());
Example #25
0
        if ($bans) {
            return $bans;
        } else {
            return array();
        }
    }
    private function get_active_bans()
    {
        global $database;
        $cached = $database->cache->get("ip_bans");
        if ($cached) {
            return $cached;
        }
        $bans = $database->get_all("\n\t\t\tSELECT bans.*, users.name as banner_name\n\t\t\tFROM bans\n\t\t\tJOIN users ON banner_id = users.id\n\t\t\tWHERE (end_timestamp > :end_timestamp) OR (end_timestamp IS NULL)\n\t\t\tORDER BY end_timestamp, bans.id\n\t\t", array("end_timestamp" => time()));
        $database->cache->set("ip_bans", $bans, 600);
        if ($bans) {
            return $bans;
        } else {
            return array();
        }
    }
    private function add_ip_ban($ip, $reason, $end, $user)
    {
        global $database;
        $sql = "INSERT INTO bans (ip, reason, end_timestamp, banner_id) VALUES (:ip, :reason, :end, :admin_id)";
        $database->Execute($sql, array("ip" => $ip, "reason" => $reason, "end" => strtotime($end), "admin_id" => $user->id));
        $database->cache->delete("ip_bans");
    }
}
add_event_listener(new IPBan(), 10);
Example #26
0
            $int = $int + ($binarray[$i] == "1" ? 1 : 0);
        }
        return $int;
    }
    private function swf_get_bounds($filename)
    {
        $fp = fopen($filename, "r");
        $head = fread($fp, 3);
        $version = fread($fp, 1);
        $length = fread($fp, 4);
        if ($head == "FWS") {
            $data = fread($fp, 16);
        } else {
            if ($head == "CWS") {
                $data = fread($fp, 128 * 1024);
                $data = gzuncompress($data);
                $data = substr($data, 0, 16);
            }
        }
        $bounds = array();
        $rect_bin = $this->str_to_binarray($data);
        $nbits = $this->binarray_to_int($rect_bin, 0, 5);
        $bounds[] = $this->binarray_to_int($rect_bin, 5 + 0 * $nbits, $nbits) / 20;
        $bounds[] = $this->binarray_to_int($rect_bin, 5 + 1 * $nbits, $nbits) / 20;
        $bounds[] = $this->binarray_to_int($rect_bin, 5 + 2 * $nbits, $nbits) / 20;
        $bounds[] = $this->binarray_to_int($rect_bin, 5 + 3 * $nbits, $nbits) / 20;
        return $bounds;
    }
}
add_event_listener(new FlashFileHandler());
Example #27
0
        global $database;
        global $config;
        $wild_tags = Tag::explode($search);
        // $search_tags = array();
        $tag_id_array = array();
        $tags_ok = true;
        foreach ($wild_tags as $tag) {
            $tag = str_replace("*", "%", $tag);
            $tag = str_replace("?", "_", $tag);
            $tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag" => $tag));
            // $search_tags = array_merge($search_tags,
            //                  $database->get_col("SELECT tag FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)));
            $tag_id_array = array_merge($tag_id_array, $tag_ids);
            $tags_ok = count($tag_ids) > 0;
            if (!$tags_ok) {
                break;
            }
        }
        $tag_id_list = join(', ', $tag_id_array);
        if ($tags_ok) {
            $query = "\n\t\t\t\tSELECT t2.tag AS tag, COUNT(it2.image_id) AS calc_count\n\t\t\t\tFROM\n\t\t\t\t\timage_tags AS it1,\n\t\t\t\t\timage_tags AS it2,\n\t\t\t\t\ttags AS t1,\n\t\t\t\t\ttags AS t2\n\t\t\t\tWHERE\n\t\t\t\t\tt1.id IN({$tag_id_list})\n\t\t\t\t\tAND it1.image_id=it2.image_id\n\t\t\t\t\tAND it1.tag_id = t1.id\n\t\t\t\t\tAND it2.tag_id = t2.id\n\t\t\t\tGROUP BY t2.tag\n\t\t\t\tORDER BY calc_count\n\t\t\t\tDESC LIMIT :limit\n\t\t\t";
            $args = array("limit" => $config->get_int('tag_list_length'));
            $related_tags = $database->get_all($query, $args);
            if (count($related_tags) > 0) {
                $this->theme->display_refine_block($page, $related_tags, $wild_tags);
            }
        }
    }
}
add_event_listener(new TagList());
Example #28
0
    {
        global $config, $database;
        $all_reports = $database->get_all("\n\t\t\tSELECT image_reports.*, users.name AS reporter_name\n\t\t\tFROM image_reports\n\t\t\tJOIN users ON reporter_id = users.id");
        if (is_null($all_reports)) {
            $all_reports = array();
        }
        $reports = array();
        foreach ($all_reports as $report) {
            $image_id = int_escape($report['image_id']);
            $image = Image::by_id($image_id);
            if (is_null($image)) {
                send_event(new RemoveReportedImageEvent($report['id']));
                continue;
            }
            $report['image'] = $image;
            $reports[] = $report;
        }
        return $reports;
    }
}
add_event_listener(new ReportImage(), 29);
// Not sure what I'm in before.
//  ===== Changelog =====
// * Version 0.3a / 0.3a_rc - 11/06/07 - I can no longer use the same theme.php file for both SVN and RCx. Sorry.
// *   Same deal with theme.php as it is with main.php
// * Version 0.3 / 0.3_rc - 11/06/07 - Added the option to display thumbnails, moved the reported image list to it's
//     own page, and checked to make sure the user is an admin before letting them delete / view reported images.
// * Version 0.2c_rc2 - 10/27/07 - Now (really!) supports Shimmie2 RC2!
// * Version 0.2b - 10/27/07 - Now supports Shimmie2 RC2!
// * Version 0.2a - 10/24/07 - Fixed some SQL issues. I will make sure to test before commiting :)
// * Version 0.2 - 10/24/07 - First public release.
Example #29
0
                        $ok = true;
                        break;
                    }
                }
                if ($valids > 0 && !$ok) {
                    throw new UploadException("Image needs to be in one of these ratios: " . html_escape($config->get_string("upload_ratios", "")));
                }
            }
        }
        if ($event instanceof SetupBuildingEvent) {
            $sb = new SetupBlock("Resolution Limits");
            $sb->add_label("Min ");
            $sb->add_int_option("upload_min_width");
            $sb->add_label(" x ");
            $sb->add_int_option("upload_min_height");
            $sb->add_label(" px");
            $sb->add_label("<br>Max ");
            $sb->add_int_option("upload_max_width");
            $sb->add_label(" x ");
            $sb->add_int_option("upload_max_height");
            $sb->add_label(" px");
            $sb->add_label("<br>(-1 for no limit)");
            $sb->add_label("<br>Ratios ");
            $sb->add_text_option("upload_ratios");
            $sb->add_label("<br>(eg. '4:3 16:9', blank for no limit)");
            $event->panel->add_block($sb);
        }
    }
}
add_event_listener(new ResolutionLimit(), 40);
// early, to veto UIE
Example #30
0
                return false;
            }
        }
        return true;
    }
    private function install()
    {
        global $database;
        global $config;
        if ($config->get_int("ext_ratings2_version") < 1) {
            $database->Execute("ALTER TABLE images ADD COLUMN rating CHAR(1) NOT NULL DEFAULT 'u'");
            $database->Execute("CREATE INDEX images__rating ON images(rating)");
            $config->set_int("ext_ratings2_version", 3);
        }
        if ($config->get_int("ext_ratings2_version") < 2) {
            $database->Execute("CREATE INDEX images__rating ON images(rating)");
            $config->set_int("ext_ratings2_version", 2);
        }
        if ($config->get_int("ext_ratings2_version") < 3) {
            $database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'");
            $config->set_int("ext_ratings2_version", 3);
        }
    }
    private function set_rating($image_id, $rating)
    {
        global $database;
        $database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
    }
}
add_event_listener(new Ratings());