Merge branch 'master' of github.com:shish/shimmie2
This commit is contained in:
commit
b82fd133fc
@ -195,7 +195,7 @@ class MemcacheCache implements CacheEngine {
|
||||
public function get($key) {
|
||||
assert(!is_null($key));
|
||||
$val = $this->memcache->get($key);
|
||||
if($val) {
|
||||
if($val !== false) {
|
||||
$this->hits++;
|
||||
return $val;
|
||||
}
|
||||
@ -259,23 +259,43 @@ class Database {
|
||||
/**
|
||||
* The PDO database connection object, for anyone who wants direct access
|
||||
*/
|
||||
var $db;
|
||||
private $db = null;
|
||||
|
||||
/**
|
||||
* Meta info about the database engine
|
||||
*/
|
||||
var $engine = null;
|
||||
private $engine = null;
|
||||
|
||||
/**
|
||||
* The currently active cache engine
|
||||
*/
|
||||
var $cache = null;
|
||||
public $cache = null;
|
||||
|
||||
/**
|
||||
* Create a new database object using connection info
|
||||
* stored in the config file
|
||||
* For now, only connect to the cache, as we will pretty much certainly
|
||||
* need it. There are some pages where all the data is in cache, so the
|
||||
* DB connection is on-demand.
|
||||
*/
|
||||
public function Database() {
|
||||
$this->connect_cache();
|
||||
}
|
||||
|
||||
private function connect_cache() {
|
||||
$matches = array();
|
||||
if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) {
|
||||
if($matches[1] == "memcache") {
|
||||
$this->cache = new MemcacheCache($matches[2]);
|
||||
}
|
||||
else if($matches[1] == "apc") {
|
||||
$this->cache = new APCCache($matches[2]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->cache = new NoCache();
|
||||
}
|
||||
}
|
||||
|
||||
private function connect_db() {
|
||||
# FIXME: detect ADODB URI, automatically translate PDO DSN
|
||||
|
||||
/*
|
||||
@ -289,13 +309,22 @@ class Database {
|
||||
if(preg_match("/password=([^;]*)/", DATABASE_DSN, $matches)) $db_pass=$matches[1];
|
||||
|
||||
$db_params = array(
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
PDO::ATTR_PERSISTENT => DATABASE_KA,
|
||||
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);
|
||||
$this->connect_engine();
|
||||
$this->engine->init($this->db);
|
||||
|
||||
$this->db->beginTransaction();
|
||||
}
|
||||
|
||||
private function connect_engine() {
|
||||
if(preg_match("/^([^:]*)/", DATABASE_DSN, $matches)) $db_proto=$matches[1];
|
||||
else throw new SCoreException("Can't figure out database engine");
|
||||
|
||||
if($db_proto === "mysql") {
|
||||
$this->engine = new MySQL();
|
||||
}
|
||||
@ -308,21 +337,29 @@ class Database {
|
||||
else {
|
||||
die('Unknown PDO driver: '.$db_proto);
|
||||
}
|
||||
}
|
||||
|
||||
$matches = array();
|
||||
if( defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) {
|
||||
if($matches[1] == "memcache") {
|
||||
$this->cache = new MemcacheCache($matches[2]);
|
||||
}
|
||||
else if($matches[1] == "apc") {
|
||||
$this->cache = new APCCache($matches[2]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->cache = new NoCache();
|
||||
}
|
||||
public function commit() {
|
||||
if(!is_null($this->db)) return $this->db->commit();
|
||||
}
|
||||
|
||||
$this->engine->init($this->db);
|
||||
public function rollback() {
|
||||
if(!is_null($this->db)) return $this->db->rollback();
|
||||
}
|
||||
|
||||
public function escape($input) {
|
||||
if(is_null($this->db)) $this->connect_db();
|
||||
return $this->db->Quote($input);
|
||||
}
|
||||
|
||||
public function scoreql_to_sql($input) {
|
||||
if(is_null($this->engine)) $this->connect_engine();
|
||||
return $this->engine->scoreql_to_sql($input);
|
||||
}
|
||||
|
||||
public function get_driver_name() {
|
||||
if(is_null($this->engine)) $this->connect_engine();
|
||||
return $this->engine->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,6 +367,7 @@ class Database {
|
||||
*/
|
||||
public function execute($query, $args=array()) {
|
||||
try {
|
||||
if(is_null($this->db)) $this->connect_db();
|
||||
_count_execs($this->db, $query, $args);
|
||||
$stmt = $this->db->prepare($query);
|
||||
if (!array_key_exists(0, $args)) {
|
||||
|
@ -149,7 +149,6 @@ class Image {
|
||||
assert(is_array($tags));
|
||||
global $database;
|
||||
if(count($tags) == 0) {
|
||||
#return $database->get_one("SELECT COUNT(*) FROM images");
|
||||
$total = $database->cache->get("image-count");
|
||||
if(!$total) {
|
||||
$total = $database->get_one("SELECT COUNT(*) FROM images");
|
||||
@ -160,7 +159,7 @@ class Image {
|
||||
else if(count($tags) == 1 && !preg_match("/[:=><]/", $tags[0])) {
|
||||
$term = Tag::resolve_alias($tags[0]);
|
||||
return $database->get_one(
|
||||
$database->engine->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
|
||||
$database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
|
||||
array("tag"=>$term));
|
||||
}
|
||||
else {
|
||||
@ -432,7 +431,7 @@ class Image {
|
||||
public function set_locked($tf) {
|
||||
global $database;
|
||||
$ln = $tf ? "Y" : "N";
|
||||
$sln = $database->engine->scoreql_to_sql('SCORE_BOOL_'.$ln);
|
||||
$sln = $database->scoreql_to_sql('SCORE_BOOL_'.$ln);
|
||||
$sln = str_replace("'", "", $sln);
|
||||
$sln = str_replace('"', "", $sln);
|
||||
if(bool_escape($sln) !== $this->locked) {
|
||||
@ -472,7 +471,7 @@ class Image {
|
||||
// insert each new tags
|
||||
foreach($tags as $tag) {
|
||||
$id = $database->get_one(
|
||||
$database->engine->scoreql_to_sql(
|
||||
$database->scoreql_to_sql(
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array("tag"=>$tag));
|
||||
@ -493,7 +492,7 @@ class Image {
|
||||
array("iid"=>$this->id, "tid"=>$id));
|
||||
}
|
||||
$database->execute(
|
||||
$database->engine->scoreql_to_sql(
|
||||
$database->scoreql_to_sql(
|
||||
"UPDATE tags SET count = count + 1 WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array("tag"=>$tag));
|
||||
@ -602,7 +601,7 @@ class Image {
|
||||
private static function build_search_querylet($terms) {
|
||||
assert(is_array($terms));
|
||||
global $database;
|
||||
if($database->engine->name === "mysql")
|
||||
if($database->get_driver_name() === "mysql")
|
||||
return Image::build_ugly_search_querylet($terms);
|
||||
else
|
||||
return Image::build_accurate_search_querylet($terms);
|
||||
@ -704,7 +703,7 @@ class Image {
|
||||
|
||||
// one positive tag (a common case), do an optimised search
|
||||
else if(count($tag_querylets) == 1 && $tag_querylets[0]->positive) {
|
||||
$query = new Querylet($database->engine->scoreql_to_sql("
|
||||
$query = new Querylet($database->scoreql_to_sql("
|
||||
SELECT images.* FROM images
|
||||
JOIN image_tags ON images.id=image_tags.image_id
|
||||
JOIN tags ON image_tags.tag_id=tags.id
|
||||
@ -725,7 +724,7 @@ class Image {
|
||||
|
||||
foreach($tag_querylets as $tq) {
|
||||
$tag_ids = $database->get_col(
|
||||
$database->engine->scoreql_to_sql(
|
||||
$database->scoreql_to_sql(
|
||||
"SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"
|
||||
),
|
||||
array("tag"=>$tq->tag));
|
||||
@ -1015,7 +1014,7 @@ class Tag {
|
||||
|
||||
global $database;
|
||||
$newtag = $database->get_one(
|
||||
$database->engine->scoreql_to_sql("SELECT newtag FROM aliases WHERE SCORE_STRNORM(oldtag)=SCORE_STRNORM(:tag)"),
|
||||
$database->scoreql_to_sql("SELECT newtag FROM aliases WHERE SCORE_STRNORM(oldtag)=SCORE_STRNORM(:tag)"),
|
||||
array("tag"=>$tag));
|
||||
if(!empty($newtag)) {
|
||||
return $newtag;
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
function _d($name, $value) {if(!defined($name)) define($name, $value);}
|
||||
_d("DATABASE_DSN", null); // string PDO database connection details
|
||||
_d("DATABASE_KA", true); // string Keep database connection alive
|
||||
_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
|
||||
|
@ -43,13 +43,17 @@ class User {
|
||||
|
||||
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";
|
||||
$row = $database->cache->get("user-session-$name-$session");
|
||||
if(!$row) {
|
||||
if($database->get_driver_name() === "mysql") {
|
||||
$query = "SELECT * FROM users WHERE name = :name AND md5(concat(pass, :ip)) = :sess";
|
||||
}
|
||||
else {
|
||||
$query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess";
|
||||
}
|
||||
$row = $database->get_row($query, array("name"=>$name, "ip"=>get_session_ip($config), "sess"=>$session));
|
||||
$database->cache->set("user-session-$name-$session", $row, 600);
|
||||
}
|
||||
else {
|
||||
$query = "SELECT * FROM users WHERE name = :name AND md5(pass || :ip) = :sess";
|
||||
}
|
||||
$row = $database->get_row($query, array("name"=>$name, "ip"=>get_session_ip($config), "sess"=>$session));
|
||||
return is_null($row) ? null : new User($row);
|
||||
}
|
||||
|
||||
@ -61,7 +65,7 @@ class User {
|
||||
if($cached) return new User($cached);
|
||||
}
|
||||
$row = $database->get_row("SELECT * FROM users WHERE id = :id", array("id"=>$id));
|
||||
if($id === 1) $database->cache->set('user-id:'.$id, $row, 300);
|
||||
if($id === 1) $database->cache->set('user-id:'.$id, $row, 600);
|
||||
return is_null($row) ? null : new User($row);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ function url_escape($input) {
|
||||
*/
|
||||
function sql_escape($input) {
|
||||
global $database;
|
||||
return $database->db->Quote($input);
|
||||
return $database->escape($input);
|
||||
}
|
||||
|
||||
|
||||
@ -285,7 +285,7 @@ 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(basename($_SERVER["SCRIPT_FILENAME"]), "", $full);
|
||||
$base = str_replace('/'.basename($_SERVER["SCRIPT_FILENAME"]), "", $full);
|
||||
}
|
||||
else {
|
||||
$base = "./".basename($_SERVER["SCRIPT_FILENAME"])."?q=";
|
||||
@ -552,6 +552,8 @@ function is_cli() {
|
||||
return (PHP_SAPI === 'cli');
|
||||
}
|
||||
|
||||
|
||||
$_execs = 0;
|
||||
/**
|
||||
* $db is the connection object
|
||||
*
|
||||
|
@ -34,7 +34,11 @@ class Blocks extends Extension {
|
||||
public function onPageRequest(PageRequestEvent $event) {
|
||||
global $config, $database, $page, $user;
|
||||
|
||||
$blocks = $database->get_all("SELECT * FROM blocks");
|
||||
$blocks = $database->cache->get("blocks");
|
||||
if($blocks === false) {
|
||||
$blocks = $database->get_all("SELECT * FROM blocks");
|
||||
$database->cache->set("blocks", $blocks, 600);
|
||||
}
|
||||
foreach($blocks as $block) {
|
||||
if(fnmatch($block['pages'], implode("/", $event->args))) {
|
||||
$page->add_block(new Block($block['title'], $block['content'], $block['area'], $block['priority']));
|
||||
@ -49,6 +53,7 @@ class Blocks extends Extension {
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
", array($_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content']));
|
||||
log_info("blocks", "Added Block #".($database->get_last_insert_id('blocks_id_seq'))." (".$_POST['title'].")");
|
||||
$database->cache->delete("blocks");
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link("blocks/list"));
|
||||
}
|
||||
@ -69,6 +74,7 @@ class Blocks extends Extension {
|
||||
", array($_POST['pages'], $_POST['title'], $_POST['area'], (int)$_POST['priority'], $_POST['content'], $_POST['id']));
|
||||
log_info("blocks", "Updated Block #".$_POST['id']." (".$_POST['title'].")");
|
||||
}
|
||||
$database->cache->delete("blocks");
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link("blocks/list"));
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class CommentList extends Extension {
|
||||
// the whole history
|
||||
if($config->get_int("ext_comments_version") < 1) {
|
||||
$database->create_table("comments", "
|
||||
id {$database->engine->auto_increment},
|
||||
id SCORE_AIPK,
|
||||
image_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL,
|
||||
owner_ip CHAR(16) NOT NULL,
|
||||
@ -390,12 +390,12 @@ class CommentList extends Extension {
|
||||
global $database;
|
||||
|
||||
// sqlite fails at intervals
|
||||
if($database->engine->name === "sqlite") return false;
|
||||
if($database->get_driver_name() === "sqlite") return false;
|
||||
|
||||
$window = int_escape($config->get_int('comment_window'));
|
||||
$max = int_escape($config->get_int('comment_limit'));
|
||||
|
||||
if($database->engine->name == "mysql") $window_sql = "interval $window minute";
|
||||
if($database->get_driver_name() == "mysql") $window_sql = "interval $window minute";
|
||||
else $window_sql = "interval '$window minute'";
|
||||
|
||||
// window doesn't work as an SQL param because it's inside quotes >_<
|
||||
|
@ -44,7 +44,7 @@ class ET extends Extension {
|
||||
$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_db'] = $database->get_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("./"));
|
||||
|
@ -60,10 +60,13 @@ class Featured extends Extension {
|
||||
global $config, $database, $page, $user;
|
||||
$fid = $config->get_int("featured_id");
|
||||
if($fid > 0) {
|
||||
$image = $database->cache->get("featured_image_object");
|
||||
if(empty($image)) {
|
||||
$image = $database->cache->get("featured_image_object-$fid");
|
||||
if($image === false) {
|
||||
$image = Image::by_id($fid);
|
||||
$database->cache->set("featured_image_object", $image, 60);
|
||||
if($image) { // make sure the object is fully populated before saving
|
||||
$image->get_tag_array();
|
||||
}
|
||||
$database->cache->set("featured_image_object-$fid", $image, 600);
|
||||
}
|
||||
if(!is_null($image)) {
|
||||
if(class_exists("Ratings")) {
|
||||
|
@ -116,6 +116,10 @@ class PixelFileHandler extends DataHandlerExtension {
|
||||
|
||||
log_debug('handle_pixel', "Generating thumnail with command `$cmd`, returns $ret");
|
||||
|
||||
if($config->get_bool("thumb_optim", false)) {
|
||||
exec("jpegoptim $outname", $output, $ret);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// }}}
|
||||
|
@ -155,7 +155,7 @@ class ImageBan extends Extension {
|
||||
$args[] = "%".$_GET['reason']."%";
|
||||
}
|
||||
$where = implode(" AND ", $where);
|
||||
$bans = $database->get_all($database->engine->scoreql_to_sql("
|
||||
$bans = $database->get_all($database->scoreql_to_sql("
|
||||
SELECT *
|
||||
FROM image_bans
|
||||
WHERE $where
|
||||
|
@ -158,7 +158,16 @@ class Index extends Extension {
|
||||
$page_size = $event->get_page_size();
|
||||
try {
|
||||
$total_pages = Image::count_pages($search_terms);
|
||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||
if(SPEED_HAX && count($search_terms) == 0 && ($page_number < 10)) { // extra caching for the first few post/list pages
|
||||
$images = $database->cache->get("post-list-$page_number");
|
||||
if(!$images) {
|
||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||
$database->cache->set("post-list-$page_number", $images, 600);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms);
|
||||
}
|
||||
}
|
||||
catch(SearchTermParseException $stpe) {
|
||||
// FIXME: display the error somewhere
|
||||
@ -194,6 +203,24 @@ class Index extends Extension {
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onImageAddition(ImageAdditionEvent $event) {
|
||||
global $database;
|
||||
if(SPEED_HAX) {
|
||||
for($i=1; $i<10; $i++) {
|
||||
$database->cache->delete("post-list-$i");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onImageDeletion(ImageDeletionEvent $event) {
|
||||
global $database;
|
||||
if(SPEED_HAX) {
|
||||
for($i=1; $i<10; $i++) {
|
||||
$database->cache->delete("post-list-$i");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function onSearchTermParse(SearchTermParseEvent $event) {
|
||||
$matches = array();
|
||||
// check for tags first as tag based searches are more common.
|
||||
|
@ -197,7 +197,7 @@ class IPBan extends Extension {
|
||||
private function block(/*string*/ $remote) {
|
||||
global $config, $database;
|
||||
|
||||
$prefix = ($database->engine->name == "sqlite" ? "bans." : "");
|
||||
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
|
||||
|
||||
$bans = $this->get_active_bans();
|
||||
|
||||
|
@ -15,8 +15,8 @@ class IPBanTheme extends Themelet {
|
||||
global $database, $user;
|
||||
$h_bans = "";
|
||||
$n = 0;
|
||||
$prefix = ($database->engine->name == "sqlite" ? "bans." : "");
|
||||
$prefix2 = ($database->engine->name == "sqlite" ? "users." : "");
|
||||
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
|
||||
$prefix2 = ($database->get_driver_name() == "sqlite" ? "users." : "");
|
||||
foreach($bans as $ban) {
|
||||
$end_human = date('Y-m-d', $ban[$prefix.'end_timestamp']);
|
||||
$h_bans .= "
|
||||
|
@ -11,7 +11,7 @@
|
||||
class LiveFeed extends Extension {
|
||||
public function onSetupBuilding(SetupBuildingEvent $event) {
|
||||
$sb = new SetupBlock("Live Feed");
|
||||
$sb->add_string_option("IP/port to send events to");
|
||||
$sb->add_text_option("livefeed_host", "IP:port to send events to: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
@ -20,13 +20,24 @@ class LiveFeed extends Extension {
|
||||
}
|
||||
|
||||
public function onImageAddition($event) {
|
||||
$this->msg("Image posted: ".make_http(make_link("post/view/".$event->image->id)));
|
||||
#$this->msg("- tagged ".$event->image->get_tag_list());
|
||||
$this->msg(
|
||||
make_http(make_link("post/view/".$event->image->id))." - ".
|
||||
"new post by ".$event->user->name
|
||||
);
|
||||
}
|
||||
|
||||
public function onTagSet($event) {
|
||||
$this->msg(
|
||||
make_http(make_link("post/view/".$event->image->id))." - ".
|
||||
"tags set to: ".Tag::implode($event->tags)
|
||||
);
|
||||
}
|
||||
|
||||
public function onCommentPosting($event) {
|
||||
$this->msg("Comment posted on ".make_http(make_link("post/view/".$event->image_id))." :");
|
||||
$this->msg("- {$event->user->name}: {$event->comment}");
|
||||
$this->msg(
|
||||
make_http(make_link("post/view/".$event->image_id))." - ".
|
||||
$event->user->name . ": " . str_replace("\n", " ", $event->comment)
|
||||
);
|
||||
}
|
||||
|
||||
public function onImageInfoSet($event) {
|
||||
|
@ -58,7 +58,7 @@ class LogDatabase extends Extension {
|
||||
$args["module"] = $_GET["module"];
|
||||
}
|
||||
if(!empty($_GET["user"])) {
|
||||
if($database->engine->name == "pgsql") {
|
||||
if($database->get_driver_name() == "pgsql") {
|
||||
if(preg_match("#\d+\.\d+\.\d+\.\d+(/\d+)?#", $_GET["user"])) {
|
||||
$wheres[] = "(username = :user1 OR text(address) = :user2)";
|
||||
$args["user1"] = $_GET["user"];
|
||||
|
@ -198,7 +198,7 @@ class PrivMsg extends Extension {
|
||||
WHERE to_id = :to_id
|
||||
AND is_read = :is_read
|
||||
", array("to_id" => $user->id, "is_read" => "N"));
|
||||
$database->cache->set("pm-count-{$user->id}", $count, 60);
|
||||
$database->cache->set("pm-count-{$user->id}", $count, 600);
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
@ -72,11 +72,13 @@ class ReportImage extends Extension {
|
||||
"INSERT INTO image_reports(image_id, reporter_id, reason)
|
||||
VALUES (?, ?, ?)",
|
||||
array($event->image_id, $event->reporter_id, $event->reason));
|
||||
$database->cache->delete("image-report-count");
|
||||
}
|
||||
|
||||
public function onRemoveReportedImage(RemoveReportedImageEvent $event) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id));
|
||||
$database->cache->delete("image-report-count");
|
||||
}
|
||||
|
||||
public function onDisplayingImage(DisplayingImageEvent $event) {
|
||||
@ -99,6 +101,7 @@ class ReportImage extends Extension {
|
||||
public function onImageDeletion(ImageDeletionEvent $event) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM image_reports WHERE image_id = ?", array($event->image->id));
|
||||
$database->cache->delete("image-report-count");
|
||||
}
|
||||
|
||||
protected function install() {
|
||||
@ -152,7 +155,14 @@ class ReportImage extends Extension {
|
||||
|
||||
public function count_reported_images() {
|
||||
global $database;
|
||||
return $database->get_one("SELECT count(*) FROM image_reports");
|
||||
|
||||
$count = $database->cache->get("image-report-count");
|
||||
if(is_null($count) || $count === false) {
|
||||
$count = $database->get_one("SELECT count(*) FROM image_reports");
|
||||
$database->cache->set("image-report-count", $count, 600);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
// ===== Changelog =====
|
||||
|
@ -49,7 +49,7 @@ class RSS_Images extends Extension {
|
||||
$image_url = $image->get_image_link();
|
||||
$posted = date(DATE_RSS, $image->posted_timestamp);
|
||||
$content = html_escape(
|
||||
"<p>" . Themelet::build_thumb_html($image) . "</p>" .
|
||||
"<p>" . $this->theme->build_thumb_html($image) . "</p>" .
|
||||
"<p>Uploaded by " . html_escape($owner->name) . "</p>"
|
||||
);
|
||||
|
||||
|
4
ext/rss_images/theme.php
Normal file
4
ext/rss_images/theme.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
/* needed for access to build_thumb_html */
|
||||
class RSS_ImagesTheme extends Themelet {}
|
||||
?>
|
@ -153,7 +153,7 @@ class TagList extends Extension {
|
||||
|
||||
$tags_min = $this->get_tags_min();
|
||||
|
||||
$tag_data = $database->get_col($database->engine->scoreql_to_sql("
|
||||
$tag_data = $database->get_col($database->scoreql_to_sql("
|
||||
SELECT DISTINCT
|
||||
SCORE_STRNORM(substr(tag, 1, 1))
|
||||
FROM tags
|
||||
@ -192,7 +192,7 @@ class TagList extends Extension {
|
||||
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
|
||||
|
||||
// SHIT: PDO/pgsql has problems using the same named param twice -_-;;
|
||||
$tag_data = $database->get_all($database->engine->scoreql_to_sql("
|
||||
$tag_data = $database->get_all($database->scoreql_to_sql("
|
||||
SELECT
|
||||
tag,
|
||||
FLOOR(LOG(2.7, LOG(2.7, count - :tags_min2 + 1)+1)*1.5*100)/100 AS scaled
|
||||
@ -228,7 +228,7 @@ class TagList extends Extension {
|
||||
$cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html");
|
||||
if(file_exists($cache_key)) {return file_get_contents($cache_key);}
|
||||
|
||||
$tag_data = $database->get_all($database->engine->scoreql_to_sql("
|
||||
$tag_data = $database->get_all($database->scoreql_to_sql("
|
||||
SELECT tag, count
|
||||
FROM tags
|
||||
WHERE count >= :tags_min
|
||||
@ -390,14 +390,15 @@ class TagList extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
private function add_refine_block(Page $page, /*string*/ $search) {
|
||||
private function add_refine_block(Page $page, /*array(string)*/ $search) {
|
||||
global $database;
|
||||
global $config;
|
||||
|
||||
$related_tags = $database->cache->get("related_tags:$search");
|
||||
$wild_tags = Tag::explode($search);
|
||||
$str_search = Tag::implode($search);
|
||||
$related_tags = $database->cache->get("related_tags:$str_search");
|
||||
|
||||
if(empty($related_tags)) {
|
||||
$wild_tags = Tag::explode($search);
|
||||
// $search_tags = array();
|
||||
|
||||
$tag_id_array = array();
|
||||
@ -434,7 +435,7 @@ class TagList extends Extension {
|
||||
$args = array("limit"=>$config->get_int('tag_list_length'));
|
||||
|
||||
$related_tags = $database->get_all($query, $args);
|
||||
$database->cache->set("related_tags:$search", $related_tags, 60*60);
|
||||
$database->cache->set("related_tags:$str_search", $related_tags, 60*60);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,9 @@ class TagListTheme extends Themelet {
|
||||
$page->add_block(new Block("Refine Search", $html, "left", 60));
|
||||
}
|
||||
|
||||
protected function ars($tag, $tags) {
|
||||
protected function ars(/*string*/ $tag, /*array(string)*/ $tags) {
|
||||
assert(is_array($tags));
|
||||
|
||||
// FIXME: a better fix would be to make sure the inputs are correct
|
||||
$tag = strtolower($tag);
|
||||
$tags = array_map("strtolower", $tags);
|
||||
|
@ -28,7 +28,7 @@ class Upgrade extends Extension {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 8);
|
||||
|
||||
$database->execute($database->engine->scoreql_to_sql(
|
||||
$database->execute($database->scoreql_to_sql(
|
||||
"ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
|
||||
));
|
||||
|
||||
@ -40,7 +40,7 @@ class Upgrade extends Extension {
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 9);
|
||||
|
||||
if($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
|
||||
if($database->get_driver_name() == 'mysql') {
|
||||
$tables = $database->get_col("SHOW TABLES");
|
||||
foreach($tables as $table) {
|
||||
log_info("upgrade", "converting $table to innodb");
|
||||
|
@ -75,7 +75,6 @@ try {
|
||||
ctx_log_start("Connecting to DB");
|
||||
// connect to the database
|
||||
$database = new Database();
|
||||
$database->db->beginTransaction();
|
||||
$config = new DatabaseConfig($database);
|
||||
ctx_log_endok();
|
||||
|
||||
@ -102,11 +101,11 @@ try {
|
||||
|
||||
// saving cache data and profiling data to disk can happen later
|
||||
if(function_exists("fastcgi_finish_request")) fastcgi_finish_request();
|
||||
$database->db->commit();
|
||||
$database->commit();
|
||||
ctx_log_endok();
|
||||
}
|
||||
catch(Exception $e) {
|
||||
if($database && $database->db) $database->db->rollback();
|
||||
if($database) $database->rollback();
|
||||
_fatal_error($e);
|
||||
ctx_log_ender();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user