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

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

    +1

    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
    if(!strpos($amount,'.')) {
        $amount = $amount . '.00';
    } else {
    	$strlength = strlen(explode('.',$amount)[1]);
    	if($strlength != 2) {
    		if($strlength == 1) {
    			$amount = $amount . '0';
    		}
    		if($strlength > 2) {
    			$amount = round($amount,2);
    		}
    	}
    }

    Получение дробного до сотых числа

    ykpon, 05 Мая 2016

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

    +1

    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 toggleAdPanelMobile(e) {
        if (mobilecheck()) {
            if ($(e.target).parents('.catalog-container').length || $(e.target).hasClass('button')) {
                if ($('#site-content').hasClass('open')) {
                    $siteAdv.show();
                }
            } else {
                if (!$('#site-content').hasClass('open')) {
                    $siteAdv.show();
                }
            }
        }
    }

    Главное, что работает

    inferusvv , 26 Апреля 2016

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

    +1

    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
    <ul id="top_menu" alias="{$alias}" parentAlias="{$parentAlias}">
        {foreach $items as $i}
            {*{$i->parentId == null} :)*}
            {if $i->parentId == null}
                <li class="{if $alias === $i->alias || $parentAlias === $i->alias}active{/if}"><a href="{Yii::app()->params->languageUrl}/{$i->alias}" onclick="return false;">{$i->lang->name}</a>
                    <ul class="sub" style="display: none;">
                        {foreach $items as $ii}
                            {if $ii->parentId == $i->id}
                                <li class="{if $alias === $ii->alias || $parentAlias === $ii->alias}active{/if}">
                                    {if $ii->hasAction > 0}
                                        <a href="{if $ii->alias!==''}{Yii::app()->params->languageUrl}/{$ii->alias}{/if}">{$ii->lang->name}</a>
                                    {else}
                                        <a href="{Yii::app()->params->languageUrl}/{$i->alias}{if $ii->alias!==''}/{$ii->alias}{/if}">{$ii->lang->name}</a>
                                    {/if}
                                </li>
                            {/if}
                        {/foreach}
                    </ul>
                </li>
            {/if}
        {/foreach}
    </ul>

    Типичное меню на фреймворках.
    В данном случае Yii

    M-A-X, 26 Апреля 2016

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

    +1

    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
    <script type="text/javascript" src="{$assetsUrl}/js/controllers/news.js"></script>
    <div class="breadcrumbs">
     <span typeof="v:Breadcrumb" ><a href="/" style="color: #000000;">{Y::t('MainMenu', 'Главная')}</a></span> /
     <span typeof="v:Breadcrumb" style="color: red;">{$this->title}</span>
    </div>
    <div class="news_sections">
        <ul>
            {assign comment ''}
            {foreach from=Trololo::model()->newsTypes() key=k item=n}
                {if Yii::app()->request->getParam('rubric')==$k}
                    {assign comment $n['comment']}
                    <li class="active"><span>{$n['label']}</span></li>
                {else}
                    <li class=""><span><a href="{Yii::app()->params->languageUrl}/news/rubric/{$k}">{$n['label']}</a></span></li>
                {/if}
            {/foreach}
        </ul>
    </div>
    <h1 class="page_title">{$comment}</h1>

    Типичный шаблон на фреймворке.
    В данном случае - Yii.

    M-A-X, 26 Апреля 2016

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

    +1

    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
    <?
    namespace components\max;
    class articles_element
    {
        static function run($_arParams)
        {
            $arParams = &$_arParams['PARAMS'];
            $tm = &$_arParams['tm'];
    
            $user = &$tm->user;
            $code = $arParams['CODE'];
    
            $arCache = array(
                'prefix' => 'show',
                'sufix' => $code,
                'time' => -1,
                'lang' => LANGUAGE_ID,
            );
    
            $tm->loadLang('show');
    
            $arSelect = array(
                'E.id',
                'E.active',
                'rel',
                'time',
                'code',
                'date_active_from',
                'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
                'content_'.LANGUAGE_ID.' AS content' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],
                'author_id',
    
                'only_for_auth_users',
    
                'source_url',
                'source_author',
                'source_date',
            );
    
            $arJoin = [];
    
            if($tm->conf['show']['show_additional'])
            {
                $arSelect[] = 'GROUP_CONCAT(show2category.category_id) AS categories';
                $arJoin[\CShow2Category::$table.' show2category ON E.id = show2category.show_id'] = 'LEFT';     
            }
    
            $arFilter = array('E.code' => $code, 'E.site_id' => $tm->conf['site_id']);
    
            $dbShow = \CShow::GetList(false, $arFilter, ['E.id'], array('nTopCount' => 1), $arSelect, $arJoin);
            while($arShow = mysql_fetch_assoc($dbShow))
            {
                $arShow['title'] = htmlspecialchars($arShow['title']);
    
                if(!empty($arShow['categories']))
                {
                    $arShow['categories'] = explode(',', $arShow['categories']);            
                }
    
                $arShow['time_write'] = date("d.m.Y", $arShow['date_active_from']);
                $arShow['only_for_auth_users'] = $arResult['only_for_auth_users'] && empty($tm->user['id']);            
    
                $arResult = $arShow;
    
                if($arResult['only_for_auth_users'])
                {
                    $arResult['title'] = GetMessage('ERROR_ONLY_AUTH');                
                }
    
                $tm->setLastModifiedTime($arShow['date_active_from']);
    
                $tm->setBuffered('title', $arResult['title'].' | '.GetMessage('sitename'));
                $tm->setBuffered('h1', $arResult['title']);
            }
    
            if(empty($arResult))
            {
                // Проверяем редиректы
                $arParamsRedirects = array(
                    'code' => $arFilter['code'], 
                    'module' => 'show',
                );                
                $tm->redirects_modules($arParamsRedirects);
    
                $tm->pagenotfound();
            }
    
            $arResult['user_status'] = $user['sts'];
    
            if($tm->conf['show']['show_additional'] && !empty($arResult['categories']))
            {
                $arFilter = [
                    'active' => 1,
                    'show2category.category_id' => $arResult['categories'],
                    '!E.id' => $arResult['id'], 
                ];
                $arSelect = [
                    'E.id',
                    'code',
                    'title_'.LANGUAGE_ID.' AS title' => $tm->conf['LANG_FALLBACKS'][LANGUAGE_ID],

    Код от противника фреймворков (это контроллер). Цитата виновника торжества:
    "У меня роутинга нету За роутинг отвечает nginx (ранее отвечал .htaccess)"

    loki90, 26 Апреля 2016

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <p class="name">
                    {% if (file.url) { %}
                        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                    {% } else { %}
                        <span>{%=file.name%}</span>
                    {% } %}
                </p>
                {% if (file.error!="SyntaxError: Unexpected token <") { %}
                    <div><span class="label label-danger">Error</span> {%=file.error%}</div>
                {% } %}

    Шедевральный человек! Оригинал http://www.yiiframework.ru/forum/viewtopic.php?t=15956#p119944

    dimka3210, 23 Апреля 2016

    Комментарии (10)
  8. C# / Говнокод #19855

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    List<dynamic> reporting = item.company_profile_data?.AnnualFinancialStatementFiles ??
                                              new List<dynamic>();
                    string annual = "";
                    foreach (var report in reporting)
                    {
                        if (report.File != null)
                        {
                            string name = report.File?.Info?.Name;
                            if (name != null) annual = annual + name.Substring(0, name.LastIndexOf('.')) + ", ";
                        }
                    }
                    item.Name = annual;

    П - производительность.

    Psilon, 21 Апреля 2016

    Комментарии (13)
  9. C++ / Говнокод #19853

    +1

    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
    98. 98
    99. 99
    void CScene::IncludeObjects()
    {
    // Reset All.
    	ExcludeObjects();
    
    // fill Vershiny of piramid...
    	point3d versh[4];
    	point3d eye = {IniSet.ptCamPos.x, IniSet.ptCamPos.y, IniSet.ptCamPos.z};
    	Screen2World(0, 0, versh[0]);
    	Screen2World(nScreenSzX, 0, versh[1]);
    	Screen2World(nScreenSzX, nScreenSzY, versh[2]);
    	Screen2World(0, nScreenSzY, versh[3]);
    
    // Increase before OO...
    	
    	int ix, sz = parrObjs.Size();
    	point3d vect;
    	for(ix = 0; ix < 4; ix++){
    		sub_vectors(&vect.x, &versh[ix].x, &eye.x);
    		norm_vect(&vect.x);
    		scale_vect(&vect.x, 200.f);
    		versh[ix] = vect;
    	}
    
    // Create faces of piramid and search collision with it...
    	point3d Piramid[4][3];
    	Piramid[0][0] = eye;
    	Piramid[1][0] = eye;
    	Piramid[2][0] = eye;
    	Piramid[3][0] = eye;
    	Piramid[0][1] = versh[0];
    	Piramid[0][2] = versh[1];
    	Piramid[1][1] = versh[1];
    	Piramid[1][2] = versh[2];
    	Piramid[2][1] = versh[2];
    	Piramid[2][2] = versh[3];
    	Piramid[3][1] = versh[3];
    	Piramid[3][2] = versh[0];
    	
    // Dyadya WALERA!!!!
    	for(ix = nObjOff; ix < sz; ix++){
    		CObj3d *pObj = parrObjs.e(ix);
    		pObj->Transform(FALSE);
    		point3d ptPos = pObj->GetPosition();
    
    		if(IniSet.nIncludeObjectMode == WS_INCLUDE_BARYCENTER){
    			point3d ptCentr = IniSet.ptCamTarget;
    			point3d vtVect;
    			
    			sub_vectors(&vtVect.x, &ptPos.x, &ptCentr.x);
    
    			plane plGran;
    			point3d ptCross;
    			for(int jx = 0; jx < 4; jx++){
    				comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
    				cross_line_plane(vtVect, &plGran.a, ptCentr, ptCross);
    				float f1, f2;
    				f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
    				f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
    				if(f1 * f2 < 0.f){
    					if(point_in_triangle(Piramid[jx][0], Piramid[jx][1], Piramid[jx][2], ptCross)){
    						ptCross = ConvertPos3D(ptCross);
    						if(IniSet.bMirrorH){ ptCross.y = -ptCross.y; }
    						if(IniSet.bMirrorV){ ptCross.x = -ptCross.x; }
    						if(IniSet.bMirrorD){ ptCross.z = -ptCross.z; }
    
    						transform_back_point(&ptCross, &ptCross, &IniSet.mtMatr);
    						pObj->ptSavedPos = ptCross;
    						break;
    					}
    				}
    			}
    		}else{ // XYZ Axes.
    			point3d vtXYZ[3] = {{1.f, 0.f, 0.f},
    								{0.f, 1.f, 0.f},
    								{0.f, 0.f, 1.f}};
    
    			BOOL bFound = FALSE;
    			for(int ax = 0; ax < 3; ax++){
    
    				point3d vtVect;
    				transform_point(&vtVect, &vtXYZ[ax], &IniSet.mtMatr);
    				
    				for(int jx = 0; jx < 4; jx++){
    					plane plGran;
    					comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
    					
    					point3d ptCentr = IniSet.ptCamTarget;
    
    					point3d ptCross;
    					cross_line_plane(vtVect, &plGran.a, ptPos, ptCross);
    					float f1, f2;
    
    					f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
    					f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
    
    					point3d vtDif;
    					sub_vectors(&vtDif.x, &ptCross.x, &IniSet.ptCamPos.x);
    					if(vec_length(&vtDif.x) < 0.01f){ continue; } // avoid crossing with eye.

    Гавнокод: включить все 3Д объекты в экран.

    falcoware, 21 Апреля 2016

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

    +1

    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
    $payments = $CI->payment_method_model->getAll();
    
        $payment = array();
        $payment[null] = array();
        $payment[null]['addr'] = " ";
        $payment[null]['perc'] = " ";
        $payment[null]['name'] = " ";
       
        foreach($payments->result() as $item)
        {
            $payment[$item->id] = array();
            $payment[$item->id]['addr'] = (json_decode($item->params,true));
            $payment[$item->id]['perc'] = $item->fee;
            $payment[$item->id]['name'] = $item->title;
        }

    No comments...
    Поддержка этого проекта вызывает душевную боль... :(

    GDim, 13 Апреля 2016

    Комментарии (4)
  11. C++ / Говнокод #19810

    +1

    1. 1
    2. 2
    3. 3
    sector_t * s = &sectors[secnum];
    if (!s->floorplane.isSlope()) s->reflect[sector_t::floor] = arg1/255.f;
    if (!s->ceilingplane.isSlope()) sectors[secnum].reflect[sector_t::ceiling] = arg2/255.f;

    присвоил переменной и во второй раз не использовал

    UsernameAK, 13 Апреля 2016

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