Lots of linting again.

This commit is contained in:
jgen 2014-04-28 03:26:35 -04:00
parent 158819cb28
commit b56e390676
7 changed files with 100 additions and 38 deletions

View file

@ -22,7 +22,8 @@
class RandomImage extends Extension {
public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user;
global $page;
if($event->page_matches("random_image")) {
$action = '';
if($event->count_args() == 1) {
@ -34,7 +35,7 @@ class RandomImage extends Extension {
$search_terms = explode(' ', $event->get_arg(1));
}
else {
# FIXME: throw exception
throw new SCoreException("Error: too many arguments.");
}
$image = Image::by_random($search_terms);

View file

@ -5,23 +5,24 @@ class RandomImageTheme extends Themelet {
$page->add_block(new Block("Random Image", $this->build_random_html($image), "left", 8));
}
public function build_random_html(Image $image, $query=null) {
global $config;
$i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip());
$tsize = get_thumbnail_size($image->width, $image->height);
public function build_random_html(Image $image, $query=null)
{
return "
<center><div>
$i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link();
$h_tip = html_escape($image->get_tooltip());
$tsize = get_thumbnail_size($image->width, $image->height);
<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
<img id='thumb_rand_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
</a>
return "
<center><div>
</div></center>
";
<a href='$h_view_link' style='position: relative; height: {$tsize[1]}px; width: {$tsize[0]}px;'>
<img id='thumb_rand_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
</a>
</div></center>
";
}
}

View file

@ -1,4 +1,4 @@
<?php
/* needed for access to build_thumb_html */
class RandomListTheme extends Themelet {}
?>

View file

@ -20,10 +20,18 @@
*/
class RatingSetEvent extends Event {
var $image, $rating;
/** @var \Image */
public $image;
/** @var string */
public $rating;
/**
* @param Image $image
* @param string $rating
*/
public function __construct(Image $image, /*char*/ $rating) {
assert(in_array($rating, array("s", "q", "e", "u")));
$this->image = $image;
$this->rating = $rating;
}
@ -31,6 +39,9 @@ class RatingSetEvent extends Event {
class Ratings extends Extension {
/**
* @return int
*/
public function get_priority() {return 50;}
public function onInitExt(InitExtEvent $event) {
@ -69,7 +80,7 @@ class Ratings extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) {
global $user, $database, $page;
global $user, $page;
/**
* Deny images upon insufficient permissions.
**/
@ -97,8 +108,6 @@ class Ratings extends Extension {
}
public function onImageInfoSet(ImageInfoSetEvent $event) {
global $user;
if($this->can_rate() && isset($_POST["rating"])) {
send_event(new RatingSetEvent($event->image, $_POST['rating']));
}
@ -125,11 +134,11 @@ class Ratings extends Extension {
}
public function onPageRequest(PageRequestEvent $event) {
global $database, $user, $page;
global $user, $page;
if ($event->page_matches("admin/bulk_rate")) {
if(!$user->is_admin()) {
throw PermissionDeniedException();
throw new PermissionDeniedException();
}
else {
$n = 0;
@ -154,9 +163,14 @@ class Ratings extends Extension {
}
}
}
public static function get_user_privs($user) {
/**
* @param \User $user
* @return null|string
*/
public static function get_user_privs(User $user) {
global $config;
if($user->is_anonymous()) {
$sqes = $config->get_string("ext_rating_anon_privs");
}
@ -169,6 +183,10 @@ class Ratings extends Extension {
return $sqes;
}
/**
* @param string $sqes
* @return string
*/
public static function privs_to_sql(/*string*/ $sqes) {
$arr = array();
$length = strlen($sqes);
@ -179,6 +197,10 @@ class Ratings extends Extension {
return $set;
}
/**
* @param string $rating
* @return string
*/
public static function rating_to_human(/*string*/ $rating) {
switch($rating) {
case "s": return "Safe";
@ -188,7 +210,11 @@ class Ratings extends Extension {
}
}
// FIXME: this is a bit ugly and guessey, should have proper options
/**
* FIXME: this is a bit ugly and guessey, should have proper options
*
* @return bool
*/
private function can_rate() {
global $config, $user;
if($user->is_anonymous() && $config->get_string("ext_rating_anon_privs") == "sqeu") return false;
@ -197,6 +223,10 @@ class Ratings extends Extension {
return false;
}
/**
* @param $context
* @return bool
*/
private function no_rating_query($context) {
foreach($context as $term) {
if(preg_match("/^rating[=|:]/", $term)) {
@ -207,8 +237,7 @@ class Ratings extends Extension {
}
private function install() {
global $database;
global $config;
global $database, $config;
if($config->get_int("ext_ratings2_version") < 1) {
$database->Execute("ALTER TABLE images ADD COLUMN rating CHAR(1) NOT NULL DEFAULT 'u'");
@ -227,6 +256,11 @@ class Ratings extends Extension {
}
}
/**
* @param int $image_id
* @param string $rating
* @param string $old_rating
*/
private function set_rating(/*int*/ $image_id, /*string*/ $rating, /*string*/ $old_rating) {
global $database;
if($old_rating != $rating){

View file

@ -1,6 +1,11 @@
<?php
class RatingsTheme extends Themelet {
/**
* @param int $image_id
* @param string $rating
* @return string
*/
public function get_rater_html(/*int*/ $image_id, /*string*/ $rating) {
$s_checked = $rating == 's' ? " checked" : "";
$q_checked = $rating == 'q' ? " checked" : "";
@ -35,6 +40,10 @@ class RatingsTheme extends Themelet {
$page->add_block(new Block("List Controls", $html, "left"));
}
/**
* @param string $rating
* @return string
*/
public function rating_to_name(/*string*/ $rating) {
switch($rating) {
case 's': return "Safe";

View file

@ -10,18 +10,30 @@
*/
class RemoveReportedImageEvent extends Event {
var $id;
/** @var int */
public $id;
/**
* @param int $id
*/
public function __construct($id) {
$this->id = $id;
}
}
class AddReportedImageEvent extends Event {
var $reporter_id;
var $image_id;
var $reason;
/** @var int */
public $reporter_id;
/** @var int */
public $image_id;
/** @var string */
public $reason;
/**
* @param int $image_id
* @param int $reporter_id
* @param string $reason
*/
public function __construct($image_id, $reporter_id, $reason) {
$this->reporter_id = $reporter_id;
$this->image_id = $image_id;
@ -89,7 +101,7 @@ class ReportImage extends Extension {
}
public function onDisplayingImage(DisplayingImageEvent $event) {
global $config, $user, $page;
global $user, $page;
if($user->can('create_image_report')) {
$reps = $this->get_reporters($event->image);
$this->theme->display_image_banner($event->image, $reps);
@ -112,8 +124,8 @@ class ReportImage extends Extension {
}
protected function install() {
global $database;
global $config;
global $database, $config;
if($config->get_int("ext_report_image_version") < 1) {
$database->create_table("image_reports", "
id SCORE_AIPK,
@ -129,6 +141,7 @@ class ReportImage extends Extension {
public function get_reporters(Image $image) {
global $database;
return $database->get_col("
SELECT users.name
FROM image_reports
@ -138,7 +151,8 @@ class ReportImage extends Extension {
}
public function get_reported_images() {
global $config, $database;
global $database;
$all_reports = $database->get_all("
SELECT image_reports.*, users.name AS reporter_name
FROM image_reports

View file

@ -57,11 +57,14 @@ class ReportImageTheme extends Themelet {
$page->set_heading("Reported Images");
$page->add_block(new NavBlock());
$page->add_block(new Block("Reported Images", $html));
}
/**
* @param Image $image
* @param array $reporters
*/
public function display_image_banner(Image $image, /*array*/ $reporters) {
global $config, $page;
global $page;
$i_image = int_escape($image->id);
$html = "";