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

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

    −101

    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
    вопрос:
    есть массив $friends[id1] и friends2[id2] можно ли их объединить?
    
    ответ:
    $friends[id1] .= $friends2[id2];//(точка перед равно)
    
    Помогло?
    
    если ключи есть совпадающие
    foreach($friends2[id2] as $key=>$item)
    {
        $friends[id1][$key.'_2']=$item;
    }
    
    
    ну или с проверкой
    foreach($friends2[id2] as $key=>$item)
    {
        if(isset($friends[id1][$key]))// проверка на существование ключа
        {
            $friends[id1][$key.'_2']=$item;
        }
        else
        {
            $friends[id1][$key]=$item;
        }
    }
    
    
    можно усложнить
    foreach($friends2[id2] as $key=>$item)
    {
        if(isset($friends[id1][$key]) && $friends[id1][$key]!==$item)// проверка на существование ключа и совпадение с существующим значением ключа первого массива
        {
                $friends[id1][$key.'_2']=$item;
        }
        else
        {
            $friends[id1][$key]=$item;
        }
    }
    вот

    мой говнокод))

    Snickers, 20 Марта 2011

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

    +159

    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
    <?php
    /* Подключаемые файлы */
    require_once('data/config.test.php');
     
    /**
    * Сохранение настроек модуля
    */
    if ($action == "dosave") {
        $find[]     = "'\r'";
        $replace[]  = "";
        $find[]     = "'\n'";
        $replace[]  = "";
     
    if ($member_db[1] != 1) {
        msg ("error", $lang['opt_denied'], $lang['opt_denied']);
    }
    $handler = @fopen('data/config.test.php', "wb");
    fwrite ($handler, "<?php \n\n//Test configurations
                             \n\n\$config_test = array(
                             \n\n'version' => \"v.1.0\",\n\n");
     
    foreach ($save_con as $name => $value) {    
        $value = trim(stripslashes ($value));
        $value = htmlspecialchars  ($value, ENT_QUOTES);
        $value = preg_replace($find, $replace, $value);
        fwrite($handler, "'{$name}' => \"{$value}\",\n\n");
    }
        
    fwrite($handler, ");\n\n?>");
    fclose($handler);
     
    msg ("info", "Строка изменена",
         "{$lang['opt_sysok_1']}<br /><br />
          <a href=\"{$PHP_SELF}?mod=test_adm\">{$lang['db_prev']}</a>");
    }
    echo"Шапка";
    echo<<<HTML
    <form action="" method="POST">
    <table width="100%">
      <tr>
        <td class="option" style="padding:4px;">
          <b> Текст выводимой строки: </b><br />
          <span class="small"> например: Hello world </span>
        <td align="middle" width="400">
          <input class="edit" style="text-align:center" size="40" value="{$config_test['text']}" name="save_con[text]"></td>
      </tr>
      
      <tr>
        <td class="option" style="padding:4px;">
           <b> Комментарий к тексту: </b><br />
           <span class="small"> например: Это ваш первый пример модуля с админпанелью </span>
        <td align="middle" width="400">
           <input class="edit" style="text-align:center" size="40" value="{$config_test['detail']}" name="save_con[detail]"></td>
      </tr>
    
      <tr>
        <td class="option" style="padding-bottom:10px; padding-top:10px; padding-left:10px;" colspan="2">
          <input class="buttons" type="hidden" name="action" value="dosave" />
          <input class="buttons" type="submit" name="do" value=" Сохранить " /></td>
      </tr>
      
    </table>
    </form>
    HTML;
    echo"Подвал";
    ?>

    qbasic, 19 Марта 2011

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
    	 * Test to see if the cache storage is available.
    	 *
    	 * @static
    	 * @access public
    	 * @return boolean  True on success, false otherwise.
    	 */
    	function test()
    	{
    		return true;
    	}

    Описание метода в коментах.
    Joomfish

    tranquillity, 16 Марта 2011

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

    +114

    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
    [Serializable()]
    	public class Vendor
    	{
    		#region Constructors
    
    		public Vendor(long vendorID)
    		{
    			LoadData(vendorID);
    		}
    
    		internal Vendor(Vendor argVendor)
    		{
    			if (argVendor != null)
    			{
    				this.ID = argVendor.ID;
    				this.VendorName = argVendor.VendorName;
    				this.Account = argVendor.VendorAccount;
    				this.EIN = argVendor.VendorEIN;
    				this.Address = argVendor.VendorAddress;
    				this.City = argVendor.VendorCity;
    				this.State = argVendor.VendorState;
    				this.PostalCode = argVendor.VendorZip;
    				this.Phone = argVendor.VendorPhone;
    				this.ContactName = argVendor.VendorContact;
    				this.VendorCode = argVendor.VendorCode;
    				this.Country = argVendor.VendorCountry;
    				this.FaxNumber = argVendor.VendorFax;
    				this.Email = argVendor.Email;
    			}
    		}
    		#endregion
    
    		public void LoadData(long vendorID)
    		{
    			POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
    			var ven = (from v in db.Vendors
    					   where v.ID == vendorID
    					   select v).SingleOrDefault();
    			if (ven != null)
    			{
                    populateMe(ven);
    			}
    		}
            public void LoadDataByVendorCode(string argVendorCode)
            {
                POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
                var ven = (from v in db.Vendors
                           where v.VendorCode == argVendorCode
                           select v).Take(1).SingleOrDefault();
                if (ven != null)
                {
                    populateMe(ven);
                }
            }
            private void populateMe(Vendor ven)
            {
                this.ID = ven.ID;
                this.VendorName = ven.VendorName;
                this.Account = ven.VendorAccount;
                this.EIN = ven.VendorEIN;
                this.Address = ven.VendorAddress;
                this.City = ven.VendorCity;
                this.State = ven.VendorState;
                this.PostalCode = ven.VendorZip;
                this.Phone = ven.VendorPhone;
                this.ContactName = ven.VendorContact;
                this.VendorCode = ven.VendorCode;
                this.Country = ven.VendorCountry;
    	    this.FaxNumber = ven.VendorFax;
    	    this.Email = ven.Email;
            }
    }

    No comments!!!

    Arterius, 16 Марта 2011

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

    +161

    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
    elseif(isset($_GET['del']))
    {
        foreach($_POST as $id=>$a)
        {
            mysql_query("DELETE FROM `{$prefixbd}$table` WHERE `id`='".intval($id)."'")or die(mysql_error());
            @chmod(ret_img($file_path.$id),0777);
            @unlink(ret_img($file_path.$id));
            @chmod(ret_img($file_path.$id.'_big'),0777);
            @unlink(ret_img($file_path.$id.'_big'));
            $sql=mysql_query("SELECT FROM `{$prefixbd}{$table}_img` WHERE `prod`='".intval($id)."'")or die(mysql_error());
            while($data=mysql_fetch_assoc($sql)){
                @chmod(ret_img($file_path.$id.'_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_'.$data['id'].'_add'));
                @chmod(ret_img($file_path.$id.'_big_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_big_'.$data['id'].'_add'));
                mysql_query("DELETE FROM `{$prefixbd}{$table}_img` WHERE `id`='".$data['id']."'");
            }
        }

    Обратите внимание как удаляет файлы)) исходник из некого chrono CMS

    dobs2005, 16 Марта 2011

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

    +163

    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
    <?php
    set_time_limit(0);
    $d    = 0;
    $t    = 0;
    $link = mysql_connect('localhost', 'root', '123456'); // or die(mysql_error());
    //mysql_query('SET NAMES `cp1251`') or die(mysql_error());
    $dbr = mysql_query('SHOW DATABASES') or die(mysql_error());
    while ($dbd = mysql_fetch_assoc($dbr)) {
        if ($dbd['Database'] != 'information_schema') {
            mysql_select_db($dbd['Database'], $link); // or die(mysql_error());
            $tr  = mysql_query('SHOW  TABLES'); // or die(mysql_error());
            $sql = '';
            while ($td = mysql_fetch_assoc($tr)) {
                $sql .= '`' . $td['Tables_in_' . $dbd['Database']] . '`, ';
                ++$t;
            }
            $sql = substr($sql, 0, -2);
            mysql_query('REPAIR TABLE  ' . $sql . ''); // or die(mysql_error());
            ++$d;
        }
    }
    echo 'Востановил: ' . $d . ' баз(ы) данных, общие кол-во таблиц: ' . $t;
    mysql_close($link);

    Делает "REPAIR" всех баз данных.

    Unknown, 14 Марта 2011

    Комментарии (4)
  8. ActionScript / Говнокод #5959

    −94

    1. 1
    2. 2
    mCharInfoContent.x += ( hexTile.x + hexTile.parent.x + hexTile.parent.parent.x + hexTile.parent.parent.parent.x );
    mCharInfoContent.y += ( hexTile.y + hexTile.parent.y + hexTile.parent.parent.y + hexTile.parent.parent.parent.y );

    Красота неописуемая, метод научного тыка в действии

    Werdn, 11 Марта 2011

    Комментарии (4)
  9. Java / Говнокод #5955

    +76

    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
    //skipped
            b1 = new JButton("Disable middle button", leftButtonIcon);
            b1.setVerticalTextPosition(AbstractButton.CENTER);
            b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
            b1.setMnemonic(KeyEvent.VK_D);
            b1.setActionCommand("disable");
            b1.addActionListener(this);
    
    }
    
     public void actionPerformed(ActionEvent e) {
            if ("disable".equals(e.getActionCommand())) {
                b2.setEnabled(false);
                b1.setEnabled(false);
                b3.setEnabled(true);
            } else {
                b2.setEnabled(true);
                b1.setEnabled(true);
                b3.setEnabled(false);
            }

    из мануала на oracle.com. Что действительно так нужно обрабатывать события?

    KoirN, 11 Марта 2011

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

    +163

    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
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    $tmp = mysql_query("SELECT DISTINCT (author),(poluchatel) FROM  messages WHERE author='$login' OR poluchatel='$login' ORDER BY  poluchatel,author ",$db); 
                $messages =  mysql_fetch_array($tmp);//извлекаем автора
     if (!empty($messages['author'])) 
    {
    $mass[]='';     // сюда хуячим все имена контактов, всё шо есть в базе
    $security;      // ключ 0,1
    $i=0;          //счетчик
    $white='ffffff';
    $blue='e3ebf8';
    $c=0;
    do //выводим всех авторов
    {
    	$security=1;   //первоначально положительно("1") в каждом цикле на каждый контакт
    if($messages['author']==$login) //если поле автор = тому чья стр
    {
    	$author = $messages['poluchatel'];  //то в пер автор сохраняем имя получателя
    	$mass[$i]=$author;  //кидаем копию имя в массив
    	$i++;	//счетчик ++
    }
    
    else{	//если поле автор не тот  чья стр
    	$author = $messages['author']; //то в пер летит имя отправителя из базы
    	$mass[$i]=$author;	//ебошим всё в массив
    	 $i++;
    		}
    
    for($j=0; $j<=$i; $j++)	//перебераем массив
    {
    
    if($mass[$j]==$messages['poluchatel']) //если в массиве уже есть такой автор
    {$security=0; break;}	//то присваеваем ключ "0"
    }
            if($security==1)	//усли ключ = 1, то выводим контакт
    {
    $result4 = mysql_query("SELECT avatar,id FROM users WHERE login='$author'",$db); //извлекаем аватар автора 
    $myrow4 = mysql_fetch_array($result4);
    if (!empty($myrow4['avatar']))  {//если такового нет, то выводим стандартный (может    этого пользователя уже давно удалили)
    $avatar = $myrow4['avatar'];
    }
    else {$avatar = "avatars/net-avatara.jpg";}
    
    $auth = $messages['author'];  //запоминаем имя этого автора
    $count = mysql_query("SELECT * FROM  messages WHERE author='$auth' AND poluchatel='$login' AND stat='0' " ); //выбираем строки с непрочит соо
    $new_msg=mysql_num_rows($count); //считаем строки
     
    //выставляем цвет фона смс
    //////
    if($c%2==0)
    {
            $color=$blue;
    }
    else
    {
            $color=$white;
    }
    //считаем сообщений от контакта
    $result5=mysql_query("SELECT * FROM messages WHERE  author='$author' AND poluchatel='$login' "); 
    $result6=mysql_query("SELECT * FROM messages WHERE  author='$login' AND poluchatel='$author' ");
    $msg_count1=mysql_num_rows($result5);
    $msg_count2=mysql_num_rows($result6);
    $msg_count=$msg_count1+$msg_count2;
    if($new_msg>0)
    {
             printf("
       <table width='450' bgcolor='f4cf90' >
    <tr>
    <td style='border-bottom:1px solid black'> 
       <a href='page.php?id=%s'><img alt='аватар' width='20px' height='30px' src='%s'></a>
             <a href='my_messages_view.php?author=%s'><font color='0c50a5' style='font-size:17px;font-weight:bold;'>%s</font></a> 
        <font color=red style='font-size:17px;font-weight:bold'>(+%s)</font>
    </td>
     </tr>
    </table>
        ",$myrow4['id'],$avatar,$author,$author,$new_msg);
    }
    else
    {
             printf("
    <table width='450'  bgcolor='".$color."' >
    <tr>
    <td style='border-bottom:1px solid black'> 
      <a href='page.php?id=%s'><img alt='аватар' width='20px' height='30px' src='%s'></a>
      
      <a href='my_messages_view.php?author=%s'><font style='font-size:17px; font-weight:bold;' color='0c50a5'>%s</a></font>
      <font color='6b6b6b' style='font-size:17px; text-align: right; font-weight:bold;'>(%s)</font>
    </td>
     </tr>
    </table>
         ",$myrow4['id'],$avatar,$author,$author,$msg_count);
    	}
      }
      $c++;
      }
         while($messages = mysql_fetch_array($tmp));
            }

    qbasic, 11 Марта 2011

    Комментарии (4)
  11. 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)