Skip to content

Instantly share code, notes, and snippets.

@jreviews
Last active February 25, 2020 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jreviews/e020b6c540edccfc16906a7c6da4455d to your computer and use it in GitHub Desktop.
Save jreviews/e020b6c540edccfc16906a7c6da4455d to your computer and use it in GitHub Desktop.
Insert bitpixels image in listing lists, listings module and listing detail pages.
<?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);
@jreviews
Copy link
Author

jreviews commented Feb 25, 2020

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:

  1. Upload the above file to jreviews_overrides/filters
  2. Add the line below to jreviews_overrides/filter_functions.php, if you are not using filters yet, read the documentation on Getting Started with JReviews developer filters
require_once "bitpixels_image.php";
  1. Adjust the fieldname jr_homepage used for the $homepage variable based on the name of the field you used for the website URL.
  2. Change the code parameter in the image URL to your own code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment