From 11fda99c896ffa9d1c3bdf6801648d00848f3abe Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Mon, 5 Sep 2005 21:14:49 +0000 Subject: [PATCH] * Optimize memory usage by splitting files * Optimize memory usage of spartacus plugin (parses chunks of XML and frees it) * Optimize memory usage of bbcode plugin * Add "memSnap" function to snapshot memory usage (debugging) --- docs/NEWS | 6 + include/admin/entries.inc.php | 3 + include/admin/plugins.inc.php | 1 + include/compat.inc.php | 30 + include/db/db.inc.php | 1 - include/functions.inc.php | 3 - include/functions_config.inc.php | 1 + include/functions_entries.inc.php | 757 ------------------ include/functions_entries_admin.inc.php | 539 +++++++++++++ include/functions_rss.inc.php | 225 ++++++ include/functions_smarty.inc.php | 30 + include/functions_trackbacks.inc.php | 29 - include/plugin_api.inc.php | 2 +- .../serendipity_event_bbcode.php | 133 +-- .../serendipity_event_spartacus.php | 48 +- .../serendipity_event_weblogping.php | 2 + rss.php | 2 + serendipity_admin.php | 1 + serendipity_config.inc.php | 1 - 19 files changed, 944 insertions(+), 870 deletions(-) create mode 100644 include/functions_entries_admin.inc.php create mode 100644 include/functions_rss.inc.php diff --git a/docs/NEWS b/docs/NEWS index 60265c6..8867a61 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,12 @@ Version 0.9 () ------------------------------------------------------------------------ + * Reduce memory usage by splitting up function files, optimizing + spartacus parsing. New files: + include/functions_rss.inc.php + include/functions_entries_admin.inc.php + (garvinhicking) + * Inserting links via the Serendipity Toolbar over the entry area now also asks for a link tooltipe/title. diff --git a/include/admin/entries.inc.php b/include/admin/entries.inc.php index a9dc08f..56e5efa 100644 --- a/include/admin/entries.inc.php +++ b/include/admin/entries.inc.php @@ -367,6 +367,7 @@ switch($serendipity['GET']['adminAction']) { $entry['id'] = $serendipity['lastSavedEntry']; } + include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php'; serendipity_printEntryForm( '?', array( @@ -408,6 +409,8 @@ switch($serendipity['GET']['adminAction']) { $entry = serendipity_fetchEntry('id', $serendipity['GET']['id'], 1, 1); default: + include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php'; + serendipity_printEntryForm( '?', array( diff --git a/include/admin/plugins.inc.php b/include/admin/plugins.inc.php index 3983044..42e49a7 100644 --- a/include/admin/plugins.inc.php +++ b/include/admin/plugins.inc.php @@ -12,6 +12,7 @@ if (!serendipity_checkPermission('adminPlugins')) { include_once S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php'; include_once S9Y_INCLUDE_PATH . 'include/plugin_internal.inc.php'; +include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php'; function serendipity_groupname($group) { if (defined('PLUGIN_GROUP_' . $group)) { diff --git a/include/compat.inc.php b/include/compat.inc.php index 7590ac6..3b83820 100644 --- a/include/compat.inc.php +++ b/include/compat.inc.php @@ -21,6 +21,36 @@ if (!defined('DIRECTORY_SEPARATOR')) { } } +/* Function to get a snapshot uf used memory */ +function memSnap($tshow = '') { + static $avail = null; + static $show = true; + static $memUsage = 0; + + if (!$show) { + return false; + } + + if ($avail === false) { + return true; + } elseif ($avail === null) { + if (function_exists('memory_get_usage')) { + $avail = memory_get_usage(); + } else { + $avail = false; + return false; + } + } + + if ($memUsage === 0) { + $memUsage = $avail; + } + + $current = memory_get_usage(); + echo '[' . date('d.m.Y H:i') . '] ' . number_format($current - $memUsage, 2, ',', '.') . ' label "' . $tshow . '", totalling ' . number_format($current, 2, ',', '.') . '
' . "\n"; + $memUsage = $current; +} + if (!function_exists('file_get_contents')) { function file_get_contents($filename, $use_include_path = 0) { $file = fopen($filename, 'rb', $use_include_path); diff --git a/include/db/db.inc.php b/include/db/db.inc.php index 6ef09e4..a5069e4 100644 --- a/include/db/db.inc.php +++ b/include/db/db.inc.php @@ -2,7 +2,6 @@ # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) # All rights reserved. See LICENSE file for licensing details - if (@include_once(S9Y_INCLUDE_PATH . "include/db/{$serendipity['dbType']}.inc.php")) { @define('S9Y_DB_INCLUDED', TRUE); } diff --git a/include/functions.inc.php b/include/functions.inc.php index 36e5038..1266c45 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -6,14 +6,12 @@ $serendipity['imageList'] = array(); include_once(S9Y_INCLUDE_PATH . "include/db/db.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/compat.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_config.inc.php"); -include_once(S9Y_PEAR_PATH . "XML/RPC.php"); include_once(S9Y_INCLUDE_PATH . "include/plugin_api.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_images.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_installer.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_entries.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_comments.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_permalinks.inc.php"); -include_once(S9Y_INCLUDE_PATH . "include/functions_trackbacks.inc.php"); include_once(S9Y_INCLUDE_PATH . "include/functions_smarty.inc.php"); function serendipity_truncateString($s, $len) { @@ -644,4 +642,3 @@ function serendipity_updateCategory($cid, $name, $desc, $authorid, $icon, $paren define("serendipity_FUNCTIONS_LOADED", true); /* vim: set sts=4 ts=4 expandtab : */ -?> diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php index bb3ce76..62f90c5 100644 --- a/include/functions_config.inc.php +++ b/include/functions_config.inc.php @@ -321,6 +321,7 @@ function serendipity_is_iframe() { global $serendipity; 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 and tags, that's why we emit different headers here than on serendipity_admin.php ?> diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 44e091e..e42f453 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -740,229 +740,6 @@ function serendipity_printEntries($entries, $extended = 0, $preview = false) { } // end function serendipity_printEntries -function serendipity_printEntries_rss($entries, $version, $comments = false, $fullFeed = false, $showMail = true) { - global $serendipity; - - if (is_array($entries)) { - foreach ($entries as $entry) { - $id = (isset($entry['entryid']) && !empty($entry['entryid']) ? $entry['entryid'] : $entry['id']); - $guid = serendipity_rss_getguid($entry, $comments); - $entryLink = serendipity_archiveURL($id, $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])); - if ($comments == true) { - // Display username as part of the title for easier feed-readability - $entry['title'] = $entry['author'] . ': ' . $entry['title']; - } - - // Embed a link to extended entry, if existing - if ($fullFeed) { - $entry['body'] .= ' ' . $entry['extended']; - } elseif ($entry['exflag']) { - $ext = '
' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . ''; - } else { - $ext = ''; - } - - serendipity_plugin_api::hook_event('frontend_display', $entry); - // Do some relative -> absolute URI replacing magic. Replaces all HREF/SRC (, , ...) references to only the serendipitypath with the full baseURL URI - // garvin: Could impose some problems. Closely watch this one. - $entry['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\1=\2' . $serendipity['baseURL'] . '\4\2\6>', $entry['body']); - // jbalcorn: clean up body for XML compliance as best we can. - $entry['body'] = xhtml_cleanup($entry['body']); - - // extract author information - if ((isset($entry['no_email']) && $entry['no_email']) || !$showMail) { - $entry['email'] = 'nospam@example.com'; // RSS Feeds need an E-Mail address! - } elseif (empty($entry['email'])) { - $query = "select email FROM {$serendipity['dbPrefix']}authors WHERE authorid = '". serendipity_db_escape_string($entry['authorid']) ."'"; - $results = serendipity_db_query($query); - $entry['email'] = $results[0]['email']; - } - - if (!is_array($entry['categories'])) { - $entry['categories'] = array(0 => array('category_name' => $entry['category_name'])); - } - - if ($version == 'atom0.3') { - /*********** ATOM 0.3 FEED *************/ -?> - - - - - - - - - - - wfwcomment.php?cid= - - - - rss.php?version=&type=comments&cid= - - - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - -
- -
-
- -
- - - - - - - - - - - wfwcomment.php?cid= - - - - rss.php?version=&type=comments&cid= - $cat) { - $name = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); ?> - - - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - -
- -
-
- -
- - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - $cat) { - ?> - #comments - wfwcomment.php?cid= - - - rss.php?version=&type=comments&cid= - - - - - - - - - - - - - - - $cat) { - $categories[] = $cat['category_name']; - } - -?> - - <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> - - - - - - - - - - wfwcomment.php?cid= - - - rss.php?version=&type=comments&cid= - - - - -' . $n; - $cat_list .= ' ' . $n; - $selected = array(); - if (is_array($entry['categories'])) { - if (count($entry['categories']) > 1) { - $categoryselector_expanded = true; - } - - foreach ($entry['categories'] as $cat) { - $selected[] = $cat['categoryid']; - } - } - - if (count($selected) > 1 || - (isset($serendipity['POST']['categories']) && is_array($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1)) { - $categoryselector_expanded = true; - } - - if (is_array($cats = serendipity_fetchCategories())) { - $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); - foreach ( $cats as $cat ) { - $cat_list .= '' . "\n"; - } - } - $cat_list .= '' . $n; - - if (!empty($serendipity['GET']['title'])) { - $entry['title'] = utf8_decode(urldecode($serendipity['GET']['title'])); - } - - if (!empty($serendipity['GET']['body'])) { - $entry['body'] = utf8_decode(urldecode($serendipity['GET']['body'])); - } - - if (!empty($serendipity['GET']['url'])) { - $entry['body'] .= "\n" . '
' . $entry['title'] . ''; - } - - $hidden = ''; - foreach($hiddens as $key => $value) { - $hidden .= ' ' . $n; - } - $hidden .= ' ' . $n; - $hidden .= ' ' . $n; - $hidden .= ' '; - - if (!empty($errMsg)) { -?> -
- -
="serendipityEntry" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- : - - - - - - -
- -
-
- : - - - - <?php echo RESET_DATE ?> - - - - - : - -
- - - - - - - - -
- -
- - - - - -
- />
- /> -
-
- -
-
-
- - +/- - - - - -
- - - - -
-
-
- - -
-
-
- - - - 'serendipity[body]', - 'extended' => 'serendipity[extended]' - ); - - foreach($fields AS $f_jsname => $f_item) { - serendipity_emit_htmlarea_code($f_item, $f_jsname); - } - serendipity_plugin_api::hook_event('backend_wysiwyg_finish', $fields); - } - - echo ' '; - echo ' '; -} - -function serendipity_emit_htmlarea_code($item, $jsname, $spawnMulti = false) { - static $init = false; - global $serendipity; - - if ($init && $spawnMulti) { - return true; - } - - if (isset($serendipity['wysiwyg']) && $serendipity['wysiwyg']) { - - $eventData = array( - 'init' => &$init, - 'item' => &$item, - 'jsname' => &$jsname, - 'skip' => false - ); - serendipity_plugin_api::hook_event('backend_wysiwyg', $eventData); - - if ($eventData['skip']) { - return true; - } - - if (!$init) { -?> - - - - - - - -' . $n; + $cat_list .= ' ' . $n; + $selected = array(); + if (is_array($entry['categories'])) { + if (count($entry['categories']) > 1) { + $categoryselector_expanded = true; + } + + foreach ($entry['categories'] as $cat) { + $selected[] = $cat['categoryid']; + } + } + + if (count($selected) > 1 || + (isset($serendipity['POST']['categories']) && is_array($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1)) { + $categoryselector_expanded = true; + } + + if (is_array($cats = serendipity_fetchCategories())) { + $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); + foreach ( $cats as $cat ) { + $cat_list .= '' . "\n"; + } + } + $cat_list .= '' . $n; + + if (!empty($serendipity['GET']['title'])) { + $entry['title'] = utf8_decode(urldecode($serendipity['GET']['title'])); + } + + if (!empty($serendipity['GET']['body'])) { + $entry['body'] = utf8_decode(urldecode($serendipity['GET']['body'])); + } + + if (!empty($serendipity['GET']['url'])) { + $entry['body'] .= "\n" . '
' . $entry['title'] . ''; + } + + $hidden = ''; + foreach($hiddens as $key => $value) { + $hidden .= ' ' . $n; + } + $hidden .= ' ' . $n; + $hidden .= ' ' . $n; + $hidden .= ' '; + + if (!empty($errMsg)) { +?> +
+ +
="serendipityEntry" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ : + + + + + + +
+ +
+
+ : + + + + <?php echo RESET_DATE ?> + + + + + : + +
+ + + + + + + + +
+ +
+ + + + + +
+ />
+ /> +
+
+ +
+
+
+ + +/- + + + + +
+ + + + +
+
+
+ + +
+
+
+ + + + 'serendipity[body]', + 'extended' => 'serendipity[extended]' + ); + + foreach($fields AS $f_jsname => $f_item) { + serendipity_emit_htmlarea_code($f_item, $f_jsname); + } + serendipity_plugin_api::hook_event('backend_wysiwyg_finish', $fields); + } + + echo ' '; + echo ' '; +} + +function serendipity_emit_htmlarea_code($item, $jsname, $spawnMulti = false) { + static $init = false; + global $serendipity; + + if ($init && $spawnMulti) { + return true; + } + + if (isset($serendipity['wysiwyg']) && $serendipity['wysiwyg']) { + + $eventData = array( + 'init' => &$init, + 'item' => &$item, + 'jsname' => &$jsname, + 'skip' => false + ); + serendipity_plugin_api::hook_event('backend_wysiwyg', $eventData); + + if ($eventData['skip']) { + return true; + } + + if (!$init) { +?> + + + + + + + + $entry['timestamp'])); + if ($comments == true) { + // Display username as part of the title for easier feed-readability + $entry['title'] = $entry['author'] . ': ' . $entry['title']; + } + + // Embed a link to extended entry, if existing + if ($fullFeed) { + $entry['body'] .= ' ' . $entry['extended']; + } elseif ($entry['exflag']) { + $ext = '
' . sprintf(VIEW_EXTENDED_ENTRY, htmlspecialchars($entry['title'])) . ''; + } else { + $ext = ''; + } + + serendipity_plugin_api::hook_event('frontend_display', $entry); + // Do some relative -> absolute URI replacing magic. Replaces all HREF/SRC (, , ...) references to only the serendipitypath with the full baseURL URI + // garvin: Could impose some problems. Closely watch this one. + $entry['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\1=\2' . $serendipity['baseURL'] . '\4\2\6>', $entry['body']); + // jbalcorn: clean up body for XML compliance as best we can. + $entry['body'] = xhtml_cleanup($entry['body']); + + // extract author information + if ((isset($entry['no_email']) && $entry['no_email']) || !$showMail) { + $entry['email'] = 'nospam@example.com'; // RSS Feeds need an E-Mail address! + } elseif (empty($entry['email'])) { + $query = "select email FROM {$serendipity['dbPrefix']}authors WHERE authorid = '". serendipity_db_escape_string($entry['authorid']) ."'"; + $results = serendipity_db_query($query); + $entry['email'] = $results[0]['email']; + } + + if (!is_array($entry['categories'])) { + $entry['categories'] = array(0 => array('category_name' => $entry['category_name'])); + } + + if ($version == 'atom0.3') { + /*********** ATOM 0.3 FEED *************/ +?> + + + + + + + + + + + wfwcomment.php?cid= + + + + rss.php?version=&type=comments&cid= + + + + <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> + +
+ +
+
+ +
+ + + + + + + + + + + wfwcomment.php?cid= + + + + rss.php?version=&type=comments&cid= + $cat) { + $name = serendipity_utf8_encode(htmlspecialchars($cat['category_name'])); ?> + + + + <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> + +
+ +
+
+ +
+ + + <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> + + $cat) { + ?> + #comments + wfwcomment.php?cid= + + + rss.php?version=&type=comments&cid= + + + + + + + + + + + + + + + $cat) { + $categories[] = $cat['category_name']; + } + +?> + + <?php echo serendipity_utf8_encode(htmlspecialchars($entry['title'])); ?> + + + + + + + + + + wfwcomment.php?cid= + + + rss.php?version=&type=comments&cid= + + + + +assign('trackbacks', $trackbacks); + + return serendipity_smarty_fetch('TRACKBACKS', 'trackbacks.tpl'); +} + function &serendipity_smarty_fetch($block, $file, $echo = false) { global $serendipity; @@ -269,3 +298,4 @@ global $serendipity; } $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath')); } + diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index 3c4a153..e17f20e 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -2,35 +2,6 @@ # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) # All rights reserved. See LICENSE file for licensing details -function serendipity_fetchTrackbacks($id, $limit = null, $showAll = false) { - global $serendipity; - - if (!$showAll) { - $and = "AND status = 'approved'"; - } - - $query = "SELECT * FROM {$serendipity['dbPrefix']}comments WHERE entry_id = '". (int)$id ."' AND type = 'TRACKBACK' $and ORDER BY id"; - if (isset($limit)) { - $limit = serendipity_db_limit_sql($limit); - $query .= " $limit"; - } - - $comments = serendipity_db_query($query); - if (!is_array($comments)) { - return array(); - } - - return $comments; -} - -function serendipity_printTrackbacks($trackbacks) { - global $serendipity; - - $serendipity['smarty']->assign('trackbacks', $trackbacks); - - return serendipity_smarty_fetch('TRACKBACKS', 'trackbacks.tpl'); -} - /** * validate trackback response */ diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index 34f6a16..323324b 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -700,7 +700,7 @@ class serendipity_plugin_api { } return false; } - + return $event_plugins; } diff --git a/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php b/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php index af245c9..21df266 100644 --- a/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php +++ b/plugins/serendipity_event_bbcode/serendipity_event_bbcode.php @@ -56,69 +56,6 @@ class serendipity_event_bbcode extends serendipity_event $conf_array[] = $element['name']; } $propbag->add('configuration', $conf_array); - - // Only allow numbers and characters for CSS: "red", "#FF0000", ... - $pattern_css = '([ 0-9a-z#-]+?)'; - - // Only allow strings occuring in emails: .-_@, 0-9, a-z - $pattern_mail = '([\.\-\+~@_0-9a-z]+?)'; - - // Only allow strings occuring in URLs: &;?:.-_@/, 0-9, a-z - $pattern_url = '([@!=~\?:&;0-9a-z#\.\-_\/]+?)'; - - // Disallow possibly evil HTML characters which may lead to Javascript XSS: '"(); - $pattern_query = '([^"\'\(\);]+?)'; - - // Note: - // * Anything between ... tags will be caught by htmlspecialchars() and disallows custom HTML tags. - // * (?::\w+)? means "non capturing" match on any word character. - // * (?bbcodes = array( - '/(? "\\2", - '/(? "\\2", - '/(? "\\2", - '/(? "
\\2
", - - '/(? "\\1", - '/(? "\\1", - '/(? "\\1", - '/(? "
\\1
", - - // [email] - '/(? "
\\1", - '/(? "\\2", - - // [url] - '/(? "\\2", - '/(? "\\1", - '/(? "\\1", - '/(? "\\2", - - // [img] - '/(? "\"\\1\"", - '/(? "\"\\3\"", - - // [quote] - '/(? "
QUOTE:
\\1
", - '/(? "
QUOTE \\1:
\\2
", - - // [list] - '/(?\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*\s*)?\[\*|(?:\s*\s*)?\[\/?list)/si' => "\n
  • \\1
  • ", - '/(?\s*)?\[\/list(:(?!u|o)\w+)?\](?:)?/si' => "\n", - '/(?\s*)?\[\/list:u(:\w+)?\](?:)?/si' => "\n", - '/(?\s*)?\[\/list:o(:\w+)?\](?:)?/si' => "\n", - '/(?\s*)?\[list(:(?!u|o)\w+)?\]\s*(?:)?/si' => "\n
      ", - '/(?\s*)?\[list:u(:\w+)?\]\s*(?:)?/si' => "\n
        ", - '/(?\s*)?\[list:o(:\w+)?\]\s*(?:)?/si' => "\n
          ", - '/(?\s*)?\[list(?::o)?(:\w+)?=1\]\s*(?:)?/si' => "\n
            ", - '/(?\s*)?\[list(?::o)?(:\w+)?=i\]\s*(?:)?/s' => "\n
              ", - '/(?\s*)?\[list(?::o)?(:\w+)?=I\]\s*(?:)?/s' => "\n
                ", - '/(?\s*)?\[list(?::o)?(:\w+)?=a\]\s*(?:)?/s' => "\n
                  ", - '/(?\s*)?\[list(?::o)?(:\w+)?=A\]\s*(?:)?/s' => "\n
                    ", - - // escaped tags like \[b], \[color], \[url], ... - '/\\\\(\[\/?\w+(?::\w+)*\])/' => "\\1" - ); } @@ -205,8 +142,76 @@ class serendipity_event_bbcode extends serendipity_event } function bbcode($input) { + static $bbcodes = null; + + // Only allow numbers and characters for CSS: "red", "#FF0000", ... + static $pattern_css = '([ 0-9a-z#-]+?)'; + + // Only allow strings occuring in emails: .-_@, 0-9, a-z + static $pattern_mail = '([\.\-\+~@_0-9a-z]+?)'; + + // Only allow strings occuring in URLs: &;?:.-_@/, 0-9, a-z + static $pattern_url = '([@!=~\?:&;0-9a-z#\.\-_\/]+?)'; + + // Disallow possibly evil HTML characters which may lead to Javascript XSS: '"(); + static $pattern_query = '([^"\'\(\);]+?)'; + + // Note: + // * Anything between ... tags will be caught by htmlspecialchars() and disallows custom HTML tags. + // * (?::\w+)? means "non capturing" match on any word character. + // * (? "\\2", + '/(? "\\2", + '/(? "\\2", + '/(? "
                    \\2
                    ", + + '/(? "\\1", + '/(? "\\1", + '/(? "\\1", + '/(? "
                    \\1
                    ", + + // [email] + '/(? "\\1", + '/(? "\\2", + + // [url] + '/(? "\\2", + '/(? "\\1", + '/(? "\\1", + '/(? "\\2", + + // [img] + '/(? "\"\\1\"", + '/(? "\"\\3\"", + + // [quote] + '/(? "
                    QUOTE:
                    \\1
                    ", + '/(? "
                    QUOTE \\1:
                    \\2
                    ", + + // [list] + '/(?\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*\s*)?\[\*|(?:\s*\s*)?\[\/?list)/si' => "\n
                  1. \\1
                  2. ", + '/(?\s*)?\[\/list(:(?!u|o)\w+)?\](?:)?/si' => "\n
      ", + '/(?\s*)?\[\/list:u(:\w+)?\](?:)?/si' => "\n
    ", + '/(?\s*)?\[\/list:o(:\w+)?\](?:)?/si' => "\n", + '/(?\s*)?\[list(:(?!u|o)\w+)?\]\s*(?:)?/si' => "\n
      ", + '/(?\s*)?\[list:u(:\w+)?\]\s*(?:)?/si' => "\n
        ", + '/(?\s*)?\[list:o(:\w+)?\]\s*(?:)?/si' => "\n
          ", + '/(?\s*)?\[list(?::o)?(:\w+)?=1\]\s*(?:)?/si' => "\n
            ", + '/(?\s*)?\[list(?::o)?(:\w+)?=i\]\s*(?:)?/s' => "\n
              ", + '/(?\s*)?\[list(?::o)?(:\w+)?=I\]\s*(?:)?/s' => "\n
                ", + '/(?\s*)?\[list(?::o)?(:\w+)?=a\]\s*(?:)?/s' => "\n
                  ", + '/(?\s*)?\[list(?::o)?(:\w+)?=A\]\s*(?:)?/s' => "\n
                    ", + + // escaped tags like \[b], \[color], \[url], ... + '/\\\\(\[\/?\w+(?::\w+)*\])/' => "\\1" + ); + } + /* Regular expressions taken from http://smarty.incutio.com/?page=BBCodePlugin Wiki (Andre Rabold) */ - $input = preg_replace(array_keys($this->bbcodes), array_values($this->bbcodes), $input); + $input = preg_replace(array_keys($bbcodes), array_values($bbcodes), $input); // [code] & [php] $input = preg_replace_callback('/(?add('description', PLUGIN_EVENT_SPARTACUS_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '2.02'); + $propbag->add('version', '2.1'); $propbag->add('requirements', array( 'serendipity' => '0.9', 'smarty' => '2.6.7', @@ -176,6 +176,7 @@ class serendipity_event_spartacus extends serendipity_event case 'close': return $children; } + unset($vals[$i]); } } @@ -316,7 +317,6 @@ class serendipity_event_spartacus extends serendipity_event $target = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . '/package_' . $url_type . $lang . '.xml'; $xml = $this->fetchfile($url, $target, $cacheTimeout, true); - echo '

                    '; $new_crc = md5($xml); @@ -327,20 +327,41 @@ class serendipity_event_spartacus extends serendipity_event } // XML functions - $p = xml_parser_create(); - xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); - xml_parse_into_struct($p, $xml, $vals, $index); - xml_parser_free($p); - + $xml_string = ''; + if (preg_match('@(<\?xml.+\?>)@imsU', $xml, $xml_head)) { + $xml_string = $xml_head[1]; + } + + preg_match_all('@(.*)@imsU', $xml, $xml_matches); + if (!is_array($xml_matches)) { + return 'cached'; + } + $i = 0; $tree = array(); - $tree[] = array( - 'tag' => $vals[$i]['tag'], - 'attributes' => $vals[$i]['attributes'], - 'value' => $vals[$i]['value'], - 'children' => $this->GetChildren($vals, $i) + $tree[$i] = array( + 'tag' => 'packages', + 'attributes' => '', + 'value' => '', + 'children' => array() ); - + + foreach($xml_matches[0] as $xml_index => $xml_package) { + $i = 0; + $p = xml_parser_create(); + xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); + $xml_package = $xml_string . "\n" . $xml_package; + xml_parse_into_struct($p, $xml_package, $vals); + xml_parser_free($p); + $tree[0]['children'][] = array( + 'tag' => $vals[$i]['tag'], + 'attributes' => $vals[$i]['attributes'], + 'value' => $vals[$i]['value'], + 'children' => $this->GetChildren($vals, $i) + ); + unset($vals); + } + $this->set_config('last_crc_' . $url_type, $new_crc); return $tree; @@ -702,4 +723,3 @@ class serendipity_event_spartacus extends serendipity_event } /* vim: set sts=4 ts=4 expandtab : */ -?> \ No newline at end of file diff --git a/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php b/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php index eca9b13..8ae94aa 100644 --- a/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php +++ b/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php @@ -149,6 +149,8 @@ class serendipity_event_weblogping extends serendipity_event break; case 'backend_publish': + include_once(S9Y_PEAR_PATH . "XML/RPC.php"); + // First cycle through list of services to remove superseding services which may have been checked foreach ($this->services as $index => $service) { if (!empty($service['supersedes']) && isset($serendipity['POST']['announce_entries_' . $service['name']])) { diff --git a/rss.php b/rss.php index 0a685c5..26af7dd 100644 --- a/rss.php +++ b/rss.php @@ -5,6 +5,8 @@ header('Content-Type: text/xml; charset=utf-8'); session_cache_limiter('public'); include_once('serendipity_config.inc.php'); +include_once(S9Y_INCLUDE_PATH . 'functions_rss.inc.php'); + $version = $_GET['version']; $description = $serendipity['blogDescription']; $title = $serendipity['blogTitle']; diff --git a/serendipity_admin.php b/serendipity_admin.php index 3ccbbe2..8642568 100644 --- a/serendipity_admin.php +++ b/serendipity_admin.php @@ -6,6 +6,7 @@ define('IN_installer', true); define('IN_upgrader', true); define('IN_serendipity', true); include('serendipity_config.inc.php'); + header('Content-Type: text/html; charset=' . LANG_CHARSET); if (IS_installed === false) { diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php index 6a91962..34b04bd 100644 --- a/serendipity_config.inc.php +++ b/serendipity_config.inc.php @@ -290,4 +290,3 @@ if (isset($_SESSION['serendipityEmail'])) { serendipity_plugin_api::hook_event('frontend_configure', $serendipity); /* vim: set sts=4 ts=4 expandtab : */ -?> -- 2.39.5