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

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

    +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
    <?
    $res = CIBlockSection::GetList(array(), array('IBLOCK_ID'=>'3', 'ACTIVE'=>'Y'));
    $res1 = CIBlockSection::GetList(array(), array('IBLOCK_ID'=>'3', 'ACTIVE'=>'Y'));
    ?>
    <table class="tableObjects">
        <tr>
            <?while($v = $res->GetNext()){
                ?><td><a href="/projects/list.php?SECTION_ID=<?=$v['ID']?>">
                    <?=CFile::ShowImage(CFile::GetPath($v['PICTURE']), 180, 160)?>
                </a></td><?
            }?>
        </tr>
        <tr>
            <?while($v = $res1->GetNext()){
                ?><td><b><a href="/projects/list.php?SECTION_ID=<?=$v['ID']?>"><?=$v['NAME']?></a></b></td><?
            }?>
        </tr>
    </table>

    Как минимум 2 раза обращаться к базе данных, чтобы разбить данные на 2 строки! Гениально!

    dimagyzeev, 09 Июля 2014

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if ($end < $start) {
    	$errorLimit = '<p><u><b>End limit</b></u> should be bigger number than <u><b>Start limit</b></u></p>';
    	//echo $errorLimit;
    	throw new \grdprc\Exception(strip_tags($errorLimit));
    	return;
    }

    <p><u><b> тоже ок.

    quall, 25 Июня 2014

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (count($vCard) == 1) {
        print_r($vCard -> n);
        print_r($vCard -> tel);
    } else {
        foreach ($vCard as $vCardPart)
        {
            print_r($vCardPart -> n);
            print_r($vCardPart -> tel);
        }
    }

    https://github.com/nuovo/vCard-parser

    Ну за каким хуем обрабатывать один элемент как отдельный случай?!

    bormand, 23 Июня 2014

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

    +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
    if ((int)($basket->summ/1000) > 999)
        {
          $price_all = substr_replace($basket->summ," ",1,0);
          $price_all = substr_replace($price_all," ",5,0);
        }
        elseif ((int)($basket->summ/1000) > 99)
        {
          $price_all = substr_replace($basket->summ," ",3,0);
        }
        elseif ((int)($basket->summ/1000) > 9)
        {
          $price_all = substr_replace($basket->summ," ",2,0);
        }
        elseif ((int)($basket->summ/1000) < 9 && (int)($basket->summ/1000) > 0)
        {
          $price_all = substr_replace($basket->summ," ",1,0);
        }
        elseif ((int)($basket->summ/1000) == 0)
        {
          $price_all = $basket->summ;
        }

    Вот так вот у нас на офисе коллега форматировал цену...

    Mayhemalexf, 18 Июня 2014

    Комментарии (4)
  6. JavaScript / Говнокод #16174

    +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
    function EngineListCtrl($scope, $timeout, $http)
    {
    	$scope.engines = {};
    	$scope.workers = [];
    	
    	$scope.checkEngines = function(){
    		$http.get(engineUrl + '&type=json&jcmd=getClients').success(function(req){
    			var engines = {};
    			var workers = {};
    			$scope.workers = []; // Это в отрисовке не используется.
    			
    // Сначала распихиваю всех по местам
    			angular.forEach(req, function(ob, i){
    				if( ob.info.type == 'engine' )
    					engines[ob.info.engine] = ob;
    				
    				if( ob.info.type == 'worker' ){
    					if( workers[ob.info.engine] == undefined )
    						workers[ob.info.engine] = {};
    					workers[ob.info.engine][ob.info.worker] = ob;
    					if( ob.task && ob.task.state )
    						ob.info.state = ob.task.state;
    					$scope.workers.push(ob);
    				}
    			});
    			
    // Перебераю уже имеющиеся объекты
    			angular.forEach($scope.engines, function(engineOb, engineName){
    				var needRemove = true;
    				angular.forEach(engines, function(val, key){
    					if( engineName == key ){
    						angular.extend($scope.engines[engineName], val);
    						needRemove = false;
    					}
    				});
    				
    				if( needRemove == false && $scope.engines[engineName] ){
    					$scope.checkEngineEvents($scope.engines[engineName]);
    					if( workers[engineName] != undefined ){
    						if( $scope.engines[engineName].workers == undefined )
    							$scope.engines[engineName].workers = {};
    						angular.extend($scope.engines[engineName].workers, workers[engineName]);
    					}else
    						$scope.engines[engineName].workers = {};
    				}
    				
    				if( needRemove == true ){
    					delete $scope.engines[engineName];
    				}
    			});
    			
    // А теперь новые добавляю
    			angular.forEach(engines, function(engineOb, engineName){
    				if( $scope.engines[engineName] == undefined ){
    					$scope.engines[engineName] = engineOb;
    					if( workers[engineName] != undefined ){
    						if( $scope.engines[engineName].workers == undefined )
    							$scope.engines[engineName].workers = {};
    						angular.extend($scope.engines[engineName].workers, workers[engineName]);
    					}
    					$scope.checkEngineEvents($scope.engines[engineName]);
    				}
    			});
    			$timeout($scope.checkEngines, 2000);
    		});
    		
    	}
    	$timeout($scope.checkEngines, 1000);

    JovialLiX, 16 Июня 2014

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

    +156

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    $currentId = $modx->resource->get('id');
    $parentIds = $modx->getParentIds($currentId);
    if($currentId == 1){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_text_main_page',
      ));
    }elseif($currentId == 3 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_text_studios_main',
      ));
    }elseif($currentId == 2){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_text_bazy_main',
      ));
    }elseif($currentId == 4 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_text_dancehalls_main',
      ));
    }elseif($currentId == 19 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_koz',
      ));
    }elseif($currentId == 6 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_ale',
      ));
    }elseif($currentId == 17 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_pav',
      ));
    }elseif($currentId == 20 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_sav',
      ));
    }elseif($currentId == 59 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_il',
      ));
    }elseif($currentId == 16 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_1905',
      ));
    }elseif($currentId == 18 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_heb',
      ));
    }elseif($currentId == 84 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_ab',
      ));
    }elseif($currentId == 27 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_1905',
      ));
    }elseif($currentId == 28 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_il',
      ));
    }elseif($currentId == 58 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_koz',
      ));
    }elseif($currentId == 26 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_ar',
      ));
    }elseif($currentId == 25 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_pav',
      ));
    }elseif($currentId == 24 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_sav',
      ));
    }elseif($currentId == 23 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_sav2',
      ));
    }elseif($currentId == 22 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_baum',
      ));
    }elseif($currentId == 21 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_shab',
      ));
    }elseif($currentId == 86 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_z_dobr',
      ));
    }elseif($currentId == 5 ){
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_prokat',
      ));
    }else{
      $chunk = $modx->getObject('modChunk',array(
       'name' => 'footer_seo_text',
      ));
    }
    return $chunk->process();

    Еле уложился в 100 строк, пришлось комментарии резать.

    savva-paladin, 12 Июня 2014

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

    +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
    (function(G, D) {
        "use strict";
        var $ = G.jQuery,
            listener;
    
        function addListener(elem, fn) {
            function handler(event) {
                event = event || G.event;
                var dx = event.DeltaX || event.wheelDeltaX || event.detail || 0,
                    dy = event.DeltaY || event.wheelDeltaY || event.detail || 0;
                event.dx = dx === 0 ? 0 : dx / Math.abs(dx);
                event.dy = dy === 0 ? 0 : dy / Math.abs(dy);
                fn(event);
            }
    
            if (elem.addEventListener) {
                if (D.hasOwnProperty('onwheel')) { //Modern browsers
                    listener = "wheel";
                } else if (D.hasOwnProperty('onmousewheel')) { //Old browsers
                    listener = "mousewheel";
                } else { //FF<17
                    listener = "MozMousePixelScroll";
                }
                elem.addEventListener(listener, handler, false);
            } else { //IE<9
                elem.attachEvent("onmousewheel", handler);
                listener = "onmousewheel";
            }
        }
    
        function removeListener(elem) {
            if (elem.removeEventListener) {
                elem.removeEventListener(listener);
            } else {
                elem.detachEvent(listener);
            }
        }
    
        $.fn.mousewheel = function(fn) {
            return this.each(function() {
                addListener(this, fn);
            });
        };
        $.fn.unmousewheel = function(fn) {
            return this.each(function() {
                removeListener(this, fn, false);
            });
        };
    }(this, document));

    Написал плагин для jQuery, который цепляет на элементы обработчик события вращения колесика мыши. Что скажете? Как бы вы написали функцию unmousewheel()?

    dunmaksim, 10 Июня 2014

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

    +156

    1. 1
    $result['BIRTHDATE'] = (($date['day'] < 10) ? '0'.$date['day'] : $date['day']).'.'.(($date['month'] < 10) ? '0'.$date['month'] : $date['month.'] ).'.'.$date['year'];

    Пых и даты.

    bormand, 28 Мая 2014

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

    +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
    $(document).ready(function(){
                if(document.location.href.indexOf("coding")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(1).addClass("activ_line2");
                }
                if(document.location.href.indexOf("portfolio")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(2).addClass("activ_line2");
                }
                if(document.location.href.indexOf("graphika")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(3).addClass("activ_line2");
                }
                if(document.location.href.indexOf("seo-yandex-google")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(4).addClass("activ_line2");
                }
                if(document.location.href.indexOf("kuchniy")>0)
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(5).addClass("activ_line2");
                }
                if(document.location.href=="http://catine.ru/")
                {
                    $("#line_menu li a").removeClass("activ_line2").eq(0).addClass("activ_line2");
                }
    			var min = false;
    			$(document).scroll(function() {
    				if($(document).scrollTop()>30&&!min)
    				{
    					$(".line2").toggleClass("header_max header_min");
    					min = true;
    				}
    				if($(document).scrollTop()<=30&&min)
    				{
    					$(".line2").toggleClass("header_max header_min");
    					min = false;
    				}
    			});
            });

    Блог начинающего веб-разработчика...

    TRANE73, 20 Мая 2014

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

    +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
    $this->_html .= '<script type="text/javascript">id_language = ' . intval($this->defaultLanguage) . ';</script>';
    		if ($ObjAdvancedTopMenuClass)
    			$haveDepend = AdvancedTopMenuClass::menuHaveDepend($ObjAdvancedTopMenuClass->id);
    		$this->_html .= '<form action="' . $this->base_config_url . '" method="post" id="menuform_' . $this->name . '" name="menuform_' . $this->name . '" method="post" enctype="multipart/form-data" class="width3">
        <div id="blocMenuForm">
            ' . ($ObjAdvancedTopMenuClass ? '<input type="hidden" name="id_menu" value="' . intval($ObjAdvancedTopMenuClass->id) . '" /><br /><a href="' . $this->base_config_url . '"><img src="../img/admin/arrow2.gif" />' . $this->l('Back') . '</a><br class="clear" /><br />' : '');
    		$this->_html .= '<label>' . $this->l('Tab type') . '</label>
           <div class="margin-form"><select name="type" id="type_menu">
              <option value="">' . $this->l('Choose') . '</option>
              <option value="1" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 1 ? 'selected="selected"' : '') . '>' . $this->l('CMS') . '</option>
              <option value="2" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 2 ? 'selected="selected"' : '') . '>' . $this->l('Link') . '</option>
              <option value="3" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 3 ? 'selected="selected"' : '') . '>' . $this->l('Category') . '</option>
               <option value="4" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 4 ? 'selected="selected"' : '') . '>' . $this->l('Manufacturer') . '</option>
              <option value="5" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 5 ? 'selected="selected"' : '') . '>' . $this->l('Supplier') . '</option>
              <option value="6" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 6 ? 'selected="selected"' : '') . '>' . $this->l('Search') . '</option>
              <option value="7" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->type == 7 ? 'selected="selected"' : '') . '>' . $this->l('Only image or icon') . '</option>
           </select></div>';
    		$this->_html .= '<script type="text/javascript">$("#type_menu").change(function() {showMenuType($(this),"menu");});</script>';
    		$this->_html .= '<label>' . $this->l('Menu link not clickable') . '</label>
              <div class="margin-form">
              <input type="checkbox" name="clickable" id="menu_clickable" value="1" ' . ($ObjAdvancedTopMenuClass && $ObjAdvancedTopMenuClass->link [$this->defaultLanguage] == '#' ? ' checked=checked' : '') . '  />
              <small>' . $this->l('Add a # in the link field. Do not remove.') . '</small>
              </div>';
    		$this->_html .= '<script type="text/javascript">$("#menu_clickable").click(function() {setUnclickable($(this));});</script>';
    		if ($ObjAdvancedTopMenuClass && in_array($ObjAdvancedTopMenuClass->type, $this->rebuildable_type)) {
    			$this->_html .= '<label>' . $this->l('Rebuild tree') . '</label>
              <div class="margin-form"><label class="t" for="rebuild_on"><img src="../img/admin/enabled.gif" alt="' . $this->l('Yes') . '" title="' . $this->l('Yes') . '" /></label>
                <input type="radio" name="rebuild" id="rebuild_on" value="1" />
                <label class="t" for="rebuild_on"> ' . $this->l('Yes') . '</label>
                <label class="t" for="rebuild_off"><img src="../img/admin/disabled.gif" alt="' . $this->l('No') . '" title="' . $this->l('No') . '" style="margin-left: 10px;" /></label>
                <input type="radio" name="rebuild" id="rebuild_off" value="0" checked=checked />
                <label class="t" for="rebuild_off"> ' . $this->l('No') . '</label><br />' . $this->l('Caution, this may change the appearance of your menu !') . '</div>';
    		}

    А Smarty стоит рядышком и тихо плачет вместе с программистом.
    Модуль для PrestaShop стоимостью 50 евро.

    in8finity, 19 Мая 2014

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