Latest updated albums on a website Latest updated albums on a website
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Latest updated albums on a website

Started by biellebrunner, March 29, 2016, 05:35:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

biellebrunner

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:

<?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.


biellebrunner

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.

allvip

I see in cpmfetch


function cpm_viewLastUpdatedAlbumsFrom


Let me test it on my test gallery.

allvip

#4
Add this in a .php file. Name it want you like and upload it the gallery root.


<?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.


<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

biellebrunner

Thank you!
Yes, I want album title as well.
One question: what each number ("(0,1,4)" ) stand for? Rows, columns and?

allvip

Quote from: biellebrunner on March 30, 2016, 01:11:07 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.

allvip

Quote from: biellebrunner on March 30, 2016, 01:11:07 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.

biellebrunner

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.

$resultado = mysql_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12", $connect)

and

$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)?

allvip

Look in include/functions.inc.php

Search for     

case 'lastalb': // Last albums to which files have been uploaded

and a little more down

// last uploaded file from album

The query is there.

biellebrunner

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. =/

lurkalot

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.
Running SMF 2.1.4  / Tinyportal 3.0.1, bridged with Coppermine 1.6.25, plus cpmfetch 2.0.0

allvip

Quote from: 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.

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)


<?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?

lurkalot

You mean this bit?

$objCpm = new cpm();$options = array("subtitle" => "<center>{{pTitle}} <br> {{pHits}} Views  </center>");
Running SMF 2.1.4  / Tinyportal 3.0.1, bridged with Coppermine 1.6.25, plus cpmfetch 2.0.0

lurkalot

Quote from: lurkalot on March 30, 2016, 06:39:47 PM
You mean this bit?  Remember I'm running my code in a Tinyportal PHP block.

$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. ;)
Running SMF 2.1.4  / Tinyportal 3.0.1, bridged with Coppermine 1.6.25, plus cpmfetch 2.0.0

allvip

Quote from: lurkalot on March 30, 2016, 06:39:47 PM
You mean this bit?

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

Nothing shows.

lurkalot

Quote from: allvip on March 30, 2016, 07:01:02 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. ;)
Running SMF 2.1.4  / Tinyportal 3.0.1, bridged with Coppermine 1.6.25, plus cpmfetch 2.0.0

allvip

Quote from: lurkalot on March 30, 2016, 08:38:09 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)


<?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(); 
?>


ΑndrĂ©

Quote from: biellebrunner on March 30, 2016, 04:54:24 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:
<?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 '\');';
?>

biellebrunner

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 ORDER BY `cpg_albums`.`aid` for to achieve that. I've tried a few different combinations of lastalb and ctime, but no such luck.

Quote from: 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.

$resultado = mysql_query("SELECT * FROM `cpg_albums` ORDER BY `cpg_albums`.`aid` DESC LIMIT 0 , 12", $connect)

and

$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)?

Quote from: 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. =/