Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31744/include
Modified Files:
functions_installer.inc.php lang.inc.php
Log Message:
- Convert old .tpl files into plain and valid .php files
- Use native PHP array to store configuration templates
- Add flag called "nosave" which will cause the data not to be saved in the database (useful for db vars, leaves a very clean db table)
- Add flag called "hideValue" which will not print the value of the var to the user (for passwords)
- Add flag called "local" which will not save the variable in the database, but only when the var is being saved in the configuration
- Fix bug with autolang (someone misspelled $serendipity, bad bad)
- Convert list of languages to a real array, which is sexy - move it to serendipity_config.inc.php
Tested with installer and config saving.
Please test - any breakage will be fixed ASAP - but please don't commit anything without pinging me.
TODO: Make a function to parse/obey the configuration flags, so we don't have to maintain it 3 places. Will do tomorrow.
NOTE: Do not add any logic to config files, or I will personally hunt you down.
Index: functions_installer.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_installer.inc.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- functions_installer.inc.php 30 Nov 2004 20:30:06 -0000 1.8
+++ functions_installer.inc.php 2 Dec 2004 20:57:44 -0000 1.9
@@ -140,106 +140,33 @@
}
}
-function serendipity_replaceEmbeddedConfigVars ($s) {
- return str_replace(
- array(
- '[USERLEVEL_ADMIN]',
- '[USERLEVEL_CHIEF]',
- '[USERLEVEL_EDITOR]',
- '[LANGUAGE_LIST]'
- ),
-
- array(
- USERLEVEL_ADMIN,
- USERLEVEL_CHIEF,
- USERLEVEL_EDITOR,
- LANGUAGE_LIST
- ), $s);
-}
-
-function serendipity_parseTemplate($n, $raw = false, $prepend_var = null, $get_defaults = true) {
+function serendipity_parseTemplate($filename, $userlevel=null) {
global $serendipity;
- if (is_array($prepend_var)) {
- $config = $configRaw = &$prepend_var;
- $usertemplate = true;
- } else {
- $config = $configRaw = array();
- $usertemplate = false;
+ if ( is_null($userlevel) ) {
+ $userlevel = $serendipity['serendipityUserlevel'];
}
- $t = file($n, 1);
-
- $maxt = count($t);
-
- for ($x=0; $x<$maxt; $x++) {
- $l = $t[$x];
- $l = trim($l);
-
- if ($l != '') {
- switch ($l[0]) {
-
- // New Configure section
- case '/':
- if ($l[1] == '/') {
- $current = @constant(trim(substr($l, 2)));
- $config['categories'][$current] = array();
- }
- break;
-
- case '#':
- $config['descriptions'][$current] = @constant(trim(substr($l, 1)));
- break;
-
- // A configure option
- case '$':
- // Grep out the name, type and default
- preg_match('#\{([^|]+\|[^|]+\|([^}]+)?)\}[^/]+/{2}(.+)#msi', $l, $match);
-
- // Make vars containing the elements in the | list
- list($constant, $name, $type, $distdefault, $permission, $flags) = explode('|', $match[1]);
+ $config = include($filename);
- // Only show directives which are destined for this user. On installation, show everyting.
- if (IS_installed === false || $serendipity['serendipityUserlevel'] >= $permission) {
- $cdef = ($get_defaults ? serendipity_query_default($name, $distdefault, $usertemplate, $type) : '');
- $distDefault = serendipity_replaceEmbeddedConfigvars($distdefault);
+ foreach ( $config as $n => $category ) {
+ foreach ( $category['items'] as $i => $item ) {
+ $items = &$config[$n]['items'][$i];
+ if ( !isset($items['userlevel']) || !is_numeric($items['userlevel']) ) {
+ $items['userlevel'] = USERLEVEL_ADMIN;
+ }
- /* Expand 'list' type, to a normal assocaitive array */
- if ($type == 'list' && preg_match_all("/([^\=]+)\=\>([^\,]+)\,?/i", $distDefault, $res)) {
- $distDefault = array();
- foreach ( $res[1] as $k => $v ) {
- $distDefault[$res[1][$k]] = $res[2][$k];
- }
- }
- $config['categories'][$current][] = $configRaw[] = array(
- 'longname' => @constant($constant),
- 'name' => $name,
- 'type' => $type,
- 'default' => $cdef,
- 'distdefault' => $distDefault,
- 'desc' => serendipity_replaceEmbeddedConfigVars(@constant(trim($match[3]))),
- 'valid_for' => $permission,
- 'flags' => explode(',', $flags)
- );
- }
- break;
+ if ( !isset($items['flags']) || !is_array($items['flags']) ) {
+ $items['flags'] = array();
}
- }
- }
- if ($raw) {
- return $configRaw;
- } else {
- // Cleanup phase. Remove categories for which no variables can be defined
- if (isset($config['categories']) && is_array($config['categories'])) {
- foreach($config['categories'] AS $item => $itemarray) {
- if (count($itemarray) < 1) {
- unset($config['categories'][$item]);
- }
+ if ( $items['userlevel'] < $userlevel ) {
+ unset($items);
}
}
- return $config;
}
+
+ return $config;
}
function serendipity_guessInput($type, $name, $value='', $default='') {
@@ -277,9 +204,8 @@
}
}
-function serendipity_printConfigTemplate($t, $from = false, $minimum = false, $folding = true) {
+function serendipity_printConfigTemplate($config, $from = false, $noForm = false, $folding = true) {
global $serendipity;
-
if (!isset($serendipity['XHTML11'])) {
$serendipity['XHTML11'] = FALSE;
}
@@ -323,7 +249,7 @@
</script>
<?php
- if (!$minimum) {
+ if (!$noForm) {
?>
<form action="?" method="POST">
<div>
@@ -331,23 +257,23 @@
<input type="hidden" name="installAction" value="check" />
<br />
<?php }
- if (sizeof($t['categories']) > 1) { ?>
+ if (sizeof($config) > 1) { ?>
<div align="right">
- <a style="border:0; text-decoration: none" href="#" onClick="showConfigAll(<?php echo count($t['categories']); ?>)" title="<?php echo TOGGLE_ALL; ?>"><img src="<?php echo serendipity_getTemplateFile('img/'. ($folding === true ? 'plus' : 'minus') .'.png') ?>" id="optionall" alt="+/-" border="0" /> <?php echo TOGGLE_ALL; ?></a></a><br />
+ <a style="border:0; text-decoration: none" href="#" onClick="showConfigAll(<?php echo sizeof($config); ?>)" title="<?php echo TOGGLE_ALL; ?>"><img src="<?php echo serendipity_getTemplateFile('img/'. ($folding === true ? 'plus' : 'minus') .'.png') ?>" id="optionall" alt="+/-" border="0" /> <?php echo TOGGLE_ALL; ?></a></a><br />
</div>
<?php
}
$el_count = 0;
- foreach ($t['categories'] as $key => $value) {
+ foreach ($config as $category) {
$el_count++;
?>
<table width="100%" cellspacing="2">
<?php
- if (sizeof($t['categories']) > 1) {
+ if (sizeof($config) > 1) {
?>
<tr>
<th align="left" colspan="2" style="padding-left: 15px;">
- <a style="border:0; text-decoration: none" href="#" onClick="showConfig('el<?php echo $el_count; ?>'); return false" title="<?php echo TOGGLE_OPTION; ?>"><img src="<?php echo serendipity_getTemplateFile('img/'. ($folding === true ? 'plus' : 'minus') .'.png') ?>" id="optionel<?php echo $el_count; ?>" alt="+/-" border="0" /> <?php echo $key; ?></a></th>
+ <a style="border:0; text-decoration: none" href="#" onClick="showConfig('el<?php echo $el_count; ?>'); return false" title="<?php echo TOGGLE_OPTION; ?>"><img src="<?php echo serendipity_getTemplateFile('img/'. ($folding === true ? 'plus' : 'minus') .'.png') ?>" id="optionel<?php echo $el_count; ?>" alt="+/-" border="0" /> <?php echo $category['title']; ?></a></th>
</tr>
<?php } ?>
<tr>
@@ -355,37 +281,37 @@
<table width="100%" cellspacing="0" cellpadding="3" style="<?php echo ($folding === true ? 'display: none;' : ''); ?>" id="el<?php echo $el_count; ?>">
<tr>
<td style="padding-left: 20px;" colspan="2">
- <?php echo $t['descriptions'][$key] ?>
+ <?php echo $category['description'] ?>
</td>
</tr>
<?php
- for ($x=0; $x<count($value); $x++) {
+ foreach ( $category['items'] as $item ) {
- /* Check for installOnly flag */
- if ( in_array('installOnly', $value[$x]['flags']) && IS_installed === true ) {
- continue;
- }
+ $value = $from[$item['var']];
+ /* Calculate value if we are not installed, how clever :) */
+ if ( IS_installed === false ) {
+ $value = serendipity_query_default($item['var'], $item['default']);
+ }
- /* If we have a valuelist, then use the value from there */
- if (@is_array($from)) {
- $value[$x]['value'] = $from[$value[$x]['name']];
+ /* Check for installOnly flag */
+ if ( in_array('installOnly', $item['flags']) && IS_installed === true ) {
+ continue;
}
- /* If the value is never assigned in the valuelist, then use our default value */
- if (!isset($from[$value[$x]['name']])) {
- $value[$x]['value'] = $value[$x]['default'];
+ if ( in_array('hideValue', $item['flags']) ) {
+ $value = '';
}
?>
<tr>
<td style="border-bottom: 1px #000000 solid" align="left" valign="top" width="75%">
- <strong><?php echo $value[$x]['longname']; ?></strong>
+ <strong><?php echo $item['title']; ?></strong>
<br />
- <span style="color: #5E7A94; font-size: 8pt;"><?php echo '(' . $value[$x]['type'] . ') ' . $value[$x]['desc']; ?></span>
+ <span style="color: #5E7A94; font-size: 8pt;"><?php echo $item['description']; ?></span>
</td>
<td style="border-bottom: 1px #000000 solid; font-size: 8pt" align="left" valign="middle" width="25%">
- <?php echo ($serendipity['XHTML11'] ? '<span style="white-space: nowrap">' : '<nobr>'); ?><?php echo serendipity_guessInput($value[$x]['type'], $value[$x]['name'], $value[$x]['value'], $value[$x]['distdefault']); ?><?php echo ($serendipity['XHTML11'] ? '</span>' : '</nobr>'); ?>
+ <?php echo ($serendipity['XHTML11'] ? '<span style="white-space: nowrap">' : '<nobr>'); ?><?php echo serendipity_guessInput($item['type'], $item['var'], $value, $item['default']); ?><?php echo ($serendipity['XHTML11'] ? '</span>' : '</nobr>'); ?>
</td>
</tr>
<?php
@@ -398,7 +324,7 @@
<?php
}
- if (!$minimum) {
+ if (!$noForm) {
?>
<input type="submit" value="<?php echo CHECK_N_SAVE; ?>" />
</div>
@@ -702,18 +628,28 @@
global $serendipity, $umask;
// Save all basic config variables to the database
- $p = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE, true);
+ $config = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE);
if (isset($_POST['sqlitedbName']) && !empty($_POST['sqlitedbName'])) {
$_POST['dbName'] = $_POST['sqlitedbName'];
}
- foreach($p as $key => $entry) {
- serendipity_set_config_var(
- $entry['name'],
- $_POST[$entry['name']],
- (($entry['range'] == 'global' || $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN || IS_installed === false) ? 0 : $serendipity['authorid'])
- );
+ foreach($config as $category) {
+ foreach ( $category['items'] as $item ) {
+
+ /* Don't save trash */
+ if ( in_array('local', $item['flags']) || in_array('nosave', $item['flags']) ) {
+ continue;
+ }
+
+ if ( $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN || IS_installed === false ) {
+ $authorid = 0;
+ } else {
+ $authorid = $serendipity['authorid'];
+ }
+
+ serendipity_set_config_var($item['var'], $_POST[$item['var']], $authorid);
+ }
}
if (IS_installed === false || $serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN) {
Index: lang.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/lang.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- lang.inc.php 2 Dec 2004 14:11:28 -0000 1.4
+++ lang.inc.php 2 Dec 2004 20:57:44 -0000 1.5
@@ -1,7 +1,5 @@
<?php # $Id$
-if (!defined('LANGUAGE_LIST')) define('LANGUAGE_LIST', 'en=>English,de=>German,da=>Danish,es=>Spanish,fr=>French,cs=>Czech (Win-1250),cz=>Czech (ISO-8859-2),nl=>Dutch,pt=>Portuguese Brazilian,bg=>Bulgarian,no=>Norwegian,it=>Italian,tw=>Traditional Chinese');
-
if (!defined('serendipity_LANG_LOADED') || serendipity_LANG_LOADED !== true) {
// Try and include preferred language from the configurated setting
if (@include(S9Y_INCLUDE_PATH . 'lang/serendipity_lang_'. $serendipity['lang'] .'.inc.php') ) {
@@ -10,8 +8,7 @@
} elseif (IS_installed === false || (defined('IS_up2date') && IS_up2date === false)) { /* -- Auto-Guess -- */
// If no config file is loaded, language includes are not available.
// Now include one. Try to auto-guess the language by looking up the HTTP_ACCEPT_LANGUAGE.
- $serendipty['autolang'] = 'en';
- $supported_languages = array('en', 'da', 'de', 'es', 'cs', 'cz', 'fr', 'nl', 'pt', 'bg', 'no', 'it', 'tw');
+ $supported_languages = array_keys($serendipity['languages']);
$possible_languages = explode(',', (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''));
if (is_array($possible_languages)) {
foreach($possible_languages as $index => $lang) {
@@ -72,4 +69,4 @@
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
\ No newline at end of file
+?>
|