Drupal & Gallery2 Embed PHP Example

Error: wrong permissions to fetch g2 URL or HTML document returned
video 7912

Enter this php code into your page or story once (even paste it into a file and include('filename'); it.
<?php
function g2embed_fetchlink($_g2link, &$_g2fgc)
{
  if (
$_COOKIE['GALLERYSID'] && preg_match('/^(?!TMP_SESSION)/'$_COOKIE['GALLERYSID']))
  {
    
$_g2cs 'Cookie: GALLERYSID='.$_COOKIE['GALLERYSID'].'; '.session_name().'='.session_id();
    
$_g2ch 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';

    if (
version_compare(phpversion(), '5.0.0''>'))
    {
      
$_fgco = array('http' => array('method' => 'GET''header' => $_g2ch."\r\n".$_g2cs."\r\n"));
      
$_fgcc stream_context_create($_fgco);

      
$_g2fgc file_get_contents($_g2linkfalse$_fgcc);

      unset(
$_fgco$_fgcc);
    }
    else if (
function_exists('curl_exec'))
    {
      
$c_h curl_init();

      
curl_setopt($c_hCURLOPT_URL$_g2link);
//      curl_setopt($c_h, CURLOPT_PORT, 80);

      
curl_setopt($c_hCURLOPT_HTTPHEADER, array($_g2cs));

      
curl_setopt($c_hCURLOPT_FOLLOWLOCATION1);
      
curl_setopt($c_hCURLOPT_RETURNTRANSFER1);
      
curl_setopt($c_hCURLOPT_BINARYTRANSFER1);

//      curl_setopt($c_h, CURLOPT_HEADER, 1);
      
curl_setopt($c_hCURLOPT_HEADER0);

      if (
$_g2fgc curl_exec($c_h));
      else
      {
        
curl_close($c_h);
        
$_g2fgc 'Error: curl error';
        return 
false;
      }
      
curl_close($c_h);
    }
    else
    {
      
$_g2fgc 'Error: no way to fetch g2 URL';
      return 
false;
    }

    unset(
$_g2cs);
  }
  else
  {
    
$_g2fgc file_get_contents($_g2link);
  }

  
//echo '<xmp>'.$_g2fgc.'</xmp>';

  
return true;
}

function 
g2embed_helper($_g2)
{
  
$_g2ggu = array('view' => $_g2['view'], 'itemId' => $_g2['ii']);

  if (
$_g2['blks'])
    
$_g2ggu['blocks'] = $_g2['blks'];
  if (
$_g2['sh'])
    
$_g2ggu['show'] = $_g2['sh'];
  if (
$_g2['lk']);
  else
    
$_g2ggu['link'] = 'none';

  
$_g2link gallery_generate_url($_g2ggufalsetrue);
  unset(
$_g2ggu);
//  echo $_g2link;

  
if ($_g2['view'] == 'core.DownloadItem')
  {
    return 
$_g2link;
  }

  if (
g2embed_fetchlink($_g2link$_g2data))
  {
    if (
preg_match('/^(?:<!DOCTYPE)/i'$_g2data) && $_g2['view'] == 'imageblock.External')
      
$_g2data 'Error: wrong permissions to fetch g2 URL or HTML document returned';
    else
    {
      
$_g2data str_replace('&amp;''&'$_g2data);
      
$_g2data preg_replace('/g2_GALLERYSID=[a-z0-9]+/i''g2_GALLERYSID='.$_COOKIE['GALLERYSID'], $_g2data);
//      echo '<xmp>'.$_g2data.'</xmp>';
      
return $_g2data;
    }
  }

  if (
$_g2['view'] = 'imageblock.External' && $_g2['sh'] == 'fullSize')
  {
    return 
'<div style="background-color: black; border: thin solid black; width: 320px; height: 256px; text-align: center" class="giThumbnail"><b style="position: relative; top: 45%; color: red">'.$_g2data.'</div></b>';
  }
  else
    return 
'<div style="border: thin solid black; padding: 25px; text-align: center" class="giThumbnail"><b style="position: relative; color: red">'.$_g2data.'</b></div>';
}
?>
then cut n paste this block of code where you want to embed. nb. some views will return a block, page or URL.
<?php
  $_g2
['ii'] = '7912';
/*
  $_g2['view'] = 'imageblock.External';
  $_g2['blks'] = 'specificItem';
  $_g2['sh'] = 'fullSize';  
*/
/*
  $_g2['view'] = 'core.ShowItem';
  $_g2['view'] = 'core.DownloadItem';
 */ 

  
echo g2embed_helper($_g2);
?>
naaaitheth

echo

got pedemont? dan at pedemont.net

Gallery



User login