Skip to content

Instantly share code, notes, and snippets.

@evemilano
Last active June 22, 2016 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evemilano/80406b4e8d01299d44f196fb3e1fe7a6 to your computer and use it in GitHub Desktop.
Save evemilano/80406b4e8d01299d44f196fb3e1fe7a6 to your computer and use it in GitHub Desktop.
Migrazione Commenti Facebook & Google Plus
<?php
#scarico il file JS
echo '<script src="https://apis.google.com/js/plusone.js"></script>';
#definisco la variabile URL del post
$permalink = get_permalink();
#imposto il tempo
$now = time();
#imposto la data della migrazione al 1 gennaio 2016, il formato è: ora, minuto, secondo, mese, giorno, anno
$compare_time = mktime(0, 0, 0, 1, 1, 2016);
#trasformo la data in formato Unix
$post_time = get_post_time('U');
#creo una nuova variabile di URL sostituendo HTTPS con HTTP
$url03 = str_replace('https://', 'http://', $permalink );
#condizione, se il post è antecedente
if ($post_time < $compare_time) {
#inserisco script con URL modificato
echo '<div class="box-gray">';
echo '<h3>Commenta con Google+</h3>';
echo "<small>Questo articolo è stato pubblicato prima della migrazione su HTTPS avvenuta il 1/1/2016. Questi commenti riguardano l'URL vecchio, senza HTTPS. Per notificarmi il commento taggami +giovannisacheli.</small></div>";
echo '<div class="g-comments" data-href="';
#uso l'URL modificato in HTTP per i post vecchi
echo $url03 . '"';
echo 'data-width="700" ';
echo 'data-first_party_property="BLOGGER" ';
echo 'data-view_type="FILTERED_POSTMOD">';
echo '</div> ';
}
#se invece la data del post è posteriore alla data di migrazione
else {
#inserisco script con URL originale
echo '<div class="box-gray">';
echo '<h3>Commenta con Google+</h3>';
echo "<small>Per notificarmi il commento taggami +giovannisacheli.</small></div>";
echo '<div class="g-comments" data-href="';
#uso l'URL originale in HTTPS per i post dopo la migrazione
echo the_permalink() . '"';
echo 'data-width="700" ';
echo 'data-first_party_property="BLOGGER" ';
echo 'data-view_type="FILTERED_POSTMOD">';
echo '</div> ';
}
# Check per la scelta della data
echo '<small>';
echo '<ul><li>Commenti successivi alla data impostata: ';
echo '<div class="g-commentcount" data-href="';
echo the_permalink();
echo '"></div></li>';
echo '<li>Commenti precedenti alla data impostata: ';
echo '<div class="g-commentcount" data-href=' . $url03 . '></div></li></ul>';
echo '</small>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment