public function search() { $lang = Router::getLanguage(); $dbc = Connect::getConnection(); $indexModel = new IndexModel(); $material_type_array = $indexModel->getType_of_Materials(); $data_total = array(); foreach ($material_type_array as $val) { $material_type = $val['type_name']; if ($material_type != 'Admin') { $fields = new FieldsModel($material_type); $fields_list = ''; $fields_list_value = ''; foreach ($fields->getFields() as $v) { if ($v != 'id' && $v != 'alias' && $v != 'id_' . $material_type . '') { $fields_list .= ',`' . $v . '` '; $fields_list_value .= $v . " LIKE '%" . $this->search_request . "%' OR "; } } $fields_list_value = trim($fields_list_value, 'OR '); $sql = "SELECT `id`, `id_{$material_type}` {$fields_list}, `alias` FROM `{$material_type}_{$lang}` WHERE {$fields_list_value}"; $placeholders = array(); $data = $dbc->getDate($sql, $placeholders); $data_total[$material_type] = $data; } } return $data_total; }
public static function getBreadcrumbs() { $url_elements = Router::getUrlArray(); if (count($url_elements)) { if (strtolower(current($url_elements)) == 'admin') { array_shift($url_elements); } } $alias_array = array(); $i = 0; if (Router::getLanguage() != Config::get('default_language')) { $i = 1; } while (count($url_elements) > $i) { $ue = $url_elements; $alias_array[] = implode('/', $ue); array_pop($url_elements); } $alias_array = array_reverse($alias_array); $bread_crumbs_array = self::breadCrumbsArray($alias_array); if (Config::get('bread_crumbs_last_element_view') != 'yes') { array_pop($bread_crumbs_array); } return Controller::render_bread_crumbs($bread_crumbs_array); }
public function getMenuDatePage($id_page) { $lang = Router::getLanguage(); $dbc = Connect::getConnection(); $placeholders = array('id_page' => $id_page); $sql = "SELECT mm.id as id_menu_item, mm.id_parent_page, mm_{$lang}.name AS name_menu_item, mm_{$lang}.alias_menu, mm.status\n FROM main_menu mm JOIN main_menu_{$lang} mm_{$lang} ON mm.id_page = :id_page AND mm.id = mm_{$lang}.id_main_menu"; $date = $dbc->getDate($sql, $placeholders); return $date; }
public function logAction() { $args = array(); require LIB_DIR . 'patterns.php'; $args['url_register'] = '/' . Router::getLanguage() . '/' . $url_patterns['register']['pattern_' . Router::getLanguage()]; $args['url_login'] = '******' . Router::getLanguage() . '/' . $url_patterns['login']['pattern_' . Router::getLanguage()]; $args['url_logout'] = '/' . Router::getLanguage() . '/' . $url_patterns['logout']['pattern_' . Router::getLanguage()]; return $this->render_login_logout($args); }
protected function render(array $args = array(), $tpl = null) { extract($args); ob_start(); require $this->file_path($tpl); //$templateFile; $content = ob_get_clean(); ob_start(); ob_start(); require VIEW_DIR . 'img_content.phtml'; //$templateFile; $img_content = ob_get_clean(); ob_start(); require VIEW_DIR . 'searchForm.phtml'; $search = ob_get_clean(); $menu = new MenuController(); $main_menu = $menu->mainMenuAction(); $login_logout = new SecurityController(); $login_logout_block = $login_logout->logAction(); $news = new NewsController(); $news_block = $news->getBlockAction(); $menu_block = $menu->getBlockMainMenuAction(); $basic_page_bl = new IndexController(); $basic_page_block = $basic_page_bl->getBasicPageBlockAction(); if (Router::getLanguage() == 'uk') { $lang = 'en'; } else { $lang = 'uk'; } $lang_icon = Lang::url_translation($lang, Config::get('default_id_error_204')); $bread_crumbs = BreadCrumbs::getBreadcrumbs(); $footer_text = __t('footer_text'); ob_start(); require VIEW_DIR . 'layout.phtml'; return ob_get_clean(); }
public function searchAction() { $page_data = $this->index('basic_page'); $request = new Request(); if ($request->isPost()) { $search = new SearchModel($request); if (!$search->isSmall()) { if (!$search->isLarge()) { $search_data = $search->search(); } else { Session::setFlash(__t('long_inquiry')); } } else { Session::setFlash(__t('short_inquiry')); } } $search_array = array(); if (isset($search_data)) { foreach ($search_data as $material_type) { foreach ($material_type as $val) { $search_array[] = $val; } } } $items_count = count($search_array); $items_per_page = Config::get('search_per_page'); $request = new Request(); $currentPage = $request->get('page') ? (int) $request->get('page') : 1; $data_pagination = self::getPagination($items_count, $items_per_page, $currentPage); if ($items_count) { $data_search_page = array_chunk($search_array, $items_per_page, true); if (isset($data_search_page[$currentPage - 1])) { $data_search_page = $data_search_page[$currentPage - 1]; } else { throw new Exception('Page (' . Router::getUri() . ') not found', 404); } } else { $data_search_page = null; } $data_url = explode('?', Router::getUri()); $lang = Router::getLanguage() == Config::get('default_language') ? '' : Router::getLanguage() . '/'; // $search_request = $search->getSearchRequest(); $args = array('page_data' => $page_data, 'data_search' => $data_search_page, 'data_pagination' => $data_pagination, 'data_url' => $data_url[0], 'lang' => $lang, 'items_count' => $items_count, 'img' => $page_data['img']); return $this->render($args); }
<?php require_once '../Library/init.php'; Session::start(); try { $request = new Request(); $content = Router::get_content_by_uri($request->server('REQUEST_URI')); } catch (PDOException $e) { IndexController::errorAction($e); //$content = $e->getMessage(); $lang = Router::getLanguage(); $content = Router::get_content_by_uri($lang . '/' . Router::get_alis_by_id(Config::get('default_id_error_500'), $lang)); } catch (Exception $e) { IndexController::errorAction($e); $lang = Router::getLanguage(); if ($e->getCode() == 403) { $content = Router::get_content_by_uri($lang . '/' . Router::get_alis_by_id(Config::get('default_id_error_403'), $lang)); } elseif ($e->getCode() == 2) { $content = Router::get_content_by_uri($lang . '/' . Router::get_alis_by_id(Config::get('not_publish'), $lang)); } elseif ($e->getCode() == 204) { $content = Router::get_content_by_uri($lang . '/' . Router::get_alis_by_id(Config::get('default_id_error_204'), $lang)); } else { $content = Router::get_content_by_uri($lang . '/' . Router::get_alis_by_id(Config::get('default_id_error_404'), $lang)); } } echo $content;
public function getBasicPageBlock() { $dbc = Connect::getConnection(); $placeholders = array(); $sql = "SELECT `id_page` FROM `pages_in_block`"; $d = $dbc->getDate($sql, $placeholders); $data = array(); if (!empty($d)) { $id_pages = ''; foreach ($d as $v) { $id_pages .= ',' . $v['id_page']; } $id_pages = substr($id_pages, 1); $placeholders = array(); $lang = Router::getLanguage(); $sql = "SELECT bp_{$lang}.title, bp_{$lang}.alias, bp.id_page FROM basic_page_{$lang} bp_{$lang} JOIN basic_page bp ON bp_{$lang}.id_basic_page = bp.id AND bp.id_page IN({$id_pages})"; $data = $dbc->getDate($sql, $placeholders); } return $data; }
public function editAction() { if (Session::hasUser('admin')) { $indexModel = new IndexModel(); $data_page = $indexModel->getPage(Router::getId(), Router::getLanguage(), $this->material_type); $menuModel = new MenuModel(); $data = $menuModel->getMainMenu('uk'); $menuController = new MenuController(); $main_menu_array = $menuController->menuArray($data); $data_menu_item = $menuModel->getMenuDatePage($data_page[0]['id']); $redirect_status = null; $request = new Request(); $editModel = new AddEditModel($request, $this->material_type); if ($request->isPost()) { if ($editModel->isValid()) { if ($editModel->isAliasExist($data_page[0]['id'])) { if ($editModel->inMenu()) { $file_data = array('max_image_size' => Config::get('max_image_size'), 'max_image_width' => Config::get('max_image_width'), 'max_image_height' => Config::get('max_image_height')); $fileUpload = new UploadFile($request, $file_data); $redirect_status = $fileUpload->uploadImg($request, $this->material_type); if ($redirect_status) { $editModel->edit($data_page[0]['id']); } } else { $with_without_menu = 1; $editModel->edit($data_page[0]['id'], $with_without_menu); } } else { Session::setFlash('Документ с таким псевдонимом уже существует!'); } } else { Session::setFlash('Поле "Заголовок" обязательно для заполнения'); } } $this->rewrite_file_alias(); $args = array('data_page' => $data_page, 'data_menu' => $main_menu_array, 'edit_model' => $editModel, 'data_menu_item' => $data_menu_item, 'redirect' => $request->post('redirect'), 'redirect_status' => $redirect_status, 'without_menu' => $request->post('without_menu'), 'menu_disable' => Config::get('menu_disable'), 'id' => $data_page[0]['id']); $tpl = 'edit' . str_replace(' ', '', ucwords(str_replace('_', ' ', $this->material_type))); return $this->render_admin($args, $tpl); } else { throw new Exception('Access denied', 403); } }
public static function menu_recurs($array = array(), $id_class = null, $active_page_class = null) { $menu_class = isset($id_class) ? $id_class : ''; echo '<ul ' . $menu_class . '>'; $lang = ''; $class = ''; if (Router::getLanguage() != Config::get('default_language')) { $lang = Router::getLanguage() . '/'; } foreach ($array as $v) { $onclick = ''; if ($v['alias_menu'] == "admin/zurnal_oshibok/clean") { $onclick = 'onclick="return confirm(\'Вы уверены что хотите удалить журнал ошибок?\')"'; } if (isset($v['child'])) { if (isset($active_page_class) && $v['id_page'] == Router::getId()) { $class = $active_page_class; } echo '<li > <a href="/' . $lang . $v['alias_menu'] . '" class="' . $class . '"' . $onclick . ' >' . $v['name'] . '</a>'; $class = ''; self::menu_recurs($v['child'], $id_class = null, $active_page_class); echo '</li>'; } else { if (isset($active_page_class) && $v['id_page'] == Router::getId()) { $class = $active_page_class; } echo '<li > <a href="/' . $lang . $v['alias_menu'] . '"class="' . $class . '" ' . $onclick . '>' . $v['name'] . '</a></li>'; $class = ''; } } echo '</ul>'; }
public function edit($id, $with_without_menu = null) { $lang = Router::getLanguage(); $placeholders = array('id' => $id); $dbc = Connect::getConnection(); $sql = "SELECT bp_{$lang}.id_{$this->material_type} AS id FROM {$this->material_type}_{$lang} bp_{$lang} JOIN {$this->material_type} bp ON bp.id = bp_{$lang}.id_{$this->material_type}\n AND bp.id_page = :id"; $date = $dbc->getDate($sql, $placeholders); $id_[$this->material_type] = $date[0]['id']; $placeholders = array('title' => $this->title, 'alias' => $this->new_alias, 'id_' . $this->material_type => $id_[$this->material_type]); $sql = "UPDATE `{$this->material_type}_{$lang}` SET `title`= :title,`alias`= :alias {$this->additional_fields_key_value} WHERE id_{$this->material_type} = :id_{$this->material_type} "; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); $publish = $this->publication ? 1 : 0; $placeholders = array('id' => $id, 'publish' => $publish); $sql = "UPDATE `pages` SET `status`= :publish WHERE id = :id"; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); if ($this->img_name) { $placeholders = array('id' => $id, 'img' => $this->img); $sql = "UPDATE `{$this->material_type}` SET `img`= :img WHERE id_page = :id"; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); } // Проверка - есть ли для этого докумета пункт меню $placeholders = array('id' => $id); $sql = "SELECT id FROM `main_menu` WHERE id_page = :id "; $date = $dbc->getDate($sql, $placeholders); $isInMenu = empty($date); //Если полученный массив пустой добавляем инф. в меню if ($isInMenu) { $placeholders = array('id_new_page' => $id, 'id_parent' => $this->id_parent); $sql = "INSERT INTO `main_menu`(`id_page`, `id_parent_page`, `status`) VALUES (:id_new_page,:id_parent,1)"; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); $sql = "SELECT MAX(id) AS max_id FROM main_menu"; $placeholders = array(); $date = $dbc->getDate($sql, $placeholders); $id_new_menu = $date[0]['max_id']; $placeholders = array('id_new_menu' => $id_new_menu, 'title' => $this->title_or_menu_name, 'alias' => $this->new_alias); $lang = Config::get('default_language'); $sql = "INSERT INTO `main_menu_{$lang}`(`id_main_menu`, `name`, `alias_menu`) VALUES (:id_new_menu,:title,:alias)"; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); foreach (Config::get('languages') as $v) { if ($v != $lang) { $placeholders = array(); $sql = "SELECT `alias_menu` FROM main_menu_{$v} WHERE id_main_menu =\n (SELECT id FROM main_menu WHERE id_page = (SELECT id_parent_page FROM main_menu WHERE id_page = {$id}) )"; $data = $dbc->getDate($sql, $placeholders); $parent_alias = $data[0]['alias_menu']; $sql = "SELECT n_{$v}.title FROM {$this->material_type}_{$v} n_{$v} JOIN {$this->material_type} n ON n_{$v}.id_{$this->material_type} = n.id AND n.id_page = {$id}"; $data = $dbc->getDate($sql, $placeholders); $title = $data[0]['title']; $translitClass = new Translit($title); $translit = $translitClass->translit; $alias_arr = array($parent_alias, $translit); $new_alias = implode('/', $alias_arr); $placeholders = array('id_new_menu' => $id_new_menu, 'title' => $title, 'alias' => $new_alias); $sql = "INSERT INTO `main_menu_{$v}`(`id_main_menu`, `name`, `alias_menu`) VALUES (:id_new_menu,:title,:alias)"; $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); } } } if (!isset($with_without_menu)) { $lang = Config::get('default_language'); $this->edit_menu($id, $lang, $this->new_alias); foreach (Config::get('languages') as $v) { if ($v != $lang) { $sql = "SELECT `alias_menu` FROM main_menu_{$v} WHERE id_main_menu =\n (SELECT id FROM main_menu WHERE id_page = (SELECT id_parent_page FROM main_menu WHERE id_page = {$id}) )"; $data = $dbc->getDate($sql, $placeholders); $parent_alias = $data ? $data[0]['alias_menu'] : null; // Debugger::PrintR($data); $sql = "SELECT mm_{$v}.alias_menu, mm_{$v}.name FROM main_menu_{$v} mm_{$v} JOIN main_menu mm ON mm_{$v}.id_main_menu = mm.id AND mm.id_page = {$id}"; $data = $dbc->getDate($sql, $placeholders); $old_alias = $data[0]['alias_menu']; $alias_arr = explode('/', $old_alias); $last_element = array_pop($alias_arr); $alias_arr = array($parent_alias, $last_element); $new_alias = $alias_arr[0] ? implode('/', $alias_arr) : $alias_arr[1]; $title = $data[0]['name']; $sql = "UPDATE {$this->material_type}_{$v} bp_{$v} JOIN {$this->material_type} bp SET `alias`= " . '"' . $new_alias . '"' . " WHERE bp_{$v}.id_{$this->material_type} = bp.id AND bp.id_page = {$id} "; $placeholders = array(); $sth = $dbc->getPDO()->prepare($sql); $sth->execute($placeholders); $this->edit_menu($id, $v, $new_alias, $title); } } } else { $edit = 1; $deleteModel = new DeleteModel($id, $edit); $deleteModel->delete_from_menu(); } }
public static function getStaticTranslation($key) { $lang = Router::getLanguage(); //print_r(self::$static_translation); return isset(self::$static_translation[strtolower($key)][$lang]) ? self::$static_translation[strtolower($key)][$lang] : self::$static_translation[strtolower($key)][Config::get('default_language')]; }