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

    +46

    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
    $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' => get_post_meta($post->ID, 'cd-conference-city', true),
    												      'conf_icon' => get_the_post_thumbnail()
    												      );
    		endwhile;
    
    		wp_reset_postdata();

    WordPress. Глубже, чем вы себе можете представить.

    varg242, 17 Сентября 2012

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

    +57

    1. 1
    if( $data['id_Account'] =! $this->user->Account )

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

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

    +74

    1. 1
    2. 2
    //переворачиваем массив с ног на голову, отрезаем голову, чтоб осталось 10 элементов и ставим все что осталось на ноги
    $_lasts = array_reverse(array_splice(array_reverse($last_view), 5));

    "казнь" массива

    Mihard, 17 Сентября 2012

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

    +43

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?php
    
    	function monthName($monthNumber) {
    
    		echo date('F', strtotime('first day of '.($monthNumber - date('n')).' month'));
    		
    	}
    	
    	monthName(10);
    	
    ?>

    Знаю, что не говнокод, но решил запостить - поделиться, ибо встречал тут много говнокода относительно подобного алгоритма получения названия месяца по порядковому номеру онного и много различных вариантов "неговнокода" в коментариях, но именно такой "пыхдатой" реализации не видел - впечатлило, хороший "антиВелосипед" :)

    killro0000, 15 Сентября 2012

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

    +41

    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
    function sqldate2time($date) {
        list($y, $m, $d) = explode('-', $date);
        $res = mktime(3,0,0,$m,$d,$y);
        return($res);
    }//function
     
    //Добавляем к дате указанное кол-во дней
    function add_days($date, $days = 1) {
        $t = sqldate2time($date);
        $t += (86400*$days);
     
        return(date('Y-m-d', $t));
    }//function

    Попытка на каком-то форуме, прибавить интервал времени (к примеру 7 дней)

    nepster, 14 Сентября 2012

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

    +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
    // что-то страшно мне стало
    class Mysql{
      private $db = null; 
      private $result = null; 
    //private $row = null;
     
     function __construct($dbname,$dbuser,$dbpass,$dbhost){
        $this->db = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
        mysql_select_db($dbname) or die ("<br>Invalid query: " . mysql_error());
        mysql_query("SET NAMES utf8") or die ("<br>Invalid query: " . mysql_error());
     }
     function connect(){
        if(!$this->db){
        exit("Error connect BD!");
        }
     }
    
     function query($query){
        if(!$query){exit("No [query]");}
    	$this->result = $query = mysql_query($query) or die ("<br>Invalid query: " . mysql_error());
    	return $query;
     } 
    }

    kuler, 13 Сентября 2012

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

    +53

    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
    <?if($arElement["PROPERTIES"]["POSTAV"]["VALUE_ENUM_ID"]==73){?>
    <?if($arElement["PREVIEW_PICTURE"]["HEIGHT"]<105){?><div width="115px" height="105px"><?}?>
    
      <a href="<?=$arElement["DETAIL_PICTURE"]["SRC"]?>" class="preview" onclick="return false;" onmousedown="window.location.href='<?=$arElement["DETAIL_PAGE_URL"]?>';"><img src="<?=$arElement["PREVIEW_PICTURE"]["SRC"]?>"  width="115" border="0px" alt="<?=$arElement["PREVIEW_PICTURE"]["ALT"]?>" title="<?=$arElement["NAME"]?>"/></a></div>
    <?if($arElement["PREVIEW_PICTURE"]["HEIGHT"]<105){?></div><?}?>
    <?}else{?>
        <a href="<?=$arElement["DETAIL_PICTURE"]["SRC"]?>" class="preview" onclick="return false;" onmousedown="window.location.href='<?=$arElement["DETAIL_PAGE_URL"]?>';"><img src="<?=$arElement["PREVIEW_PICTURE"]["SRC"]?>" width="115" height="105" border="0px" alt="<?=$arElement["PREVIEW_PICTURE"]["ALT"]?>" title="<?=$arElement["NAME"]?>"/></a>
    <?}?>
    	<br>&nbsp;
    					<?endif?></td>
                                              </tr>
                                            </table></td>
    									</tr>
    								</table>
    
                                    </div>
    		  </td>
    		<?$cell++;
    		if($cell%$arParams["LINE_ELEMENT_COUNT"] == 0):?>
    	</tr>
    		<?endif?>
    
    		<?endforeach; // foreach($arResult["ITEMS"] as $arElement):?>
    
    		<?if($cell%$arParams["LINE_ELEMENT_COUNT"] != 0):?>
    			<?while(($cell++)%$arParams["LINE_ELEMENT_COUNT"] != 0):?>
    
    			<?endwhile;?>
    			</tr>
    		<?endif?>
    
    </table></div>
     <?if($arParams["DISPLAY_BOTTOM_PAGER"]):?>
    	<br />
    	<?
    	$arResult["NAV_STRING"] = str_replace('|&nbsp;<a href="/e-store/rings/diamond.php?bitrix_include_areas=Y&amp;bitrix_show_mode=configure&amp;login=yes&amp;SHOWALL_1=1">Все</a>','',$arResult["NAV_STRING"]);
    	?>
    	<?=$arResult["NAV_STRING"]?>
    <?endif;?>

    randombot, 13 Сентября 2012

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

    +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
    <option <? if(isset($_POST['day']) and $_POST['day']=="01") echo "selected";  ?>   value="01">1</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="02") echo "selected";  ?>  value="02">2</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="03") echo "selected";  ?>  value="03">3</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="04") echo "selected";  ?>  value="04">4</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="05") echo "selected";  ?>  value="05">5</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="06") echo "selected";  ?>  value="06">6</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="07") echo "selected";  ?>  value="07">7</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="08") echo "selected";  ?>  value="08">8</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="09") echo "selected";  ?>  value="09">9</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="10") echo "selected";  ?>  value="10">10</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="11") echo "selected";  ?>  value="11">11</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="12") echo "selected";  ?>  value="12">12</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="13") echo "selected";  ?>  value="13">13</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="14") echo "selected";  ?>  value="14">14</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="15") echo "selected";  ?>  value="15">15</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="16") echo "selected";  ?>  value="16">16</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="17") echo "selected";  ?>  value="17">17</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="18") echo "selected";  ?>  value="18">18</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="19") echo "selected";  ?>  value="19">19</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="20") echo "selected";  ?> value="20">20</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="21") echo "selected";  ?> value="21">21</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="22") echo "selected";  ?>  value="22">22</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="23") echo "selected";  ?>  value="23">23</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="24") echo "selected";  ?>  value="24">24</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="25") echo "selected";  ?>  value="25">25</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="26") echo "selected";  ?>  value="26">26</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="27") echo "selected";  ?> value="27">27</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="28") echo "selected";  ?> value="28">28</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="29") echo "selected";  ?>  value="29">29</option>
                  <option <? if(isset($_POST['day']) and $_POST['day']=="30") echo "selected";  ?>  value="30">30</option>
                  <option  <? if(isset($_POST['day']) and $_POST['day']=="31") echo "selected";  ?> value="31">31</option>

    вЫводим дни в селекте )) А как ты выводишь дни в селекте? %)

    Diwms, 13 Сентября 2012

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

    +49

    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
    wordpress:
    function __( $text, $domain = 'default' ) {
    	        return translate( $text, $domain );
    }
    
    function translate( $text, $domain = 'default' ) {
    	        $translations = &get_translations_for_domain( $domain );
    	        return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
    }
    
    PHP-manual:
    PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality. 
    
    wordpress:
    /*
    * Don't use translate() directly, use __()
    */

    xcont, 12 Сентября 2012

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

    +51

    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
    class happy
    {
    
    public $today = 0;
    public $text = null;
    public function __construct($text)
    {
    if (!$text){
    exit('ничего не пришло!:(');
    }
    if ($text)
    {
    $this->text = $text;
    }
    }
    public function today()
    {
    $date = date('z');
    $this->today = $date;
    return $this->today;
    }
    
    public function echotext()
    {
    if (!$this->text)
    {
    echo 'нет текста!';
    }
    if ($this->text)
    {
    echo $this->text;
    }
    }
    
    }
    if (date('z') == 256)
    {
    $obj = new happy('С днём программиста!');
    if ($obj->today == 0)
    {
    $obj->today();
    }
    if ($obj->today == 256)
    {
    $obj->echotext();
    }
    }

    С праздником!

    kuler, 12 Сентября 2012

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