
<?php
// Get current URL to fetch name in title
$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// Make sure it's the first time we check so that we don't end up in an infinite loop
if($_GET['titleset'] != 'yes')
{
// Call the function to get the title
// NOTE: If there's a variable with Piwigo that holds the site title just replace "getTitle($url)" with that variable
$title = getTitle($url);
}
// Clean up the title to only have the name left
$title = explode('|', $title);
$name = $title[0];
$name = rtrim($name, ' ');
$searchName = str_replace(' ', '+', $name);
// Create variables with search links for a few sites
$google = '<a href="https://www.google.com/search?q='.$searchName.'" target="_blank">Search using Google</a>';
$imdb = '<a href="http://www.imdb.com/find?q='.$searchName.'" target="_blank">Search using IMDB</a>';
$wikipedia = '<a href="http://en.wikipedia.org/w/index.php?search='.$searchName.'" target="_blank">Search using Wikipedia</a>';
// Output the search links to the page, as well as line breaks for each one (<br>)
// NOTE: The variables are only usable AFTER the above code.
echo $google;
echo '<br>';
echo $imdb;
echo '<br>';
echo $wikipedia;
echo '<br>';
// Function to fetch the title of the specified URL (current page)
function getTitle($url)
{
// Check if we need to use ? or & for the parameters to not end up in a loop
if(empty($_SERVER['QUERY_STRING']))
{
$url = $url.'?titleset=yes';
}
else
{
$url = $url.'&titleset=yes';
}
// Get the contents of the current page
if($contents = @file_get_contents($url))
{
// Find the title
preg_match_all('/<title>(.*)<\/title>/', $contents, $matches);
// Return the title to the function caller
return $matches[1][0];
}
}
?>Return to Suggestions/Feedback
Users browsing this forum: No registered users and 0 guests