instant_search = Tools::getValue('instantSearch'); $this->ajax_search = Tools::getValue('ajaxSearch'); if ($this->instant_search || $this->ajax_search) { $this->display_header = false; $this->display_footer = false; } } public function setMedia() { parent::setMedia(); /*$this->context->controller->addCss(ROOTDIR.'news/newMessage.css', 'all');*/ $this->context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/jquery.scrollTo.js', 'all'); } /** * Start forms process * @see FrontController::postProcess() */ public function postProcess() { if (Tools::isSubmit('sendComment') && Tools::isSubmit('idnews') && (int)Tools::getValue('idnews')>0) { if (!($name = Tools::getValue('user_name')) || !Validate::isCleanHtml($name)) $this->errors[] = Tools::displayError('Invalid user name'); else if (!($email = Tools::getValue('user_mail')) || !Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); else if ($web = Tools::getValue('user_web') && !Validate::isCleanHtml($web)) $this->errors[] = Tools::displayError('Invalid web address'); //$content = Tools::getValue('content'); // Html entities is not usefull, iscleanHtml check there is no bad html tags. else if (!$content = Tools::getValue('content')) $this->errors[] = Tools::displayError('Commentary cannot be blank'); else if (!Validate::isCleanHtml($content)) $this->errors[] = Tools::displayError('Invalid commentary'); else{ $parent_id = (int)Tools::getValue('parent_id',0); Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'news_comments` (`news_comment_id`, `news_id`, `parent_id`, `name`,`content`,`email`,`web`) VALUES (null,'.(int)Tools::getValue('idnews').' , '.(int)$parent_id.', \''.$name.'\', \''.$content.'\', \''.$email.'\', \''.$web.'\')'); } $link = new Link(); // Tools::redirect($link->getPageLink('blog',true).'?idnews='.(int)Tools::getValue('idnews')); Tools::redirect($link->getBlogLink((int)Tools::getValue('idnews'))); } } public function process() { parent::process(); if ($this->instant_search || $this->ajax_search){ $this->search_query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q'))); } elseif(Tools::isSubmit('submit_search') && Tools::isSubmit('search_query')){ $this->search_query = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_query'))); } //print_r(''.$query); setlocale(LC_ALL, "sk_SK.utf8"); $this->_newsId = ($_GET['idnews']) ? $_GET['idnews'] : NULL; $category = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'news_category`'); if($category){ $GLOBALS['category'] = array(); foreach($category as $row){ $GLOBALS['category'][''.$row['news_id_category']] = $row['name']; } $this->_category = $GLOBALS['category']; } else{ $this->_category = $GLOBALS['category']; } $this->_categoryId = Tools::getValue('category',0); $this->_tag = Tools::getValue('tag'); $this->_date = split('-',Tools::getValue('date',0)); if ($this->_newsId) { $category = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'news_category`'); $archive = Db::getInstance()->ExecuteS('SELECT COUNT(news_id) AS count, YEAR(news_timestamp) AS year, MONTH(news_timestamp) AS month FROM `'._DB_PREFIX_.'news` GROUP BY YEAR(news_timestamp),MONTH(news_timestamp) ORDER BY YEAR(news_timestamp) DESC, MONTH(news_timestamp) DESC'); foreach($archive as &$arch){ $arch['month1'] = strftime('%B', mktime(0, 0, 0, (int)$arch['month'], 1,(int)$arch['year'])); } $data = self::getNewsData($this->_newsId); $dataComments = self::getNewsDataComments($this->_newsId); self::$smarty->assign('newsId', $this->_newsId); self::$smarty->assign('categoryId', $this->_categoryId); self::$smarty->assign('categoryTitle', $this->_category[$this->_categoryId]); self::$smarty->assign('blogCategory', $category); self::$smarty->assign('blogArchive', $archive); self::$smarty->assign('data', $data); self::$smarty->assign('dataComments', $dataComments); self::$smarty->assign('dataCommentsCount', count($dataComments)); self::$smarty->assign('errors', $this->errors); //galéria if ($data['news_id_gallery']) { self::$smarty->assign('images', self::getFieldsImage($data['news_id_gallery'])); $sql = 'SELECT gallery_title FROM ps_gallery WHERE gallery_id = '.$data['news_id_gallery']; $result = Db::getInstance()->getRow($sql); $row = $result; self::$smarty->assign('galleryName', $row['gallery_title']); } } else { //include_once(PS_ADMIN_DIR.'/news/paginator.php'); //$pages = new Paginator; //$sql = 'SELECT * FROM ps_news WHERE news_id_category = '.$this->_categoryId.' ORDER BY news_timestamp DESC LIMIT 0,20'; //$result = Db::getInstance()->NumRows($sql); //$pages->items_total = $result; //$pages->mid_range = 7; //$pages->paginate(); //self::$smarty->assign('displayPages', $pages->display_pages()); //self::$smarty->assign('displayJumpMenu', $pages->display_jump_menu()); //self::$smarty->assign('displayItemsPerPage', $pages->display_items_per_page()); self::$smarty->assign('news_dir', PS_ADMIN_DIR.'/news/'); self::$smarty->assign('categoryTitle', $this->_category[$this->_categoryId]); self::$smarty->assign('categoryID', $this->_categoryId); self::$smarty->assign('data', self::getFields()); if ($this->ajax_search && $this->search_query != '') { $searchResults = self::getFields(); $link = new Link(); foreach($searchResults as &$row){ // $row['news_link'] = $link->getPageLink('blog',true).'?idnews='.(int)$row['news_id']; $row['news_link'] = $link->getBlogLink((int)$row['news_id']); } die(Tools::jsonEncode($searchResults)); exit; } } } public function displayContent() { parent::displayContent(); self::$smarty->display(PS_ADMIN_DIR.'/news/news.tpl'); } public function getFields() { if (!$this->instant_search && !$this->ajax_search && !$this->search_query){ $sql = 'SELECT * FROM ps_news WHERE 1=1'.($this->_categoryId != 0 ? ' AND news_id_category = '.$this->_categoryId : '').($this->_tag != '' ? ' AND news_tags LIKE \'%'.$this->_tag.'%\'' : '').(count($this->_date) == 2 ? ' AND MONTH(news_timestamp) = \''.$this->_date[0].'\' AND YEAR(news_timestamp) = \''.$this->_date[1].'\'' : '').' ORDER BY news_timestamp DESC LIMIT 0,21'; $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); $i = 0; foreach ($result as &$row) { $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['news_timestamp'])); $arr[$i] = $row; $i++; } return $arr; } elseif($this->search_query != ''){ $searchWords = explode(" ", $this->search_query); $where = array(); foreach($searchWords as $word){ $word_dia = array('á', 'ä', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ĺ', 'ň', 'ř', 'ŕ', 'š', 'ť', 'ú', 'ů', 'ó', 'ô', 'ž', 'ý', 'Á', 'Ä', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ĺ', 'Ň', 'Ř', 'Ŕ', 'Š', 'Ť', 'Ú', 'Ů', 'Ó', 'Ô', 'Ž', 'Ý'); $word_no_dia = array('a', 'a', 'c', 'd', 'e', 'e', 'i', 'l', 'l', 'n', 'r', 'r', 's', 't', 'u', 'u', 'o', 'o', 'z', 'y', 'A', 'A', 'C', 'D', 'E', 'E', 'I', 'L', 'L', 'N', 'R', 'R', 'S', 'T', 'U', 'U', 'O', 'O', 'Z', 'Y'); $word1 = str_replace($word_dia, $word_no_dia, $word); if(str_replace(' ','',$word1) != ''){ $where[] = '`news_title` LIKE \'%'.$word1.'%\''; $where[] = '`news_body` LIKE \'%'.$word1.'%\''; } } $sql = 'SELECT DISTINCT * FROM `'._DB_PREFIX_.'news` n LEFT JOIN `'._DB_PREFIX_.'news_category` nc ON (n.`news_id_category` = nc.`news_id_category`) WHERE 1=1 AND ('.implode(' OR ', $where).') ORDER BY news_timestamp DESC LIMIT 0,21'; //SELECT * FROM `ps_news` WHERE `news_title` LIKE '%test1%' OR `news_title` LIKE '%lore%' $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); $i = 0; foreach ($result as &$row) { $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['news_timestamp'])); $arr[$i] = $row; $i++; } return $arr; } } public function getNewsData($idNews) { $sql = 'SELECT * FROM ps_news WHERE news_id = '.$idNews; $result = Db::getInstance()->getRow($sql); setlocale(LC_ALL, "sk_SK.utf8"); $result['timestamp'] = strftime('%d. %B %Y', strtotime($result['news_timestamp'])); $result['news_img'] = str_ireplace('_crop','_croplarge',$result['news_img']); $pieces = explode(",", $result['news_tags']); foreach($pieces as &$row){ $row = trim($row); } $result['tags'] = $pieces; return $result; } public function getNewsDataComments($idNews, $parent_id = 0, $deep = 0){ $sql = 'SELECT * FROM `'._DB_PREFIX_.'news_comments` WHERE `news_id` = '.(int)$idNews.' AND `parent_id` = '.(int)$parent_id; $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); foreach ($result as &$row){ $sql1 = 'SELECT COUNT(`news_comment_id`) AS count FROM `'._DB_PREFIX_.'news_comments` WHERE `parent_id` = '.(int)$row['news_comment_id']; $result1 = Db::getInstance()->getRow($sql1); $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['date_add'])); $row['deep'] = $deep; if($result1 && (int)$result1['count'] > 0){ $row['children'] = $this->getNewsDataComments($idNews,(int)$row['news_comment_id'],$deep + 1); } } return $result; } public function getFieldsImage($id) { $sql = 'SELECT * FROM ps_gallery_image WHERE gallery_image_id_gallery = '.$id.' LIMIT 500'; $result = Db::getInstance()->ExecuteS($sql); $i = 0; foreach ($result as &$row) { $arr[$i] = $row; $i++; } return $arr; } }instant_search = Tools::getValue('instantSearch'); $this->ajax_search = Tools::getValue('ajaxSearch'); if ($this->instant_search || $this->ajax_search) { $this->display_header = false; $this->display_footer = false; } } public function setMedia() { parent::setMedia(); /*$this->context->controller->addCss(ROOTDIR.'news/newMessage.css', 'all');*/ $this->context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/jquery.scrollTo.js', 'all'); } /** * Start forms process * @see FrontController::postProcess() */ public function postProcess() { if (Tools::isSubmit('sendComment') && Tools::isSubmit('idnews') && (int)Tools::getValue('idnews')>0) { if (!($name = Tools::getValue('user_name')) || !Validate::isCleanHtml($name)) $this->errors[] = Tools::displayError('Invalid user name'); else if (!($email = Tools::getValue('user_mail')) || !Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); else if ($web = Tools::getValue('user_web') && !Validate::isCleanHtml($web)) $this->errors[] = Tools::displayError('Invalid web address'); //$content = Tools::getValue('content'); // Html entities is not usefull, iscleanHtml check there is no bad html tags. else if (!$content = Tools::getValue('content')) $this->errors[] = Tools::displayError('Commentary cannot be blank'); else if (!Validate::isCleanHtml($content)) $this->errors[] = Tools::displayError('Invalid commentary'); else{ $parent_id = (int)Tools::getValue('parent_id',0); Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'news_comments` (`news_comment_id`, `news_id`, `parent_id`, `name`,`content`,`email`,`web`) VALUES (null,'.(int)Tools::getValue('idnews').' , '.(int)$parent_id.', \''.$name.'\', \''.$content.'\', \''.$email.'\', \''.$web.'\')'); } $link = new Link(); // Tools::redirect($link->getPageLink('blog',true).'?idnews='.(int)Tools::getValue('idnews')); Tools::redirect($link->getBlogLink((int)Tools::getValue('idnews'))); } } public function process() { parent::process(); if ($this->instant_search || $this->ajax_search){ $this->search_query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q'))); } elseif(Tools::isSubmit('submit_search') && Tools::isSubmit('search_query')){ $this->search_query = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_query'))); } //print_r(''.$query); setlocale(LC_ALL, "sk_SK.utf8"); $this->_newsId = ($_GET['idnews']) ? $_GET['idnews'] : NULL; $category = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'news_category`'); if($category){ $GLOBALS['category'] = array(); foreach($category as $row){ $GLOBALS['category'][''.$row['news_id_category']] = $row['name']; } $this->_category = $GLOBALS['category']; } else{ $this->_category = $GLOBALS['category']; } $this->_categoryId = Tools::getValue('category',0); $this->_tag = Tools::getValue('tag'); $this->_date = split('-',Tools::getValue('date',0)); if ($this->_newsId) { $category = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'news_category`'); $archive = Db::getInstance()->ExecuteS('SELECT COUNT(news_id) AS count, YEAR(news_timestamp) AS year, MONTH(news_timestamp) AS month FROM `'._DB_PREFIX_.'news` GROUP BY YEAR(news_timestamp),MONTH(news_timestamp) ORDER BY YEAR(news_timestamp) DESC, MONTH(news_timestamp) DESC'); foreach($archive as &$arch){ $arch['month1'] = strftime('%B', mktime(0, 0, 0, (int)$arch['month'], 1,(int)$arch['year'])); } $data = self::getNewsData($this->_newsId); $dataComments = self::getNewsDataComments($this->_newsId); self::$smarty->assign('newsId', $this->_newsId); self::$smarty->assign('categoryId', $this->_categoryId); self::$smarty->assign('categoryTitle', $this->_category[$this->_categoryId]); self::$smarty->assign('blogCategory', $category); self::$smarty->assign('blogArchive', $archive); self::$smarty->assign('data', $data); self::$smarty->assign('dataComments', $dataComments); self::$smarty->assign('dataCommentsCount', count($dataComments)); self::$smarty->assign('errors', $this->errors); //galéria if ($data['news_id_gallery']) { self::$smarty->assign('images', self::getFieldsImage($data['news_id_gallery'])); $sql = 'SELECT gallery_title FROM ps_gallery WHERE gallery_id = '.$data['news_id_gallery']; $result = Db::getInstance()->getRow($sql); $row = $result; self::$smarty->assign('galleryName', $row['gallery_title']); } } else { //include_once(PS_ADMIN_DIR.'/news/paginator.php'); //$pages = new Paginator; //$sql = 'SELECT * FROM ps_news WHERE news_id_category = '.$this->_categoryId.' ORDER BY news_timestamp DESC LIMIT 0,20'; //$result = Db::getInstance()->NumRows($sql); //$pages->items_total = $result; //$pages->mid_range = 7; //$pages->paginate(); //self::$smarty->assign('displayPages', $pages->display_pages()); //self::$smarty->assign('displayJumpMenu', $pages->display_jump_menu()); //self::$smarty->assign('displayItemsPerPage', $pages->display_items_per_page()); self::$smarty->assign('news_dir', PS_ADMIN_DIR.'/news/'); self::$smarty->assign('categoryTitle', $this->_category[$this->_categoryId]); self::$smarty->assign('categoryID', $this->_categoryId); self::$smarty->assign('data', self::getFields()); if ($this->ajax_search && $this->search_query != '') { $searchResults = self::getFields(); $link = new Link(); foreach($searchResults as &$row){ // $row['news_link'] = $link->getPageLink('blog',true).'?idnews='.(int)$row['news_id']; $row['news_link'] = $link->getBlogLink((int)$row['news_id']); } die(Tools::jsonEncode($searchResults)); exit; } } } public function displayContent() { parent::displayContent(); self::$smarty->display(PS_ADMIN_DIR.'/news/news.tpl'); } public function getFields() { if (!$this->instant_search && !$this->ajax_search && !$this->search_query){ $sql = 'SELECT * FROM ps_news WHERE 1=1'.($this->_categoryId != 0 ? ' AND news_id_category = '.$this->_categoryId : '').($this->_tag != '' ? ' AND news_tags LIKE \'%'.$this->_tag.'%\'' : '').(count($this->_date) == 2 ? ' AND MONTH(news_timestamp) = \''.$this->_date[0].'\' AND YEAR(news_timestamp) = \''.$this->_date[1].'\'' : '').' ORDER BY news_timestamp DESC LIMIT 0,21'; $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); $i = 0; foreach ($result as &$row) { $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['news_timestamp'])); $arr[$i] = $row; $i++; } return $arr; } elseif($this->search_query != ''){ $searchWords = explode(" ", $this->search_query); $where = array(); foreach($searchWords as $word){ $word_dia = array('á', 'ä', 'č', 'ď', 'é', 'ě', 'í', 'ľ', 'ĺ', 'ň', 'ř', 'ŕ', 'š', 'ť', 'ú', 'ů', 'ó', 'ô', 'ž', 'ý', 'Á', 'Ä', 'Č', 'Ď', 'É', 'Ě', 'Í', 'Ľ', 'Ĺ', 'Ň', 'Ř', 'Ŕ', 'Š', 'Ť', 'Ú', 'Ů', 'Ó', 'Ô', 'Ž', 'Ý'); $word_no_dia = array('a', 'a', 'c', 'd', 'e', 'e', 'i', 'l', 'l', 'n', 'r', 'r', 's', 't', 'u', 'u', 'o', 'o', 'z', 'y', 'A', 'A', 'C', 'D', 'E', 'E', 'I', 'L', 'L', 'N', 'R', 'R', 'S', 'T', 'U', 'U', 'O', 'O', 'Z', 'Y'); $word1 = str_replace($word_dia, $word_no_dia, $word); if(str_replace(' ','',$word1) != ''){ $where[] = '`news_title` LIKE \'%'.$word1.'%\''; $where[] = '`news_body` LIKE \'%'.$word1.'%\''; } } $sql = 'SELECT DISTINCT * FROM `'._DB_PREFIX_.'news` n LEFT JOIN `'._DB_PREFIX_.'news_category` nc ON (n.`news_id_category` = nc.`news_id_category`) WHERE 1=1 AND ('.implode(' OR ', $where).') ORDER BY news_timestamp DESC LIMIT 0,21'; //SELECT * FROM `ps_news` WHERE `news_title` LIKE '%test1%' OR `news_title` LIKE '%lore%' $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); $i = 0; foreach ($result as &$row) { $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['news_timestamp'])); $arr[$i] = $row; $i++; } return $arr; } } public function getNewsData($idNews) { $sql = 'SELECT * FROM ps_news WHERE news_id = '.$idNews; $result = Db::getInstance()->getRow($sql); setlocale(LC_ALL, "sk_SK.utf8"); $result['timestamp'] = strftime('%d. %B %Y', strtotime($result['news_timestamp'])); $result['news_img'] = str_ireplace('_crop','_croplarge',$result['news_img']); $pieces = explode(",", $result['news_tags']); foreach($pieces as &$row){ $row = trim($row); } $result['tags'] = $pieces; return $result; } public function getNewsDataComments($idNews, $parent_id = 0, $deep = 0){ $sql = 'SELECT * FROM `'._DB_PREFIX_.'news_comments` WHERE `news_id` = '.(int)$idNews.' AND `parent_id` = '.(int)$parent_id; $result = Db::getInstance()->ExecuteS($sql); setlocale(LC_ALL, "sk_SK.utf8"); foreach ($result as &$row){ $sql1 = 'SELECT COUNT(`news_comment_id`) AS count FROM `'._DB_PREFIX_.'news_comments` WHERE `parent_id` = '.(int)$row['news_comment_id']; $result1 = Db::getInstance()->getRow($sql1); $row['timestamp'] = strftime('%d. %B %Y', strtotime($row['date_add'])); $row['deep'] = $deep; if($result1 && (int)$result1['count'] > 0){ $row['children'] = $this->getNewsDataComments($idNews,(int)$row['news_comment_id'],$deep + 1); } } return $result; } public function getFieldsImage($id) { $sql = 'SELECT * FROM ps_gallery_image WHERE gallery_image_id_gallery = '.$id.' LIMIT 500'; $result = Db::getInstance()->ExecuteS($sql); $i = 0; foreach ($result as &$row) { $arr[$i] = $row; $i++; } return $arr; } }