All pastes #426465 Raw Edit

JayBachatero

public php v1 · immutable
·published 2007-04-06 04:26 UTC
rendered paste body
function languageDrop(){	global $modSettings, $func, $context, $scripturl, $settings, $txt, $boarddir, $ID_MEMBER;	// Find something if its null	if (empty($languagecheck) && isset($_REQUEST['language']))		$languagecheck = $_REQUEST['language'];	// Valid Markup only..	if (isset($_POST['changelang']))		$_POST['changelang'] = (int) $_POST['changelang'];	// Jay didn't think of it already being set.. bad monkey... 	if (empty($context['languages']))	{		// Do this the old fashion way if cache is old or not set		if (($context['languages'] = cache_get_data('selectLanguage', 86400)) == null)		{			// Are languages user selectable?  If so, get a list. 			$context['languages'] = array();			$language_directories = array(				$settings['default_theme_dir'] . '/languages',				$settings['actual_theme_dir'] . '/languages',			);			if (!empty($settings['base_theme_dir']))				$language_directories[] = $settings['base_theme_dir'] . '/languages';			// Only one per person			$language_directories = array_unique($language_directories);			// For each we find stuff			foreach ($language_directories as $language_dir)			{				// Can't look in here... doesn't exist!				if (!file_exists($language_dir))					continue;				// No bugs..				if ($language_dir == '/languages')					continue;				$dir = dir($language_dir);				while ($entry = $dir->read())				{					// Look for the index language file....					if (preg_match('~^index\.(.+)\.php$~', $entry, $matches) == 0)						continue;					$context['languages'][] = array(						'name' => $func['ucwords'](strtr($matches[1], array('_' => ' ', '-utf8' => ''))),						'selected' => $selectedLanguage == $matches[1],						'filename' => $matches[1],					);				}				$dir->close();			}			if (!empty($modSettings['cache_enable']))				cache_put_data('selectLanguage', $context['languages'], 86400);		}	}	// Sort Them out.. [Thanks to mwmconsulting for the suggestion]	sort($context['languages']);	// hmm.. If this is true we are validating the language selection.. 	if (!empty($languagecheck) && !empty($_POST['changelang']))	{		// How ever this happens it does.		if(empty($context['languages']))			return false;		// Clean it up. it comes through with filename		foreach($context['languages'] as $temp)			$FindLanguage[] = $temp['filename'];		// Not a valid Language? Forget it... 		if(!in_array($languagecheck, $FindLanguage))			return false;		// Finally!!! Update this sucker.		if($languagecheck != false && !empty($ID_MEMBER))			updateMemberData($ID_MEMBER, array('lngfile' => '\'' . $languagecheck . '\''));	}	// No Reason to Show it if nothing exists.. 	if (!empty($context['languages']))	{		echo '			<form action="', $scripturl , !empty($_REQUEST['action']) ? '?action=' . $_REQUEST['action'] . (!empty($_REQUEST['sa']) ? ';sa=' . $_REQUEST['sa'] : '' ) : '', '" method="post" class="smalltext" style="float: right;">				<select id="language_select" name="language" onchange="this.form.submit()" class="smalltext">';		foreach($context['languages'] as $language)			echo '					<option value="', $language['filename'], '"', isset($context['user']['language']) && $context['user']['language'] == $language['filename'] ? ' selected="selected"' : '', '>', $language['name'], '</option>';		echo '				</select>				<input type="hidden" name="changelang" value="1" />&nbsp;				<noscript><input type="submit" value="', $txt['quick_mod_go'], '" /></noscript>			</form>';	}}