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 <?php
class FeaturedTheme extends Themelet { 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) { public function display_featured(Page $page, Image $image) {
$page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3)); $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) { public function get_buttons_html(/*int*/ $image_id) {
global $user; global $user;
return " return "
".make_form(make_link("featured_image/set"))." ".make_form(make_link("featured_image/set"))."
".$user->get_auth_html()." ".$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'> <input type='submit' value='Feature This'>
</form> </form>
"; ";
} }
/**
* @param Image $image
* @param null|string $query
* @return string
*/
public function build_featured_html(Image $image, $query=null) { public function build_featured_html(Image $image, $query=null) {
global $config;
$i_id = int_escape($image->id); $i_id = int_escape($image->id);
$h_view_link = make_link("post/view/$i_id", $query); $h_view_link = make_link("post/view/$i_id", $query);
$h_thumb_link = $image->get_thumb_link(); $h_thumb_link = $image->get_thumb_link();
@ -29,7 +40,7 @@ class FeaturedTheme extends Themelet {
return " return "
<a href='$h_view_link'> <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> </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) { private function do_rss($images, $search_terms, /*int*/ $page_number) {
global $page; global $page;
global $config; global $config;
@ -78,6 +83,10 @@ class RSS_Images extends Extension {
$page->set_data($xml); $page->set_data($xml);
} }
/**
* @param Image $image
* @return string
*/
private function thumb(Image $image) { private function thumb(Image $image) {
global $database; global $database;

View file

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

View file

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

View file

@ -51,7 +51,11 @@ class TagEditCloud extends Extension {
$event->panel->add_block($sb); $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; global $database, $config;
$html = ""; $html = "";
@ -75,9 +79,12 @@ class TagEditCloud extends Extension {
} }
} }
$tag_data = null;
switch($sort_method){ switch($sort_method){
case 'a': case 'a':
case 'p': case 'p':
default:
$tag_data = $database->get_all("SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count $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", 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)); array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count));
@ -151,7 +158,11 @@ class TagEditCloud extends Extension {
return "<div id='tageditcloud' class='tageditcloud'>$html</div>"; // FIXME: stupidasallhell 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; global $user;
return ($user->can("edit_image_tag") && (!$image->is_locked() || $user->can("edit_image_lock"))); 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) { public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user; global $page, $user;
if($event->page_matches("tag_history/revert")) { if($event->page_matches("tag_history/revert")) {
// this is a request to revert to a previous version of the tags // this is a request to revert to a previous version of the tags
@ -113,8 +113,11 @@ class Tag_History extends Extension {
} }
} }
/* /**
* 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) { private function process_revert_request($revert_id) {
global $page; global $page;
@ -200,6 +203,10 @@ class Tag_History extends Extension {
$this->theme->display_revert_ip_results(); $this->theme->display_revert_ip_results();
} }
/**
* @param int $revert_id
* @return mixed|null
*/
public function get_tag_history_from_revert(/*int*/ $revert_id) { public function get_tag_history_from_revert(/*int*/ $revert_id) {
global $database; global $database;
$row = $database->get_row(" $row = $database->get_row("
@ -210,6 +217,10 @@ class Tag_History extends Extension {
return ($row ? $row : null); return ($row ? $row : null);
} }
/**
* @param int $image_id
* @return array
*/
public function get_tag_history_from_id(/*int*/ $image_id) { public function get_tag_history_from_id(/*int*/ $image_id) {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
@ -222,6 +233,10 @@ class Tag_History extends Extension {
return ($row ? $row : array()); return ($row ? $row : array());
} }
/**
* @param int $page_id
* @return array
*/
public function get_global_tag_history($page_id) { public function get_global_tag_history($page_id) {
global $database; global $database;
$row = $database->get_all(" $row = $database->get_all("
@ -328,10 +343,13 @@ class Tag_History extends Extension {
log_info("tag_history", 'Reverted '.count($result).' edits.'); 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; global $database, $config, $user;
$new_tags = Tag::implode($tags); $new_tags = Tag::implode($tags);

View file

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

View file

@ -132,10 +132,13 @@ class Tips extends Extension {
$this->theme->showAll($url, $tips); $this->theme->showAll($url, $tips);
} }
/**
* @param int $tipID
*/
private function setStatus($tipID) { private function setStatus($tipID) {
global $database; 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'])) { if (bool_escape($tip['enable'])) {
$enable = "N"; $enable = "N";
@ -143,12 +146,15 @@ class Tips extends Extension {
$enable = "Y"; $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) { private function deleteTip($tipID) {
global $database; 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) { public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user; global $page, $user;
if($event->page_matches("upload/replace")) { if($event->page_matches("upload/replace")) {
// check if the user is an administrator and can upload files. // check if the user is an administrator and can upload files.
@ -333,6 +333,7 @@ class Upload extends Extension {
/** /**
* Handle an transload. * Handle an transload.
*
* @param string $url * @param string $url
* @param mixed $tags * @param mixed $tags
* @param string $source * @param string $source

View file

@ -232,7 +232,12 @@ class UploadTheme extends Themelet {
return $html; 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) { public function display_replace_page(Page $page, /*int*/ $image_id) {
global $config, $page; global $config, $page;
$tl_enabled = ($config->get_string("transload_engine", "none") != "none"); $tl_enabled = ($config->get_string("transload_engine", "none") != "none");
@ -276,6 +281,10 @@ class UploadTheme extends Themelet {
$page->add_block(new Block("Upload Replacement Image", $html, "main", 20)); $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) { public function display_upload_status(Page $page, /*bool*/ $ok) {
if($ok) { if($ok) {
$page->set_mode("redirect"); $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) { public function display_upload_error(Page $page, /*string*/ $title, /*string*/ $message) {
$page->add_block(new Block($title, $message)); $page->add_block(new Block($title, $message));
} }

View file

@ -344,8 +344,7 @@ class UserPage extends Extension {
// }}} // }}}
// Things done *with* the user {{{ // Things done *with* the user {{{
private function login(Page $page) { private function login(Page $page) {
global $user; global $user, $config;
global $config;
$name = $_POST['user']; $name = $_POST['user'];
$pass = $_POST['pass']; $pass = $_POST['pass'];
@ -380,12 +379,12 @@ class UserPage extends Extension {
} }
private function check_user_creation($event) { // FIXME type private function check_user_creation($event) { // FIXME type
global $database;
$name = $event->username; $name = $event->username;
$pass = $event->password; $pass = $event->password;
$email = $event->email; $email = $event->email;
global $database;
if(strlen($name) < 1) { if(strlen($name) < 1) {
throw new UserCreationException("Username must be at least 1 character"); 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})"); log_info("user", "Created User #$uid ({$event->username})");
} }
/**
* @param string $name
* @param string $pass
*/
private function set_login_cookie(/*string*/ $name, /*string*/ $pass) { private function set_login_cookie(/*string*/ $name, /*string*/ $pass) {
global $config; global $config;
@ -544,10 +547,13 @@ class UserPage extends Extension {
return $rows; 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) { private function delete_user(Page $page, /*boolean*/ $with_images=false, /*boolean*/ $with_comments=false) {
global $user; global $user, $config, $database;
global $config;
global $database;
$page->set_title("Error"); $page->set_title("Error");
$page->set_heading("Error"); $page->set_heading("Error");