Jump to content

IP Content Block- get images from topic


HSlammer

Recommended Posts

I am attempting to create a featured topic block that includes the first image in the topic, and below that a snippet of the text in the original post.  I have the text portion figured out but I have run into a snag finding and getting the first image in the post, seems it cannot resolve images using the Image Proxy?  So I get images with regular urls they show up - but images served by the image proxy return no image.

 

<div>
{{preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $topic->content()|raw, $matches);}}
{{$first_img = $matches [1] [0];}}
<img alt="{$topic->title}" title="{$topic->title}" src="{$first_img}"/>  
</div>

This is the portion of the block that I need help with to resolve images served up by the proxy.

 

and the code for the entire block

 

{{if !empty( $topics ) }}
	<h3 class='ipsWidget_title ipsType_reset'>{$title}</h3>

		<div class='ipsPad_half ipsWidget_inner'>
			<ul class='ipsDataList ipsDataList_reducedSpacing'>
				{{foreach $topics as $topic}}
					<li class='ipsDataItem{{if $topic->unread()}} ipsDataItem_unread{{endif}}{{if $topic->hidden()}} ipsModerated{{endif}}'>
						<div class='ipsDataItem_icon ipsPos_top'>
							{template="userPhoto" group="global" app="core" params="$topic->author(), 'tiny'"}
						</div>
						<div class='ipsDataItem_main cWidgetComments'>
							<div class="ipsCommentCount ipsPos_right {{if ( $topic->posts - 1 ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$topic->posts - 1"}'>{expression="$topic->posts - 1"}</div>
							
							<div class='ipsType_break ipsContained'>
								{{if $topic->mapped('featured') || $topic->hidden() === -1 || $topic->hidden() === 1}}
									{{if $topic->hidden() === -1}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{$topic->hiddenBlurb()}'><i class='fa fa-eye-slash'></i></span></span>
									{{elseif $topic->hidden() === 1}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{lang="pending_approval"}'><i class='fa fa-warning'></i></span></span>
									{{endif}}
									{{if $topic->mapped('featured')}}
										<span><span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_positive" data-ipsTooltip title='{lang="featured"}'><i class='fa fa-star'></i></span></span>
									{{endif}}
								{{endif}}							
								<a href="{$topic->url()->setQueryString( 'do', 'getNewComment' )}" title='{lang="view_this_topic" sprintf="$topic->title"}' class='ipsDataItem_title'>{$topic->title}</a>
							</div>
							<p class='ipsType_reset ipsType_medium ipsType_blendLinks'>
								<span>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span><br>
								<span class='ipsType_light'>{lang="topic_started_date" htmlsprintf="\IPS\DateTime::ts( $topic->mapped('date') )->html()"}</span>
							</p>
                      </div>
<div>
{{preg_match_all('/src="([^"]*)"/i', $topic->content()|raw, $matches);}}
{{$first_img = $matches [1] [0];}}
<img alt="{$topic->title}" title="{$topic->title}" src="{$first_img}"/>  
</div>
			<div class='ipsType_medium ipsType_richText ipsContained {{if $type != 'search'}}ipsSpacer_both{{else}}ipsSpacer_bottom{{endif}} ipsSpacer_half' data-ipsTruncate data-ipsTruncate-size='8 lines' data-ipsTruncate-type='remove'>
				{$topic->truncated()|raw}
			</div>
					</li>
				{{endforeach}}
			</ul>
		</div>
	
{{endif}}

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...