Skip to content

Commit

Permalink
Working on #2972 Template Conversion to Twig Format (miscellaneous) (#…
Browse files Browse the repository at this point in the history
…3256)

* Converted miscellaneous templates

* Added php_warnings

* Fixed indenting

* Fixed indenting and changed & to &
  • Loading branch information
Shade- authored and euantorano committed Jun 2, 2019
1 parent fefaac8 commit d73fe85
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 131 deletions.
2 changes: 1 addition & 1 deletion contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@

if($mybb->settings['captchaimage'] && !$mybb->user['uid'])
{
$post_captcha = new captcha(true, "post_captcha");
$post_captcha = new captcha(true, "post");

if($post_captcha->html)
{
Expand Down
2 changes: 1 addition & 1 deletion editpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
$posticons = get_post_icons();
}

eval("\$loginbox = \"".$templates->get("changeuserbox")."\";");
$loginbox = \MyBB\template('misc/changeuserbox.twig');

$editpost['showdelete'] = false;
// Can we delete posts?
Expand Down
46 changes: 19 additions & 27 deletions inc/class_captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,6 @@ function __construct($build = false, $template = "")
if($template)
{
$this->captcha_template = $template;

if($this->type == 4)
{
$this->captcha_template .= "_nocaptcha";
}
elseif($this->type == 5)
{
$this->captcha_template .= "_recaptcha_invisible";
}
}

// Work on which CAPTCHA we've got installed
Expand Down Expand Up @@ -147,7 +138,7 @@ function __construct($build = false, $template = "")
*/
function build_captcha($return = false)
{
global $db, $lang, $templates, $theme, $mybb;
global $db, $lang, $theme;

// This will build a MyBB CAPTCHA
$randomstr = random_str(5);
Expand All @@ -160,49 +151,50 @@ function build_captcha($return = false)
);

$db->insert_query("captcha", $insert_array);
eval("\$this->html = \"".$templates->get($this->captcha_template)."\";");
//eval("\$this->html = \"".$templates->get("member_register_regimage")."\";");
$this->html = \MyBB\template('misc/captcha/' . $this->captcha_template . '.twig', [
'randomstr' => $randomstr,
'imagehash' => $imagehash
]);
}

function build_recaptcha()
{
global $lang, $mybb, $templates;

// This will build a reCAPTCHA
$server = $this->server;
$public_key = $mybb->settings['captchapublickey'];
global $mybb;

eval("\$this->html = \"".$templates->get($this->captcha_template, 1, 0)."\";");
//eval("\$this->html = \"".$templates->get("member_register_regimage_recaptcha")."\";");
$this->html = \MyBB\template('misc/captcha/' . $this->captcha_template . '.twig', [
'server' => $this->server,
'type' => $this->type
]);
}

/**
* @return string
*/
function build_hidden_captcha()
{
global $db, $mybb, $templates;
global $db, $mybb;

$field = array();
$fields = array();

if($this->type == 1)
{
// Names
$hash = "imagehash";
$string = "imagestring";
$fields['names']['hash'] = "imagehash";
$fields['names']['string'] = "imagestring";

// Values
$field['hash'] = $db->escape_string($mybb->input['imagehash']);
$field['string'] = $db->escape_string($mybb->input['imagestring']);
$fields['hash'] = $db->escape_string($mybb->input['imagehash']);
$fields['string'] = $db->escape_string($mybb->input['imagestring']);
}
elseif($this->type == 3)
{
// Are You a Human can't be built as a hidden captcha
return '';
}

eval("\$this->html = \"".$templates->get("post_captcha_hidden")."\";");
return $this->html;
$this->html = \MyBB\template('misc/captcha/hidden.twig', [
'fields' => $fields
]);
}

/**
Expand Down
26 changes: 3 additions & 23 deletions inc/class_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,29 +260,9 @@ function show_warnings()
$lang->warnings = "The following warnings occurred:";
}

$template_exists = false;

if(!is_object($templates) || !method_exists($templates, 'get'))
{
if(@file_exists(MYBB_ROOT."inc/class_templates.php"))
{
@require_once MYBB_ROOT."inc/class_templates.php";
$templates = new templates;
$template_exists = true;
}
}
else
{
$template_exists = true;
}

$warning = '';
if($template_exists == true)
{
eval("\$warning = \"".$templates->get("php_warnings")."\";");
}

return $warning;
return \MyBB\template('misc/php_warnings.twig', [
'warnings' => $this->warnings
]);
}

/**
Expand Down
89 changes: 45 additions & 44 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,29 @@ function output_page($contents)
$serverload = get_server_load();

if (my_strpos(getenv("REQUEST_URI"), "?")) {
$debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "&debug=1";
$debuglink = getenv("REQUEST_URI") . "&debug=1";
} else {
$debuglink = htmlspecialchars_uni(getenv("REQUEST_URI")) . "?debug=1";
$debuglink = getenv("REQUEST_URI") . "?debug=1";
}

$memory_usage = get_memory_usage();

if ($memory_usage) {
$memory_usage = $lang->sprintf($lang->debug_memory_usage, get_friendly_size($memory_usage));
} else {
$memory_usage = '';
}
// MySQLi is still MySQL, so present it that way to the user
$database_server = $db->short_title;

if ($database_server == 'MySQLi') {
$database_server = 'MySQL';
}
$generated_in = $lang->sprintf($lang->debug_generated_in, $totaltime);
$debug_weight = $lang->sprintf($lang->debug_weight, $percentphp, $percentsql, $database_server);
$sql_queries = $lang->sprintf($lang->debug_sql_queries, $db->query_count);
$server_load = $lang->sprintf($lang->debug_server_load, $serverload);

eval("\$debugstuff = \"".$templates->get("debug_summary")."\";");
$debugstuff = \MyBB\template('misc/debugsummary.twig', [
'debug_weight' => $debug_weight,
'sql_queries' => $sql_queries,
'serverload' => $serverload,
'totaltime' => $totaltime,
'memory_usage' => get_friendly_size($memory_usage)
]);
$contents = str_replace("<debugstuff>", $debugstuff, $contents);
}

Expand Down Expand Up @@ -816,10 +815,12 @@ function redirect($url, $message="", $title="", $force_redirect=false)
// Show redirects only if both ACP and UCP settings are enabled, or ACP is enabled, and user is a guest, or they are forced.
if ($force_redirect == true || ($mybb->settings['redirects'] == 1 && ($mybb->user['showredirect'] == 1 || !$mybb->user['uid']))) {
$url = str_replace("&amp;", "&", $url);
$url = htmlspecialchars_uni($url);

eval("\$redirectpage = \"".$templates->get("redirect")."\";");
output_page($redirectpage);
output_page(\MyBB\template('misc/redirect.twig', [
'url' => $url,
'title' => $title,
'message' => $message
]));
} else {
$url = htmlspecialchars_decode($url);
$url = str_replace(array("\n","\r",";"), "", $url);
Expand Down Expand Up @@ -2759,13 +2760,14 @@ function build_mycode_inserter($bind="message", $smilies = true)

$editor_language .= "}})(jQuery);";

$toolbar = [];

if (defined("IN_ADMINCP")) {
global $page;
$codeinsert = $page->build_codebuttons_editor($bind, $editor_language, $smilies);
} else {
// Smilies
$emoticon = "";
$emoticons_enabled = "false";
$emoticons = [];
if ($smilies) {
if (!$smiliecache) {
if (!isset($smilie_cache) || !is_array($smilie_cache)) {
Expand All @@ -2778,16 +2780,14 @@ function build_mycode_inserter($bind="message", $smilies = true)
}

if ($mybb->settings['smilieinserter'] && $mybb->settings['smilieinsertercols'] && $mybb->settings['smilieinsertertot'] && !empty($smiliecache)) {
$emoticon = ",emoticon";
$toolbar['emoticon'] = ",emoticon";
}
$emoticons_enabled = "true";

unset($smilie);

if (is_array($smiliecache)) {
reset($smiliecache);

$dropdownsmilies = $moresmilies = $hiddensmilies = "";
$i = 0;

foreach ($smiliecache as $smilie) {
Expand All @@ -2802,70 +2802,69 @@ function build_mycode_inserter($bind="message", $smilies = true)
$image = str_replace(array('\\', '"'), array('\\\\', '\"'), $image);

if (!$mybb->settings['smilieinserter'] || !$mybb->settings['smilieinsertercols'] || !$mybb->settings['smilieinsertertot'] || !$smilie['showclickable']) {
$hiddensmilies .= '"'.$find.'": "'.$image.'",';
$emoticons['hidden'] .= '"'.$find.'": "'.$image.'",';
} elseif ($i < $mybb->settings['smilieinsertertot']) {
$dropdownsmilies .= '"'.$find.'": "'.$image.'",';
$emoticons['dropdown'] .= '"'.$find.'": "'.$image.'",';
++$i;
} else {
$moresmilies .= '"'.$find.'": "'.$image.'",';
$emoticons['more'] .= '"'.$find.'": "'.$image.'",';
}

for ($j = 1; $j < $finds_count; ++$j) {
$find = str_replace(array('\\', '"'), array('\\\\', '\"'), htmlspecialchars_uni($finds[$j]));
$hiddensmilies .= '"'.$find.'": "'.$image.'",';
$emoticons['hidden'] .= '"'.$find.'": "'.$image.'",';
}
}
}
}

$basic1 = $basic2 = $align = $font = $size = $color = $removeformat = $email = $link = $list = $code = $sourcemode = "";

if ($mybb->settings['allowbasicmycode'] == 1) {
$basic1 = "bold,italic,underline,strike|";
$basic2 = "horizontalrule,";
$toolbar['basic1'] = "bold,italic,underline,strike|";
$toolbar['basic2'] = "horizontalrule,";
}

if ($mybb->settings['allowalignmycode'] == 1) {
$align = "left,center,right,justify|";
$toolbar['align'] = "left,center,right,justify|";
}

if ($mybb->settings['allowfontmycode'] == 1) {
$font = "font,";
$toolbar['font'] = "font,";
}

if ($mybb->settings['allowsizemycode'] == 1) {
$size = "size,";
$toolbar['size'] = "size,";
}

if ($mybb->settings['allowcolormycode'] == 1) {
$color = "color,";
$toolbar['color'] = "color,";
}

if ($mybb->settings['allowfontmycode'] == 1 || $mybb->settings['allowsizemycode'] == 1 || $mybb->settings['allowcolormycode'] == 1) {
$removeformat = "removeformat|";
$toolbar['removeformat'] = "removeformat|";
}

if ($mybb->settings['allowemailmycode'] == 1) {
$email = "email,";
$toolbar['email'] = "email,";
}

if ($mybb->settings['allowlinkmycode'] == 1) {
$link = "link,unlink";
$toolbar['link'] = "link,unlink";
}

if ($mybb->settings['allowlistmycode'] == 1) {
$list = "bulletlist,orderedlist|";
$toolbar['list'] = "bulletlist,orderedlist|";
}

if ($mybb->settings['allowcodemycode'] == 1) {
$code = "code,php,";
$toolbar['code'] = "code,php,";
}

if ($mybb->user['sourceeditor'] == 1) {
$sourcemode = "MyBBEditor.sourceMode(true);";
}

eval("\$codeinsert = \"".$templates->get("codebuttons")."\";");
$codeinsert = \MyBB\template('misc/codebuttons.twig', [
'toolbar' => $toolbar,
'emoticons' => $emoticons,
'editor_language' => $editor_language,
'bind' => $bind
]);
}
}

Expand Down Expand Up @@ -3435,7 +3434,7 @@ function get_attachment_icon($ext)

$icon = $attach_icons_schemes[$ext];

$name = htmlspecialchars_uni($attachtypes[$ext]['name']);
$name = $attachtypes[$ext]['name'];
} else {
if (defined("IN_ADMINCP")) {
$theme['imgdir'] = "../images";
Expand All @@ -3449,9 +3448,11 @@ function get_attachment_icon($ext)
$name = $lang->unknown;
}

$icon = htmlspecialchars_uni($icon);
eval("\$attachment_icon = \"".$templates->get("attachment_icon")."\";");
return $attachment_icon;
return \MyBB\template('misc/attachment_icon.twig', [
'ext' => $ext,
'icon' => $icon,
'name' => $name
]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions inc/views/base/layouts/master.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
</script>
</head>
<body>
{% include 'partials/header.twig' %}
{% block header %}{% include 'partials/header.twig' %}{% endblock %}

{% block body %}{% endblock %}

{% include 'partials/footer.twig' %}
{% block footer %}{% include 'partials/footer.twig' %}{% endblock %}
</body>
</html>
1 change: 1 addition & 0 deletions inc/views/base/misc/attachment_icon.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img src="{{ icon }}" title="{{ name }}" border="0" alt=".{{ ext }}" />
2 changes: 2 additions & 0 deletions inc/views/base/misc/captcha/hidden.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<input type="hidden" name="{{ fields.names.hash }}" value="{{ fields.hash }}" />
<input type="hidden" name="{{ fields.names.string }}" value="{{ fields.string }}" />

0 comments on commit d73fe85

Please sign in to comment.