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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function showEntry($name)
    {
        if(empty($name))
        {
             return false;
             break;
        }
    ...
    }

    123qweasdzxc, 30 Августа 2011

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

    +168

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?php  
    function makestime($string) {  
    
    $day=floor($string/86400);  
    $hours=floor(($string/3600)-$day*24);  
    $min=floor(($string-$hours*3600-$day*86400)/60);  
    $sec=$string-($min*60+$hours*3600+$day*86400);  
    
    return $day.' дн. '.$hours.':'.$min.':'.$sec;  
    }  
    ?>

    Перевод секунд в дни
    Функция из WAP-MotoR CMS.
    Воистину, язык программирования дат.

    7ion, 30 Августа 2011

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

    +168

    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
    Функция Антимата
    
    
    <?php  
    //Маты записываёте в antmat.dat 
    function antimat($msg) {  
    if (file_exists("antimat.dat")) {  
    $mat = file_get_contents("antimat.dat");  
    $arr_mat = explode("|",$mat);  
    foreach($arr_mat as $value) {  
    if($value != "") {  
    $msg = preg_replace("|$value|iu","***",$msg);  
    }}}  
    return $msg;  
    }  
    ?>

    И заходишь на любой форум про похапе
    @
    И копируешь на говнокод всю тему "полезные функции"

    7ion, 30 Августа 2011

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

    +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
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    <?php 
    function crypt_apr1_md5($plainpasswd) { 
        $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8); 
        $len = strlen($plainpasswd); 
        $text = $plainpasswd.'$apr1$'.$salt; 
        $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd)); 
        for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); } 
        for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; } 
        $bin = pack("H32", md5($text)); 
        for($i = 0; $i < 1000; $i++) { 
            $new = ($i & 1) ? $plainpasswd : $bin; 
            if ($i % 3) $new .= $salt; 
            if ($i % 7) $new .= $plainpasswd; 
            $new .= ($i & 1) ? $bin : $plainpasswd; 
            $bin = pack("H32", md5($new)); 
        } 
        for ($i = 0; $i < 5; $i++) { 
            $k = $i + 6; 
            $j = $i + 12; 
            if ($j == 16) $j = 5; 
            $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp; 
        } 
        $tmp = chr(0).chr(0).$bin[11].$tmp; 
        $tmp = strtr(strrev(substr(base64_encode($tmp), 2)), 
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 
        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); 
        return "$"."apr1"."$".$salt."$".$tmp; 
    } 
    ?>

    Кручу-верчу, запутать хочу!

    7ion, 30 Августа 2011

    Комментарии (4)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)