xoops forums

Zap_English

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

Re: Publisher Random Item Image

<?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));


    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['title']            = $itemsObj->title(); // irmtfan
    
$block['lang_fullitem'] = _MB_BEVERAGES_FULLITEM;

    return 
$block;
}


directly from the file

zyspec

Module Developer
Posted on: 5/4 17:03
zyspec
zyspec (Show more)
Module Developer
Posts: 1016
Since: 2004/9/21
#12

Re: Publisher Random Item Image

Two (2) things...

1. The original code you posted isn't anywhere in the copy of the file you just sent, so I'm still confused.
2. beverages_items_random_item_show isn't a standard part of the publisher module so I'm not sure where you got it. Perhaps you should go back to the person that modified the code and see if they can help you figure it out.

Zap_English

Quite a regular
Posted on: 5/4 17:12
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#13

Re: Publisher Random Item Image

it's a cloned publisher. that's why the name is different

forget the first code. i must have cut n pasted the wrong code

Zap_English

Quite a regular
Posted on: 5/5 14:28
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#14

Re: Publisher Random Item Image

So where do I stick to code in the items_random_item.php file? Everywhere I've tried to insert it crashes the index page

zyspec

Module Developer
Posted on: 5/5 16:54
zyspec
zyspec (Show more)
Module Developer
Posts: 1016
Since: 2004/9/21
#15

Re: Publisher Random Item Image

@Zap_English,

Unfortunately it's a little more complex than just adding anything that's been previously posted in this thread. The random item block does not currently display the main item image, just the item itself.

Let me state: I have not tried any of the following code, I don't have the module currently loaded on my test site and I'm sorry but I don't have time right now to go try/test this. So anything you see/use below is "at your own risk"... Before you try this code I'd recommend you go to your XOOPS Admin > Preferences > System Options > General Settings and set Debug Mode to Enable debug (inline mode).

Basically what needs to happen is that in ./blocks/items_random_item.php you will need to get the item's main image thumbnail, if it doesn't exist then substitute you're default image. Then in the ./templates/blocks/publisher_items_random_item.tpl you will need to display the image.

The publisher_items_random_item_show() function in ./blocks/items_random_item.php should look something like:
/**
 * @param $options
 *
 * @return array
 */
function publisher_items_random_item_show($options)
{
    
$block     = array();
    
$publisher PublisherPublisher::getInstance();
    
// creating the ITEM object
    
$itemsObj $publisher->getHandler('item')->getRandomItem('', array(PublisherConstants::PUBLISHER_STATUS_PUBLISHED));
    if (!
is_object($itemsObj)) {
        return 
$block;
    }
    
$mainImage $itemsObj->getMainImage();
    if (empty(
$mainImage['image_thumb'])) {
        
// the  in the following line path_to_your_default_image_thumbnail should be something 
        // like XOOPS_UPLOADS_URL . "publisher/default_thumbnail.jpg"
        
$mainImage['image_thumb'] = {path_to_your_default_image_thumbnail};
    } 
    
$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['title']         = $itemsObj->title(); // irmtfan
    
$block['lang_fullitem'] = _MB_PUBLISHER_FULLITEM;
    
$block['item_thumb']    = $mainImage['item_thumb'];
    return 
$block;
}


Now, provided you're using the standard templates (i.e. they haven't been modified) you should be able to use the following in your ./templates/blocks/publisher_items_random_item.tpl file:
<{$block.content}><br><br>
<
br class="clear">
<
div class="floatleft">
    <
img class="pad3" src="<{$block.item_thumb}>" alt="" title="<{$block['title']}>">
</
div>
<
div align="right">
    <
a href='<{$block.url}>'><{$block.lang_fullitem}></a>
</
div>

Zap_English

Quite a regular
Posted on: 5/6 8:15
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#16

Re: Publisher Random Item Image

unfortunately, that code didn't do anything except remove the highlighting from the "Read the complete article" link

The original code from my second post worked, except it didn't show the default image if no image was available in the article.

The articles have been modified to show our logo if there is no attached image

trabis

Core Developer
Posted on: 5/6 11:44
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#17

Re: Publisher Random Item Image

Perhaps a typo:

$block 'item_thumb' ] = $mainImage ['item_thumb' ];


Should be:

$block 'item_thumb' ] = $mainImage ['image_thumb' ];

zyspec

Module Developer
Posted on: 5/6 12:43
zyspec
zyspec (Show more)
Module Developer
Posts: 1016
Since: 2004/9/21
#18

Re: Publisher Random Item Image

Sorry @Zap_English

Thanks @Trabis....

Zap_English

Quite a regular
Posted on: 5/6 12:58
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#19

Re: Publisher Random Item Image

Error : Smarty error: [in db:recipes_items_random_item.tpl line 5]: syntax error: unrecognized tag: $block['title'] (Smarty_Compiler.class.php, line 446)

Zap_English

Quite a regular
Posted on: 5/6 13:12
Zap_English
Zap_English (Show more)
Quite a regular
Posts: 343
Since: 2016/5/24
#20

Re: Publisher Random Item Image

Quote:

Zap_English wrote:
Error : Smarty error: [in db:recipes_items_random_item.tpl line 5]: syntax error: unrecognized tag: $block['title'] (Smarty_Compiler.class.php, line 446)


that problem was $block['title'] should be $block.title

but there;s still a problem. My default image is a moving GIF and I thought that might be a problem so I created a 94x94 thumb.jpg and designated that as the image in $mainImage['image_thumb'] =

If the article does NOT have an image, it shows the thumb.jpg in the random item block

BUT

If the articles DOES have an image, it shows both the article image AND the thumb.jpg in the random item block, and the article image is now full sized and is no longer a thumb

The original code I posted in post #2 does work, it shows the articles attached image as a thumb. But if there is no image it shows as a missing image. Can't the original code from #2 be modified with an IF to show the default if an image isn't attached to the article?