MyBB Community Forums

Full Version: Just A Question.Uhmm a few questions :D
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,
i've coded a plug-in and i can't get the variable codes (like that,{$username} )
(done creating new templates)

for example ,i described the variables in the plugin file ($tid,$username etc.) but it doesn't work when it's in the new templates,when i try to getting it.

in the plugin (creating new template,activate fuction)
<a href=\"member.php?action=profile&amp;uid=\$uid\"><b>\$username</b></a></td>
in the plugin function

$query = $db->query ("SELECT subject,username,uid,pid,tid FROM ".TABLE_PREFIX."posts WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");
$newest_posts = $db->fetch_array($query);
$uid = $newest_posts['uid'];
$username = $newest_posts['username'];

One more problem; i done that for to load language files (in the plugin function)

$language = $mybb->settings['bblanguage'];
$lang->load("advportal");

and it's saying 'inc/languages/turkish/admin/advportal.lang.php doesnt exist' ?
namely, why doesn't it look to the only folder of turkish? why turkish/admin ?


Thanks a lot Toungue
Silverday Wrote:Hello all,
i've coded a plug-in and i can't get the variable codes (like that,{$username} )
(done creating new templates)

for example ,i described the variables in the plugin file ($tid,$username etc.) but it doesn't work when it's in the new templates,when i try to getting it.

in the plugin (creating new template,activate fuction)
<a href=\"member.php?action=profile&amp;uid=\$uid\"><b>\$username</b></a></td>
in the plugin function
Umm, you didn't enclose the variables with braces? Should be {$uid} not $uid.

Silverday Wrote:One more problem; i done that for to load language files (in the plugin function)

$language = $mybb->settings['bblanguage'];
$lang->load("advportal");

and it's saying 'inc/languages/turkish/admin/advportal.lang.php doesnt exist' ?
namely, why doesn't it look to the only folder of turkish? why turkish/admin ?
Because you're language is set to turkish.
Setting the $language variable won't help in this case.
You'll have to set the language through the $lang object (can't remember the code - you'll have to look that one up).
i have enclosed with { } ,didn't work.

and i've described $lang as global $mybb, $lang, $cache etc.
and i don't know the code you mean.
on result i still need help.
Enes*
Could you please post most of your code?

It's difficult trying to guess what's happening.


Silverday Wrote:in the plugin (creating new template,activate fuction)
<a href=\"member.php?action=profile&amp;uid=\$uid\"><b>\$username</b></a></td>
I'm assuming your code looks something like this:
Code:
$new_template = " [...]   <a href=\"member.php?action=profile&amp;uid={\$uid}\"><b>{\$username}</b></a></td>  [...]

Right?

Silverday Wrote:in the plugin function

$query = $db->query ("SELECT subject,username,uid,pid,tid FROM ".TABLE_PREFIX."posts WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");
$newest_posts = $db->fetch_array($query);
$uid = $newest_posts['uid'];
$username = $newest_posts['username'];
I'm going to guess that the issue is here.
If it's inside a function, and the code is being eval'd in the global scope (outside the function), you'll have to global $uid and $username, or else those two variables "die" once the function finishes executing.



Silverday Wrote:and i don't know the code you mean.
I'm still not sure you want...

The file inc/languages/turkish/admin/advportal.lang.php doesn't exist. So what language file does exist?
PHP Code:
function advportal_activate()

    global 
$db$lang$mybb;
    
advportal();

    
$advportal_group = array(
        
"gid" => "NULL",
        
"name" => "advportal",
        
"title" => "Advanced Portal Settings",
        
"description" => "Settings",
        
"disporder" => "1",
        
"isdefault" => "no",
        );

    
$db->insert_query(TABLE_PREFIX."settinggroups"$advportal_group);
    
$gid $db->insert_id();

    
// Ayarlar

    
$advportal_1 = array(
        
"sid" => "NULL",
        
"name" => "advportal_item_lenght",
        
"title" => "Maximum Length For Subject Titles",
        
"description" => "How many characters do you want to set as maximum? If 0,it is free.",
        
"optionscode" => "text",
        
"value" => "0",
        
"disporder" => "1",
        
"gid" => intval($gid),
        );

    
$db->insert_query(TABLE_PREFIX."settings"$advportal_1);

    
$advportal_2 = array(
        
"sid" => "NULL",
        
"name" => "advportal_max",
        
"title" => "How Many Threads",
        
"description" => "How Many Threads do you want to show?",
        
"optionscode" => "text",
        
"value" => "15",
        
"disporder" => "2",
        
"gid" => intval($gid),
        );

    
$db->insert_query(TABLE_PREFIX."settings"$advportal_2);

    
// Şablon Güncellemesi

        
require MYBB_ROOT."/inc/adminfunctions_templates.php"
    
find_replace_templatesets("footer"'#<!-- End copyright -->#'"<br>MyBB Advanced Portal by <a href=\"http://www.miqrop.net\"><b>eN-S</b></a>\n<!-- End copyright -->");
    
find_replace_templatesets("portal"'#{\$stats}#'"\n");
    
find_replace_templatesets("portal"'#{\$latestthreads}#'"\n");
    
find_replace_templatesets("portal"'#{\$whosonline}#'"\n");
    
find_replace_templatesets("portal"'#{\$announcements}#'"{\$announcements}\n{\$advportal}\n{\$whosonline}\n{\$stats}");

    
// Yeni Şablon Yaratımı

    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "portal_advportal",
        
"template" => "
<td valign=\"top\">
<table align=\"center\" valign=\"top\" width=\"900\">
    <tr class=\"thead\" width=\"900\">
<td align=\"left\"><b>{\$lang->advportal_lastposts}</b></td>\n
    </tr>\n
    <tr class=\"tcat\">\n
<td align=\"left\" width=\"50%\"><b>{\$lang->advportal_subject}</b></td>\n
<td align=\"right\" width=\"13%\"><b>{\$lang->advportal_author}</b></td>\n
<td align=\"center\" width=\"19%\"><b>{\$lang->advportal_poster}</b></td>\n
<td align=\"right\" width=\"9%\"><b>{\$lang->advportal_views}</b></td>\n
<td align=\"right\" width=\"9%\"><b>{\$lang->advportal_replies}</b></td>\n
    </tr>\$advportal_ek</table></td>"
,
        
"sid" => "-1",
        );

    
$db->insert_query(TABLE_PREFIX."templates"$templatearray);

    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "portal_advportal_ek",
        
"template" => "<tr class=\"trow1\" width=\"900\" height=\"40\">
        <td align=\"left\" valign=\"top\" width=\"50%\"><a href=\"showthread.php?tid={\$tid}\" title=\"{\$subject}\"><b>{\$subject}</b></a></td>
    <td align=\"right\" valign=\"top\" width=\"13%\">\{\$author}</td>
        <td align=\"center\" valign=\"top\" width=\"19%\"><a href=\"member.php?action=profile&amp;uid={\$uid}\"><b>{\$username}</b></a></td>
        <td align=\"right\" valign=\"top\" width=\"13%\">{\$views}</a></td>
        <td align=\"right\" valign=\"top\" width=\"13%\">{\$replies}</td>
        </tr>"
,
        
"sid" => "-1",
        );
    
$db->insert_query(TABLE_PREFIX."templates"$templatearray);

    
// Dil paketi yüklenmesi
        
$language $mybb->settings['bblanguage'];
        
$lang->load("advportal");

    
// settings.php yi yeniden Yapılandır
    
rebuild_settings();

}

function 
advportal()
{

    global 
$db$mybb$cache$templates$theme$lang$advportal$advportal_ek$unviewwhere;


    
// Tüm Değişkenler 

if(!$mybb->settings['advportal_max'])
{
     
$mybb->settings['advportal_max'] = 20;
}  
if(!
$length)
{
     
$length 10;

        
$query $db->query ("SELECT subject,username,uid,pid,tid FROM ".TABLE_PREFIX."posts WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");
        
$query2 $db->query ("SELECT subject,username,uid,tid,replies FROM ".TABLE_PREFIX."threads WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");

        
$newest_posts $db->fetch_array($query);
        
$newest_thread $db->fetch_array($query2); 
        
$tid $newest_posts['tid'];
        
$uid $newest_posts['uid'];
        
$username $newest_posts['username'];
        
$author $newest_thread['username'];
        
$replies $newest_posts['replies'];
        
$subject $newest_posts['subject'];
        
$views $newest_posts['views'];

    
// Şablon Değişkenlerinin Tanımlanması

        
eval("\$advportal = \"".$templates->get("portal_advportal")."\";");
        eval(
"\$advportal_ek = \"".$templates->get("portal_advportal_ek")."\";");



    
// Uzunluk Degeri
    
$length $mybb->settings['advportal_item_lenght'];
    
$width $mybb->settings['advportal_width'];

    if (
$length != 0)
    {
        if (
strlen($subject) > $length
        {
        
$subject substr($subject,0,$length) . "...";
        }
    }
    return 
$subject;
    
}
function 
get_unviewable() {
$unviewable get_unviewable_forums();
if(
$unviewable)
    {
    
$unviewwhere " AND fid NOT IN ($unviewable)";
    }


these codes are. (didnt copy deactivate and info functions)
First thing - you should escape your template inserts with $db->escape_string()

Secondly, for your language issue:
ZiNga BuRgA Wrote:The file inc/languages/turkish/admin/advportal.lang.php doesn't exist. So what language file does exist?




Here's some fixed code (language thing not fixed):
PHP Code:
function advportal_activate()

    global 
$db$lang$mybb;
    
advportal();

    
$advportal_group = array(
        
"gid" => "NULL",
        
"name" => "advportal",
        
"title" => "Advanced Portal Settings",
        
"description" => "Settings",
        
"disporder" => "1",
        
"isdefault" => "no",
        );

    
$db->insert_query(TABLE_PREFIX."settinggroups"$advportal_group);
    
$gid $db->insert_id();

    
// Ayarlar

    
$advportal_1 = array(
        
"sid" => "NULL",
        
"name" => "advportal_item_lenght",
        
"title" => "Maximum Length For Subject Titles",
        
"description" => "How many characters do you want to set as maximum? If 0,it is free.",
        
"optionscode" => "text",
        
"value" => "0",
        
"disporder" => "1",
        
"gid" => intval($gid),
        );

    
$db->insert_query(TABLE_PREFIX."settings"$advportal_1);

    
$advportal_2 = array(
        
"sid" => "NULL",
        
"name" => "advportal_max",
        
"title" => "How Many Threads",
        
"description" => "How Many Threads do you want to show?",
        
"optionscode" => "text",
        
"value" => "15",
        
"disporder" => "2",
        
"gid" => intval($gid),
        );

    
$db->insert_query(TABLE_PREFIX."settings"$advportal_2);

    
// Sablon Güncellemesi

        
require MYBB_ROOT."/inc/adminfunctions_templates.php"
    
find_replace_templatesets("footer"'#<!-- End copyright -->#'"<br>MyBB Advanced Portal by <a href=\"http://www.miqrop.net\"><b>eN-S</b></a>\n<!-- End copyright -->");
    
find_replace_templatesets("portal"'#{\$stats}#'"\n");
    
find_replace_templatesets("portal"'#{\$latestthreads}#'"\n");
    
find_replace_templatesets("portal"'#{\$whosonline}#'"\n");
    
find_replace_templatesets("portal"'#{\$announcements}#'"{\$announcements}\n{\$advportal}\n{\$whosonline}\n{\$stats}");

    
// Yeni Sablon Yaratimi

    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "portal_advportal",
        
"template" => $db->escape_string("
<td valign=\"top\">
<table align=\"center\" valign=\"top\" width=\"900\">
    <tr class=\"thead\" width=\"900\">
<td align=\"left\"><b>{\$lang->advportal_lastposts}</b></td>\n
    </tr>\n
    <tr class=\"tcat\">\n
<td align=\"left\" width=\"50%\"><b>{\$lang->advportal_subject}</b></td>\n
<td align=\"right\" width=\"13%\"><b>{\$lang->advportal_author}</b></td>\n
<td align=\"center\" width=\"19%\"><b>{\$lang->advportal_poster}</b></td>\n
<td align=\"right\" width=\"9%\"><b>{\$lang->advportal_views}</b></td>\n
<td align=\"right\" width=\"9%\"><b>{\$lang->advportal_replies}</b></td>\n
    </tr>{\$advportal_ek}</table></td>"
),
        
"sid" => "-1",
        );

    
$db->insert_query(TABLE_PREFIX."templates"$templatearray);

    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "portal_advportal_ek",
        
"template" => $db->escape_string("<tr class=\"trow1\" width=\"900\" height=\"40\">
        <td align=\"left\" valign=\"top\" width=\"50%\"><a href=\"showthread.php?tid={\$tid}\" title=\"{\$subject}\"><b>{\$subject}</b></a></td>
    <td align=\"right\" valign=\"top\" width=\"13%\">\{\$author}</td>
        <td align=\"center\" valign=\"top\" width=\"19%\"><a href=\"member.php?action=profile&amp;uid={\$uid}\"><b>{\$username}</b></a></td>
        <td align=\"right\" valign=\"top\" width=\"13%\">{\$views}</a></td>
        <td align=\"right\" valign=\"top\" width=\"13%\">{\$replies}</td>
        </tr>"
),
        
"sid" => "-1",
        );
    
$db->insert_query(TABLE_PREFIX."templates"$templatearray);

    
// Dil paketi yüklenmesi
        
$lang->load("advportal");

    
// settings.php yi yeniden Yapilandir
    
rebuild_settings();

}

function 
advportal()
{

    global 
$db$mybb$cache$templates$theme$lang$advportal$advportal_ek$unviewwhere;


    
// Tüm Degiskenler 

if(!$mybb->settings['advportal_max'])
{
     
$mybb->settings['advportal_max'] = 20;
}  
if(!
$length)
{
     
$length 10;

        
$query $db->query ("SELECT subject,username,uid,pid,tid FROM ".TABLE_PREFIX."posts WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");
        
$query2 $db->query ("SELECT subject,username,uid,tid,replies FROM ".TABLE_PREFIX."threads WHERE visible='1' ".get_unviewable()." ORDER BY dateline DESC LIMIT 0,".$mybb->settings['advportal_max']."");

        
$newest_posts $db->fetch_array($query);
        
$newest_thread $db->fetch_array($query2); 
        
$tid $newest_posts['tid'];
        
$uid $newest_posts['uid'];
        
$username $newest_posts['username'];
        
$author $newest_thread['username'];
        
$replies $newest_posts['replies'];
        
$subject $newest_posts['subject'];
        
$views $newest_posts['views'];

    
// Sablon Degiskenlerinin Tanimlanmasi

        
eval("\$advportal = \"".$templates->get("portal_advportal")."\";");
        eval(
"\$advportal_ek = \"".$templates->get("portal_advportal_ek")."\";");



    
// Uzunluk Degeri
    
$length $mybb->settings['advportal_item_lenght'];
    
$width $mybb->settings['advportal_width'];

    if (
$length != 0)
    {
        if (
strlen($subject) > $length
        {
        
$subject substr($subject,0,$length) . "...";
        }
    }
    return 
$subject;
    
}
function 
get_unviewable() {
$unviewable get_unviewable_forums();
if(
$unviewable)
    {
    
$unviewwhere " AND fid NOT IN ($unviewable)";
    }

Silverday Wrote:and it's saying 'inc/languages/turkish/admin/advportal.lang.php doesnt exist' ?
namely, why doesn't it look to the only folder of turkish? why turkish/admin ?

Cause you load the lang file within the 'activate_section' and that part happens in your PluginManager (=> /admin/ dir )

And i should remove advportal() from your activate_section and use the portal_hook to call that function; And in the advportal() function i would load that lang file; not in the activate_section.
Reference URL's