¿Cómo cambiar las urls https por http?
Datos importantes:Url del foro: http://www.argentinairc.net/Foro/Version de SMF: 2.0.11
Theme del foro: CleanTek
Cuenta demo: User: usuario
pass: holaamigo
Descripcion del problema:Hola amigos!!
Espero que anden muy bien!
Me gustaría que mi foro cambie las urls
https por
http, es decir cuando se publiquen urls en el cuerpo del mensaje, que en vez de salir así, por ejemplo:
https://paginaweb.com/que salga así:
http://paginaweb.com/se preguntarán ¿porqué quiero hacer esto?...
Bueno lo que pasa es que yo tengo instalado el mod Title Links en mi foro y funciona muy bien, pero no funciona con las urls que son https, solamente las que son http, mirando el código fuente y haciendo pruebas, logro darme cuenta que el mod no toma en cuenta las urls https, solamente http, digamos que ignora los https.
Me gustaría saber como lograr cambiar las urls https por http para que el mod pueda funcionar poniendo los títulos en vez de la url, ya que si pongo la web con el https pues el título no sale.
He probado a hacer algunas modificaciones en el archivo
Subs-Post.php, pero no he tenido éxito...
He probado a cambiar esta línea:
$message = preg_replace(array('~(?<=[\s>\.(;\'"]|^)((?:http)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i', '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'), array('[url]$1[/url%]', '[url]$1[/url%]'), $message);
por esta:
$message = preg_replace(array('~(?<=[\s>\.(;\'"]|^)((?:http|https)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i', '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'), array('[url]$1[/url%]', '[url]$1[/url%]'), $message);
y un poquito más abajo he cambiado esta parte:
// Attach http:// to the url...
$uri_modified = strpos($uri, 'http://') === false ? 'http://' . $uri : $uri;
por esta:
// Attach http:// to the url...
$uri = str_replace('https://', 'http://', $uri);
$uri_modified = strpos($uri, 'http://') === false ? 'http://' . $uri : $uri;
pero no ha funcionado...
También me he ido a Palabras censuradas y he puesto que cuando alguien escriba https://, se reemplace por http://, si bien se reemplaza, pero no sale el título, es como si fuese que el censurador trabajara después del mod Title links.
Por último quiero comentarles que ya he probado varios sitios cambiandole el https por el http y siempre funciona perfectamente, los títulos se insertan correctamente.
Aquí les dejo una captura de 2 urls, una con https y la otra con http:
Muchas gracias desde ya!!
EDITO: He conseguido lo que quería, he probado una modificación y funciona perfectamente, pero no sé si la forma es totalmente correcta, no quisiera tener problemas futuros por algo mal que hice, por eso les dejo una parte de la función
preparsecode para que por favor me avisen si el cambio que hice es correcto:
function preparsecode(&$message, $previewing = false)
{
global $user_info, $modSettings, $smcFunc, $context;
global $sourcedir;
// This line makes all languages *theoretically* work even with the wrong charset ;).
$message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
// Clean up after nobbc ;).
$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', 'nobbc__preg_callback', $message);
// Remove \r's... they're evil!
$message = strtr($message, array("\r" => ''));
// You won't believe this - but too many periods upsets apache it seems!
$message = preg_replace('~\.{100,}~', '...', $message);
$message = str_replace('https://', 'http://', $message);
// Time to do some cool stuff with URL's
if (!$previewing && $modSettings['convert_urls'])
{
// We're gonna save the old socket timeout, reduce it down to 3 seconds, so we prevent this from hanging up
// We are supressing the errors in case the user cannot change this value on their server.
$timeout = ini_get('default_socket_timeout');
@ini_set('default_socket_timeout',3);
$message = preg_replace(array('~(?<=[\s>\.(;\'"]|^)((?:http)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i', '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#+:\'\\\\]*|[\(\{][\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'), array('[url]$1[/url%]', '[url]$1[/url%]'), $message);
// Now we find the urls that we just changed, so we can run through them and get titles
preg_match_all("~\[url\](.+?)\[/url%\]~smi", $message, $urls);
if (!empty($urls[0]))
{
// Lets make a counter so we don't exceed the settings...
$title_counter = 0;
foreach($urls[1] as $uri)
{
// If our counter has exceeded the amount, replace the remaining urls back to what they were and get outta dodge.
if(!empty($modSettings['title_url_count']) && $title_counter++ >= $modSettings['title_url_count'])
{
$message = preg_replace('~\[url\]' . $uri . '\[/url%\]~', $uri, $message);
continue;
}
// Attach http:// to the url...
$uri_modified = strpos($uri, 'http://') === false ? 'http://' . $uri : $uri;
// Use the @ to suppress errors from the function not finding a url, which will still return false if
// there is an error. This just prevents the error log from filling up without cause.
// In 2.0, we have fetch_web_data() which makes our lives easier :)
require_once($sourcedir . '/Subs-Package.php');
$request = @fetch_web_data($uri_modified);
if ($request !== false && preg_match('~<title>(.+?)</title>~smi', $request, $matches))
{
$title = $smcFunc['htmlspecialchars'](stripslashes($matches[1]), ENT_QUOTES);
// Need to fix the &amp;
$title = str_replace('&amp;', '&', $title);
$title = trim($title);
// w00t! Changin the link to titlize it (is that word?)
$message = str_replace('[url]' . $uri . '[/url%]', '[url=' . $uri_modified . ']' . $title . '[/url]', $message);
}
// Looks like we couldn't get the title, darn. Back to the original we go...
else
$message = str_replace('[url]' . $uri . '[/url%]', $uri, $message);
}
}
// Change it back to what it was. Suppress again incase...
@ini_set('default_socket_timeout',$timeout);
}
la parte que he agregado es esta línea:
$message = str_replace('https://', 'http://', $message);
Gracias amigos