News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Ayuda URL en avatar

Started by fran46, July 22, 2015, 05:05:11 AM

Previous topic - Next topic

fran46

NOTA:
He intentado postear aquí mi problema... pero me ha sido imposible porque al enviar el post me salta el siguiente error:
QuoteSorry, you are not allowed to post external links.

No puedo explicar mi problema sin poner URLS.... ya que hay muchas referencias e imagenes.
Por lo tanto, he publicado aqui mi problema: hxxp:forosdelweb.com/f18/error-imagen-foro-smf-1133105/#post4728492 [nonactive]
Espero que no sea una molestia leerlo alli y responderme aqui :/

Muchas gracias

Gluz

#1
QuoteHola!
De antemano agradecerte que te hayas tomado la molestia de abrir este tema y empezar a leer ^^

Antes de contarte mi problema, haré una pequeña introducción:

Estoy creando un foro SMF, en el cual únicamente quiero que los usuarios inicien sesión con su cuenta de Steam. (para quien no conozca Steam, es una plataforma de videojuegos http://steamcommunity.com/ )

Mi foro es el siguiente: http://www.csgo.com.es/foro/
Si se fijan en la parte superior derecha esta el enlace para iniciar sesión desde Steam. Para hacer todo esto.... he usado el siguiente plugin: https://github.com/live627/smf-steam-auth/

Ahora bien... Mi problema es que a la hora de mostrar el avatar del usuario, no se muestra bien debido a que se añade antes de la URL a la imagen la url del foro.

Un ejemplo:
Fijate en esta imagen: http://gyazo.com/1b2ba73a96e692c6a00e739eda0cc381
Como puedes ver en la parte superior derecha de la pantalla, la imagen esta "rota". Esto es, porque como podran ver mas abajo de la captura, la URL de la imagen es:
http://csgo.com.es/foro/avatars/http...fd9_medium.jpg
Cuando solo deberia ser:
https://steamcdn-a.akamaihd.net/stea...fd9_medium.jpg

¿como quito la dichosa URL que se muestra antes del avatar?

MAS INFO:

- En base de datos (tabla members) se guarda la URL a la imagen correctamente: http://gyazo.com/e5d87183940bfadca74f91db205181cb

- Una "casi solución" para este problema es editar el archivo index.template.php cambiando esta linea:
echo '<img src="', $context['user']['avatar']['href'], '" class="avatar img-circle img-thumbnail" alt="*" />';


Por esta otra:
echo '<img src="', substr($context['user']['avatar']['href'],32), '" class="avatar img-circle img-thumbnail" alt="*" />';

http://gyazo.com/8f95738e7b9700cb05b0f42e5898ad8f
El problema es que esta solución solo me sirve para esta imagen... pero hay otros sitios del foro donde sale el avatar (por ejemplo al crear un post) y en estos sitios también se añade la URL del foro antes de la URL de la imagen.

- En Github, en la pagina del plugin, hay una incidencia (ya cerrada) https://github.com/live627/smf-steam-auth/issues/1 en donde un usuario dice que lo soluciono asi:
(pego el texto original en ingles)
QuoteAlright so after some digging I was able to finally fix this. This may not be the right or best solution but it did the trick for me.

In both load.php and portalblocks.php there are numerous pieces of code dealing with avatars that looks like this:

'<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar'])

What fixed it for me was removing the / from the middle in every instance. With the slash being there, it kept trying to load the avatar from my domain in front of the steamcdn server which in turn broke the url. Removing this slash makes the url work correctly. I'm not sure how many of the /'s I should have removed but I just took them all out and the avatars are loading up everywhere without issue. Hope this helps somebody.
Sin embargo, he tratado de hacer eso y no me ha funcionado.

Muchas gracias!


Viendo que en la base de datos se agrega bien la URL entonces es un problema de SMF que las URLs para avatares externos solo soporta http:// y no https:// ya que en las partes que se carga el avatar solo tiene comprobación para http:// y para arreglar eso hay que hacer que use comprobación para https://

Revisé el foro y hay un hilo en inglés donde mencionan este error, que para SMF 2.1 ya lo resolvieron, pero en la rama 2.0.x no, pero aquí está la solución:

En /Sources/Load.php buscar:
'avatar' => array(
'name' => $profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
),


y sustituir por:
'avatar' => array(
'name' => $profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : ((stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : ((stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
'url' => $profile['avatar'] == '' ? '' : ((stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
),



Y en /Sources/Subs.php buscar:
elseif (substr($user_info['avatar']['url'], 0, 7) == 'http://')

y reemplazar por:
elseif (substr($user_info['avatar']['url'], 0, 7) == 'http://' || substr($user_info['avatar']['url'], 0, 8) == 'https://')

Aunque creo que hay algunas partes como el perfil que puedan no cargar el avatar, pero eso ya no se muy bien, pues el mod que hize para un avatar por defecto funciona solo modificando esas 2 partes, pero si quieres echarle un vistazo a que mas podría requerir cambios visita la página del Github de SMF donde muestran esos cambios: https://github.com/Arantor/SMF2.1/commit/b3d25d972c8ae399a7bd5976f31c1ca819628b6e

Advertisement: