Facilmente consultar Rich snippets online
<body> ... <star-snippet></star-snippet> ... </body>
<body> ... <!-- star-snippets.com --> <script> (function() { function async_load(){ var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'http://star-snippets.com/script'; //s.src = 'http://star-snippets.com/script?prevent_cache=' + new Date().getTime(); //opcionalmente também é possível desativar o Caching var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); } if (window.attachEvent) window.attachEvent('onload', async_load); else window.addEventListener('load', async_load, false); })(); </script> </body> <!-- integrar diretamente antes do body Tag de fechamento -->
<body> ... <?php //parâmetro url deve estar de acordo com o parâmetro href do código javascript $url = "http://star-snippets.com/rating?url=http://www.example.com"; $title = "Página de exemplo"; $description = "Uma descrição para minha página de exmplo"; if($title != "") { $url .= "&name=".rawurlencode($title); } if($description != "") { $url .= "&description=".rawurlencode($description); } $timeout = 10; try { $streamContext = stream_context_create(array('http' => array('timeout' => $timeout))); $response = file_get_contents($url, false, $streamContext); if (!$response) {} else { echo $response; } } catch (Exception $ex) { } ?> ... </body>
// Comente esta linha. // $response = file_get_contents($url, false, $streamContext); // Ao invés disso, utilize as seguintes linhas $session = curl_init($url); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_TIMEOUT, $timeout); $response = curl_exec($session); curl_close($session);
<body> ... <star-snippet></star-snippet> ... </body>
<body> ... <?php $doc = JFactory::getDocument(); $url = "http://star-snippets.com/rating?url=".JURI::current(); if($doc->getTitle() != "") { $url .= "&name=".rawurlencode($doc->getTitle()); } if($doc->getDescription() != "") { $url .= "&description=".rawurlencode($doc->getDescription()); } $timeout = 10; try { $streamContext = stream_context_create(array('http' => array('timeout' => $timeout))); $response = file_get_contents($url, false, $streamContext); if (!$response) {} else { echo $response; } } catch (Exception $ex) { } ?> <!-- star-snippets.com --> <script> (function() { function async_load(){ var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'http://star-snippets.com/script'; //s.src = 'http://star-snippets.com/script?prevent_cache=' + new Date().getTime(); //opcionalmente também é possível desativar o Caching var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); } if (window.attachEvent) window.attachEvent('onload', async_load); else window.addEventListener('load', async_load, false); })(); </script> </body>
// Comente esta linha. // $response = file_get_contents($url, false, $streamContext); // Ao invés disso, utilize as seguintes linhas $session = curl_init($url); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session, CURLOPT_TIMEOUT, $timeout); $response = curl_exec($session); curl_close($session);