I know the preferred method is to make an extension, but I haven't quite grokked that process yet. For now I've been editing the core code where and when I need to like I've always done.
So I made this function and put it in functions_content.php
Code: Select all
function get_title($url, $alt)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
$doc = new DOMDocument();
@$doc->loadHTML($data);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
if (isset($title))
{
$title = preg_replace( "/\r|\n/", "", $title );
// in case there's nothing left after preg_replace
if (isset($title))
{
return $title;
}
else
{
return $alt;
}
}
else
{
return $alt;
}
}
So then I edited a couple of cases:
Code: Select all
case MAGIC_URL_FULL:
$tag = 'm';
//$text = $short_url;
$text = get_title($orig_url, $short_url);
break;
case MAGIC_URL_WWW:
$tag = 'w';
$url = 'http://' . $url;
//$text = $short_url;
$text = get_title($orig_url, $short_url);
break;
Code: Select all
[url=http://this.is.my/link.html]This is my title[/url]
Example can be seen here:
http://criticalpoliticalboard.com/viewt ... 711#p13711
all PACE had to do was post only the link itself, and my function took care of the rest.
http://www.rferl.org/content/russia-lgb ... 81994.html
But it would still be nice to have the ability to define link titles once again without losing this function.
What am I doing wrong?
Thank you in advance.
-Okashii