more linty bits

This commit is contained in:
Shish 2016-06-18 19:26:56 +01:00
parent cfd3a9d248
commit 4577ff70ef
4 changed files with 123 additions and 97 deletions

View file

@ -390,8 +390,8 @@ function show_ip($ip, $ban_reason) {
/** /**
* Checks if a given string contains another at the beginning. * Checks if a given string contains another at the beginning.
* *
* @param $haystack String to examine. * @param string $haystack String to examine.
* @param $needle String to look for. * @param string $needle String to look for.
* @return bool * @return bool
*/ */
function startsWith(/*string*/ $haystack, /*string*/ $needle) { function startsWith(/*string*/ $haystack, /*string*/ $needle) {
@ -402,8 +402,8 @@ function startsWith(/*string*/ $haystack, /*string*/ $needle) {
/** /**
* Checks if a given string contains another at the end. * Checks if a given string contains another at the end.
* *
* @param $haystack String to examine. * @param string $haystack String to examine.
* @param $needle String to look for. * @param string $needle String to look for.
* @return bool * @return bool
*/ */
function endsWith(/*string*/ $haystack, /*string*/ $needle) { function endsWith(/*string*/ $haystack, /*string*/ $needle) {
@ -695,7 +695,7 @@ function is_https_enabled() {
* from the "Amazon S3 PHP class" which is Copyright (c) 2008, Donovan Schönknecht * from the "Amazon S3 PHP class" which is Copyright (c) 2008, Donovan Schönknecht
* and released under the 'Simplified BSD License'. * and released under the 'Simplified BSD License'.
* *
* @param string &$file File path * @param string $file File path
* @param string $ext * @param string $ext
* @param bool $list * @param bool $list
* @return string * @return string
@ -1463,7 +1463,7 @@ function _dump_event_listeners($event_listeners, $path) {
} }
/** /**
* @param $ext_name string * @param string $ext_name Main class name (eg ImageIO as opposed to ImageIOTheme or ImageIOTest)
* @return bool * @return bool
*/ */
function ext_is_live($ext_name) { function ext_is_live($ext_name) {

View file

@ -213,7 +213,7 @@ class CronUploader extends Extension {
/** /**
* Returns amount of files & total size of dir. * Returns amount of files & total size of dir.
* @param $path string * @param string $path directory name to scan
* @return multitype:number * @return multitype:number
*/ */
function scan_dir($path){ function scan_dir($path){
@ -234,7 +234,7 @@ class CronUploader extends Extension {
/** /**
* Uploads the image & handles everything * Uploads the image & handles everything
* @param $upload_count int to upload a non-config amount of imgs * @param int $upload_count to upload a non-config amount of imgs
* @return boolean returns true if the upload was successful * @return boolean returns true if the upload was successful
*/ */
public function process_upload($upload_count = 0) { public function process_upload($upload_count = 0) {

View file

@ -86,7 +86,7 @@ class IcoFileHandler extends Extension {
} }
/** /**
* @param $file * @param string $file
* @return bool * @return bool
*/ */
private function check_contents($file) { private function check_contents($file) {
@ -98,7 +98,7 @@ class IcoFileHandler extends Extension {
} }
/** /**
* @param $hash * @param string $hash
* @return bool * @return bool
*/ */
private function create_thumb($hash) { private function create_thumb($hash) {

View file

@ -11,7 +11,7 @@
* This is done to prevent duplicate views. * This is done to prevent duplicate views.
* A person can only count as a view again 1 hour after viewing the image initially. * A person can only count as a view again 1 hour after viewing the image initially.
*/ */
class image_view_counter extends Extension { class ImageViewCounter extends Extension {
private $view_interval = 3600; # allows views to be added each hour private $view_interval = 3600; # allows views to be added each hour
# Add Setup Block with options for view counter # Add Setup Block with options for view counter
@ -32,10 +32,12 @@ class image_view_counter extends Extension {
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
global $user, $config; global $user, $config;
$adminonly = $config->get_bool("image_viewcounter_adminonly"); // todo0 $adminonly = $config->get_bool("image_viewcounter_adminonly"); // todo
if ($adminonly == false || ($adminonly && $user->is_admin())) if ($adminonly == false || ($adminonly && $user->is_admin()))
$event->add_part("<tr><th>Views:</th><td>". $event->add_part(
$this->get_view_count($event->image->id) ."</th></tr>", 38); "<tr><th>Views:</th><td>".
$this->get_view_count($event->image->id) .
"</th></tr>", 38);
} }
# Installs DB table # Installs DB table
@ -54,7 +56,10 @@ class image_view_counter extends Extension {
} }
} }
# Adds a view to the item if needed /**
* Adds a view to the item if needed
* @param int $imgid
*/
private function addview($imgid) private function addview($imgid)
{ {
global $database, $user; global $database, $user;
@ -63,43 +68,64 @@ class image_view_counter extends Extension {
if ($this->can_add_view($imgid) == false) return; if ($this->can_add_view($imgid) == false) return;
// Add view for current IP // Add view for current IP
$database->execute("INSERT INTO image_views (image_id, user_id, timestamp, ipaddress) $database->execute(
VALUES (:image_id, :user_id, :timestamp, :ipaddress)", array( "
INSERT INTO image_views (image_id, user_id, timestamp, ipaddress)
VALUES (:image_id, :user_id, :timestamp, :ipaddress)
",
array(
"image_id" => $imgid, "image_id" => $imgid,
"user_id" => $user->id, "user_id" => $user->id,
"timestamp" => time(), "timestamp" => time(),
"ipaddress" => $_SERVER['REMOTE_ADDR'], "ipaddress" => $_SERVER['REMOTE_ADDR'],
)); )
);
} }
# Returns true if this IP hasn't recently viewed this image /**
* Returns true if this IP hasn't recently viewed this image
* @param int $imgid
*/
private function can_add_view($imgid) private function can_add_view($imgid)
{ {
global $database; global $database;
// counts views from current IP in the last hour // counts views from current IP in the last hour
$recent_from_ip = (int)$database->get_one("SELECT COUNT(*) FROM image_views WHERE $recent_from_ip = (int)$database->get_one(
ipaddress=:ipaddress AND timestamp >:lasthour AND image_id =:image_id", "
array( "ipaddress" => $_SERVER['REMOTE_ADDR'], SELECT COUNT(*)
FROM image_views
WHERE ipaddress=:ipaddress AND timestamp >:lasthour AND image_id =:image_id
",
array(
"ipaddress" => $_SERVER['REMOTE_ADDR'],
"lasthour" => time() - $this->view_interval, "lasthour" => time() - $this->view_interval,
"image_id" => $imgid)); "image_id" => $imgid
)
);
// if no views were found with the set criteria, return true // if no views were found with the set criteria, return true
if($recent_from_ip == 0) return true; if($recent_from_ip == 0) return true;
else return false; else return false;
} }
# Returns the int of the view count from the given image id /**
// $imgid - if not set or 0, return views of all images * Returns the int of the view count from the given image id
* @param int $imgid - if not set or 0, return views of all images
*/
private function get_view_count($imgid = 0) private function get_view_count($imgid = 0)
{ {
global $database; global $database;
if ($imgid == 0) // return view count of all images if ($imgid == 0) // return view count of all images
$view_count = (int)$database->get_one("SELECT COUNT(*) FROM image_views"); $view_count = (int)$database->get_one(
"SELECT COUNT(*) FROM image_views"
);
else // return view count of specified image else // return view count of specified image
$view_count = (int)$database->get_one("SELECT COUNT(*) FROM image_views WHERE ". $view_count = (int)$database->get_one(
"image_id =:image_id", array("image_id" => $imgid)); "SELECT COUNT(*) FROM image_views WHERE image_id =:image_id",
array("image_id" => $imgid)
);
// returns the count as int // returns the count as int
return $view_count; return $view_count;