1. SQL / Говнокод #7240

    −851

    1. 1
    facepalm.sql

    В таблице платежей несколько полей с цифрами - _amount и _value.
    В связаной таблице есть поле PaymentAmount.
    Угадайте, какому полю платежа оно соответствует 7:

    wiz, 13 Июля 2011

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

    +174

    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
    <?php
    function htmlspecialchars($a) {
    	return htmlspecialchars($a);
    	return preg_replace('/</','<',htmlspecialchars($a));
            echo htmlspecialchars($a);
    }
    echo htmlspecialchars('<a href="http://">линка</a>');  // мы пришли к тому, 
    что заменили <a href="http://">линка</a>, 
    то есть оно выведет прям ссылку, 
    а мы сделали так, 
    чтобы оно вывело <a href="http://">линка</a>, 
    то есть выведит само <a href="http://">линка</a>, 
    без всяких ссылок, прям как текст. 
    Внести в функцию изменения, 
    можно, 
    но осторожно. 
    ТОЛЬКО ДЛЯ ЗНОЮЩИХ ПИХХИПИ.
    ?>

    мозготрах

    substr, 13 Июля 2011

    Комментарии (26)
  3. C++ / Говнокод #7238

    +147

    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
    //для краткости порезано
    //первый файл
    //объявление контрола, который в себе рисует квадратные thumbnailы
    class ThumbnailViewer : .... {
    ...
    //внимание!
    private: 
    struct Impl;
    Impl *m_impl;
    }
    //второй файл
    //объявление мифической структуры Impl
    
    struct ThumbnailView::Impl
    {
    ...
    //а вот это и есть то, что должно рисоваться на экране для каждого thumbnail
        class Item : public QGraphicsPixmapItem {
    ...
    }
    ...
    }

    что хотел иметь ввиду афтор?

    mr_borod, 13 Июля 2011

    Комментарии (6)
  4. C++ / Говнокод #7237

    +159

    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
    #include <iostream>
    
    class Schotchik { public:
    Schotchik();
    Schotchik(int znach);
    ~Schotchik(){}
    int vzyat_znachenie()const { return znachenye; }
    void vstavit_znachenie(int x) {znachenye = x; }
    operator unsigned int();
    private: int znachenye; };
    Schotchik::Schotchik(): znachenye(0) {}
    Schotchik::Schotchik(int novoe_znachenie): znachenye(novoe_znachenie) {}
    Schotchik::operator unsigned int () { return ( int (znachenye) ); }
    
    void* main() {
    Schotchik ctr(5);
    int znachenye = ctr;
    std::cout << "znachenye: " << znachenye << std::endl;
    return 5 ; }

    Govnocoder#0xFF, 12 Июля 2011

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /*
    * Условия для шаблонов и не только ;)
    * $content - то что проверям
    * $data - то что выводим
    */
    function if_set($content, $data) {
    	return empty($content) ? '' : stripslashes($data);
    }

    Комментарий больше кода, и автор ещё Вам подмигивает.

    nethak, 12 Июля 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function utf_decode($str) {
        /*static $table = array("\xD0\x81" => "\xA8", "\xD1\x91" => "\xB8",);
        return preg_replace('#([\xD0-\xD1])([\x80-\xBF])#se', 'isset($table["$0"]) ? $table["$0"] : chr(ord("$2")+("$1" == "\xD0" ? 0x30 : 0x70))', $str);*/
    	return $str;
    }

    Зря закоментил такая панацея была что вы, что вы...

    nethak, 12 Июля 2011

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

    +168

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    /*
    * Выводим чекбоксы :D
    * $name - имя инпута чеки
    * $val - тру ор фалсе
    */
    function checkbox($name, $val) 
    {
    	$checked = !empty($val) ? 'checked ' : false;
    	return "<input type=\"checkbox\" name=\"" . $name . "\" " . $checked . "/>";
    }

    Тру от фалсе

    nethak, 12 Июля 2011

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

    +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
    /*
    * Получаем категории из массива ЭКСПЕРЕМЕНТАЛЬНАЯ ФУНКЦИЯ :D
    * $fp - файл
    * $content - то что запишем
    */
    function save_conf($fp, $content) 
    {
    	$file_name = basename($fp);
    	if(!file_exists($fp))
    	{
    		file_put_contents($fp,'');
    		@chmod(ROOT . $fp, 0666 );
    	}
    	if (file_exists($fp) && $content) 
    	{
    		$fp = fopen($fp, "wb");
    		$content = "<?php
    if (!defined('ACCESS')) 
    {
        header('Location: /');
        exit;
    }
    \n\n".$content."\n";
    		fwrite($fp, $content);
    		fclose($fp);
    	}
    }

    И как же он тут получит категории остаётся загадкой, и поржать он любит в комментариях смотрю)
    * BY Toogle CMS

    nethak, 12 Июля 2011

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

    +163

    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
    Файл 1 :
    <?php
    for ($i=0; $i<10; $i++) // Моё примечение - вонять начинает отсюда
    {
    include "delstr.php";
    include "razdel2.php";
    include "gendat.php";
    include "dopismain.php";
    }
    Файл delstr.php:
    <?php
    $num_stroka = 7; //Удалим 7 строку из файла
    $file = file("gendat.php"); // Считываем весь файл в массив
    for($i = 0; $i < sizeof($file); $i++)
    if($i == $num_stroka) unset($file[$i]);
    $fp = fopen("gendat.php", "w");
    fputs($fp, implode("", $file));
    fclose($fp);
    ?>
    Файл razdel2.php:
    <?php
    $sl = file('ancorrzd.txt');
    $sm = $sl[array_rand($sl, 1)];
    $datam = $sm;
    $file = fopen ("rzd.txt","w");
    $str = "$datam";
    fputs ( $file, $str);
    fclose ($file);
    $dataC = trim(file_get_contents ("rzd.txt"));
    $data="\$dataCata='$dataC';";
    $file = 'gendat.php';
    $array=file( $file );
    $array[7]= $data; //строка в которой нужно изменить значение $data
    file_put_contents( $file, $array );
    ?>
    Файл gendat.php:
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
    ini_set('session.auto_start', '1');
    //ini_set('upload_tmp_dir', 'c:\tmp');
    set_time_limit(120);
    @session_start();
    $dataCata='xfgjcfyi';
    $txtFile = 'result.txt'; // файл с текстом
    $ancorFile = 'ancor.txt'; // файл с заголовками
    $tplFile = 'template.txt'; // файл шаблона .dat файлов
    $mainTplFile= 'maintemplate.txt'; // Шаблон файла со ссылками
    $datDir = "articles/$dataCata"; // директория для .dat файлов
    $datExt = 'dat'; // расширение .dat файлов
    $mainFile = 'main.dat'; // Файл со ссылками на .dat файлы
    $srcCharset = 'cp1251'; // Кодировка исходных файлов
    $destCharset = 'cp1251'; // Кодировка файлов на выходе
    $scriptCharset = 'utf-8'; // Кодировка скрипта
    $blockLength = 4000; // Максимальный размер блока в байтах из файла с текстом
    $file = fopen ("engine/menu.php","a");
    $str = "<li><a href=\"/$dataCata/\">$dataCata</a></li>";
    if ( !$file )
    {
    echo("Ошибка открытия файла");
    }
    else
    {
    fputs ( $file, $str);
    }
    fclose ($file);
    if ($srcCharset == 'utf-8') $blockLength *= 2;
    $blockLength = $blockLength % 2 > 0 ? $blockLength+1 : $blockLength;
    if ( !is_dir($datDir) ) mkdir($datDir, 0777, true);
    $hMain = NULL;
    if ( !(@$hMain = fopen($mainFile, 'w+')) ) die("Невозможно создать файл $mainFile<br/>\b");
    $hText = fopen($txtFile, 'r');
    $ancors = explode("\n", $srcCharset == $scriptCharset ? file_get_contents($ancorFile) : iconv($srcCharset, $scriptCharset, file_get_contents($ancorFile)));
    $template = $srcCharset == $scriptCharset ? file_get_contents($tplFile, 'r') : iconv( $srcCharset, $scriptCharset, file_get_contents($tplFile, 'r') ); // читаем шаблон
    $content = '';
    while ($content = fread($hText, $blockLength)) {
    $fname = genName();
    if (@$hDat = fopen("$datDir/$fname.$datExt", 'w')) {
    $ancor = trim($ancors[rand(0, count($ancors)-1)]);
    $content = $srcCharset == $scriptCharset ? trim($content) : iconv($srcCharset, $scriptCharset, trim($content));
    // Генерим dat файлы по шаблону
    $thisTpl = preg_replace("/(<!--.*?Kan_title.*?-->).*?(<!--.*?Kan_title.*?-->)/uism", "$1\n$ancor\n$2", $template);
    $thisTpl = preg_replace("/(<!--.*?Kan_content.*?-->).*?(<!--.*?Kan_content.*?-->)/uism", "$1\n$content\n$2", $thisTpl);
    $thisTpl = $scriptCharset == $destCharset ? $thisTpl : iconv( $scriptCharset, $destCharset, $thisTpl );
    if (fwrite($hDat, $thisTpl)) {
    echo "Файл $dataCata/$fname.$datExt записан<br/>\n";
    $html = "
    <loc><a href=\"/$dataCata/$fname.html\">$ancor</a></loc>\n";
    fwrite($hMain, iconv($scriptCharset, $destCharset, $html));
    } else { echo "Ошибка записи в файл $dataCata/$fname.$datExt<br/>\n"; }
    } else {
    echo "Не могу записать в файл $dataCata/$fname.$datExt<br/>\n";
    }
    }
    // Генерация уникального имени
    function genName() {
    return substr(md5(uniqid(rand(), true)), 0, rand(7, 13));
    }
    ?>

    Человек интересуется, почему цикл выполняется только 1 раз. Ему посоветовали разместить лучше свой код тут, но по-моему, делать это самостоятельно у него желания нет, решил помочь. Пруфлинк - http://forum.searchengines.ru/showthread.php?t=643176

    Nemoden, 12 Июля 2011

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !trim(strip_tags($strAddress))){
            return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !trim(strip_tags($strAddress))){
    	return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !$this->address_houses && !trim(strip_tags($strAddress))){
    	return '';
    }
    if(!$this->first_name && !$this->last_name && !$this->countryID && !$this->zoneID && !$this->zip && !$this->state && !$this->city && !$this->address_street && !$this->address_home && !$this->address_houses && !$this->address_houseroom && !trim(strip_tags($strAddress))){
    	return '';
    }

    Найдено в одной CMS

    CRRaD, 12 Июля 2011

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