public function getPath($dir) { //первым делом ищем в структуре $category = new Model_Category('tree'); $categoryId = $category->getCategoryIdByUrl($dir); if ($categoryId) { $dirs = []; $categoryData = $category->getCategory($categoryId); $parents = $category->getParents($categoryId); foreach ($parents as $parent) { if ($parent['level'] > 1 && $parent['url'] != 'glavnaya') { $dirs[] = $parent['url']; } } return array('name' => $categoryData['name'], 'path' => implode('/', $dirs)); } //теперь ищем в материалах $materials = new Model_Material('group'); $materialUrl = str_replace('.html', '', $dir); $materialId = $materials->getMaterialIdByUrl($materialUrl); if ($materialId) { $materialData = $materials->getMaterial($materialId); $categoryId = $materials->getTreeIdByMid($materialId); $categoryData = $category->getCategory($categoryId); return array('name' => $materialData['name'], 'path' => $categoryData['url'] . '/' . $dir); } else { return FALSE; } }
public function action_index() { $category = new Model_Category('tree'); $data['categories'] = $category->getTree(); if (isset($_POST['add_category'])) { $categoryName = Arr::get($_POST, 'categoryName', ''); $categoryUrl = Arr::get($_POST, 'categoryUrl', ''); $parentId = Arr::get($_POST, 'parentId', ''); $previousId = Arr::get($_POST, 'previousId', ''); $res = $category->catInsert($parentId, $previousId, array('name' => $categoryName, 'url' => $categoryUrl)); if ($res) { Controller::redirect('admin'); } else { $data['errors'] = $category->getErrors(); } } if (isset($_POST['save_category'])) { $categoryName = Arr::get($_POST, 'categoryName', ''); $categoryKeywords = Arr::get($_POST, 'categoryKeywords', ''); $categoryDescription = Arr::get($_POST, 'categoryDescription', ''); $url = $this->request->param('id'); $categoryId = $category->getCategoryIdByUrl($url); $res = $category->catUpdate($categoryId, array('name' => $categoryName, 'keywords' => $categoryKeywords, 'description' => $categoryDescription)); if ($res) { Controller::redirect('admin/' . $url); } else { $data['errors'] = $category->getErrors(); } } if (isset($_POST['create_from_groups'])) { $groupId = Arr::get($_POST, 'groupId', ''); $parentId = Arr::get($_POST, 'parentId', ''); $include_content = Arr::get($_POST, 'include_content', ''); $category->createFromGroups($parentId, $groupId); if ($include_content == 'on') { } } $url = $this->request->param('id'); $widgetId = $this->request->param('widget'); $widgets = new Model_Widget(); if ($url != NULL) { $data['thisCategory'] = $category->getCategory($category->getCategoryIdByUrl($url)); //получаем виджеты для категории $data['widgets'] = $widgets->getWidgets($category->getCategoryIdByUrl($url)); } if ($widgetId) { $data['widget'] = $widgets->getWidget($widgetId); $data['widgetTypes'] = $widgets->getWidgetTypes(); } //Получаем группу пользователя $auth = Auth::instance(); $user = $auth->get_user(); // echo '<pre>'; $this->template->content = View::factory('admin/admIndex', array('data' => $data, 'user' => $this->user)); }
public function action_material() { $materials = new Model_Material('groups'); //получаем url материала $materialUrl = $this->request->param('id'); $categoryUrl = $this->request->param('category'); View::set_global('categoryName', $categoryUrl); $category = new Model_Category('tree'); $categoryId = $category->getCategoryIdByUrl($categoryUrl); $categoryTitle = $category->getCategory($categoryId); $subcategoryUrl = $this->request->param('subcategory'); if ($subcategoryUrl) { $categoryId = $category->getCategoryIdByUrl($subcategoryUrl); } $groupId = $materials->getGroupFromCategory($categoryId); $materialId = $materials->getMaterialIdByUrl($materialUrl, $groupId); $material = $materials->getMaterial($materialId); $fields = $materials->getFields2($materialId, TRUE); $title = ''; $category_url = $this->request->param('category'); $category_id = $category->getCategoryIdByUrl($category_url); $category_data = $category->getCategory($category_id); $material_url = $this->request->param('id'); $group_id = $materials->getGroupFromCategory($category_id); $material_id = $materials->getMaterialIdByUrl($material_url, $group_id); $material_data = $materials->getMaterial($material_id); $this->template->title = $title . ' ' . $material['name']; $this->template->page_title = $material['name']; $this->template->keywords = $material['keywords']; $this->template->description = $material['description']; $this->template->styles = $this->getStyles($this->styles); if (!$material['id']) { throw new HTTP_Exception_404(); } //обновляем просмотры $materials->updateViews($material['id']); $widgets[] = Request::factory('widgets/material/index/' . $material['id'])->execute(); $this->template->block_center = $widgets; }
public function action_index() { $category = new Model_Category('tree'); $widgets = new Model_Widget(); $data['categories'] = $category->getTree(); if (isset($_POST['add_category'])) { $categoryName = Arr::get($_POST, 'categoryName', ''); $categoryUrl = Arr::get($_POST, 'categoryUrl', ''); $parentId = Arr::get($_POST, 'parentId', ''); $previousId = Arr::get($_POST, 'previousId', ''); $res = $category->catInsert($parentId, $previousId, array('name' => $categoryName, 'url' => $categoryUrl)); if ($res) { Controller::redirect('admin/structure'); } else { $data['errors'] = $category->getErrors(); } } if (isset($_POST['save_category'])) { $categoryName = Arr::get($_POST, 'categoryName', ''); $categoryKeywords = Arr::get($_POST, 'categoryKeywords', ''); $categoryDescription = Arr::get($_POST, 'categoryDescription', ''); $url = $this->request->param('id'); $categoryId = $category->getCategoryIdByUrl($url); $res = $category->catUpdate($categoryId, array('name' => $categoryName, 'keywords' => $categoryKeywords, 'description' => $categoryDescription)); if ($res) { Controller::redirect('admin/structure/' . $url); } else { $data['errors'] = $category->getErrors(); } } if (isset($_POST['create_from_groups'])) { $groupId = Arr::get($_POST, 'groupId', ''); $parentId = Arr::get($_POST, 'parentId', ''); $include_content = Arr::get($_POST, 'include_content', ''); $category->createFromGroups($parentId, $groupId); if ($include_content == 'on') { } } if (isset($_POST['addWidget'])) { $widgets->addWidget($_POST); } if (isset($_POST['checked_del'])) { $delArr = Arr::get($_POST, 'check_name', array()); $widgets->deleteWidgets($delArr); } $url = $this->request->param('id'); $widgetId = $this->request->param('widget'); if ($url != NULL) { $data['thisCategory'] = $category->getCategory($category->getCategoryIdByUrl($url)); //получаем виджеты для категории $data['widgets'] = $widgets->getWidgets($category->getCategoryIdByUrl($url)); $data['widgetsTypes'] = $widgets->getWidgetTypes(); $data['positions'] = Kohana::$config->load('main')->positions; $data['templates'] = $this->getTemplates(); } if ($widgetId) { if (isset($_POST['save_widget'])) { PC::debug($_POST, "post"); //сохраняем данные виджета $data['errors'] = $widgets->saveWidget($_POST); } $data['widget'] = $widgets->getWidget($widgetId); $data['widgetTypes'] = $widgets->getWidgetTypes(); if ($data['widget']['template'] && $data['widget']['template'] != '') { $template = $data['widget']['template']; } else { $template = $data['widget']['def_template']; } $lessfile = DOCROOT . 'css/' . $data['widget']['name'] . '.less'; $jsfile = DOCROOT . 'js/' . $data['widget']['name'] . '.js'; if ($template) { $filename = DOCROOT . 'application/views/widgets/' . $template . '.php'; if (is_file($filename) && is_readable($filename) && filesize($filename) > 0) { $fh = fopen($filename, "r"); $file = fread($fh, filesize($filename)); $data['file'] = $file; fclose($fh); } } if (is_file($lessfile) && is_readable($lessfile) && filesize($lessfile) > 0) { $fh = fopen($lessfile, "r"); $file = fread($fh, filesize($lessfile)); $data['less'] = $file; fclose($fh); } if (is_file($jsfile) && is_readable($jsfile) && filesize($jsfile) > 0) { $fh = fopen($jsfile, "r"); $file = fread($fh, filesize($jsfile)); $data['js'] = $file; fclose($fh); } $num_backups = 10; $template .= '.php'; $lname = $data['widget']['name'] . '.less'; $jname = $data['widget']['name'] . '.js'; for ($n = 1; $n <= $num_backups; ++$n) { $name1 = str_replace($template, str_replace(".", "_" . $n . ".", $template), $template); $res = str_replace($template, 'backups/' . $name1, $filename); if (is_file($res)) { $data['template_backups'][$n]['file'] = $res; $data['template_backups'][$n]['name'] = $name1; } $namel = str_replace($lname, str_replace(".", "_" . $n . ".", $lname), $lname); $namej = str_replace($jname, str_replace(".", "_" . $n . ".", $jname), $jname); $lres = str_replace($lname, 'backups/' . $namel, $lessfile); if (is_file($lres)) { $data['less_backups'][$n]['file'] = $lres; $data['less_backups'][$n]['name'] = $namel; } $jres = str_replace($jname, 'backups/' . $namej, $jsfile); if (is_file($jres)) { $data['js_backups'][$n]['file'] = $jres; $data['js_backups'][$n]['name'] = $namej; } } } if (isset($_POST['imgUpload'])) { //get uploadDir $uploadDir = DOCROOT . 'img/user/menu'; $name = $_POST['filename']; //перебираем массив файлов for ($i = 0; $i < count($_FILES['file']['name']); ++$i) { if ($_FILES['file']['size'][$i] > 11100000) { echo 'Файл не должен быть больше 10 Мб'; } else { $ext = explode('.', $_FILES['file']['name'][$i]); $extension = array_pop($ext); $base = new Model_Base(); $extarr = explode('.', $_FILES['file']['name'][$i]); $ext = array_pop($extarr); $filename = $name . '.' . $ext; //$filename = substr(md5(microtime() * time()),0,rand(20,10)).'.'.$extension; if (copy($_FILES['file']['tmp_name'][$i], $uploadDir . "/" . $filename)) { $base = new Model_Base(); $options = $base->getOptions(); $size = explode(',', Arr::get($options, 'structure_photos_size')); //изменяем картинку //открываем изображение $image = Image::factory($uploadDir . "/" . $filename); //начинаем работу с нужной картинкой. Путь указан от корня приложения //меняем размер картинки if (count($size) == 2) { $image->resize($size[0], $size[1]); } //сохраняем новое изображение $image->save(NULL, 90); //первый параметр - путь, имя и формат изображения. Второй - качество изображения unset($image); } } } } //Получаем группу пользователя $auth = Auth::instance(); $user = $auth->get_user(); // echo '<pre>'; $this->template->content = View::factory('admin/admIndex', array('data' => $data, 'user' => $this->user, 'request' => $this->request, 'response' => $this->response)); }
public function action_graph($options = array("parent_id" => 4)) { $this->setopt(array("name" => "parent_id", "description" => "Ид каталога", "default" => $options["parent_id"])); $parent_id = $this->getopt("parent_id"); $model = array("items" => array()); $model_tree = new Model_Widgets_Menu('tree'); $category = new Model_Category('tree'); $parent_node = $category->getNode($parent_id); $level = $parent_node["level"]; //Получаем список меню $items = $model_tree->menuItems($parent_id, $level + 1); foreach ($items as $key => $item) { $this_category = $category->getCategory($category->getCategoryIdByUrl($item['url'])); $category_id = $this_category['id']; $cat_photo = '/img/user/menu/' . $category_id . '_' . $item['url']; $cat_photo_path_jpg = $cat_photo . ".jpg"; $cat_photo_path_png = $cat_photo . ".png"; $cat_photo_path = "/img/noimg.png"; if (file_exists(DOCROOT . $cat_photo_path_jpg)) { $cat_photo_path = $cat_photo_path_jpg; } elseif (file_exists(DOCROOT . $cat_photo_path_png)) { $cat_photo_path = $cat_photo_path_png; } $model["items"][] = array("href" => "/" . $item["parent"] . "/" . $item["url"], "photo" => Route::url('miniimg3', array('filename' => $cat_photo_path)), "name" => $item["name"]); } $this->set_template("widgets/menu/graph.php", "twig")->render($model)->body(); }
public function getRandomMaterials($gid, $limit, $time = 0) { $data = array(); $query = 'SELECT count(a.id) FROM materials a, group_materials_rel b WHERE b.gid = ' . $gid . ' AND b.mid = a.id'; $count = DB::query(Database::SELECT, $query)->execute()->current(); $offset = rand(0, $count['count(a.id)'] - 2); $query = 'SELECT a.* FROM materials a, group_materials_rel b WHERE b.gid = ' . $gid . ' AND b.mid = a.id LIMIT ' . $offset . ', ' . $limit; $materials = DB::query(Database::SELECT, $query)->execute(); foreach ($materials as $material) { //получаем поля $fields = $this->getFields2($material['id'], TRUE); $category = new Model_Category('tree'); $node = $category->getCategory($this->getTreeIdByMid($material['id'])); $arr = array_merge($material, $fields); $arr['node'] = $node['url']; $data[$material['id']] = $arr; } return $data; }