コード例 #1
0
ファイル: blocks.php プロジェクト: hypnomez/opir.org
     $Page->title($L->editing_a_block(get_block_title($rc[3])));
     $a->content(h::{'p.lead.cs-center'}($L->editing_a_block(get_block_title($rc[3]))) . h::{'table.cs-table-borderless.cs-center-all tr'}(\cs\modules\System\form_rows_to_cols([array_map(function ($in) {
         return h::{'th info'}($in);
     }, ['block_title', 'block_active', 'block_template', 'block_start', 'block_expire']), array_map(function ($in) {
         return h::td($in);
     }, [h::input(['name' => 'block[title]', 'value' => get_block_title($rc[3])]), h::{'div input[type=radio]'}(['name' => 'block[active]', 'checked' => $block['active'], 'value' => [1, 0], 'in' => [$L->yes, $L->no]]), h::select(['in' => _mb_substr(get_files_list(TEMPLATES . '/blocks', '/^block\\..*?\\.(php|html)$/i', 'f'), 6)], ['name' => 'block[template]', 'selected' => $block['template'], 'size' => 5]), h::{'input[type=datetime-local]'}(['name' => 'block[start]', 'value' => date('Y-m-d\\TH:i', $block['start'] ?: TIME)]), h::{'input[type=radio]'}(['name' => 'block[expire][state]', 'checked' => $block['expire'] != 0, 'value' => [0, 1], 'in' => [$L->never, $L->as_specified]]) . h::br(2) . h::{'input[type=datetime-local]'}(['name' => 'block[expire][date]', 'value' => date('Y-m-d\\TH:i', $block['expire'] ?: TIME)])])]), $block['type'] == 'html' ? h::{'td[colspan=5] textarea.EDITOR'}(get_block_content($rc[3]), ['name' => 'block[html]']) : ($block['type'] == 'raw_html' ? h::{'td[colspan=5] textarea'}(get_block_content($rc[3]), ['name' => 'block[raw_html]']) : '')) . h::{'input[type=hidden]'}([[['name' => 'block[id]', 'value' => $rc[3]]], [['name' => 'mode', 'value' => $rc[2]]]]));
     break;
 case 'permissions':
     if (!isset($rc[3], $Config->components['blocks'][$rc[3]])) {
         break;
     }
     $form = false;
     $a->apply_button = false;
     $a->cancel_button_back = true;
     $permission = Permission::instance()->get(null, 'Block', $Config->components['blocks'][$rc[3]]['index'])[0]['id'];
     $groups = Group::instance()->get_all();
     $groups_content = [];
     foreach ($groups as $group) {
         $group_permission = $User->db()->qfs(["SELECT `value`\n\t\t\t\t\tFROM `[prefix]groups_permissions`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t= '%s' AND\n\t\t\t\t\t\t`permission`\t= '%s'", $group['id'], $permission]);
         $groups_content[] = h::th($group['title'], ['data-title' => $group['description']]) . h::{'td input[type=radio]'}(['name' => "groups[{$group['id']}]", 'checked' => $group_permission === false ? -1 : $group_permission, 'value' => [-1, 0, 1], 'in' => [$L->inherited, $L->deny, $L->allow]]);
     }
     unset($groups, $group, $group_permission);
     if (count($groups_content) % 2) {
         $groups_content[] = h::{'td[colspan=2]'}();
     }
     $count = count($groups_content);
     $content_ = [];
     for ($i = 0; $i < $count; $i += 2) {
         $content_[] = $groups_content[$i] . $groups_content[$i + 1];
     }
     $groups_content = $content_;
コード例 #2
0
ファイル: groups.php プロジェクト: hypnomez/opir.org
/**
 * @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;

use h;
$Config = Config::instance();
$L = Language::instance();
$Page = Page::instance();
$Group = Group::instance();
$a = Index::instance();
$rc = $Config->route;
if (isset($rc[2])) {
    switch ($rc[2]) {
        case 'add':
            $a->apply_button = false;
            $a->cancel_button_back = true;
            $Page->title($L->adding_a_group);
            $a->content(h::{'p.lead.cs-center'}($L->adding_a_group) . h::{'table.cs-table-borderless.cs-center-all tr'}(h::{'thead tr th'}($L->group_name, $L->description), h::{'tbody tr td'}(h::{'input[name=group[title]]'}(), h::{'input[name=group[description]]'}())));
            break;
        case 'edit':
            if (!isset($rc[3])) {
                break;
            }
            $a->apply_button = false;
コード例 #3
0
ファイル: User.php プロジェクト: hypnomez/opir.org
 /**
  * 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;
     }
 }