More linting and fixing of comments and PHP Doc, types, etc.

This commit is contained in:
jgen 2014-04-28 01:26:22 -04:00
parent a0a39784d4
commit 022c162f40
11 changed files with 194 additions and 65 deletions

View file

@ -1,26 +1,37 @@
<?php
class FeaturedTheme extends Themelet {
/*
* Show $text on the $page
/**
* Show $text on the $page.
*
* @param Page $page
* @param Image $image
*/
public function display_featured(Page $page, Image $image) {
$page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3));
}
/**
* @param int $image_id
* @return string
*/
public function get_buttons_html(/*int*/ $image_id) {
global $user;
return "
".make_form(make_link("featured_image/set"))."
".$user->get_auth_html()."
<input type='hidden' name='image_id' value='$image_id'>
<input type='hidden' name='image_id' value='{$image_id}'>
<input type='submit' value='Feature This'>
</form>
";
}
/**
* @param Image $image
* @param null|string $query
* @return string
*/
public function build_featured_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();
@ -29,7 +40,7 @@ class FeaturedTheme extends Themelet {
return "
<a href='$h_view_link'>
<img id='thumb_$i_id' title='$h_tip' alt='$h_tip' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link'>
<img id='thumb_{$i_id}' title='{$h_tip}' alt='{$h_tip}' class='highlighted' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='{$h_thumb_link}'>
</a>
";
}

View file

@ -33,6 +33,11 @@ class RSS_Images extends Extension {
}
}
/**
* @param array $images
* @param array $search_terms
* @param int $page_number
*/
private function do_rss($images, $search_terms, /*int*/ $page_number) {
global $page;
global $config;
@ -78,6 +83,10 @@ class RSS_Images extends Extension {
$page->set_data($xml);
}
/**
* @param Image $image
* @return string
*/
private function thumb(Image $image) {
global $database;

View file

@ -24,8 +24,12 @@ class ConfigSaveEvent extends Event {
* Sent when the setup page is ready to be added to
*/
class SetupBuildingEvent extends Event {
var $panel;
/** @var \SetupPanel */
public $panel;
/**
* @param SetupPanel $panel
*/
public function __construct(SetupPanel $panel) {
$this->panel = $panel;
}
@ -35,8 +39,12 @@ class SetupBuildingEvent extends Event {
*
*/
class SetupPanel {
var $blocks = array();
/** @var \SetupBlock[] */
public $blocks = array();
/**
* @param SetupBlock $block
*/
public function add_block(SetupBlock $block) {
$this->blocks[] = $block;
}
@ -46,9 +54,14 @@ class SetupPanel {
*
*/
class SetupBlock extends Block {
var $header;
var $body;
/** @var string */
public $header;
/** @var string */
public $body;
/**
* @param string $title
*/
public function __construct($title) {
$this->header = $title;
$this->section = "main";
@ -56,20 +69,31 @@ class SetupBlock extends Block {
$this->body = "";
}
/**
* @param string $text
*/
public function add_label($text) {
$this->body .= $text;
}
/**
* @param string $name
* @param null|string $label
*/
public function add_text_option($name, $label=null) {
global $config;
$val = html_escape($config->get_string($name));
if(!is_null($label)) {
$this->body .= "<label for='$name'>$label</label>";
$this->body .= "<label for='{$name}'>{$label}</label>";
}
$this->body .= "<input type='text' id='$name' name='_config_$name' value='$val'>\n";
$this->body .= "<input type='hidden' name='_type_$name' value='string'>\n";
$this->body .= "<input type='text' id='{$name}' name='_config_{$name}' value='{$val}'>\n";
$this->body .= "<input type='hidden' name='_type_{$name}' value='string'>\n";
}
/**
* @param string $name
* @param null|string $label
*/
public function add_longtext_option($name, $label=null) {
global $config;
$val = html_escape($config->get_string($name));
@ -81,6 +105,10 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='string'>\n";
}
/**
* @param string $name
* @param null|string $label
*/
public function add_bool_option($name, $label=null) {
global $config;
$checked = $config->get_bool($name) ? " checked" : "";
@ -97,6 +125,10 @@ class SetupBlock extends Block {
// $this->body .= "<input type='hidden' id='$name' name='$name' value='$val'>";
// }
/**
* @param string $name
* @param null|string $label
*/
public function add_int_option($name, $label=null) {
global $config;
$val = html_escape($config->get_string($name));
@ -107,6 +139,10 @@ class SetupBlock extends Block {
$this->body .= "<input type='hidden' name='_type_$name' value='int'>\n";
}
/**
* @param string $name
* @param null|string $label
*/
public function add_shorthand_int_option($name, $label=null) {
global $config;
$val = to_shorthand_int($config->get_string($name));

View file

@ -40,9 +40,15 @@
*
*/
class OwnerSetEvent extends Event {
var $image;
var $owner;
/** @var \Image */
public $image;
/** @var \User */
public $owner;
/**
* @param Image $image
* @param User $owner
*/
public function __construct(Image $image, User $owner) {
$this->image = $image;
$this->owner = $owner;
@ -150,7 +156,7 @@ class TagEdit extends Extension {
}
public function onImageInfoSet(ImageInfoSetEvent $event) {
global $user, $page;
global $user;
if($user->can("edit_image_owner")) {
$owner = User::by_name($_POST['tag_edit__owner']);
send_event(new OwnerSetEvent($event->image, $owner));
@ -211,7 +217,6 @@ class TagEdit extends Extension {
}
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
global $user;
$event->add_part($this->theme->get_user_editor_html($event->image), 39);
$event->add_part($this->theme->get_tag_editor_html($event->image), 40);
$event->add_part($this->theme->get_source_editor_html($event->image), 41);
@ -230,18 +235,17 @@ class TagEdit extends Extension {
}
private function can_tag(Image $image) {
global $config, $user;
global $user;
return ($user->can("edit_image_tag") || !$image->is_locked());
}
private function can_source(Image $image) {
global $config, $user;
global $user;
return ($user->can("edit_image_source") || !$image->is_locked());
}
private function mass_tag_edit($search, $replace) {
global $database;
global $config;
$search_set = Tag::explode(strtolower($search), false);
$replace_set = Tag::explode(strtolower($replace), false);
@ -297,9 +301,6 @@ class TagEdit extends Extension {
}
private function mass_source_edit($tags, $source) {
global $database;
global $config;
$tags = Tag::explode($tags);
$last_id = -1;

View file

@ -51,7 +51,11 @@ class TagEditCloud extends Extension {
$event->panel->add_block($sb);
}
private function build_tag_map($image) {
/**
* @param Image $image
* @return string
*/
private function build_tag_map(Image $image) {
global $database, $config;
$html = "";
@ -75,23 +79,26 @@ class TagEditCloud extends Extension {
}
}
$tag_data = null;
switch($sort_method){
case 'a':
case 'p':
$tag_data = $database->get_all("SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count
FROM tags WHERE count >= :tag_min2 ORDER BY ".($sort_method == 'a' ? "tag" : "count DESC")." LIMIT :limit",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
break;
case 'r':
$relevant_tags = array_diff($image->get_tag_array(),$ignore_tags);
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
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",
case 'a':
case 'p':
default:
$tag_data = $database->get_all("SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count
FROM tags WHERE count >= :tag_min2 ORDER BY ".($sort_method == 'a' ? "tag" : "count DESC")." LIMIT :limit",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
}
break;
break;
case 'r':
$relevant_tags = array_diff($image->get_tag_array(),$ignore_tags);
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
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",
array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
}
break;
}
$counter = 1;
@ -151,7 +158,11 @@ class TagEditCloud extends Extension {
return "<div id='tageditcloud' class='tageditcloud'>$html</div>"; // FIXME: stupidasallhell
}
private function can_tag($image) {
/**
* @param Image $image
* @return bool
*/
private function can_tag(Image $image) {
global $user;
return ($user->can("edit_image_tag") && (!$image->is_locked() || $user->can("edit_image_lock")));
}

View file

@ -24,7 +24,7 @@ class Tag_History extends Extension {
}
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
global $page, $user;
if($event->page_matches("tag_history/revert")) {
// this is a request to revert to a previous version of the tags
@ -112,9 +112,12 @@ class Tag_History extends Extension {
$config->set_int("ext_tag_history_version", 3);
}
}
/*
* this function is called when a revert request is received
/**
* This function is called when a revert request is received.
*
* @param int $revert_id
* @throws ImageDoesNotExist
*/
private function process_revert_request($revert_id) {
global $page;
@ -199,7 +202,11 @@ class Tag_History extends Extension {
// output results
$this->theme->display_revert_ip_results();
}
/**
* @param int $revert_id
* @return mixed|null
*/
public function get_tag_history_from_revert(/*int*/ $revert_id) {
global $database;
$row = $database->get_row("
@ -210,6 +217,10 @@ class Tag_History extends Extension {
return ($row ? $row : null);
}
/**
* @param int $image_id
* @return array
*/
public function get_tag_history_from_id(/*int*/ $image_id) {
global $database;
$row = $database->get_all("
@ -222,6 +233,10 @@ class Tag_History extends Extension {
return ($row ? $row : array());
}
/**
* @param int $page_id
* @return array
*/
public function get_global_tag_history($page_id) {
global $database;
$row = $database->get_all("
@ -327,11 +342,14 @@ class Tag_History extends Extension {
log_info("tag_history", 'Reverted '.count($result).' edits.');
}
/*
* this function is called just before an images tag are changed
/**
* This function is called just before an images tag are changed.
*
* @param Image $image
* @param null|string|string[] $tags
*/
private function add_tag_history($image, $tags) {
private function add_tag_history(Image $image, $tags) {
global $database, $config, $user;
$new_tags = Tag::implode($tags);

View file

@ -7,6 +7,11 @@
class Tag_HistoryTheme extends Themelet {
var $messages = array();
/**
* @param Page $page
* @param int $image_id
* @param array $history
*/
public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) {
global $user;
$start_string = "
@ -57,6 +62,11 @@ class Tag_HistoryTheme extends Themelet {
$page->add_block(new Block("Tag History", $history_html, "main", 10));
}
/**
* @param Page $page
* @param array $history
* @param int $page_number
*/
public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) {
$start_string = "
<div style='text-align: left'>
@ -105,8 +115,10 @@ class Tag_HistoryTheme extends Themelet {
$page->add_block(new Block("Navigation", $nav, "left"));
}
/*
/**
* Add a section to the admin page.
*
* @param string $validation_msg
*/
public function display_admin_block(/*string*/ $validation_msg='') {
global $page;
@ -141,7 +153,11 @@ class Tag_HistoryTheme extends Themelet {
$html = implode($this->messages, "\n");
$page->add_block(new Block("Bulk Revert Results", $html));
}
/**
* @param string $title
* @param string $body
*/
public function add_status(/*string*/ $title, /*string*/ $body) {
$this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>';
}

View file

@ -132,10 +132,13 @@ class Tips extends Extension {
$this->theme->showAll($url, $tips);
}
/**
* @param int $tipID
*/
private function setStatus($tipID) {
global $database;
$tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array($tipID));
$tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array(int_escape($tipID)));
if (bool_escape($tip['enable'])) {
$enable = "N";
@ -143,12 +146,15 @@ class Tips extends Extension {
$enable = "Y";
}
$database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, $tipID));
$database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, int_escape($tipID)));
}
/**
* @param int $tipID
*/
private function deleteTip($tipID) {
global $database;
$database->execute("DELETE FROM tips WHERE id = ?", array($tipID));
$database->execute("DELETE FROM tips WHERE id = ?", array(int_escape($tipID)));
}
}

View file

@ -123,7 +123,7 @@ class Upload extends Extension {
}
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
global $page, $user;
if($event->page_matches("upload/replace")) {
// check if the user is an administrator and can upload files.
@ -333,6 +333,7 @@ class Upload extends Extension {
/**
* Handle an transload.
*
* @param string $url
* @param mixed $tags
* @param string $source

View file

@ -232,7 +232,12 @@ class UploadTheme extends Themelet {
return $html;
}
/* only allows 1 file to be uploaded - for replacing another image file */
/**
* Only allows 1 file to be uploaded - for replacing another image file.
*
* @param Page $page
* @param int $image_id
*/
public function display_replace_page(Page $page, /*int*/ $image_id) {
global $config, $page;
$tl_enabled = ($config->get_string("transload_engine", "none") != "none");
@ -275,7 +280,11 @@ class UploadTheme extends Themelet {
$page->add_block(new NavBlock());
$page->add_block(new Block("Upload Replacement Image", $html, "main", 20));
}
/**
* @param Page $page
* @param bool $ok
*/
public function display_upload_status(Page $page, /*bool*/ $ok) {
if($ok) {
$page->set_mode("redirect");
@ -288,6 +297,11 @@ class UploadTheme extends Themelet {
}
}
/**
* @param Page $page
* @param string $title
* @param string $message
*/
public function display_upload_error(Page $page, /*string*/ $title, /*string*/ $message) {
$page->add_block(new Block($title, $message));
}

View file

@ -344,8 +344,7 @@ class UserPage extends Extension {
// }}}
// Things done *with* the user {{{
private function login(Page $page) {
global $user;
global $config;
global $user, $config;
$name = $_POST['user'];
$pass = $_POST['pass'];
@ -380,12 +379,12 @@ class UserPage extends Extension {
}
private function check_user_creation($event) { // FIXME type
global $database;
$name = $event->username;
$pass = $event->password;
$email = $event->email;
global $database;
if(strlen($name) < 1) {
throw new UserCreationException("Username must be at least 1 character");
}
@ -417,6 +416,10 @@ class UserPage extends Extension {
log_info("user", "Created User #$uid ({$event->username})");
}
/**
* @param string $name
* @param string $pass
*/
private function set_login_cookie(/*string*/ $name, /*string*/ $pass) {
global $config;
@ -543,11 +546,14 @@ class UserPage extends Extension {
ORDER BY most_recent DESC", array("id"=>$duser->id));
return $rows;
}
/**
* @param Page $page
* @param bool $with_images
* @param bool $with_comments
*/
private function delete_user(Page $page, /*boolean*/ $with_images=false, /*boolean*/ $with_comments=false) {
global $user;
global $config;
global $database;
global $user, $config, $database;
$page->set_title("Error");
$page->set_heading("Error");