Архив

< Март 2024 >
П В С Ч П С В
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Вход на сайт

Тэги

Блог Alex Delphine

Здесь я оставляю разные свои мысли.

 

Меня спрашивали: "Как разрешить скачивать файлы незарегистрированным пользователям (пользователи типа гость)".

Ответ оказался прост.

Открываем файл /components/com_attachments/helper.php ищем там код:

Код PHP:
    function download_attachment($id)
    {
        // Verify the user is logged in
        $user =& JFactory::getUser();
        if ( $user->get('username') == '' ) {
            $redirect_to = JRoute::_('index.php?option=com_attachments&task=request_login');
            $this->setRedirect( $redirect_to );
            $this->redirect();
            }
 
        // Get the article ID
        $db =& JFactory::getDBO();
        $query = "SELECT * FROM #__attachments WHERE id='$id' LIMIT 1";
        $db->setQuery($query);
        $rows = $db->loadObjectList();
        if ( count($rows) != 1 ) {
            $errmsg = JText::_('ERROR INVALID ATTACHMENT ID') . " ($id)";
            JError::raiseError(500, $errmsg);
            }
        $article_id = $rows[0]->article_id;
 
        // NOTE: When 'who_can_see' mode is generalized for secure mode,
        //       we will probably need to add further checking here.
 
        // Get the component parameters
        jimport('joomla.application.component.helper');
        $params = JComponentHelper::getParams('com_attachments');
 
        // Get the other info about the attachment

и меняем на код:

Код PHP:
    function download_attachment($id)
    {
        // Get the component parameters
        jimport('joomla.application.component.helper');
        $params = JComponentHelper::getParams('com_attachments');
    $who_can_see = $params->get('who_can_see', 'logged_in');
 
        // Verify the user is logged in
        $user =& JFactory::getUser();
        if ( $who_can_see == 'logged_in' ) {
            $redirect_to = JRoute::_('index.php?option=com_attachments&task=request_login');
            $this->setRedirect( $redirect_to );
            $this->redirect();
            }
 
        // Get the article ID
        $db =& JFactory::getDBO();
        $query = "SELECT * FROM #__attachments WHERE id='$id' LIMIT 1";
        $db->setQuery($query);
        $rows = $db->loadObjectList();
        if ( count($rows) != 1 ) {
            $errmsg = JText::_('ERROR INVALID ATTACHMENT ID') . " ($id)";
            JError::raiseError(500, $errmsg);
            }
        $article_id = $rows[0]->article_id;
 
        // Get the other info about the attachment

Теперь, если в параметрах attachments опцию "Кому разрешено видеть вложения?" выставить "Любой посититель", то видеть и скачивать смогут как зарегистрированные пользователи, так и гости. Если выставить "Любой зарегистрированный пользователь", то просматривать и скачивать смогут только зарегистрированные пользователи.



У Вас не достаточно прав, для того что бы оставлять комментарии.