News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Change $context['page_title_html_safe']?

Started by samborabora, April 27, 2015, 09:06:00 AM

Previous topic - Next topic

samborabora

I'd like to simplify the title for the page to remove the forum name and the page number, where is $context['page_title_html_safe'] actually defined? Also, can this be done per theme? The reason I ask is I'd like this to be only done on my mobile theme for clean looking reasons.

Shambles

It's set in Subs.php in function setupThemeContext.

samborabora

Which part?

setupThemeContext();

// Print stuff to prevent caching of pages (except on attachment errors, etc.)
if (empty($context['no_last_modified']))
{
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

// Are we debugging the template/html content?
if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !$context['browser']['is_ie'] && !WIRELESS)
header('Content-Type: application/xhtml+xml');
elseif (!isset($_REQUEST['xml']) && !WIRELESS)
header('Content-Type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
}

header('Content-Type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));

$checked_securityFiles = false;
$showed_banned = false;
foreach ($context['template_layers'] as $layer)
{
loadSubTemplate($layer . '_above', true);

// May seem contrived, but this is done in case the body and main layer aren't there...
if (in_array($layer, array('body', 'main')) && allowedTo('admin_forum') && !$user_info['is_guest'] && !$checked_securityFiles)
{
$checked_securityFiles = true;
$securityFiles = array('install.php', 'webinstall.php', 'upgrade.php', 'convert.php', 'repair_paths.php', 'repair_settings.php', 'Settings.php~', 'Settings_bak.php~');
foreach ($securityFiles as $i => $securityFile)
{
if (!file_exists($boarddir . '/' . $securityFile))
unset($securityFiles[$i]);
}

if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)))
{
echo '
<div class="errorbox">
<p class="alert">!!</p>
<h3>', empty($securityFiles) ? $txt['cache_writable_head'] : $txt['security_risk'], '</h3>
<p>';

foreach ($securityFiles as $securityFile)
{
echo '
', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br />';

if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
echo '
', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br />';
}

if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
echo '
<strong>', $txt['cache_writable'], '</strong><br />';

echo '
</p>
</div>';
}
}
// If the user is banned from posting inform them of it.
elseif (in_array($layer, array('main', 'body')) && isset($_SESSION['ban']['cannot_post']) && !$showed_banned)
{
$showed_banned = true;
echo '
<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);

if (!empty($_SESSION['ban']['cannot_post']['reason']))
echo '
<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';

if (!empty($_SESSION['ban']['expire_time']))
echo '
<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
else
echo '
<div>', $txt['your_ban_expires_never'], '</div>';

echo '
</div>';
}
}

if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template']))
{
$settings['theme_url'] = $settings['default_theme_url'];
$settings['images_url'] = $settings['default_images_url'];
$settings['theme_dir'] = $settings['default_theme_dir'];
}
}


Also, can this be done on a per theme basis? That way I can truncate it for mobile but leave it as is for normal themes.

margarett

Here
$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title']));

You can do it by theme, eg:
if ($settings['name'] == 'YourThemeName')
$context['page_title_html_safe'] = 'Something here';
else
$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title']));
$context['meta_keywords'] = !empty($modSettings['meta_keywords']) ? $smcFunc['htmlspecialchars']($modSettings['meta_keywords']) : '';
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Ahh thank you! I was doing it with
<title>
';
if (!empty($context['i_am_on_boardindex']))

echo'
', iPhoneTitle(), '';

elseif (!empty($context['i_am_on_messageindex']))
echo'', $context['name'], '';
elseif (!empty($context['i_am_on_display']))
echo'', $context['subject'], '
';
else
echo'
', iPhoneTitle(), '';
echo'
</title>


which is incredibly long winded and probably not good for the server! ;D I'll try yours now, thanks!

Advertisement: