MyBB Community Forums

Full Version: HTML link in lang file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all,

I have a stupid question - I wanna include html link to sources into plugin description. Everything works fine, description is shown from my lang file but link is not working - it gives me after click:


http://www.mysite.com/http://github.com


is there any way how to make it working? The link should be only http://github.com


In lang file I use:

<a href="http://github.com" target="_blank">LINK</a>

Thank you
It works well for me:

Plugin file:
function abp_test_info()
{
 global $plugins_cache, $db, $lang;
 $lang->load('abp_test');

    $info = array(
        "name" => "ABP Test",
        "description" => $lang->description,
        "website" => "http://ab-plugin.cc/",
        "author" => "CrazyCat",
        "authorsite" => "http://ab-plugin.cc",
        "version" => "1.0",
 "compatibility" => "18*"
    );
}

abp_test.lang.php
<?php

$l['description'] = 'Test plugin sources: <a href="http://ab-plugin.cc/">here !</a>';

And my link goes to the good destination.
Hmm, I will try again. Thank you anyway, I will contact you soon Smile
BTW, something quite better:
In the plugin:
"description"		=> sprintf($lang->description, 'http://ab-plugin.cc/'),

In the lang file:
$l['description'] = 'Contact to new thread <a href="%s">test</a>';
I have problem here:
description line in plugin: https://github.com/Cu8eR/thankyou-like-p...ke.php#L53
lang file fot this description: https://github.com/Cu8eR/thankyou-like-p...ang.php#L9

I also tried with no extra "\" but same problem
Why do you use $db->escape_string() ?
The contents of the language files aren't stored in DB, and you may master them, so you don't have to do that for the info part.

$db->escape_string() must be used only for DB queries, to avoid SQL injections and protect special characters.
i think sprintf() is not necessary but if you wona use this batter why is take all html to param

"description"        => sprintf($lang->description, 'http://ab-plugin.cc/">test</a>'), 

$l['description'] = 'Contact to new thread {1}'; 

$db->escape_string() is good idea
IMHO
If you use {1} in language file, it should be like this
"description"        => $lang->sprintf($lang->description, 'http://ab-plugin.cc/">test</a>'), 
(2015-04-04, 08:09 AM)Supryk Wrote: [ -> ]$db->escape_string()  is good idea

It's not.. As Crazycat said above, it's the cause of the issue - it escapes characters in HTML output unnecessarily, which breaks the link.

$db->escape_string() is supposed to be used only for dealing with textual inputs in database queries. Nowhere else.
I use it because many time ago have an SQL injection problem with lang file and it's reported but i see i can inject SQL code inside lang files, i know thi have to be fixed, but anyway i take my own codes to make care about some curious people in the future if exist again some bad code or any who brokes function of core code then this areas can stay protected.

I use allways on db requests or something i think can be take a risk escapes to do that.

But in some cases i use another type of code. In info i think it's unnecesary to use that but who know, i use it anyway for the reason i mentioned.

You can set a sprintf with values and then asign your urls to vars and add it on lang sprintf file and finally add it into lang file and done !!!

Only remove escape_string and all have to be fine.

I use this besides if it was my case:

In core file:

$url_AT= '<a href="http://my-bb.ir" target="_blank">AliReza_Tofighi</a>'
$url_SP = '<a href="http://community.mybb.com/user-91011.html" target="_blank">SvePu</a>';
$url_E = '<a href="http://community.mybb.com/user-84065.html" target="_blank">Eldenroot</a>'
$url_S = '<a href="https://github.com/Cu8eR/thankyou-like-plugin" target="_blank">GitHub</a>';

 $info = array(
"name"	=> $db->escape_string($lang->tyl_info_title),
"description"	=> $lang->sprintf($lang->tyl_info_desc,$url_AT,$url_SP,$url_E,$url_S),
"website"	=> "http://www.geekplugins.com/mybb/thankyoulikesystem",
"author"	=> "- G33K -",
"authorsite"	=> "http://community.mybboard.net/user-19236.html",
"version"	=> "1.9.1",
"codename"	=> "thankyoulikesystem",
"compatibility"	=> "18*"
);



In lang file:
$l['tyl_info_desc'] = "Adds option for users to Thank the user for the post or Like the post.<br />*Edited for MyBB 1.8 by: {1}<br />*Maintained by: {2} and {3}<br />*Sources: {4}";

In that way you can change only source code and not the lang vars and users only traduce parts who have to be changed and not all content Big Grin

See yah !!!

I think this for me can be the bet way to make the change, but you can use anything you like and test it Big Grin you can use only text and escape and before that add a new info with links.

$url_AT= '<a href="http://my-bb.ir" target="_blank">AliReza_Tofighi</a>'
$url_SP = '<a href="http://community.mybb.com/user-91011.html" target="_blank">SvePu</a>';
$url_E = '<a href="http://community.mybb.com/user-84065.html" target="_blank">Eldenroot</a>'
$url_S = '<a href="https://github.com/Cu8eR/thankyou-like-plugin" target="_blank">GitHub</a>';

 $info = array(
"name"	=> $db->escape_string($lang->tyl_info_title),
"description"	=> $db->escape_string($lang->tyl_info_desc) . $lang->sprintf($lang->tyl_info_desc_url,$url_AT,$url_SP,$url_E,$url_S),
"website"	=> "http://www.geekplugins.com/mybb/thankyoulikesystem",
"author"	=> "- G33K -",
"authorsite"	=> "http://community.mybboard.net/user-19236.html",
"version"	=> "1.9.1",
"codename"	=> "thankyoulikesystem",
"compatibility"	=> "18*"
);



In lang file:
$l['tyl_info_desc'] = "Adds option for users to Thank the user for the post or Like the post.";
$l['tyl_info_desc_url'] ="<br />*Edited for MyBB 1.8 by: {1}<br />*Maintained by: {2} and {3}<br />*Sources: {4}";

Or direct on file all entire code of second arg. It's only an idea but it's what i do in your case.

See yah !!!
Pages: 1 2