View file ksw-beta/incfiles/classes/kswitcher.php

File size: 2.5Kb
<?php
class KSwitcher {
    private $path;
    private $autodetect = 0; // 0 -> off | 1 -> on | 2 -> user select

    public function __construct() {
        $this->setPath();
    }

    public function setPath() {
        $_SESSION['path'] = $this->getUserTheme();
    }

    public function getPath() {
        return $_SESSION['path'];
    }

    public function getUserTheme() {
        global $user_id;
        if ($user_id) {
            $st =  mysql_result(mysql_query("SELECT `set_user` FROM `users` WHERE `id`= " . $user_id) , 0);
            if (!empty($st)) {
                $serialize = unserialize($st);
                return $serialize['skin'];
            } else {
                return $this->getSiteDefaultTheme();
            }
        } else {
            return $this->getSiteDefaultTheme();
        }
    }

    public function getSiteDefaultTheme() {
        return mysql_result(mysql_query("SELECT `val` FROM `cms_settings` WHERE `key`='skindef'"), 0);
    }

    public function getElement($element) {
        $exp = explode('/', $element);
        return end($exp);
    }

    public function selectTheme() {
        $array = array();
        $schems = array_map(array($this, 'getElement'), glob('../theme/*'));
        foreach ($schems as $type) {
            $style = array_map(array($this, 'getElement'), glob('../theme/' . $type . '/*'));
            foreach ($style as $vid) {
                $array[$type . ' - ' . $vid] = 'theme/' . $type . '/' . $vid . '/';
            }
        }
        return $array;
    }

    public function head() {
        global $set, $user_id, $act, $lng, $login, $datauser, $agn, $rights, $headmod, $rootpath;
        $head = file_exists($rootpath . $this->getPath() . 'head.php') ? $rootpath . $this->getPath() . 'head.php' : $rootpath . 'theme/wap/default/head.php';
        include($head);
    }

    public function end() {
        global $set, $user_id, $act, $lng, $login, $datauser, $agn, $rights, $headmod, $rootpath;
        $end = file_exists($rootpath . $this->getPath() . 'end.php') ? $rootpath . $this->getPath() . 'end.php' : $rootpath . 'theme/wap/default/end.php';
        include($end);
    }

    public function main() {
        global $set, $user_id, $act, $lng, $login, $datauser, $agn, $rights, $headmod, $rootpath;
        $main = file_exists($rootpath . $this->getPath() . 'main.php') ? $rootpath . $this->getPath() . 'main.php' : $rootpath . 'theme/wap/default/main.php';
        include($main);
    }
}