Template function to synchro like counts of i18n translated nodes

Created on 2 May 2013, over 11 years ago
Updated 11 November 2024, 5 days ago

I has content translated with i18n module. With this translation, every translated node have diferent 'nid' value, but I need to unify the likes count of the facebook button.

I created a function in order to acomplish this. Basically, I get the source node from the tyranslation set and alter the src parameter that fblikebutton.tpl.php uses in order to render the facebook like button. I don't think that this must be included in the module, but I post here if it can be help someone.

function MYTHEME_preprocess_fblikebutton(&$variables) {
  //Get the site URL to make string changes
  $site_URL = $_SERVER['HTTP_HOST'];  
  //Modify the url string to obtain a language independent URL
  $url_temp = str_replace('http://' . $site_URL, "", $variables['url']);
  $url_temp = substr($url_temp, 4); //Delete the first 4 characters "/es/" corresponding to language
  //get the normal drupal path like "node/12"
  $font = drupal_lookup_path('source', $url_temp);
  if (substr($font, 0, 4) == 'node') { //is node??
    $node_ID = substr($font, 5); //extract the node ID
    $current_node = node_load($node_ID);
    //Get the translation original node to unify the like links
    $base_node = $current_node->tnid;
    $base_node = node_load($base_node);
    $node_language = $base_node->language;
    $alias = drupal_get_path_alias('node/'.$current_node->tnid, $node_language);
    $variables['url'] = 'http://'.$site_URL.'/'.$node_language.'/'.$alias;
    $url = 'http://'.$site_URL.'/'.$node_language.'/'.$alias;
  }
  //redefine this two variables in order to reconstruct the variables['src']
  $show_faces = $variables['show_faces'] ? 'true' : 'false';
  $language = ($variables['language']) ? '&locale=' . $variables['language'] : '';
  
  $variables['src'] = htmlentities(sprintf('href=%s&layout=%s&show_faces=%s&width=%s&font=%s&height=%s&action=%s&colorscheme=%s%s&send=false',
    $url,
    $variables['layout'],
    $show_faces,
    $variables['width'],
    $variables['font'],
    $variables['height'],
    $variables['action'],
    $variables['color_scheme'],
    $language
  ));
}
πŸ“Œ Task
Status

Closed: outdated

Version

2.3

Component

Documentation

Created by

πŸ‡ͺπŸ‡ΈSpain eidoscom

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine AstonVictor

    I'm closing it because the issue was created a long time ago without any further steps.

    if you still need it then raise a new one.
    thanks

Production build 0.71.5 2024