Add APP_NAME constant
Improved issue display Add component::prepend Add switches to form html Updated form html to Bootstrap 5. Updated navigation html to Bootstrap 5.
This commit is contained in:
@ -46,12 +46,14 @@ class Components {
|
||||
self::$components[ $name ] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function unset( $name ) {
|
||||
if ( isset( self::$components[ $name ] ) ) {
|
||||
unset( self::$components[ $name ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function append( $name, $value ) {
|
||||
if ( ! isset( self::$components[ $name ] ) ) {
|
||||
return self::set( $name, $value );
|
||||
@ -60,4 +62,13 @@ class Components {
|
||||
self::$components[ $name ] = $curr . $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function prepend( $name, $value ) {
|
||||
if ( ! isset( self::$components[ $name ] ) ) {
|
||||
return self::set( $name, $value );
|
||||
}
|
||||
$curr = self::$components[ $name ];
|
||||
self::$components[ $name ] = $value . $curr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
*/
|
||||
namespace TheTempusProject\Houdini\Classes;
|
||||
|
||||
use TheTempusProject\Canary\Bin\Canary as Debug;
|
||||
use DateTimeZone;
|
||||
|
||||
class Forms {
|
||||
@ -66,6 +67,9 @@ class Forms {
|
||||
case 'checkbox':
|
||||
$fieldHtml = self::getCheckboxHtml( $fieldname, $defaultValue );
|
||||
break;
|
||||
case 'switch':
|
||||
$fieldHtml = self::getSwitchHtml( $fieldname, $defaultValue );
|
||||
break;
|
||||
case 'timezone':
|
||||
$fieldHtml = self::getTimezoneHtml( $defaultValue );
|
||||
break;
|
||||
@ -76,19 +80,18 @@ class Forms {
|
||||
Debug::error( "unknown field type: $type" );
|
||||
break;
|
||||
}
|
||||
$out .= '<div class="form-group">';
|
||||
$out .= '<label for="' . $fieldname . '" class="col-lg-3 control-label">' . $fieldTitle . '</label>';
|
||||
$out .= '<div class="col-lg-3">';
|
||||
|
||||
$out .= '<div class="mb-3">';
|
||||
$out .= '<label for="' . $fieldname . '" class="form-label">' . $fieldTitle . '</label>';
|
||||
$out .= $fieldHtml;
|
||||
$out .= '</div>';
|
||||
// @todo need to remove this or make it more generic (can't depend on bedrock anymore)
|
||||
if ( 'file' === $type ) {
|
||||
$out .= '<div class="col-lg-3 avatar-125" align="center">';
|
||||
$out .= '<img alt="User Avatar" src="' . $defaultValue . '" class="img-circle img-responsive">';
|
||||
$out .= '<img alt="User Avatar" src="{ROOT_URL}' . $defaultValue . '" class="img-circle img-fluid p-2">';
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
return Template::parse( $out );
|
||||
}
|
||||
|
||||
public static function getTimezoneHtml( $default ) {
|
||||
@ -117,7 +120,8 @@ class Forms {
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
return '<input type="checkbox" class="form-control" name="' . $name . '" id="' . $name . '" value="true"' . $checked . '>';
|
||||
return '<div class="form-check"><input class="form-check-input" type="checkbox" value="true" name="' . $name . '" id="' . $name . '"' . $checked . '>
|
||||
<label class="form-check-label" for="' . $name . '">' . ucfirst($name) . '</label></div>';
|
||||
}
|
||||
|
||||
public static function getTextHtml( $name, $default = '' ) {
|
||||
@ -133,7 +137,8 @@ class Forms {
|
||||
|
||||
public static function getSelectHtml( $name, $options, $default = null ) {
|
||||
$out = '<select name="' . $name . '" id="' . $name . '" class="form-control">';
|
||||
if ( !is_string( $options ) ) {
|
||||
|
||||
if ( is_iterable( $options ) ) {
|
||||
$out .= self::getOptionsHtml( $options, $default );
|
||||
} else {
|
||||
$out .= $options;
|
||||
@ -190,4 +195,17 @@ class Forms {
|
||||
</fieldset>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function getSwitchHtml( $name, $default = null ) {
|
||||
$checked = '';
|
||||
|
||||
if ( ! empty( $default ) ) {
|
||||
$checked = ' checked="checked"';
|
||||
}
|
||||
|
||||
$out = '<div class="mb-3 form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="' . $name . '" id="' . $name . '" value="true"' . $checked . '>
|
||||
</div>';
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ class Issues {
|
||||
$child = [ $child ];
|
||||
}
|
||||
foreach ( $child as $children ) {
|
||||
if ( ! is_string( $children ) ) {
|
||||
$children = var_export( $children, true );
|
||||
}
|
||||
$out .= '<li>' . $children . '</li>';
|
||||
}
|
||||
$out .= '</ul>';
|
||||
|
@ -57,17 +57,36 @@ class Navigation extends Template {
|
||||
self::$menus_array[ $menuName ][] = self::normalizeLinkArray( $link );
|
||||
}
|
||||
|
||||
public static function getMenuLinks( $menuName ) {
|
||||
if ( !isset( self::$menus_array[ $menuName ] ) ) {
|
||||
Debug::debug( 'menu link mot found, creating new:' . $menuName);
|
||||
return false;
|
||||
}
|
||||
$out = [];
|
||||
foreach ( self::$menus_array[ $menuName ] as $key => $item) {
|
||||
$filter = $item['filter'];
|
||||
|
||||
if ( ! empty( $filter ) ) {
|
||||
$input = '{' . strtoupper($item['filter']) . '}testing{/' . strtoupper($item['filter']) . '}';
|
||||
$output = Filters::apply( $input );
|
||||
// 20 years later and a zero 'location' still gets me....
|
||||
if ( ! stripos( $output, 'esting' ) ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$out[] = (object) $item;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function getListItem( $link, $class = '' ) {
|
||||
$link = self::normalizeLinkArray( $link );
|
||||
if ( empty( $link ) ) {
|
||||
return '';
|
||||
}
|
||||
if ( ! empty( $class ) ) {
|
||||
$class = ' class="' . $class . '"';
|
||||
}
|
||||
// this is a good idea but it breaks active page select because the regex is not equipped to deal with the inclusion of a 'class' field in the list items field
|
||||
// $list_item_class = ''; # the class for individual list items
|
||||
$data = '<li'.$class.'><a href="' . $link['url'] . '">' . $link['text'] . '</a></li>';
|
||||
$data = '<li class="'.$class.' nav-item"><a href="' . $link['url'] . '" class="nav-link">' . $link['text'] . '</a></li>';
|
||||
if ( !empty( $link['filter'] ) ) {
|
||||
$data = '{' . strtoupper($link['filter']) . '}'.$data.'{/' . strtoupper($link['filter']) . '}';
|
||||
$data = Filters::apply( $data );
|
||||
@ -88,8 +107,8 @@ class Navigation extends Template {
|
||||
foreach ( $link['url'] as $key => $sub_link ) {
|
||||
$sub_list .= self::getListItem( $sub_link, 'submenu' );
|
||||
}
|
||||
$list .= '<li>
|
||||
<a href="javascript:;" data-toggle="collapse" data-target="#menu-collapse-' . self::$collapse_count . '">
|
||||
$list .= '<li class="nav-item">
|
||||
<a href="javascript:;" class="nav-link" data-toggle="collapse" data-target="#menu-collapse-' . self::$collapse_count . '">
|
||||
' . $link['text'] . '<i class="fa fa-fw fa-caret-down"></i>
|
||||
</a>
|
||||
<ul id="menu-collapse-' . self::$collapse_count . '" class="collapse">' . $sub_list . '</ul>
|
||||
@ -120,7 +139,6 @@ class Navigation extends Template {
|
||||
}
|
||||
|
||||
if ( !empty( $previousCrumb ) ) {
|
||||
$allCrumbs .= ' <b>></b> ';
|
||||
$previousCrumb = trim( $previousCrumb ) . '/' . $crumb;
|
||||
} else {
|
||||
$previousCrumb = $crumb;
|
||||
@ -132,25 +150,27 @@ class Navigation extends Template {
|
||||
'view' === substr( $crumb, 0, 4 ) ||
|
||||
$url === Routes::getRequestUrl() ||
|
||||
'edit' === substr( $crumb, 0, 4 ) ) {
|
||||
$allCrumbs .= '<b>' . ucfirst( $crumb ) . '</b>';
|
||||
$allCrumbs .= '<li class="breadcrumb-item active" aria-current="page">' . ucfirst( $crumb ) . '</li>';
|
||||
break;
|
||||
}
|
||||
|
||||
$allCrumbs .= '<a href="' . $url . '">' . ucfirst( $crumb ) . '</a>';
|
||||
$allCrumbs .= '<li class="breadcrumb-item"><a href="' . $url . '" class="text-decoration-none atb-green">' . ucfirst( $crumb ) . '</a></li>';
|
||||
}
|
||||
Components::set( $breadcrumb_component, $allCrumbs );
|
||||
$nav = '';
|
||||
$nav .= '<nav aria-label="breadcrumb">';
|
||||
$nav .= ' <ol class="breadcrumb">';
|
||||
$nav .= ' ' . $allCrumbs;
|
||||
$nav .= ' </ol>';
|
||||
$nav .= '</nav>';
|
||||
Components::set( $breadcrumb_component, $nav );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function parses either given html or the current page content and sets
|
||||
* the current active page to selected within an html list.
|
||||
*
|
||||
* @param string $menu - The name of the view you wish to add. can be any arbitrary value if $view is
|
||||
* provided.
|
||||
* @param string $selectString - The string/url you are searching for, default model/controller is used if none is
|
||||
* provided.
|
||||
* @param string $menu - The name of the view you wish to add. can be any arbitrary value if $view is provided.
|
||||
* @param string $selectString - The string/url you are searching for, default model/controller is used if none is provided.
|
||||
* @param string $view - The html you want parsed, view is generated from menu name if $view is left blank
|
||||
*
|
||||
* @return string|bool - returns bool if the menu was added to the page content or
|
||||
* returns the parsed view if one was provided with the
|
||||
* function call.
|
||||
|
@ -36,7 +36,7 @@ class Template {
|
||||
*/
|
||||
public function __construct() {
|
||||
Debug::group( 'Template Constructor', 1 );
|
||||
Components::set( 'SITENAME', 'Houdini Site' );
|
||||
Components::set( 'SITENAME', APP_NAME );
|
||||
Components::set( 'ROOT_URL', Routes::getRoot() );
|
||||
Components::set( 'ROOT_ADDRESS', Routes::getAddress() );
|
||||
Components::set( 'TITLE', '' );
|
||||
@ -49,25 +49,25 @@ class Template {
|
||||
Filters::add( 'issues', '#{ISSUES}(.*?){/ISSUES}#is', ( Issues::hasIssues() ? '$1' : '' ), true );
|
||||
$notices = implode( '<br>', Issues::getNoticeMessages() );
|
||||
if ( !empty( $notices ) ) {
|
||||
$notices = '<div class="alert alert-warning" role="alert">' . $notices . '</div>';
|
||||
$notices = '<div class="alert alert-warning w-100" role="alert">' . $notices . '</div>';
|
||||
}
|
||||
Components::set( 'NOTICE', $notices );
|
||||
|
||||
$successes = implode( '<br>', Issues::getSuccessMessages() );
|
||||
if ( !empty( $successes ) ) {
|
||||
$successes = '<div class="alert alert-success" role="alert">' . $successes . '</div>';
|
||||
$successes = '<div class="alert alert-success w-100" role="alert">' . $successes . '</div>';
|
||||
}
|
||||
Components::set( 'SUCCESS', $successes );
|
||||
|
||||
$errors = implode( '<br>', Issues::getErrorMessages() );
|
||||
if ( !empty( $errors ) ) {
|
||||
$errors = '<div class="alert alert-danger" role="alert">' . $errors . '</div>';
|
||||
$errors = '<div class="alert alert-danger w-100" role="alert">' . $errors . '</div>';
|
||||
}
|
||||
Components::set( 'ERROR', $errors );
|
||||
|
||||
$infos = implode( '<br>', Issues::getInfoMessages() );
|
||||
if ( !empty( $infos ) ) {
|
||||
$infos = '<div class="alert alert-info" role="alert">' . $infos . '</div>';
|
||||
$infos = '<div class="alert alert-info w-100" role="alert">' . $infos . '</div>';
|
||||
}
|
||||
Components::set( 'INFO', $infos );
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ if ( ! defined( 'HOUDINI_ROOT_DIRECTORY' ) ) {
|
||||
if ( ! defined( 'HOUDINI_CONFIG_DIRECTORY' ) ) {
|
||||
define( 'HOUDINI_CONFIG_DIRECTORY', HOUDINI_ROOT_DIRECTORY . 'config' . DIRECTORY_SEPARATOR );
|
||||
}
|
||||
if (!defined('APP_NAME')) {
|
||||
define('APP_NAME', 'Houdini Site');
|
||||
}
|
||||
// # Tell the app all constants have been loaded.
|
||||
if ( ! defined('HOUDINI_CONSTANTS_LOADED' ) ) {
|
||||
define( 'HOUDINI_CONSTANTS_LOADED', true );
|
||||
|
Reference in New Issue
Block a user