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

    +1502

    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
    if(isset($db_array["reference"]) && is_array($db_array["reference"]))
    		$ref = $db_array["reference"];
    	elseif(isset($db_array["REFERENCE"]) && is_array($db_array["REFERENCE"]))
    		$ref = $db_array["REFERENCE"];
    	else
    		$ref = array();
    
    	if(isset($db_array["reference_id"]) && is_array($db_array["reference_id"]))
    		$ref_id = $db_array["reference_id"];
    	elseif(isset($db_array["REFERENCE_ID"]) && is_array($db_array["REFERENCE_ID"]))
    		$ref_id = $db_array["REFERENCE_ID"];
    	else
    		$ref_id = array();

    bitrix/modules/main/tools.php:182

    maxyc, 25 Августа 2016

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

    +1913

    1. 1
    2. 2
    if(!empty($_REQUEST['action_button']))
    			$_REQUEST['action'] = $_REQUEST['action_button'];

    bitrix/modules/main/interface/admin_lib.php:3320

    maxyc, 25 Августа 2016

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

    +1487

    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
    app::storage()->setUserUploadDir('public');
            app::storage()->avatar = 'profile/avatars';
            app::storage()->background = 'profile/background';
            app::storage()->audioFile = 'music';
            app::storage()->videoFile = 'video/file';
            app::storage()->videoScreen = 'video/screen';
            app::storage()->forum = 'forum';
            app::storage()->systemImages = 'system/images';
            app::storage()->tmpUpload('upload');
     
     
            app::storage()->registerMethod('avatar', function($id, $type = false)
            {
     
                if($type==true){
                    return app::storage()->fileExists(app::storage()->path('avatar').'/'.$id.'.png') ?  '/'.app::storage()->path('avatar').'/'.$id.'.png' : null;
     
                }else{
                    return '/'.app::storage()->path('avatar').'/'.$id.'.png';
     
                }
            } );
     
            app::storage()->registerMethod('defaultAvatar', function()
            {
     
                    return '/'.app::storage()->path('systemImages').'/noavatar.png';
     
            } );

    Загрузка файлов от программиста с двадцатилетним стажем.

    pravka, 24 Августа 2016

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

    +545

    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
    <?php
    /**
     * Объединяет массивы, сохраняя элементы присутствующие лишь в одном из массивов
     * + сортирует без сохранения ключей
     * @param array $a1
     * @param array $a2
     * @return array
     */
    function array_xor_merge($a1, $a2) {
    	$allr	 = array_merge($a1, $a2);
    	$allp	 = array_flip($allr);
    	foreach (array_count_values($allr) as $key => $cnt) {
    		if ($cnt > 1) {
    			unset($allp[$key]);
    		}
    	}
    	$res = array_flip($allp);
    	sort($res);
    	return $res;
    }

    Rijen, 22 Августа 2016

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

    +451

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    const CHANGE_TYPE_ADD        = 'add';//add elem in groups
        const CHANGE_TYPE_CHANGE    = 'change';//add elem
        const CHANGE_TYPE_RECHANGE    = 'rechange';//edit elem
        const CHANGE_TYPE_EDIT        = 'edit';//delete element from groups
        const CHANGE_TYPE_DEL        = 'del';//delete element

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

    _dk, 19 Августа 2016

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

    +313

    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
    <?php
    
    use PHPUnit\Framework\TestCase;
    
    class SecurityTokenTest extends TestCase
    {
    
        /**
         * @dataProvider getData
         */
        public function testGetCookieToken($user, $token, $result)
        {
            $reflect = new \ReflectionClass('AppBundle\Security\TokenCookieStorage');
            /** @var TokenCookieStorage $storage */
            $storage = $reflect->newInstanceWithoutConstructor();
    
            $reflect->getProperty('abstractUser')
                ->setValue($storage, $user);
            $reflect->getProperty('cookieDriver')
                ->setValue($storage, new class($token) {
                    public $token;
    
                    public function __construct($token)
                    {
                        $this->token = $token;
                    }
    
                    public function get($id)
                    {
                        return ($id) ? $this->token : null;
                    }
                });
    
            $this->assertSame($storage->getToken(), $result);
        }
    
    ....

    PHPUnit. Тяжело написать тесты для говнокода. Чувак не слышал про mockbuilder

    konmado, 19 Августа 2016

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

    +314

    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
    <?php
    require 'classes/_func.class.php';
    $func = new func();
    if($_SESSION['user']){
      $user_id = func::clear($_SESSION['user'],'int');
      $time = time();
      $ip = $_SERVER['REMOTE_ADDR'];
      $db->Query("UPDATE users SET last = '{$time}', ip = '{$ip}' WHERE id = '{$user_id}'");
      function stockGen($user_id){
        global $db;
        $db->Query("SELECT * FROM users WHERE id = '{$user_id}'");
        $user_data = $db->FetchArray();
        $db->Query("SELECT * FROM users_conf WHERE user_id = '{$user_id}'");
        $sub_data = $db->FetchArray();
        $data = array_merge($user_data,$sub_data);
        $day = time() - 86400;
        $db->Query("SELECT
          (SELECT ref_1 FROM users_ref WHERE user_id = '{$user_id}') ref_id,
          (SELECT COUNT(*) FROM banner_history WHERE user_id = '{$user_id}') banner_views,
          (SELECT COUNT(*) FROM link_history WHERE user_id = '{$user_id}') link_views,
          (SELECT COUNT(*) FROM users_ref WHERE ref_1 = '$user_id') referals,
          (SELECT time FROM auth WHERE user_id = '{$user_id}' ORDER BY id DESC LIMIT 1) last_auth,
          (SELECT SUM(money) FROM payments WHERE user_id = '{$user_id}' AND status = '2') pay,
          (SELECT SUM(money) FROM inserts WHERE user_id = '{$user_id}' AND status = '2') ins,
          (SELECT SUM(to_ref_1) FROM users_ref WHERE ref_1 = '{$user_id}') from_refs_1,
          (SELECT SUM(to_ref_2) FROM users_ref WHERE ref_2 = '{$user_id}') from_refs_2,
          (SELECT SUM(to_ref_3) FROM users_ref WHERE ref_3 = '{$user_id}') from_refs_3,
          (SELECT to_ref_1 FROM users_ref WHERE user_id = '{$user_id}') to_ref");
        $data += $db->FetchArray();
        $data['from_refs'] = sprintf('%.2f',$data['from_refs_1'] + $data['from_refs_2'] + $data['from_refs_3']);
        $data['all_view'] = intval($data['banner_views']) + intval($data['link_views']);
        $data['all_money'] = 0;/*sprintf('%.2f',(floatval($data['link_money']) + floatval($data['banner_money']) + floatval($data['mails_money'])))*/
        $data['all_money_day'] = 0;/*sprintf('%.2f',(floatval($data['link_money_day']) + floatval($data['banner_money_day']) + floatval($data['mails_money_day'])))*/
        $ref_id = $data['ref_id'];
        if ($ref_id != '0') {
          $db->Query("SELECT login FROM users WHERE id = '{$ref_id}'");
          $data['referer'] = $db->FetchRow();
        }else $data['referer'] = 'Пришел сам';
        $db->Query("SELECT * FROM auth WHERE user_id = '{$user_id}' ORDER BY time DESC LIMIT 10");
        if ($db->NumRows() > 0) {
          $data['auth_history'] = $db->FetchAll();
        }else $data['auth_history'] = '0';
        new gen('account/account',$data);
      }
      if(isset($url[2]) && !empty($url[2])){
        $ctrl = $func->clear($url[2]);
        $file = 'controllers/account/'.$ctrl.'Ctrl.php';
        if(file_exists($file)){
          include $file;
        }else stockGen($user_id);
      }else stockGen($user_id);
    }else header('location: /login');
    
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}') banner_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}') link_money,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}') mails_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}' AND time > '{$day}') link_money_day,
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}' AND time > '{$day}') banner_money_day,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}' AND time > '{$day}') mails_money_day,

    источник: https://toster.ru/q/346342

    riot26, 19 Августа 2016

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

    +316

    1. 1
    $this->db->query("UPDATE `" . DB_PREFIX . "order` SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_company_id = '" . $this->db->escape($data['payment_company_id']) . "', payment_tax_id = '" . $this->db->escape($data['payment_tax_id']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($payment_country) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($payment_zone) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($payment_address_format) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "',  shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($shipping_country) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($shipping_zone) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($shipping_address_format) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', order_status_id = '" . (int)$data['order_status_id'] . "', affiliate_id  = '" . (int)$data['affiliate_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");

    Строчечка

    govnozmey, 18 Августа 2016

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

    +119

    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
    <?php header('Content-Type: application/rss+xml'); ?>
    <?='<?xml version="1.0" encoding="utf-8"?>'?>
    <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
      <channel>
        <title><![CDATA[Neon Genesis Kode]]></title>
        <link>http://govnokod.ru</link>
        <description><![CDATA[Свежие комментарии]]></description>
        <pubDate><?=date(DATE_RSS)?></pubDate>
        <language>ru-ru</language>
        <docs>http://blogs.law.harvard.edu/tech/rss</docs>
        <ttl>3600</ttl>
    <?php
    
    $curl_context = curl_init(); 
    curl_setopt($curl_context, CURLOPT_URL, 'http://146.185.130.46/ngk/api/v1/latest'); 
    curl_setopt($curl_context, CURLOPT_RETURNTRANSFER, 1); 
    $raw_data = curl_exec($curl_context); 
    curl_close($curl_context);     
    $data = JSON_decode($raw_data);
    
    foreach($data as $item) { ?>
      <item>
          <title><![CDATA[Комментарий к говнокоду #<?=$item->thread_id?>]]></title>
          <link>http://govnokod.ru/<?=$item->thread_id?>#comment<?=$item->comment_id?></link>
          <guid>http://govnokod.ru/<?=$item->thread_id?>#comment<?=$item->comment_id?></guid>
          <description><![CDATA[<?=$item->text?>]]></description>
          <pubDate><?=date(DATE_RSS, strtotime($item->posted))?></pubDate>
      </item>
    <?php } ?>
    </channel>
    </rss>

    Обычный пыхокод. Листайте дальше.

    inkanus-gray, 17 Августа 2016

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

    +341

    1. 1
    2. 2
    $dom = new DOMDocument;
    $dom->loadHTML('<?xml encoding="UTF-8">' . $document);

    Выжал самое интересное.

    Кто угадает, зачем к документу прилепляется строка '<?xml encoding="UTF-8">', тому ничего. Но без неё не работает. Точнее, работает, но неправильно.

    inkanus-gray, 13 Августа 2016

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