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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <p class="name">
                    {% if (file.url) { %}
                        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
                    {% } else { %}
                        <span>{%=file.name%}</span>
                    {% } %}
                </p>
                {% if (file.error!="SyntaxError: Unexpected token <") { %}
                    <div><span class="label label-danger">Error</span> {%=file.error%}</div>
                {% } %}

    Шедевральный человек! Оригинал http://www.yiiframework.ru/forum/viewtopic.php?t=15956#p119944

    dimka3210, 23 Апреля 2016

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

    +2

    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
    public function get($userId = null, $advense = false) {
            
            if ($userId === null) $userId = $this->currentId;
            
            $user = DB::table('users')
                    ->select(
                            '*',
                            DB::raw('IF(email IS NOT NULL AND email_confirm IS NULL, 1, 0) AS email_confirm'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL, 1, 0) AS phone_confirm'),
                            DB::raw('IF(birthday IS NOT NULL, TIMESTAMPDIFF(YEAR,birthday,CURDATE()), NULL) AS age'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL AND email IS NOT NULL AND email_confirm IS NULL AND (new_first_name IS NOT NULL OR new_last_name IS NOT NULL OR new_status_text IS NOT NULL OR new_image_url IS NOT NULL), 1, 0) AS on_moderate'))
                    ->where('id', $userId)->first();
            
            if ($user === null) throw new Exception ('User is not found', 404);
            unset($user->password);
            $user->locality           = Geo::get($user->locality_id);
            $rating = $this->rating($userId);
            $user->rating           = (float)$rating->avg;
            $user->rating_counter   = (int)$rating->cnt;
            $user->counters        = $this->getCounters($userId);
    
            
            $contact = $this->contacts->isMyContact($userId);
            if ($userId != $this->currentId) {
                $user->created = null;
                $user->updated = null;
                $user->birthday = null;
                $user->email_confirm = null;
                $user->phone_confirm = null;
                $user->subscribed = null;
                $user->organizations = null;
                $contact = $this->contacts->isMyContact($userId);
                // Если пользователь не контакт авторизованного, сотрем контактную информацию
                if ( $contact === null || $contact === 'declined') {
                    $user->phone = null;
                    $user->email = null;
                    $user->last_name = mb_substr($user->last_name, 0, 1, 'UTF-8');
                }
                
            } else {
                if($user->new_first_name !== null) {
                    $user->first_name = $user->new_first_name;
                }
                if($user->new_last_name !== null) {
                    $user->last_name = $user->new_last_name;
                }
                if($user->new_image_url !== null) {
                    $user->image_url = $user->new_image_url;
                }
                if($user->new_status_text !== null) {
                    $user->status_text = $user->new_status_text;
                }
                $user->organizations = Organizations\Organizations::getByUserId($userId);
                $user->is_followed     = null;
                $user->is_my_contact   = null;
                $user->has_my_contact  = null;
                $user->has_my_opinion  = null;
            }
            unset($user->new_status_text);
            unset($user->new_image_url);
            unset($user->new_last_name);
            unset($user->new_first_name);
            unset($user->reset_code);
    
            
            $user->is_followed     = $this->followers->isFollowed($userId);
            $user->is_my_contact   = $this->contacts->isMyContact($userId);
            $user->has_my_contact  = $this->contacts->hasMyContact($userId);
            return $user;
            
        }

    Тыдыдыдыдыыыц, laravel code О_О
    Что же тут вообще происходит?

    lemax, 20 Апреля 2016

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

    +4

    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
    // Авторизация
    $app->post('/action/login', function(Request $request, Response $response)
    {
    	global $connection, $hash;
    	
    	$data = $request->getParsedBody('login');
    	$login = $data['login'];
    	$password = md5($data['password']);
    	
    	$result = mysqli_query($connection, "SELECT `password` FROM `users` WHERE `login` = '$login'");
    	$row = $result->fetch_assoc();
    	
    	if(!empty($login) and !empty($password))
    	{
    		if($password === $row['password'])
    		{
    			$_SESSION['auth'] = $hash;
    			echo "<script>location.href='/log';</script>";
    		}
    		else
    		{
    			redirect();
    		}
    	}
    });

    st55, 19 Апреля 2016

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

    +8

    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
    <?
    	function __echo($str){
    		return "$str\n";
    	}
    	function _echo ($str){
    		echo __echo($str);
    	}
    	function _echo_utf8($str){
    		_echo (iconv('windows-1251', 'UTF-8//IGNORE', $str));
    	}
    
    	_echo("<div id='class_edit_add' style='display:none;margin-left:30px;'>");
    	_echo("<div style='margin-bottom:30px;'><center>");
    	_echo_utf8("Добавить &nbsp;");
    	_echo("<select id='chose_class_edit_add_something'>");
    	_echo("<option selected value='0'></option>");
    	_echo_utf8("<option value='1'>предмет</option>");
    	_echo_utf8("<option value='2'>учителя</option>");
    	_echo_utf8("<option value='3'>ученика</option>");
    	_echo_utf8("<option value='4'>подгруппу</option>");
    	_echo("</select>");
    	_echo("<input type='button' class='button' value='ok' onclick=\"class_edit_add_something();\">");
    	_echo("</сenter></div>");
    	_echo("<div id='div_class_edit_add_something_out' style='display:none'></div>");
    	_echo("</div>");

    _echo_utf8

    jufer, 16 Апреля 2016

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?if(false){?>
    <ul class="top_nav_lang">
    <?if($lang != 'en'){?><li><a href="en"><span>EN</span></a></li><?}?>
    <?if($lang != 'bg'){?><li><a href="bg"><span>BG</span></a></li><?}?>
    </ul>
    <?}?>

    выбор языка...

    daemonkeeper, 15 Апреля 2016

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

    −2

    1. 1
    curl_setopt($ch, CURLOPT_POSTFIELDS, urldecode(http_build_query($postParams)));

    Bitrop, если читаешь это... Спасибо.. мы тут немного посидели подумали).. Сначала зачем, потом почему)

    dwsVad, 15 Апреля 2016

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

    +9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    1. http://govnokod.ru/user/register
    2. login: zizzleZee
    3. email: ****[email protected]
    4. >> ВВЕДИТЕ ДЕЙСТВИТЕЛЬНЫЙ АДРЕС!
    5. WAT-WAT !!!????
    6. http://10minutemail.net -> [email protected]
    7. email: [email protected]
    8. >> СПАСИБО ЗА РЕГИСТРАЦИЮ!
    9. atomic facepalm

    govnokod.ru::email_validate
    The best practice ever!

    zizzleZee, 15 Апреля 2016

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $outbad = array();
    $outgood = array();
    foreach((array)$emails as $key=>$e){
    if (да){
    $outgood[] .= $emailadress['dfgh'] . " хороший адрес"; // и такой вариант
    } else{
    $outbad[] .= array($emailadress . " плохой адрес"); // и такой вариант
    }
    echo $outgood;
    echo $outbad;

    Просто вопрос на тостере

    planaric, 14 Апреля 2016

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    public function actionView($id = null) {
    
            $user = Yii::$app->user->identity;
            $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : $id;
    
    
            $new_model = 0;
            if (empty($id)) {
                $draft_model = Applicant::find()->where(['draft' => 1, 'created_by' => $user->id])->one();
                if (empty($draft_model)) {
                    $draft_model = new Applicant();
                    $new_model = 1;
                    $draft_model->draft = 1;
                    $draft_model->save();
                }
                if (!empty($draft_model->id)) {
                    $id = $draft_model->id;
                }
            }
            $model = $this->findModel($id);
            $allow_sections = [];
            if (empty($model->draft)) {
                $updateRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
                if (!empty($updateRequest)) {
                    $allow_sections = explode(";", $updateRequest->additional_info);
                }
            }
    
            if (isset($_GET['done']) && $_GET['done'] == 1) {
                $result['success'] = false;
    
                $userRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
                if (!empty($userRequest)) {
                    $userRequest->status = 3;
                    if ($userRequest->save()) {
                        $result['success'] = true;
                    } else {
                        $error = \yii\widgets\ActiveForm::validate($userRequest);
                        if ($error != '[]') {
                            $result['msg'] = $error;
                        }
                    }
                }
    
                echo(json_encode($result));
                exit;
            } elseif (isset($_FILES['files']['name'][0]) && isset($_FILES['files']['type'][0]) && isset($_FILES['files']['tmp_name'][0]) && isset($_FILES['files']['size'][0])) {
                $result['success'] = false;
    
                $filename = strtotime("now") . "_" . $_FILES['files']['name'][0];
                $size = $_FILES['files']['size'][0];
    
                $uploaddir = realpath('../web') . '/images/applicant/';
                if (!file_exists($uploaddir)) {
                    mkdir($uploaddir);
                }
                $uploadfile = $uploaddir . basename($filename);
                $path_image = '/images/applicant/' . basename($filename);
                if (move_uploaded_file($_FILES['files']['tmp_name'][0], $uploadfile)) {
    
                    if (!empty($model->photo_id)) {
                        $photo_model = \app\models\File::findOne($model->photo_id);
                    }
    
                    if (empty($photo_model->id)) {
                        $photo_model = new \app\models\File();
                    }
    
                    $photo_model->original = $filename;
                    $photo_model->name = $filename;
                    $photo_model->size = $size;
                    $photo_model->mime = $_FILES['files']['type'][0];
                    $photo_model->hash = $photo_model->generateHash();
    
                    if ($photo_model->save()) {
                        $model->photo_id = $photo_model->id;
                        if ($model->save()) {
                            $result['img'] = $filename;
                            $result['success'] = true;
                        }
                    }
                    $image = new Image();
                    $image->load($uploadfile);
                    if($image->getWidth()>640){
                        $image->resizeToWidth(640);
                        $image->save($uploadfile);
                    }
                }
    
                echo(json_encode($result));
                exit;
            } elseif (isset($_REQUEST['name'])) {
                $result['success'] = false;
    
                $model_attributes = $model->getAttributes();
                $model_attributes['education'] = '';
                unset($model_attributes['id']);
                if ($_REQUEST['name'] == 'address_properties') {
                    $values = json_decode($_REQUEST['value'], true);
                    $names_values = ['address_region', 'address_city', 'address_street', 'address_house'];

    yii 2

    print_r_var_dump, 14 Апреля 2016

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

    +1

    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
    $payments = $CI->payment_method_model->getAll();
    
        $payment = array();
        $payment[null] = array();
        $payment[null]['addr'] = " ";
        $payment[null]['perc'] = " ";
        $payment[null]['name'] = " ";
       
        foreach($payments->result() as $item)
        {
            $payment[$item->id] = array();
            $payment[$item->id]['addr'] = (json_decode($item->params,true));
            $payment[$item->id]['perc'] = $item->fee;
            $payment[$item->id]['name'] = $item->title;
        }

    No comments...
    Поддержка этого проекта вызывает душевную боль... :(

    GDim, 13 Апреля 2016

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