Một số điều kiện cơ bản trong vbb Code cần biết

Thảo luận trong 'Mã nguồn Xenforo - VBB' bắt đầu bởi admin, 22/8/14.

  1. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,883
    Đã được thích:
    1,193
    Điểm thành tích:
    113
    Giới tính:
    Nam
    • Dưới đây là một số lệnh cơ bản trong vbb code, bạn nhiều bạn quan tâm, nhiều bạn đọc không hiểu nó là gì? nói chung ai cần thì tự hiểu thôi :D.

    Mã:
    <vb:if condition="$show['threadinfo']"> <!-- Nếu là trang threads -->
    
    <vb:elseif condition="$show['foruminfo']" /><!-- Nếu là trang forums -->    
    
    <vb:else /><!-- Nếu là trang chủ và các trang khác-->
    
    </vb:if>
    
    <vb:if condition="is_member_of($bbuserinfo, 3,8)"><!-- Nếu là user thuoc nhom nay thi thuc hien lenh gì đó -->
    
    </vb:if>
    
    <vb:if condition="THIS_SCRIPT == 'showthread' || THIS_SCRIPT == 'forumdisplay'"><!-- nếu trang forum con và trang bài viết thì thực hiện lệnh gì đó --> 
    <vb:elseif condition="THIS_SCRIPT == 'index'" /><!-- nếu là trang chủ forum home thì làm lệnh gì đó -->
    
    <vb:else /><!-- Ngược lại sẽ làm lệnh gì đó -->
    
    </vb:if>

    • Để lấy thông tin ip của người đang truy cập web đưa vào footer của web thì bạn dùng câu lệnh.

    Mã:
    {vb:raw _SERVER.REMOTE_ADDR}
    
    Chúc các bạn thành công.
     
    Cảm ơn đã xem bài:

    Một số điều kiện cơ bản trong vbb Code cần biết

    Chỉnh sửa cuối: 27/9/15
  2. yeuseo
    Tham gia ngày:
    15/8/14
    Bài viết:
    92
    Đã được thích:
    1
    Điểm thành tích:
    6
    Biến trong vbb code

    1.Trạng thái diễn đàn:
    • $totalthreads - Hiển thị tổng số Chủ đề trong diễn đàn
    • $totalposts - Hiển thị tổng số bài viết trong diễn đàn
    • $numbermembers - Hiển thị tổng số thành viên trong diễn đàn
    • $totalonline - Hiển thị tổng số người hiện đang online
    • $numberregistered - Hiển thị tổng số thành viên hiện đang online
    • $numberguest - Hiển thị tổng số khách vãng lại hiện đang online
    • $recordusers - Displays the number of most users ever online / Hiển thị số thành viên nhiều nhất đã từng online
    • $recorddate - Displays the date on which most users were ever online / Hiển thị ngày có nhiều thành viên online nhất
    • $recordtime - Displays the time on which most users were ever online / Hiển thị giờ có nhiều thành viên online nhất
    • $activeusers - Displays a list of currently active/online Users (i.e. logged in) / Hiển thị một danh sách các thành viên hiện đang online
    • $activemembers - Displays the number of members who are active in the forum / Hiển thị số thành viên tích cực trong diễn đàn
    • $newusername - Displays the username of the newly registered user / Hiển thị tên người dùng mới đăng ký
    • $birthdays - Displays list of users whose birthday is today / Hiển thị danh sách người dùng có sinh nhật trong ngày
    • $upcomingevents - Displays list of upcoming events
    2.Mảng thông thành viên, là tất cả những gì được chứa trong bảng user:
    • $bbuserinfo[username] - Tên đăng nhập thành viên
    • $bbuserinfo[userid] - Mã thành viên
    • $bbuserinfo[posts] - Số bài viết của thành viên
    • $bbuserinfo[signature] - Chữ kí cá nhân của thành viên
    • $bbuserinfo - Địa chỉ email thành viên
    • $bbuserinfo[homepage] - Trang chủ của thành viên
    • $bbuserinfo[msn] - Tài khoản msn của thành viên
    • $bbuserinfo[yahoo] - Tài khoản Yahoo của thành viên
    • $bbuserinfo[icq] - Tài khoản ICQ của thành viên
    • $bbuserinfo[usertitle] - Trạng thái tùy chỉnh của thành viên
    3. $vboptions Array, these are the options stored in the settings table, i.e things that you configured from vbulletin AdminCP>>vbulletin Options:
    • $vboptions[forumactive] - Status of whether forum is turned on/off / Trạng thái tắt/mở diễn đàn
    • $vboptions[bbclosedreason] - Reason why forum turned off / Lý do đóng forum
    • $vboptions[bbtitle] - Forum title / Tên của forum
    • $vboptions[bburl] - Forum URL / Đường dẫn forum không có / ở cuối (Ví dụ https://itseovn.com/@forum)
    • $vboptions[hometitle] - Site homepage Title / Title trang index
    • $vboptions[homeurl] - Site homepage URL / Đường dẫn trang chủ ( ví dụ : https://itseovn.com/ là trang chủ; https://itseovn.com/@forum/ là diễn đàn )
    • {vb:link thread, {vb:raw thread}} - lấy đường dẫn URL bài viết.
    • {vb:link forum, {vb:raw forum}} - lấy đường dẫn URL chuyên mục bài viết.
    • $vboptions[copyrighttext] - Site copyright text
    • $vboptions[privacyurl] - URL to forum privacy statement
    • $vboptions[webmasteremail] - Webmaster email address / Địa chỉ mail của admin
    • $vboptions[contactuslink] - contact us URL / Địa chỉ liên lạc
    • $vboptiions[enablehooks] - Status of plugin/hook system
    • $vboptions[imagetype] - Determine if using GD or Imagemagick
    • $vboptions[timeoffset] - forum time offset
    • $vboptions[cookiepath] - forum cookie path / Đường dẫn lưu cookie
    • $vboptions[legacypostbit] - Determine if using legacy (side) postbit or new horizontal postbit / Postbit dọc
    • $vboptions[use_smtp] - If SMTP mail is enabled / Kiểm tra SMTP mail có bật hay không
    • $vboptions[smtp_host] - SMTP hostname
    • $vboptions[smtp_port] - SMTP port number
    • $vboptions[allowregistrations] - Determine if new users can register / Cho phép thành viên mới đăng kí
    • $vboptions[welcomemail] - Determine if welcome mail is sent on registration / Xác nhận chức năng gửi mail cho thành viên mới
    • $vboptions[avatarenabled] - Check if avatars are enabled / Kiểm tra avatar có bật hay không
    • $vboptions[reputationenable] - Check if reputation system is enabled / Kiểm tra chức năng reputation có bật hay không
    4.$stylevar Array, this contains all the paths to forum images and other style variables that are editable in the Styles and templates >> Stylevars:
    • $stylevar[titleimage] - Path/filename for top banner
    • $stylevar[outertablewidth] - The width of your forum
    • $stylevar[spacersize] - Spacing betwen main body and content
    • $stylevar[cellspacing] - Inner border width
    • $stylevar[cellpadding] - Table cell padding
    • $stylevar[formwidth] - Form width in pixels
    • $stylevar[imgdir_button] - Path for forum buttons
    • $stylevar[imgdir_statusicon] - Path for status icons
    • $stylevar[imgdir_attach] - Path for attachment icons
    5.$css array, this is where all the CSS attributed can be located
    • $css variables[body][background] - Body background colour
    • $css[body][color] - Body text colour
    • $css[body][LINK_N][color] - Body normal links
    • $css[body][LINK_V][color] - Body visited links
    • $css[body][LINK_M][color] - Body link hover colour
    • $css[.page][background] - Page background colour
    • $css[.page][color] - Page text colour
    • $css[.tborder][background] - Table border background colour
    • $css[.tborder][color] - Table border font colour
    • $css[.tcat][background] - Category strip background/colour
    • $css[.tcat][color] - Category strip font colour
    • $css[.thead][background] - Table header background gradient/colour
    • $css[.thead][color] - Table header background colour
    • $css[.tfoot][background] - Table footer background colour/gradient
    • $css[.tfoot][color] - Table footer text colour
    6.Ad Location Template variables:
    • $ad_location[ad_footer_end] - Displays content of ad_footer_end template
    • $ad_location[ad_footer_start] - Displays content of ad_footer_start template
    • $ad_location[ad_forumdisplay_afterthreads] - Displays content of ad_forumdisplay_afterthreads template
    • $ad_location[ad_forumdisplay_afterforums] - Displays content of ad_forumdisplay_afterforums template
    • $ad_location[ad_header_logo] - Displays content of ad_header_logo template
    • $ad_location[ad_header_end] - Displays content of ad_header_end template
    • $ad_location[ad_navbar_below] - Displays content of ad_navbar_below template
    • $ad_location[ad_showthread_beforeqr] - Displays content of ad_showthread_beforeqr template
    • $ad_location[ad_showthread_firstpost] - Displays content of ad_showthread_firstpost template
    7.Miscellenous:
    • $notices - Used to display notices (for 3.7 onwards)
    • $notifications_total - Used to display total number of unread notifications (for 3.7 onwards)
    8.$post[varname] - Các thông tin trong bài viết
    • $post[username] : Nick người post bài
    • $post[musername] : Nick người post bài (đã được markup)
    • $post[birthday] : Ngày Sinh người post bài
    • $post[posts] : số bài viết của người post bài
    • $post[joindate] : Ngày gia nhập của người post bài
    • $post[icq] : Nick ICQ
    • $post[yahoo] : Nick YAHOO
    • $post[msn] : Nick MSN
    • $post[skype] : Nick SKYPE
    • $post[signature] : chữ ký người post
    • $post[usertitle] : Title người post bài
     
    Last edited by a moderator: 27/9/15
  3. yeuseo
    Tham gia ngày:
    15/8/14
    Bài viết:
    92
    Đã được thích:
    1
    Điểm thành tích:
    6
    Hàm và biến trong vbb code

    vBulletin Template Conditionals List I have listed some really useful conditionals that are widely used throughout vB. Will keep adding more.

    1. If Viewer is a Member
    • If you want to show a link only to registered members you would use this conditional.
    • <vb:if condition="$show['member']"></vb:if>
    2. If Viewer is in the Following Usergroups Array. Enter the Usergroup Number(s) Seperated by a Comma
    • If you want to show an advertisement to viewers that are unregistered, registered members and awaiting email confirmation you would use the usergroup ids 1,2,3 within the array.
    • <vb:if condition="is_member_of($vbulletin->userinfo, 1, 2, 3)"></vb:if>
    3. If This Script Is or Is Not XXX

    If this script is index (as used in the example below) then it will show the code within the conditional. You can use it to show a piece of code only on Forumhome if you have to put it in a template that is global such as the header. To find out what the script is per page open up the php file that loads the page like for instance showthread.php and look for
    • define('THIS_SCRIPT', 'showthread');
    and the showthread part is what you would use.
    • <vb:if condition="THIS_SCRIPT == 'index'"></vb:if>
    and here you can show information on every page but the index page by using this conditional
    • <vb:if condition="THIS_SCRIPT != 'index'"></vb:if>
    For checking multiple scripts:
    • <vb:if condition="THIS_SCRIPT != 'arcade' AND THIS_SCRIPT != 'adv_index'"></vb:if>
    OR we can use this way as well
    • <vb:if condition="!in_array(THIS_SCRIPT, array('arcade', 'adv_index'))"></vb:if>
    4.If this user equals or does not equal xxx

    What this conditional will do is only show certain information if the person viewing the page has the same userid as defined within the conditional. So if you put userid 667 inside the conditional below and put a link inside the conditional tags only the user that has the userid 667 will see that link.
    • <vb:if condition="$bbuserinfo['userid'] == 667"></vb:if>
    and it works the opposite way as well if you do not want information to show for 667 but you want it to show for everyone else you would use
    • <vb:if condition="$bbuserinfo['userid'] != 667"></vb:if>
    OR we can also use this way
    • <vb:if condition="$vbulletin->userinfo['userid'] == 667">
    5.Display Information To Guests Only
    • The following conditional will display information only to guests and no one else. This is helpful in displaying a welcome message that you only wish for guests to see.
    • <vb:if condition="$show['guest']"></vb:if>
    6.Display Information On a Per Forum Basis

    This conditional allows you to display information on a per forum basis. This can be helpful if you wish to display different advertisements depending on what forum that the user is in. You would simply replace X with the forum id that you wish the information to appear in.
    • <vb:if condition="$forum['forumid'] == X"></vb:if>
    Or this
    • <vb:if condition="$foruminfo['forumid'] == X"></vb:if>
    OR this
    • <vb:if condition="$forumid == X"></vb:if>
    and on the other hand you can use the ! to do the opposite and display the information in every forum but the id you list
    • <vb:if condition="$forum['forumid'] != X"></vb:if>
    or if you have multiple forums you wish to include something with you can use an array such as this
    • <vb:if condition="in_array($forum['forumid'], array(1,2,3,6))"></vb:if>
    OR this
    • <vb:if condition="in_array($forumid, array(1,2,3,6))">
    7.If Usergroup Is or Is Not X

    If the user is a member of the x usergroup then show the code
    • <vb:if condition="$post['usergroupid'] == 6"></vb:if>
    and then you can use the ! to tell it to not show it to the x usergroup but show it to everyone else.
    • <vb:if condition="$post['usergroupid'] != 6"></vb:if>
    8.If Users Birthday is Less Than or Greater Than XXXX-XX-XX Do Something

    Just to show the power of vBulletin here is a cool conditional that will show information based on the birthday of the user. The one below will show "Too Young" if they were born after 01-01-1980.
    • <vb:if condition="$bbuserinfo['birthday_search'] > '1980-01-01'">Too Young</vb:if>
    and this one will show you "Too Young" if the user was born before 01-01-1980
    • <vb:if condition="$bbuserinfo['birthday_search'] < '1980-01-01'">Too Young</vb:if>
    9.If Thread is or is not in X Forum Execute Code

    For instance if you want a piece of code to appear within thread in a particular forum you can do so with this conditional.
    • <vb:if condition="$thread['forumid'] == X"></vb:if>
    If you want to show the piece of code on every new reply on every thread but 1 forum you can use this which says if thread is in forum x do not show the code but show it for all the other threads out side of forum x.
    • <vb:if condition="$thread['forumid'] != X"></vb:if>
    and of course you can define multiple forum ids with the array
    • <vb:if conditional="in_array($thread['forumid'], array(1,2,3,6))"></vb:if>
    10.Is user moderator of any forum?

    If the user is a moderator execute code.
    • <vb:if condition="can_moderate()"></vb:if>
    11.Is user moderator of current forum?

    If the user is a moderator of the current forum execute code
    • <vb:if condition="can_moderate($forum['forumid'])"></vb:if>
    12.Is user moderator of x Forum?

    If the user is a moderator of x forum execute code.
    • <vb:if condition="can_moderate($forum['x'])"></vb:if>
    Note: can_moderate() may add queries to your page.

    13.Is user the thread starter?

    Is the user the thread creator? If so execute code.
    • <vb:if condition="$threadinfo['postuserid'] == $bbuserinfo['userid']"></vb:if>
    14.Is user the thread starter?

    If the thread is closed execute code.
    • <vb:if condition="!$show['closethread']"></vb:if>
    15.Place Information After First Post

    Useful for adding a advertisement or other information after the first post on every page.
    • <vb:if condition="!$GLOBALS['FIRSTPOSTID']"></vb:if>
    16.Place Information After x Post On Every Page

    This will add your code directly after the post number you define on each page. If you put 2 in place of x the code will appear on every page after the second post.
    • <vb:if condition="$post['postcount'] % $vboptions['maxposts'] == x"></vb:if>
    17.Using If Else in Templates

    You can also use If Else conditionals within your templates. The below shows you how to correctly do this.

    <vb:if condition="$show['guest']">
    Show Guest This Message​
    <else />​
    Show Everyone but guests this message​
    </vb:if>
     
  4. yeuseo
    Tham gia ngày:
    15/8/14
    Bài viết:
    92
    Đã được thích:
    1
    Điểm thành tích:
    6
    Hàm và biến trong vbb code

    1.If unread PM

    You can use this conditional within your templates to display something if a user has an unread PM.
    • <vb:if condition="$bbuserinfo['pmunread']"></vb:if>
    2.If unread Notification

    You can use this conditional to display something if a user has any unread Notification (for vB 3.7 onwards).
    • <vb:if condition="$show['notifications']"></vb:if>
    3.If registration enabled

    You can use this conditional to display something if registration is enabled on the board.
    • <vb:if condition="$show['registerbutton']"></vb:if>
    4.If memberlist is viewable

    You can use this conditional to display something if memberlist is enabled/viewable on the board.
    • <vb:if condition="$vboptions['enablememberlist']"></vb:if>
    5.If notice is viewable

    You can use this conditional to display something if displaying of notices conditions are met (for vB 3.7 onwards).
    • <vb:if condition="$show['notices']"></vb:if>
    6.If Style Choosing enabled/viewable

    You can use this conditional to display something if Style choosing dropdown is enabled/viewable in footer
    • <vb:if condition="$show['quickchooser']"></vb:if>
    7.If Language choosing enabled

    You can use this conditional to display something if language choosing is enabled.
    • <vb:if condition="$show['languagechooser']"></vb:if>
    8.If Contact Us link enabled

    You can use this conditional to display something if "Contact Us" is enabled.
    • <vb:if condition="$show['contactus']"></vb:if>
    9.If AdminCP link enabled (or is administrator)

    You can use this conditional to display something if "AdminCP" is enabled (or is administrator)
    • <vb:if condition="$show['admincplink']"></vb:if>
    10.If ModCP link enabled (or is Super Moderator)

    You can use this conditional to display something if "ModCP" is enabled (or is Super Moderator)
    • <vb:if condition="$show['modcplink']"></vb:if>
     
  5. yeuseo
    Tham gia ngày:
    15/8/14
    Bài viết:
    92
    Đã được thích:
    1
    Điểm thành tích:
    6
    Biến trong vbb code

    vB4 Template Conditionals List

    I put this together because it seems lots of people are having problems with the new syntax for conditionals.

    First off remember you can not use {vb:raw var} in template conditionals.

    1.Show only members:

    <vb:if condition="$show['member']">
    Show this to members only​
    </vb:if>​


    2.Show only guest:

    <vb:if condition="$show['guest']">
    Show this to guest only​
    </vb:if>​


    3.Show specific user groups :
    • <vb:if condition="is_member_of($bbuserinfo, 1,2,3)"> Show this to user group 1, 2, and 3 </vb:if>
    4.Show one member:

    <vb:if condition="$bbuserinfo['userid'] == 318713">
    Show this only to the member with the user id of 318713​
    </vb:if>​


    5.Show every one but one member:

    <vb:if condition="$bbuserinfo['userid'] != 318713">
    Show this to every one but the member with the user id of 318713​
    </vb:if>​


    6.Show only moderators of any forum:

    <vb:if condition="can_moderate()">
    Show this to all moderators​
    </vb:if>​


    7.Show Moderator of one forum: Remember to change x


    <vb:if condition="can_moderate($forum['x])">
    Show this if moderator is moderator of the forum with the id of x​
    </vb:if>​


    8.Show Moderator of current forum:

    <vb:if condition="can_moderate($forum['forumid'])">
    Show this to the moderator of the current forum​
    </vb:if>​


    9.Show in one forum: Remember to change x


    <vb:if condition="$forum[forumid] == x">
    Show this if forum id is x​
    </vb:if>​


    10.Show is every forum but one: Remember to change x

    <vb:if condition="$forum[forumid] != x">
    Show this if forum id is not x​
    </vb:if>​


    11.Show in several forums:

    <vb:if condition="in_array($forum['forumid'], array(1,2,3))">
    Show this to forum 1, 2 and 3​
    </vb:if>​


    12.Show in only one file: Look for define('THIS_SCRIPT', 'calendar'), in the top of the php file you want it to show in.


    <vb:if condition="THIS_SCRIPT == 'calendar'">
    Show this only on calendar.php​
    </vb:if>

    13.Show in every file but one: Look for define('THIS_SCRIPT', 'calendar'), in the top of the php file you do not want it to show in.


    <vb:if condition="THIS_SCRIPT != 'calendar'">
    Show this only on calendar.php
    </vb:if>​


    14.If $customvar is set:

    <vb:if condition="$customvar">
    Show this if $customvar is set​
    </vb:if>​


    15.If $customvar equals:

    <vb:if condition="$customvar == blah">
    Show this if $customvar equals blah​
    </vb:if>

    16.If $customvar does not equal:

    <vb:if condition="$customvar != blah">
    Show this if $customvar does not equal blah​
    </vb:if>​


    17.vBulletin else statement:

    <vb:if condition="$show['guest']">
    Show this to only guest.​
    <vb:else />
    Show this to all registered users ​
    </vb:if>​


    18.vBulletin else if statement:

    <vb:if condition="$show['guest']">
    Show this to only guest. ​
    <vb:elseif condition="is_member_of($bbuserinfo, 5,6)" />
    Show this to user group 5 and 6 which is mods and admins ​
    <vb:else />
    Show this to all registered users ​
    </vb:if>​


    This is all that I can think of right now off the top of my head.
    Please feel free to add any I forgot and I will add them to this list and give you credit.
     
    Chỉnh sửa cuối: 3/9/14
  6. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,883
    Đã được thích:
    1,193
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Đầy đủ toàn bộ vbb code rồi đó nhỉ.