@@ -260,7 +260,7 @@ public function get_custom_field_by_name($name_custom_field, $post_type){
260260 $ field = $ wpdb ->get_row ( $ query , ARRAY_A );
261261 return $ field ;
262262 }
263-
263+
264264 public function mf_resolve_linebreaks ($ data = NULL ){
265265 $ data = preg_replace (array ("/ \r\n/ " ,"/ \r/ " ,"/ \n/ " ),"\\n " ,$ data );
266266 return $ data ;
@@ -375,7 +375,7 @@ public function import($file_path,$overwrite){
375375 $ post_type ['label ' ]['name ' ] = $ temp_name ;
376376 $ post_type ['label ' ]['menu_name ' ] = $ temp_name ;
377377 }
378-
378+
379379 $ post_type ['core ' ]['id ' ] = NULL ;
380380
381381 $ this ->new_posttype ($ post_type );
@@ -398,7 +398,7 @@ public function import($file_path,$overwrite){
398398 unset($ tmp_group );
399399 $ tmp_group ['core ' ] = $ group ;
400400 $ this ->update_custom_group ($ tmp_group );
401-
401+
402402 foreach ($ fields as $ field ){
403403 $ tmp_field = $ this ->get_custom_field_by_name ($ field ['name ' ],$ name );
404404
@@ -416,7 +416,7 @@ public function import($file_path,$overwrite){
416416 $ tmp_field ['option ' ] = unserialize ( $ field ['options ' ] );
417417 $ this ->new_custom_field ($ tmp_field );
418418 }
419-
419+
420420 }
421421
422422 }else {
@@ -453,7 +453,7 @@ public function import($file_path,$overwrite){
453453 foreach ($ taxonomies as $ taxonomy ){
454454 if ($ overwrite ){
455455 $ t_type = $ taxonomy ['core ' ]['type ' ];
456-
456+
457457 $ tmp_taxonomy = $ this ->get_custom_taxonomy_by_type ($ t_type );
458458
459459 if ($ tmp_taxonomy ){
@@ -468,9 +468,9 @@ public function import($file_path,$overwrite){
468468
469469 }else {
470470 $ t_type = $ taxonomy ['core ' ]['type ' ];
471-
471+
472472 $ tmp_taxonomy = $ this ->get_custom_taxonomy_by_type ($ t_type );
473-
473+
474474 if ($ tmp_taxonomy ){
475475 $ i = 2 ;
476476 $ temp_name = $ t_type . "_1 " ;
@@ -490,7 +490,7 @@ public function import($file_path,$overwrite){
490490 $ this ->new_custom_taxonomy ($ taxonomy );
491491 }
492492 }
493-
493+
494494 }
495495 /* end register custom taxonomies */
496496
@@ -503,12 +503,47 @@ function escape_data(&$value){
503503 // quick fix for ' character
504504 /** @todo have a proper function escaping all these */
505505 if (is_string ($ value )){
506+ $ value = htmlspecialchars_decode ($ value );
507+ $ value = self ::strip_html_tags ($ value );
508+ $ value = htmlentities ($ value );
506509 $ value = stripslashes ($ value );
507510 $ value = preg_replace ('/ \'/ ' ,'´ ' , $ value );
508511 $ value = addslashes ($ value );
512+ pr ($ value );
509513 }
510514 }
511515
516+ public static function strip_html_tags ( $ text ) {
517+ $ text = preg_replace (
518+ array (
519+ // Remove invisible content
520+ '@<head[^>]*?>.*?</head>@siu ' ,
521+ '@<style[^>]*?>.*?</style>@siu ' ,
522+ '@<script[^>]*?.*?</script>@siu ' ,
523+ '@<object[^>]*?.*?</object>@siu ' ,
524+ '@<embed[^>]*?.*?</embed>@siu ' ,
525+ '@<applet[^>]*?.*?</applet>@siu ' ,
526+ '@<noframes[^>]*?.*?</noframes>@siu ' ,
527+ '@<noscript[^>]*?.*?</noscript>@siu ' ,
528+ '@<noembed[^>]*?.*?</noembed>@siu ' ,
529+ // Add line breaks before and after blocks
530+ '@</?((address)|(blockquote)|(center)|(del))@iu ' ,
531+ '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu ' ,
532+ '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu ' ,
533+ '@</?((table)|(th)|(td)|(caption))@iu ' ,
534+ '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu ' ,
535+ '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu ' ,
536+ '@</?((frameset)|(frame)|(iframe))@iu ' ,
537+ ),
538+ array (
539+ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ,
540+ "\n\$0 " , "\n\$0 " , "\n\$0 " , "\n\$0 " , "\n\$0 " , "\n\$0 " ,
541+ "\n\$0 " , "\n\$0 " ,
542+ ),
543+ $ text );
544+ return strip_tags ( $ text );
545+ }
546+
512547 /* function save and update for post type */
513548
514549 /**
@@ -545,7 +580,7 @@ public function update_post_type($data){
545580
546581 // escape all the strings
547582 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
548-
583+
549584 $ sql = $ wpdb ->prepare (
550585 "Update " . MF_TABLE_POSTTYPES .
551586 " SET type = %s, name = %s, description = %s, arguments = %s " .
@@ -567,10 +602,10 @@ public function update_post_type($data){
567602 */
568603 public function new_custom_group ($ data ){
569604 global $ wpdb ;
570-
605+
571606 // escape all the strings
572607 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
573-
608+
574609 $ sql = $ wpdb ->prepare (
575610 "INSERT INTO " . MF_TABLE_CUSTOM_GROUPS .
576611 " (name, label, post_type, duplicated, expanded) " .
@@ -582,7 +617,7 @@ public function new_custom_group($data){
582617 1
583618 );
584619 $ wpdb ->query ($ sql );
585-
620+
586621 $ postTypeId = $ wpdb ->insert_id ;
587622 return $ postTypeId ;
588623 }
@@ -596,7 +631,7 @@ public function update_custom_group($data){
596631 //ToDo: falta sanitizar variables
597632 // podriamos crear un mettodo para hacerlo
598633 // la funcion podria pasarle como primer parametro los datos y como segundo un array con los campos que se va a sanitizar o si se quiere remplazar espacios por _ o quitar caracteres extraños
599-
634+
600635 // escape all the strings
601636 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
602637
@@ -610,7 +645,7 @@ public function update_custom_group($data){
610645 1 ,
611646 $ data ['core ' ]['id ' ]
612647 );
613-
648+
614649 $ wpdb ->query ($ sql );
615650 }
616651
@@ -619,7 +654,7 @@ public function new_custom_field($data){
619654 global $ wpdb ;
620655
621656 if ( !isset ($ data ['option ' ]) ) $ data ['option ' ] = array ();
622-
657+
623658 // escape all the strings
624659 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
625660
@@ -632,7 +667,7 @@ public function new_custom_field($data){
632667 $ data ['core ' ]['name ' ] = str_replace (" " ,"_ " ,$ data ['core ' ]['name ' ]);
633668
634669 $ sql = $ wpdb ->prepare (
635- "INSERT INTO " . MF_TABLE_CUSTOM_FIELDS .
670+ "INSERT INTO " . MF_TABLE_CUSTOM_FIELDS .
636671 " (name, label, description, post_type, custom_group_id, type, required_field, duplicated, options) " .
637672 " VALUES (%s, %s, %s, %s, %d, %s, %d, %d, %s) " ,
638673 $ data ['core ' ]['name ' ],
@@ -656,7 +691,7 @@ public function update_custom_field($data){
656691 global $ wpdb ;
657692
658693 if ( !isset ($ data ['option ' ]) ) $ data ['option ' ] = array ();
659-
694+
660695 // escape all the strings
661696 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
662697
@@ -669,7 +704,7 @@ public function update_custom_field($data){
669704 $ data ['core ' ]['name ' ] = str_replace (" " ,"_ " ,$ data ['core ' ]['name ' ]);
670705
671706 $ sql = $ wpdb ->prepare (
672- "UPDATE " . MF_TABLE_CUSTOM_FIELDS .
707+ "UPDATE " . MF_TABLE_CUSTOM_FIELDS .
673708 " SET name = %s, label = %s, description = %s, type = %s, required_field = %d, " .
674709 " duplicated = %d, options = %s " .
675710 " WHERE id = %d " ,
@@ -686,13 +721,13 @@ public function update_custom_field($data){
686721 }
687722
688723 /* function for save and update custom taxonomies */
689-
724+
690725 /**
691726 * Save a new custom taxonomy
692727 */
693728 public function new_custom_taxonomy ($ data ){
694729 global $ wpdb ;
695-
730+
696731 // escape all the strings
697732 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
698733
@@ -708,7 +743,7 @@ public function new_custom_taxonomy($data){
708743 1
709744 );
710745
711- $ wpdb ->query ($ sql );
746+ $ wpdb ->query ($ sql );
712747 $ custom_taxonomy_id = $ wpdb ->insert_id ;
713748 return $ custom_taxonomy_id ;
714749 }
@@ -718,7 +753,7 @@ public function new_custom_taxonomy($data){
718753 */
719754 public function update_custom_taxonomy ($ data ){
720755 global $ wpdb ;
721-
756+
722757 // escape all the strings
723758 array_walk_recursive ($ data , array ($ this , 'escape_data ' ));
724759
@@ -737,7 +772,7 @@ public function update_custom_taxonomy($data){
737772 }
738773
739774 public static function mf_unregister_post_type ( $ post_type ) {
740- /* Ideally we should just unset the post type from the array
775+ /* Ideally we should just unset the post type from the array
741776 but wordpress 3.2.1 this doesn't work */
742777
743778 //global $wp_post_types;
@@ -746,8 +781,8 @@ public static function mf_unregister_post_type( $post_type ) {
746781 // return true;
747782 //}
748783
749- /* So, we are only remove the item from the menu (this is not a
750- real unregister post_type but for at least we not will see
784+ /* So, we are only remove the item from the menu (this is not a
785+ real unregister post_type but for at least we not will see
751786 the post or page menu)
752787 */
753788 if ( $ post_type == "post " ) {
0 commit comments