Ciao ragazzi, in questa guida imparerete a creare un template che può essere visualizzato solo dai registrati, se non sei registrato ne visualizzerai un altro, proprio come welcomeblock.
Cominciamo con il creare i seguenti template globali con i loro relativi contenuti (i nomi potete cambiarli, ma per la prima volta per non confondervi vi suggerisco di lasciarli così):
- profile_block_guest
- profile_block_member
- profile_block_member_admin
- profile_block_member_mod
- profile_block_guest
profile_block_guest
<form action="member.php" method="post"> <br /><span style="margin-right: 5px;"><strong>{$lang->username}</strong><br /> <strong><div style="margin-top: 3px;">{$lang->password}</div></strong> </span> <span> <center> <input type="text" name="username" size="25" maxlength="{$mybb->settings['maxnamelength']}" style="width: 120px;" value="{$username}" /><br /> <input type="password" name="password" size="25" style="width: 120px;" value="{$password}" /> </center> </span> <br /> <br /><input type="submit" name="submit" value="{$lang->login}" /> <a href="member.php?action=register">Registrati</a> | <a href="member.php?action=lostpw">Password dimenticata?</a> <input type="hidden" name="action" value="do_login" /> <input type="hidden" name="url" value="{$redirect_url}" /> </form>
profile_block_member:
<center><a href="{$mybb->settings['bburl']}/member.php?action=profile&uid={$mybb->user['uid']}"><img src="{$mybb->user['avatar']}"></a></center> {$lang->welcome_back}<br /><br /> - <a href="{$mybb->settings['bburl']}/usercp.php">{$lang->welcome_usercp}</a><br /> {$profilemod} {$profileadmin}<br /> <a href="{$mybb->settings['bburl']}/search.php?action=getnew">{$lang->welcome_newposts}</a> | <a href="{$mybb->settings['bburl']}/private.php">{$lang->welcome_pms}</a><br /><br /> <span style="float:right;">{$lang->welcome_current_time} | <a href="{$mybb->settings['bburl']}/member.php?action=logout&logoutkey={$mybb->user['logoutkey']}">{$lang->welcome_logout}</a></span>
profile_block_member_admin:
<a href="{$mybb->settings['bburl']}/{$config['admin_dir']}/index.php">{$lang->welcome_admin}</a><br />
profile_block_member_mod:
<a href="{$mybb->settings['bburl']}/modcp.php">{$lang->welcome_modcp}</a><br />
Ok. Andiamo ad aprire il file global.php, questo perché vogliamo che il nostro template funzioni ovunque.
Troviamo la voce “$templatelist” e aggiungiamo i template: profile_block_guest e profile_block_member in questo modo:
$templatelist .= "css,headerinclude,header,footer,gobutton,htmldoctype,header_welcomeblock_member,header_welcomeblock_guest,header_welcomeblock_member_admin,global_pm_alert,global_unreadreports,profile_block_guest,profile_block_member,";
Stessa cosa per la templatelist sottostante:
Ok ora cerchiamo la voce “welcomeblock” e scorriamo finché non troviamo il codice:
// Load appropriate welcome block for the current logged in user if($mybb->user['uid'] != 0) { // User can access the admin cp and we're not hiding admin cp links, fetch it if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1) { eval("\$admincplink = \"".$templates->get("header_welcomeblock_member_admin")."\";"); } if($mybb->usergroup['canmodcp'] == 1) { eval("\$modcplink = \"".$templates->get("header_welcomeblock_member_moderator")."\";"); } // Format the welcome back message $lang->welcome_back = $lang->sprintf($lang->welcome_back, $mybb->user['username'], $lastvisit); // Tell the user their PM usage $lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total'])); eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_member")."\";"); } // Otherwise, we have a guest else { eval("\$welcomeblock = \"".$templates->get("header_welcomeblock_guest")."\";"); }
Perfetto, ora andate sotto e incollate questo codice (esaminatelo per bene prima per capirlo):
// Load appropriate profile block for the current logged in user if($mybb->user['uid'] != 0) { // User can access the admin cp and we're not hiding admin cp links, fetch it if($mybb->usergroup['cancp'] == 1 && $mybb->config['hide_admin_links'] != 1) { eval("\$profileadmin = \"".$templates->get("profile_block_member_admin")."\";"); } if($mybb->usergroup['canmodcp'] == 1) { eval("\$profilemod = \"".$templates->get("profile_block_member_mod")."\";"); } // Format the welcome back message $lang->welcome_back = $lang->sprintf($lang->welcome_back, $mybb->user['username'], $lastvisit); // Tell the user their PM usage $lang->welcome_pms_usage = $lang->sprintf($lang->welcome_pms_usage, my_number_format($mybb->user['pms_unread']), my_number_format($mybb->user['pms_total'])); eval("\$profile_block = \"".$templates->get("profile_block_member")."\";"); } // Otherwise, we have a guest else { eval("\$profile_block = \"".$templates->get("profile_block_guest")."\";"); }
NB: Ho lasciato alcune frasi di welcomeblock così potevate richiamare anche in questo template come già fatto quando abbiamo creato i tempalte globali:
- profile_block_guest
- profile_block_member
- profile_block_member_admin
- profile_block_member_mod
Ok, ora non vi resta che andare nella pagina dove volete vedere il vostro login e richiamare il template in questo modo:
{$profile_block}
Ecco fatto, ora avrete il vostro sistema secondario di login staccato dall’header e nella pagina che volete!