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

    +144

    1. 1
    $

    TarasGovno, 04 Января 2012

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

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    class Mysql_class {
    
      function get_row($query) {
        $sql_query = mysql_query($query) or exit(mysql_error());
        return mysql_fetch_array($sql_query);
      }
    
      function single_query($query) {
        if (mysql_query($query)) return true;
        else return mysql_error();
      }
    }

    2011-й год, прототип класса для работы с базой данных ( http://www.askdev.ru/q/8552 )

    demotivator, 04 Января 2012

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

    +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
    exec(" cd $dir; ls -al|grep '^d';",$file_all);
      	//die(" cd $dir; ls -al|grep '^d';");
      	$filelist_date = array();
      	
      	for($i=0;$i<count($file_all);$i++) {
      		$file_all[$i] = preg_replace('/\s+/','|',$file_all[$i]);
      		
      		$file_all[$i] = explode('|',$file_all[$i],9);
      		if(!empty($file_all[$i][8])) $file_all[$i][8] = str_replace('|',' ',$file_all[$i][8]);
      		
      		//print_r($file_all[$i]); echo "\n\n";
      		if($file_all[$i][8] == '.' || $file_all[$i][8] == '..') continue;
      		
      		$k = strtotime($file_all[$i][5]." ".$file_all[$i][6]." ".$file_all[$i][7]);
      		$filelist_date[$k] = $file_all[$i][8];
      	}
      	krsort($filelist_date);
      	
      	$filelist = array_values($filelist_date);

    этот кусок кода выполняет начитку директорий фото галерей

    kolexander, 04 Января 2012

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

    +155

    1. 1
    2. 2
    3. 3
    $string = "http://site.ru/1/";
    if(get_magic_quotes_runtime()) $string = stripslashes($string);
    $query = "INSERT INTO `table` (`col1`,`col2`) VALUES ('$string','0');"

    В довольно таки популярном враппере для работы с субд мускуля...

    govnophp, 04 Января 2012

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

    +152

    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
    if($sedit){
    	switch ($action) {
    	case 'insert':
    		sectionInsert($structure);
    		insertMessage($_page['right_bottom'],L_MESSAGE_ADD_OK);
    		sectionInsertForm($_page['right_top'],$structure);
    		sectionList($out,$structure,$_page[FIELD_ID],$sedit);
    		$_page['bookmark_1']['content'] = L_INSERT_SECTION;
    		$_page['bookmark_1']['style'] = 'bookmark_selected';
    		$_page['bookmark_1']['url'] = URL_STRUCTURE_EDIT.'?sedit=1';
    		break;
    	case 'delete':
    		$structure->deleteBranch($_POST[FIELD_ID]);
    		insertMessage($_page['right_bottom'],L_MESSAGE_DELETE_OK);
    		sectionInsertForm($_page['right_top'],$structure);
    		sectionList($out,$structure,$_page[FIELD_ID],$sedit);
    		$_page['bookmark_1']['content'] = L_INSERT_SECTION;
    		$_page['bookmark_1']['style'] = 'bookmark';
    		$_page['bookmark_1']['url'] = URL_STRUCTURE_EDIT.'?sedit=1';
    		break;
    	case 'update':
    		sectionUpdate($structure);
    		insertMessage($_page['right_bottom'],L_MESSAGE_CHANGE_OK);
    		sectionInsertForm($_page['right_top'],$structure,$_page[FIELD_ID]);
    		sectionList($out,$structure,$_page[FIELD_ID],$sedit);
    		$_page['bookmark_1']['content'] = L_INSERT_SECTION;
    		$_page['bookmark_1']['style'] = 'bookmark';
    		$_page['bookmark_1']['url'] = URL_STRUCTURE_EDIT.'?sedit=1';
    		break;
    	case 'add_form':
    		sectionInsertForm($_page['right_top'],$structure);
    		sectionList($out,$structure,$_page[FIELD_ID],$sedit);
    		$_page['bookmark_1']['content'] = L_INSERT_SECTION;
    		$_page['bookmark_1']['style'] = 'bookmark_selected';
    		$_page['bookmark_1']['url'] = URL_STRUCTURE_EDIT.'?sedit=1';
    		break;
    	default:
    		sectionInsertForm($_page['right_top'],$structure,$_page[FIELD_ID]);
    		sectionList($out,$structure,$_page[FIELD_ID],$sedit);
    		$_page['bookmark_1']['content'] = L_INSERT_SECTION;
    		$_page['bookmark_1']['style'] = 'bookmark';
    		$_page['bookmark_1']['url'] = URL_STRUCTURE_EDIT.'?sedit=1';
    		break;
    	}
    } else{//режим редактора контента
    	switch ($action) {
    	case 'insert':
    		break;
    	case 'delete':
    		break;
    	case 'edit':
    		break;
    	case 'move':
    		break;
    	case 'update':
    		break;
    	default:
    		sectionList($out,$structure,$_page[FIELD_ID]);
    		break;
    	}
    }

    Из одной самопальной цмс.

    kyzi007, 04 Января 2012

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <?php
    @fwrite($fp, "<?php
    \$config['dbhost'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbhost'])))."\";
    \$config['dbuser'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbuser'])))."\";
    \$config['dbpass'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbpass'])))."\";
    \$config['dbname'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbname'])))."\";
    \$config['dbpref'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbprefix'])))."\";
    ?>");
    ?>

    avecms нах.

    TBoolean, 19 Декабря 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $res = $db -> select('SELECT * FROM table_a');
    foreach ($res as $k => $row)
    {
        $res[$k]['field_bb'] = $db -> selectRow('SELECT field_bb FROM table_b WHERE p_id = ?', $row['p_id']);
    }

    Человек видимо не знал про JOIN

    Shitafaka, 19 Декабря 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!empty($errors)) {
    	return $errors;
    } else {
    	return array();
    }

    $errors это массив ошибок

    ghost404, 19 Декабря 2011

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    if(!$this->result = $this->dbo->query($this->sql))
    {
       throw new Exception('Error Query: '. $this->sql);
    }

    Ооо я знаю про исключения...

    Sulik78, 19 Декабря 2011

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

    +168

    1. 1
    preg_match('/(.*?)[.,!|]/',ltrim(preg_replace('/[\n\r]+/','|',strip_tags($item[$this->tooltip])),'|'),$regs);

    жонглирование регулярками

    Lure Of Chaos, 18 Декабря 2011

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