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
Ok thanks!
But now... the links don't work anymore. There is no personally link. All the links go to the root
Offline
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
Nice script and great and fast help
THANKS !!!!!
Offline
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
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
Hi populas,
Considering this output....
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
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.
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
hello,
sorry to insist... if anybody can help me solve the above mentionned problem, I would be more than grateful.
Thank you
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
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
thx for reporting
but what file are you talking about?
Offline
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
I want to know to, the old one is not working anymore.
Thanks in advance !