Fixing/adding/cleaning up the PHP Doc comments.

This commit is contained in:
jgen 2014-04-26 05:01:49 -04:00
parent a8dd045586
commit 4e9e5ca2be
7 changed files with 204 additions and 23 deletions

View File

@ -1,10 +1,18 @@
<?php <?php
/** /**
* Class BaseThemelet
*
* A collection of common functions for theme parts * A collection of common functions for theme parts
*/ */
class BaseThemelet { class BaseThemelet {
/** /**
* Generic error message display * Generic error message display
*
* @param int $code
* @param string $title
* @param string $message
*/ */
public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) { public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) {
global $page; global $page;
@ -24,7 +32,6 @@ class BaseThemelet {
$page->add_block(new Block("Error", $message)); $page->add_block(new Block("Error", $message));
} }
/** /**
* A specific, common error message * A specific, common error message
*/ */
@ -36,6 +43,9 @@ class BaseThemelet {
/** /**
* Generic thumbnail code; returns HTML rather than adding * Generic thumbnail code; returns HTML rather than adding
* a block since thumbs tend to go inside blocks... * a block since thumbs tend to go inside blocks...
*
* @param Image $image
* @return string
*/ */
public function build_thumb_html(Image $image) { public function build_thumb_html(Image $image) {
global $config; global $config;
@ -65,9 +75,14 @@ class BaseThemelet {
"</a>\n"; "</a>\n";
} }
/** /**
* Add a generic paginator * Add a generic paginator.
*
* @param Page $page
* @param string $base
* @param string $query
* @param int $page_number
* @param int $total_pages
*/ */
public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) { public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) {
if($total_pages == 0) $total_pages = 1; if($total_pages == 0) $total_pages = 1;
@ -75,11 +90,28 @@ class BaseThemelet {
$page->add_block(new Block(null, $body, "main", 90, "paginator")); $page->add_block(new Block(null, $body, "main", 90, "paginator"));
} }
/**
* Generate a single HTML link.
*
* @param string $base_url
* @param string $query
* @param int|string $page
* @param string $name
* @return string
*/
private function gen_page_link($base_url, $query, $page, $name) { private function gen_page_link($base_url, $query, $page, $name) {
$link = make_link($base_url.'/'.$page, $query); $link = make_link($base_url.'/'.$page, $query);
return '<a href="'.$link.'">'.$name.'</a>'; return '<a href="'.$link.'">'.$name.'</a>';
} }
/**
* @param string $base_url
* @param string $query
* @param int|string $page
* @param int|string $current_page
* @param string $name
* @return string
*/
private function gen_page_link_block($base_url, $query, $page, $current_page, $name) { private function gen_page_link_block($base_url, $query, $page, $current_page, $name) {
$paginator = ""; $paginator = "";
if($page == $current_page) $paginator .= "<b>"; if($page == $current_page) $paginator .= "<b>";
@ -88,6 +120,15 @@ class BaseThemelet {
return $paginator; return $paginator;
} }
/**
* Build the paginator.
*
* @param int $current_page
* @param int $total_pages
* @param string $base_url
* @param string $query
* @return string
*/
private function build_paginator($current_page, $total_pages, $base_url, $query) { private function build_paginator($current_page, $total_pages, $base_url, $query) {
$next = $current_page + 1; $next = $current_page + 1;
$prev = $current_page - 1; $prev = $current_page - 1;

View File

@ -6,14 +6,14 @@ class Block {
/** /**
* The block's title * The block's title
* *
* @retval string * @var string
*/ */
public $header; public $header;
/** /**
* The content * The content
* *
* @retval string * @var string
*/ */
public $body; public $body;
@ -21,7 +21,7 @@ class Block {
* Where the block should be placed. The default theme supports * Where the block should be placed. The default theme supports
* "main" and "left", other themes can add their own areas * "main" and "left", other themes can add their own areas
* *
* @retval string * @var string
*/ */
public $section; public $section;
@ -30,15 +30,24 @@ class Block {
* numbers appear lower. The scale is 0-100 by convention, * numbers appear lower. The scale is 0-100 by convention,
* though any number or string will work. * though any number or string will work.
* *
* @retval int * @var int
*/ */
public $position; public $position;
/** /**
* * @var int
*/ */
public $id; public $id;
/**
* Construct a block.
*
* @param string $header
* @param string $body
* @param string $section
* @param int $position
* @param null|int $id
*/
public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) { public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) {
$this->header = $header; $this->header = $header;
$this->body = $body; $this->body = $body;
@ -47,6 +56,12 @@ class Block {
$this->id = str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id); $this->id = str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id);
} }
/**
* Get the HTML for this block.
*
* @param bool $hidable
* @return string
*/
public function get_html($hidable=false) { public function get_html($hidable=false) {
$h = $this->header; $h = $this->header;
$b = $this->body; $b = $this->body;

View File

@ -30,6 +30,9 @@ class PageRequestEvent extends Event {
public $arg_count; public $arg_count;
public $part_count; public $part_count;
/**
* @param string $path
*/
public function __construct($path) { public function __construct($path) {
global $config; global $config;
@ -63,6 +66,7 @@ class PageRequestEvent extends Event {
* *
* If it matches, store the remaining path elements in $args * If it matches, store the remaining path elements in $args
* *
* @param string $name
* @return bool * @return bool
*/ */
public function page_matches(/*string*/ $name) { public function page_matches(/*string*/ $name) {
@ -84,8 +88,9 @@ class PageRequestEvent extends Event {
/** /**
* Get the n th argument of the page request (if it exists.) * Get the n th argument of the page request (if it exists.)
* @param $n integer *
* @return The argmuent (string) or NULL * @param int $n
* @return string|null The argmuent (string) or NULL
*/ */
public function get_arg(/*int*/ $n) { public function get_arg(/*int*/ $n) {
$offset = $this->part_count + $n; $offset = $this->part_count + $n;
@ -108,6 +113,10 @@ class PageRequestEvent extends Event {
/* /*
* Many things use these functions * Many things use these functions
*/ */
/**
* @return array
*/
public function get_search_terms() { public function get_search_terms() {
$search_terms = array(); $search_terms = array();
if($this->count_args() === 2) { if($this->count_args() === 2) {
@ -115,6 +124,10 @@ class PageRequestEvent extends Event {
} }
return $search_terms; return $search_terms;
} }
/**
* @return int
*/
public function get_page_number() { public function get_page_number() {
$page_number = 1; $page_number = 1;
if($this->count_args() === 1) { if($this->count_args() === 1) {
@ -126,6 +139,10 @@ class PageRequestEvent extends Event {
if($page_number === 0) $page_number = 1; // invalid -> 0 if($page_number === 0) $page_number = 1; // invalid -> 0
return $page_number; return $page_number;
} }
/**
* @return int
*/
public function get_page_size() { public function get_page_size() {
global $config; global $config;
return $config->get_int('index_images'); return $config->get_int('index_images');

View File

@ -152,6 +152,9 @@ class Image {
/** /**
* Count the number of image results for a given search * Count the number of image results for a given search
*
* @param array $tags
* @return mixed
*/ */
public static function count_images($tags=array()) { public static function count_images($tags=array()) {
assert(is_array($tags)); assert(is_array($tags));
@ -181,6 +184,9 @@ class Image {
/** /**
* Count the number of pages for a given search * Count the number of pages for a given search
*
* @param array $tags
* @return float
*/ */
public static function count_pages($tags=array()) { public static function count_pages($tags=array()) {
assert(is_array($tags)); assert(is_array($tags));
@ -250,7 +256,9 @@ class Image {
} }
/** /**
* Set the image's owner * Set the image's owner.
*
* @param User $owner
*/ */
public function set_owner(User $owner) { public function set_owner(User $owner) {
global $database; global $database;
@ -272,7 +280,9 @@ class Image {
} }
/** /**
* Get this image's tags as a string * Get this image's tags as a string.
*
* @return string
*/ */
public function get_tag_list() { public function get_tag_list() {
return Tag::implode($this->get_tag_array()); return Tag::implode($this->get_tag_array());
@ -1022,6 +1032,10 @@ class Tag {
return $tag_array; return $tag_array;
} }
/**
* @param $tags
* @return string
*/
public static function implode($tags) { public static function implode($tags) {
assert(is_string($tags) || is_array($tags)); assert(is_string($tags) || is_array($tags));
@ -1036,6 +1050,10 @@ class Tag {
return $tags; return $tags;
} }
/**
* @param string $tag
* @return string
*/
public static function resolve_alias($tag) { public static function resolve_alias($tag) {
assert(is_string($tag)); assert(is_string($tag));
@ -1084,8 +1102,8 @@ class Tag {
/** /**
* This function takes a list (array) of tags and changes any tags that have aliases * This function takes a list (array) of tags and changes any tags that have aliases
* *
* @param $tags Array of tags * @param array $tags Array of tags
* @return Array of tags * @return array of tags
*/ */
public static function resolve_aliases($tags) { public static function resolve_aliases($tags) {
assert(is_array($tags)); assert(is_array($tags));
@ -1135,6 +1153,10 @@ function move_upload_to_archive(DataUploadEvent $event) {
/** /**
* Given a full size pair of dimensions, return a pair scaled down to fit * Given a full size pair of dimensions, return a pair scaled down to fit
* into the configured thumbnail square, with ratio intact * into the configured thumbnail square, with ratio intact
*
* @param int $orig_width
* @param int $orig_height
* @return array
*/ */
function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) { function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) {
global $config; global $config;

View File

@ -8,16 +8,23 @@ function _new_user($row) {
/** /**
* An object representing a row in the "users" table. * An object representing a row in the "users" table.
* *
* The currently logged in user will always be accessable via the global variable $user * The currently logged in user will always be accessible via the global variable $user
*/ */
class User { class User {
/** @var int */
public $id; public $id;
/** @var string */
public $name; public $name;
/** @var string */
public $email; public $email;
public $join_date; public $join_date;
public $passhash; public $passhash;
/* @var UserClass */ /** @var UserClass */
var $class; var $class;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@ -44,6 +51,13 @@ class User {
$this->class = $_user_classes[$row["class"]]; $this->class = $_user_classes[$row["class"]];
} }
/**
* Construct a User by session.
*
* @param string $name
* @param string $session
* @return null|User
*/
public static function by_session(/*string*/ $name, /*string*/ $session) { public static function by_session(/*string*/ $name, /*string*/ $session) {
global $config, $database; global $config, $database;
$row = $database->cache->get("user-session-$name-$session"); $row = $database->cache->get("user-session-$name-$session");
@ -60,6 +74,11 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/**
* Construct a User by session.
* @param int $id
* @return null|User
*/
public static function by_id(/*int*/ $id) { public static function by_id(/*int*/ $id) {
assert(is_numeric($id)); assert(is_numeric($id));
global $database; global $database;
@ -72,6 +91,11 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/**
* Construct a User by name.
* @param string $name
* @return null|User
*/
public static function by_name(/*string*/ $name) { public static function by_name(/*string*/ $name) {
assert(is_string($name)); assert(is_string($name));
global $database; global $database;
@ -79,6 +103,12 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/**
* Construct a User by name and hash.
* @param string $name
* @param string $hash
* @return null|User
*/
public static function by_name_and_hash(/*string*/ $name, /*string*/ $hash) { public static function by_name_and_hash(/*string*/ $name, /*string*/ $hash) {
assert(is_string($name)); assert(is_string($name));
assert(is_string($hash)); assert(is_string($hash));
@ -88,6 +118,11 @@ class User {
return is_null($row) ? null : new User($row); return is_null($row) ? null : new User($row);
} }
/**
* @param int $offset
* @param int $limit
* @return array
*/
public static function by_list(/*int*/ $offset, /*int*/ $limit=50) { public static function by_list(/*int*/ $offset, /*int*/ $limit=50) {
assert(is_numeric($offset)); assert(is_numeric($offset));
assert(is_numeric($limit)); assert(is_numeric($limit));
@ -97,8 +132,12 @@ class User {
} }
/* /* useful user object functions start here */
* useful user object functions start here
/**
* @param string $ability
* @return bool
*/ */
public function can($ability) { public function can($ability) {
return $this->class->can($ability); return $this->class->can($ability);
@ -134,6 +173,9 @@ class User {
return ($this->class->name === "admin"); return ($this->class->name === "admin");
} }
/**
* @param string $class
*/
public function set_class(/*string*/ $class) { public function set_class(/*string*/ $class) {
assert(is_string($class)); assert(is_string($class));
global $database; global $database;
@ -141,6 +183,9 @@ class User {
log_info("core-user", 'Set class for '.$this->name.' to '.$class); log_info("core-user", 'Set class for '.$this->name.' to '.$class);
} }
/**
* @param string $password
*/
public function set_password(/*string*/ $password) { public function set_password(/*string*/ $password) {
global $database; global $database;
$hash = md5(strtolower($this->name) . $password); $hash = md5(strtolower($this->name) . $password);

View File

@ -19,6 +19,13 @@ class UserClass {
$_user_classes[$name] = $this; $_user_classes[$name] = $this;
} }
/**
* Determine if this class of user can perform an action or has ability.
*
* @param string $ability
* @return bool
* @throws SCoreException
*/
public function can(/*string*/ $ability) { public function can(/*string*/ $ability) {
global $config; global $config;

View File

@ -1,7 +1,15 @@
<?php <?php
class Themelet extends BaseThemelet { class Themelet extends BaseThemelet {
/** /**
* Add a generic paginator * Add a generic paginator.
*
* @param Page $page
* @param string $base
* @param string $query
* @param int $page_number
* @param int $total_pages
* @param int $position
*/ */
public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $position=90) { public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $position=90) {
if($total_pages == 0) $total_pages = 1; if($total_pages == 0) $total_pages = 1;
@ -9,11 +17,28 @@ class Themelet extends BaseThemelet {
$page->add_block(new Block(null, $body, "main", $position)); $page->add_block(new Block(null, $body, "main", $position));
} }
/**
* Generate a single HTML link.
*
* @param string $base_url
* @param string $query
* @param int|string $page
* @param string $name
* @return string
*/
public function futaba_gen_page_link($base_url, $query, $page, $name) { public function futaba_gen_page_link($base_url, $query, $page, $name) {
$link = make_link("$base_url/$page", $query); $link = make_link("$base_url/$page", $query);
return "[<a href='$link'>{$name}</a>]"; return "[<a href='$link'>{$name}</a>]";
} }
/**
* @param string $base_url
* @param string $query
* @param int|string $page
* @param int|string $current_page
* @param string $name
* @return string
*/
public function futaba_gen_page_link_block($base_url, $query, $page, $current_page, $name) { public function futaba_gen_page_link_block($base_url, $query, $page, $current_page, $name) {
$paginator = ""; $paginator = "";
if($page == $current_page) $paginator .= "<b>"; if($page == $current_page) $paginator .= "<b>";
@ -22,6 +47,15 @@ class Themelet extends BaseThemelet {
return $paginator; return $paginator;
} }
/**
* Build the paginator.
*
* @param int $current_page
* @param int $total_pages
* @param string $base_url
* @param string $query
* @return string
*/
public function futaba_build_paginator($current_page, $total_pages, $base_url, $query) { public function futaba_build_paginator($current_page, $total_pages, $base_url, $query) {
$next = $current_page + 1; $next = $current_page + 1;
$prev = $current_page - 1; $prev = $current_page - 1;