Advertisement:

Author Topic: Call first image of news on SSI boardnews..  (Read 24446 times)

Offline Özgür

  • SMF Hero
  • ******
  • Posts: 3,924
  • Gender: Male
  • Özgür | jQuery Lover
    • ozgurce on Facebook
    • @ozgurce on Twitter
    • Özgür Yalçın
Call first image of news on SSI boardnews..
« on: September 17, 2009, 09:37:16 PM »
I search this in sm.org. But i can't find out. But now, after i learning to regex, this is very easy and useful.

If you don't have any idea for this look at that picture. This is we're final results.


http://img44.imageshack.us/img44/5540/71532501.png
As you see, i find first image for post and showed floating left of news text. I work on boardnews function on smf 2.0.

Her you go..

 Find in SSI.php
 
Code: [Select]
function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
 {
This is we're function. All changes, should in that function.

Find on that function
 
Code: [Select]
        // Check that this message icon is there...
         if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
             $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

Add After
 
Code: [Select]
            // search <img> in $row['body']
   $find = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $row['body'], $value);
   // find src="" value.
 if(!empty($value[0]) && !empty($value[1]))
   $first_image = $value [1] [0];
 
  else{ // if message don't have picture, just show it default image
     $first_image = "http://www.site.com/images/default.jpg";
   }
 

Find
 
Code: [Select]
'subject' => $row['subject'],Add After
 
Code: [Select]
'image' => $first_image,
So function completed. But we not include image in news.
Now we can add in it..
 
 Find
 
Code: [Select]
    foreach ($return as $news)
     {
         echo '
             <div>
                 <a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
                 <div class="smaller">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '</div>
 
                 <div class="post" style="padding: 2ex 0;">', $news['body'], '</div>
 
                 ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
             </div>';
 
         if (!$news['is_last'])
             echo '
             <hr style="margin: 2ex 0;" width="100%" />';
     }

Replace for this
 
Code: [Select]
foreach ($return as $news)
     {
         echo '
             <div>
                 <a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
                 <div class="smaller">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '</div>
 
                 <div class="post" style="padding: 2ex 0;"><div class="image_border">
                 
                 <img src="', $news['image'], '" alt="', $news['subject'], '" class="news_image" /></div>
                 
                 ', $news['body'], '</div>
 
                 ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
             </div>';
 
         if (!$news['is_last'])
             echo '
             <hr style="margin: 2ex 0;" width="100%" />';
     }
But image and text didn't styled. And not seems like cool..  I already add class="" prority to image

Add that styles in where you used that function.
 
 
Code: [Select]
.image_border
 {
 float:left;
 background:#ddd;
 border:1px solid #ccc;}
 
 .news_image{
 width:150px;
 height:150px;
 padding:5px;
 margin:3px;
 }
 
Yeah cool now. But image called twice. And if news text centered or aligned to left,  displaying corrupted.
 
I use my strip tags on the news text
 
Add this to SSI.php last line (befor ?>)
 
Code: [Select]
function temizle($haber) {
     $strs=explode('<',$haber);
     $res=$strs[0];
     for($i=1;$i<count($strs);$i++)
     {
         if(!strpos($strs[$i],'>'))
             $res = $res.'&lt;'.$strs[$i];
         else
             $res = $res.'<'.$strs[$i];
     }
     return strip_tags($res);   
 }

And replace to news body.
Find
 
Code: [Select]
  ', $news['body'], '</div>
Replace
 
Code: [Select]
  ', temizle($news['body']), '</div>
And final...
- Daydreamer
« Last Edit: September 20, 2009, 01:17:55 PM by [Daydreamer] »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,123
    • StoryBB/StoryBB on GitHub
Re: Call first image of news on SSI boardnews..
« Reply #1 on: September 20, 2009, 01:01:19 PM »
Nice work! I'll move this to Tips & Tricks since that's really what it is.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

Nothing turns to hate so bitter as what once was love.

Offline Googgig

  • Newbie
  • *
  • Posts: 3
Re: Call first image of news on SSI boardnews..
« Reply #2 on: October 08, 2009, 09:25:54 PM »
Thank you for this code. It's work!
Anyway I have a little problem. If the topic has smiley its will call smiley to the first. No matter there are 3-4 images before smiley, it will show smiley first.

Offline Özgür

  • SMF Hero
  • ******
  • Posts: 3,924
  • Gender: Male
  • Özgür | jQuery Lover
    • ozgurce on Facebook
    • @ozgurce on Twitter
    • Özgür Yalçın
Re: Call first image of news on SSI boardnews..
« Reply #3 on: October 09, 2009, 01:45:03 AM »
Hmm. I will look today afternoon, i'm still busy on my profile song mod sorry.

Offline Alpay

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 3,604
  • Gender: Male
  • test
    • Personal Web Page
Re: Call first image of news on SSI boardnews..
« Reply #4 on: June 05, 2011, 01:27:42 PM »
Thank you Özgür. Goooood Work..

Offline MyTime

  • Jr. Member
  • **
  • Posts: 135
  • Do you remember that guy who quit?
    • The CannabisGamerClub
Re: Call first image of news on SSI boardnews..
« Reply #5 on: November 23, 2014, 03:21:08 PM »
Could someone explain what exactly this does? I think it's something I might be interested in, with adding an image too an article in a block

Offline Xpresskonami

  • Jr. Member
  • **
  • Posts: 205
  • Gender: Male
    • @spyloaded_com on Twitter
Re: Call first image of news on SSI boardnews..
« Reply #6 on: August 24, 2017, 07:52:43 PM »
not working for me, any solution
Spyloadedng