09 Subtitle mod by putyn

Started by Mindless, September 19, 2012, 04:49:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
Credits to putyn
Xhtml valid

ALTER TABLE torrents ADD `subs` varchar(100) NOT NULL default '';


Putyn built this mod as light as it could be done so for the subs list it uses a file (would be simpler if you use another table but this mean another query for each torrent or one big slow query )

create subs.php - easy to add as many as you want.

<?php
$subs 
= array(
array(
'id'=> '1''name'=> 'Romania''pic'=> 'pic/flag/romania.gif'),
array(
'id'=> '2''name'=> 'English',  'pic'=> 'pic/flag/uk.gif'),
array(
'id'=> '3''name'=> 'Bulgarian''pic'=> 'pic/flag/bulgarian.gif'),
array(
'id'=> '4''name'=> 'Deutsch',  'pic'=> 'pic/flag/germany.gif')
);
?>


If you want more just duplicate the lines

Now in upload.php add this where you want to display the list :

  require_once "cache/subs.php";
$subs_list='';
$subs_list .= "<table border=\"1\"><tr>\n";
$i = 0;
foreach($subs as $s)
{
  $subs_list .=  ($i && $i % 2 == 0) ? "</tr><tr>" : "";
  $subs_list .= "<td style='padding-right: 5px'><input name=\"subs[]\" type=\"checkbox\" value=\"".$s["id"]."\" /> ".$s["name"]."</td>\n";
  ++$i;
}
$subs_list .= "</tr></table>\n";
  $HTMLOUT .= tr("Subtitile",$subs_list,1);


takeupload.php

Under

$catid = (0 + $_POST["type"]);
    if (!is_valid_id($catid))
      stderr($lang['takeupload_failed'], $lang['takeupload_no_cat']);


If you want to return an error if the sub is not selected add this

$subs = isset($_POST["subs"]) ? implode(",", $_POST['subs']) : "";
$movie_cat = array("1","2","3","4"); //add here your movie category
if (empty($subs) && in_array($catid, $movie_cat))
stderr("Error", "Select a subtitle!");


And next add to the big query :

subs and $subs

And your query should look something like - dont copy this  :

$ret = mysql_query("INSERT INTO torrents (search_text, filename, owner, visible, info_hash, name, url, scene, subs ,free, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, safe, markedby, imageurl, nfo) VALUES (" .
implode(",", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $CURUSER["id"], "no", $infohash, $torrent, $url, $scene,$subs,$free, $totallen, count($filelist), $type, $descr, $descr, 0 + $_POST["type"], $dname))) . ", '" . time() . "', '" . time() . "' , $safe, $markedby, '" . $image. "', $nfo)");


Now if you want to show the subtitle lang in browse.php go to bittorrent torrenttable function
and after

<td class='colhead' align='left'><a href='{$TBDEV['baseurl']}/browse.php?{$oldlink}sort=1&amp;type={$link1}'>{$lang["torrenttable_name"]}</a></td>

Add

<td class='colhead' align='left'>{$lang["torrenttable_subtitles"]}</td>

Go down after the code that displays the torrent name

$htmlout .= "'><b>" . CutName($dispname, $char) . " </b></a>&nbsp;$release_group&nbsp;$sticky&nbsp;".($row['added'] >= $CURUSER['last_browse'] ? " <img src='{$TBDEV['pic_base_url']}newb.png' border='0' alt='New !' title='New !' />" : "")."&nbsp;$checked&nbsp;$free_tag&nbsp;$nuked<br />\n".$isdlfree.$isdouble."</td>\n";

And add this

$movie_cat = array("3","5","6","10","11"); //add here your movie category
$htmlout .="<td align=\"right\" nowrap=\"nowrap\" >\n";
if (in_array($row["category"], $movie_cat) && !empty($row["subs"]) )
{
$subs_array = explode(",",$row["subs"]);
foreach ($subs_array as $id => $sid) {
require_once "cache/subs.php";
foreach ($subs as $sub){
if ($sub["id"] == $sid)
$htmlout .="<img border=\"0\" width=\"16px\" style=\"padding:3px;\"src=\"".$sub["pic"]."\" alt=\"".$sub["name"]."\" title=\"".$sub["name"]."\" />";
}
}
}else
$htmlout .="---";
$htmlout .="</td>";


Add to : lang/lang_torrenttable_functions.php :

'torrenttable_subtitles' => 'Subs',

Add to the torrents query in browse.php :

torrents.subs,

now if you want to display it in details.php add this to the big torrents query :

torrents.category, torrents.subs,

And this where you want it to show

    $movie_cat = array("3","5","6","10","11"); //add here your movie category
  if (in_array($row["category"], $movie_cat) && !empty($row["subs"]) )
{
  $HTMLOUT .="<tr><td class='rowhead'>Subtitles</td><td align='left'>";
$subs_array = explode(",",$row["subs"]);
  foreach ($subs_array as $id => $sid) {
  require_once "cache/subs.php";
  foreach ($subs as $sub){
if ($sub["id"] == $sid)
$HTMLOUT .="<img border=\"0\" width=\"25px\" style=\"padding:3px;\"src=\"".$sub["pic"]."\" alt=\"".$sub["name"]."\" title=\"".$sub["name"]."\" />";
  }
  }
    $HTMLOUT .="</td></tr>\n";
  }


Now for edit.php :

  require_once "cache/subs.php";
$subs_list='';
$subs_list .= "<table border=\"1\"><tr>\n";
$i = 0;
foreach($subs as $s)
{
  $subs_list .=  ($i && $i % 2 == 0) ? "</tr><tr>" : "";
  $subs_list .= "<td style='padding-right: 5px'><input name=\"subs[]\" " . (strpos($row["subs"], $s["id"]) !== false ? " checked='checked'" : "") . "  type=\"checkbox\" value=\"".$s["id"]."\" /> ".$s["name"]."</td>\n";
  ++$i;
}
$subs_list .= "</tr></table>\n";
$HTMLOUT .= tr("Subtitiles",$subs_list,1);



And the code for takeedit.php :

$movie_cat = array("3","5","6","10","11"); //add here your movie category
    if (in_array($category, $movie_cat))
    {
    $subs = isset($_POST['subs'])? implode(",", $_POST['subs']) : "" ;
    $updateset[] = "subs = " . sqlesc($subs);
    }