Piwigo.org

You are not logged in. (Register / Login)

Announcement

#1 2017-07-31 10:17:26

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

How to setup each album first image to representative ?

Hello/Hi/Greetings,

I really need that help, please, please help me , GOD...

How to setup each album first image to representative default?

The default is seems random.

Piwigo version: 2.9.1
PHP version: 7.0.1
MySQL version: 5.55
Piwigo URL: http://testing now.

Offline

 

#2 2017-07-31 21:13:22

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

please master, need help, thanks very much.

Offline

 

#3 2017-08-02 08:51:36

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

still waiting that help, master ~~ god ~~ I need you lol

Offline

 

#4 2017-08-02 14:24:44

ddtddt
Piwigo Team
Location: Quetigny - France
Registered: 2007-07-27
Posts: 6672

Re: How to setup each album first image to representative ?

Hi :-)

They're no option to make this


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#5 2017-08-02 18:44:32

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

ddtddt wrote:

Hi :-)

They're no option to make this

thanks, but it's scripts, must have some where can be edit it ?

Offline

 

#6 2017-08-02 21:43:25

ddtddt
Piwigo Team
Location: Quetigny - France
Registered: 2007-07-27
Posts: 6672

Re: How to setup each album first image to representative ?

kiwiyak wrote:

ddtddt wrote:

Hi :-)

They're no option to make this

thanks, but it's scripts, must have some where can be edit it ?

You can make plugin for this


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#7 2017-08-02 21:45:17

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

ddtddt wrote:

kiwiyak wrote:

ddtddt wrote:

Hi :-)

They're no option to make this

thanks, but it's scripts, must have some where can be edit it ?

You can make plugin for this

Already have that plugin please ??? lol

No sorry I'haven't this

Offline

 

#8 2017-08-11 08:50:14

birdlives
Member
Registered: 2017-08-11
Posts: 1

Re: How to setup each album first image to representative ?

This is a feature I wish piwigo had as well.

I am not at all a programmer so writing a php plugin is not possible. But I have come up with my own method to do this and it involves using a combination of SQL queries, a simple bash loop, and the piwigo api 'pwg.categories.setRepresentative' which for me running on localhost, more information is located at: http://localhost/piwigo/tools/ws.htm.

This is all done from a linux terminal. I suppose you could do the same thing on windows with cygwin.

First I get a list of the categories/album ID's:

Code:

mysql --user=yourusername -B -N   -p -e "SELECT id FROM piwigo.piwigo_categories;" > albumIDs

You use your database username, -B makes the output separated by tab, -N strips out the column names, -p is so it asks for your password, -e is to execute the given SQL query. Then it writes the output to a text file named albumIDs

This text file contains all the ID #'s of your albums.

The next step requires curl and your cookie file for piwigo. I use a firefox addon called CLIget which automatically outputs the cookie in the necessary format.

Code:

for SET in `cat albumIDs ` ; do PIC=`mysql -B -N  --user=yourusername --p -e "SELECT id FROM piwigo.piwigo_images WHERE storage_category_id=$SET order by path ASC limit 1;"` ; curl  --header 'Cookie: pwg_id=18t4c2htj7rtp1p4q57iahgfq4; __zlcmid=fsgLZSGNrIcWIQ'  -d "method=pwg.categories.setRepresentative&category_id=$SET&image_id=$PIC"  -X POST 'http://localhost/piwigo/ws.php?format=rest'  ; done

This is a single line bash script. Sorry I'm not a programmer so I don't know best practice to make things more easily understandable. What it does is:
For each ID in that albumIDs file, do a sql query that SELECTS the ID of all the images with a matching storage_category_id. SORT those images ASC (ascending), and LIMIT the output to the first one.

Then have curl call the piwigo API method 'pwg.categories.setRepresentative' with the the category being the albumID and the image_id being the matching id number from the previous sql query.

You MUST replace the cookie part with your actual piwigo cookie when logged in as an administrator. I included an expired cookie just as an example, it should look similar form. If you use cliget and have it give you a command to download your admin page, you can use the cookie part. Also you need to to use your URL, my piwigo is on localhost.

Once this is all done it will set representative for all the albums which have images in them, to the first one. What it will NOT do is change the representative for parent albums which contain only sub albums.  I've figured how to do this as well but I can't find my notes on how I did it. It was not too dificult to do, I think I just  looped on the parent albums, selected the representatives from the subalbums and limited it to 1. Parents get their representative from subalbums so if a random first image doesn't bother you then you can stop here.  Otherwise if you manage to get my first method I'm sure you could figure out the parent albums.

Sorry for the long explanation. But I'm always a bit nervous when I copy commands into the command line and I have no idea what they are doing. As I said I'm not trained in programming whatsoever and the only first principles I'm working off is a bit of logic and bunch of trial and error. But I hope this helps you at least to finding your own method that makes sense for you.

Last edited by birdlives (2017-08-11 09:05:09)

Offline

 

#9 2017-08-11 18:13:50

jdev21
Member
Registered: 2017-08-11
Posts: 1

Re: How to setup each album first image to representative ?

I am also looking for a simple way to do this.
Thanks for the guide birdlives. This seems a lot more complicated than it should be.

I was hoping for a simple code edit to change the representative from being random to being the first.

Offline

 

#10 2017-08-13 20:06:36

Knitter
Member
Location: Denmark
Registered: 2016-05-26
Posts: 58
Website

Re: How to setup each album first image to representative ?

Maybe I misunderstand what you are after, but this will set the album thumbnail

Choose the pic, and click on "album thumbnail"


Uploaded Images

Last edited by Knitter (2017-08-13 20:09:10)

Offline

 

#11 2017-08-26 23:20:38

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

thanks very much,

recently, I'm full check all the php scripts files with piwigo

I notice in 1 php files, handle the representative , it's order by "random", I try to edit it , order by ASC , but it's not work.

I'm wondering, how it's not work even I edited it , upload it ...

Offline

 

#12 2017-08-26 23:45:11

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

the files is functions.php, I'm edit following (ORDER BY image_id ASC LIMIT 1), not work:

/**
* Set a new random representant to the categories.
*
* @param int[] $categories
*/
function set_random_representant($categories)
{
  $datas = array();
  foreach ($categories as $category_id)
  {
    $query = '
SELECT image_id
  FROM '.IMAGE_CATEGORY_TABLE.'
  WHERE category_id = '.$category_id.'
  ORDER BY image_id ASC
  LIMIT 1
;';
    list($representative) = pwg_db_fetch_row(pwg_query($query));

    $datas[] = array(
      'id' => $category_id,
      'representative_picture_id' => $representative,
      );
  }

  mass_updates(
    CATEGORIES_TABLE,
    array(
      'primary' => array('id'),
      'update' => array('representative_picture_id')
      ),
    $datas
    );
}

Offline

 

#13 2017-08-26 23:48:03

kiwiyak
Member
Registered: 2015-10-02
Posts: 17

Re: How to setup each album first image to representative ?

as my edit, it should be work, but not ... dont know what's wrong

Offline

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2017 · Contact