Skip to content

Commit

Permalink
Working on #2972 Template Conversion to Twig Format (footer) (#3253)
Browse files Browse the repository at this point in the history
* Converted footer

* Added missing post_code_string

* Fixed indent
  • Loading branch information
Shade- authored and euantorano committed Jun 2, 2019
1 parent 954b08e commit 9296399
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 50 deletions.
56 changes: 10 additions & 46 deletions global.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,6 @@
// Set up some of the default templates
eval('$header = "'.$templates->get('header').'";');

$copy_year = my_date('Y', TIME_NOW);

// Are we showing version numbers in the footer?
$mybbversion = '';
if ($mybb->settings['showvernum'] == 1) {
$mybbversion = ' '.$mybb->version;
}

// Check to see if we have any tasks to run
$task_image = '';
$task_cache = $cache->read('tasks');
Expand All @@ -643,55 +635,29 @@
eval("\$task_image = \"".$templates->get("task_image")."\";");
}

// Post code
$post_code_string = '';
if ($mybb->user['uid']) {
$post_code_string = '&my_post_key='.$mybb->post_code;
}
// Use a fictional setting to inject the footer code into Twig without creating an ad-hoc extension
$mybb->settings['footer'] = [];

// Are we showing the quick language selection box?
$lang_select = $lang_options = '';
if ($mybb->settings['showlanguageselect'] != 0) {
$languages = $lang->get_languages();
$mybb->settings['footer']['langselect']['options'] = $lang->get_languages();

if (count($languages) > 1) {
foreach ($languages as $key => $language) {
$language = htmlspecialchars_uni($language);

// Current language matches
if ($lang->language == $key) {
$selected = " selected=\"selected\"";
} else {
$selected = '';
}

eval('$lang_options .= "'.$templates->get('footer_languageselect_option').'";');
}

$lang_redirect_url = get_current_location(true, 'language');
eval('$lang_select = "'.$templates->get('footer_languageselect').'";');
if (count($mybb->settings['footer']['langselect']) > 1) {
$mybb->settings['footer']['langselect']['current_url'] = get_current_location(true, 'language');
}
}

// Are we showing the quick theme selection box?
$theme_select = $theme_options = '';
if ($mybb->settings['showthemeselect'] != 0) {
$theme_options = build_theme_select("theme", $mybb->user['style'], 0, '', false, true);
$mybb->settings['footer']['themeselect']['options'] = build_theme_select("theme", $mybb->user['style'], 0, '', false, true);

if (!empty($theme_options)) {
$theme_redirect_url = get_current_location(true, 'theme');
eval('$theme_select = "'.$templates->get('footer_themeselect').'";');
if (!empty($mybb->settings['footer']['themeselect']['options'])) {
$mybb->settings['footer']['themeselect']['current_url'] = get_current_location(true, 'theme');
}
}

// If we use the contact form, show 'Contact Us' link when appropriate
$contact_us = '';
if (($mybb->settings['contactlink'] == "contact.php" && $mybb->settings['contact'] == 1 && ($mybb->settings['contact_guests'] != 1 && $mybb->user['uid'] == 0 || $mybb->user['uid'] > 0)) || $mybb->settings['contactlink'] != "contact.php") {
if (!my_validate_url($mybb->settings['contactlink'], true) && my_substr($mybb->settings['contactlink'], 0, 7) != 'mailto:') {
$mybb->settings['contactlink'] = $mybb->settings['bburl'].'/'.$mybb->settings['contactlink'];
}

eval('$contact_us = "'.$templates->get('footer_contactus').'";');
if (!my_validate_url($mybb->settings['contactlink'], true) && my_substr($mybb->settings['contactlink'], 0, 7) != 'mailto:') {
$mybb->settings['contactlink'] = $mybb->settings['bburl'].'/'.$mybb->settings['contactlink'];
}

// DST Auto detection enabled?
Expand All @@ -701,8 +667,6 @@
eval('$auto_dst_detection = "'.$templates->get('global_dst_detection').'";');
}

eval('$footer = "'.$templates->get('footer').'";');

// Add our main parts to the navigation
$navbits = array();
$navbits[0]['name'] = $mybb->settings['bbname_orig'];
Expand Down
7 changes: 3 additions & 4 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4198,19 +4198,18 @@ function get_current_location($fields=false, $ignore=array(), $quick=false)
if (!is_array($ignore)) {
$ignore = array($ignore);
}

$form_html = '';
$fields = [];
if (!empty($mybb->input)) {
foreach ($mybb->input as $name => $value) {
if (in_array($name, $ignore) || is_array($name) || is_array($value)) {
continue;
}

$form_html .= "<input type=\"hidden\" name=\"".htmlspecialchars_uni($name)."\" value=\"".htmlspecialchars_uni($value)."\" />\n";
$fields[$name] = $value;
}
}

return array('location' => $location, 'form_html' => $form_html, 'form_method' => $mybb->request_method);
return array('location' => $location, 'fields' => $fields, 'form_method' => $mybb->request_method);
} else {
if (isset($_SERVER['QUERY_STRING'])) {
$location .= "?".htmlspecialchars_uni($_SERVER['QUERY_STRING']);
Expand Down
69 changes: 69 additions & 0 deletions inc/views/base/partials/footer.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
<debugstuff>
</div>
</div>
<div id="footer">
<div class="upper">
<div class="wrapper">
{% if mybb.settings.footer.langselect is iterable %}
<div class="language">
<form method="post" action="{{ mybb.settings.footer.langselect.current_url.location }}" id="lang_select">
<input type="hidden" name="my_post_key" value="{{ mybb.post_code }}" />
{% for name, field in mybb.input if name != 'language' and name is not iterable and value is not iterable and value %}
<input type="hidden" name="{{ name }}" value="{{ value }}" />
{% endfor %}
<select name="language" onchange="MyBB.changeLanguage();">
<optgroup label="{{ lang.select_language }}">
{% for key, language in mybb.settings.footer.langselect.options %}
{{ language }}
<option value="{{ key }}"{% if lang.language == key %} selected{% endif %}>{{ language }}</option>
{% endfor %}
</optgroup>
</select>
<input type="submit" class="button" value="{{ lang.go }}" />
</form>
</div>
{% endif %}
{% if mybb.settings.footer.themeselect is iterable %}
<div class="theme">
<form method="post" action="{{ mybb.settings.footer.themeselect.current_url.location }}" id="theme_select">
<input type="hidden" name="my_post_key" value="{{ mybb.post_code }}" />
{% if mybb.settings.footer.themeselect.options %}
{% for name, field in mybb.input if name != 'theme' and name is not iterable and value is not iterable and value %}
<input type="hidden" name="{{ name }}" value="{{ value }}" />
{% endfor %}
{% endif %}
{{ mybb.settings.footer.themeselect.options|raw }}
<input type="submit" class="button" value="{{ lang.go }}" />
</form>
</div>
{% endif %}
<ul class="menu bottom_links">
{% if (mybb.settings.contactlink == "contact.php" and mybb.settings.contact and (mybb.settings.contact_guests != 1 and mybb.user.uid == 0 or mybb.user.uid > 0)) or mybb.settings.contactlink != "contact.php" %}
<li><a href="{{ mybb.settings.contactlink }}">{{ lang.bottomlinks_contactus }}</a></li>
{% endif %}
<li><a href="{{ mybb.settings.homeurl }}">{{ mybb.settings.homename }}</a></li>
<li><a href="#top">{{ lang.bottomlinks_returntop }}</a></li>
<li><a href="<archive_url>">{{ lang.bottomlinks_litemode }}</a></li>
<li><a href="{{ mybb.settings.bburl }}/misc.php?action=markread{% if mybb.user.uid %}&amp;my_post_key={{ mybb.post_code }}{% endif %}">{{ lang.bottomlinks_markread }}</a></li>
<li><a href="{{ mybb.settings.bburl }}/misc.php?action=syndication">{{ lang.bottomlinks_syndication }}</a></li>
</ul>
</div>
</div>
<div class="lower">
<div class="wrapper">
<span id="current_time">{{ lang.welcome_current_time|raw }}</span>
<span id="copyright">
<!-- MyBB is free software developed and maintained by a volunteer community.
It would be much appreciated by the MyBB Group if you left the full copyright and "powered by" notice intact,
to show your support for MyBB. If you choose to remove or modify the copyright below,
you may be refused support on the MyBB Community Forums.
This is free software, support us and we'll support you. -->
{{ lang.powered_by }} <a href="https://mybb.com" target="_blank" rel="noopener">MyBB{% if mybb.settings.showvernum %} {{ mybb.version }}{% endif %}</a>, &copy; 2002-{{ "now"|date("Y") }} <a href="https://mybb.com" target="_blank" rel="noopener">MyBB Group</a>.
<!-- End powered by -->
</span>
</div>
</div>
</div>
<!-- The following piece of code allows MyBB to run scheduled tasks. DO NOT REMOVE -->{{ task_image }}<!-- End task image code. TODO: convert task_image template -->
{% if mybb.settings.dst_correction %}
{{ mybb.settings.dst_correction }}
{% endif %}
</div>

0 comments on commit 9296399

Please sign in to comment.