Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16974/include
Modified Files:
functions_installer.inc.php plugin_api.inc.php
plugin_internal.inc.php
Log Message:
* Somehow my commit to plugin API from yesterday didn't make it, so
the optimizations where missing. Now they're in. (That's why I couldn't
reproduce the smarty calendar issue on my installation...)
* Empty nuggets can have empty title again
* Somehow the way of parsing/printing the config template changed and
Rewrite Autodetection got lost. Now moved that autodecetion to
query_default function where it makes much more sense (and works again)
* Fixed bad tabs instead of spaces, fixed indentation.
Index: plugin_internal.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/plugin_internal.inc.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- plugin_internal.inc.php 20 Nov 2004 01:38:06 -0000 1.4
+++ plugin_internal.inc.php 20 Nov 2004 12:21:40 -0000 1.5
@@ -205,6 +205,7 @@
'classes' => implode(' ', array_keys($cellProps)));
} // end for
} // end for
+
$serendipity['smarty']->assign('plugin_calendar_weeks', $smartyRows);
Index: functions_installer.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_installer.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- functions_installer.inc.php 19 Nov 2004 11:05:31 -0000 1.2
+++ functions_installer.inc.php 20 Nov 2004 12:21:40 -0000 1.3
@@ -53,20 +53,20 @@
global $serendipity;
/* I won't tell you the password, it's MD5 anyway, you can't do anything with it */
- if ( $type == 'protected' && IS_installed === true ) {
+ if ($type == 'protected' && IS_installed === true) {
return '';
}
switch ($optname) {
case 'dbType' :
- if ( extension_loaded('mysqli') ) {
+ if (extension_loaded('mysqli')) {
$type = 'mysqli';
}
- if ( extension_loaded('postgres') ) {
+ if (extension_loaded('postgres')) {
$type = 'postgres';
}
- if ( extension_loaded('mysql') ) {
+ if (extension_loaded('mysql')) {
$type = 'mysql';
}
return $type;
@@ -114,6 +114,9 @@
}
return $default;
+ case 'rewrite':
+ return serendipity_check_rewrite($default);
+
default:
if ($usertemplate) {
return serendipity_get_user_var($optname, $serendipity['authorid'], $default);
@@ -184,27 +187,27 @@
// 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);
+ $cdef = ($get_defaults ? serendipity_query_default($name, $distdefault, $usertemplate, $type) : '');
+ $distDefault = serendipity_replaceEmbeddedConfigvars($distdefault);
- /* 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)
- );
- }
+ /* 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;
}
}
@@ -226,11 +229,7 @@
}
function serendipity_guessInput($type, $name, $value='', $default='') {
- global $serendipity;
-
- if ($name == 'rewrite' && $default == $value && isset($serendipity['rewrite_default']) && $serendipity['rewrite_default'] != '') {
- $value = $serendipity['rewrite_default'];
- }
+ global $serendipity;
switch ($type) {
case 'bool' :
@@ -255,16 +254,16 @@
}
echo '</select>';
break;
- case 'file' :
- echo '<input type="file" size="30" name="' . $name . '" />';
- break;
+ case 'file' :
+ echo '<input type="file" size="30" name="' . $name . '" />';
+ break;
default :
echo '<input type="text" size="30" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
break;
}
}
-function serendipity_printConfigTemplate($t, $from = false, $minimum = false, $folding = true, $_abort = true) {
+function serendipity_printConfigTemplate($t, $from = false, $minimum = false, $folding = true) {
global $serendipity;
if (!isset($serendipity['XHTML11'])) {
@@ -275,57 +274,6 @@
$folding = false;
}
- // If not yet installed, do some magic:
- $abort = false;
- if (IS_installed !== true && $_abort !== true) {
- $serendipity_root = dirname($_SERVER['PHP_SELF']) . '/';
- $serendipity_core = serendipity_httpCoreDir();
- $old_htaccess = @file_get_contents($serendipity_core . '.htaccess');
- $fp = @fopen($serendipity_core . '.htaccess', 'w');
- $serendipity_host = preg_replace('@^([^:]+):?.*$@', '\1', $_SERVER['HTTP_HOST']);
-
- if (!$fp) {
- printf(HTACCESS_ERROR,
- '<b>chmod go+rwx ' . getcwd() . '/</b>'
- );
- $abort = true;
- } else {
- fwrite($fp, 'ErrorDocument 404 ' . $serendipity_root . 'index.php');
- fclose($fp);
-
- // Do a request on a nonexistant file to see, if our htaccess allows ErrorDocument
- $sock = @fsockopen($serendipity_host, $_SERVER['SERVER_PORT'], $errorno, $errorstring, 10);
- $response = '';
-
- if ($sock) {
- fputs($sock, "GET {$_SERVER['PHP_SELF']}nonexistant HTTP/1.0\r\n");
- fputs($sock, "Host: $serendipity_host\r\n");
- fputs($sock, "User-Agent: Serendipity/{$serendipity['version']}\r\n");
- fputs($sock, "Connection: close\r\n\r\n");
-
- while (!feof($sock) && strlen($response) < 4096) {
- $response .= fgets($sock, 400);
- }
- fclose($sock);
- }
-
- if (preg_match('@^HTTP/\d\.\d 200@', $response) && preg_match('@X\-Blog: Serendipity@', $response)) {
- $serendipity['rewrite_default'] = 'errordocs';
- } else {
- $serendipity['rewrite_default'] = 'none';
- }
-
- if (!empty($old_htaccess)) {
- $fp = @fopen($serendipity_core . '.htaccess', 'w');
- fwrite($fp, $old_htaccess);
- fclose($fp);
- } else {
- @unlink($serendipity_core . '.htaccess');
- }
- }
- }
-
- if ($abort === false) {
?>
<script type="text/javascript" language="JavaScript">
function showConfig(id) {
@@ -361,7 +309,7 @@
</script>
<?php
- if (!$minimum) {
+ if (!$minimum) {
?>
<form action="?" method="POST">
<div>
@@ -369,19 +317,19 @@
<input type="hidden" name="installAction" value="check" />
<br />
<?php }
- if ( sizeof($t['categories']) > 1 ) { ?>
+ if (sizeof($t['categories']) > 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 />
</div>
<?php
- }
- $el_count = 0;
- foreach ($t['categories'] as $key => $value) {
- $el_count++;
+ }
+ $el_count = 0;
+ foreach ($t['categories'] as $key => $value) {
+ $el_count++;
?>
<table width="100%" cellspacing="2">
<?php
- if ( sizeof($t['categories']) > 1 ) {
+ if (sizeof($t['categories']) > 1) {
?>
<tr>
<th align="left" colspan="2" style="padding-left: 15px;">
@@ -398,23 +346,23 @@
</tr>
<?php
- for ($x=0; $x<count($value); $x++) {
+ for ($x=0; $x<count($value); $x++) {
- /* Check for installOnly flag */
- if ( in_array('installOnly', $value[$x]['flags']) && IS_installed === true ) {
- continue;
- }
+ /* Check for installOnly flag */
+ if ( in_array('installOnly', $value[$x]['flags']) && IS_installed === true ) {
+ continue;
+ }
- /* If we have a valuelist, then use the value from there */
- if (@is_array($from)) {
- $value[$x]['value'] = $from[$value[$x]['name']];
- }
+ /* If we have a valuelist, then use the value from there */
+ if (@is_array($from)) {
+ $value[$x]['value'] = $from[$value[$x]['name']];
+ }
- /* 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 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'];
+ }
?>
<tr>
<td style="border-bottom: 1px #000000 solid" align="left" valign="top" width="75%">
@@ -427,22 +375,21 @@
</td>
</tr>
<?php
- }
+ }
?>
</table><br /><br />
</td>
</tr>
</table>
<?php
- }
+ }
- if (!$minimum) {
+ if (!$minimum) {
?>
<input type="submit" value="<?php echo CHECK_N_SAVE; ?>" />
</div>
</form>
<?php
- }
}
}
@@ -836,4 +783,59 @@
return preg_replace('@/include$@', '', dirname($file)) . '/';
}
+function serendipity_check_rewrite($default) {
+ global $serendipity;
+
+ if (IS_installed == true) {
+ return $default;
+ }
+
+ $serendipity_root = dirname($_SERVER['PHP_SELF']) . '/';
+ $serendipity_core = serendipity_httpCoreDir();
+ $old_htaccess = @file_get_contents($serendipity_core . '.htaccess');
+ $fp = @fopen($serendipity_core . '.htaccess', 'w');
+ $serendipity_host = preg_replace('@^([^:]+):?.*$@', '\1', $_SERVER['HTTP_HOST']);
+
+ if (!$fp) {
+ printf(HTACCESS_ERROR,
+ '<b>chmod go+rwx ' . getcwd() . '/</b>'
+ );
+ return $default;
+ } else {
+ fwrite($fp, 'ErrorDocument 404 ' . $serendipity_root . 'index.php');
+ fclose($fp);
+
+ // Do a request on a nonexistant file to see, if our htaccess allows ErrorDocument
+ $sock = @fsockopen($serendipity_host, $_SERVER['SERVER_PORT'], $errorno, $errorstring, 10);
+ $response = '';
+
+ if ($sock) {
+ fputs($sock, "GET {$_SERVER['PHP_SELF']}nonexistant HTTP/1.0\r\n");
+ fputs($sock, "Host: $serendipity_host\r\n");
+ fputs($sock, "User-Agent: Serendipity/{$serendipity['version']}\r\n");
+ fputs($sock, "Connection: close\r\n\r\n");
+
+ while (!feof($sock) && strlen($response) < 4096) {
+ $response .= fgets($sock, 400);
+ }
+ fclose($sock);
+ }
+
+ if (preg_match('@^HTTP/\d\.\d 200@', $response) && preg_match('@X\-Blog: Serendipity@', $response)) {
+ $default = 'errordocs';
+ } else {
+ $default = 'none';
+ }
+
+ if (!empty($old_htaccess)) {
+ $fp = @fopen($serendipity_core . '.htaccess', 'w');
+ fwrite($fp, $old_htaccess);
+ fclose($fp);
+ } else {
+ @unlink($serendipity_core . '.htaccess');
+ }
+
+ return $default;
+ }
+}
?>
Index: plugin_api.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/plugin_api.inc.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- plugin_api.inc.php 20 Nov 2004 01:38:06 -0000 1.3
+++ plugin_api.inc.php 20 Nov 2004 12:21:40 -0000 1.4
@@ -26,7 +26,6 @@
*/
class serendipity_plugin_api {
-
function register_default_plugins()
{
/* Register default sidebar plugins, order matters */
@@ -78,10 +77,11 @@
/* Check for multiple dependencies */
$plugin =& serendipity_plugin_api::load_plugin($key, $authorid);
- $plugin->install();
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
+ serendipity_plugin_api::get_event_plugins(false, true); // Refresh static list of plugins to allow execution of added plugin
$plugin->register_dependencies(false, $authorid);
+ $plugin->install();
return $key;
}
@@ -292,7 +292,7 @@
}
}
- $class_name = $name;
+ $class_name =& $name;
}
$p =& new $class_name($instance_id);
@@ -343,6 +343,7 @@
function generate_plugins($side)
{
global $serendipity;
+
$plugins = serendipity_plugin_api::enum_plugins($side);
if (!is_array($plugins)) {
@@ -362,14 +363,15 @@
ob_end_clean();
if ($show_plugin !== FALSE) {
- $pluginData[] = array('side' => $side,
- 'class' => get_class($plugin),
- 'title' => $title,
+ $pluginData[] = array('side' => $side,
+ 'class' => $class,
+ 'title' => $title,
'content' => $content);
}
}
$serendipity['smarty']->assign('plugindata', $pluginData);
+
return serendipity_smarty_fetch('sidebar_'. $side, 'sidebar.tpl', true);
}
@@ -377,7 +379,21 @@
{
global $serendipity;
- $title = $plugin->get_config('title');
+ // Generate plugin output. Make sure that by probing the plugin, no events are actually called. After that,
+ // restore setting of 'no_events'.
+
+ if (!is_null($plugin->title)) {
+ // Preferred way of fetching a plugins title
+ $title = &$plugin->title;
+ } else {
+ $ne = (isset($serendipity['no_events']) && $serendipity['no_events'] ? TRUE : FALSE);
+ $serendipity['no_events'] = TRUE;
+ ob_start();
+ $plugin->generate_content($title);
+ ob_end_clean();
+ $serendipity['no_events'] = $ne;
+ }
+
if (strlen(trim($title)) == 0) {
if (!empty($default_title)) {
$title = $default_title;
@@ -395,10 +411,16 @@
return (strstr($name, '_event_'));
}
- function &get_event_plugins($getInstance = false) {
+ function &get_event_plugins($getInstance = false, $refresh = false) {
static $event_plugins;
- if (isset($event_plugins) && is_array($event_plugins)) {
+ if (!$refresh && isset($event_plugins) && is_array($event_plugins)) {
+ if ($getInstance) {
+ if (isset($event_plugins[$getInstance]['p'])) {
+ return $event_plugins[$getInstance]['p'];
+ }
+ return false;
+ }
return $event_plugins;
}
@@ -409,7 +431,7 @@
}
$event_plugins = array();
- foreach ($plugins as $plugin_data) {
+ foreach($plugins AS $plugin_data) {
if ($event_plugins[$plugin_data['name']]['p'] = &serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'])) {
/* query for its name, description and configuration data */
$event_plugins[$plugin_data['name']]['b'] = new serendipity_property_bag;
@@ -441,10 +463,17 @@
$plugins = &serendipity_plugin_api::get_event_plugins();
if (is_array($plugins)) {
- foreach($plugins AS $plugin => $plugin_data) {
+ // foreach() operates on copies of values, but we want to operate on references, so we use while()
+ @reset($plugins);
+ while(list($plugin, $plugin_data) = each($plugins)) {
$bag = &$plugin_data['b'];
- if ( array_key_exists($event_name, $bag->get('event_hooks')) ) {
- $plugin_data['p']->event_hook($event_name, $plugin_data['b'], $eventData, $addData);
+ if (array_key_exists($event_name, $bag->get('event_hooks'))) {
+ // Check for cachable events.
+ if (isset($eventData['is_cached']) && $eventData['is_cached'] && array_key_exists($event_name, (array)$bag->get('cachable_events'))) {
+ continue;
+ }
+
+ $plugin_data['p']->event_hook($event_name, $bag, $eventData, $addData);
}
}
}
@@ -469,42 +498,25 @@
}
}
-/* holds a bunch of properties; you can have multiple
-* properties with the same name */
+/* holds a bunch of properties; since serendipity 0.8 only one value per key is allowed [was never really useful] */
class serendipity_property_bag {
var $properties = array();
var $name = null;
function add($name, $value)
{
- $this->properties[] = array(
- 'name' => $name,
- 'value' => $value
- );
+ $this->properties[$name] = $value;
}
- function get($name)
+ function &get($name)
{
- $v = array();
- foreach ($this->properties as $data) {
- if ($data['name'] == $name) {
- $v[] = $data['value'];
- }
- }
-
- if (count($v) == 1) {
- return $v[0];
- }
-
- return implode(', ', $v);
+ return $this->properties[$name];
}
function is_set($name)
{
- foreach ($this->properties as $data) {
- if ($data['name'] == $name) {
- return true;
- }
+ if (isset($this->properties[$name])) {
+ return true;
}
return false;
@@ -517,6 +529,7 @@
var $wrap_class = 'serendipitySideBarItem';
var $title_class = 'serendipitySideBarTitle';
var $content_class = 'serendipitySideBarContent';
+ var $title = null;
/* Be sure to call this method from your derived classes constructors,
* otherwise your config data will not be stored or retrieved correctly
|