From c04e66894cc5c70746a50880e6db74becd6e5076 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Wed, 2 Aug 2006 09:27:27 +0000 Subject: [PATCH] use chunk_split for larger messages --- include/functions.inc.php | 180 +++++++++++++++++++++++++++++++++----- 1 file changed, 159 insertions(+), 21 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index 282ccf5..772ae7b 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -2,18 +2,42 @@ # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) # All rights reserved. See LICENSE file for licensing details -$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_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_smarty.inc.php"); +if (defined('S9Y_FRAMEWORK_FUNCTIONS')) { + return; +} +@define('S9Y_FRAMEWORK_FUNCTIONS', true); +$serendipity['imageList'] = array(); +if (!defined('S9Y_FRAMEWORK_DB')) { + include(S9Y_INCLUDE_PATH . "include/db/db.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_COMPAT')) { + include(S9Y_INCLUDE_PATH . "include/compat.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_CONFIG')) { + include(S9Y_INCLUDE_PATH . "include/functions_config.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_PLUGIN_API')) { + include(S9Y_INCLUDE_PATH . "include/plugin_api.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_IMAGES')) { + include(S9Y_INCLUDE_PATH . "include/functions_images.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_INSTALLER')) { + include(S9Y_INCLUDE_PATH . "include/functions_installer.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_ENTRIES')) { + include(S9Y_INCLUDE_PATH . "include/functions_entries.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_COMMENTS')) { + include(S9Y_INCLUDE_PATH . "include/functions_comments.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_PERMALINKS')) { + include(S9Y_INCLUDE_PATH . "include/functions_permalinks.inc.php"); +} +if (!defined('S9Y_FRAMEWORK_SMARTY')) { + include(S9Y_INCLUDE_PATH . "include/functions_smarty.inc.php"); +} /** * Truncate a string to a specific length, multibyte aware. Appends '...' if successfully truncated * @@ -63,6 +87,38 @@ function serendipity_serverOffsetHour($timestamp = null, $negative = false) { } } +/* Converts a date string (DD.MM.YYYY, YYYY-MM-DD, MM/DD/YYYY) into a unix timestamp + * + * @access public + * @param string The input date + * @return int The output unix timestamp + */ +function &serendipity_convertToTimestamp($in) { + if (preg_match('@([0-9]+)([/\.-])([0-9]+)([/\.-])([0-9]+)@', $in, $m)) { + if ($m[2] != $m[4]) { + return $in; + } + + switch($m[2]) { + case '.': + return mktime(0, 0, 0, /* month */ $m[3], /* day */ $m[1], /* year */ $m[5]); + break; + + case '/': + return mktime(0, 0, 0, /* month */ $m[1], /* day */ $m[3], /* year */ $m[5]); + break; + + case '-': + return mktime(0, 0, 0, /* month */ $m[3], /* day */ $m[5], /* year */ $m[1]); + break; + } + + return $in; + } + + return $in; +} + /** * Format a timestamp * @@ -94,7 +150,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { $out = strftime($format, $timestamp); break; - case 'jalali-utf8': + case 'persian-utf8': if ($timestamp == null) { $timestamp = serendipity_serverOffsetHour(); } elseif ($useOffset) { @@ -102,7 +158,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { } require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; - $out = jalali_strftime_utf($format, $timestamp); + $out = persian_strftime_utf($format, $timestamp); break; } @@ -112,6 +168,7 @@ function serendipity_strftime($format, $timestamp = null, $useOffset = true) { return $out; } + /** * A wrapper function call for formatting Timestamps. * @@ -446,7 +503,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL $maildata['message'] = str_replace("=\r\n", "", imap_8bit($maildata['message'])); } else { $maildata['headers'][] = 'Content-Transfer-Encoding: base64'; - $maildata['message'] = base64_encode($maildata['message']); + $maildata['message'] = chunk_split(base64_encode($maildata['message'])); } } } @@ -464,7 +521,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL function serendipity_fetchReferences($id) { global $serendipity; - $query = "SELECT name,link FROM {$serendipity['dbPrefix']}references WHERE entry_id = '" . (int)$id . "'"; + $query = "SELECT name,link FROM {$serendipity['dbPrefix']}references WHERE entry_id = '" . (int)$id . "' AND type = ''"; return serendipity_db_query($query); } @@ -855,11 +912,7 @@ function serendipity_xhtml_target($target) { if ($serendipity['enablePopup'] != true) return ""; - if ($serendipity['XHTML11']) { - return ' onclick="window.open(this.href, \'target' . time() . '\'); return false;" '; - } else { - return ' target="' . $target . '" '; - } + return ' onclick="window.open(this.href, \'target' . time() . '\'); return false;" '; } /** @@ -874,8 +927,12 @@ function serendipity_discover_rss($name, $ext) { static $default = '2.0'; /* Detect type */ - if ( $name == 'comments' ) { + if ($name == 'comments') { $type = 'comments'; + } elseif ($name == 'comments_and_trackbacks') { + $type = 'comments_and_trackbacks'; + } elseif ($name == 'trackbacks') { + $type = 'trackbacks'; } else { $type = 'content'; } @@ -984,5 +1041,86 @@ function serendipity_updateCategory($cid, $name, $desc, $authorid, $icon, $paren } +/** + * Ends a session, so that while a file requests happens, Serendipity can work on in that session + */ +function serendipity_request_start() { + @session_write_close(); + return true; +} + +/** + * Continues a session after a file request + */ +function serendipity_request_end() { + @session_start(); + return true; +} + +if (!function_exists('microtime_float')) { + /** + * Get current timestamp as microseconds + * + * @access public + * @return float the time + */ + function microtime_float() { + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); + } +} + +/** + * Converts Array data to be used as a GET string + * + * @access public + * @param array The input array + * @param string An array prefix + * @param string How to join the array + * @return string The HTTP query string + */ +function serendipity_build_query(&$array, $array_prefix = null, $comb_char = '&') { + $ret = array(); + if (!is_array($array)) { + return ''; + } + + foreach ($array as $k => $v) { + $newkey = urlencode($k); + if ($array_prefix) { + $newkey = $array_prefix . '[' . $newkey . ']'; + } + if (is_array($v)) { + $ret[] = serendipity_build_query($v, $newkey, $comb_char); + } else { + $ret[] = $newkey . '=' . urlencode($v); + } + } + + return implode($comb_char, $ret); +} + +/* Picks a specified key from an array and returns it + * + * @access public + * @param array The input array + * @param string The key to search for + * @param string The default value to return when not found + * @return null + */ +function &serendipity_pickKey(&$array, $key, $default) { + if (!is_array($array)) { + return $default; + } + + foreach($array AS $child) { + if (is_array($child) && isset($child[$key]) && !empty($child[$key])) { + return $child[$key]; + } + } + + return $default; +} + define("serendipity_FUNCTIONS_LOADED", true); /* vim: set sts=4 ts=4 expandtab : */ -- 2.39.5