[MOD][V2.2.2][FUN]Optimización json.php

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

  • [MOD][V2.2.2][FUN]Optimización json.php

    Aquí les dejo el fichero un poco mas optimizado cumpliendo la misma función pero con menos de líneas de código. Si te resulto útil este post no olvides dejarnos un like :thumbsup:

    PHP Source Code: json.php

    1. <?php
    2. /*
    3. * ╔══╗╔══╗╔╗──╔╗╔═══╗╔══╗╔╗─╔╗╔╗╔╗──╔╗╔══╗╔══╗╔══╗
    4. * ║╔═╝║╔╗║║║──║║║╔═╗║║╔╗║║╚═╝║║║║║─╔╝║╚═╗║║╔═╝╚═╗║
    5. * ║║──║║║║║╚╗╔╝║║╚═╝║║╚╝║║╔╗─║║╚╝║─╚╗║╔═╝║║╚═╗──║║
    6. * ║║──║║║║║╔╗╔╗║║╔══╝║╔╗║║║╚╗║╚═╗║──║║╚═╗║║╔╗║──║║
    7. * ║╚═╗║╚╝║║║╚╝║║║║───║║║║║║─║║─╔╝║──║║╔═╝║║╚╝║──║║
    8. * ╚══╝╚══╝╚╝──╚╝╚╝───╚╝╚╝╚╝─╚╝─╚═╝──╚╝╚══╝╚══╝──╚╝
    9. *
    10. * @author Tsvira Yaroslav <https://github.com/Yaro2709>
    11. * @info ***
    12. * @link https://github.com/Yaro2709/New-Star
    13. * @Basis 2Moons: XG-Project v2.8.0
    14. * @Basis New-Star: 2Moons v1.8.0
    15. */
    16. define('MODE', 'JSON');
    17. define('ROOT_PATH', str_replace('\\', '/',dirname(__FILE__)).'/');
    18. require(ROOT_PATH.'includes/common.php');
    19. $AJAX = array();
    20. // $new_code
    21. $MIS = array(1 => 'ataks', 6 => 'spio', 9 => 'unic', 10 => 'rakets');
    22. $sql = "SELECT COUNT(*) as count FROM %%FLEETS%% WHERE fleet_start_time > :time AND fleet_mission = :missionId AND fleet_mess = 0 AND fleet_owner <> :userId AND fleet_target_owner = :userId;";
    23. foreach ($MIS as $MisID => $Type) {
    24. $total = Database::get()->selectSingle($sql, array(
    25. ':userId' => $USER['id'],
    26. ':time' => TIMESTAMP,
    27. ':missionId' => $MisID
    28. ));
    29. $AJAX[$Type] = $total['count'];
    30. }
    31. if($AJAX['ataks'] > 0)
    32. $AJAX['ICOFLEET'] ='<div id="attack" class="indicator active_indicator">';
    33. else
    34. $AJAX['ICOFLEET'] ='<div id="attack" class="indicator">';
    35. $AJAX['ICOFLEET'] .='<div class="icoi"></div>';
    36. $AJAX['ICOFLEET'] .='</div>';
    37. if($AJAX['spio'] > 0)
    38. $AJAX['ICOFLEET'] .='<div id="espionage" class="indicator active_indicator">';
    39. else
    40. $AJAX['ICOFLEET'] .='<div id="espionage" class="indicator">';
    41. $AJAX['ICOFLEET'] .='<div class="icoi"></div>';
    42. $AJAX['ICOFLEET'] .='</div>';
    43. if($AJAX['unic'] > 0)
    44. $AJAX['ICOFLEET'] .='<div id="destruction" class="indicator active_indicator">';
    45. else
    46. $AJAX['ICOFLEET'] .='<div id="destruction" class="indicator">';
    47. $AJAX['ICOFLEET'] .='<div class="icoi"></div>';
    48. $AJAX['ICOFLEET'] .='</div>';
    49. if($AJAX['rakets'] > 0)
    50. $AJAX['ICOFLEET'] .='<div id="rocket" class="indicator active_indicator">';
    51. else
    52. $AJAX['ICOFLEET'] .='<div id="rocket" class="indicator">';
    53. $AJAX['ICOFLEET'] .='<div class="icoi"></div>';
    54. $AJAX['ICOFLEET'] .='</div>';
    55. $AJAX['SOUNDATAKS'] = false;
    56. if($USER['sound_ataks'] != 0)
    57. {
    58. if($AJAX['SOUNDATAKS'] == false)
    59. $AJAX['SOUNDATAKS'] = HTTP::_GP('ataks', 0) < $AJAX['ataks'] ? true : false;
    60. if($AJAX['SOUNDATAKS'] == false)
    61. $AJAX['SOUNDATAKS'] = HTTP::_GP('unic', 0) < $AJAX['unic'] ? true : false;
    62. if($AJAX['SOUNDATAKS'] == false)
    63. $AJAX['SOUNDATAKS'] = HTTP::_GP('rakets', 0) < $AJAX['rakets'] ? true : false;
    64. }
    65. $AJAX['NEWMSG'] = $USER['messages'] == 0 ? '' : ("+".$USER['messages']);
    66. $AJAX['SOUNDMSG'] = false;
    67. if($USER['setting_msg'] != 0)
    68. {
    69. $AJAX['SOUNDMSG'] = true;
    70. }
    71. $AJAX['msg'] = $USER['messages'];
    72. echo json_encode($AJAX);
    73. ?>
    Display All
    Files
    • json.zip

      (1.3 kB, downloaded 41 times, last: )