[Admin Trick]  Country Flags in Postbit

Electric ShockDivided by Zero
#1
Yesterday, in [this thread] spork sort of challenged me to make this while I replied a negative statement to the plugin request. So, here I am.

Writing all those country names in the box took me 30 damn minutes. What a waste of time..
says who?

Then, without further ado, lets get this started!
1. Admin CP > Configuration > Custom Profile Fields > Add New Profile Field

In the Add Profile Field page, write these details according to their columns:

Title
Code:
Country

Short Description
Code:
In which country do you reside?

Field Type
Code:
Select Box

Maximum Length
(not making a difference since this option is not for select boxes)

Field Length
Code:
15

Selectable Options?

Code:
Afghanistan
African Union
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua & Barbuda
Arab League
Argentina
Armenia
Aruba
ASEAN
Australia
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bosnia & Herzegovina
Botswana
Brazil
Brunei
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Cape Verde
CARICOM
Cayman Islands
Central African Republic
Chad
Chile
China
CIS
Columbia
Commonwealth
Comoros
Congo
Congo-Kinshasa
Cook Islands
Costa Rica
Cote d'Ivoire
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
Egypt
El Salvador
England
Equador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
European Union
Faroes
Fiji
Finland
France
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran
Iraq
Ireland
Islamic Conference
Isle of Man
Israel
Italy
Jamaica
Japan
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Kosovo
Kuwait
Kyrgyzstan
Laos
Latvia
Lebanon
Lesotho
Liberia
Libya
Liechtenstein
Lithuania
Luxembourg
Macao
Macedonia
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mexico
Micronesia
Moldova
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
NATO
Nauru
Nepal
Netherlands Antilles
Netherlands
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
North Korea
Northern Cyprus
Northern Island
Norway
Oman
OPEC
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Poland
Portugal
Puerto Rico
Qatar
Romania
Russian Federation
Rwanda
Saint Lucia
Samoa
San Marino
Sao Tome & Principe
Saudi Arabia
Scotland
Senegal
Serbia
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
Somaliland
South Africa
South Korea
Spain
Sri Lanka
St Kitts & Nevis
St Vincent & the Grenadines
Sudan
Suriname
Swaziland
Sweden
Switzerland
Syria
Tahiti
Taiwan
Tajikistan
Tanzania
Thailand
Timor
Togo
Tonga
Trinidad & Tobago
Tunisia
Turkey
Turkmenistan
Turks & Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United Kingdom
United States of America
Uruguay
Uzbekistan
Vanuatu
Vatican City
Venezuela
Vietnam
Virgin Islands British
Virgin Islands US
Wales
Western Sahara
Yemen
Zambia
Zimbabwe
(ouch)

Display Order
Code:
22
(again this does not matter, put this whatever you want)

Required?
Code:
YES!

Editable by User?
Code:
YES!

Hide on profile?
Code:
NO!

Minimum post count?
(again does not matter, put zero or leave it blank)

2. Fetch the Field ID (FID)
After the new Profile Field has been created, you would be taken back to the page where you came from, except that you have a brand new profile field waiting for you!
[Image: wdJU7Mh.png]
Remember, the ID of the field is not same in every case.
(here it is 5, in most cases it is 4)
Memorize the number that appears as the ID in your screen.

3. Templates & Style > Templates > *your theme* Templates > Post Bit Templates > postbit_author_user
Now comes the markup!
In the template, find:
PHP Code:
{$post['replink']} {$post['warninglevel']} 

Replace with:
Quote:{$post['replink']}<br/>
Country: <img src="http://eshock.Demonate/hosted/flags/{$post['fidX']}.png" alt="{$post['fidX']}" title="This user is from {$post['fidX']}" style="margin-bottom: -6.5px;"/>
<!-- Flag Icons by IconDrawer.com -->
{$post['warninglevel']}
Make sure you replace "X" with the Field ID number I told you to memorize in step 2.

[Image: BlDNXaE.png]
Please do not remove the copyright. Save the template.
Happy coding! Big Grin

What the heck did I do here?
The field stores the country name in its variables.

Now, the flag images are renamed in such a way:
countryname.png

So, if I chose "India", the markup that would be printed is:
India.png

Which returns:
[Image: Zh6x105.png]

And it is different for each user's settings.
[Image: 2IGFwvm.png]

Notes:
1. The flag images (239 images, 171 kB) are hosted on my subdomain on Demonate, so as long as it is online, expect the images to work. Hope effone does not mind! If you ever find it not working, PM me and I will move it to another server.

2. This little experiment can be used as a no-plugin replacement for the "Country Flag in Postbit" plugin.

3. If you understand the racket behind this little addon, and want to be self-dependant on your own host, here is a ZIP package of the flag images.
[link]
[Image: FxbVPSd.png]
Harry K.Xige Time
#2
Good tutorial! Thanks. Smile
[Image: UBJSJ7l.png]
effoneDesigner
#3
Better late than never. Have some rep. Cheers!!!!
ksrTrusted Member
#4
Nice job dude....
[Image: uniqueminds.png]
PrinceTazAnother Demon
#5
How would we modify this to add more country's?
terzierFirefox Lovers &lt;3
#6
how to set up default all members with a particular country? (specifically on my MyBB forum, Indonesia) Suspect
effoneDesigner
#7
^ If you want it to set as default during registration you will need a little core edit for that.
There are also two scenario:

1. It will set country as 'Indonesia' by default, silently, without asking user input and user can change it later from UCP.
2. It will allow user to select the country with initially default value set to 'Indonesia' which user can leave as is or change to applicable one during registration only ...

The edits are slight different for the cases, so we need to know exactly how you want it.
terzierFirefox Lovers &lt;3
#8
@effone.
Yes. I mean that. then (core edit) what changes should be made? Cry
effoneDesigner
#9
You didn't define a scenario yet.
terzierFirefox Lovers &lt;3
#10
(02-21-2014, 10:36 PM)effone Wrote: You didn't define a scenario yet.


(01-27-2014, 12:11 PM)effone Wrote: ...
There are also two scenario:

1. It will set country as 'Indonesia' by default, silently, without asking user input and user can change it later from UCP.
...

with notes: the user user can change it later from UCP, (if necessary) after the account activation process.

Big Grin