web/app/plugins/sitepress-multilingual-cms/inc/translation-management/translation-management.class.php
/**
    * calculate post md5
    * 
    * @param object|int $post
    * @return string
    * 
    * @todo full support for custom posts and custom taxonomies
    */
calculate post md5

@param object|int $post
@return string

@todo full support for custom posts and custom taxonomies
calculate post md5 @param object|int $post @return string @todo full support for custom posts and custom taxonomies
function post_md5($post){
        if (isset($post->external_type) && $post->external_type) {
            $md5str = '';
            foreach ($post->string_data as $key => $value) {
                $md5str .= $key . $value;
            }
        } else {
            $post_tags = $post_categories = $custom_fields_values = array();
            if(is_numeric($post)){
                $post = get_post($post);    
            }
            foreach(wp_get_object_terms($post->ID, 'post_tag') as $tag){
                $post_tags[] = $tag->name;
            }
            if(is_array($post_tags)){
                sort($post_tags, SORT_STRING);
            }        
            foreach(wp_get_object_terms($post->ID, 'category') as $cat){
                $post_categories[] = $cat->name;
            }    
            if(is_array($post_categories)){
                sort($post_categories, SORT_STRING);
            }
            global $wpdb, $sitepress_settings;
            $taxonomies = $wpdb->get_col("
                SELECT DISTINCT tx.taxonomy 
                FROM {$wpdb->term_taxonomy} tx JOIN {$wpdb->term_relationships} tr ON tx.term_taxonomy_id = tr.term_taxonomy_id
                WHERE tr.object_id = {$post->ID}
            ");
            sort($taxonomies, SORT_STRING);
            foreach($taxonomies as $t){
                if(@intval($sitepress_settings['taxonomies_sync_option'][$t]) == 1){
                    $taxs = array();
                    foreach(wp_get_object_terms($post->ID, $t) as $trm){
                        $taxs[] = $trm->name;
                    }
                    if($taxs){
                        sort($taxs,SORT_STRING);
                        $all_taxs[] = '['.$t.']:'.join(',',$taxs);
                    }
                }
            }
            $custom_fields_values = array();
            if(is_array($this->settings['custom_fields_translation'])){
                foreach($this->settings['custom_fields_translation'] as $cf => $op){
                    if ($op == 2 || $op == 1) {
                        $value = get_post_meta($post->ID, $cf, true);
                        if(!is_array($value)){
                            $custom_fields_values[] = $value;
                        }
                    }
                }
            }
            $md5str =         
                $post->post_title . ';' .                 
                $post->post_content . ';' . 
                join(',',$post_tags).';' . 
                join(',',$post_categories) . ';' . 
                join(',', $custom_fields_values);
            if(!empty($all_taxs)){
                $md5str .= ';' . join(';', $all_taxs);
            }
            if($sitepress_settings['translated_document_page_url'] == 'translate'){
                $md5str .=  $post->post_name . ';';
            }
        }
        $md5 = md5($md5str);
        return $md5;        
    }
function post_md5 ( $ post ) { if ( isset ( $ post -> external_type ) && $ post -> external_type ) { $ md5str = '' ; foreach ( $ post -> string_data as $ key => $ value ) { $ md5str .= $ key . $ value ; } } else { $ post_tags = $ post_categories = $ custom_fields_values = array ( ) ; if ( is_numeric ( $ post ) ) { $ post = get_post ( $ post ) ; } foreach ( wp_get_object_terms ( $ post -> ID , 'post_tag' ) as $ tag ) { $ post_tags [ ] = $ tag -> name ; } if ( is_array ( $ post_tags ) ) { sort ( $ post_tags , SORT_STRING ) ; } foreach ( wp_get_object_terms ( $ post -> ID , 'category' ) as $ cat ) { $ post_categories [ ] = $ cat -> name ; } if ( is_array ( $ post_categories ) ) { sort ( $ post_categories , SORT_STRING ) ; } global $ wpdb , $ sitepress_settings ; $ taxonomies = $ wpdb -> get_col ( " 
                SELECT DISTINCT tx.taxonomy 
                FROM  { $ wpdb -> term_taxonomy }  tx JOIN  { $ wpdb -> term_relationships }  tr ON tx.term_taxonomy_id = tr.term_taxonomy_id
                WHERE tr.object_id =  { $ post -> ID } " ) ; sort ( $ taxonomies , SORT_STRING ) ; foreach ( $ taxonomies as $ t ) { if ( @ intval ( $ sitepress_settings [ 'taxonomies_sync_option' ] [ $ t ] ) == 1 ) { $ taxs = array ( ) ; foreach ( wp_get_object_terms ( $ post -> ID , $ t ) as $ trm ) { $ taxs [ ] = $ trm -> name ; } if ( $ taxs ) { sort ( $ taxs , SORT_STRING ) ; $ all_taxs [ ] = '[' . $ t . ']:' . join ( ',' , $ taxs ) ; } } } $ custom_fields_values = array ( ) ; if ( is_array ( $ this -> settings [ 'custom_fields_translation' ] ) ) { foreach ( $ this -> settings [ 'custom_fields_translation' ] as $ cf => $ op ) { if ( $ op == 2 || $ op == 1 ) { $ value = get_post_meta ( $ post -> ID , $ cf , true ) ; if ( ! is_array ( $ value ) ) { $ custom_fields_values [ ] = $ value ; } } } } $ md5str = $ post -> post_title . ';' . $ post -> post_content . ';' . join ( ',' , $ post_tags ) . ';' . join ( ',' , $ post_categories ) . ';' . join ( ',' , $ custom_fields_values ) ; if ( ! empty ( $ all_taxs ) ) { $ md5str .= ';' . join ( ';' , $ all_taxs ) ; } if ( $ sitepress_settings [ 'translated_document_page_url' ] == 'translate' ) { $ md5str .= $ post -> post_name . ';' ; } } $ md5 = md5 ( $ md5str ) ; return $ md5 ; }
calculate post md5
calculate post md5
// get custom taxonomies