09 Offensive Avatar Mod

Started by Mindless, July 21, 2012, 07:51:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

denede

works like pie.
any chance of code for default forum ?

Mindless

With this mod users can set if their avatar is offensive or not. They can also select if they want to view offensive avatars or not.

    * One extra field in the users SQL table.
    * Checkbox for offensive avatar.
    * Radio for view avatars.
    * Working on forum posts.
    * Working on torrent comments.

Credits to Scars - warade - islander
Xhtml valid
Language to be completed
Default forums.php code still to be done as this is posted for 09 Multilayer Forum
SQL :

Code (sql) Select
ALTER TABLE `users` DROP `avatars`;
ALTER TABLE `users` ADD `avatars` ENUM('all', 'some', 'none') NOT NULL default 'all';
ALTER TABLE `users` ADD `offavatar` ENUM('yes', 'no') NOT NULL default 'no';


On my.php replace the Avatar Url part with this:

Code (php) Select
$HTMLOUT .="<tr><td class='rowhead'>{$lang['my_avatar']}</td><td><input name='avatar' size='50' value='" . htmlspecialchars($CURUSER["avatar"]) . "' /><br />
<font class='small'>Width should be 150px. (Will be resized if necessary)\n<br />
If you need a host for the picture, try our  <a href='{$TBDEV['baseurl']}/bitbucket.php'>Bitbucket</a>.</font>
<br /><input type='checkbox' name='offavatar' ".($CURUSER["offavatar"] == "yes" ? " checked='checked'" : "")." /><b>This avatar may be offensive to some people.</b><br />
<font class='small'>Please check this box if your avatar contains nudity or may<br />otherwise be potentially offensive to or unsuitable for minors.</font></td></tr>";


And replace the View Avatars with this:

Code (php) Select
$HTMLOUT .="<tr><td class='rowhead'>{$lang['my_view_avatars']}</td><td><input type='radio' name='avatars'" . ($CURUSER["avatars"] == "all" ? " checked='checked'" : "") . " value='all' />All
<input type='radio' name='avatars' " .  ($CURUSER["avatars"] == "some" ? " checked='checked'" : "") . " value='some' />All except potentially offensive
<input type='radio' name='avatars' " .  ($CURUSER["avatars"] == "none" ? " checked='checked'" : "") . " value='none' />None</td></tr>";


on takeprofedit.php replace :

Code (php) Select
/////// do the avatar stuff
    $avatars = ($_POST["avatars"] != "" ? "yes" : "no");
    $avatar = trim( urldecode( $_POST["avatar"] ) );
     
      if ( preg_match( "/^http:\/\/$/i", $avatar )
          or preg_match( "/[?&;]/", $avatar )
          or preg_match("#javascript:#is", $avatar )
          or !preg_match("#^https?://(?:[^<>*\"]+|[a-z0-9/\._\-!]+)$#iU", $avatar )
          )
      {
        $avatar='';
      }

   
With :   
     
   
Code (php) Select
/////// do the avatar stuff
    $avatars = $_POST["avatars"];
    $offavatar = (isset($_POST['offavatar']) && $_POST["offavatar"] != "" ? "yes" : "no");
    $avatar = trim( urldecode( $_POST["avatar"] ) );
     
      if ( preg_match( "/^http:\/\/$/i", $avatar )
          or preg_match( "/[?&;]/", $avatar )
          or preg_match("#javascript:#is", $avatar )
          or !preg_match("#^https?://(?:[^<>*\"]+|[a-z0-9/\._\-!]+)$#iU", $avatar )
          )
      {
      $avatar='';
      }

     
Under :

Code (php) Select
$updateset[] = "avatars = '$avatars'";

Add :

Code (php) Select
$updateset[] = "offavatar = ".sqlesc($offavatar);

For 09 multilayer forum : forums.php change (~line 558 ish):

Code (php) Select
$postres = mysql_query("SELECT p.id, p.added, p.body, p.anonymous, u.id AS uid, u.username, u.avatar " . "FROM posts AS p " . "LEFT JOIN users AS u ON u.id = p.userid " . "WHERE p.topicid = " . sqlesc($id) . " " . "ORDER BY p.id DESC LIMIT 10") or sqlerr(__FILE__, __LINE__);

To :

Code (php) Select
$postres = mysql_query("SELECT p.id, p.added, p.body, p.anonymous, u.id AS uid, u.username, u.avatar, u.offavatar " . "FROM posts AS p " . "LEFT JOIN users AS u ON u.id = p.userid " . "WHERE p.topicid = " . sqlesc($id) . " " . "ORDER BY p.id DESC LIMIT 10") or sqlerr(__FILE__, __LINE__);

And change (~line 595 ish):

Code (php) Select
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($post["avatar"]) : "");

to:

Code (php) Select
$avatar = ($CURUSER["avatars"] == "all" ? htmlspecialchars($post["avatar"]) : ($CURUSER["avatars"] == "some" && $post["offavatar"] == "no" ? htmlspecialchars($post["avatar"]) : ""));

On line 1301 - $res query add u.offavatar after u.avatar

Code (php) Select
u.avatar, u.offavatar,

and (~line 1338):

Code (php) Select
$avatar = (!empty($postername) ? ($CURUSER['avatars'] == "yes" ? htmlspecialchars($arr['avatar']) : '') : '');

to:

Code (php) Select
$avatar = ($CURUSER["avatars"] == "all" ? htmlspecialchars($arr["avatar"]) : ($CURUSER["avatars"] == "some" && $arr["offavatar"] == "no" ? htmlspecialchars($arr["avatar"]) : ""));

And on include/torrenttable_functions.php change:

Code (php) Select
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($row["avatar"]) : "");

to:

Code (php) Select
$avatar = ($CURUSER["avatars"] == "all" ? htmlspecialchars($row["avatar"]) : ($CURUSER["avatars"] == "some" && $row["offavatar"] == "no" ? htmlspecialchars($row["avatar"]) : ""));

Then on comment.php find this query or similiar :

Code (php) Select
$res = mysql_query("SELECT comments.id, text, comments.added, username, users.id as user, users.avatar FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = $torrentid ORDER BY comments.id DESC LIMIT 5");

and add , users.offavatar into it (put it after users.avatar).

Then on details.php find this query:

Code (sql) Select
$subres = mysql_query("SELECT comments.id, text, user, comments.added, editedby, editedat, avatar, warned, ".
  "username, title, class, donor FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = " .
  "$id ORDER BY comments.id ".$pager['limit']") or sqlerr(__FILE__, __LINE__);


And add , offavatar into it (put it after avatar)

In userdetails.php change:

Code (php) Select
$HTMLOUT .= "<tr><td class='rowhead'>{$lang['userdetails_avatar_url']}</td><td colspan='2' align='left'><input type='text' size='60' name='avatar' value='$avatar' /></td></tr>\n";

To:

Code (php) Select
$HTMLOUT .="<tr><td class='rowhead'>{$lang['userdetails_avatar_url']}</td><td colspan='2' align='left'><input type='text' size='60' name='avatar' value='$avatar' /><br /><b> Avatar May Be Offensive To Some Users</b> <input type='checkbox' name='offavatar' value='yes' " .($user["offavatar"] == "yes" ? " checked='checked'" : "")." /></tr>\n";

And in modtask.php add :

Code (php) Select
//==09  Offensive Avatar
    if ((isset($_POST['offavatar'])) && (($offavatar = $_POST['offavatar']) != $user['offavatar']))
    {
    if ($offavatar == 'yes')
    {
    $modcomment = get_date( time(), 'DATE', 1 ) . " - Marked as Offensive Avatar by " . $CURUSER['username'] . ".\n" . $modcomment;
    $msg = sqlesc("Your Avatar is set as Offensive by  ".htmlspecialchars($CURUSER['username']).", Please PM ".htmlspecialchars($CURUSER['username'])." for the reason why.");
    $added = time();
    $subject = sqlesc("Your Avatar is set as Offensive.");
    mysql_query("INSERT INTO messages (sender, receiver, msg, added, subject) VALUES (0, $userid, $msg, $added, $subject)") or sqlerr(__FILE__, __LINE__);
    write_log("$username Marked as Offensive Avatar by $CURUSER[username]");
    }
    elseif ($offavatar == 'no')
    {
    $modcomment = get_date( time(), 'DATE', 1 ) . " - Un-Marked as Not Offensive Avatar by " . $CURUSER['username'] . ".\n" . $modcomment;
    $msg = sqlesc("Your Avatar is set as Not Offensive by  ".htmlspecialchars($CURUSER['username']).".");
    $added = time();
    $subject = sqlesc("Your Avatar is not Offensive.");
    mysql_query("INSERT INTO messages (sender, receiver, msg, added, subject) VALUES (0, $userid, $msg, $added, $subject)") or sqlerr(__FILE__, __LINE__);
    write_log("$username Un-Marked as Not Offensive Avatar by $CURUSER[username]");
    }
    else
    die();
    $updateset[] = "offavatar = " . sqlesc($offavatar);
    }
    //==End