Last active
February 25, 2020 14:05
-
-
Save jreviews/e020b6c540edccfc16906a7c6da4455d to your computer and use it in GitHub Desktop.
Insert bitpixels image in listing lists, listings module and listing detail pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('MVC_FRAMEWORK') or die; | |
function bitpixels_thumbnail($listings, $params) | |
{ | |
if ( $params['controller'] == 'com_content' ) | |
{ | |
$listings = [$listings]; | |
} | |
foreach ($listings as &$listing ) | |
{ | |
if ( !S2Array::get($listing,'MainMedia.media_info') ) | |
{ | |
$homepage = S2Array::get($listing,'Field.pairs.jr_homepage.value.0'); | |
if ( $homepage ) | |
{ | |
$listing['Listing']['summary'] .= ' <img src="https://www.bitpixels.com/getthumbnail?code=abc123&size=480&url='.$homepage.'" />'; | |
} | |
} | |
} | |
if ( $params['controller'] == 'com_content' ) | |
{ | |
return $listings[0]; | |
} | |
return $listings; | |
} | |
Clickfwd\Hook\Filter::add('post_get_listings_listpage_query', 'bitpixels_thumbnail', 10); | |
Clickfwd\Hook\Filter::add('post_get_listings_listings_module_query', 'bitpixels_thumbnail', 10); | |
function bitpixels_thumbnail_detail($listing, $params) | |
{ | |
if ( !S2Array::get($listing,'MainMedia.media_info') ) | |
{ | |
$homepage = S2Array::get($listing,'Field.pairs.jr_homepage.value.0'); | |
if ( $homepage ) | |
{ | |
$homepage = 'https://www.bitpixels.com/getthumbnail?code=10536&size=480&url='.$homepage; | |
$listing['MainMedia'] = [ | |
"media_function" => null, | |
"media_type" => "photo", | |
"title" => $listing['Listing']['title'], | |
"media_id" => "1", | |
"main_media" => "1", | |
"likes_up" => "0", | |
"likes_total" => "0", | |
"file_extension" => "jpg", | |
"description" => "", | |
"duration" => "0", | |
"media_info" => [ | |
"image" => [ | |
"format" => "jpg", | |
"width" => 480, | |
"height" => 360, | |
"url" => $homepage, | |
], | |
"thumbnail" => [ | |
"640x460s" => [ | |
"format" => "jpg", | |
"width" => 480, | |
"height" => 360, | |
"url" => $homepage, | |
] | |
], | |
], | |
"metadata" => null, | |
"embed" => "", | |
"published" => "1", | |
"approved" => "1", | |
"access" => "1", | |
"views" => "0", | |
"filesize" => "", | |
"extension" => "com_content", | |
"drive" => "photo", | |
"media_base_url" => $homepage, | |
"media_url" => $homepage, | |
]; | |
} | |
} | |
return $listing; | |
} | |
Clickfwd\Hook\Filter::add('post_get_listing_detailpage_query', 'bitpixels_thumbnail_detail', 10); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The filter allows you to automatically use website thumbnails for your listings based on the website URL entered in a custom field.
To use this filter:
jr_homepage
used for the $homepage variable based on the name of the field you used for the website URL.code
parameter in the image URL to your own code.