xoops forums

Zap_English

Quite a regular
Posted on: 5/4 5:25
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#1

Publisher Random Item Image

I thought I saw something here about adding the article image to a random item block but I can't find it again

Does anyone know where it is, or how to do it?

Zap_English

Quite a regular
Posted on: 5/4 7:41
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#2

Re: Publisher Random Item Image

ok, I found it

in items_random_item.php

$mainImage $itemsObj->getMainImage(); // check to see if GD function exist if (!function_exists('imagecreatetruecolor')) { $block['item_image'] = $mainImage['image_path']; } else { $block['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&w=' . $imgwidth; // No $imgheight for autoheight option }


template publisher_items_random_item.html

<img src="<{$block.item_image}>" alt="" width="100" height="100" align="left" style="padding:5px;"/>


Now the big question... I also have coding to display a default image if an item doesn't have an assigned imagefrom this thread

So, how can I get the random item block to show the default image, if an assigned image doesn't exist.

Basically, both bits of code have to be merged

Zap_English

Quite a regular
Posted on: 5/4 8:56
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#3

Re: Publisher Random Item Image

Another question

the file random_item.php is not a large file

where does that code go?

<?php /* You may not change or alter any portion of this comment or credits of supporting developers from this source code or any supporting source code which is considered copyrighted (c) material of the original comment or credit authors. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /** * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ * @license http://www.fsf.org/copyleft/gpl.html& ... public license * @package Beverages * @subpackage Blocks * @since 1.0 * @author trabis <lusopoemas@gmail.com> * @author The SmartFactory <www.smartfactory.ca> */ // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); include_once dirname(__DIR__) . '/include/common.php'; /** * @param $options * * @return array */ function beverages_items_random_item_show($options) { $block = array(); $beverages = BeveragesBeverages::getInstance(); // creating the ITEM object $itemsObj = $beverages->getHandler('item')->getRandomItem('', array(BeveragesConstants::BEVERAGES_STATUS_PUBLISHED)); $mainImage = $itemsObj->getMainImage(); // check to see if GD function exist if (!function_exists('imagecreatetruecolor')) { $block['item_image'] = $mainImage['image_path']; } else { $block['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&amp;w=' . $imgwidth; // No $imgheight for autoheight option } if (!is_object($itemsObj)) { return $block; } $block['content'] = $itemsObj->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available $block['id'] = $itemsObj->itemid(); $block['url'] = $itemsObj->getItemUrl(); $block['title'] = $itemsObj->title(); // irmtfan $block['lang_fullitem'] = _MB_BEVERAGES_FULLITEM; return $block; }

zyspec

Module Developer
Posted on: 5/4 9:06
zyspec
zyspec (Show more)
Module Developer
Posts: 1011
Since: 2004/9/21
#4

Re: Publisher Random Item Image

Quote:

Zap_English wrote:
ok, I found it

in items_random_item.php

$mainImage $itemsObj->getMainImage(); // check to see if GD function exist if (!function_exists('imagecreatetruecolor')) { $block['item_image'] = $mainImage['image_path']; } else { $block['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&amp;w=' . $imgwidth; // No $imgheight for autoheight option }


template publisher_items_random_item.html

<img src="<{$block.item_image}>" alt="" width="100" height="100" align="left" style="padding:5px;"/>


Now the big question... I also have coding to display a default image if an item doesn't have an assigned imagefrom this thread

So, how can I get the random item block to show the default image, if an assigned image doesn't exist.

Basically, both bits of code have to be merged


You can add a check to see if the image is empty and then substitute your default image. Something like:
$mainImage $itemsObj->getMainImage(); // check to see if GD function exist
if (empty($mainImage['image_path'])) {
    
$mainImage['image_path'] = <path_to_your_default_image// this should be something like "publisher/default.jpg"
}
if (!
function_exists('imagecreatetruecolor')) { 
    
$block['item_image'] = $mainImage['image_path']; 
} else { 
    
$block['item_image'] = PUBLISHER_URL '/thumb.php?src=' $mainImage['image_path'] . '&amp;w=' $imgwidth// No $imgheight for autoheight option
}


I believe your default image should be placed in the ./uploads /publisher directory.

Zap_English

Quite a regular
Posted on: 5/4 9:15
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#5

Re: Publisher Random Item Image

ok, where should that code be placed in random_item.php

zyspec

Module Developer
Posted on: 5/4 9:45
zyspec
zyspec (Show more)
Module Developer
Posts: 1011
Since: 2004/9/21
#6

Re: Publisher Random Item Image

I'm not sure exactly which version you're using so I can't give you an exact line number but.... just add the following:
if (empty($mainImage['image_path'])) { 
    
$mainImage['image_path'] = <path_to_your_default_image// this should be something like "publisher/default.jpg"
}


immediately following the line:
$mainImage $itemsObj->getMainImage();


in the items_random_item.php file (from the code you posted above).

Zap_English

Quite a regular
Posted on: 5/4 9:53
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#7

Re: Publisher Random Item Image

unfortunately, that code crashed the index page

it's
XOOPS Version XOOPS 2.5.8.1
PHP Version 7.0.17
mySQL Version 5.5.52-MariaDB

and publisher is

'version' => '1.03',
'module_status' => 'RC 1',
'release_date' => '2016/07/06',

according to the xoops_version.php

zyspec

Module Developer
Posted on: 5/4 10:34
zyspec
zyspec (Show more)
Module Developer
Posts: 1011
Since: 2004/9/21
#8

Re: Publisher Random Item Image

Probably did crash it...

I assumed that when you said the code above came from items_random_item.php that it did, apparently not. Where did the code above come from?

Zap_English

Quite a regular
Posted on: 5/4 10:53
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 337
Since: 2016/5/24
#9

Re: Publisher Random Item Image

blocks > items_random_item.php

zyspec

Module Developer
Posted on: 5/4 11:07
zyspec
zyspec (Show more)
Module Developer
Posts: 1011
Since: 2004/9/21
#10

Re: Publisher Random Item Image

Afraid not... Here's the code from GitHub v1.03 RC1 for ./blocks/items_random_item.php:

getHandler('item')->getRandomItem('', array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED));
    if (!
is_object($itemsObj)) {
        return 
$block;
    }
    
$block['content']       = $itemsObj->getBlockSummary(300true); //show complete summary  but truncate to 300 if only body available
    
$block['id']            = $itemsObj->itemid();
    
$block['url']           = $itemsObj->getItemUrl();
    
$block['lang_fullitem'] = _MB_PUBLISHER_FULLITEM;
    return 
$block;
}


*Edit: You can see it directly here:
https://github.com/XoopsModules25x/pub ... cks/items_random_item.php

You won't find the original code you posted in there anywhere... So you must have gotten that code from somewhere else.