вставить в iMode картинки в виде прямых ссылок

Автор Alex K, 02 июля 2009, 13:16:42

« назад - далее »

0 Пользователи и 1 гость просматривают эту тему.

Alex K

юзеры свирепствуют и требуют вставить в облегченные версии форума картинки (гы...), если wap версии мне удалось отстоять, то верить в то, что iMode версия не расчитана на отображение картинок верить отказываются. как компромисный вариант - размещать в этой версии не картинку, а прямую ссылку на нее (кому надо - зайдет и посмотрит, а кому нет - сэкономит трафик). собственно понятно, что нужно редактировать "Wireless.template.php", функцию "template_imode_display", нужен кусок кода, который бы:
1. выделял тэг с изображением (картинки частично расположены в виде аттачей, частично - на внешнем хранилище)
2. доставать из картинки ее адрес
3. заменять тэг картинки на адрес
буду благодарен любым предложениям

BIOHAZARD


$wireless_message
= strip_tags(str_replace(array('<div class="quote">', '<div class="code">', '</div>'), '<br />', $message['body']), '<br>');


заменить - картинки () вставляются нормально
$wireless_message = strip_tags(str_replace(array('<div class="quote">', '<div class="code">', '</div>'), '<br />', $message['body']), '<br><img>');


про аттачи надо думать
Мои моды:
  • RedirectPage
  • Counters
  • CustomSearch
  • SypexDumper
   адаптирую темы    1.1.хx<=>2.0задавая вопросы, старайтесь сразу указывать конечную цель, предполагаемый Вами путь не обязательно окажется самым коротким

Любые моды на заказ

BIOHAZARD

воткнул кусок для аттачей, получилось следующее

while ($message = $context['get_message']())
{
// This is a special modification to the post so it will work on phones:
$wireless_message = strip_tags(str_replace(array('<div class="quote">', '<div class="code">', '</div>'), '<br />', $message['body']), '<br><img>');

echo '
<tr><td>'
, $message['first_new'] ? '
<a name="new"></a>'
: '', '
<b>'
, $message['member']['name'], '</b>:<br />
'
, $wireless_message;
// Assuming there are attachments...
if (!empty($message['attachment']))
{
echo '
<hr />'
;
foreach ($message['attachment'] as $attachment)
{
echo '
<a href="'
. $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
}
};
echo '
</td></tr>'
;
}



раньше было:
while ($message = $context['get_message']())
{
// This is a special modification to the post so it will work on phones:
$wireless_message = strip_tags(str_replace(array('<div class="quote">', '<div class="code">', '</div>'), '<br />', $message['body']), '<br>');

echo '
<tr><td>'
, $message['first_new'] ? '
<a name="new"></a>'
: '', '
<b>'
, $message['member']['name'], '</b>:<br />
'
, $wireless_message, '
</td></tr>'
;
}

Мои моды:
  • RedirectPage
  • Counters
  • CustomSearch
  • SypexDumper
   адаптирую темы    1.1.хx<=>2.0задавая вопросы, старайтесь сразу указывать конечную цель, предполагаемый Вами путь не обязательно окажется самым коротким

Любые моды на заказ

BIOHAZARD

Пример:
userjs.org.ru/index.php/topic,29.0/imode.html + следующая страница (можно глянуть оперой)
Мои моды:
  • RedirectPage
  • Counters
  • CustomSearch
  • SypexDumper
   адаптирую темы    1.1.хx<=>2.0задавая вопросы, старайтесь сразу указывать конечную цель, предполагаемый Вами путь не обязательно окажется самым коротким

Любые моды на заказ

Alex K

#4
гм, не вижу ни ссылок, ни картинок...
этот кусок я уже маленько подправил, чтобы визуально выделить цитируемый текст, теперь у меня так:
while ($message = $context['get_message']())
{
     
// This is a special modification to the post so it will work on phones:
     
$wireless_message_q_header = str_replace(array('<div class="quoteheader">','<div class="codeheader">'), '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;', $message['body']);
     
$wireless_message = str_replace(array('<div class="quote">', '<div class="code">'), '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;', $wireless_message_q_header);
     
$wireless_message_div_cut = strip_tags(str_replace('</div>', '<br />', $wireless_message),'<br><img>');
echo '
<tr><td>'
, $message['first_new'] ? '
<a name="new"></a>'
: '', '
<b>'
, $message['member']['name'], '</b>:<br />
'
, $wireless_message_div_cut;
// Assuming there are attachments...
if (!empty($message['attachment']))
{
echo '
<hr />'
;
foreach ($message['attachment'] as $attachment)
{
echo '
<a href="'
. $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
}
};
echo '
                <hr>
            </td></tr>'
;
}

Alex K

#5
попробовал код, все работает, респект )
только немного не так, как хотелось: аттачи выглядят как кликабельные строковые ссылки (что и нужно), а вот сторонние картинки - в виде тех же картинок (а надо в виде таких же ссылок - линков)

а, еще пожелание, чтобы линки на аттачи и внешние картинки мог видеть только зарегистрированный юзер...

BIOHAZARD

while ($message = $context['get_message']())
{
// This is a special modification to the post so it will work on phones:
$wireless_message = preg_replace('/<img src="([^"]+)[^>]*>/i', '<a href="$1">Link to Image</a>', strip_tags(str_replace(array('<div class="quote">', '<div class="code">', '</div>'), '<br />', $message['body']), '<br><img>'));

echo '
<tr><td>'
, $message['first_new'] ? '
<a name="new"></a>'
: '', '
<b>'
, $message['member']['name'], '</b>:<br />
'
, $wireless_message;
// Assuming there are attachments...
if (!empty($message['attachment']))
{
echo '
<hr />'
;
foreach ($message['attachment'] as $attachment)
{
echo '
<a href="'
. $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
}
};
echo '
</td></tr>'
;
}


смотреть всё там же (вторая страница, последнее сообщение)
Мои моды:
  • RedirectPage
  • Counters
  • CustomSearch
  • SypexDumper
   адаптирую темы    1.1.хx<=>2.0задавая вопросы, старайтесь сразу указывать конечную цель, предполагаемый Вами путь не обязательно окажется самым коротким

Любые моды на заказ

Alex K

еще раз спасибо, вроде все работает -)