Detectar y reemplazar avatar roto

Started by Cap. Price, January 22, 2010, 05:40:06 PM

Previous topic - Next topic

Cap. Price

IMPORTANTE:Lamentablemente este codigo NO es xhtml transitorio válido.

Es hiper-simple y muy efectivo...

Primero subimos un avatar (el que mas nos guste) a la carpeta donde tenemos nuestros avatares:

(debería quedar así):
avatars/blank.gif

es decir (por si no queda claro):
http://www.misitio.com/avatars/blank.gif

Es MUY importante que el nombre sea blank.gif y NO OTRO... a menos que cambien el codigo que les voy a dejar.

En Subs.php:
Buscamos:
$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '"' . (isset($context['user']['avatar']['width']) ? ' width="' . $context['user']['avatar']['width'] . '"' : '') . (isset($context['user']['avatar']['height']) ? ' height="' . $context['user']['avatar']['height'] . '"' : '') . ' alt="" class="avatar" border="0" />';

Reemplazamos por:
$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '"' . (isset($context['user']['avatar']['width']) ? ' width="' . $context['user']['avatar']['width'] . '"' : '') . (isset($context['user']['avatar']['height']) ? ' height="' . $context['user']['avatar']['height'] . '"' : '') . ' alt="" class="avatar" border="0" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/blank.gif\';" />';

En Load.php:
Buscamos:
'image' => $profile['avatar'] == '' ? ($profile['ID_ATTACH'] > 0 ? '<img src="' . (empty($profile['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $profile['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" class="avatar" border="0" />'),

Reemplazamos por:
'image' => $profile['avatar'] == '' ? ($profile['ID_ATTACH'] > 0 ? '<img src="' . (empty($profile['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $profile['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" class="avatar" border="0" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/blank.gif\';" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/blank.gif\';" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" class="avatar" border="0" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/blank.gif\';" />'),

Lesto... cuando un avatar no se cargue por algún motivo entonces va entrar en acción Chuck Norris, porque dicen que destrás del avatar de Chuck hay un puño (aparte del que tiene debajo de la barba).

¡Gort! ¡Klaatu barada nikto!

mafia7

muestra imagenes para ver que esplica amigo

Arkangel

Quote from: mafia7 on January 22, 2010, 09:27:34 PM
muestra imagenes para ver que esplica amigo

bueno segu lo k entendi esta modifikacion lo k realiza es por ejemplo si un usuario tiene un avatar o la url de este y por algun motivo no carga ya sea quizas murio link etc.. este saldra una imagen x defecto el cual se configuro antes .. si me ekivoco corriganme.. saludos muy buen tip...

dusst

Uhm intente esto y no encontraba los codigos, revise detalladamente y lo pude hacer funcionar, pero en este caso mi imagen es "avatar.png", en la misma ubicacion, la carpeta "avatars" del foro.

version del foro 2.0.7

sub.php
encontrar

$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '"' . (isset($context['user']['avatar']['width']) ? ' width="' . $context['user']['avatar']['width'] . '"' : '') . (isset($context['user']['avatar']['height']) ? ' height="' . $context['user']['avatar']['height'] . '"' : '') . ' alt="" class="avatar" />';


reemplazar
$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '"' . (isset($context['user']['avatar']['width']) ? ' width="' . $context['user']['avatar']['width'] . '"' : '') . (isset($context['user']['avatar']['height']) ? ' height="' . $context['user']['avatar']['height'] . '"' : '') . ' alt="" class="avatar" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/avatar.png\';" />';


load.php
encontrar
'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="" />'),


reemplazar
'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="" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/avatar.png\';" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/avatar.png\';" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" onerror="this.onerror=null;this.src=\'' . $modSettings['avatar_url'] . '/avatar.png\';" />'),
SMF 2.1 RC3

dusst

y si quiero usar una imagen en otra ubicacion como hago???
SMF 2.1 RC3

Patrick D

Quote from: dusst on June 16, 2014, 12:57:24 AM
y si quiero usar una imagen en otra ubicacion como hago???

Supongo que cambiarías esto:
' . $modSettings['avatar_url'] . '/avatar.png

por lo que quisieras, ej:
'.$boarddir.'/avatar_en_carpeta_raiz.png o http://imgur.com/imagen.png

Advertisement: