<?php

/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.ifrights.php
 * Type:     block
 * Name:     ifrights
 * Purpose:  Check user rights
 * -------------------------------------------------------------
 */
function smarty_block_ifrights($params, $content, Smarty_Internal_Template $template, &$repeat)
{
    if (!isset($params['rights'])) {
        throw new InvalidArgumentException('Parameter rights is required');
    }

    if (!$repeat) {
        if (UserRights::hasRights($params['rights'], $params['specific'] ?? '')) {
            return $content;
        }
    }

    return '';
}
