From e24d138b486f84665e8ef9d2e1069f11338916ad Mon Sep 17 00:00:00 2001 From: cornernote Date: Mon, 24 Feb 2014 19:15:57 +1030 Subject: [PATCH] control bootstrap css/js via yii-embed wordpress settings page --- includes/YiiEmbed.php | 38 ++++++++- includes/YiiEmbedSettings.php | 147 ++++++++++++++++++++++++++++++++-- 2 files changed, 174 insertions(+), 11 deletions(-) diff --git a/includes/YiiEmbed.php b/includes/YiiEmbed.php index 1ed1249..fdebe49 100644 --- a/includes/YiiEmbed.php +++ b/includes/YiiEmbed.php @@ -99,7 +99,9 @@ public static function activation() } // add options delete_option('yii_embed'); - add_option('yii_embed', array('yii_path' => '')); + add_option('yii_embed', array( + 'yii_path' => '', + )); } /** @@ -175,9 +177,37 @@ public static function registerScripts() if (!YII_EMBED_YII_VERSION) return; - Yii::app()->bootstrap->register(); - if (is_admin()) - Yii::app()->clientScript->registerCss('wp-admin-fix', 'body{background-color:transparent;}ul,ol{margin:0;}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{height:auto;}'); + $options = get_option('yii_embed'); + $bootstrap = Yii::app()->bootstrap; + + // admin css/js + if (is_admin()) { + if (!empty($options['admin_bootstrap_css'])) { + $bootstrap->registerCoreCss(); + Yii::app()->clientScript->registerCss('wp-bs-admin-fix', 'body{background-color:transparent;}ul,ol{margin:0;}select,textarea,input[type="text"],input[type="password"],input[type="datetime"],input[type="datetime-local"],input[type="date"],input[type="month"],input[type="time"],input[type="week"],input[type="number"],input[type="email"],input[type="url"],input[type="search"],input[type="tel"],input[type="color"],.uneditable-input{height:auto;}'); + } + if (!empty($options['admin_bootstrap_css_responsive'])) + $bootstrap->registerResponsiveCss(); + if (!empty($options['admin_bootstrap_js'])) + $bootstrap->registerCoreScripts(); + if (!empty($options['admin_bootstrap_js_popover'])) + $bootstrap->registerPopover(); + if (!empty($options['admin_bootstrap_js_tooltip'])) + $bootstrap->registerTooltip(); + } + // front css/js + else { + if (!empty($options['front_bootstrap_css'])) + $bootstrap->registerCoreCss(); + if (!empty($options['front_bootstrap_css_responsive'])) + $bootstrap->registerResponsiveCss(); + if (!empty($options['front_bootstrap_js'])) + $bootstrap->registerCoreScripts(); + if (!empty($options['front_bootstrap_js_popover'])) + $bootstrap->registerPopover(); + if (!empty($options['front_bootstrap_js_tooltip'])) + $bootstrap->registerTooltip(); + } } /** diff --git a/includes/YiiEmbedSettings.php b/includes/YiiEmbedSettings.php index 2d3b5e5..035464e 100644 --- a/includes/YiiEmbedSettings.php +++ b/includes/YiiEmbedSettings.php @@ -83,11 +83,25 @@ public function admin_init() // register the setting and validation callback register_setting('yii_embed', 'yii_embed', array($this, 'validate')); - // add the settings section - add_settings_section('yii_embed', '', array($this, 'settings_section_yii_embed'), 'yii-embed-settings'); + // yii settings + add_settings_section('yii', '', array($this, 'settings_section_yii'), 'yii-embed-settings'); + add_settings_field('yii_embed_yii_path', __('Yii Path'), array($this, 'settings_field_yii_path'), 'yii-embed-settings', 'yii'); - // add the yii_path field - add_settings_field('yii_embed_yii_path', __('Yii Path'), array($this, 'settings_field_yii_path'), 'yii-embed-settings', 'yii_embed'); + // admin bootstrap settings + add_settings_section('admin_bootstrap', '', array($this, 'settings_section_admin_bootstrap'), 'yii-embed-settings'); + add_settings_field('yii_embed_admin_bootstrap_css', __('Bootstrap CSS'), array($this, 'settings_field_admin_bootstrap_css'), 'yii-embed-settings', 'admin_bootstrap'); + add_settings_field('yii_embed_admin_bootstrap_css_responsive', __('Bootstrap Responsive CSS'), array($this, 'settings_field_admin_bootstrap_css_responsive'), 'yii-embed-settings', 'admin_bootstrap'); + add_settings_field('yii_embed_admin_bootstrap_js', __('Bootstrap JS'), array($this, 'settings_field_admin_bootstrap_js'), 'yii-embed-settings', 'admin_bootstrap'); + add_settings_field('yii_embed_admin_bootstrap_js_popover', __('Bootstrap Popover JS'), array($this, 'settings_field_admin_bootstrap_js_popover'), 'yii-embed-settings', 'admin_bootstrap'); + add_settings_field('yii_embed_admin_bootstrap_js_tooltip', __('Bootstrap Tooltip JS'), array($this, 'settings_field_admin_bootstrap_js_tooltip'), 'yii-embed-settings', 'admin_bootstrap'); + + // front bootstrap settings + add_settings_section('front_bootstrap', '', array($this, 'settings_section_front_bootstrap'), 'yii-embed-settings'); + add_settings_field('yii_embed_front_bootstrap_css', __('Bootstrap CSS'), array($this, 'settings_field_front_bootstrap_css'), 'yii-embed-settings', 'front_bootstrap'); + add_settings_field('yii_embed_front_bootstrap_css_responsive', __('Bootstrap Responsive CSS'), array($this, 'settings_field_front_bootstrap_css_responsive'), 'yii-embed-settings', 'front_bootstrap'); + add_settings_field('yii_embed_front_bootstrap_js', __('Bootstrap JS'), array($this, 'settings_field_front_bootstrap_js'), 'yii-embed-settings', 'front_bootstrap'); + add_settings_field('yii_embed_front_bootstrap_js_popover', __('Bootstrap Popover JS'), array($this, 'settings_field_front_bootstrap_js_popover'), 'yii-embed-settings', 'front_bootstrap'); + add_settings_field('yii_embed_front_bootstrap_js_tooltip', __('Bootstrap Tooltip JS'), array($this, 'settings_field_front_bootstrap_js_tooltip'), 'yii-embed-settings', 'front_bootstrap'); } /** @@ -172,9 +186,9 @@ public function options_page() /** * Callback to add the section settings */ - public static function settings_section_yii_embed() + public static function settings_section_yii() { - //echo __('Yii Embed Settings:'); + echo '

' . __('Yii Settings') . '

'; } /** @@ -183,10 +197,129 @@ public static function settings_section_yii_embed() public function settings_field_yii_path() { echo strtr('

:description :default_path

', array( - ':value' => isset($this->options['yii_path']) ? esc_attr($this->options['yii_path']) : '', + ':value' => !empty($this->options['yii_path']) ? esc_attr($this->options['yii_path']) : '', ':description' => __('Full path the the folder that contains Yii\'s "framework" folder.'), ':default_path' => empty($this->options['yii_path']) ? '
' . __('Default:') . ' ' . YiiEmbed::yiiPath() : '', )); } + /** + * Callback to add the section settings + */ + public static function settings_section_admin_bootstrap() + { + echo '

' . __('Admin Bootstrap Settings') . '

'; + echo '

' . __('Choose which bootstrap styles and scripts should be enabled in the Administration theme.') . '

'; + } + + /** + * Callback to add the admin_bootstrap_css setting field + */ + public function settings_field_admin_bootstrap_css() + { + echo strtr('', array( + ':checked' => !empty($this->options['admin_bootstrap_css']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the admin_bootstrap_css_responsive setting field + */ + public function settings_field_admin_bootstrap_css_responsive() + { + echo strtr('', array( + ':checked' => !empty($this->options['admin_bootstrap_css_responsive']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the admin_bootstrap_js setting field + */ + public function settings_field_admin_bootstrap_js() + { + echo strtr('', array( + ':checked' => !empty($this->options['admin_bootstrap_js']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the admin_bootstrap_js_popover setting field + */ + public function settings_field_admin_bootstrap_js_popover() + { + echo strtr('', array( + ':checked' => !empty($this->options['admin_bootstrap_js_popover']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the admin_bootstrap_js_tooltip setting field + */ + public function settings_field_admin_bootstrap_js_tooltip() + { + echo strtr('', array( + ':checked' => !empty($this->options['admin_bootstrap_js_tooltip']) ? 'checked="checked"' : '', + )); + } + + + /** + * Callback to add the section settings + */ + public static function settings_section_front_bootstrap() + { + echo '

' . __('Front Bootstrap Settings') . '

'; + echo '

' . __('Choose which bootstrap styles and scripts should be enabled in the Front-End theme.') . '

'; + } + + /** + * Callback to add the front_bootstrap_css setting field + */ + public function settings_field_front_bootstrap_css() + { + echo strtr('', array( + ':checked' => !empty($this->options['front_bootstrap_css']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the front_bootstrap_css_responsive setting field + */ + public function settings_field_front_bootstrap_css_responsive() + { + echo strtr('', array( + ':checked' => !empty($this->options['front_bootstrap_css_responsive']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the front_bootstrap_js setting field + */ + public function settings_field_front_bootstrap_js() + { + echo strtr('', array( + ':checked' => !empty($this->options['front_bootstrap_js']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the front_bootstrap_js_popover setting field + */ + public function settings_field_front_bootstrap_js_popover() + { + echo strtr('', array( + ':checked' => !empty($this->options['front_bootstrap_js_popover']) ? 'checked="checked"' : '', + )); + } + + /** + * Callback to add the front_bootstrap_js_tooltip setting field + */ + public function settings_field_front_bootstrap_js_tooltip() + { + echo strtr('', array( + ':checked' => !empty($this->options['front_bootstrap_js_tooltip']) ? 'checked="checked"' : '', + )); + } + }