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

    0

    1. 1
    2. 2
    3. 3
    foreach ($properties->xml->ЗначенияСвойства as $property) {
        //......
    }

    $properties->xml->ЗначенияСвойства

    hrustbb2, 10 Сентября 2020

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

    +3

    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
    # Alternative mysql_real_escape_string without mysql connection
    
    function escape_string($param) {
        if(is_array($param))
            return array_map(__METHOD__, $param);
    
        if(!empty($param) && is_string($param)) {
            return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $param);
        }
    
        return $param;
    }
    
    #Using example
    $name       = @trim(escape_string(stripslashes($_POST['name'])));

    https://gist.github.com/wilnaweb/ca37459bdf92aa74bd2dd7994fa5b0df

    real_escape_string, 09 Сентября 2020

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

    +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
    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
    $DI_WName = Array('ѕн','¬т','—р','„т','ѕт','—б','¬с');
    	$DI_MName = Array('январь','‘евраль','ћарт','јпрель','ћай','»юнь','»юль','јвгуст','—ент¤брь','ќкт¤брь','Ќо¤брь','ƒекабрь');
    
    	$today = TodayDate();
    	$today = explode(".",$today);
    	$today = $today[2]*10000+$today[1]*100+$today[0];
    
    	$DI_Date = TodayDate();
    	if (isset($_GET["p0"])) $DI_Date = $_GET["p0"];
    	$DI_Date = explode(".",$DI_Date);
    
    	$DI_YY = $DI_Date[2];
    	$DI_LYY = $DI_YY;
    	$DI_NYY = $DI_YY;
    
    	$DI_MM = $DI_Date[1]-1;
    	$DI_LMM = $DI_MM-1;
    	if ($DI_LMM<0) $DI_LMM = 11;
    	$DI_NMM = $DI_MM+1;
    	if ($DI_NMM>11) $DI_NMM = 0;
    
    	if ($DI_MM==0) $DI_LYY = $DI_YY-1;
    	if ($DI_MM==11) $DI_NYY = $DI_YY+1;
    
    	$DI_DD = $DI_Date[0];
    
    	$lastM = $DI_MM-2;
    	$yy = $DI_YY;
    	if ($lastM<1) {
    		$lastM = 12+$lastM;
    		$yy = $yy - 1;
    	}
    	$lastM = $DI_DD.".".$lastM.".".$yy;
    
    	$nextM = $DI_MM+4;
    	$yy = $DI_YY;
    	if ($nextM>12) {
    		$nextM = $nextM-12;
    		$yy = $yy + 1;
    	}
    	$nextM = $DI_DD.".".$nextM.".".$yy;
    
    	$lastY = $DI_DD.".".($DI_MM+1).".".($DI_YY-1);
    	$nextY = $DI_DD.".".($DI_MM+1).".".($DI_YY+1);

    kib0rg, 08 Сентября 2020

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

    +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
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    function DI_MNum($Mon, $Year) {
    		$nn = Array(31,28,31,30,31,30,31,31,30,31,30,31);
    		$x = 28;
    		$y = (Round($Year/4))*4;
    		if ($y==$Year) $x = 29;
    		$ret = $nn[$Mon];
    		if ($Mon==1) $ret = $x;
    		return $ret;
    	}
    
    	function DI_FirstDay($Mon,$Year) {
    		$x0 = 365;
    		$Y = $Year-1;
    		$days = $Y*$x0+floor($Y/4)+6;
    		for ($j=0; $j<$Mon; $j=$j+1) {
    			$days = $days+DI_MNum($j,$Year);
    		}
    		$week = $days-(7*Round(($days/7)-0.5));
    		return $week;
    	}
    
    	function even_week($Day,$Mon,$Year) {
    		$x0 = 365;
    		$Y = $Year-1;
    		$days = $Y*$x0+floor($Y/4)+6;
    		for ($j=0; $j<$Mon; $j=$j+1) {
    			$days = $days+DI_MNum($j,$Year);
    		}
    		$days = $days + $Day;
    		$weeks = ceil($days/7);
    
    		$res = false;
    		if (2*ceil($weeks/2) == $weeks) $res = true;
    		return $res;
    	}

    kib0rg, 08 Сентября 2020

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

    −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
    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
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    public function index()
        {
            $items = CartManager::getAllItems();
    
            $couponCode = Coupon::getFromSession()->implode('code', ', ');
    
            $address = auth()->user()->address;
    
            $user = auth()->user();
            $userDetails = auth()->user() ? auth()->user()->fields : null;
    
            $fields = [
                'promo_code' => $couponCode,
                'email' => $user->email,
                'first_name' => $userDetails->firstname,
                'last_name' => $userDetails->lastname,
                'phone' => $userDetails->phone,
            ];
    
            if ($address) {
                $field = [
                    'value' => $address->city->title
                ];
                if ($address->city->type === \App\Address::TYPE_CITY) {
                    $field ['data']['city_fias_id'] = $address->city->id;
                    $field ['data']['city'] = $address->city->title;
                } elseif ($address->city->type === \App\Address::TYPE_SETTLEMENT) {
                    $field ['data']['settlement_fias_id'] = $address->city->id;
                    $field ['data']['settlement'] = $address->city->title;
                }
                $fields ['delivery_city'] = $field;
            }
    
            if ($address->street) {
                $fields ['delivery_street'] = [
                    'value' => $address->street->title,
                    'data' => [
                        'street_fias_id' => $address->street->id,
                    ]
                ];
            }
    
            if ($address->street_number) {
                $fields ['delivery_house_number'] = [
                    'value' => $address->street_number,
                ];
            }
    
            if ($address->flat) {
                $fields ['delivery_flat_number'] = $address->flat;
            }
    
            $fields = (object)$fields;
    
            $actions = [
                'remove' => route('shop.cart.remove'),
                'remove_gift_card' => route('shop.cart.gift-cards.remove'),
                'change' => route('shop.cart.update'),
                'promo' => route('shop.coupon.apply'),
                'checkout' => route('orders.store'),
                'get_pickups' => route('delivery_points.index'),
                'check_email' => route('check_email'),
            ];
    
            return view('shop.cart.index', compact(
                'items',
                'address',
                'couponCode',
                'fields',
                'actions'
            ));
        }

    this is MVC, baby !

    hrustbb2, 31 Августа 2020

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (SCRIPT_DEBUG || filemtime(get_theme_file_path('/assets/js/global.min.js')) < filemtime(get_theme_file_path('/assets/js/global.js'))) {
        wp_enqueue_script('gk-global', get_theme_file_uri('/assets/js/global.js'), array('jquery'), $ver, true);
    } else {
        wp_enqueue_script('gk-global', get_theme_file_uri('/assets/js/global.min.js'), array('jquery'), $ver, true);
    }

    Обосрался.
    Сделал, чтобы после правок скрипта не использовался min файл. В какой-то момент время сравнялось, а версии разошлись.

    Хрю.

    guest8, 20 Августа 2020

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    private function changePlans(Coupon $coupon): Coupon
    {
            $coupon->paypal_plan_yearly_rub_id = $this->getPaypalId($coupon->billingPlanYearlyRub, $coupon);
            $coupon->paypal_plan_yearly_usd_id = $this->getPaypalId($coupon->billingPlanYearlyUsd, $coupon);
            $coupon->paypal_plan_monthly_rub_id = $this->getPaypalId($coupon->billingPlanMonthlyRub, $coupon);
            $coupon->paypal_plan_monthly_usd_id = $this->getPaypalId($coupon->billingPlanMonthlyUsd, $coupon);
    
            return $coupon;
    }

    Вот это забавно $this->getPaypalId($coupon->billingPlanMonthlyUsd, $coupon); (getPaypalId приватный)

    hrustbb2, 20 Августа 2020

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

    0

    1. 1
    https://ru.wikihow.com/%D0%B8%D0%B7%D1%83%D1%87%D0%B8%D1%82%D1%8C-PHP-%D0%B8-MySQL

    Stallman, 18 Августа 2020

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

    +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
    private function _postPhotoWidth($post) {
            $raw_code = rtrim(str_replace("\r", '', $post->post_content));
            $lines = explode("\n", $raw_code);
            if (count($lines) <= 1) {
                return -1;
            }
            $text_width = 0;
            foreach ($lines as $line) {
                $text_width = max($text_width, mb_strlen($line) + substr_count($line, "\t") * 7);
            }
            return (int)(max(20 + $text_width, 60) * 18.5);
        }

    Код для вычисления длины данного гамнакода.

    3_dar, 15 Августа 2020

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    В боте @GovnokodBot обновление:
    
    Теперь говнокоды отправляются скриншотами.
    Также создан канал "Говнокода" в "Telegram": https://t.me/GovnokodChannel
    
    Баги и пожелания можно писать сюда.

    Зеркала Говнокода и полезные ресурсы:
    * https://govnokod.xyz/
    * https://gcode.space/
    * индекс оффтопов: https://index.gcode.space/
    * https://t.me/GovnokodBot
    * https://pethu.ru

    guest8, 14 Августа 2020

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