Archived
1
0

(experimental) global theme options

This commit is contained in:
Garvin Hicking
2010-08-24 08:45:09 +00:00
parent a7b27ff06a
commit f9fa8503f0
68 changed files with 2264 additions and 2023 deletions
+19 -7
View File
@@ -27,11 +27,20 @@ class template_option {
function set_config($item, $value) {
global $serendipity;
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}options
WHERE okey = 't_" . serendipity_db_escape_string($serendipity['template']) . "'
AND name = '" . serendipity_db_escape_string($item) . "'");
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)
VALUES ('t_" . serendipity_db_escape_string($serendipity['template']) . "', '" . serendipity_db_escape_string($item) . "', '" . serendipity_db_escape_string($value) . "')");
if ($this->config[$item]['scope'] == 'global') {
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}options
WHERE okey = 't_global'
AND name = '" . serendipity_db_escape_string($item) . "'");
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)
VALUES ('t_global', '" . serendipity_db_escape_string($item) . "', '" . serendipity_db_escape_string($value) . "')");
} else {
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}options
WHERE okey = 't_" . serendipity_db_escape_string($serendipity['template']) . "'
AND name = '" . serendipity_db_escape_string($item) . "'");
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)
VALUES ('t_" . serendipity_db_escape_string($serendipity['template']) . "', '" . serendipity_db_escape_string($item) . "', '" . serendipity_db_escape_string($value) . "')");
}
return true;
}
@@ -70,8 +79,10 @@ if (is_array($template_config)) {
serendipity_plugin_api::hook_event('backend_templates_configuration_top', $template_config);
if ($serendipity['POST']['adminAction'] == 'configure' && serendipity_checkFormToken()) {
$storage = new template_option();
$storage->import($template_config);
foreach($serendipity['POST']['template'] AS $option => $value) {
template_option::set_config($option, $value);
$storage->set_config($option, $value);
}
echo '<div class="serendipityAdminMsgSuccess"><img style="height: 22px; width: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_success.png') . '" alt="" />' . DONE .': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '</div>';
}
@@ -82,8 +93,9 @@ if (is_array($template_config)) {
echo serendipity_setFormToken();
include S9Y_INCLUDE_PATH . 'include/functions_plugins_admin.inc.php';
$template_vars =& serendipity_loadThemeOptions($template_config);
$template_vars =& serendipity_loadThemeOptions($template_config);
$template_options = new template_option();
$template_options->import($template_config);
$template_options->values =& $template_vars;
+59 -1
View File
@@ -2070,7 +2070,8 @@ function &serendipity_loadThemeOptions(&$template_config, $okey = '') {
}
$_template_vars =& serendipity_db_query("SELECT name, value FROM {$serendipity['dbPrefix']}options
WHERE okey = 't_" . serendipity_db_escape_string($okey) . "'", false, 'assoc', false, 'name', 'value');
WHERE okey = 't_" . serendipity_db_escape_string($okey) . "'
OR okey = 't_global'", false, 'assoc', false, 'name', 'value');
if (!is_array($_template_vars)) {
$template_vars = array();
} else {
@@ -2086,6 +2087,63 @@ function &serendipity_loadThemeOptions(&$template_config, $okey = '') {
return $template_vars;
}
/**
* Load global available/configured options for a specific theme
* into an array.
*
* @param array Referenced variable coming from the config.inc.php file, where the config values will be stored in
* @param array Current template configuration
* @return array Final return array with default values
*/
function serendipity_loadGlobalThemeOptions(&$template_config, &$template_loaded_config, $supported = array()) {
global $serendipity;
if ($supported['navigation']) {
$navlinks = array();
$conf_amount = array(
'var' => 'amount',
'name' => NAVLINK_AMOUNT,
'type' => 'string',
'default' => '5',
'scope' => 'global'
);
$template_config[] = $conf_amount;
if (empty($template_loaded_config['amount'])) {
$template_loaded_config['amount'] = $conf_amount['default'];
}
for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
$navlinks[] = array(
'title' => $template_loaded_config['navlink' . $i . 'text'],
'href' => $template_loaded_config['navlink' . $i . 'url']
);
$template_config[] = array(
'var' => 'navlink' . $i . 'text',
'name' => NAV_LINK_TEXT . ' #' . ($i+1),
'type' => 'string',
'default' => 'Link #' . $i,
'scope' => 'global'
);
$template_config[] = array(
'var' => 'navlink' . $i . 'url',
'name' => NAV_LINK_URL . ' #' . ($i+1),
'type' => 'string',
'default' => '#',
'scope' => 'global'
);
}
$serendipity['smarty']->assign_by_ref('navlinks', $navlinks);
}
// Forward thinking. ;-)
serendipity_plugin_api::hook_event('backend_templates_globalthemeoptions', $template_config, $supported);
}
/**
* Check if a member of a group has permissions to execute a plugin
+1 -1
View File
@@ -851,7 +851,7 @@ function &serendipity_replaceSmartyVars($tpl_source, &$smarty) {
* @return null
*/
function serendipity_smarty_init($vars = array()) {
global $serendipity, $template_config;
global $serendipity, $template_config, $template_global_config;
if (!isset($serendipity['smarty'])) {
$template_dir = $serendipity['serendipityPath'] . $serendipity['templatePath'] . $serendipity['template'];