Merge branch 'develop' of git://github.com/shish/shimmie2 into hotfix/downtime_theme_edits

This commit is contained in:
jgen 2014-04-18 20:25:36 -04:00
commit 505a3e5233
101 changed files with 920 additions and 898 deletions

84
.gitignore vendored
View file

@ -3,4 +3,88 @@ data
images images
thumbs thumbs
!lib/images !lib/images
# Created by http://www.gitignore.io
### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
# Icon must ends with two \r.
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
### Linux ###
*~
# KDE directory preferences
.directory
### vim ###
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~ *.un~
Session.vim
.netrwhist
*~
### PhpStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
## File-based project format
*.ipr
*.iws
*.iml
## Additional for IntelliJ
out/
# generated by mpeltonen/sbt-idea plugin
.idea_modules/
# generated by JIRA plugin
atlassian-ide-plugin.xml
# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml

6
.scrutinizer.yml Normal file
View file

@ -0,0 +1,6 @@
imports:
- javascript
- php
filter:
excluded_paths: [lib/*,ext/chatbox/js/jquery.js]

View file

@ -39,19 +39,19 @@ class BaseThemelet {
*/ */
public function build_thumb_html(Image $image) { public function build_thumb_html(Image $image) {
global $config; global $config;
$i_id = (int) $image->id; $i_id = (int) $image->id;
$h_view_link = make_link('post/view/'.$i_id); $h_view_link = make_link('post/view/'.$i_id);
$h_thumb_link = $image->get_thumb_link(); $h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip()); $h_tip = html_escape($image->get_tooltip());
$h_tags = strtolower($image->get_tag_list()); $h_tags = strtolower($image->get_tag_list());
$ext = strtolower($image->ext);
// If the file doesn't support thumbnail generation, show it at max size. $extArr = array_flip(array('swf', 'svg', 'mp4', 'ogv', 'webm', 'flv')); //List of thumbless filetypes
if($ext === 'swf' || $ext === 'svg' || $ext === 'mp4' || $ext === 'ogv' || $ext === 'webm' || $ext === 'flv'){ if(!isset($extArr[$image->ext])){
$tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height'));
}
else{
$tsize = get_thumbnail_size($image->width, $image->height); $tsize = get_thumbnail_size($image->width, $image->height);
}else{
//Use max thumbnail size if using thumbless filetype
$tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height'));
} }
$custom_classes = ""; $custom_classes = "";

View file

@ -181,7 +181,7 @@ class DatabaseConfig extends BaseConfig {
/* /*
* Load the config table from a database * Load the config table from a database
*/ */
public function DatabaseConfig(Database $database) { public function __construct(Database $database) {
$this->database = $database; $this->database = $database;
$cached = $this->database->cache->get("config"); $cached = $this->database->cache->get("config");

View file

@ -5,7 +5,7 @@ class Querylet {
var $sql; var $sql;
var $variables; var $variables;
public function Querylet($sql, $variables=array()) { public function __construct($sql, $variables=array()) {
$this->sql = $sql; $this->sql = $sql;
$this->variables = $variables; $this->variables = $variables;
} }
@ -28,7 +28,7 @@ class TagQuerylet {
var $tag; var $tag;
var $positive; var $positive;
public function TagQuerylet($tag, $positive) { public function __construct($tag, $positive) {
$this->tag = $tag; $this->tag = $tag;
$this->positive = $positive; $this->positive = $positive;
} }
@ -37,7 +37,7 @@ class ImgQuerylet {
var $qlet; var $qlet;
var $positive; var $positive;
public function ImgQuerylet($qlet, $positive) { public function __construct($qlet, $positive) {
$this->qlet = $qlet; $this->qlet = $qlet;
$this->positive = $positive; $this->positive = $positive;
} }
@ -271,11 +271,13 @@ class Database {
/** /**
* Meta info about the database engine * Meta info about the database engine
* @var DBEngine
*/ */
private $engine = null; private $engine = null;
/** /**
* The currently active cache engine * The currently active cache engine
* @var CacheEngine
*/ */
public $cache = null; public $cache = null;
@ -290,7 +292,7 @@ class Database {
* need it. There are some pages where all the data is in cache, so the * need it. There are some pages where all the data is in cache, so the
* DB connection is on-demand. * DB connection is on-demand.
*/ */
public function Database() { public function __construct() {
$this->connect_cache(); $this->connect_cache();
} }

View file

@ -140,9 +140,9 @@ abstract class FormatterExtension extends Extension {
*/ */
abstract class DataHandlerExtension extends Extension { abstract class DataHandlerExtension extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
global $user; $supported_ext = $this->supported_ext($event->type);
$check_contents = $this->check_contents($event->tmpname);
if(($supported_ext = $this->supported_ext($event->type)) && ($check_contents = $this->check_contents($event->tmpname))) { if($supported_ext && $check_contents) {
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); send_event(new ThumbnailGenerationEvent($event->hash, $event->type));

View file

@ -49,7 +49,7 @@ class Image {
* One will very rarely construct an image directly, more common * One will very rarely construct an image directly, more common
* would be to use Image::by_id, Image::by_hash, etc * would be to use Image::by_id, Image::by_hash, etc
*/ */
public function Image($row=null) { public function __construct($row=null) {
if(!is_null($row)) { if(!is_null($row)) {
foreach($row as $name => $value) { foreach($row as $name => $value) {
// some databases use table.name rather than name // some databases use table.name rather than name
@ -73,7 +73,6 @@ class Image {
public static function by_id(/*int*/ $id) { public static function by_id(/*int*/ $id) {
assert(is_numeric($id)); assert(is_numeric($id));
global $database; global $database;
$image = null;
$row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id)); $row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
@ -86,7 +85,6 @@ class Image {
public static function by_hash(/*string*/ $hash) { public static function by_hash(/*string*/ $hash) {
assert(is_string($hash)); assert(is_string($hash));
global $database; global $database;
$image = null;
$row = $database->get_row("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash)); $row = $database->get_row("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash));
return ($row ? new Image($row) : null); return ($row ? new Image($row) : null);
} }
@ -124,12 +122,12 @@ class Image {
if(SPEED_HAX) { if(SPEED_HAX) {
if(!$user->can("big_search") and count($tags) > 3) { if(!$user->can("big_search") and count($tags) > 3) {
die("Anonymous users may only search for up to 3 tags at a time"); // FIXME: throw an exception? throw new SCoreException("Anonymous users may only search for up to 3 tags at a time");
} }
} }
$querylet = Image::build_search_querylet($tags); $querylet = Image::build_search_querylet($tags);
$querylet->append(new Querylet(" ORDER BY images.".($order_sql ?: $config->get_string("index_order")))); $querylet->append(new Querylet(" ORDER BY ".($order_sql ?: "images.".$config->get_string("index_order"))));
$querylet->append(new Querylet(" LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start))); $querylet->append(new Querylet(" LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start)));
#var_dump($querylet->sql); var_dump($querylet->variables); #var_dump($querylet->sql); var_dump($querylet->variables);
$result = $database->execute($querylet->sql, $querylet->variables); $result = $database->execute($querylet->sql, $querylet->variables);
@ -646,7 +644,7 @@ class Image {
* images table. Yes, MySQL does suck this much. * images table. Yes, MySQL does suck this much.
*/ */
private static function build_accurate_search_querylet($terms) { private static function build_accurate_search_querylet($terms) {
global $config, $database; global $database;
$tag_querylets = array(); $tag_querylets = array();
$img_querylets = array(); $img_querylets = array();
@ -806,7 +804,7 @@ class Image {
* build_accurate_search_querylet() for a full explanation * build_accurate_search_querylet() for a full explanation
*/ */
private static function build_ugly_search_querylet($terms) { private static function build_ugly_search_querylet($terms) {
global $config, $database; global $database;
$tag_querylets = array(); $tag_querylets = array();
$img_querylets = array(); $img_querylets = array();
@ -912,9 +910,6 @@ class Image {
// more than one positive tag, or more than zero negative tags // more than one positive tag, or more than zero negative tags
else { else {
$s_tag_array = array_map("sql_escape", $tag_search->variables);
$s_tag_list = join(', ', $s_tag_array);
$tag_id_array = array(); $tag_id_array = array();
$tags_ok = true; $tags_ok = true;
foreach($tag_search->variables as $tag) { foreach($tag_search->variables as $tag) {
@ -1058,7 +1053,7 @@ class Tag {
else { else {
global $database; global $database;
$db_wild_tag = str_replace("%", "\%", $tag); $db_wild_tag = str_replace("%", "\%", $tag);
$db_wild_tag = str_replace("*", "%", $tag); $db_wild_tag = str_replace("*", "%", $db_wild_tag);
$newtags = $database->get_col($database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), array($db_wild_tag)); $newtags = $database->get_col($database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), array($db_wild_tag));
if(count($newtags) > 0) { if(count($newtags) > 0) {
$resolved = $newtags; $resolved = $newtags;
@ -1116,7 +1111,6 @@ function move_upload_to_archive(DataUploadEvent $event) {
if(!@copy($event->tmpname, $target)) { if(!@copy($event->tmpname, $target)) {
$errors = error_get_last(); // note: requires php 5.2 $errors = error_get_last(); // note: requires php 5.2
throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target): {$errors['type']} / {$errors['message']}"); throw new UploadException("Failed to copy file from uploads ({$event->tmpname}) to archive ($target): {$errors['type']} / {$errors['message']}");
return false;
} }
return true; return true;
} }

View file

@ -15,6 +15,9 @@ class User {
var $name; var $name;
var $email; var $email;
var $join_date; var $join_date;
var $passhash;
/* @var UserClass */
var $class; var $class;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@ -30,7 +33,7 @@ class User {
* One will very rarely construct a user directly, more common * One will very rarely construct a user directly, more common
* would be to use User::by_id, User::by_session, etc * would be to use User::by_id, User::by_session, etc
*/ */
public function User($row) { public function __construct($row) {
global $_user_classes; global $_user_classes;
$this->id = int_escape($row['id']); $this->id = int_escape($row['id']);

View file

@ -385,7 +385,13 @@ function make_http(/*string*/ $link) {
/** /**
* Make a form tag with relevant auth token and stuff * Make a form tag with relevant auth token and stuff
* *
* @retval string * @param target string
* @param method string
* @param multipart boolean
* @param form_id string
* @param onsubmit string
*
* @return string
*/ */
function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") { function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") {
global $user; global $user;
@ -451,7 +457,7 @@ function captcha_get_html() {
} }
else { else {
session_start(); session_start();
$securimg = new Securimage(); //$securimg = new Securimage();
$base = get_base_href(); $base = get_base_href();
$captcha = "<br/><img src='$base/lib/securimage/securimage_show.php?sid=". md5(uniqid(time())) ."'>". $captcha = "<br/><img src='$base/lib/securimage/securimage_show.php?sid=". md5(uniqid(time())) ."'>".
"<br/>CAPTCHA: <input type='text' name='code' value='' />"; "<br/>CAPTCHA: <input type='text' name='code' value='' />";
@ -1276,6 +1282,7 @@ function _sanitise_environment() {
} }
function _get_themelet_files($_theme) { function _get_themelet_files($_theme) {
$base_themelets = array();
if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php'; if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php';
$base_themelets[] = 'themes/'.$_theme.'/layout.class.php'; $base_themelets[] = 'themes/'.$_theme.'/layout.class.php';
$base_themelets[] = 'themes/'.$_theme.'/themelet.class.php'; $base_themelets[] = 'themes/'.$_theme.'/themelet.class.php';
@ -1406,7 +1413,7 @@ function _decaret($str) {
} }
function _get_user() { function _get_user() {
global $config, $database; global $config;
$user = null; $user = null;
if(get_prefixed_cookie("user") && get_prefixed_cookie("session")) { if(get_prefixed_cookie("user") && get_prefixed_cookie("session")) {
$tmp_user = User::by_session(get_prefixed_cookie("user"), get_prefixed_cookie("session")); $tmp_user = User::by_session(get_prefixed_cookie("user"), get_prefixed_cookie("session"));

View file

@ -25,7 +25,7 @@
*/ */
class AdminBuildingEvent extends Event { class AdminBuildingEvent extends Event {
var $page; var $page;
public function AdminBuildingEvent(Page $page) { public function __construct(Page $page) {
$this->page = $page; $this->page = $page;
} }
} }
@ -182,14 +182,18 @@ class AdminPage extends Extension {
case 'sqlite': case 'sqlite':
$cmd = "sqlite3 $database .dump"; $cmd = "sqlite3 $database .dump";
break; break;
default:
$cmd = false;
} }
//FIXME: .SQL dump is empty if cmd doesn't exist //FIXME: .SQL dump is empty if cmd doesn't exist
if($cmd) {
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("application/x-unknown"); $page->set_type("application/x-unknown");
$page->set_filename('shimmie-'.date('Ymd').'.sql'); $page->set_filename('shimmie-'.date('Ymd').'.sql');
$page->set_data(shell_exec($cmd)); $page->set_data(shell_exec($cmd));
}
return false; return false;
} }

View file

@ -14,9 +14,9 @@ class AdminPageTheme extends Themelet {
protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) { protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) {
$c_protected = $protected ? " protected" : ""; $c_protected = $protected ? " protected" : "";
$html = make_form(make_link("admin/$action"), "POST", false, false, false, "admin$c_protected"); $html = make_form(make_link("admin/$action"), "POST", false, null, null, "admin$c_protected");
if($protected) { if($protected) {
$html .= "<input type='submit' id='$action' value='$name' disabled='true'>"; $html .= "<input type='submit' id='$action' value='$name' disabled='disabled'>";
$html .= "<input type='checkbox' onclick='$(\"#$action\").attr(\"disabled\", !$(this).is(\":checked\"))'>"; $html .= "<input type='checkbox' onclick='$(\"#$action\").attr(\"disabled\", !$(this).is(\":checked\"))'>";
} }
else { else {

View file

@ -14,7 +14,7 @@ class AddAliasEvent extends Event {
var $oldtag; var $oldtag;
var $newtag; var $newtag;
public function AddAliasEvent($oldtag, $newtag) { public function __construct($oldtag, $newtag) {
$this->oldtag = trim($oldtag); $this->oldtag = trim($oldtag);
$this->newtag = trim($newtag); $this->newtag = trim($newtag);
} }

View file

@ -29,7 +29,6 @@ class AliasEditorTheme extends Themelet {
} }
$h_aliases = ""; $h_aliases = "";
$n = 0;
foreach($aliases as $old => $new) { foreach($aliases as $old => $new) {
$h_old = html_escape($old); $h_old = html_escape($old);
$h_new = "<a href='".make_link("post/list/".url_escape($new)."/1")."'>".html_escape($new)."</a>"; $h_new = "<a href='".make_link("post/list/".url_escape($new)."/1")."'>".html_escape($new)."</a>";

View file

@ -11,7 +11,7 @@
class AuthorSetEvent extends Event { class AuthorSetEvent extends Event {
var $image, $user, $author; var $image, $user, $author;
public function AuthorSetEvent(Image $image, User $user, /*string*/ $author) public function __construct(Image $image, User $user, /*string*/ $author)
{ {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
@ -59,8 +59,8 @@ class Artists extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
created DATETIME NOT NULL, created SCORE_DATETIME NOT NULL,
updated DATETIME NOT NULL, updated SCORE_DATETIME NOT NULL,
notes TEXT, notes TEXT,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
"); ");
@ -70,8 +70,8 @@ class Artists extends Extension {
artist_id INTEGER NOT NULL, artist_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
created DATETIME NOT NULL, created SCORE_DATETIME NOT NULL,
updated DATETIME NOT NULL, updated SCORE_DATETIME NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE
"); ");
@ -79,8 +79,8 @@ class Artists extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
artist_id INTEGER NOT NULL, artist_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
created DATETIME, created SCORE_DATETIME,
updated DATETIME, updated SCORE_DATETIME,
alias VARCHAR(255), alias VARCHAR(255),
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE
@ -89,8 +89,8 @@ class Artists extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
artist_id INTEGER NOT NULL, artist_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
created DATETIME NOT NULL, created SCORE_DATETIME NOT NULL,
updated DATETIME NOT NULL, updated SCORE_DATETIME NOT NULL,
url VARCHAR(1000) NOT NULL, url VARCHAR(1000) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (artist_id) REFERENCES artists (id) ON UPDATE CASCADE ON DELETE CASCADE
@ -143,7 +143,7 @@ class Artists extends Extension {
} }
public function handle_commands($event) public function handle_commands($event)
{ {
global $config, $page, $user; global $page, $user;
if($event->page_matches("artist")) if($event->page_matches("artist"))
{ {

View file

@ -14,18 +14,10 @@ class ArtistsTheme extends Themelet {
"; ";
} }
public function display_artists(){
global $page;
$page->set_title("Artists");
$page->set_heading("Artists");
$page->add_block(new Block("Artists", $html, "main", 10));
//$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages);
}
public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE){ public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE){
global $page; global $page, $user;
$html = "";
if($mode == "neutral"){ if($mode == "neutral"){
$html = "<form method='post' action='".make_link("artist/new_artist")."'> $html = "<form method='post' action='".make_link("artist/new_artist")."'>
@ -72,11 +64,14 @@ class ArtistsTheme extends Themelet {
<input type='hidden' name='artist_id' value='".$artistID."'> <input type='hidden' name='artist_id' value='".$artistID."'>
</form>"; </form>";
} }
$page->add_block(new Block("Manage Artists", $html, "left", 10));
if($html) $page->add_block(new Block("Manage Artists", $html, "left", 10));
} }
public function show_artist_editor($artist, $aliases, $members, $urls) public function show_artist_editor($artist, $aliases, $members, $urls)
{ {
global $user;
$artistName = $artist['name']; $artistName = $artist['name'];
$artistNotes = $artist['notes']; $artistNotes = $artist['notes'];
$artistID = $artist['id']; $artistID = $artist['id'];
@ -140,7 +135,7 @@ class ArtistsTheme extends Themelet {
public function new_artist_composer() public function new_artist_composer()
{ {
global $page; global $page, $user;
$html = "<form action=".make_link("artist/create")." method='POST'> $html = "<form action=".make_link("artist/create")." method='POST'>
".$user->get_auth_html()." ".$user->get_auth_html()."
@ -175,7 +170,6 @@ class ArtistsTheme extends Themelet {
$html .= "</tr></thead>"; $html .= "</tr></thead>";
$n = 0;
$deletionLinkActionArray = $deletionLinkActionArray =
array('artist' => 'artist/nuke/' array('artist' => 'artist/nuke/'
, 'alias' => 'artist/alias/delete/' , 'alias' => 'artist/alias/delete/'
@ -199,7 +193,7 @@ class ArtistsTheme extends Themelet {
$artist['name'] = str_replace("_", " ", $artist['name']); $artist['name'] = str_replace("_", " ", $artist['name']);
$elementLink = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['name'])."</a>"; $elementLink = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['name'])."</a>";
$artist_link = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['artist_name'])."</a>"; //$artist_link = "<a href='".make_link("artist/view/".$artist['artist_id'])."'>".str_replace("_", " ", $artist['artist_name'])."</a>";
$user_link = "<a href='".make_link("user/".$artist['user_name'])."'>".$artist['user_name']."</a>"; $user_link = "<a href='".make_link("user/".$artist['user_name'])."'>".$artist['user_name']."</a>";
$edit_link = "<a href='".make_link($editionLinkActionArray[$artist['type']].$artist['id'])."'>Edit</a>"; $edit_link = "<a href='".make_link($editionLinkActionArray[$artist['type']].$artist['id'])."'>Edit</a>";
$del_link = "<a href='".make_link($deletionLinkActionArray[$artist['type']].$artist['id'])."'>Delete</a>"; $del_link = "<a href='".make_link($deletionLinkActionArray[$artist['type']].$artist['id'])."'>Delete</a>";
@ -235,6 +229,8 @@ class ArtistsTheme extends Themelet {
public function show_new_alias_composer($artistID) public function show_new_alias_composer($artistID)
{ {
global $user;
$html = $html =
'<form method="POST" action='.make_link("artist/alias/add").'> '<form method="POST" action='.make_link("artist/alias/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
@ -251,6 +247,8 @@ class ArtistsTheme extends Themelet {
} }
public function show_new_member_composer($artistID) public function show_new_member_composer($artistID)
{ {
global $user;
$html = $html =
' <form method="POST" action='.make_link("artist/member/add").'> ' <form method="POST" action='.make_link("artist/member/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
@ -268,6 +266,8 @@ class ArtistsTheme extends Themelet {
public function show_new_url_composer($artistID) public function show_new_url_composer($artistID)
{ {
global $user;
$html = $html =
' <form method="POST" action='.make_link("artist/url/add").'> ' <form method="POST" action='.make_link("artist/url/add").'>
'.$user->get_auth_html().' '.$user->get_auth_html().'
@ -285,6 +285,8 @@ class ArtistsTheme extends Themelet {
public function show_alias_editor($alias) public function show_alias_editor($alias)
{ {
global $user;
$html = $html =
' '
<form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'"> <form method="POST" action="'.make_link("artist/alias/edited/".$alias['id']).'">
@ -302,6 +304,8 @@ class ArtistsTheme extends Themelet {
public function show_url_editor($url) public function show_url_editor($url)
{ {
global $user;
$html = $html =
' '
<form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'"> <form method="POST" action="'.make_link("artist/url/edited/".$url['id']).'">
@ -319,6 +323,8 @@ class ArtistsTheme extends Themelet {
public function show_member_editor($member) public function show_member_editor($member)
{ {
global $user;
$html = $html =
' '
<form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'"> <form method="POST" action="'.make_link("artist/member/edited/".$member['id']).'">
@ -336,12 +342,10 @@ class ArtistsTheme extends Themelet {
public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin) public function show_artist($artist, $aliases, $members, $urls, $images, $userIsLogged, $userIsAdmin)
{ {
global $user, $event, $page; global $page;
$artist_link = "<a href='".make_link("post/list/".$artist['name']."/1")."'>".str_replace("_", " ", $artist['name'])."</a>"; $artist_link = "<a href='".make_link("post/list/".$artist['name']."/1")."'>".str_replace("_", " ", $artist['name'])."</a>";
$n = 0;
$html = "<table id='poolsList' class='zebra'> $html = "<table id='poolsList' class='zebra'>
<thead> <thead>
<tr> <tr>
@ -495,7 +499,6 @@ class ArtistsTheme extends Themelet {
$page->set_heading("Artist"); $page->set_heading("Artist");
$page->add_block(new Block("Artist", $html, "main", 10)); $page->add_block(new Block("Artist", $html, "main", 10));
//we show the images for the artist //we show the images for the artist
$artist_images = ""; $artist_images = "";
foreach($images as $image) { foreach($images as $image) {

View file

@ -31,7 +31,6 @@ class BlotterTheme extends Themelet {
* Long function name, but at least I won't confuse it with something else ^_^ * Long function name, but at least I won't confuse it with something else ^_^
*/ */
$html = "";
// Add_new stuff goes here. // Add_new stuff goes here.
$table_header = " $table_header = "
<tr> <tr>
@ -134,7 +133,7 @@ class BlotterTheme extends Themelet {
// Reset variables: // Reset variables:
$i_open = ""; $i_open = "";
$i_close = ""; $i_close = "";
$id = $entries[$i]['id']; //$id = $entries[$i]['id'];
$messy_date = $entries[$i]['entry_date']; $messy_date = $entries[$i]['entry_date'];
$clean_date = date("m/d/y", strtotime($messy_date)); $clean_date = date("m/d/y", strtotime($messy_date));
$entry_text = $entries[$i]['entry_text']; $entry_text = $entries[$i]['entry_text'];
@ -145,8 +144,6 @@ class BlotterTheme extends Themelet {
$entries_list .= "<li>{$i_open}{$clean_date} - {$entry_text}{$i_close}</li>"; $entries_list .= "<li>{$i_open}{$clean_date} - {$entry_text}{$i_close}</li>";
} }
$out_text = "";
$in_text = "";
$pos_break = ""; $pos_break = "";
$pos_align = "text-align: right; position: absolute; right: 0px;"; $pos_align = "text-align: right; position: absolute; right: 0px;";

View file

@ -53,6 +53,7 @@ class BulkAdd extends Extension {
if(!array_key_exists('extension', $pathinfo)) { if(!array_key_exists('extension', $pathinfo)) {
throw new UploadException("File has no extension"); throw new UploadException("File has no extension");
} }
$metadata = array();
$metadata['filename'] = $pathinfo['basename']; $metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension']; $metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags; $metadata['tags'] = $tags;
@ -65,8 +66,6 @@ class BulkAdd extends Extension {
} }
private function add_dir(/*string*/ $base, $subdir="") { private function add_dir(/*string*/ $base, $subdir="") {
global $page;
if(!is_dir($base)) { if(!is_dir($base)) {
$this->theme->add_status("Error", "$base is not a directory"); $this->theme->add_status("Error", "$base is not a directory");
return; return;

View file

@ -62,6 +62,7 @@ class BulkAddCSV extends Extension {
if(!array_key_exists('extension', $pathinfo)) { if(!array_key_exists('extension', $pathinfo)) {
throw new UploadException("File has no extension"); throw new UploadException("File has no extension");
} }
$metadata = array();
$metadata['filename'] = $pathinfo['basename']; $metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension']; $metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags; $metadata['tags'] = $tags;
@ -82,8 +83,6 @@ class BulkAddCSV extends Extension {
} }
private function add_csv(/*string*/ $csvfile) { private function add_csv(/*string*/ $csvfile) {
global $page;
if(!file_exists($csvfile)) { if(!file_exists($csvfile)) {
$this->theme->add_status("Error", "$csvfile not found"); $this->theme->add_status("Error", "$csvfile not found");
return; return;

View file

@ -12,7 +12,7 @@
class BulkRemove extends Extension { class BulkRemove extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $user;
if($event->page_matches("bulk_remove") && $user->is_admin() && $user->check_auth_token()) { if($event->page_matches("bulk_remove") && $user->is_admin() && $user->check_auth_token()) {
if ($event->get_arg(0) == "confirm") $this->do_bulk_remove(); if ($event->get_arg(0) == "confirm") $this->do_bulk_remove();
else $this->show_confirm(); else $this->show_confirm();
@ -20,7 +20,7 @@ class BulkRemove extends Extension {
} }
public function onAdminBuilding(AdminBuildingEvent $event) { public function onAdminBuilding(AdminBuildingEvent $event) {
global $page, $user; global $page;
$html = "<b>Be extremely careful when using this!</b><br> $html = "<b>Be extremely careful when using this!</b><br>
Once an image is removed there is no way to recover it so it is recommended that Once an image is removed there is no way to recover it so it is recommended that
you first take when removing a large amount of images.<br> you first take when removing a large amount of images.<br>
@ -83,10 +83,10 @@ class BulkRemove extends Extension {
// if no images were found with the given info // if no images were found with the given info
if (count($images_for_removal) == 0 && $html == "") if (count($images_for_removal) == 0)
$error = "No images selected for removal"; $error = "No images selected for removal";
var_dump($tags_arr); //var_dump($tags_arr);
return array( return array(
"error" => $error, "error" => $error,
"images_for_removal" => $images_for_removal); "images_for_removal" => $images_for_removal);
@ -119,6 +119,7 @@ class BulkRemove extends Extension {
private function do_bulk_remove() private function do_bulk_remove()
{ {
global $page;
// display error if user didn't go through admin board // display error if user didn't go through admin board
if (!isset($_POST["bulk_remove_images"])) { if (!isset($_POST["bulk_remove_images"])) {
$page->add_block(new Block("Bulk Remove Error", $page->add_block(new Block("Bulk Remove Error",

View file

@ -13,7 +13,7 @@ class Chatbox extends Extension {
global $page, $user; global $page, $user;
// Adds header to enable chatbox // Adds header to enable chatbox
$root = make_http(); $root = get_base_href();
$yPath = "$root/ext/chatbox/"; $yPath = "$root/ext/chatbox/";
$page->add_html_header(" $page->add_html_header("
<script src=\"$root/ext/chatbox/js/jquery.js\" type=\"text/javascript\"></script> <script src=\"$root/ext/chatbox/js/jquery.js\" type=\"text/javascript\"></script>

View file

@ -14,7 +14,7 @@ require_once "lib/akismet.class.php";
class CommentPostingEvent extends Event { class CommentPostingEvent extends Event {
var $image_id, $user, $comment; var $image_id, $user, $comment;
public function CommentPostingEvent($image_id, $user, $comment) { public function __construct($image_id, $user, $comment) {
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user = $user; $this->user = $user;
$this->comment = $comment; $this->comment = $comment;
@ -29,7 +29,7 @@ class CommentPostingEvent extends Event {
class CommentDeletionEvent extends Event { class CommentDeletionEvent extends Event {
var $comment_id; var $comment_id;
public function CommentDeletionEvent($comment_id) { public function __construct($comment_id) {
$this->comment_id = $comment_id; $this->comment_id = $comment_id;
} }
} }
@ -37,7 +37,11 @@ class CommentDeletionEvent extends Event {
class CommentPostingException extends SCoreException {} class CommentPostingException extends SCoreException {}
class Comment { class Comment {
public function Comment($row) { var $owner, $owner_id, $owner_name, $owner_email, $owner_class;
var $comment, $comment_id;
var $image_id, $poster_ip, $posted;
public function __construct($row) {
$this->owner = null; $this->owner = null;
$this->owner_id = $row['user_id']; $this->owner_id = $row['user_id'];
$this->owner_name = $row['user_name']; $this->owner_name = $row['user_name'];

View file

@ -244,7 +244,7 @@ class CommentListTheme extends Themelet {
$hb = ($comment->owner_class == "hellbanned" ? "hb" : ""); $hb = ($comment->owner_class == "hellbanned" ? "hb" : "");
if($trim) { if($trim) {
return " $html = "
<div class=\"comment $hb\"> <div class=\"comment $hb\">
$h_userlink: $h_comment $h_userlink: $h_comment
<a href=\"".make_link("post/view/$i_image_id#c$i_comment_id")."\">&gt;&gt;&gt;</a> <a href=\"".make_link("post/view/$i_image_id#c$i_comment_id")."\">&gt;&gt;&gt;</a>
@ -263,7 +263,7 @@ class CommentListTheme extends Themelet {
$h_del = $user->can("delete_comment") ? $h_del = $user->can("delete_comment") ?
' - <a onclick="return confirm(\'Delete comment by '.$h_name.':\\n'.$stripped_nonl.'\');" '. ' - <a onclick="return confirm(\'Delete comment by '.$h_name.':\\n'.$stripped_nonl.'\');" '.
'href="'.make_link('comment/delete/'.$i_comment_id.'/'.$i_image_id).'">Del</a>' : ''; 'href="'.make_link('comment/delete/'.$i_comment_id.'/'.$i_image_id).'">Del</a>' : '';
return " $html = "
<div class=\"comment $hb\" id=\"c$i_comment_id\"> <div class=\"comment $hb\" id=\"c$i_comment_id\">
<div class=\"info\"> <div class=\"info\">
$h_avatar $h_avatar
@ -273,7 +273,7 @@ class CommentListTheme extends Themelet {
</div> </div>
"; ";
} }
return ""; return $html;
} }
protected function build_postbox(/*int*/ $image_id) { protected function build_postbox(/*int*/ $image_id) {

View file

@ -206,7 +206,7 @@ class CronUploader extends Extension {
/** /**
* Returns amount of files & total size of dir. * Returns amount of files & total size of dir.
* @param unknown $path * @param $path string
* @return multitype:number * @return multitype:number
*/ */
function scan_dir($path){ function scan_dir($path){
@ -227,7 +227,7 @@ class CronUploader extends Extension {
/** /**
* Uploads the image & handles everything * Uploads the image & handles everything
* @param number $upload_count to upload a non-config amount of imgs * @param $upload_count int to upload a non-config amount of imgs
* @return boolean returns true if the upload was successful * @return boolean returns true if the upload was successful
*/ */
public function process_upload($upload_count = 0) { public function process_upload($upload_count = 0) {
@ -254,11 +254,11 @@ class CronUploader extends Extension {
try { try {
$this->add_image($img[0], $img[1], $img[2]); $this->add_image($img[0], $img[1], $img[2]);
$newPath = $this->move_uploaded($img[0], $img[1], false); $this->move_uploaded($img[0], $img[1], false);
} }
catch (Exception $e) { catch (Exception $e) {
$newPath = $this->move_uploaded($img[0], $img[1], true); $this->move_uploaded($img[0], $img[1], true);
} }
// Remove img from queue array // Remove img from queue array
@ -295,37 +295,17 @@ class CronUploader extends Extension {
$this->add_upload_info($info . "Image \"$filename\" moved from queue to \"$newPath\"."); $this->add_upload_info($info . "Image \"$filename\" moved from queue to \"$newPath\".");
} }
/**
* moves a directory up or gets the directory of a file
*
* @param string $path Path to modify
* @param int $depth Amount of directories to go up
* @return unknown Path to correct Directory
*/
private function move_directory_up($path, $depth=1)
{
$path = str_replace("//", "/", $path);
$array = explode("/", $path);
for ($i = 0; $i < $depth; $i++) {
$to_remove = count($array) -1; // Gets number of element to remove
unset($array[$to_remove]);
}
return implode("/", $array);
}
/** /**
* Generate the necessary DataUploadEvent for a given image and tags. * Generate the necessary DataUploadEvent for a given image and tags.
*/ */
private function add_image($tmpname, $filename, $tags) { private function add_image($tmpname, $filename, $tags) {
global $user, $image;
assert ( file_exists ( $tmpname ) ); assert ( file_exists ( $tmpname ) );
$pathinfo = pathinfo ( $filename ); $pathinfo = pathinfo ( $filename );
if (! array_key_exists ( 'extension', $pathinfo )) { if (! array_key_exists ( 'extension', $pathinfo )) {
throw new UploadException ( "File has no extension" ); throw new UploadException ( "File has no extension" );
} }
$metadata = array();
$metadata ['filename'] = $pathinfo ['basename']; $metadata ['filename'] = $pathinfo ['basename'];
$metadata ['extension'] = $pathinfo ['extension']; $metadata ['extension'] = $pathinfo ['extension'];
$metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here $metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here
@ -343,12 +323,9 @@ class CronUploader extends Extension {
// Set tags // Set tags
$img = Image::by_id($event->image_id); $img = Image::by_id($event->image_id);
$img->set_tags($tags); $img->set_tags($tags);
} }
private function generate_image_queue($base = "", $subdir = "") { private function generate_image_queue($base = "", $subdir = "") {
global $config;
if ($base == "") if ($base == "")
$base = $this->root_dir . "/queue"; $base = $this->root_dir . "/queue";
@ -391,8 +368,9 @@ class CronUploader extends Extension {
/** /**
* Adds a message to the info being published at the end * Adds a message to the info being published at the end
* @param string $text * @param $text string
* @param int $addon Enter a value to modify an existing value (enter value number) * @param $addon int Enter a value to modify an existing value (enter value number)
* @return int
*/ */
private function add_upload_info($text, $addon = 0) { private function add_upload_info($text, $addon = 0) {
$info = $this->upload_info; $info = $this->upload_info;
@ -409,7 +387,7 @@ class CronUploader extends Extension {
// else if addon function is used, select the line & modify it // else if addon function is used, select the line & modify it
$lines = substr($info, "\n"); // Seperate the string to array in lines $lines = substr($info, "\n"); // Seperate the string to array in lines
$lines[$addon] = "$line[$addon] $text"; // Add the content to the line $lines[$addon] = "$lines[$addon] $text"; // Add the content to the line
$this->upload_info = implode("\n", $lines); // Put string back together & update $this->upload_info = implode("\n", $lines); // Put string back together & update
return $addon; // Return line number return $addon; // Return line number
@ -419,7 +397,7 @@ class CronUploader extends Extension {
* This is run at the end to display & save the log. * This is run at the end to display & save the log.
*/ */
private function handle_log() { private function handle_log() {
global $page, $config; global $page;
// Display message // Display message
$page->set_mode("data"); $page->set_mode("data");

View file

@ -106,9 +106,6 @@ class DanbooruApi extends Extension {
if($user->can("create_image")) if($user->can("create_image"))
{ {
$file = null;
$filename = "";
$source = "";
if(isset($_FILES['file'])) if(isset($_FILES['file']))
{ // A file was POST'd in { // A file was POST'd in
$file = $_FILES['file']['tmp_name']; $file = $_FILES['file']['tmp_name'];

View file

@ -21,8 +21,9 @@ function __extman_extcmp(ExtensionInfo $a, ExtensionInfo $b) {
class ExtensionInfo { class ExtensionInfo {
var $ext_name, $name, $link, $author, $email; var $ext_name, $name, $link, $author, $email;
var $description, $documentation, $version, $visibility; var $description, $documentation, $version, $visibility;
var $enabled;
function ExtensionInfo($main) { function __construct($main) {
$matches = array(); $matches = array();
$lines = file($main); $lines = file($main);
$number_of_lines = count($lines); $number_of_lines = count($lines);
@ -167,6 +168,7 @@ class ExtManager extends Extension {
private function set_things($settings) { private function set_things($settings) {
$core = explode(",", CORE_EXTS); $core = explode(",", CORE_EXTS);
$extras = array();
foreach(glob("ext/*/main.php") as $main) { foreach(glob("ext/*/main.php") as $main) {
$matches = array(); $matches = array();

View file

@ -17,7 +17,6 @@ class ExtManagerTheme extends Themelet {
</thead> </thead>
<tbody> <tbody>
"; ";
$n = 0;
foreach($extensions as $extension) { foreach($extensions as $extension) {
if(!$editable && $extension->visibility == "admin") continue; if(!$editable && $extension->visibility == "admin") continue;
@ -53,7 +52,6 @@ class ExtManagerTheme extends Themelet {
/* /*
public function display_blocks(Page $page, $extensions) { public function display_blocks(Page $page, $extensions) {
global $user; global $user;
$n = 0;
$col_1 = ""; $col_1 = "";
$col_2 = ""; $col_2 = "";
foreach($extensions as $extension) { foreach($extensions as $extension) {

View file

@ -16,7 +16,7 @@
class FavoriteSetEvent extends Event { class FavoriteSetEvent extends Event {
var $image_id, $user, $do_set; var $image_id, $user, $do_set;
public function FavoriteSetEvent(/*int*/ $image_id, User $user, /*boolean*/ $do_set) { public function __construct(/*int*/ $image_id, User $user, /*boolean*/ $do_set) {
assert(is_numeric($image_id)); assert(is_numeric($image_id));
assert(is_bool($do_set)); assert(is_bool($do_set));
@ -35,7 +35,7 @@ class Favorites extends Extension {
} }
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
global $database, $page, $user; global $database, $user;
if(!$user->is_anonymous()) { if(!$user->is_anonymous()) {
$user_id = $user->id; $user_id = $user->id;
$image_id = $event->image->id; $image_id = $event->image->id;
@ -51,7 +51,7 @@ class Favorites extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) { public function onDisplayingImage(DisplayingImageEvent $event) {
$people = $this->list_persons_who_have_favorited($event->image); $people = $this->list_persons_who_have_favorited($event->image);
if(count($people) > 0) { if(count($people) > 0) {
$html = $this->theme->display_people($people); $this->theme->display_people($people);
} }
} }
@ -88,7 +88,7 @@ class Favorites extends Extension {
in_array('favorite_action', $_POST) && in_array('favorite_action', $_POST) &&
(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) (($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset"))
) { ) {
send_event(new FavoriteSetEvent($event->image_id, $user, ($_POST['favorite_action'] == "set"))); send_event(new FavoriteSetEvent($event->image->id, $user, ($_POST['favorite_action'] == "set")));
} }
} }
@ -148,15 +148,13 @@ class Favorites extends Extension {
if($config->get_int("ext_favorites_version") < 1) { if($config->get_int("ext_favorites_version") < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN favorites INTEGER NOT NULL DEFAULT 0"); $database->Execute("ALTER TABLE images ADD COLUMN favorites INTEGER NOT NULL DEFAULT 0");
$database->Execute("CREATE INDEX images__favorites ON images(favorites)"); $database->Execute("CREATE INDEX images__favorites ON images(favorites)");
$database->Execute(" $database->create_table("user_favorites", "
CREATE TABLE user_favorites (
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
created_at DATETIME NOT NULL, created_at SCORE_DATETIME NOT NULL,
UNIQUE(image_id, user_id), UNIQUE(image_id, user_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE
)
"); ");
$database->execute("CREATE INDEX user_favorites_image_id_idx ON user_favorites(image_id)", array()); $database->execute("CREATE INDEX user_favorites_image_id_idx ON user_favorites(image_id)", array());
$config->set_int("ext_favorites_version", 1); $config->set_int("ext_favorites_version", 1);

View file

@ -27,8 +27,8 @@ class Forum extends Extension {
sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, sticky SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
uptodate DATETIME NOT NULL, uptodate SCORE_DATETIME NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT
"); ");
$database->execute("CREATE INDEX forum_threads_date_idx ON forum_threads(date)", array()); $database->execute("CREATE INDEX forum_threads_date_idx ON forum_threads(date)", array());
@ -37,7 +37,7 @@ class Forum extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
thread_id INTEGER NOT NULL, thread_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
message TEXT, message TEXT,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (thread_id) REFERENCES forum_threads (id) ON UPDATE CASCADE ON DELETE CASCADE
@ -330,7 +330,7 @@ class Forum extends Extension {
private function save_new_thread($user) private function save_new_thread($user)
{ {
$title = html_escape($_POST["title"]); $title = html_escape($_POST["title"]);
$sticky = html_escape($_POST["sticky"]); $sticky = !empty($_POST["sticky"]) ? html_escape($_POST["sticky"]) : "N";
if($sticky == ""){ if($sticky == ""){
$sticky = "N"; $sticky = "N";
@ -344,11 +344,11 @@ class Forum extends Extension {
(?, ?, ?, now(), now())", (?, ?, ?, now(), now())",
array($title, $sticky, $user->id)); array($title, $sticky, $user->id));
$result = $database->get_row("SELECT LAST_INSERT_ID() AS threadID", array()); $threadID = $database->get_last_insert_id("forum_threads_id_seq");
log_info("forum", "Thread {$result["threadID"]} created by {$user->name}"); log_info("forum", "Thread {$threadID} created by {$user->name}");
return $result["threadID"]; return $threadID;
} }
private function save_new_post($threadID, $user) private function save_new_post($threadID, $user)
@ -367,9 +367,9 @@ class Forum extends Extension {
(?, ?, now(), ?)" (?, ?, now(), ?)"
, array($threadID, $userID, $message)); , array($threadID, $userID, $message));
$result = $database->get_row("SELECT LAST_INSERT_ID() AS postID", array()); $postID = $database->get_last_insert_id("forum_posts_id_seq");
log_info("forum", "Post {$result["postID"]} created by {$user->name}"); log_info("forum", "Post {$postID} created by {$user->name}");
$database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID));
} }

View file

@ -83,9 +83,7 @@ class ForumTheme extends Themelet {
global $config, $page/*, $user*/; global $config, $page/*, $user*/;
$posts_per_page = $config->get_int('forumPostsPerPage'); $posts_per_page = $config->get_int('forumPostsPerPage');
$theme_name = $config->get_string('theme');
$html = "";
$current_post = 0; $current_post = 0;
$html = $html =

View file

@ -50,11 +50,11 @@ class ArchiveFileHandler extends Extension {
assert(file_exists($tmpname)); assert(file_exists($tmpname));
try { try {
global $user;
$pathinfo = pathinfo($filename); $pathinfo = pathinfo($filename);
if(!array_key_exists('extension', $pathinfo)) { if(!array_key_exists('extension', $pathinfo)) {
throw new UploadException("File has no extension"); throw new UploadException("File has no extension");
} }
$metadata = array();
$metadata['filename'] = $pathinfo['basename']; $metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension']; $metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags; $metadata['tags'] = $tags;
@ -69,8 +69,6 @@ class ArchiveFileHandler extends Extension {
// copied from bulk add extension // copied from bulk add extension
private function add_dir($base, $subdir="") { private function add_dir($base, $subdir="") {
global $page;
$list = ""; $list = "";
$dir = opendir("$base/$subdir"); $dir = opendir("$base/$subdir");

View file

@ -17,8 +17,6 @@ class FlashFileHandler extends DataHandlerExtension {
} }
protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) {
global $config;
$image = new Image(); $image = new Image();
$image->filesize = $metadata['size']; $image->filesize = $metadata['size'];
@ -28,15 +26,8 @@ class FlashFileHandler extends DataHandlerExtension {
$image->tag_array = Tag::explode($metadata['tags']); $image->tag_array = Tag::explode($metadata['tags']);
$image->source = $metadata['source']; $image->source = $metadata['source'];
// redundant, since getimagesize() works on SWF o_O $info = getimagesize($filename);
// $rect = $this->swf_get_bounds($filename); if(!$info) return null;
// if(is_null($rect)) {
// return $null;
// }
// $image->width = $rect[1];
// $image->height = $rect[3];
if(!($info = getimagesize($filename))) return null;
$image->width = $info[0]; $image->width = $info[0];
$image->height = $info[1]; $image->height = $info[1];
@ -54,52 +45,5 @@ class FlashFileHandler extends DataHandlerExtension {
return true; return true;
} }
private function str_to_binarray(/*string*/ $string) {
$binary = array();
$length = strlen($string);
for($j=0; $j<$length; $j++) {
$c = ord($string[$j]);
for($i=7; $i>=0; $i--) {
$binary[] = ($c >> $i) & 0x01;
}
}
return $binary;
}
private function binarray_to_int($binarray, $start=0, $length=32) {
$int = 0;
for($i=$start; $i<$start + $length; $i++) {
$int = $int << 1;
$int = $int + ($binarray[$i] == "1" ? 1 : 0);
}
return $int;
}
private function swf_get_bounds(/*string*/ $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;
}
} }
?> ?>

View file

@ -36,7 +36,7 @@ class IcoFileHandler extends Extension {
} }
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page; global $page;
if($event->page_matches("get_ico")) { if($event->page_matches("get_ico")) {
$id = int_escape($event->get_arg(0)); $id = int_escape($event->get_arg(0));
$image = Image::by_id($id); $image = Image::by_id($id);
@ -56,11 +56,8 @@ class IcoFileHandler extends Extension {
} }
private function create_image_from_data($filename, $metadata) { private function create_image_from_data($filename, $metadata) {
global $config;
$image = new Image(); $image = new Image();
$info = "";
$fp = fopen($filename, "r"); $fp = fopen($filename, "r");
$header = unpack("snull/stype/scount", fread($fp, 6)); $header = unpack("snull/stype/scount", fread($fp, 6));

View file

@ -6,8 +6,8 @@ class IcoHandlerTest extends ShimmieWebTestCase {
$this->assert_response(302); $this->assert_response(302);
$this->log_out(); $this->log_out();
$raw = $this->get_page("post/view/$image_id"); // test for no crash $this->get_page("post/view/$image_id"); // test for no crash
$raw = $this->get_page("get_ico/$image_id"); // test for no crash $this->get_page("get_ico/$image_id"); // test for no crash
$this->log_in_as_admin(); $this->log_in_as_admin();
$this->delete_image($image_id); $this->delete_image($image_id);

View file

@ -14,12 +14,10 @@ class PixelFileHandler extends DataHandlerExtension {
} }
protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) {
global $config;
$image = new Image(); $image = new Image();
$info = ""; $info = getimagesize($filename);
if(!($info = getimagesize($filename))) return null; if(!$info) return null;
$image->width = $info[0]; $image->width = $info[0];
$image->height = $info[1]; $image->height = $info[1];
@ -52,9 +50,10 @@ class PixelFileHandler extends DataHandlerExtension {
} }
protected function create_thumb_force(/*string*/ $hash) { protected function create_thumb_force(/*string*/ $hash) {
global $config;
$inname = warehouse_path("images", $hash); $inname = warehouse_path("images", $hash);
$outname = warehouse_path("thumbs", $hash); $outname = warehouse_path("thumbs", $hash);
global $config;
$ok = false; $ok = false;
@ -165,7 +164,7 @@ class PixelFileHandler extends DataHandlerExtension {
if($width > $height*5) $width = $height*5; if($width > $height*5) $width = $height*5;
if($height > $width*5) $height = $width*5; if($height > $width*5) $height = $width*5;
$image = imagecreatefromstring($this->read_file($tmpname)); $image = imagecreatefromstring(file_get_contents($tmpname));
$tsize = get_thumbnail_size($width, $height); $tsize = get_thumbnail_size($width, $height);
$thumb = imagecreatetruecolor($tsize[0], $tsize[1]); $thumb = imagecreatetruecolor($tsize[0], $tsize[1]);
@ -176,16 +175,6 @@ class PixelFileHandler extends DataHandlerExtension {
return $thumb; return $thumb;
} }
} }
private function read_file(/*string*/ $fname) {
$fp = fopen($fname, "r");
if(!$fp) return false;
$data = fread($fp, filesize($fname));
fclose($fp);
return $data;
}
// }}} // }}}
} }
?> ?>

View file

@ -15,26 +15,26 @@ $(function() {
} }
}); });
function zoom(zoom) { function zoom(zoom_type) {
var img = $('.shm-main-image'); var img = $('.shm-main-image');
if(zoom == "full") { if(zoom_type == "full") {
img.css('max-width', img.data('width') + 'px'); img.css('max-width', img.data('width') + 'px');
img.css('max-height', img.data('height') + 'px'); img.css('max-height', img.data('height') + 'px');
} }
if(zoom == "width") { if(zoom_type == "width") {
img.css('max-width', '95%'); img.css('max-width', '95%');
img.css('max-height', img.data('height') + 'px'); img.css('max-height', img.data('height') + 'px');
} }
if(zoom == "height") { if(zoom_type == "height") {
img.css('max-width', img.data('width') + 'px'); img.css('max-width', img.data('width') + 'px');
img.css('max-height', (window.innerHeight * 0.95) + 'px'); img.css('max-height', (window.innerHeight * 0.95) + 'px');
} }
if(zoom == "both") { if(zoom_type == "both") {
img.css('max-width', '95%'); img.css('max-width', '95%');
img.css('max-height', (window.innerHeight * 0.95) + 'px'); img.css('max-height', (window.innerHeight * 0.95) + 'px');
} }
$(".shm-zoomer").val(zoom); $(".shm-zoomer").val(zoom_type);
$.cookie("ui-image-zoom", zoom, {path: '/', expires: 365}); $.cookie("ui-image-zoom", zoom_type, {path: '/', expires: 365});
} }

View file

@ -10,7 +10,6 @@ class SVGFileHandler extends Extension {
public function onDataUpload(DataUploadEvent $event) { public function onDataUpload(DataUploadEvent $event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2);
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
$image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata); $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata);
@ -27,7 +26,6 @@ class SVGFileHandler extends Extension {
global $config; global $config;
if($this->supported_ext($event->type)) { if($this->supported_ext($event->type)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2);
copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash)); copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
} }
@ -88,7 +86,7 @@ class SVGFileHandler extends Extension {
class MiniSVGParser { class MiniSVGParser {
var $valid=false, $width=0, $height=0; var $valid=false, $width=0, $height=0;
function MiniSVGParser($file) { function __construct($file) {
$xml_parser = xml_parser_create(); $xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, array($this, "startElement"), array($this, "endElement")); xml_set_element_handler($xml_parser, array($this, "startElement"), array($this, "endElement"));
$this->valid = xml_parse($xml_parser, file_get_contents($file), true); $this->valid = xml_parse($xml_parser, file_get_contents($file), true);

View file

@ -31,6 +31,9 @@ else {
<source src='" . make_link("/image/" . $image->id) . "' type='video/webm' /> <source src='" . make_link("/image/" . $image->id) . "' type='video/webm' />
</video>"; </video>";
} }
else {
$html = "Video type '$ext' not recognised";
}
$page->add_block(new Block("Video", $html, "main", 10)); $page->add_block(new Block("Video", $html, "main", 10));
} }
} }

View file

@ -20,9 +20,9 @@ class ImageAdditionEvent extends Event {
* this new image. * this new image.
* *
* @sa TagSetEvent * @sa TagSetEvent
* @param $image The new image to add. * @param $image Image The new image to add.
*/ */
public function ImageAdditionEvent(Image $image) { public function __construct(Image $image) {
$this->image = $image; $this->image = $image;
} }
} }
@ -46,9 +46,9 @@ class ImageDeletionEvent extends Event {
* Used by things like tags and comments handlers to * Used by things like tags and comments handlers to
* clean out related rows in their tables. * clean out related rows in their tables.
* *
* @param $image The image being deleted * @param $image Image The image being deleted
*/ */
public function ImageDeletionEvent(Image $image) { public function __construct(Image $image) {
$this->image = $image; $this->image = $image;
} }
} }
@ -70,7 +70,7 @@ class ImageReplaceEvent extends Event {
* @param $image * @param $image
* The image object of the new image to use * The image object of the new image to use
*/ */
public function ImageReplaceEvent(/*int*/ $id, Image $image) { public function __construct(/*int*/ $id, Image $image) {
$this->id = $id; $this->id = $id;
$this->image = $image; $this->image = $image;
} }
@ -93,10 +93,11 @@ class ThumbnailGenerationEvent extends Event {
/** /**
* Request a thumbnail be made for an image object * Request a thumbnail be made for an image object
* *
* @param $hash The unique hash of the image * @param $hash string The unique hash of the image
* @param $type The type of the image * @param $type string The type of the image
* @param $force boolean Regenerate the thumbnail even if one already exists
*/ */
public function ThumbnailGenerationEvent($hash, $type, $force=false) { public function __construct($hash, $type, $force=false) {
$this->hash = $hash; $this->hash = $hash;
$this->type = $type; $this->type = $type;
$this->force = $force; $this->force = $force;
@ -113,7 +114,7 @@ class ThumbnailGenerationEvent extends Event {
class ParseLinkTemplateEvent extends Event { class ParseLinkTemplateEvent extends Event {
var $link, $original, $image; var $link, $original, $image;
public function ParseLinkTemplateEvent($link, Image $image) { public function __construct($link, Image $image) {
$this->link = $link; $this->link = $link;
$this->original = $link; $this->original = $link;
$this->image = $image; $this->image = $image;
@ -223,9 +224,6 @@ class ImageIO extends Extension {
} }
public function onUserPageBuilding(UserPageBuildingEvent $event) { public function onUserPageBuilding(UserPageBuildingEvent $event) {
global $user;
global $config;
$u_id = url_escape($event->display_user->id); $u_id = url_escape($event->display_user->id);
$i_image_count = Image::count_images(array("user_id={$event->display_user->id}")); $i_image_count = Image::count_images(array("user_id={$event->display_user->id}"));
$i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1; $i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
@ -279,7 +277,7 @@ class ImageIO extends Extension {
// add image {{{ // add image {{{
private function add_image($image) { private function add_image(Image $image) {
global $page, $user, $database, $config; global $page, $user, $database, $config;
/* /*
@ -325,7 +323,7 @@ class ImageIO extends Extension {
)", )",
array( array(
"owner_id"=>$user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'], "filename"=>substr($image->filename, 0, 60), "filesize"=>$image->filesize, "owner_id"=>$user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'], "filename"=>substr($image->filename, 0, 60), "filesize"=>$image->filesize,
"hash"=>$image->hash, "ext"=>$image->ext, "width"=>$image->width, "height"=>$image->height, "source"=>$image->source "hash"=>$image->hash, "ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source
) )
); );
$image->id = $database->get_last_insert_id('images_id_seq'); $image->id = $database->get_last_insert_id('images_id_seq');
@ -401,10 +399,7 @@ class ImageIO extends Extension {
// replace image {{{ // replace image {{{
private function replace_image($id, $image) { private function replace_image($id, $image) {
global $page;
global $user;
global $database; global $database;
global $config;
/* Check to make sure the image exists. */ /* Check to make sure the image exists. */
$existing = Image::by_id($id); $existing = Image::by_id($id);
@ -435,7 +430,7 @@ class ImageIO extends Extension {
", ",
array( array(
"filename"=>$image->filename, "filesize"=>$image->filesize, "hash"=>$image->hash, "filename"=>$image->filename, "filesize"=>$image->filesize, "hash"=>$image->hash,
"ext"=>$image->ext, "width"=>$image->width, "height"=>$image->height, "source"=>$image->source, "ext"=>strtolower($image->ext), "width"=>$image->width, "height"=>$image->height, "source"=>$image->source,
"id"=>$id "id"=>$id
) )
); );

View file

@ -13,7 +13,7 @@
class RemoveImageHashBanEvent extends Event { class RemoveImageHashBanEvent extends Event {
var $hash; var $hash;
public function RemoveImageHashBanEvent($hash) { public function __construct($hash) {
$this->hash = $hash; $this->hash = $hash;
} }
} }
@ -23,7 +23,7 @@ class AddImageHashBanEvent extends Event {
var $hash; var $hash;
var $reason; var $reason;
public function AddImageHashBanEvent($hash, $reason) { public function __construct($hash, $reason) {
$this->hash = $hash; $this->hash = $hash;
$this->reason = $reason; $this->reason = $reason;
} }
@ -36,7 +36,7 @@ class ImageBan extends Extension {
$database->create_table("image_bans", " $database->create_table("image_bans", "
id SCORE_AIPK, id SCORE_AIPK,
hash CHAR(32) NOT NULL, hash CHAR(32) NOT NULL,
date DATETIME DEFAULT SCORE_NOW, date SCORE_DATETIME DEFAULT SCORE_NOW,
reason TEXT NOT NULL reason TEXT NOT NULL
"); ");
$config->set_int("ext_imageban_version", 1); $config->set_int("ext_imageban_version", 1);

View file

@ -22,7 +22,6 @@ class ImageBanTheme extends Themelet {
*/ */
public function display_image_hash_bans(Page $page, $page_number, $page_count, $bans) { public function display_image_hash_bans(Page $page, $page_number, $page_count, $bans) {
$h_bans = ""; $h_bans = "";
$n = 0;
foreach($bans as $ban) { foreach($bans as $ban) {
$h_bans .= " $h_bans .= "
<tr> <tr>

View file

@ -94,6 +94,10 @@
* <li>order=width -- find all images sorted from highest > lowest width * <li>order=width -- find all images sorted from highest > lowest width
* <li>order=filesize_asc -- find all images sorted from lowest > highest filesize * <li>order=filesize_asc -- find all images sorted from lowest > highest filesize
* </ul> * </ul>
* <li>order=random_####, eg
* <ul>
* <li>order=random_8547 -- find all images sorted randomly using 8547 as a seed
* </ul>
* </ul> * </ul>
* <p>Search items can be combined to search for images which match both, * <p>Search items can be combined to search for images which match both,
* or you can stick "-" in front of an item to search for things that don't * or you can stick "-" in front of an item to search for things that don't
@ -159,7 +163,7 @@ class SearchTermParseEvent extends Event {
var $context = null; var $context = null;
var $querylets = array(); var $querylets = array();
public function SearchTermParseEvent($term, $context) { public function __construct($term, $context) {
$this->term = $term; $this->term = $term;
$this->context = $context; $this->context = $context;
} }
@ -362,7 +366,15 @@ class Index extends Extension {
$ord = strtolower($matches[1]); $ord = strtolower($matches[1]);
$default_order_for_column = preg_match("/^(id|filename)$/", $matches[1]) ? "ASC" : "DESC"; $default_order_for_column = preg_match("/^(id|filename)$/", $matches[1]) ? "ASC" : "DESC";
$sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column; $sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column;
$order_sql = "$ord $sort"; $order_sql = "images.$ord $sort";
$event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
}
else if(preg_match("/^order[=|:]random[_]([0-9]{1,4})$/i", $event->term, $matches)){
global $order_sql;
//order[=|:]random requires a seed to avoid duplicates
//since the tag can't be changed during the parseevent, we instead generate the seed during submit using js
$seed = $matches[1];
$order_sql = "RAND($seed)";
$event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
} }

View file

@ -17,6 +17,18 @@ $(function() {
function() {$('.shm-image-list').show();} function() {$('.shm-image-list').show();}
); );
} }
//Generate a random seed when using order:random
$('form > input[placeholder="Search"]').parent().submit(function(e){
var input = $('form > input[placeholder="Search"]');
var tagArr = input.val().split(" ");
var rand = (($.inArray("order:random", tagArr) + 1) || ($.inArray("order=random", tagArr) + 1)) - 1;
if(rand !== -1){
tagArr[rand] = "order:random_"+Math.floor((Math.random()*9999)+1);
input.val(tagArr.join(" "));
}
});
}); });
function select_blocked_tags() { function select_blocked_tags() {

View file

@ -1,6 +1,8 @@
<?php <?php
class IndexTheme extends Themelet { class IndexTheme extends Themelet {
var $page_number, $total_pages, $search_terms;
public function set_page($page_number, $total_pages, $search_terms) { public function set_page($page_number, $total_pages, $search_terms) {
$this->page_number = $page_number; $this->page_number = $page_number;
$this->total_pages = $total_pages; $this->total_pages = $total_pages;

View file

@ -16,7 +16,7 @@
class RemoveIPBanEvent extends Event { class RemoveIPBanEvent extends Event {
var $id; var $id;
public function RemoveIPBanEvent($id) { public function __construct($id) {
$this->id = $id; $this->id = $id;
} }
} }
@ -27,7 +27,7 @@ class AddIPBanEvent extends Event {
var $reason; var $reason;
var $end; var $end;
public function AddIPBanEvent(/*string(ip)*/ $ip, /*string*/ $reason, /*string*/ $end) { public function __construct(/*string(ip)*/ $ip, /*string*/ $reason, /*string*/ $end) {
$this->ip = trim($ip); $this->ip = trim($ip);
$this->reason = trim($reason); $this->reason = trim($reason);
$this->end = trim($end); $this->end = trim($end);
@ -130,8 +130,8 @@ class IPBan extends Extension {
$database->Execute("CREATE TABLE bans ( $database->Execute("CREATE TABLE bans (
id int(11) NOT NULL auto_increment, id int(11) NOT NULL auto_increment,
ip char(15) default NULL, ip char(15) default NULL,
date datetime default NULL, date SCORE_DATETIME default NULL,
end datetime default NULL, end SCORE_DATETIME default NULL,
reason varchar(255) default NULL, reason varchar(255) default NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
)"); )");

View file

@ -14,7 +14,6 @@ class IPBanTheme extends Themelet {
public function display_bans(Page $page, $bans) { public function display_bans(Page $page, $bans) {
global $database, $user; global $database, $user;
$h_bans = ""; $h_bans = "";
$n = 0;
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : ""); $prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
$prefix2 = ($database->get_driver_name() == "sqlite" ? "users." : ""); $prefix2 = ($database->get_driver_name() == "sqlite" ? "users." : "");
foreach($bans as $ban) { foreach($bans as $ban) {

View file

@ -62,7 +62,7 @@ class LinkImageTheme extends Themelet {
$text = "[url=".$url."]".$content."[/url]"; $text = "[url=".$url."]".$content."[/url]";
break; break;
default: default:
$text = $link." - ".$content; $text = $url." - ".$content;
} }
return $text; return $text;
} }

View file

@ -63,6 +63,7 @@ class LiveFeed extends Extension {
fwrite($fp, "$data\n"); fwrite($fp, "$data\n");
fclose($fp); fclose($fp);
} catch (Exception $e) { } catch (Exception $e) {
/* logging errors shouldn't break everything */
} }
} }
} }

View file

@ -40,7 +40,6 @@ class LogDatabaseTheme extends Themelet {
</form> </form>
</thead> </thead>
<tbody>\n"; <tbody>\n";
$n = 0;
reset($events); // rewind to first element in array. reset($events); // rewind to first element in array.
foreach($events as $event) { foreach($events as $event) {

View file

@ -42,6 +42,7 @@ class LogNet extends Extension {
fwrite($fp, "$data\n"); fwrite($fp, "$data\n");
fclose($fp); fclose($fp);
} catch (Exception $e) { } catch (Exception $e) {
/* logging errors shouldn't break everything */
} }
} }
} }

View file

@ -53,6 +53,7 @@ class MassTagger extends Extension {
} }
$page->set_mode("redirect"); $page->set_mode("redirect");
if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = make_link();
$page->set_redirect($_SERVER['HTTP_REFERER']); $page->set_redirect($_SERVER['HTTP_REFERER']);
} }
} }

View file

@ -29,7 +29,7 @@ class NotATag extends Extension {
} }
private function scan(/*array*/ $tags_mixed) { private function scan(/*array*/ $tags_mixed) {
global $config, $database; global $database;
$tags = array(); $tags = array();
foreach($tags_mixed as $tag) $tags[] = strtolower($tag); foreach($tags_mixed as $tag) $tags[] = strtolower($tag);
@ -53,12 +53,12 @@ class NotATag extends Extension {
} }
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user; global $database, $page, $user;
if($event->page_matches("untag")) { if($event->page_matches("untag")) {
if($user->can("ban_image")) { if($user->can("ban_image")) {
if($event->get_arg(0) == "add") { if($event->get_arg(0) == "add") {
$tag = isset($_POST["tag"]) ? $_POST["tag"] : $image->tag; $tag = $_POST["tag"];
$redirect = isset($_POST['redirect']) ? $_POST['redirect'] : "DNP"; $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : "DNP";
$database->Execute( $database->Execute(

View file

@ -2,7 +2,6 @@
class NotATagTheme extends Themelet { class NotATagTheme extends Themelet {
public function display_untags(Page $page, $page_number, $page_count, $bans) { public function display_untags(Page $page, $page_number, $page_count, $bans) {
$h_bans = ""; $h_bans = "";
$n = 0;
foreach($bans as $ban) { foreach($bans as $ban) {
$h_bans .= " $h_bans .= "
<tr> <tr>

View file

@ -20,7 +20,7 @@ class Notes extends Extension {
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
user_ip CHAR(15) NOT NULL, user_ip CHAR(15) NOT NULL,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
x1 INTEGER NOT NULL, x1 INTEGER NOT NULL,
y1 INTEGER NOT NULL, y1 INTEGER NOT NULL,
height INTEGER NOT NULL, height INTEGER NOT NULL,
@ -35,7 +35,7 @@ class Notes extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE
"); ");
@ -49,7 +49,7 @@ class Notes extends Extension {
image_id INTEGER NOT NULL, image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
user_ip CHAR(15) NOT NULL, user_ip CHAR(15) NOT NULL,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
x1 INTEGER NOT NULL, x1 INTEGER NOT NULL,
y1 INTEGER NOT NULL, y1 INTEGER NOT NULL,
height INTEGER NOT NULL, height INTEGER NOT NULL,
@ -363,6 +363,8 @@ class Notes extends Extension {
*/ */
private function delete_note() private function delete_note()
{ {
global $user;
$imageID = int_escape($_POST["image_id"]); $imageID = int_escape($_POST["image_id"]);
$noteID = int_escape($_POST["note_id"]); $noteID = int_escape($_POST["note_id"]);
@ -388,7 +390,7 @@ class Notes extends Extension {
* HERE WE DELETE ALL NOTES FROM IMAGE * HERE WE DELETE ALL NOTES FROM IMAGE
*/ */
private function nuke_notes() { private function nuke_notes() {
global $database; global $database, $user;
$image_id = int_escape($_POST["image_id"]); $image_id = int_escape($_POST["image_id"]);
$database->execute("DELETE FROM notes WHERE image_id = ?", array($image_id)); $database->execute("DELETE FROM notes WHERE image_id = ?", array($image_id));
log_info("notes", "Notes deleted from {$image_id} by {$user->name}"); log_info("notes", "Notes deleted from {$image_id} by {$user->name}");
@ -400,7 +402,7 @@ class Notes extends Extension {
* HERE WE DELETE ALL REQUESTS FOR IMAGE * HERE WE DELETE ALL REQUESTS FOR IMAGE
*/ */
private function nuke_requests() { private function nuke_requests() {
global $database; global $database, $user;
$image_id = int_escape($_POST["image_id"]); $image_id = int_escape($_POST["image_id"]);
$database->execute("DELETE FROM note_request WHERE image_id = ?", array($image_id)); $database->execute("DELETE FROM note_request WHERE image_id = ?", array($image_id));
@ -588,7 +590,6 @@ class Notes extends Extension {
$noteEnable = $history['note_enable']; $noteEnable = $history['note_enable'];
$noteID = $history['note_id']; $noteID = $history['note_id'];
$imageID = $history['image_id']; $imageID = $history['image_id'];
$userID = $user->id;
$noteX1 = $history['x1']; $noteX1 = $history['x1'];
$noteY1 = $history['y1']; $noteY1 = $history['y1'];
$noteHeight = $history['height']; $noteHeight = $history['height'];

View file

@ -170,8 +170,8 @@ class NotesTheme extends Themelet {
$page->add_block(new Block("Note Requests", $pool_images, "main", 20)); $page->add_block(new Block("Note Requests", $pool_images, "main", 20));
} }
public function display_histories($histories, $pageNumber, $totalPages) { private function get_history($histories) {
global $user, $page; global $user;
$html = "<table id='poolsList' class='zebra'>". $html = "<table id='poolsList' class='zebra'>".
"<thead><tr>". "<thead><tr>".
@ -181,7 +181,6 @@ class NotesTheme extends Themelet {
"<th>Updater</th>". "<th>Updater</th>".
"<th>Date</th>"; "<th>Date</th>";
if(!$user->is_anonymous()){ if(!$user->is_anonymous()){
$html .= "<th>Action</th>"; $html .= "<th>Action</th>";
} }
@ -189,7 +188,6 @@ class NotesTheme extends Themelet {
$html .= "</tr></thead>". $html .= "</tr></thead>".
"<tbody>"; "<tbody>";
$n = 0;
foreach($histories as $history) { foreach($histories as $history) {
$image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>"; $image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>";
$history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>"; $history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>";
@ -211,6 +209,14 @@ class NotesTheme extends Themelet {
$html .= "</tr></tbody></table>"; $html .= "</tr></tbody></table>";
return $html;
}
public function display_histories($histories, $pageNumber, $totalPages) {
global $page;
$html = $this->get_history($histories);
$page->set_title("Note Updates"); $page->set_title("Note Updates");
$page->set_heading("Note Updates"); $page->set_heading("Note Updates");
$page->add_block(new Block("Note Updates", $html, "main", 10)); $page->add_block(new Block("Note Updates", $html, "main", 10));
@ -219,45 +225,9 @@ class NotesTheme extends Themelet {
} }
public function display_history($histories, $pageNumber, $totalPages) { public function display_history($histories, $pageNumber, $totalPages) {
global $user, $page; global $page;
$html = "<table id='poolsList' class='zebra'>". $html = $this->get_history($histories);
"<thead><tr>".
"<th>Image</th>".
"<th>Note</th>".
"<th>Body</th>".
"<th>Updater</th>".
"<th>Date</th>";
if(!$user->is_anonymous()){
$html .= "<th>Action</th>";
}
$html .= "</tr></thead>".
"<tbody>";
$n = 0;
foreach($histories as $history) {
$image_link = "<a href='".make_link("post/view/".$history['image_id'])."'>".$history['image_id']."</a>";
$history_link = "<a href='".make_link("note/history/".$history['note_id'])."'>".$history['note_id'].".".$history['review_id']."</a>";
$user_link = "<a href='".make_link("user/".$history['user_name'])."'>".$history['user_name']."</a>";
$revert_link = "<a href='".make_link("note/revert/".$history['note_id']."/".$history['review_id'])."'>Revert</a>";
$html .= "<tr>".
"<td>".$image_link."</td>".
"<td>".$history_link."</td>".
"<td style='text-align:left;'>".$history['note']."</td>".
"<td>".$user_link."</td>".
"<td>".autodate($history['date'])."</td>";
if(!$user->is_anonymous()){
$html .= "<td>".$revert_link."</td>";
}
}
$html .= "</tr></tbody></table>";
$page->set_title("Note History"); $page->set_title("Note History");
$page->set_heading("Note History"); $page->set_heading("Note History");

View file

@ -13,7 +13,7 @@
class NumericScoreSetEvent extends Event { class NumericScoreSetEvent extends Event {
var $image_id, $user, $score; var $image_id, $user, $score;
public function NumericScoreSetEvent(/*int*/ $image_id, User $user, /*int*/ $score) { public function __construct(/*int*/ $image_id, User $user, /*int*/ $score) {
$this->image_id = $image_id; $this->image_id = $image_id;
$this->user = $user; $this->user = $user;
$this->score = $score; $this->score = $score;
@ -237,7 +237,7 @@ class NumericScore extends Extension {
global $order_sql; global $order_sql;
$default_order_for_column = "DESC"; $default_order_for_column = "DESC";
$sort = isset($matches[3]) ? strtoupper($matches[3]) : $default_order_for_column; $sort = isset($matches[3]) ? strtoupper($matches[3]) : $default_order_for_column;
$order_sql = "numeric_score $sort"; $order_sql = "images.numeric_score $sort";
$event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
} }
} }

View file

@ -28,6 +28,7 @@ class Oekaki extends Extension {
throw new UploadException("File has no extension"); throw new UploadException("File has no extension");
} }
log_info("oekaki", "Processing file [{$pathinfo['filename']}]"); log_info("oekaki", "Processing file [{$pathinfo['filename']}]");
$metadata = array();
$metadata['filename'] = 'oekaki.png'; $metadata['filename'] = 'oekaki.png';
$metadata['extension'] = $pathinfo['extension']; $metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = 'oekaki tagme'; $metadata['tags'] = 'oekaki tagme';

View file

@ -9,7 +9,6 @@ class OekakiTheme extends Themelet {
global $config, $page; global $config, $page;
$base_href = get_base_href(); $base_href = get_base_href();
$http_base = make_http($base_href);
$oekW = $config->get_int("oekaki_width", 400); $oekW = $config->get_int("oekaki_width", 400);
$oekH = $config->get_int("oekaki_height", 400); $oekH = $config->get_int("oekaki_height", 400);

View file

@ -387,9 +387,11 @@ class OuroborosAPI extends Extension
// @TODO Should move the validation logic into OuroborosPost instead? // @TODO Should move the validation logic into OuroborosPost instead?
if ($user->can("create_image")) { if ($user->can("create_image")) {
$post = array( $post = array(
'tags' => !empty($_REQUEST['post']['tags']) ? filter_var( 'tags' => !empty($_REQUEST['post']['tags']) ? Tag::implode(
urldecode($_REQUEST['post']['tags']), array_map(
FILTER_SANITIZE_STRING array('Tag', 'sanitise'),
Tag::explode(urldecode($_REQUEST['post']['tags']))
)
) : 'tagme', ) : 'tagme',
'file' => !empty($_REQUEST['post']['file']) ? filter_var( 'file' => !empty($_REQUEST['post']['file']) ? filter_var(
$_REQUEST['post']['file'], $_REQUEST['post']['file'],

View file

@ -11,12 +11,16 @@
*/ */
class SendPMEvent extends Event { class SendPMEvent extends Event {
var $pm;
public function __construct(PM $pm) { public function __construct(PM $pm) {
$this->pm = $pm; $this->pm = $pm;
} }
} }
class PM { class PM {
var $id, $from_id, $from_ip, $to_id, $sent_date, $subject, $message, $is_read;
public function __construct($from_id=0, $from_ip="0.0.0.0", $to_id=0, $subject="A Message", $message="Some Text", $read=False) { public function __construct($from_id=0, $from_ip="0.0.0.0", $to_id=0, $subject="A Message", $message="Some Text", $read=False) {
# PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language" # PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language"
if(is_array($from_id)) { if(is_array($from_id)) {
@ -53,7 +57,7 @@ class PrivMsg extends Extension {
from_id INTEGER NOT NULL, from_id INTEGER NOT NULL,
from_ip SCORE_INET NOT NULL, from_ip SCORE_INET NOT NULL,
to_id INTEGER NOT NULL, to_id INTEGER NOT NULL,
sent_date DATETIME NOT NULL, sent_date SCORE_DATETIME NOT NULL,
subject VARCHAR(64) NOT NULL, subject VARCHAR(64) NOT NULL,
message TEXT NOT NULL, message TEXT NOT NULL,
is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, is_read SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,

View file

@ -8,7 +8,6 @@ class PrivMsgTheme extends Themelet {
<table id='pms' class='zebra sortable'> <table id='pms' class='zebra sortable'>
<thead><tr><th>R?</th><th>Subject</th><th>From</th><th>Date</th><th>Action</th></tr></thead> <thead><tr><th>R?</th><th>Subject</th><th>From</th><th>Date</th><th>Action</th></tr></thead>
<tbody>"; <tbody>";
$n = 0;
foreach($pms as $pm) { foreach($pms as $pm) {
$h_subject = html_escape($pm->subject); $h_subject = html_escape($pm->subject);
if(strlen(trim($h_subject)) == 0) $h_subject = "(No subject)"; if(strlen(trim($h_subject)) == 0) $h_subject = "(No subject)";

View file

@ -33,7 +33,7 @@ class Pools extends Extension {
public SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, public SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
description TEXT, description TEXT,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
posts INTEGER NOT NULL DEFAULT 0, posts INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
"); ");
@ -51,7 +51,7 @@ class Pools extends Extension {
action INTEGER NOT NULL, action INTEGER NOT NULL,
images TEXT, images TEXT,
count INTEGER NOT NULL DEFAULT 0, count INTEGER NOT NULL DEFAULT 0,
date DATETIME NOT NULL, date SCORE_DATETIME NOT NULL,
FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (pool_id) REFERENCES pools(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
"); ");

View file

@ -12,7 +12,6 @@ class PoolsTheme extends Themelet {
} }
public function get_adder_html(Image $image, /*array*/ $pools) { public function get_adder_html(Image $image, /*array*/ $pools) {
$editor = "";
$h = ""; $h = "";
foreach($pools as $pool) { foreach($pools as $pool) {
$h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>"; $h .= "<option value='".$pool['id']."'>".html_escape($pool['title'])."</option>";
@ -43,8 +42,6 @@ class PoolsTheme extends Themelet {
<th>Public</th> <th>Public</th>
</tr></thead><tbody>'; </tr></thead><tbody>';
$n = 0;
// Build up the list of pools. // Build up the list of pools.
foreach($pools as $pool) { foreach($pools as $pool) {
$pool_link = '<a href="'.make_link("pool/view/".$pool['id']).'">'.html_escape($pool['title'])."</a>"; $pool_link = '<a href="'.make_link("pool/view/".$pool['id']).'">'.html_escape($pool['title'])."</a>";
@ -133,7 +130,6 @@ class PoolsTheme extends Themelet {
<th class="left">Description</th> <th class="left">Description</th>
</tr></thead><tbody>'; </tr></thead><tbody>';
$n = 0;
foreach($pools as $pool) { foreach($pools as $pool) {
$pool_info .= "<tr>". $pool_info .= "<tr>".
"<td class='left'>".html_escape($pool['title'])."</td>". "<td class='left'>".html_escape($pool['title'])."</td>".
@ -303,15 +299,15 @@ class PoolsTheme extends Themelet {
$this->display_top($pools, "Sorting Pool"); $this->display_top($pools, "Sorting Pool");
$pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>"; $pool_images = "\n<form action='".make_link("pool/order")."' method='POST' name='checks'>";
$n = 0; $i = 0;
foreach($images as $pair) { foreach($images as $pair) {
$image = $pair[0]; $image = $pair[0];
$thumb_html = $this->build_thumb_html($image); $thumb_html = $this->build_thumb_html($image);
$pool_images .= '<span class="thumb">'."\n".$thumb_html."\n". $pool_images .= '<span class="thumb">'."\n".$thumb_html."\n".
'<br><input name="imgs['.$n.'][]" type="text" style="max-width:50px;" value="'.$image->image_order.'" />'. '<br><input name="imgs['.$i.'][]" type="text" style="max-width:50px;" value="'.$image->image_order.'" />'.
'<input name="imgs['.$n.'][]" type="hidden" value="'.$image->id.'" />'. '<input name="imgs['.$i.'][]" type="hidden" value="'.$image->id.'" />'.
'</span>'; '</span>';
$n++; $i++;
} }
$pool_images .= "<br>". $pool_images .= "<br>".
@ -382,7 +378,6 @@ class PoolsTheme extends Themelet {
<th>Action</th> <th>Action</th>
</tr></thead><tbody>'; </tr></thead><tbody>';
$n = 0;
foreach($histories as $history) { foreach($histories as $history) {
$pool_link = "<a href='".make_link("pool/view/".$history['pool_id'])."'>".html_escape($history['title'])."</a>"; $pool_link = "<a href='".make_link("pool/view/".$history['pool_id'])."'>".html_escape($history['title'])."</a>";
$user_link = "<a href='".make_link("user/".url_escape($history['user_name']))."'>".html_escape($history['user_name'])."</a>"; $user_link = "<a href='".make_link("user/".url_escape($history['user_name']))."'>".html_escape($history['user_name'])."</a>";

View file

@ -22,7 +22,7 @@
class RatingSetEvent extends Event { class RatingSetEvent extends Event {
var $image, $rating; var $image, $rating;
public function RatingSetEvent(Image $image, /*char*/ $rating) { public function __construct(Image $image, /*char*/ $rating) {
assert(in_array($rating, array("s", "q", "e", "u"))); assert(in_array($rating, array("s", "q", "e", "u")));
$this->image = $image; $this->image = $image;
$this->rating = $rating; $this->rating = $rating;

View file

@ -2,7 +2,6 @@
class RatingsTheme extends Themelet { class RatingsTheme extends Themelet {
public function get_rater_html(/*int*/ $image_id, /*string*/ $rating) { public function get_rater_html(/*int*/ $image_id, /*string*/ $rating) {
$i_image_id = int_escape($image_id);
$s_checked = $rating == 's' ? " checked" : ""; $s_checked = $rating == 's' ? " checked" : "";
$q_checked = $rating == 'q' ? " checked" : ""; $q_checked = $rating == 'q' ? " checked" : "";
$e_checked = $rating == 'e' ? " checked" : ""; $e_checked = $rating == 'e' ? " checked" : "";

View file

@ -12,7 +12,7 @@
class RemoveReportedImageEvent extends Event { class RemoveReportedImageEvent extends Event {
var $id; var $id;
public function RemoveReportedImageEvent($id) { public function __construct($id) {
$this->id = $id; $this->id = $id;
} }
} }
@ -22,7 +22,7 @@ class AddReportedImageEvent extends Event {
var $image_id; var $image_id;
var $reason; var $reason;
public function AddReportedImageEvent($image_id, $reporter_id, $reason) { public function __construct($image_id, $reporter_id, $reason) {
$this->reporter_id = $reporter_id; $this->reporter_id = $reporter_id;
$this->image_id = $image_id; $this->image_id = $image_id;
$this->reason = $reason; $this->reason = $reason;

View file

@ -15,7 +15,6 @@ class ReportImageTheme extends Themelet {
global $config; global $config;
$h_reportedimages = ""; $h_reportedimages = "";
$n = 0;
foreach($reports as $report) { foreach($reports as $report) {
$image = $report['image']; $image = $report['image'];
$h_reason = format_text($report['reason']); $h_reason = format_text($report['reason']);

View file

@ -84,7 +84,7 @@ class ResizeImage extends Extension {
} }
if($isanigif == 0){ if($isanigif == 0){
try { try {
$this->resize_image($event->image_id, $width, $height); $this->resize_image($image_obj, $width, $height);
} catch (ImageResizeException $e) { } catch (ImageResizeException $e) {
$this->theme->display_resize_error($page, "Error Resizing", $e->error); $this->theme->display_resize_error($page, "Error Resizing", $e->error);
} }
@ -107,7 +107,7 @@ class ResizeImage extends Extension {
// Try to get the image ID // Try to get the image ID
$image_id = int_escape($event->get_arg(0)); $image_id = int_escape($event->get_arg(0));
if (empty($image_id)) { if (empty($image_id)) {
$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null; $image_id = isset($_POST['image_id']) ? int_escape($_POST['image_id']) : null;
} }
if (empty($image_id)) { if (empty($image_id)) {
throw new ImageResizeException("Can not resize Image: No valid Image ID given."); throw new ImageResizeException("Can not resize Image: No valid Image ID given.");
@ -134,7 +134,7 @@ class ResizeImage extends Extension {
/* Attempt to resize the image */ /* Attempt to resize the image */
try { try {
$this->resize_image($image_id, $width, $height); $this->resize_image($image, $width, $height);
//$this->theme->display_resize_page($page, $image_id); //$this->theme->display_resize_page($page, $image_id);
@ -157,19 +157,14 @@ class ResizeImage extends Extension {
This function could be made much smaller by using the ImageReplaceEvent This function could be made much smaller by using the ImageReplaceEvent
ie: Pretend that we are replacing the image with a resized copy. ie: Pretend that we are replacing the image with a resized copy.
*/ */
private function resize_image(/*int*/ $image_id, /*int*/ $width, /*int*/ $height) { private function resize_image(Image $image_obj, /*int*/ $width, /*int*/ $height) {
global $config, $user, $page, $database; global $config, $user, $page, $database;
if ( ($height <= 0) && ($width <= 0) ) { if ( ($height <= 0) && ($width <= 0) ) {
throw new ImageResizeException("Invalid options for height and width. ($width x $height)"); throw new ImageResizeException("Invalid options for height and width. ($width x $height)");
} }
$image_obj = Image::by_id($image_id);
$hash = $image_obj->hash; $hash = $image_obj->hash;
if (is_null($hash)) {
throw new ImageResizeException("Image does not have a hash associated with it.");
}
$image_filename = warehouse_path("images", $hash); $image_filename = warehouse_path("images", $hash);
$info = getimagesize($image_filename); $info = getimagesize($image_filename);
/* Get the image file type */ /* Get the image file type */
@ -177,7 +172,7 @@ class ResizeImage extends Extension {
$filetype = strtolower($pathinfo['extension']); $filetype = strtolower($pathinfo['extension']);
if (($image_obj->width != $info[0] ) || ($image_obj->height != $info[1])) { if (($image_obj->width != $info[0] ) || ($image_obj->height != $info[1])) {
throw new ImageResizeException("The image size does not match what is in the database! - Aborting Resize."); throw new ImageResizeException("The current image size does not match what is set in the database! - Aborting Resize.");
} }
/* /*
@ -192,7 +187,18 @@ class ResizeImage extends Extension {
The factor of 2.5 is simply a rough guideline. The factor of 2.5 is simply a rough guideline.
http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
*/ */
if (isset($info['bits']) && isset($info['channels']))
{
$memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024; $memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024;
} else {
//
// If we don't have bits and channel info from the image then assume default values
// of 8 bits per color and 4 channels (R,G,B,A) -- ie: regular 24-bit color
//
$memory_use = ($info[0] * $info[1] * 1 * 4 * 2.5) / 1024;
}
$memory_limit = get_memory_limit(); $memory_limit = get_memory_limit();
if ($memory_use > $memory_limit) { if ($memory_use > $memory_limit) {
@ -219,28 +225,41 @@ class ResizeImage extends Extension {
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break; case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break;
case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;
default: default:
throw new ImageResizeException("Unsupported image type."); throw new ImageResizeException("Unsupported image type (Only GIF, JPEG, and PNG are supported).");
} }
/* Resize and resample the image */ // Handle transparent images
$image_resized = imagecreatetruecolor( $new_width, $new_height ); $image_resized = imagecreatetruecolor( $new_width, $new_height );
if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) { if ($info[2] == IMAGETYPE_GIF) {
$transparency = imagecolortransparent($image); $transparency = imagecolortransparent($image);
// If we have a specific transparent color
if ($transparency >= 0) { if ($transparency >= 0) {
$transparent_color = imagecolorsforindex($image, $trnprt_indx); // Get the original image's transparent color's RGB values
$transparency = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); $transparent_color = imagecolorsforindex($image, $transparency);
// Allocate the same color in the new image resource
$transparency = imagecolorallocate($image_resized, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($image_resized, 0, 0, $transparency); imagefill($image_resized, 0, 0, $transparency);
// Set the background color for new image to transparent
imagecolortransparent($image_resized, $transparency); imagecolortransparent($image_resized, $transparency);
} }
elseif ($info[2] == IMAGETYPE_PNG) { } elseif ($info[2] == IMAGETYPE_PNG) {
//
// More info here: http://stackoverflow.com/questions/279236/how-do-i-resize-pngs-with-transparency-in-php
//
imagealphablending($image_resized, false); imagealphablending($image_resized, false);
$color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
imagefill($image_resized, 0, 0, $color);
imagesavealpha($image_resized, true); imagesavealpha($image_resized, true);
$transparent_color = imagecolorallocatealpha($image_resized, 255, 255, 255, 127);
imagefilledrectangle($image_resized, 0, 0, $new_width, $new_height, $transparent_color);
} }
}
// Actually resize the image.
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $image_obj->width, $image_obj->height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $image_obj->width, $image_obj->height);
/* Temp storage while we resize */ /* Temp storage while we resize */
@ -255,7 +274,7 @@ class ResizeImage extends Extension {
case IMAGETYPE_JPEG: imagejpeg($image_resized, $tmp_filename); break; case IMAGETYPE_JPEG: imagejpeg($image_resized, $tmp_filename); break;
case IMAGETYPE_PNG: imagepng($image_resized, $tmp_filename); break; case IMAGETYPE_PNG: imagepng($image_resized, $tmp_filename); break;
default: default:
throw new ImageResizeException("Unsupported image type."); throw new ImageResizeException("Failed to save the new image - Unsupported image type.");
} }
/* Move the new image into the main storage location */ /* Move the new image into the main storage location */
@ -286,11 +305,11 @@ class ResizeImage extends Extension {
", ",
array( array(
"filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash, "filename"=>$new_filename, "filesize"=>$new_size, "hash"=>$new_hash,
"width"=>$new_width, "height"=>$new_height, "id"=>$image_id "width"=>$new_width, "height"=>$new_height, "id"=>$image_obj->id
) )
); );
log_info("resize", "Resized Image #{$image_id} - New hash: {$new_hash}"); log_info("resize", "Resized Image #{$image_obj->id} - New hash: {$new_hash}");
} }
} }
?> ?>

View file

@ -7,7 +7,6 @@ class ResizeImageTheme extends Themelet {
public function get_resize_html(Image $image) { public function get_resize_html(Image $image) {
global $user, $config; global $user, $config;
$i_image_id = int_escape($image->id);
$default_width = $config->get_int('resize_default_width'); $default_width = $config->get_int('resize_default_width');
$default_height = $config->get_int('resize_default_height'); $default_height = $config->get_int('resize_default_height');

View file

@ -7,8 +7,6 @@ class RotateImageTheme extends Themelet {
public function get_rotate_html(/*int*/ $image_id) { public function get_rotate_html(/*int*/ $image_id) {
global $user, $config; global $user, $config;
$i_image_id = int_escape($image_id);
$html = " $html = "
".make_form(make_link('rotate/'.$image_id), 'POST')." ".make_form(make_link('rotate/'.$image_id), 'POST')."
<input type='hidden' name='image_id' value='$image_id'> <input type='hidden' name='image_id' value='$image_id'>

View file

@ -14,7 +14,7 @@
class ConfigSaveEvent extends Event { class ConfigSaveEvent extends Event {
var $config; var $config;
public function ConfigSaveEvent(Config $config) { public function __construct(Config $config) {
$this->config = $config; $this->config = $config;
} }
} }
@ -26,7 +26,7 @@ class ConfigSaveEvent extends Event {
class SetupBuildingEvent extends Event { class SetupBuildingEvent extends Event {
var $panel; var $panel;
public function SetupBuildingEvent(SetupPanel $panel) { public function __construct(SetupPanel $panel) {
$this->panel = $panel; $this->panel = $panel;
} }
} }
@ -49,10 +49,11 @@ class SetupBlock extends Block {
var $header; var $header;
var $body; var $body;
public function SetupBlock($title) { public function __construct($title) {
$this->header = $title; $this->header = $title;
$this->section = "main"; $this->section = "main";
$this->position = 50; $this->position = 50;
$this->body = "";
} }
public function add_label($text) { public function add_label($text) {

View file

@ -23,7 +23,6 @@ class SetupTheme extends Themelet {
*/ */
$setupblock_html = ""; $setupblock_html = "";
foreach($panel->blocks as $block) { foreach($panel->blocks as $block) {
$html = $this->sb_to_html($block);
$setupblock_html .= $this->sb_to_html($block); $setupblock_html .= $this->sb_to_html($block);
} }
@ -44,12 +43,10 @@ class SetupTheme extends Themelet {
global $user; global $user;
$h_rows = ""; $h_rows = "";
$n = 0;
ksort($options); ksort($options);
foreach($options as $name => $value) { foreach($options as $name => $value) {
$h_name = html_escape($name); $h_name = html_escape($name);
$h_value = html_escape($value); $h_value = html_escape($value);
$len = strlen($h_value);
$h_box = ""; $h_box = "";
if(strpos($value, "\n") > 0) { if(strpos($value, "\n") > 0) {

View file

@ -207,7 +207,7 @@ class ShimmieWebTestCase extends SCoreWebTestCase {
/** @private */ /** @private */
class TestFinder extends TestSuite { class TestFinder extends TestSuite {
function TestFinder($hint) { function __construct($hint) {
if(strpos($hint, "..") !== FALSE) return; if(strpos($hint, "..") !== FALSE) return;
// Select the test cases for "All" extensions. // Select the test cases for "All" extensions.

View file

@ -10,7 +10,7 @@ class SCoreWebReporter extends HtmlReporter {
var $fails; var $fails;
var $exceptions; var $exceptions;
public function SCoreReporter(Page $page) { public function __construct(Page $page) {
$this->page = $page; $this->page = $page;
$this->fails = 0; $this->fails = 0;
$this->exceptions = 0; $this->exceptions = 0;

View file

@ -63,7 +63,7 @@ class XMLSitemap extends Extension {
{ {
global $database, $config; global $database, $config;
// add index // add index
$index[0] = $base_href = $config->get_string("front_page"); $index[0] = $config->get_string("front_page");
$this->add_sitemap_queue($index, "weekly", "1"); $this->add_sitemap_queue($index, "weekly", "1");
/* --- Add 20 most used tags --- */ /* --- Add 20 most used tags --- */

View file

@ -93,7 +93,7 @@ class Source_History extends Extension {
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
user_ip SCORE_INET NOT NULL, user_ip SCORE_INET NOT NULL,
source TEXT NOT NULL, source TEXT NOT NULL,
date_set DATETIME NOT NULL, date_set SCORE_DATETIME NOT NULL,
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
"); ");
@ -351,7 +351,7 @@ class Source_History extends Extension {
} }
// add a history entry // add a history entry
$row = $database->execute(" $database->execute("
INSERT INTO source_histories(image_id, source, user_id, user_ip, date_set) INSERT INTO source_histories(image_id, source, user_id, user_ip, date_set)
VALUES (?, ?, ?, ?, now())", VALUES (?, ?, ?, ?, now())",
array($image->id, $new_source, $user->id, $_SERVER['REMOTE_ADDR'])); array($image->id, $new_source, $user->id, $_SERVER['REMOTE_ADDR']));

View file

@ -48,6 +48,30 @@ class TagCategories extends Extension {
} }
} }
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
if(preg_match("/^(.+)tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9]+)$/i", $event->term, $matches)) {
global $database;
$type = $matches[1];
$cmp = ltrim($matches[2], ":") ?: "=";
$count = $matches[3];
$types = $database->get_col('SELECT category FROM image_tag_categories');
if(in_array($type, $types)) {
$event->add_querylet(
new Querylet("EXISTS (
SELECT 1
FROM image_tags it
LEFT JOIN tags t ON it.tag_id = t.id
WHERE images.id = it.image_id
GROUP BY image_id
HAVING SUM(CASE WHEN t.tag LIKE '$type:%' THEN 1 ELSE 0 END) $cmp $count
)"));
}
}
}
public function getDict() { public function getDict() {
global $database; global $database;

View file

@ -43,7 +43,7 @@ class OwnerSetEvent extends Event {
var $image; var $image;
var $owner; var $owner;
public function OwnerSetEvent(Image $image, User $owner) { public function __construct(Image $image, User $owner) {
$this->image = $image; $this->image = $image;
$this->owner = $owner; $this->owner = $owner;
} }
@ -60,7 +60,7 @@ class SourceSetEvent extends Event {
var $image; var $image;
var $source; var $source;
public function SourceSetEvent(Image $image, $source) { public function __construct(Image $image, $source) {
$this->image = $image; $this->image = $image;
$this->source = $source; $this->source = $source;
} }
@ -77,7 +77,7 @@ class TagSetEvent extends Event {
var $image; var $image;
var $tags; var $tags;
public function TagSetEvent(Image $image, $tags) { public function __construct(Image $image, $tags) {
$this->image = $image; $this->image = $image;
$this->tags = Tag::explode($tags); $this->tags = Tag::explode($tags);
} }
@ -93,7 +93,7 @@ class LockSetEvent extends Event {
var $image; var $image;
var $locked; var $locked;
public function LockSetEvent(Image $image, $locked) { public function __construct(Image $image, $locked) {
assert(is_bool($locked)); assert(is_bool($locked));
$this->image = $image; $this->image = $image;
$this->locked = $locked; $this->locked = $locked;
@ -109,7 +109,7 @@ class TagTermParseEvent extends Event {
var $id = null; var $id = null;
var $metatag = false; var $metatag = false;
public function TagTermParseEvent($term, $id) { public function __construct($term, $id) {
$this->term = $term; $this->term = $term;
$this->id = $id; $this->id = $id;
} }
@ -243,8 +243,8 @@ class TagEdit extends Extension {
global $database; global $database;
global $config; global $config;
$search_set = Tag::explode(strtolower($search)); $search_set = Tag::explode(strtolower($search), false);
$replace_set = Tag::explode(strtolower($replace)); $replace_set = Tag::explode(strtolower($replace), false);
log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'"); log_info("tag_edit", "Mass editing tags: '$search' -> '$replace'");
@ -266,17 +266,19 @@ class TagEdit extends Extension {
// search returns high-ids first, so we want to look // search returns high-ids first, so we want to look
// at images with lower IDs than the previous. // at images with lower IDs than the previous.
$search_forward = $search_set; $search_forward = $search_set;
if($last_id >= 0) $search_forward[] = "id<$last_id"; $search_forward[] = "order=id_desc"; //Default order can be changed, so make sure we order high > low ID
if($last_id >= 0){
$search_forward[] = "id<$last_id";
}
$images = Image::find_images(0, 100, $search_forward); $images = Image::find_images(0, 100, $search_forward);
if(count($images) == 0) break; if(count($images) == 0) break;
foreach($images as $image) { foreach($images as $image) {
// remove the search'ed tags // remove the search'ed tags
$before = $image->get_tag_array(); $before = array_map('strtolower', $image->get_tag_array());
$after = array(); $after = array();
foreach($before as $tag) { foreach($before as $tag) {
$tag = strtolower($tag);
if(!in_array($tag, $search_set)) { if(!in_array($tag, $search_set)) {
$after[] = $tag; $after[] = $tag;
} }

View file

@ -83,8 +83,9 @@ class TagEditCloud extends Extension {
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break; break;
case 'r': case 'r':
$relevant_tags = implode(",",array_map(array($database,"escape"),array_diff($image->get_tag_array(),$ignore_tags))); $relevant_tags = array_diff($image->get_tag_array(),$ignore_tags);
if(count($relevant_tags) > 0) { if(count($relevant_tags) > 0) {
$relevant_tags = implode(",",array_map(array($database,"escape"),$relevant_tags));
$tag_data = $database->get_all("SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled $tag_data = $database->get_all("SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled
FROM image_tags it1 JOIN image_tags it2 USING(image_id) JOIN tags t1 ON it1.tag_id = t1.id JOIN tags t2 ON it2.tag_id = t2.id FROM image_tags it1 JOIN image_tags it2 USING(image_id) JOIN tags t1 ON it1.tag_id = t1.id JOIN tags t2 ON it2.tag_id = t2.id
WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) GROUP BY t2.tag ORDER BY count DESC LIMIT :limit", WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) GROUP BY t2.tag ORDER BY count DESC LIMIT :limit",

View file

@ -93,7 +93,7 @@ class Tag_History extends Extension {
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
user_ip SCORE_INET NOT NULL, user_ip SCORE_INET NOT NULL,
tags TEXT NOT NULL, tags TEXT NOT NULL,
date_set DATETIME NOT NULL, date_set SCORE_DATETIME NOT NULL,
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE, FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
"); ");
@ -103,7 +103,7 @@ class Tag_History extends Extension {
if($config->get_int("ext_tag_history_version") == 1) { if($config->get_int("ext_tag_history_version") == 1) {
$database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL"); $database->Execute("ALTER TABLE tag_histories ADD COLUMN user_id INTEGER NOT NULL");
$database->Execute("ALTER TABLE tag_histories ADD COLUMN date_set DATETIME NOT NULL"); $database->Execute($database->scoreql_to_sql("ALTER TABLE tag_histories ADD COLUMN date_set SCORE_DATETIME NOT NULL"));
$config->set_int("ext_tag_history_version", 2); $config->set_int("ext_tag_history_version", 2);
} }

View file

@ -45,16 +45,19 @@ class TagList extends Extension {
} }
$this->theme->display_page($page); $this->theme->display_page($page);
} }
else if($event->page_matches("api/internal/tag_list/complete")) {
if($event->page_matches("api/internal/tag_list/complete")) {
if(!isset($_GET["s"])) return; if(!isset($_GET["s"])) return;
$all = $database->get_all( $limit = 0;
"SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 LIMIT 10", $limitSQL = "";
array("search"=>$_GET["s"]."%")); $SQLarr = array("search"=>$_GET["s"]."%");
if(isset($_GET["limit"]) && $_GET["limit"] !== 0){
$limitSQL = "LIMIT :limit";
$SQLarr['limit'] = $_GET["limit"];
}
$res = array(); $res = $database->get_col(
foreach($all as $row) {$res[] = $row["tag"];} "SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 $limitSQL", $SQLarr);
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("text/plain"); $page->set_type("text/plain");

View file

@ -80,7 +80,6 @@ class TaggerXML extends Extension {
$q_where = "WHERE {$match} {$hidden} AND count > 0"; $q_where = "WHERE {$match} {$hidden} AND count > 0";
// FROM based on return count // FROM based on return count
$q_from = null;
$count = $this->count($q_where,$values); $count = $this->count($q_where,$values);
if ($count > $max_rows) { if ($count > $max_rows) {
$q_from = "FROM (SELECT * FROM `tags` {$q_where} ". $q_from = "FROM (SELECT * FROM `tags` {$q_where} ".
@ -139,25 +138,5 @@ class TaggerXML extends Extension {
return $database->Execute( return $database->Execute(
"SELECT COUNT(*) FROM `tags` $query",$values)->fields['COUNT(*)']; "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;
}
} }
?> ?>

View file

@ -65,7 +65,6 @@ class TipsTheme extends Themelet {
$html .= "</tr></thead>"; $html .= "</tr></thead>";
$n = 0;
foreach ($tips as $tip) { foreach ($tips as $tip) {
$tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No"; $tip_enable = ($tip['enable'] == "Y") ? "Yes" : "No";
$set_link = "<a href='".make_link("tips/status/".$tip['id'])."'>".$tip_enable."</a>"; $set_link = "<a href='".make_link("tips/status/".$tip['id'])."'>".$tip_enable."</a>";

View file

@ -75,6 +75,22 @@ class Upgrade extends Extension {
log_info("upgrade", "Database at version 11"); log_info("upgrade", "Database at version 11");
$config->set_bool("in_upgrade", false); $config->set_bool("in_upgrade", false);
} }
if($config->get_int("db_version") < 12) {
$config->set_bool("in_upgrade", true);
$config->set_int("db_version", 12);
if($database->get_driver_name() == 'pgsql') {
log_info("upgrade", "Changing ext column to VARCHAR");
$database->execute("ALTER TABLE images ALTER COLUMN ext SET DATA TYPE VARCHAR(4)");
}
log_info("upgrade", "Lowering case of all exts");
$database->execute("UPDATE images SET ext = LOWER(ext)");
log_info("upgrade", "Database at version 12");
$config->set_bool("in_upgrade", false);
}
} }
public function get_priority() {return 5;} public function get_priority() {return 5;}

View file

@ -19,7 +19,7 @@ class DataUploadEvent extends Event {
* @param $tmpname The temporary file used for upload. * @param $tmpname The temporary file used for upload.
* @param $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source". * @param $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source".
*/ */
public function DataUploadEvent(/*string*/ $tmpname, /*array*/ $metadata) { public function __construct(/*string*/ $tmpname, /*array*/ $metadata) {
assert(file_exists($tmpname)); assert(file_exists($tmpname));
$this->tmpname = $tmpname; $this->tmpname = $tmpname;
@ -49,6 +49,7 @@ class Upload extends Extension {
global $config; global $config;
$config->set_default_int('upload_count', 3); $config->set_default_int('upload_count', 3);
$config->set_default_int('upload_size', '1MB'); $config->set_default_int('upload_size', '1MB');
$config->set_default_bool('upload_tlsource', TRUE);
// SHIT: fucking PHP "security" measures -_-;;; // SHIT: fucking PHP "security" measures -_-;;;
$free_num = @disk_free_space(realpath("./images/")); $free_num = @disk_free_space(realpath("./images/"));
@ -90,6 +91,7 @@ class Upload extends Extension {
$sb->add_shorthand_int_option("upload_size", "<br/>Max size per file: "); $sb->add_shorthand_int_option("upload_size", "<br/>Max size per file: ");
$sb->add_label("<i>PHP Limit = ".ini_get('upload_max_filesize')."</i>"); $sb->add_label("<i>PHP Limit = ".ini_get('upload_max_filesize')."</i>");
$sb->add_choice_option("transload_engine", $tes, "<br/>Transload: "); $sb->add_choice_option("transload_engine", $tes, "<br/>Transload: ");
$sb->add_bool_option("upload_tlsource", "<br/>Use transloaded URL as source if none is provided: ");
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
@ -350,7 +352,7 @@ class Upload extends Extension {
$metadata['filename'] = $filename; $metadata['filename'] = $filename;
$metadata['extension'] = getExtension($headers['Content-Type']) ?: $pathinfo['extension']; $metadata['extension'] = getExtension($headers['Content-Type']) ?: $pathinfo['extension'];
$metadata['tags'] = $tags; $metadata['tags'] = $tags;
$metadata['source'] = $source; $metadata['source'] = (($url == $source) && !$config->get_bool('upload_tlsource') ? "" : $source);
/* check for locked > adds to metadata if it has */ /* check for locked > adds to metadata if it has */
if(!empty($locked)){ if(!empty($locked)){

View file

@ -31,7 +31,7 @@ class ImageInfoBoxBuildingEvent extends Event {
var $image; var $image;
var $user; var $user;
public function ImageInfoBoxBuildingEvent(Image $image, User $user) { public function __construct(Image $image, User $user) {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
} }
@ -45,7 +45,7 @@ class ImageInfoBoxBuildingEvent extends Event {
class ImageInfoSetEvent extends Event { class ImageInfoSetEvent extends Event {
var $image; var $image;
public function ImageInfoSetEvent(Image $image) { public function __construct(Image $image) {
$this->image = $image; $this->image = $image;
} }
} }
@ -55,7 +55,7 @@ class ImageAdminBlockBuildingEvent extends Event {
var $image = null; var $image = null;
var $user = null; var $user = null;
public function ImageAdminBlockBuildingEvent(Image $image, User $user) { public function __construct(Image $image, User $user) {
$this->image = $image; $this->image = $image;
$this->user = $user; $this->user = $user;
} }
@ -70,11 +70,7 @@ class ViewImage extends Extension {
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $page, $user; global $page, $user;
if( if($event->page_matches("post/prev") || $event->page_matches("post/next")) {
$event->page_matches("post/prev") ||
$event->page_matches("post/next")
) {
$image_id = int_escape($event->get_arg(0)); $image_id = int_escape($event->get_arg(0));
if(isset($_GET['search'])) { if(isset($_GET['search'])) {
@ -107,8 +103,7 @@ class ViewImage extends Extension {
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("post/view/{$image->id}", $query)); $page->set_redirect(make_link("post/view/{$image->id}", $query));
} }
else if($event->page_matches("post/view")) {
if($event->page_matches("post/view")) {
$image_id = int_escape($event->get_arg(0)); $image_id = int_escape($event->get_arg(0));
$image = Image::by_id($image_id); $image = Image::by_id($image_id);
@ -124,8 +119,7 @@ class ViewImage extends Extension {
$this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id"); $this->theme->display_error(404, "Image not found", "No image in the database has the ID #$image_id");
} }
} }
else if($event->page_matches("post/set")) {
if($event->page_matches("post/set")) {
if(!isset($_POST['image_id'])) return; if(!isset($_POST['image_id'])) return;
$image_id = int_escape($_POST['image_id']); $image_id = int_escape($_POST['image_id']);

View file

@ -12,7 +12,7 @@ class WikiUpdateEvent extends Event {
var $user; var $user;
var $wikipage; var $wikipage;
public function WikiUpdateEvent(User $user, WikiPage $wikipage) { public function __construct(User $user, WikiPage $wikipage) {
$this->user = $user; $this->user = $user;
$this->wikipage = $wikipage; $this->wikipage = $wikipage;
} }
@ -31,7 +31,7 @@ class WikiPage {
var $locked; var $locked;
var $body; var $body;
public function WikiPage($row) { public function __construct($row) {
assert(!empty($row)); assert(!empty($row));
$this->id = $row['id']; $this->id = $row['id'];
@ -63,7 +63,7 @@ class Wiki extends Extension {
id SCORE_AIPK, id SCORE_AIPK,
owner_id INTEGER NOT NULL, owner_id INTEGER NOT NULL,
owner_ip SCORE_INET NOT NULL, owner_ip SCORE_INET NOT NULL,
date DATETIME DEFAULT NULL, date SCORE_DATETIME DEFAULT NULL,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
revision INTEGER NOT NULL DEFAULT 1, revision INTEGER NOT NULL DEFAULT 1,
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
@ -157,7 +157,7 @@ class Wiki extends Extension {
global $database; global $database;
$wpage = $event->wikipage; $wpage = $event->wikipage;
try { try {
$row = $database->Execute(" $database->Execute("
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body) INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
VALUES (?, ?, now(), ?, ?, ?, ?)", array($event->user->id, $_SERVER['REMOTE_ADDR'], VALUES (?, ?, now(), ?, ?, ?, ?)", array($event->user->id, $_SERVER['REMOTE_ADDR'],
$wpage->title, $wpage->rev, $wpage->locked?'Y':'N', $wpage->body)); $wpage->title, $wpage->rev, $wpage->locked?'Y':'N', $wpage->body));

View file

@ -39,7 +39,6 @@ class WikiTheme extends Themelet {
protected function create_edit_html(WikiPage $page) { protected function create_edit_html(WikiPage $page) {
$h_title = html_escape($page->title); $h_title = html_escape($page->title);
$u_title = url_escape($page->title);
$i_revision = int_escape($page->revision) + 1; $i_revision = int_escape($page->revision) + 1;
global $user; global $user;

View file

@ -8,17 +8,20 @@ $(document).ready(function() {
//TODO: Possibly move to using TextExtJS for autocomplete? - http://textextjs.com/ //TODO: Possibly move to using TextExtJS for autocomplete? - http://textextjs.com/
// Also use autocomplete in tag box? // Also use autocomplete in tag box?
$('.autocomplete_tags').autocomplete(base_href + '/api/internal/tag_list/complete', { $('.autocomplete_tags').autocomplete(base_href + '/api/internal/tag_list/complete', {
width: 320, //extraParams: {limit: 10},
max: 15,
highlight: false,
multiple: true,
multipleSeparator: ' ',
scroll: true,
scrollHeight: 300,
selectFirst: false,
queryParamName: 's', queryParamName: 's',
delay: 150, minChars: 1,
minChars: 1 delay: 0,
useCache: true,
maxCacheLength: 10,
matchInside: false,
selectFirst: true,
selectOnly: false,
preventDefaultReturn: 1,
preventDefaultTab: 1,
useDelimiter: true,
delimiterChar : " ",
delimiterKeyCode : 48
}); });
$("TABLE.sortable").tablesorter(); $("TABLE.sortable").tablesorter();

View file

@ -231,8 +231,8 @@ $header_html
Images &copy; their respective owners, Images &copy; their respective owners,
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy; <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
<a href="http://www.shishnet.org/">Shish</a> &amp; <a href="http://www.shishnet.org/">Shish</a> &amp;
<a href="https://github.com/shish/shimmie2/contributors">The Team</a> <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
2007-2012, 2007-2014,
based on the Danbooru concept. based on the Danbooru concept.
$debug $debug
$contact $contact

View file

@ -21,7 +21,6 @@ class Themelet extends BaseThemelet {
private function build_paginator($current_page, $total_pages, $base_url, $query) { private function build_paginator($current_page, $total_pages, $base_url, $query) {
$next = $current_page + 1; $next = $current_page + 1;
$prev = $current_page - 1; $prev = $current_page - 1;
$rand = mt_rand(1, $total_pages);
$at_start = ($current_page <= 3 || $total_pages <= 3); $at_start = ($current_page <= 3 || $total_pages <= 3);
$at_end = ($current_page >= $total_pages -2); $at_end = ($current_page >= $total_pages -2);

View file

@ -35,7 +35,6 @@ class CustomUserPageTheme extends UserPageTheme {
} }
public function display_user_block(Page $page, User $user, $parts) { public function display_user_block(Page $page, User $user, $parts) {
$h_name = html_escape($user->name);
$html = ""; $html = "";
$blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile"); $blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile");
foreach($parts as $part) { foreach($parts as $part) {

View file

@ -254,11 +254,11 @@ $header_html
</article> </article>
<footer><div> <footer><div>
Running Shimmie &ndash; Running Shimmie &ndash;
Images &copy; their respective owners &ndash; Images &copy; their respective owners,
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy; <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
<a href="http://www.shishnet.org/">Shish</a> &amp; <a href="http://www.shishnet.org/">Shish</a> &amp;
<a href="https://github.com/shish/shimmie2/contributors">The Team</a> <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
2007-2012, 2007-2014,
based on the Danbooru concept<br /> based on the Danbooru concept<br />
$debug $debug
$contact $contact

View file

@ -21,7 +21,6 @@ class Themelet extends BaseThemelet {
private function build_paginator($current_page, $total_pages, $base_url, $query) { private function build_paginator($current_page, $total_pages, $base_url, $query) {
$next = $current_page + 1; $next = $current_page + 1;
$prev = $current_page - 1; $prev = $current_page - 1;
$rand = mt_rand(1, $total_pages);
$at_start = ($current_page <= 3 || $total_pages <= 3); $at_start = ($current_page <= 3 || $total_pages <= 3);
$at_end = ($current_page >= $total_pages -2); $at_end = ($current_page >= $total_pages -2);

View file

@ -35,7 +35,6 @@ class CustomUserPageTheme extends UserPageTheme {
} }
public function display_user_block(Page $page, User $user, $parts) { public function display_user_block(Page $page, User $user, $parts) {
$h_name = html_escape($user->name);
$html = ""; $html = "";
$blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile"); $blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile");
foreach($parts as $part) { foreach($parts as $part) {

View file

@ -83,8 +83,8 @@ $header_html
Images &copy; their respective owners, Images &copy; their respective owners,
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy; <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
<a href="http://www.shishnet.org/">Shish</a> &amp; <a href="http://www.shishnet.org/">Shish</a> &amp;
<a href="https://github.com/shish/shimmie2/contributors">The Team</a> <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
2007-2012, 2007-2014,
based on the Danbooru concept. based on the Danbooru concept.
$debug $debug
$contact $contact

View file

@ -56,7 +56,7 @@ class CustomCommentListTheme extends CommentListTheme {
} }
protected function comment_to_html(Comment $comment, $trim=false) { protected function comment_to_html($comment, $trim=false) {
$inner_id = $this->inner_id; // because custom themes can't add params, because PHP $inner_id = $this->inner_id; // because custom themes can't add params, because PHP
global $user; global $user;

View file

@ -1,7 +1,7 @@
<?php <?php
class Layout { class Layout {
function display_page($page) { function display_page(Page $page) {
global $config; global $config;
$theme_name = $config->get_string('theme', 'default'); $theme_name = $config->get_string('theme', 'default');
@ -90,8 +90,8 @@ $header_html
Images &copy; their respective owners, Images &copy; their respective owners,
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy; <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
<a href="http://www.shishnet.org/">Shish</a> &amp; <a href="http://www.shishnet.org/">Shish</a> &amp;
<a href="https://github.com/shish/shimmie2/contributors">The Team</a> <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
2007-2012, 2007-2014,
based on the Danbooru concept. based on the Danbooru concept.
<br>Futaba theme based on 4chan's layout and CSS :3 <br>Futaba theme based on 4chan's layout and CSS :3
$debug $debug

View file

@ -75,7 +75,6 @@ class Layout {
} }
$custom_sublinks = "<div class='sbar'>"; $custom_sublinks = "<div class='sbar'>";
$cs = null;
// hack // hack
global $user; global $user;
$username = url_escape($user->name); $username = url_escape($user->name);
@ -190,8 +189,8 @@ class Layout {
Images &copy; their respective owners, Images &copy; their respective owners,
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy; <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
<a href="http://www.shishnet.org/">Shish</a> &amp; <a href="http://www.shishnet.org/">Shish</a> &amp;
<a href="https://github.com/shish/shimmie2/contributors">The Team</a> <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
2007-2012, 2007-2014,
based on the Danbooru concept.<br /> based on the Danbooru concept.<br />
Lite Theme by <a href="http://seemslegit.com">Zach</a> Lite Theme by <a href="http://seemslegit.com">Zach</a>
$debug $debug

View file

@ -1,7 +1,7 @@
<?php <?php
class CustomUserPageTheme extends UserPageTheme { class CustomUserPageTheme extends UserPageTheme {
public function display_login_page($page) { public function display_login_page(Page $page) {
global $config; global $config;
$page->set_title("Login"); $page->set_title("Login");
$page->set_heading("Login"); $page->set_heading("Login");
@ -27,14 +27,14 @@ class CustomUserPageTheme extends UserPageTheme {
$page->add_block(new Block("Login", $html, "main", 90)); $page->add_block(new Block("Login", $html, "main", 90));
} }
public function display_user_links($page, $user, $parts) { public function display_user_links(Page $page, User $user, $parts) {
// no block in this theme // no block in this theme
} }
public function display_login_block(Page $page) { public function display_login_block(Page $page) {
// no block in this theme // no block in this theme
} }
public function display_user_block($page, $user, $parts) { public function display_user_block(Page $page, User $user, $parts) {
$h_name = html_escape($user->name); $h_name = html_escape($user->name);
$html = ""; $html = "";
$blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile"); $blocked = array("Pools", "Pool Changes", "Alias Editor", "My Profile");
@ -45,7 +45,7 @@ class CustomUserPageTheme extends UserPageTheme {
$page->add_block(new Block("User Links", $html, "user", 90)); $page->add_block(new Block("User Links", $html, "user", 90));
} }
public function display_signup_page($page) { public function display_signup_page(Page $page) {
global $config; global $config;
$tac = $config->get_string("login_tac", ""); $tac = $config->get_string("login_tac", "");
@ -74,7 +74,7 @@ class CustomUserPageTheme extends UserPageTheme {
$page->add_block(new Block("Signup", $html)); $page->add_block(new Block("Signup", $html));
} }
public function display_ip_list($page, $uploads, $comments) { public function display_ip_list(Page $page, $uploads, $comments) {
$html = "<table id='ip-history' style='width: 400px;'>"; $html = "<table id='ip-history' style='width: 400px;'>";
$html .= "<tr><td>Uploaded from: "; $html .= "<tr><td>Uploaded from: ";
foreach($uploads as $ip => $count) { foreach($uploads as $ip => $count) {

View file

@ -1,7 +1,7 @@
<?php <?php
class CustomViewImageTheme extends ViewImageTheme { class CustomViewImageTheme extends ViewImageTheme {
public function display_page($image, $editor_parts) { public function display_page(Image $image, $editor_parts) {
global $page; global $page;
$metatags = str_replace(" ", ", ", html_escape($image->get_tag_list())); $metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list())); $page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
@ -17,7 +17,7 @@ class CustomViewImageTheme extends ViewImageTheme {
$page->add_block(new Block(null, $this->build_pin($image), "main", 11)); $page->add_block(new Block(null, $this->build_pin($image), "main", 11));
} }
private function build_stats($image) { private function build_stats(Image $image) {
$h_owner = html_escape($image->get_owner()->name); $h_owner = html_escape($image->get_owner()->name);
$h_ownerlink = "<a href='".make_link("user/$h_owner")."'>$h_owner</a>"; $h_ownerlink = "<a href='".make_link("user/$h_owner")."'>$h_owner</a>";
$h_ip = html_escape($image->owner_ip); $h_ip = html_escape($image->owner_ip);

Some files were not shown because too many files have changed in this diff Show more