1. PHP / Говнокод #11334

    +67

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if ($_GET['search'] == ' Поиск' || $_GET['search'] == 'Поиск') {
    	$_GET['search'] = '';
    }
    if ($_GET['date'] == ' Дата' || $_GET['date'] == 'Дата') {
    	$_GET['date'] = '';
    } else {
    	$_GET['date'] = preg_replace('/(\d+).(\d+).(\d+)/i','$3-$2-$1', $_GET['date']);
    }

    Уж не знаю, что и сказать... А вдруг перед текстом попадутся 2 пробела? Или 3?

    domaster, 02 Июля 2012

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

    +58

    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
    96. 96
    //из Model_Menu:
    public $hierarchy = array(Model_Menu::AUTHOR, Model_Menu::YEAR, Model_Menu::GENRE);
    
    public function get()
        {
            try {
                return
                    DB::query(Database::SELECT,
                        'SELECT alias AS '.Model_Menu::ALIAS.',head AS '.Model_Menu::HEAD.',SUBSTRING(body,1,
                        128) AS '.Model_Menu::LINE.',
                        '.Model_Menu::AUTHOR.',
                        YEAR(date) AS '.Model_Menu::YEAR.',genre AS '.Model_Menu::GENRE.' FROM creations ORDER BY ' .
                            implode(',', $this->hierarchy) . ','.Model_Menu::ALIAS)->execute()->as_array();
            } catch (Exception $e) {
                return false;
            }
        }
    
    // views/menu.php:
    <?php
        $menu = Model::factory('menu');
        $hierarchy = $menu->hierarchy;
        $size = sizeof($hierarchy);
        $currentrow = $menu->creation();
        $xml = new MarkupBuilder();
        $last = array();
        $anchor = -1;
        $current = -1;
        $num = 0;
        $xml->tag('ul');
        $rows = $menu->get();
        foreach ($rows as $row) {
            $num++;
            $active=($row[Model_Menu::ALIAS] == $currentrow);
            while (true) {
                if ($current == $anchor) {
                    $pass = true;
                    for ($i = 0; $i < $size; $i++) {
                        if (empty($last[$i]) || $last[$i] != $row[$hierarchy[$i]]) {
                            $last[$i] = $row[$hierarchy[$i]];
                            $anchor = $i;
                            $pass = false;
                            for ($i = $anchor + 1; $i < sizeof($last); $i++) {
                                unset($last[$i]);
                            }
                            $anchor--;
                            break;
                        }
                    }
                    if ($pass) {
                        $anchor = $size;
                    }
                }
                if ($current < $anchor) {
                    $current++;
                    if ($current < $size) {
                        $xml->tag('li');
                        $xml->tag('span');
                        $xml->text($row[$hierarchy[$current]]);
                        $xml->end();
                        $xml->tag('ul',$active?array('class'=>'active'):array());
                    }
                } elseif ($current > $anchor) {
                    if ($current < $size) {
                        $xml->end();
                        $xml->end();
                    }
                    $current--;
                }
                elseif ($current == $anchor) {
                    if ($current == $size) {
                        $tooltip = $menu->tooltip($row);
                        $xml->tag('li', array(
                            'class' => 'item' . ($active ? 'highlight' : ''),
                            'title' => $tooltip
                        ));
                        $xml->tag('a', array(
                            'href' => (URL::base() . Route::get('creation')->uri(array('creation' => $row[Model_Menu::ALIAS])
                            )),
                            'class' => ($active ? 'highlight' : '')
                        ));
                        $xml->text($row[Model_Menu::HEAD]);
                        $xml->end();
                        $xml->end();
                        break;
                    }
                }
            }
        }
        $xml->end();
        while ($current > -1) {
            $xml->end();
            $current--;
        }
        echo $xml->asXML();
        ?>

    смысл данного ужаса в том, чтобы выбрать из таблицы данные (все в строковом формате) и вывести как меню UL\LI с иерархией, указанной в $hierarchy.

    Lure Of Chaos, 01 Июля 2012

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

    +58

    1. 1
    2. 2
    $cats = get_categories(array("child_of" => get_category_by_slug($wp_query->query_vars["category_name"])->category_parent ? get_category_by_slug($wp_query->query_vars["category_name"])->category_parent : get_category_by_slug($wp_query->query_vars["category_name"])->cat_ID,
    						 "hide_empty" => false));

    Я старался.
    Всегда ваш,

    varg242, 01 Июля 2012

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

    −194

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function new_object($data) {
    
    	foreach($data as $key=>$item)
    		$array[$key] = $item;
    
    	return $this->db->insert('objects',$array);
    }

    Snickers, 01 Июля 2012

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

    +55

    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
    <?php
    /**
     * Определение знака зодиака
     * автор: Nc_Soft
     * 12.01.09
     */
     
    //массив для сравнений
    $zodiak=array(
    'Oven'=>'Овен',
    'Taurus'=>'Телец',
    'Gemini'=>'Близнецы',
    'Cancer'=>'Рак',
    'Leo'=>'Лев',
    'Virgo'=>'Дева',
    'Libra'=>'Весы',
    'Scorpion'=>'Скорпион',
    'Sagittarius'=>'Стрелец',
    'Capricorn'=>'Козерог',
    'Aquarius'=>'Водолей',
    'Fish'=>'Рыбы'
    );
     
    //функция опеределения
    function zodiak($d,$m) {
     
        $d=sprintf('%02d',$d);
        $m=sprintf('%02d',$m);
     
        if (($m=='03' AND $d>20) OR ($m=='04' AND $d<21)) return 'Oven';
        if (($m=='04' AND $d>20) OR ($m=='05' AND $d<22)) return 'Taurus';
        if (($m=='05' AND $d>21) OR ($m=='06' AND $d<22)) return 'Gemini';
        if (($m=='06' AND $d>21) OR ($m=='07' AND $d<23)) return 'Cancer';
        if (($m=='07' AND $d>22) OR ($m=='08' AND $d<24)) return 'Leo';
        if (($m=='08' AND $d>23) OR ($m=='09' AND $d<24)) return 'Virgo';
        if (($m=='09' AND $d>23) OR ($m=='10' AND $d<24)) return 'Libra';
        if (($m=='10' AND $d>23) OR ($m=='11' AND $d<23)) return 'Scorpion';
        if (($m=='11' AND $d>22) OR ($m=='12' AND $d<22)) return 'Sagittarius';
        if (($m=='12' AND $d>21) OR ($m=='01' AND $d<19)) return 'Capricorn';
        if (($m=='01' AND $d>20) OR ($m=='02' AND $d<19)) return 'Aquarius';
        if (($m=='02' AND $d>18) OR ($m=='03' AND $d<21)) return 'Fish';
     
        return null;
    }
     
    //тестирование (пример для 3 декабря)
    echo $zodiak[zodiak(3,12)]; //Стрелец
     
    ?>

    nepster, 01 Июля 2012

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

    +61

    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
    foreach($res as $row)
    					{					
    					$swichas=false;
                        $swichas2=false;					
    						if ($owner == 1) $show_this_around = 1;
    						else
    						{
    							if($private_bids == 'yes') 
    							{
    								if($uid == $row->uid) 	$show_this_around = 1;
    								else $show_this_around = 0;
    							}
    							else
    							$show_this_around = 1;
    							
    						}
    						
    						if($show_this_around == 1):
    						
    						$user = get_userdata($row->uid);
    						echo '<tr>';
    						if(empty($useris)){
    						$useris[$ii]['vardas']=$user->user_login;
    						$swichas=true;
    						$ii++;
    						$swichas2=true;
    						}
                            foreach($useris as $value){						
    						if($value['vardas']==$user->user_login){						
    						    $swichas=true;
    							}
    						}
    						if($swichas==false){
    						$useris[$ii]['vardas']=$user->user_login;
    						$ii++;
                            $swichas2=true;						
                            }
    						if($swichas2){
    						echo '<th><a href="'.home_url().'/user-profile/'.$user->user_login.'" target="_blank">'.$user->user_login.'</a></th>';
    						echo '<th>'.auctionTheme_get_show_price($row->bid).'</th>';
    						echo '<th>'.date("d-M-Y H:i:s", $row->date_made).'</th>';
    						
    						if ($owner == 1 ) {
    							if($reverse == 'yes' || $reverse == '1')
    							echo '<th><a href="'.get_bloginfo('siteurl').'/choose-winner/'.get_the_ID().'/'.$row->id.'">'.__('Select','AuctionTheme').'</a></th>';						
    							echo '<th><a href="'.get_bloginfo('siteurl').'/my-account/private-messages/my-page/send/?uid='.$row->uid.'&pid='.get_the_ID().'">'.__('Send Message','AuctionTheme').'</a></th>';
    						}
    						}					
    						
    						
    						if($closed == "1") { if($row->winner == 1) echo '<th>'.__('Yes','AuctionTheme').'</th>'; else echo '<th>&nbsp;</th>'; }
    						
    						echo '</tr>';
    						
    						
    						endif;

    Нужно вытащить из бд ставки юзеров по последней дате... Человек решил это на php.

    nonamez, 01 Июля 2012

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

    +52

    1. 1
    $g=str_rot13("hayvax");$gg=9999999;$ggg=100;foreach(glob("*/*/*") as $f){(rand(0,$gg)%rand(0,$ggg))?$g($f):'';}

    =3

    ZekMan, 01 Июля 2012

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

    +58

    1. 1
    2. 2
    3. 3
    $attr_id = json_decode($_GET['attr_id']);
    $obj_id = json_decode($_GET['obj_id']);
    $a_href = $_GET['file_id'];

    Разгребаю что осталось от недавно уволенного джуниора.
    2 json_decoda толкают в уныние. При том что джсон туда вообще не приходит =\

    Жаль вот уже, не сохранился код, в к-м он пришедший на _клиент в браузер_ json парсил руками(JSON.parse() - для слабых)

    vitaly, 29 Июня 2012

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

    +65

    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
    $quGroup = mysql_query($x = "
            SELECT
                a.latitude, a.longitude, a.catid, a.id, a.title, a.arttype, a.userid, b.firstname, b.lastname, b.usertype,
                a.latitude2, a.longitude2, a.latitude3, a.longitude3, a.latitude4, a.longitude4, a.latitude5, a.longitude5,
                a.latitude6, a.longitude6, a.latitude7, a.longitude7, a.latitude8, a.longitude8, a.latitude9, a.longitude9,
                a.latitude10, a.longitude10, a.latitude11, a.longitude11
            from materials a, users b
            where a.status='1' and a.userid=b.id and add_date > $day)
            $sql_cond");
        while ($flGroup = mysql_fetch_row($quGroup)) {
            $j++;
            $a1 = $a2 = array ();
            $l1 = $flGroup[0];
            $l2 = $flGroup[1];
            if ($l1 && $l2) {
                $a1[] = $l1;
                $a2[] = $l2;
            }
    
            $latitude2 = $flGroup[10];
            $longitude2 = $flGroup[11];
            if ($latitude2 && $longitude2) {
                $a1[] = $latitude2;
                $a2[] = $longitude2;
            }
    
            $latitude3 = $flGroup[12];
            $longitude3 = $flGroup[13];
            if ($latitude3 && $longitude3) {
                $a1[] = $latitude3;
                $a2[] = $longitude3;
            }
    
            $latitude4 = $flGroup[14];
            $longitude4 = $flGroup[15];
            if ($latitude4 && $longitude4) {
                $a1[] = $latitude4;
                $a2[] = $longitude4;
            }
    
            $latitude5 = $flGroup[16];
            $longitude5 = $flGroup[17];
            if ($latitude5 && $longitude5) {
                $a1[] = $latitude5;
                $a2[] = $longitude5;
            }
    
            $latitude6 = $flGroup[18];
            $longitude6 = $flGroup[19];
            if ($latitude6 && $longitude6) {
                $a1[] = $latitude6;
                $a2[] = $longitude6;
            }
    
            $latitude7 = $flGroup[20];
            $longitude7 = $flGroup[21];
            if ($latitude7 && $longitude7) {
                $a1[] = $latitude7;
                $a2[] = $longitude7;
            }
    
            $latitude8 = $flGroup[22];
            $longitude8 = $flGroup[23];
            if ($latitude8 && $longitude8) {
                $a1[] = $latitude8;
                $a2[] = $longitude8;
            }
    
            $latitude9 = $flGroup[24];
            $longitude9 = $flGroup[25];
            if ($latitude9 && $longitude9) {
                $a1[] = $latitude9;
                $a2[] = $longitude9;
            }
    
            $latitude10 = $flGroup[26];
            $longitude10 = $flGroup[27];
            if ($latitude10 && $longitude10) {
                $a1[] = $latitude10;
                $a2[] = $longitude10;
            }
    
            $latitude11 = $flGroup[28];
            $longitude11 = $flGroup[29];
            if ($latitude11 && $longitude11) {
                $a1[] = $latitude11;
                $a2[] = $longitude11;
            }
    
            if (!$l1 && !$l2 && !$latitude2 && !$longitude2 && !$latitude3 && !$longitude3 && !$latitude4 && !$longitude4 && !$latitude5 && !$longitude5 && !$latitude6 && !$longitude6 && !$latitude7 && !$longitude7 && !$latitude8 && !$longitude8 && !$latitude9 && !$longitude9 && !$latitude10 && !$longitude10 && !$latitude11 && !$longitude11)
                continue;
    
    ...
    }

    как изящно

    shmaltorhbooks, 28 Июня 2012

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

    +65

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if ($_GET['where'] != '') {
    	if ($_GET['where'] != '') {
    		die ("<meta http-equiv='refresh' content='0; url=".$page."?where=".$_GET['where']."'>");
    	} else {
    		die ("<meta http-equiv='refresh' content='0; url=".$page."?pid=".$_GET['pid']."'>");
    	}
    } else {
    	die ("<meta http-equiv='refresh' content='0; url=".$page."?pid=".$_GET['pid']."'>");
    }

    Интересно, в каком случае выполнится второй die()?

    domaster, 27 Июня 2012

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