2016-11-07 17:41:46 +08:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CodeIgniter
|
|
|
|
*
|
|
|
|
* An open source application development framework for PHP
|
|
|
|
*
|
|
|
|
* This content is released under the MIT License (MIT)
|
|
|
|
*
|
2018-01-09 01:01:00 -08:00
|
|
|
* Copyright (c) 2014-2018 British Columbia Institute of Technology
|
2016-11-07 17:41:46 +08:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @package CodeIgniter
|
|
|
|
* @author CodeIgniter Dev Team
|
2018-01-09 01:01:00 -08:00
|
|
|
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
|
2017-01-20 00:45:11 -08:00
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
|
|
* @link https://codeigniter.com
|
2016-11-07 17:41:46 +08:00
|
|
|
* @since Version 3.0.0
|
|
|
|
* @filesource
|
|
|
|
*/
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CodeIgniter HTML Helper
|
|
|
|
*
|
|
|
|
* @package CodeIgniter
|
|
|
|
* @subpackage Helpers
|
|
|
|
* @category Helpers
|
|
|
|
* @author CodeIgniter Dev Team
|
2017-01-20 00:45:11 -08:00
|
|
|
* @link https://codeigniter.com/user_guide/helpers/html_helper.html
|
2016-11-07 17:41:46 +08:00
|
|
|
*/
|
|
|
|
if ( ! function_exists('ul'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Unordered List
|
|
|
|
*
|
2017-11-04 05:49:12 -02:00
|
|
|
* Generates an HTML unordered list from an single or
|
2016-11-17 22:27:56 +08:00
|
|
|
* multi-dimensional array.
|
|
|
|
*
|
|
|
|
* @param array $list
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function ul(array $list, string $attributes = ''): string
|
|
|
|
{
|
|
|
|
return _list('ul', $list, $attributes);
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('ol'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Ordered List
|
|
|
|
*
|
|
|
|
* Generates an HTML ordered list from an single or multi-dimensional array.
|
|
|
|
*
|
|
|
|
* @param array $list
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function ol(array $list, string $attributes = ''): string
|
|
|
|
{
|
|
|
|
return _list('ol', $list, $attributes);
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('_list'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Generates the list
|
|
|
|
*
|
|
|
|
* Generates an HTML ordered list from an single or multi-dimensional array.
|
|
|
|
*
|
|
|
|
* @param string $type
|
2018-06-29 12:59:46 -07:00
|
|
|
* @param mixed $list
|
2016-11-17 22:27:56 +08:00
|
|
|
* @param string $attributes
|
|
|
|
* @param int $depth
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-06-29 12:59:46 -07:00
|
|
|
function _list(string $type = 'ul', $list = [], string $attributes = '', int $depth = 0): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
|
|
|
// Set the indentation based on the depth
|
|
|
|
$out = str_repeat(' ', $depth)
|
2017-07-13 10:22:49 -07:00
|
|
|
// Write the opening list tag
|
|
|
|
. '<' . $type . stringify_attributes($attributes) . ">\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Cycle through the list elements. If an array is
|
|
|
|
// encountered we will recursively call _list()
|
|
|
|
|
|
|
|
static $_last_list_item = '';
|
|
|
|
foreach ($list as $key => $val)
|
|
|
|
{
|
|
|
|
$_last_list_item = $key;
|
|
|
|
|
|
|
|
$out .= str_repeat(' ', $depth + 2) . '<li>';
|
|
|
|
|
|
|
|
if ( ! is_array($val))
|
|
|
|
{
|
|
|
|
$out .= $val;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
$out .= $_last_list_item
|
|
|
|
. "\n"
|
|
|
|
. _list($type, $val, '', $depth + 4)
|
|
|
|
. str_repeat(' ', $depth + 2);
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$out .= "</li>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the indentation for the closing tag and apply it
|
|
|
|
return $out . str_repeat(' ', $depth) . '</' . $type . ">\n";
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('img'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Image
|
|
|
|
*
|
|
|
|
* Generates an image element
|
|
|
|
*
|
|
|
|
* @param mixed $src
|
|
|
|
* @param bool $indexPage
|
2018-06-29 12:59:46 -07:00
|
|
|
* @param mixed $attributes
|
2016-11-17 22:27:56 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-06-29 12:59:46 -07:00
|
|
|
function img($src = '', bool $indexPage = false, $attributes = ''): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
if ( ! is_array($src))
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
|
|
|
$src = ['src' => $src];
|
|
|
|
}
|
|
|
|
|
|
|
|
//If there is no alt attribute defined, set it to an empty string.
|
|
|
|
if ( ! isset($src['alt']))
|
|
|
|
{
|
|
|
|
$src['alt'] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$img = '<img';
|
|
|
|
|
|
|
|
foreach ($src as $k => $v)
|
|
|
|
{
|
2017-11-04 05:49:12 -02:00
|
|
|
//Include a protocol if nothing is explicitely defined.
|
2016-11-17 22:27:56 +08:00
|
|
|
if ($k === 'src' && ! preg_match('#^([a-z]+:)?//#i', $v))
|
|
|
|
{
|
|
|
|
if ($indexPage === true)
|
|
|
|
{
|
|
|
|
$img .= ' src="' . site_url($v) . '"';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$img .= ' src="' . slash_item('baseURL') . $v . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$img .= ' ' . $k . '="' . $v . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $img . stringify_attributes($attributes) . ' />';
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('doctype'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Doctype
|
|
|
|
*
|
|
|
|
* Generates a page document type declaration
|
|
|
|
*
|
|
|
|
* Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans,
|
|
|
|
* xhtml-frame, html4-strict, html4-trans, and html4-frame.
|
|
|
|
* All values are saved in the doctypes config file.
|
|
|
|
*
|
2018-06-29 12:59:46 -07:00
|
|
|
* @param string $type The doctype to be generated
|
2016-11-17 22:27:56 +08:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-06-29 12:59:46 -07:00
|
|
|
function doctype(string $type = 'html5'): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
$config = new \Config\DocTypes();
|
|
|
|
$doctypes = $config->list;
|
2017-12-13 00:54:31 -02:00
|
|
|
return $doctypes[$type] ?? false;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('script_tag'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Script
|
|
|
|
*
|
|
|
|
* Generates link to a JS file
|
|
|
|
*
|
|
|
|
* @param mixed $src Script source or an array
|
|
|
|
* @param bool $indexPage Should indexPage be added to the JS path
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-06-29 12:59:46 -07:00
|
|
|
function script_tag($src = '', bool $indexPage = false): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
|
|
|
$script = '<script ';
|
2018-06-29 12:59:46 -07:00
|
|
|
if ( ! is_array($src))
|
|
|
|
{
|
|
|
|
$src = ['src' => $src];
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-06-29 12:59:46 -07:00
|
|
|
foreach ($src as $k => $v)
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
if ($k === 'src' && ! preg_match('#^([a-z]+:)?//#i', $v))
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
if ($indexPage === true)
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
$script .= 'src="' . site_url($v) . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
$script .= 'src="' . slash_item('baseURL') . $v . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
$script .= $k . '="' . $v . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $script . 'type="text/javascript"' . "></script>";
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if ( ! function_exists('link_tag'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
/**
|
|
|
|
* Link
|
|
|
|
*
|
|
|
|
* Generates link to a CSS file
|
|
|
|
*
|
2018-06-29 12:59:46 -07:00
|
|
|
* @param mixed $href Stylesheet href or an array
|
2016-11-17 22:27:56 +08:00
|
|
|
* @param string $rel
|
|
|
|
* @param string $type
|
|
|
|
* @param string $title
|
|
|
|
* @param string $media
|
|
|
|
* @param bool $indexPage should indexPage be added to the CSS path.
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-06-29 12:59:46 -07:00
|
|
|
function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/css', string $title = '', string $media = '', bool $indexPage = false): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
|
|
|
$link = '<link ';
|
|
|
|
|
2018-06-29 12:59:46 -07:00
|
|
|
// extract fields if needed
|
2016-11-17 22:27:56 +08:00
|
|
|
if (is_array($href))
|
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
$rel = $href['rel'] ?? $rel;
|
|
|
|
$type = $href['type'] ?? $type;
|
|
|
|
$title = $href['title'] ?? $title;
|
|
|
|
$media = $href['media'] ?? $media;
|
|
|
|
$indexPage = $href['indexPage'] ?? $indexPage;
|
|
|
|
$href = $href['href'] ?? '';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2018-06-29 12:59:46 -07:00
|
|
|
|
|
|
|
if ( ! preg_match('#^([a-z]+:)?//#i', $href))
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-06-29 12:59:46 -07:00
|
|
|
if ($indexPage === true)
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
|
|
|
$link .= 'href="' . site_url($href) . '" ';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$link .= 'href="' . slash_item('baseURL') . $href . '" ';
|
|
|
|
}
|
2018-06-29 12:59:46 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
$link .= 'href="' . $href . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-06-29 12:59:46 -07:00
|
|
|
$link .= 'rel="' . $rel . '" type="' . $type . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-06-29 12:59:46 -07:00
|
|
|
if ($media !== '')
|
|
|
|
{
|
|
|
|
$link .= 'media="' . $media . '" ';
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-06-29 12:59:46 -07:00
|
|
|
if ($title !== '')
|
|
|
|
{
|
|
|
|
$link .= 'title="' . $title . '" ';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $link . "/>";
|
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('video'))
|
|
|
|
{
|
2017-12-31 06:28:29 -02:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Video
|
|
|
|
*
|
|
|
|
* Geneartes a video element to embed videos. The video element can
|
|
|
|
* contain one or more video sources
|
|
|
|
*
|
|
|
|
* @param mixed $src Either a source string or an array of sources
|
|
|
|
* @param string $unsupportedMessage The message to display
|
|
|
|
* if the media tag is not supported by the browser
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @param array $tracks
|
|
|
|
* @param bool $indexPage
|
|
|
|
* @return string
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function video($src, string $unsupportedMessage = '', string $attributes = '', array $tracks = [], bool $indexPage = false): string
|
|
|
|
{
|
|
|
|
if (is_array($src))
|
|
|
|
{
|
|
|
|
return _media('video', $src, $unsupportedMessage, $attributes, $tracks);
|
|
|
|
}
|
2017-12-31 06:28:29 -02:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$video = '<video';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if (_has_protocol($src))
|
|
|
|
{
|
|
|
|
$video .= ' src="' . $src . '"';
|
|
|
|
}
|
|
|
|
elseif ($indexPage === true)
|
|
|
|
{
|
|
|
|
$video .= ' src="' . site_url($src) . '"';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$video .= ' src="' . slash_item('baseURL') . $src . '"';
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ($attributes !== '')
|
|
|
|
{
|
|
|
|
$video .= ' ' . $attributes;
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$video .= ">\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($tracks))
|
|
|
|
{
|
|
|
|
foreach ($tracks as $track)
|
2017-12-31 06:28:29 -02:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$video .= _space_indent() . $track . "\n";
|
2017-12-31 06:28:29 -02:00
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($unsupportedMessage))
|
|
|
|
{
|
|
|
|
$video .= _space_indent()
|
|
|
|
. $unsupportedMessage
|
|
|
|
. "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$video .= "</video>\n";
|
|
|
|
|
|
|
|
return $video;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('audio'))
|
|
|
|
{
|
2017-12-31 06:28:29 -02:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Audio
|
|
|
|
*
|
|
|
|
* Generates an audio element to embed sounds
|
|
|
|
*
|
|
|
|
* @param mixed $src Either a source string or an array of sources
|
|
|
|
* @param string $unsupportedMessage The message to display if the media tag is not supported by the browser.
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @param array $tracks
|
|
|
|
* @param bool $indexPage
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function audio($src, string $unsupportedMessage = '', string $attributes = '', array $tracks = [], bool $indexPage = false): string
|
|
|
|
{
|
|
|
|
if (is_array($src))
|
|
|
|
{
|
|
|
|
return _media('audio', $src, $unsupportedMessage, $attributes, $tracks);
|
|
|
|
}
|
2017-12-31 06:28:29 -02:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$audio = '<audio';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if (_has_protocol($src))
|
|
|
|
{
|
|
|
|
$audio .= ' src="' . $src . '"';
|
|
|
|
}
|
|
|
|
elseif ($indexPage === true)
|
|
|
|
{
|
|
|
|
$audio .= ' src="' . site_url($src) . '"';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$audio .= ' src="' . slash_item('baseURL') . $src . '"';
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ($attributes !== '')
|
|
|
|
{
|
|
|
|
$audio .= ' ' . $attributes;
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$audio .= '>';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($tracks))
|
|
|
|
{
|
|
|
|
foreach ($tracks as $track)
|
2017-12-31 06:28:29 -02:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$audio .= "\n" . _space_indent() . $track;
|
2017-12-31 06:28:29 -02:00
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($unsupportedMessage))
|
|
|
|
{
|
|
|
|
$audio .= "\n" . _space_indent() . $unsupportedMessage . "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$audio .= "</audio>\n";
|
|
|
|
|
|
|
|
return $audio;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 22:27:56 +08:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('_media'))
|
|
|
|
{
|
|
|
|
|
|
|
|
function _media(string $name, array $types = [], string $unsupportedMessage = '', string $attributes = '', array $tracks = []): string
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$media = '<' . $name;
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if (empty($attributes))
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$media .= '>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$media .= ' ' . $attributes . '>';
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$media .= "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
foreach ($types as $option)
|
|
|
|
{
|
|
|
|
$media .= _space_indent() . $option . "\n";
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($tracks))
|
|
|
|
{
|
|
|
|
foreach ($tracks as $track)
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$media .= _space_indent() . $track . "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($unsupportedMessage))
|
|
|
|
{
|
|
|
|
$media .= _space_indent() . $unsupportedMessage . "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$media .= '</' . $name . ">\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
return $media;
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('source'))
|
|
|
|
{
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Source
|
|
|
|
*
|
|
|
|
* Generates a source element that specifies multiple media resources
|
|
|
|
* for either audio or video element
|
|
|
|
*
|
|
|
|
* @param string $src The path of the media resource
|
|
|
|
* @param string $type The MIME-type of the resource with
|
|
|
|
* optional codecs parameters
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @param bool $indexPage
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function source(string $src, string $type = 'unknown', string $attributes = '', bool $indexPage = false): string
|
|
|
|
{
|
|
|
|
if ( ! _has_protocol($src))
|
|
|
|
if ($indexPage === true)
|
|
|
|
{
|
|
|
|
$src = site_url($src);
|
|
|
|
}
|
|
|
|
else
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$src = slash_item('baseURL') . $src;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$source = '<source src="' . $src
|
|
|
|
. '" type="' . $type . '"';
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! empty($attributes))
|
|
|
|
{
|
|
|
|
$source .= ' ' . $attributes;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$source .= ' />';
|
|
|
|
|
|
|
|
return $source;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('track'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Track
|
|
|
|
*
|
|
|
|
* Generates a track element to specify timed tracks. The tracks are
|
|
|
|
* formatted in WebVTT format.
|
|
|
|
*
|
|
|
|
* @param string $src The path of the .VTT file
|
|
|
|
* @param string $kind
|
|
|
|
* @param string $srcLanguage
|
|
|
|
* @param string $label
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function track(string $src, string $kind, string $srcLanguage, string $label): string
|
|
|
|
{
|
|
|
|
return '<track src="' . $src
|
|
|
|
. '" kind="' . $kind
|
|
|
|
. '" srclang="' . $srcLanguage
|
|
|
|
. '" label="' . $label
|
|
|
|
. '" />';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('object'))
|
|
|
|
{
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Object
|
|
|
|
*
|
|
|
|
* Generates an object element that represents the media
|
|
|
|
* as either image or a resource plugin such as audio, video,
|
|
|
|
* Java applets, ActiveX, PDF and Flash
|
|
|
|
*
|
|
|
|
* @param string $data A resource URL
|
|
|
|
* @param string $type Content-type of the resource
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @param array $params
|
|
|
|
* @param bool $indexPage
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function object(string $data, string $type = 'unknown', string $attributes = '', array $params = [], bool $indexPage = false): string
|
|
|
|
{
|
|
|
|
if ( ! _has_protocol($data))
|
|
|
|
if ($indexPage === true)
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$data = site_url($data);
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
else
|
2016-11-17 22:27:56 +08:00
|
|
|
{
|
2018-08-04 00:02:47 +02:00
|
|
|
$data = slash_item('baseURL') . $data;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$object = '<object data="' . $data . '" '
|
|
|
|
. $attributes . '>';
|
|
|
|
|
|
|
|
if ( ! empty($params))
|
|
|
|
{
|
|
|
|
$object .= "\n";
|
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
foreach ($params as $param)
|
|
|
|
{
|
|
|
|
$object .= _space_indent() . $param . "\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
$object .= "</object>\n";
|
|
|
|
|
|
|
|
return $object;
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('param'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Param
|
|
|
|
*
|
|
|
|
* Generates a param element that defines parameters
|
|
|
|
* for the object element.
|
|
|
|
*
|
|
|
|
* @param string $name The name of the parameter
|
|
|
|
* @param string $value The value of the parameter
|
|
|
|
* @param string $type The MIME-type
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function param(string $name, string $value, string $type = 'ref', string $attributes = ''): string
|
|
|
|
{
|
|
|
|
return '<param name="' . $name
|
|
|
|
. '" type="' . $type
|
|
|
|
. '" value="' . $value
|
|
|
|
. '" ' . $attributes . ' />';
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('embed'))
|
|
|
|
{
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
/**
|
|
|
|
* Embed
|
|
|
|
*
|
|
|
|
* Generates an embed element
|
|
|
|
*
|
|
|
|
* @param string $src The path of the resource to embed
|
|
|
|
* @param string $type MIME-type
|
|
|
|
* @param string $attributes HTML attributes
|
|
|
|
* @param bool $indexPage
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function embed(string $src, string $type='unknown', string $attributes = '', bool $indexPage = false): string
|
|
|
|
{
|
|
|
|
if ( ! _has_protocol($src))
|
|
|
|
if ($indexPage === true)
|
|
|
|
{
|
|
|
|
$src = site_url($src);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$src = slash_item('baseURL') . $src;
|
|
|
|
}
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
return '<embed src="' . $src
|
|
|
|
. '" type="' . $type . '" '
|
|
|
|
. $attributes . " />\n";
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('_has_protocol'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
function _has_protocol($url)
|
|
|
|
{
|
|
|
|
return preg_match('#^([a-z]+:)?//#i', $url);
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
}
|
2016-11-17 22:27:56 +08:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
// ------------------------------------------------------------------------
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
if ( ! function_exists('_space_indent'))
|
|
|
|
{
|
2017-07-13 10:22:49 -07:00
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
function _space_indent($depth = 2)
|
|
|
|
{
|
|
|
|
return str_repeat(' ', $depth);
|
2016-11-17 22:27:56 +08:00
|
|
|
}
|
2018-08-04 00:02:47 +02:00
|
|
|
|
2016-11-07 17:41:46 +08:00
|
|
|
}
|
|
|
|
|
2018-08-04 00:02:47 +02:00
|
|
|
|
2017-11-04 05:49:12 -02:00
|
|
|
// ------------------------------------------------------------------------
|