Язык
Контакты
GitHub
Поддержка
Регистрация
Войти
Логин: Пароль: Запомнить:
Пользователи
Последние сообщения
Ответить
1

Список материалов пользователя

Сашка_из_Шебекино

  • Заклинатель Атома
  • Пользователь
  • 1803
  • Репутация:87 
  • Предупреждения: 0 
  • Регистрация:
    27 Мар 2011
#1
Вот скрипт показывает все файлы пользователя. На стабильной и альфа версиях вроде работает. Ставьте на свой страх и риск - скрипт сделал чтоб работало, а ошибки исправит Drunya :)

Откройте /modules/loads/index.php

и перед

Code:
}
?>

Вставьте:

Code:
public function user_files($user_id) {
        //turn access
        $this->ACL->turn(array('loads', 'view_list'));
        
        
        //формируем блок со списком  разделов
        $this->_getCatsTree();
        
        
        if ($this->cached && $this->Cache->check($this->cacheKey)) {
            $html = $this->Cache->read($this->cacheKey);
        } else {
        
        
            //Узнаем кол-во материалов в БД
            $total = $this->DB->select('loads', DB_COUNT, array('cond' => array('available' => '1','author_id' => $user_id)));

            $cntPages = ceil( $total / Config::read('per_page', 'loads') );
            if ( isset($_GET['page']) ) {
                $page = (int)$_GET['page'];
                if ( $page < 1 ) $page = 1;
            } else {
                $page = 1;
            }
            if ( $page > $cntPages ) $page = $cntPages;
            $pages = ($cntPages > 1) ? pagination($page, $cntPages, '/loads/user_files/'.$user_id) : '&nbsp;';
            
            
            //navigation panel
            $navi = array();
                if ($this->ACL->turn(array('loads', 'add_materials'), false))
                $navi['{ADD_LINK}'] = '<div class="submit"><a class="a_submit" href="/loads/add_form">Добавить материал</a></div>';
            $navi['{NAVIGATION}'] = get_link(__('Home'), '/') . __('Separator') . get_link(h($this->module_title),'/loads/') . __('Separator') . 'Файлы пользователя';
            $navi['{PAGINATION}'] = $pages;
            $navi['{META}'] = __('Count all material') . $total;
            $this->_globalize($navi);
            
            if ($total == 0) {
                $html = 'Пользователь не выложил файлы :(';
                return $this->_view($html);
            }
            

            $html = '';
            // get data 
            $conditions = array();
            if (!$this->ACL->turn(array('other', 'can_see_hidden'), false)) $conditions['`a`.`available`'] = '1';
            $sql = $this->DB->select('loads', DB_ALL, array(
                'joins' => array(
                    array(
                        'table' => 'loads_sections',
                        'type' => 'LEFT',
                        'alias' => 'b',
                        'cond' => 'a.`category_id` = b.`id`',
                    ),
                    array(
                        'table' => 'users',
                        'type' => 'LEFT',
                        'alias' => 'd',
                        'cond' => 'd.`id` = a.`author_id`',
                    ),
                ),
                'fields' => array('a.*', 'b.`title` as category_name','d.`name` AS author'
                , 'd.`status` AS author_status'),
                'alias' => 'a',
                'cond' => array("`author_id` = '" . $user_id . "'"),
                'order' => getOrderParam(__CLASS__),
                'page' => $page,
                'limit' => Config::read('per_page', 'loads'),
            ));
            // Additional fields
            if (is_object($this->AddFields) && count($sql) > 0) {
                $sql = $this->AddFields->mergeRecords($sql);
            }
            
            
            // get ids list
            $ids = array();
            foreach ($sql as $result) {
                $ids[] = $result['id'];
            }
            $ids = implode(', ', $ids);
            $attaches = $this->DB->select($this->module . '_attaches', DB_ALL, array('cond' => array('`entity_id` IN ('.$ids.')')));
            
            
            //ITERATION RECORDS
            foreach ($sql as $result) {
                $markets = array();
                $result = $this->Parser->quoteTags($result);
                $_SESSION['current_vars'] = $result;
                $htmlloads = $this->Parser->getAndParse('tablemat.html');

                
                $rec_attaches = array();
                if (!empty($attaches) && count($attaches) > 0) {
                    foreach ($attaches as $k => $attach) {
                        if ($attach['entity_id'] == $result['id']) {
                            $rec_attaches[] = $attach;
                            unset($attaches[$k]);
                        }
                    }
                }
                
                
                $markets['{MODER_PANEL}'] = $this->_getAdminBar($result);
                $entry_url = get_url(entryUrl($result, $this->module));
                $markets['{ENTRY_URL}'] = $entry_url;

                
                $announce = $this->Parser->unquoteTags($result['description']);
                // replace image tags in text
                if (!empty($rec_attaches) && count($rec_attaches) > 0) {
                    $attachDir = R . 'sys/files/' . $this->module . '/';
                    foreach ($rec_attaches as $attach) {
                        if ($attach['is_image'] == 1 && file_exists($attachDir . $attach['filename'])) {
                            $announce = str_replace('{IMAGE'.$attach['attach_number'].'}'
                            , '[img]' . get_url('/sys/files/'.$this->module.'/'.$attach['filename']).'[/img]'
                            , $announce);
                        }
                    }
                }
                $announce = $this->Textarier->getAnnounce($announce, $entry_url, 0, 
                    Config::read('announce_lenght', 'loads'), $result);
                $markets['{ANNOUNCE}'] = $this->Parser->quoteTags($announce);
                
                
                foreach ($result as $key=>$value) {
                    $markets['{'.strtoupper($key).'}'] = h($value);  
                }
                
                $markets['{LOADS}'] = $result['downloads'];
                $markets['{PROFILE_URL}'] = getProfileUrl($result['author_id']);
                $markets['{CATEGORY_URL}'] = get_url('/loads/category/' . $result['category_id']);
                $html .= $this->_replaceMarkets($markets, $htmlloads);


                //prepear cache tags
                $this->setCacheTag(array(
                    'user_id_' . $result['author_id'],
                    'record_id_' . $result['id'],
                ));
            }
    
            $materials_tpl = $this->Parser->getAndParse('materials_container.html');
            $markets = array(
                '{MATERIALS}' => $html,
            );
            $html = $this->_replaceMarkets($markets, $materials_tpl);

            if ($this->cached)
                $this->Cache->write($html, $this->cacheKey, $this->cacheTags);
        }
        return $this->_view($html);
    }

файлы пользователя доступны по адресу http://сайт/loads/user_files/айди_юзера

Отредактировано автором 5 Мар 2012

Drunya

  • Man of God
  • Админ
  • 3527
  • Репутация:110 
  • Предупреждения: 0 
  • Регистрация:
    30 Ноя -0001
#2
о круто) Сенк. Надо будет вставить в сборку

Я горжусь тем, что создал бесплатную CMS - AtomX. И люблю нашу команду)
1
Сейчас online: 5. Зарегистрированных: 0. Гостей: 5.