ljr/local/htdocs/directory.bml

381 lines
16 KiB
Plaintext
Executable File

<?_code $head = ""; _code?><?page
title=>Search Results
body<=
<?_code
return LJ::server_down_html() if ($LJ::SERVER_DOWN);
LJ::set_active_crumb('searchregion');
my @errors = ();
my @filters = LJ::Dir::validate(\%FORM, \@errors);
return LJ::bad_input(@errors) if @errors;
my $dbr = LJ::get_db_reader();
# the common case (small installations), people want the directory
# to just work. so we'll support that by default. but on big sites,
# you don't want the directory ever getting near the other databases,
# so we provide a flag to make sure the code can't.
my @extraroles = ("slave", "master");
if ($LJ::DIRECTORY_SEPARATE) { @extraroles = (); }
my $dbdir = LJ::get_dbh("directory", @extraroles);
return "Directory database not available." unless $dbdir;
my @matches;
my %info;
my $ret = "";
if (BML::get_query_string() eq "")
{
LJ::load_codes({ state => \%state, country => \%country });
$ret = "";
$ret .= "<?h1 $ML{'.browse.usa.title'} h1?><?p $ML{'.browse.usa.desc'} p?>\n";
$ret .= "<form action='get' name=\"stateForm\"><p align='center'>";
$ret .= "<script language=\"JavaScript\" type='text/javascript'><!--\n document.write('<input name=\"s\" type=\"text\" size=\"30\"><br />'); \n// --></script>\n";
$ret .= "<script language=\"JavaScript\" type='text/javascript'><!--\nfunction updateStatus (text) { self.status = text; document.stateForm.s.value=text; return true; } \n// --></script>\n";
$ret .= "<img alt='US Map' src=\"$LJ::IMGPREFIX/us_map.gif\" width='489' height='315' border='0' usemap=\"#state_test\" ismap='ismap' /></p></form><map name='state_test' id='state_test'>\n";
$sth = $dbr->prepare("SELECT statcat, statkey, statval FROM stats WHERE statcat IN ('country', 'stateus')");
$sth->execute;
while ($_ = $sth->fetchrow_hashref) {
$count{$_->{'statcat'}}->{$_->{'statkey'}} = $_->{'statval'};
}
my @shapes = (
"1,235,1,309,108,309,108,235,18,235,1,235", "AK",
"328,196,328,236,355,235,345,195,328,196,328,196", "AL",
"267,182,272,215,294,216,293,206,300,182,267,182,267,182", "AR",
"86,162,72,205,113,225,124,167,86,162,86,162", "AZ",
"14,86,6,110,22,166,54,198,69,189,29,123,38,90,14,86,14,86", "CA",
"137,122,133,160,191,169,191,128,137,122,137,122", "CO",
"444,91,443,99,456,92,456,88,444,91,444,91", "CT",
"445,158,460,158,460,168,445,158", "DC",
"428,122,433,134,436,132,430,121,428,122", "DE",
"450,126,464,135", "DE",
"335,240,335,244,371,242,391,259,410,293,414,279,390,238,335,240,335,240", "FL",
"352,194,366,234,388,233,389,216,364,192,352,194,352,194", "GA",
"119,269,185,312", "HI",
"248,101,254,126,289,126,286,97,248,101,248,101", "IA",
"86,24,73,90,114,99,118,76,100,72,86,24,86,24", "ID",
"302,111,293,135,313,162,321,147,316,111,302,111,302,111", "IL",
"326,119,328,154,344,143,343,114,326,119,326,119", "IN",
"199,140,196,167,257,170,254,141,199,140,199,140", "KS",
"325,172,324,161,341,160,348,148,366,149,367,164,325,172,325,172", "KY",
"274,224,277,255,307,254,307,244,290,244,291,221,274,224,274,224", "LA",
"471,79,488,88", "MA",
"442,82,442,89,458,84,464,89,466,87,457,79,442,82,442,82", "MA",
"465,142,483,153", "MD",
"397,128,426,122,432,135,437,136,431,142,419,138,420,128,411,128,409,126,397,129,397,128", "MD",
"462,27,457,52,461,64,476,38,469,25,462,27,462,27", "ME",
"309,56,361,61,359,107,331,110,309,56,309,56", "MI",
"243,36,250,92,277,92,268,65,283,46,243,36,243,36", "MN",
"260,134,267,173,308,173,283,133,260,134,260,134", "MO",
"322,196,321,240,299,237,301,204,322,196,322,196", "MS",
"96,22,111,64,176,73,180,33,96,22,96,22", "MT",
"388,171,374,181,415,186,423,166,388,171,388,171", "NC",
"189,33,186,59,240,63,236,36,189,33,189,33", "ND",
"184,104,182,119,200,121,200,134,248,135,237,108,184,104,184,104", "NE",
"453,51,459,74,449,79,450,61,452,60,452,51,453,51,453,51", "NH",
"435,27,452,36", "NH",
"432,102,431,109,436,114,431,121,437,125,441,111,437,111,438,103,432,102,432,102", "NJ",
"132,170,125,221,176,227,180,174,132,170,132,170", "NM",
"45,93,37,122,72,173,82,102,45,93,45,93", "NV",
"433,59,439,77,440,99,430,98,429,91,391,100,401,87,417,78,419,63,433,59", "NY",
"450,99,440,106,445,109,455,100,450,99", "NY",
"379,112,350,116,352,139,368,143,381,127,379,112,379,112", "OH",
"186,172,186,175,212,177,214,201,259,207,259,174,186,172,186,172", "OK",
"27,42,13,75,64,91,72,51,27,42,27,42", "OR",
"386,106,388,125,428,117,425,99,386,106,386,106", "PA",
"421,229,485,260", "PR",
"472,100,482,110", "RI",
"458,86,457,94,461,89,458,86", "RI",
"375,191,395,210,410,193,375,191,375,191", "SC",
"187,69,183,97,240,101,241,71,187,69,187,69", "SD",
"315,180,311,190,355,188,372,172,315,180,315,180", "TN",
"188,180,183,235,151,230,174,258,184,250,202,254,223,292,242,263,266,252,266,216,204,205,207,181,188,180,188,180", "TX",
"97,103,86,153,126,160,131,120,112,119,114,106,97,103,97,103", "UT",
"411,135,383,163,425,158,411,135,411,135", "VA",
"454,272,481,307", "VI",
"416,34,430,43", "VT",
"437,58,442,80,446,79,447,54,437,58,437,58", "VT",
"41,6,82,17,75,45,34,37,41,6,41,6", "WA",
"282,62,283,81,293,87,297,103,313,102,308,66,282,62,282,62", "WI",
"385,133,374,148,383,156,401,133,385,133,385,133", "WV",
"126,73,122,111,174,120,178,80,126,73,126,73", "WY",
);
while (my ($coords, $state) = splice(@shapes, 0, 2))
{
next unless ($count{'stateus'}->{$state});
my $shape = "poly";
if ($coords =~ /^[^,]+,[^,]+,[^,]+,[^,]+$/) { $shape = "RECTANGLE"; }
$ret .= "<area shape='$shape' alt='$state' coords=\"$coords\" href=\"/directory.bml?loc_cn=US&amp;loc_st=$state&amp;opt_sort=ut\" onmouseover=\"updateStatus('";
$ret .= BML::eall($state{$state});
$ret .= " - ";
$ret .= ($count{'stateus'}->{$state}+0);
$s = $count{'stateus'}->{$state} != 1 ? "s" : "";
$ret .= " Journal$s'); return true;\" onmouseout=\"updateStatus(''); return true;\" />\n";
}
$ret .= "</map>\n";
# by country
$ret .= "<?h1 $ML{'.browse.country.title'} h1?><?p $ML{'.browse.country.desc'} p?>";
$ret .= "<table style='margin-left: 20px' cellpadding='5'><tr valign='top'><td align='left'><ul>";
my $total = scalar(keys %{$count{'country'}});
my $count = 0;
my $col = 0;
foreach (sort { $country{$a} cmp $country{$b} } keys %{$count{'country'}})
{
$count++;
$ret .= "<li><a href=\"/directory.bml?loc_cn=$_&amp;opt_sort=ut\">$country{$_}</a> <i>($count{'country'}->{$_})</i></li>\n";
if ($col==0 && $count > ($total/2)) { $ret .= "</ul></td><td align='left'><ul>"; $col = 1; }
}
$ret .= "</ul></td></tr></table>\n";
return $ret;
}
my $remote = LJ::get_remote();
# unless (LJ::check_priv($remote, "betatest", "directory") ||
# LJ::get_cap($remote, "directory") ||
# (@filters == 1 && $filters[0] eq "int" && $GET{'opt_format'} eq "simple"))
#{
# return $ML{'.error.accounttype'};
#}
unless (LJ::Dir::do_search($dbr, $dbdir, \%FORM, \@matches, \%info)) {
return "<?h1 $ML{'Error'} h1?><?p $ML{'Error'}: $info{'errmsg'} p?>";
}
# opt_format and opt_sort might've been modified by do_search,
# filling in appropriate defaults based on other parameters
my $opt_format = $FORM{'opt_format'};
my $opt_sort = $FORM{'opt_sort'};
$info{'allwhat'} ||= "users";
if ($info{'searching'}) {
my ($uri, $args) = (BML::get_uri(), BML::get_query_string());
$uri .= '?' . $args if $args;
$head .= "<meta http-equiv='Refresh' content='3;URL=" . LJ::ehtml($LJ::SITEROOT . $uri) . "' />\n";
return "<center><b>$ML{'.search.title'}<img src='$LJ::IMGPREFIX/searchingdots.gif' alt='...' width='18' height='12' /></b><p>$ML{'.search.monkey'}</p></center>";
}
if ($POST{'com_do'} || $GET{'com_do'}) {
$ret .= "<a href=\"/community/search.bml\">&lt;&lt; $ML{'.search.new'}</a><p>\n";
} else {
$ret .= "<a href=\"/directorysearch.bml\">&lt;&lt; $ML{'.search.new'}</a><p>\n";
}
unless (@{$info{'english'}}) {
push @{$info{'english'}}, "wish to be listed in the public directory";
}
$ret .= "Below are all $info{'allwhat'} that ";
my $count_preds = @{$info{'english'}};
### remove consecutive "are"s
my $last_are = 0;
foreach (@{$info{'english'}}) {
if (/^are /) {
if ($last_are) {
s/^are //;
}
$last_are = 1;
} else {
$last_are = 0;
}
}
my $last = pop @{$info{'english'}};
if (@{$info{'english'}}) {
$ret .= join(", ", map { LJ::ehtml($_) } @{$info{'english'}}) . ", and ";
}
$ret .= LJ::ehtml($last) . ".\n";
if ($info{'overflow'}) {
$ret .= BML::ml(".search.overflow", {'count' => $info{'count'}});
}
if ($count_preds == 1 && $GET{'int_like'}) {
my $intid = $dbr->selectrow_array("SELECT intid FROM interests WHERE interest=?",
undef, $GET{'int_like'});
LJ::run_hooks("interests_bml", {
'intid' => $intid,
'int' => $interest,
'ret' => \$ret,
}) if $intid;
}
########## make the navcrap
my $navcrap;
$navcrap .= "<?standout <CENTER><FONT FACE=\"Arial,Helvetica\" SIZE=-1><B>".BML::ml(".navcrap.matches", {'count' => $info{'count'}})."</B>";
if ($info{'count'}) {
if ($info{'pages'} > 1) {
$navcrap .= "<BR>";
$navcrap .= BML::ml(".navcrap.xofy", {'curpage' => $info{'page'}, 'totpages' => $info{'pages'}, 'reca' => $info{'first'}, 'recb' => $info{'last'}});
$navcrap .= "<BR>";
my $left = "<B>&lt;&lt;</B>";
if ($info{'page'} > 1) { $left = "<A HREF=\"" . BML::self_link({ 'page' => $info{'page'}-1 }) . "\">$left</A>"; }
my $right = "<B>&gt;&gt;</B>";
if ($info{'page'} < $info{'pages'}) { $right = "<A HREF=\"" . BML::self_link({ 'page' => $info{'page'}+1 }) . "\">$right</A>"; }
$navcrap .= $left . " ";
for (my $i=1; $i<=$info{'pages'}; $i++) {
my $link = "[$i]";
if ($i != $info{'page'}) { $link = "<A HREF=\"" . BML::self_link({ 'page' => $i }) . "\">$link</A>"; }
else { $link = "<FONT SIZE=+1><B>$link</B></FONT>"; }
$navcrap .= "$link ";
}
$navcrap .= "$right";
}
$navcrap .= "</FONT></CENTER> standout?>\n";
} else {
$navcrap .= "</CENTER> standout?>\n";
}
####### end navcrap
$ret .= $navcrap . "<P>";
unless ($info{'count'}) { return $ret; }
if ($opt_sort eq "loc") {
LJ::load_codes({ state => \%state, country => \%country });
}
if ($opt_format eq "simple")
{
my $showloc = $GET{'opt_sort'} eq "loc" ? 1 : 0;
my %last = ();
$ret .= "<ul>\n";
foreach my $rec (@matches)
{
if ($showloc) {
if ($last{'country'} ne $rec->{'country'} ||
$last{'state'} ne $rec->{'state'} ||
$last{'city'} ne $rec->{'city'}) {
foreach (qw(country state city)) { $last{$_} = $rec->{$_}; }
my $country = $country{$rec->{'country'}};
my ($state, $city);
if ($rec->{'state'}) {
$state = ", " . ($rec->{'country'} eq "US" ? $state{$rec->{'state'}} : $rec->{'state'});
}
if ($rec->{'city'}) {
$city = ", $rec->{'city'}";
}
$ret .= "<?h1 $country$state$city h1?><BR>";
}
}
$ret .= "<a href=\"/userinfo.bml?user=$rec->{'user'}\">";
if ($rec->{'journaltype'} eq "C") {
$ret .= "<img border='0' src=\"$LJ::IMGPREFIX/community.gif\" width='16' height='16' align='absmiddle'>";
} else {
$ret .= "<img border='0' src=\"$LJ::IMGPREFIX/userinfo.gif\" width='17' height='17' align='absmiddle'>";
}
$ret .= "</a> ";
$ret .= "<a href=\"/users/$rec->{'user'}/\">$rec->{'user'}</A> - <b>" . LJ::ehtml($rec->{'name'}) . "</b>, <font size='-1' face=\"Arial\"><i>Updated ";
$ret .= LJ::ago_text($rec->{'secondsold'});
$ret .= "</i></font><br />\n";
}
$ret .= "</ul>\n";
}
if ($opt_format eq "com")
{
$ret .= "<TABLE CELLSPACING=3>\n";
$ret .= "<TR><TD>&nbsp;</TD><TD><B>$ML{'.user'}</B></TD><TD><B>$ML{'.community'}</B></TD><TD><B>$ML{'.open'}</B></TD><TD><B>$ML{'.post'}</B></TD></TR>\n";
foreach my $rec (@matches)
{
$ret .= "<TR VALIGN=TOP>";
$ret .= "<TD NOWRAP><A HREF=\"/userinfo.bml?user=$rec->{'user'}\">";
if ($rec->{'journaltype'} eq "C") {
$ret .= "<IMG BORDER=0 SRC=\"$LJ::IMGPREFIX/community.gif\" WIDTH=16 HEIGHT=16 ALIGN=ABSMIDDLE>";
} else {
$ret .= "<IMG BORDER=0 SRC=\"$LJ::IMGPREFIX/userinfo.gif\" WIDTH=17 HEIGHT=17 ALIGN=ABSMIDDLE>";
}
$ret .= "</A></TD>";
$ret .= "<TD><B><A HREF=\"/community/$rec->{'user'}/\">$rec->{'user'}</A></B></TD>";
$ret .= "<td>" . LJ::ehtml($rec->{'name'}) . "</td>";
my $color;
if ($rec->{'membership'} eq "open") { $color = "green"; } else { $color = "red"; }
$ret .= "<TD ALIGN=CENTER><IMG SRC=\"$LJ::IMGPREFIX/dot_$color.gif\" WIDTH=14 HEIGHT=14></TD>";
if ($rec->{'postlevel'} eq "members") { $color = "green"; } else { $color = "red"; }
$ret .= "<TD ALIGN=CENTER><IMG SRC=\"$LJ::IMGPREFIX/dot_$color.gif\" WIDTH=14 HEIGHT=14></TD>";
$ret .= "</TR>";
}
$ret .= "</TABLE>\n";
}
if ($opt_format eq "pics")
{
my $showloc = $GET{'opt_sort'} eq "loc" ? 1 : 0;
my %last = ();
my %pic;
my @picids = map { [$_, $_->{'defaultpicid'}] } @matches;
LJ::load_userpics(\%pic, \@picids);
my $count = 0;
my $pos = 0;
my $more_to_show = 0;
$ret .= "<TABLE CELLPADDING=3>\n";
foreach my $rec (@matches)
{
if ($pos==5) { $ret .= "</TR>\n"; }
$pos++; $pos %= 5;
if ($showloc) {
if ($last{'country'} ne $rec->{'country'} ||
$last{'state'} ne $rec->{'state'} ||
$last{'city'} ne $rec->{'city'}) {
foreach (qw(country state city)) { $last{$_} = $rec->{$_}; }
my $country = $country{$rec->{'country'}};
my ($state, $city);
if ($rec->{'state'}) {
$state = ", " . ($rec->{'country'} eq "US" ? $state{$rec->{'state'}} : $rec->{'state'});
}
if ($rec->{'city'}) {
$city = ", $rec->{'city'}";
}
if ($pos > 1) { $ret .= "</TR>"; $pos = 1; }
$ret .= "</TABLE>";
$ret .= "<?h1 $country$state$city h1?><BR>";
$ret .= "<TABLE CELLPADDING=3>\n";
}
}
if ($pos==1) { $ret .= "<TR ALIGN=CENTER VALIGN=BOTTOM>\n"; }
my $picid = $rec->{'defaultpicid'};
my $updateago = LJ::ago_text($rec->{'secondsold'});
my $img;
if ($picid) {
$img = "<IMG SRC=\"$LJ::USERPIC_ROOT/$picid/$rec->{'userid'}\" ALT=\"$_->{'user'}\" WIDTH=$pic{$picid}->{'width'} HEIGHT=$pic{$picid}->{'height'} BORDER=0><BR>";
}
$ret .= "<TD>";
$ret .= $img;
$ret .= LJ::ljuser($rec->{'user'});
$ret .= "<BR><FONT SIZE=-1><B>$Ml{'.update'} </B> $updateago</FONT></TD>\n";
}
$ret .= "</TR></TABLE>\n";
}
if ($info{'pages'} > 1) { $ret .= $navcrap; }
return $ret;
_code?>
<=body
head<=
<meta name="robots" content="noindex,nofollow" />
<?_code return $head; _code?>
<=head
page?>