solucion
  • 0
  • 4 RepliesReplies
  • 5432 ReadTimes Read
  • 0 PointsPoints

Topic: ¿Cómo cambiar las urls https por http?

Usuario: Príncipe_Azul
Rango: Nuevo Usuario
Mensajes: 294
Points: 12
Perfil: View Profile
Pais:
ar
¿Cómo cambiar las urls https por http?
March 04, 2016 - 11:47 23:47
¿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:

Code: [Select]
$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:

Code: [Select]
$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:

Code: [Select]
// Attach http:// to the url...
$uri_modified = strpos($uri, 'http://') === false ? 'http://' . $uri : $uri;

por esta:

Code: [Select]
// 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:

Code: [Select]
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('~&amp;#(\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;amp;
$title = str_replace('&amp;amp;', '&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:

Code: [Select]
    $message = str_replace('https://', 'http://', $message);

Gracias amigos :)
Usuario: Príncipe_Azul
Rango: Nuevo Usuario
Mensajes: 294
Points: 12
Perfil: View Profile
Pais:
ar
Re:¿Cómo cambiar las urls https por http?
Reply #1 March 18, 2016 - 12:35 00:35
Hola amigos!!!

He conseguido la solución, me ha ayudado Suki en su foro, así que aquí la comparto para que a otras personas les sirva y para dar este tema como Solucionado.
En el archivo Sources/Subs-Post.php deben buscar esta línea:

Code: [Select]
$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);
y reemplazarla por esta:

Code: [Select]
$message = preg_replace(array('~(?<=[\s>\.(;\'"]|^)((?: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 buscar esta otra línea:

Code: [Select]
$uri_modified = strpos($uri, 'http://') === false ? 'http://' . $uri : $uri;
y reemplazarla por esta:

Code: [Select]
$uri_modified = (strpos($uri, 'http://') === false && strpos($uri, 'https://') === false) ? 'http://' . $uri : $uri;
Con ese cambio, el mod ya trabajará con enlaces seguros.


Saludos y gracias!! :) :)


Fuente: http://missallsunday.com/soporte_en_espanol/ccambiar_las_urls_https_por_http_725.0.html
Usuario: Papá distante
Rango: Moderador Global
Mensajes: 3504
Points: 168
Perfil: View Profile
Pais:
de
Re:¿Cómo cambiar las urls https por http?
Reply #2 March 18, 2016 - 06:04 06:04
(YYY)
Usuario: 4kstore
Rango: Moderador Global
Mensajes: 4916
Points: 8111
Mi web: http://www.smfsimple.com
Perfil: View Profile
Pais:
ar
Re:¿Cómo cambiar las urls https por http?
Reply #3 March 18, 2016 - 07:25 07:25
gracias por dejar la respuestaaaa!
Usuario: Príncipe_Azul
Rango: Nuevo Usuario
Mensajes: 294
Points: 12
Perfil: View Profile
Pais:
ar
Re:¿Cómo cambiar las urls https por http?
Reply #4 March 18, 2016 - 11:45 23:45
De nada amigos :) :)

Un abrazo!!
 

TAGS



top

Smfsimple.com es un sitio destinado a brindar un servicio de soporte y herramientas para foros realizados con el sistema de foros gratuito simplemachines.org. Contamos con un selecto equipo de desarrolladores y conocedores del sistema, sus foros estaran en buenas manos.
This site is not affiliated with or endorsed by Simple Machines