Archive

Archive for December, 2010

how to add IRC to your vBulletin forum/CMS

December 19th, 2010 1 comment

goal: create a tab that features the webclient of quakenet or freenode to choose from :)

first, we need to add some tab to the navigation bar:

1. Create a plugin in the Admin Control Panel under (Plugins & Products) > Add New Plugin:
2. set hook location to "process_templates_complete"
3. set Title to "IRC TAB for navbar" (wont get displayed)
4. add the following php code:

1
2
3
4
5
6
7
8
9
10
11
12
13
$tabselected = '';
$tablinks = '';
if (THIS_SCRIPT == 'irc')
{
    $vbulletin->options['selectednavtab']='irc';
    $tabselected = ' class="selected"';
    $tablinks = '                <ul class="floatcontainer">
                        <li>Quakenet IRC</li>
                        <li>FreeNode IRC</li>
                </ul> '
;

}
$template_hook['navtab_end'] .= '<li'.$tabselected.'>Chat'.$tablinks.'</li>' ;

5. after that, create a new file in the web folder (/) named "irc.php":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'irc');
define('CSRF_PROTECTION', true);
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array('irc');
$actiontemplates = array();
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

$navbits = construct_navbits(array('' => 'irc'));
$navbar = render_navbar_template($navbits);
$pagetitle = 'IRC Chat';

$templater = vB_Template::create('irc');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);

$network='quakenet';
if(isset($_GET['network']))
 $network = addslashes($_GET['network']);
$templater->register('irc_network', $network);

if($vbulletin->userinfo['userid'] == 0)
 // guest
 print_no_permission();

$templater->register('username', $vbulletin->userinfo['username']);

print_output($templater->render());
?>

6. add the template required for rendering the new page:
in the admin control panel > Styles & Templates > Style Manager > (select "add new template" from your style)

style title: irc
template:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}">
<head>
{vb:raw headinclude}
{vb:raw headinclude_bottom}
{vb:raw header_scripts}
</head>

<script language="javascript">
<!--
window.onbeforeunload = function(){ return 'When you close this site the chat will also stop.';}
-->
</script>

<body>

{vb:raw header}
{vb:raw navbar}

<vb:if condition="$irc_network == 'quakenet'">
<iframe src="http://webchat.quakenet.org/?nick={vb:raw username}&channels=rigsofrods&uio=OT10cnVlJjExPTUx91" width="100%" height="400"></iframe>
</vb:if>

<vb:if condition="$irc_network == 'freenode'">
<iframe src="http://webchat.freenode.net?nick={vb:raw username}&channels=rigsofrods" width="100%" height="400"></iframe>
</vb:if>

{vb:raw footer}
</body>
</html>

thats it, should work well :)

(you should replace "rigsofrods" with your own channel ;)

(used this tutorial: http://www.vbulletin.org/forum/showthread.php?t=226914)

demo: http://www.rigsofrods.com/irc.php

Categories: coding, php Tags:

convert binary file to c array – python one-liner

December 7th, 2010 No comments

very easy ;)

1
import textwrap; s=open('your-binary-file.bin', 'rb').read().encode("hex").upper(); t="".join(["\\x"+x+y for (x,y) in zip(s[0::2], s[1::2])]) ; print "static const char foo[] = \\\n\t\"%s\";"%"\" \\\n\t\"".join(textwrap.wrap(t,80))

example output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
static const char foo[] = \
        "\xD4\x7B\x1F\x43\xD7\x71\xD8\xDD\xF9\x86\x48\x24\x19\xB9\xCD\xF3\x84\xA6\x28\x8A" \
        "\x7D\x2B\xAA\x70\x6A\x8E\xBF\xF9\x6E\x86\xEE\x53\x20\x52\x4F\x8E\x11\x49\x8A\x7E" \
        "\x55\xE3\x5F\xE6\xF2\x5A\x6C\xDD\x25\xC7\x05\xB1\xDF\x20\x8C\xBA\x5A\xFC\x86\x6D" \
        "\x28\x3A\x7F\xEB\x1E\xE2\xB8\x2D\x4F\x75\x95\xEA\xE5\xE2\x9D\x29\xD7\x9C\xA0\x63" \
        "\x4D\x53\xEF\xCF\x7F\xBB\x95\xB5\x27\x8F\x36\xC3\xF8\xFE\x2B\xAE\x56\xA9\x85\xBA" \
        "\xFE\x91\x1B\x70\x87\x68\x36\x11\xC9\x60\xF7\xEE\x67\x13\x98\x36\x3E\xC1\x53\x18" \
        "\x33\x4B\x00\x32\x59\x1C\xD6\x30\x43\x77\xD8\xAD\xC3\x5D\x9A\x0A\x69\x93\xA1\x1D" \
        "\xA7\x10\x05\xE4\x56\x71\x92\xF6\x24\x1B\xE7\x84\x15\xAC\xDC\x2A\x46\xE0\xC1\xF8" \
        "\xF7\xDC\xE2\x11\x0A\xF6\xF3\xCB\x51\x5F\x57\x0D\x68\x84\x64\x22\xD8\xEA\x25\x6B" \
        "\xCC\xB5\x52\xF9\xD8\xD5\x00\x76\x6F\x66\xDF\x06\x42\xE9\x09\x8C\x1C\xBF\x1D\xAC" \
        "\x73\x32\x38\x56\xAE\x79\xED\x39\x83\x53\x76\x3D\xD4\x06\x67\x23\x39\x15\x5B\xB4" \
        "\xB0\x51\x75\xE3\xBA\xF4\xE3\xB5\x16\x69\xE5\xCB\x7B\xD3\x6D\x59\x07\x8D\xEB\xEA" \
        "\xA2\xB5\x82\x53\x10\xC6\xE7\xB7\x01\x6B\x58\xE1\xE3\x45\xA2\xC8\xA6\x71\xD0\xBB" \
        "\xA7\xEE\xDB\x76\x18\x5B\xF8\x55\x59\x86\x8B\x66\x1C\x66\x2A\x1E\x23\x02\xA2\xBC" \
        "\x9B\x42\xE5\xF0\x7D\x67\xCA\x0D\x06\x8D\xD0\x96\x1B\x46\xF7\x35\x25\x14\x40\xC9" \
        "\x7A\xEA\x65\xB0\xC0\x3C\xC2\x13\xA9\xE7\x50\x1C\xB4\xC8\xDF\xED\x4B\xF9\xFA\x3C" \
        "\x53\xDA\xE6\x7E\xDF\x38\x73\x3D\xF2\xC8\xFB\xF4\x1C\x66\x27\xDD\xC1\x2B\x06\x1C" \
        "\x78\x03\x70\xB9\xAC\x84\x1D\x7F\x22\xAF\xF3\xFC\x31\x6F\x8A\x5D\x5A\x6E\x03\x45" \
        "\x6C\x4F\xD6\xC2\xD0\xE9\x02\x82\x3C\x81\x7E\xF7\x70\xFB\xA8\x6E\x54\xEB\xCE\xF7" \
        "\xFB\x8C\xA2\x10\x1F\x65\x17\x7C\xB7\x3A\x0E\x17\x0E\xE3\xD1\x9C\x6E\x9B\x64\xBD" \
        "\x97\x7F\xEE\xFB\x33\x82\x97\x24\xA2\xE2\xAE\x87\xFB\xAD\xD2\xD1\x48\x24\x73\xC1" \
        "\x6C\x77\x1B\xE7\xF7\xAF\xFA\xBB\x11\x0A\xF9\x91";

thanks to soeren! :)

Categories: coding, python Tags:

resolve symbols for android’s ndk-gdb

December 6th, 2010 No comments

very simple if you know how:

1
2
cd <your-android-ndk-project-dir>
cp <path-to-mydroid-dir>/out/target/product/generic/symbols/system/lib/* obj/local/armeabi/
Categories: android, coding Tags: