Announcement

#16 2010-06-04 13:44:59

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

Re: showing last 5 albums on external page

Gust wrote:

The "$category" in the script give a conflict with Cutenews, a familiar news script. Is it possible to give an alternative name for $category?

I have renammed $categories into $albums and $category into $album (and of course it still work)

Offline

 

#17 2010-06-04 14:13:16

Gust
Member
2010-06-02
77

Re: showing last 5 albums on external page

Ok thanks!
But now... the links don't work anymore. There is no personally link. All the links go to the root

Offline

 

#18 2010-06-04 14:18:50

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

Re: showing last 5 albums on external page

Gust wrote:

Ok thanks!
But now... the links don't work anymore. There is no personally link. All the links go to the root

bug fixed

Offline

 

#19 2010-06-04 14:36:22

Gust
Member
2010-06-02
77

Re: showing last 5 albums on external page

Nice script and great and fast help
THANKS !!!!!

Offline

 

#20 2012-02-15 23:16:55

populas
Guest

Re: showing last 5 albums on external page

Hello,

I was looking exactly for this type of code. However it seems I have problems with the FetchRemote function.
If anybody can help me, I would be really thankful.

Here are the errors :

Warning: Invalid argument supplied for foreach() in ....

Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in ....

Warning: array_slice() expects parameter 1 to be array, null given in ....

Warning: Invalid argument supplied for foreach() in .....

And here is what the page
http://...../ws.php?format=php&method=pwg.categories.getList&recursive=true&public=true
gives :

a:2:{s:4:"stat";s:2:"ok";s:6:"result";a:1:{s:10:"categories";a:0:{}}}

Last thing, the $result variable is empty.

Thank you in advance for your help

 

#21 2012-02-17 20:32:47

populas
Guest

Re: showing last 5 albums on external page

Hello again,

Can anybody help me?

Maybe was I not very clear or accurate enough explaining the issue?
I really need the help of an expert to solve this problem.

Regards

 

#22 2012-02-17 22:28:03

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

Re: showing last 5 albums on external page

Hi populas,

Considering this output....

Code:

a:2:{s:4:"stat";s:2:"ok";s:6:"result";a:1:{s:10:"categories";a:0:{}}}

... there should be no warning : there is no categories but there is an empty array, not an undefined value.

Is it expected that you have no album? Are all your albums/photos private?

Offline

 

#23 2012-02-17 23:30:49

populas
Guest

Re: showing last 5 albums on external page

plg wrote:

Hi populas,

Considering this output....

Code:

a:2:{s:4:"stat";s:2:"ok";s:6:"result";a:1:{s:10:"categories";a:0:{}}}

... there should be no warning : there is no categories but there is an empty array, not an undefined value.

Is it expected that you have no album? Are all your albums/photos private?

Thank you plg for your answer, the problem is solved!!

Actually I was working with .htaccess/.htpasswd (on the root) which were hiding the album...

Do you know if it is possible to still work with the htaccess but without hiding the piwigo album?

again, thank you for your help.

 

#24 2012-08-12 15:23:43

populas
Guest

Re: showing last 5 albums on external page

Hello,

The code isn't working with the new version 2.4.  Actually, the "random" picture isn't appearing, whereas the title and the link are still ok.

The problem should be within these lines?

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';

Can anybody help me to fix it?

Kind regards

 

#25 2012-08-14 23:24:32

populas
Guest

Re: showing last 5 albums on external page

hello,
sorry to insist... if anybody can help me solve the above mentionned problem, I would be more than grateful.
Thank you

 

#26 2012-08-16 20:53:54

populas
Guest

Re: showing last 5 albums on external page

please, can anybody tell me if a solution exists for this problem? It looks like easy even if I have no hint, but if it's not and needs much work, then let me know so that I start to find another solution. akhhh it would be sad, I liked it...

Thank you

 

#27 2013-08-30 17:14:57

Pavel
Member
2012-08-28
7

Re: showing last 5 albums on external page

I tried this script on my Drupal based site (7.22) with Piwigo (2.5.2) ,

Ran into this error:
Notice: Undefined index: tn_url in eval() (line 25 of /var/www/drupal/modules/php/php.module(80) : eval()'d code)

To fix this line:

$thumbnail_url = $result['result']['images']['_content'][0]['tn_url'];

needs to be changed to:

$thumbnail_url = $result['result']['images']['_content'][0]['derivatives']['thumb']['url'];

And it works again.

;)

Offline

 

#28 2013-08-31 20:21:29

flop25
Piwigo Team
2006-07-06
7036

Re: showing last 5 albums on external page

thx for reporting

but what file are you talking about?


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#29 2014-07-15 14:28:20

Gust
Member
2010-06-02
77

Re: showing last 5 albums on external page

Hi,

In the new versions, you see only the album name, but not the thumbs. What must we replace/fix?

<?php
$base_url = 'pad-to/fotoalbum/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, 0, 4);

echo '<table width="99%" align="center"><tr valign="top">';
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']['_content'][0]['tn_url'];
 
  echo(
    sprintf(
// '<td><center><a href="%s"><img border="0" width="128" height="96" src="%s"><br>%s</a></center></td>',
//'<td><table width="128" border="0"><tr><td><center><a href="%s"><img border="0" height="96" src="%s"><br>%s</a></center></td></tr></table></td>',
'<td><center><a href="%s"><img border="0" height="90" src="%s"><br>%s</a></center></td>',
      $album['url'],
      $thumbnail_url,
      $album['name']
      )
    );
}
echo '</center></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;
}
?>

Thanks!

Last edited by Gust (2014-07-15 15:37:57)

Offline

 

#30 2014-07-17 16:24:19

niek
Guest

Re: showing last 5 albums on external page

I want to know to, the old one is not working anymore.

Thanks in advance !

 

Board footer

Powered by FluxBB

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