Categories
vBulletin Tips

vBulletin: How to add more buttons to quick reply box toolbar?

When people are replying to a thread, going advanced editing would require an extra click as well as page loading time – very inconvenient. However, at gotalk.org, users would generally want to post a lot of code because it’s a programming language forum in nature. But vBulletin doesn’t come with a CODE button in the quick reply editor toolbar by default.

So I’ll have to add the CODE button to the quick reply box myself.

How to add extra buttons to the toolbar of the quick reply editor? (v4.1.2)

Just copy and paste the buttons code from the advanced editor to the quick reply editor. The advanced editor template is “editor_toolbar_on” while that of the quick reply editor is “showthread_quickreply”. All we have to do is to copy some code from “editor_toolbar_on” to “showthread_quickreply”.

In the example below, I’ll add the CODE button from the advanced editor to the quick reply editor. You can add other buttons to the quick reply box in similar steps.

1. Open “editor_toolbar_on” template

From /admincp, Styles & Templates –> Style Manager –> click “Search in Templates” –> in the “Search for Text” box, enter “editor_toolbar_on” –> click “Find” –> double click “editor_toolbar_on” in the left selection.

2. Open “showthread_quickreply” template

From /admincp, Styles & Templates –> Style Manager –> click “Search in Templates” –> in the “Search for Text” box, enter “showthread_quickreply” –> click “Find” –> double click “showthread_quickreply” in the left selection.

3. Find the code for CODE button in the “editor_toolbar_on” template

Simply search for:

$show['code_bbcode']

In the “editor_toolbar_on” template and you would find a code block like this:

<vb:if condition="$show['code_bbcode'] OR $show['html_bbcode'] OR $show['php_bbcode']"> <li> <vb:if condition="$show['code_bbcode']"><img src="{vb:stylevar imgdir_editor}/code.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_code" width="20" height="20" alt="{vb:rawphrase wrap_code_tags}" /></vb:if> <vb:if condition="$show['html_bbcode']"><img src="{vb:stylevar imgdir_editor}/html.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_html" width="20" height="20" alt="{vb:rawphrase wrap_html_tags}" /></vb:if> <vb:if condition="$show['php_bbcode']"><img src="{vb:stylevar imgdir_editor}/php.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_php" width="20" height="20" alt="{vb:rawphrase wrap_php_tags}" /></vb:if> </li> </vb:if>

Copy this code block, and switch to the “showthread_quickreply” template.

4. Add the code in the “showthread_quickreply” template

Search for:

$show['quote_bbcode']

And you would find the code for the QUOTE button:

<vb:if condition="$show['quote_bbcode']"> <li class="editor_control_group_item"> <img src="{vb:stylevar imgdir_editor}/quote.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_quote" width="20" height="20" alt="{vb:rawphrase wrap_quote_tags}" /> </li> </vb:if>

Immediately below the QUOTE button block, paste what you just copied from the “editor_toolbar_on” template, and add a class=”editor_control_group_item” to the <li> element:

<vb:if condition="$show['quote_bbcode']"> <li class="editor_control_group_item"> <img src="{vb:stylevar imgdir_editor}/quote.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_quote" width="20" height="20" alt="{vb:rawphrase wrap_quote_tags}" /> </li> </vb:if> <vb:if condition="$show['code_bbcode'] OR $show['html_bbcode'] OR $show['php_bbcode']"> <li class="editor_control_group_item"> <vb:if condition="$show['code_bbcode']"><img src="{vb:stylevar imgdir_editor}/code.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_code" width="20" height="20" alt="{vb:rawphrase wrap_code_tags}" /></vb:if> <vb:if condition="$show['html_bbcode']"><img src="{vb:stylevar imgdir_editor}/html.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_html" width="20" height="20" alt="{vb:rawphrase wrap_html_tags}" /></vb:if> <vb:if condition="$show['php_bbcode']"><img src="{vb:stylevar imgdir_editor}/php.png" class="imagebutton" id="{vb:raw editorid}_cmd_wrap0_php" width="20" height="20" alt="{vb:rawphrase wrap_php_tags}" /></vb:if> </li> </vb:if>

Click “Save” or “Save and Reload”. Done!

Now refresh any thread page and you’ll see the CODE button as well as the HTML code button and PHP code button are all added to the toolbar of the quick reply editor. Following the same steps, you can add other buttons from the advanced editor to the quick reply editor.

(This is for vBulletin 4.1.2)

Categories
vBulletin Tips

vBulletin: Change default height of editor and quick reply box

The quick reply box of vBulletin is by default about 100px or less in height which is bit small for large chunks of text editing such as code. To change the default height of the quick reply box without having to click the enlarge button manually every time, you’ll have to edit the template:

Changing default height of quick reply box

After you have logged in the /admincp:

Styles & Templates –> Style Manager –> Edit Templates (in the dropdown menu) –> double click Show Thread Templates (in the left selection of all the templates) –> double click “showthread_quickreply” –> search for “rows=” and you will arrive at the line you should edit.

However, just updating the rows property to a larger one won’t work, you have to manually add a style property like this:

rows="10" tabindex="1" cols="80" style="height:25em;" dir="{vb:stylevar textdirection}"

25em indicates that the quick reply box will be able to accommodate 40 lines of text within one scroll.

Now click “Save”.

Changing default height of advanced editor

The steps to change the default height or size of the advanced message editor in vBulletin goes similar. Instead of “showthread_quickreply”, just search for “editor_toolbar_on”. Search for “row=” or “textarea” and you will find the editor control. Add a style property just the same:

rows="10" tabindex="1" cols="80" style="height:40em;" dir="{vb:stylevar textdirection}"

These steps are for vBulletin 4.1.2. Some of the tutorials you can find for changing the default height of the editing boxes are a bit outdated and for older versions.

Categories
Content / SEO Tips & Tutorials vBulletin Tips

How to Change the Homepage Title of vBulletin Forum?

By default, only the forum name / title is displayed in the <title></title> tag of the homepage of your vBulletin forum, which is far from ideal in terms of SEO. One should give a much more descriptive title to the home page of the forum other than the mere name of it.

To do this:

  1. Log in to the /admincp of your vBulletin forum
  2. From the left administrative menu, Styles & Templates –> Style Manager –> Select Edit Templates in the right drop down of the current style set.
  3. In the left selection of templates, double click Forum Home Templates –> double click FORUMHOME.
  4. Now opens the homepage template of your forum, search for ‘<title>’ and you would find the HTML tag to edit.
  5. Add something descriptive and keywords-rich in the <title></title> tag and click Save.
  6. Done!

vBulletin is such a sophisticated application with a very large user base. Took me some time to find this solution. Hope it helps! Check out how I changed the homepage title of the forum for Go.

Categories
SQL / MySQL Tips and Tutorials

MySQL Performance Tips

MySQLI’m not an expert but I’ve had my own errors and trials along the way so here I am. These are all the tips I believe you should use when you are optimizing for MySQL database performance. Some stuff may be very handy, but they may not be good for performance.

Design

  1. Normalize first, and de-normalize where appropriate. Table joins are never lags in performance. Use them!
  2. Choose the appropriate collation / charset. UTF16 is omnipotent but it requires 2 times the storage. UTF8 delivers more characters but it’s slower than latin1. Unless it’s necessary, use latin1.
  3. utf8_general_ci is slightly faster than utf8_unicode_ci, thus better in performance.
  4. Use NOT NULL wherever possible.
  5. Use indexes. Create indexes by analyzing the SELECTs you are doing on the table.
  6. Indexing increases performance in selecting, yet decreases performance in inserting. So don’t index everything but only those necessary. And don’t make duplicate indexes.

Querying

  1. Use smallest data types possible.
  2. IN (…) is a total fail. Avoid it wherever possible.
  3. ORDER BY RAND() is a fail too.
  4. When you need to SELECT … to make sure there’s no duplicate unique index values before inserting something, use INSERT … ON DUPLICATE KEY UPDATE … instead.
  5. If your app writes a lot, use InnoDB; if it reads a lot, use MyISAM. Here’s a comparison.
  6. Never use LIMIT xxxx1, xxxx2 with large tables especially when offset xxxx1 is a pretty large number. Instead, give a more strict WHERE … clause with LIMIT xxxx2.
  7. If a feature is deprecated, stop using it.
  8. Avoid wildcards % or _ at the beginning of LIKE queries, e.g. LIKE ‘%bloom’ – this should be avoided. For instance, you should store email addresses reversed (REVERSED()) so it’s faster to search by domain.
  9. If you have a large set of data rows to be inserted at once, create a combined INSERT query string in PHP first – that is, to bulk insert them in batches rather than one by one. LOAD DATA is also a better option than individual INSERT.
  10. Prefer GROUP BY over DISTINCT.
  11. Frequently visit Slow Query Log.
  12. Avoid calculated values in WHERE … , LIMIT … , ORDER BY … , etc.
  13. Use EXPLAIN … to get an idea of how MySQL is doing with your queries thus better optimize it. For example, it would suggest the indexes you should have created.
  14. Don’t SELECT * … on everything, SELECT only what you need.
  15. Be wary of lots of small queries that may be triggered in loops. Instead, combine them and use one large query wherever possible.

Storage Engines

  1. Know the pros and cons of different storage engines and use them accordingly. But try them out in the test environment before making the decision.
  2. Archive old data such as logs in ARCHIVE tables or MERGE tables.
  3. BLACKHOLE engine is very fast for busy things like logs.

my.ini

  1. Increase the default key buffer size: key_buffer = 128M
  2. Increase the default number of tables that can be kept open: table_cache = 128
  3. Increase the default sort buffer size:
    sort_buffer_size = 32M
    myisam_sort_buffer_size = 32M
  4. Disable binary logging that is for data replication by commenting out the line like this:  # log-bin=mysql-bin

What to read from here:

  1. Indexing: http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
  2. “LIMIT” Optimization: http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html
  3. “ORDER BY” Optimizationhttp://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
  4. Efficient Paging: http://www.slideshare.net/suratbhati/efficient-pagination-using-mysql-6187107
  5. Configuration Tweaks: http://docs.cellblue.nl/2007/03/17/easy-mysql-performance-tweaks/
Categories
SQL / MySQL Tips and Tutorials

MySQL: Get the exact size of a database by SQL query

phpMyAdmin doesn’t show the exact size in MB when the size of your database exceeds 1GB. It just shows something like 4.2GB, truncating everything out in the 100MB precision. So is it possible to get the database size in MB in exact numbers using MySQL query?

Yes, it is:

SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like 'YOUR_DATABASE_NAME_HERE%' ;

Just change YOUR_DATABASE_NAME_HERE into the name of your database. And it would prints out something like this:

+------------+
| Size       |
+------------+
| 4906.79 MB |
+------------+
1 row in set (0.05 sec)

You can also get the size of a specific table. Read here: http://www.novell.com/communities/node/8706/check-mysql-database-size-using-sql-query

Categories
CSS & HTML Tips

Pure CSS Rounded Corner, No Images

Though it does look great, I haven’t given it a try until the other day when I was developing smartbabynames.com. Notice the previous and next link immediately below the boy image at here:

http://www.smartbabynames.com/meaning/boy/Langleigh/

They look and feel great.

So here’s what I’ve done to achieve the rounded corner box in pure CSS – no images nor whatever. Just CSS:

.rounded {
	-moz-border-radius: 2px;
	-webkit-border-radius: 2px;
	-khtml-border-radius: 2px;
	border-radius: 2px;
}

Tested across major modern browsers other than IE. Sure it doesn’t work in IE6, but not sure if it works in IE7, IE8, IE9, etc. But let me know if you know.

Categories
SQL / MySQL Tips and Tutorials

MySQL: Find non-ASCII characters in a table column

ASCII is the most fundamental character set that has been around since the early days of command line interfaces. There are 128 (0 – 127) most basic ASCII characters such as a-z, A-Z, 0-9, and all the printable punctuations you can type out by a single strike of your keyboard.

As all ASCII characters have an internal decimal value of 0 – 127, which is 0x00 – 0x0F in heximal values, you can find all the non-ASCII characters in my_column by query:

SELECT * FROM my_table WHERE NOT HEX(my_column) REGEXP '^([0-7][0-9A-F])*$';

On the other hand, if you wish to find all records that a certain column (my_column) contains ASCII characters:

SELECT * FROM my_table WHERE HEX(my_column) REGEXP '^([0-7][0-9A-F])*$';