예제 #1
0
 /**
  * default action
  */
 function index($id = null, $s = null, $x = null)
 {
     // if isset ID - we need load page with this ID
     if (!empty($id)) {
         if (is_int($id)) {
             $id = (int) $id;
             if ($id < 2) {
                 redirect('/pages/');
             }
             $page = $this->Model->getById($id);
             if (empty($page) || !$page->getPublish()) {
                 return $this->showInfoMessage(__('Can not find this page'), '/');
             }
         } else {
             if (!preg_match('#^[\\dа-яa-z_\\-./]+$#ui', $id)) {
                 redirect('/pages/');
             }
             $page = $this->Model->getByUrl($id);
             if (empty($page)) {
                 return $this->showInfoMessage(__('Can not find this page'), '/');
             }
         }
         $this->Register['active_page_id'] = $page->getId();
         $this->addToPageMetaContext('entity_title', h($page->getMeta_title()));
         $this->page_meta_keywords = $page->getMeta_keywords();
         $this->page_meta_description = $page->getMeta_description();
         $this->template = $page->getTemplate() ? $page->getTemplate() : 'default';
         $source = $page->getContent();
         $source = $this->renderString($source, array('entity' => $page));
         // Tree line
         $navi['navigation'] = get_link(__('Home'), '/');
         $cnots = array_filter(explode('.', $page->getPath()));
         if (false !== ($res = array_search(1, $cnots))) {
             unset($cnots[$res]);
         }
         if (!empty($cnots)) {
             $ids = "'" . implode("', '", $cnots) . "'";
             $pages = $this->Model->getCollection(array("`id` IN (" . $ids . ")"), array('order' => 'path'));
             if (!empty($pages) && is_array($pages)) {
                 foreach ($pages as $p) {
                     $navi['navigation'] .= __('Separator') . get_link(__($p->getName()), '/' . $this->Model->buildUrl($p->getId()));
                 }
             }
         }
         $navi['navigation'] .= __('Separator') . h($page->getName());
         $this->_globalize($navi);
         return $this->_view($source);
         //may be need view latest materials
     } else {
         $this->page_title = $this->Register['Config']->read('title');
         $latest_on_home = $this->Register['Config']->read('latest_on_home');
         $navi = null;
         //vsyakiy sluchay:)
         //if we want view latest materials on home page
         if (is_array($latest_on_home) && count($latest_on_home) > 0) {
             // Navigation Block
             $navi = array();
             $navi['add_link'] = $this->ACL->turn(array('news', 'add_materials'), false) ? get_link(__('Add material'), '/news/add_form') : '';
             $navi['navigation'] = get_link(__('Home'), '/');
             $this->_globalize($navi);
             if ($this->cached && $this->Cache->check($this->cacheKey)) {
                 $html = $this->Cache->read($this->cacheKey);
                 return $this->_view($html);
             }
             //create SQL query
             $entities = $this->Model->getEntitiesByHomePage($latest_on_home);
             //if we have records
             if (count($entities) > 0) {
                 // Get users(authors)
                 $uids = array();
                 $mod_mats = array('news' => array(), 'stat' => array(), 'loads' => array());
                 foreach ($entities as $key => $mat) {
                     $uids[] = $mat->getAuthor_id();
                     switch ($mat->getSkey()) {
                         case 'news':
                             $mod_mats['news'][$key] = $mat;
                             break;
                         case 'stat':
                             $mod_mats['stat'][$key] = $mat;
                             break;
                         case 'loads':
                             $mod_mats['loads'][$key] = $mat;
                             break;
                     }
                 }
                 $uids = '(' . implode(', ', $uids) . ')';
                 $uModelClassName = $this->Register['ModManager']->getModelNameFromModule('users');
                 $uModel = new $uModelClassName();
                 $authors = $uModel->getCollection(array('`id` IN ' . $uids));
                 // Merge records with additional fields
                 if (is_object($this->AddFields)) {
                     if (!empty($mod_mats['news']) && count($mod_mats['news']) > 0) {
                         $mod_mats['news'] = $this->AddFields->mergeRecords($mod_mats['news'], false, 'news');
                     }
                     if (!empty($mod_mats['stat']) && count($mod_mats['stat']) > 0) {
                         $mod_mats['stat'] = $this->AddFields->mergeRecords($mod_mats['stat'], false, 'stat');
                     }
                     if (!empty($mod_mats['loads']) && count($mod_mats['loads']) > 0) {
                         $mod_mats['loads'] = $this->AddFields->mergeRecords($mod_mats['loads'], false, 'loads');
                     }
                 }
                 $all_attaches = array('news' => array(), 'stat' => array());
                 foreach ($mod_mats as $module => $mats) {
                     if (count($mats) > 0 && ($module == 'news' || $module == 'stat')) {
                         $attach_ids = array();
                         foreach ($mats as $mat) {
                             $attach_ids[] = $mat->getId();
                         }
                         $ids = implode(', ', $attach_ids);
                         $attModelClassName = $this->Register['ModManager']->getModelNameFromModule($module . 'Attaches');
                         $attModel = new $attModelClassName();
                         $attaches = $attModel->getCollection(array('`entity_id` IN (' . $ids . ')'));
                         foreach ($mats as $mat) {
                             if ($attaches) {
                                 foreach ($attaches as $attach) {
                                     if ($mat->getId() == $attach->getEntity_id()) {
                                         $currAttaches = $mat->getAttaches();
                                         if (is_array($currAttaches)) {
                                             $currAttaches[] = $attach;
                                         } else {
                                             $currAttaches = array($attach);
                                         }
                                         $mat->setAttaches($currAttaches);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $entities = $mod_mats['news'] + $mod_mats['stat'] + $mod_mats['loads'];
                 ksort($entities);
                 //if we have materials for view on home page (now we get their an create page)
                 $info = null;
                 foreach ($entities as $result) {
                     foreach ($authors as $author) {
                         if ($result->getAuthor_id() == $author->getId()) {
                             $result->setAuthor($author);
                             break;
                         }
                     }
                     // Create and replace markers
                     $markers = array();
                     $this->Register['current_vars'] = $result;
                     //moder panel
                     $markers['moder_panel'] = $this->_getAdminBar($result->getId(), $result->getSkey());
                     $entry_url = entryUrl($result, $result->getSkey());
                     $markers['entry_url'] = $entry_url;
                     $matattaches = $result->getAttaches() && count($result->getAttaches()) ? $result->getAttaches() : array();
                     $announce = $result->getMain();
                     $announce = $this->Textarier->getAnnounce($announce, $result, Config::read('announce_lenght'), 0, $result->getSkey());
                     $markers['announce'] = $announce;
                     $markers['profile_url'] = get_url(getProfileUrl($result->getAuthor_id()));
                     $markers['module_title'] = $this->Register['Config']->read('title', $result->getSkey());
                     $result->setAdd_markers($markers);
                     //set users_id that are on this page
                     $this->setCacheTag(array('module_' . $result->getSkey(), 'record_id_' . $result->getId()));
                 }
                 $html = $this->render('list.html', array('entities' => $entities));
                 //write int cache
                 if ($this->cached) {
                     $this->Cache->write($html, $this->cacheKey, $this->cacheTags);
                 }
             }
             if (empty($html)) {
                 $html = __('Materials not found');
             }
             return $this->_view($html);
         }
         return $this->_view(__('Materials not found'));
     }
 }
예제 #2
0
 /**
  * @param array $theme
  * @param string $template
  * If $template = FALSE, use default template file
  * @retrun string HTML theme table with replaced markers
  */
 private function __parseThemeTable($theme, $template = false)
 {
     $htmltheme = null;
     //ICONS
     $themeicon = $this->__getThemeIcon($theme);
     $theme->setTheme_url(entryUrl($theme, $this->module));
     //ADMINBAR
     $adminbar = '';
     if ($this->ACL->turn(array('forum', 'edit_themes', $theme->getId_forum()), false) || !empty($_SESSION['user']['id']) && $theme->getId_author() == $_SESSION['user']['id'] && $this->ACL->turn(array('forum', 'edit_mine_themes', $theme->getId_forum()), false)) {
         $adminbar .= get_link('', '/forum/edit_theme_form/' . $theme->getId(), array('class' => 'fps-edit'));
     }
     if ($this->ACL->turn(array('forum', 'close_themes', $theme->getId_forum()), false)) {
         if ($theme->getLocked() == 0) {
             // заблокировать тему
             $adminbar .= get_link('', '/forum/lock_theme/' . $theme->getId(), array('class' => 'fps-close'));
         } else {
             // разблокировать тему
             $adminbar .= get_link('', '/forum/unlock_theme/' . $theme->getId(), array('class' => 'fps-open'));
         }
     }
     if ($this->ACL->turn(array('forum', 'important_themes'), false)) {
         if ($theme->getImportant() == 1) {
             $adminbar .= get_link('', '/forum/unimportant/' . $theme->getId(), array('class' => 'fps-unfix'));
         } else {
             $adminbar .= get_link('', '/forum/important/' . $theme->getId(), array('class' => 'fps-fix'));
         }
     }
     if ($this->ACL->turn(array('forum', 'delete_themes', $theme->getId_forum()), false) || !empty($_SESSION['user']['id']) && $theme->getId_author() == $_SESSION['user']['id'] && $this->ACL->turn(array('forum', 'delete_mine_themes', $theme->getId_forum()), false)) {
         $adminbar .= get_link('', '/forum/delete_theme/' . $theme->getId(), array('class' => 'fps-delete', 'onClick' => "return confirm('" . __('Are you sure') . "')"));
     }
     $theme->setAdminbar($adminbar);
     //USER PROFILE
     $author_url = __('Guest');
     if ($theme->getId_author()) {
         $author_url = get_link(h($theme->getAuthor()->getName()), getProfileUrl($theme->getId_author()));
     }
     $theme->setAuthorUrl($author_url);
     // Last post author
     $last_user = __('Guest');
     if ($theme->getId_last_author()) {
         $last_user = get_link(h($theme->getLast_author()->getName()), getProfileUrl($theme->getId_last_author()));
     }
     $last_page = get_link(__('To last'), '/forum/view_theme/' . $theme->getId() . '?page=99999');
     //NEAR PAGES
     $near_pages = '';
     if ($theme->getPosts() + 1 > $this->Register['Config']->read('posts_per_page', 'forum')) {
         $cnt_near_pages = ceil(($theme->getPosts() + 1) / $this->Register['Config']->read('posts_per_page', 'forum'));
         if ($cnt_near_pages > 1) {
             $near_pages .= '&nbsp;(';
             for ($n = 1; $n < $cnt_near_pages + 1; $n++) {
                 if ($cnt_near_pages > 5 && $n > 3) {
                     $near_pages .= '...&nbsp;' . get_link($cnt_near_pages - 1, '/forum/view_theme/' . $theme->getId() . '?page=' . ($cnt_near_pages - 1)) . '&nbsp;' . get_link($cnt_near_pages, '/forum/view_theme/' . $theme->getId() . '?page=' . $cnt_near_pages) . '&nbsp;';
                     break;
                 } else {
                     if ($n > 5) {
                         break;
                     }
                     $near_pages .= get_link($n, '/forum/view_theme/' . $theme->getId() . '?page=' . $n) . '&nbsp;';
                 }
             }
             $near_pages .= ')';
         }
     }
     $theme->setLast_page($last_page);
     $theme->setLast_user($last_user);
     $theme->setThemeicon($themeicon);
     $theme->setFps_css_class($theme->getImportant() ? 'fps-theme-important' : '');
     $theme->setNear_pages($near_pages);
     $theme->setImportantly($theme->getImportant() == 1 ? __('Important2') : '');
     return $theme;
 }
예제 #3
0
 /**
  * @param null|int $id
  */
 public function view($id = null)
 {
     //turn access
     $this->ACL->turn(array($this->module, 'view_product'));
     $id = intval($id);
     if (empty($id) || $id < 1) {
         redirect('/');
     }
     $where = array("(quantity > 0 || hide_not_exists = '0')");
     $where['id'] = $id;
     $this->Model->bindModel('attributes_group');
     $this->Model->bindModel('attributes.content');
     $this->Model->bindModel('vendor');
     $this->Model->bindModel('category');
     $this->Model->bindModel('author');
     $this->Model->bindModel('attaches');
     $entity = $this->Model->getFirst($where);
     if (empty($entity)) {
         redirect('/error.php?ac=404');
     }
     if ($entity->getAvailable() == 0 && !$this->ACL->turn(array('other', 'can_see_hidden'), false)) {
         return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/');
     }
     if (!$this->ACL->checkCategoryAccess($entity->getCategory()->getNo_access())) {
         return $this->showInfoMessage(__('Permission denied'), '/' . $this->module . '/');
     }
     Plugins::intercept('view_category', $entity->getCategory());
     // category block
     $this->_getCatsTree($entity->getCategory()->getId());
     // Comments && add comment form
     if (Config::read('comment_active', $this->module) == 1 && $this->ACL->turn(array($this->module, 'view_comments'), false) && $entity->getCommented() == 1) {
         if ($this->ACL->turn(array($this->module, 'add_comments'), false)) {
             $this->comments_form = $this->_add_comment_form($id);
         }
         $this->comments = $this->_get_comments($entity);
     }
     $tags = $entity->getTags();
     if (!empty($tags)) {
         $this->addToPageMetaContext('tags', h($tags));
     }
     $this->addToPageMetaContext('entity_title', h($entity->getTitle()));
     $this->addToPageMetaContext('category_title', h($entity->getCategory()->getTitle()));
     $navi = array();
     $navi['module_url'] = get_url('/' . $this->module . '/');
     $navi['category_url'] = get_url('/' . $this->module . '/category/' . $entity->getCategory()->getId());
     $navi['category_name'] = h($entity->getCategory()->getTitle());
     $navi['navigation'] = $this->_buildBreadCrumbs($entity->getCategory()->getId());
     $this->_globalize($navi);
     $filters = $this->__getProductsFilters($entity->getCategory()->getId());
     $filters .= $this->__getVendorsFilter($entity->getCategory()->getId());
     $this->_globalize(array('products_filters' => $filters));
     $markers = array();
     $markers['moder_panel'] = $this->_getAdminBar($entity);
     $entry_url = entryUrl($entity, $this->module);
     $markers['entry_url'] = $entry_url;
     $markers['main_text'] = $this->Textarier->parseBBCodes($entity->getDescription(), $entity);
     $entity->setAdd_markers($markers);
     $source = $this->render('material.html', array('context' => array('entity' => $entity)));
     return $this->_view($source);
 }
예제 #4
0
 /**
  * Show materials by user. User ID must be integer and not null.
  */
 public function user($id = null)
 {
     //turn access
     $this->ACL->turn(array($this->module, 'view_list'));
     $id = intval($id);
     if ($id < 1) {
         return $this->showInfoMessage(__('Can not find user'), '/' . $this->module . '/');
     }
     $usersModel = $this->Register['ModManager']->getModelInstance('Users');
     $user = $usersModel->getById($id);
     if (!$user) {
         return $this->showInfoMessage(__('Can not find user'), '/' . $this->module . '/');
     }
     //формируем блок со списком разделов
     $this->_getCatsTree();
     if ($this->cached && $this->Cache->check($this->cacheKey)) {
         $source = $this->Cache->read($this->cacheKey);
         return $this->_view($source);
     }
     // we need to know whether to show hidden
     $where = array('author_id' => $id);
     $where[] = $this->_getDeniSectionsCond();
     $total = $this->Model->getTotal(array('cond' => $where));
     list($pages, $page) = pagination($total, $this->Register['Config']->read('per_page', $this->module), '/' . $this->module . '/user/' . $id);
     $this->Register['pages'] = $pages;
     $this->Register['page'] = $page;
     $this->addToPageMetaContext('page', $page);
     $this->addToPageMetaContext('entity_title', sprintf(__('User materials'), h($user->getName())));
     $navi = array();
     $navi['add_link'] = $this->ACL->turn(array($this->module, 'add_materials'), false) ? get_link(__('Add material'), '/' . $this->module . '/add_form/') : '';
     $navi['navigation'] = get_link(__('Home'), '/') . __('Separator') . get_link(h($this->module_title), '/' . $this->module . '/') . __('Separator') . sprintf(__('User materials'), h($user->getName())) . '"';
     $navi['pagination'] = $pages;
     $navi['meta'] = __('Total materials') . $total;
     $navi['category_name'] = sprintf(__('User materials'), h($user->getName()));
     $this->_globalize($navi);
     if ($total <= 0) {
         $html = __('Materials not found');
         return $this->_view($html);
     }
     $this->Model->bindModel('author');
     $this->Model->bindModel('category');
     $params = array('page' => $page, 'limit' => $this->Register['Config']->read('per_page', $this->module), 'order' => $this->Model->getOrderParam());
     $records = $this->Model->getCollection($where, $params);
     // create markers
     foreach ($records as $entity) {
         $this->Register['current_vars'] = $entity;
         $markers = array();
         $markers['moder_panel'] = $this->_getAdminBar($entity);
         $entry_url = entryUrl($entity, $this->module);
         $markers['entry_url'] = $entry_url;
         $markers['foto_alt'] = h(preg_replace('#[^\\w\\d ]+#ui', ' ', $entity->getTitle()));
         $markers['category_url'] = get_url('/' . $this->module . '/category/' . $entity->getCategory_id());
         $markers['profile_url'] = getProfileUrl($entity->getAuthor_id());
         //set users_id that are on this page
         $this->setCacheTag(array('user_id_' . $entity->getAuthor_id(), 'record_id_' . $entity->getId(), 'category_id_' . $id));
         $entity->setAdd_markers($markers);
     }
     $source = $this->render('list.html', array('entities' => $records));
     //write int cache
     if ($this->cached) {
         $this->Cache->write($source, $this->cacheKey, $this->cacheTags);
     }
     return $this->_view($source);
 }
예제 #5
0
        foreach ($deni_sections as $deni_section) {
            $ids[] = $deni_section->getId();
        }
    }
    $ids = count($ids) ? implode(', ', $ids) : 'NULL';
    $query_params = array("`category_id` IN ({$ids})", 'premoder' => 'confirmed');
    if (!$this->ACL->turn(array('other', 'can_see_hidden'), false)) {
        $query_params['available'] = 1;
    }
    $this->Model->bindModel('category');
    $this->Model->bindModel('author');
    $records = $this->Model->getCollection($query_params, array('limit' => $this->Register['Config']->read('rss_cnt', 'rss'), 'order' => $this->Model->getOrderParam()));
    if (!empty($records) && is_array($records)) {
        $html .= '<lastBuildDate>' . date('r', strtotime($records[0]->getDate())) . '</lastBuildDate>';
        foreach ($records as $record) {
            $html .= '<item>';
            $html .= '<link>' . $sitename . entryUrl($record, $this->module) . '</link>';
            $html .= '<pubDate>' . date('r', strtotime($record->getDate())) . '</pubDate>';
            $html .= '<title>' . $record->getTitle() . '</title>';
            $html .= '<description><![CDATA[' . mb_substr($record->getMain(), 0, $this->Register['Config']->read('rss_lenght', 'rss')) . '<br />';
            $html .= 'Автор: ' . $record->getAuthor()->getName() . '<br />]]></description>';
            $html .= '<category>' . $record->getCategory()->getTitle() . '</category>';
            $html .= '<guid>' . $sitename . $this->module . '/view/' . $record->getId() . '</guid>';
            $html .= '</item>';
        }
    }
    $html .= '</channel>';
    $html .= '</rss>';
    $this->Cache->write($html, $cache_key, $cache_tags);
}
echo $html;