PDA

View Full Version : Find First Image or Attachment and replace it with Avatar


devoidfeast
09-10-2014, 04:04 PM
Hello Fellows,
I am trying to customize the "Search Widget" where i am replacing the user avatar with a thumbnail.the thumbnail is to be generated from any video or images attached to the post.i am able to write an api call which gets the thumbnail from any video attached but i am still not successful to do it for images and attachment.

{vb:data thumbnail, content_video, getVideoThumbnail, {vb:raw url}}
<vb:if condition="isset($thumbnail) AND $thumbnail">
<img src="{vb:raw thumbnail}" alt=""
<vb:if condition="isset($height) AND $height > 0"> height="{vb:raw height}"</vb:if>
<vb:if condition="isset($width) AND $width > 0"> width="{vb:raw width}"</vb:if>
/>
</vb:if>

getVideoThumbnail(url) is method i found in the "core/vb/api/content/video.php". i was successfully able to get the thumbnail from and video embeded.


Now i want to do some thing like the video with photos or [IMG] tag i found a method in the
"core/vb/api/content/text.php"
function autoPopulatePreviewImage($nodeId)

this function can reads all the post and search for images in it and populate the following array
$data = array(
'parentid' => $node['parentid'],
'previewimage' => $attachment['nodeid'],
'nodeoptions' => $node['nodeoptions'],
);



How can i call the above api function from a template?

Thank You.

Dead Eddie
09-10-2014, 04:55 PM
{vb:data thumbnail, content_text, autoPopulatePreviewImage, {vb:raw nodeid}}

The nodeid variable would depend on what variable is in scope for the template you're using.

devoidfeast
09-10-2014, 05:10 PM
i will call it in "display_contenttype_searchwidget_item_header" template.

{vb:data thumbnail, content_text, autoPopulatePreviewImage, {vb:raw conversation.nodeid}}

--------------- Added 1410373793 at 1410373793 ---------------

thumbnail variable will contain an array?? because autoPopulatePreviewImage() populate an array "data" which contain a possible address to the preview image.after calling the function as follow.
{vb:data thumbnail, content_text, autoPopulatePreviewImage, {vb:raw conversation.nodeid}}

<img src="{vb:raw thumbnail}" width="32" height="32" alt="{vb:raw conversation.authorname}" />
Now i just get on the avatar the name of the user with image missing.

am i using the thumnail variable wrong?

Dead Eddie
09-10-2014, 06:34 PM
Sorry, don't have access to the vbulletin source code right now.

Does autoPopulatePreviewImage actually return the array? Or does it use it internally?

If you want to see what's in the variable, you can use:

{vb:debugvardump thumbnail}

--------------- Added 1410389539 at 1410389539 ---------------

$data isn't returned from the function, so you can't use it to do what you want it to do.

devoidfeast
09-10-2014, 09:53 PM
the "autoPopulatePreviewImage()" in the api calls to "autoPopulatePreviewImage()" of library
public function autoPopulatePreviewImage($nodeId)
{
$data = $this->library->getFullContent($nodeId);
if ($this->validate($data, self::ACTION_UPDATE, $nodeId))
{
$this->library->autoPopulatePreviewImage($nodeId);
}
}

the "autoPopulatePreviewImage()" in the Library does not return anything it also destroys all the variables the only array left ath the end is the following but its not returned.
$data = array(
'parentid' => $node['parentid'],
'previewimage' => $attachment['nodeid'],
'nodeoptions' => $node['nodeoptions'],
);



if let say at the end i add a line return $data how will i be able to access "$data['previewimage'] " from template page.

thank you

Dead Eddie
09-10-2014, 10:22 PM
{vb:raw thumbnail.previewimage}

devoidfeast
09-10-2014, 10:43 PM
great Work. Mr Eddie.
Thank you