getImageBlock vs getBlock

Rash

Joined: 2006-03-04
Posts: 54
Posted: Sun, 2008-11-16 23:21

Seeing as how the getImageBlock function of the embed API is being depreciated, I thought I'd see about switching over some of the code in the e107 bridge plugin to use getBlock. Saddly, the person who did the bulk of the coding on the plugin has gone perminantly AWOL, and I'm not much of a coder, just the guy trying to keep the project from dieing... so I'm having a bit of trouble.

First, our existing code to display a random image in a side menu kind of thing (example here:

if (!defined('e107_INIT')) { exit; }

// the common gallery tasks are now in functions.php
require_once(e_PLUGIN."gallery2/functions.php");

// Load configured values from db
g2_LoadConfig();

// Initialize gallery2 embedding
$ret = g2_Init(true);

list ($ret, $imageBlockHtml) = GalleryEmbed::getImageBlock( array(
    'blocks'  => 'randomImage',
    'show'    => 'title',
    'maxSize' => 170));
    
if ($ret)
{
  if (($ret->getErrorCode() & ERROR_CONFIGURATION_REQUIRED) > 0)
    $imageBlockHtml = G2_LAN_ERROR_ACTIVATE_BLOCK;
  else
  {
    $imageBlockHtml = G2_LAN_ERROR_GET_IMAGE_BLOCK.
    'ErrorCode: '.$ret->getErrorCode().'<BR>'.
    'ErrorMessage: '.$ret->getErrorMessage().'<BR>';
  }
}

$text     = "<div class='randomimage' style='text-align:center'>".$imageBlockHtml."</div>";
$caption  = G2_LAN_RANDOM_HEAD;

$ns->tablerender($caption, $text, 'g2random_photo');

g2_Close();

?>

since getBlock does things a little bit different, I'm not sure I've got this right (and the results from my tests say I havn't ;) ).

<...snip...>
list ($ret, $imageBlockHtml) = GalleryEmbed::getBlock(ImageBlock, randomImage, array(
    'show'    => 'title',
    'maxSize' => 170));
    
if ($ret)
{
  if (($ret->getErrorCode() & ERROR_CONFIGURATION_REQUIRED) > 0)
    $imageBlockHtml = G2_LAN_ERROR_ACTIVATE_BLOCK;
  else
  {
    $imageBlockHtml = G2_LAN_ERROR_GET_IMAGE_BLOCK.
    'ErrorCode: '.$ret->getErrorCode().'<BR>'.
    'ErrorMessage: '.$ret->getErrorMessage().'<BR>';
  }
<...snip...>

Doesn't seem to return much...

Also, slightly related: could one hypothetically use the getBlock function to display the Gallery2 sidebar? I've seen a few methods in the forums for pulling the sidebar information out of the gallery2 page, just was wondering if you could do it this way "easier".

Thanks for any insight.

 
gasmasher

Joined: 2008-12-02
Posts: 2
Posted: Wed, 2008-12-03 04:35

I took a look at GalleryEmbed.class for getImageBlock and it calls getBlock like this

    function getImageBlock($params) {
        return GalleryEmbed::getBlock('imageblock', 'ImageBlock', $params);
    }

This basically means that when you called getImageBlock in the old version of your code and pass in an array it just calls getBlock and sets the first two params to 'imageblock' and 'ImageBlock' and the third param is exactly what you pass to getImageBlock.

Try replacing your line

list ($ret, $imageBlockHtml) = GalleryEmbed::getBlock(ImageBlock, randomImage, array(
    'show'    => 'title',
    'maxSize' => 170));

with this

list ($ret, $imageBlockHtml) = GalleryEmbed::getBlock('imageblock', 'ImageBlock', array(
    'blocks' => 'randomImage', 'show' => 'title', 'maxSize' => 170));

imageblock is the module
ImageBlock is what you want
randomImage is the block type that you want

 
Rash

Joined: 2006-03-04
Posts: 54
Posted: Wed, 2008-12-03 12:59

thanks for the reply! I think one of my failed attempts was pretty close to what you've posted... probably missing some vital punctuation. ;) I appreciate you explaining it clearly.

I'll give it a shot and see what happens. Though, with the G3 announceent, I'm not so sure it's vital to upgrade the existing plugin anymore, if it's all going to have to change for G3 anyways...

thanks again for the explaination!