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

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

    +155.2

    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
    function search($source,$text)
    {
    
    $result = false;
    
    $searchfilms = "#<a class=\"all\" href=\"/level/1/film/(.*?)a>#si";
    $searchfilms2 = "#<font color=\"\#999999\">(.*?)</font>#si";
    
      while (preg_match_all ($searchfilms, $source, $matches))
      {
        preg_match_all($searchfilms2, $source, $matches2);
        foreach ($matches as $key => $temparray)
        foreach ($temparray as $key2 => $tempresult){
        $result[$key2] = $tempresult;
        $result[$key2] = preg_replace("#(.*?)/sr/1/\">(.*?)</#is", "<a href=\"?id=\\1\">\\2</a>", $result[$key2])."   ".$matches2[$key][$key2];
        }
     return $result;
      }
    }
    
    
    Парсер результатов с кинопоиска, отсюдова: http://bit-torrent.kiev.ua/arser_kinopoisk_ru-t3637/index.html
    Может я что-то не понимаю, но зачем так извращаться совсем не ясноне ясно, 3 вложенных  цикла О_о.   preg_match в while зачем совсем не ясно.
    
    Короче чтобы добавить сюда еще и год фильма, пришлось переписать... А хотелось AFAIK :)
    
    Короче AFAIK вышло вот так:
    
    
    function search($source, $text) {
    
    	$result = array();
    
    	$searchfilms = 	"#<a class=\"all\" href=\"/level/1/film/(.*?)/.*?>(.*?)<.*?a>.*?(\d{4}).*?#si";
    	$searchfilms2 = "#<font color=\"\#999999\">(.*?)</font>(.*?)#si";
    
    	preg_match_all ($searchfilms, $source, $matches);
    	preg_match_all($searchfilms2, $source, $matches2);
    
    	foreach ($matches[1] as $key => $temparray) {
    		$id = $matches[1][$key];
    		$name = $matches[2][$key];
    		$name_eng = $matches2[1][$key];
    		$year = $matches[3][$key];
    		
    		$result[] =  "<a href=\"?id=$id\">$name..$name_eng...($year)</a>";	
    	}
    
    	return $result;
    }
    
    p.s. ИМХО читабельнее в разы

    netdog, 21 Октября 2009

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <button type="button" title="<?=GetMessage("Detail")?>" class="button btn-detail" onclick="setLocation('<?=$arElement["DETAIL_PAGE_URL"]?>')">
         <span>
            <span><?=GetMessage("Detail")?></span>
        </span>
     </button>

    Битрикс. К вопросу о том, почему не стоит покупать готовые шаблоны.

    Serko1989, 14 Апреля 2015

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

    +155

    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
    foreach ($out as $fio => $massdate) {
    	foreach ($massdate as $date => $masshour) {
    		foreach ($masshour as $hour => $massmm) {
    			foreach ($massmm as $minute) {
    				if (!isset(${'ctrl'.$hour.$date.$fio})) {
    					$rez=0; 
    					$prv_minute=$minute; 
    					${'ctrl'.$hour.$date.$fio}=1;} 
    					ELSE {$rez=$minute-$prv_minute; 
    					 $prv_minute=$minute; }
    																								
    				$summ += $rez;
    			}	
    if (count($massmm)<>1) {$sr=round($summ/(count($massmm)-1), 2);}
    else {$sr=round($summ/count($massmm), 2);}
    $all_out[$fio][$date][$hour]=array(count($massmm), $sr);
    $hours_arr[]=$hour*1;
    //echo "Всего ".count($massmm)." комментария(ев) Среднее время $sr минут(ы) $hour <br>";
    $summ=0;
    		}
    	}
    } 
    $hours_arr=array_unique($hours_arr);
    asort($hours_arr);

    Подарок прошлого разработчика

    noffily, 02 Апреля 2015

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

    +155

    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
    $.analyse.analysePage = function(params, callbacks) {
    	$.analyse.sidebar({
    		'story': params.story,
    		'format': params.format,
    		'parentId': params.parentId
    	}, callbacks);
    	$.analyse.content({
    		'story': params.story,
    		'format': params.format,
    		'formatTemplate': params.formatTemplate,
    		'template': params.template,
    		'response' : params.response,
    		'selectedId': params.selectedId
    	}, callbacks);
    	[...]
    };
    
    
    $.analyse.content = function(params, callbacks) {
    	var data = {
    			params : params
    		};
            [...] //В 2-ух местах используется params
    	otherFunction(data); //Название изменено
    	[...]
    };

    История путешествия данных по функциям.

    Edd, 27 Марта 2015

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /**
     * @param string $singular
     * @param string $context
     */
    function translate($singular, $context=null) {
    	return $singular;
    }

    Любимый вордпресс, wp-includes/pomo/translations.php. Кажется, это такой интерфейс.

    Fike, 24 Марта 2015

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

    +155

    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
    function img2u($str,$str2) {
    	
    	if (is_uploaded_file($_FILES[$str]['tmp_name'][$str2])) {
    	
    		$imageinfo = getimagesize($_FILES[$str]['tmp_name'][$str2]); 
    		if($imageinfo['mime'] == 'image/gif' || $imageinfo['mime'] == 'image/jpeg' || $imageinfo['mime'] == 'image/png')  {
    			
    			if(($_FILES[$str]['size'][$str2] != 0) AND ($_FILES[$str]['size'][$str2]<=1024*1000*3)) {
    				return 1;
    			}
    		}
    	}
    	return 0;
    }

    zombie65536, 18 Марта 2015

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

    +155

    1. 1
    logs.splice.apply(logs, [j, 1].concat(line.split("\n")));

    strax, 03 Марта 2015

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (in_array ($v["field_currency_out"]["und"][0]["tid"], array(20, 21, 26, 27,153,157,154,152,155,162)) || in_array ($v["field_currency_in"]["und"][0]["tid"], array(22, 23, 24, 25,151,156,150,149,148,161))) {
        $v["field_payment"]["und"][0]["tid"] = 28;
    } else {
        $v["field_payment"]["und"][0]["tid"]= 13;
    }

    Представте что весь сайт написан в этом же духе.
    Причем мы имеем дело с двома наборами констант для обозначения валют - для входа и выхода перевода.

    kissarat, 10 Февраля 2015

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

    +155

    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
    //Плэй
        var allOneComposition = $('.list ol').children('.oneComposition');
        for (var i = 0; i < allOneComposition.length; i++) {
            var oneComposition = allOneComposition.eq(i);
    
            var listPlay = oneComposition.find('.listPlay');
            listPlay.on('click', function() {
                var listPlayParents = $(this).parents();
                var d = listPlayParents.eq(3);
                d.toggleClass('oneComposition2');
    
            });
            /****удалить классы на неактивных элементах*****/
            var myClass = oneComposition.attr('class');
            if (myClass == 'oneComposition2') {
                //console.log(myClass);
            }
        }

    Занимательное чтиво

    hasesanches, 17 Января 2015

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

    +155

    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
    public function actionNominate()
    	{
    		if (isset($_POST['user']) and isset($_POST['ref']))
    		{
    
    			$user = $ref = NULL;
    			$user = strip_tags(trim($_POST['user']));
    			$ref = strip_tags(trim($_POST['ref']));
    
    			$test = UserAwardsRef::model()->count(array("condition"=>"id_ref=$ref AND id_user=$user"));
    
    			if ($test==0)
    			{
    				if ($user and $ref)
    				{
    					$model = new UserAwardsRef();
    					$model->id_ref = $ref;
    					$model->id_user = $user;
    					if ($model->save())
    					{
    						echo 1;
    					} else {
    						echo 'error';
    					}
                    } else {
    
    					echo "error";
    				}
    
    			} else {
    				echo 2;
    			}
    
    		} else {
    
    			echo "error";
    		}
    
    	}

    Входящие параметры предполагаются - integer
    Необходимо один раз насрать в таблицу с ключами из поста.

    obidnov, 16 Января 2015

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