Ergebnis 1 bis 3 von 3

Thema: Contao 3.2.4 und lessphp

  1. #1
    Contao-Nutzer Avatar von brandtmarke
    Registriert seit
    30.07.2009.
    Ort
    Bremerhaven
    Beiträge
    105

    Standard Contao 3.2.4 und lessphp

    Hallo zusammen,

    ich musste gerade feststellen, dass die lessphp Erweiterung unter contao 3.2.4 nicht mehr funktioniert. Es lässt sich zwar ein .less File im Seitenlayout unter zusätzliche Stylesheets auswählen und es wird auch eine dazu passende .css generiert, diese wird dann allerdings nicht verarbeitet (genauso wie auch andere, reguläre css Dateien nicht, wenn die Erweiterung installiert ist). Ausserdem wird die generierte .css wieder gelöscht, wenn man die Dateiverwaltung synchronisiert.

    Hat jemand eine Idee, wie man Abhilfe schaffen bzw. die Erweiterung contao 3.2.4 kompatibel machen könnte?

    Gruß

    Dennis

  2. #2
    Contao-Nutzer
    Registriert seit
    06.10.2009.
    Beiträge
    13

    Standard

    Hallo Dennis,

    ich habe den Code von "lessphp" für Contao 3.2.x aufbereitet.

    Dies ist der neue Code aus der Datei: "/system/modules/lessphp/classes/LessHelper.php".

    PHP-Code:
    <?php

    /**
     * Contao Open Source CMS
     * Copyright (C) 2005-2013 Leo Feyer
     *
     * Formerly known as TYPOlight Open Source CMS.
     *
     * This program is free software: you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation, either
     * version 3 of the License, or (at your option) any later version.
     * 
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     * Lesser General Public License for more details.
     * 
     * You should have received a copy of the GNU Lesser General Public
     * License along with this program. If not, please visit the Free
     * Software Foundation website at <http://www.gnu.org/licenses/>.
     *
     * PHP version 5
     * @copyright  David Enke 2013 
     * @author     David Enke (post@davidenke.de) 
     * @package    lessphp 
     * @license    LGPL 
     * @filesource
     */


    /**
     * Run in a custom namespace, so the class can be replaced
     */
    namespace Contao;

    /**
     * Include lessc
     */
    require_once(TL_ROOT '/system/vendor/lessphp/lessc.inc.php');

    /**
     * Class LessHelper
     *
     */
    class LessHelper extends \Frontend {
        protected function 
    createCssFile($objLessFile) {
            if (!
    $objLessFile) return;

            
    $strDestination preg_replace('/\.less$/i''.css'$objLessFile->path);

            
    $objCssFile = clone $objLessFile;
            
    // remove old ID field
            
    $objCssFile->path $strDestination;
            
    $objCssFile->extension 'css';
            
    $objCssFile->hash md5_file(TL_ROOT '/' $strDestination);
            
    $objCssFile->name preg_replace('/\.less$/i''.css'$objLessFile->name);
            
    $objCssFile->save(true);

            return 
    $objCssFile;
        }

        public function 
    renderLess(\PageModel $objPage, \LayoutModel $objLayout, \PageRegular $objPageRegular) {
            
    $arrCache = array();
            
    $arrExternal deserialize($objLayout->external);
            
    $arrOrderExt deserialize($objLayout->orderExt);

            
    // External style sheets
            
    if (is_array($arrExternal) && !empty($arrExternal)) {
                
    // Get the file entries from the database
                
    $objFiles = \FilesModel::findMultipleByIds($arrExternal);

                
    $objLess = new \lessc;
                
    //$objLess->setImportDir(array('/files'));
                
    if ($GLOBALS['TL_CONFIG']['gzipScripts']) {
                    
    $objLess->setFormatter('compressed');
                }

                if (
    $objFiles !== null) {
                    while (
    $objFiles->next()) {
                        if (
    file_exists(TL_ROOT '/' $objFiles->path)) {
                            
    $intFileId $objFiles->uuid;

                            if (
    $objFiles->extension == 'less') {
                                
    $strDes preg_replace('/\.less$/i''.css'$objFiles->path);

                                try {
                                    if (
    $GLOBALS['TL_CONFIG']['checkedCompile'])
                                        
    $objLess->checkedCompile(TL_ROOT '/' $objFiles->pathTL_ROOT '/' $strDes);
                                    else 
    $objLess->compileFile(TL_ROOT '/' $objFiles->pathTL_ROOT '/' $strDes);
                                } catch (
    exception $e) {
                                    
    $this->log('Could not compile less file "' $objFiles->path '"''LessHelper renderLess()'TL_ERROR);
                                }

                                
    $objFile = \FilesModel::findMultipleByBasepath($strDes);

                                if (
    is_null($objFile)) {
                                    
    $objFile $this->createCssFile($objFiles);
                                }

                                
    // replace old ID in $objLayout->orderExt
                                
    $arrOrderExt array_replace($arrOrderExtarray_fill_keys(array_keys($arrOrderExt$intFileId), $objFile->uuid));

                                
    $intFileId $objFile->uuid;
                            }

                            
    $arrCache[] = $intFileId;
                        }
                    }
                }

                
    $objLayout->external serialize($arrCache);
                
    $objLayout->orderExt serialize($arrOrderExt);
            }
        }
    }

    ?>

  3. #3
    Contao-Nutzer Avatar von brandtmarke
    Registriert seit
    30.07.2009.
    Ort
    Bremerhaven
    Beiträge
    105

    Standard

    Besten Dank; werde ich gleich mal testen

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •