1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 13:17:24 +02:00

Seamless upgrade of theme prefs when moving to theme_config specification.

bootstrap3 theme upgraded to use theme_config. CDN pref removed in favor of e107::library() core CDN pref.
This commit is contained in:
Cameron
2017-01-29 13:47:20 -08:00
parent 108f9b8297
commit 8c542c9e82
2 changed files with 34 additions and 63 deletions

View File

@@ -1498,12 +1498,18 @@ class themeHandler
$mes = e107::getMessage(); $mes = e107::getMessage();
$frm = e107::getForm(); $frm = e107::getForm();
$pref = e107::getConfig()->getPref();
$mes->addDebug("Rendering Theme Config"); $mes->addDebug("Rendering Theme Config");
$this->loadThemeConfig(); $this->loadThemeConfig();
$value = e107::getThemeConfig($this->id)->getPref(); $value = e107::getThemeConfig($this->id)->getPref();
if(empty($value) && !empty($pref['sitetheme_pref']))
{
$value = $pref['sitetheme_pref'];
}
if($this->themeConfigObj) if($this->themeConfigObj)
{ {
$var = call_user_func(array(&$this->themeConfigObj, 'config')); $var = call_user_func(array(&$this->themeConfigObj, 'config'));
@@ -1523,7 +1529,8 @@ class themeHandler
$value[$field] = varset($value[$field][e_LANGUAGE],''); $value[$field] = varset($value[$field][e_LANGUAGE],'');
} }
$text .= "<tr><td><b>".$val['title']."</b>:</td><td colspan='2'>".$frm->renderElement($field, $value[$field], $val)."<div class='field-help'>".$val['help']."</div> $tdClass = !empty($val['writeParms']['post']) ? 'form-inline' : '';
$text .= "<tr><td><b>".$val['title']."</b>:</td><td class='".$tdClass."' colspan='2'>".$frm->renderElement($field, $value[$field], $val)."<div class='field-help'>".$val['help']."</div>
</td></tr>"; </td></tr>";
} }
} }
@@ -1566,9 +1573,24 @@ class themeHandler
$theme_pref[$field] = $_POST[$field]; $theme_pref[$field] = $_POST[$field];
} }
return $pref->setPref($theme_pref)->save(true,true,false); if($pref->setPref($theme_pref)->save(true,true,false))
{
$siteThemePref = e107::getConfig()->get('sitetheme_pref');
if(!empty($siteThemePref))
{
e107::getConfig()->set('sitetheme_pref',null)->save(false,true,false); // remove old theme pref
}
} }
if($pref->dataHasChanged())
{
e107::getCache()->clearAll('system'); // Need to clear cache in order to refresh library information.
}
return true;
}
e107::getCache()->clearAll('system');
return call_user_func(array(&$this->themeConfigObj, 'process')); //pre v2.1.4 return call_user_func(array(&$this->themeConfigObj, 'process')); //pre v2.1.4
} }
} }

View File

@@ -2,53 +2,17 @@
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
e107::lan('theme', 'admin',true); // e_PLUGIN.'tinymce4/languages/'.e_LANGUAGE.'_admin.php' e107::lan('theme', 'admin',true);
// Dummy Theme Configuration File. // Theme Configuration File.
class theme_bootstrap3 implements e_theme_config class theme_config implements e_theme_config
{ {
function process() // Save posted values from config() fields.
{
$pref = e107::getConfig();
$theme_pref = array();
$theme_pref['nav_alignment'] = $_POST['nav_alignment'];
$theme_pref['usernav_placement'] = $_POST['usernav_placement'];
$theme_pref['branding'] = $_POST['branding'];
$theme_pref['bootswatch'] = $_POST['bootswatch'];
$theme_pref['cdn'] = $_POST['cdn'];
$pref->set('sitetheme_pref', $theme_pref);
$changed = $pref->dataHasChanged();
if($changed)
{
// Need to clear cache in order to refresh library information.
e107::getCache()->clearAll('system');
}
return $changed;
}
function config($type='front') function config($type='front')
{ {
$frm = e107::getForm();
$brandingOpts = array('sitename'=>LAN_THEMEPREF_04, 'logo' => LAN_THEMEPREF_05, 'sitenamelogo'=>LAN_THEMEPREF_06); $brandingOpts = array('sitename'=>LAN_THEMEPREF_04, 'logo' => LAN_THEMEPREF_05, 'sitenamelogo'=>LAN_THEMEPREF_06);
$var[0]['caption'] = LAN_THEMEPREF_00;
$var[0]['html'] = $frm->select('branding', $brandingOpts, e107::pref('theme', 'branding', 'sitename'));
$var[0]['help'] = "";
$var[1]['caption'] = LAN_THEMEPREF_01;
$var[1]['html'] = $frm->select('nav_alignment', array('left'=>LAN_THEMEPREF_07,'right'=> LAN_THEMEPREF_08), e107::pref('theme', 'nav_alignment', 'left'));
$var[1]['help'] = "";
$var[2]['caption'] = LAN_THEMEPREF_02;
$var[2]['html'] = $frm->select('usernav_placement', array('top'=>LAN_THEMEPREF_09, 'bottom'=>LAN_THEMEPREF_10), e107::pref('theme', 'usernav_placement', 'top'));
$var[2]['help'] = "";
$bootswatch = array( $bootswatch = array(
// '' => LAN_DEFAULT, // '' => LAN_DEFAULT,
"cerulean"=> 'Cerulean', "cerulean"=> 'Cerulean',
@@ -69,33 +33,18 @@ class theme_bootstrap3 implements e_theme_config
"yeti"=> 'Yeti', "yeti"=> 'Yeti',
); );
$cdnFront = array(
'cdnjs' => "CDNJS (Cloudflare)",
'jsdelivr' => "jsDelivr"
// google ? No fontawesome support?
);
$previewLink = " <a class='btn btn-default e-modal' data-modal-caption=\"Use the 'Themes' menu to view the selection.\" href='http://bootswatch.com/default/'>".LAN_PREVIEW."</a>"; $previewLink = " <a class='btn btn-default e-modal' data-modal-caption=\"Use the 'Themes' menu to view the selection.\" href='http://bootswatch.com/default/'>".LAN_PREVIEW."</a>";
$var[3]['caption'] = LAN_THEMEPREF_03; $fields = array(
$var[3]['html'] = "<div class='form-inline'>".$frm->select('bootswatch', $bootswatch, e107::pref('theme', 'bootswatch', ''),null,LAN_DEFAULT ).$previewLink."</div>"; 'branding' => array('title'=>LAN_THEMEPREF_00, 'type'=>'dropdown', 'writeParms'=>array('optArray'=> $brandingOpts)),
$var[3]['help'] = ""; 'nav_alignment' => array('title'=>LAN_THEMEPREF_01, 'type'=>'dropdown', 'writeParms'=>array('optArray'=> array('left'=> LAN_THEMEPREF_07,'right'=> LAN_THEMEPREF_08))),
'usernav_placement' => array('title'=>LAN_THEMEPREF_02, 'type'=>'dropdown', 'writeParms'=>array('optArray'=> array('top'=> LAN_THEMEPREF_09, 'bottom'=> LAN_THEMEPREF_10))),
'bootswatch' => array('title'=>LAN_THEMEPREF_03, 'type'=>'dropdown', 'writeParms'=>array('optArray'=> $bootswatch, 'post'=>$previewLink)),
);
$var[4]['caption'] = "CDN"; return $fields;
$var[4]['html'] = $frm->select('cdn', $cdnFront, e107::pref('theme', 'cdn', '') );
$var[4]['help'] = "";
// $var[1]['caption'] = "Sample configuration field 2";
// $var[1]['html'] = $frm->text('_blank_example2', e107::pref('theme', 'example2', 'default'));
return $var;
} }