Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/09/2011, 17:12
Honolulu
 
Fecha de Ingreso: febrero-2011
Mensajes: 99
Antigüedad: 13 años, 2 meses
Puntos: 6
Información Guia Rapida: Botones Sociales Customizados

Aprovecho la conexión para explicar como hacer una cajita con los botones de facebook y twitter, el de votar y el de comentar, todos con sus contadores, independientes y 100% customizables.
Lo insertamos mediante php en un customfield de la vista.
Necesitaremos el modulo plus1 para los votos.
para facebook y twiter obtenemos los resultados de su api graph. (en local ralentiza un poco, yo lo dejo comentado si trabajo en local), ponemos el boton que queramos.
para el plus1 lo votamos por url y obtenemos su esultado
para los comentarios como no llamada al modulo statics.
Suerte
Código PHP:
<?php
            $targetPath 
"node/";
            
$targetPath .= $data->nid;
            
$targetPath 'http://'.$_SERVER['HTTP_HOST'].base_path().drupal_get_path_alias($targetPath$path_language '');
            
$base_url_ruta 'http://'.$_SERVER['HTTP_HOST'].base_path();
            
?>
            
            
    <table id="shares_grid_table" width="165">
          <tr>
            <td id="fb_share">
                <a name="fb_share" type="button" href="http://www.facebook.com/sharer.php?u=<?php print $targetPath?>" target="_blank"><img src="<?php print $base_url_ruta?>sites/all/imagenes/social/fb_share_grid.jpg" width="18" height="18"></a>
          </td>
            <td id="fb_count">
                <?php
                $like_results 
file_get_contents('http://graph.facebook.com/'$targetPath);
                
$like_array json_decode($like_resultstrue);
                
$like_count =  $like_array['shares'];
                print (
$like_count ) ? $like_count "0";
                
?>
            </td>
            <td id="twitt_share"><a name="twitt_share" type="button" href="http://twitter.com/home?status=Currently reading <?php print $targetPath?>" target="_blank"><img src="<?php print $base_url_ruta?>sites/all/imagenes/social/twitt_share_grid.jpg" width="18" height="18"></a></td>
            <td id="twitt_count">
                <?php
                
 
                    $twitt_results 
file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' $targetPath);  
                    
$twitt_array json_decode($twitt_resultstrue);
                    
$twitt_count $json['count'];
                     
                    print (
$twitt_count) ? $twitt_count "0";
                
                
?>
            </td>
            <td id="heart_share">
                    <div id="votar"> <a href="/plus1/vote/<?php $numeroNodo $data->nid; print $numeroNodo?>?token=<?php print drupal_get_token($node->nid?>&destination=" class="plus1-link">
                    
                    <img src="<?php print $base_url_ruta?>sites/all/imagenes/social/heart_share_grid.jpg" width="18" height="18">
                    
                    </a></div>
                    
            </td>
            <td id="heart_count">
            <?php
$current_rating 
votingapi_select_results(array('content_id' => $data->nid'function' => 'sum''value_type' =>'points'));
$votos $current_rating[0]['value'];
$cero '0';
$uno '1';
if (
$votos >= $uno){
    print 
$votos.'</div>';
}else{print 
$cero;}

?>
            </td>
            <td id="comment_share">
                <a href="node/<?php $numeroNodo $data->nid; print $numeroNodo?>">
                    
                    <img src="<?php print $base_url_ruta?>sites/all/imagenes/social/comment_share_grid.jpg" width="18" height="18">
                    
                    </a>
            </td>
            <td id="comment_counts">
            
            <?php   
                
 
print $data->node_comment_statistics_comment_count;
?>
            
            </td>
        </tr>
   </table>