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

    +165

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    /* Здесь мы имеем сраный унаследованный пиздец: количество товара передается в параметрах POST-запроса,
    	имеющих имена вида productX_count, где X - ИД товара. Как предыдущие разработчики разобирали это счастье?
    	Правильно, перебирали все (блядь, ВСЕ, блядь, 20000 штук!) товары и проверяли, есть ли соответствующее
    	значение в запросе.
    */
    
      $items5 = GetIBlockElementList(5);
      while($arItem = $items5->GetNext())
        if(isset($_POST['product'.$arItem['ID']."_id"]) && is_numeric($_POST['product'.$arItem['ID']."_id"]))
        {
          $_PRODUCTS[$arItem['ID']]['count'] = $_POST['product'.$arItem['ID']."_count"];
        }

    В этом коде меня утешает только боль и ненависть комментария.

    clauclauclau, 20 Января 2014

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

    +154

    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
    $this->load->model('localisation/country');
    $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
    
    if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
         $json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
    }
         
    if ($this->request->post['shipping_country_id'] == '') {
         $json['error']['shipping']['country'] = $this->language->get('error_country');
    }
                
    if ($this->request->post['shipping_zone_id'] == '') {
          $json['error']['shipping']['zone'] = $this->language->get('error_zone');
    }
                             
    $this->load->model('localisation/country');
    $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
                 
    if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
         $json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
    }

    строки 279 - 301
    файл catalog/controller/checkout/manual.php
    opencart 1.5.5.1.1

    Зачем два идентичных куска кода (1 - 6 и 16 - 21), в одном файле идущих друг за другом, я так и не понял.

    gnom_virtuoz, 17 Января 2014

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

    +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
    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
    $up = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".$x."_".($y-1)."_'"));
    $down = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".$x."_".($y+1)."_'"));
    $right = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x+1)."_".($y)."_'"));
    $left = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x-1)."_".($y)."_'"));
    $lup = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x-1)."_".($y-1)."_'"));
    $rup = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x+1)."_".($y-1)."_'"));
    $rdown = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x+1)."_".($y+1)."_'"));
    $ldown = mysql_fetch_array (mysql_query("SELECT name FROM locations WHERE id='p_".($x-1)."_".($y+1)."_'"));
    if (@$up["name"]) $up = 1; else $up=0;
    if (@$down["name"]) $down = 1;  else $down=0;
    if (@$right["name"]) $right = 1;  else $right=0;
    if (@$left["name"]) $left = 1; else $left=0;
    if (@$lup["name"]) $lup = 1; else $lup=0;
    if (@$rup["name"]) $rup = 1; else $rup=0;
    if (@$rdown["name"]) $rdown = 1;  else $rdown=0;
    if (@$ldown["name"]) $ldown = 1;  else $ldown=0;
    if ($_GET["go_nature"]=='up' and $up==1) $y-=1;
    if ($_GET["go_nature"]=='down' and $down==1) $y+=1;
    if ($_GET["go_nature"]=='left' and $left==1) $x-=1;
    if ($_GET["go_nature"]=='right' and $right==1) $x+=1;
    if ($_GET["go_nature"]=='lup' and $lup==1) $x-=1;
    if ($_GET["go_nature"]=='rup' and $rup==1) $x+=1;
    if ($_GET["go_nature"]=='lup' and $lup==1) $y-=1;
    if ($_GET["go_nature"]=='rup' and $rup==1) $y-=1;
    if ($_GET["go_nature"]=='rdown' and $rdown==1) $x+=1;
    if ($_GET["go_nature"]=='ldown' and $ldown==1) $x-=1;
    if ($_GET["go_nature"]=='rdown' and $rdown==1) $y+=1;
    if ($_GET["go_nature"]=='ldown' and $ldown==1) $y+=1;

    вксняшка

    SuperChel, 16 Января 2014

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

    +149

    1. 1
    2. 2
    3. 3
    array_unshift($available, $noSize);
    if (is_null($noSize))
        unset($available[0]);

    CRRaD, 15 Января 2014

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

    +153

    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
    switch ($order[0]['filials_link_type']) {
                    case 0:
                        $this->operator_model->send_partner_mail($order_id);
                        $status = $this->operator_model->send_partner_msg($order_id);
                        foreach ($status as $value) {
                            if (!($value)) {
                                echo "Один из партнеров не получил заказ";
                                break;
                            }
                        }
                        break;
                    case 1:
                        $this->operator_model->send_partner_mail($order_id);
                        $status = $this->operator_model->send_partner_msg($order_id);
                        foreach ($status as $value) {
                            if (!($value)) {
                                echo "Один из партнеров не получил заказ";
                                break;
                            }
                        }
                        break;
                    case 2:
                        $this->operator_model->send_partner_mail($order_id);
                        $status = $this->operator_model->send_partner_msg($order_id);
                        foreach ($status as $value) {
                            if (!($value)) {
                                echo "Один из партнеров не получил заказ";
                                break;
                            }
                        }
                        break;
                    case 3:
                        $this->operator_model->send_partner_mail($order_id);
                        $status = $this->operator_model->send_partner_msg($order_id);
                        foreach ($status as $value) {
                            if (!($value)) {
                                echo "Один из партнеров не получил заказ";
                                break;
                            }
                        }
                        break;
    ...
    ...
    }

    wtf?? O.o

    ragnar, 14 Января 2014

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

    +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
    19. 19
    20. 20
    21. 21
    static function anyToTimestamp($date) {
    		// 2009-09-03 12:10:55
    		if (preg_match('/^([0-9]{4})\-([0-9]{2})\-([0-9]{2})(?: ([0-9]{2})\:([0-9]{2})\:([0-9]{2}))?$/', $date, $arr)) {
    			$ts = mktime($arr[4], $arr[5], $arr[6], $arr[2], $arr[3], $arr[1]);
    		// 03.04.2008 10:12:11
    		} elseif (preg_match('/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})(?: ([0-9]{1,2})\:([0-9]{1,2})(?:\:([0-9]{2}))?)?$/', $date, $arr)) {
    			$ts = mktime($arr[4], $arr[5], $arr[6], $arr[2], $arr[1], $arr[3]);
    			// MySQL timestamp YYYYMMDDHHMISS
    		} elseif (preg_match('/^\d{14}$/', $date)) {
    			$ts = mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2), substr($string, 6, 2),
    				substr($string, 0, 4));
    			// PHP timestamp
    		} elseif (is_int($date)) {
    			$ts = $date;
    			// давно заметил, что предыдущее условие не всегда срабатывает. добавил условие ниже. если передается timestamp 100% сработает
    		}elseif(strlen((int)$date)>=10 && is_int((int)$date)) {
    			$ts = $date;
    		}
    
    		return ($ts && $ts!=-1)?$ts:null;
    	}

    Копаюсь как обычно в проекте, а этот довольно большой на протяжении нескольких лет над ним трудились разные программисты.
    Причем бывает читаю смешные комментарии.

    Однако весь смысл не в этом как вы уже поняли.

    oooZinka, 14 Января 2014

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

    +130

    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
    foreach($filenames as $fk => $fv) {
        if($noBootStrap) {
         $pos = strpos($fv->filename, 'bootstrap');
         if($pos === false) {} else {
          continue;
         }
        }
       ...
    
        if ($fv->menulink != '') {
          $menuLinks  = explode(',', $fv->menulink);
          $isIncluded = in_array((int)$itemid, $menuLinks);
          if ($isIncluded) {
            JHtml::stylesheet($path . $fv->filename );
          }
        } else {
         JHtml::stylesheet($path . $fv->filename );
        }
     }

    @copyright Copyright (C) Jan Pavelka www.phoca.cz
    Я плакал...

    virtual_cia, 12 Января 2014

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

    +153

    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
    $db = new Db();
                    $db->prepare('SELECT `ID`, `Title`, `Date`, `Active` FROM `videos` WHERE `UserID` = :userId AND `is_temporary` = 0 ORDER BY `Date` DESC')
                            ->bindInt(':userId', $userId)
                            ->execute();
                    $dbResult = $db->fetchAll();
                    if (empty($dbResult)) return array();
                    $orderDir = strtoupper($orderDir);
                    if (!in_array($orderDir, array('DESC', 'ASC'))) $orderDir = 'DESC';
                    if (empty($filter) && $orderDir == 'DESC') return ArrayHelper::extract($dbResult, 'ID', ArrayHelper::INT);
                    $db->prepare('CREATE TEMPORARY TABLE `videos_tmp` (
                                            `id` INT(11),
                                            `title` VARCHAR(256),
                                            `date` DATETIME,
                                            `active` VARCHAR(1)
                                    ) ENGINE = MEMORY
                                CHARACTER SET utf8
                                COLLATE utf8_general_ci')
                            ->execute();
                    foreach ($dbResult as $row) {
                            $db->prepare('INSERT INTO `videos_tmp` (`id`, `title`, `date`, `active`) VALUES (:id, :title, :date, :active)')
                                    ->bindInt(':id', $row['ID'])
                                    ->bindStr(':title', $row['Title'])
                                    ->bindStr(':date', $row['Date'])
                                    ->bindStr(':active', $row['Active'])
                                    ->execute();
                    }
                    $sql = 'SELECT `id` FROM `videos_tmp` WHERE 1';
                    if (isset($filter['active'])) $sql .= ' AND `Active` = :active';
                    if (isset($filter['search'])) $sql .= ' AND `title` LIKE :search';
                    if (isset($filter['fromDate'])) $sql .= ' AND `Date` >= :fromDate';
                    if (isset($filter['toDate'])) $sql .= ' AND `Date` <= :toDate';
                    $sql .= ' ORDER BY `Date` ' . $orderDir;
                    $stmt = $db->prepare($sql);
                    if (isset($filter['active'])) $stmt->bindStr(':active', $filter['active']);
                    if (isset($filter['search'])) $stmt->bindStr(':search', '%' . $filter['search'] . '%');
                    if (isset($filter['fromDate'])) $stmt->bindStr(':fromDate', $filter['fromDate']);
                    if (isset($filter['toDate'])) $stmt->bindStr(':toDate', $filter['toDate']);
                    $stmt->execute();
                    $dbResult = $db->fetchAll();
                    $db->prepare('DROP TABLE `videos_tmp`')->execute();

    Извиняюсь, что так много, но какого слоника надо было делать выборку, создавать временную таблицу и делать выборку снова - загадка.

    begmst, 10 Января 2014

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

    +148

    1. 1
    <link rel="stylesheet" href="css/css.css" type="text/css" />

    Ехал Гитлер через Гитлер,
    Гитлер Гитлер Гитлер Гитлер!

    cahbtexhuk, 10 Января 2014

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

    +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
    function t($text, $parameters = null) {
            $lang = empty($_COOKIE['lang']) ? 'ru' : $_COOKIE['lang'];
            $result = !array_key_exists($text, Application_Model_Translate::$lang_package) || ($lang == 'ru') ? $text :
                    Application_Model_Translate::$lang_package[$text][(int) ($lang == 'en')];
            if (isset($parameters)) {
                    if (!is_array($parameters))
                            $parameters = array($parameters);
                    foreach ($parameters as &$param)
                            $param = addslashes($param);
                    eval('$result = sprintf($result, "'. implode('","', $parameters) . '");');
            }
            return $result;
    }

    Groovy, 10 Января 2014

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