assign(array( 'forum_error_answer_empty' => false ,'forum_error_answer_confirm' => false ,'forum_error_block' => false ,'forum_error_answer_delete' => false ,'forum_cat_close' => false ,'show_topics_empty' => false ,'forum_all_categories' => false ,'forum_submit_story_show' => false ,'forum_all_topics' => false ,'forum_create_parent_link' => false ,'forum_topic_parent_id' => false ,'forum_poll_answer' => false ,'forum_error_create_topic' => false ,'forum_show_old_parent_topic' => false ,'forum_show_old_answer' => false ,'forum_show_old_answer_quote' => false ,'forum_vote_show_result' => false ,'forum_timeout' => false )); $smarty->assign('forum_user_id', intval($cookie->id_customer)); $address = explode ("-", $_SERVER["REQUEST_URI"]); $protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http'; if(!strpos($address[0], 'forum')) { $address[0] = __PS_BASE_URI__ . 'forum'; unset($address[1]); $address = array_values($address); } $all_settings = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'invertus_forum_settings'); foreach($all_settings AS $settings) { $smarty->assign($settings['name'], $settings['parameter']); } if(intval(Configuration::get('PS_REWRITING_SETTINGS'))) { //Turn on Friendly URL $friendly_url = 1; $full_address = $protocol.'://' . $_SERVER['HTTP_HOST'].__PS_BASE_URI__.'forum-'; $smarty->assign('forum_browsing_category_base_url', 'forum-'); if(isset($address[2])) { if (categoryPermissions(isset($address[2]))) { $browsing_category = Db::getInstance()->ExecuteS('SELECT category_name FROM '._DB_PREFIX_.'invertus_forum_category WHERE id = "'.$address[2].'"'); if(!empty($browsing_category)) { $create_link = 'forum-'.change_to_friendly_name($browsing_category[0]['category_name']).'-'.$address[2]; $smarty->assign('forum_browsing_category_url', $create_link); $smarty->assign('forum_browsing_category_name', $browsing_category[0]['category_name']); } else { $smarty->assign('forum_browsing_category_url', ''); $smarty->assign('forum_browsing_category_name', ''); } } else { $smarty->assign('forum_access', 'true'); $smarty->assign('forum_browsing_category_url', ''); $smarty->assign('forum_browsing_category_name', ''); } } else { $smarty->assign('forum_browsing_category_url', ''); $smarty->assign('forum_browsing_category_name', ''); } } else { $friendly_url = 0; $full_address = $protocol.'://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)); $smarty->assign('forum_browsing_category_base_url', 'forum.php'); if(isset($_GET['cat'])) { if (categoryPermissions($_GET['cat'])) { $browsing_category = Db::getInstance()->ExecuteS('SELECT category_name FROM '._DB_PREFIX_.'invertus_forum_category WHERE id = "'.$_GET['cat'].'"'); $create_link = 'forum.php?cat='.$_GET['cat']; $smarty->assign('forum_browsing_category_url', $create_link); $smarty->assign('forum_browsing_category_name', $browsing_category[0]['category_name']); } else { $smarty->assign('forum_access', 'true'); $smarty->assign('forum_browsing_category_url', ''); $smarty->assign('forum_browsing_category_name', ''); } } else { $smarty->assign('forum_browsing_category_url', ''); $smarty->assign('forum_browsing_category_name', ''); } } //Copy to: .htaccess //RewriteRule ^forum-([a-zA-Z0-9-]*)(.*)$ /prestashop_root_folder/forum.php?topic=$1 [QSA,L,E] //--------------------------- if(isset($_POST['answer_order_by'])) { $an_order_by = $_SESSION['forum_answer_order_by']; if($an_order_by == '1') { $_SESSION['forum_answer_order_by'] = '0'; } elseif($an_order_by == '0') { $_SESSION['forum_answer_order_by'] = '1'; } else { $answer_order_by_default = Db::getInstance()->ExecuteS('SELECT parameter FROM '._DB_PREFIX_.'invertus_forum_settings WHERE name = "forum_answer_show_order_by_date"'); $_SESSION['forum_answer_order_by'] = $answer_order_by_default[0]['parameter']; } } if(isset($_SESSION['forum_answer_order_by'])) $smarty->assign('forum_answer_show_order_by_date', $_SESSION['forum_answer_order_by']); else { $answer_order_by_default = Db::getInstance()->ExecuteS('SELECT parameter FROM '._DB_PREFIX_.'invertus_forum_settings WHERE name = "forum_answer_show_order_by_date"'); if (!empty($answer_order_by_default)) { $_SESSION['forum_answer_order_by'] = $answer_order_by_default[0]['parameter']; $smarty->assign('forum_answer_show_order_by_date', $_SESSION['forum_answer_order_by']); } } if(isset($_POST['parent_post_edit'])) { $get_post = Db::getInstance()->ExecuteS('SELECT id, text, title FROM '._DB_PREFIX_.'invertus_forum_posts_parent WHERE id = "'.$_POST['topic_id'].'"'); $smarty->assign('forum_show_old_parent_topic', $get_post[0]); } if(isset($_POST['update_story'])) { $title = htmlspecialchars($_POST['title'], ENT_QUOTES); $text = htmlspecialchars($_POST['text'], ENT_QUOTES); if($friendly_url) { $address_ex = str_replace("submit_story-", "", $_SERVER["HTTP_REFERER"]) . 'topic-' . change_to_friendly_name($_POST['title']) . '-' . $_POST['old_parent_id']; } else { $address_ex = str_replace("page_name=submit_story", "", $_SERVER["HTTP_REFERER"]) . 'story_id=' . $_POST['old_parent_id']; } if(Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'invertus_forum_posts_parent SET title = "'.$title.'", text = "'.$text.'" WHERE id = "'.$_POST['old_parent_id'].'"')) { $smarty->assign('forum_error_answer_confirm', true); header('Location: '.$address_ex.''); } else $error[] = 'Error, data is not sent to the database'; } if(isset($_POST['parent_post_delete'])) { $delete_topic = Db::getInstance()->ExecuteS('DELETE FROM '._DB_PREFIX_.'invertus_forum_posts_parent WHERE id = "'.$_POST['topic_id'].'"'); //Delete poll $delete_poll = Db::getInstance()->Execute('DELETE '._DB_PREFIX_.'invertus_forum_poll_question.*, '._DB_PREFIX_.'invertus_forum_poll_answers.*, '._DB_PREFIX_.'invertus_forum_poll_response_author.* FROM '._DB_PREFIX_.'invertus_forum_poll_question LEFT JOIN '._DB_PREFIX_.'invertus_forum_poll_answers ON '._DB_PREFIX_.'invertus_forum_poll_question.id = '._DB_PREFIX_.'invertus_forum_poll_answers.question_id LEFT JOIN '._DB_PREFIX_.'invertus_forum_poll_response_author ON '._DB_PREFIX_.'invertus_forum_poll_answers.id = '._DB_PREFIX_.'invertus_forum_poll_response_author.answer_id WHERE '._DB_PREFIX_.'invertus_forum_poll_question.topic_id = "'.$_POST['topic_id'].'"'); if($delete_topic and $delete_poll) { $smarty->assign('forum_error_answer_confirm', true); header('Location: '.$full_address.''); } else { $error[] = 'Error, data is not sent to the database'; header('Location: '.$full_address.''); } } if(isset($_POST['answer_edit'])) { $get_post = Db::getInstance()->ExecuteS('SELECT id, text FROM '._DB_PREFIX_.'invertus_forum_posts WHERE id = "'.$_POST['answer_id'].'"'); $smarty->assign('forum_show_old_answer', $get_post[0]); } if(isset($_POST['answer_update'])) { $text = htmlspecialchars($_POST['text'], ENT_QUOTES); if(Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'invertus_forum_posts SET text = "'.$text.'" WHERE id = "'.$_POST['answer_id'].'"')) $smarty->assign('forum_error_answer_confirm', true); else $error[] = 'Error, data is not sent to the database'; } if(isset($_POST['answer_delete'])) { if(Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'invertus_forum_posts WHERE id = "'.$_POST['answer_id'].'"')) $smarty->assign('forum_error_answer_delete', true); else $error[] = 'Error, data is not sent to the database'; //header('Location: '.get_full_address().''); } if(isset($_POST['answer_quote'])) { $get_post = Db::getInstance()->ExecuteS('SELECT '._DB_PREFIX_.'invertus_forum_posts.text, '._DB_PREFIX_.'customer.firstname, '._DB_PREFIX_.'customer.lastname FROM '._DB_PREFIX_.'invertus_forum_posts LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'invertus_forum_posts.author_id WHERE '._DB_PREFIX_.'invertus_forum_posts.id = "'.$_POST['answer_id'].'" '); $answer_quote_text = '[quote]'.$get_post[0]['firstname'] . ' '.$get_post[0]['lastname']. ' \n ' .$get_post[0]['text'].'[/quote]'; $smarty->assign('forum_show_old_answer_quote', $answer_quote_text); } if(isset($_POST['answer'])) { if(!empty($_POST['text'])) { $text = htmlspecialchars($_POST['text'], ENT_QUOTES); if(Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'invertus_forum_posts (parent_posts, text, author_id, date) VALUES ("'.$_POST['forum_topic_parent_id'].'", "'.$text.'", "'.intval($cookie->id_customer).'", "'.date('Y-m-d H:i:s').'")')) $smarty->assign('forum_error_answer_confirm', true); else $error[] = 'Error, data is not sent to the database'; } else $smarty->assign('forum_error_answer_empty', true); } if(isset($_POST['submit_story'])) { $poll = false; $topic_error = false; if(!empty($_POST['poll_name']) and !empty($_POST['all_responses'])) $poll = true; elseif(!empty($_POST['poll_name']) and empty($_POST['all_responses'])) $poll = true; elseif(empty($_POST['poll_name']) and empty($_POST['all_responses'])) $poll = true; else { $poll = false; } if(!empty($_POST['title']) and !empty($_POST['text']) and $poll) { if(!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'invertus_forum_posts_parent (category_id, title, author_id, status, date, text) VALUES ("'.$_POST['cat_id'].'", "'.htmlspecialchars($_POST['title'], ENT_QUOTES).'", "'.intval($cookie->id_customer).'", "1", "'.date('Y-m-d H:i:s').'", "'.htmlspecialchars($_POST['text'], ENT_QUOTES).'")')) { $error[] = 'Error, data is not sent to the database'; $topic_error = true; } } else $error[] = 'Error, you must enter topic name and message'; $get_new_post_id = mysql_insert_id(); if($friendly_url) { $address_ex = str_replace("submit_story-", "", $_SERVER["HTTP_REFERER"]) . 'topic-' . change_to_friendly_name($_POST['title']) . '-' .mysql_insert_id(); } else { $address_ex = str_replace("page_name=submit_story", "", $_SERVER["HTTP_REFERER"]) . 'story_id=' .mysql_insert_id(); } if(!empty($_POST['poll_name']) and !empty($_POST['all_responses']) and !$topic_error) { $forum_max_answer_pool = Db::getInstance()->ExecuteS('SELECT parameter FROM '._DB_PREFIX_.'invertus_forum_settings WHERE name = "forum_max_answer"'); if(!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'invertus_forum_poll_question (question, time_end, topic_id, type) VALUES ("'.htmlspecialchars($_POST['poll_name'], ENT_QUOTES).'", "'.$_POST['valid_until'].'", "'.$get_new_post_id.'", "'.$_POST['type_poll'].'" )')) $error[] = 'Error, data is not sent to the database'; $poll_parent = mysql_insert_id(); $all_responses_array = explode("\r\n", $_POST['all_responses']); $i = 1; foreach($all_responses_array AS $response) { $i++; if($forum_max_answer_pool[0]['parameter'] < $i) break; if(!empty($response)) { if(!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'invertus_forum_poll_answers (answer, question_id) VALUES ("'.htmlspecialchars($response, ENT_QUOTES).'", "'.$poll_parent.'")')) $error[] = 'Error, data is not sent to the database'; } } } if(empty($error)) { $smarty->assign('forum_create_topic_true', true); header('Location: '.$address_ex.''); } else $smarty->assign('forum_error_create_topic', $error); } if(isset($_POST['vote_submit'])) { $total_vote = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_poll_response_author.id FROM '._DB_PREFIX_.'invertus_forum_poll_response_author WHERE '._DB_PREFIX_.'invertus_forum_poll_response_author.author_id = "'.intval($cookie->id_customer).'" and '._DB_PREFIX_.'invertus_forum_poll_response_author.topic_id = "'.$_POST['topic_id'].'" '); $user_votes = false; if(count($total_vote) > 0) $user_votes = true; if(!empty($_POST['user_unswer']) and !$user_votes) { $user_unswer = $_POST['user_unswer']; if(!is_array($user_unswer)) { $user_unswer_array[0] = $user_unswer; } else $user_unswer_array = $user_unswer; foreach($user_unswer_array AS $answer) { if(!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'invertus_forum_poll_response_author (answer_id, topic_id, author_id) VALUES ("'.$answer.'", "'.$_POST['topic_id'].'", "'.intval($cookie->id_customer).'")')) $error[] = 'Error, data is not sent to the database'; if(!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'invertus_forum_poll_answers SET count_answer = count_answer + 1 WHERE id = "'.$answer.'"')) $error[] = 'Error, data is not sent to the database'; } } elseif(!$user_votes) { $error[] = 'Error, You must select at least one option'; } if(isset($error)) $smarty->assign('forum_error_create_topic', $error); } if(isset($_POST['vote_show_result'])) $smarty->assign('forum_vote_show_result', true); if(isset($_POST['vote_submit_wish_voute'])) $smarty->assign('forum_vote_show_result', false); $user_info = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_block_users.unlock_date, '._DB_PREFIX_.'invertus_forum_block_users.text, '._DB_PREFIX_.'customer.firstname, '._DB_PREFIX_.'customer.lastname, '._DB_PREFIX_.'customer.email FROM '._DB_PREFIX_.'invertus_forum_block_users LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'invertus_forum_block_users.user_id WHERE '._DB_PREFIX_.'invertus_forum_block_users.user_id = "'.intval($cookie->id_customer).'" ORDER BY '._DB_PREFIX_.'invertus_forum_block_users.unlock_date DESC LIMIT 1'); if(isset($user_info[0]['unlock_date']) and $user_info[0]['unlock_date'] > date('Y-m-d H:i:s')) { block_user($user_info[0]['text'], $user_info[0]['unlock_date']); } /* checks is user is granted rights to access this category */ function categoryPermissions($cat) { global $cookie; $sql = "SELECT group_id FROM "._DB_PREFIX_."invertus_forum_groups WHERE `forum_id`='$cat'"; $groups = Db::getInstance()->getRow($sql); if (!empty($groups)) // if any groups are assigned to certain category, then it will be accessible to only those groups { if (isset($cookie->logged)) // user has to be logged in { if (Db::getInstance()->getValue("SELECT `group_id` FROM "._DB_PREFIX_."invertus_forum_groups WHERE `forum_id`='$cat'")=='0') return true; //accessible to all groups foreach ($groups as $group) { $sql = "SELECT A.id_group FROM "._DB_PREFIX_."customer_group AS A LEFT JOIN "._DB_PREFIX_."invertus_forum_groups AS B ON A.id_group=B.group_id WHERE B.forum_id='$cat' AND A.id_customer='".$cookie->id_customer."'"; Db::getInstance()->ExecuteS($sql); if(Db::getInstance()->NumRows() > 0) return true; // user belongs to assigned group } return false; // user does not belong to any assigned groups } else return false; // user is not logged in } $sql = "SELECT registered, visitors FROM "._DB_PREFIX_."invertus_forum_category WHERE `id`='$cat'"; $permissions = Db::getInstance()->getRow($sql); if ($permissions['registered'] == '1' && $permissions['visitors'] == '1') return true; // category is accessible to everybody if ($permissions['registered'] == '1' && !isset($cookie->logged)) return false; // only registered users may browse this category if ($permissions['visitors'] == '1' && isset($cookie->logged)) return false; // only visitors are aloud to browse this category return true; // user is aloud to browse this category } function get_full_address() { $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; } function bbcode($input) { $input = strip_tags($input); preg_match_all("/\[img\](.*?)\[\/img\]/", $input, $all_img); $file_types = array('image/gif', 'image/jpeg', 'image/png', 'image/jpg', 'image/bmp'); if(!empty($all_img[0])) { for($i = 0; $i < count($all_img); $i++) { $size = @getimagesize($all_img[1][$i]); if(isset($all_img[1][$i]) and isset($size['mime']) and in_array($size['mime'], $file_types)) $input = str_replace($all_img[0][$i], convert_size($all_img[1][$i]), $input); } } $input = str_replace("watch?v=", "v/", $input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[quote\](.*?)\[\/quote\]/is', '/\[url=(.*?)\](.*?)\[\/url\]/is', '/\[youtube\](.*?)\[\/youtube\]/is' ); $replace = array( '$1', '$1', '$1', '
$1
', '$2', '' ); return preg_replace($search, $replace, $input); } function convert_size($url) { $size = getimagesize($url); $new_width = $size[0]; $new_height = $size[1]; if(isset($new_width) and $new_width > 400) { $new_width_old = $new_width; $new_width = 400; $percent_w = $new_width_old / 400; $new_height = $new_height / $percent_w; } if(isset($new_height) and $new_height > 400) { $new_height_old = $new_height; $new_height = 400; $percent_h = $new_height_old / 400; $new_width = $new_width / $percent_h ; } $show_img = ''; return $show_img; } function change_to_friendly_name($title) { $title = iconv('UTF-8', 'LATIN1//TRANSLIT', $title); $title = strtolower(trim($title)); $title = preg_replace('/[^a-z0-9-]/', '_', $title); $title = preg_replace('/-+/', "_", $title); return $title; } function pagination($place, $address, $full_address, $friendly_url) { $protocol = isset($_SERVER['HTTPS']) ? 'https' : 'http'; if($place == 'first_page') { $column_name = 'forum_first_page'; if($friendly_url) { if(isset($address[4])) $page = $address[4]; else $page = ''; if(isset($address[4])) $curent_page = $address[4]; else $curent_page = ''; $page_name = $address[1] . '-' . $address[2] . '-' . 'page-'; $cat_id = $address[2]; } else { $cat_id = Tools::getValue('cat'); $page = Tools::getValue('page'); $curent_page = Tools::getValue('page'); $page_name = '?cat=' . $cat_id . '&page='; } $in_category = Db::getInstance()->ExecuteS('SELECT COUNT(id) AS in_cat FROM '._DB_PREFIX_.'invertus_forum_posts_parent WHERE category_id = "'.$cat_id.'" AND status = "1"'); } elseif($place == 'answers') { $column_name = 'forum_submit_story'; if($friendly_url) { if(isset($address[7])) { $page = $address[7]; $curent_page = $address[7]; } else { $page = ''; $curent_page = ''; } $page_name = $address[1].'-'.$address[2].'-'.$address[3].'-'.$address[4].'-'.$address[5].'-page-'; $parent_post = $address[5]; } else { $page = Tools::getValue('page'); $curent_page = Tools::getValue('page'); $cat_id = Tools::getValue('cat'); $parent_post = Tools::getValue('story_id'); $full_address = $protocol.'://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)) . '?cat='.$cat_id.'&story_id='.$parent_post.''; $page_name = '&page='; } $in_category = Db::getInstance()->ExecuteS('SELECT COUNT(id) AS in_cat FROM '._DB_PREFIX_.'invertus_forum_posts WHERE '._DB_PREFIX_.'invertus_forum_posts.parent_posts = "'.$parent_post.'"'); } $in_cat = $in_category[0]['in_cat']; $max_in_page2 = Db::getInstance()->ExecuteS('SELECT parameter FROM '._DB_PREFIX_.'invertus_forum_settings WHERE name = "'.$column_name.'"'); $max_in_page = $max_in_page2[0]['parameter']; $pagination = ''; if(empty($page)) { $page = 1; $curent_page = 1; } $start = ($max_in_page * $page) - $max_in_page; if ($in_cat <= $max_in_page) $num_of_pages = 1; elseif(($in_cat % $max_in_page) == 0) $num_of_pages = $in_cat / $max_in_page; else $num_of_pages = $in_cat / $max_in_page + 1; if($curent_page > 1) { $back = $curent_page - 1; $pagination .= '<<' . ' '; } $next = $curent_page + 1; $pagination .= '|'; $num_of_pages_f = intval($num_of_pages); if($curent_page - 4 > 1) $pagination .= '1|'; if($curent_page - 5 > 1) $pagination .= '...'; $firs_element = $curent_page - 4; if($firs_element < 1) $firs_element = 1; for($i = $firs_element; $i < $curent_page; $i++) { $pagination .= ''.$i.'|'; } $pagination .= $curent_page . '|'; for($i = $curent_page + 1; $i < $curent_page + 5; $i++) { if($i > $num_of_pages_f) break; $pagination .= ''.$i.'|'; } if($curent_page + 5 < $num_of_pages_f) $pagination .= '...|'; if($curent_page + 4 < $num_of_pages_f) $pagination .= ''.$num_of_pages_f.'|'; if($curent_page + 1 < $num_of_pages) { $next = $curent_page + 1; $pagination .= ' ' . '>>'; } return array ($start, $max_in_page, $pagination); } if($friendly_url) { if(isset($address[1])) $first_page = $address[1]; if(isset($address[3])) $topic = $address[3]; if(isset($address[3])) $submit_story = $address[3]; if(isset($address[2])) $cat_id = $address[2]; if(isset($address[5])) $story_id = $address[5]; } else { $submit_story = Tools::getValue('page_name'); $cat_id = Tools::getValue('cat'); $first_page = Tools::getValue('cat'); $story_id = Tools::getValue('story_id'); } if(!isset($topic)) $topic = ''; if(!isset($submit_story)) $submit_story = ''; if(!isset($submit_story)) $submit_story = ''; if(empty($first_page)) $open_page = 'all_categories'; elseif(!empty($first_page) and $topic != 'topic' and $submit_story != 'submit_story' and empty($story_id)) $open_page = 'show_topics'; elseif($topic == 'topic' or !empty($story_id)) $open_page = 'show_answer'; elseif($submit_story == 'submit_story') $open_page = 'submit_story'; switch ($open_page) { case 'all_categories': all_categories($friendly_url, $full_address); break; case 'show_topics': show_topics($friendly_url, $address, $full_address, $cat_id); break; case 'show_answer': show_answer($friendly_url, $address, $full_address, $story_id, $cat_id); show_poll($story_id); break; case 'submit_story': submit_story($cat_id); } function all_categories($friendly_url, $full_address) { global $smarty; $all_categories = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'invertus_forum_category WHERE status = "1" ORDER BY position ASC'); if($friendly_url) { for($i = 0; $i < count($all_categories); $i++) { $all_categories[$i]['f_url'] = $full_address . change_to_friendly_name($all_categories[$i]['category_name']) . '-' . $all_categories[$i]['id']; $all_categories[$i]['access'] = (categoryPermissions($all_categories[$i]['id'])) ? 1 : 0; // checks if user is aloud to access this category } } else { for($i = 0; $i < count($all_categories); $i++) { $all_categories[$i]['f_url'] = $full_address . '?cat=' . $all_categories[$i]['id']; $all_categories[$i]['access'] = (categoryPermissions($all_categories[$i]['id'])) ? 1 : 0; // checks if user is aloud to access this category } } $smarty->assign('forum_all_categories', $all_categories); } function show_topics($friendly_url, $address, $full_address, $cat_id) { global $smarty; if($friendly_url) $forum_create_parent_link = $full_address . $address[1] . '-' . $address[2] . '-' . 'submit_story-'; else $forum_create_parent_link = $full_address . '?cat='.$cat_id.'&page_name=submit_story'; $smarty->assign('forum_create_parent_link', $forum_create_parent_link); $pagination_nr = pagination($place = 'first_page', $address, $full_address, $friendly_url); $smarty->assign('forum_topics_pagination', $pagination_nr[2]); $all_topics_parent = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_posts_parent.id, '._DB_PREFIX_.'invertus_forum_posts_parent.title, '._DB_PREFIX_.'invertus_forum_posts_parent.date, '._DB_PREFIX_.'invertus_forum_posts_parent.text, '._DB_PREFIX_.'customer.firstname, '._DB_PREFIX_.'customer.lastname, '._DB_PREFIX_.'customer.email, '._DB_PREFIX_.'invertus_forum_category.status AS cat_status FROM '._DB_PREFIX_.'invertus_forum_posts_parent LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'invertus_forum_posts_parent.author_id LEFT JOIN '._DB_PREFIX_.'invertus_forum_category ON '._DB_PREFIX_.'invertus_forum_category.id = '._DB_PREFIX_.'invertus_forum_posts_parent.category_id WHERE '._DB_PREFIX_.'invertus_forum_posts_parent.status = "1" AND '._DB_PREFIX_.'invertus_forum_posts_parent.category_id = "'.$cat_id.'" AND '._DB_PREFIX_.'invertus_forum_category.status = "1" ORDER BY '._DB_PREFIX_.'invertus_forum_posts_parent.date DESC LIMIT '.$pagination_nr[0].', '.$pagination_nr[1].' '); $all_topics_parent_cat_status = Db::getInstance()->getRow(' SELECT '._DB_PREFIX_.'invertus_forum_category.status FROM '._DB_PREFIX_.'invertus_forum_category WHERE '._DB_PREFIX_.'invertus_forum_category.id = "'.$cat_id.'" '); if(count($all_topics_parent) < 1 and $all_topics_parent_cat_status['status']) $smarty->assign('show_topics_empty', true); for($i = 0; $i < count($all_topics_parent); $i++) { $all_topics_parent[$i]['date'] = date("Y-m-d H:i", strtotime($all_topics_parent[$i]['date'])); $all_topics_parent[$i]['text'] = nl2br(substr($all_topics_parent[$i]['text'], 0, 155)) . '...'; if($friendly_url) { $title = change_to_friendly_name($all_topics_parent[$i]['title']); $all_topics_parent[$i]['read_more'] = $full_address . $address[1] . '-' . $address[2] . '-' . 'topic-'.$title.'-'. $all_topics_parent[$i]['id'] . '-'; } else { $all_topics_parent[$i]['read_more'] = $full_address . '?cat=' . $cat_id . '&story_id=' . $all_topics_parent[$i]['id']; } } $smarty->assign('forum_all_topics', $all_topics_parent); if(empty($all_topics_parent_cat_status['status'])) $smarty->assign('forum_cat_close', true); } function show_answer($friendly_url, $address, $full_address, $story_id, $cat_id) { global $smarty; $topic = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_posts_parent.id, '._DB_PREFIX_.'invertus_forum_posts_parent.title, '._DB_PREFIX_.'invertus_forum_posts_parent.author_id, '._DB_PREFIX_.'invertus_forum_posts_parent.date, '._DB_PREFIX_.'invertus_forum_posts_parent.text, '._DB_PREFIX_.'customer.firstname, '._DB_PREFIX_.'customer.lastname, '._DB_PREFIX_.'customer.email FROM '._DB_PREFIX_.'invertus_forum_posts_parent LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'invertus_forum_posts_parent.author_id WHERE '._DB_PREFIX_.'invertus_forum_posts_parent.id = "'.$story_id.'" AND '._DB_PREFIX_.'invertus_forum_posts_parent.status = "1" '); if($friendly_url) $forum_create_parent_link = $full_address . $address[1] . '-' . $address[2] . '-' . 'submit_story-'; else $forum_create_parent_link = $full_address . '?cat='.$cat_id.'&page_name=submit_story'; if(isset($forum_create_parent_link)) $smarty->assign('forum_create_parent_link', $forum_create_parent_link); if(!empty($topic[0]['id'])) { $topic[0]['text'] = nl2br(bbcode($topic[0]['text'])); $topic[0]['text_w_bb'] = nl2br($topic[0]['text']); $smarty->assign('forum_topic_parent_id', $topic[0]['id']); } $smarty->assign('forum_topic_parent', $topic); $pagination_nr = pagination($place = 'answers', $address, $full_address, $friendly_url); $smarty->assign('forum_answers_pagination', $pagination_nr[2]); // if(!isset($_SESSION['forum_answer_order_by'])) $_SESSION['forum_answer_order_by'] = Db::getInstance()->getValue('SELECT parameter FROM '._DB_PREFIX_.'invertus_forum_settings WHERE name = "forum_answer_show_order_by_date"'); if($_SESSION['forum_answer_order_by'] == 1) $answer_order_by = ' DESC'; else $answer_order_by = ' ASC'; $all_answers = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_posts.id, '._DB_PREFIX_.'invertus_forum_posts.date, '._DB_PREFIX_.'invertus_forum_posts.text, '._DB_PREFIX_.'invertus_forum_posts.author_id, '._DB_PREFIX_.'customer.firstname, '._DB_PREFIX_.'customer.lastname, '._DB_PREFIX_.'customer.email FROM '._DB_PREFIX_.'invertus_forum_posts LEFT JOIN '._DB_PREFIX_.'customer ON '._DB_PREFIX_.'customer.id_customer = '._DB_PREFIX_.'invertus_forum_posts.author_id WHERE '._DB_PREFIX_.'invertus_forum_posts.parent_posts = "'.$story_id.'" ORDER BY '._DB_PREFIX_.'invertus_forum_posts.date '.$answer_order_by.' LIMIT '.$pagination_nr[0].', '.$pagination_nr[1].' '); for($i = 0; $i < count($all_answers); $i++) { $all_answers[$i]['text'] = nl2br(bbcode($all_answers[$i]['text'])); } $smarty->assign('forum_all_answers', $all_answers); } function show_poll($story_id) { global $smarty; global $cookie; $check_user_vote = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_poll_response_author.topic_id FROM '._DB_PREFIX_.'invertus_forum_poll_response_author WHERE '._DB_PREFIX_.'invertus_forum_poll_response_author.topic_id = "'.$story_id.'" AND '._DB_PREFIX_.'invertus_forum_poll_response_author.author_id = "'.intval($cookie->id_customer).'" LIMIT 1 '); $show_poll = Db::getInstance()->ExecuteS(' SELECT '._DB_PREFIX_.'invertus_forum_poll_question.id, '._DB_PREFIX_.'invertus_forum_poll_question.question, '._DB_PREFIX_.'invertus_forum_poll_question.type, '._DB_PREFIX_.'invertus_forum_poll_question.time_end, '._DB_PREFIX_.'invertus_forum_poll_answers.id AS answer_id, '._DB_PREFIX_.'invertus_forum_poll_answers.answer, '._DB_PREFIX_.'invertus_forum_poll_answers.count_answer, '._DB_PREFIX_.'invertus_forum_poll_answers.count_answer, '._DB_PREFIX_.'invertus_forum_poll_answers.question_id FROM '._DB_PREFIX_.'invertus_forum_poll_question LEFT JOIN '._DB_PREFIX_.'invertus_forum_poll_answers ON '._DB_PREFIX_.'invertus_forum_poll_answers.question_id = '._DB_PREFIX_.'invertus_forum_poll_question.id WHERE '._DB_PREFIX_.'invertus_forum_poll_question.topic_id = "'.$story_id.'" '); if(!empty($show_poll[0]['question_id'])) { $total_vote = Db::getInstance()->ExecuteS(' SELECT SUM('._DB_PREFIX_.'invertus_forum_poll_answers.count_answer) AS total_vote FROM '._DB_PREFIX_.'invertus_forum_poll_answers WHERE '._DB_PREFIX_.'invertus_forum_poll_answers.question_id = "'.$show_poll[0]['question_id'].'" GROUP BY '._DB_PREFIX_.'invertus_forum_poll_answers.question_id '); if($show_poll[0]['time_end'] < date('Y-m-d H:i:s')) $smarty->assign('forum_timeout', true); $forum_total_vote = $total_vote[0]['total_vote']; for($i = 0; $i < count($show_poll); $i++) { if($forum_total_vote > 0) { $percent = ( $show_poll[$i]['count_answer'] * 100 / $forum_total_vote ) * 2; if($percent < 1) $show_poll[$i]['response_content'] = 1; else $show_poll[$i]['response_content'] = $percent; } else $show_poll[$i]['response_content'] = 1; } $user_id = intval($cookie->id_customer); if($user_id < 1 or empty($user_id)) $check_user_vote[0]['topic_id'] = 1; $smarty->assign('forum_poll_answer', $show_poll); if(isset($check_user_vote[0]['topic_id'])) $smarty->assign('forum_check_user_vote', $check_user_vote[0]['topic_id']); else $smarty->assign('forum_check_user_vote', false); $smarty->assign('forum_total_vote', $forum_total_vote); } } function submit_story($cat_id) { global $smarty; $all_topics_parent_cat_status = Db::getInstance()->getRow(' SELECT '._DB_PREFIX_.'invertus_forum_category.status FROM '._DB_PREFIX_.'invertus_forum_category WHERE '._DB_PREFIX_.'invertus_forum_category.id = "'.$cat_id.'" '); if(!empty($all_topics_parent_cat_status['status'])) $smarty->assign('forum_submit_story_show', $cat_id); } function block_user($message, $unlock_date) { global $smarty; $smarty->assign('forum_error_block', true); $smarty->assign('forum_error_block_message', $message); $smarty->assign('forum_error_block_date', $unlock_date); } $smarty->assign('forum_images_url', $full_address = $protocol.'://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__. 'modules/forum/upload/'); $smarty->display(_PS_THEME_DIR_.'forum.tpl'); include(dirname(__FILE__).'/footer.php'); ?>