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

    +158

    1. 1
    <?if ((eregi('?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])**',$_POST['admin_mail']))){echo'Ошибка в адресе почты';} ?>

    Пооверка на валидность e-mail

    drZlo, 16 Июня 2011

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

    +158

    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
    if(isset($_POST['otmen'])){
    	die('1');
    	echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=/admin/?page=pages'>";
    	exit();
    }else{
        $id=$_GET['id'];
    $name=$_POST['name'];
        $title=$_POST['title'];
    $txt=$_POST['txt'];
    $txt=str_replace("\\\"","\"", $txt);
    $meta_desc=$_POST['meta_desc'];
    $meta_key=$_POST['meta_key'];
    $templ=$_POST['templ'];
    mysql_query("set names cp1251");
        $DB->query("UPDATE ".$pdb."_pages SET name='".$name."', title='".$title."', templ='".$templ."' WHERE id='".$id."'");
        $DB->query("UPDATE ".$pdb."_pages SET txt='".$txt."' WHERE id='".$id."'");
        $DB->query("UPDATE ".$pdb."_meta SET meta_desc_txt='$meta_desc' WHERE id='$id'");
        $DB->query("UPDATE ".$pdb."_meta SET meta_key_txt='$meta_key' WHERE id='$id'");
    
    echo "<center>Текст изменён!<br>Если вас не перенаправляет на другую странице, то нажмите на эту ссылку: <a href='/admin/?page=pages'>Заказы</a></center>";
    	if(isset($_POST['prim'])){
    		echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=/admin/?page=pages'>";
    	}
    	if(isset($_POST['ok'])){
    		echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=/admin/?page=pages&id=$id'>";
    	}
    	exit();
    }

    Модуль (?) редактирования страниц. $_POST['otmen'] - это при нажатии кнопки "отмена". $_POST['prim'] - это "применить", $_POST['ok'] - "сохранить". Иногда лучше не смотреть, в чем работаешь...

    ling, 16 Июня 2011

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

    +157

    1. 1
    print str_replace('collapsed', '', str_replace('expanded', '', str_replace('leaf', '', menu_tree($menu_name = 'menu-fabric'))))

    Вывод меню через файл шаблона в Drupal…

    Razunter, 16 Июня 2011

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

    +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
    include "./include/db.conf.php";
    $con = mysql_connect($DB["host"],$DB["user"],$DB["pass"]) or die ("could not connect:".mysql_error());
    mysql_set_charset('utf8');
    mysql_select_db($DB["dbName"]) or die ("could not connect:".mysql_error());
    
    $hash = $_GET['hash'];
    $login = $_GET['login'];
    echo "SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'";
    
    $query = mysql_query("SELECT id FROM reg WHERE log = '".$login."' AND hash = '".$hash."'") or die ("MYSQL error".mysql_error());
    
    if ($query) {
        while($row = mysql_fetch_array($query)) {
        echo row['id'];}
                
    $query = mysql_query("UPDATE reg SET commit=1 WHERE id=".row['id'])
         or die ("MYSQL error".mysql_error());}

    Знакомая поделилась шедевром. Так, конечно, можно... но в общем комментарии излишни.
    Да, форматирование оригинала сохранено.

    0rt, 16 Июня 2011

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

    +162

    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
    public function save() {
            try {
                try {
                    $this->create();
                } catch (Exception $e) {
                    //probably dulplicate
                    $this->update();
                }
            } catch (Exception $e) {
                logger::error($e);
            }
    
        }

    try-catch много не бывает

    super, 15 Июня 2011

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

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function date_preobr($date, $ind=0) {
    $date1=substr($date, 8, 2); $date21=substr($date, 5, 2); $date3=substr($date, 0, 4);
    if ($ind==0) $data=$date1.".".$date21.".".$date3;
    elseif ($ind==1) $data=$date1.".".$date21.".".substr($date3, 2, strlen($date3)-2);
    elseif ($ind==2) {switch ($date21) {case "01":$date21="января";break;case "02":$date21="февраля";break;
    case "03":$date21="марта";break;case "04":$date21="апреля";break;case "05":$date21="мая";break;
    case "06":$date21="июня";break;case "07":$date21="июля";break;case "08":$date21="августа";break;
    case "09":$date21="сентября";break;case "10":$date21="октября";break;case "11":$date21="ноября";break;
    case "12":$date21="декабря";break;} $data=$date1." ".$date21." ".$date3;}
    return $data;}

    Были даты, есть дата, будут даты.
    Привожу в первозданном виде.

    De-Luxis, 15 Июня 2011

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

    +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
    19. 19
    20. 20
    public function setIndex() {
    		$lang = '';
    		switch($this->data['find_in']) {
    			case '1' :
    				$this->indexes = Indexes::COMPANIES.$lang;
    			break;
    
    			case '2' :
    				$this->indexes = Indexes::PRODUCTS.$lang;
    			break;
    
    			case '3' :
    				$this->indexes = Indexes::PROMOS.$lang;
    			break;
    
    			default:
    				$this->indexes = Indexes::COMPANIES.$lang;
    			break;
    		}
    	}

    hellow, 14 Июня 2011

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

    +148

    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
    <?php
    
    class CodeCounter {
        const MULTILINE_COMMENT = 0x01;
    
        private $dir = null;
        private $ext = null;
    
        public function __construct($dir = '.', $ext = '*') {
            $this->dir = $dir;
            if($ext == '*') {
                $this->ext = "/.*/si";
            } else {
                $e = explode('|', $ext);
                foreach($e as &$ext) {
                    $ext = trim($ext);
                    if($ext == '')
                        unset($ext);
                }
                $r = implode('|', $e);
                $this->ext = "/.*\.({$r})$/si";
            }
    
        }
    
        public function calculate() {
            $lines = 0;
            $args = func_get_args();
            if(count($args) == 0)
                $dir = $this->dir;
            else
                $dir = $args[0];
            if(file_exists($dir) && is_dir($dir)) {
                $list = scandir($dir);
                foreach($list as $item) {
                    if($item == '.' || $item == '..')
                        continue;
                    $fullItem = realpath($dir . DIRECTORY_SEPARATOR . $item);
                    if(is_dir($fullItem)) {
                        $lines += $this->calculate($fullItem);
                    } else {
                        if(preg_match($this->ext, $item)) {
                            echo "Calculating lines in {$fullItem}:  ";
                            $_lines = self::count($fullItem);
                            echo "{$_lines}\n";
                            $lines += $_lines;
                        }
                    }
                }
            }
            return $lines;
        }
    
        private static function count($file) {
            $lines = 0;
            $d = null;
            if(file_exists($file) && ($file = file($file))) {
                foreach($file as $line) {
                    $line = trim($line);
                    if($line == '')
                        continue;
                    if( substr($line, 0, 2) == '//' || //single line comment
                        substr($line, 0, 1) == '#'  || //single line comment
                        substr($line, 0, 2) == '<?' || //php open tag
                        substr($line, 0, 2) == '?>'    //php close tags
                    )
                        continue;
                    if(($pos = strpos('/*', $line)) !== false) {
                        if($pos == 0) {
                            if(strpos('*/', $line, $pos) === false) {
                                $d = self::MULTILINE_COMMENT;
                            }
                        } else {
                            $lines++;
                        }
                        continue;
                    }
                    if($d == self::MULTILINE_COMMENT) {
                        if(strpos('*/', $line) !== false) {
                            $d = null;
                        }
                        continue;
                    }
                    $lines++;
                }
            }
            return $lines;
        }
    }
    
    $counter = new CodeCounter('./amapys', 'php|js');
    $lines = $counter->calculate();
    echo "\nTotal: {$lines} lines\n";

    Автор: POPSuL
    Пхп-шники такие пхп-шники.
    ООП во все поля. Им неведом sed и awk.

    cutwater, 13 Июня 2011

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

    +154

    1. 1
    2. 2
    3. 3
    foreach ($templatedata as $templatedataname=>$templatedatavalue)
    	$$templatedataname = $templatedatavalue;
    include($templatesDir.'/'.$file.'.tpl.php');

    Велошаблонизатор, превращающий пары ключ-значение из массива в локальные переменные шаблона.
    Шаблон - простой php-файл, в нужных местах выводящий полученные значения (реже с какой-либо логикой вроде обработки массива).

    Vindicar, 13 Июня 2011

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

    +167

    1. 1
    $r = $this->client->getBerechneteGrundversorgungsTarifebyPLZundVerbrauchKundenart($this->params);

    По сути не говнокод, но нечитабельность налицо...

    vov4ik, 13 Июня 2011

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