|
If (! Defined ('basepath') exit ('no direct script access allowed ');
/**
* HTML replacement processing class. Consider the following replacement methods:
* 1. img src: '/] + ?) /I'
* 2. a href: '/] + ?) /I'
* 3. ifram. src :'/ ] + ?) /I'
* 4. frame src :'/ ] + ?) /I'
* 5. js: '/window. open ([(] + ?) ([\ '"] + ?) (. + ?) ([) +?]) /I'
* 6. css: '/background (. + ?) Url ([(]) ([\ '"] + ?) (. + ?) ([) +?]) /I'
*/
Class Myreplace {
Private $ moudle_array = array ('udata', 'tdata', 'tresresult', 'dresresult ');
Private $ content;
Private $ relative_dirname;
Private $ projectid;
Private $ moudle;
Function _ construct (){
$ This-> CI = & get_instance ();
}
/**
* Replace
* @ Param string $ content HTML content
* @ Param string $ relative path of relative
* @ Param int $ projectid Project id
* @ Moudle string $ moudle template id: udata, tdata, tresult, dresult
*/
Public function my_replace ($ content, $ relative, $ projectid, $ moudle ){
$ This-> content = $ content;
$ This-> relative_dirname = $ relative;
$ This-> projectid = $ projectid;
If (in_array (strtolower ($ moudle), $ this-> moudle_array ))
$ This-> moudle = $ moudle;
Else exit;
Switch ($ this-> moudle ){
Case 'udata ':
$ This-> CI-> load-> model ('mupload _ data', 'model ');
Break;
Case 'tdata ':
$ This-> CI-> load-> model ('taskdata', 'model ');
Break;
Case 'result ':
$ This-> CI-> load-> model ('taskresult', 'model ');
Break;
Case 'dresresult ':
$ This-> CI-> load-> model ('dmsresult', 'model ');
Break;
Default:
Break;
}
$ Pattern = '/] + ?) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'image _ replace '), $ content );
$ Pattern = '/] + ?) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'HTML _ replace '), $ content );
$ Pattern = '/ ] + ?) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'iframe _ replace '), $ content );
$ Pattern = '/ ] + ?) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'frame _ replace '), $ content );
$ Pattern = '/window. open ([(] + ?) ([\ '"] + ?) (. + ?) ([)] + ?) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'JS _ replace '), $ content );
$ Pattern = '/background (. + ?) Url ([(]) ([\ '"] + ?) (. + ?) ([) +?]) /I ';
$ Content = preg_replace_callback ($ pattern, array ($ this, 'css _ replace '), $ content );
Return $ content;
}
Private function image_replace ($ matches ){
If (count ($ matches) <4) return '';
If (empty ($ matches [3]) return '';
$ Matches [3] = rtrim ($ matches [3], '\' "/');
// Obtain the image id
$ Parent_dir_num = substr_count ($ matches [3], '.../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ matches [3], './');
$ Image_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ image_id )){
If ($ this-> moudle = 'dresresult '){
Return "CI-> config-> item (" base_url ")." cdms/". $ this-> moudle."/readpic/$ image_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
} Else {
Return "CI-> config-> item (" base_url ")." cdms/". $ this-> moudle."/picfile/$ image_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
}
} Else {
Return"
}
}
Private function html_replace ($ matches ){
If (count ($ matches) <4) return '';
If (empty ($ matches [3]) return '';
// If the href link ($ matches [3]) starts with http, www, or mailto, no processing is performed.
// If (preg_match ('/^ [http | www | mailto] (. + ?) /I ', $ matches [3])
// Return"
$ Matches [3] = rtrim ($ matches [3], '\' "/');
// Process the anchor
If (substr_count ($ matches [3], '#')> 0)
$ Matches [3] = substr ($ matches [3], 0, strrpos ($ matches [3], '#');
// Obtain the html id
$ Parent_dir_num = substr_count ($ matches [3], '.../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ matches [3], './');
$ Txtfile_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ txtfile_id )){
If ($ this-> moudle = 'dresresult '){
Return "CI-> config-> item (" base_url ")." cdms/". $ this-> moudle."/readfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
} Else {
Return "CI-> config-> item (" base_url ")." cdms/". $ this-> moudle."/txtfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
}
} Else {
Return"
}
}
Private function iframe_replace ($ matches ){
If (count ($ matches) <4) return '';
If (empty ($ matches [3]) return '';
$ Matches [3] = rtrim ($ matches [3], '\' "/');
// Process the anchor
If (substr_count ($ matches [3], '#')> 0)
$ Matches [3] = substr ($ matches [3], 0, strrpos ($ matches [3], '#');
// Obtain the html id
$ Parent_dir_num = substr_count ($ matches [3], '.../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ matches [3], './');
$ Txtfile_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ txtfile_id )){
If ($ this-> moudle = 'dresresult '){
Return" CI-> config-> item ("base_url"). "cdms/". $ this-> moudle. "/readfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
} Else {
Return" CI-> config-> item ("base_url"). "cdms/". $ this-> moudle. "/txtfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
}
} Else {
Return" < p> <>
}
}
Private function frame_replace ($ matches ){
If (count ($ matches) <4) return '';
If (empty ($ matches [3]) return '';
$ Matches [3] = rtrim ($ matches [3], '\' "/');
// Process the anchor
If (substr_count ($ matches [3], '#')> 0)
$ Matches [3] = substr ($ matches [3], 0, strrpos ($ matches [3], '#');
// Obtain the html id
$ Parent_dir_num = substr_count ($ matches [3], '.../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ matches [3], './');
$ Txtfile_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ txtfile_id )){
If ($ this-> moudle = 'dresresult '){
Return" CI-> config-> item ("base_url"). "cdms/". $ this-> moudle. "/readfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
} Else {
Return" CI-> config-> item ("base_url"). "cdms/". $ this-> moudle. "/txtfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. $ matches [4];
}
} Else {
Return" < p> <>
}
}
Private function js_replace ($ matches ){
If (count ($ matches) <4) return '';
If (empty ($ matches [3]) return '';
// Process the link
$ Arr_html = split (',', $ matches [3]);
$ Href = $ arr_html [0];
$ Other = '';
For ($ I = 0; $ I
$ Other = $ arr_html [$ I]. ",";
$ Other = rtrim ($ other ,"\,");
$ Href = rtrim ($ href ,'\'\"');
// Process the anchor
If (substr_count ($ href, '#')> 0)
Return "window. open". $ matches [1]. $ matches [2]. $ matches [3]. $ matches [4];
// Obtain the html id
$ Parent_dir_num = substr_count ($ href ,'../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ href ,'./');
$ Txtfile_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ txtfile_id )){
If ($ this-> moudle = 'dresresult '){
Return "window. open ". $ matches [1]. $ matches [2]. $ this-> CI-> config-> item ("base_url "). "cdms /". $ this-> moudle. "/readfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. ','. $ other. $ matches [4];
} Else {
Return "window. open ". $ matches [1]. $ matches [2]. $ this-> CI-> config-> item ("base_url "). "cdms /". $ this-> moudle. "/txtfile/$ txtfile_id? Pid = ". $ this-> projectid. $ matches [2]. ','. $ other. $ matches [4];
}
} Else {
Return "window. open". $ matches [1]. $ matches [2]. $ matches [3]. $ matches [4];
}
}
Private function css_replace ($ matches ){
If (count ($ matches) <5) return '';
If (empty ($ matches [4]) return '';
$ Matches [4] = rtrim ($ matches [4], '\' "/');
// Obtain the image id
$ Parent_dir_num = substr_count ($ matches [4], '.../');
$ Relative_dirname = $ this-> relative_dirname;
For ($ I = 0; $ I <$ parent_dir_num; $ I ++ ){
$ Relative_dirname = substr ($ relative_dirname, 0, strrpos ($ relative_dirname ,"/"));
}
$ Relativepath = rtrim ($ relative_dirname, '/'). '/'. ltrim ($ matches [4], './');
$ Image_id = $ this-> CI-> model-> get_id_by_path_and_project ($ relativepath, $ this-> projectid );
// Output
If (! Empty ($ image_id )){
If ($ this-> moudle = 'dresresult '){
Return "background ". $ matches [1]. "url ". $ matches [2]. $ matches [3]. $ this-> CI-> config-> item ("base_url "). "cdms /". $ this-> moudle. "/readpic/$ image_id? Pid = ". $ this-> projectid. $ matches [3]. $ matches [5];
} Else {
Return "background ". $ matches [1]. "url ". $ matches [2]. $ matches [3]. $ this-> CI-> config-> item ("base_url "). "cdms /". $ this-> moudle. "/picfile/$ image_id? Pid = ". $ this-> projectid. $ matches [3]. $ matches [5];
}
} Else {
Return "background ". $ matches [1]. "url ". $ matches [2]. $ matches [3]. $ matches [4]. $ matches [3]. $ matches [5];
}
}
}
/* End of Myreplace. php */
/* Location:/application/libraries/Myreplace. php */
|