aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_html.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/functions_html.inc.php')
-rw-r--r--include/functions_html.inc.php218
1 files changed, 134 insertions, 84 deletions
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index 5b6a5079b..8cad4e395 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -22,21 +22,22 @@
// +-----------------------------------------------------------------------+
/**
- * returns the list of categories as a HTML string
- *
- * categories string returned contains categories as given in the input
+ * @package functions\html
+ */
+
+
+/**
+ * Generates breadcrumb from categories list.
+ * Categories string returned contains categories as given in the input
* array $cat_informations. $cat_informations array must be an array
* of array( id=>?, name=>?, permalink=>?). If url input parameter is null,
* returns only the categories name without links.
*
- * @param array cat_informations
- * @param string url
- * @param boolean replace_space
+ * @param array $cat_informations
+ * @param string|null $url
* @return string
*/
-function get_cat_display_name($cat_informations,
- $url = '',
- $replace_space = false)
+function get_cat_display_name($cat_informations, $url='')
{
global $conf;
@@ -86,32 +87,21 @@ function get_cat_display_name($cat_informations,
$output.= $cat['name'].'</a>';
}
}
- if ($replace_space)
- {
- return replace_space($output);
- }
- else
- {
- return $output;
- }
+ return $output;
}
/**
- * returns the list of categories as a HTML string, with cache of names
- *
- * categories string returned contains categories as given in the input
- * array $cat_informations. $uppercats is the list of category ids to
- * display in the right order. If url input parameter is empty, returns only
- * the categories name without links.
+ * Generates breadcrumb from categories list using a cache.
+ * @see get_cat_display_name()
*
- * @param string uppercats
- * @param string url
- * @param boolean replace_space
+ * @param string $uppercats
+ * @param string|null $url
+ * @param bool $single_link
+ * @param string|null $link_class
* @return string
*/
function get_cat_display_name_cache($uppercats,
$url = '',
- $replace_space = false,
$single_link = false,
$link_class = null)
{
@@ -184,23 +174,32 @@ SELECT id, name, permalink
$output.= '</a>';
}
- if ($replace_space)
- {
- return replace_space($output);
- }
- else
- {
- return $output;
- }
+ return $output;
}
/**
- * returns HTMLized comment contents retrieved from database
+ * Generates breadcrumb for a category.
+ * @see get_cat_display_name()
*
- * newlines becomes br tags, _word_ becomes underline, /word/ becomes
- * italic, *word* becomes bolded
+ * @param int $cat_id
+ * @param string|null $url
+ * @return string
+ */
+function get_cat_display_name_from_id($cat_id, $url = '')
+{
+ $cat_info = get_cat_info($cat_id);
+ return get_cat_display_name($cat_info['upper_names'], $url);
+}
+
+/**
+ * Apply basic markdown transformations to a text.
+ * newlines becomes br tags
+ * _word_ becomes underline
+ * /word/ becomes italic
+ * *word* becomes bolded
+ * urls becomes a tags
*
- * @param string content
+ * @param string $content
* @return string
*/
function render_comment_content($content)
@@ -227,15 +226,9 @@ function render_comment_content($content)
$replacement = '<span style="font-style:italic;">$1$2</span>';
$content = preg_replace($pattern, $replacement, $content);
- return $content;
-}
+ // TODO : add a trigger
-function get_cat_display_name_from_id($cat_id,
- $url = '',
- $replace_space = false)
-{
- $cat_info = get_cat_info($cat_id);
- return get_cat_display_name($cat_info['upper_names'], $url, $replace_space);
+ return $content;
}
/**
@@ -287,11 +280,17 @@ function get_html_tag_selection(
return $output;
}
+/**
+ * Callback used for sorting by name.
+ */
function name_compare($a, $b)
{
return strcmp(strtolower($a['name']), strtolower($b['name']));
}
+/**
+ * Callback used for sorting by name (slug) with cache.
+ */
function tag_alpha_compare($a, $b)
{
global $cache;
@@ -308,7 +307,7 @@ function tag_alpha_compare($a, $b)
}
/**
- * exits the current script (either exit or redirect)
+ * Exits the current script (or redirect to login page if not logged).
*/
function access_denied()
{
@@ -335,9 +334,11 @@ function access_denied()
}
/**
- * exits the current script with 403 code
- * @param string msg a message to display
- * @param string alternate_url redirect to this url
+ * Exits the current script with 403 code.
+ * @todo nice display if $template loaded
+ *
+ * @param string $msg
+ * @param string|null $alternate_url redirect to this url
*/
function page_forbidden($msg, $alternate_url=null)
{
@@ -352,9 +353,11 @@ function page_forbidden($msg, $alternate_url=null)
}
/**
- * exits the current script with 400 code
- * @param string msg a message to display
- * @param string alternate_url redirect to this url
+ * Exits the current script with 400 code.
+ * @todo nice display if $template loaded
+ *
+ * @param string $msg
+ * @param string|null $alternate_url redirect to this url
*/
function bad_request($msg, $alternate_url=null)
{
@@ -369,9 +372,11 @@ function bad_request($msg, $alternate_url=null)
}
/**
- * exits the current script with 404 code when a page cannot be found
- * @param string msg a message to display
- * @param string alternate_url redirect to this url
+ * Exits the current script with 404 code.
+ * @todo nice display if $template loaded
+ *
+ * @param string $msg
+ * @param string|null $alternate_url redirect to this url
*/
function page_not_found($msg, $alternate_url=null)
{
@@ -386,9 +391,12 @@ function page_not_found($msg, $alternate_url=null)
}
/**
- * exits the current script with 500 http code
- * this method can be called at any time (does not use template/language/user etc...)
- * @param string msg a message to display
+ * Exits the current script with 500 code.
+ * @todo nice display if $template loaded
+ *
+ * @param string $msg
+ * @param string|null $title
+ * @param bool $show_trace
*/
function fatal_error($msg, $title=null, $show_trace=true)
{
@@ -429,7 +437,10 @@ $btrace_msg
die(0); // just in case
}
-/* returns the title to be displayed above thumbnails on tag page
+/**
+ * Returns the breadcrumb to be displayed above thumbnails on tag page.
+ *
+ * @return string
*/
function get_tags_content_title()
{
@@ -452,7 +463,7 @@ function get_tags_content_title()
.'" title="'
.l10n('display photos linked to this tag')
.'">'
- .trigger_event('render_tag_name', $page['tags'][$i]['name'])
+ .trigger_event('render_tag_name', $page['tags'][$i]['name'], $page['tags'][$i])
.'</a>';
if (count($page['tags']) > 2)
@@ -478,7 +489,9 @@ function get_tags_content_title()
}
/**
- Sets the http status header (200,401,...)
+ * Sets the http status header (200,401,...)
+ * @param int $code
+ * @param string $text for exotic http codes
*/
function set_status_header($code, $text='')
{
@@ -507,16 +520,25 @@ function set_status_header($code, $text='')
trigger_action('set_status_header', $code, $text);
}
-/** returns the category comment for rendering in html textual mode (subcatify)
- * this is an event handler. don't call directly
+/**
+ * Returns the category comment for rendering in html textual mode (subcatify)
+ * This method is called by a trigger_action()
+ *
+ * @param string $desc
+ * @return string
*/
function render_category_literal_description($desc)
{
return strip_tags($desc, '<span><p><a><br><b><i><small><big><strong><em>');
}
-/*event handler for menu*/
-function register_default_menubar_blocks( $menu_ref_arr )
+/**
+ * Add known menubar blocks.
+ * This method is called by a trigger_event()
+ *
+ * @param BlockManager[] $menu_ref_arr
+ */
+function register_default_menubar_blocks($menu_ref_arr)
{
$menu = & $menu_ref_arr[0];
if ($menu->get_id() != 'menubar')
@@ -530,34 +552,46 @@ function register_default_menubar_blocks( $menu_ref_arr )
}
/**
+ * Returns display name for an element.
+ * Returns 'name' if exists of name from 'file'.
+ *
+ * @param array $info at least file or name
+ * @return string
*/
function render_element_name($info)
{
- $name = $info['name'];
- if (!empty($name))
+ if (!empty($info['name']))
{
- $name = trigger_event('render_element_name', $name);
- return $name;
+ return trigger_event('render_element_name', $info['name']);
}
-
return get_name_from_file($info['file']);
}
-function render_element_description($info)
+/**
+ * Returns display description for an element.
+ *
+ * @param array $info at least comment
+ * @param string $param used to identify the trigger
+ * @return string
+ */
+function render_element_description($info, $param='')
{
- $comment = $info['comment'];
- if (!empty($comment))
+ if (!empty($info['comment']))
{
- $comment = trigger_event('render_element_description', $comment);
- return $comment;
+ return trigger_event('render_element_description', $info['comment'], $param);
}
return '';
}
/**
- * returns the title of the thumbnail based on photo properties
+ * Add info to the title of the thumbnail based on photo properties.
+ *
+ * @param array $info hit, rating_score, nb_comments
+ * @param string $title
+ * @param string $comment
+ * @return string
*/
-function get_thumbnail_title($info, $title, $comment)
+function get_thumbnail_title($info, $title, $comment='')
{
global $conf, $user;
@@ -585,21 +619,35 @@ function get_thumbnail_title($info, $title, $comment)
if (!empty($comment))
{
- $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
+ $comment = strip_tags($comment);
+ $title.= ' '.substr($comment, 0, 100).(strlen($comment) > 100 ? '...' : '');
}
$title = htmlspecialchars(strip_tags($title));
$title = trigger_event('get_thumbnail_title', $title, $info);
+
return $title;
}
-/** optional event handler to protect src image urls */
+/**
+ * Event handler to protect src image urls.
+ *
+ * @param string $url
+ * @param SrcImage $src_image
+ * @return string
+ */
function get_src_image_url_protection_handler($url, $src_image)
{
return get_action_url($src_image->id, $src_image->is_original() ? 'e' : 'r', false);
}
-/** optional event handler to protect element urls */
+/**
+ * Event handler to protect element urls.
+ *
+ * @param string $url
+ * @param array $infos id, path
+ * @return string
+ */
function get_element_url_protection_handler($url, $infos)
{
global $conf;
@@ -614,7 +662,9 @@ function get_element_url_protection_handler($url, $infos)
return get_action_url($infos['id'], 'e', false);
}
-
+/**
+ * Sends to the template all messages stored in $page and in the session.
+ */
function flush_page_messages()
{
global $template, $page;