Ajax čats bez garumzīmēm...

Moderatori: janis.wd, Vecākie lietotāji

User avatar
elwins
Reģistrēts lietotājs
Atbildes: 69
Pievienojies: 17 Jūn 2008, 15:03
Reputācija: 0
Atrodas: Latvija

Ajax čats bez garumzīmēm...

Post no elwins » 28 Okt 2009, 18:12

Savā lapā esmu uzstādījis 'Ajax ShoutBox' Version 0.1.5 čatu. (Mods)

Datubāzē, valodas un ajax failā itkā kļūdas nemanu, bet, kad lietotājs ieraksta čatā kaut ko ar garumzīmēm, tad uzmetās ķeburi, kā šajā attēlā:


Image

User avatar
drono
Lietpratējs
Atbildes: 706
Pievienojies: 14 Mar 2007, 15:59
Reputācija: 0
Atrodas: Liepāja

Post no drono » 28 Okt 2009, 18:15

Saliec visur UTF-8 encodingu, gan datu bāzei, gan HTMLam.

Iespējams, ka PHP kodā, kur pieslēdzas datu bāzei, vaig arī pievienot šādas 2 rindiņas:

mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");

usver
Reģistrēts lietotājs
Atbildes: 311
Pievienojies: 04 Okt 2009, 14:53
Reputācija: 0

Post no usver » 28 Okt 2009, 22:49

jāizmanto ir urldecode(), lai dabūtu no %uXXXX unikoda vērtības lasāmo vērtību. kur tieši? atrodi pats vai arī iedod pieeju strādājošai sistēmai, tad pateikšu.

uz aci varētu būt pie 1370. rindiņas.

User avatar
elwins
Reģistrēts lietotājs
Atbildes: 69
Pievienojies: 17 Jūn 2008, 15:03
Reputācija: 0
Atrodas: Latvija

Post no elwins » 28 Okt 2009, 23:04

no 1172. rindiņas līdz beigām kods ajax failam man ir šāds:

Code: Select all

			//Lets delete this post :D
			$sql = "DELETE FROM " . SHOUTBOX_TABLE . " WHERE shout_id = " . $id;
			if(!$db->sql_query($sql))
			{
				sql_error($sql, __LINE__, __FILE__);
			}
			else
			{
				print "<msg></msg></xml>";
				die;
			&#125;
		&#125;
		
	break;
	case "add"&#58;
		if&#40;$userdata&#91;'user_id'&#93; == ANONYMOUS &#41;
		&#123;
		
		&#125;
		else
		&#123;
			//Remove all messages older as 2 weeks,
			//Config option be a good thing for this?
			$time = time&#40;&#41; - &#40;3600 * 24 * 14&#41;;//3600 seconds in 1 hour, 24 hours in a day, 14 days in 2 weeks.
			
			$sql = "DELETE FROM  " . SHOUTBOX_TABLE . " WHERE shout_time < $time";
			if&#40;!$db->sql_query&#40;$sql&#41;&#41;
			&#123;
				sql_error&#40;$SQL, __LINE__, __FILE__&#41;;
			&#125;
			
			$current_time = time&#40;&#41;;
			if&#40;$userdata&#91;'user_level'&#93; != ADMIN&#41;
			&#123;
				//
				// Flood control
				//
				$sql = "SELECT MAX&#40;shout_time&#41; AS last_post_time
					FROM " . SHOUTBOX_TABLE . "
					WHERE shout_user_id = " . $userdata&#91;'user_id'&#93;;
				if &#40; $result = $db->sql_query&#40;$sql&#41; &#41;
				&#123;
					if &#40; $row = $db->sql_fetchrow&#40;$result&#41; &#41;
					&#123;
						if &#40; $row&#91;'last_post_time'&#93; > 0 && &#40; $current_time - $row&#91;'last_post_time'&#93; &#41; </error>sql_query&#40;$sql&#41;&#41; 
				&#123;
					sql_error&#40;$sql, __LINE__, __FILE__&#41;;
				&#125;
				print "<msg>" . $lang&#91;'posted'&#93; . "</msg></xml>";
				die;
			&#125;	
		&#125;
		
	break;
	case "check"&#58;
		$last = intval&#40;$HTTP_GET_VARS&#91;'last'&#93;&#41;;
		$sql = "SELECT shout_time AS s FROM " . SHOUTBOX_TABLE . "
		ORDER BY shout_time DESC LIMIT 1";		
		$result = $db->sql_query&#40;$sql&#41;;
		if&#40;!$result&#41;
		&#123;
			sql_error&#40;$sql, __LINE__, __FILE__&#41;;
		&#125;
		else
		&#123;
			$row = $db->sql_fetchrow&#40;$result&#41;;
			$s = $row&#91;'s'&#93;;
		 	print "<last>$s</last><tijd>" . &#40;int&#41;&#40;$s != $last&#41; . "</tijd></xml>";
		 	die;
		&#125;	
					
	break;
	case 'nr'&#58;
		$sql = "SELECT COUNT&#40;shout_id&#41; as nr FROM " . SHOUTBOX_TABLE;
		$result = $db->sql_query&#40;$sql&#41;;
		if&#40;!$result&#41;
		&#123;
			sql_error&#40;$sql, __LINE__, __FILE__&#41;;
		&#125;
		$row = $db->sql_fetchrow&#40;$result&#41;;
		$row = &#40;int&#41;$row&#91;'nr'&#93;;
		print "<nr>$row</nr></xml>";
		die;
		
	break;
	case 'view'&#58;
		$start = intval&#40;$HTTP_GET_VARS&#91;'start'&#93;&#41;;
		$start = &#40;$start <0>sql_query&#40;$sql&#41;;
		
		if&#40;!$result&#41;
		&#123;
			sql_error&#40;$sql, __LINE__, __FILE__&#41;;
		&#125;
		else
		&#123;
		 	if&#40;!$db->sql_numrows&#40;$result&#41;&#41;
			&#123;
		 		print "<error>" . $lang&#91;'no_message'&#93; . "</error></xml>";
		 		die;
		 	&#125;
			else
			&#123;
		 		$i = 0;
				$orig_word = array&#40;&#41;;
				$replacement_word = array&#40;&#41;;
				obtain_word_list&#40;$orig_word, $replacement_word&#41;;
							 		
		 	 	while&#40;$row = $db->sql_fetchrow&#40;$result&#41;&#41;
				&#123;
		 	 	 	print "<posts>\n";

		 	 	 	$door = xml&#40;$row&#91;'username'&#93;&#41;;
					$i++;
					$row_color = &#40; !&#40;$i % 2&#41; &#41; ? $theme&#91;'td_color1'&#93; &#58; $theme&#91;'td_color2'&#93;;
					$row_class = &#40; !&#40;$i % 2&#41; &#41; ? $theme&#91;'td_class1'&#93; &#58; $theme&#91;'td_class2'&#93;;
					print "\t<row_color>$row_color</row_color>\n\t<row_class>$row_class</row_class>\n\t";

			 	 	$row&#91;'shout_time'&#93; = create_date&#40;$board_config&#91;'default_dateformat'&#93;, $row&#91;'shout_time'&#93;, $board_config&#91;'board_timezone'&#93;&#41;;
					
					if &#40; $board_config&#91;'allow_smilies'&#93; &#41;
					&#123;
						$row&#91;'shout_text'&#93; = smilies_pass&#40;$row&#91;'shout_text'&#93;&#41;;
					&#125;
					
					if &#40; $board_config&#91;'allow_bbcode'&#93; &#41;
					&#123;
						$row&#91;'shout_text'&#93; = bbencode_second_pass&#40;$row&#91;'shout_text'&#93;,$row&#91;'shout_bbcode_uid'&#93;&#41;;
					&#125;		
							
					$row&#91;'shout_text'&#93; = make_clickable&#40;$row&#91;'shout_text'&#93;&#41;;
					
					$row&#91;'shout_text'&#93; = preg_replace&#40;$orig_word, $replacement_word, $row&#91;'shout_text'&#93;&#41;;
					$row&#91;'shout_text'&#93; = str_replace&#40;"\n", "<br>", $row&#91;'shout_text'&#93;&#41;;			 	 	 	
					$x = &#40;strlen&#40;'<br>'&#41; - 1&#41;;
					
					if&#40;substr&#40;$row&#91;'shout_text'&#93;, 0, $x&#41; == '<br>'&#41;
					&#123;
						$row&#91;'shout_text'&#93; = substr&#40;$row&#91;'shout_text'&#93;, $x&#41;;
					&#125;
					
					if&#40;$userdata&#91;'user_level'&#93; == ADMIN || $userdata&#91;'user_level'&#93; == MOD&#41;
					&#123;
						$row&#91;'shout_ip'&#93; = decode_ip&#40;$row&#91;'shout_ip'&#93;&#41;;
					&#125;
					
					//Next items aren't needed in XML.
					unset&#40;$row&#91;'shout_bbcode_uid'&#93;, $row&#91;'user_allowsmile'&#93;&#41;;
		 	 	 	foreach&#40;$row as $el => $wa&#41;
					&#123;
						if&#40;is_numeric&#40;$el&#41;&#41;
						&#123;
							continue;
						&#125;
		 	 	 	 	print "\t<el>$wa</el>\n";
		 	 	 	&#125;	
		 	 	 			 	 	 	
		 	 	 	print "</posts>\n";
		 	 	&#125;
		 	 	
		 	 	print "</xml>";
		 	 	die;
		 	&#125;
		&#125;
		
	break;
&#125;

if&#40;in_array&#40;$mode,$ajax_m&#41;&#41;
&#123;
	print "<error></error>";

 	print '</xml>';
&#125;

/**
 * Returns cdata'd string
 *
 * @param string $txt 
 * @return string
 */
function xml&#40;$txt&#41;
&#123;
	return  "<CDATA>";
&#125;

/**
 * Prints a XML error, if in XML modus. Else use default message_die.
 *
 * @param string $sql Sql query
 * @param int $line Linenumber
 * @param string $file Filename
 */
function sql_error&#40;$sql, $line = __LINE__, $file = __FILE__&#41;
&#123;
	global $db, $mode, $ajax_m;	
	if&#40;in_array&#40;$mode,$ajax_m&#41;&#41;
	&#123;
		$sql = xml&#40;$sql&#41;;
		$err = $db->sql_error&#40;&#41;;
		$err = xml&#40;$err&#91;'message'&#93;&#41;;
		print "<error>$err</error>\n<sql>$sql</sql>";
	 	print '</xml>';
	 	die;
	&#125;	
	else
	&#123;
		message_die&#40;GENERAL_ERROR, "Could not run AJAX ShoutBox Query.", "", $line, $file, $sql&#41;;
	&#125;
&#125;
?>

usver
Reģistrēts lietotājs
Atbildes: 311
Pievienojies: 04 Okt 2009, 14:53
Reputācija: 0

Post no usver » 29 Okt 2009, 11:47

Code: Select all

               $row&#91;'shout_text'&#93; = preg_replace&#40;$orig_word, $replacement_word, $row&#91;'shout_text'&#93;&#41;;
               $row&#91;'shout_text'&#93; = str_replace&#40;"\n", "<br>", $row&#91;'shout_text'&#93;&#41;;                     
starp vai aiz šīm rindiņām pamēģini ielikt

Code: Select all

$row&#91;'shout_text'&#93; = urldecode&#40;$row&#91;'shout_text'&#93;&#41;;

User avatar
elwins
Reģistrēts lietotājs
Atbildes: 69
Pievienojies: 17 Jūn 2008, 15:03
Reputācija: 0
Atrodas: Latvija

Post no elwins » 29 Okt 2009, 12:18


Pievienot atbildi

Return to “PHPBB”