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

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

    +154

    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
    class Key{
    	private $chars = array('1'=>'a','2'=>'b','3'=>'c','4'=>'d','5'=>'e','6'=>'f','7'=>'g','8'=>'h','9'=>'i');
    	private $invChars = array('9'=>'a','8'=>'b','7'=>'c','6'=>'d','5'=>'e','4'=>'f','3'=>'g','2'=>'h','1'=>'i');
    	private $key = "";
    	private $numbers = array();
    
    	public function createKey(){
    		for($a=0;$a<4;$a++){
    			$this->numbers[0] = rand(1, 9);
    			$this->numbers[1] = rand(1, 9);
    			$this->key .= $this->numbers[0].$this->invChars[$this->numbers[1]].$this->numbers[1].$this->chars[$this->numbers[0]]."-";
    		}
    		return substr_replace($this->key, '', 19, 1);
    	}
    
    	public function checkKey($key){
    		if(preg_match("/^([1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I])$/", $key)){
    			$key = str_replace('-', '', $key);
    			if($this->chars[$key[0]] == $key[3] && $this->invChars[$key[2]] == $key[1]){
    				if($this->chars[$key[4]] == $key[7] && $this->invChars[$key[6]] == $key[5]){
    					if($this->chars[$key[8]] == $key[11] && $this->invChars[$key[10]] == $key[9]){
    						if($this->chars[$key[12]] == $key[15] && $this->invChars[$key[14]] == $key[13]){
    							return true;
    						}
    						else{
    							return false;
    						}
    					}
    					else{
    						return false;
    					}
    				}
    				else{
    					return false;
    				}
    			}
    			else{
    				return false;
    			}
    		}
    		else{
    			return false;
    		}
    	}
    }

    Особенно регулярка...

    makssof, 14 Марта 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $background_nid = _get_last_section_background($node);
    $new_background_nid = ($background_nid == 47)?48:47;
    $background_color = db_query("SELECT field_background_color_value FROM {field_revision_field_background_color} WHERE entity_id=:nid AND entity_type='node'", array(":nid" => $new_background_nid))->fetchField();
    $style_background = "background-color: #".$background_color."; ";

    Изысканное получение node id в Drupal

    valllllera, 18 Февраля 2014

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

    +154

    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
    <?php
    session_start();
    include("database.php");
    include("filter.php");
    $filter = new Filter();
    isset($_GET['cat']) ? $id = $filter->Symbols($_GET['cat']) : exit("Вы зашли на страницу без параметра!");
    	
    if ( !isset($_POST['class']) && empty($_POST['class']) )
    {
    	include('header.php');
    	echo '
    		<title>Title</title>
    	';
    	include('slider.php');
    	echo '
    	<div id="Content">
    	';
    }
    
    $query_amount = $mysqli->query("SELECT COUNT(id) FROM `page_film` WHERE `genre_film`='$id' ");
    $amount_film = $query_amount->fetch_row();
    
    $query = $mysqli->query("SELECT * FROM `page_film` WHERE `genre_film`='$id' ORDER BY `id` DESC ");
    
    if ( $amount_film[0] > 0 )
    	while( $row = $query->fetch_array(MYSQLI_ASSOC) )
    		echo '
    			<div class="block-film">
    				<a class="block-link-image" href="../films/film.php?id='.$row['id'].'">
    					<img src="'.$row['poster'].'" />
    				</a>
    				<div class="block-film-text">
    					<p class="film-name">
    						<a href="../films/film.php?id='.$row['id'].'">'.$row['title'].'</a>
    					</p>
    					<p class="film-mini-name">
    						<a href="../films/film.php?id='.$row['id'].'">'.$row['desc'].'</a>
    					</p>
    					<p class="film-genre"><span>'.$row['genre'].'</span></p>
    					<p class="film-description">'.$row['description'].'</p>
    				</div>
    			</div>
    		';
    
    if ( !isset($_POST['class']) && empty($_POST['class']) )
    {
    	echo '	
    	</div>
    </body>
    </html>
    	';
    }
    ?>

    alexkor, 13 Февраля 2014

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

    +154

    1. 1
    /^(?!\s)[a-zA-Z0-9\x2d-\x2f\x7f-\xff_-\s]+(?!\s)$/

    Регулярочка из Modx. После обновления PCRE до последней версии перестала восприниматься как валидная. Недоумеваем, что имели в виду, задавая диапазон "_-\s" и как оно работало раньше.

    Lblss, 11 Февраля 2014

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $this->db->insert("orders", $data);
    
            //Get order's id
            $this->db->select("orders_id");
            $this->db->where('orders_customer_tel', $data['tel']);
            $this->db->order_by("orders_id", "desc");
            $this->db->limit(1);
            $query = $this->db->get("orders");
            foreach ($query->result_array() as $res) {
                $orders_id = $res['orders_id'];
            }

    Ништяяяк!

    ragnar, 10 Февраля 2014

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function login()
    	{
    	$.ajax({
    		type:'post',
    		url:'index.php/main/login',
    		data:{x:1},
    	 success:function(data){
                   $("body").html(data);
                }
              });
         }

    Функция из single page приложения

    devalentino, 01 Февраля 2014

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

    +154

    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
    <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
    
    <?if (!empty($arResult)):?>
    <nav class="mainNav">
    <table>
    <tbody><tr>
    <?
    $i = 0;
    $previousLevel = 0;
    //echo '<pre>'; print_r($arResult); echo '</pre>';
    $CatItemMenu = str_replace("/", "", $arResult[0]['LINK']);
    foreach($arResult as $arItem):?>
    
    
    <?$i++;?>
    	<?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?>
    	
    	
    	<?if($previousLevel != 3):?>
    		<?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?>
    	<?endif;?>
    	
    	<?if($previousLevel == 3):?>
    		</li></ul>
     <div class="someProduct" style="min-height: 336px;">
                                            <a class="productLink" href="<?=$arResult["CATALOG_MENU"][$CatItemMenu]["DETAIL_PAGE_URL"]?>">
                                                    <span class="image"><img alt="" src="<?=$arResult["CATALOG_MENU"][$CatItemMenu]["PICTURE_SRC"]?>"></span>
                                                    <span><?=$arResult["CATALOG_MENU"][$CatItemMenu]["NAME"]?></span>
    												
    												
    											<?if($arResult["CATALOG_MENU"][$CatItemMenu]["SALE_PRICE"]  < $arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]):?>	
                                                <span class="oldPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]?> руб.</span>
                                                <span class="newPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["SALE_PRICE"]?> руб.</span>
    											<?else:?>
    											 <span class="newPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]?> руб.</span>
    											<?endif;?>
                                            </a>         </div></div>	<?endif;?>	<?endif?><?if ($arItem["IS_PARENT"]):?>	<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    		<td><div><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a>
    	<div class="test_mark" style=""><ul>		
    				
    		<?else:?>
    		
    		<?if($arItem["DEPTH_LEVEL"] == 2):?>
    		<li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?><ins>»</ins></a>
    	<div class="test_mark" style="min-height: 336px;"><ul style="min-height: 304px;">
    	<?else:?>
    	<li><a href="<?=$arItem["LINK"]?>" class="parent<?if ($arItem["SELECTED"]):?> item-selected<?endif?>"><?=$arItem["TEXT"]?></a>
    				<ul>
    	
    	<?endif;?>			
    		<?endif?>
    	<?else:?>
    		<?if ($arItem["PERMISSION"] > "D"):?>
    			<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    				<li><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a></li>
    			<?else:?>
    						<?if($arItem["DEPTH_LEVEL"] == 3):?>						
    			<?//Танцы с бубном для вывода меню по два пункта. ?>			
    			<?if($i%2):?>	
              	<li>
    			<span><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></span>
    			<?if($arResult[$i]["DEPTH_LEVEL"] == 3):?><span><a href="<?=$arResult[$i]["LINK"]?>"><?=$arResult[$i]["TEXT"]?></a></span><?endif;?>
    			<?if($arResult[$i-3]["DEPTH_LEVEL"] == 2 && $arItem["TEXT"] != $arResult[$i-1]["TEXT"]):?><span><a href="<?=$arResult[$i-1]["LINK"]?>"><?=$arResult[$i-1]["TEXT"]?></a></span><?endif;?>		
    			<?endif;?>
    	        <?if(!($i%2)):?></li><?endif;?>
    			<?//Танцы Окончены. ?>	
    			
    			<?else:?>
    			<li><a href="<?=$arItem["LINK"]?>" <?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>><?=$arItem["TEXT"]?></a></li>
    			<?endif;?>
    											<?endif?>
    		<?else:?>
    			<?if ($arItem["DEPTH_LEVEL"] == 1):?>
    				<li><a href="" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
    			<?else:?>
    				<li><a href="" class="denied" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
    			<?endif?>
    		<?endif?>
    	<?endif?>
    	<?$previousLevel = $arItem["DEPTH_LEVEL"];?>
    
    <?
    
    //Добавляем товар
    if($arItem["DEPTH_LEVEL"] == 1){
    
    $ClearLink = str_replace("/", "", $arItem['LINK']);
    $CatItemMenu = $ClearLink;
    //echo $ClearLink.' - '.$previousLevel;
    
    }
    ?>	
    <?endforeach?>
    <?if ($previousLevel > 1)://close last item tags?>
    	<?=str_repeat("</ul>", ($previousLevel-1) );?>
    <?endif?>
    </tr>
    </tbody></table>
    </nav>
    <?endif?>

    Создадим меню и выведем его списком по два пункта.

    hipachka, 20 Января 2014

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

    +154

    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
    $this->load->model('localisation/country');
    $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
    
    if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
         $json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
    }
         
    if ($this->request->post['shipping_country_id'] == '') {
         $json['error']['shipping']['country'] = $this->language->get('error_country');
    }
                
    if ($this->request->post['shipping_zone_id'] == '') {
          $json['error']['shipping']['zone'] = $this->language->get('error_zone');
    }
                             
    $this->load->model('localisation/country');
    $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
                 
    if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
         $json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
    }

    строки 279 - 301
    файл catalog/controller/checkout/manual.php
    opencart 1.5.5.1.1

    Зачем два идентичных куска кода (1 - 6 и 16 - 21), в одном файле идущих друг за другом, я так и не понял.

    gnom_virtuoz, 17 Января 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var i1id = setInterval(function () {
                $('#step-2 table.step-1-top-tabs td#images').addClass('tab-selected');
                $('#step-2 table.step-1-top-tabs td#images').click();
                clearInterval(i1id);
            }, 100);

    О функции setTimeout не слышали.

    begmst, 10 Января 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    if((int)$this->tmpl['detailwindow'] == 4 || (int)$this->tmpl['detailwindow'] == 5 || (int)$this->tmpl['detailwindow'] == 7) {
      } else { 
       echo '<td align="center">' . str_replace("%onclickclose%", $this->tmpl['detailwindowclose'], $this->item->closebutton). '</td>';
      }

    Какая глубина мысли!
    Интересно, а чтобы ОНО написало в С++?

    virtual_cia, 26 Декабря 2013

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