Topic: [patch release] Place category in the Forums header, save space

<?php
/**
 * PunBB Patch: Place category in the Forums header instead of using extra vertical space.
 * This means that category headers will be collapsed - the category is shown before 'Forums' instead.
 * The line 'Forums,...Topics,.., Posts,...' becomes 'CATEGORY Forums,...Topics,.., Posts,...'
 * ---------------------------------------------
 * Patch is compatible at least with PunBB 1.3.4
 * Important: Needs write permissions for index.php
 * A backup of index.php is created automatically
 * HowToUse: Place this in the same directory as index.php, then open (execute) it.
 * Patch uses NC-patch-engine v1.1
 */

//files
$file_to_patch = 'index.php';
$file_backup = 'index.php.bak';

//patches
$patches[0]['pattern'] = '/<h2 class=\"hn\"><span><\?php echo forum_htmlencode\(\$cur_forum\[\'cat_name\'\]\)/i';
$patches[0]['replacement'] = '<h2 class="hn" style="display:none"><span><\?php echo forum_htmlencode($cur_forum[\'cat_name\'])';
$patches[1]['pattern'] = '/<strong class=\"subject-title\">\'\.\$lang_index\[\'Forums\'\]/i';
$patches[1]['replacement'] = '<strong class="subject-title">\'.$cur_forum["cat_name"].\' \'.$lang_index["Forums"]';






$error = 0;
//does patch target exist
if (!file_exists($file_to_patch)){
    echo 'Cannot find index.php - patch failed!';
    exit;
}

//try to make a backup
$backup = file_get_contents($file_to_patch);
try{
    if (!file_exists($file_backup))
        file_put_contents($file_backup, $backup);
}catch(Exception $e){;}

//make sure backup exists
if (!file_exists($file_backup)){
    echo 'Could not write backup file '.$file_backup.' Patch abortet. Nothing has been modified!';;
    exit;
}

//do the patch work
$matches = 0;
$array_of_lines = explode("\n", file_get_contents($file_to_patch));
$num_lines = count($array_of_lines);
try{
    for ($i = 0; $i < $num_lines; $i++)
    {
        $k = 0;
        while(isset($patches[$k])){
            if (preg_match($patches[$k]['pattern'], $array_of_lines[$i], $results)) {
                $matches++;
                $array_of_lines[$i] = preg_replace($patches[$k]['pattern'], $patches[$k]['replacement'], $array_of_lines[$i]);
            }
            $k++;
        }
    }
}catch(Exception $e){$error++;}

//write patched bytes back to file
try{
    if(!$error)
        file_put_contents($file_to_patch, implode("\n", $array_of_lines));
}catch(Exception $e){$error++;}

//give the user something to read
echo (!$error && $matches) ? $matches.' lines have been patched. Now try the modified file.' : 'File already patched or wrong version of '.$file_to_patch.'. Nothing has been modified!'

?>

Create a new php file, place code inside and run in index.php directory (needs write rights).

Re: [patch release] Place category in the Forums header, save space

I think it could be an extension.

Re: [patch release] Place category in the Forums header, save space

Are you sure?
I tried to make it an extension but I must admit that I had no idea how to do it.

Re: [patch release] Place category in the Forums header, save space

The goal of the extension system is to add or modify the forum functionality without touching the code smile

I'll see later if it's possible in your case.

Re: [patch release] Place category in the Forums header, save space

The goal of the extension system is to add or modify the forum functionality without touching the code

Yes I know, however I did not find a better solution.
I won't publish a patch again! (only extensions)