(.*)<\/span><\/a><\/h1>/", $formattedSong, $matches);
$chord2html->artistname = stripslashes($matches[1]);
$artistname = $chord2html->artistname;
$chord2html->sourceurl = $fileurl;
} else {
if ($songbook != "source") {
//Check if this song has been corrected
$dbLinkAdmin = mysql_pconnect(MY_DATABASE_HOST, MY_DATABASE_USERNAME, MY_DATABASE_PASSWORD);
mysql_select_db(guitaradmin, $dbLinkAdmin);
//By error some songs where inserted into correctedsongs with "replaceqmark" at the end. This fix searches for both versions
$fileurl2 = $fileurl . "pppppp";
$fileurl2 = str_replace("replaceqmarkpppppp", "", $fileurl2);
$fileurl2 = str_replace("?pppppp", "", $fileurl2);
$fileurl2 = str_replace("pppppp", "", $fileurl2);
$query = "select chopro,editor from guitaradmin.correctedsongs where (url='" . addslashes(str_replace("?", "replaceqmark", $fileurl)) . "' or url='" . addslashes(str_replace("?", "replaceqmark", $fileurl2)) . "') and chopro IS NOT NULL";
$result = sql_query($query, $dbLinkAdmin);
if (($row = mysql_fetch_object($result)) && ($original != 1)) {
$song = stripslashes($row->chopro);
if (strpos("&", $url) == "") {
$linktooriginal = "/chord.pere/" . str_replace("http://", "", $url) . "?1944-06-06=always&original=1&tuning=$tuning&transpose=$transpose";
} else {
$linktooriginal = "/chord.pere/" . str_replace("http://", "", $url) . "&1944-06-06=always&original=1&tuning=$tuning&transpose=$transpose";
}
//$correctcomment = "\n";
$myFile = $song;
} else {
$myFile = createChopro($fileurl, $fileurl, "no");
if ($original == 1) $correctcomment = "\n";
}
//turns on debug!!
if ($debug == true) {
header("Content-Type: text/plain");
print $myFile;
exit;
}
//This should happen only if it is a chopro-file already!
// X
} else {
$timer["before backup if already chopro"] = microtime(true);
//If this is called from the songbook, it will give the song from the songbook whatever happens
if ($songbook == "source") {
$dbLinkAdmin = mysql_pconnect(MY_DATABASE_HOST, MY_DATABASE_USERNAME, MY_DATABASE_PASSWORD);
mysql_select_db(guitaradmin, $dbLinkAdmin);
$queryUrl = str_replace("?", "replaceqmark", $url);
if (strpos($url, "&songbook") != "") {
$queryUrl = substr($queryUrl, 0, strpos($queryUrl, "&songbook"));
}
$fileurl = str_replace("replaceqmark", "?", $queryUrl);
//If this is from someone elses songbook
if ($owner == "") $owner = $username;
//Chenged this from %20 to + - 22122006
$queryUrl = str_replace(" ", "%20", urldecode($queryUrl));
$owner = str_replace("'", "NO INSERTS HERE", $owner);
//Check for abuse or inserts
//if(strstr($owner,"punbb")){
// exit;
//}
$query = "select chopro,title,artist from guitaradmin.songbook where url='" . addslashes($queryUrl) . "' and owner='$owner' order by chopro desc";
$result = sql_query($query, $dbLinkAdmin);
$row = mysql_fetch_array($result);
$timer["another checkpoint - 111"] = microtime(true);
if ($row[0] != "") {
$myFile.= stripslashes($row[0]);
} else {
//Give it one more try.. This time see if the song could be stored under somebody else
$query = "select chopro from songbook where url='" . addslashes($queryUrl) . "' limit 1";
$result = sql_query($query, $dbLinkAdmin);
$row = mysql_fetch_array($result);
$timer["another checkpoint - 222"] = microtime(true);
if ($row[0] != "") {
//$myFile = "{t: ".stripslashes($row[1])."}\n";
//$myFile .= "{st: ".stripslashes($row[2])."}\n";
$myFile = stripslashes($row[0]);
} else {
//$timer["another checkpoint - 333"] = microtime(true);
//Now it is time to give up
//Giveerror message, and send a mail to admin
echo $query;
print ("
File not in songbook. Error code: 555.
This is a serious internal error.
It is greatly appreciated it you inform us about this by sending a mail to admin@chordie.com.
Please describe what you did before getting this error message, and include the address of this page.
Thank you!
Debug info: $query
");
$mailmessage = getallinfo();
//No point in sending mail if it is generated by a bot
if (strstr($mailmessage, "oogle") == "") {
@mail("admin@chordie.com", "Error 555 - File not in songbook", "$mailmessage\n$query", "From: admin@chordie.com");
}
//print $query;
exit;
}
}
$timer["another checkpoint - 444"] = microtime(true);
$unFormattedSong = $myFile;
} else {
$timer["another checkpoint - 555"] = microtime(true);
//Denne skal benytte seg av cachen!!!!!
$timer["getting it from cache"] = microtime(true);
$myFile = getCachedFile($fileurl);
}
//Check if the song is in the users' songbook
//If it is... .. just give this instead
//THIS IS MOST LIKELY OBSOLETE NOW!!!
//SEE NEW FUNCTION ABOVE
//if ($myFile == "FALSE" && $user !="" && $fileName!=""){
// $dbLinkAdmin2 = mysql_pconnect(MY_DATABASE_HOST, MY_DATABASE_USERNAME, MY_DATABASE_PASSWORD);
// mysql_select_db(guitaradmin, $dbLinkAdmin2);
// $queryFileName = addslashes(str_replace("?","replaceqmark",$fileName));
// $query = "select chopro from songbook where url='$queryFileName' and owner='$user'";
// $result = sql_query($query, $dbLinkAdmin);
// $row = mysql_fetch_array($result);
// if ($row[0]!=""){
// $myFile = $row[0];
// }
//}
if ($myFile == "FALSE") {
//$timer["another checkpoint - 666"] = microtime(true);
$myFile = @file($fileurl);
if (!$myFile) {
include ('include/notavailiable.inc');
exit;
}
$myFile = implode($myFile, "");
}
}
//XOK
//$timer["after chopro is created"] = microtime(true);
//Trims any -tags enclosing the file
$myFile = trimPre($myFile);
//If there should be problems with lineshifts and cache. Enable this.
//$myFile = str_replace("\r", "", $myFile);
//Problems with some strange chords. Deletes paranthesis
$myFile = str_replace("[/]", "", $myFile);
$myFile = str_replace("[(", "[", $myFile);
$myFile = str_replace(")]", "]", $myFile);
$myFile = str_replace("[+", "", $myFile);
$myFile = str_replace("++]", "", $myFile);
$myFile = str_replace("[A(", "[A", $myFile);
//Test on: http://chordie.com/chord.pere/www.thudspace.net/tabs/s/springsteen_bruce/one_step_up.pro
//This song contains two problems for transposing: Short from of {define: is used, and tabulator is used inside brackets.
$myFile = str_replace("{d:", "{define:", $myFile);
if (strpos($myFile, "\t") != "") {
//Changed * to {1,15}. This is taking too long time, and times out.
//This should make it faster, but I am not sure if it will work
$myFile = preg_replace("/(\{.{1,15}?)\t(.{1,15}?\})/s", "\\1 \\2", $myFile);
}
$timer["after heavy reg exp"] = microtime(true);
//Give credit
switch (TRUE) {
//case (strstr($PHP_SELF, "pjandphil")): $myFile .= "
the song is from PJ's Guitar Chords & Lyrics site"; break;
//case (strstr($url, "pjandphil")): $myFile .= "
\n"; break;
case ($pjandphil == 1):
$myFile.= "
\n";
break;
case (strstr($url, "across_a_painted_sky.crd")):
$myFile.= "
";
break;
case (strstr($url, "paul_cotton_do_what_you_do.txt")):
$myFile.= "
";
break;
case (strstr($url, "cotton_paul/not_out_of_mind.crd")):
$myFile.= "
";
break;
}
$timer["(chord.pere:185)before running the php-chord-class-script"] = microtime(true);
$flatFile = $myFile;
//This fixes a small error where the chord2htmlclass formats multiple tags on same line wrong.
$myFile = str_replace("}{", "}\n{", $myFile);
//Fix a small error where PJ overlaps guitarchords when printing
$myFile = str_replace("
the song is from PJ's Guitar Chords & Lyrics site", "", $myFile);
if ($correctsong) {
//Small bug fix when replaceqmark is at the end of the url
$url = $url . "pppppp";
$url = str_replace("replaceqmarkpppppp", "", $url);
$url = str_replace("pppppp", "", $url);
$dbLink = mysql_pconnect(MY_DATABASE_HOST, MY_DATABASE_USERNAME, MY_DATABASE_PASSWORD);
$query = "select * from guitaradmin.correctedsongs where url='" . addslashes($url) . "'";
$result = sql_query($query, $dbLink);
if ($row = mysql_fetch_object($result)) {
//Get songid
$songid = $row->ID;
} else {
//Insert url and chopro
$md5chopro = choproChecksum($myFile);
$query = "insert into guitaradmin.correctedsongs set url='" . addslashes($url) . "',editor='" . addslashes($user) . "',md5chopro='" . addslashes($md5chopro) . "',originalchopro='" . addslashes($myFile) . "'";
sql_query($query, $dbLink);
//Get songid
$query = "select * from guitaradmin.correctedsongs where url='" . addslashes($url) . "'";
$result = sql_query($query, $dbLink);
$row = mysql_fetch_object($result);
$songid = $row->ID;
}
//Remove this song from the cache
//This is not really testet - should checked - added 20061218
$Cache_Lite_song->remove($contentid);
header("Location: /correctsong.php?editsongid=$songid");
}
//Add chord definitions
$define = str_replace(" ", "+", $define);
$define = str_replace("++", "+", $define);
$definearray = explode("+", $define);
for ($i = 0;$i < count($definearray);$i++) {
$definetext = "";
if (trim($definearray[$i]) != "") $definetext.= ("\n{define: " . substr($definearray[$i], 0, -8) . " " . substr($definearray[$i], -1, 1) . " " . substr($definearray[$i], -8, 1) . " " . substr($definearray[$i], -7, 1) . " " . substr($definearray[$i], -6, 1) . " " . substr($definearray[$i], -5, 1) . " " . substr($definearray[$i], -4, 1) . " " . substr($definearray[$i], -3, 1) . "}");
$myFile.= $definetext;
}
//Set the session variables
//Used for printing
$printvarsong = $myFile;
$printvartuning = $tuning;
//Chord2html needs array
$myFile = explode("\n", $myFile);
//Creates the Chord-object
$chord2html = new chord2html();
$chord2html->songurl = $url;
$chord2html->user = $user;
$chord2html->file = $myFile;
$chord2html->showhtmlheader = "0";
$chord2html->showhtmlfooter = "0";
$chord2html->imgdir = "ramimages";
$chord2html->imgdirhtml = "/ramimages";
$chord2html->tuning = $tuning;
$chord2html->transposevalue = ($transpose + 12) % 12;
$chord2html->sourceurl = $fileurl;
$chord2html->clickable_grid_images = "voicings.php";
$chord2html->define = $define;
$chord2html->return = $url;
$chord2html->mysqlpassword = "nievslige";
$chord2html->showversion = 0;
$chord2html->htmlmode = $htmlmode;
$formattedSong = $chord2html->createhtml();
$artistname = $chord2html->artistname;
$songtitle = $chord2html->songtitle;
//Removes song for copyright reasons
if (trim(strtolower($chord2html->songtitle)) == "tainted love") {
print ("
This song is removed by transcribers/authors request
");
include 'include/footer.inc';
exit;
}
//Remove pjandphil
//if (strstr($url,"pjandphil") != "" || strstr($url,"murphypj") != ""){
// print ("
");
// include 'include/footersign.inc';
// include 'include/footer.inc';
// exit;
//}
$blockhash = strtolower($chord2html->artistname . substr($chord2html->songtitle, 0, 5));
//Debugging - allows admin to see what is going on
if ($user == "andymo" || $user == "admin") $blockhash = "";
//Check if this is clocked by musicsales - sets songisblocked variable
include ('include/musicsalesblock.inc');
if ($songisblocked == "1") {
print ("
");
print ("I have received a letter from someone claiming that this song violates their copyright. Until these issues are solved, I have chosen to block this song from being shown on Chordie.
");
$query = "update topsongbooksongs set textonly='1' where url='$url'";
sql_query($query, $dbLinkAdmin);
include 'include/footer.inc';
exit;
}
//Blocking all Beatles songs for UK users
if (strtolower($chord2html->artistname) == "beatles") {
?>
//This script loads two images. One from an area controlled by a .htaccess-file, and one in a safe area.
//If only the image in the safe area is loaded, the user will be forwarded to an error page
print ("");
print ("");
//debug
//print ("");
}
$testtext2 = strtolower($chord2html->artistname);
if ($user == "andymo" || $user == "admin") $testtext2 = "xxx";
switch ($testtext2) {
case "anal cunt";
print ("Chordie do no longer index this band.
");
include 'include/footer.inc';
exit;
break;
}
$timer["after running the php-chord-class-script"] = microtime(true);
$formattedSong = str_replace("
\n\n\n\n", "", $formattedSong);
//replaces strange paragraph
$formattedSong = str_replace(chr(213), "'", $formattedSong);
// Save the page to cache
if ($writeToContentCache == "yes") {
$Cache_Lite_song->save($formattedSong, $contentid);
}
}
$timer["almost at the end - checking if user is logged in"] = microtime(true);
if ($username) {
//Clean up the url
if (strstr($url, "&transpose") != "") {
$cleanurl = substr($url, 0, strpos($url, "&transpose"));
} else {
$cleanurl = $url;
}
$dbLinkAdmin = mysql_pconnect(MY_DATABASE_HOST, MY_DATABASE_USERNAME, MY_DATABASE_PASSWORD);
mysql_select_db(guitaradmin, $dbLinkAdmin);
//Add songs to songbook
if ($songbook == "add") {
$title = $chord2html->songtitle;
$artist = $chord2html->artistname;
//Only insert if no duplicates exists
$query = "select id from songbook where owner='$user' and url='" . addslashes($cleanurl) . "' and songbookname='" . addslashes($selectedsongbook) . "';";
$duplicates = mysql_num_rows(sql_query($query, $dbLinkAdmin));
//Clean up song - remove comments
//Here there is an error. Also messes up things like A#. Should only delete lines starting with #. Disabled for now
//$flatFile = preg_replace("/^#(.*)\n/","",$flatFile);
if (strpos($flatFile, "\n/", "", $flatFile);
//Add the chord-definitions
//Add chord definitions
$define = str_replace(" ", "+", $define);
$define = str_replace("++", "+", $define);
$definearray = explode("+", $define);
for ($i = 0;$i < count($definearray);$i++) {
$definetext = "";
if (trim($definearray[$i]) != "") $definetext.= ("\n{define: " . substr($definearray[$i], 0, -8) . " " . substr($definearray[$i], -1, 1) . " " . substr($definearray[$i], -8, 1) . " " . substr($definearray[$i], -7, 1) . " " . substr($definearray[$i], -6, 1) . " " . substr($definearray[$i], -5, 1) . " " . substr($definearray[$i], -4, 1) . " " . substr($definearray[$i], -3, 1) . "}");
$flatFile.= $definetext;
}
//And now it is time to add it to the songbook
if ($duplicates == "") {
$htmlbody = addslashes(extractString($formattedSong, "