Example #1
0
if (isset($rc[2])) {
    switch ($rc[2]) {
        case 'enable':
            if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) {
                break;
            }
            $Config->components['blocks'][$rc[3]]['active'] = 1;
            $a->save();
            break;
        case 'disable':
            if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) {
                break;
            }
            $Config->components['blocks'][$rc[3]]['active'] = 0;
            $a->save();
            unset(Cache::instance()->{'blocks/' . $Config->components['blocks'][$rc[3]]['index']});
            break;
        case 'delete':
            if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) {
                break;
            }
            $form = false;
            $a->buttons = false;
            $a->cancel_button_back = true;
            $a->action = 'admin/System/' . $rc[0] . '/' . $rc[1];
            $Page->title($L->deletion_of_block(get_block_title($rc[3])));
            $a->content(h::{'p.lead.cs-center'}($L->sure_to_delete_block(get_block_title($rc[3])) . h::{'input[type=hidden]'}(['name' => 'mode', 'value' => 'delete']) . h::{'input[type=hidden]'}(['name' => 'id', 'value' => $rc[3]])) . h::{'button[type=submit]'}($L->yes));
            break;
        case 'add':
            $form = false;
            $a->apply_button = false;
Example #2
0
<?php

/**
 * @package		CleverStyle CMS
 * @subpackage	System module
 * @category	modules
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs\modules\System;

use h, cs\Config, cs\Cache, cs\Index, cs\Language;
$Config = Config::instance();
$L = Language::instance();
$sa = $Config->core['simple_admin_mode'];
Index::instance()->content(h::{'table.cs-table-borderless.cs-left-even.cs-right-odd tr| td'}(core_input('gzip_compression', 'radio', null, zlib_compression()), core_input('cache_compress_js_css', 'radio'), core_input('put_js_after_body', 'radio'), !$sa ? core_input('inserts_limit', 'number', null, false, 1) : false, !$sa ? core_input('update_ratio', 'number', null, false, 0, 100) : false, [h::{'div#clean_cache'}(), h::{'div#clean_pcache'}()], [h::button($L->clean_settings_cache, Cache::instance()->cache_state() ? ['onMouseDown' => "cs.admin_cache('#clean_cache', '{$Config->base_url()}/api/System/admin/cache/clean_cache');"] : ['disabled']), h::button($L->clean_scripts_styles_cache, $Config->core['cache_compress_js_css'] ? ['onMouseDown' => "cs.admin_cache('#clean_pcache', '{$Config->base_url()}/api/System/admin/cache/clean_pcache');"] : ['disabled'])]));
Example #3
0
 * @copyright	Copyright (c) 2013-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs;

use h;
/**
 * Multilingual functionality: redirects and necessary meta-tags
 */
Trigger::instance()->register('System/User/construct/after', function () {
    $Config = Config::instance();
    if (!$Config->core['multilingual']) {
        return;
    }
    $relative_address = $Config->server['relative_address'];
    $Cache = Cache::instance();
    if (!FIXED_LANGUAGE && $_SERVER['REQUEST_METHOD'] == 'GET' && $Cache->cache_state() && Core::instance()->cache_engine != 'BlackHole') {
        $clang = Language::instance()->clang;
        if (!HOME) {
            header("Location: /{$clang}/{$relative_address}", true, 301);
        } else {
            header("Location: /{$clang}", true, 301);
        }
    }
    $base_url = substr($Config->base_url(), 0, -3);
    Page::instance()->Head .= h::{'link[rel=alternate]'}(['hreflang' => 'x-default', 'href' => !HOME ? "{$base_url}/{$relative_address}" : "{$base_url}"]) . h::{'link[rel=alternate]|'}(array_map(function ($lang) use($base_url, $relative_address) {
        return ['hreflang' => $lang, 'href' => "{$base_url}/{$lang}/{$relative_address}"];
    }, array_values($Cache->get('languages/clangs', function () use($Config) {
        return $Config->update_clangs();
    })) ?: []));
});
Example #4
0
 /**
  * Delete item from cache
  *
  * @param string	$item	May contain "/" symbols for cache structure, for example users/<i>user_id</i>
  *
  * @return bool
  */
 function del($item)
 {
     return Cache::instance()->del("{$this->prefix}/{$item}");
 }
Example #5
0
 /**
  * @param int		$id
  * @param string	$type
  *
  * @return bool
  */
 protected function del_any_permissions_all($id, $type)
 {
     $id = (int) $id;
     if (!$id) {
         return false;
     }
     switch ($type) {
         case 'user':
             $table = '[prefix]users_permissions';
             break;
         case 'group':
             $table = '[prefix]groups_permissions';
             break;
         default:
             return false;
     }
     $return = $this->db_prime()->q("DELETE FROM `{$table}` WHERE `id` = '{$id}'");
     if ($return) {
         $Cache = $this->cache;
         unset($Cache->{"permissions/{$id}"});
         if ($type == 'group') {
             unset(Cache::instance()->{'users/permissions'});
         }
         return true;
     }
     return false;
 }
Example #6
0
 * @author		Nazar Mokrynskyi <*****@*****.**>
 * @copyright	Copyright (c) 2011-2014, Nazar Mokrynskyi
 * @license		MIT License, see license.txt
 */
namespace cs\modules\Static_pages;

use cs\Cache, cs\User, cs\Trigger;
Trigger::instance()->register('admin/System/components/modules/uninstall/process', function ($data) {
    if ($data['name'] != 'Static_pages' || !User::instance()->admin()) {
        return true;
    }
    time_limit_pause();
    $Static_pages = Static_pages::instance();
    $structure = $Static_pages->get_structure();
    while (!empty($structure['categories'])) {
        foreach ($structure['categories'] as $category) {
            $Static_pages->del_category($category['id']);
        }
        $structure = $Static_pages->get_structure();
    }
    unset($category);
    if (!empty($structure['pages'])) {
        foreach ($structure['pages'] as $page) {
            $Static_pages->del($page);
        }
        unset($page);
    }
    unset($structure, Cache::instance()->Static_pages);
    time_limit_pause(false);
    return true;
});
Example #7
0
/**
 * Updates user contacts for specified provider
 *
 * @param \Hybrid_User_Contact[]	$contacts
 * @param string					$provider
 */
function update_user_contacts($contacts, $provider)
{
    $Cache = Cache::instance();
    $id = User::instance()->id;
    /**
     *	@var \cs\DB\_Abstract $cdb
     */
    $cdb = DB::instance()->{Config::instance()->module('HybridAuth')->db('integration')}();
    $cdb->q("DELETE FROM `[prefix]users_social_integration_contacts`\n\t\tWHERE\n\t\t\t`id`\t\t= '%s' AND\n\t\t\t`provider`\t= '%s'", $id, $provider);
    if (!empty($contacts)) {
        $insert = [];
        $params = [];
        foreach ($contacts as $contact) {
            $insert[] = "('%s', '%s', '%s')";
            $params[] = $id;
            $params[] = $provider;
            $params[] = $contact->identifier;
        }
        $insert = implode(',', $insert);
        $cdb->q("INSERT INTO `[prefix]users_social_integration_contacts`\n\t\t\t(\n\t\t\t\t`id`,\n\t\t\t\t`provider`,\n\t\t\t\t`identifier`\n\t\t\t) VALUES {$insert}", $params);
    }
    unset($Cache->{"HybridAuth/contacts/{$id}"});
}
Example #8
0
 /**
  * Delete group
  *
  * @param int	$group
  *
  * @return bool
  */
 function del($group)
 {
     $group = (int) $group;
     Trigger::instance()->run('System/User/Group/del/before', ['id' => $group]);
     if ($group != 1 && $group != 2 && $group != 3) {
         $return = $this->db_prime()->q(["DELETE FROM `[prefix]groups` WHERE `id` = {$group}", "DELETE FROM `[prefix]users_groups` WHERE `group` = {$group}"]);
         $this->del_permissions_all($group);
         $Cache = $this->cache;
         unset(Cache::instance()->{'users/groups'}, $Cache->{$group}, $Cache->all);
         Trigger::instance()->run('System/User/Group/del/after', ['id' => $group]);
         return (bool) $return;
     } else {
         return false;
     }
 }
Example #9
0
 /**
  * Get permission state for specified user
  *
  * Rule: if not denied - allowed (users), if not allowed - denied (admins)
  *
  * @param string	$group	Permission group
  * @param string	$label	Permission label
  * @param bool|int	$user	If not specified - current user assumed
  *
  * @return bool				If permission exists - returns its state for specified user, otherwise for admin permissions returns <b>false</b> and for
  * 							others <b>true</b>
  */
 function get_permission($group, $label, $user = false)
 {
     $user = (int) ($user ?: $this->id);
     if ($this->system() || $user == self::ROOT_ID) {
         return true;
     }
     if (!$user) {
         return false;
     }
     if (!isset($this->permissions[$user])) {
         $this->permissions[$user] = $this->cache->get("permissions/{$user}", function () use($user) {
             $permissions = [];
             if ($user != self::GUEST_ID) {
                 $groups = $this->get_groups($user);
                 if (is_array($groups)) {
                     $Group = Group::instance();
                     foreach ($groups as $group_id) {
                         foreach ($Group->get_permissions($group_id) ?: [] as $p => $v) {
                             $permissions[$p] = $v;
                         }
                         unset($p, $v);
                     }
                 }
                 unset($groups, $group_id);
             }
             foreach ($this->get_permissions($user) ?: [] as $p => $v) {
                 $permissions[$p] = $v;
             }
             return $permissions;
         });
     }
     $all_permission = Cache::instance()->{'permissions/all'} ?: Permission::instance()->get_all();
     if (isset($all_permission[$group], $all_permission[$group][$label])) {
         $permission = $all_permission[$group][$label];
         if (isset($this->permissions[$user][$permission])) {
             return (bool) $this->permissions[$user][$permission];
         } else {
             return $this->admin() ? true : strpos($group, 'admin/') !== 0;
         }
     } else {
         return true;
     }
 }
Example #10
0
 /**
  * Module page generation, menus rendering, blocks processing, adding of form with save/apply/cancel/reset and/or custom users buttons
  */
 protected function generate()
 {
     $Config = Config::instance();
     $L = Language::instance();
     $Page = Page::instance();
     if ($this->api) {
         $Page->content($this->Content);
         return;
     }
     $this->main_menu_auto && $this->main_menu();
     $this->main_sub_menu_auto && $this->main_sub_menu();
     $this->main_menu_more_auto && $this->main_menu_more();
     $this->blocks_processing();
     if ($this->form) {
         $Page->content(h::form($this->Content . ($this->apply_button && $this->buttons ? h::button($L->apply, ['name' => 'edit_settings', 'data-title' => $L->apply_info, 'id' => 'apply_settings', 'type' => 'submit', 'value' => 'apply', 'add' => Cache::instance()->cache_state() ? '' : ' disabled']) : '') . ($this->save_button && $this->buttons ? h::button($L->save, ['name' => 'edit_settings', 'data-title' => $L->save_info, 'id' => 'save_settings', 'type' => 'submit', 'value' => 'save']) : '') . ($this->apply_button && $this->buttons || $this->cancel_button_back ? h::button($L->cancel, ['name' => 'edit_settings', 'id' => 'cancel_settings', 'value' => 'cancel', 'data-title' => $this->cancel_button_back ? false : $L->cancel_info, 'type' => $this->cancel_button_back ? 'button' : 'submit', 'onClick' => $this->cancel_button_back ? 'history.go(-1);' : false, 'add' => $this->cancel_button_back ? '' : (isset($Config->core['cache_not_saved']) ? '' : $this->cancel_button)]) : '') . ($this->buttons && $this->reset_button ? h::button($L->reset, ['id' => 'reset_settings', 'data-title' => $L->reset_info, 'type' => 'reset']) : '') . $this->post_buttons, array_merge(['enctype' => $this->file_upload ? 'multipart/form-data' : false, 'action' => $this->action], $this->form_atributes)));
     } elseif ($this->Content) {
         $Page->content($this->Content);
     }
 }
Example #11
0
/**
 * Checks whether specified functionality available or not
 *
 * @param string|string[]	$functionality	One functionality or array of them
 *
 * @return bool								<i>true</i> if all functionality available, <i>false</i> otherwise
 */
function functionality($functionality)
{
    if (is_array($functionality)) {
        $result = true;
        foreach ($functionality as $f) {
            $result = $result && functionality($f);
        }
        return $result;
    }
    $all = Cache::instance()->get("functionality", function () {
        $functionality = [];
        $components = Config::instance()->components;
        foreach ($components['modules'] as $module => $module_data) {
            if ($module_data['active'] != 1 || !file_exists(MODULES . "/{$module}/meta.json")) {
                continue;
            }
            $meta = file_get_json(MODULES . "/{$module}/meta.json");
            if (!isset($meta['provide'])) {
                continue;
            }
            $functionality = array_merge($functionality, (array) $meta['provide']);
        }
        unset($module, $module_data, $meta);
        foreach ($components['plugins'] as $plugin) {
            if (!file_exists(PLUGINS . "/{$plugin}/meta.json")) {
                continue;
            }
            $meta = file_get_json(PLUGINS . "/{$plugin}/meta.json");
            if (!isset($meta['provide'])) {
                continue;
            }
            $functionality = array_merge($functionality, (array) $meta['provide']);
        }
        return $functionality;
    });
    return array_search($functionality, $all) !== false;
}
Example #12
0
    /**
     * Loading of base system configuration, creating of missing directories
     */
    protected function construct()
    {
        if (!file_exists(CONFIG . '/main.json')) {
            error_code(500);
            Page::instance()->error(h::p('Config file not found, is system installed properly?') . h::a('How to install CleverStyle CMS', ['href' => 'https://github.com/nazar-pc/CleverStyle-CMS/wiki/Installation']));
            exit;
        }
        $this->config = file_get_json_nocomments(CONFIG . '/main.json');
        _include_once(CONFIG . '/main.php', false);
        defined('DEBUG') || define('DEBUG', false);
        define('DOMAIN', $this->config['domain']);
        date_default_timezone_set($this->config['timezone']);
        if ($clangs = Cache::instance()->{'languages/clangs'}) {
            if (is_array($clangs) && !empty($clangs)) {
                $clang = explode('/', trim($_SERVER['REQUEST_URI'], '/'), 2)[0];
                if (in_array($clang, $clangs)) {
                    $this->set('language', array_flip($clangs)[$clang]);
                    define('FIXED_LANGUAGE', true);
                }
                unset($clang);
            }
        }
        unset($clangs);
        if (!is_dir(STORAGE)) {
            @mkdir(STORAGE, 0755);
            file_put_contents(STORAGE . '/.htaccess', 'Allow From All');
        }
        if (!is_dir(CACHE)) {
            @mkdir(CACHE, 0700);
        }
        if (!is_dir(PCACHE)) {
            @mkdir(PCACHE, 0755);
            file_put_contents(PCACHE . '/.htaccess', '<FilesMatch "\\.(css|js)$">
	Allow From All
</FilesMatch>
<ifModule mod_expires.c>
	ExpiresActive On
	ExpiresDefault "access plus 1 month"
</ifModule>
<ifModule mod_headers.c>
	Header set Cache-Control "max-age=2592000, public"
</ifModule>
AddEncoding gzip .js
AddEncoding gzip .css
');
        }
        if (!is_dir(LOGS)) {
            @mkdir(LOGS, 0700);
        }
        if (!is_dir(TEMP)) {
            @mkdir(TEMP, 0755);
            file_put_contents(TEMP . '/.htaccess', 'Allow From All');
        }
        if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/json') === 0) {
            $_POST = _json_decode(@file_get_contents('php://input')) ?: [];
            $_REQUEST = array_merge($_REQUEST, $_POST);
        } elseif (in_array(strtolower($_SERVER['REQUEST_METHOD']), ['head', 'put', 'delete'])) {
            if (isset($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') === 0) {
                @parse_str(file_get_contents('php://input'), $_POST);
                $_REQUEST = array_merge($_REQUEST, $_POST);
            }
        }
        $this->constructed = true;
    }
Example #13
0
 /**
  * Change language
  *
  * @param string	$language
  *
  * @return bool
  */
 function change($language)
 {
     static $changed_once = false;
     if ($this->fixed_language && $changed_once) {
         return false;
     }
     $changed_once = true;
     if ($language == $this->clanguage) {
         return true;
     }
     $Config = Config::instance(true);
     if (empty($language)) {
         if ($Config && $Config->core['multilingual']) {
             $language = $this->scan_aliases($Config->core['active_languages']) ?: $language;
         }
     }
     if (!$Config || $language == $Config->core['language'] || $Config->core['multilingual'] && in_array($language, $Config->core['active_languages'])) {
         $this->clanguage = $language;
         $return = false;
         $Cache = Cache::instance();
         /**
          * If translations in cache
          */
         if ($translate = $Cache->{"languages/{$this->clanguage}"}) {
             $this->set($translate);
             $return = true;
             /**
              * Otherwise check for system translations
              */
         } elseif (file_exists(LANGUAGES . "/{$this->clanguage}.json")) {
             /**
              * Set system translations
              */
             $this->set(file_get_json_nocomments(LANGUAGES . "/{$this->clanguage}.json"));
             $translate =& $this->translate;
             $translate['clanguage'] = $this->clanguage;
             if (!isset($translate['clang'])) {
                 $translate['clang'] = mb_strtolower(mb_substr($this->clanguage, 0, 2));
             }
             if (!isset($translate['clanguage_en'])) {
                 $translate['clanguage_en'] = $this->clanguage;
             }
             if (!isset($translate['locale'])) {
                 $translate['locale'] = $this->clang . '_' . strtoupper($this->clang);
             }
             /**
              * Set modules' translations
              */
             foreach (get_files_list(MODULES, false, 'd') as $module) {
                 if (file_exists(MODULES . "/{$module}/languages/{$this->clanguage}.json")) {
                     $this->set(file_get_json_nocomments(MODULES . "/{$module}/languages/{$this->clanguage}.json") ?: []);
                 }
             }
             unset($module);
             /**
              * Set plugins' translations
              */
             foreach (get_files_list(PLUGINS, false, 'd') as $plugin) {
                 if (file_exists(PLUGINS . "/{$plugin}/languages/{$this->clanguage}.json")) {
                     $this->set(file_get_json_nocomments(PLUGINS . "/{$plugin}/languages/{$this->clanguage}.json") ?: []);
                 }
             }
             unset($plugin);
             Trigger::instance()->run('System/general/languages/load', ['clanguage' => $this->clanguage, 'clang' => $this->clang, 'cregion' => $this->cregion, 'clanguage_en' => $this->clanguage_en]);
             $Cache->{"languages/{$this->clanguage}"} = $translate;
             $return = true;
         }
         _include(LANGUAGES . "/{$this->clanguage}.php", false, false);
         header("Content-Language: {$translate['content_language']}");
         return $return;
     }
     return false;
 }