[MOD] Block messages for username

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • [MOD] Block messages for username

      Hi
      My english is no good. ^^

      2Moons 1.8 to 2.0 available.
      Register the username you want to block messages from.
      You can delete and add in settings.
      I made it easy to use and it is very easy.

      A screenshot is attached.
      I hope this helps a lot.


      1. Add to sql
      ALTER TABLE `uni1_users` ADD `message_x` text DEFAULT NULL;



      2. Create a php file.
      includes/game/ShowMessagesxxPage.class.php

      PHP Source Code: ShowMessagesxxPage.class.php

      1. <?php
      2. class ShowMessagesxxPage extends AbstractGamePage
      3. {
      4. public static $requireModule = 0;
      5. function __construct()
      6. {
      7. parent::__construct();
      8. $this->setWindow('popup');
      9. $this->initTemplate();
      10. }
      11. function show()
      12. {
      13. global $LNG, $USER;
      14. $db = Database::get();
      15. $scarray = explode("\r\n", $USER['message_x']);
      16. $MessageS_L = array();
      17. foreach($scarray as $b)
      18. {
      19. if(empty($b))
      20. continue;
      21. $c = explode(',', $b);
      22. $MessageS_L[] = array(
      23. 'name' => $c[0],
      24. 'username' => $c[1],
      25. 'userid' => $USER['authlevel'] >= 3 ? '('.$c[2].')' : '',
      26. );
      27. }
      28. $this->assign(array(
      29. 'MessageS_L' => $MessageS_L,
      30. ));
      31. $this->display('page.messagesxx.tpl');
      32. }
      33. function add()
      34. {
      35. global $LNG, $USER;
      36. $name = HTTP::_GP('n', '', UTF8_SUPPORT);
      37. $username = HTTP::_GP('username', '', UTF8_SUPPORT);
      38. $name = 'Delete ';
      39. $db = Database::get();
      40. $sql = "SELECT id FROM %%USERS%% WHERE username = :userID AND universe = :uni ;" ;
      41. $exists = $db->selectSingle($sql, array(
      42. ':userID' => $username,
      43. ':uni' => Universe::current()
      44. ));
      45. if(empty($exists['id']) || empty($username) || empty($name))
      46. {
      47. $this->printMessage("<span style=font-size:1.2em;color:red>Username does not exist !!!</font>", array(array(
      48. 'label' => $LNG['sys_back'],
      49. 'url' => 'game.php?page=messagesxx'
      50. )));
      51. }else{
      52. $USER['message_x'] .= $name.','.$username.','.$exists['id']."\r\n";
      53. $sql = "UPDATE %%USERS%% SET message_x = :messx WHERE id = :userID;" ;
      54. $db->update($sql, array(
      55. ':messx' => $USER['message_x'],
      56. ':userID' => $USER['id'],
      57. ));
      58. }
      59. $this->redirectTo('game.php?page=messagesxx');
      60. }
      61. function delete()
      62. {
      63. global $LNG, $USER;
      64. $a = HTTP::_GP('n', '');
      65. $db = Database::get();
      66. if(!is_numeric($a)) {
      67. $this->printMessage("<span style=font-size:1.2em;color:red>input error!!</font>", array(array(
      68. 'label' => $LNG['sys_back'],
      69. 'url' => 'game.php?page=messagesxx'
      70. )));
      71. }
      72. $scarray = explode("\r\n", $USER['message_x']);
      73. $r = explode(",", $scarray[$a]);
      74. unset($scarray[$a]);
      75. $USER['message_x'] = implode("\r\n", $scarray);
      76. $sql = "UPDATE %%USERS%% SET message_x = :messx WHERE id = :userID;" ;
      77. $db->update($sql, array(
      78. ':messx' => $USER['message_x'],
      79. ':userID' => $USER['id'],
      80. ));
      81. $this->redirectTo('game.php?page=messagesxx');
      82. }
      83. }
      Display All





      3. Create a tpl file.
      templates/game/page.messagesxx.tpl

      HTML Source Code: page.messagesxx.tpl

      1. {block name="title" prepend}{$LNG.lm_notes}{/block}
      2. {block name="content"}
      3. <style>
      4. td{
      5. font-size:1.3em;
      6. }
      7. th{
      8. font-size:1.3em;
      9. }
      10. </style>
      11. <div class="content_page" style="width: 690px;margin-left:8px">
      12. <div class="title">
      13. Messages Block
      14. </div>
      15. <form action="game.php?page=messagesxx&mode=add" method="post">
      16. <table style="width:100%;">
      17. <tr style="height: 20px;">
      18. <td>
      19. Block username: <input type="text" name="username" value="" size="17" maxlength="30" placeholder="username" required> <input type="submit" value="SAVE">
      20. </td>
      21. </tr>
      22. <tr>
      23. <td></td>
      24. </tr>
      25. </table>
      26. </form>
      27. <table style="width:100%;">
      28. {foreach name=MessageS_L key=id item=short from=$MessageS_L}
      29. {if $smarty.foreach.MessageS_L.iteration is odd}<tr style="height:20px;">{/if}
      30. <td><a style="color:#6995B9" href="?page=messagesxx&mode=delete&n={$id}">{$short.name}</a>
      31. <a style="color:#00B6FF"> [ {$short.username} ]</a>
      32. </td>
      33. {if $smarty.foreach.MessageS_L.last && $smarty.foreach.MessageS_L.total is odd && $smarty.foreach.MessageS_L.total != 1}<td>&nbsp;</td>{/if}
      34. {if $smarty.foreach.MessageS_L.iteration is even}</tr>{/if}
      35. {foreachelse}
      36. <td colspan="2">There are no blocked users.</td>
      37. {/foreach}
      38. <tr><th colspan="2"></th></tr>
      39. </table>
      40. </div>
      41. {/block}
      Display All

      4. Add php content.
      includes/game/ShowMessagesPage.class.php

      Find line
      function send()
      .
      .
      Find line
      if (empty($receiverID) || empty($text) || !isset($session->messageToken) || $session->messageToken != md5($USER['id'].'|'.$receiverID))
      {
      $this->sendJSON($LNG['mg_error']);
      }

      Add code

      PHP Source Code

      1. # [SRTART] Block messages when receiving is rejected
      2. $sql = "SELECT message_x FROM %%USERS%% WHERE id = :userID AND universe = :uni;";
      3. $Ownercheck = Database::get()->selectSingle($sql, array(
      4. ':userID' => $receiverID,
      5. ':uni' => Universe::current()
      6. ));
      7. $scarray = explode("\r\n", $Ownercheck['message_x']);
      8. foreach($scarray as $b)
      9. {
      10. if(empty($b))
      11. continue;
      12. $c = explode(',', $b);
      13. if($c[2] == $USER['id']){
      14. $this->sendJSON("Message blocked.");
      15. }
      16. }
      17. # [END] Block messages when receiving is rejected
      Display All

      Find line
      function show()
      .
      .
      Find line
      foreach($TitleColor as $CategoryID => $CategoryColor) {
      $CategoryList[$CategoryID] = array(
      'color'=> $CategoryColor,
      'unread' => $UnRead[$CategoryID],
      'total'=> $Total[$CategoryID],
      );
      }

      Add code

      PHP Source Code

      1. ## [START] Show Message Blocked Users
      2. $scarray = explode("\r\n", $USER['message_x']);
      3. $MessageS_L = array();
      4. foreach($scarray as $b)
      5. {
      6. if(empty($b))
      7. continue;
      8. $c = explode(',', $b);
      9. $MessageS_L[] = array(
      10. 'name' => $c[0],
      11. 'username' => $c[1],
      12. );
      13. }
      14. ## [END] Show Message Blocked Users
      15. ## Add code
      16. $this->assign(array(
      17. 'MessageS_L' => $MessageS_L, //Add code
      18. ));
      Display All


      5. Add tpl content..
      templates/game/page.messages.default.tpl

      Just add it wherever you want.

      HTML Source Code

      1. <div class="title fontsize12" style="margin: 0 -5px 0 -5px;" >
      2. Users who blocks to receive messages
      3. </div>
      4. <table style="width:100%;">
      5. <tr><th colspan="2"><a href="game.php?page=messagesxx"onclick="return Dialog.open(this.href, 720, 400);" data-toggle="dropdown" href="#" role="button" style="background:#004F79;border-radius:3px;padding: 4px 20px;">Settings</a></th></tr>
      6. {foreach name=MessageS_L key=id item=short from=$MessageS_L}
      7. {if $smarty.foreach.MessageS_L.iteration is odd}<tr style="height:20px;">{/if}
      8. <td><a style="color:#6995B9;font-size:1.2em">Block</a>
      9. <a style="color:#00B6FF;font-size:1.2em"> [ {$short.username} ]</a>
      10. </td>
      11. {if $smarty.foreach.MessageS_L.last && $smarty.foreach.MessageS_L.total is odd && $smarty.foreach.MessageS_L.total != 1}<td>&nbsp;</td>{/if}
      12. {if $smarty.foreach.MessageS_L.iteration is even}</tr>{/if}
      13. {foreachelse}
      14. <td colspan="2">There are no blocked users.</td>
      15. {/foreach}
      16. <tr><th colspan="2">&nbsp;</th></tr>
      17. </table>
      Display All


      Thanks.
      ^^ :D
      Images
      • 01.JPG

        46.04 kB, 910×381, viewed 38 times
      • 02.JPG

        48.02 kB, 1,050×595, viewed 39 times
      --------------------------------------------------------------------------------------

      The post was edited 1 time, last by noonn ().

    • Hi nice mod and thanks for sharing with us.I only have one question and that is the script is now only written in English. Can the tpl be linked so that it translates the languages into the language folder.
    • Reychen wrote:

      Hi nice mod and thanks for sharing with us.I only have one question and that is the script is now only written in English. Can the tpl be linked so that it translates the languages into the language folder.
      It's easy.
      Just add the language to INGAME.php .
      like below

      $LNG['Messagesxx_a'] = 'Username does not exist !!!';
      $LNG['Messagesxx_ae'] = 'input error!!';
      $LNG['Messagesxx_b'] = 'There are no blocked users';
      add lang.
      add lang.
      add lang.
      .

      Changes to PHP and TPL are as follows.

      Open PHP file
      includes/game/ShowMessagesxxPage.class.php

      Find line
      $this->printMessage("<span style=font-size:1.2em;color:red>Username does not exist !!!</font>"
      Change
      $this->printMessage($LNG['Messagesxx_a']

      Find line
      $this->printMessage("<span style=font-size:1.2em;color:red>input error!!</font>"
      Change
      $this->printMessage($LNG['Messagesxx_ae']

      Open TPL file
      templates/game/page.messagesxx.tpl

      Find lang (You can change tpl as below.)
      <td colspan="2">There are no blocked users.</td>
      Change
      <td colspan="2">{$LNG.Messagesxx_b}</td>

      :) :)
      --------------------------------------------------------------------------------------