<?php
/*----------------------------------------------------------
LySite
Brad Landis (hide@address.com)
Copyright (C) 2005 Brad Landis
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth
Floor, Boston, MA 02110-1301, USA.
----------------------------------------------------------*/
ob_start();
require("includes.php");
/* --- LYRICS TODO ---
** Open Source:
** Installation System
** Album Focused Option
**/
function log_search($term) {
$query = "SELECT * FROM top_searches WHERE search_term='$term' AND ip=".ip2long($_SERVER['REMOTE_ADDR']);
if($results = mysql_query($query)) {
if(mysql_num_rows($results) >= 1) {
return false;
}
}
$query = "INSERT INTO top_searches SET search_term='$term',date=NOW(),ip=".ip2long($_SERVER['REMOTE_ADDR']);
if(mysql_query($query)) {
if(mysql_affected_rows() >= 1) {
return true;
}
} else trigger_error(mysql_error());
return false;
}
if($_GET['search']) {
trim($_GET['search']);
if(!isset($_POST['from_link']) && text_is_clean($_GET['search'])) {
if(log_search($_GET['search'])) {
log_event("Search: \"".stripslashes($_GET['search'])."\"","<a href=\"http://www.google.com/search?q=".urlencode(stripslashes($_GET['search']))."\">Google Search</a>","index.php?search=".urlencode(stripslashes($_GET['search'])),-1);
}
} else {
log_event("Search (Censored): \"".stripslashes($_GET['search'])."\"","<a href=\"http://www.google.com/search?q=".urlencode(stripslashes($_GET['search']))."\">Google Search</a>","index.php?search=".urlencode(stripslashes($_GET['search'])));
}
$query = "SELECT lid FROM lyrics WHERE title='$_GET[search]'".(is_admin_user() ? " AND approved='y'" : '');
if($results = mysql_query($query)) {
if(mysql_num_rows($results) == 1) {
$line = mysql_fetch_assoc($results);
header("Location: songs.php?song=$line[lid]");
}
}
}
include('header.php');
if (isset($_GET['search'])) {
echo "<div class='block'>";
echo "<h2>Searched for '".stripslashes($_GET['search'])."'</h2>";
$query = "(SELECT lid,title,author,approved FROM lyrics WHERE ".(!is_admin_user()?"approved='y' AND ": "")."title LIKE '%$_GET[search]%' ORDER BY title) UNION (SELECT lid,title,author,approved FROM lyrics WHERE ".(is_admin_user()?"approved='y' AND ":"")."author LIKE '%$_GET[search]%' OR REPLACE(text, '\n', '') LIKE '%$_GET[search]%' ORDER BY title)";
if($results = mysql_query($query)) {
if(isset($search_in_title)) {
while($line = mysql_fetch_assoc($search_in_title))
echo "<a href='songs.php?song=$line[lid]'".($line['approved'] == 'n'?" class='unapproved'":"").">$line[title]".($line['author'] != ""?" <small>($line[author])</small>":"")."</a><br>\n";
echo "<br>\n";
}
if(mysql_num_rows($results) > 0) {
while($line = mysql_fetch_assoc($results)) {
echo "<a href='songs.php?song=$line[lid]'".($line['approved'] == 'n'?" class='unapproved'":"").">$line[title]".($line['author'] != ""?" <small>($line[author])</small>":"")."</a><br>\n";
}
} else {
$query = "SELECT lid, title, author, approved FROM lyrics WHERE ".(!is_admin_user()?"approved='y' AND ": "")."MATCH(title, text) AGAINST('$_GET[search]')";
if($results = mysql_query($query)) {
while($line = mysql_fetch_assoc($results)) {
echo "<a href='songs.php?song=$line[lid]'".($line['approved'] == 'n'?" class='unapproved'":"").">$line[title]".($line['author'] != ""?" <small>($line[author])</small>":"")."</a><br>\n";
}
}
}
} else {
trigger_error(mysql_error());
}
echo "</div>";
} else if($_GET['album']) {
header("Location: albums.php?album=$_GET[album]");
} else if($_GET['author']) {
header("Location: songs.php?author=$_GET[author]");
} else if($_GET['song']) {
header("Location: songs.php?song=$_GET[song]");
} else if(isset($_GET['song_list'])) {
if($_GET['song_list'] == 'by_author') {
header("Location: songs.php?order_by=author");
} else if($_GET['song_list'] == 'by_album') {
header("Location: albums.php");
} else {
header("Location: songs.php");
}
} else {
function homepage_songs() {
$query = "SELECT lid,title,approved FROM lyrics ".(!is_logged_in()?"WHERE (approved='y' OR user_id='".get_user_id()."') ":"")."ORDER BY lid DESC LIMIT 8";
if($results = mysql_query($query)) {
if(mysql_num_rows($results) > 0) {
echo "<h2>Newest Songs</h2>\n";
echo "<ol>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<li><a href='songs.php?song=$line[lid]'".($line['approved'] == 'n'?" class='unapproved'":"").">$line[title]</a><br>\n";
}
echo "</ol>\n";
}
} else {
trigger_error(mysql_error());
}
}
function homepage_searches() {
$query = "SELECT search_term,COUNT(*) cnt FROM top_searches GROUP BY search_term DESC ORDER BY cnt DESC LIMIT 8";
if($results = mysql_query($query)) {
if(mysql_num_rows($results) > 0) {
echo "<h2>Top Searches</h2>\n";
echo "<ol>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<li><a href='index.php?from_link=&search=".urlencode(strtolower($line['search_term']))."'>".ucwords($line['search_term'])."</a><br>\n";
}
echo "</ol>\n";
}
} else {
trigger_error(mysql_error());
}
}
function homepage_favorites() {
$query = "SELECT lyrics.title,lyrics.lid,COUNT(*) cnt FROM favs LEFT JOIN lyrics USING(lid) WHERE approved='y' GROUP BY lid ORDER BY cnt DESC,lyrics.title LIMIT 8";
if($results = mysql_query($query)) {
if(mysql_num_rows($results) > 0) {
echo "<h2>Top Favorites</h2>\n";
echo "<ol>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<li><a href='songs.php?song=$line[lid]'>$line[title]</a><br>\n";
}
echo "</ol>\n";
}
} else {
trigger_error(mysql_error());
}
}
function homepage_attachments() {
$query = "SELECT lyrics.* FROM attachments LEFT JOIN lyrics USING(lid)".(is_admin_user()?"":" WHERE (lyrics.approved='y' OR lyrics.user_id='".get_user_id()."') AND (attachments.approved='y' OR attachments.user_id='".get_user_id()."')")." GROUP BY lyrics.lid ORDER BY attachment_id DESC LIMIT 8";
if($results = mysql_query($query)) {
if(mysql_num_rows($results) > 0) {
echo "<h2>Newest Attachments</h2>\n";
echo "<ol>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<li><a href='songs.php?song=$line[lid]'".($line['approved'] == 'n'?" class='unapproved'":"").">$line[title]</a><br>\n";
}
echo "</ol>\n";
}
} else trigger_error(mysql_error());
}
function homepage_albums() {
$query = "SELECT * FROM albums ".(!is_admin_user()?"WHERE (approved='y' OR user_id='".get_user_id()."') ":'')."ORDER BY aid LIMIT 4";
if($results = mysql_query($query)) {
echo "<h2>Newest Albums</h2>\n<ol>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<li><img src='album_art/$line[album_art]' class='album_art' style='display:block; float:left;'><a href='albums.php?album=$line[aid]'".($line['approved'] != 'y'?" class='unapproved'":"").">$line[album_title]</a><br>\n$line[album_artist]<br clear='both'>\n";
}
echo "</ol>\n";
} else {
trigger_error(mysql_error());
}
}
if(!is_logged_in())
echo "<p style='font-weight: bold; text-align: center;'>Be sure to <a href='login.php'>Register</a> so you can subscribe, submit songs, and more.</p>\n";
echo "<table class='block' style='font-size:.9em;'>";
echo "<tr style='vertical-align: top;'><td width='50%'>";
call_user_func("homepage_".SITE_LEFT_BLOCK);
echo "<td width='50%'>";
call_user_func("homepage_".SITE_RIGHT_BLOCK);
echo "</table>\n";
echo "<p style='font-size: .8em;'>All songs copyright of their respected authors.</p>\n";
?>
<?php
}
include('footer.php');
?>