Mistři v programování na #hovnokod

nalezeno v jednom CMS. Nejen že to slavné "řazení", řešené dvojitou smyčkou, lze udělat už v SQL dotazu, ale hlavně, pokud $data obsahují záznamy s neexistujícím ID, tak se to hezky zacyklí :)

/**
 * select pictures src by ids
 * @param array $data
 * @return multitype:|multitype:unknown
 */
private function modelSelectPicturesSrcByIds(array $data) {
    if (empty($data)) {
        return array();
    } else {
        foreach ($data as &$tmp) {
            $tmp = (int) $tmp;
        }

        $ids = implode(',', $data);

        $result = $this->env->db->selectAssocList("SELECT * FROM {$this->table_file_p} WHERE id in ({$ids})");

        //order by id
        $return = array();
        $data = array_reverse($data);
        $currentId = array_pop($data);
        if ($result) {
            while ($currentId != null) {
                foreach ($result as $row) {
                    if ($row['id'] == $currentId) {
                        $return[] = $row;
                        $currentId = array_pop($data);
                        break;
                    }
                }
            }
        }

        return $return;
    }
}

Anonymous,

najdi rozdíl

    if(element.data("max")) {
            helps = $(this).closest(element).find("input").val();
            newVal = Number(helps)+1;

            $(this).closest(element).find("input").val(newVal).trigger('change');

    }else {
            helps = $(this).closest(element).find("input").val();
            newVal = Number(helps)+1;
            $(this).closest(element).find("input").val(newVal).trigger('change');
    }

Anonymous,

Jak ziskat posledni e-mail? Preci si nacist vsechny z db a vratit prvni.

function getLastEmail($code) {			
    $mails = dibi::fetchAll('SELECT id FROM emails e WHERE e.deleted = 0 AND e.name LIKE %~like~ ORDER BY e.date_entered DESC', $code);

    foreach($mails as $mail) {
        return $mail;
    }
}

Anonymous,

Verejne dostupny GDPR-ready kod

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

ini_set('memory_limit', '-1');

include "NotORM.php";
$pdo = new PDO("mysql:dbname=production", "production", "Secr3tPassw0rd");
$db = new NotORM($pdo);
foreach ($db->sales_flat_order() as $order) { // get all applications
    echo "$order[customer_email]<br>"; // print application title
}
//echo 'Hello world';

Anonymous,

Potřebuje to komentář? :D

public function actionAuth($accessToken, $consumerKey) {
        // jakoze asi ok, zejo :)
        
        $this->responseOk();
}

Anonymous,