This is experemental MOD, that will let members select templates from list of avalable.
The reason it's "experemental" because some code from global.php has to move into /includes/sessions.php. With some tests I had on my site I didnt see any side effects though.
Another maybe usefull feature this mod will add into 4images is "dropdown" option in db_field_definitions.php
----- Changes in files --------
/global.php
/includes/sessions.php
/includes/functions.php
/includes/db_field_definitions.php
/member.php
/lang/<yourlanguage>/main.php
/admin/admin_functions.php
/templates/<yourtemplate>/member_editprofile.html----- Installation ---------
Step 1.Open
/global.phpFind and delete (or comment):
define('TEMPLATE_PATH', ROOT_PATH.TEMPLATE_DIR."/".$config['template_dir']);
define('ICON_PATH', ROOT_PATH.TEMPLATE_DIR."/".$config['template_dir']."/icons");
Step 1.2Find:
//-----------------------------------------------------
//--- Templates ---------------------------------------
//-----------------------------------------------------
include(ROOT_PATH.'includes/template.php');
$site_template = new Template(TEMPLATE_PATH);
Replace with:
//-----------------------------------------------------
//--- Templates ---------------------------------------
//-----------------------------------------------------
$dir = opendir(ROOT_PATH.TEMPLATE_DIR);
$templates_cache = array();
while($dir_cache = readdir($dir))
{
if (@is_dir(ROOT_PATH.TEMPLATE_DIR."/".$dir_cache) && $dir_cache != "." && $dir_cache != "..")
{
$templates_cache[] = $dir_cache;
}
}
closedir($dir);
Step 2.Open
/includes/sessions.phpFind:
if (defined("GET_USER_ONLINE") && ($config['display_whosonline'] == 1 || $user_info['user_level'] == ADMIN)) {
Add before:
//-----------------------------------------------------
//--- Templates ---------------------------------------
//-----------------------------------------------------
$user_info['user_template'] = (isset($HTTP_GET_VARS['user_template'])) ? $HTTP_GET_VARS['user_template'] : ((isset($HTTP_POST_VARS['user_template'])) ? $HTTP_POST_VARS['user_template'] : $user_info['user_template']);
$user_template = ($user_info['user_template']) ? ((in_array($user_info['user_template'], $templates_cache)) ? $user_info['user_template'] : $config['template_dir']) : $config['template_dir'];
define('TEMPLATE_PATH', ROOT_PATH.TEMPLATE_DIR."/".$user_template);
define('ICON_PATH', ROOT_PATH.TEMPLATE_DIR."/".$user_template."/icons");
include(ROOT_PATH.'includes/template.php');
$site_template = new Template(TEMPLATE_PATH);
//--- End Templates -----------------------------------
Step 3.Open
/includes/functions.phpAdd at the end, just before closing
?>//--- DB Field Dropdown ---
function get_db_fields_dropdown($key, $val, $value) {
$dropdown = "<SELECT name=\"".$key."\" onkeypress=\"if(window.event.keyCode==13)this.form.submit();\" class=\"select\">";
$i = 0;
foreach ($val[3] as $item) {
$what = ($val[4]) ? $item : $i;
$dropdown .= "<option value=\"".$what."\"".(($value == $what) ? " selected" : "").">".$item."</option>\n";
$i++;
}
$dropdown .= "</select>\n";
return $dropdown;
}
//--- End DB Field Dropdown ---
Step 4.Open
/includes/db_field_definitions.phpAdd at the end, just before closing
?>$additional_user_fields['user_template'] = array($lang['user_template'], "dropdown", 0, $templates_cache, 1);
Step 5.Open
/members.phpv1.7 / v1.7.1[/color]
Find:
else{
$value = (isset($HTTP_POST_VARS[$key])) ? htmlspecialchars(trim($HTTP_POST_VARS[$key])) : $user_info[$key];
Replace with:
elseif ($val[1] == "dropdown") {
$value = (isset($HTTP_POST_VARS[$key])) ? $HTTP_POST_VARS[$key] : $user_info[$key];
$additional_field_array[$key.'_dropdown'] = get_db_fields_dropdown($key, $val, $value);
}else{
$value = (isset($HTTP_POST_VARS[$key])) ? htmlspecialchars(trim($HTTP_POST_VARS[$key])) : $user_info[$key];
v1.7.2Find:
else {
$value = (isset($HTTP_POST_VARS[$key])) ? format_text(trim($HTTP_POST_VARS[$key]), 2) : $user_info[$key];
Replace with:
elseif ($val[1] == "dropdown") {
$value = (isset($HTTP_POST_VARS[$key])) ? format_text(trim($HTTP_POST_VARS[$key]), 2) : $user_info[$key];
$additional_field_array[$key.'_dropdown'] = get_db_fields_dropdown($key, $val, $value);
}else{
$value = (isset($HTTP_POST_VARS[$key])) ? format_text(trim($HTTP_POST_VARS[$key]), 2) : $user_info[$key];
Step 6.Open
/lang/<yourlanguage>/main.phpAdd at the end, just before closing
?>//--- User templates --------
$lang['user_template'] = "Select style";
//--- End User templates ----
Step 7.Open
/admin/admin_functions.phpFind:
case "text":
Add before:
case "dropdown":
show_dropdown_row($val[0], $field_name, $value, $val[3], $val[4]);
break;
Step 7.2.Add at the end, just before closing
?>function show_dropdown_row($title, $name, $value = 0, $array = array(), $value_show = 0){
$i = 0;
echo "<tr width=\"50%\"class=\"".get_row_bg()."\" valign='top'>\n<td><p class=\"rowtitle\">".$title."</p></td>\n";
echo "<td width=\"50%\" valign=\"middle\">\n<SELECT name=\"".$name."\" onkeypress=\"if(window.event.keyCode==13){this.form.submit();}\"\">";
foreach ($array as $key) {
$what = ($value_show) ? $key : $i;
echo "<option value=\"".$what."\"".(($value == $what) ? " selected" : "").">".$key."</option>\n";
$i++;
}
echo "</select>\n</td>\n</tr>\n";
}
Step 8.Open
/templates/<yourtemplate>/member_editprofile.htmlAdd this:
<tr>
<td class="row1"><b>{lang_user_template}:</b></td>
<td class="row1">
{user_template_dropdown}
</td>
</tr>
*Repeat
Step 8. for each template, or your members wont be able change templates if chose the one without that change.
Step 9.Download
this installer.
Unpack it and upload
user_template_install.php file into 4images root dir.
Install it
http://yoursite.com/4images/user_template_install.phpIf u did everything correctly, in control panel (not ACP) u should see new dropdown.
The script automaticaly scans /templates/ folder and if it finds any folders, it add them as selection, so be carefull, make sure that each of your template sets has all needed templates.