Advertisement
zeusmaximus

Staff Chatbox

Oct 26th, 2015
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***
  2.  * Application: Staff\'s ChatBox - Installer module.
  3.  * Description: Install an exclusive chat room for your forum staff.
  4.  * Version: 2.02112015-jq1.9.1 - (wizard) Nesu, neb Tot.
  5.  * Made and Optimizations by JScript - 2014/12/06, 2015/02/11
  6.  * Copyright (c) 2015 JScript <jscriptbrasil at live dot com>
  7.  * This work is free. You can redistribute it and/or modify it
  8.  * under the terms of the WTFPL, Version 2
  9.  */
  10. var install = {
  11.     version: "2.02112015-jq1.9.1",
  12.     codeName: "(wizard) Nesu, neb Tot.",
  13.     author: "JScript",
  14.     contact: "jscriptbrasil at live dot com",
  15.     installMsg: "Bine ai venit in panoul de instalare Staff Chatbox!\n\nDoriti sa-l instalati?",
  16.     uninstallMsg: "Bine ai venit in panoul de dezinstalare Staff Chatbox! Doriti sa-l dezinstalati?",
  17.     instMsg1: "Creez suportul pentru structura bazei de date, asteptati...",
  18.     instMsg2: "Actualizez permisiunile petru administratori si moderatori, asteptati...",
  19.     instMsg3: "Creez baza de date locala, asteptati...",
  20.     instMsg4: "Copiez codul interfetei chatbox, asteptati...",
  21.     instMsg5: "Instalare finalizata!\n\nReinprospatati pagina pentru a vedea chatbox-ul!",
  22.     dinstMsg1: "Elimin suportul pentru structura bazei de date, asteptati...",
  23.     dinstMsg2: "Elimin codul interfetei chatbox...",
  24.     dinstMsg3: "Modulul Staff Chatbox a fost eliminat cu succes de pe forumul dumneavoastra.",
  25.  
  26.     create: {
  27.         auth_copy: 0,
  28.         desc: "Staff Chatbox va fi vizibil doar administratorilor si moderator! Puteti schimba permisiunile din <i>Panou => General => Forum => Categorii si forumuri => <span style='color:red;'><b>Staff Chatbox</b></span></i> pentru a adauga alte grupuri.<br />" +
  29.             "<br/><br/>Comenzi disponibile:<br /><b>/dezinstalare</b> - Pentru a dezinstala acest chat (doar fondatorul este autorizat)<br /><b>/curata</b> - Pentru a sterge toate mesajele din chat, inclusiv acest mesaj <br /><b>/stop</b> - Opreste chat-ul<br /> <b>/start</b> - Porneste chat-ul",
  30.         fid: "",
  31.         image: "",
  32.         main: -1,
  33.         mode: "create",
  34.         name: "Staff Chatox",
  35.         order_posts: 1,
  36.         order_topics: 1,
  37.         position: "f0",
  38.         preset_choice: 0,
  39.         prune_days: 90,
  40.         prune_enable: 0,
  41.         prune_freq: 7,
  42.         rule_display: {
  43.             0: "on"
  44.         },
  45.         rule_img_url: "",
  46.         rule_msg: "",
  47.         selected_id: "Root",
  48.         status: 0,
  49.         type: "f",
  50.         update: 1
  51.     },
  52.  
  53.     permissions: {
  54.         fid: 0,
  55.         forum_preset_read: "",
  56.         forum_preset_view_images: 0,
  57.         forum_preset_view_links: 0,
  58.         forum_preset_write: "",
  59.         group: {
  60.             mod: {
  61.                 2: "on"
  62.             },
  63.             view: {
  64.                 2: "on"
  65.             },
  66.             write: {
  67.                 2: "on"
  68.             }
  69.         },
  70.         mode: "auth",
  71.         preset_choice: 0,
  72.         selected_id: "Root",
  73.         simple_auth: 1,
  74.         update: 1
  75.     },
  76.  
  77.     topicDB: {
  78.         subject: "baza_de_date_chatbox",
  79.         message: "",
  80.         topictype: 0,
  81.         mode: 'newtopic',
  82.         f: 0,
  83.         post: 1
  84.     },
  85.  
  86.     DB_edit: "",
  87.     DB_url: "",
  88.     TID: 0,
  89.     founder: undefined,
  90.  
  91.     updateProgressBar: function(value) {
  92.         var width = Math.round((value * 100) / 100);
  93.         document.getElementById("shout-installer-prg").style.width = width + '%';
  94.     }
  95. };
  96.  
  97. jQuery(window).load(function() {
  98.     if (_userdata.user_level !== 1) {
  99.         return false;
  100.     }
  101.     install.TID = jQuery('a[href*="tid="]').attr('href').split('tid=')[1].split('&')[0]; //Get the var {TID}
  102.     /*
  103.     $.ajax({
  104.         url: "/admin/index.forum?part=themes&tid=" + install.TID,
  105.         type: 'get',
  106.         async: false,
  107.         dataType: 'html',
  108.         success: function(response, status, xhr) {
  109.             if (xhr.status == 200) {
  110.                 install.founder = $(response).find('a[href^="/admin/index.forum?mode=main&part=themes&sub=templates"]').attr('href');
  111.             }
  112.         }
  113.     });
  114.     if (install.founder == undefined) {
  115.         return false;
  116.     }
  117.     */
  118.     if (!__iConfirm(install.create.name + " - " + install.version + ", creat de " + install.author + "!\n\n" + install.installMsg)) {
  119.         return false;
  120.     }
  121.  
  122.     $('body').prepend('<div id="document_modal" class="modal" style="z-index: 10000; left: 0px; opacity: 0.4; position: fixed; top: 0px; height: 100%; width: 100%; background-color: rgb(62, 62, 62);"></div>');
  123.     if ($('table.bodylinewidth').length) {
  124.         //phpBB2
  125.         $('body').prepend(
  126.             '<table cellspacing="1" cellpadding="0" border="0" class="forumline" style="position: fixed; top: 20%; left: 30%; right: 30%; min-width: 400px; z-index: 10001;">' +
  127.             '   <tbody>' +
  128.             '       <tr>' +
  129.             '           <td height="25" class="catLeft">' +
  130.             '               <span class="genmed module-title">Staff Chatbox - Instalare modul</span>' +
  131.             '           </td>' +
  132.             '       </tr>' +
  133.             '       <tr>' +
  134.             '           <td align="left" class="row1">' +
  135.             '               <div style="border: 1px solid rgb(210, 210, 210); box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.07); padding: 5px;">' +
  136.             '                   <div id="shout-installer-msg" style="font-size: 14px; font-weight: bold; padding: 5px; margin-top: 15px; word-wrap: break-word;"></div>' +
  137.             '                   <div style="border: 1px solid rgb(210, 210, 210); margin-top: 20px; padding: 4px 2px 5px; margin-bottom: 10px; font-size: 16px;">' +
  138.             '                       <div style="height: 20px; padding: 0px; background-color: rgb(205, 205, 205);" id="shout-installer-prg"></div>' +
  139.             '                   </div>' +
  140.             '               </div>' +
  141.             '           </td>' +
  142.             '       </tr>' +
  143.             '   </tbody>' +
  144.             '</table>'
  145.         );
  146.     } else {
  147.         //phpBB3, PunBB, Invision
  148.         $('body').prepend(
  149.             '<div class="module main borderwrap" style="position: fixed; top: 20%; left: 30%; right: 30%; min-width: 400px; z-index: 10001;">' +
  150.             '   <span class="corners-top"><span></span></span>' +
  151.             '   <div class="main-head inner">' +
  152.             '       <div class="maintitle genmed module-title">' +
  153.             '           <h3>Staff Chatbox - Instalare modul</h3>' +
  154.             '       </div>' +
  155.             '   </div>' +
  156.             '   <div class="main-content clearfix box-content" style="background-color: rgb(251, 251, 251); border: 1px solid rgb(221, 221, 221);">' +
  157.             '       <div style="border: 1px solid rgb(210, 210, 210); box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.07); padding: 5px;">' +
  158.             '           <div id="shout-installer-msg" style="font-size: 14px; font-weight: bold; padding: 5px; margin-top: 15px; word-wrap: break-word;"></div>' +
  159.             '           <div style="border: 1px solid rgb(210, 210, 210); margin-top: 20px; padding: 4px 2px 5px; margin-bottom: 10px; font-size: 16px;">' +
  160.             '               <div style="height: 20px; padding: 0px; background-color: rgb(205, 205, 205);" id="shout-installer-prg" class="maintitle genmed module-title"></div>' +
  161.             '           </div>' +
  162.             '       </div>' +
  163.             '   </div>' +
  164.             '   <span class="corners-bottom"><span></span></span>' +
  165.             '</div>'
  166.         );
  167.     }
  168.  
  169.     var msgElem = document.getElementById("shout-installer-msg");
  170.  
  171.     msgElem.innerHTML = install.instMsg1;
  172.     install.updateProgressBar(5);
  173.     $.ajax({
  174.         url: "/admin/index.forum?part=general&sub=general&mode=create&fid=&extended_admin=1&tid=" + install.TID,
  175.         type: 'post',
  176.         data: install.create,
  177.         dataType: 'html',
  178.         success: function(response, status, xhr) {
  179.             if (xhr.status == 200) {
  180.                 var response = $(response);
  181.                 if (response.find('.successbox') !== null) {
  182.                     var FID = response.find('input[name="fid"]').val();
  183.                     install.permissions.fid = FID;
  184.  
  185.                     msgElem.innerHTML = install.instMsg2;
  186.                     install.updateProgressBar(15);
  187.                     $.ajax({
  188.                         url: "/admin/index.forum?part=general&sub=general&mode=auth&fid=" + FID + "&extended_admin=1&tid=" + install.TID,
  189.                         type: 'post',
  190.                         data: install.permissions,
  191.                         dataType: 'html',
  192.                         success: function(response, status, xhr) {
  193.                             if (xhr.status == 200) {
  194.                                 var firstPost = {
  195.                                     user: [{
  196.                                         id: _userdata.user_id,
  197.                                         name: _userdata.username,
  198.                                         pname: encodeURIComponent($('a[href="/u' + _userdata.user_id + '"]')[0].innerHTML),
  199.                                         avatar: $(_userdata.avatar).attr("src")
  200.                                     }],
  201.                                     msgs: [{
  202.                                         id: _userdata.user_id,
  203.                                         msg: encodeURIComponent(install.create.desc).replace(/%20/g, " "),
  204.                                         date: Math.round(new Date().getTime() / 1000)
  205.                                             //date: (new Date().toLocaleTimeString().substr(0, 5)) + " - " + (new Date().toLocaleDateString()) //IE fail...
  206.                                             //date: (new Date().toLocaleTimeString().split(':').slice(0, 2).join(':')) + " - " + (new Date().toLocaleDateString())
  207.                                     }]
  208.                                 };
  209.                                 install.topicDB.message = JSON.stringify(firstPost);
  210.                                 install.topicDB.f = FID.substr(1);
  211.  
  212.                                 msgElem.innerHTML = install.instMsg3;
  213.                                 install.updateProgressBar(25);
  214.                                 $.ajax({
  215.                                     url: "/post",
  216.                                     type: 'post',
  217.                                     data: install.topicDB,
  218.                                     dataType: 'html',
  219.                                     success: function(response, status, xhr) {
  220.                                         if (xhr.status == 200) {
  221.                                             var parse = /url=.*t=([0-9]+).*#([0-9]+)/ig.exec(response);
  222.                                             if (parse !== null) {
  223.                                                 install.DB_url = "/t" + parse[1] + "-" + install.topicDB.subject;
  224.                                                 install.DB_edit = "/post?p=" + parse[2] + "&mode=editpost";
  225.                                                 __install_ChatBox(msgElem);
  226.                                             }
  227.                                         }
  228.                                     }
  229.                                 });
  230.                             }
  231.                         }
  232.                     });
  233.                 }
  234.             }
  235.         }
  236.     });
  237.  
  238.     function __iConfirm(text) {
  239.         return (confirm(text) == true) ? true : false;
  240.     };
  241. });
  242.  
  243. function __install_ChatBox(msgElem) {
  244.     var chatbox_script = function() {
  245.  
  246.         // "For" asynchronous loop, faster and does not lock the browser interface when you have many messages!
  247.         (function($) {
  248.             jQuery.assyncFor = function(arr, callback) {
  249.                 for (var i = 0, len = arr.length; i < len; ++i) {
  250.                     var boundCallback = callback.bind(null, i, arr[i]);
  251.                     setTimeout(boundCallback, i);
  252.                 }
  253.                 return this;
  254.             };
  255.         }(jQuery));
  256.  
  257.         chatStaff = {
  258.             autor: "JScript",
  259.             version: "$install.version$",
  260.             codename: "$install.codeName$",
  261.  
  262.             readLoop: 0,
  263.             readInterval: 6000 /*Below this is danger!*/ ,
  264.             startingMsg: "Va rugam asteptati...",
  265.             restartMsg: "<span style='color: green;font-style: italic;'>Baza de date a fost reinitializata cu succes!</span>",
  266.             mentionMsg: "Insert name into Shout",
  267.             editChatMsg: "Editeaza",
  268.             delChatMsg: "Sterge",
  269.             sendError: "Atentie!\n\n A aparut o problema in momentul trimiterii mesajului, va rugam asteptati 10 secunde.",
  270.             removeError: "Atentie!\n\n A aparut o problema in momentul editarii mesajului,  va rugam asteptati 10 secunde!",
  271.             uninstallMsg: "Staff ChatBox - $install.version$, creat de JScript!\n\nSunteti pe cale sa dezinstalati Staff Chatbox, doriti sa continuati?",
  272.             uninstallMsg: "$install.create.name$ - $install.version$, creat de $install.author$!\n\n$install.uninstallMsg$",
  273.             stopRead: 0,
  274.             postSize: 0,
  275.             founder: undefined,
  276.  
  277.             oPost: {
  278.                 user: [],
  279.                 msgs: []
  280.             },
  281.  
  282.             oBBCode: {
  283.                 patt: [
  284.                     /\[b](.*?)\[\/b]/gi,
  285.                     /\[i](.*?)\[\/i]/gi,
  286.                     /\[u](.*?)\[\/u]/gi,
  287.                     /\[s](.*?)\[\/s]/gi,
  288.                     /\[center](.*?)\[\/center]/gi,
  289.                     /\[size=(.*?)](.*?)\[\/size]/gi,
  290.                     /\[url](.*?)\[\/url]/gi,
  291.                     /\[url=(.*?)](.*?)\[\/url]/gi,
  292.                     /\[color=(.*?)](.*?)\[\/color]/gi,
  293.                     /\[img](.*?)\[\/img]/gi,
  294.                     /\[spoiler](.*?)\[\/spoiler]/gi,
  295.                     /\[spoiler](.*?)\[\/spoiler]/gi,
  296.                     /\[code](.*?)\[\/code]/gi,
  297.                     /\[quote](.*?)\[\/quote]/gi,
  298.                     /\[quote=(.*?)](.*?)\[\/quote]/gi
  299.                 ],
  300.                 html: [
  301.                     "<strong>$1</strong>",
  302.                     "<i>$1</i>",
  303.                     "<span style='text-decoration:underline;'>$1</span>",
  304.                     "<span style='text-decoration:line-through'>$1</span>",
  305.                     "<div style='margin:auto;text-align:center;width:100%'>$1</div>",
  306.                     "<span style='font-size: $1;'>$2</span>",
  307.                     "<a rel='nofollow' target='_blank' href='$1'>$1</a>",
  308.                     "<a rel='nofollow' target='_blank' href='$1'>$2</a>",
  309.                     "<span style='color: $1'>$2</span>",
  310.                     "<img src='$1' style='max-width:120px;max-height:120px;'/>",
  311.                     "<dl class='codebox spoiler'><dt style='cursor: pointer;'>Spoiler:</dt><dd><div class='spoiler_content'>$1</div></dd></dl>",
  312.                     "<dl class='codebox spoiler'><dt style='cursor: pointer;'>$1</dt><dd><div class='spoiler_content'>$2</div></dd></dl>",
  313.                     "<dl class='codebox'><dt>CΓ³digo:</dt><dd class='cont_code'><code>$1</code></dd></dl>",
  314.                     "<blockquote><div>$1</div></blockquote>",
  315.                     "<blockquote><div>$2</div></blockquote>"
  316.                 ]
  317.             },
  318.  
  319.             initialize: function() {
  320.                 jQuery(function() {
  321.                     if (_userdata.user_level > 0) {
  322.                         if (!String.prototype.repeat) { /* String repeat - By JScript */
  323.                             String.prototype.repeat = function(count) {
  324.                                 return (count < 1) ? "" : Array(count + 1).join(this.valueOf())
  325.                             };
  326.                         };
  327.                         chatStaff.setupChatbox();
  328.                     }
  329.                 });
  330.             },
  331.  
  332.             setupChatbox: function() {
  333.                 jQuery("head").append(
  334.                     "<style type='text/css'>" +
  335.                     ".jschatbox_container.row1 {" +
  336.                     "   border: 1px solid #dbe4ef;" +
  337.                     "}" +
  338.                     ".message.block_wrap {" +
  339.                     "   background: none repeat scroll 0 0 #ebfcdf;" +
  340.                     "   border: 1px solid #a4cfa4;" +
  341.                     "   color: #0e440e;" +
  342.                     "   font-size: 12px;" +
  343.                     "   line-height: 1.6;" +
  344.                     "   padding: 10px;" +
  345.                     "}" +
  346.                     ".jschatbox_container .content {" +
  347.                     "   border-bottom: 1px solid #f3f3f3 !important;" +
  348.                     "   overflow: visible !important;" +
  349.                     "   padding: 4px;" +
  350.                     "}" +
  351.                     "#staff-chatbox-shouts {" +
  352.                     "   border: 1px solid #d5dde5;" +
  353.                     "}" +
  354.                     "#staff-chatbox-shouts > div {" +
  355.                     "   border-bottom: 1px solid #d5dde5;" +
  356.                     "   padding: 4px;" +
  357.                     "   font-size: 12px;" +
  358.                     "   line-height: 135%;" +
  359.                     "   min-height: 35px;" +
  360.                     "   margin: 0;" +
  361.                     "}" +
  362.                     ".altrow_avatar {" +
  363.                     "   float: left;" +
  364.                     "   padding-right: 4px;" +
  365.                     "}" +
  366.                     ".jschat_avatar {" +
  367.                     "   background: none repeat scroll 0 0 #fff;" +
  368.                     "   border: 1px solid #d5d5d5 !important;" +
  369.                     "   box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);" +
  370.                     "   height: 30px;" +
  371.                     "   padding: 1px;" +
  372.                     "   vertical-align: middle;" +
  373.                     "   width: 30px;" +
  374.                     "}" +
  375.                     ".right.desc {" +
  376.                     "   color: #777;" +
  377.                     "   float: right;" +
  378.                     "   font-size: 12px;" +
  379.                     "}" +
  380.                     ".altrow_text .right.desc > img {" +
  381.                     "   cursor: pointer;" +
  382.                     "}" +
  383.                     ".shout_text {" +
  384.                     "   display: block;" +
  385.                     "   padding-top: 3px;" +
  386.                     "   word-wrap: break-word;" +
  387.                     "}" +
  388.                     ".shout_text > img {" +
  389.                     "   margin-bottom: 0 !important;" +
  390.                     "   vertical-align: middle;" +
  391.                     "}" +
  392.                     "#rt_input {" +
  393.                     "   font-family: inherit;" +
  394.                     "   font-size: inherit;" +
  395.                     "   vertical-align: middle;" +
  396.                     "}" +
  397.                     "#staff-shouts-resizer {" +
  398.                     "   background-color: #dbe2ec;" +
  399.                     "   cursor: n-resize;" +
  400.                     "   height: 6px;" +
  401.                     "}" +
  402.                     ".message.error.block_wrap {" +
  403.                     "   background-color: #f3e3e6;" +
  404.                     "   border-color: #e599aa;" +
  405.                     "   color: #80001c;" +
  406.                     "   font-size: 12px;" +
  407.                     "   line-height: 1.6;" +
  408.                     "   padding: 10px;" +
  409.                     "}" +
  410.                     ".jschatbox_container .input_text, .jschatbox_container .input_submit {" +
  411.                     "   padding: 4px;" +
  412.                     "   vertical-align: middle;" +
  413.                     "}" +
  414.                     ".jschatbox_container .button2 {" +
  415.                     "   cursor: pointer;" +
  416.                     "   margin-left: 4px;" +
  417.                     "}" +
  418.                     "#staff-smiles-show {" +
  419.                     "   background: none no-repeat scroll center center rgb(255, 255, 255);" +
  420.                     "   border: 2px solid #d2d2d2;" +
  421.                     "   height: 250px;" +
  422.                     "   overflow: auto;" +
  423.                     "   padding-top: 6px;" +
  424.                     "   position: absolute;" +
  425.                     "   width: 225px;" +
  426.                     "   z-index: 99999;" +
  427.                     "}" +
  428.                     "#staff-smiles-show > p {" +
  429.                     "   margin: 0;" +
  430.                     "}" +
  431.                     "#staff-smiles-show p a {" +
  432.                     "   margin-bottom: 14px;" +
  433.                     "}" +
  434.                     "#staff-smiles-show a {" +
  435.                     "   display: inline-block;" +
  436.                     "   font-size: 18px;" +
  437.                     "   margin-bottom: 5px;" +
  438.                     "   margin-left: 10px;" +
  439.                     "   text-decoration: none;" +
  440.                     "}" +
  441.                     "</style>"
  442.                 );
  443.                 jQuery("#$install.permissions.fid$, a[href^='/$install.permissions.fid$']")
  444.                     .closest("#$install.permissions.fid$, .main-content, .topiclist.forums, .forumline tr")
  445.                     .html(
  446.                         "<div class='jschatbox_container row1'>" +
  447.                         "   <div class='content row2' id='staff-announcement-row' style='display: none;'>" +
  448.                         "       <div class='message block_wrap' id='staff-announcement-text'></div>" +
  449.                         "   </div>" +
  450.                         "   <div class='content top row1'>" +
  451.                         "       <div id='staff-chatbox-shouts' style='top: 0px; height: 225px; min-height: 155px; left: 0px; overflow: auto;'>" +
  452.                         "           <p id='shout-row-0' class='row2' style='padding: 8px;'>" +
  453.                         "               <span class='altrow_text'>" +
  454.                         "                   <span class='shout_text' style='font-size: 18px;'><strong>" + chatStaff.startingMsg + "</strong></span>" +
  455.                         "               </span>" +
  456.                         "           </p>" +
  457.                         "       </div>" +
  458.                         "       <div id='staff-shouts-resizer' title='Click to resize' oncontextmenu='localStorage.removeItem(&quot;shout_height&quot;);return false;' onmousedown='chatStaff.resize();'></div>" +
  459.                         "       <div style='display: none;' class='message error block_wrap' id='staff-shoutbox-error'></div>" +
  460.                         "   </div>" +
  461.                         "   <div class='content bottom row1'>" +
  462.                         "       <div valign='top' class='footer altrow' colspan='2'>" +
  463.                         "           <input type='text' id='staff-shout-input' size='75' class='input_text'>" +
  464.                         "           <input type='button' onclick='chatStaff.submitShout();' id='staff-submit-button' value='Trimite' class='button2 input_submit'>" +
  465.                         "           <input type='button' onclick='document.getElementById(&quot;staff-shout-input&quot;).value = &quot;&quot;;' id='staff-clear-button' value='Curatare' class='button2 input_submit'>" +
  466.                         "           <input type='button' onclick='chatStaff.refresh(true);' id='staff-refresh-button' value='Reinprospatare' class='button2 input_submit'>" +
  467.                         "           <input type='button' onclick='chatStaff.showSmile(event);' id='staff-smiles-button' value='Smile-uri' class='button2 input_submit'>" +
  468.                         /*"         <input type='button' class='button2 input_submit' value='BBCode' id='staff-bbcode-button'>" +*/
  469.                         "           <div id='staff-smiles-show' style='display: none;'></div>" +
  470.                         "       </div>" +
  471.                         "   </div>" +
  472.                         "</div>"
  473.                     )
  474.                     .closest(".forabg, .table, tbody")
  475.                     .find(".topics, .posts, .lastpost, th:not(:first)")
  476.                     .remove();
  477.  
  478.                 if (localStorage.getItem("shout_height")) {
  479.                     jQuery("#staff-chatbox-shouts").css("height", localStorage.getItem("shout_height"));
  480.                 }
  481.                 jQuery("#staff-shout-input").keydown(function(e) {
  482.                     if (e.keyCode == 13 && jQuery("#staff-shout-input").val() !== "") {
  483.                         chatStaff.submitShout();
  484.                     }
  485.                 });
  486.                 chatStaff.refresh(true);
  487.                 chatStaff.readLoop = setInterval("chatStaff.refresh()", chatStaff.readInterval);
  488.                 chatStaff.loadSmile();
  489.             },
  490.  
  491.             dataRead: function(callback) {
  492.                 jQuery.ajax({
  493.                     url: '$install.DB_url$',
  494.                     cache: false,
  495.                     type: "get",
  496.                     dataType: "text",
  497.                     success: callback
  498.                 });
  499.             },
  500.  
  501.             dataSave: function(failMsg) {
  502.                 failMsg = failMsg || "";
  503.  
  504.                 jQuery.post('$install.DB_edit$', {
  505.                     subject: "$install.topicDB.subject$",
  506.                     message: JSON.stringify(chatStaff.oPost),
  507.                     edit_reason: "",
  508.                     attach_sig: 0,
  509.                     notify: 0,
  510.                     post: 1
  511.                 }).done(function() {
  512.                     /*
  513.                     chatStaff.getMsgs(function() {
  514.                         document.getElementById("staff-chatbox-shouts").scrollTop = 999999;
  515.                     });
  516.                     */
  517.                     chatStaff.stopRead = 0;
  518.                 }).fail(function() {
  519.                     if (failMsg.length) {
  520.                         alert(failMsg);
  521.                     }
  522.                     chatStaff.stopRead = 0;
  523.                 });
  524.             },
  525.  
  526.             parseDB: function(response, refresh) {
  527.                 refresh = refresh || false;
  528.  
  529.                 response = /{"user":.+}]}/i.exec(jQuery(response).text());
  530.                 /*response = jQuery("td > .postbody div, div.postbody > .content div, div.entry-content > div > div, div.post-entry div", response).first().text();*/
  531.                 if (response !== null) {
  532.                     response = response[0];
  533.                     if (refresh && chatStaff.postSize == response.length) {
  534.                         return false;
  535.                     }
  536.                     chatStaff.postSize = response.length;
  537.                     chatStaff.oPost = JSON.parse(response);
  538.                     if (refresh) {
  539.                         chatStaff.getMsgs(function() {
  540.                             document.getElementById("staff-chatbox-shouts").scrollTop = 999999
  541.                         });
  542.                     }
  543.                 }
  544.                 return true
  545.             },
  546.  
  547.             refresh: function(force) {
  548.                 force = force || false;
  549.  
  550.                 if (!force && chatStaff.stopRead) {
  551.                     return false;
  552.                 }
  553.                 chatStaff.dataRead(function(response, status, xhr) {
  554.                     if (xhr.status == 200) {
  555.                         chatStaff.parseDB(response, true);
  556.                     }
  557.                 });
  558.             },
  559.  
  560.             resize: function() {
  561.                 var element = jQuery("#staff-chatbox-shouts");
  562.                 jQuery(document).mousemove(function(event) {
  563.                     element.css("height", event.pageY - element.offset().top);
  564.                     document.getElementById("staff-chatbox-shouts").scrollTop = 999999;
  565.                 }).mouseup(function() {
  566.                     jQuery(document).unbind("mouseup").unbind("mousemove");
  567.                     localStorage.setItem("shout_height", element.css("height"));
  568.                 });
  569.             },
  570.  
  571.             getUser: function(id) {
  572.                 var user = chatStaff.oPost.user;
  573.                 for (var i = 0, len = user.length; i < len; i++) {
  574.                     if (user[i].id === id) {
  575.                         return user[i];
  576.                     }
  577.                 }
  578.                 return null;
  579.             },
  580.  
  581.             addMsg: function(id, msg, idx) {
  582.                 idx = idx || chatStaff.oPost.msgs.length;
  583.  
  584.                 if (!chatStaff.getUser(id)) {
  585.                     chatStaff.oPost.user.push({
  586.                         id: _userdata.user_id,
  587.                         name: _userdata.username,
  588.                         pname: encodeURIComponent(jQuery('a[href="/u' + _userdata.user_id + '"]').slice(-1)[0].innerHTML),
  589.                         avatar: jQuery(_userdata.avatar).attr("src")
  590.                     });
  591.                 }
  592.                 return (msg.length) ?
  593.                     chatStaff.oPost.msgs[idx] = {
  594.                         id: _userdata.user_id,
  595.                         msg: encodeURIComponent(msg).replace(/%20/g, " "),
  596.                         date: Math.round(new Date().getTime() / 1000)
  597.                             //date: (new Date().toLocaleTimeString().substr(0, 5)) + " - " + (new Date().toLocaleDateString()) //IE fail...
  598.                             //date: (new Date().toLocaleTimeString().split(":").slice(0, 2).join(":")) + " - " + (new Date().toLocaleDateString())
  599.                     } :
  600.                     chatStaff.oPost.msgs[idx] = null;
  601.             },
  602.  
  603.             delMsg: function(index) {
  604.                 return chatStaff.oPost.msgs.splice(index, 1);
  605.             },
  606.  
  607.             editMsg: function(index, value) {
  608.                 return chatStaff.oPost.msgs[index].msg = encodeURIComponent(value).replace(/%20/g, " ");
  609.             },
  610.  
  611.             getMsgs: function(callback) {
  612.                 var aMsgLen = chatStaff.oPost.msgs.length - 1,
  613.                     user = 0,
  614.                     epoch = "",
  615.                     posts = "";
  616.                 $.assyncFor(chatStaff.oPost.msgs, function(i, value) {
  617.                     user = chatStaff.getUser(value.id);
  618.                     epoch = new Date(value.date * 1000);
  619.                     posts +=
  620.                         '<div id="shout-row-' + i + '" class="row2">' +
  621.                         '   <span class="altrow_avatar">' +
  622.                         '       <img width="30" height="30" class="jschat_avatar" src="' + user.avatar + '" alt="avatar">' +
  623.                         '   </span>' +
  624.                         '   <span class="altrow_name">' +
  625.                         '       <a title="' + chatStaff.mentionMsg + '" data-store="' + user.name +
  626.                         '           " class="at_member" onclick="chatStaff.insertMember(this);return false;" href="#">@</a>&nbsp;' +
  627.                         '       <a title="" rel="nofollow" target="_blank" href="/u' + user.id + '" class="hover_url">' + user.pname + '</a>&nbsp;:' +
  628.                         '   </span>' +
  629.                         '   <span class="altrow_text">' +
  630.                         '       <span title="" class="right desc">(' + epoch.toLocaleString() + " )&nbsp;";
  631.                     if ((user.id == _userdata.user_id) && (i > 0)) {
  632.                         posts +=
  633.                             '       <img alt="' + chatStaff.editChatMsg + '" onclick="chatStaff.editShout(' + i + ', 0, this)" src="http://i59.servimg.com/u/f59/18/17/62/92/commen10.png">&nbsp;' +
  634.                             '       <img alt="' + chatStaff.delChatMsg + '" onclick="chatStaff.editShout(' + i + ', 1, this)" src="http://i59.servimg.com/u/f59/18/17/62/92/delete10.png">'
  635.                     }
  636.                     posts +=
  637.                         '       </span>' +
  638.                         '       <span class="shout_text">' + value.msg + '</span>' +
  639.                         '   </span>' +
  640.                         '</div>';
  641.  
  642.                     if (i == aMsgLen) {
  643.                         posts = posts.replace(/%0A|%5Cn/gi, "<br>");
  644.                         posts = decodeURIComponent(posts);
  645.                         /*
  646.                         if (/\[url]/gi.test(data)) {
  647.                             data = data.replace(/\[url]([\s\S]*?)\[\/url]/gi, "<a rel='nofollow' target='_blank' href='$1'>$1</a>");
  648.                         } else if (/\[url=/gi.test(data)) {
  649.                             data = data.replace(/\[url=([\s\S]*?)]([\s\S]*?)\[\/url]/gi, "<a rel='nofollow' target='_blank' href='$1'>$2</a>");
  650.                         } else {
  651.                             data = data.replace(/((?:https?|ftp)%3A%2F%2F[A-Z0-9+&@#\/%?=~_|$!:,.;-]*[A-Z0-9+&@#\/%=~_|$])/gi, "<a rel='nofollow' target='_blank' href='$1'>$1</a>");
  652.                         }
  653.                         */
  654.                         var pattLen = chatStaff.oBBCode.patt.length - 1,
  655.                             html = chatStaff.oBBCode.html;
  656.                         $.assyncFor(chatStaff.oBBCode.patt, function(i, value) {
  657.                             posts = posts.replace(value, html[i]);
  658.  
  659.                             if (i == pattLen) {
  660.                                 jQuery("#staff-chatbox-shouts").html(posts);
  661.                                 callback();
  662.                             }
  663.                         });
  664.                     }
  665.                 });
  666.             },
  667.  
  668.             submitShout: function() {
  669.                 var user_msg = jQuery("#staff-shout-input").val();
  670.                 if (user_msg == "") {
  671.                     return false;
  672.                 }
  673.                 chatStaff.stopRead = 1;
  674.                 jQuery("#staff-shout-input").val("");
  675.                 switch (user_msg) {
  676.                     case "/curata":
  677.                         chatStaff.oPost.user = [];
  678.                         chatStaff.oPost.msgs = [];
  679.                         user_msg = chatStaff.restartMsg;
  680.                         jQuery("#staff-chatbox-shouts").html("");
  681.                         break;
  682.                     case "/stop":
  683.                         jQuery("#staff-chatbox-shouts").css({
  684.                             "opacity": "0.4",
  685.                             "-moz-opacity": "0.4",
  686.                             "filter": "alpha(opacity=40)"
  687.                         });
  688.                         return false;
  689.                         break;
  690.                     case "/start":
  691.                         chatStaff.stopRead = 0;
  692.                         jQuery("#staff-chatbox-shouts").css({
  693.                             "opacity": "1",
  694.                             "-moz-opacity": "1",
  695.                             "filter": "alpha(opacity=100)"
  696.                         });
  697.                         return false;
  698.                         break;
  699.                     case '/info':
  700.                         return alert(
  701.                             chatStaff.info.Title +
  702.                             '\n\nVersiune: ' + chatStaff.info.Version +
  703.                             '\nData lansarii: ' + chatStaff.info.Release +
  704.                             '\nTip Cod:: ' + chatStaff.info.codeName +
  705.                             '\nAutor: ' + chatStaff.info.Author +
  706.                             '\nCopyright: ' + chatStaff.info.copyRight
  707.                         );
  708.                         break;
  709.                     case "/dezinstalare":
  710.                         if (chatStaff.confirm(chatStaff.uninstallMsg)) {
  711.                             jQuery("#staff-shoutbox-error").show();
  712.                             return chatStaff.uninstall();
  713.                         }
  714.                         return false;
  715.                         break;
  716.                 }
  717.  
  718.                 chatStaff.dataRead(function(response, status, xhr) {
  719.                     if (xhr.status == 200) {
  720.                         if (chatStaff.oPost.msgs.length) {
  721.                             chatStaff.parseDB(response);
  722.                         }
  723.                         if (chatStaff.postSize > 14000) {
  724.                             chatStaff.oPost.msgs.splice(0, 1);
  725.                             chatStaff.oPost.msgs.splice(1, 1);
  726.                         }
  727.                         chatStaff.addMsg(_userdata.user_id, user_msg);
  728.                         chatStaff.getMsgs(function() {
  729.                             document.getElementById("staff-chatbox-shouts").scrollTop = 999999;
  730.                             chatStaff.dataSave(chatStaff.sendError)
  731.                         });
  732.                     }
  733.                 });
  734.             },
  735.  
  736.             editShout: function(index, mode, vData) {
  737.                 chatStaff.stopRead = 1;
  738.                 if (mode == 0) {
  739.                     var td = jQuery(vData).closest(".altrow_text"),
  740.                         width = td.width() - td.find(".right.desc").width(),
  741.                         height = td.height(),
  742.                         sHtml =
  743.                             "<span class='shout_text' id='staff-shout-edit'>" +
  744.                             /*" <input type='text' maxlength='1024' size='50' class='input_text' value='" + decodeURIComponent(chatStaff.oPost.msgs[index].msg) + "' id='rt_input' style='width: 56%; margin-right: 4px;'>" +*/
  745.                             "   <textarea id='rt_input' style='width: " + width + "px; height: " + height + "px;'>" + decodeURIComponent(chatStaff.oPost.msgs[index].msg) + "</textarea>" +
  746.                             "   <input type='submit' id='rt_submit' class='button2' value='Save' onclick='chatStaff.editShout(" + index + ", 2, jQuery(\"#rt_input\").val());return false;' style='margin-right: 4px;'>" +
  747.                             "   <a title='Cancel' href='javascript:void(0);' onclick='var oEdit = jQuery(\"#staff-shout-edit\");oEdit.next().show();oEdit.prev().show();oEdit.remove();chatStaff.stopRead = 0;return false;'>Cancel</a>" +
  748.                             "</span>";
  749.                     td.find(".right.desc").hide();
  750.                     td.find(".shout_text").hide().before(sHtml);
  751.                     return false;
  752.                 }
  753.  
  754.                 chatStaff.dataRead(function(response, status, xhr) {
  755.                     if (xhr.status == 200) {
  756.                         chatStaff.parseDB(response);
  757.                         (mode == 2) ? chatStaff.editMsg(index, vData): chatStaff.delMsg(index);
  758.                         chatStaff.getMsgs(function() {
  759.                             chatStaff.dataSave(chatStaff.removeError)
  760.                         });
  761.                     }
  762.                 });
  763.             },
  764.  
  765.             loadSmile: function() {
  766.                 jQuery.ajax({
  767.                     url: "/post?mode=smilies",
  768.                     cache: true,
  769.                     type: "get",
  770.                     dataType: "text",
  771.                     success: function(response, status, xhr) {
  772.                         if (xhr.status == 200) {
  773.                             var htmlSmile = jQuery("<div>" + response + "</div>");
  774.                             htmlSmile.find("#smilies_categ, p, span").remove();
  775.                             htmlSmile.html(htmlSmile.html().replace(/insert_chatboxsmilie/g, "chatStaff.insertSmile"));
  776.  
  777.                             var oTarget = htmlSmile.find("a"),
  778.                                 alen = oTarget.length - 1,
  779.                                 oThis, patt, regex,
  780.                                 pHtml = chatStaff.oBBCode.patt,
  781.                                 bHtml = chatStaff.oBBCode.html;
  782.                             $.assyncFor(oTarget, function(i, value) {
  783.                                 oThis = jQuery(value);
  784.                                 patt = /\('(.*?)'\)/i.exec(oThis.attr("href"))[1];
  785.                                 regex = new RegExp("(?:^|\\s)" + patt.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\^\$\|]/g, "\\$&") + "(?:\\s|$)", "gi");
  786.                                 pHtml.push(regex);
  787.                                 bHtml.push(oThis.html());
  788.  
  789.                                 if (i == alen) {
  790.                                     var aSmiles = [
  791.                                             "&phone;", "&starf;", "&hearts;", "&sung;", "&check;",
  792.                                             "&boxbox;", "&copy;", "&Jscr;&Sscr;", "&block;", "&blk34;",
  793.                                             "&xcirc;", "&star;", "&clubs;", "&cross;", "&Fscr;&Mscr;"
  794.                                         ],
  795.                                         sSmiles = "<p>";
  796.                                     for (var i = 0, len = aSmiles.length; i < len; i++) {
  797.                                         sSmiles += "<a href='#' onclick='chatStaff.insertSmile(\"" + aSmiles[i] + "\");return false;'>" + aSmiles[i] + "</a>"
  798.                                     }
  799.                                     sSmiles += "</p>";
  800.                                     jQuery("#staff-smiles-show").html(sSmiles + htmlSmile.find("#simple-wrap, tbody:last").html())
  801.                                 }
  802.                             });
  803.                         }
  804.                     }
  805.                 })
  806.             },
  807.  
  808.             showSmile: function(event) {
  809.                 var elenPos = jQuery("#staff-smiles-button"),
  810.                     target = jQuery("#staff-smiles-show");
  811.                 target.css({
  812.                     "left": (elenPos.offset().left + elenPos.outerWidth()) - target.outerWidth(),
  813.                     "top": elenPos.offset().top - target.outerHeight()
  814.                 });
  815.                 return (target[0].style.display == "none") ? target.fadeIn("fast") : target.fadeOut("fast");
  816.             },
  817.  
  818.             insertSmile: function(smile) {
  819.                 var id = document.getElementById("rt_input") || document.getElementById("staff-shout-input");
  820.                 id.focus();
  821.                 id.value += " " + smile + " ";
  822.                 document.getElementById("staff-smiles-show").style.display = "none";
  823.             },
  824.  
  825.             insertMember: function(oThis) {
  826.                 var id = document.getElementById("staff-shout-input");
  827.                 id.focus();
  828.                 id.value += "@" + oThis.getAttribute("data-store") + " -> ";
  829.             },
  830.  
  831.             confirm: function(text) {
  832.                 return (confirm(text) == true) ? true : false;
  833.             },
  834.  
  835.             // Basic info...
  836.             info: {
  837.                 Title: "Staff Chatbox",
  838.                 Version: "$install.version$",
  839.                 Release: "31.05.2015",
  840.                 codeName: "sosrio",
  841.                 Author: "JScript - 11.02.2015",
  842.                 copyRight: "(c) 2015 JScript <jscriptbrasil la live punct com>\nContributia mea a fost gratuita. Redistribuirea sau modificarea trebuie sa se faca conform termenilor WTFPL, Versiunea 2"
  843.             },
  844.  
  845.             uninstall: function() {
  846.                 var TID = jQuery('a[href*="tid="]').attr("href").split("tid=")[1].split("&")[0],
  847.                     prgBar = parseInt((jQuery("#staff-shoutbox-error").width() / 4) / 9);
  848.                 document.getElementById("staff-shoutbox-error").innerHTML += "&blk34;".repeat(prgBar);
  849.  
  850.                 jQuery.ajax({
  851.                     url: "/admin/index.forum?part=general&sub=general&mode=edit&fid=$install.permissions.fid$&extended_admin=1&tid=" + TID,
  852.                     type: "post",
  853.                     data: {
  854.                         fid: "$install.permissions.fid$",
  855.                         mode: "delete",
  856.                         move: -2,
  857.                         selected_id: "Root",
  858.                         update: "Delete"
  859.                     },
  860.                     dataType: "html",
  861.                     success: function(response, status, xhr) {
  862.                         document.getElementById("staff-shoutbox-error").innerHTML += "&blk34;".repeat(prgBar);
  863.                         if (xhr.status == 200) {
  864.                             var response = jQuery(response);
  865.                             if (response.find(".successbox") !== null) {
  866.                                 jQuery.ajax({
  867.                                     url: "/admin/index.forum?mode=js&part=modules&sub=html&tid=" + TID,
  868.                                     type: "get",
  869.                                     dataType: "html",
  870.                                     success: function(response, status, xhr) {
  871.                                         document.getElementById("staff-shoutbox-error").innerHTML += "&blk34;".repeat(prgBar);
  872.                                         if (xhr.status == 200) {
  873.                                             var response = jQuery(response);
  874.                                             var JS = response.find("#listJs td:contains('Modul: $install.topicDB.subject$')").closest("tr").find("td:last input").val();
  875.                                             jQuery.ajax({
  876.                                                 url: "/admin/index.forum?part=modules&sub=html&mode=js&extended_admin=1&tid=" + TID,
  877.                                                 type: "post",
  878.                                                 data: {
  879.                                                     conf: [JS],
  880.                                                     confirm: 1,
  881.                                                     mode: "js_delete"
  882.                                                 },
  883.                                                 dataType: "html",
  884.                                                 success: function(response, status, xhr) {
  885.                                                     document.getElementById("staff-shoutbox-error").innerHTML += "&blk34;".repeat(prgBar);
  886.                                                     if (xhr.status == 200) {
  887.                                                         alert("$install.dinstMsg3$");
  888.                                                         window.location.reload(true);
  889.                                                     }
  890.                                                 }
  891.                                             });
  892.                                         }
  893.                                     }
  894.                                 });
  895.                             }
  896.                         }
  897.                     }
  898.                 });
  899.             }
  900.         };
  901.  
  902.         chatStaff.initialize();
  903.     };
  904.  
  905.     chatbox_script =
  906.         '/***\n' +
  907.         ' * Application: Staff\'s ChatBox.\n' +
  908.         ' * Description: Exclusive chat room for your forum staff.\n' +
  909.         ' * Version: ' + install.version + ' - ' + install.codeName + '\n' +
  910.         ' * Made and Optimizations by JScript - 2015/02/11\n' +
  911.         ' * Copyright (c) 2015 JScript <jscriptbrasil at live dot com>\n' +
  912.         ' * This work is free. You can redistribute it and/or modify it\n' +
  913.         ' * under the terms of the WTFPL, Version 2\n' +
  914.         ' */\n\n' +
  915.         "(" +
  916.             chatbox_script.toString()
  917.                 .replace(/\$install.version\$/g, install.version)
  918.                 .replace(/\$install.codeName\$/g, install.codeName)
  919.                 .replace(/\$install.create.name\$/g, install.create.name)
  920.                 .replace(/\$install.author\$/g, install.author)
  921.                 .replace(/\$install.uninstallMsg\$/g, install.uninstallMsg)
  922.                 .replace(/\$install.permissions.fid\$/g, install.permissions.fid)
  923.                 .replace(/\$install.DB_url\$/g, install.DB_url)
  924.                 .replace(/\$install.DB_edit\$/g, install.DB_edit)
  925.                 .replace(/\$install.topicDB.subject\$/g, install.topicDB.subject)
  926.                 .replace(/\$install.dinstMsg1\$/g, install.dinstMsg1)
  927.                 .replace(/\$install.dinstMsg2\$/g, install.dinstMsg2)
  928.                 .replace(/\$install.dinstMsg3\$/g, install.dinstMsg3) +
  929.         ")();"
  930.     ;
  931.  
  932.     msgElem.innerHTML = install.instMsg4;
  933.     install.updateProgressBar(45);
  934.     jQuery.post('/admin/index.forum?part=modules&sub=html&mode=js_edit&extended_admin=1&tid=' + install.TID, { /* <- Parameters! */
  935.         /* Post action */
  936.         title: 'Modul: ' + install.topicDB.subject,
  937.         js_placement: ['index'],
  938.         type: 0,
  939.         content: chatbox_script,
  940.         mode: 'save',
  941.         submit: 1
  942.     }).done(function() {
  943.         install.updateProgressBar(65);
  944.         jQuery.ajax({
  945.             url: "/admin/index.forum?mode=js&part=modules&sub=html&tid=" + install.TID,
  946.             type: "get",
  947.             dataType: "html",
  948.             success: function(response, status, xhr) {
  949.                 if (xhr.status == 200) {
  950.                     var response = jQuery(response);
  951.                     var JS = response.find("#listJs td:contains(\'@instalare_chat\')").closest("tr").find("td:last input").val();
  952.  
  953.                     install.updateProgressBar(85);
  954.                     jQuery.ajax({
  955.                         url: "/admin/index.forum?part=modules&sub=html&mode=js&extended_admin=1&tid=" + install.TID,
  956.                         type: "post",
  957.                         data: {
  958.                             conf: [JS],
  959.                             confirm: 1,
  960.                             mode: "js_delete"
  961.                         },
  962.                         dataType: "html",
  963.                         success: function(response, status, xhr) {
  964.                             if (xhr.status == 200) {
  965.                                 install.updateProgressBar(100);
  966.                                 alert(install.instMsg5);
  967.                                 window.location.reload(true);
  968.                             }
  969.                         }
  970.                     });
  971.                 }
  972.             }
  973.         });
  974.     });
  975. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement