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

    +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
    public function get($module, $fields, $options=null) {
            $results = $this->get_with_related($module, array($module => $fields), $options);
            $records = array();
            if ($records) {
                foreach ($results['entry_list'] as $entry) {
                    $record = array();
                    foreach ($entry['name_value_list'] as $field) {
                        $record[$field['name']] = $field['value'];
                    }
                    $records[] = $record;
                }
            }
            return $records;
        }

    SugarCRM REST API Class https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class/blob/master/sugar_rest.php

    stark, 30 Августа 2011

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

    +156

    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
    /**
     * форматирование даты - преобразует дату в формат ДД-ММ-ГГГГ
     *
     * @param unknown_type $inDate - дата
     * @return unknown
     */
    public static function getDateFormatted($inDate, $forView = false, $inTime = '') {
    	//2011-05-03 20:27:26
    	
    	$a_tmp = explode(' ', $inDate);
    	if ($forView) {
    		$time = substr($a_tmp[1], 0, 5);
    		if ($a_tmp[0] == date('Y-m-d')) {
    			if ($time == '') {
    				$time = substr($inTime, 11, 5);
    				if ($time == '') {
    					$time = $inTime;
    				}
    			}
    			if ($time != '') {
    				return 'Сегодня, ' . $time;
    			}
    		}
    
    		$a_tmp = explode('-', $a_tmp[0]);
    
    		return $a_tmp[2] . '-' . $a_tmp[1] . '-' . $a_tmp[0];
    	}
    
    	$inDate = substr($inDate, 0 , 10);
    	$inDate = str_replace(' ', '', $inDate);
    	$inDate = str_replace('.', '-', $inDate);
    
    	$a_tmp = explode('-', $inDate);
    	if (strlen($a_tmp[0]) == 4) {
    		$inDate = str_pad($a_tmp[2], 2, '0', STR_PAD_LEFT) . '-' . $a_tmp[1] . '-' . $a_tmp[0];
    	}
    	return $inDate;
    }

    Sers, 30 Августа 2011

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

    +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
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $name = $_POST['name'];
    $famname = $_POST['famname'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date('Y-m-d [H:i:s]');
    
    if($_GET['reg'] == 'good' && $email!="" && $name!="" && $famname!="" && $pass!="" ) {
         if(!@mysql_connect('localhost', 'root', '')) {
              echo 'ѥ䩱򰠶鿠㱥񻑭塤ﲲ󯭠';
              exit();
         }
         mysql_select_db('efimov');
         $number = 0;
         $query = "select count(uid) as c from users";
         $res = mysql_query($query);
         while($row = mysql_fetch_array($res)) {
              $number = $row['c'] + 1;
         }	
         if(mysql_query("insert into users values ('$number', '$name','$famname','$email','$pass','$ip','$date')")) { 
              echo "$name, hello"; 
         }
    }
    echo '<script type="text/javascript">'.
    'alert("fuuu")'.
    '</script>';

    Регистрация пользователя ;)

    substr, 30 Августа 2011

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

    +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
    /*
    	Функция для парсинга CSV файла. 
    	Автор: Федорченко Антон Александрович ([email protected], http://sites.neeweb.com/antfsite)
    	
    	Возвращает двумерный массив:
    		array(
    			array ( ... )	//Строка 1
    			array ( ... )	//Строка 2
    			...
    			array ( ... )	//Строка n
    			)
    */
    
    function parse_csv($filename, $codepage = 'windows-1251') {
        $csv_lines  = file($filename);
        $skip_char = false;
        $column = '';
        if (is_array($csv_lines)) {
            $cnt = count($csv_lines);
            for($i = 0; $i < $cnt; $i++) {
                $line = trim($csv_lines[$i]);
                $first_char = true;
                $col_num = 0;
                $length = strlen($line);
                for ($b = 0; $b < $length; $b ++) {
                    if ($skip_char != true) {
                        $process = true;
                        if ($first_char == true) {
                            if($line[$b] == '"') {
                                $terminator = '";';
                                $process = false;
                            } else {
                                $terminator = ';';
                            }
                            $first_char = false;
                        }
                        if ($line[$b] == '"') {
                            $next_char = $line[$b + 1];
                            if ($next_char == '"') {
                                $skip_char = true;
                            } elseif ($next_char == ';') {
                                if($terminator == '";') {
                                    $first_char = true;
                                    $process = false;
                                    $skip_char = true;
                                }
                            }
                        }
                        if ($process == true) {
                            if ($line[$b] == ';') {
                                if ($terminator == ';') {
                                    $first_char = true;
                                    $process = false;
                                }
                            }
                        }
                        if ($process == true) $column .= $line[$b];
                        if ($b == ($length - 1)) $first_char = true;
                        if ($first_char == true) {
                            $values[$i][$col_num] = $column;
                            $column = '';
                            $col_num ++;
                        }
                    } else {
                        $skip_char = false;
                    }
                }
            }
        }
        if (strtolower($codepage) != "utf-8") {
            foreach ($values as $lineIndex => $line) {
                foreach ($line as $cellIndex => $cell) $values[$lineIndex][$cellIndex] = iconv($codepage, "UTF-8", $cell);
            }
        }
        return $values;
    }

    Жаль, не пришло в голову запостить сразу - ОНО ещё и неотворматировано было.
    Антон Александрович - мощный дядька =)

    cybervantyz, 30 Августа 2011

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

    +165

    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
    function show_price_list() {
    		$period_1 = $period_2 = $period_3 = $period_4 = $period_5 = $period_6 = "";
    		$query = "
    				SELECT id, price, type
    				FROM price 
    				ORDER BY type, start
    			";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			foreach ($this->registry['sql']->getFetchObject() as $oRow) {
    				switch($oRow->type) {
    					case 0: $period_1 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 1: $period_2 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 2: $period_3 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 3: $period_4 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 4: $period_5 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 5: $period_6 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    				}
    			}
    		}
    		@$this->registry['template']->set('period_1', $period_1);
    		@$this->registry['template']->set('period_2', $period_2);
    		@$this->registry['template']->set('period_3', $period_3);
    		@$this->registry['template']->set('period_4', $period_4);
    		@$this->registry['template']->set('period_5', $period_5);
    		@$this->registry['template']->set('period_6', $period_6);
    	}

    Модель в шаблоне MVC

    vkontakte, 30 Августа 2011

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

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (strlen($_POST["NEW_PASSWORD"]) <= 0)
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_FLAG1");
    
    				if (strlen($_POST["NEW_PASSWORD"]) > 0 && strlen($_POST["NEW_PASSWORD_CONFIRM"]) <= 0)
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_FLAG1");
    
    				if (strlen($_POST["NEW_PASSWORD"]) > 0
    					&& strlen($_POST["NEW_PASSWORD_CONFIRM"]) > 0
    					&& $_POST["NEW_PASSWORD"] != $_POST["NEW_PASSWORD_CONFIRM"])
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_PASS");

    Взято из Битрикса /bitrix/components/bitrix/sale.order.ajax/component.php

    Потрясающие идентификаторы мессаджей. Ну а то, что прочитать код без слома глаз нельзя отдельная песня.
    В целом там такого внутри много.

    zima, 29 Августа 2011

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

    +175

    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
    function get_user_name($id) {
    		$query = "
    			SELECT name
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->name;
    		}
    	}
    	
    	function get_user_login($id) {
    		$query = "
    			SELECT login
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->login;
    		}
    	}
    	
    	function get_user_password($id) {
    		$query = "
    			SELECT password
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->password;
    		}
    	}
    	
    	function get_user_role($id) {
    		$query = "
    			SELECT role
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->role;
    		}
    	}
    	
    	function get_user_adress($id) {
    		$query = "
    			SELECT adress
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->adress;
    		}
    	}
    	
    	function get_user_valuta($id) {
    		$query = "
    			SELECT valuta
    			FROM users 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->valuta;
    		}
    	}
    	
    	function get_room_type($id){
    		$query = "
    			SELECT type
    			FROM rooms 
    			WHERE id = '".$id."'
    		";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			$result = $this->registry['sql']->getFetchObject();
    			return $result[0]->type;
    		}	
    	}

    в догонку к Говнокод #7684

    vkontakte, 29 Августа 2011

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

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function get_field_by_id($tbl,$field,$id){ //получить field по id
    	$res=mysql_query($v="SELECT * FROM $tbl where `id`=$id");
    	$rez=mysql_fetch_array($res);
    	return $rez["$field"];
    }

    De-Luxis, 29 Августа 2011

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

    +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
    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
    // Достаем данные переданные с формы
     $name=$_POST['name'];
     $title=$_POST['title'];
     $titlepage=$_POST['titlepage'];
     $titletext=$_POST['titletext'];
     $textarea=$_POST['textarea'];
     //путь и сам файл
     $file="/pages/".$name.".html";
     //если файла нету создаем новый, записываем туда информормацию
     if(!file_exists($file)) {
     $fp=fopen($file, "a");
     $fp=fwrite($file, "<html>");
     $fp=fwrite($file, "<head>");
     $fp=fwrite($file, "<title>".$name."</title>");
     $fp=fwrite($file, "<link rel='stylesheet' href='style.css' type='text/css'>");
     $fp=fwrite($file, "</head>");
     $fp=fwrite($file, "<body>");
     $fp=fwrite($file, "<div id='container'>");
     $fp=fwrite($file, "<div id='header'>".$titlepage."</div>");
     $fp=fwrite($file, "<div id='sidebar'>");
     $fp=fwrite($file, "<p><a href='about.html'>О сайте</a></p>");
     $fp=fwrite($file, "<p><a href='faq.html'>FAQ</a></p>");
     $fp=fwrite($file, "<p><a href='articles.php'>Статьи</a></p>");
     $fp=fwrite($file, "<p><a href='services.html'>Сервисы</a></p>");
     $fp=fwrite($file, "</div>");
     $fp=fwrite($file, "<dic id='content'>");
     $fp=fwrite($file, "<p>".$textarea."</p>");
     $fp=fwrite($file, "<div id='footer'>Игорь Дудкин. Все права защищены</div>");
     $fp=fwrite($file, "</div>");
     $fp=fwrite($file, "</body>");
     $fp=fwrite($file, "</html>");
     fclose ($fp);
     }

    Слова автора: "я создал скрипт, который создает страницы html со статьями в спец папке pages".
    просто facepalm))

    invision70, 29 Августа 2011

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

    +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
    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
    function str_from_translit($st)
    {
    
    
        $trans = array(
            "a" => "а",
            "b" => "б",
            "v" => "в",
            "g" => "г",
            "d" => "д",
            "e" => "е",
            "j" => "ж",
            "z" => "з",
            "i" => "и",
            "k" => "к",
            "l" => "л",
            "m" => "м",
            "n" => "н",
            "o" => "о",
            "p" => "п",
            "r" => "р",
            "s" => "с",
            "t" => "т",
            "y" => "у",
            "f" => "ф",
            "h" => "х",
            "c" => "ц",
            "ch" => "ч",
            "sh" => "ш",
            "sh" => "щ",
            "A" => "А",
            "B" => "Б",
            "V" => "В",
            "G" => "Г",
            "D" => "Д",
            "E" => "Е",
            "J" => "Ж",
            "Z" => "З",
            "I" => "И",
            "K" => "К",
            "L" => "Л",
            "M" => "М",
            "N" => "Н",
            "O" => "О",
            "P" => "П",
            "R" => "Р",
            "S" => "С",
            "T" => "Т",
            "Y" => "У",
            "F" => "Ф",
            "H" => "Х",
            "C" => "Ц",
        );
        return strtr($st, $trans);
    }

    amerov, 27 Августа 2011

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