fix arabic cross_site_rss with ajaxcrud_PHP_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > PHP > fix arabic cross_site_rss with ajaxcrud

fix arabic cross_site_rss with ajaxcrud

 2011/12/5 7:34:55  zycbob  http://zycbob.iteye.com  我要评论(0)
  • 摘要:1.changethemysqltable/fieldstoutf8_general_ciandaddalineonpreheader.phpmysql_query("SETNAMESutf8");applyutf-8forallrelativephp/jsfiles.2.addtinyMCEinphppage.<scriptlanguage="javascript"type="text/javascript"src="tiny_mce/tiny_mce.js"><
  • 标签:Ajax RSS
1. change the mysql table / fields to utf8_general_ci and add a line on preheader.php
mysql_query("SET NAMES utf8");
apply utf-8 for all relative php/js files.


2. add tinyMCE in php page.
	<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
	<link rel="stylesheet" href="tiny_mce/themes/advanced/skins/default/ui.css">

	<script xmlns="http://www.w3.org/1999/xhtml" language="javascript" type="text/javascript">
        tinyMCE.init({
			mode : "textareas",
			theme : "advanced",
			gecko_spellcheck : true,
			remove_linebreaks : true,
			width : "640",
			plugins : "table,advimage,advlink,emotions,iespell,insertdatetime,preview,searchreplace,xhtmlxtras,media,directionality",
			theme_advanced_buttons1 : "justifyleft,ltr,|,justifyright,rtl,|,justifycenter",
			theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,fontsizeselect,forecolor,backcolor,|,sub,sup",
			theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,removeformat,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,preview",
			theme_advanced_disable : "charmap",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_path_location : "bottom"
			});
	</script>


3. remember to trigger the save function before submit on page ajaxCRUD.class.php function insertHeader and function makeAjaxEditor
tinyMCE.triggerSave();

4. decode the fields on function doAction
                        foreach($submitted_array as $field){
                            $submitted_values[] = urldecode($field);
                        }



5. encodeURIComponent on function makeAjaxEditor
        $return_html .= "<span class=\"editable hand_cursor\" id=\"" . $prefield ."_show\" onClick=\"
			document.getElementById('" . $prefield . "_edit').style.display = '';
			document.getElementById('" . $prefield . "_show').style.display = 'none';
			document.getElementById('" . $input_name . "').focus();
            \">" . $field_text . "</span>
        <span id=\"" . $prefield ."_edit\" style=\"display: none;\">
            <form style=\"display: inline;\" name=\"form_" . $prefield . "\" id=\"form_" . $prefield . "\" onsubmit=\"
				tinyMCE.triggerSave();
				document.getElementById('" . $prefield . "_edit').style.display='none';
				document.getElementById('" . $prefield . "_save').style.display='';
                var req = '" . $this->ajax_file . "?ajaxAction=update&id=" . $unique_id . "&field=" . $field_name . "&table=" . $this->db_table . "&pk=" . $this->db_table_pk . "&val=' + encodeURIComponent(document.getElementById('" . $input_name . "').value);
				sndUpdateReq(req);
				return false;
			\">";



6. on file javascript_functions.js
change the charset
http_request.overrideMimeType('text/plain;charset=utf-8');

replace escape to encodeURIComponent for function getFormValues
			str += fobj.elements[i].name + "=" + encodeURIComponent(fobj.elements[i].value) + "&";

				var chkValue = encodeURIComponent(fobj.elements[i].value);


7. add <![CDATA[]]> to rss files - announcement_.php
	echo "		<title><![CDATA[" . $row['announcement_title'] . "]]></title>";
	echo "		<description><![CDATA[" . $row['announcement_description'] . "]]></description>";


8. summary
use javascript function encodeURIComponent but escape to encode value
use php function urldecode to decode value
// raw value
// <p>????? (???????</p>
$str = urldecode('%3Cp%3E%D8%B4%D8%B9%D8%A8%D9%8A%D8%A9%20(%D8%A8%D8%A7%D9%84%D8%B5%D9%8A%D9%86%D9%8A%3C%2Fp%3E');
echo $str;
发表评论
用户名: 匿名