\n"; // 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) . '
  • '; if (! is_array($val)) { $out .= $val; } else { $out .= $_last_list_item . "\n" . _list($type, $val, '', $depth + 4) . str_repeat(' ', $depth + 2); } $out .= "
  • \n"; } // Set the indentation for the closing tag and apply it return $out . str_repeat(' ', $depth) . '\n"; } } // ------------------------------------------------------------------------ if (! function_exists('img')) { /** * Image * * Generates an image element * * @param mixed $src * @param boolean $indexPage * @param mixed $attributes * @return string */ function img($src = '', bool $indexPage = false, $attributes = ''): string { if (! is_array($src)) { $src = ['src' => $src]; } if (! isset($src['alt'])) { $src['alt'] = $attributes['alt'] ?? ''; } $img = ' $v) { //Include a protocol if nothing is explicitely defined. 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 . '"'; } } // prevent passing "alt" to stringify_attributes if (is_array($attributes) && isset($attributes['alt'])) { unset($attributes['alt']); } return $img . stringify_attributes($attributes) . ' />'; } } // ------------------------------------------------------------------------ if (! function_exists('doctype')) { /** * 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. * * @param string $type The doctype to be generated * @return string */ function doctype(string $type = 'html5'): string { $config = new \Config\DocTypes(); $doctypes = $config->list; return $doctypes[$type] ?? false; } } // ------------------------------------------------------------------------ if (! function_exists('script_tag')) { /** * Script * * Generates link to a JS file * * @param mixed $src Script source or an array * @param boolean $indexPage Should indexPage be added to the JS path * @return string */ function script_tag($src = '', bool $indexPage = false): string { $script = ''; } } // ------------------------------------------------------------------------ if (! function_exists('link_tag')) { /** * Link * * Generates link to a CSS file * * @param mixed $href Stylesheet href or an array * @param string $rel * @param string $type * @param string $title * @param string $media * @param boolean $indexPage should indexPage be added to the CSS path. * @return string */ function link_tag($href = '', string $rel = 'stylesheet', string $type = 'text/css', string $title = '', string $media = '', bool $indexPage = false): string { $link = ''; } } // ------------------------------------------------------------------------ if (! function_exists('video')) { /** * Video * * Generates 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 boolean $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); } $video = ''; } $media .= "\n"; foreach ($types as $option) { $media .= _space_indent() . $option . "\n"; } if (! empty($tracks)) { foreach ($tracks as $track) { $media .= _space_indent() . $track . "\n"; } } if (! empty($unsupportedMessage)) { $media .= _space_indent() . $unsupportedMessage . "\n"; } $media .= '\n"; return $media; } } // ------------------------------------------------------------------------ if (! function_exists('source')) { /** * 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 boolean $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 { $src = slash_item('baseURL') . $src; } } $source = ''; } } // ------------------------------------------------------------------------ if (! function_exists('object')) { /** * 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 boolean $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) { $data = site_url($data); } else { $data = slash_item('baseURL') . $data; } } $object = ''; if (! empty($params)) { $object .= "\n"; } foreach ($params as $param) { $object .= _space_indent() . $param . "\n"; } $object .= "\n"; return $object; } } // ------------------------------------------------------------------------ if (! function_exists('param')) { /** * 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 ''; } } // ------------------------------------------------------------------------ if (! function_exists('embed')) { /** * 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 boolean $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; } } return '\n"; } } // ------------------------------------------------------------------------ if (! function_exists('_has_protocol')) { /** * Test the protocol of a URI. * * @param string $url * * @return false|integer */ function _has_protocol(string $url) { return preg_match('#^([a-z]+:)?//#i', $url); } } // ------------------------------------------------------------------------ if (! function_exists('_space_indent')) { /** * Provide space indenting. * * @param integer $depth * * @return string */ function _space_indent(int $depth = 2): string { return str_repeat(' ', $depth); } } // ------------------------------------------------------------------------