Files
thetempusproject/app/classes/config.php
Joey Kimsey d7e8b586d7 various updates
remove dependence on jQuery
add image delete
Admin ui fix for mobile
image updates to new style
update comments
2025-02-05 06:36:29 -05:00

122 lines
4.4 KiB
PHP

<?php
/**
* app/classes/config.php
*
* This class handles all the hard-coded configurations.
*
* @version 5.0.1
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Classes;
use TheTempusProject\Houdini\Classes\Forms;
use TheTempusProject\Houdini\Classes\Template;
use TheTempusProject\Canary\Bin\Canary as Debug;
use TheTempusProject\Bedrock\Functions\Check;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Bedrock\Classes\Config as BedrockConfig;
class Config extends BedrockConfig {
public static function getFieldEditHtml( $name, $includeProtected = false ) {
$node = self::get( $name );
if ( empty( $node ) ) {
return;
}
if ( true === $node['protected'] ) {
return;
}
$fieldname = str_ireplace( '/', '-', $name );
$html = '';
$fieldHtml = '';
switch ( $node['type'] ) {
case 'radio':
case 'bool':
case 'boolean':
$fieldHtml = Forms::getSwitchHtml( $fieldname, $node['value'] );
break;
case 'select':
$fieldHtml = Forms::getSelectHtml( $fieldname, $options, $node['value'] );
break;
case 'block':
$fieldHtml = Forms::getTextBlockHtml( $fieldname, $node['value'] );
break;
case 'text':
case 'url':
$fieldHtml = Forms::getTextHtml( $fieldname, $node['value'] );
break;
case 'checkbox':
$fieldHtml = Forms::getCheckboxHtml( $fieldname, $node['value'] );
break;
case 'timezone':
$fieldHtml = Forms::getTimezoneHtml( $node['value'] );
break;
case 'file':
$fieldHtml = Forms::getFileHtml( $fieldname );
break;
case 'customSelect':
if ( empty( $options ) ) {
$options = '{' . $fieldname . '-options}';
}
$fieldHtml = Forms::getSelectHtml( $fieldname, $options, $node['value'] );
break;
}
$html .= '<div class="mb-3 row">';
$html .= '<label for="' . $fieldname . '" class="col-lg-3 col-form-label text-end">' . $node['pretty'] . '</label>';
$html .= '<div class="col-lg-6">';
$html .= $fieldHtml;
$html .= '</div>';
$html .= '</div>';
if ( 'file' === $node['type'] ) {
$html .= '<div class="mb-3 row">';
$html .= '<h4 class="col-lg-3 col-form-label text-end">Current Value</h4>';
$html .= '<div class="col-lg-6">';
$html .= '<input type="text" class="form-control" name="'.$name.'Text" value="'.$node['value'] . '">';
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="mb-3 row">';
$html .= '<h4 class="col-lg-3 col-form-label text-end">Current Image</h4>';
$html .= '<div class="col-lg-6 d-flex justify-content-center">';
$html .= '<img alt="configured image" src="{ROOT_URL}' . $node['value'] . '" class="img-circle img-fluid p-2 avatar-125">';
$html .= '</div>';
$html .= '</div>';
}
return Template::parse( $html );
}
public static function getCategoryEditHtml( $category ) {
$html = '';
if ( self::$config === false ) {
Debug::warn( 'Config not loaded.' );
return;
}
if ( empty( self::$config[$category] ) ) {
Debug::warn( "Config category not found: $category" );
return;
}
$categoryHeader = '<div class=""><h3 class="text-center">' . ucfirst( $category ) . ':</h3><hr>';
foreach ( self::$config[$category] as $field => $node ) {
$html .= self::getFieldEditHtml( $category . '/' . $field );
}
if ( !empty( $html ) ) {
$html = $categoryHeader . $html . '</div>';
}
return $html;
}
public static function getEditHtml() {
if ( self::$config === false ) {
Debug::warn( 'Config not loaded.' );
return;
}
$html = '';
foreach ( self::$config as $category => $fields ) {
$html .= self::getCategoryEditHtml( $category );
}
return $html;
}
}