Color & BgColor Clickable BBCode Bar Mod installation

When I attempted to install the Color & BgColor Clickable BBCode Bar mod on a Simple Machines Forum (SMF) 2.0.13 forum I saw an "Error in Packages" message:

Error in Package Installation
At least one error was encountered during a test installation of this package. It is strongly recommended that you do not continue with installation unless you know what you are doing, and have made a backup very recently. This error may be caused by a conflict between the package you're trying to install and another package you have already installed, an error in the package, a package which requires another package that you don't have installed yet, or a package designed for another version of SMF.

And I saw Test failed for modifications to two files:

TypeAction Description
Execute Modification./Themes/default/GenericControls.template.php Test Failed
Execute Modification./Themes/default/style.css File not found

For error due to the missing file, style.css, I created an empty file named style.css in the Themes/default directory for the forum software. When I then again attempted the install, I saw "Test successful" for the modification to style.css. The installation process makes the following "Add Before" change:

Code: (Find) [Select]
?>
Code: (Add Before) [Select]

/* Color Bar CSS Class */
.colorbar {
width:450px;
}
.colorcell {
height:18px;
}
.colorbox {
border-color:#808080;
border-width:1px;
border-style:solid;
width:18px;
height:18px;
overflow:hidden;
}
.colorboxspacer {
width:18px;
height:18px;
}

Though the style.css file I created was completely empty, i.e., there was no ?>, which is used to close a segment of PHP code, the test was successful. The other test was an "Add After" test where the installation process was looking for the following code:

Code: (Find) [Select]
if (!isset($context['disabled_tags']['color']))
echo ' <select name="sel_color" id="sel_color" style="margin-bottom: 1ex; font-size: x-small;">
<option value="" selected="selected">', $txt['change_color'], '</option>
<option value="black">', $txt['black'], '</option>
<option value="red">', $txt['red'], '</option>
<option value="yellow">', $txt['yellow'], '</option>
<option value="pink">', $txt['pink'], '</option>
<option value="green">', $txt['green'], '</option>
<option value="orange">', $txt['orange'], '</option>
<option value="purple">', $txt['purple'], '</option>
<option value="blue">', $txt['blue'], '</option>
<option value="beige">', $txt['beige'], '</option>
<option value="brown">', $txt['brown'], '</option>
<option value="teal">', $txt['teal'], '</option>
<option value="navy">', $txt['navy'], '</option>
<option value="maroon">', $txt['maroon'], '</option>
<option value="limeGreen">', $txt['lime_green'], '</option>
</select>';
Code: (Add After) [Select]
			
// if both color and bgcolor are disabled
if (!isset($context['disabled_tags']['color']) || !isset($context['disabled_tags']['bgcolor'])) {

echo '<script language="javascript" type="text/javascript">
function bbc_highlight(something, mode)
{
something.style.backgroundImage = "url(" + smf_images_url + (mode ? "/bbc/bbc_hoverbg.gif)" : "/bbc/bbc_bg.gif)");
}
';
// define the image dir
echo 'var cbid = "', $settings['default_theme_url'],'/images/bbc/";
';
// define the settings for javascript purposes
echo 'var usecolor = ', (!isset($context['disabled_tags']['color'])) ? 1 : 0 , ';
';
echo 'var usebgcolor = ', (!isset($context['disabled_tags']['bgcolor'])) ? 1 : 0 , ';
';
// use array to quickly write all the language strings since javascript can't read php language strings
$lang = array(
'yourtexthere', 'insert', 'changetoinsertcolor', 'changetoinsertbgcolor',
'switchbetween', 'insertlastclicked', 'insertlasthovered'
);
// WRITE EACH VAR WE MAY USE
foreach($lang as $var) {
echo 'var '.$var.' = "'.$txt[$var].'";
';
}

// call colorbar.js which has the javascript in
echo '</script>
<script language="javascript" src="', $settings['default_theme_url'], '/color.js" type="text/javascript"></script>';
}

But the actual relevant code in the Themes/default/GenericControls.template.php file was as follows:


					if (!isset($context['disabled_tags']['color']))
						echo ',
							{
								sType: \'select\',
								sName: \'sel_color\',
								oOptions: {
									\'\': ', JavaScriptEscape($txt['change_color']), ',
									\'black\': ', JavaScriptEscape($txt['black']), ',
									\'red\': ', JavaScriptEscape($txt['red']), ',
									\'yellow\': ', JavaScriptEscape($txt['yellow']), ',
									\'pink\': ', JavaScriptEscape($txt['pink']), ',
									\'green\': ', JavaScriptEscape($txt['green']), ',
									\'orange\': ', JavaScriptEscape($txt['orange']), ',
									\'purple\': ', JavaScriptEscape($txt['purple']), ',
									\'blue\': ', JavaScriptEscape($txt['blue']), ',
									\'beige\': ', JavaScriptEscape($txt['beige']), ',
									\'brown\': ', JavaScriptEscape($txt['brown']), ',
									\'teal\': ', JavaScriptEscape($txt['teal']), ',
									\'navy\': ', JavaScriptEscape($txt['navy']), ',
									\'maroon\': ', JavaScriptEscape($txt['maroon']), ',
									\'limegreen\': ', JavaScriptEscape($txt['lime_green']), ',
									\'white\': ', JavaScriptEscape($txt['white']), '
								}
							}';

I also saw a message indicating that some of the files that the installation process needed to modify were not writable:

FTP Information Required

Some of the files the package manager needs to modify are not writable. This needs to be changed by logging into FTP and using it to chmod or create the files and folders. Your FTP information may be temporarily cached for proper operation of the package manager. Note you can also do this manually using an FTP client - to view a list of the affected files please click here.

When I clicked on the link to view the files that were not writable, I saw the the only file that was listed was /Themes/default/style.css. When I checked the file permissions on it, I saw it was readable by the owner and group, which were both set to be the user’s account and group.

$ ls -l style.css
-rw-rw-r--. 1 amy amy 0 Apr  2 17:07 style.css

Since the forum software was running under the Apache account, from the root account, I set the group for the file to be "apache" with the chgrp command.

# chgrp apache Themes/default/style.css

I then backed up to the prior page in the browser and clicked on Install Mod again. I then no longer saw the error message regarding files not being writable. I still saw the "Test failed" message for /Themes/default/GenericControls.template.php, but I clicked on Install Now anyway to proceed with the installation after first executing the tar command below from the directory above the forum software directory to make a backup of all files and folders.

$ tar -cvf dreaming_forum_20170402.tar forum

I saw the warning "Are you sure you wish to continue installing this modification, even though it will not install successfully?" I clicked on OK to proceed, intending to insert the needed code in GenericControls.template.php myself after the installation completed, but then saw the message that the smf.settings table doesn't exist.

Table 'smf.smf_settings' doesn't exist

But the installation process should have looked for smf.dreaming_settings, since the forum's tables were in an smf database, but the settings table had a prefix of the forum's name, "dreaming", rather than "smf".

Forum settings, such as the database name are contained in Settings.php in the top-level directory for the forum software. Within that file you will see files like the following one:

########## Database Info ##########
$db_type = 'mysql';
$db_server = 'localhost';
$db_name = 'smf';
$db_user = 'ann';
$db_passwd = 'ASecretOfCourse';
$ssi_db_user = '';
$ssi_db_passwd = '';
$db_prefix = 'dreaming_';
$db_persist = 0;
$db_error_send = 1;

The forum was named "Dreaming" with a prefix for tables in the database of dreaming_, so the installation process seemed to be ignoring the value for db_prefix. At that point, since I needed to complete other work, I restored all of the files from the backup tar file, which I had moved to a temp directory, so that the files were as they were before the attempted installation of the mod. Note: the --preserve option to the tar command is important to ensure file perissions are restored as they were originally.

$ tar --preserve -xvf ~/temp/dreaming_forum_20170402.tar

I copied the .zip file for the mod, which is stored in the Packages directory underneath the top-level directory for the forum when you start the install process, to a temporary directory and unzipped it to locate the source of the problem. Within the package-info.xml are code that controls what steps will be taken depedning on the version of SMF installed for the forum. Since the forum was running version 2.0.13, the following section applied:

        <install for="2.0 - 2.0.99">
                <readme type="file" parsebbc="true">readme.txt</readme>
                <code>install2.php</code>
                <modification>install2.xml</modification>
                <require-file name="color.js" destination="$themedir/" />
                <require-file name="blank.gif" destination="$themedir/images/bbc" />
                <require-file name="fontcolor.gif" destination="$themedir/images/bbc" />
                <require-file name="bgcolor.gif" destination="$themedir/images/bbc" />
        </install>

Since the install2.php file would control what changes are made to tables in the database for the forum, I looked at it and found the following code in it:

<?php 
/************************************************** 
   COLOR & BGCOLOR BBCODE BAR v3.5 By Ben Burt 
*************************************************** 
            INSTALL 2.PHP 
*************************************************** 
    - creates array 
    - stores our settings in the array 
    - checks the settings table if setting exists 
    - inserts the setting (ignores if already exists 
*/ 
 
// INSTALL SHOULD ONLY BE RUN WITH SMF 
if (!defined('SMF')) 
    include_once("SSI.php"); 
 
// CREATE AN ARRAY FOR OUR SETTINGS 
$newSetting = array(); 
 
// NOW ADD OUR SETTINGS TO THE ARRAY 
$newSetting['enable_colorbar'] = '1'; 
$newSetting['enable_qrcolorbar'] = '1'; 
 
// CYCLE THROUGH ARRAY ADDING EACH NEW SETTING - IF ALREADY EXISTS, IGNORE 
foreach ($newSetting as $key => $value){ 
     
    mysql_query(" 
        INSERT IGNORE 
        INTO smf_settings (`variable`, `value`)    VALUES     ('$key', '$value')") or die(mysql_error()); 
} 
// tidy up 
unset($newSetting,$key,$value); 
 
?>

I can see I would only need to modify the INTO smf_settings line to point to the correct table, i.e., replacing that code with INTO dreaming_settings, to fix the problem. I could then create a new zip file and upload it to the forum server to be installed, but I will need to do that another day.