Deleting the xhstyles.css file via the backend

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
frase
Posts: 5085
Joined: Thu Apr 21, 2016 6:32 am
Location: Saxony
Contact:

Deleting the xhstyles.css file via the backend

Post by frase » Thu Dec 24, 2020 11:36 am

It is always necessary to delete the xhstyles.css file manually, just when you work with new plugins or core styles and especially when you restore an older version.

Should there be a way to delete this file via the backend? If so - where?

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Deleting the xhstyles.css file via the backend

Post by Tata » Thu Dec 24, 2020 3:07 pm

frase wrote:
Thu Dec 24, 2020 11:36 am
Should there be a way to delete this file via the backend? If so - where?
If the necessity to delete the file is a standard, deletion may be hardcoded in functions.php directly after any new plugin is installed/removed, core styles are manipulated, or an older version is restored(?).
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Deleting the xhstyles.css file via the backend

Post by cmb » Thu Dec 24, 2020 3:27 pm

I agree with Tata. Maybe replace XH_pluginStylesheet with the following:

Code: Select all

function XH_pluginStylesheet()
{
    global $pth;

    $plugins = XH_plugins();

    // create array of pluginname => hash of CSS file contents
    $hashes = ['core' => sha1_file($pth['file']['corestyle'])];
    foreach ($plugins as $plugin) {
        $fn = $pth['folder']['plugins'] . $plugin . '/css/stylesheet.css';
        if (is_file($fn)) {
            $hashes[$plugin] = sha1_file($fn);
        } else {
            $hashes[$plugin] = '';
        }
    }

    $ofn = $pth['folder']['corestyle'] . 'xhstyles.css';
    $expired = !file_exists($ofn);

    // check for newly (un)installed plugins and changes in the individual plugin stylesheets
    if (!$expired) {
        if (($ofp = fopen($ofn, 'r')) !== false
            && fgets($ofp) && fgets($ofp)
            && ($oldPlugins = fgets($ofp))
        ) {
            $oldPlugins = explode(',', trim($oldPlugins, " *\r\n"));
            $oldhashes = [];
            foreach ($oldPlugins as $oldPlugin) {
                list($plugin, $hash) = explode(':', $oldPlugin);
                $oldhashes[$plugin] = $hash;
            }
            $expired = $hashes != $oldhashes;
        } else {
            $expired = true;
        }
        if ($ofp !== false) {
            fclose($ofp);
        }
    }

    // create combined plugin stylesheet
    if ($expired) {
        var_dump("expired");
        $o = array(
            PHP_EOL . '/' . str_pad(' ' . $pth['file']['corestyle'], 76, '*', STR_PAD_LEFT) . ' */'
            . PHP_EOL . PHP_EOL . file_get_contents($pth['file']['corestyle'])
        );
        foreach ($plugins as $plugin) {
            $fn = $pth['folder']['plugins'] . $plugin . '/css/stylesheet.css';
            if (file_exists($fn)) {
                $css = file_get_contents($fn);
                if (substr($css, 0, 3) === "\xEF\xBB\xBF") {
                    $css = substr($css, 3);
                }
                $css = XH_adjustStylesheetURLs($plugin, $css);
                $css = PHP_EOL
                    . '/' . str_pad(' ' . $fn, 76, '*', STR_PAD_LEFT) . ' */'
                    . PHP_EOL . PHP_EOL . $css;
                $o[] = $css;
            }
        }
        $pluginline = '';
        foreach ($hashes as $plugin => $hash) {
            if ($pluginline) {
                $pluginline .= ',';
            }
            $pluginline .= "$plugin:$hash";
        }
        $o = '/*' . PHP_EOL
            . ' * Automatically created by CMSimple_XH. DO NOT MODIFY!' . PHP_EOL
            . ' * ' . $pluginline . PHP_EOL
            . ' */' . PHP_EOL . PHP_EOL
            . implode(PHP_EOL . PHP_EOL, $o);
        if (!XH_writeFile($ofn, $o)) {
            e('cntwriteto', 'stylesheet', $ofn);
        }
    }

    return $ofn;
}
This does no longer check for the file modification time, but rather calculates SHA1 hashes, and compares these. It is likely a bit slower than the old code, but I guess that is acceptable.
Christoph M. Becker – Plugins for CMSimple_XH

frase
Posts: 5085
Joined: Thu Apr 21, 2016 6:32 am
Location: Saxony
Contact:

Re: Deleting the xhstyles.css file via the backend

Post by frase » Fri Dec 25, 2020 8:31 am

cmb wrote:
Thu Dec 24, 2020 3:27 pm
This does no longer check for the file modification time, but rather calculates SHA1 hashes, and compares these. It is likely a bit slower than the old code, but I guess that is acceptable.
It seems to me that this hash method is more effective than just comparing modification time.
Besides, it actually makes the work easier - you don't have to shimmy through folders all the time.
I would be in favor of adopting this in one of the next XH versions.

olape
Posts: 2713
Joined: Fri Mar 13, 2015 8:47 am
Contact:

Re: Deleting the xhstyles.css file via the backend

Post by olape » Fri Dec 25, 2020 8:37 am

Well then 1.7.5
Gruß Olaf, Plugins for CMSimple_XH

Ich habe schon lange den Verdacht, dass so viele so eifrig auf Gender, Trans und Queer machen:
Weil sie für das Fachliche ganz einfach zu doof sind.

Post Reply