* @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 .= '
'; $html .= ''; $html .= '
'; $html .= $fieldHtml; $html .= '
'; $html .= '
'; if ( 'file' === $node['type'] ) { $html .= '
'; $html .= '

Current Value

'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '

Current Image

'; $html .= '
'; $html .= 'configured image'; $html .= '
'; $html .= '
'; } 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 = '

' . ucfirst( $category ) . ':


'; foreach ( self::$config[$category] as $field => $node ) { $html .= self::getFieldEditHtml( $category . '/' . $field ); } if ( !empty( $html ) ) { $html = $categoryHeader . $html . '
'; } 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; } }