more comments

This commit is contained in:
Shish 2015-09-27 12:38:48 +01:00
parent 80f5a016c2
commit 1ac88e8923
27 changed files with 195 additions and 160 deletions

View File

@ -950,21 +950,19 @@ function transload($url, $mfile) {
}
if($config->get_string("transload_engine") === "fopen") {
$fp = @fopen($url, "r");
if(!$fp) {
$fp_in = @fopen($url, "r");
$fp_out = fopen($mfile, "w");
if(!$fp_in || !$fp_out) {
return false;
}
$data = "";
$length = 0;
while(!feof($fp) && $length <= $config->get_int('upload_size')) {
$data .= fread($fp, 8192);
$length = strlen($data);
while(!feof($fp_in) && $length <= $config->get_int('upload_size')) {
$data = fread($fp_in, 8192);
$length += strlen($data);
fwrite($fp_out, $data);
}
fclose($fp);
$fp = fopen($mfile, "w");
fwrite($fp, $data);
fclose($fp);
fclose($fp_in);
fclose($fp_out);
$headers = http_parse_headers(implode("\n", $http_response_header));

View File

@ -321,44 +321,15 @@ class DanbooruApi extends Extension {
$source = null;
}
} elseif (isset($_REQUEST['source']) || isset($_REQUEST['post']['source'])) { // A url was provided
$url = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source'];
$source = $url;
$tmp_filename = tempnam("/tmp", "shimmie_transload");
// Are we using fopen wrappers or curl?
if ($config->get_string("transload_engine") == "fopen") {
$fp = fopen($url, "r");
if (!$fp) {
$page->set_code(409);
$page->add_http_header("X-Danbooru-Errors: fopen read error");
}
$data = "";
$length = 0;
while (!feof($fp) && $length <= $config->get_int('upload_size')) {
$data .= fread($fp, 8192);
$length = strlen($data);
}
fclose($fp);
$fp = fopen($tmp_filename, "w");
fwrite($fp, $data);
fclose($fp);
$source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $_REQUEST['post']['source'];
$file = tempnam("/tmp", "shimmie_transload");
$ok = transload($source, $file);
if (!$ok) {
$page->set_code(409);
$page->add_http_header("X-Danbooru-Errors: fopen read error");
return;
}
if ($config->get_string("transload_engine") == "curl") {
$ch = curl_init($url);
$fp = fopen($tmp_filename, "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
$file = $tmp_filename;
$filename = basename($url);
$filename = basename($source);
} else { // Nothing was specified at all
$page->set_code(409);
$page->add_http_header("X-Danbooru-Errors: no input files");
@ -367,8 +338,9 @@ class DanbooruApi extends Extension {
// Get tags out of url
$posttags = Tag::explode(isset($_REQUEST['tags']) ? $_REQUEST['tags'] : $_REQUEST['post']['tags']);
$hash = md5_file($file);
// Was an md5 supplied? Does it match the file hash?
$hash = md5_file($file);
if (isset($_REQUEST['md5']) && strtolower($_REQUEST['md5']) != $hash) {
$page->set_code(409);
$page->add_http_header("X-Danbooru-Errors: md5 mismatch");

View File

@ -23,7 +23,7 @@ class ExtensionInfo {
var $description, $documentation, $version, $visibility;
var $enabled;
function __construct($main) {
public function __construct($main) {
$matches = array();
$lines = file($main);
$number_of_lines = count($lines);
@ -156,7 +156,7 @@ class ExtManager extends Extension {
/**
* @param bool $all
* @return array
* @return ExtensionInfo[]
*/
private function get_extensions(/*bool*/ $all) {
$extensions = array();

View File

@ -204,7 +204,7 @@ class Favorites extends Extension {
/**
* @param Image $image
* @return array
* @return string[]
*/
private function list_persons_who_have_favorited(Image $image) {
global $database;

View File

@ -44,7 +44,7 @@ class ArchiveFileHandler extends Extension {
}
/**
* @param $ext
* @param string $ext
* @return bool
*/
private function supported_ext($ext) {

View File

@ -50,7 +50,7 @@ class FlashFileHandler extends DataHandlerExtension {
}
/**
* @param $file
* @param string $file
* @return bool
*/
protected function check_contents(/*string*/ $file) {

View File

@ -50,7 +50,7 @@ class IcoFileHandler extends Extension {
}
/**
* @param $ext
* @param string $ext
* @return bool
*/
private function supported_ext($ext) {
@ -59,8 +59,8 @@ class IcoFileHandler extends Extension {
}
/**
* @param $filename
* @param $metadata
* @param string $filename
* @param mixed[] $metadata
* @return Image
*/
private function create_image_from_data($filename, $metadata) {

View File

@ -26,7 +26,7 @@ class MP3FileHandler extends DataHandlerExtension {
/**
* @param string $filename
* @param array $metadata
* @param mixed[] $metadata
* @return Image|null
*/
protected function create_image_from_data($filename, $metadata) {

View File

@ -67,7 +67,7 @@ class PixelFileHandler extends DataHandlerExtension {
}
/**
* @param $hash
* @param string $hash
* @return bool
*/
protected function create_thumb_force(/*string*/ $hash) {
@ -91,9 +91,6 @@ class PixelFileHandler extends DataHandlerExtension {
return $ok;
}
/**
* @param ImageAdminBlockBuildingEvent $event
*/
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
$event->add_part("
<form>

View File

@ -51,7 +51,7 @@ class SVGFileHandler extends Extension {
}
/**
* @param $ext
* @param string $ext
* @return bool
*/
private function supported_ext($ext) {
@ -60,8 +60,8 @@ class SVGFileHandler extends Extension {
}
/**
* @param $filename
* @param $metadata
* @param string $filename
* @param mixed[] $metadata
* @return Image
*/
private function create_image_from_data($filename, $metadata) {
@ -82,7 +82,7 @@ class SVGFileHandler extends Extension {
}
/**
* @param $file
* @param string $file
* @return bool
*/
private function check_contents($file) {

View File

@ -118,7 +118,7 @@ class VideoFileHandler extends DataHandlerExtension {
/**
* @param string $filename
* @param array $metadata
* @param mixed[] $metadata
* @return Image|null
*/
protected function create_image_from_data($filename, $metadata) {
@ -162,7 +162,7 @@ class VideoFileHandler extends DataHandlerExtension {
}
/**
* @param $file
* @param string $file
* @return bool
*/
protected function check_contents($file) {

View File

@ -32,6 +32,9 @@ class ImageAdditionEvent extends Event {
class ImageAdditionException extends SCoreException {
var $error;
/**
* @param string $error
*/
public function __construct($error) {
$this->error = $error;
}

View File

@ -13,6 +13,9 @@
class RemoveImageHashBanEvent extends Event {
var $hash;
/**
* @param string $hash
*/
public function __construct($hash) {
$this->hash = $hash;
}
@ -23,6 +26,10 @@ class AddImageHashBanEvent extends Event {
var $hash;
var $reason;
/**
* @param string $hash
* @param string $reason
*/
public function __construct($hash, $reason) {
$this->hash = $hash;
$this->reason = $reason;
@ -126,6 +133,11 @@ class ImageBan extends Extension {
// DB funness
/**
* @param int $page
* @param int $size
* @return array
*/
public function get_image_hash_bans($page, $size=100) {
global $database;

View File

@ -3,6 +3,11 @@
class IndexTheme extends Themelet {
var $page_number, $total_pages, $search_terms;
/**
* @param int $page_number
* @param int $total_pages
* @param string[] $search_terms
*/
public function set_page($page_number, $total_pages, $search_terms) {
$this->page_number = $page_number;
$this->total_pages = $total_pages;
@ -27,6 +32,10 @@ and of course start organising your images :-)
$page->add_block(new Block("Installation Succeeded!", $text, "main", 0));
}
/**
* @param Page $page
* @param Image[] $images
*/
public function display_page(Page $page, $images) {
$this->display_page_header($page, $images);
@ -41,12 +50,21 @@ and of course start organising your images :-)
}
}
public function display_admin_block(/*array(string)*/ $parts) {
/**
* @param string[] $parts
*/
public function display_admin_block($parts) {
global $page;
$page->add_block(new Block("List Controls", join("<br>", $parts), "left", 50));
}
/**
* @param int $page_number
* @param int $total_pages
* @param string[] $search_terms
* @return string
*/
protected function build_navigation($page_number, $total_pages, $search_terms) {
$prev = $page_number - 1;
$next = $page_number + 1;
@ -72,6 +90,11 @@ and of course start organising your images :-)
return $h_prev.' | '.$h_index.' | '.$h_next.'<br>'.$h_search;
}
/**
* @param Image[] $images
* @param string $query
* @return string
*/
protected function build_table($images, $query) {
$h_query = html_escape($query);
$table = "<div class='shm-image-list' data-query='$h_query'>";
@ -82,6 +105,10 @@ and of course start organising your images :-)
return $table;
}
/**
* @param Page $page
* @param Image[] $images
*/
protected function display_page_header(Page $page, $images) {
global $config;
@ -102,6 +129,10 @@ and of course start organising your images :-)
$page->set_heading($page_title);
}
/**
* @param Page $page
* @param Image[] $images
*/
protected function display_page_images(Page $page, $images) {
if (count($this->search_terms) > 0) {
$query = url_escape(implode(' ', $this->search_terms));

View File

@ -16,62 +16,54 @@ class MassTagger extends Extension {
public function onPostListBuilding(PostListBuildingEvent $event) {
global $config, $page, $user;
if( !$user->is_admin() ) return;
$this->theme->display_mass_tagger( $page, $event, $config );
if($user->is_admin()) {
$this->theme->display_mass_tagger( $page, $event, $config );
}
}
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
if( !$event->page_matches("mass_tagger") ) return;
if( !$user->is_admin() ) return;
if($event->get_arg(0) == "tag") $this->_apply_mass_tags( $config, $page, $user, $event );
}
private function _apply_mass_tags( $config, Page $page, $user, $event ) {
if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return;
$tag = $_POST['tag'];
$tag_array = explode(" ",$tag);
$pos_tag_array = array();
$neg_tag_array = array();
foreach($tag_array as $new_tag) {
if (strpos($new_tag, '-') === 0)
$neg_tag_array[] = substr($new_tag,1);
else
$pos_tag_array[] = $new_tag;
}
$ids = explode( ':', $_POST['ids'] );
$ids = array_filter ( $ids , 'is_numeric' );
$images = array_map( "Image::by_id", $ids );
if(isset($_POST['setadd']) &&
$_POST['setadd'] == 'set')
{
foreach($images as $image) {
$image->set_tags(Tag::explode($tag));
}
}
else
{
foreach($images as $image) {
if (!empty($neg_tag_array)) {
$img_tags = array_merge($pos_tag_array, explode(" ",$image->get_tag_list()));
$img_tags = array_diff($img_tags, $neg_tag_array);
$image->set_tags(Tag::explode($img_tags));
}
global $page, $user;
if($event->page_matches("mass_tagger/tag") && $user->is_admin()) {
if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return;
$tag = $_POST['tag'];
$tag_array = explode(" ",$tag);
$pos_tag_array = array();
$neg_tag_array = array();
foreach($tag_array as $new_tag) {
if (strpos($new_tag, '-') === 0)
$neg_tag_array[] = substr($new_tag,1);
else
$image->set_tags(Tag::explode($tag . " " . $image->get_tag_list()));
$pos_tag_array[] = $new_tag;
}
$ids = explode( ':', $_POST['ids'] );
$ids = array_filter ( $ids , 'is_numeric' );
$images = array_map( "Image::by_id", $ids );
if(isset($_POST['setadd']) && $_POST['setadd'] == 'set') {
foreach($images as $image) {
$image->set_tags(Tag::explode($tag));
}
}
else {
foreach($images as $image) {
if (!empty($neg_tag_array)) {
$img_tags = array_merge($pos_tag_array, explode(" ",$image->get_tag_list()));
$img_tags = array_diff($img_tags, $neg_tag_array);
$image->set_tags(Tag::explode($img_tags));
}
else
$image->set_tags(Tag::explode($tag . " " . $image->get_tag_list()));
}
}
$page->set_mode("redirect");
if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = make_link();
$page->set_redirect($_SERVER['HTTP_REFERER']);
}
$page->set_mode("redirect");
if(!isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] = make_link();
$page->set_redirect($_SERVER['HTTP_REFERER']);
}
}

View File

@ -28,7 +28,10 @@ class NotATag extends Extension {
$this->scan($event->tags);
}
private function scan(/*array*/ $tags_mixed) {
/**
* @param string[] $tags_mixed
*/
private function scan($tags_mixed) {
global $database;
$tags = array();
@ -90,6 +93,11 @@ class NotATag extends Extension {
}
}
/**
* @param int $page
* @param int $size
* @return array
*/
public function get_untags($page, $size=100) {
global $database;

View File

@ -13,7 +13,12 @@
class NumericScoreSetEvent extends Event {
var $image_id, $user, $score;
public function __construct(/*int*/ $image_id, User $user, /*int*/ $score) {
/**
* @param int $image_id
* @param User $user
* @param int $score
*/
public function __construct($image_id, User $user, $score) {
$this->image_id = $image_id;
$this->user = $user;
$this->score = $score;
@ -168,7 +173,10 @@ class NumericScore extends Extension {
$this->delete_votes_by($event->id);
}
public function delete_votes_by(/*int*/ $user_id) {
/**
* @param int $user_id
*/
public function delete_votes_by($user_id) {
global $database;
$image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id));
@ -290,7 +298,7 @@ class NumericScore extends Extension {
* @param int $user_id
* @param int $score
*/
private function add_vote(/*int*/ $image_id, /*int*/ $user_id, /*int*/ $score) {
private function add_vote($image_id, $user_id, $score) {
global $database;
$database->execute(
"DELETE FROM numeric_score_votes WHERE image_id=:imageid AND user_id=:userid",

View File

@ -260,13 +260,13 @@ class Pools extends Extension {
if($config->get_bool("poolsInfoOnViewImage")) {
$imageID = $event->image->id;
$poolsIDs = $this->get_pool_id($imageID);
$poolsIDs = $this->get_pool_ids($imageID);
$show_nav = $config->get_bool("poolsShowNavLinks", false);
$navInfo = array();
foreach($poolsIDs as $poolID) {
$pool = $this->get_single_pool($poolID['pool_id']);
$pool = $this->get_single_pool($poolID);
$navInfo[$pool['id']] = array();
$navInfo[$pool['id']]['info'] = $pool;
@ -411,7 +411,7 @@ class Pools extends Extension {
/**
* HERE WE CREATE A NEW POOL
*
* @return mixed
* @return int
* @throws PoolCreationException
*/
private function add_pool() {
@ -433,12 +433,9 @@ class Pools extends Extension {
VALUES (:uid, :public, :title, :desc, now())",
array("uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"]));
$result = array();
$result['poolID'] = $database->get_last_insert_id('pools_id_seq');
log_info("pools", "Pool {$result["poolID"]} created by {$user->name}");
return $result["poolID"];
$poolID = $database->get_last_insert_id('pools_id_seq');
log_info("pools", "Pool {$poolID} created by {$user->name}");
return $poolID;
}
/**
@ -477,11 +474,11 @@ class Pools extends Extension {
/**
* Get all of the pool IDs that an image is in, given an image ID.
* @param int $imageID Integer ID for the image
* @return array
* @return int[]
*/
private function get_pool_id(/*int*/ $imageID) {
private function get_pool_ids(/*int*/ $imageID) {
global $database;
return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID));
}
/**

View File

@ -141,7 +141,10 @@ class ReportImage extends Extension {
$this->delete_reports_by($event->id);
}
public function delete_reports_by(/*int*/ $user_id) {
/**
* @param int $user_id
*/
public function delete_reports_by($user_id) {
global $database;
$database->execute("DELETE FROM image_reports WHERE reporter_id=?", array($user_id));
$database->cache->delete("image-report-count");
@ -165,7 +168,7 @@ class ReportImage extends Extension {
/**
* @param Image $image
* @return array
* @return string[]
*/
public function get_reporters(Image $image) {
global $database;
@ -206,7 +209,7 @@ class ReportImage extends Extension {
}
/**
* @return mixed
* @return int
*/
public function count_reported_images() {
global $database;
@ -220,13 +223,3 @@ class ReportImage extends Extension {
return $count;
}
}
// ===== Changelog =====
// * Version 0.3a / 0.3a_rc - 11/06/07 - I can no longer use the same theme.php file for both SVN and RCx. Sorry.
// * Same deal with theme.php as it is with main.php
// * Version 0.3 / 0.3_rc - 11/06/07 - Added the option to display thumbnails, moved the reported image list to it's
// own page, and checked to make sure the user is an admin before letting them delete / view reported images.
// * Version 0.2c_rc2 - 10/27/07 - Now (really!) supports Shimmie2 RC2!
// * Version 0.2b - 10/27/07 - Now supports Shimmie2 RC2!
// * Version 0.2a - 10/24/07 - Fixed some SQL issues. I will make sure to test before commiting :)
// * Version 0.2 - 10/24/07 - First public release.

View File

@ -291,7 +291,7 @@ class ResizeImage extends Extension {
* http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize
*
* @param $info
* @return array
* @return int
*/
private function calc_memory_use($info) {
if (isset($info['bits']) && isset($info['channels'])) {
@ -308,7 +308,7 @@ class ResizeImage extends Extension {
* @param Image $image_obj
* @param $width
* @param $height
* @return array
* @return int[]
*/
private function calc_new_size(Image $image_obj, $width, $height) {
/* Calculate the new size of the image */

View File

@ -113,7 +113,7 @@ class ShimmieApi extends Extension {
/**
* @param string $arg
* @return array
* @return string[]
*/
private function api_get_tags($arg) {
global $database;

View File

@ -234,8 +234,8 @@ class Upload extends Extension {
}
/**
* @param string|int $id
* @return array
* @param int $id
* @return string[]
*/
private function tags_for_upload_slot($id) {
if(isset($_POST["tags$id"])) {

View File

@ -30,7 +30,7 @@ class Themelet extends BaseThemelet {
* @param string $base_url
* @param string $query
* @param int|string $page
* @param int|string $current_page
* @param int $current_page
* @param string $name
* @return string
*/

View File

@ -1,6 +1,10 @@
<?php
class CustomIndexTheme extends IndexTheme {
/**
* @param Page $page
* @param Image[] $images
*/
public function display_page(Page $page, $images) {
global $config;
@ -33,7 +37,12 @@ class CustomIndexTheme extends IndexTheme {
}
}
/**
* @param int $page_number
* @param int $total_pages
* @param string[] $search_terms
* @return string
*/
protected function build_navigation($page_number, $total_pages, $search_terms) {
$h_search_string = count($search_terms) == 0 ? "" : html_escape(implode(" ", $search_terms));
$h_search_link = make_link();
@ -48,6 +57,11 @@ class CustomIndexTheme extends IndexTheme {
return $h_search;
}
/**
* @param Image[] $images
* @param string $query
* @return string
*/
protected function build_table($images, $query) {
$h_query = html_escape($query);
$table = "<div class='shm-image-list' data-query='$h_query'>";

View File

@ -264,12 +264,18 @@ $header_html
</html>
EOD;
}
/**
* @param string $link
* @param string $desc
* @param string[] $pages_matched
* @return string
*/
private function navlinks($link, $desc, $pages_matched) {
/**
* Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.)
*/
$html = null;
$html = "";
$url = _get_query();
$re1='.*?';
@ -286,7 +292,7 @@ EOD;
$html = "<li class='current-page'><a href='$link'>$desc</a></li>";
}
}
if(is_null($html)) {$html = "<li><a class='tab' href='$link'>$desc</a></li>";}
if(empty($html)) {$html = "<li><a class='tab' href='$link'>$desc</a></li>";}
return $html;
}
}

View File

@ -30,7 +30,7 @@ class Themelet extends BaseThemelet {
* @param string $base_url
* @param string $query
* @param int|string $page
* @param int|string $current_page
* @param int $current_page
* @param string $name
* @return string
*/

View File

@ -16,7 +16,11 @@ class CustomViewImageTheme extends ViewImageTheme {
$page->add_block(new Block(null, $this->build_info($image, $editor_parts), "main", 11));
$page->add_block(new Block(null, $this->build_pin($image), "main", 11));
}
/**
* @param Image $image
* @return string
*/
private function build_stats(Image $image) {
$h_owner = html_escape($image->get_owner()->name);
$h_ownerlink = "<a href='".make_link("user/$h_owner")."'>$h_owner</a>";