/** * Gets the selected language from personal configuration if needed * * This function also sets HTTP Headers and cookies to contain the language for follow-up requests * * @access public * @return string Returns the name of the selected language. */ function serendipity_getPostAuthSessionLanguage() { global $serendipity; if (!is_null($serendipity['detected_lang'])) { return $serendipity['detected_lang']; } if ($_SESSION['serendipityAuthedUser']) { if ($serendipity['expose_s9y']) { serendipity_header('X-Serendipity-InterfaceLangSource: Database'); } $lang = $serendipity['lang']; } else { $lang = isset($_SESSION['serendipityLanguage']) ? $_SESSION['serendipityLanguage'] : $serendipity['lang']; } if (!isset($serendipity['languages'][$lang])) { $lang = $serendipity['lang']; } $_SESSION['serendipityLanguage'] = $lang; if ($serendipity['expose_s9y']) { serendipity_header('X-Serendipity-InterfaceLang: ' . $lang); } if ($lang != $serendipity['lang']) { $serendipity['content_lang'] = $lang; } return $lang; }
function show() { global $serendipity; if ($this->selected()) { if ($this->error_404 === FALSE) { serendipity_header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK'); serendipity_header('Status: 200 OK'); } else { serendipity_header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); serendipity_header('Status: 404 Not Found'); } echo $this->parseStaticPage(); } }
$serendipity['smarty']->assignByRef('rightSidebarElements', $rightSidebarElements); switch ($serendipity['GET']['action']) { // User wants to read the diary case 'read': if (isset($serendipity['GET']['id'])) { $entry = array(serendipity_fetchEntry('id', $serendipity['GET']['id'])); if (!is_array($entry) || count($entry) < 1 || !is_array($entry[0])) { unset($serendipity['GET']['id']); $entry = array(array()); $serendipity['head_title'] = serendipity_specialchars($serendipity['blogTitle']); $serendipity['head_subtitle'] = ''; $serendipity['smarty']->assign('head_title', $serendipity['head_title']); $serendipity['smarty']->assign('head_subtitle', $serendipity['head_subtitle']); $serendipity['view'] = '404'; serendipity_header('HTTP/1.0 404 Not found'); serendipity_header('Status: 404 Not found'); } serendipity_printEntries($entry, 1); } else { serendipity_printEntries(serendipity_fetchEntries($serendipity['range'], true, $serendipity['fetchLimit'])); } break; // User searches // User searches case 'search': $r = serendipity_searchEntries($serendipity['GET']['searchTerm']); if (strlen($serendipity['GET']['searchTerm']) <= 3) { $serendipity['smarty']->assign(array('content_message' => SEARCH_TOO_SHORT, 'searchresult_tooShort' => true)); break; } if (is_string($r) && $r !== true) {
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = array(); if (is_object($bag)) { $hooks =& $bag->get('event_hooks'); } elseif (is_array($eventData) && $eventData['shortcircuit']) { $hooks[$event] = true; } if (isset($hooks[$event])) { $this->debugMsg(''); $this->debugMsg($_SERVER['REQUEST_URI']); @(include_once 'Cache/Lite.php'); if (!class_exists('Cache_Lite')) { $this->debugMsg('Cache_Lite not available.'); return false; } $options = array('cacheDir' => $serendipity['serendipityPath'] . 'templates_c/', 'lifeTime' => 3600, 'hashedDirectoryLevel' => 2); $this->cache = new Cache_Lite($options); switch ($event) { case 'frontend_comment': if (isset($serendipity['GET']['adminModule']) && $serendipity['GET']['adminModule'] == 'comments') { return true; } ?> <script type="text/javascript"> // <![CDATA[ function getCommentCookie(name) { var dc = document.cookie; var prefix = 'serendipity[' + name + "]="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return ''; } else { begin += 2; } var end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; } value = unescape(dc.substring(begin + prefix.length, end)); if (value && value != null) { return value; } else { return ''; } } document.getElementById('serendipity_commentform_name').value = getCommentCookie('name'); document.getElementById('serendipity_commentform_email').value = getCommentCookie('email'); document.getElementById('serendipity_commentform_url').value = getCommentCookie('url'); <?php $post_import = array('name', 'email', 'url'); foreach ($post_import as $importvar) { if (!empty($serendipity['POST'][$importvar])) { echo "document.getElementById('serendipity_commentform_{$importvar}').value = '" . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST'][$importvar]) : htmlspecialchars($serendipity['POST'][$importvar], ENT_COMPAT, LANG_CHARSET)) . "';\n"; } } ?> // ]]> </script> <?php break; case 'frontend_configure': if (!$this->cacheAllowed()) { return true; } case 'frontend_shortcircuit': $cache_options = $serendipity['GET']; // This tries to keep individual sites with pre-filled form elements, // but also swamps your cache directory with individual cache files. $cache_options['COOKIE'] = $serendipity['COOKIE']; $cache_options['base'] = $serendipity['baseURL']; unset($cache_options['COOKIE']['author_information']); unset($cache_options['COOKIE']['karmaVote']); unset($cache_options['COOKIE']['name']); unset($cache_options['COOKIE']['url']); unset($cache_options['COOKIE']['email']); if (serendipity_db_bool($this->get_config('browser'))) { if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !stristr($_SERVER['HTTP_USER_AGENT'], 'Opera') && !stristr($_SERVER['HTTP_USER_AGENT'], 'Mac_PowerPC') && !stristr($_SERVER['HTTP_ACCEPT'], 'text/html')) { $cache_options['browser'] = 'ie'; } else { $cache_options['browser'] = 'other'; } } $this->cache_key = 'serendipity_cachesimple_' . preg_replace('@[^0-9a-z\\-_]@', '_', $_SERVER['REQUEST_URI']) . crc32(serialize($cache_options)); $this->debugMsg($this->cache_key . ' cache prepared'); $this->cache->_setFileName($this->cache_key, $this->cache_group); if (serendipity_db_bool($this->get_config('keep_fresh', false))) { serendipity_header('Pragma:'); serendipity_header('Cache-Control: max-age=3'); } else { serendipity_header('Pragma:'); serendipity_header('Cache-Control: max-age=3600, must-revalidate'); serendipity_header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $options['lifeTime'])); } if (function_exists('microtime_float')) { $time_end = microtime_float(); serendipity_header('X-Serendipity-ParseTime: ' . round($time_end - $GLOBALS['time_start'], 6)); } // HTTP Conditional Request. May exit with 304. if ($this->cacheHeaders(@filemtime($this->cache->_file))) { exit; } if ($content = $this->cache->get($this->cache_key, $this->cache_group)) { serendipity_header('X-Serendipity-Cache: true'); // No valid HTTP Conditional Request. Emit output. echo $content; $this->debugMsg('CACHE HIT'); exit; } else { serendipity_header('X-Serendipity-Cache: false'); $this->debugMsg('CACHE MISS'); } $serendipity['useGzip'] = false; // This is a bit wicked. Index.php already starts a ob, thus // we end it here, output the data so far, start another handler // and forward the data to it. Then we can throw our own handler // later on. // Get previous ob data of the outmost OB and erase it afterwards $prev_data = ob_get_contents(); ob_end_clean(); // Create our new outmost OB and set a callback method. ob_start(array(&$this, 'storeCache')); // Create a faked inner OB which will be the outmost OB to Serendipity ob_start(); // Echo previous data to the faked OB echo $prev_data; // "What comes around, goes around, you'll see." ;) register_shutdown_function(array(&$this, 'shutdown')); return true; break; case 'xmlrpc_updertEntry': case 'xmlrpc_deleteEntry': case 'backend_save': case 'backend_publish': $this->purgeCache(); return true; break; case 'frontend_saveComment': if (is_array($eventData) && serendipity_db_bool($eventData['allow_comments'])) { // Only purge comments if a comment could be made. Prevents purging and recreating cache when // unter spam/referrer attack. $this->purgeCache(); } return true; break; default: return false; } } else { return false; } }
function introspect(&$propbag) { global $serendipity; $propbag->add('name', PLUGIN_EVENT_MULTILINGUAL_TITLE); $propbag->add('description', PLUGIN_EVENT_MULTILINGUAL_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking, Wesley Hwang-Chung, Ian'); $propbag->add('requirements', array('serendipity' => '0.8', 'smarty' => '2.6.7', 'php' => '4.1.0')); $propbag->add('groups', array('FRONTEND_ENTRY_RELATED', 'BACKEND_EDITOR')); $propbag->add('version', '2.22'); $propbag->add('configuration', array('copytext', 'placement', 'tagged_title', 'tagged_entries', 'tagged_sidebar', 'langswitch')); $propbag->add('event_hooks', array('frontend_fetchentries' => true, 'frontend_fetchentry' => true, 'entry_display' => true, 'backend_publish' => true, 'backend_save' => true, 'backend_display' => true, 'frontend_entryproperties' => true, 'backend_sidebar_entries' => true, 'external_plugin' => true, 'css' => true, 'backend_entryform' => true, 'backend_entry_presave' => true, 'backend_entry_updertEntry' => true, 'frontend_display' => true, 'frontend_entries_rss' => true, 'frontend_comment' => true, 'frontend_sidebar_plugins' => true, 'genpage' => true)); $this->supported_properties = array('lang_selected', 'lang_display'); $this->dependencies = array('serendipity_plugin_multilingual' => 'remove'); // Okay, Garv. I explain this to you ONCE and ONLY. // $this->lang_display is the variable that FORCES translations of entries. If a translation does not exist, // an entry is NOT SHOWN. // $this->showlang is the variable that indicates which language of an entry to prefer. if (isset($serendipity['GET']['lang_display'])) { $this->lang_display = serendipity_db_escape_string($serendipity['GET']['lang_display']); header('X-Serendipity-ML-LD-1: ' . $this->cleanheader($this->lang_display)); } if (!defined('IN_serendipity_admin')) { $resetlang = false; // GET is either a forced session or a single entry lang and we normally do not use it with cookies set, since they have preference if (serendipity_db_bool($this->get_config('langswitch')) && (!isset($_POST['user_language']) || !isset($_COOKIE['serendipityLanguage']))) { // check for REQUESTs being sent (imagine the user in a DE blog links an EN entry version and force option is set TRUE) // $_REQUEST was somehow disabled and not available, but used here and in serendipity_getSessionLanguage() $_REQUEST['user_language'] = $serendipity['GET']['user_language']; // normal fallback if (!isset($serendipity['GET']['lang_selected']) && !isset($_REQUEST['user_language'])) { if (!empty($_SESSION['serendipityLanguage'])) { $this->showlang = $_SESSION['serendipityLanguage']; } } } elseif (!isset($_COOKIE['serendipityLanguage'])) { $resetlang = true; } // force == false and we only want the translated article, nothing else being touched multilingual } if (empty($this->showlang) && isset($serendipity['POST']['properties']['lang_selected'])) { $this->showlang = serendipity_db_escape_string($serendipity['POST']['properties']['lang_selected']); $_SESSION['last_lang'] = $this->showlang; serendipity_header('X-Serendipity-ML-SL-1: ' . $this->cleanheader($this->showlang)); } elseif (empty($this->showlang) && isset($serendipity['GET']['lang_selected'])) { $this->showlang = serendipity_db_escape_string($serendipity['GET']['lang_selected']); $_SESSION['last_lang'] = $this->showlang; serendipity_header('X-Serendipity-ML-SL-2: ' . $this->cleanheader($this->showlang)); } elseif (empty($this->showlang) && isset($_REQUEST['user_language'])) { $this->showlang = serendipity_db_escape_string($_REQUEST['user_language']); serendipity_header('X-Serendipity-ML-SL-3: ' . $this->cleanheader($this->showlang)); } elseif (empty($this->showlang) && isset($_REQUEST['serendipity']['serendipityLanguage'])) { $this->showlang = serendipity_db_escape_string($_REQUEST['serendipity']['serendipityLanguage']); serendipity_header('X-Serendipity-ML-SL-4: ' . $this->cleanheader($this->showlang)); } elseif (empty($this->showlang) && isset($serendipity['lang']) && !isset($_SESSION['last_lang'])) { $this->showlang = $serendipity['lang']; serendipity_header('X-Serendipity-ML-SL-5: ' . $this->cleanheader($this->showlang)); } if (!defined('IN_serendipity_admin')) { // case reset TRUE without POST cookies if ($resetlang && !isset($_COOKIE['serendipityLanguage'])) { $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_SESSION['last_lang'] = $serendipity['default_lang']; // reset strictly to default global language } // case force langswitch to default, normally without POST cookies set, since they have preference if (serendipity_db_bool($this->get_config('langswitch')) && (!isset($_POST['user_language']) || !isset($_COOKIE['serendipityLanguage']))) { // a user has already set a forced language and now wants to return to the default language - doing such here after all, avoids a doubleclick need.. if ($this->showlang == 'default' || $_SESSION['last_lang'] == 'default') { $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_REQUEST['user_language'] = $serendipity['default_lang']; if ($_SESSION['last_lang'] == 'default') { $_SESSION['last_lang'] = $serendipity['default_lang']; } } // the entry is shown in default language as a fallback, when another language is chosen that has no entryproperties translation } // case repair cookie array if (isset($_COOKIE['serendipity']['serendipityLanguage'])) { $_COOKIE['serendipityLanguage'] = $_COOKIE['serendipity']['serendipityLanguage']; unset($_COOKIE['serendipity']); } // case POST set cookies mean, always check cookies to set current lang! if (isset($_COOKIE['serendipityLanguage'])) { // reset all langs strictly to default global hold COOKIE language $serendipity['lang'] = $this->showlang = $_SESSION['serendipityLanguage'] = $_SESSION['last_lang'] = $serendipity['default_lang'] = $_COOKIE['serendipity']['serendipityLanguage'] = $_COOKIE['serendipityLanguage']; $this->lang_display = ''; // need this to always get the correct set lang and be the default in case of fallback and default } // case unforced language entry lang links if (isset($serendipity['GET']['lang_selected']) && !isset($serendipity['GET']['user_language'])) { $this->lang_display = $this->showlang = $serendipity['GET']['lang_selected']; } if ($serendipity['GET']['lang_selected'] == 'default' && !isset($serendipity['GET']['user_language'])) { $this->lang_display = ''; // sets entry lang to default } } if (!isset($serendipity['languages'][$this->showlang])) { $this->showlang = ''; serendipity_header('X-Serendipity-ML-SL-RESET: ' . $this->cleanheader($serendipity['default_lang'])); } if (!headers_sent()) { serendipity_header('X-Serendipity-ContentLang: ' . $this->cleanheader($this->showlang)); } $this->setupDB(); }