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

    +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
    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
    function make_cat_options($pid='0',$selected='',$depth=1,$not='')
    {
    	global $cat_cache,$udb,$database,$admin;
    	if ( !is_array($cat_cache) )
    	{
    		$sql = $udb->query('SELECT * FROM '.$database['cat'].' ORDER BY orders ASC, cid ASC');
    		while ($row = $udb->fetch_array($sql))
    		{
    			$cat_cache[$row['pid']][$row['cid']] = $row;
    		}
    	}
    	$cache = $cat_cache;
    	$xaccess = explode(",",$not);
    	if(!isset($cache[$pid])) return;
    	while (list($parent,$category) = each($cache[$pid]))
    	{
    		if ( $this->cattpl != '' )
    		{
    			$a .= str_replace( 
    				array('{url}','{description}','{name}'),
    				array( 
    						$this->link_cat( $category[$this->sestype_cat()]),
    						$admin->superhtmlentities($category['description']),
    						str_repeat(' ',$depth-1)." ".$category['name']
    					),
    			
    				$this->cattpl );
    		}
    		else
    		{
    			$category['name'] = $this->hsc == 1 ? $admin->superhtmlentities($category['name']) : $category['name'];
    			unset($sel);
    			if ($category['cid'] == $selected)
    			{
    				$sel = 'selected="selected"';
    			}			       
    			if ( !in_array($category['cid'],$xaccess) )
    			{
    				if ( $category['disabled'] != 1 )
    				{
    					$a .= '<option value="'.($this->cat_name == 1 ? $this->link_cat($category[$this->sestype_cat()]) : $category['cid']).'" '.$sel.'>';
    					if ($depth > 1)
    					{ 
    						$a .= str_repeat("-",$depth-1)." ".$category['name']."</option>"."\n";
    					}
    					else
    					{
    						$a .= $category['name']."</option>";
    					}
    				}
    				else
    				{
    					$a .= '<optgroup label="'. str_repeat("-",$depth-1)." ".$category['name'].'">';
    					$closegroup = 1;
    				}
    			}
    		}
    		$a .= $this->make_cat_options($category['cid'],$selected,$depth+1,$not);
    		if ( $closegroup == 1 )
    		{
    			$a .= "</optgroup>\n";
    		}
    	} 
    	$udb->free_result($sql);
    	return $a;
    }

    qbasic, 06 Марта 2011

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

    +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
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    function get_list_templ()
    {
    $list = array();
    $odir = opendir("../templetes");
    while (($rdir = readdir($odir)) != false)
    {
    if ($rdir !== '.' and $rdir !== '..' and !strpos($rdir, '.'))
    {
    echo $rdir.': ';
    $odir2 = opendir("../templetes/$rdir");
    while($rdir2 = readdir($odir2))
    if ($rdir2 !== '.' and $rdir2 != '..' and strpos($rdir2, '.'))
    {
    if ($rdir2 === 'index.php')
    {
    echo $rdir2."<br />";
    } else
    {
    
    echo 'No exits index.php<br />';
    }
    }
    }
    }

    qbasic, 06 Марта 2011

    Комментарии (3)
  3. JavaScript / Говнокод #5906

    +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
    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
    function convert(val){
        var TablePrice = document.getElementById("main_price");
        var trList = TablePrice.getElementsByTagName("tr");
        var IdVal = document.getElementById("IndocatorCurHide");
        var IdCur = document.getElementById("IndocatorCur");
        
        var CurUSD = parseFloat(document.getElementById("CurUSD").innerHTML);
        var CurRUR = parseFloat(document.getElementById("CurRUR").innerHTML);
        var CurEUR = parseFloat(document.getElementById("CurEUR").innerHTML);
        
        var Kurce = 1;
        var KurceUAH = 1;
        
        switch (val) {
            case "RUR":
                IdCur.style.backgroundImage = "url('flags/FlagsRussia.jpg')";
                break;
            case "EUR":
                IdCur.style.backgroundImage = "url('flags/FlagsEU.jpg')";
                break;
            case "USD":
                IdCur.style.backgroundImage = "url('flags/FlagsUSA.jpg')";
                break;
            case "UAH":
                IdCur.style.backgroundImage = "url('flags/FlagsUkraine.jpg')";
                break;
        }
        
        for (var i = 0; i < trList.length; i++) {
            var tdList = trList[i].getElementsByTagName('td');
            for (j = 0; j < tdList.length; j++) {
                if (tdList[j].id == "ToConvert") {
                    if ((tdList[j].innerHTML != "") && (tdList[j].innerHTML != "-")) {
                        var TmpPrice = parseFloat(tdList[j].innerHTML);
                        switch (IdVal.innerHTML) {
                            case "RUR":
                                switch (val) {
                                    case "UAH":
    	
                                        TmpPrice *= CurRUR;
                                        break;
                                    case "EUR":
                                        TmpPrice *= CurRUR;
                                        TmpPrice /= CurEUR;
                                        break;
                                    case "USD":
                                        TmpPrice *= CurRUR;
                                        TmpPrice /= CurUSD;
                                        break;
                                }
                                ;                            break;
                            case "USD":
                                switch (val) {
                                    case "UAH":
                                        TmpPrice *= CurUSD;
                                        break;
                                    case "EUR":
                                        TmpPrice *= CurUSD;
                                        TmpPrice /= CurEUR;
                                        break;
                                    case "RUR":
                                        TmpPrice *= CurUSD;
                                        TmpPrice /= CurRUR;
                                        break;
                                }
                                ;                            break;
                                
                            case "EUR":
                                switch (val) {
                                    case "UAH":
                                        TmpPrice *= CurEUR;
                                        break;
                                    case "RUR":
                                        TmpPrice *=  CurEUR;
                                        TmpPrice /=  CurRUR;
                                        break;
                                    case "USD":
                                        TmpPrice *= CurEUR;
                                        TmpPrice /= CurUSD;
                                        break;
                                }
                                ;                            break;
    ...
                        }
                        tdList[j].innerHTML = TmpPrice.toFixed(2);//Math.round(TmpPrice / 0.1) * 0.1;

    Наткнулся на форуме JavaScript, функция для конвертирования валют =).

    vulkan, 06 Марта 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    <input type="text" name="quantity- <?php echo $row['id']; ?>" size="2" style="text-align:center" value="<?php echo $_SESSION['cart'][$row['id']]['quantity']; ?>" id='inp_<? echo $er;?>' onBlur='calculate(this.value, "<?php echo $row['cena'];?>", "bdo_<? echo $er;?>")'/>
    
    <? 
    if ($_SESSION['cart'][$row['id']]['quantity'] != $_POST['quantity-'.$row['id']]) $_SESSION['cart'][$row['id']]['quantity'] = $_POST['quantity-'.$row['id']];

    qbasic, 06 Марта 2011

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

    +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
    <?
    $xml = xml_parser_create();
    xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE,1);
    xml_parse_into_struct($xml, file_get_contents($url), $el, $fe);
    xml_parser_free($xml);
    
    for($i=0; $i<5; $i++){
       $m = $fe['ITEM'][$i];
       $title = $el[$m+1]['value'];
       $link = $el[$m+2]['value'];
       $time = $el[$m+4]['value'];
       $desc = mb_substr( $el[$m+3]['value'], 0, 80, 'UTF-8');
       echo '<br/><strong>'.$title.'</strong> <br/>['.
        $time.']<br/>'.$desc.'<br/><a href="'.$link.'">читать...</a>';
    }

    qbasic, 06 Марта 2011

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

    +164

    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
    /**
     * @class Session
     * @brief Класс для управления безопасностью на сайте.
     * тут еще многа инфы
     */
    // Отрывки из классы
    
     public static function auth($email, $password)
        {
        	$result = 0;
        	$email = strtolower($email);
    
            $dbh = DB::select("SELECT id, is_active, confirm_code FROM ".TB_USERS."
                              WHERE email='".$email."' AND password='".md5($email.$password)."' LIMIT 1");
    ...
    // Замечу что $email и $password получены при помощи мега крутой функции http://govnokod.ru/5901
    
     public static function get($mode = 0, $role = 0)
        {
            $result = false;
    
            list ($session_id, $user_id) = self::getcookie();
    
            if(!empty($session_id))
            {
                self::$id = $session_id;
    
                $dbh = DB::select("SELECT u.email, u.role FROM ".TB_SESSION." AS s LEFT JOIN ".TB_USERS." AS u ON s.user_id=u.id
                                  WHERE s.id='".$session_id."' AND s.user_id=".$user_id.($role > 0 ? " AND u.role&".$role : "")." LIMIT 1");
    ...
    
    protected static function getcookie()
        {
            $parts = explode(BOUND, (isset($_COOKIE[self::$name]) ? $_COOKIE[self::$name] : ""));
    
            if(sizeof($parts) != 2)
            {
                $parts = array("", 0);
            }
            else
            {
                $parts[0] = encode($parts[0]);
                $parts[1] = (int)$parts[1];
            }
    
            return $parts;
        }
    
    // А вот и encode
    function encode($value, $html_encode = true)
    {
        $value = trim((string)$value);
    
        if(empty($value)) return false;
    
        if($html_encode)
        {
            $value = htmlspecialchars($value, ENT_QUOTES);
        }
    
        $search  = array('/"/', "/'/", "/\\\\&quot;/", "/\\\\&#039;/", "/<\?/", "/\?>/");
        $replace = array("&quot;", "&#039;", "&quot;", "&#039;", "&lt;?", "?&gt;");
    
        return preg_replace($search, $replace, $value);
    }

    Улыбнула третья строка.

    winbackgo, 06 Марта 2011

    Комментарии (6)
  7. Pascal / Говнокод #5902

    +92

    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
    procedure TForm1.Button1Click(Sender: TObject);
    var
    outfi:string;
    begin
      if OpenDialog1.Execute then
      begin
      outfi:=sysutils.ExtractFilePath((OpenDialog1.FileName))+'/program.asm';
      windows.CreateFile(PChar(outfi),0,0,0,0,0,0);
      AssignFile(outPutFile,outfi);
      Rewrite(outPutFile);
      Append(outPutFile);
      AssignFile(inPutFile,OpenDialog1.FileName);
      Reset(inPutFile);
      init();
      writeLn(outPutFile,prologMemo.Lines.GetText());
     
      doprogram();
     
      writeLn(outPutFile,epilogMemo.Lines.GetText());
     
      CloseFile(outPutFile);
      CloseFile(inPutFile);
      ShellExecute( 0, 'open', PChar(outfi), nil, nil, SW_SHOWNORMAL);
      end;
    end;

    bugmenot, 06 Марта 2011

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

    +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
    20. 20
    /**
     * Возвращает значение поля формы.
     * @param[in] name as string. Имя поля формы.
     * @return mixed
     */
    function GetItem($name)
    {
        $value = "";
    
        if(isset($_POST[$name]))
        {
            $value = $_POST[$name];
        }
        else if(isset($_GET[$name]))
        {
            $value = $_GET[$name];
        }
    
        return $value;
    }

    winbackgo, 06 Марта 2011

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

    +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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    const mime_list = array("any"   => "7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip|ico",
                                "image" => "jpg|jpeg|gif|png|ico",
                                "flash" => "swf|flv",
                                "xml"   => "xml",
                                "price" => "txt|csv");
    
    // далее из того же класса
    public function is_mime_valid($realtype, $needtype = "any")
        {
            $realtype = trim($realtype);
    
            if(empty($realtype) || !isset($this->mime_list[$needtype])
               || !preg_match("/(".self::mime_list[$needtype].")/i", $realtype))
               return false;
    
            return true;
        }
    // конструктора там нет и никакой $this->mime_list не специализируется

    winbackgo, 06 Марта 2011

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

    +171

    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
    void Cryptogram(const vector<string> &vector1, vector<string> &vector2)
    {
      string word;
      char new_letter;
      long i, j, wordSize, vecSize, vecSize2;
      vecSize = vector1.size();
      for(j=0; j<vecSize; j++)
        {
          word = vector1[j];
          //cout<<word<<endl;
          wordSize = word.size();
          cout<<wordSize<<endl;
          for(i=0; i<wordSize; i++)
      {
        new_letter = word[i];
        cout<<"& " << new_letter<< " " << isalpha(new_letter) << endl;
        if(isalpha(new_letter)==true)
          {
            if(isupper(new_letter)==true)
        {
    
          if (new_letter == 'A')
            new_letter = 'W';
          else if(new_letter == 'B')
            new_letter = 'Y';
          else if(new_letter == 'C')
            new_letter = 'I';
          else if(new_letter == 'D')
            new_letter = 'J';
          else if(new_letter == 'E')
            new_letter = 'K';
          else if(new_letter == 'F')
            new_letter = 'C';
          else if(new_letter == 'G')
            new_letter = 'U';
          else if(new_letter == 'H')
            new_letter = 'V';
          else if(new_letter == 'I')
            new_letter = 'D';
          else if(new_letter == 'J')
            new_letter = 'P';
          else if(new_letter == 'K')
            new_letter = 'Q';
          else if(new_letter == 'L')
            new_letter = 'L';
          else if(new_letter == 'M')
            new_letter = 'Z';
          else if(new_letter == 'N')
            new_letter = 'H';
          else if(new_letter == 'O')
    
            new_letter = 'T';
          else if(new_letter == 'P')
            new_letter = 'G';
          else if(new_letter == 'Q')
            new_letter = 'A';
          else if(new_letter == 'R')
            new_letter = 'B';
          else if(new_letter == 'S')
            new_letter = 'M';
          else if(new_letter == 'T')
            new_letter = 'X';
          else if(new_letter == 'U')
            new_letter = 'E';
          else if(new_letter == 'V')
            new_letter = 'F';
          else if(new_letter == 'W')
            new_letter = 'O';
          else if(new_letter == 'X')
            new_letter = 'N';
          else if(new_letter == 'Y')
            new_letter = 'R';
          else if(new_letter == 'Z')
            new_letter = 'S';
        }

    Cryptogram function, it's much longer, with 26 if statements if the letter is lowercase.

    BigEndian, 06 Марта 2011

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