1. Лучший говнокод

    В номинации:
    За время:
  2. JavaScript / Говнокод #14402

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    function search(url,param)
                    {
                            $("#rightContent").hide()
                            setBlock("Загрузка")
                            loadLeftMenu()
                            $("#content").load("/search", function(response, status, xhr){
                                $("#Subscription").show()
                                    queryStr=param.split("&")
    
                                    if (queryStr.length==2){
                                            str=(queryStr[0]).replace("querystr=","")
                                            $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
                                            region=((queryStr[1]).replace("region=","")).split(",")
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            updateMultiselect("#region", region, "region")
                                    }
                                    if (queryStr.length==3){
                                            str=(queryStr[1]).replace("querystr=","")
                                            $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
                                            region=((queryStr[2]).replace("region=","")).split(",")
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            updateMultiselect("#region", region, "region")
                                    }
                                    if (queryStr.length==4){
                        str=(queryStr[0]).replace("querystr=","")
                        $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
    
                        region=((queryStr[1]).replace("region=","")).split(",")
    
                        if (queryStr[2]=='fz94=true'){
                          $('#fz94').attr('checked','checked')
                        }else{
                          $('#fz94').removeAttr('checked')
                        }
    
                        if (queryStr[3]=='fz223=true'){
                          $('#fz223').attr('checked','checked')
                        }else{
                          $('#fz223').removeAttr('checked')
                        }
                                            
                                            replaceItemInArray(region,"59","59,81")
                                            removeFromArray(region,'81')
                                            replaceItemInArray(region,"75","75,80")
                                            removeFromArray(region,'80')
                                            
                                            updateMultiselect("#region", region, "region")
                                    }
                    if (queryStr.length==5){
                        str=(queryStr[1]).replace("querystr=","")
                        $("#querystr").val(decodeURI(str.replace(/\+/g," ")))
    
                        region=((queryStr[2]).replace("region=","")).split(",")
    
                        if (queryStr[3]=='fz94=true'){
                            $('#fz94').attr('checked','checked')
                        }else{
                            $('#fz94').removeAttr('checked')
                        }
    
                        if (queryStr[4]=='fz223=true'){
                            $('#fz223').attr('checked','checked')
                        }else{
                            $('#fz223').removeAttr('checked')
                        }
    
                        replaceItemInArray(region,"59","59,81")
                        removeFromArray(region,'81')
                        replaceItemInArray(region,"75","75,80")
                        removeFromArray(region,'80')
    
                        updateMultiselect("#region", region, "region")
                    }
    
    // Ну и так далее

    Разбор строки запроса

    hdkeeper, 23 Января 2014

    Комментарии (0)
  3. PHP / Говнокод #14339

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    function t($text, $parameters = null) {
            $lang = empty($_COOKIE['lang']) ? 'ru' : $_COOKIE['lang'];
            $result = !array_key_exists($text, Application_Model_Translate::$lang_package) || ($lang == 'ru') ? $text :
                    Application_Model_Translate::$lang_package[$text][(int) ($lang == 'en')];
            if (isset($parameters)) {
                    if (!is_array($parameters))
                            $parameters = array($parameters);
                    foreach ($parameters as &$param)
                            $param = addslashes($param);
                    eval('$result = sprintf($result, "'. implode('","', $parameters) . '");');
            }
            return $result;
    }

    Groovy, 10 Января 2014

    Комментарии (43)
  4. PHP / Говнокод #14304

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    class core {
    public static function txt($var){
    $var = trim($var);
    $var = stripslashes($var);
    $var = str_replace("\00", '', $var);
    $var = htmlspecialchars($var, ENT_QUOTES, 'UTF-8');
    $var = str_replace("%", "\%", $var);
    $var = str_replace("_", "\_", $var);
    $var = iconv('utf-8', 'windows-1251', $var);
    $var = iconv('windows-1251', 'utf-8', $var);
    return $var;
    }
    public static function nik($id){
    global $dbs;
    $nick = $dbs->query("SELECT * FROM `users` WHERE `id` = '$id'")->fetch_assoc();
    if(empty($nick)){
    $us = '[Удален]';
    }else{
    $us = ($nick['onl']<time()-600?'<font color="red">[off]</font>':'<font color="green">[on]</font>').' <a href="/'.$nick['login'].'" style="color:black;"><b>'.$nick['login'].'</b></a>';
    }
    return $us;
    }
    /*.....и еще куча срани*/

    Вот он ООП, ну и оптимизция))

    Ruslyakan, 31 Декабря 2013

    Комментарии (107)
  5. JavaScript / Говнокод #14272

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function hideRequestBySelector(selector, str) {
        var num = $('td:nth-child(2)', selector).text();
        var cur = $('.requests .main-tr-more.' + num);
        var requestSent = $('.requests .send-notice.' + num);
        $(selector).css('background','#ccc');
        $('td:nth-child(1)', selector).html('<img src="/static/v12/img/tr-ok.png" alt="">');
        $(".main-request-action."+ num +" .answers-number.magenta").show();
        var code = "cur." + str + ";requestSent." + str + ";";
        eval(code);                                                                         
    }

    Черномагическое применение jquery-метода к обьекту по селектору

    blessed, 25 Декабря 2013

    Комментарии (0)
  6. PHP / Говнокод #14271

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    class StaticArray { // TO DO: add float, char, double
    private $min = 0;
    private $lengch = 0;
    private $max = 0;
    private $array = array();
    function __construct($lengch,$type) {
    if (!is_numeric($lengch) || $type != 'int'&& $type != 'long'&& $type != 'byte'&& $type != 'short'){  
    echo "BAD ARRRAY TYPE OR LENGCH!\n";
    return false;
    }
    $this->lengch = $lengch;
    switch ($type){
    case 'int':
    $this->min = -2147483647;
    $this->max = 2147483648;
    break;
    case 'byte':
    $this->min = -127;
    $this->max = 128;
    break;
    case 'short':
    $this->min = -32768;
    $this->max = 32767;
    break;
    case 'long':
    $this->min = -9223372036854775808;
    $this->max = 9223372036854775807;
    break;
    }
    for ($i=0;$i < $lengch;$i++){
    $this->array[$i] = 0;
    }
    }
     function add ($vaule,$num){
     if ($vaule >= $this->max || $vaule <= $this->min || !is_numeric($num) || $num < 0 || $num >= $this->lengch){
     echo "Not valid vaule!\n";
     return false;
     }
     $this->array[$num] = $vaule;
    }
     
     function ToNormalArray (){
     return $this->array;
     }
     function get ($num){
     if ($num >= $this->lengch || $num < 0){
     echo "BAD ARRAY INDEX\n";
     return false;
     }
     return $this->array[$num];
     }
     function GetLengch(){
     return $this->lengch; 
    }
    }

    Обнаружил в исходниках одного из сайтов который разрабатывал. Предыдущий кодер действительно этим ползовался! Особенно умиляет метод ToNormalArray().

    zadrot, 25 Декабря 2013

    Комментарии (30)
  7. PHP / Говнокод #14242

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /* @component Phoca Component
     * @copyright Copyright (C) Jan Pavelka www.phoca.cz
    */
    	protected function getLabel() {
    		echo '<div class="clearfix"></div>';
    		return parent::getLabel();
    		echo '<div class="clearfix"></div>';
    	}

    Это диагноз...

    virtual_cia, 18 Декабря 2013

    Комментарии (35)
  8. PHP / Говнокод #14044

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    function date_to_text($date){
    	
    
    	
    	$now=time();
    	if ($s=strtotime($date)) //the function returns false is $date is not a string (as already in numeric unix date format)
    		$date = $s;
    	$d=round(($now-$date)); //s
    
    	//echo $d;
    	if($d>60){
    		$d=$d/60;//m	
    		if($d>60){
    			$d=$d/60;//h
    			if($d>24){
    				$d=$d/24;//d
    				if($d>7){
    					$d=$d/7;//w						
    					if($d>(52/12)){
    						$d=$d/52*12;//m
    						if($d>12){
    							$d=$d/12;//y
    							$d=floor($d);			
    							$str=$d.' year'.(($d>1)?'s':'');								
    						}else{
    							$d=floor($d);			
    							$str=$d.' month'.(($d>1)?'s':'');		
    						}
    					}else{
    						$d=floor($d);			
    						$str=$d.' wk'.($d>1?'s':'');									
    					}
    				}else{					
    					$d=floor($d);
    					$str=$d.' day'.($d>1?'s':'');											
    				}
    			}else{			
    				$d=floor($d);			
    				$str=$d.' hr'.(($d>1)?'s':'');		
    			}
    		}else{
    			$d=floor($d);			
    			$str=$d.' min'.(($d>1)?'s':'');			
    		}
    	}elseif ($d>0) {
    		$d=floor($d);			
    		$str=$d.' sec'.(($d>1)?'s':'');		
    	}
    	if ($d>0){
    		$str.=' ago';
    	} else {
    		$str = '';
    	}
    	return $str;
    }

    неопiсуемо

    rombik, 22 Октября 2013

    Комментарии (3)
  9. PHP / Говнокод #13912

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?php
    
    if ($user_id == 0 || $user_id == '0') {
        /*НИЧЕГО*/
    }

    1С Битрикс, этим всё сказано...

    P.S давненько ничего не постил...

    qbbr, 09 Октября 2013

    Комментарии (3)
  10. PHP / Говнокод #13887

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    foreach ($item as $prop) {
                if ($prop['tag']==$this->props[0]){
                    $new_item['sku']=(int)$prop['value'];
                } else {
                    if ($prop['tag'] == $this->props[1]) {
                        $new_item['name']=$prop['value'];
                    } else {
                        if ($prop['tag'] == $this->props[2]) {
                            $new_item['price']=(float)$prop['value'];
                        } else {
                            if ($prop['tag'] == $this->props[3]) {
                                $new_item['is_spec']=(float)$prop['value'];
                            } else {
                                if ($prop['tag'] == $this->props[4]) {
                                    $new_item['spec_price']=(float)$prop['value'];
                                } else {
                                    if ($prop['tag'] == $this->props[5]) {
                                        $new_item['old']=(float)$prop['value'];
                                    }
                                }
                            }
                        }
                    }
                }
            }

    XML бессмысленный и беспощадный

    madfriend, 02 Октября 2013

    Комментарии (9)
  11. JavaScript / Говнокод #13562

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    registrationButtons = (function ()
      {
        var initRequestInviteButton = function ()
        {
          $("#btnRequestInvite").on('click', function ()
          {
            $('#login-registry-form').submit();
          });
        };
        var initRequestConfirmationButton = function ()
        {
          $("#btnRequestConfirmation").on('click', function ()
          {
            $('#login-registry-form').submit();
          });
        };
        var initForgotPasswordButton = function ()
        {
          $("#btnForgotPassword").on('click', function ()
          {
            $('#login-forgot-form').submit();
          });
        };
        var initLoginBrandButton = function ()
        {
          $("#buttonRegisterBrands").on('click', function ()
          {
            $('#login-brand-form').submit();
          });
        };
        var initSignInFromFacebookButton = function ()
        {
          $("#buttonSignInFromFacebook").on('click', function ()
          {
            $('#login-form').submit();
          });
        };
        var initStartPampingButton = function ()
        {
          $("#btnStartPamping").on('click', function ()
          {
            $('#login-options-form').submit();
          });
        };
        var initRequestInviteTwitterButton = function ()
        {
          $("#btnRequestInviteTwitter").on('click', function ()
          {
            $('#login-form').submit();
          });
        };
        var initSetPasswordButton = function ()
        {
          $("#btnSetPassword").on('click', function ()
          {
            $('#login-reset-form').submit();
          });
        };
        var external = {
          init: function ()
          {
            initRequestInviteButton();
            initRequestConfirmationButton();
            initForgotPasswordButton();
            initLoginBrandButton();
            initSignInFromFacebookButton();
            initStartPampingButton();
            initRequestInviteTwitterButton();
            initSetPasswordButton();
          },
          initRequestInviteButton: function ()
          {
            initRequestInviteButton();
          },
          initFBButtons: function ()
          {
            initSignInFromFacebookButton();
          },
          initForgotPasswordButton: function ()
          {
            initForgotPasswordButton();
          },
          initStartPampingButton: function ()
          {
            initStartPampingButton();
          },
          initTwitterButtons: function ()
          {
            initRequestInviteTwitterButton();
          },
          initSetPasswordButton: function ()
          {
            initSetPasswordButton();
          }
        };
        return external;
      })();

    DarkThinker, 07 Августа 2013

    Комментарии (0)