feat: add videodb media index with Docker stack
- Add videodb PHP/MySQL media collection manager (Blu-ray, DVD, CD) - Dockerfile: PHP 8.1 + Apache with GD/mysqli/exif extensions - docker-compose.yml: app on port 6761 + MySQL 8.0 with health checks - docker-entrypoint.sh: auto-generates config.inc.php from env vars, waits for MySQL, initializes DB schema idempotently - init-db.php: CLI schema installer using app's own prefix_query() logic - Persistent volumes for DB, cache, and cover images Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
83
videodb/lib/smarty/custom/function.html_checkbox.php
Normal file
83
videodb/lib/smarty/custom/function.html_checkbox.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
* @author Andreas Goetz <cpuidle@gmx.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_checkbox} function plugin
|
||||
*
|
||||
* File: function.html_checkbox.php<br>
|
||||
* Type: function<br>
|
||||
* Name: html_checkbox<br>
|
||||
* Purpose: Prints out a checkbox input<br>
|
||||
* Input:<br>
|
||||
* - name (optional) - string default "checkbox"
|
||||
* - value (required) - string
|
||||
* - checked (optional) - array default not set
|
||||
* - id (optional) - checkbox id (name is default)
|
||||
* - label (optional) - string for checkbox label
|
||||
* Examples:
|
||||
* <pre>
|
||||
* {html_checkbox value=1 name=horst}
|
||||
* {html_checkbox value=1 name=horst label="Select Horst"}
|
||||
* </pre>
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_checkbox($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
|
||||
$name = 'checkbox';
|
||||
$value = null;
|
||||
$selected = null;
|
||||
$label = null;
|
||||
|
||||
$extra = '';
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
case 'id':
|
||||
case 'value':
|
||||
case 'label':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
||||
case 'checked':
|
||||
case 'selected':
|
||||
$selected = (bool)$_val;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
} else {
|
||||
trigger_error("html_checkbox: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// assign default id
|
||||
if (empty($id)) $id = $name;
|
||||
|
||||
$_output = '';
|
||||
if ($label) $_output .= '<nobr><label for="'.smarty_function_escape_special_chars($id).'">';
|
||||
|
||||
$_output .= '<input type="checkbox" name="'
|
||||
. smarty_function_escape_special_chars($name) . '" id="'
|
||||
. smarty_function_escape_special_chars($id) . '" value="'
|
||||
. smarty_function_escape_special_chars($value). '"';
|
||||
|
||||
if ($selected) $_output .= ' checked="checked"';
|
||||
$_output .= $extra .' />';
|
||||
if ($label) $_output .= $label.'</label></nobr>';
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
?>
|
||||
349
videodb/lib/smarty/custom/function.html_image.php
Normal file
349
videodb/lib/smarty/custom/function.html_image.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
* @author Andreas Goetz <cpuidle@gmx.de>
|
||||
*/
|
||||
|
||||
////require_once('./vendor/james-heinrich/phpthumb/phpthumb.class.php');
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
define('THUMB_CACHE_SOURCE', true);
|
||||
define('THUMB_CACHE_TARGET', true);
|
||||
|
||||
/**
|
||||
* This function is to replace PHP's extremely buggy realpath().
|
||||
* http://stackoverflow.com/questions/4049856/replace-phps-realpath
|
||||
* @param string The original path, can be relative etc.
|
||||
* @return string The resolved path, it might not exist.
|
||||
*/
|
||||
function truepath($path){
|
||||
// whether $path is unix or not
|
||||
$relpath = strlen($path)==0 || $path[0]!='/';
|
||||
// attempts to detect if path is relative in which case, add cwd
|
||||
if (strpos($path,':')===false && $relpath) {
|
||||
$path = getcwd().DIRECTORY_SEPARATOR.$path;
|
||||
$relpath = false;
|
||||
}
|
||||
// resolve path parts (single dot, double dot and double delimiters)
|
||||
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
|
||||
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
|
||||
$absolutes = array();
|
||||
foreach ($parts as $part) {
|
||||
if ('.' == $part) continue;
|
||||
if ('..' == $part) {
|
||||
array_pop($absolutes);
|
||||
} else {
|
||||
$absolutes[] = $part;
|
||||
}
|
||||
}
|
||||
$path = implode(DIRECTORY_SEPARATOR, $absolutes);
|
||||
// resolve any symlinks
|
||||
if (file_exists($path) && linkinfo($path)>0) {
|
||||
$path = readlink($path);
|
||||
// } else {
|
||||
} elseif (strpos($path,':') === false && !$relpath) {
|
||||
// put back initial unix separator that could have been lost
|
||||
// $path = (strpos($path,':')>=0 || $relpath) ? $path : '/'.$path;
|
||||
$path = '/'.$path;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
function html_image_get_cache($tag, &$width, &$height)
|
||||
{
|
||||
$res = runSQL("SELECT * FROM ".TBL_CACHE." WHERE tag='".escapeSQL($tag)."'");
|
||||
|
||||
if (count($res))
|
||||
{
|
||||
if (preg_match('/(\d+)x(\d+)/', $res[0]['value'], $m))
|
||||
{
|
||||
list($foo, $width, $height) = $m;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function html_image_put_cache($tag, $value)
|
||||
{
|
||||
$res = runSQL("REPLACE INTO ".TBL_CACHE." SET tag='".escapeSQL($tag)."', value='".escapeSQL($value)."'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Thumbnail generation
|
||||
*/
|
||||
function generate_thumbnail(&$file, &$width, &$height, $max_width, $max_height, $cache_tag)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$thumb_cache_tag = $cache_tag.'_'.$max_width.'x'.$max_height;
|
||||
|
||||
// the names of the existing or to-be created thumbnail- still missing dimensions
|
||||
$thumb_name = './cache/'.CACHE_THUMBS.'/'.
|
||||
(($config['hierarchical']) ? substr($cache_tag, 0, 1).'/' : '').
|
||||
$cache_tag;
|
||||
|
||||
// did we already create this thumbnail?
|
||||
if (THUMB_CACHE_TARGET && html_image_get_cache($thumb_cache_tag, $width, $height))
|
||||
{
|
||||
// get updated filename
|
||||
$file = $thumb_name.'_'.$width.'x'.$height.'.jpg';
|
||||
return;
|
||||
}
|
||||
|
||||
// thumbnail not created yet
|
||||
$scale = min($max_width/$width, $max_height/$height);
|
||||
$width = round($width * $scale);
|
||||
$height = round($height * $scale);
|
||||
|
||||
// really need to scale?
|
||||
$thumb_must_scale = (($config['thumbnail_level'] == TUMB_SCALE) ||
|
||||
($config['thumbnail_level'] == TUMB_REDUCE_ONLY && ($scale < 1)) ||
|
||||
($config['thumbnail_level'] > 1) && ($config['thumbnail_level'] < @filesize($file)));
|
||||
#dump("scaling required: ".(int)$thumb_must_scale." filesize: ".@filesize($file));
|
||||
|
||||
// perform actual scaling
|
||||
if ($thumb_must_scale)
|
||||
{
|
||||
$phpThumb = new phpThumb();
|
||||
|
||||
// use of truepath was added for php 5.4 apparently- otherwise thumbnail creation would inadvertantly fail
|
||||
$phpThumb->config_cache_directory = '';
|
||||
$phpThumb->src = '';
|
||||
$phpThumb->sourceFilename = truepath($file);
|
||||
$phpThumb->w = $max_width;
|
||||
$phpThumb->h = $max_height;
|
||||
if ($config['thumbnail_quality']) $phpThumb->q = $config['thumbnail_quality'];
|
||||
|
||||
// set cache filename
|
||||
$thumb_name .= '_'.$width.'x'.$height.'.jpg';
|
||||
#dump("thumbname:$thumb_name");
|
||||
|
||||
// check to see if file already exists in cache, and output it with no processing if it does
|
||||
if (is_writable(dirname($thumb_name)) || is_writable($thumb_name))
|
||||
{
|
||||
if (@filesize($thumb_name) ||
|
||||
($phpThumb->GenerateThumbnail() && $phpThumb->RenderOutput() &&
|
||||
file_put_contents($thumb_name, $phpThumb->outputImageData)))
|
||||
{
|
||||
$file = $thumb_name;
|
||||
if (THUMB_CACHE_TARGET) html_image_put_cache($thumb_cache_tag, $width.'x'.$height);
|
||||
}
|
||||
/*
|
||||
# emergency debugging
|
||||
else
|
||||
{
|
||||
dlog("Fail: $thumb_name");
|
||||
dlog("fs: ".@filesize($thumb_name));
|
||||
dlog($phpThumb->GenerateThumbnail());
|
||||
dlog($phpThumb->RenderOutput());
|
||||
dlog($phpThumb->debugmessages);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// free memory
|
||||
$phpThumb = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty {html_image} function plugin
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: html_image<br>
|
||||
* Date: Feb 24, 2003<br>
|
||||
* Purpose: format HTML tags for the image<br>
|
||||
* Examples: {html_image file="/images/masthead.gif"}
|
||||
* Output: <img src="/images/masthead.gif" width=400 height=23>
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author credits to Duda <duda@big.hu>
|
||||
* @version 1.0
|
||||
* @param array $params parameters
|
||||
* Input:<br>
|
||||
* - file = file (and path) of image (required)
|
||||
* - height = image height (optional, default actual height)
|
||||
* - width = image width (optional, default actual width)
|
||||
* - basedir = base directory for absolute paths, default
|
||||
* is environment variable DOCUMENT_ROOT
|
||||
* - path_prefix = prefix for path output (optional, default empty)
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_image($params, $template)
|
||||
{
|
||||
global $config;
|
||||
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
|
||||
$alt = '';
|
||||
$file = '';
|
||||
$border = 0;
|
||||
$height = '';
|
||||
$width = '';
|
||||
$extra = '';
|
||||
$prefix = '';
|
||||
$suffix = '';
|
||||
$path_only = false;
|
||||
$path_prefix = '';
|
||||
$server_vars = $_SERVER;
|
||||
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
|
||||
$no_scaling = false;
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'file':
|
||||
case 'height':
|
||||
case 'width':
|
||||
case 'dpi':
|
||||
case 'path_only':
|
||||
case 'path_prefix':
|
||||
case 'basedir':
|
||||
//!! cpuidle@gmx.de
|
||||
case 'border':
|
||||
case 'max_width':
|
||||
case 'max_height':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
||||
case 'alt':
|
||||
if(!is_array($_val)) {
|
||||
$$_key = smarty_function_escape_special_chars($_val);
|
||||
} else {
|
||||
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'link':
|
||||
case 'href':
|
||||
// cpuidle@gmx.de suppress hrefs without link
|
||||
if (!empty($_val)) {
|
||||
$prefix = '<a href="' . $_val . '">';
|
||||
$suffix = '</a>';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
} else {
|
||||
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (substr($file, 0, 1) == '/') {
|
||||
$_image_path = $basedir . $file;
|
||||
} else {
|
||||
$_image_path = $file;
|
||||
}
|
||||
|
||||
#dlog("\nimg: $_image_path");
|
||||
|
||||
if (!isset($params['width']) || !isset($params['height']))
|
||||
{
|
||||
// cpuidle@gmx.de check for non-local images
|
||||
if (preg_match("/nocover|^(http:|img\.php)/", $_image_path))
|
||||
{
|
||||
$no_scaling = true;
|
||||
#dlog("no scaling");
|
||||
}
|
||||
else
|
||||
{
|
||||
// do we already know this image?
|
||||
$cache_tag = md5($_image_path);
|
||||
|
||||
// are we creating thumbnails and can we get the thumbnail from cache?
|
||||
if (!(THUMB_CACHE_SOURCE && html_image_get_cache($cache_tag, $width, $height)))
|
||||
{
|
||||
if ($_image_data = @getimagesize($_image_path)) {
|
||||
if (!isset($params['width'])) $width = $_image_data[0];
|
||||
if (!isset($params['height'])) $height = $_image_data[1];
|
||||
if (THUMB_CACHE_SOURCE) html_image_put_cache($cache_tag, $width.'x'.$height);
|
||||
#dlog("cache commit: $width $height");
|
||||
}
|
||||
else {
|
||||
#dlog("image error: $_image_path");
|
||||
// TODO check how to handle non-existing images
|
||||
if (!file_exists($_image_path)) {
|
||||
trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
|
||||
return;
|
||||
} else if(!is_readable($_image_path)) {
|
||||
trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
|
||||
return;
|
||||
} else {
|
||||
trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($template->security_policy)) {
|
||||
if (!$template->security_policy->isTrustedResourceDir($_image_path)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($width)) $width = $max_width;
|
||||
if (empty($height)) $height = $max_height;
|
||||
|
||||
/*
|
||||
* Scaling is required if:
|
||||
* - scale mode TUMB_SCALE
|
||||
* - scale mode TUMB_REDUCE_ONLY and dimensions > target dimensions
|
||||
* - scale mode is any other numeric and filesize > scale mode
|
||||
*/
|
||||
if ($max_width && $max_height && !$no_scaling)
|
||||
{
|
||||
// even if thumbnails are not generated we should get aspect ratio right
|
||||
if ($config['thumbnail_level'] == TUMB_NO_SCALE)
|
||||
{
|
||||
$scale = min($max_width/$width, $max_height/$height);
|
||||
$width = round($width * $scale);
|
||||
$height = round($height * $scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
generate_thumbnail($file, $width, $height, $max_width, $max_height, $cache_tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['dpi']))
|
||||
{
|
||||
$dpi_default = (strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) ? 72 : 96;
|
||||
$_resize = $dpi_default/$params['dpi'];
|
||||
$width = round($width * $_resize);
|
||||
$height = round($height * $_resize);
|
||||
}
|
||||
|
||||
if ($path_only) {
|
||||
// we only need the image path
|
||||
return($file);
|
||||
}
|
||||
|
||||
$result = $prefix . '<img src="'.$file.'" alt="'.$alt;
|
||||
if (isset($border)) $result .= '" border="'.$border;
|
||||
if ($width) $result .= '" width="'.$width;
|
||||
if ($height) $result .= '" height="'.$height;
|
||||
$result .= '"'.$extra.' />' . $suffix;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
||||
154
videodb/lib/smarty/custom/function.html_radios.php
Normal file
154
videodb/lib/smarty/custom/function.html_radios.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
* @author Andreas Goetz <cpuidle@gmx.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_radios} function plugin
|
||||
*
|
||||
* File: function.html_radios.php<br>
|
||||
* Type: function<br>
|
||||
* Name: html_radios<br>
|
||||
* Date: 24.Feb.2003<br>
|
||||
* Purpose: Prints out a list of radio input types<br>
|
||||
* Examples:
|
||||
* <pre>
|
||||
* {html_radios values=$ids output=$names}
|
||||
* {html_radios values=$ids name='box' separator='<br>' output=$names}
|
||||
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
|
||||
* </pre>
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
|
||||
* (Smarty online manual)
|
||||
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
|
||||
* @author credits to Monte Ohrt <monte at ohrt dot com>
|
||||
* @version 1.0
|
||||
* @param array $params parameters
|
||||
* Input:<br>
|
||||
* - name (optional) - string default "radio"
|
||||
* - values (required) - array
|
||||
* - options (optional) - associative array
|
||||
* - checked (optional) - array default not set
|
||||
* - separator (optional) - ie <br> or
|
||||
* - output (optional) - the output next to each radio button
|
||||
* - assign (optional) - assign the output as an array to this variable
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_radios($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
|
||||
$name = 'radio';
|
||||
$values = null;
|
||||
$options = null;
|
||||
$selected = null;
|
||||
$separator = '';
|
||||
$labels = true;
|
||||
$label_ids = false;
|
||||
$output = null;
|
||||
$extra = '';
|
||||
$label_extra = '';
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
case 'separator':
|
||||
$$_key = (string)$_val;
|
||||
break;
|
||||
|
||||
case 'checked':
|
||||
case 'selected':
|
||||
if(is_array($_val)) {
|
||||
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
|
||||
} else {
|
||||
$selected = (string)$_val;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'labels':
|
||||
case 'label_ids':
|
||||
$$_key = (bool)$_val;
|
||||
break;
|
||||
|
||||
case 'options':
|
||||
$$_key = (array)$_val;
|
||||
break;
|
||||
|
||||
case 'values':
|
||||
case 'output':
|
||||
$$_key = array_values((array)$_val);
|
||||
break;
|
||||
|
||||
case 'radios':
|
||||
trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
|
||||
$options = (array)$_val;
|
||||
break;
|
||||
|
||||
case 'assign':
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
if (preg_match('/label_(.*)/', $_key, $m))
|
||||
$label_extra .= ' '.$m[1].'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
else
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
} else {
|
||||
trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($options) && !isset($values))
|
||||
return '';
|
||||
/* raise error here? */
|
||||
|
||||
$_html_result = '';
|
||||
|
||||
if (isset($options) && is_array($options)) {
|
||||
|
||||
foreach ((array)$options as $_key=>$_val)
|
||||
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_extra);
|
||||
|
||||
} else {
|
||||
|
||||
foreach ((array)$values as $_i=>$_key) {
|
||||
$_val = isset($output[$_i]) ? $output[$_i] : '';
|
||||
$_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_extra);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $_html_result;
|
||||
|
||||
}
|
||||
|
||||
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_extra) {
|
||||
$_output = '';
|
||||
// if ($labels) $_output .= '<label for="'.smarty_function_escape_special_chars($name).smarty_function_escape_special_chars($value).'">';
|
||||
if ($labels) $_output .= '<label for="'.smarty_function_escape_special_chars($name).smarty_function_escape_special_chars($value).'"'.$label_extra.'>';
|
||||
|
||||
$_output .= '<input type="radio" name="'
|
||||
. smarty_function_escape_special_chars($name) . '" id="'
|
||||
. smarty_function_escape_special_chars($name) . smarty_function_escape_special_chars($value) . '" value="'
|
||||
. smarty_function_escape_special_chars($value) . '"';
|
||||
|
||||
if ($value==$selected) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
$_output .= $extra . ' />' . $output;
|
||||
if ($labels) $_output .= '</label>';
|
||||
$_output .= $separator . "\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
?>
|
||||
72
videodb/lib/smarty/custom/function.html_rating.php
Normal file
72
videodb/lib/smarty/custom/function.html_rating.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
* @author Andreas Goetz <cpuidle@gmx.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_rating} function plugin
|
||||
*
|
||||
* File: function.html_rating.php<br>
|
||||
* Type: function<br>
|
||||
* Name: html_rating<br>
|
||||
* Purpose: Prints out a rating as a series of stars<br>
|
||||
* Input:<br>
|
||||
* - name (optional) - string default "checkbox"
|
||||
* - value (required) - string
|
||||
* - id (optional) - checkbox id (name is default)
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_rating($params, &$smarty)
|
||||
{
|
||||
$name = 'rating';
|
||||
$value = null;
|
||||
|
||||
$extra = '';
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
case 'id':
|
||||
case 'value':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
} else {
|
||||
$smarty->trigger_error("rating: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// assign default id
|
||||
if (empty($id)) $id = $name;
|
||||
|
||||
$_output = '';
|
||||
|
||||
$rcv = 0;
|
||||
if (is_numeric($value))
|
||||
{ $rcv = ceil($value); }
|
||||
|
||||
for ($i=0; $i< $rcv; $i++)
|
||||
{
|
||||
$_output .= '<img src="'.img('goldstar.gif').'" width="20" height="18" />';
|
||||
}
|
||||
for ($i=0; $i< (10 - $rcv); $i++)
|
||||
{
|
||||
$_output .= '<img src="'.img('greystar.gif').'" width="20" height="18" />';
|
||||
}
|
||||
|
||||
$_output .= $extra;
|
||||
|
||||
$_output .= " ($value)";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
?>
|
||||
70
videodb/lib/smarty/custom/function.rating_input.php
Normal file
70
videodb/lib/smarty/custom/function.rating_input.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
* @author Andreas Goetz <cpuidle@gmx.de>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {rating_input} function plugin
|
||||
*
|
||||
* File: function.rating_input.php<br>
|
||||
* Type: function<br>
|
||||
* Name: rating_input<br>
|
||||
* Purpose: Prints out a rating input control<br>
|
||||
* Input:<br>
|
||||
* - name (optional) - string default "checkbox"
|
||||
* - value (required) - string
|
||||
* - id (optional) - checkbox id (name is default)
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_rating_input($params, &$smarty)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
//$smarty->loadPlugin('Smarty_shared_escape_special_chars');
|
||||
|
||||
$name = 'rating';
|
||||
$value = null;
|
||||
|
||||
$extra = '';
|
||||
|
||||
foreach($params as $_key => $_val) {
|
||||
switch($_key) {
|
||||
case 'name':
|
||||
case 'id':
|
||||
case 'value':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($_val)) {
|
||||
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
|
||||
} else {
|
||||
$smarty->trigger_error("rating_input: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// assign default id
|
||||
if (empty($id)) $id = $name;
|
||||
|
||||
$_output = '';
|
||||
|
||||
$_output .= '<input type="text" size="10" maxlength="4"'.
|
||||
' name="'.smarty_function_escape_special_chars($name).'"'.
|
||||
' id="'.smarty_function_escape_special_chars($id).'"'.
|
||||
' value="'.smarty_function_escape_special_chars($value).'"';
|
||||
|
||||
$_output .= $extra .' />';
|
||||
|
||||
for ($i=1; $i<=10; $i++)
|
||||
{
|
||||
$_output .= " <a href='#' onclick='document.edi.".$name.".value=\"".$i.'.0"\'>'.$i.'</a>';
|
||||
}
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user