11
Zap_English
Re: Publisher Random Item Image

/*
 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 
 * @author          The SmartFactory 
 */

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

12
zyspec
Re: Publisher Random Item Image
  • 2017/5/4 17:03

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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.

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

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

15
zyspec
Re: Publisher Random Item Image
  • 2017/5/5 16:54

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


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

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

17
trabis
Re: Publisher Random Item Image
  • 2017/5/6 11:44

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Perhaps a typo:

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


Should be:

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

18
zyspec
Re: Publisher Random Item Image
  • 2017/5/6 12:43

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


Sorry @Zap_English

Thanks @Trabis....

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

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

Login

Who's Online

168 user(s) are online (128 user(s) are browsing Support Forums)


Members: 0


Guests: 168


more...

Donat-O-Meter

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

Latest GitHub Commits