dracoblue.net

PHP script to order builds, release numbers and versions

I had the problem, that I wanted to sort an array of builds by name, but names could be 1.1 or, 2.10.0.1 or even 2.0.9.

Thatswhy I made the following sort alogrithm in PHP by using usort and an own compare function.

function builds_sort($a, $b) {
    if ($a['name']==$b['name']) {
        return 0;
    }
    $ap=explode('.',$a['name']);
    $bp=explode('.',$b['name']);
    foreach ($ap as $pos => $number) {
    	if (!isset($bp[$pos])) {
    	  return 1;
    	} elseif ($number > $bp[$pos]) {
    	  return 1;
    	} elseif ($number < $bp[$pos]) {
    	  return -1;
    	}
    }
    return -1;
}
	
// Testarray
$builds=array(
	array("name"=>"2.1.0","id"=>"210","suite_id"=>1),
	array("name"=>"2.1.1","id"=>"211","suite_id"=>1),
	array("name"=>"3.0.0","id"=>"3","suite_id"=>1),
	array("name"=>"10","id"=>"3","suite_id"=>1),
	array("name"=>"2.1.10","id"=>"2110","suite_id"=>1),
	array("name"=>"2.1.2","id"=>"212","suite_id"=>1)
);
	
usort ($builds,"builds_sort");

This function sorts each element by "name" with DESC.

In open source, php by DracoBlue @ 2007-11-06 | 108 Words

Workaround for UTF-8 issues with PHP's imagestring

Some of you may have expirienced the issue, that php's

imagestring-function doesn't properly show UTF-8 characters.

As workaround you can use the imagettftext-function.

When using imageTTFtext instead of imagestring, you have to know, that you don't use the $font-ids from PHP, instead you use fontfiles.

So:

imagestring ( resource $im, int $font, int $x, int $y, string $s, int $color )

becomes to:

imagettftext ( resource $im, int $size, int $angle, int $x, int $y, int $color, string $fontfile, string $text ) 

Keep $angle=0 if you want just horizontal-text. Hope that helps!

In open source, php, utf-8 by DracoBlue @ 2007-11-04 | 94 Words

Quick-Edit button broken in Simple Machines Forum

Thanks to Korl for pointing out, that the QuickEdit-Button in SMF won't work in locked topics, even if the user has rights to do so.

I took some minutes and found out what the reason was, the [em]$moderate_boards[/em] variable is not set properly and not even loaded.

Quickfix:

Open

Sources/Post.php

Replace line 2050f (containing the following):

(!isset($_REQUEST['modify']) || (!empty($moderate_boards) && $moderate_boards[0] == 0) ? '' : '
AND (t.locked = 0' . (empty($moderate_boards) ? '' : ' OR b.ID_BOARD IN (' . implode(', ', $moderate_boards)) . ')')

And replace it with:

""

Now put right after the

		mysql_free_result($request);

in line 2059 the following:

 		if (!empty($row['locked'])) isAllowedTo('moderate_board');

Thats it, have fun! Bugreport with Fix has been

posted at official SMF-Site.

In open source, php, smf by DracoBlue @ 2007-10-28 | 119 Words

.innerHTML vs. value in textarea

Some of you may already noticed, that .innerHTML of an html-object like textarea may not be changed if you edited the objects content manually.

For example setting a textarea's innerHTML won't result in any changes if you do it, right after you manually added text to the textarea.

To workaround this issue, you should always use .value on textarea-fields, even though its declared as:

<textarea>inner html</textarea>

In HTML, JavaScript, open source by DracoBlue @ 2007-10-23 | 67 Words

Mines updates and bugfixes

Today I fixed some serious issues, which could have appeared when using mines on the GTA:Tournament-Servers.

Also I added some neat new functions for our GameMasters (a godmode detection module and a info module which shows stats and some other cool stuff of the player).Â? Most coding has been done by elyks for those two modules, so big thanks again!

In GTA:Tournament, Project by DracoBlue @ 2007-10-15 | 60 Words

Page 38 - Page 39 - Page 40