HEX
Server: Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 mod_fcgid/2.3.9 PHP/5.4.16
System: Linux dvm.vladweb.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: region-gk.ru (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: /home/temp/yarusvl.ru/adminx/core/StylesAdmin.php
<?php

require_once('api/Mgc.php');

class StylesAdmin extends Mgc {

    /*Файл стилей шаблона*/
    public function fetch() {
        $current_theme = $this->settings->theme;
        if ($this->settings->admin_theme) {
            $current_theme = $this->settings->admin_theme;
        }

        $styles_dir = 'tpls/'.$current_theme.'/css/';
        $styles = array();
        // Чтаем все css-файлы
        if($handle = opendir($styles_dir)) {
            while(false !== ($file = readdir($handle))) {
                if(is_file($styles_dir.$file) && $file[0] != '.'  && pathinfo($file, PATHINFO_EXTENSION) == 'css') {
                    $styles[] = $file;
                }
            }
            closedir($handle);
        }
        asort($styles);
        
        // Текущий шаблон
        $style_file = $this->request->get('file');
        
        if(!empty($style_file) && pathinfo($style_file, PATHINFO_EXTENSION) != 'css') {
            exit();
        }
        
        // Если не указан - вспоминаем его из сессии
        if(empty($style_file) && isset($_SESSION['last_edited_style'])) {
            $style_file = $_SESSION['last_edited_style'];
        }
        // Иначе берем первый файл из списка
        elseif(empty($style_file)) {
            $style_file = reset($styles);
        }
        
        // Передаем имя шаблона в дизайн
        $this->design->assign('style_file', $style_file);
        
        // Если можем прочитать файл - передаем содержимое в дизайн
        if(is_readable($styles_dir.$style_file)) {
            $style_content = file_get_contents($styles_dir.$style_file);
            $this->design->assign('style_content', $style_content);
        }
        
        // Если нет прав на запись - передаем в дизайн предупреждение
        if(!empty($style_file) && !is_writable($styles_dir.$style_file) && !is_file($styles_dir.'../locked')) {
            $this->design->assign('message_error', 'permissions');
        } elseif(is_file($styles_dir.'../locked')) {
            $this->design->assign('message_error', 'theme_locked');
        } else {
            // Запоминаем в сессии имя редактируемого шаблона
            $_SESSION['last_edited_style'] = $style_file;
        }
        
        $this->design->assign('theme', $current_theme);
        $this->design->assign('styles', $styles);
        return $this->design->fetch('styles.tpl');
    }
    
}