Archived
1
0

Use return instead of echo in the remaining core

Debug-messages still may use echo, and some functions in functions_image and trackback still use it to generate progress messages, which should get cleaned up as well but is not that urgent
This commit is contained in:
onli
2013-07-05 19:16:11 +02:00
parent 0614fcdf51
commit d80a8334c8
16 changed files with 51 additions and 73 deletions

View File

@@ -16,7 +16,8 @@
* New additional option to render smarty-functions: serendipity_smarty_show($template, $data) * New additional option to render smarty-functions: serendipity_smarty_show($template, $data)
* A number of functions now returns their result instead of echoing them (TODO: Make that "all functions"): * A number of functions now returns their result instead of echoing them (TODO: a bunch of image- and
trackback-functions still use echo for messages"):
serendipity_plugin_config serendipity_plugin_config
serendipity_printEntryForm serendipity_printEntryForm
serendipity_printEntries serendipity_printEntries
@@ -24,6 +25,12 @@
serendipity_showPropertyForm serendipity_showPropertyForm
showMediaLibrary showMediaLibrary
serendipity_guessInput serendipity_guessInput
memSnap
serendipity_displayTopUrlList
serendipity_displayTopExits
serendipity_displayTopReferrers
serendipity_printConfigTemplate
show_plugins
* Functions removed from the core: * Functions removed from the core:
serendipity_printConfigJS serendipity_printConfigJS
@@ -77,4 +84,6 @@
* jQuery in the backend no longer runs in noConflict-mode. Use $(...) instead of jQuery(...) * jQuery in the backend no longer runs in noConflict-mode. Use $(...) instead of jQuery(...)
* The entryproperty-plugin will now always delete its cache on uninstall, not only if the cache is activated then * The entryproperty-plugin will now always delete its cache on uninstall, not only if the cache is activated then
* serendipity_is_iframe now really only checks for iframe and doesn't also echo it

View File

@@ -68,10 +68,7 @@ switch ($_POST['installAction'] && serendipity_checkFormToken()) {
default: default:
$from = &$serendipity; $from = &$serendipity;
$t = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE); $t = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE);
ob_start(); $data['config'] = serendipity_printConfigTemplate($t, $from, false, true);
serendipity_printConfigTemplate($t, $from, false, true);
$data['config'] = ob_get_contents();
ob_end_clean();
break; break;
} }

View File

@@ -325,17 +325,11 @@ if ( (int)$serendipity['GET']['step'] == 0 ) {
} elseif ( $serendipity['GET']['step'] == '2a' ) { } elseif ( $serendipity['GET']['step'] == '2a' ) {
$config = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE, null, array('simpleInstall')); $config = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE, null, array('simpleInstall'));
ob_start(); $data['ob_serendipity_printConfigTemplate'] = serendipity_printConfigTemplate($config, $from, true, false, false);
serendipity_printConfigTemplate($config, $from, true, false, false);
$data['ob_serendipity_printConfigTemplate'] = ob_get_contents();
ob_end_clean();
} elseif ( $serendipity['GET']['step'] == '2b' ) { } elseif ( $serendipity['GET']['step'] == '2b' ) {
$config = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE); $config = serendipity_parseTemplate(S9Y_CONFIG_TEMPLATE);
ob_start(); $data['ob_serendipity_printConfigTemplate'] = serendipity_printConfigTemplate($config, $from, true, false, false);
serendipity_printConfigTemplate($config, $from, true, false, false);
$data['ob_serendipity_printConfigTemplate'] = ob_get_contents();
ob_end_clean();
} elseif ( $serendipity['GET']['step'] == '3' ) { } elseif ( $serendipity['GET']['step'] == '3' ) {
$serendipity['dbPrefix'] = $_POST['dbPrefix']; $serendipity['dbPrefix'] = $_POST['dbPrefix'];

View File

@@ -105,10 +105,7 @@ $user = serendipity_fetchUsers($serendipity['authorid']);
$from = $user[0]; $from = $user[0];
$from['groups'] = serendipity_getGroups($serendipity['authorid']); $from['groups'] = serendipity_getGroups($serendipity['authorid']);
unset($from['password']); unset($from['password']);
ob_start(); $data['config'] = serendipity_printConfigTemplate($template, $from, true, false);
serendipity_printConfigTemplate($template, $from, true, false);
$data['config'] = ob_get_contents();
ob_get_clean();
$add = array('internal' => true); $add = array('internal' => true);

View File

@@ -389,20 +389,14 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
$data['backend_plugins_sidebar_header'] = ob_get_contents(); $data['backend_plugins_sidebar_header'] = ob_get_contents();
ob_end_clean(); ob_end_clean();
ob_start(); $data['sidebar_plugins'] = show_plugins(false, $sidebars);
show_plugins(false, $sidebars);
$data['sidebar_plugins'] = ob_get_contents();
ob_end_clean();
ob_start(); ob_start();
serendipity_plugin_api::hook_event('backend_plugins_event_header', $serendipity); serendipity_plugin_api::hook_event('backend_plugins_event_header', $serendipity);
$data['backend_plugins_event_header'] = ob_get_contents(); $data['backend_plugins_event_header'] = ob_get_contents();
ob_end_clean(); ob_end_clean();
ob_start(); $data['event_plugins'] = show_plugins(true);
show_plugins(true);
$data['event_plugins'] = ob_get_contents();
ob_end_clean();
if (count($serendipity['memSnaps']) > 0) { if (count($serendipity['memSnaps']) > 0) {
$data['$memsnaps'] = $serendipity['memSnaps']; $data['$memsnaps'] = $serendipity['memSnaps'];
@@ -410,10 +404,6 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
} }
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
echo serendipity_smarty_show('admin/plugins.inc.tpl', $data); echo serendipity_smarty_show('admin/plugins.inc.tpl', $data);
/* vim: set sts=4 ts=4 expandtab : */ /* vim: set sts=4 ts=4 expandtab : */

View File

@@ -228,10 +228,7 @@ if ( ($serendipity['GET']['adminAction'] == 'edit' && serendipity_checkPermissio
$from['groups'] = array(); $from['groups'] = array();
} }
ob_start(); $data['config'] = serendipity_printConfigTemplate($config, $from, true, false, true, true);
serendipity_printConfigTemplate($config, $from, true, false, true, true);
$data['config'] = ob_get_contents();
ob_end_clean();
} elseif ($serendipity['GET']['adminAction'] == 'delete' && serendipity_checkPermission('adminUsersDelete')) { } elseif ($serendipity['GET']['adminAction'] == 'delete' && serendipity_checkPermission('adminUsersDelete')) {
$user = serendipity_fetchUsers($serendipity['GET']['userid']); $user = serendipity_fetchUsers($serendipity['GET']['userid']);
@@ -246,11 +243,6 @@ if ( ($serendipity['GET']['adminAction'] == 'edit' && serendipity_checkPermissio
} }
} }
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
echo serendipity_smarty_show('admin/users.inc.tpl', $data); echo serendipity_smarty_show('admin/users.inc.tpl', $data);
/* vim: set sts=4 ts=4 expandtab : */ /* vim: set sts=4 ts=4 expandtab : */

View File

@@ -58,8 +58,8 @@ function memSnap($tshow = '') {
} }
$current = memory_get_usage(); $current = memory_get_usage();
echo '[' . date('d.m.Y H:i') . '] ' . number_format($current - $memUsage, 2, ',', '.') . ' label "' . $tshow . '", totalling ' . number_format($current, 2, ',', '.') . '<br />' . "\n";
$memUsage = $current; $memUsage = $current;
return '[' . date('d.m.Y H:i') . '] ' . number_format($current - $memUsage, 2, ',', '.') . ' label "' . $tshow . '", totalling ' . number_format($current, 2, ',', '.') . '<br />' . "\n";
} }
/** /**

View File

@@ -856,7 +856,7 @@ function serendipity_track_url($list, $url, $entry_id = 0) {
* @return string List of Top referrers * @return string List of Top referrers
*/ */
function serendipity_displayTopReferrers($limit = 10, $use_links = true, $interval = 7) { function serendipity_displayTopReferrers($limit = 10, $use_links = true, $interval = 7) {
serendipity_displayTopUrlList('referrers', $limit, $use_links, $interval); return serendipity_displayTopUrlList('referrers', $limit, $use_links, $interval);
} }
/** /**
@@ -870,7 +870,7 @@ function serendipity_displayTopReferrers($limit = 10, $use_links = true, $interv
* @return string List of Top exits * @return string List of Top exits
*/ */
function serendipity_displayTopExits($limit = 10, $use_links = true, $interval = 7) { function serendipity_displayTopExits($limit = 10, $use_links = true, $interval = 7) {
serendipity_displayTopUrlList('exits', $limit, $use_links, $interval); return serendipity_displayTopUrlList('exits', $limit, $use_links, $interval);
} }
/** /**
@@ -913,18 +913,18 @@ function serendipity_displayTopUrlList($list, $limit, $use_links = true, $interv
} }
$rows = serendipity_db_query($query); $rows = serendipity_db_query($query);
echo "<span class='serendipityReferer'>"; $output = "<span class='serendipityReferer'>";
if (is_array($rows)) { if (is_array($rows)) {
foreach ($rows as $row) { foreach ($rows as $row) {
if ($use_links) { if ($use_links) {
printf( $output .= sprintf(
'<span class="block_level"><a href="%1$s://%2$s" title="%2$s" >%2$s</a> (%3$s)</span>', '<span class="block_level"><a href="%1$s://%2$s" title="%2$s" >%2$s</a> (%3$s)</span>',
htmlspecialchars($row['scheme']), htmlspecialchars($row['scheme']),
htmlspecialchars($row['host']), htmlspecialchars($row['host']),
htmlspecialchars($row['total']) htmlspecialchars($row['total'])
); );
} else { } else {
printf( $output .= sprintf(
'<span class="block_level">%1$s (%2$s)</span>', '<span class="block_level">%1$s (%2$s)</span>',
htmlspecialchars($row['host']), htmlspecialchars($row['host']),
htmlspecialchars($row['total']) htmlspecialchars($row['total'])
@@ -932,7 +932,8 @@ function serendipity_displayTopUrlList($list, $limit, $use_links = true, $interv
} }
} }
} }
echo "</span>"; $output .= "</span>";
return $output;
} }
/** /**

View File

@@ -110,6 +110,7 @@ function serendipity_set_config_var($name, $val, $authorid = 0) {
} }
if (is_string($r)) { if (is_string($r)) {
# if $r is a string, it is the error-message from the insert
echo $r; echo $r;
} }
} }
@@ -737,18 +738,6 @@ function serendipity_is_iframe() {
global $serendipity; global $serendipity;
if ($serendipity['GET']['is_iframe'] && is_array($_SESSION['save_entry'])) { if ($serendipity['GET']['is_iframe'] && is_array($_SESSION['save_entry'])) {
include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
// An iframe may NOT contain <html> and </html> tags, that's why we emit different headers here than on serendipity_admin.php
// We need to restore GET/POST variables to that depending plugins inside the iframe
// can still fetch all that variables; and we also tighten security by not allowing
// to pass any different GET/POST variables to our iframe.
$iframe_mode = $serendipity['GET']['iframe_mode'];
$serendipity['POST'] = &$_SESSION['save_entry_POST'];
$serendipity['GET'] = &$_SESSION['save_entry_POST']; // GET-Vars are the same as POST to ensure compatibility.
$serendipity['hidefooter'] = true;
ignore_user_abort(true);
echo serendipity_iframe($_SESSION['save_entry'], $iframe_mode);
return true; return true;
} }
return false; return false;

View File

@@ -494,7 +494,7 @@ function serendipity_printConfigTemplate($config, $from = false, $noForm = false
} }
} }
$data['config'] = $config; $data['config'] = $config;
echo serendipity_smarty_show('admin/config_template.tpl', $data); return serendipity_smarty_show('admin/config_template.tpl', $data);
} }
/** /**

View File

@@ -203,7 +203,7 @@ function show_plugins($event_only = false, $sidebars = null)
} }
$data['total'] = $i; $data['total'] = $i;
echo serendipity_smarty_show('admin/show_plugins.fnc.tpl', $data); return serendipity_smarty_show('admin/show_plugins.fnc.tpl', $data);
} }
/** /**
@@ -625,10 +625,7 @@ function serendipity_plugin_config(&$plugin, &$bag, &$name, &$desc, &$config_nam
if ($showExample && method_exists($plugin, 'example') ) { if ($showExample && method_exists($plugin, 'example') ) {
$data['showExample'] = true; $data['showExample'] = true;
ob_start(); $data['plugin_example'] = $plugin->example();
echo $plugin->example();
$data['plugin_example'] = ob_get_contents();
ob_end_clean();
} }
if ($spawnNuggets && isset($serendipity['wysiwyg']) && $serendipity['wysiwyg'] && count($htmlnugget) > 0) { if ($spawnNuggets && isset($serendipity['wysiwyg']) && $serendipity['wysiwyg'] && count($htmlnugget) > 0) {

View File

@@ -14,7 +14,7 @@ class serendipity_event_statistics extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_STATISTICS_DESC); $propbag->add('description', PLUGIN_EVENT_STATISTICS_DESC);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Arnan de Gans, Garvin Hicking, Fredrik Sandberg, kalkin'); $propbag->add('author', 'Arnan de Gans, Garvin Hicking, Fredrik Sandberg, kalkin');
$propbag->add('version', '1.51'); $propbag->add('version', '1.52');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '0.8', 'serendipity' => '0.8',
'smarty' => '2.6.7', 'smarty' => '2.6.7',
@@ -532,11 +532,11 @@ class serendipity_event_statistics extends serendipity_event
<br /> <br />
<dt><strong><?php echo TOP_REFERRER; ?></strong></dt> <dt><strong><?php echo TOP_REFERRER; ?></strong></dt>
<dd><?php serendipity_displayTopReferrers($max_items, true); ?></dd> <dd><?php echo serendipity_displayTopReferrers($max_items, true); ?></dd>
<br /> <br />
<dt><strong><?php echo TOP_EXITS; ?></strong></dt> <dt><strong><?php echo TOP_EXITS; ?></strong></dt>
<dd><?php serendipity_displayTopExits($max_items, true); ?></dd> <dd><?php echo serendipity_displayTopExits($max_items, true); ?></dd>
</dl> </dl>
<hr /> <hr />
<?php serendipity_plugin_api::hook_event('event_additional_statistics', $eventData, array('maxitems' => $max_items)); ?> <?php serendipity_plugin_api::hook_event('event_additional_statistics', $eventData, array('maxitems' => $max_items)); ?>

View File

@@ -9,7 +9,7 @@ class serendipity_plugin_topexits extends serendipity_plugin {
$propbag->add('description', SHOWS_TOP_EXIT); $propbag->add('description', SHOWS_TOP_EXIT);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team'); $propbag->add('author', 'Serendipity Team');
$propbag->add('version', '1.0'); $propbag->add('version', '1.1');
$propbag->add('configuration', array('limit', 'use_links', 'interval')); $propbag->add('configuration', array('limit', 'use_links', 'interval'));
$propbag->add('groups', array('STATISTICS')); $propbag->add('groups', array('STATISTICS'));
} }
@@ -62,7 +62,7 @@ class serendipity_plugin_topexits extends serendipity_plugin {
$use_links = serendipity_db_bool($use_links); $use_links = serendipity_db_bool($use_links);
} }
serendipity_displayTopExits($this->get_config('limit', 10), $use_links, $this->get_config('interval', 7)); echo serendipity_displayTopExits($this->get_config('limit', 10), $use_links, $this->get_config('interval', 7));
} }
} }

View File

@@ -9,7 +9,7 @@ class serendipity_plugin_topreferrers extends serendipity_plugin {
$propbag->add('description', SHOWS_TOP_SITES); $propbag->add('description', SHOWS_TOP_SITES);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Serendipity Team'); $propbag->add('author', 'Serendipity Team');
$propbag->add('version', '1.1'); $propbag->add('version', '1.2');
$propbag->add('configuration', array('limit', 'use_links', 'interval')); $propbag->add('configuration', array('limit', 'use_links', 'interval'));
$propbag->add('groups', array('STATISTICS')); $propbag->add('groups', array('STATISTICS'));
} }
@@ -61,7 +61,7 @@ class serendipity_plugin_topreferrers extends serendipity_plugin {
} else { } else {
$use_links = serendipity_db_bool($use_links); $use_links = serendipity_db_bool($use_links);
} }
serendipity_displayTopReferrers($this->get_config('limit', 10), $use_links, $this->get_config('interval', 7)); echo serendipity_displayTopReferrers($this->get_config('limit', 10), $use_links, $this->get_config('interval', 7));
} }
} }

View File

@@ -37,6 +37,18 @@ if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModul
// If we are inside an iframe, halt the script // If we are inside an iframe, halt the script
if (serendipity_is_iframe() !== false) { if (serendipity_is_iframe() !== false) {
include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
// An iframe may NOT contain <html> and </html> tags, that's why we emit different headers here than on serendipity_admin.php
// We need to restore GET/POST variables to that depending plugins inside the iframe
// can still fetch all that variables; and we also tighten security by not allowing
// to pass any different GET/POST variables to our iframe.
$iframe_mode = $serendipity['GET']['iframe_mode'];
$serendipity['POST'] = &$_SESSION['save_entry_POST'];
$serendipity['GET'] = &$_SESSION['save_entry_POST']; // GET-Vars are the same as POST to ensure compatibility.
$serendipity['hidefooter'] = true;
ignore_user_abort(true);
echo serendipity_iframe($_SESSION['save_entry'], $iframe_mode);
return true; return true;
} }

View File

@@ -41,7 +41,7 @@ if (!defined('IN_serendipity')) {
include(S9Y_INCLUDE_PATH . 'include/compat.inc.php'); include(S9Y_INCLUDE_PATH . 'include/compat.inc.php');
if (defined('USE_MEMSNAP')) { if (defined('USE_MEMSNAP')) {
memSnap('Framework init'); echo memSnap('Framework init');
} }
// The version string // The version string
@@ -296,7 +296,7 @@ if (!serendipity_db_connect()) {
*/ */
if (defined('USE_MEMSNAP')) { if (defined('USE_MEMSNAP')) {
memSnap('Framework init'); echo memSnap('Framework init');
} }
serendipity_load_configuration(); serendipity_load_configuration();