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

    +146

    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
    <?php
    define('STOCK_URL', 'http://govnokod.ru/comments');
    define('REFERER_URL', 'http://govnokod.ru/');
    define('AUTH_COOKIES', 'a:2:{s:9:"PHPSESSID";s:26:"k719c8rqcm85dptista7b7rck7";s:4:"auth";s:32:"0ce5a7d54092aa07e37b88ffbe098135";}');
    define('MODERATED_TEXT', '[color=red][i]Слава «Беркуту»![/i][/color]');
    define('DEFAULT_UA', 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.16');
    define('POST_HEADERS', "X-Requested-With: XMLHttpRequest\r\nContent-Type: application/x-www-form-urlencoded\r\n");
    define('PONY1', "//ol[@class='posts hatom']/li/h2/a");
    define('PONY2', "//form/div/input[@name='_csrf_token']");
    define('PONY3', "//li[@class='hcomment']/div/a[@class='edit-comment-link']");
    
    function myCookies() {
    	$map_cookies = function($k, $v) {return $k . '='. $v;};
    	return implode('; ', array_map($map_cookies, array_keys(unserialize(AUTH_COOKIES)), unserialize(AUTH_COOKIES)));
    }
    
    function huyarim($url, $referer, $mask, $attr) {
    	$context_options = stream_context_create(array('http' => array(
    	  'method' => 'GET',
    	  'user_agent' => DEFAULT_UA,
    	  'header' => 'Referer: '. $referer . "\r\n" . 'Cookie: ' . myCookies()
    	)));
    	$links = array();
    	$file = @file_get_contents($url, false, $context_options);
    	if ($file) {
    	  $old_libxml_error = libxml_use_internal_errors(true);
    	  $dom = new DOMDocument;
     	  $dom->loadHTML($file);
    	  libxml_use_internal_errors($old_libxml_error);
     	  $domxpath = new DOMXPath($dom);
     	  $filtered = $domxpath->query($mask);
    	  foreach ($filtered as $item) {
    		$links[] = $item->getAttribute($attr);
    	  }
    	}  
    	return $links;
    }
    
    function getList() {return huyarim(STOCK_URL, REFERER_URL, PONY1, 'href');}
    function getCsrf($url) {$tokens = huyarim($url, STOCK_URL, PONY2, 'value'); return $tokens[0];}
    function getComments($url) {return huyarim($url, STOCK_URL, PONY3, 'href');}
    
    function doPost($url, $referer, $token) {
    	$postdata = http_build_query(array(
    	  '_csrf_token' => $token,
    	  'text' => MODERATED_TEXT,
    	  'commentSubmit' => 'Отправить комментарий [Ctrl+Enter]',
    	  'ajax' => 'true'
     	));
    	$context_options = stream_context_create(array('http' => array(
    	  'protocol_version' => 1.1,
    	  'method' => 'POST',
    	  'user_agent' => DEFAULT_UA,
    	  'header' => POST_HEADERS . 'Referer: '. $referer . "\r\n" . 'Cookie: ' . myCookies(),
    	  'content' => $postdata
    	)));
    	return file_get_contents($url, false, $context_options);
    }
    
    $links = getList();
    foreach($links as $link) {
    	$token = getCsrf($link);
    	$comments = getComments($link);
    	foreach($comments as $comment) {
    		if (false !== doPost($comment, $link, $token)) {
    			echo $comment . ' OK' . PHP_EOL;
    		}
    	}
    }

    CURL и PECL_HTTP не нужны. Да, и ООП тоже не нужно.

    inkanus-gray, 19 Февраля 2014

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

    +160

    1. 1
    <a href="javascript:;" class="detail_back_link" ahref="/services_catalog/appl_list.php?SECTION=<?=$arResult["Block"]["ID"]?>"></a>

    Добавить атрибут ahref к тегу <a> ??? Фантазер-разработчик. И написать href="javascript:;"........
    Караул.

    ben, 19 Февраля 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $background_nid = _get_last_section_background($node);
    $new_background_nid = ($background_nid == 47)?48:47;
    $background_color = db_query("SELECT field_background_color_value FROM {field_revision_field_background_color} WHERE entity_id=:nid AND entity_type='node'", array(":nid" => $new_background_nid))->fetchField();
    $style_background = "background-color: #".$background_color."; ";

    Изысканное получение node id в Drupal

    valllllera, 18 Февраля 2014

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

    +171

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if($pos === false){
    $true = true;
    }
    else{
    $true = false;
    }
    if($true){ /* тут код */ }

    Просто оставлю это здесь.

    dbepcepk, 17 Февраля 2014

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

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $synonyms = array(
        1 => 'once',
        2 => 'twice',
        3 => 'three times',
        4 => 'four times',
        5 => 'five times',
        6 => 'six times',
        7 => 'seven times',
        8 => 'eight times',
        9 => 'nine times',
        10 => 'ten times',
    );

    Dima, ты лучший!;)

    valllllera, 14 Февраля 2014

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

    +155

    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
    function compileStr($arrStrings) {
    	if (is_array($arrStrings)) {
    		$part1 = 'a:2:{s:5:"VALUE";a:';
    		$part2 = 's:11:"DESCRIPTION";a:';
    		$part3 = '}';
    
    		$ornums = array();
    
    		foreach ($arrStrings as $str) {
    			$exp = explode(",", str_replace(" ", "", $str));
    			$ornums = array_merge($ornums, $exp);
    		}
    
    		$ecount = count($ornums);
    		$s1 = $ecount.':{';
    		$s2 = $ecount.':{';
    
    		for ($i = 0; $i < $ecount; $i++) {
    			$s1 .= 'i:'.$i.';s:'.strlen($ornums[$i]).':"'.$ornums[$i].'";';
    			$s2 .= 'i:'.$i.';s:0:"";';
    		}
    
    		$s1 .= '}';
    		$s2 .= '}';
    
    		$result = $part1.$s1.$part2.$s2.$part3;
    		return $result;
    	}
    }

    Нашел в дебрях проекта. Писать php-сериализатор на php - это концептуально )))
    если кто не понял функция делает вот это:
    if (is_array($arrStrings)) {
    $ornums = explode(',', implode(',', str_replace(' ', '', $arrStrings)));
    return serialize(array("VALUE" => $ornums, "DESCRIPTION" => array_fill(0, count($ornums), '')));
    }

    Homess, 14 Февраля 2014

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

    +153

    1. 1
    $rec_area=sql2arr2('select om,alr from omolog where omvis=1');

    названия полей и таблицы

    govnomes, 14 Февраля 2014

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    class Z {
       public function __toString() { return 'zzzzzzzz'; }
    }
    
     $zz = array();
     $zz[call_user_func_array('sprintf', array('%s', new Z))] = 1;

    нахуй так жить?

    __proto__, 13 Февраля 2014

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

    +151

    1. 1
    2. 2
    3. 3
    error_reporting( 0 );
    
    unset( $x[new XSLTProcessor()][new RecursiveArrayIterator()] );

    __proto__, 13 Февраля 2014

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

    +138

    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
    private function toDBFields($fields){
    			$db_fields = array();
    			if ($fields){
    				foreach($fields as $field){
    					switch ($field){
    
                            case 'p_bits':
                                if (!array_search('b1',$db_fields))	$db_fields[] = 'b1';
                                break;
                            case 'n2':
                                if (!array_search('b1',$db_fields))	$db_fields[] = 'b1';
                                break;
                            case 'n1':
                                if (!array_search('b1',$db_fields))	$db_fields[] = 'b1';
                                break;
    						case 'cntdf':
    							if (!array_search('cntdf',$db_fields))	$db_fields[] = 'cntdf';
    							break;
    						case 'first_pckg':
    						
    							break;
    						case 'az':
    							if (!array_search('az',$db_fields))		$db_fields[] = 'az';
    							break;
    						case 'akb_v':
    							//if (!array_search('b2',$db_fields))		$db_fields[] = 'b2';
    							if (!array_search('b3',$db_fields))		$db_fields[] = 'b3';
    							break;
    						case 'p1code':
                            case 'ignition_ap1':
    							if (!array_search('b4',$db_fields))		$db_fields[] = 'b4';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
    						case 'fuel_p2':
                            case 'fuel_p2_debug':
                            case 'p2code':
    							if (!array_search('b5',$db_fields))		$db_fields[] = 'b5';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
                            case 'fuel_p3':
                            case 'fuel_p3_debug':
    						case 'p3code':
                            case 'p3code_debug':
    							if (!array_search('b7',$db_fields))		$db_fields[] = 'b7';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
                            case 'fuel_p3p4_2drt':
                                if (!array_search('b8',$db_fields))		$db_fields[] = 'b8';
    							if (!array_search('b7',$db_fields))		$db_fields[] = 'b7';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
                            case 'fuel_p2p3':
                                if (!array_search('b5',$db_fields))		$db_fields[] = 'b5';
    							if (!array_search('b7',$db_fields))		$db_fields[] = 'b7';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
                            case 'fuel_p4':
                            case 'p4code_debug':
    						case 'p4code':
    							if (!array_search('b8',$db_fields))		$db_fields[] = 'b8';
    							if (!array_search('b6',$db_fields))		$db_fields[] = 'b6';
    							break;
    					}
    				}
    			}
    
    			return $db_fields;

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

    Deimm, 13 Февраля 2014

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