Creating Php nuke Blocks from Scratch
I am going to teach you everything you need to know about creating Php nuke blocks from scratch. The built in editor for creating new blocks that comes with the latest distributions or forks of php nuke can not handle a lot of custom coding like some javascript for example. So this is almost a necessary evil and you need to learn how to do this the old fashion way if you plan to customize your nuke site.
Where are all my current Php Nuke Blocks located?
All of your existing blocks are located in your blocks folder just below your nuke root. So if your nuke root directory is public_html then the path to blocks folder is public_html/blocks. This is standard for every distribution or fork of nuke I have ever seen. When you create a new block it should be placed in your blocks folder or else you will not be able to add it via the nuke admin panel.
Block File Names
Php nuke blocks have a particular naming schema they use to identify themselves as blocks. They use block-your_name.php, broken down block- is the prefix and anything the rest uses underscores in replacement for spaces. This format is used so php nuke can list them for you in the admin section. That list I am referring too is the drop down you see when you are adding a new block.
This is how that list is formed and why the naming schema is so important.
$blocksdir = dir("blocks");
$blockslist = '';
while($func=$blocksdir->read()) {
if(substr($func, 0, 6) == "block-") {
$blockslist .= "$func ";
}
}
closedir($blocksdir->handle);
$blockslist = explode(" ", $blockslist);
sort($blockslist);
for ($i=0; $i < sizeof($blockslist); $i++) {
if($blockslist[$i]!="") {
$bl = ereg_replace("block-","",$blockslist[$i]);
$bl = ereg_replace(".php","",$bl);
$bl = ereg_replace("_"," ",$bl);
echo "<option value=\"$blockslist[$i]\" ";
if ($blockfile == $blockslist[$i]) { echo 'selected="selected"'; }
echo ">$bl</option>\n";
}
}
Noob Note: I would avoid using any type of punctuation or special characters when deciding your block filename. Best practice would be to simply use underscores ( _ ) to identify a space. (ex: block-New_Block.php)
The above code pretty much says that if the block isn’t already active and being used, put it in this list of available or new blocks that can be added. So if you want your title in the list to show up as “New Block“, then your actual block filename is block-New_Block.php. If your naming schema is correct and it exist in your blocks folder, you should be all set here.
Coding Syntax
So I have created a file on my desktop named block-New_Block.php and I have opened it in my text editor of choice, UltraEdit. I suggest not using windows notepad for editing scripts as it sometimes interrupts code differently or removes needed characters upon saving. Your better off using a high end editor like notepad++ or UltraEdit. If all your ever going to do is create blocks, then something free like notepad++ should do.
I use a standard snippet for each block I create because it saves a lot of time and I don’t have to remember all that syntax everytime I want to toss an image into a new block. My snippet looks like this.
<?php
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
//Require Mainfile (once means don't if its already included/required)
require_once 'mainfile.php';
//Set Your Globals
global $db, $prefix;
//Start Content
$content = 'my content';
$content .= 'my content continued';
$content .= 'my content continued again';
//End Content
?>
I am going to break that down into sections so we can discuss what each part does. The first line of course is the opening statement <?php.
Noob Note: Do not use shorthand here as your script might not work and it is just a bad php practice. When I stay shorthand I am referring to using <? instead of <?php. <?php is the correct way of doing things.
Lines 2-5 of the above block snippet are a security check to reassure that this an actual block file for php nuke. The catch here is for some distributions like Nuke Evolution, it can be different. The best way to figure out what you should use is to grab the block-Modules.php file from your blocks folder and duplicate the security check. I believe this all started with ChatServ Patches, but don’t quote me on it. So lines 2-5 for you might be different from mine depending on what distribution or patch level your using.
Line 6 & 7 are the inclusion of mainfile.php which contains the majority of the nuke functions. I have set it to require_once just as a good practice to make sure we didn’t conflict with another module / block. It is a good practice.
//Require Mainfile (once means don't if its already included/required) require_once 'mainfile.php';
Next is the globals, if your going to be pulling something from the database or using functions from mainfile.php you will need some of these. I have only included the main two so we can use the database. Some other basic ones are $user, $admin, $nukeurl, and $cookie.
//Set Your Globals global $db, $prefix;
Last, but surely not least is the inclusion of the $content string. One php concept you need to understand about building blocks is string operators and string concatenation. Basically, it is how to join two string instances together. I call it continuation, but whatever floats you.
You will notice below how this technique is used to continue a string.
//Start Content $content = 'my content'; $content .= 'my content continued'; $content .= 'my content continued again'; //End Content
As you can see we continue the $content string by using $content .= . You don’t have to concatenate with the $content either you can use a different string name. However at the end of the block $content must be used. See below.
<?php
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
//Require Mainfile (once means don't if its already included/required)
require_once 'mainfile.php';
//Set Your Globals
global $db, $prefix;
//Custom Variable
$myblock = 'my content';
$myblock .= 'my content continued';
$myblock .= 'my content continued again';
//End Custom Variable
//Define Custom Variable as $content
$content = $myblock;
?>
Your code can be a simple or complex as you wish to make it, but those are the very basics to creating your own phpnuke blocks from scratch.
Trick for Beginners
Another decent trick I used when I first started creating blocks that my good friend Ped taught me so many years ago was this one.
<?php
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
//Require Mainfile (once means don't if its already included/required)
require_once 'mainfile.php';
//Set Your Globals
global $db, $prefix;
//Start Content
?>
<!-- Close Php Tag -->
<!-- Paste Html or Javascript Content Here-->
<!-- Now Open the Php Tag again -->
<?php
$content = 'You can include more php content here';
$content .= 'and here';
$content .= 'or here';
//End Content
?>
This technique allows you to combine html or javascript with php very easily. I found most useful when I ran across 3rd party websites that required me to include some javascript they provided. I don’t suggest becoming addicted to using that method, because it has its limitations. However, as a beginner your end goal is most likely to just get it working.
Uploading and Activating your Php Nuke Block
I sort of feel I don’t need to go into this in much detail if you have gotten this far. Basically, your gonna upload the nuke block to your blocks folder and activate it (or add new) through that drop down we discussed in the beginning of the tutorial via the nuke blocks admin panel.
If you are confused by any of this you should watch Dread’s Phpnuke Block Break Down Video Tutorial.
Thanks for reading and I hope it will be as useful to you as it has been to me.
Related posts:





July 29, 2010 at 2:20 am | Eloise Deruso
good good good stuff. It was a great read and a great way to waste time lol. But I like your article though.