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', '