joaocasta Posted April 7, 2012 at 04:04 PM Report #448046 Posted April 7, 2012 at 04:04 PM Olá, esta modificação não parece estar correcta, aqui vai o codigo: <?php require_once("include/bittorrent.php"); dbconn(); //made by putyn @tbdev if(!function_exists(safe)){ function safe($var) { return str_replace(array('&', '>', '<', '"', '\'' ), array('&', '>', '<', '"', ''' ), str_replace(array('>', '<', '"', ''', '&'), array('>', '<', '"', '\'', '&'), $var)); } } $updir = "C:/appserv/www/legendas"; $maxsize = 500 * 1024; $action = (isset($_GET["action"]) ? safe($_GET["action"]) : (isset($_POST["action"]) ? safe($_POST["action"]) : '')); $mode = (isset($_GET["mode"]) ? safe($_GET["mode"]) : ""); if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($action == "upload" || $action == "edit") { $lang = isset($_POST["language"]) ? safe($_POST["language"]) : ""; if (empty($lang)) stderr("Upload failed","No language selected"); $releasename = isset($_POST["releasename"]) ? safe($_POST["releasename"]) : ""; if (empty($releasename)) stderr("Upload failed","Use a descriptive name for you subtitle"); $imdb = isset($_POST["imdb"]) ? safe($_POST["imdb"]) : ""; if (empty($imdb)) stderr("Upload failed","You forgot to add the imdb link"); $comment = isset($_POST["comment"]) ? safe($_POST["comment"]) : ""; $poster = isset($_POST["poster"]) ? safe($_POST["poster"]) : ""; $fps = isset($_POST["fps"]) ? safe($_POST["fps"]) : ""; $cd = isset($_POST["cd"]) ? safe($_POST["cd"]) : ""; if ($action == "upload") { $file = $_FILES["sub"]; if (!isset($file)) stderr("Upload failed","The file can't be empty!"); if ($file["size"] > $maxsize) stderr("Upload failed","What the hell did you upload?"); $fname = $file["name"]; $temp_name = $file["tmp_name"]; $ext = (substr($fname ,-3)); $allowed = array("srt", "sub","txt"); if (!in_array($ext,$allowed)) stderr("Upload failed","File not allowed only .srt , .sub , .txt files"); $new_name = md5(time()); $filename = "$new_name.$ext"; $date = get_date_time(); $owner = $CURUSER["id"]; mysql_query("INSERT INTO subtitles (name , filename,imdb,comment, lang, fps, poster, cds, added, owner ) VALUES (" .implode(",", array_map("sqlesc", array($releasename, $filename,$imdb,$comment, $lang, $fps,$poster, $cd , $date, $owner ))).")") or sqlerr(__FILE__, __LINE__); move_uploaded_file($temp_name, "$updir/$filename"); $id = mysql_insert_id(); header("Refresh: 0; url=subtitles.php?mode=details&id=$id"); }//end upload if ($action == "edit"){ $id = isset($_POST["id"]) ? 0 + $_POST["id"] : 0; if ($id == 0) stderr("Err","Not a valid id"); else { $res = mysql_query("SELECT * FROM subtitles WHERE id={$id} ") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); if (mysql_num_rows($res) == 0) stderr("Sorry","There is no subtitle with that id"); if ($CURUSER["id"] != $arr["owner"] && get_user_class() < UC_MODERATOR) bark("You're not the owner! How did that happen?\n"); $updateset = array(); if ($arr["name"] != $releasename) $updateset[] = "name = " . sqlesc($releasename); if ($arr["imdb"] != $imdb) $updateset[] = "imdb = " . sqlesc($imdb); if ($arr["lang"] != $lang) $updateset[] = "lang = " . sqlesc($lang); if ($arr["poster"] != $poster) $updateset[] = "poster = " . sqlesc($poster); if ($arr["fps"] != $fps) $updateset[] = "fps = " . sqlesc($fps); if ($arr["cds"] != $cd) $updateset[] = "cds = " . sqlesc($cd); if ($arr["comment"] != $comment) $updateset[] = "comment = " . sqlesc($comment); if (count($updateset) > 0) mysql_query("UPDATE subtitles SET " . join(",", $updateset) . " WHERE id ={$id} ") or sqlerr(__FILE__, __LINE__); header("Refresh: 0; url=subtitles.php?mode=details&id=$id"); } }//end edit }//end upload && edit }//end POST if($mode == "upload" || $mode == "edit") { if ($mode == "edit"){ $id = isset($_GET["id"]) ? 0 + $_GET["id"] : 0; if ($id == 0) stderr("Err","Not a valid id"); else { $res = mysql_query("SELECT id, name, imdb, poster, fps, comment, cds, lang FROM subtitles WHERE id={$id} ") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); if (mysql_num_rows($res) == 0) stderr("Sorry","There is no subtitle with that id"); } } stdhead("".($mode == "upload" ? "Upload new Subtitle" : "Edit subtitle ".$arr["name"]."").""); begin_main_frame(); begin_frame("".($mode == "upload" ? "New Subtitle" : "Edit subtitle ".$arr["name"]."")."");?> <script type="text/javascript"> function checkext(upload_field) { var re_text = /\.sub|\.srt|\.txt/i; var filename = upload_field.value; /* Checking file type */ if (filename.search(re_text) == -1) { alert("File does not have allowed (sub, srt, txt) extension"); upload_field.form.reset(); return false; } } </script> <form enctype="multipart/form-data" method="post" action="<?php$PHP_SELF?>"> <table style="width:400px; border:solid 1px #000000;" align="center" cellpadding="5" cellspacing="0" > <?php if ($mode == "upload") {?> <tr><td colspan="2" align="center" class="colhead"><font color="red"><b>Only .srt, .sub , .txt file are accepted<br>Max file size <?php=mksize($maxsize)?><b></font></td></tr> <?php } ?> <tr><td class="rowhead" style="border:none">Language <font color="red">*</font></td><td style="border:none"><select name="language" title="Select the subtitle language"> <option value="">- Select -</option> <option value="eng" <?php=($mode == "edit" && $arr["lang"] == "eng" ? "selected=\"selected\"" : "")?>>English</option> <option value="swe" <?php=($mode == "edit" && $arr["lang"] == "swe" ? "selected=\"selected\"" : "")?>>Swedish</option> <option value="dan" <?php=($mode == "edit" && $arr["lang"] == "dan" ? "selected=\"selected\"" : "")?>>Danish</option> <option value="nor" <?php=($mode == "edit" && $arr["lang"] == "nor" ? "selected=\"selected\"" : "")?>>Norwegian</option> <option value="fin" <?php=($mode == "edit" && $arr["lang"] == "fin" ? "selected=\"selected\"" : "")?>>Finnish</option> <option value="spa" <?php=($mode == "edit" && $arr["lang"] == "spa" ? "selected=\"selected\"" : "")?>>Spanish</option> <option value="fre" <?php=($mode == "edit" && $arr["lang"] == "fre" ? "selected=\"selected\"" : "")?>>French</option> </select> </td></tr> <tr><td class="rowhead" style="border:none" >Release Name <font color="red">*</font></td><td style="border:none" ><input type="text" name="releasename" size="50" value="<?php=($mode == "edit" ? $arr["name"] : "")?>" title="The releasename of the movie (Example:Disturbia.2007.DVDRip.XViD-aAF)"/></td></tr> <tr><td class="rowhead" style="border:none" >IMDB link <font color="red">*</font></td><td style="border:none" ><input type="text" name="imdb" size="50" value="<?php=($mode == "edit" ? $arr["imdb"] : "")?>" title="Copy&Paste the link from IMDB for this movie"/></td></tr> <?php if ($mode == "upload") {?> <tr><td class="rowhead" style="border:none" >SubFile <font color="red">*</font></td><td style="border:none" ><input type="file" name="sub" size="36" onChange="checkext(this)" title="Only .rar and .zip file allowed"/></td></tr> <?php }?> <tr><td class="rowhead" style="border:none" >Poster</td><td style="border:none" ><input type="text" name="poster" size="50" value="<?php=($mode == "edit" ? $arr["poster"] : "")?>" title="Direct link to a picture"/></td></tr> <tr><td class="rowhead" style="border:none" >Comments</td><td style="border:none" ><textarea rows="5" cols="45" name="comment" title="Any specific details about this subtitle we need to know"><?php=($mode == "edit" ? $arr["comment"] : "")?></textarea> <tr><td class="rowhead" style="border:none" >FPS</td><td style="border:none"><select name="fps"> <option value="0">- Select -</option> <option value="23.976" <?php=($mode == "edit" && $arr["fps"] == "23.976" ? "selected=\"selected\"" : "")?> >23.976</option> <option value="23.980" <?php=($mode == "edit" && $arr["fps"] == "23.980" ? "selected=\"selected\"" : "")?>>23.980</option> <option value="24.000" <?php=($mode == "edit" && $arr["fps"] == "24.000" ? "selected=\"selected\"" : "")?>>24.000</option> <option value="25.000" <?php=($mode == "edit" && $arr["fps"] == "25.000" ? "selected=\"selected\"" : "")?>>25.000</option> <option value="29.970" <?php=($mode == "edit" && $arr["fps"] == "29.970" ? "selected=\"selected\"" : "")?>>29.970</option> <option value="30.000" <?php=($mode == "edit" && $arr["fps"] == "30.000" ? "selected=\"selected\"" : "")?>>30.000</option> </select> </td></tr> <tr><td class="rowhead" style="border:none" >CD<br/>number</td><td style="border:none" ><select name="cd"> <option value="0" >- Select -</option> <option value="1" <?php=($mode == "edit" && $arr["cds"] == "1" ? "selected=\"selected\"" : "")?>>1CD</option> <option value="2" <?php=($mode == "edit" && $arr["cds"] == "2" ? "selected=\"selected\"" : "")?>>2CD</option> <option value="3" <?php=($mode == "edit" && $arr["cds"] == "3" ? "selected=\"selected\"" : "")?>>3CD</option> <option value="4" <?php=($mode == "edit" && $arr["cds"] == "4" ? "selected=\"selected\"" : "")?>>4CD</option> <option value="5" <?php=($mode == "edit" && $arr["cds"] == "5" ? "selected=\"selected\"" : "")?>>5CD</option> <option value="255" <?php=($mode == "edit" && $arr["cds"] == "255" ? "selected=\"selected\"" : "")?>>More</option> </select> </td></tr> <tr><td colspan="2" align="center" class="colhead"> <?php if($mode == "upload") {?> <input type="submit" value="Upload it" /> <input type="hidden" name="action" value="upload"> <?php } else { ?> <input type="submit" value="Edit it"/> <input type="hidden" name="action" value="edit" /> <input type="hidden" name="id" value="<?php=$arr["id"]?>" /> <?php}?> </td></tr> </table> </form> <?php end_frame(); end_main_frame(); stdfoot(); } //delete subtitle if ($mode == "delete") { $id = isset($_GET["id"]) ? 0 + $_GET["id"] : 0; if ($id == 0) stderr("Err","Not a valid id"); else { $res = mysql_query("SELECT id, name, filename FROM subtitles WHERE id={$id} ") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); if (mysql_num_rows($res) == 0) stderr("Sorry","There is no subtitle with that id"); $sure = (isset($_GET["sure"]) && $_GET["sure"] == "yes") ? "yes" : "no" ; if ($sure == "no" ) stderr("Sanity check...","Your are about to delete subtitile <b>".safe($arr["name"])."</b> . Click <a href=subtitles.php?mode=delete&id=$id&sure=yes>here</a> if you are sure.",false) ; else{ mysql_query("DELETE FROM subtitles WHERE id={$id} ") or sqlerr(__FILE__,__LINE__); $file = $updir.'/'.$arr["filename"]; @unlink($file); header("Refresh: 0; url=subtitles.php"); } } } //end delete subtitle elseif ($mode == "details") { $id = isset($_GET["id"]) ? 0 + $_GET["id"] : 0; if ($id == 0) stderr("Err","Not a valid id"); else { $res = mysql_query("SELECT s.id, s.name,s.lang, s.imdb,s.fps,s.poster,s.cds,s.hits,s.added,s.owner,s.comment, u.username FROM subtitles AS s LEFT JOIN users AS u ON s.owner=u.id WHERE s.id={$id} ") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); if (mysql_num_rows($res) == 0) stderr("Sorry","There is no subtitle with that id"); if ($arr["lang"] == "eng") $lang = "<img src=\"pic/flag/england.gif\" border=\"0\" alt=\"English\" title=\"English\" />"; elseif ($arr["lang"] == "swe") $lang = "<img src=\"pic/flag/sweden.gif\" border=\"0\" alt=\"Swedish\" title=\"Swedish\" />"; elseif ($arr["lang"] == "dan") $lang = "<img src=\"pic/flag/denmark.gif\" border=\"0\" alt=\"Danish\" title=\"Danish\" />"; elseif ($arr["lang"] == "nor") $lang = "<img src=\"pic/flag/norway.gih\" border=\"0\" alt=\"Norwegian\" title=\"Norwegian\" />"; elseif ($arr["lang"] == "fin") $lang = "<img src=\"pic/flag/finland.gif\" border=\"0\" alt=\"Finnish\" title=\"Finnish\" />"; elseif ($arr["lang"] == "spa") $lang = "<img src=\"pic/flag/spain.gif\" border=\"0\" alt=\"Spanish\" title=\"Spanish\" />"; elseif ($arr["lang"] == "fre") $lang = "<img src=\"pic/flag/france.gif\" border=\"0\" alt=\"French\" title=\"French\" />"; else $lang = "<b>Unknown</b>"; stdhead("Details for ".safe($arr["name"]).""); begin_main_frame(); ?> <table width="600" cellpadding="5" cellspacing="0" border="1" align="center" style="border-collapse:collapse;"> <tr><td width="150" rowspan="10" valign="top" align="center"><img src="<?php=$arr["poster"]?>" width="150" height="195" alt="<?php=$arr["name"]?>" /> <br/><br/><form action="downloadsub.php" method="post"> <input type="hidden" name="sid" value="<?php=$arr["id"]?>" /> <input type="submit" value=" " style="background:url(pic/down.png) no-repeat; width:124px;height:25px;border:none;" /> <input type="hidden" name="action" value="download" /> </form><br/> <a href="#" onclick="window.open('subtitles.php?mode=preview&id=<?php=$arr["id"]?>','','height=500,width=400,resizable=yes,scrollbars=yes')" ><img src="pic/preview.png" width="124" height="25" border="0" /></a> </td></tr> <tr><td align="left">Name : <b><?php=safe($arr["name"])?></b></td></tr> <tr><td align="left">IMDb : <a href="<?php=safe($arr["imdb"])?>" target="_blank" ><?php=safe($arr["imdb"])?></a></td></tr> <tr><td align="left">Language : <?php=$lang?></td></tr> <?php if (!empty($arr["comment"])) { ?> <tr><td align="left"><fieldset><legend><b>Comment</b></legend> <?php=safe($arr["comment"])?></fieldset></td></tr> <?php}?> <tr><td align="left">FPS : <b><?php print($arr["fps"] == 0 ? "Unknow" : safe($arr["fps"]));?></b></td></tr> <tr><td align="left">Cd# : <b><?php print($arr["cds"] == 0 ? "Unknow" : ($arr["cds"] == 255 ? "More than 5 " : safe($arr["cds"])) );?></b></td></tr> <tr><td align="left">Hits : <b><?php=$arr["hits"]?></b></td></tr> <tr><td align="left">Uploader : <b><a href="userdetails.php?id=<?php=$arr["owner"]?>" target="_blank"><?php=$arr["username"]?></a> <?php if ($arr["owner"] == $CURUSER["id"] || get_user_class() > UC_MODERATOR) { ?> <a href="subtitles.php?mode=edit&id=<?php=$arr["id"]?>"><img src="pic/edit.png" title="Edit Sub" style="border:none;padding:2px;" /></a> <a href="subtitles.php?mode=delete&id=<?php=$arr["id"]?>"><img src="pic/drop.png" title="Delete Sub" style="border:none;padding:2px;" /></a> <?php }?> </td></tr> <tr><td align="left">Added : <b><?php=$arr["added"]?></b></td></tr> </table> <?php end_main_frame(); stdfoot(); } } if ($mode== "preview") { $id = isset($_GET["id"]) ? 0 + $_GET["id"] : 0; if ($id == 0) stderr("Err","Not a valid id"); else { $res = mysql_query("SELECT id, name,filename FROM subtitles WHERE id={$id} ") or sqlerr(__FILE__, __LINE__); $arr = mysql_fetch_assoc($res); if (mysql_num_rows($res) == 0) stderr("Sorry","There is no subtitle with that id"); $file = $updir."/".$arr["filename"]; $fileContent = file_get_contents($file); print("<html><title>Preview for - ".$arr["name"]."</title> <body bgcolor=\"#CCCCCC\"> <div style=\"white-space:pre; color:#333333;font-family:tahoma; font-size:12px;\">".safe($fileContent)."</div></body></html>"); } } else { stdhead("Subtitles"); begin_frame(); $s = (isset($_GET["s"]) ? safe($_GET["s"]) : ""); $w = (isset($_GET["w"]) ? safe($_GET["w"]) : ""); if ($s && $w == "name") $where = "WHERE s.name LIKE ".sqlesc("%".$s."%"); elseif ($s && $w == "imdb") $where = "WHERE s.imdb LIKE ".sqlesc("%".$s."%"); elseif ($s && $w == "comment") $where = "WHERE s.comment LIKE ".sqlesc("%".$s."%"); else $where = ""; $link = ($s && $w ? "s=$s&w=$w&" : ""); $count = get_row_count("subtitles AS s","$where"); if ($count == 0 && !$s && !$w) stdmsg ("","There is no subtitle, go <a href=\"subtitles.php?mode=upload\">here</a> and start uploading.",false); $perpage = 5; list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "subtitles.php?".$link); $res = sql_query("SELECT s.id, s.name,s.lang, s.imdb,s.fps,s.poster,s.cds,s.hits,s.added,s.owner,s.comment, u.username FROM subtitles AS s LEFT JOIN users AS u ON s.owner=u.id $where ORDER BY s.added DESC $limit ") or sqlerr(__FILE__, __LINE__); ?> <table width="700" cellpadding="5" cellspacing="0" border="0" align="center" style="font-weight:bold" > <tr><td style="border:none" valign="middle"> <fieldset style="text-align:center; border:#0066CC solid 1px; background-color:#999999"> <legend style="text-align:center; border:#0066CC solid 1px ; background-color:#999999;font-size:13px;"><b>Search</b></legend> <form action="subtitles.php" method="get"> <input size="50" value="<?php=$s?>" name="s" type="text" /> <select name="w" > <option value="name" <?php=($w == "name" ? "selected" : "")?>>Name</option> <option value="imdb" <?php=($w == "imdb" ? "selected" : "")?>>IMDb</option> <option value="comment" <?php=($w == "comment" ? "selected" : "")?> >Comments</option> </select> <input type="submit" value="Search" /> <input type="button" onClick="window.location.href='subtitles.php?mode=upload'" value="Upload" /> </form> </td></tr> <?php if ($s) {?> <tr><td style="border:none;">Search result for <i>"<?php=$s?>"</i><br/> <?php=(mysql_num_rows($res) == 0 ? "Nothing found! Try again with a refined search string." : "" )?> </td></tr> <?php}?> </fieldset> </table> <br/> <?php if (mysql_num_rows($res) > 0) { if ($count > $perpage ) print("<div align=\"left\" style=\"padding:5px\">$pagertop</div>"); ?> <table width="700" cellpadding="5" cellspacing="0" border="1" align="center" style="font-weight:bold" > <tr><td class="colhead" align="center">Lang</td> <td class="colhead" align="left" style="width:80%">Name</td> <td class="colhead" align="center">IMDb</td> <td class="colhead" align="center">Added</td> <td class="colhead" align="center">Hits</td> <td class="colhead" align="center">FPS</td> <td class="colhead" align="center">CD#</td> <?php if ($arr["owner"] == $CURUSER["id"] || get_user_class() > UC_MODERATOR) { ?> <td class="colhead" align="center">Tools</td> <?php } ?> <td class="colhead" align="center">Upper</td></tr> <?php while ($arr = mysql_fetch_assoc($res)) { if ($arr["lang"] == "eng") $lang = "<img src=\"pic/flag/england.gif\" border=\"0\" alt=\"English\" title=\"English\" />"; elseif ($arr["lang"] == "swe") $lang = "<img src=\"pic/flag/sweden.gif\" border=\"0\" alt=\"Swedish\" title=\"Swedish\" />"; elseif ($arr["lang"] == "dan") $lang = "<img src=\"pic/flag/denmark.gif\" border=\"0\" alt=\"Danish\" title=\"Danish\" />"; elseif ($arr["lang"] == "nor") $lang = "<img src=\"pic/flag/norway.gih\" border=\"0\" alt=\"Norwegian\" title=\"Norwegian\" />"; elseif ($arr["lang"] == "fin") $lang = "<img src=\"pic/flag/finland.gif\" border=\"0\" alt=\"Finnish\" title=\"Finnish\" />"; elseif ($arr["lang"] == "spa") $lang = "<img src=\"pic/flag/spain.gif\" border=\"0\" alt=\"Spanish\" title=\"Spanish\" />"; elseif ($arr["lang"] == "fre") $lang = "<img src=\"pic/flag/france.gif\" border=\"0\" alt=\"French\" title=\"French\" />"; else $lang = "<b>Unknown</b>"; ?> <tr valign="middle"> <td align="center"><?php=$lang?></td> <td><a href="subtitles.php?mode=details&id=<?php=$arr["id"]?>" onmouseover="Tip('<img src=\'<?php=$arr["poster"]?>\' width=\'100\'>')" onmouseout="UnTip()" ><?php=safe($arr["name"])?></a></td> <td align="center"><a href="<?php=safe($arr["imdb"])?> " target="_blank"><img src="pic/imdb.gif" border="0"/></a></td> <td align="center"><?php=str_replace(" ", "<br/>", $arr["added"])?></td> <td align="center"><?php=$arr["hits"]?></td> <td align="center"><?php=($arr["fps"] == 0 ? "Unknow" : safe($arr["fps"]));?></td> <td align="center"><?php=($arr["cds"] == 0 ? "Unknow" : ($arr["cds"] == 255 ? "More than 5 " : safe($arr["cds"])) );?></td> <?php if ($arr["owner"] == $CURUSER["id"] || get_user_class() > UC_MODERATOR) { ?> <td align="center" nowrap="nowrap"> <a href="subtitles.php?mode=edit&id=<?php=$arr["id"]?>"><img src="pic/edit.png" title="Edit Sub" style="border:none;padding:2px;" /></a> <a href="subtitles.php?mode=delete&id=<?php=$arr["id"]?>"><img src="pic/drop.png" title="Delete Sub" style="border:none;padding:2px;" /></a> </td> <?php } ?> <td align="center"><a href="userdetails.php?id=<?php=$arr["owner"]?>"><?php=safe($arr["username"])?></a></td> </tr> <?php } ?> </table> <?php } end_frame(); stdfoot(); } ?> Alguém pode ver o que se passa? Devia aparecer algo assim: mas dá-me este erro: Parse error: syntax error, unexpected end of file in C:\wamp\www\subtitles.php on line 430
NazgulTuga Posted April 7, 2012 at 06:11 PM Report #448060 Posted April 7, 2012 at 06:11 PM Aconselhava-te a fazer uma coisa. Começa a indentar melhor o teu código. Parte o ficheiro em pequenas partes e faz um include. Era preferível guardares todo o HTML em vários ficheiros, ou as várias acções de cada IF extenso, para te poupar tempo e trabalho. É que eu tive a olhar para o teu código e mesmo depois de o ter indentado fiquei a perceber o mesmo. Não vi qualquer problema, nem falta de chaveta } nem de ?>, parte o ficheiro em vários mais pequenos e vê se descobres qual é o problema, porque ver 430 linhas de código... é que depois mais tarde vais-te ver às aranhas para optimizá-lo ou modificá-lo sem estragar nada.
joaocasta Posted April 24, 2012 at 10:28 PM Author Report #451262 Posted April 24, 2012 at 10:28 PM Vou fazer e depois digo algo! ^.^ 😉
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now