Staff Smiley Upload

Started by MelvinMeow, December 28, 2013, 01:23:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MelvinMeow

This is a modified version of the u-232 v3 code found in this topic.
Coded it to work on tbdev09 for my site so figured others still using the source might like it as well.

Original By Stoner.
https://u-232-forum.duckdns.org/index.php?topic=1537.0.html

admin/staffsmiley.php
<?php
/**
 *   https://github.com/Bigjoos/
 *   Licence Info: GPL
 *   Copyright (C) 2010 U-232 v.3
 *   A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
 *   Project Leaders: Mindless, putyn.
 *
 */
if ( ! defined'IN_TBDEV_ADMIN' ) )
{
$HTMLOUT='';
$HTMLOUT .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Error!</title>
</head>
<body>
<div style='font-size:33px;color:white;background-color:red;text-align:center;'>Incorrect access<br />You cannot access this file directly.</div>
</body></html>"
;
print $HTMLOUT;
exit();
}

require_once(
"include/bittorrent.php");
require_once (
"include/user_functions.php");
require_once (
"include/html_functions.php");
require_once (
"include/bbcode_functions.php");
require_once (
"include/torrenttable_functions.php");

dbconn(false);

function 
htmlsafechars($txt='') {
$txt preg_replace("/&(?!#[0-9]+;)(?:amp;)?/s"'&amp;'$txt );
$txt str_replace( array("<",">",'"',"'"), array("&lt;""&gt;""&quot;"'''), $txt );
return $txt;
}

$lang = array_merge( load_language('
global'), load_language('browse'), load_language('torrenttable_functions') );
loggedinorreturn();

$HTMLOUT = '';

function insert_line($file, $text, $line_number=0) { //If line number is 0 insert at end of file
$lines = file($file); //Array of lines
$handle = fopen($file, '
w+'); //Open for writing, create if not found
if ($line_number > 0) { //Add line at line_number
$tmp = array(); //Temporary stack
for ($i = 0; $i < $line_number-1; $i++) //Copy data until the line given
$tmp[] = $lines[$i];
$tmp[] = "\n$text"; //Add line at correct point
for ($i = $line_number; $i < count($lines); $i++) //Copy remaining lines
$tmp[] = $lines[$i];
$lines = $tmp; //Copy the new stack back to the original
}
else $lines[] = "\n$text\n"; // ...or add line at end
$data = implode("", $lines);
fwrite ($handle, $data);
fclose($handle);
}

if (isset($_POST['
submit'])) {
if (!$_POST['
name']) {
$HTMLOUT .= '
No name.';
exit();
}
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/JPG") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 1000000)) {
if ($_FILES["file"]["error"] > 0) {
$HTMLOUT .= "Return Code: " . $_FILES["file"]["error"] . "<br />";
} else {
if (file_exists("./pic/smilies/" . $_FILES["file"]["name"])) {
$HTMLOUT .= "The smiley you attempted to upload <b><u>" . $_FILES["file"]["name"] . "</u></b> already exists.";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "./pic/smilies/" . $_FILES["file"]["name"]);
$name = htmlsafechars($_POST['
name']);
$filename = htmlsafechars($_FILES['
file']['name']);
$stringData = "\":$name:\" \t=>\t \"$filename\",\n";
$content = "$stringData"; 
$filepath = '
./include/emoticons.php'; 
insert_line("$filepath", "$content", "201");
$HTMLOUT .= "Smiley Uploaded.<br />";
}
}
} else {
$HTMLOUT .= "Invalid file.";
}
}

$HTMLOUT .= '
<form action="admin.php?action=staffsmiley" method="post" enctype="multipart/form-data"><label for="file">Filename:</label><input type="file" name="file" id="file" /><label for="name">Code:</label><input type="text" name="name" size="10" /> Do not add the : and :<br /><input type="submit" name="submit" value="Submit" /></form>';

print stdhead("Add Smileys") . $HTMLOUT . stdfoot(); 
?>


admin.php add:
'staffsmiley'            => 'staffsmiley',

Make sure your /pic/smilies/    directory is chmodded properly.
/include/emoticons.php  should also be chmodded as well.

In /include/emoticons.php find:
);
$privatesmilies = array(

Above ^^^ insert a blank space. Check to see which line # the space is.

Go back to /admin/staffsmiley.php
Find:
insert_line("$filepath", "$content", "201");

Change the 201 portion of the above mentioned line to the # you had for the blank space in the /include/emoticons.php file.