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

    −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
    <?php 
    		if($theme_options->get( 'header_type' ) == 2) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_02.tpl'); 
    		} elseif($theme_options->get( 'header_type' ) == 3) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_03.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 4) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_04.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 5) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_05.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 6) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_06.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 7) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_07.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 8) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_08.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 9) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_09.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 10) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_10.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 11) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_11.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 12) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_12.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 13) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_13.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 14) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_14.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 15) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_15.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 16) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_16.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 17) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_17.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 18) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_18.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 19) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_19.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 20) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_20.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 21) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_21.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 22) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_22.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 23) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_23.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 24) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_24.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 25) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_25.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 26) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_26.tpl');
    		} elseif($theme_options->get( 'header_type' ) == 27) {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_27.tpl');
    		} else {
    			include('catalog/view/theme/'.$config->get('config_template').'/template/common/header/header_01.tpl');
    		}	
    		?>

    phpBidlokoder2, 21 Января 2021

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

    +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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    <?php
     
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
     
    session_start();
     
    $mysqli = new mysqli('localhost', 'root', 'root', 'id15267461_base3');
     
    if (mysqli_connect_errno()) {
        echo "Подключение невозможно: " . mysqli_connect_error();
        die();
    }
     
    if (!empty($_POST)) {
        if (isset($_GET['del'])) {
            $id = $_POST['id'];
     
            $stmt = $mysqli->prepare("DELETE FROM `stars` WHERE id=?");
            $stmt->bind_param('i', $id);
            $stmt->execute();
     
            header('Location: /note.php');
            die();
        }
     
        if (isset($_GET['otz'])) {
            $name = $_POST['name'];
            $text = $_POST['message'];
     
            $stmt = $mysqli->prepare("INSERT INTO `stars` VALUES (NULL, ?, ?)");
            $stmt->bind_param('ss', $name, $text);
            $stmt->execute();
     
            header('Location: /note.php');
            die();
        }
    }
     
     
    $reviews = [];
    $res = $mysqli->query("SELECT * FROM `stars`");
    while($row = mysqli_fetch_array($res)) {
        $reviews[] = $row;
    }
     
     
    $isAdmin = $_SESSION['admin'] == true;
    $isGuest = empty($_SESSION['name']);
     
    ?>
     
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" text="text/css">
        <link href="https://fonts.googleapis.com/css?family=Julius+Sans+One" rel="stylesheet" text="text/css">
        <title>Отзывы</title>
        <link rel="stylesheet" type="text/css" href="style.css?<?= time(); ?>">
    </head>
    <body>
     
    <div id="main">
        <p>ОТЗЫВЫ</p>
        <h2>РЕСТОРАН</h2>
        <h1>КОЛЕСО</h1>
    </div>
     
    <div class="menu" id="regularmenu">
        <ul>
            <a href="index.php"><li>ГЛАВНАЯ</li></a>
            <a href="menu/salads-and-appetizers.php"><li>МЕНЮ</li></a>
            <a href="contact.php"><li>КОНТАКТЫ</li></a>
            <a href="news.php"><li>НОВОСТИ</li></a>
            <a href="note.php"><li>ОТЗЫВЫ</li></a>
            <a href="reges.php"><li>ЛИЧНЫЙ КАБИНЕТ</li></a>
            <a href="booking.php"><li>ЗАБРОНИРОВАТЬ СТОЛИК</li></a>
        </ul>
    </div>
     
    <div id="news">
        <?php foreach ($reviews as $review): ?>
            <div class="news-card">
                <h3><strong> <?= $review['Fio'] ?></strong></h3>
                <p>
                    <?= $review['inf'] ?>
                </p>
                <?php if ($isAdmin) : ?>
                    <form id="note-form" method="post" action="?del">
                        <input type="hidden" name="id" value="<?= $review['id'] ?>">
                        <button type="submit">Удалить отзыв</button>
                    </form>
                <?php endif; ?>
            </div>
        <?php endforeach ?>

    Говнокодеры с киберфорума.
    Как обычно = Проебали 10 летний опыт с накрученными постами.

    Ссылка на пост: https://www.cyberforum.ru/php-beginners/thread2743655.html#post15065275

    Внизу темы аргументы.

    MouseZver, 05 Декабря 2020

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

    +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
    <?php include_once("routing" .DIRECTORY_SEPARATOR  . "Router.php");?>
    <?php include_once("task" . DIRECTORY_SEPARATOR . "Task.php");?>
    <?php include_once("db" . DIRECTORY_SEPARATOR . "DB.php");?>
    <?php include_once("model" . DIRECTORY_SEPARATOR . "Model.php");?>
    <?php 
    class App{
    	public static $webuser = null;
    	public static $config;
    	public static $routing;
    	public static $DB;
    	public static $document_root;
    	
    	public static function run($config){
    		//config
                    self::$config = $config;
                    
                    /**
                     * init database
                     */
                    
                    
                    $db = new DB();
                    $db->connect(self::$config['db']);
                    self::$DB = $db;
                    
                    
                    
                    /**
                     * Run task
                     */
    		$request      = Router::getRequest(self::$config['default_task']);
    		
    		$task_path    = self::$document_root . DIRECTORY_SEPARATOR . "tasks" . DIRECTORY_SEPARATOR . $request . ".php";
                    
                    
                    
    		if(file_exists($task_path )){
    			include_once($task_path);
    			
    			$task = new $request();
    			
    			$task->init();
    		
    		}else {
    			throw new Exception("File don't exists");
    		}
                    
    			
    	}
            
            public static function isGuest(){
                if(is_null(self::$webuser)){
                    return true;
                }
                return false;
            }
    }
    ?>

    http://govnokod.ru/27036#comment585451

    https://habr.com/ru/post/523828/https://habr.com/ru/post/523828/

    я так ахуел, что скачал и посмотрел... говорят теперь я должен сжечь комп

    pahhan, 04 Декабря 2020

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

    +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
    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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    $queapplemode = mysqli_query($connect, "SELECT * FROM application_moderate_history ORDER BY user_id ") or die ("error_11111");
        $num=0;
        $nummm=0;
        $oldmodered="";
       	$newmodered="";
        while($apmod =  ($queapplemode))
        {
            // по данной таблице сортируем модераторов по порядку по айди, отслеживаем аппликатион айди, если его нет в бечелор аппликатион, тогда долой, если есть, то сверяем type_id, если 1, то успех и (если не успех, то мимо) тогда берем все данные из таблицы аппликатион модерат и далее обращаемсся в таблицу бачелор аппликатион и берем по аппликатион id там user_id абитуриента
            
            $apid = $apmod['application_id']; //id таблицы bachelor_application
    
            $apidquee = mysqli_query($connect, "SELECT * FROM bachelor_application WHERE id = '{$apid}'") or die ("error_11111");
            if($apidquee11 = mysqli_fetch_assoc($apidquee))
            {
                if($apidquee11['type_id'] == 2)
                {
                    $stateus = $apmod['status']; // статус модерирования
                    if($stateus == 0)
                    {
                        $stateuss = "Готовится";
                    }
                    elseif($stateus == 1)
                    {
                        $stateuss = "Подано";
                    }
                    elseif($stateus == 2)
                    {
                        $stateuss = "Принято";
                    }
                    elseif($stateus == 3)
                    {
                        $stateuss = "Отклонено";
                    }
    
                    $id_moderchika = $apmod['user_id']; // id модератора
                    $moder = mysqli_query($connect, "SELECT * FROM user WHERE id = '{$id_moderchika}' ") or die ("error_111");
                    $modered = mysqli_fetch_assoc($moder);
                    $modered = $modered['username']; //имя модератора
    
                    $commentar = $apmod['comment']; //комментарий от модератора
                    
                    $sozdan = $apmod['created_at']; //дата модерации
                    $sozdan = Yii::$app->formatter->asDatetime($sozdan); 
    
                    $id_polzot = $apidquee11['user_id']; //id абитуриента
                    $user = mysqli_query($connect, "SELECT * FROM user WHERE id = '{$id_polzot}' ") or die ("error_1110");
                    $usered = mysqli_fetch_assoc($user);
                    $usered = $usered['username'];
    
                        $userfio = mysqli_query($connect, "SELECT * FROM user_profile WHERE user_id = '{$id_polzot}' ") or die ("error_1110");
                        $userfioed = mysqli_fetch_assoc($userfio);
                        $userfiofir = $userfioed['firstname'];
                        $userfiomid = $userfioed['middlename'];
                        $userfiolas = $userfioed['lastname'];
    
                    ?>
                        <tr>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $id_moderchika; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $modered; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $id_polzot; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $usered; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $userfiofir." ".$userfiomid." ".$userfiolas; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $stateuss; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $commentar; ?></td>
                            <td style="border: solid 1px #000; text-align:center;"><?php echo $sozdan; ?></td>
                        </tr>
                
                    <?php 
                    $num++;
    
                    $newmodered = $modered['username'];
                    if($newmodered == $oldmodered)
                    {
                    	$nummm++;
                    	$oldmodered = $newmodered;
                    }
                    else
                    {
                    	$oldmodered = $newmodered;
                    }
                    
    
                    // получаем нового модератора, если новый модератор сопоставим со старым модератором, который в предыдущем цикле прошел итерацию, то просто +1 пишем, если нет, то завершаем суммирование и вносим в старого модера нового модера
                }
            }
        }

    Когда не умеешь пользоваться Джоинами, и соединяешь таблицы, перебирая результат запроса в цикле

    Stipa, 30 Ноября 2020

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

    +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
    <?php
    $data = file_get_contents('https://music.yandex.ru/users/[данные удалены]/playlists/[данные удалены]');
    $data = json_decode($data);
    $tracks = $data->result->tracks;
    $track = $tracks[$argv[1]]; // передаём номер песни из плейлиста
    /* Step 1 */
    $trackId = $track->track->id;
    $albumId = $track->track->albums[0]->id;
    $time = strval(time()) . '000';
    $url1 = 'https://music.yandex.ru/api/v2.1/handlers/track/' . $trackId . '%3A' . $albumId . '/web-user_playlists-playlist-track-saved/download/m?hq=0&external-domain=music.yandex.ru&overembed=no&__t=' . $time;
    
    $options['http']['header'] = "Accept: application/json; q=1.0, text/*; q=0.8, */*; q=0.1\r\n"
                               . "X-Retpath-Y: https%3A%2F%2Fmusic.yandex.ru%2F\r\n"
                               . "X-Requested-With: XMLHttpRequest\r\n"
                               . "User-Agent: Mozilla/5.0 [данные удалены]\r\n"
                               . "Cookie: [данные удалены]\r\n";
    $context = stream_context_create($options);
    $data = file_get_contents($url1, false, $context);
    $data = json_decode($data);
    /* Step 2 */
    $time = strval(time()) . '000';
    $url2 = 'https:' . $data->src . '&format=json&external-domain=music.yandex.ru&overembed=no&__t=' . $time;
    $data = file_get_contents($url2);
    $data = json_decode($data);
    /* Step 3 */
    $salt = 'XGRlBW9FXlekgbPrRHuSiA';
    $hash = md5($salt . substr($data->path, 1) . $data->s);
    $url3 = 'https://' . $data->host . '/get-mp3/' . $hash . '/' . $data->ts . $data->path;
    
    $name = $track->track->title;
    if(isset($track->track->version)) {
        $name .= ' (' . $track->track->version . ')';
    }
    
    $artists = array();
    foreach($track->track->artists as $artist) {
        $artists[] = $artist->name;
    }
    $name = implode(',', $artists) . ' - ' . $name;
    
    $name = strtr($name, ':/\\*?<|>', '________');
    $name = str_replace('"', '”', $name);
    $name = mb_substr($name, 0, 255-4);
    
    copy($url3, $name . '.mp3');

    Найдётся всё.

    Fainal_kantdaun, 26 Ноября 2020

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

    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
    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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    <?php
    
    class ModelExtensionModuleAridiusfastorder extends Model {
    	
    	public function deleteOrder($order_id) {
    		
    		$this->db->query("DELETE FROM " . DB_PREFIX . "aridiusfastorder WHERE order_id = '" . (int) $order_id . "'");
    	}
    
    	public function editOrder($order_id, $data) {
    		
    		$this->db->query("UPDATE `" . DB_PREFIX . "aridiusfastorder` SET firstname = '" . $this->db->escape($data['firstname']) . "',status = '" . $this->db->escape($data['status']) . "',email = '" . $this->db->escape($data['email']) . "',comment_manager = '" . $this->db->escape($data['comment_manager']) . "',contact = '" . $data['contact'] . "' WHERE order_id = '" . (int)$order_id . "'");
    	}
    	
    	public function getOrder($order_id) {
    		
    		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "aridiusfastorder WHERE order_id = '" . (int)$order_id . "'");
    		
    		return $query->row;
    	}
    
    	public function getOrders($data = array()) {
    
    		$sql = "SELECT * FROM " . DB_PREFIX . "aridiusfastorder";
    
    		if (isset($data['filter_order_id']) && !is_null($data['filter_order_id'])) {
    			$sql .= " WHERE order_id = '" . (int) $data['filter_order_id'] . "'";
    		} else {
    			$sql .= " WHERE order_id > '0'";
    		}
    
    		if (!empty($data['filter_contact'])) {
    			$sql .= " AND contact LIKE '%" . $this->db->escape($data['filter_contact']) . "%'";
    		}
    			if (!empty($data['filter_email'])) {
    			$sql .= " AND email LIKE '%" . $this->db->escape($data['filter_email']) . "%'";
    		}
    		if (!empty($data['filter_status'])) {
    			$sql .= " AND status LIKE '%" . $this->db->escape($data['filter_status']) . "%'";
    		}
    		
    		if (!empty($data['filter_firstname'])) {
    			$sql .= " AND firstname LIKE '%" . $this->db->escape($data['filter_firstname']) . "%'";
    		}
    
    		if (!empty($data['filter_product_name'])) {
    			$sql .= " AND product_name LIKE '%" . $this->db->escape($data['filter_product_name']) . "%'";
    		}
    
    		if (!empty($data['filter_date_added'])) {
    			$sql .= " AND DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
    		}
    
    		if (!empty($data['filter_total'])) {
    			$sql .= " AND total = '" . (float) $data['filter_total'] . "'";
    		}
    
    		$sort_data = array(
    			'order_id',
    			'status',
    			'email',
    			'contact',
    			'firstname',
    			'product_name',
    			'total',
    			'date_added'
    		);
    
    		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
    			$sql .= " ORDER BY " . $data['sort'];
    		} else {
    			$sql .= " ORDER BY order_id";
    		}
    
    		if (isset($data['order']) && ($data['order'] == 'DESC')) {
    			$sql .= " DESC";
    		} else {
    			$sql .= " ASC";
    		}
    
    		if (isset($data['start']) || isset($data['limit'])) {
    			if ($data['start'] < 0) {
    				$data['start'] = 0;
    			}
    
    			if ($data['limit'] < 1) {
    				$data['limit'] = 20;
    			}
    
    			$sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
    		}
    
    		$query = $this->db->query($sql);
    
    		return $query->rows;
    	}
    
    	public function getTotalOrders() {

    rastabumper, 25 Ноября 2020

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

    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
    https://habr.com/ru/company/vk/blog/527420/
    
    ВКонтакте снова выкладывает KPHP 
    
    ....
    
    Сгенерировать С++ из PHP — этого мало. Собственно говоря, это самое простое.
    
    Во-первых, в PHP мы используем кучу функций стандартной библиотеки: header(),
     mb_strlen(), curl_init(), array_merge(). Их тысячи — и все должны быть
    реализованы внутри KPHP с учётом типизации и работать так же, как в PHP.
    Реализация всего PHP stdlib (а также KPHP-дополнений), всех PHP-типов с
    операциями и допущениями — это называется runtime, вон там квадратик сверху.
    
    Во-вторых, PHP-сайт — это веб-сервер. Следовательно, и в KPHP должна быть вся
    серверная часть, чтобы можно было в том же nginx подменить PHP-шный upstream
    на KPHP-шный — и всё продолжало работать так же. KPHP поднимает свой веб-сервер,
    оркестрирует процессы, заполняет суперглобалы и переинициализирует состояние,
    как и PHP… Это тоже хардкорная часть — называется server, квадратик снизу.
    
    И только имея результирующий код C++, написанные runtime и server, всё это можно
    объединить и отдать на откуп плюсовым компиляторам. Мы используем g++ — там в
    диаграмме есть квадратик g++. Но не совсем так: у vk.com настолько огромная
    кодовая база, что этот компилятор не справляется, и поэтому мы применяем патченный
    distcc для параллельной компиляции на множестве агентов. В итоге всё линкуется в
    один огромный бинарник (это весь vk.com), он раскидывается на кучу бэкендов и
    синхронно перезапускается. Каждая копия запускает мастер-процесс, который порождает
    группу однопоточных воркеров. Вот они на самом деле и исполняют исходный PHP-код.
    
    Многие технические проблемы остаются за кадром — их не опишешь в статье на Хабре.
    Чего стоит один только сбор трейсов при ошибках: ведь в С++ не получить
    человекочитаемый стек, а хочется разработчику вообще его на PHP-код намаппить.
    Гигантское количество внутренних нюансов, множество подпорок и легаси — но в итоге
    продукт хорошо работает и развивается.

    PHP и C++... два говна нашли друг друга

    j123123, 11 Ноября 2020

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

    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
    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
    <?php declare(strict_types=1);
    /**
     * This file is part of Swoft.
     *
     * @link     https://swoft.org
     * @document https://swoft.org/docs
     * @contact  [email protected]
     * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
     */
    
    namespace Database;
    
    use Swoft;
    use Swoft\SwoftComponent;
    
    /**
     * Class AutoLoader
     *
     * @since 2.0
     */
    class AutoLoader extends SwoftComponent
    {
        /**
         * Class constructor.
         */
        public function __construct()
        {
            parent::__construct();
    
            Swoft::setAlias('@database', dirname(__DIR__) . '/database');
        }
    
        /**
         * @return array
         */
        public function getPrefixDirs(): array
        {
            return [
                __NAMESPACE__ => __DIR__,
            ];
        }
    
        /**
         * @return array
         */
        public function metadata(): array
        {
            return [];
        }
    }

    https://github.com/swoft-cloud/swoft/blob/master/database/AutoLoader.php

    MAPTbIwKA, 10 Ноября 2020

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

    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
    $snippet = preg_split('/'. $qs .'/i', $replace);
            $c = 1;
            foreach( $snippet as $snip ) {
              $length  = strlen( $snip ) * .3;
              $xlength = strlen( explode( $qs, $snip )[0] ); 
              if( $c % 2 !== 0 ) {
                $highlight_1 = substr( $snip, $xlength * .3, $xlength );
              }
              else {
                $highlight_2 = substr( $snip, 0, $length );
              }
              $c++;
            }
            $output .= '<dfn class="revolver__search-snippet">... '. preg_replace("#[^а-яА-ЯA-Za-z:;._,? -]+#u", '', $highlight_1) . '<mark>'. $qs .'</mark>'. preg_replace("#[^а-яА-ЯA-Za-z:.;_,? -]+#u", '', $highlight_2) .' ...</dfn></li>';

    Pick — самая маленькая поисковая система на PHP и MySQL
    Здесь пришлось повозиться. Простой подход совсем не подразумевал, что PHP начнет обрабатывать UTF-8 корректно, но я смог добиться работы с русским и английским языками.

    https://habr.com/post/526652

    gost, 08 Ноября 2020

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

    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
    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
    <?php
    /* 
    Purpose : To add database functions.
    Created : Nikitasa
    Date : 16-11-2016
    */
    include 'configs/dbconfig.php';
    class mysql{
    	var $link;
    	// connect database function 
    	public function connect_database(){		
    		$this->link = mysqli_connect(Host,Username,Password,Database);
    		if(!$this->link){
    			die('Unable to connect');
    		}
    		// return $this->link;
       }
    	// query execution
    	public function execute_query($query){		  
    		$result = mysqli_query( $this->link, $query);  
    		// mysqli_more_results($this->link);   
    		return $result;
    	}
      	
    	
    	// next query execution
    	public function next_query(){		      
    		mysqli_next_result($this->link);		
    	}
    	
    	// result display	    
    	public function display_result($result){ 
    		$obj = mysqli_fetch_assoc($result);
    		return $obj;
    	} 
    	
    	// clear the results	    
    	public function clear_result($result){ 
    		mysqli_free_result($result);
       } 
    
    	// real escape string 
    	public function real_escape_str($str){
    		return mysqli_real_escape_string($this->link, $str);
    	}	
    	// number of rows	
    	public function num_rows($result){ 
    		$num = mysqli_num_rows($result);
    	   return $num;
    	}            
    	// close connection
    	public function close_connection(){
    		//mysqli_close($res);	
    		mysqli_close($this->link);	
    	}
    } 
    $mysql = new mysql();
    ?>

    real_escape_string, 07 Ноября 2020

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