Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.28 KB | None | 0 0
  1. <?php
  2. /*
  3. Version: 1.0
  4. Author: Kamil Hudecki
  5. */
  6.  
  7. class ControllerBlogBlog extends Controller {
  8. private $error = array();
  9. private $settings = array();
  10.  
  11. public function __construct($registry) {
  12. parent::__construct($registry);
  13.  
  14. if (file_exists(DIR_TEMPLATE . $this->config->get($this->config->get('config_theme') . '_directory') . '/css/blog/blog.css')) {
  15. $this->document->addStyle('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/css/blog/blog.css');
  16. }
  17. if (file_exists(DIR_TEMPLATE . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/masonry.pkgd.min.js')) {
  18. $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/masonry.pkgd.min.js');
  19. }
  20. if (file_exists(DIR_TEMPLATE . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/imagesloaded.pkgd.min.js')) {
  21. $this->document->addScript('catalog/view/theme/' . $this->config->get($this->config->get('config_theme') . '_directory') . '/js/imagesloaded.pkgd.min.js');
  22. }
  23. $this->load->language('blog/blog');
  24.  
  25. $this->load->model('blog/category');
  26. $this->load->model('blog/author');
  27. $this->load->model('blog/comment');
  28. $this->load->model('blog/settings');
  29.  
  30. $this->load->model('blog/article');
  31.  
  32. $this->load->model('tool/image');
  33.  
  34. // load blog settings
  35. $this->settings = $this->model_blog_settings->getSettings();
  36.  
  37. }
  38.  
  39. public function index()
  40. {
  41.  
  42.  
  43. if (isset($this->request->get['filter'])) {
  44. $filter = $this->request->get['filter'];
  45. } else {
  46. $filter = '';
  47. }
  48.  
  49. if (isset($this->request->get['sort'])) {
  50. $sort = $this->request->get['sort'];
  51. } else {
  52. $sort = 'sort_order';
  53. }
  54.  
  55. if (isset($this->request->get['order'])) {
  56. $order = $this->request->get['order'];
  57. } else {
  58. $order = 'sort_order';
  59. }
  60.  
  61. if (isset($this->request->get['page'])) {
  62. $page = $this->request->get['page'];
  63. } else {
  64. $page = 1;
  65. }
  66.  
  67. if (isset($this->request->get['limit'])) {
  68. $limit = $this->request->get['limit'];
  69. } else {
  70. $limit = $this->settings['article_page_limit'];
  71. }
  72.  
  73. if (isset($this->request->get['author'])) {
  74. $author = $this->request->get['author'];
  75. } else {
  76. $author = 0;
  77. }
  78.  
  79.  
  80. if (isset($this->request->get['search'])) {
  81. $search = $this->request->get['search'];
  82. } else {
  83. $search = '';
  84. }
  85.  
  86. if (isset($this->request->get['tag'])) {
  87. $tag = $this->request->get['tag'];
  88. } elseif (isset($this->request->get['search'])) {
  89. $tag = $this->request->get['search'];
  90. } else {
  91. $tag = '';
  92. }
  93.  
  94. $data['breadcrumbs'] = array();
  95.  
  96. $data['breadcrumbs'][] = array(
  97. 'text' => $this->language->get('text_home'),
  98. 'href' => $this->url->link('common/home')
  99. );
  100. $data['breadcrumbs'][] = array(
  101. 'text' => $this->language->get('text_blog'),
  102. 'href' => $this->url->link('blog/blog')
  103. );
  104.  
  105. if(isset($this->request->get['blog_path'])){
  106. $this->request->get['path'] = $this->request->get['blog_path'];
  107. }
  108.  
  109.  
  110. if (isset($this->request->get['path'])) {
  111. $url = '';
  112.  
  113. if (isset($this->request->get['sort'])) {
  114. $url .= '&sort=' . $this->request->get['sort'];
  115. }
  116.  
  117. if (isset($this->request->get['order'])) {
  118. $url .= '&order=' . $this->request->get['order'];
  119. }
  120.  
  121. if (isset($this->request->get['limit'])) {
  122. $url .= '&limit=' . $this->request->get['limit'];
  123. }
  124.  
  125. if (isset($this->request->get['author'])) {
  126. $url .= '&author=' . $this->request->get['author'];
  127. }
  128.  
  129. if (isset($this->request->get['search'])) {
  130. $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
  131. }
  132.  
  133. if (isset($this->request->get['tag'])) {
  134. $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
  135. }
  136.  
  137. $path = '';
  138.  
  139. $parts = explode('_', (string)$this->request->get['path']);
  140.  
  141. $category_id = (int)array_pop($parts);
  142.  
  143. foreach ($parts as $path_id) {
  144. if (!$path) {
  145. $path = (int)$path_id;
  146. } else {
  147. $path .= '_' . (int)$path_id;
  148. }
  149.  
  150. $category_info = $this->model_blog_category->getCategory($path_id);
  151.  
  152. if ($category_info) {
  153. $data['breadcrumbs'][] = array(
  154. 'text' => $category_info['name'],
  155. 'href' => $this->url->link('blog/blog', 'path=' . $path . $url)
  156. );
  157. }
  158. }
  159.  
  160. } else {
  161. $category_id = 0;
  162. }
  163.  
  164. $category_info = $this->model_blog_category->getCategory($category_id);
  165. $url = '';
  166.  
  167.  
  168. if ($category_info) {
  169. $this->document->setTitle($category_info['meta_title']);
  170. $this->document->setDescription($category_info['meta_description']);
  171. $this->document->setKeywords($category_info['meta_keyword']);
  172. $this->document->addLink($this->url->link('blog/blog', 'path=' . $this->request->get['path']), 'canonical');
  173.  
  174. $data['heading_title'] = $category_info['name'];
  175.  
  176.  
  177. // Set the last category breadcrumb
  178. $data['breadcrumbs'][] = array(
  179. 'text' => $category_info['name'],
  180. 'href' => $this->url->link('blog/blog', 'path=' . $this->request->get['path'])
  181. );
  182.  
  183. $data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  184.  
  185.  
  186.  
  187. if (isset($this->request->get['sort'])) {
  188. $url .= '&sort=' . $this->request->get['sort'];
  189. }
  190.  
  191. if (isset($this->request->get['order'])) {
  192. $url .= '&order=' . $this->request->get['order'];
  193. }
  194.  
  195. if (isset($this->request->get['limit'])) {
  196. $url .= '&limit=' . $this->request->get['limit'];
  197. }
  198.  
  199. if (isset($this->request->get['author'])) {
  200. $url .= '&author=' . $this->request->get['author'];
  201. }
  202.  
  203. if (isset($this->request->get['search'])) {
  204. $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
  205. }
  206.  
  207. if (isset($this->request->get['tag'])) {
  208. $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
  209. }
  210.  
  211. if (isset($this->request->get['author'])) {
  212. $url .= '&author=' . $this->request->get['author'];
  213. }
  214.  
  215. $data['categories'] = array();
  216.  
  217. $results = $this->model_blog_category->getCategories($category_id);
  218.  
  219. foreach ($results as $result) {
  220. $filter_data = array(
  221. 'filter_category_id' => $result['category_id'],
  222. 'filter_sub_category' => true
  223. );
  224.  
  225. $data['categories'][] = array(
  226. 'name' => $result['name'],
  227. 'href' => $this->url->link('blog/blog', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
  228. );
  229. }
  230. }else{
  231. $this->document->setTitle($this->language->get('meta_title_default'));
  232. $this->document->setDescription($this->language->get('meta_descripion_default'));
  233. $this->document->setKeywords($this->language->get('meta_keywords_default'));
  234. $data['heading_title'] = $this->language->get('heading_blog');
  235. }
  236.  
  237.  
  238. $data['text_empty'] = $this->language->get('text_empty');
  239. $data['text_quantity'] = $this->language->get('text_quantity');
  240. $data['text_sort'] = $this->language->get('text_sort');
  241. $data['text_limit'] = $this->language->get('text_limit');
  242. $data['text_comments'] = $this->language->get('text_comments');
  243. $data['text_read_more'] = $this->language->get('text_read_more');
  244. $data['text_posted_by'] = $this->language->get('text_posted_by');
  245. $data['text_category'] = $this->language->get('text_category');
  246.  
  247. $data['button_continue'] = $this->language->get('button_continue');
  248. $data['button_list'] = $this->language->get('button_list');
  249. $data['button_grid'] = $this->language->get('button_grid');
  250. $data['button_read_more'] = $this->language->get('button_read_more');
  251. $data['button_load_more'] = $this->language->get('button_load_more');
  252.  
  253. $data['settings'] = $this->settings;
  254.  
  255. $data['articles'] = array();
  256.  
  257. $filter_data = array(
  258. 'sort' => $sort,
  259. 'filter_title' => $search,
  260. 'filter_tag' => $tag,
  261. 'filter_category_id' => $category_id,
  262. 'filter_author' => $author,
  263.  
  264. 'order' => $order,
  265. 'start' => ($page - 1) * $limit,
  266. 'limit' => $limit
  267. );
  268. $article_total = $this->model_blog_article->getTotalArticles($filter_data);
  269.  
  270. $results = $this->model_blog_article->getArticles($filter_data);
  271.  
  272. if(!empty($results)){
  273. foreach ($results as $result) {
  274. $article_categories = $this->model_blog_article->getArticleCategories($result['article_id']);
  275. $article_galleries = $this->model_blog_article->getArticleGalleries($result['article_id']);
  276. $article_author = $this->model_blog_author->getAuthor($result['author_id']);
  277. if($article_author){
  278. $article_author['href'] = $this->url->link('blog/blog', 'author=' . $result['author_id']);
  279. }else{
  280. $article_author = false;
  281. }
  282.  
  283. //prepare main image/video
  284. foreach($article_categories as &$category){
  285. $category['href'] = $this->url->link('blog/blog', 'path=' . $this->model_blog_category->getCategoryPath($category['category_id']));
  286. }
  287.  
  288. $thumb = false;
  289. if(!empty($result['image'])) {
  290. $thumb = $result['image'];
  291. }
  292.  
  293. if($thumb){
  294. $this->load->model('tool/image');
  295. $thumb = $this->model_tool_image->resize($thumb, $this->settings['gallery_related_article_width'], $this->settings['gallery_related_article_height']);
  296. }
  297.  
  298. $tags_array = array();
  299.  
  300. if ($result['tags']) {
  301. $tags = explode(',', $result['tags']);
  302. foreach ($tags as $tag) {
  303. $tags_array[] = array(
  304. 'tag' => trim($tag),
  305. 'href' => $this->url->link('blog/blog', 'tag=' . trim($tag))
  306. );
  307. }
  308. }
  309.  
  310. $data['articles'][] = array(
  311. 'article_id' => $result['article_id'],
  312. 'title' => $result['title'],
  313. 'description' => html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),
  314. 'date_published' => $result['date_published'],
  315. 'tags' => $tags_array,
  316. 'thumb' => $thumb,
  317. 'author' => $article_author,
  318. 'categories' => $article_categories,
  319. 'article_list_gallery_display' => $result['article_list_gallery_display'],
  320. 'gallery' => $article_galleries,
  321. 'comments_count' => $this->model_blog_comment->getTotalCommentsForArticle($result['article_id']),
  322. 'href' => $this->url->link('blog/article', (isset($this->request->get['path']) ? 'path=' . $this->request->get['path'] . '&' : '') .'article_id=' . $result['article_id'] . $url)
  323. );
  324. }
  325.  
  326.  
  327. $url = '';
  328.  
  329. if (isset($this->request->get['limit'])) {
  330. $url .= '&limit=' . $this->request->get['limit'];
  331. }
  332.  
  333. $data['sorts'] = array();
  334.  
  335. $data['sorts'][] = array(
  336. 'text' => $this->language->get('text_default'),
  337. 'value' => 'sort_order',
  338. 'href' => $this->url->link('blog/blog', (isset($this->request->get['path']) ? 'path=' . $this->request->get['path'] . '&' : '') . 'sort=sort_order' . $url)
  339. );
  340.  
  341. $data['sorts'][] = array(
  342. 'text' => $this->language->get('text_title_asc'),
  343. 'value' => 'sort_order',
  344. 'href' => $this->url->link('blog/blog', (isset($this->request->get['path']) ? 'path=' . $this->request->get['path'] . '&' : '') . 'sort=sort_order' . $url)
  345. );
  346.  
  347.  
  348.  
  349. $url = '';
  350.  
  351. if (isset($this->request->get['filter'])) {
  352. $url .= '&filter=' . $this->request->get['filter'];
  353. }
  354.  
  355. if (isset($this->request->get['sort'])) {
  356. $url .= '&sort=' . $this->request->get['sort'];
  357. }
  358.  
  359. if (isset($this->request->get['order'])) {
  360. $url .= '&order=' . $this->request->get['order'];
  361. }
  362.  
  363. if (isset($this->request->get['author'])) {
  364. $url .= '&author=' . $this->request->get['author'];
  365. }
  366.  
  367. if (isset($this->request->get['search'])) {
  368. $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
  369. }
  370.  
  371. if (isset($this->request->get['tag'])) {
  372. $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
  373. }
  374.  
  375. if (isset($this->request->get['search'])) {
  376. $data['heading_title'] = $this->language->get('heading_blog') . ' - ' . $this->request->get['search'];
  377. }
  378.  
  379.  
  380. $data['limits'] = array();
  381.  
  382. $limits = array_unique(array($this->config->get('config_article_limit'), 25, 50, 75, 100));
  383.  
  384. sort($limits);
  385.  
  386. foreach($limits as $value) {
  387. $data['limits'][] = array(
  388. 'text' => $value,
  389. 'value' => $value,
  390. 'href' => $this->url->link('blog/blog', (isset($this->request->get['path']) ? 'path=' . $this->request->get['path'] : '') . $url . '&limit=' . $value)
  391. );
  392. }
  393.  
  394. $url = '';
  395.  
  396. if (isset($this->request->get['filter'])) {
  397. $url .= '&filter=' . $this->request->get['filter'];
  398. }
  399.  
  400. if (isset($this->request->get['sort'])) {
  401. $url .= '&sort=' . $this->request->get['sort'];
  402. }
  403.  
  404. if (isset($this->request->get['order'])) {
  405. $url .= '&order=' . $this->request->get['order'];
  406. }
  407.  
  408. if (isset($this->request->get['limit'])) {
  409. $url .= '&limit=' . $this->request->get['limit'];
  410. }
  411.  
  412. if (isset($this->request->get['author'])) {
  413. $url .= '&author=' . $this->request->get['author'];
  414. }
  415.  
  416. if (isset($this->request->get['search'])) {
  417. $url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
  418. }
  419.  
  420. if (isset($this->request->get['tag'])) {
  421. $url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
  422. }
  423.  
  424.  
  425.  
  426. $pagination = new Pagination();
  427. $pagination->total = $article_total;
  428. $pagination->page = $page;
  429. $pagination->limit = $limit;
  430. $pagination->url = $this->url->link('blog/blog', (isset($this->request->get['path']) ? 'path=' . $this->request->get['path'] : '') . $url . '&page={page}');
  431.  
  432. $data['pagination'] = $pagination->render();
  433.  
  434. $data['results'] = sprintf($this->language->get('text_pagination'), ($article_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($article_total - $limit)) ? $article_total : ((($page - 1) * $limit) + $limit), $article_total, ceil($article_total / $limit));
  435.  
  436. $data['sort'] = $sort;
  437. $data['order'] = $order;
  438. $data['limit'] = $limit;
  439.  
  440. $data['is_more'] = $article_total >= $limit ? true : false;
  441.  
  442. $data['template'] = $this->settings['article_list_template'];
  443.  
  444. $data['continue'] = $this->url->link('common/home');
  445.  
  446. $data['column_left'] = $this->load->controller('common/column_left');
  447. $data['column_right'] = $this->load->controller('common/column_right');
  448. $data['content_top'] = $this->load->controller('common/content_top');
  449. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  450. $data['footer'] = $this->load->controller('common/footer');
  451. $data['header'] = $this->load->controller('common/header');
  452.  
  453. // IF ajax request LOAD MORE
  454. if(isset($this->request->get['ajax_request']) && $this->request->get['ajax_request'] == 1){
  455. return $this->response->setOutput($this->load->view('blog/article_list/' . $this->settings['article_list_template'], $data));
  456. }
  457.  
  458. $this->response->setOutput($this->load->view('blog/blog', $data));
  459. } else {
  460. $url = '';
  461.  
  462. if (isset($this->request->get['path'])) {
  463. $url .= '&path=' . $this->request->get['path'];
  464. }
  465.  
  466. if (isset($this->request->get['filter'])) {
  467. $url .= '&filter=' . $this->request->get['filter'];
  468. }
  469.  
  470. if (isset($this->request->get['sort'])) {
  471. $url .= '&sort=' . $this->request->get['sort'];
  472. }
  473.  
  474. if (isset($this->request->get['order'])) {
  475. $url .= '&order=' . $this->request->get['order'];
  476. }
  477.  
  478. if (isset($this->request->get['page'])) {
  479. $url .= '&page=' . $this->request->get['page'];
  480. }
  481.  
  482. if (isset($this->request->get['limit'])) {
  483. $url .= '&limit=' . $this->request->get['limit'];
  484. }
  485.  
  486. $data['breadcrumbs'][] = array(
  487. 'text' => $this->language->get('text_error'),
  488. 'href' => $this->url->link('blog/blog', $url)
  489. );
  490.  
  491. $this->document->setTitle($this->language->get('text_error'));
  492.  
  493. $data['heading_title'] = $this->language->get('text_error');
  494.  
  495. $data['text_error'] = $this->language->get('text_error');
  496.  
  497. $data['button_continue'] = $this->language->get('button_continue');
  498.  
  499. $data['continue'] = $this->url->link('blog/blog');
  500.  
  501. $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
  502.  
  503. $data['column_left'] = $this->load->controller('common/column_left');
  504. $data['column_right'] = $this->load->controller('common/column_right');
  505. $data['content_top'] = $this->load->controller('common/content_top');
  506. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  507. $data['footer'] = $this->load->controller('common/footer');
  508. $data['header'] = $this->load->controller('common/header');
  509.  
  510. // IF ajax request LOAD MORE
  511. if(isset($this->request->get['ajax_request']) && $this->request->get['ajax_request'] == 1){
  512. return '';
  513. }
  514.  
  515. $this->response->setOutput($this->load->view('error/not_found', $data));
  516. }
  517. }
  518.  
  519.  
  520.  
  521.  
  522. }
  523. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement