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

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function unix_timestamp_to_human ($timestamp = "", $format = 'D d M Y - H:i:s')
    {
        if (empty($timestamp) || ! is_numeric($timestamp)) $timestamp = time();
        return ($timestamp) ? date($format, $timestamp) : date($format, $timestamp);
    }
    
    $unix_time = "1251208071";
    
    echo unix_timestamp_to_human($unix_time); //Return: Tue 25 Aug 2009 - 14:47:51

    Я всё правильно понял, код воняет?

    denis90, 15 Июня 2013

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

    +152

    1. 1
    2. 2
    // maybe even strtolower($value)?
    $bool = ($value && ($value !== 'false') && ($value !== 'null'));

    А разгадка одна — безблагодатность^w кривой JSON.

    AntonioK, 06 Июня 2013

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

    +152

    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
    function CreatePriceListArray($result_array)//TODO:Формирует древовидную форму прайс листа
    {
    		//print_r($result_array);
        $price_list=array();//Жилая недвижимость
        $current_object_name="";
        $current_section_name="none";
        $current_section_id=0;
        $current_object_array=null;
        $current_section_array=null;
        $current_kvartira_type=null;
        $current_kvartira_type_name="";
        $current_kvartira=null;
        $current_kvartira_area="";
        
        foreach($result_array as $value)
        {
            if($current_object_name != $value['object'])
            {
                if($current_object_array !=null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                    $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
                }
                $current_object_array=array();
                $current_object_name=$value['object'];
                $current_section_name="none";
                $current_section_id=0;
                $current_section_array=null;
            }
    
            if($current_section_name != $value['section_name'])
            {
                   // echo $current_kvartira_type['name']; echo ' | ';
                //if($current_kvartira_type['name'] != '') 
                {
                    
                    foreach ($current_kvartira_type as $value)
                    
                    //print_r($current_kvartira_type);
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);                
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                }
                $current_section_array=array();
                $current_section_name = $value['section_name'];
                $current_section_id=$value['section_id'];
               // $current_kvartira_type=null;
                $current_kvartira_type_name="";
            }
    
            if($current_kvartira_type_name != $value['kvartira_name'])
            {
               // if($current_kvartira_type != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                }
                $current_kvartira_type=array();
                $current_kvartira_type_name = $value['kvartira_name'];
                $current_kvartira=null;
                $current_kvartira_area="";
            }
    
            if($current_kvartira_area != $value['area'])
            {
               // if($current_kvartira != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                }
                $current_kvartira=array();
                $current_kvartira_area = $value['area'];
            }
            
            $current_kvartira[]=$value['floor'];
        }
    		
    			
           $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
           $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
           $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
    //echo $current_object_name;        
    if($current_object_name!='') $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
    
    echo '<!--';
    print_r($price_list);
    echo '-->';
        return $price_list;    
    }

    Пытаюсь тут что-то найти... Идет второй час.

    ghz, 04 Июня 2013

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

    +152

    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
    <?php
    session_start();
    
    if (empty($_SESSION['login']) or empty($_SESSION['session_id'])) {
    	$DATA = array('login' => $_POST['login'], 'password' => $_POST['password']);
    	include "classes/data_base_class.php";
    	$auth_result = DataBase::StartAuth($DATA['login'], $DATA['password']);
    	
    	if ($auth_result == 1) {
    		echo '<meta http-equiv="refresh" content="0;URL=../error.php?mod=auth">';
    		exit();
    	}
    	else
    	{
    		$_SESSION['login'] = $auth_result['user_login'];
    		$_SESSION['user_name'] = $auth_result['user_name'];
    		$_SESSION['session_id'] = $auth_result['reg_data'];
    		echo '<meta http-equiv="refresh" content="0;URL=../index.php">';
    		exit();
    	}
    }
    else
    {
    	echo '<meta http-equiv="refresh" content="0;URL=../index.php">';
    	exit();
    }
    ?>

    Вот вам авторизация, ага - ага!

    Govnisti_Diavol, 07 Мая 2013

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

    +152

    1. 1
    $language = json_decode(JFactory::getUser()->getProperties()['params'])->language;

    Посоны, это нормально или у меня диагноз Чехова?

    nonamez, 18 Апреля 2013

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

    +152

    1. 1
    return x==y && "$x"=="$y";

    а вдруг нет?

    Lure Of Chaos, 17 Апреля 2013

    Комментарии (8)
  8. JavaScript / Говнокод #12830

    +152

    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
    function TimeViewport(rootElement, container, canvas, minZoom, maxZoom)
    {
    	this.container = container;
    	this.rootElement = rootElement;
    	this.lowPassAlpha = 0.38;
    	this.canvas = canvas;
    	this.minZoom = minZoom;
    	this.maxZoom = maxZoom;
    	this.zoom = minZoom;
    	this.size = Math.min(1.0, 1.0 / Math.pow(2, this.zoom));
    	this.left = 0.5 - this.size / 2.0;
    	this.right = 0.5 + this.size / 2.0;
    	this.mouse = {
    		isDown : false,
    		panning : false,
    		velocityMode : false,
    		downPos : {x : 0, y : 0}, 
    		movePos : {x : 0, y : 0},
    		lastMovePos : {x : 0, y : 0}
    	};
    	var self = this;
    	this.filtered = {
    		"left" : 0.5 - self.size / 4.0,
    		"right" : 0.5 + self.size / 4.0
    	};
    	this.lastRedrawTime = (new Date()).getTime();
    	this.maxRedrawInterval = 500;
    	setInterval(function () { if (self.doLowPass != null) self.doLowPass(); }, 17);
    	this.canvas.onmousedown = function(event) { self.mouseDown(event) };
    	this.canvas.onmousewheel = function(event) { self.onMouseWheel(event); };
    	var oldMouseMoveHandler = this.rootElement.onmousemove;
    	this.rootElement.onmousemove = function (event) {
    		if (self.mouseMove) self.mouseMove(event);
    		if (oldMouseMoveHandler != null) oldMouseMoveHandler(event);
    	};
    	var oldMouseUpHandler = this.rootElement.onmouseup;
    	this.rootElement.onmouseup = function (event) {
    		if (self.mouseUp) self.mouseUp(event);
    		if (oldMouseUpHandler != null) oldMouseUpHandler(event);
    	};
    	var oldMouseLeaveHandler = this.rootElement.onmouseleave;
    	this.rootElement.onmouseleave = function (event) {
    		if (self.mouseLeave) self.mouseLeave(event);
    		if (oldMouseLeaveHandler != null) oldMouseLeaveHandler(event);
    	};
    };

    Очередной велосипедик.

    just_nameless, 30 Марта 2013

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

    +152

    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
    <html>
        <head>
        <meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>
        <head>
        <title>test</title>
        <script type="text/javascript">
        // Функция, осуществляющая AJAX запрос
        function loadXMLDoc(method, url) {
          if(window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open(method, url, true);
            req.send(null);
          } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            req.onreadystatechange = processReqChange;
            req.open(method, url, true);
            req.send();
          }
        }
        // Функция, выполняемая при изменении статуса
        // запроса, если статус  равен 200, данные получены
        function processReqChange() {
          if(req.readyState == 4) {
         
            if(req.status == 200) {
              getNumber(req.responseText);
         
            } else {
              alert("There was a problem retrieving the XML data:\n" + req.statusText);
            }
          }
        }
        // Функция выполняется при клике по кнопке
        function process() {
         
           var v = document.getElementById("flag");
           var url = "ajax.php?flag=" + v.checked;
           loadXMLDoc( "get", url );
           setTimeout('process()', 1000);
        }
         
        // Функция записывает в элемент content значение, полученное от сервера
        function getNumber(text) {
          //для текстового поля
          var content = document.getElementById( "content" );
         content.value = text;
          //для div
         var content = document.getElementById( "content2" );
         content.innerHTML = text;
         
        }
         
        </script>
        </head>
        <body onload='process()'>
        <input type='checkbox' id='flag'>Флажок
        <input type='text' id='content'>
        <div id='content2'></div>
        </body>
        </html>
        .....................................................................................
         
        //файл ajax.php
        <?php
        if (isset($_GET['flag']))
        {
        if($_GET['flag']==='true') echo 'checked';
        else echo 'not checked';
        }
        ?>

    Как скопировать значение одного поля в другое.
    Очередное оригинальное решение от нашего старого знакомого, который не верит в существование говнокода и быдлокодеров.

    Stallman, 13 Марта 2013

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

    +152

    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
    function getTestDataById ($testid) {
    
    	$query="select * from mdl_test where id=".$testid."";
    	$result = mysql_query($query) or die('getTestDataById query failed: ' . mysql_error());
    
    	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
    	$courseid=$row['courseid'] ;
    	$moduleid=$row['moduleid'];
    	$name=$row['name'];
    	$maxscore=$row['maxscore'];
    	$successscore=$row['successscore'];
    	$attempts=$row['attempts'];
    	$dur=$row['dur'];
    	$showsuccessmessage=$row['showsuccessmessage'];
    	$successmessage=$row['successmessage'];
    	$showfailedmessage=$row['showfailedmessage'];
    	$failedmessage=$row['failedmessage'];
    	$showtestsuccessmessage=$row['showtestsuccessmessage'];
    	$testsuccessmessage=$row['testsuccessmessage'];
    	$showtestfailedmessage=$row['showtestfailedmessage'];
    	$testfailedmessage=$row['testfailedmessage'];
    	$freequestions=$row['freequestions'];
    	$questionsorder=$row['questionsorder'];
    	$defertest=$row['defertest'];
    	$totalperpage=$row['totalperpage'];
    	$showcorrectreply=$row['showcorrectreply'];
    	$showscore=$row['showscore'];
    	$limittype = $row['limittype'];
    	$annotation = $row['annotation'];
    
    	} // end while
    
    	$res=array('courseid'=>$courseid,
    			   'moduleid'=>$moduleid,
    			   'name'=>stripslashes($name),
    			   'maxscore'=>$maxscore,
    			   'successscore'=>$successscore,
    			   'attempts'=>$attempts,
    			   'dur'=>$dur,
    			   'showsuccessmessage'=>$showsuccessmessage,
    			   'successmessage'=>stripslashes($successmessage),
    			   'showfailedmessage'=>$showfailedmessage,
    			   'failedmessage'=>stripslashes($failedmessage),
    			   'showtestsuccessmessage'=>stripslashes($showtestsuccessmessage),
    			   'testsuccessmessage'=>stripslashes($testsuccessmessage),
    			   'showtestfailedmessage'=>stripslashes($showtestfailedmessage),
    			   'testfailedmessage'=>stripslashes($testfailedmessage),
    			   'freequestions'=>stripslashes($freequestions),
    			   'questionsorder'=>stripslashes($questionsorder),
    			   'defertest'=>stripslashes($defertest),
    			   'totalperpage'=>stripslashes($totalperpage),
    			   'showcorrectreply'=>stripslashes($showcorrectreply),
    			   'showscore'=>stripslashes($showscore),
    				'limittype' => stripslashes($limittype),  // Total 21 items
    				'annotation' => stripslashes($annotation));
    
    	return $res;
    
    	} // end of function

    От начальника отдела))) Как вам?))

    Krugly, 09 Марта 2013

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

    +152

    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
    function fixMootoolsJSON(thing) {
        var i, member, pattern = /^"\[.*\]"$/, copy;
        if (thing instanceof Array) {
            for (i = 0; i < thing.length; i++) {
                member = thing[i];
                if (typeof member == "string" && pattern.test(member)) {
                    thing[i] = fixMootoolsJSON(JSON.decode(member));
                }
            }
        } else if (typeof thing == "object") {
            copy = { };
            for (i in thing) {
                if (thing.hasOwnProperty(i)) {
                    copy[i] = fixMootoolsJSON(JSON.decode(thing[i]));
                }
            }
            for (i in copy) {
                if (copy.hasOwnProperty(i)) {
                    thing[i] = copy[i];
                }
            }
        }
        return thing;
    }

    http://outsourceror.blogspot.co.il/2011/04/mootools-intrudes-on-native-json-and.html

    Но вы не подумайте, оказалось, что я был первый (в нашем небольшом коллективе), кто это заметил, а (в нашем небольшом коллективе) было принято JSON прям как есть в базу сохранять...

    wvxvw, 24 Февраля 2013

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