From 65ee9f84f8068b99c9d14d14f3bd1440857a6877 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Wed, 1 Feb 2006 13:24:20 +0000 Subject: [PATCH] * Trackback transcoding * Spartacus debugging reloaded * Categories plugin HTML fixes * Document changes --- docs/NEWS | 9 +++ include/functions_trackbacks.inc.php | 69 +++++++++++++++++-- include/plugin_internal.inc.php | 18 +++-- .../serendipity_event_spartacus.php | 2 +- 4 files changed, 85 insertions(+), 13 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index a39de9b..aeb70e9 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,15 @@ Version 1.0-beta2 () ------------------------------------------------------------------------ + * Made categories plugin default HTML output more XHTML compliant. + (garvinhicking) + + * Added option "stronger captchas" in spamblock plugin. + + * Transcode incoming trackbacks from the given charset to your blog's + charset. Reliably only works with the two most common formats, + ISO-8859-1 <-> UTF-8. (garvinhicking) + * Change karma plugin and search results to output more HTML span classes for better styling (garvinhicking) diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index 9613827..8f2d4de 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -229,19 +229,55 @@ function add_trackback ($id, $title, $url, $name, $excerpt) { // We can't accept a trackback if we don't get any URL // This is a protocol rule. - if ( empty($url) ) { + if (empty($url)) { return 0; } // If title is not provided, the value for url will be set as the title // This is a protocol rule. - if ( empty($title) ) { + if (empty($title)) { $title = $url; } - $comment['title'] = $title; - $comment['url'] = $url; - $comment['name'] = $name; - $comment['comment'] = $excerpt; + + $comment = array( + 'title' => $title, + 'url' => $url, + 'name' => $name, + 'comment' => $excerpt + ); + + $is_utf8 = strtolower(LANG_CHARSET) == 'utf-8'; + + if ($GLOBALS['tb_logging']) { + $fp = fopen('trackback2.log', 'a'); + fwrite($fp, '[' . date('d.m.Y H:i') . '] TRACKBACK TRANSCODING CHECK' . "\n"); + } + + foreach($comment AS $idx => $field) { + if (is_utf8($field)) { + // Trackback is in UTF-8. Check if our blog also is UTF-8. + if (!$is_utf8) { + if ($GLOBALS['tb_logging']) { + fwrite($fp, '[' . date('d.m.Y H:i') . '] Transcoding ' . $idx . ' from UTF-8 to ISO' . "\n"); + } + $comment[$idx] = utf8_decode($field); + } + } else { + // Trackback is in some native format. We assume ISO-8859-1. Check if our blog is also ISO. + if ($is_utf8) { + if ($GLOBALS['tb_logging']) { + fwrite($fp, '[' . date('d.m.Y H:i') . '] Transcoding ' . $idx . ' from ISO to UTF-8' . "\n"); + } + $comment[$idx] = utf8_encode($field); + } + } + } + + if ($GLOBALS['tb_logging']) { + fwrite($fp, '[' . date('d.m.Y H:i') . '] TRACKBACK DATA: ' . print_r($comment, true) . '...' . "\n"); + fwrite($fp, '[' . date('d.m.Y H:i') . '] TRACKBACK STORING...' . "\n"); + fclose($fp); + } serendipity_saveComment($id, $comment, 'TRACKBACK'); @@ -434,3 +470,24 @@ function serendipity_handle_references($id, $author, $title, $text) { serendipity_db_query($query); } } + +/** + * Check if a string is in UTF-8 format. + * + * @access public + * @param string The string to check + * @return bool + */ +function is_utf8($string) { + // From http://w3.org/International/questions/qa-forms-utf-8.html + return preg_match('%^(?:' + . '[\x09\x0A\x0D\x20-\x7E]' # ASCII + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 + . ')*$%xs', $string); +} \ No newline at end of file diff --git a/include/plugin_internal.inc.php b/include/plugin_internal.inc.php index 66f861e..ed4a41a 100644 --- a/include/plugin_internal.inc.php +++ b/include/plugin_internal.inc.php @@ -1402,7 +1402,9 @@ class serendipity_categories_plugin extends serendipity_plugin { $html = ''; if (!$smarty && $is_form) { - $html .= '
'; + $html .= ' +
+
    '; } $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); @@ -1464,28 +1466,32 @@ class serendipity_categories_plugin extends serendipity_plugin { } if (!$smarty) { - $html .= '
    '; + $html .= '
  • '; if ($is_form) { $html .= ''; } if ( !empty($image) ) { - $html .= 'XML '; + $html .= 'XML '; } $html .= ''. htmlspecialchars($categories[$cid]['category_name']) .''; - $html .= '
  • ' . "\n"; + $html .= '' . "\n"; } } } + if (!$smarty) { + $html .= '
'; + } + if (!$smarty && $is_form) { - $html .= '

'; + $html .= '

'; } if (!$smarty) { $html .= sprintf( - '
%s', + '', $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'], ALL_CATEGORIES, diff --git a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php index fb09304..f077f01 100644 --- a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php +++ b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php @@ -570,7 +570,7 @@ class serendipity_event_spartacus extends serendipity_event function checkArray(&$tree) { if (!is_array($tree) || !is_array($tree[0]['children'])) { - echo "DEBUG: Tree not an array, but: " . print_r($tree, true) . ". Please report this bug. This might be an error with the downloaded XML file. You can try to go to the plugin configuration of the Spartacus Plugin and simply click on 'Save' - this will purge all cached XML files and try to download it again.
\n"; + echo "DEBUG: The XML file could not be successfully parsed. Download or caching error. Please try again later or switch your XML/File mirror location. You can also try to go to the plugin configuration of the Spartacus Plugin and simply click on 'Save' - this will purge all cached XML files and try to download it again.
" . print_r($tree, true) . "

\n"; } } -- 2.39.5