From 76fd27f87c5f6b750824ddd5632b42b218e3bf7d Mon Sep 17 00:00:00 2001 From: jgen Date: Mon, 28 Apr 2014 00:56:19 -0400 Subject: [PATCH] Fixing/Cleaning more PHP Doc related issues. --- ext/handle_mp3/main.php | 18 +++++ ext/notes/main.php | 146 ++++++++++++++++++++-------------------- ext/pools/main.php | 129 +++++++++++++++++++++-------------- 3 files changed, 171 insertions(+), 122 deletions(-) diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index be807472..691fc644 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -6,15 +6,29 @@ */ class MP3FileHandler extends DataHandlerExtension { + /** + * @param string $hash + * @return bool + */ protected function create_thumb($hash) { copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash)); + return true; } + /** + * @param string $ext + * @return bool + */ protected function supported_ext($ext) { $exts = array("mp3"); return in_array(strtolower($ext), $exts); } + /** + * @param string $filename + * @param array $metadata + * @return Image|null + */ protected function create_image_from_data($filename, $metadata) { global $config; @@ -47,6 +61,10 @@ class MP3FileHandler extends DataHandlerExtension { return $image; } + /** + * @param $file + * @return bool + */ protected function check_contents($file) { if (file_exists($file)) { require_once('lib/getid3/getid3/getid3.php'); diff --git a/ext/notes/main.php b/ext/notes/main.php index 3a259c1c..f2ea535f 100644 --- a/ext/notes/main.php +++ b/ext/notes/main.php @@ -109,7 +109,7 @@ class Notes extends Extension { } $page->set_mode("redirect"); - $page->set_redirect(make_link("note/updated")); + $page->set_redirect(make_link("note/updated")); break; } case "add_note": @@ -118,7 +118,7 @@ class Notes extends Extension { $this->add_new_note(); $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/".$_POST["image_id"])); + $page->set_redirect(make_link("post/view/".$_POST["image_id"])); break; } case "add_request": @@ -127,7 +127,7 @@ class Notes extends Extension { $this->add_note_request(); $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/".$_POST["image_id"])); + $page->set_redirect(make_link("post/view/".$_POST["image_id"])); break; } case "nuke_notes": @@ -136,7 +136,7 @@ class Notes extends Extension { $this->nuke_notes(); $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/".$_POST["image_id"])); + $page->set_redirect(make_link("post/view/".$_POST["image_id"])); break; } case "nuke_requests": @@ -145,7 +145,7 @@ class Notes extends Extension { $this->nuke_requests(); $page->set_mode("redirect"); - $page->set_redirect(make_link("post/view/".$_POST["image_id"])); + $page->set_redirect(make_link("post/view/".$_POST["image_id"])); break; } case "edit_note": @@ -238,18 +238,21 @@ class Notes extends Extension { } - /* - * HERE WE GET ALL NOTES FOR DISPLAYED IMAGE + /** + * HERE WE GET ALL NOTES FOR DISPLAYED IMAGE. + * + * @param int $imageID + * @return array */ private function get_notes($imageID) { global $database; - return $database->get_all( - "SELECT * ". - "FROM notes ". - "WHERE enable = ? AND image_id = ? ". - "ORDER BY date ASC" - , array('1', $imageID)); + return $database->get_all( + "SELECT * ". + "FROM notes ". + "WHERE enable = ? AND image_id = ? ". + "ORDER BY date ASC" + , array('1', $imageID)); } @@ -345,7 +348,6 @@ class Notes extends Extension { $this->add_history(1, $noteID, $imageID, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText); } - /* @@ -353,7 +355,7 @@ class Notes extends Extension { */ private function delete_note() { - global $user; + global $user; $imageID = int_escape($_POST["image_id"]); $noteID = int_escape($_POST["note_id"]); @@ -399,28 +401,27 @@ class Notes extends Extension { log_info("notes", "Requests deleted from {$image_id} by {$user->name}"); } - - - - /* - * HERE WE ALL IMAGES THAT HAVE NOTES - */ - private function get_notes_list($event) { - $pageNumber = $event->get_arg(1); - if(is_null($pageNumber) || !is_numeric($pageNumber)) - $pageNumber = 0; - else if ($pageNumber <= 0) - $pageNumber = 0; - else - $pageNumber--; - global $config; - + /** + * HERE WE ALL IMAGES THAT HAVE NOTES + * @param PageRequestEvent $event + */ + private function get_notes_list(PageRequestEvent $event) { + global $database, $config; + + $pageNumber = $event->get_arg(1); + + if(is_null($pageNumber) || !is_numeric($pageNumber)) + $pageNumber = 0; + else if ($pageNumber <= 0) + $pageNumber = 0; + else + $pageNumber--; + $notesPerPage = $config->get_int('notesNotesPerPage'); - //$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=?", array($poolID)); - global $database; + $get_notes = " SELECT DISTINCT image_id ". "FROM notes ". @@ -440,26 +441,26 @@ class Notes extends Extension { $this->theme->display_note_list($images, $pageNumber + 1, $totalPages); } - - - - /* - * HERE WE GET ALL NOTE REQUESTS - */ - private function get_notes_requests($event) { - $pageNumber = $event->get_arg(1); - if(is_null($pageNumber) || !is_numeric($pageNumber)) - $pageNumber = 0; - else if ($pageNumber <= 0) - $pageNumber = 0; - else - $pageNumber--; - global $config; - + /** + * HERE WE GET ALL NOTE REQUESTS + * @param PageRequestEvent $event + */ + private function get_notes_requests(PageRequestEvent $event) { + global $config; + + $pageNumber = $event->get_arg(1); + + if(is_null($pageNumber) || !is_numeric($pageNumber)) + $pageNumber = 0; + else if ($pageNumber <= 0) + $pageNumber = 0; + else + $pageNumber--; + $requestsPerPage = $config->get_int('notesRequestsPerPage'); - - + + //$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=?", array($poolID)); global $database; $get_requests = " @@ -501,13 +502,13 @@ class Notes extends Extension { (?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?)", array($noteEnable, $noteID, $reviewID, $imageID, $userID, $_SERVER['REMOTE_ADDR'], $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText)); } - - - - /* - * HERE WE GET ALL HISTORIES. - */ - private function get_histories($event){ + + + /** + * HERE WE GET ALL HISTORIES. + * @param PageRequestEvent $event + */ + private function get_histories(PageRequestEvent $event){ $pageNumber = $event->get_arg(1); if(is_null($pageNumber) || !is_numeric($pageNumber)) $pageNumber = 0; @@ -533,13 +534,13 @@ class Notes extends Extension { $this->theme->display_histories($histories, $pageNumber + 1, $totalPages); } - - - - /* - * HERE WE THE HISTORY FOR A SPECIFIC NOTE. - */ - private function get_history($event){ + + + /** + * HERE WE THE HISTORY FOR A SPECIFIC NOTE. + * @param PageRequestEvent $event + */ + private function get_history(PageRequestEvent $event){ $noteID = $event->get_arg(1); $pageNumber = $event->get_arg(2); if(is_null($pageNumber) || !is_numeric($pageNumber)) @@ -566,14 +567,14 @@ class Notes extends Extension { $this->theme->display_history($histories, $pageNumber + 1, $totalPages); } - - - - /* - * HERE GO BACK IN HISTORY AND SET THE OLD NOTE. IF WAS REMOVED WE READD IT. - */ + + /** + * HERE GO BACK IN HISTORY AND SET THE OLD NOTE. IF WAS REMOVED WE RE-ADD IT. + * @param int $noteID + * @param int $reviewID + */ private function revert_history($noteID, $reviewID){ - global $user, $database; + global $database; $history = $database->get_row("SELECT * FROM note_histories WHERE note_id = ? AND review_id = ?",array($noteID, $reviewID)); @@ -596,7 +597,6 @@ class Notes extends Extension { "WHERE image_id = ? AND id = ?", array(1, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText, $imageID, $noteID)); $this->add_history($noteEnable, $noteID, $imageID, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText); - } } diff --git a/ext/pools/main.php b/ext/pools/main.php index 3f565b7f..4f5c6635 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -13,8 +13,12 @@ * This class is just a wrapper around SCoreException. */ class PoolCreationException extends SCoreException { - var $error; + /** @var string */ + public $error; + /** + * @param string $error + */ public function __construct($error) { $this->error = $error; } @@ -92,7 +96,7 @@ class Pools extends Extension { } public function onPageRequest(PageRequestEvent $event) { - global $config, $page, $user; + global $page, $user; if ($event->page_matches("pool")) { @@ -220,8 +224,8 @@ class Pools extends Extension { case "nuke": // Completely remove the given pool. - // -> Only admins and owners may do this - if($user->is_admin() || $user->id == $pool['user_id']) { + // -> Only admins and owners may do this + if($user->is_admin() || $user->id == $pool['user_id']) { $this->nuke_pool($pool_id); $page->set_mode("redirect"); $page->set_redirect(make_link("pool/list")); @@ -249,7 +253,7 @@ class Pools extends Extension { * to the Next image in the pool. */ public function onDisplayingImage(DisplayingImageEvent $event) { - global $config, $database, $page; + global $config; if($config->get_bool("poolsInfoOnViewImage")) { $imageID = $event->image->id; @@ -338,10 +342,14 @@ class Pools extends Extension { /* ------------------------------------------------- */ /* -------------- Private Functions -------------- */ /* ------------------------------------------------- */ - + /** * Check if the given user has permission to edit/change the pool. + * * TODO: Should the user variable be global? + * + * @param \User $user + * @param $pool * @return bool */ private function have_permission($user, $pool) { @@ -357,7 +365,7 @@ class Pools extends Extension { /** * HERE WE GET THE LIST OF POOLS. * - * @param Page $page + * @param \Page $page * @param int $pageNumber */ private function list_pools(Page $page, /*int*/ $pageNumber) { @@ -437,8 +445,11 @@ class Pools extends Extension { /** * Retrieve information about pools given multiple pool IDs. + * + * TODO: What is the difference between this and get_single_pool() other than the db query? + * * @param int $poolID Array of integers - * @return 2D Array + * @return array */ private function get_pool(/*int*/ $poolID) { global $database; @@ -448,7 +459,7 @@ class Pools extends Extension { /** * Retrieve information about a pool given a pool ID. * @param int $poolID the pool id - * @return 2D array (with only 1 element in the one dimension) + * @return array Array with only 1 element in the one dimension */ private function get_single_pool(/*int*/ $poolID) { global $database; @@ -457,8 +468,8 @@ class Pools extends Extension { /** * Retrieve information about a pool given a pool title. - * @param $poolTitle Integer - * @return 2D array (with only 1 element in the one dimension) + * @param string $poolTitle + * @return array Array (with only 1 element in the one dimension) */ private function get_single_pool_from_title(/*string*/ $poolTitle) { global $database; @@ -467,20 +478,20 @@ class Pools extends Extension { /** * Get all of the pool IDs that an image is in, given an image ID. - * @param $imageID Integer - * @return 2D array + * @param int $imageID Integer ID for the image + * @return array */ private function get_pool_id(/*int*/ $imageID) { global $database; return $database->get_all("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID)); } - - /* + /** * HERE WE GET THE IMAGES FROM THE TAG ON IMPORT + * @param int $pool_id */ private function import_posts(/*int*/ $pool_id) { - global $page, $config, $database; + global $page, $config; $poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000); @@ -489,10 +500,12 @@ class Pools extends Extension { } - /* + /** * HERE WE ADD CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY * * TODO: Fix this so that the pool ID and images are passed as Arguments to the function. + * + * @return int */ private function add_posts() { global $database; @@ -523,11 +536,12 @@ class Pools extends Extension { WHERE id=:pid", array("pid"=>$poolID) ); - return $poolID; + return $poolID; } - /* + /** * TODO: Fix this so that the pool ID and images are passed as Arguments to the function. + * @return int */ private function order_posts() { global $database; @@ -547,11 +561,12 @@ class Pools extends Extension { return $poolID; } - - /* + /** * HERE WE REMOVE CHECKED IMAGES FROM POOL AND UPDATE THE HISTORY * * TODO: Fix this so that the pool ID and images are passed as Arguments to the function. + * + * @return int */ private function remove_posts() { global $database; @@ -569,8 +584,9 @@ class Pools extends Extension { return $poolID; } - /* + /** * Allows editing of pool description. + * @return int */ private function edit_description() { global $database; @@ -586,8 +602,8 @@ class Pools extends Extension { * Used by add_posts() * * @see add_posts() - * @param $poolID integer - * @param $imageID integer + * @param int $poolID + * @param int $imageID * @return bool */ private function check_post(/*int*/ $poolID, /*int*/ $imageID) { @@ -599,9 +615,9 @@ class Pools extends Extension { /** * Gets the next successive image from a pool, given a pool ID and an image ID. * - * @param $pool Array for the given pool - * @param $imageID Integer - * @return Integer which is the next Image ID or NULL if none. + * @param array $pool Array for the given pool + * @param int $imageID Integer + * @return int Integer which is the next Image ID or NULL if none. */ private function get_next_post(/*array*/ $pool, /*int*/ $imageID) { global $database; @@ -627,6 +643,9 @@ class Pools extends Extension { /** * Retrieve all the images in a pool, given a pool ID. + * + * @param PageRequestEvent $event + * @param int $poolID */ private function get_posts($event, /*int*/ $poolID) { global $config, $user, $database; @@ -690,8 +709,8 @@ class Pools extends Extension { /** * This function gets the current order of images from a given pool. - * @param $poolID integer - * @return Array of image objects. + * @param int $poolID + * @return \Image[] Array of image objects. */ private function edit_posts(/*int*/ $poolID) { global $database; @@ -708,8 +727,11 @@ class Pools extends Extension { } - /* - * WE GET THE ORDER OF THE IMAGES BUT HERE WE SEND KEYS ADDED IN ARRAY TO GET THE ORDER IN THE INPUT VALUE + /** + * WE GET THE ORDER OF THE IMAGES BUT HERE WE SEND KEYS ADDED IN ARRAY TO GET THE ORDER IN THE INPUT VALUE. + * + * @param int $poolID + * @return \Image[] */ private function edit_order(/*int*/ $poolID) { global $database; @@ -732,8 +754,10 @@ class Pools extends Extension { } - /* - * HERE WE NUKE ENTIRE POOL. WE REMOVE POOLS AND POSTS FROM REMOVED POOL AND HISTORIES ENTRIES FROM REMOVED POOL + /** + * HERE WE NUKE ENTIRE POOL. WE REMOVE POOLS AND POSTS FROM REMOVED POOL AND HISTORIES ENTRIES FROM REMOVED POOL. + * + * @param int $poolID */ private function nuke_pool(/*int*/ $poolID) { global $user, $database; @@ -765,8 +789,9 @@ class Pools extends Extension { } - /* - * HERE WE GET THE HISTORY LIST + /** + * HERE WE GET THE HISTORY LIST. + * @param int $pageNumber */ private function get_history(/*int*/ $pageNumber) { global $config, $database; @@ -778,7 +803,6 @@ class Pools extends Extension { else $pageNumber--; - $historiesPerPage = $config->get_int("poolsUpdatedPerPage"); $history = $database->get_all(" @@ -799,9 +823,9 @@ class Pools extends Extension { } - - /* - * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL + /** + * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL. + * @param int $historyID */ private function revert_history(/*int*/ $historyID) { global $database; @@ -816,8 +840,8 @@ class Pools extends Extension { if($entry['action'] == 0) { // READ ENTRIES - foreach($images as $image) { - $imageID = $image; + foreach($images as $image) { + $imageID = $image; $this->add_post($poolID, $imageID); $imageArray .= " ".$imageID; @@ -827,7 +851,7 @@ class Pools extends Extension { else if($entry['action'] == 1) { // DELETE ENTRIES foreach($images as $image) { - $imageID = $image; + $imageID = $image; $this->delete_post($poolID, $imageID); $imageArray .= " ".$imageID; @@ -846,9 +870,13 @@ class Pools extends Extension { - /* - * HERE WE ADD A SIMPLE POST FROM POOL - * USED WITH FOREACH IN revert_history() & onTagTermParse() + /** + * HERE WE ADD A SIMPLE POST FROM POOL. + * USED WITH FOREACH IN revert_history() & onTagTermParse(). + * + * @param int $poolID + * @param int $imageID + * @param bool $history */ private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) { global $database; @@ -869,10 +897,13 @@ class Pools extends Extension { } - - /* - * HERE WE REMOVE A SIMPLE POST FROM POOL - * USED WITH FOREACH IN revert_history() & onTagTermParse() + /** + * HERE WE REMOVE A SIMPLE POST FROM POOL. + * USED WITH FOREACH IN revert_history() & onTagTermParse(). + * + * @param int $poolID + * @param int $imageID + * @param bool $history */ private function delete_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) { global $database;