forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: biellebrunner on March 29, 2016, 05:35:07 am

Title: Latest updated albums on a website
Post by: biellebrunner on March 29, 2016, 05:35:07 am
Hi. Soryr if this is in the wrong place, I wasn't sure if this was to go under plugins, bridges, or something else.

Anyway, I wanted to display the latest updated albums from my gallery on my site. I thought I'd found a way to do that, but it actually shows only the last albums that were created.
This is the code I have:

Code: [Select]
<?php
require_once(
'include/config.inc.php');
header("Content-type: application/x-javascript");

$connect mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass'])
or die('Error connecting to the server');
$connect_db mysql_select_db($CONFIG['dbname'], $connect)
or die ('Error connecting to the database');
$resultado mysql_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12"$connect)
or die('No albums found with this query');    
echo 'document.write(\'';
if(mysql_num_rows($resultado) == 0){
echo 'No albums created';
} else {
echo '<div class="wrapper"><ul>';
while($row mysql_fetch_array($resultado)){
echo ' ';
$album_id $row['aid'];
$subresult mysql_query("SELECT * FROM `cpg_pictures` where aid=$album_id order by pid DESC LIMIT 0, 12");

if(mysql_num_rows($subresult) == 0){
$album_img "GALLERY URL/thumbs/thumb_nopic.png";
} else {
while($subrow mysql_fetch_array($subresult)){
$album_img "GALLERY URL/albums/".$subrow['filepath'].'thumb_'.$subrow['filename']  .$subrow['datebrowse'];                             
}
}
echo '<li><div class="albimg"><img src="'.$album_img.'" alt="" /><div class="galtit"><a href="http://stanakaticbrasil.com./galteste/thumbnails.php?album='.$album_id.' ">'.$row['title'].'</a></div></div></li>';
echo '';
}
}
echo '</ul></div>';
echo '\');';
?>

Is there something I can change in this code to get the output I want?
Thank you.
Title: Re: Latest updated albums on a website
Post by: allvip on March 29, 2016, 09:58:27 am
I think CPMfetch for 1.5.6  is for that http://forum.coppermine-gallery.net/index.php/topic,65412.0.html (http://forum.coppermine-gallery.net/index.php/topic,65412.0.html)
Title: Re: Latest updated albums on a website
Post by: biellebrunner on March 29, 2016, 11:48:55 pm
Sorry if I'm being dumb/blind, but I just went through 4 pages of that thread and didn't find it in a single place saying how to get cpmfetch do display albums instead of images.
Title: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 12:00:52 am
I see in cpmfetch

Code: [Select]
function cpm_viewLastUpdatedAlbumsFrom

Let me test it on my test gallery.
Title: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 12:41:24 am
Add this in a .php file. Name it want you like and upload it the gallery root.

Code: [Select]
<?php
  
include "cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("cpmfetch/cpmfetch_config.php");
  
$objCpm->cpm_viewLastUpdatedAlbumsFrom(0,1,4);
  
$objCpm->cpm_close();
?>


Then use iframes to call the php file on your html pages.

Code: [Select]
<iframe src="your_path/your_php_file.php"></iframe>

If is a php file then you can paste the code in the page.
Change the paths to your cmpetch paths (cpmfetch/cpmfetch.php and cpmfetch/cpmfetch_config.php) with the right path.

You want to display title or the caption under too?

If the page you want to display the last up alb is not on the same domain as the gallery then you have to use iframes.

Look in cpmfetch.php for all the possible cmpfetch options like display random etc
Title: Re: Latest updated albums on a website
Post by: biellebrunner on March 30, 2016, 01:11:07 am
Thank you!
Yes, I want album title as well.
One question: what each number ("(0,1,4)" ) stand for? Rows, columns and?
Title: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 01:14:49 am
One question: what each number ("(0,1,4)" ) stand for? Rows, columns and?

0 is the cat id and I used 0 so will take the last from all cats.
1 row and 4 albums.
Title: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 01:57:26 am
Yes, I want album title as well.

You will have to search the forum for how to display the caption in cmpfetch or wait for the coppermine team to reply.
On my test it did not worked out. Don't know how.
Sorry.
Title: Re: Latest updated albums on a website
Post by: biellebrunner on March 30, 2016, 04:54:24 am
Thank you for trying though.
I think it might be easier to edit the code I had at first. I always had a hard time figuring cpmfetch out.

The current query has all albums to be displayed by album ID (aid) is descent order. So it returns the last created albums.

Code: [Select]
$resultado = mysql_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12", $connect)
and

Code: [Select]
$album_id = $row['aid'];
$subresult = mysql_query("SELECT * FROM `cpg_pictures` where aid=$album_id order by pid DESC LIMIT 0, 12");

I just can't seem to figure out what I should replace "aid" for. I couldn't find anything on cpg documentation. Any idea where I could find it (or what I can use to replace aid)?
Title: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 05:39:51 am
Look in include/functions.inc.php

Search for     

Code: [Select]
case 'lastalb': // Last albums to which files have been uploaded
and a little more down

Code: [Select]
// last uploaded file from album
The query is there.
Title: Re: Latest updated albums on a website
Post by: biellebrunner on March 30, 2016, 06:38:37 am
I tried that, but I keep getting a "No albums found with this query" as a result. I also tried with "ctime" and in different variations ("... ORDER BY `cpg_albums`.`ctime` DESC ..."; "... ORDER BY `cpg_albums`.`lastalb` DESC ...", "... ORDER BY `lastalb` DESC ...", and so on).
Does the $subresult need to be edited as well?

I'm really sorry, but I'm completely new in php, and I'm clearly over my head. =/
Title: Re: Latest updated albums on a website
Post by: lurkalot on March 30, 2016, 09:57:49 am
Not sure all the functions work in cmpfetch, in fact I know some don't.  it was originally written for Coppermine 1.4.xx before it was retired.

I only use it to display random images and latest images on my front page as can be seen here http://cameracraniums.com

I haven't tried using it for anything else tbh.
Title: Re: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 10:18:04 am
Not sure all the functions work in cmpfetch, in fact I know some don't.  it was originally written for Coppermine 1.4.xx before it was retired.

I only use it to display random images and latest images on my front page as can be seen here http://cameracraniums.com

I haven't tried using it for anything else tbh.

How did you made it to make the title and views to show?

The code should be something like this (is working but the options not)

Code: [Select]
<?php
$options 
= array( 'subtitle' => 'Image %t is %S KB' 'imagewidth' => '200' );
  include 
"cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("cpmfetch/cpmfetch_config.php");
  
$objCpm->cpm_viewLastUpdatedAlbumsFrom(0,1,4,$options);
  
$objCpm->cpm_close();
?>


Where  %t should display the title and %S the file zise but only the 'imagewidth' => '200' is working.
What should be used for subtitle to make it display the image title?
Title: Re: Latest updated albums on a website
Post by: lurkalot on March 30, 2016, 06:39:47 pm
You mean this bit?

Code: [Select]
$objCpm = new cpm();$options = array("subtitle" => "<center>{{pTitle}} <br> {{pHits}} Views  </center>");
Title: Re: Re: Latest updated albums on a website
Post by: lurkalot on March 30, 2016, 06:47:26 pm
You mean this bit?  Remember I'm running my code in a Tinyportal PHP block.

Code: [Select]
$objCpm = new cpm();$options = array("subtitle" => "<center>{{pTitle}} <br> {{pHits}} Views  </center>");

When I used this cpmfetch in Coppermine 1.4.xx a few years ago I also had it showing the user name below each image, but that ceased to function in Coppermine 1.5.xx, and I never did discover how to get that bit working again. ;)
Title: Re: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 07:01:02 pm
You mean this bit?

Code: [Select]
$objCpm = new cpm();$options = array("subtitle" => "<center>{{pTitle}} <br> {{pHits}} Views  </center>");

Nothing shows.
Title: Re: Re: Latest updated albums on a website
Post by: lurkalot on March 30, 2016, 08:38:09 pm
Nothing shows.

That's only part of the code I'm using. Are you running it in a portal block same as me?  If so there's my original code here, (the second one in that post) http://forum.coppermine-gallery.net/index.php/topic,65412.msg336985.html#msg336985

Or if you need my current code which shows both random and latest (in a portal block), I'll PM it to you. ;)
Title: Re: Re: Re: Latest updated albums on a website
Post by: allvip on March 30, 2016, 09:07:29 pm
Are you running it in a portal block same as me?  If so there's my original code here, (the second one in that post) http://forum.coppermine-gallery.net/index.php/topic,65412.msg336985.html#msg336985

Or if you need my current code which shows both random and latest (in a portal block), I'll PM it to you. ;)

No. I created a php file in the gallery root. Your code is working but not the subtitle option.

The example from the docs (options subtitle not working)

Code: [Select]
<?php
  
include_once "cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("cpmfetch/cpmfetch_config.php");
  
$options = array("subtitle" => "File name : {{pFilename}}");
  
$objCpm->cpm_viewLastAddedMedia(14$options);
  
$objCpm->cpm_viewRandomMediaFrom(0,14$options);
  
$objCpm->cpm_close(); 
?>

Title: Re: Latest updated albums on a website
Post by: Αndré on April 06, 2016, 11:59:53 am
I think it might be easier to edit the code I had at first.

I think the main issue is the table prefix, which is probably different in your gallery than "cpg_". This worked for me, as it used the table prefix set in include/config.inc.php:
Code: [Select]
<?php
require_once(
'include/config.inc.php');
header("Content-type: application/x-javascript");

$connect mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass'])
or die('Error connecting to the server');
$connect_db mysql_select_db($CONFIG['dbname'], $connect)
or die ('Error connecting to the database');
$resultado mysql_query("SELECT * FROM `{$CONFIG['TABLE_PREFIX']}albums` ORDER BY `{$CONFIG['TABLE_PREFIX']}albums`.`aid` DESC LIMIT 0 , 12"$connect)
or die('No albums found with this query');    
echo 'document.write(\'';
if(mysql_num_rows($resultado) == 0){
echo 'No albums created';
} else {
echo '<div class="wrapper"><ul>';
while($row mysql_fetch_array($resultado)){
echo ' ';
$album_id $row['aid'];
$subresult mysql_query("SELECT * FROM `{$CONFIG['TABLE_PREFIX']}pictures` where aid=$album_id order by pid DESC LIMIT 0, 12");

if(mysql_num_rows($subresult) == 0){
$album_img "GALLERY URL/thumbs/thumb_nopic.png";
} else {
while($subrow mysql_fetch_array($subresult)){
$album_img "GALLERY URL/albums/".$subrow['filepath'].'thumb_'.$subrow['filename']  .$subrow['datebrowse'];                             
}
}
echo '<li><div class="albimg"><img src="'.$album_img.'" alt="" /><div class="galtit"><a href="http://stanakaticbrasil.com./galteste/thumbnails.php?album='.$album_id.' ">'.$row['title'].'</a></div></div></li>';
echo '';
}
}
echo '</ul></div>';
echo '\');';
?>
Title: Re: Latest updated albums on a website
Post by: biellebrunner on April 06, 2016, 12:57:47 pm
Actually, the code was working just fine, but it retrieves the last created albums, and I wanted the last updated albums.
I can't figure out what to change
Code: [Select]
ORDER BY `cpg_albums`.`aid` for to achieve that. I've tried a few different combinations of lastalb and ctime, but no such luck.

Thank you for trying though.
I think it might be easier to edit the code I had at first. I always had a hard time figuring cpmfetch out.

The current query has all albums to be displayed by album ID (aid) is descent order. So it returns the last created albums.

Code: [Select]
$resultado = mysql_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12", $connect)
and

Code: [Select]
$album_id = $row['aid'];
$subresult = mysql_query("SELECT * FROM `cpg_pictures` where aid=$album_id order by pid DESC LIMIT 0, 12");

I just can't seem to figure out what I should replace "aid" for. I couldn't find anything on cpg documentation. Any idea where I could find it (or what I can use to replace aid)?

I tried that, but I keep getting a "No albums found with this query" as a result. I also tried with "ctime" and in different variations ("... ORDER BY `cpg_albums`.`ctime` DESC ..."; "... ORDER BY `cpg_albums`.`lastalb` DESC ...", "... ORDER BY `lastalb` DESC ...", and so on).
Does the $subresult need to be edited as well?

I'm really sorry, but I'm completely new in php, and I'm clearly over my head. =/
Title: Re: Latest updated albums on a website
Post by: Αndré on April 06, 2016, 01:32:39 pm
Sorry, I misunderstood the request. I'll post updated code soon.
Title: Re: Latest updated albums on a website
Post by: Αndré on April 06, 2016, 01:50:24 pm
Please try this:
Code: [Select]
<?php
    
require_once('include/config.inc.php');
    
header("Content-type: application/x-javascript");

    
$connect mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass'])
        or die(
'Error connecting to the server');
    
$connect_db mysql_select_db($CONFIG['dbname'], $connect)
        or die (
'Error connecting to the database');
    
$sql "SELECT * FROM `{$CONFIG['TABLE_PREFIX']}albums` AS a INNER JOIN `{$CONFIG['TABLE_PREFIX']}pictures` AS r ON a.aid = r.aid WHERE approved = 'YES' GROUP BY r.aid ORDER BY ctime DESC LIMIT 0 , 12";
    
$resultado mysql_query($sql$connect)
        or die(
'No albums found with this query');    
    echo 
'document.write(\'';
    if(
mysql_num_rows($resultado) == 0){
        echo 
'No albums created';
    } else {
        echo 
'<div class="wrapper"><ul>';
            while(
$row mysql_fetch_array($resultado)){
            echo 
' ';
            
/*
                $album_id = $row['aid'];
                $subresult = mysql_query("SELECT * FROM `{$CONFIG['TABLE_PREFIX']}pictures` where aid=$album_id order by pid DESC LIMIT 0, 12");
                                
                if(mysql_num_rows($subresult) == 0){
                    $album_img = "GALLERY URL/thumbs/thumb_nopic.png";
                } else {
                    while($subrow = mysql_fetch_array($subresult)){
                        $album_img = "GALLERY URL/albums/".$subrow['filepath'].'thumb_'.$subrow['filename']  .$subrow['datebrowse'];                             
                    }
                }
            */
            
$album_img "GALLERY URL/albums/".$row['filepath'].'thumb_'.$row['filename'].$row['datebrowse'];                             
            echo 
'<li><div class="albimg"><img src="'.$album_img.'" alt="" /><div class="galtit"><a href="http://stanakaticbrasil.com./galteste/thumbnails.php?album='.$album_id.' ">'.$row['title'].'</a></div></div></li>';
            echo 
'';
        }
    }
    echo 
'</ul></div>';
    echo 
'\');';
?>
Title: Re: Latest updated albums on a website
Post by: biellebrunner on April 06, 2016, 03:11:37 pm
Ok. It is getting the last updated albums. But now the album title won't show up, and the thumbnails aren't linking to their albums.  :(
Title: Re: Latest updated albums on a website
Post by: Αndré on April 06, 2016, 03:28:10 pm
Sorry. It's quite hard to check the result with the code you provided, as I get just the HTML output and thus don't see such obvious flaws.

Please try this:
Code: [Select]
<?php
    
require_once('include/config.inc.php');
    
header("Content-type: application/x-javascript");

    
$connect mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass'])
        or die(
'Error connecting to the server');
    
$connect_db mysql_select_db($CONFIG['dbname'], $connect)
        or die (
'Error connecting to the database');
    
$sql "SELECT *, a.title AS alb_title FROM `{$CONFIG['TABLE_PREFIX']}albums` AS a INNER JOIN `{$CONFIG['TABLE_PREFIX']}pictures` AS r ON a.aid = r.aid WHERE approved = 'YES' GROUP BY r.aid ORDER BY ctime DESC LIMIT 0 , 12";
    
$resultado mysql_query($sql$connect)
        or die(
'No albums found with this query');
    echo 
'document.write(\'';
    if(
mysql_num_rows($resultado) == 0){
        echo 
'No albums created';
    } else {
        echo 
'<div class="wrapper"><ul>';
        while(
$row mysql_fetch_array($resultado)){
            
$album_img "GALLERY URL/albums/".$row['filepath'].'thumb_'.$row['filename'].$row['datebrowse'];                             
            echo 
'<li><div class="albimg"><img src="'.$album_img.'" alt="" /><div class="galtit"><a href="http://stanakaticbrasil.com./galteste/thumbnails.php?album='.$row['aid'].'">'.$row['alb_title'].'</a></div></div></li>';
        }
    }
    echo 
'</ul></div>';
    echo 
'\');';
?>
Title: Re: Latest updated albums on a website
Post by: biellebrunner on April 06, 2016, 04:00:20 pm
Yes! It worked perfectly!
And no need to apologise, you're already doing so much by just giving it a try (and succeeding!).
Thank you so, so much!  ;D