Просмотр файла element_function/element_function_forum.php

Размер файла: 3.6Kb
<?php

	// Возвращает количество тем в разделе
	function Count_Topic_Subforum($subforum) {
		return mysql_result(mysql_query("SELECT COUNT(lost_id) FROM `element_forum_topic_2` WHERE `lost_subforum` = '$subforum'"), 0);
	}
	
	// Возвращает количество комментариев в топике
	function Count_Topic_Comment($topic) {
		return mysql_result(mysql_query("SELECT COUNT(lost_id) FROM `element_forum_comment_2` WHERE `lost_topic` = '$topic'"), 0);
	}
	
	function Read_Topic_User($user, $topic) {
		$result = mysql_fetch_array(mysql_query("SELECT `lost_time` FROM `element_forum_read_2` WHERE `lost_user` = '$user' AND `lost_topic` = '$topic' LIMIT 1"));
		if ($result) return $result['lost_time']; else return false;
	}
	
	function Create_Read_Topic($user, $topic, $time) {
		mysql_query("INSERT INTO `element_forum_read_2` SET `lost_user` = '$user', `lost_topic` = '$topic', `lost_time` = '$time'");
	}
	
	function Update_Read_Topic($user, $topic, $time) {
		mysql_query("UPDATE `element_forum_read_2` SET `lost_time` = '$time' WHERE `lost_user` = '$user' AND `lost_topic` = '$topic' LIMIT 1");
	}
	
	
	function Open_Close_Topic($open_close, $topic, $header) {
		if ($open_close > 0) $open_close = 0; else $open_close = 1;
		mysql_query("UPDATE `element_forum_topic_2` SET `lost_close` = '$open_close' WHERE `lost_id` = '$topic' LIMIT 1");
		return header('Location: '.$header.'');
	}
	
	function Pricrepit_Topic($pric, $topic, $header) {
		if ($pric > 0) $pric = 0; else $pric = 1;
		mysql_query("UPDATE `element_forum_topic_2` SET `lost_pric` = '$pric' WHERE `lost_id` = '$topic' LIMIT 1");
		return header('Location: '.$header.'');
	}
	
	function Delete_Topic($topic, $subforum) {
		mysql_query("DELETE FROM `element_forum_topic_2` WHERE `lost_id` = '$topic' LIMIT 1");
		mysql_query("DELETE FROM `element_forum_comment_2` WHERE `lost_topic` = '$topic' LIMIT 1");
		mysql_query("DELETE FROM `element_forum_read_2` WHERE `lost_topic` = '$topic'");
		return header('Location: /forum/subforum?id='.$subforum.'');
	}

	function Delete_Comment($comment, $topic, $user, $header, $type) {
		if (!empty($comment) AND !empty($topic) AND !empty($user)) {
			if ($type == 1) $user = $user; else $user = 0;
			mysql_query("UPDATE `element_forum_comment` SET `lost_delete` = '$user' WHERE `lost_id` = '$comment' AND `lost_topic` = '$topic' LIMIT 1");
			return header('Location: '.$header.'');
		}
	}
	
	// Функция конвертирует BB-коды на html теги
	function AddBB($var) {
		$search = array(
			'/\[b\](.*?)\[\/b\]/is',
			'/\[i\](.*?)\[\/i\]/is',
			'/\[color\=(.*?)\](.*?)\[\/color\]/is',
			'/\[u\](.*?)\[\/u\]/is',
			'/\[url\](.*?)\[\/url\]/is',
			'/\[img\=(.*?)\](.*?)/is',
			'/\[hr]/is',
			'/\[url\=(.*?)\](.*?)\[\/url\]/is');
			
		$replace = array(
			'<strong>$1</strong>',
			'<em>$1</em>',
			'<font color="$1">$2</font>',
			'<u>$1</u>',
			'<a href="$1">$1</a>',
			'<img src="$1">',
			'<div class="hr mt3 mb3"></div>',
			'<a href="$1">$2</a>');
			
		$var = preg_replace ($search, $replace, $var);
		return $var;
	}

	// Функция конвертирует html теги в вв-коды
	function BBcode($var) {
		$search = array(
			'/\<strong>(.*?)\<\/strong>/is',
			'/\<em>(.*?)\<\/em>/is',
			'/\<font color=\"(.*?)\">(.*?)\<\/font>/is',
			'/\<u>(.*?)\<\/u>$/is',
			'/\<img src=\"(.*?)\">/is',
			'/\<div class="hr"><\/div>/is',
			'/\<a href=\"(.*?)\">(.*?)\<\/a>/is');
			
		$replace = array(
			'[b]$1[/b]',
			'[i]$1[/i]',
			'[color=$1]$2[/color]',
			'[u]$1[/u]',
			'[img=$1]',
			'[hr]',
			'[url=$1]$2[/url]');
			
		$var = preg_replace ($search, $replace, $var);
		return $var; 
	}	
	
	
?>