change roundcube skins via webadmin

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
tester02
Normal user
Normal user
Posts: 33
Joined: 2016-04-09 23:28

change roundcube skins via webadmin

Post by tester02 » 2017-01-25 22:50

I host some domains for friends with a roundcube webmail interface. Since they all have different tastes I want to offer the domain admin the choice to select and change their standart roundcubeskin as they like. Since there is now an alternative webadmin script in development I tried to make the roundcube-look changeable via that webadmin interface.

I found no way to use the object based way and used instead the GET array. But maybe someone can enlighten me how to make it better.


Necessary additions and changes for the webadmin code:

background_domain_save.php

Code: Select all

....
   $SkinDesktop = hmailGetVar("SkinDesktop", "litecube");
   $SkinTablet = hmailGetVar("SkinTablet", "litecube");
   $SkinPhone = hmailGetVar("SkinPhone", "litecube");
   
   header("Location: index.php?page=domain&action=edit&domainid=$domainid&skin_desktop=$SkinDesktop&skin_tablet=$SkinTablet&skin_phone=$SkinPhone");
.....
hm_domain.php

Code: Select all

.....
<?php
	PrintCheckboxRow("domainantispamenablegreylisting", $obLanguage->String("Enabled"), $domainantispamenablegreylistingchecked);
?>
        </div>
        <h3><a href="#"><?php EchoTranslation("Webmail Skin")?></a></h3>
        <div class="hidden">
            <?php 
                $path = "../mail/skins/";
                $DomainSkin = "";
                
                if (isset($_GET['skin_desktop']) && $_GET['skin_desktop'] != "" && 
                    isset($_GET['skin_tablet']) && $_GET['skin_tablet'] != "" && 
                    isset($_GET['skin_phone']) && $_GET['skin_phone'] != "") {
                    $SkinDesktop = htmlspecialchars(stripslashes($_GET['skin_desktop']));
	                 $SkinTablet = htmlspecialchars(stripslashes($_GET['skin_tablet']));
	                 $SkinPhone = htmlspecialchars(stripslashes($_GET['skin_phone']));
                    $zuordnung = parse_ini_file($path."skins.ini"); 
                    foreach($zuordnung as $key=>$value){
                        if (strpos(strtolower($domainname), strtolower($key)) !== false){
                            $zuordnung[$key] = $SkinDesktop.",".$SkinTablet.",".$SkinPhone;
                            $fp = fopen($path."skins.ini", 'w');
                            foreach($zuordnung as $schluessel=>$wert) {
                                fputs($fp, $schluessel."=\"".$wert."\"\r\n");
                            }
                            fclose($fp); 
                        }
                    }
                }

                $zuordnung = parse_ini_file($path."skins.ini");             
                foreach($zuordnung as $key=>$value){
                    if (strpos(strtolower($domainname), strtolower($key)) !== false){
			            $testwert_desktop = strstr($zuordnung[$key],",",TRUE);
			            $testwert_tablet = strstr(substr(strstr($zuordnung[$key],",",FALSE),1),",",TRUE);
			            $testwert_phone = substr(strstr(substr(strstr($zuordnung[$key],",",FALSE),1),",",FALSE),1);
                    }
                }
            ?>
            <br><br>
			<?php EchoTranslation("Desktop-Skin:")?>
            <br>
			<select name="SkinDesktop" class="medium">
            <?php
				$scanned_directory = array_diff(scandir($path), array('..', '.'));
				foreach ($scanned_directory as $testdir){
					if (is_dir($path.'/'.$testdir)){
                        if ($testwert_desktop == $testdir){
                            echo "<option value=\"".$testdir."\" selected>".$testdir."</option>";
                        } else {
                            echo "<option value=\"".$testdir."\">".$testdir."</option>";
                        }    
					}
				}
            ?>
            </select>
            <br>
            <?php EchoTranslation("Tablet-Skin:")?>
            <br>
				<select name="SkinTablet" class="medium">
                <?php
				$scanned_directory = array_diff(scandir($path), array('..', '.'));
				foreach ($scanned_directory as $testdir){
					if (is_dir($path.'/'.$testdir)){
                        if ($testwert_tablet == $testdir){
                            echo "<option value=\"".$testdir."\" selected>".$testdir."</option>";
                        } else {
                             echo "<option value=\"".$testdir."\">".$testdir."</option>";
                        }    
					}
				}
                ?>
				</select>
            <br>
			<?php EchoTranslation("Phone-Skin:")?>
            <br>
            <select name="SkinPhone" class="medium">
                <?php
				$scanned_directory = array_diff(scandir($path), array('..', '.'));
				foreach ($scanned_directory as $testdir){
					if (is_dir($path.'/'.$testdir)){
                        if ($testwert_phone == $testdir){
                            echo "<option value=\"".$testdir."\" selected>".$testdir."</option>";
                        } else {
                            echo "<option value=\"".$testdir."\">".$testdir."</option>";
                        }    
					}
				} 
                ?>
				</select>
            <br>
            <br>"larry" and "classic" are NOT tailored for mobile devices!
            <br>        
        </div>
<?php
	PrintSaveButton();
?>
.....

and the roundcube additions
defaults.inc.php

Code: Select all

....
$zuordnung = parse_ini_file("..\mail\skins\skins.ini");
$skin_wert = "";
  
switch ($_SERVER['HTTP_HOST']) {
    case "xyz.ab":
    case "www.xyz.ab":
        $skin_logo = '.\skins\roundcube_xyz_logo.png';
        $name = 'XYZ';
            foreach($zuordnung as $key=>$value){
                if (strpos(strtolower($_SERVER['HTTP_HOST']), strtolower($key)) !== false){
                    $skin_desktop_wert = strstr($zuordnung[$key],",",TRUE);
                    $skin_tablet_wert = strstr(substr(strstr($zuordnung[$key],",",FALSE),1),",",TRUE);
                    $skin_phone_wert = substr(strstr(substr(strstr($zuordnung[$key],",",FALSE),1),",",FALSE),1);
                }
            }
        break;

    // add some more cases here for every other domain
   
    default:   
        $name = '';
        $skin_desktop_wert = "some_skin";
        $skin_tablet_wert = "some_other_skin";
        $skin_phone_wert = "again_some_other_skin";
}


// skin name: folder from skins
$config['desktop_skin'] = $skin_desktop_wert;
$config['tablet_skin'] = $skin_tablet_wert;
$config['phone_skin'] = $skin_phone_wert;


// skin logo
$config['login_branding_XYZ'] = $skin_logo;
//add some lines here for every skin you have

//header logo best 200px x 50px
$config['header_branding_XYZ'] = $skin_logo;
//add some lines here for every skin you have

....

// Name your service. This is displayed on the login screen and in the window title
$config['product_name'] = $name.' webmail ';

// Add this user-agent to message headers when sending
$config['useragent'] = $name.' webmail ';

....

Post Reply