1
Zap_English
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?

2
Zap_English
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

3
Zap_English
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 GNU 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; }

4
zyspec
Re: Publisher Random Item Image
  • 2017/5/4 13:06

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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.

5
Zap_English
Re: Publisher Random Item Image

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

6
zyspec
Re: Publisher Random Item Image
  • 2017/5/4 13:45

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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).

7
Zap_English
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

8
zyspec
Re: Publisher Random Item Image
  • 2017/5/4 14:34

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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?

9
Zap_English
Re: Publisher Random Item Image

blocks > items_random_item.php

10
zyspec
Re: Publisher Random Item Image
  • 2017/5/4 15:07

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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/publisher/blob/1.03_RC1/blocks/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.

Login

Who's Online

185 user(s) are online (119 user(s) are browsing Support Forums)


Members: 0


Guests: 185


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits