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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $adres = $_SERVER["REQUEST_URI"];
    
    if (strpos($adres, "?"))
    {
    	$adres = substr( $adres, strpos($adres, "?") + 1 ) ;
    	$T = explode('?', $adres) ;
    	$id = $T[0];
    	$count_product = $T[1];
    }

    Добавление товара в корзину на одном из интернет-магазинов через AJAX.
    После нажатия кнопки "В корзину" происходит запрос /js/ajax-basket.php?1966?2
    где "1966" - id товара, а "2" - количество
    Собственно код выше - это обработка данного запроса

    0day, 15 Июля 2014

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $data = "<?php define('DSN', 'mysql:dbname={$_POST['db_name']};host={$_POST['host_mysql']}'); define('DBUSER', '{$_POST['login_mysql']}'); define('DBPASS', '{$_POST['password_mysql']}');";
    $mysql_string = file_get_contents( 'class/mysql.php' );
    $new_mysql = $data . ' ' . $mysql_string;
    if ( !file_put_contents( 'class/mysql.php', $new_mysql ) ) {
    	errorMessage( "Не удалось сохранить файлы конфигураций, пожалуйста обратитесь в службу технической поддержки клиентов" );
    }

    install.php

    kindofbear, 15 Июля 2014

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

    +157

    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
    <?php
    
    class ListWidget extends Widget
    {
    	public $itemsPerPage = 10;
    	private static $allowedItemsPerPage = array(10);
    	// ...
    
    	private function getTotalPages()
    	{
    		$this->itemsPerPage = in_array($this->itemsPerPage, self::$allowedItemsPerPage) ? $this->itemsPerPage : 10;
    		// ...
    	}
    }

    Надежная проверка.

    ftr, 14 Июля 2014

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

    +150

    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
    function email($from, $to, $subject, $message)
    {
    	$ci =& get_instance();
    	
    	$config['mailtype'] = 'html';
    	$ci->load->library('email', $config);
    
    	$ci->email->clear();
    	$ci->email->from($from);
    	$ci->email->to($to);  
    	$ci->email->subject($subject);
    	$ci->email->message($message); 
    	$ci->email->send();
    }

    iweb, 12 Июля 2014

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

    +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
    <?endif?></ul><?endif;?><?endif;?><ul id="gnb-section-help" class="gnb-menu"><?if(isset($group['HelpGroup'])):?>
            <?for($i=0;$i<count($group['HelpGroup']);$i++):?>
            <?$groupItem = $group['HelpGroup'][$i]?>
            <?if(!$groupItem->IsItemList):?>
            <li><a target="_blank" href="<?=$groupItem->Href?>"><?=$groupItem->Content?></a></li>
            <?else:?>
            <li class="gnb-dropdown">
              <a href="#" class="btn gnb-dropdown-toggle-link">
                <?if(isset($groupItem->Content) && $groupItem->Content != ""):?><span class="gnb-dropdown-toggle-text"><?=$groupItem->Content?></span><?endif?></a><a href="#" class="btn gnb-dropdown-toggle"><i>▾</i></a>
              <ul class="gnb-dropdown-menu">
                <?if(isset($groupItem->ItemList)):?>
                <?for($i=0;$i<count($groupItem->ItemList->Item);$i++):?>
                <?$subItem = $groupItem->ItemList->Item[$i]?>
                <li><a target="_blank" href="<?=$subItem->Href?>"><?=$subItem->Content?></a></li>
                <?endfor?>
                <?endif?>
              </ul>
            </li>
            <?endif?>
            <?endfor?>
            <?endif?>
          </ul>

    Встретил в одном из проектов.
    Долго думал к какому языку отнести это дело, решил, что всё же PHP.

    Не пишите так никогда, это как минимум, нечитаемо.

    johny, 11 Июля 2014

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

    +157

    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
    $pogoda = file_get_contents('http://export.yandex.ru/weather/');
        preg_match('/<weather_type>(.*?)<\/weather_type>/i',$pogoda,$type);
        preg_match('/<dampness>(.*?)<\/dampness>/i',$pogoda,$vlaga);
        preg_match('/<temperature>(.*?)<\/temperature>/i',$pogoda,$temp);
        preg_match('/<image2>(.*?)<\/image2>/i',$pogoda,$img2);
        preg_match('/<pressure>(.*?)<\/pressure>/i',$pogoda,$press);
        $imgp = substr($img2[1], 24);
    
    $vivod = "<img align=\"top\" src=\"//img.yandex.net$imgp\" alt=\"$type[1]\" />$temp[1] °C
        $type[1]<br />
        Влажность: $vlaga[1] %<br />
        Давление: $press[1] мм рт.ст.";
        echo $vivod;

    Парсинг XML от Яндекс-погоды. Только хардкор!

    huitator, 10 Июля 2014

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

    +156

    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
    while ($this->tariffs_model->getCarsCheckedByTariff($user_id, $tariff_info[0]['id']) > $tariff_info[0]['cars_count'])
    {
    	$cars = $this->tariffs_model->getCarsChecked($tariff_info[0]['id'], $user_id);
    	if ($cars)
    	{
    		//удаляем одну объяву
    		$this->tariffs_model->delCarChecked($cars[0]);
    		$this->sms_model->removeSmsByCarId($cars[0]);
    	}
    }
    
    /*-=-=-=-=-=-=-=-=-=-=-=-=- реализация ф-ций -=-=-=-=-=-=-=-=-=-=-=-=-*/
    
    /**
     * Получаем кол-во реально отмеченых объявлений
     * @param int $user_id
     * @param int $tariff_id
     */
    function getCarsCheckedByTariff($user_id, $tariff_id)
    {
    	$query = "SELECT COUNT(*) as count FROM tariffs_cars_checked WHERE car_id IN
    		(SELECT id FROM a2_cars WHERE user = ? AND expire_date >= ?) AND tariff_id = ?";
    	$result = $this->db->query($query, array($user_id, MYSQL_CURDATE, $tariff_id));
    
    	//echo $this->db->last_query();
    
    	if ($result && $result->num_rows() == 1)
    	{
    		return $result->row()->count;
    	}
    	else
    	{
    		return null;
    	}
    }
    
    /**
     * Список ID отмеченных объявлений по тарифу пользователя
     *
     * @param Int $tariff_id
     * @return Array[]
     * @author КОЕ-КТО 21.12.2009 12:35
     * @uses Controller::Profile
     */
    function getCarsChecked($tariff_id, $user_id)
    {
    	$this->db->select('tariffs_cars_checked.car_id')->from('tariffs_cars_checked')
    	->join('a2_cars', 'a2_cars.id = tariffs_cars_checked.car_id', 'inner')
    	->where(array('tariffs_cars_checked.tariff_id' => intval($tariff_id), 'a2_cars.user' => intval($user_id)));
    
    	$result = $this->db->get();
    	if ($result && $result->num_rows() > 0)
    	{
    		$cars = array();
    		foreach ($result->result_array() as $row)
    		{
    			$cars[] = $row['car_id'];
    		}
    		return $cars;
    	}
    	else
    	{
    		return null;
    	}
    }

    Удаляем объявления скопом!

    smail01, 10 Июля 2014

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

    +156

    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
    <?
    $res = CIBlockSection::GetList(array(), array('IBLOCK_ID'=>'3', 'ACTIVE'=>'Y'));
    $res1 = CIBlockSection::GetList(array(), array('IBLOCK_ID'=>'3', 'ACTIVE'=>'Y'));
    ?>
    <table class="tableObjects">
        <tr>
            <?while($v = $res->GetNext()){
                ?><td><a href="/projects/list.php?SECTION_ID=<?=$v['ID']?>">
                    <?=CFile::ShowImage(CFile::GetPath($v['PICTURE']), 180, 160)?>
                </a></td><?
            }?>
        </tr>
        <tr>
            <?while($v = $res1->GetNext()){
                ?><td><b><a href="/projects/list.php?SECTION_ID=<?=$v['ID']?>"><?=$v['NAME']?></a></b></td><?
            }?>
        </tr>
    </table>

    Как минимум 2 раза обращаться к базе данных, чтобы разбить данные на 2 строки! Гениально!

    dimagyzeev, 09 Июля 2014

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function wait($time)
    {
        $tmp_time = time();
        $i = $tmp_time;
        $time = $tmp_time + $time;
        while ($i < $time)
        {
            If (time() != $i) { $i++; }
        }
    }

    Автор сего творения явно не подозревал о существовании функции sleep

    phpcoder, 07 Июля 2014

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

    +166

    1. 1
    2. 2
    3. 3
    function array_min_recursive($arr, &$peaks = array(), $current_key = '') {
      return array_max_recursive($arr, $peaks, $current_key, true); // Неожиданно, правда?
    }

    DIX315, 05 Июля 2014

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