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

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    /*	Адаптация под оперу	*/
    if ( stristr($_SERVER['HTTP_USER_AGENT'], 'Opera') )
    	echo "<input type=hidden value='file_ok' name='action'><br><input type=\"image\" src=\"".$url."images/buttons/button_file_ok.png\">";
    else 
    	echo "<br><input type=\"image\" src=\"".$url."images/buttons/button_file_ok.png\" value=\"file_ok\" name=\"action\">";

    особый говнокод для Оперы
    http://my.opera.com/russian/forums/topic.dml?id=918821

    xxx, 28 Февраля 2011

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

    +158

    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
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
    	function  myTags(mytags){
    		mytags=mytags.replace(/<A/g, '<a')
    			.replace(/\/A>/g, "/a>")
    			.replace(/(\starget=_)(\w*)/g, ' target="_$2"')
    			.replace(/(\sclass=)(?!")(\w*)/g, ' class="$2"')
    			.replace(/(\sname=)(?!")(\w*)/g, ' name="$2"')
    			.replace(/(\sid=)(?!")(\w*)/g, ' id="$2"')
    			.replace(/(\srel=)(?!")(\w*)/g, ' rel="$2"');
    		mytags=encodeURIComponent(mytags).replace(/!/g, '%21')
    			.replace(/'/g, '%27').replace(/\(/g, '%28')
    			.replace(/\)/g, '%29').replace(/\*/g, '%2A');
    		var rnumber = Math.floor(Math.random()*9999999);
    		var flashvars = {
    			tcolor:"0x2A62C8",
    			tcolor2:"0x000000",
    			hicolor:"0xB12AC8",
    			tspeed:"110",
    			distr:"true",
    			mode:"tags",
    			tagcloud:mytags
    		};
    		var params = {
    			allowScriptAccess:"always",
    			bgcolor:'#ffffff'
    		};
    		var attributes = {
    			id:"flash_cloud"
    		};
    		swfobject.embedSWF("tagcloud.swf?r="+rnumber,
    						   "tags", "600", "420", "9.0.0",
    						   "expressInstall.swf", flashvars,
    						   params, attributes);
    	}
    	window.onload=function(){
    		var mytags="<tags>"
    		+document.getElementById('tags').innerHTML
    		+"</tags>";
    		myTags(mytags);
    	};
    </script>

    qbasic, 22 Февраля 2011

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

    +158

    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
    <?
    //include('../root/start.php');
    include('start.php');
    
    
    
    
    $hotels_menu_id = GetSettingsParam('hotels_menu_id');
    
    if ($image_id = $_GET['image_id']) {
        $row = mysql_fetch_assoc(mysql_query(
                        'select co.id co_id, co.title co_title, ' .
                        'ci.id ci_id, ci.title ci_title, ' .
                        'h.id h_id, h.title h_title ' .
                        'from ' . _mysql_tbl_prefix . 'countries co ' .
                        'left join ' . _mysql_tbl_prefix . 'cities ci on co.id = ci.country_id ' .
                        'left join ' . _mysql_tbl_prefix . 'hotels h on ci.id = h.city_id ' .
                        'left join ' . _mysql_tbl_prefix . 'hotel_images hi on hi.hotel_id = h.id ' .
                        'where hi.image_id = ' . $image_id));
        echo mysql_error();
    # $src = '../../hotel_images/'.(int)($image_id/2000).'/'.$image_id.'.jpg';
        $src = './hotel_images/' . (int) ($image_id / 2000) . '/' . $image_id . '.jpg';
    }
    ?>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
            <title>Фото отеля "<?= $row['h_title'] ?>" (<?= $row['ci_title'] . ', ' . $row['co_title'] ?>) - Туроператор</title>
        </head>
        <link rel="stylesheet" href="../hotel_image.css">
        <body>
            <table height="100%" width="100%">
                <tr>
                    <td valign="middle" align="center">
                        <h1 class="hotel-image-title"><?=
    'Фото отеля "<a href="../index.php?menu_id=' . $hotels_menu_id . '&hotel_id=' . $row['h_id'] . '">' . $row['h_title'] . '</a>" ' .
            '(<a href="../index.php?menu_id=' . $hotels_menu_id . '&city_id=' . $row['ci_id'] . '">' . $row['ci_title'] . '</a>, ' .
            '<a href="../index.php?menu_id=' . $hotels_menu_id . '&country_id=' . $row['co_id'] . '">' . $row['co_title'] . '</a>)'
    ?></h1>
                        <a href="#" onClick="window.close()"><img src="<?= $src ?>" class="hotel-image" alt="Фото отеля "<?= $row['h_title'] ?>" (<?= $row['ci_title'] . ', ' . $row['co_title'] ?>)"></a>
                    </td>
                </tr>
            </table>
        </body>
    </html>

    Попросили так сазать исправить))
    я был ошеломлен "магическим числом" 2000

    rainerg, 22 Февраля 2011

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

    +158

    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
    function portfolio_lists($bool, $d, $str, $ids) {
    if (!isset($_GET['page']) or !is_numeric($_GET['page'])) { $page = 1; } else { $page = mysql_real_escape_string($_GET['page']); }
    $write = null;
    $sch_res_num = 0;
    $sch = 0;
        if ($bool == "personal") { $query = "SELECT * FROM `wp_posts` WHERE post_type='jh-portfolio' && post_status='publish'"; }
        if ($bool == "category") { $query = "SELECT * FROM `wp_posts` WHERE post_status='publish' && post_type='jh-portfolio' &&".$ids; }
        $sql = mysql_query($query) or die("Error ;)");
        $num = mysql_num_rows($sql);
        
        if ($bool == "personal") {
        $sql = mysql_query($str->strake($num, $d, $page, false)); } else { $sql = mysql_query($str->strake($num, $d, $page, $ids));}
        
      
        if ($num > 0) {
        while ($moar = mysql_fetch_array($sql)) {
    
        //Изображение 
        $img1 = mysql_fetch_row(mysql_query("SELECT * FROM `wp_postmeta` WHERE post_id='".$moar['ID']."' && meta_key='_jhp_main_image'"));
        $img2 = mysql_fetch_row(mysql_query("SELECT * FROM `wp_postmeta` WHERE post_id='".$img1[3]."' && meta_key='_wp_attached_file'"));
    
        //Категория принадлежности
        $cat = mysql_query("SELECT * FROM `wp_term_relationships` WHERE object_id=".$moar['ID']) or die("Error:&nbsp;".mysql_error());
        if (mysql_num_rows($cat) > 0) {
        $cat = mysql_fetch_array($cat);
        $cat = mysql_fetch_array(mysql_query("SELECT * FROM `wp_terms` WHERE term_id=".$cat[1]));
        $cat = array('id'=>$cat['term_id'], 'name'=>$cat['name']);
        $im = false;
        } else {
        $cat = array('id'=>'', 'name'=>'Other Category');
        $im = true;
        }
        if (strlen($img2[3]) > 0) {
        $connect = explode(".", $img2[3]);
        $connect = $connect[0]."-150x150.".$connect[1];
        if ($im == 0) { $w = "<a href=\"http://".URL."/?page_id=20&cat_portfolio=".$cat['id']."\" class=\"category\">".$cat['name']."</a>"; }
        if ($im == 1) { $w = "<font class=\"category\">".$cat['name']."</font>"; }
        //Запись в переменную
        $write .= "<td class=\"content_text\" ".$kr."><img src=\"http://".URL."/wp-content/uploads/".$connect."\" alt=\"\" class=\"image_portfolio\" style=\"padding-bottom: 10px;\"><br><a href=\"".$moar['guid']."\">".$moar['post_title']."</a><br>".$w."</td>"; 
        } else {
         $write .= "<td class=\"content_text\" ".$kr."><img src=\"http://".URL."/wp-content/themes/wp-framework/img/inu.png\" alt=\"Основное изображение работы не загружено\" class=\"image_portfolio\" style=\"padding-bottom: 10px;\"><br><a href=\"".$moar['guid']."\">".$moar['post_title']."</a><br>".$w."</td>";    
        }
    $sch++;
    
     if($sch == 3 or $sch == $sch_res_num+3) { $write .= "</tr><tr>"; $sch_res = true; $sch_res_num = $sch; } else { $sch_res = false; }
         } 
    print($write);
    if ($bool == "personal") { print("<tr><td class=\"content_text\">Go to page:&nbsp;".$str->strprint("personal")."</td></tr>"); }
    if ($bool == "category") { print("<tr><td class=\"content_text\">Go to page:&nbsp;".$str->strprint("category")."</td></tr>"); }
        
    if ($sch_res == false) { echo "</tr>"; }
    } else { print("<td class=\"content_text\">No projects</td></tr>"); }
     }

    Furry, 20 Февраля 2011

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

    +158

    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
    if ($_GET[action] == "avatar") {
    
    
    	if ($info = $_GET[info]) {
    
    			if ($info[avatar]) {
    				echo $info[avatar];
    			} else {
    					header("Content-type: image/png");
    
    					$im = imagecreatetruecolor(80, 80);
    					$white = imagecolorallocate($im, 255, 255, 255);
    					$grey = imagecolorallocate($im, 128, 128, 128);
    					$black = imagecolorallocate($im, 0, 0, 0);
    					imagefilledrectangle($im, 0, 0, 80, 80, $white);
    					$font = "fonts/avatar.ttf";
    
    					$text = "HET";
    					imagettftext($im, 20, 0, 15, 40, $grey, $font, $text);
    					imagettftext($im, 20, 0, 14, 39, $black, $font, $text);
    					$text = "ABATAPA";
    					imagettftext($im, 14, 0, 5, 55, $grey, $font, $text);
    					imagettftext($im, 14, 0, 4, 54, $black, $font, $text);
    					imagepng($im);
    					imagedestroy($im);
    			}
    	} else {
    					header("Content-type: image/png");
    
    					$im = imagecreatetruecolor(80, 80);
    					$white = imagecolorallocate($im, 255, 255, 255);
    					$grey = imagecolorallocate($im, 128, 128, 128);
    					$black = imagecolorallocate($im, 0, 0, 0);
    					imagefilledrectangle($im, 0, 0, 80, 80, $white);
    					$font = "fonts/avatar.ttf";
    
    					$text = "HET";
    					imagettftext($im, 20, 0, 15, 40, $grey, $font, $text);
    					imagettftext($im, 20, 0, 14, 39, $black, $font, $text);
    					$text = "ABATAPA";
    					imagettftext($im, 14, 0, 5, 55, $grey, $font, $text);
    					imagettftext($im, 14, 0, 4, 54, $black, $font, $text);
    					imagepng($im);
    					imagedestroy($im);	
    	}
    
    }

    Вот такое говнецо встретилось))

    Sulik78, 19 Февраля 2011

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

    +158

    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
    <?
        $id = isset($_GET['id']) ? (int)$_GET['id']: false;
        if(!isset($_GET['id'])){echo "Right";}
        elseif(!(int)($_GET['id'])){echo "The id does not exist";}else{
        $id = mysql_real_escape_string($_GET['id']);      }
        $sql = "SELECT * FROM `users` WHERE `id` = '$id'";
        $result = mysql_query($sql) or die(mysql_error() ."<br/>". $sql);
        
        while ($row = mysql_fetch_assoc($result)){
            Echo $row['name'];
            Echo $row['surname'];
        }
        
        # вывод рейтинга <<<
        
         // в этот запрос передаем id пользователя, полученный на предыдущем этапе
        $query = mysql_query("SELECT * FROM test WHERE id={$row['id']}");
     
        $info = mysql_fetch_assoc($query); // $info содержит рейтинг *одного* пользователя
        $rating = (int)$info[rating];
    ?>
    
    <table border="0" width="135" cellspacing="0" cellpadding="0" height="21">
        <tr>
            <td id="rating_<?php echo $info[id]; ?>" style="width: 88px; height: 21px">
                <span class="star_1"><img src="star_blank.png" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span>
                <span class="star_2"><img src="star_blank.png" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span>
                <span class="star_3"><img src="star_blank.png" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span>
                <span class="star_4"><img src="star_blank.png" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span>
                <span class="star_5"><img src="star_blank.png" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span>
            </td>
            <td class="floatleft" width="46" align="left">
                (<?php echo $info[rating]; ?>)
            </td>
        </tr>
    </table>

    qbasic, 19 Февраля 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function search() {
        $ret = array();
        foreach($this->dir() as $file)
            if($file->folder())
                $ret = array_merge($ret,$file->search()->asArray());
            else
                $ret[] = $file;
        return new mod_file_list($ret);
    }

    Красота, в результате работы функции мы получаем объект, состоящий из массива объектов класса file (этот метод в этом классе)... "чудо-поиска" (хотя это вовсе и не поиск, а банальный список файлов всех дочерних папок), особенно будет забавно, если в списке будет несколько тысяч файлов...
    В этом классе в принципе много мест, которые наровят насоздавать кучу экземпляров этого же класса, вместо замены одной приватной переменной...

    GhOsTMZ, 15 Февраля 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function changeType(what) {
                    if (what == "forward") {
                            if (document.forms[0].elements['forward_list'].disabled == true) {
                                    document.forms[0].elements['forward_list'].disabled = false;
                            } else {
                                    document.forms[0].elements['forward_list'].disabled = true;
                            }
                    }
            }

    Есть замечательная ispCP и форма для настройки форвардинга е-мэйлов. Тут описывается поведение чек-бокса для включения формы.

    Mr_Alone, 09 Февраля 2011

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

    +158

    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
    do
            {
                    do
                            {
                                    if ($myrow_cats["category_id"] == $myrow_oldtovar_1["id"])
                                            {
                                                    printf("<tr><td class='newcat_author'><input name='old_id_cat[]' type='checkbox' value='%s' checked >
                                                    %s</td></tr>",
                                                    $myrow_oldtovar_1["id"],$myrow_oldtovar_1["rubrikatitle"]);
                                            }
                                    else
                                            {
                                                    printf("<tr><td class='newcat_author'><input name='old_id_cat[]' type='checkbox' value='%s' >%s</td></tr>",
                                                    $myrow_oldtovar_1["id"],$myrow_oldtovar_1["rubrikatitle"]);
                                            }       
                            }
                    while($myrow_oldtovar_1 = mysql_fetch_array($result_oldtovar_1));
            }
    while ( $myrow_cats = mysql_fetch_array($result_cats) );

    qbasic, 08 Февраля 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    $arTime = localtime();
    //формируем ядро номера заказа, которое будем подцеплять к разным префиксам
    
    $orderNumberCore = str_pad($arTime[4]+1, 2, "0", STR_PAD_LEFT).str_pad($arTime[3], 2, "0", STR_PAD_LEFT).str_pad($arTime[2], 2, "0", STR_PAD_LEFT).str_pad($arTime[1], 2, "0", STR_PAD_LEFT).str_pad($arTime[0], 2, "0", STR_PAD_LEFT);

    Формируется номер заказав интернет-магазине из даты/времени. Но при этом не учитывается год.

    $orderNumberCore -- это дата в формате dmhis.

    kost, 07 Февраля 2011

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