# Core\_Auth::logged()

## Вывод данных только для администраторов

{% code lineNumbers="true" fullWidth="true" %}

```php
if(Core_Auth::logged())
{
    print_r($_SESSION);
}

// для определенного пользвоателя ЦА
$oUser = Core_Auth::getCurrentUser();

if(!is_null($oUser) && $oUser->id == 123)
{
    print_r($_SESSION);
}
```

{% endcode %}

## Компрессия CSS и JS

Позволяет отключать компрессию css и js для администраторов сайта, но для посетителей компрессия будет работать

{% code lineNumbers="true" fullWidth="true" %}

```php
Core_Page::instance()
	->prependCss('/css/bootstrap.min.css')
	->fileTimestamp(TRUE)
	->compress(!Core_Auth::logged())
	->showCss();

Core_Page::instance()
	->prependJs('/js/jquery.min.js')
	->fileTimestamp(TRUE)
	->compress(!Core_Auth::logged())
	->showJs(TRUE);
```

{% endcode %}

## Компиляция Less

При внесении администратором сайта изменений в `less` файл макета, будет сразу компилировать `css` (код можно разместить например в основном макете сайта в самом начале)

{% code lineNumbers="true" fullWidth="true" %}

```php
if(Core_Auth::logged() && Core_Page::instance()->template)
{
    $oTemplate = Core_Page::instance()->template;

    $content = is_file($oTemplate->getTemplateLessFilePath())
        ? $oTemplate->loadTemplateLessFile()
        : $oTemplate->loadTemplateCssFile();
	
     if ($oTemplate->type == 1 && strlen($content))
    {
        // Rebuild CSS
        $css = Template_Preprocessor::factory('less')->compile($content);
        $oTemplate->saveTemplateCssFile($css);
    }
	
    while ($oTemplate->template_id)
    {
        $oTemplate = $oTemplate->getParent();
	
        $content = is_file($oTemplate->getTemplateLessFilePath())
            ? $oTemplate->loadTemplateLessFile()
            : $oTemplate->loadTemplateCssFile();
			
        if ($oTemplate->type == 1 && strlen($content))
        {
            // Rebuild CSS
            $css = Template_Preprocessor::factory('less')->compile($content);
            $oTemplate->saveTemplateCssFile($css);
        }
    }
}
```

{% endcode %}

## XSL-шаблоны

Добавления тэга Core\_Auth в XSL-шаблон через хук

{% code lineNumbers="true" fullWidth="true" %}

```php
class Auth_Shop_Controller_Show
{
    static public function onBeforeRedeclaredShow($controller)
    {
        Core_Auth::logged() && $controller->addEntity(
            Core::factory('Core_Xml_Entity')
                ->name('Core_Auth')
                ->value(1)
        );
    }
}
// хук для контроллера информационных систем
Core_Event::attach('Informationsystem_Controller_Show.onBeforeRedeclaredShow', array('Auth_Shop_Controller_Show', 'onBeforeRedeclaredShow'));
// хук для контроллера магазина
Core_Event::attach('Shop_Controller_Show.onBeforeRedeclaredShow', array('Auth_Shop_Controller_Show', 'onBeforeRedeclaredShow'));
```

{% endcode %}

Проверка в XSL-шаблоне

{% code lineNumbers="true" fullWidth="true" %}

```html
<xsl:if test="/shop/Core_Auth">
    Я админ!
</xsl:if>
```

{% endcode %}

## TPL-шаблоны

Проверка в TPL-шаблоне

{% code fullWidth="true" %}

```smarty
{if Core_Auth::logged()}
    Я админ!
{/if}
```

{% endcode %}

## Template (макеты)

При разработке нового дизайн позволяет подменять макеты и XSL-шаблоны для ТДС на новые для администраторов сайта, но для посетителей будут работать старые, данный хук можно разметсить в `bootstrap.php`

{% code lineNumbers="true" fullWidth="true" %}

```php
if(Core_Auth::logged())
{
    class Auth_Template_Observer
    {
        static public function onBeforeSetTemplate($controller)
        {
            $libParams = Core_Page::instance()->libParams;
            $object = Core_Page::instance()->object;
            $template = Core_Page::instance()->template;
            
            if(CURRENT_SITE == 1) // ID сайта
            {
                isset($libParams['shopXsl']) && $libParams['shopXsl'] == 'МагазинКаталогТоваров'
                    && $libParams['shopXsl'] = 'МагазинКаталогТоваров [NEW]';
                    
                $aTemplates = array(
                    97 => 116 // старый макет => новый макет
                );
                
                $oTemplate = Core_Entity::factory('Template', Core_Array::get($aTemplates, $template->id, $template->id));

                Core_Page::instance()
                    ->libParams($libParams)
                    ->template($oTemplate);
            }
        }
    }
    
    Core_Event::attach('Core_Command_Controller_Default.onBeforeSetTemplate', array('Auth_Template_Observer', 'onBeforeSetTemplate'));
}
```

{% endcode %}

## Вывод 404 на тестовой странице

{% code fullWidth="true" %}

```php
if(!Core_Auth::logged() && strpos(Core::$url['path'], '/test/') !== FALSE)
{
    Core_Page::instance()->error404();
}
```

{% endcode %}

## Показ неактивных групп и элементов

Позволяет показывать отключенные группы/элементы для администратора сайта, а пользователям 404 ошибку

{% code lineNumbers="true" fullWidth="true" %}

```php
// для информационных систем
Core_Auth::logged() && $Informationsystem_Controller_Show->itemsActivity('all')->groupsActivity('all');

// для магазина
Core_Auth::logged() && $Shop_Controller_Show->itemsActivity('all')->groupsActivity('all');
```

{% endcode %}

## Кэширование XXX\_Controller\_Show

Позволяет отключать кэширование контрллеров показа для администраторов сайта, но для посетителей кэширование будет работать

{% code lineNumbers="true" fullWidth="true" %}

```php
// для информационных систем
$Informationsystem_Controller_Show->cache(!Core_Auth::logged());

// для магазина
$Shop_Controller_Show->cache(!Core_Auth::logged());

// для структуры сайта / хлебных крошек
$Structure_Controller_Show->cache(!Core_Auth::logged());
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.morozovpimnev.ru/poleznosti/core_auth-logged.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
