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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    /* Convert IP address to unsigned long int. */
    function ip2ulong($ip) {
        return sprintf("%u", ip2long32($ip));
    }

    https://github.com/pfsense/pfsense/blob/master/etc/inc/util.inc#L414-L417

    Продолжаем осторожно идти дальше. Это нормально вообще? Да, я видел всякие смехуёчки с магическим приведением типов в PHP и JS, так что наверняка оно где-то правильно конвертится и все работает несмотря ни на что и вопреки. Может, это даже нормальная практика в мире PHP, но мне страшно.

    superhacker777, 17 Мая 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($ipaddr == $ip_reverse) {
        return true;
    } else {
        return false;
    }

    https://github.com/pfsense/pfsense/blob/master/etc/inc/util.inc#L625-L629

    Давно хотел спросить: это как-нибудь здравым смыслом оправдывается? Часто встречаю похожее, когда чужой код смотрю. Может, это профи делают для… читаемости какой-то, я не знаю. Или я ищу хорошее там, где его нет?

    superhacker777, 17 Мая 2015

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

    +143

    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
    if (is_array($search_ct_properties->getEngines()))
    		{
    			$where_engines = array();
    			foreach ($search_ct_properties->getEngines() as $engine)
    			{
    				if ($engine == 5)
    				{
    					$where_engines[] = 'ct_modifications.fuel_id != 6';
    				}
    				else
    				{
    					$where_engines[] = 'ct_modifications.fuel_id = 6';
    				}
    			}
    			$where[] = '(' . implode(' OR ', $where_engines) . ')';
    		}

    если 5, то это точно не 6!

    smail01, 16 Мая 2015

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

    +141

    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
    $page = strtoupper($_SERVER['REQUEST_URI']);
        if (strpos($page, "%D0%A2%D0%BE%D0%BF10")){
          echo "<li class=\"active\"><a  href=\"/%D0%A2%D0%BE%D0%BF10\">Топ-10</a></li>";
        } else {
          echo "<li><a href=\"/%D0%A2%D0%BE%D0%BF10\">Топ-10</a></li>";
        }
        if (strpos($page, "%D0%A2%D1%80%D0%B0%D1%84%D0%B8%D0%BA")){
          echo "<li class=\"active\"><a  href=\"/%D0%A2%D1%80%D0%B0%D1%84%D0%B8%D0%BA\">Трафик</a></li>";
        } else {
          echo "<li><a href=\"/%D0%A2%D1%80%D0%B0%D1%84%D0%B8%D0%BA\">Трафик</a></li>";
        } 
        if (strpos($page, "%D0%9B%D0%B8%D0%B4%D0%B5%D1%80")) {
          echo "<li class=\"active\"><a  href=\"/%D0%9B%D0%B8%D0%B4%D0%B5%D1%80\">Лидер</a></li>";
        } else {
          echo "<li><a href=\"/%D0%9B%D0%B8%D0%B4%D0%B5%D1%80\">Лидер</a></li>";
        }

    ...а кроме того, в данном случае strtoupper бесполезен

    olvin, 15 Мая 2015

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

    +145

    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
    <?
    for ($i = 1; $i <= 100; $i++) {
        $t1 = $i / 3;
        $t2 = $i / 5;
        if (preg_match("/\./", "$t1") == false && preg_match("/\./", "$t2") == false) {
            echo "FizzBuzz<br>";
        } else {
            if (preg_match("/\./", "$t1") == false) {
                echo "Fizz<br>";
            } else {
                if (preg_match("/\./", "$t2") == false) {
                    echo "Buzz<br>";
                } else {
                    echo "$i<br>";
                }
            }
        }
    }
    ?>

    ZF...

    Yshk, 15 Мая 2015

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $phsms = '';
    
    for($p=0;$p<strlen($phonesms);$p++)
        if(intval($phonesms[$p]) >= 0) $phsms = $phsms.intval($phonesms[$p]);
    
    preg_match('/.*(9[0-9]{2})([0-9]{7})/', $phsms, $match2);
    
    $phsms = $match2[1].$match2[2];

    Валидируем телефоны.

    aego09, 15 Мая 2015

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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function buildUpdateTimestampTrigger($tableName) {
    		return 
    			sprintf(
    				file_get_contents(SQL_FILES_PATH . 'updateTimestamp_PlPg.sql'),
    				strtolower($tableName) . '_updated'
    			) .
    			sprintf(
    				file_get_contents(SQL_FILES_PATH . 'updateTimestampTrigger.sql'),
    				$tableName
    			);
    	}

    artembegood, 14 Мая 2015

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

    +144

    1. 1
    $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];

    https://github.com/uisky/notabenoid/blob/6edfee9f33b8466be9164cd3ba6be90b8f3a5770/protected/controllers/MyCommentsController.php#L123

    Stallman, 14 Мая 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?php
    class ModelCheckoutOrder extends Model {
    	public function addOrder($data) {
    		$this->event->trigger('pre.order.add', $data);
    		$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? serialize($data['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_custom_field = '" . $this->db->escape(isset($data['payment_custom_field']) ? serialize($data['payment_custom_field']) : '') . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_custom_field = '" . $this->db->escape(isset($data['shipping_custom_field']) ? serialize($data['shipping_custom_field']) : '') . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', marketing_id = '" . (int)$data['marketing_id'] . "', tracking = '" . $this->db->escape($data['tracking']) . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" .  $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "', date_added = NOW(), date_modified = NOW()");

    Я вас еще немного помучаю, хорошо?
    3978 символов, считая отступы

    https://github.com/opencart/opencart/blob/d5f66b0d75a5adf35815e333e45598bbc38750d0/upload/catalog/model/checkout/order.php#L6

    Fike, 14 Мая 2015

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(isset($_GET['go']))
    	$go = htmlspecialchars(strip_tags(stripslashes(trim(urldecode(mysql_escape_string($_GET['go']))))));
    else
    	$go = "main";
    
    // ....
    
    switch($go){

    "Тыыыыыыы не пройдеееешь!". Зафильтровали (да ещё и криво) бедную переменную только для того, чтобы потом использовать её в switch-case блоке. Индусы-паникеры.

    bSun0000, 13 Мая 2015

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