#!/usr/local/bin/perl use strict; use lib '/path/to/your/admin'; use Links qw/$IN $DB $CFG/; use CGI::Carp qw(fatalsToBrowser); use Links::Plugins; use Image::Size; local $SIG{__DIE__} = \&Links::fatal; Links::init('/path/to/your/admin'); my $sth = $DB->table('Links')->select( ['DISTINCT(LinkOwner)'] ) || die $GT::SQL::error; while (my $hit = $sth->fetchrow_hashref) { print "Working on: $hit->{LinkOwner} \n"; send_email($hit->{LinkOwner}); } sub send_email { my $user = $_[0]; my $link_db = $DB->table ('Links'); $link_db->select_options ('ORDER BY Hits DESC') || die $GT::SQL::error; my $sth = $link_db->select( { isValidated => "Yes", LinkOwner => $user } ) || die $GT::SQL::error; my $user_hash = $DB->table('Users')->select( { Username => $user } )->fetchrow_hashref; my @links; my $count = $sth->rows(); if ($count < 1) { next; } # just top rated links. while (my $link = $sth->fetchrow_hashref) { push @links, $link; } Links::send_email("users_links_email.eml", { links_loop => \@links, %$user_hash, count => $count } ) or die "Unable to send message: $GT::Mail::error"; }