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

    +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
    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
    class Super_Loader extends Zend_Loader {
        public static function loadClass($class, $dirs = null)
        {
            parent::loadClass($class, $dirs);
        }
    
        private function moduleIsExist($name) {
            if(is_dir(APPLICATION_PATH . "/modules/" . $name . "/")) {
                return true;
            }
    
            return false;
        }
    
        public static function autoload($class)
        {
            $classArray = explode("_", $class);
            $firstPart = array_shift($classArray);
    
            if(self::moduleIsExist($firstPart)) {
    
                $moduleDir = APPLICATION_PATH . "/modules/";
                $typePart = array_shift($classArray);
                switch($typePart) {
                    case "Lib":
                        $file_name = $moduleDir . $firstPart . "/lib/" . implode("/", $classArray) . ".php";
                        break;
                    case "Model":
                        $file_name = $moduleDir . $firstPart . "/models/" . implode("/", $classArray) . ".php";
                        break;
                    default:
    
                        break;
                }
    
                if($file_name) {
                    try {
                        self::loadFile($file_name);
                        return $class;
                    } catch (Exception $e) {
                        return false;
                    }
                }
            } else {
                try {
                    self::loadClass($class);
                    return $class;
                } catch (Exception $e) {
                    return false;
                }
            }
        }
    }

    Свой супер-автолоадер для ZF

    asfalanaft, 03 Ноября 2011

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

    +167

    1. 1
    2. 2
    3. 3
    $query1234 = "select ....";
    $result1234 = mysql_query($query1234);
    $rs1234 = mysql_fetch_assoc($result1234);

    Это до такой степени не было фантазии придумать осмысленное название переменным. И бедные боялись, что перепишет где-то другие $query, $result, $rs. Не говоря уже о том, что никакой модели, сплошные фетчи, вместо того, чтобы вытянуть всё сразу

    Sash, 03 Ноября 2011

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //Redirect Using JAVASCRIPT 
         
        function redirect_to($url){ 
            echo '<script type="text/javascript"> 
            window.location = "'.$url.'" 
            </script>'; 
            exit("Javascript is turned off, <a href='$url'>click here to go to requested page</a>"); 
            }

    Может в кучу надо было?http://forum.antichat.ru/threadnav19997-48-10.html

    bot-minurast, 02 Ноября 2011

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

    +155

    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
    function toCyrillicTranslit($title)
    {
        $title = trim($title);
        
        $title = str_replace("&#192;", "А", $title);
        $title = str_replace("&#193;", "А", $title);
        $title = str_replace("&#194;", "А", $title);
        $title = str_replace("&#195;", "А", $title);
        $title = str_replace("&#196;", "А", $title);
        $title = str_replace("&#197;", "А", $title);
        $title = str_replace("&#198;", "А", $title);
        $title = str_replace("&#199;", "С", $title);
        $title = str_replace("&#200;", "Е", $title);
        $title = str_replace("&#201;", "Е", $title);
        $title = str_replace("&#202;", "Е", $title);
        $title = str_replace("&#203;", "Е", $title);
        $title = str_replace("&#204;", "И", $title);
        $title = str_replace("&#205;", "И", $title);
        $title = str_replace("&#206;", "И", $title);
        $title = str_replace("&#207;", "И", $title);
        $title = str_replace("&#208;", "Д", $title);
        $title = str_replace("&#209;", "Н", $title);
        $title = str_replace("&#210;", "О", $title);
        $title = str_replace("&#211;", "О", $title);
        $title = str_replace("&#212;", "О", $title);
        $title = str_replace("&#213;", "О", $title);
        $title = str_replace("&#214;", "О", $title);
        $title = str_replace("&#215;", "х", $title);
        $title = str_replace("&#216;", "О", $title);
        $title = str_replace("&#217;", "У", $title);
        $title = str_replace("&#218;", "У", $title);
        $title = str_replace("&#219;", "У", $title);
        $title = str_replace("&#220;", "У", $title);
        $title = str_replace("&#221;", "У", $title);
        $title = str_replace("&#222;", "П", $title);
    // и так далее ...

    kolexander, 02 Ноября 2011

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

    +149

    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 
    $USD = '30';
    $pecent = '10';
    ?>
    <SCRIPT language=JavaScript>
    var default_value1=0;
    
    function auto1(t){
    var silver = Math.floor(document.form.sum_out.value);
    if(silver>=0){
    var percent = (silver/100)*<?php echo $pecent ?>;
    var suma = (silver-percent)/<?php echo $USD ?>; 
    var sum = (Math.round(suma)).toFixed(2);
    
    document.form.summ.value=sum;
    default_value1 = silver;
    }else{
    alert("Поле должно содержать только цифры!");
    document.form.sum_out.value=default_value1; }
    if(t) auto2(); }
    
    function auto2(t){
    var sum=document.form.summ.value;
    if(sum>=0){
    var silver = (Math.round(sum*<?php echo $USD ?>)).toFixed(2);
    
    document.form.sum_out.value=silver;
    default_value2 = sum;
    }else{
    alert("Поле должно содержать только цифры!"); 
    document.form.summ.value=default_value2; }
    if(t) auto1(); }
    
    </SCRIPT>
    <form name=form action="test2.php" method="POST">
    
    <input onchange="auto1()" onkeyup="auto1()" onfocusout="auto1(true)" type=text name=sum_out value="">
    <input onchange="auto2()" onkeyup="auto2()" onfocusout="auto2(true)" type=text name=summ value="">
    
    	</FORM>
        
    <SCRIPT language=JavaScript>
    document.form.sum.value = ;
    auto1();
    </SCRIPT>

    в одну сторону считает, а как сдела что бы со второй пересчитывал не допру

    sumax, 02 Ноября 2011

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

    +151

    1. 1
    2. 2
    3. 3
    for ($i = 0, $cnt = count($arList); $i < $cnt; $i++) {
    		$arConfig["CONFIG"]["category"]["VALUES"][$arList[$i]] = GetMessage('SALE_DH_RUSSIANPOST_CONFIG_CATEGORY_'.$arList[$i]);
    }

    ... вместо человеческого foreach($arList as $k => $v) { ... }

    Iceman, 02 Ноября 2011

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

    +173

    1. 1
    2. 2
    3. 3
    // какоето говно
    elseif ((strlen(intval($_GET[1])) != strlen($_GET[1]))) {
    //какоето говно

    warider, 01 Ноября 2011

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

    +155

    1. 1
    2. 2
    3. 3
    $janres = serialize(isset($_POST['janres']) ? SafeEnv($_POST['janres'], 11, int) : array());
    
        if($tree->IdCats[$cat]['janres'] == "0") $janres = serialize(array());

    Бредокод

    Мартин, 01 Ноября 2011

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

    +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
    function getDirName($artistId)
        {
            $dirName = 1;
            $startNumber = 500;
            $result = false;
    
            while(!$result) {
                if ($artistId <= $startNumber) {
                    $result = true;
                }
                else {
                    $dirName++;
                    $startNumber += 500;
                }
            }
    
            return $dirName;
        }

    Весь прикол такой, что фотки на сервере лежат по 500 штук и зная id артиста можно узнать в какой из директории лежит его фотка. Вместо того чтобы написать, что то типа - $dirName = round($artistId / 500); я выдумал вот такую несуразицу :)

    dev6alexander, 01 Ноября 2011

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

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (
    	$arItem["DEPTH_LEVEL"]==$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]>3
    	||$arItem["DEPTH_LEVEL"]<$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]==3
    	&&$previousLevel-$arItem["DEPTH_LEVEL"]==1
    ) 
    .....

    Paranoid mode deteсted! Внимание! (Г)Код был в строку, для удобства чтения отформатировал.

    ProfBiss, 01 Ноября 2011

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