Auto Link Titles

Auto Link Titles 1.0.10

No permission to download
You need to enable the mb_convert_encoding function in PHP.
How can I enable this function ? On my server the mbstring module is enabled. Is there anything to configure additionally ?
I get the same error messages ("Incorrect string value..." followed by a "\x..") if I try to insert a link to a website that is not UTF-8 encoded AND has at least 1 German special character (ä,ö,ü,....)
 
Think so. I don't get any "Call to undefined function mb_convert_encoding() " error messages, and phpinfo says:
upload_2015-1-12_15-16-18.webp

I tested a bit to search for a workaround.
Therefore I added a str_replace function to replace all German special characters in $urlTitle, but still had the same errors.
After a longer investigation I found out, that the $urlTitle doesn't contain any German special characters to replace. It looks like the function "_getTitle" returns a $urlTitle that already contains these "\x.." things instead of the original characters of the linked site.
 
Think so. I don't get any "Call to undefined function mb_convert_encoding() " error messages, and phpinfo says:
View attachment 94583

I tested a bit to search for a workaround.
Therefore I added a str_replace function to replace all German special characters in $urlTitle, but still had the same errors.
After a longer investigation I found out, that the $urlTitle doesn't contain any German special characters to replace. It looks like the function "_getTitle" returns a $urlTitle that already contains these "\x.." things instead of the original characters of the linked site.

I see. Yes now I tested it and that is correct. However not at all in title characters. It just getting the error on some characters. E.g;

´ and

XenForo ´n´ Link ´n´ Title Test

After this, then getting the error...

An option would be awesome like this;

Code:
"' => '',
        "'" => '',
        "Ö" => "o",
        "ö" => "o",
        "C" => "c",
        "c" => "c",
        "Ğ" => "g",
        "ğ" => "g",
        "Ş" => "s",
        "ş" => "s",
        "Ü" => "u",
        "ü" => "u",
        "İ" => "i",
        "ı" => "i",
        "Ç" => "c",
        "ç" => "c",
        "é" => "i",
        "â" => "a",
        "Ê" => "e",
        "Â" => "a",
        "?" => "_",
        "*" => "_",
        "." => "_",
        "," => "_",
        ";" => "_",
        ")" => "_",
        "(" => "_",
        "{" => "_",
        "}" => "_",
        "[" => "_",
        "]" => "_",
        "!" => "_",
        "+" => "_",
        "%" => "_",
        "&" => "_",
        "#" => "_",
        "$" => "_",
        "=" => "_",
        "ê" => "e",
        "." => "-"
 
Well, in AutoLink.php

Code:
$urlTitle = str_replace("\n", '', trim($urlTitle));

So...

I think this should be like this;

Code:
$urlTitle = str_replace($title, array(
        '"' => '',
        "'" => '',
        "Ö" => "o",
        "ö" => "o",
        "C" => "c",
        "c" => "c",
        "Ğ" => "g",
        "ğ" => "g",
        "Ş" => "s",
        "ş" => "s",
        "Ü" => "u",
        "ü" => "u",
        "İ" => "i",
        "ı" => "i",
        "Ç" => "c",
        "ç" => "c",
        "é" => "i",
        "â" => "a",
        "Ê" => "e",
        "Â" => "a",
        "?" => "_",
        "*" => "_",
        "." => "_",
        "," => "_",
        ";" => "_",
        ")" => "_",
        "(" => "_",
        "{" => "_",
        "}" => "_",
        "[" => "_",
        "]" => "_",
        "!" => "_",
        "+" => "_",
        "%" => "_",
        "&" => "_",
        "#" => "_",
        "$" => "_",
        "=" => "_",
        "ê" => "e",
        "." => "-",
        trim($urlTitle)
        ));

Note that don't try please. It just a testing. So if you remember vBSEO, you did not need this functions anymore. The author should look at that then.

Regards,
 
However not at all in title characters.
Yes, only if the target site is not on UTF-8 AND the title contains special characters.
An option would be awesome like this;
I tried it with
PHP:
    protected function _sonderzeichen($urlTitle)
        {
        $search = array("Ä", "Ö", "Ü", "ä", "ö", "ü", "ß", "´");
        $replace = array("Ae", "Oe", "Ue", "ae", "oe", "ue", "ss", "");
        return str_replace($search, $replace, $urlTitle);
        }
and added it after the trim line:
PHP:
        // Removes white space from before and after (and in the middle!) of the URLs
        $urlTitle = str_replace("\n", '', trim($urlTitle));
       
        $urlTitle = $this->_sonderzeichen($urlTitle);
But, as written in my earlier post, at this time there is no special character left in the $urlTitle to replace.
Only the "\x.." things ...
 
@pecadm I have fixed this issue.

Find in AutoLink.php;

Code:
$urlTitle = html_entity_decode($urlTitle, ENT_QUOTES);

Replace with;

Code:
$urlTitle = html_entity_decode($urlTitle, ENT_QUOTES, 'UTF-8');

Save and done.

Note that after made this changes, it will solve the problem. ;)

Regards,
 
Last edited:
@Eagle
works, with an additional code change ;)

The charset can be noted in 2 ways:
Code:
<meta charset="iso-something"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-something"/>
Most of the sites I know do note it using the first way, so the original preg_match will never find the charset as there is no "content-type" part and the function will always give back "UTF-8" as charset:
PHP:
if (!preg_match('#content-type:.*?charset=([a-z0-9\-]+)#is', $pageHeaders, $contentTypeMatch))
I changed the preg_match to
PHP:
if (!preg_match('#<meta[^>]*?charset=\"?([a-z0-9\-]+)#is', $pageHeaders, $contentTypeMatch))
This should now cover both notations (not sure, I am not a regex specialist ;) )

Additionally I noticed that if-conditions seem to be case-sensitive ?! :eek:
As long as I used
PHP:
if ($pageCharset == 'UTF-8')
the return was always "false" if the the charset was "utf-8".
So I changed it to
PHP:
if (($pageCharset == 'utf-8') || ($pageCharset == 'UTF-8'))
Now everything is working as expected ;)
 
Not for me :(
Code:
http://www.immobilio.it/threads/diventare-agente-immobiliare-oggi-si-può-o-è-un-suicidio.33204/
What exactly is the problem ? Can't see anything on the page you linked. And my Italian isn't as good as a it should be to understand what's written there ;)
Do you get error messages when trying to link an external site ? If so, how is this site encoded ? Which one is it ?
What you pls attach your autolink.php ?
 
The problem is that if the URLs contain some accented letters (ì è ò ù à) the addon don't convert it

Schermata 2015-01-20 alle 22.57.54.webp

This is my autolink.php

PHP:
<?php

class AVForums_AutoLinkTitles_BbCode_Formatter_BbCode_AutoLink extends XFCP_AVForums_AutoLinkTitles_BbCode_Formatter_BbCode_AutoLink
{
    protected $_pageHeader = '';
    protected $_pageContent = '';

    /**
     * Handles autolinking the given URL.
     *
     * @param string $url
     *
     * @return string
     */
    protected function _autoLinkUrl($url)
    {
        $parent = parent::_autoLinkUrl($url);

        try
        {
            if (preg_match('/\[url="(.*?)"\](.*?)\[\/url\]/i', $parent, $linkParts))
            {
                if (isset($linkParts[1]) && isset($linkParts[2]))
                {
                    $url = $linkParts[1];

                    $urlTitle = $this->getTitle($url);
                    if (!$urlTitle)
                    {
                        return $parent;
                    }
                    $parent = '[url="' . $url . '"]' . $urlTitle . '[/url]';
                }
            }
            elseif (preg_match('/\[url\](.*?)\[\/url\]/i', $parent, $linkParts))
            {
                $url = $linkParts[1];

                $urlTitle = $this->getTitle($url);
                if (!$urlTitle)
                {
                    return $parent;
                }

                $parent = '[url="' . $url . '"]' . $urlTitle . '[/url]';
            }
        }
        catch (Exception $e)
        {
            return $parent;
        }

        return $parent;
    }

    public function getTitle($url)
    {
        if (!Zend_Uri::check($url))
        {
            return false;
        }

        $this->_pageHeader = '';
        $this->_pageContent = '';

        $urlTitle = $this->_getTitle($url);
        if (!$urlTitle)
        {
            return false;
        }

        // Converts HTML entities to the real characters e.g. &amp = & and &reg = ®
        $urlTitle = html_entity_decode($urlTitle, ENT_QUOTES, 'UTF-8');

        // Removes white space from before and after (and in the middle!) of the URLs
        $urlTitle = str_replace("\n", '', trim($urlTitle));

        $pageCharset = $this->_getPageCharset($this->_pageHeader, $this->_pageContent);
        if (($pageCharset == 'utf-8') || ($pageCharset == 'UTF-8'))
        {
            return $urlTitle;
        }
        else
        {
            $urlTitle = mb_convert_encoding($urlTitle, 'UTF-8', $pageCharset);
        }

        return $urlTitle;
    }

    /**
     * Internal function to get title and cache headers etc.
     * Slightly amended from XenForo_Helper_Url::getTitle.
     *
     * @return string
     */
    protected function _getTitle($url)
    {
        if (preg_match('#^https?://#i', $url))
        {
            try
            {
                $client = XenForo_Helper_Http::getClient($url, array(
                    'timeout' => 10
                ));

                $request = $client->request();

                if ($request->isSuccessful())
                {
                    $this->_pageHeader = $request->getHeadersAsString();

                    $html = $request->getBody();
                    $this->_pageContent = $html;

                    if (preg_match('#<title[^>]*>(.*)</title>#siU', $html, $match))
                    {
                        return $match[1];
                    }
                }
            }
            catch (Zend_Http_Client_Exception $e)
            {
                return false;
            }
        }

        return false;
    }

    protected function _getPageCharset($pageHeaders, $pageContent)
    {
        if (!preg_match('#<meta[^>]*?charset=\"?([a-z0-9\-]+)#is', $pageHeaders, $contentTypeMatch))
        {
            $pageContent = preg_replace('#<!--.*?-->#s', '', $pageContent);
            preg_match('#<meta[^>]*?content-type[^>]*?charset=(.+?)\"#is', $pageContent, $contentTypeMatch);
        }

        if (isset($contentTypeMatch[1]))
        {
            return $contentTypeMatch[1];
        }

        return 'UTF-8';
    }
}
 
The problem is that if the URLs contain some accented letters (ì è ò ù à) the addon don't convert it
For me it works if I add your URL to a post in my forum:
upload_2015-1-20_23-10-7.webp

Did you activate the option "Romanize Titles in URLs" (last option on /admin.php?options/list/basicBoard).

Is the given URL one of the forum where you try to post the link ? As I know from the former posts the Autolink script is not working for internal links.
 
I just got an error that I'll post here, although it works well most of the time:

Code:
ErrorException: Fatal Error: Call to undefined function mb_convert_encoding() - library/AVForums/AutoLinkTitles/BbCode/Formatter/BbCode/AutoLink.php:85
Generated By: ADMIN, A moment ago
Stack Trace
#0 [internal function]: XenForo_Application::handleFatalError()
#1 {main}
Request State
array(3) {
  ["url"] => string(48) "https://mysite.com/posts/6870/my-post"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(7) {
    ["message_html"] => string(423) "<p><b>Re: Thread Title</b></p><p><br></p><p>just.cheaper&nbsp; <img src="styles/default/xenforo/clear.png" class="mceSmilieSprite mceSmilie2" alt=";)" unselectable="on"></p><p>check out these links.</p><p><br></p>http://www.typicallink.com<br><br><p><br></p><p>the ballast is usually included</p>
"
    ["_xfRelativeResolver"] => string(83) "https://mysite.com/threads/mythread-3205/"
    ["silent"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfRequestUri"] => string(58) "/threads/mythread.3205/"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
  }
}
 
Back
Top Bottom