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

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

    +50

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if($_REQUEST['filter2'] == 'my' OR $_REQUEST['filter2'] == 'all' OR $_REQUEST['filter2'] == 'delegated'){
        $filter2 = htmlspecialchars( $_REQUEST['filter2'], ENT_QUOTES );
    }else{
        $filter2 = 'all';
    }

    Может тогда уж $filter2 = htmlspecialchars( 'all', ENT_QUOTES ); для полного счастья?

    somnambulism, 27 Сентября 2012

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

    +50

    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
    <?php
    		
    		$confs = array();
    		
    		$q = new WP_Query(array('post_type' => 'conference',
    					'posts_per_page' => -1,
    					'meta_key' => 'cd-conference-date-start',
    					'orderby' => 'meta_value_num',
    					'order' => 'DESC'
    					));
    		while($q->have_posts()): $q->the_post();
    		$confs[date("Y", get_post_meta($post->ID, 'cd-conference-date-start', true))][] = array('conf_title' => get_the_title(),
    												      'conf_date_start' => get_post_meta($post->ID, 'cd-conference-date-start', true),
    												      'conf_date_end' => get_post_meta($post->ID, 'cd-conference-date-end', true),
    												      'conf_link' => get_permalink(),
    												      'conf_city' => '', /* Город */
    												      'conf_icon' => '' /* Иконка */
    												      );
    		endwhile;
    
    		wp_reset_postdata();
    		
    		foreach($confs as $key => $value)
    		{
    		?>
                    <h1 class="year"><?=$key;?></h1>
    		<?php
    		//print_r($value);
    		?>
                    <div class="conferences">
    		  <?php foreach($value as $val)
    		  {
    		  //print_r($val);
    		  ?>
                      <div class="conf">
                        <div class="leftcol">
                          <a href="<?=$val["conf_link"];?>"><img src="<?=$val["conf_icon"];?>"></a>
                        </div>
                        <div class="rightcol">
                          <a href="<?=$val["conf_link"];?>"><h2><?=$val["conf_title"];?></h2></a>
                          <span class="date-place">
    			<?php
    			//setlocale(LC_TIME, "ru_RU");
    			if(date("m", $val["conf_date_start"]) == date("m", $val["conf_date_end"])) $confdays = date("j", $val["conf_date_start"])."-".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]));
    			else
    			{
    				$confdays = date("j", $val["conf_date_start"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]))." - ".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_end"]));
    			}
    			?>
    			<?=$confdays;?>, <?=$val["conf_city"];?>
    		      </span>
                        </div>
                      </div>
    		  <?php
    		  }
    		  ?>
                    </div>
    		
    		<?php } ?>

    varg242, 23 Июня 2012

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

    +50

    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
    <?php
     require('url_to_absolute.php');
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    $ext=array(
    'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
    'docs'=>array('rtf','doc','docx','pdf','txt'),
    'html'=>array('shtml','html','xml','css','htm','xhtml'),
    'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
    'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
    'pack'=>array('deb','rpm','jar'),
    'scripts'=>array('sh','pl','py','php','js')
    );
    $murl="";
    $sext="";
    $routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
    foreach($ext as $sk=>$sval){
    foreach($sval as $exts){
      $routh.='(?!'.$exts.'")';
    }
    }
    $routh.='[a-z0-9]{1,5}(?=[" ]))|i';
    echo $routh."<br\ >";
    if(isset($_GET['url'])){
    $url=$_GET['url'];echo $url."<br>";
    preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
    if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
    $html=file_get_contents($url);
    
    foreach($ext as $key=>$val){
    echo "<h2>$key</h2><br\>";
    foreach($val as $mext){
    echo "$mext<br>";
    preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
      if(!empty($result)){
      if(!empty($result[0])){
        $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
        echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
      $result[0]=array_unique($result[0]);
      foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a> ");}
    }
    }
    
    }
    }
    preg_match_all($routh,$html,$result);
    if(!empty($result)){
    if(!empty($result[0])){
    $result[0]=array_unique($result[0]);
    echo "<br><h2>Other documents</h2><br>";
    foreach($result[0] as $vres){
        $aurl=url_to_absolute($url,$vres);
    echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
    }
    }
    }
    } else { printf("No url\n");}
    ?>

    Вытягивает ссылки на картинки с html файла

    AliceGoth, 21 Июня 2012

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

    +50

    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
    // $conn - mysqli_object
     $query = "insert into orders values
                ('0', '".$customerid."', '".$_SESSION['total_price']."',
                '".$date."', '".PARTIAL."', '".$ship_name."',
                '".$ship_address."', '".$ship_city."',
                '".$ship_state."', '".$ship_zip."',
                '".$ship_phone."', '".$ship_mail."')";
      $result = $conn->query($query) ;
      if (!$result) {
        return false;
      }
    //amount - float
      $query = "select orderid from orders where
              customerid = '".$customerid."' and
              amount > (".$_SESSION['total_price']."-.001) and
              amount < (".$_SESSION['total_price']."+.001) and
              date = '".$date."' and
              order_status = 'PARTIAL' and
              ship_name = '".$ship_name."' and
              ship_address = '".$ship_address."' and
              ship_city = '".$ship_city."' and
              ship_state = '".$ship_state."' and
              ship_zip = '".$ship_zip."' and
              ship_country = '".$ship_country."'";
      $result = $conn->query($query);
      if ($result->num_rows > 0) {
        $order = $result->fetch_object();
        $orderid = $order->orderid;
      } else {
        return false;
      }

    Источник: Люк Веллинг и Лора Томсон: Разработка веб-приложений с помощью PHP и MySQL(4 издание стр 594)

    Как выдрать last_insert_id? Очень просто: нужно составить запрос на select вставленного orderid с указанием всех вставленных значений в поля, а для флоата указать на всякий случай интервал, и только тогда можно из выборки извлечь вставленный id

    ps: констатна PARTIAL нигде не задаётся=)

    RedMonkey, 16 Июня 2012

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

    +50

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int i, j;
    for (i = j = 0; i < 4; i++)
    	if (frame & (0x8 >> i))
    	{
    		if (i < 2 && p.value < double(frames1[j]) && !(i && j) ||
    			i > 1 && p.value > double(frames1[j]))
    			p.value.attr = 1 + i;
    		j++;
    	}

    Как вам цикл до 4 с тремя проверками на значение счётчика? :)

    Dimarius, 25 Августа 2009

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

    +49.9

    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
    bool __fastcall TForm1::ImportFile(AnsiString FName, int Direction)
    {
    bool StatusUpload;
    StatusUpload = true;
    
    TStringList *Inside;
    Inside = new TStringList;
    Inside->LoadFromFile(FName);
    if (Direction == 1)
    {
      // ...
      date_made = StrToSqlDate(Inside->Strings[1]);
      ops = Inside->Strings[0];
    
      Inside->Delete(0);
      Inside->Delete(0);
      Inside->Delete(0);
    
      int Iterations = (Inside->Count/5);
      for (int i=0; i<Iterations; i++)
      {
        AnsiString A, B, C, D, E;
        A = Inside->Strings[0].Trim();
        B = Inside->Strings[1].Trim();
        C = Inside->Strings[2].Trim();
        D = Inside->Strings[3].Trim();
        E = Inside->Strings[4].Trim();
        for (int j=0; j<5;j++)
           Inside->Delete(0);
    
        if (A == "1.1.2")
          E='1';
    
        if (A == "4.13" || A == "4.13" || A == "4.13")
    	  E='20';
        C = RemoveZPT(C);
    	ADOQuery1->SQL->Text = "INSERT INTO dnevnik_inside (row_id, ops, date_made, code, sign, val, val_init, direction, type) VALUES ("
          + row_id + ", '" + ops + "', '" + date_made + "', '" + A + "', '"
          + B + "', " + C + ", " + C + ", '" + D +"', '"+E+"')";
        ADOQuery1->ExecSQL();
      }
      Trans->CommitRetaining();
    }

    Собсно, название функции говорит само за себя :)
    П.С. Коллега, не обижайся!

    labutinpa, 05 Сентября 2009

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

    +49.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    bool ok;
    double d;
    
    QLocale c(QLocale::C);
    d = c.toDouble( "1234.56", &ok );  // ok == true, d == 1234.56

    Ссылка на bool!

    mock, 14 Апреля 2010

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

    +49.6

    1. 1
    2. 2
    3. 3
    /*
     * ToDo: дописать, что нужно сделать.
     */

    greevex, 19 Ноября 2009

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

    +49.5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (gettype($x/2) == 'int') { 
       $rowspan = $x - $i;                     
    } else { 
       $rowspan = ($x - $i) + 1; 
    }

    Проверка на остаток от деления на 2 одним начинающим знакомым ПХП программистом

    guest, 20 Декабря 2008

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

    +49.2

    1. 1
    2. 2
    3. 3
    4. 4
    if (strlen(tmpStr) > 250) 
        strncpy(fields[i].info.fieldName, tmpStr, 250);
    else 
        strcpy(fields[i].info.fieldName, tmpStr);

    А пох - все равно скопируем. =)

    rockerzz, 27 Августа 2009

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