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

    0

    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
    while($art = $obSection->GetNext()){
      
       for($k=0;$k<=($art['DEPTH_LEVEL']-2);$k++)
      //  echo "..";
      //  echo "<h4>Дома серии ".$arGor." в городе ";
      //  echo $art['NAME'].'</h4>';
    	
    		$i = 1;
    		
    		foreach($arResult["HOMES"] as $arHome)
    		{
    			
    			if($art["ID"]==$arHome["IBLOCK_SECTION_ID"]){
    				
    			if($dec=="" || $dec!=$art['NAME']){
    					echo "<h4>Дома серии ".$arGor." в городе ";
    					echo $art['NAME'].'</h4>';
    					 echo "<div class=\"korp\">";
    				$dec = $art['NAME'];
    				}
               				
    			echo '<a href="'.$arHome["DETAIL_PAGE_URL"].'">'.$arHome["PROPERTY_KORPUS_VALUE"].'</a>';
    			
    			if(count($arResult["HOMES"])>$i)
    			{
    				echo "<div class=\"last\">, </div>";
    			}
    			$i++;
    		  }
    		}
    		
    		echo "</div><br>"; 
    	
    }

    Глубокомысленный цикл for

    ZENKOT, 23 Сентября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    if (preg_match('/'.preg_quote($subString).'/', $string)) {
        ...
    }

    Проверка, есть ли подстрока в строке.
    Вроде, как минимум несколько лет человек в программировании на PHP.
    Показывает опытность тем, что экранирует спецсимволы в регулярном выражении.
    А можно было использовать простейшую функцию strpos().

    zlsoft, 22 Сентября 2017

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

    +4

    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
    // ...
    if (isset($_GET["download"])) {
    	include "./download.inc.php";
    } elseif (isset($_GET["table"])) {
    	include "./table.inc.php";
    } elseif (isset($_GET["schema"])) {
    	include "./schema.inc.php";
    } elseif (isset($_GET["dump"])) {
    	include "./dump.inc.php";
    } elseif (isset($_GET["privileges"])) {
    	include "./privileges.inc.php";
    } elseif (isset($_GET["sql"])) {
    	include "./sql.inc.php";
    } elseif (isset($_GET["edit"])) {
    	include "./edit.inc.php";
    } elseif (isset($_GET["create"])) {
    	include "./create.inc.php";
    } elseif (isset($_GET["indexes"])) {
    	include "./indexes.inc.php";
    } elseif (isset($_GET["database"])) {
    	include "./database.inc.php";
    } elseif (isset($_GET["scheme"])) {
    	include "./scheme.inc.php";
    } elseif (isset($_GET["call"])) {
    	include "./call.inc.php";
    } elseif (isset($_GET["foreign"])) {
    	include "./foreign.inc.php";
    } elseif (isset($_GET["view"])) {
    	include "./view.inc.php";
    } elseif (isset($_GET["event"])) {
    	include "./event.inc.php";
    } elseif (isset($_GET["procedure"])) {
    	include "./procedure.inc.php";
    } elseif (isset($_GET["sequence"])) {
    	include "./sequence.inc.php";
    } elseif (isset($_GET["type"])) {
    	include "./type.inc.php";
    } elseif (isset($_GET["trigger"])) {
    	include "./trigger.inc.php";
    } elseif (isset($_GET["user"])) {
    	include "./user.inc.php";
    } elseif (isset($_GET["processlist"])) {
    	include "./processlist.inc.php";
    } elseif (isset($_GET["select"])) {
    	include "./select.inc.php";
    } elseif (isset($_GET["variables"])) {
    	include "./variables.inc.php";
    } elseif (isset($_GET["script"])) {
    	include "./script.inc.php";
    } else {
    	include "./db.inc.php";
    }
    // ...

    https://github.com/vrana/adminer/blob/master/adminer/index.php
    p.s хотя сама штука полезная, пару раз выручала

    alex228, 22 Сентября 2017

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

    0

    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
    if ($session_data['iam']) {
                    $newparam = $param = " AND member_gender = '" . $session_data['iam'] . "' ";
                }
    
                if ($session_data['add_title_new']) {
                    $newparam = $param = " AND member_name like '%" . $session_data['add_title_new'] . "%' ";
                }
    
                if ($session_data['i_am']) {
                    $param = " AND member_gender = '" . $session_data['i_am'] . "' ";
                }
    
                if ($session_data['looking']) {
                    $newparam .= $param .= " AND member_looking_for = '" . $session_data['looking'] . "' ";
                }
    
                if ($session_data['agefrom'] != '0' && $session_data['agefrom'] != '') {
                    $param .= " AND partner_age_range_from = '" . $session_data['agefrom'] . "' ";
                }

    Ладно, зачем-то присваивание сразу двух переменных, которые названы совершенно невнятно. Но что делает .= $param .= я вообще боюсь представить (и честно говоря лень проверять)

    gorsash, 11 Сентября 2017

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

    −2

    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
    public static function GenerateMenu()
        {
            $item = [];
            $section = self::find()->all();
            $count_section = 0;
    
            foreach ($section as $model_section) {
                $item[] = ['label' => $model_section->name, 'url' => '#'];
                $category = \common\models\Category::find()->where(['id_section' => $model_section->id])->all();
                $count_category = 0;
                foreach ($category as $model_category) {
                    $item[$count_section]['items'][$count_category] = ['label' => $model_category->name, 'url' => '#'];
                    $subcategory = \common\models\Subcategory::find()->where(['id_category' => $model_category->id])->all();
                    $count_subcategory = 0;
                    foreach ($subcategory as $model2) {
                        $item[$count_section]['items'][$count_category]['items'][$count_subcategory] = ['label' => $model2->name, 'url' => '#'];
                        $count_subcategory++;
                    }
                    $count_category++;
                }
                $count_section++;
            }
    
            return $item;
        }

    Феерическое решение для вывода tree из трех категорий.

    qstd, 09 Сентября 2017

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

    −2

    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
    public static function getItemGrid($settings, $site_width, $columns) {
            $products_per_row_xs = Journal2Utils::getProperty($settings, 'mobile.value', 1);
            $products_per_row_sm = Journal2Utils::getProperty($settings, 'mobile1.value', 2);
            if ($columns == 1) {
                $products_per_row_md = Journal2Utils::getProperty($settings, 'tablet1.value', 2);
            } else if ($columns == 2) {
                $products_per_row_md = Journal2Utils::getProperty($settings, 'tablet2.value', 1);
            } else {
                $products_per_row_md = Journal2Utils::getProperty($settings, 'tablet.value', 3);
            }
            if ($columns == 1) {
                $products_per_row_lg = Journal2Utils::getProperty($settings, 'desktop1.value', 4);
            } else if ($columns == 2) {
                $products_per_row_lg = Journal2Utils::getProperty($settings, 'desktop2.value', 3);
            } else {
                $products_per_row_lg = Journal2Utils::getProperty($settings, 'desktop.value', 5);
            }
            if ($columns == 1) {
                $products_per_row_xl = Journal2Utils::getProperty($settings, 'large_desktop1.value', 4);
            } else if ($columns == 2) {
                $products_per_row_xl = Journal2Utils::getProperty($settings, 'large_desktop2.value', 3);
            } else {
                $products_per_row_xl = Journal2Utils::getProperty($settings, 'large_desktop.value', 5);
            }
            return array(
                'xs'    => $products_per_row_xs,
                'sm'    => $products_per_row_sm,
                'md'    => $products_per_row_md,
                'lg'    => $products_per_row_lg,
                'xl'    => $site_width > 1200 ? $products_per_row_xl : $products_per_row_lg
            );
        }

    Метод из шаблона Journal в opencart

    den_rad, 06 Сентября 2017

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

    +1

    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
    $parent = (new \yii\db\Query())
    ->select(['parent','parent_1','parent_2'])
    ->from('user')
    ->where(['id' => "$user_id",])
    ->all();
    
    $sum_for_parent = (new \yii\db\Query())
    ->select(['first_parent'])
    ->from('referal_control')
    ->all();
    
    $sum_for_parent = $sum_for_parent[0]['first_parent'];    
    
    $sum_for_parent_1 = (new \yii\db\Query())
    ->select(['second_parent'])
    ->from('referal_control')
    ->all();
    $sum_for_parent_1 = $sum_for_parent_1[0]['second_parent'];     
    
    $sum_for_parent_2 = (new \yii\db\Query())
    ->select(['third_parent'])
    ->from('referal_control')
    ->all();    
    $sum_for_parent_2 = $sum_for_parent_2[0]['third_parent'];

    Обращение к одной записи к 3-м полям через три запроса

    reddevil, 31 Августа 2017

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if($folder!=array()){      
        $fold .= ' and(';
        $count = 0;
        foreach ($folder as $key => $value) {
            if($value==1){
                 if($count == 0) {$fold .= ' `table`.`folder_id`='.$key; $count +=1;}else{$fold .= ' or `table`.`folder_id`='.$key;}
            }
        }
        $fold .=')';
        if($fold == ' and()')  $fold ='';
        
    }

    Вот так собираются sql-запросы в легаси коде текущего проекта на Yii2. ActiveRecord? Query? Не не слышали

    Hvreg, 31 Августа 2017

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function get_link(){
            if (function(){
                return stripos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android');}){
                return $this->get_android_link();
            }
            else{
                return $this->get_ios_link();
            }
        }

    mk354, 30 Августа 2017

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    <?php if (!\MUserAuth::isAuthenticated()) : ?>
                <div id="wrapper-for-cabinet-content" style="display: none;"></div>
            {else}
                <div id="wrapper-for-cabinet-content">
                {include file="/themes/$__theme/en/common/muser_dropdown_part/cabinet.tpl"}
                </div>
            {/if}

    И это #работает#блять... "Smarty" нашего тимлида...

    rez1dent3, 25 Августа 2017

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