Announcement

#31 2014-12-19 10:00:23

Leif
Guest

Re: showing last 5 albums on external page

plg wrote:

I have updated the script

demo : http://piwigo.org/tmp/last5albums.php
source : http://piwigo.org/tmp/last5albums.phps

Now it shows the 5 last updated albums + a random thumbnail for each one.

Please make it fit for Piwigo 2.7.
It is a very nice feature to set the thumbnails incl.  Links direct to the Homepage.

Thumbnails do not longer generated.

@Pierrick: Please help us.

 

#32 2015-02-12 15:27:29

Leif
Guest

Re: showing last 5 albums on external page

Problem is still exist. No Ideas to solve it?

 

#33 2015-03-01 12:59:16

jc
Member
2015-01-04
26

Re: showing last 5 albums on external page

up

Offline

 

#34 2015-04-17 11:27:34

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: showing last 5 albums on external page

Offline

 

#35 2015-06-22 20:32:11

Leif
Guest

Re: showing last 5 albums on external page

Thank you. Great Job!

Is it possible to use square thumbnails? Thats better on the external page.
Within in Piwigo i use the Plugin GDThumb.

 

#36 2015-06-22 20:39:03

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: showing last 5 albums on external page

line 25 replace thumb by square

Offline

 

#37 2015-06-22 20:51:37

Leif
Guest

Re: showing last 5 albums on external page

Now is perfect, thanks for your support.

My Url: http://gallery.alphaville.nu/

/*edit*/
Direct link piwigo gallery

Last edited by ddtddt (2015-06-23 07:24:06)

 

#38 2015-09-29 21:06:16

Scott_T
Member
2015-09-29
9

Re: showing last 5 albums on external page

Hello...

I think this is close to what I need, I found this in a search so here I start....

My info FWIW:

Piwigo version:  2.7.4
PHP version: 5.3.29
MySQL version: 5.5.45-MariaDB
Piwigo URL: http://true-grit.org/piwigo

I am looking to display a 1 random thumbnail on another web page, in a Tinyportal 'block' on a SMF forum . I've used other galleries and was able to display a random thumbnail, but am new to piwigo.

I tried the codes here edited, I'll post one below that I edited as maybe I made a mistke, but mostly I think that the code is not quite right, but am not sure why. You can see the gallery block here, on the right side. Nothing fancy just a random thumbnail from an SMF gallery.

http://true-grit.org/TGAB/

Here is your code I edited:

<?php
$base_url = 'http://true-grit.org/piwigo/ws.php?format=php&method=';

$url = $base_url.'pwg.categories.getList&recursive=true&public=true';
fetchRemote($url, $result);
$result = unserialize($result);
$albums = $result['result']['categories'];

foreach ($albums as $idx => $album) {
  $date_last[$idx] = $album['date_last'];
}

array_multisort($date_last, SORT_DESC, $albums);
$albums = array_slice($albums, 1, 1);

echo '<table><tr>';
foreach ($albums as $album) {
  $thumbnail_url = $base_url.'pwg.categories.getImages';
  $thumbnail_url.= '&cat_id='.$album['id'];
  $thumbnail_url.= '&per_page=1';
  $thumbnail_url.= '&order=random';

  fetchRemote($thumbnail_url, $result);
  $result = unserialize($result);
  $thumbnail_url = $result['result']['images'][0]['derivatives']['thumb']['url'];
 
  echo(
    sprintf(
      '<td><a href="%s"><img src="%s"><br>%s</a></td>',
      $album['url'],
      $thumbnail_url,
      $album['name']
      )
    );
}
echo '</tr></table>';

/**
* Retrieve data from external URL
*
* @param string $src: URL
* @param global $dest: can be a file ressource or string
* @return bool
*/
function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
{
  // After 3 redirections, return false
  if ($step > 3) return false;

  // Initialize $dest
  is_resource($dest) or $dest = '';

  // Try curl to read remote file
  if (function_exists('curl_init'))
  {
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_URL, $src);
    @curl_setopt($ch, CURLOPT_HEADER, 1);
    @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $content = @curl_exec($ch);
    $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    @curl_close($ch);
    if ($content !== false and $status >= 200 and $status < 400)
    {
      if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
      {
        return fetchRemote($m[1], $dest, $user_agent, $step+1);
      }
      $content = substr($content, $header_length);
      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
      return true;
    }
  }

  // Try file_get_contents to read remote file
  if (ini_get('allow_url_fopen'))
  {
    $content = @file_get_contents($src);
    if ($content !== false)
    {
      is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
      return true;
    }
  }

  // Try fsockopen to read remote file
  $src = parse_url($src);
  $host = $src['host'];
  $path = isset($src['path']) ? $src['path'] : '/';
  $path .= isset($src['query']) ? '?'.$src['query'] : '';

  if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
  {
    return false;
  }

  fwrite($s,
    "GET ".$path." HTTP/1.0\r\n"
    ."Host: ".$host."\r\n"
    ."User-Agent: ".$user_agent."\r\n"
    ."Accept: */*\r\n"
    ."\r\n"
  );

  $i = 0;
  $in_content = false;
  while (!feof($s))
  {
    $line = fgets($s);

    if (rtrim($line,"\r\n") == '' && !$in_content)
    {
      $in_content = true;
      $i++;
      continue;
    }
    if ($i == 0)
    {
      if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m))
      {
        fclose($s);
        return false;
      }
      $status = (integer) $m[2];
      if ($status < 200 || $status >= 400)
      {
        fclose($s);
        return false;
      }
    }
    if (!$in_content)
    {
      if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m))
      {
        fclose($s);
        return fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
      }
      $i++;
      continue;
    }
    is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line;
    $i++;
  }
  fclose($s);
  return true;
}
?>

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact