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

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

    +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
    <?
    class ActiveRecord {
    static function find_by_id($id) {
    	$class = get_called_class(); // LSI magic comes from here
    	$sql = 'SELECT FROM `' . $class . '` WHERE `id`=\'' . $id .  "';";
    	echo "Generate sql for select by id\n";
    	echo $sql . "\n";
    	return(new $class);
    }
    
    function save() {
    
    $class = get_class();
    
    if(!isset($this->id)) {
    echo "Generate sql for new Record:\n";
    $sql = 'INSERT INTO `' . $class . '` ';
    $sql_fields = '(';
    $sql_values = '(';
    foreach($this->fields as $field => $type) {
    	if($field != 'id') {
    	$sql_fields .= '`' . $field . '`,';
    	$sql_values .= "'" . $this->{$field} . "',";
    	}
    }
    $sql = $sql . substr($sql_fields, 0, -1) . ') VALUES ' . substr($sql_values, 0, -1) . ');';
    echo 'sql: ' . $sql . "\n";
    $this->id = 1;
    } 
    else {
    	echo "Generate sql for Update:\n";
    	 
    	$sql = 'UPDATE `' . $class . '` SET ';
    	foreach($this->fields as $field => $type) {
    	if($field != 'id') {
    	$sql .= '`' . $field . '`=\'' . $this->{$field} . '\',';
    	}
    	}
    	$sql = substr($sql, 0, -1) . ';';
    	echo 'sql: ' . $sql . "\n";
    }
    }
    }

    qbasic, 21 Марта 2011

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

    +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
    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
    elseif( $action == "pingationmod" ) { 
    echoheader( "options", "pingationMod" ); 
    echo <<<HTML 
    <form action="{$PHP_SELF}" method="post"> 
    <div style="padding-top:5px;padding-bottom:2px;"> 
    <table width="100%"> 
    <tr> 
    <td width="4"><img src="engine/skins/images/tl_lo.gif" width="4" height="4" border="0"></td> 
    <td background="engine/skins/images/tl_oo.gif"><img src="engine/skins/images/tl_oo.gif" width="1" height="4" border="0"></td> 
    <td width="6"><img src="engine/skins/images/tl_ro.gif" width="6" height="4" border="0"></td> 
    </tr> 
    <tr> 
    <td background="engine/skins/images/tl_lb.gif"><img src="engine/skins/images/tl_lb.gif" width="4" height="1" border="0"></td> 
    <td style="padding:5px;" bgcolor="#FFFFFF"> 
    <table width="100%"> 
    <tr> 
    <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">Отправка уведомлений в пинг сервисы</div></td> 
    </tr> 
    </table> 
    <div class="unterline"></div> 
    <table width="100%"> 
    <tr> 
    <td style="padding:2px;" height="100" align="center"> 
    HTML; 
         
    echo "Вы действительно хотите отправить уведомления в пинг сервисы, на (<b>" . count( $selected_news ). "</b>) $lang[mass_confirm_1]<br><br> 
    <input class=bbcodes type=submit value=\"   $lang[mass_yes]   \"> &nbsp; <input type=button class=bbcodes value=\"  $lang[mass_no]  \" onclick=\"javascript:document.location='$PHP_SELF?mod=editnews&action=list'\"> 
    <input type=hidden name=action value=\"do_mass_ping\"> 
    <input type=hidden name=user_hash value=\"{$dle_login_hash}\"> 
    <input type=hidden name=mod value=\"massactions\">"; 
    foreach ( $selected_news as $newsid ) { 
    $newsid = intval($newsid); 
    echo "<input type=hidden name=selected_news[] value=\"$newsid\">"; 
    } 
    echo <<<HTML 
    </tr> 
    </table> 
    </td> 
    <td background="engine/skins/images/tl_rb.gif"><img src="engine/skins/images/tl_rb.gif" width="6" height="1" border="0"></td> 
    </tr> 
    <tr> 
    <td><img src="engine/skins/images/tl_lu.gif" width="4" height="6" border="0"></td> 
    <td background="engine/skins/images/tl_ub.gif"><img src="engine/skins/images/tl_ub.gif" width="1" height="6" border="0"></td> 
    <td><img src="engine/skins/images/tl_ru.gif" width="6" height="6" border="0"></td> 
    </tr> 
    </table> 
    </div></form> 
    HTML; 
    echofooter(); 
    exit(); 
    }elseif( $action == "do_mass_ping" ) { 
    include ENGINE_DIR .'/inc/include/pingfunction.php'; 
    include ENGINE_DIR .'/data/pingdata.php'; 
    foreach ( $selected_news as $newsid ) { 
    $newsid = intval($newsid); 
    $sql_select = "SELECT id, title, date, category, alt_name, flag FROM ".PREFIX ."_post WHERE id=".$newsid; 
    $sql_result = $db->query( $sql_select ); 
    while ( $row = $db->get_row( $sql_result ) ) { 
    $row['date'] = strtotime( $row['date'] ); 
    $title = $row['title']; 
    if( $config['allow_alt_url'] == "yes") { 
    if( $row['flag'] and $config['seo_type'] ) { 
    if( $row['category'] and $config['seo_type'] == 2 ) { 
    $full_link = $config['http_home_url'] .get_url( $row['category'] ) ."/".$row['id'] ."-".$row['alt_name'] .".html"; 
    }else { 
    $full_link = $config['http_home_url'] .$row['id'] ."-".$row['alt_name'] .".html"; 
    } 
    }else { 
    $full_link = $config['http_home_url'] .date( 'Y/m/d/',$row['date'] ) .$row['alt_name'] .".html"; 
    } 
    }else { 
    $full_link = $config['http_home_url'] ."index.php?newsid=".$row['id']; 
    } 
    } 
    pingationMod($title, $full_link, 0, $pingdata['service'], $pingdata['zaderjka']); 
    } 
    if($pingdata['allow_log']){ 
     
    saveLog("Массовая отправка уведомлений в пинг сервисы"); 
    } 
     
    clear_cache(); 
    msg( "info", "Уведомления успешно отправлены", "Уведомления успешно отправлены в пинг сервисы", $_SESSION['admin_referrer'] ); 
    }

    qbasic, 16 Марта 2011

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

    +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
    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
    <?php
    /*---------------------------------------------------------------------------
    *       @Module Name: Clans
    * @Description: ClanWars for LiveStreet
    * @Version: 1.0
    * @Author: trim06
    * @LiveStreet Version: 0.3.1
    * @File Name: Clans.mapper.class.php
    * @License: GNU GPL v2, http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    *----------------------------------------------------------------------------
    */
     
    class Mapper_Clans extends Mapper {
            public function AddClan($ownerId, $clanName, $nameUrl, $clanPeople, $clanDesc, $urlHomePage, $pathAvatar)
      {
                    $sql = 'INSERT INTO '.DB_TABLE_CLANS.'
                            (owner_id,
                            name,
                            name_url,
          people,
          people_count,
          description,
          reg_date,
          avator,
          url_home_page
                            )
                            VALUES(?d, ?, ?, ?, ?d, ?, NOW(), ?, ?)
                    ';
        $clanPeopleCount = count(explode(',', $clanPeople));
                    if($this->oDb->query($sql, $ownerId, $clanName, $nameUrl, $clanPeople, $clanPeopleCount, $clanDesc, $pathAvatar, $urlHomePage))
        {
                        $this->DropInviteClanCreate($ownerId);
                            return true;
                    }               
                    return false;
            }
      
            public function UpdateClan($clanId, $ownerId, $clanPeople, $clanName, $nameUrl, $clanDesc, $urlHomePage, $pathAvatar)
      {
                    $sql = 'UPDATE '.DB_TABLE_CLANS.' 
                            SET 
            name = ?,
            name_url = ?,
            people = ?,
            description = ?,'.
            (($pathAvatar) ? "avator = '".$pathAvatar."'," : '').
            'url_home_page = ?,
            people_count = ?d
                            WHERE
                                    owner_id = ?d AND id = ?d
                    ';
        $clanPeopleCount = count(explode(',', $clanPeople));
                    if ($this->oDb->query($sql, $clanName, $nameUrl, $clanPeople, $clanDesc, $urlHomePage, $clanPeopleCount, $ownerId, $clanId))
        {
                            return true;
                    }               
                    return false;
            }
      public function GetClans($status,&$iCount,$iCurrPage,$iPerPage)
      {
        $sql = 'SELECT * FROM '.DB_TABLE_CLANS.' WHERE status=?d 
    AND id NOT IN (SELECT clan_id
                    FROM '.DB_TABLE_CLANS_BANS.'
                    WHERE ban_active=1
                    GROUP BY clan_id)
    ORDER BY rating DESC LIMIT ?d, ?d';
        $status = ($status=='good') ? 0 : 1;
        if($aRows=$this->oDb->selectPage($iCount, $sql, $status, ($iCurrPage-1)*$iPerPage, $iPerPage))
        {
          return $aRows;
        }
        return null;
      }
    public function GetBannedClans(&$iCount,$iCurrPage,$iPerPage)
      {
        $sql = 'SELECT c.* 
            FROM  
            (SELECT clan_id
                    FROM '.DB_TABLE_CLANS_BANS.'
                    WHERE ban_active=1
                    GROUP BY clan_id) as cb
            JOIN '.DB_TABLE_CLANS.' as c ON c.id=cb.clan_id
            ORDER BY rating 
            DESC LIMIT ?d, ?d';
        if($aRows=$this->oDb->selectPage($iCount, $sql, ($iCurrPage-1)*$iPerPage, $iPerPage))
        {
          return $aRows;
        }
        return null;
      }

    qbasic, 11 Марта 2011

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

    +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
    54. 54
    55. 55
    <?php
    include("db.php");
    $query = "SELECT * FROM dbtest";
    $result = mysql_query($query);
    $fp = fopen("~/.ihmiheiha.conf", "w");
    if (!$fp)
    die("Ты намутил что-то не то... ведь всё работало");
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    $ihm=$row[0];
    $ihe=$row[1];
    $iha=$row[2];
    $filed = "tnkf: $ihm, tnkd: $ihe, tnka: $iha";
    fwrite($fp, $filed);
    }
    mysql_close ( $db );
    fclose($fp);
    ?>
    <html>
    <body>
    <form action='del.php' method='post'>
    <?php
    include("db.php");
    $query = "SELECT * FROM dhcpd";
    $result = mysql_query ( $query );
    $n = mysql_num_rows ( $result );
    for ( $i=0; $i<$n; $i++ )
      {
       $row = mysql_fetch_array($result);
       echo "<p><b><input type='checkbox' name='".($i+1)."' value='1'>";
       echo " ".($i+1).". Host: $row[ihm]</b></br>";
       echo "<b>MAC адрес:</b> $row[ihe]<br>";
       echo "<b>IP адрес:</b> $row[iha]</p>";
       }
    if ( $n == 0 ) echo "Никого нет.";
    mysql_close ( $db );
    ?>
    </form>
    <center>
    <div style="float:left">
    <FORM ACTION="add.php">
    <INPUT TYPE="submit" VALUE="Добавить">
    </FORM></div>
    <div style="float:left">
    <FORM ACTION="del.php">
    <INPUT TYPE="submit" VALUE="Удалить">
    </FORM>
    </div>
    <div style="float:left">
    <FORM ACTION="<?php echo $PHP_SELF?>">
    <INPUT TYPE="submit" VALUE="Применить изменения">
    </FORM>
    </div>
    </center>
    </body>
    </html>

    qbasic, 09 Марта 2011

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

    +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
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    #include <iostream.h>
    #include <stdlib.h>
    #define make(a,b) new a[b];
    #define init(a,b) for(int i=0; i<b; i++) a[i]=random(10);
    #define MyType int
    template<class type>
    void sort(type *m,int  n)
     {
     type *m1 = m;
       for(int i=0; i<n-1; i++)
      		{
            for(int j=0; j<n-i-1; j++)
               {
               if (*m1>*(m1+1))
            	    {
                                              MyType temp;
       		      temp=*m1;
      	    	       *m1=*(m1+1);
    		       *(m1+1)=temp;
             	  }
               m1++;
               }
           m1=m;
          }
     }
    
     template<class type>
     void input(type *m,int num)
     {
     type *m1=m;
     for(int i=0;i<num; i++)
      		{
             cin>>*m1;
              m1++;
          }
      m1=m;
      cout << endl;
     }
    
     template<class type>
     void output(type  *m, int n)
     {
     for(int i=0;i<n; i++)
      		{
             cout << *(m+i)<<" ";
          }
     }
    
     main()
     {
     int len;
      cout << "Vvedite razmer massiva" << endl;
      cin >> len;
    
      MyType *mas1 = make(MyType,len);
      input(mas1,len);
      //init(mas1,len);
      output<MyType>(mas1,len);
      sort<MyType>(mas1,len);
      cout<<endl;
      output<MyType>(mas1,len);
      cout<<endl;
      system("pause");;
     }

    Делалось на Borland C++ 5.02 , что прикольно без макроса make , если память выделяется просто в теле, то ревет, что память ниразу не выделена . Делали ее часика в 4 утра к зачету, препод конечно прибалдел от таких раскладов, но покопавшись ничего сам сделать не смог, плюнул на это дело и зачет поставил.

    USERNAME, 08 Марта 2011

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

    +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
    function buildKust( $queryId )
    {
        $commentQuery = getElementsBy('queryncomment', 'query', $queryId);
        IF($commentQuery)
         foreach($commentQuery as $key=>$CQ)
          {
           $query = mysql_query("SELECT * FROM comments WHERE lev = 0 AND id = '".$CQ['comment']."' ");
           while($comment = mysql_fetch_array($query))
            $nullLevel[] = $comment; 
          } 
          IF($nullLevel)
         foreach($nullLevel as $key=>$nullComment)
          {
             $nullComment['level'] = 0;
              $brunch[0] = $nullComment;
            $kust[] = getChildren($nullComment,$brunch, 1);
          }      
      return $kust;
    }

    Коменты

    GogaF, 06 Марта 2011

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

    +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
    function make_category_select($name,$selected='',$not='',$additional='')
            {
                    global $udb,$admin,$evoLANG,$cat_cache;
                    
                    $this->parent_name = $this->parent_name != "" ? $this->parent_name : $evoLANG['noparent'];
            
                    if ($this->onlyoptions != 1)
                    {
                            $a .= "<select name=\"".$name."\" ".$additional.">\n";
                    }
                    
                    $a .=  '<option value=""> '.$this->parent_name." </option>\n";
                    
     
                    $a .= $this->make_cat_options('0',$selected,1,$not);
     
                    if ($this->onlyoptions != 1)
                    {
                            $a .= '</select>';
                    }
     
                    return $a;
            }

    qbasic, 06 Марта 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function &_extract(&$array, $path) {
      $element = &$array;
      while(count($path)) {
        $key = array_shift($path);
        $element = &$element[$key];
      }
    
      return $element;
    }

    vectoroc, 05 Марта 2011

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

    +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
    <script language="php">
    $curl=curl_init("http://www.sportbox.ru");
    $proxy='us:psw@IP:port';
     
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_PROXY, $proxy);
     
    $content=curl_exec($curl);
     
    preg_match_all('#<h3><a href(.*)>(.*)</a></h3>#siU', $content, $titles);
    foreach ($titles[2] as $title)
    echo "<b>$title</b><br>";
     
    curl_close($content);
    </script>

    qbasic, 03 Марта 2011

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

    +158

    1. 1
    2. 2
    3. 3
    function sqlemptydate($test) {
      return (!$test || ($test == '0000-00-00') || ($test == '0000-00-00 00:00:00'));
    }

    ilyamx, 03 Марта 2011

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