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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $db=Yii::$app->db;
    
    if($db->driverName == 'pgsql') {
    $sql ="select a.* from report a inner join code_report b on a.id=b.report_id ";
    $sql.=" inner join code c on b.code_id=c.id  where cast (c.val as integer ) {$znaki[$sign]} $value group by a.id";//pgsql
    }
    if($db->driverName == 'mysql') {
    $sql ="select a.* from report a inner join code_report b on a.id=b.report_id ";
    $sql.=" inner join code c on b.code_id=c.id  where convert(c.val, signed) {$znaki[$sign]} $value group by a.id";//mysql
    }

    Кандидат прислал тестовое задание

    heleg, 08 Августа 2016

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

    +5

    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
    function make_json($array){
    
        $json = '{';
        $pairs = array();
    
        foreach($array as $key=>$val){
            if (!is_numeric($val)) { $val = "'{$val}'"; }
            $pairs[] = "{$key}: $val";
        }
    
        $json .= implode(', ', $pairs);
        $json .= '}';
    
        return $json;
    
    }

    dm_fomenok, 08 Августа 2016

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

    0

    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
    // Validation
    		$err = $fc->validationInput($fieldsArray, wire('input')->post);
    		if( $err === false ) {
    			// Saving
    			$fc->saveInput($fieldsArray, wire('input')->post);
    			// Send emails to the submitter and to the owner
    
    			$toSubmitter = wire('user')->email;
    			$toOwner = wire('pages')->get(wire('page')->created_users_id)->email;
    			
    		
    
    			$subject = "reservation #{$destPage->id}";
    
    			
    			ob_start(); ?>
    			
    			<p>Dear <?php echo $owner->o_firstname; ?>,</p>
    
    			<p>We have enquiry for your <?php echo $destPage->id->title; ?> in your account on site. Please log in to see details and replay to the guests directly.</p>
    			
    			<p>Here is the link: <a href="<?php echo 'http://'.$loginLink; ?>">http://<?php echo $loginLink; ?></a><p>
    
    			<p>Thank you in advance for contacting guests shortly. If you require any assistance please do not hesitate to get in touch.</p>
    
    			<p>The Team<br />
    			Lionl<br />
    			237 Perrier<br />
    			74700 <br />
    			<br />
    			Fr</p>
    			
    			<?php $textBody = ob_get_clean(); 
    			
    			$sent1 = wireMail($toSubmitter, '', $subject, '', array( 'bodyHTML' => $textBody ));
    			wireMail($toSubmitter, '', $subject, array( 'bodyHTML' => $textBody ));
    			
    			$agentMail = $fc->getInput('reservation_contact_email')->value;
    			$agentName = $fc->getInput('leader')->value;
    			$agentPhone = $fc->getInput('reservation_contact_phone')->value;
    
    			$regUser = wire('users')->find("email=$agentMail");
    			
    			
    			$destPage->of(false);

    Отправка письма

    gorbatka42, 02 Августа 2016

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

    0

    1. 1
    2. 2
    $result = call_user_func_array([ $brief, $value ? 'setOption' : 'deleteOption' ],
                                           [ $option ] + ($value ? [ 1 => $value ] : []));

    heleg, 02 Августа 2016

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

    +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
    <?php
    /*
    * System class
    * @package: PerfCMS
    */
    
    class System extends PerfSystem
    {
    	public static function textarea($rows = 5, $cols = 25, $name = 'text', $value = '', $class = '', $id = 'area', $style = '')
    	{
    		if(parent::browserType() == 'web')
    		{
    			Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/assets/js/bbtags.js');
    			return '
    			<div id="tagspanel" class="textarea">
    			<a href="#" title="'. Lang::get('bold_text').'" id="bold" onclick="return bbtags(\'[b]\', \'[/b]\', \'bold\', \''.$id.'\')">'.System::image('bbpanel/bold.png').'<span class="tooltip"></span></a>
    			<a href="#" title="'. Lang::get('italic_text').'" id="italic" onclick="return bbtags(\'[i]\', \'[/i]\', \'italic\', \''.$id.'\')">'.System::image('bbpanel/italic.png').'</a>
    			<a href="#" title="'. Lang::get('underline_text').'" id="underline" onclick="return bbtags(\'[u]\', \'[/u]\', \'underline\', \''.$id.'\')">'.System::image('bbpanel/underline.png').'</a>
    			<a href="#" title="'. Lang::get('strike_text').'" id="strikethrough" onclick="return bbtags(\'[s]\', \'[/s]\', \'strikethrough\', \''.$id.'\')">'.System::image('bbpanel/strikethrough.png').'</a>
    			<a href="#" title="'. Lang::get('quote_text').'" id="blockquote" onclick="return bbtags(\'[quote]\', \'[/quote]\', \'blockquote\', \''.$id.'\')">'.System::image('bbpanel/blockquote.png').'</a>
    			<a href="#" title="'. Lang::get('spoiler_text').'" id="spoiler" onclick="return bbtags(\'[spoiler]\', \'[/spoiler]\', \'spoiler\', \''.$id.'\')">'.System::image('bbpanel/spoiler.png').'</a>
    			<a href="#" title="'. Lang::get('color_text').'" id="color" onclick="return bbtags(\'[color=]\', \'[/color]\', \'color\', \''.$id.'\')">'.System::image('bbpanel/text_color.png').'</a>
    			<a href="#" title="'. Lang::get('url_text').'" id="link" onclick="return bbtags(\'[url=http://]\', \'[/url]\', \'link\', \''.$id.'\')">'.System::image('bbpanel/insert_link.png').'</a>
    			<a href="#" id="image" onclick="return bbtags(\'[img=http://]\', \'[/img]\', \'image\', \''.$id.'\')">'.System::image('bbpanel/image.png').'</a>
    			<a href="#" title="'. Lang::get('video_text').'" id="video" onclick="return bbtags(\'[video]\', \'[/video]\', \'video\', \''.$id.'\')">'.System::image('bbpanel/video.png').'</a>
    			<a href="#" title="'.Lang::get('source_text').'" id="source" onclick="return bbtags(\'[source lang=]\', \'[/source]\', \'source\', \''.$id.'\')">'.System::image('bbpanel/script_code.png').'</a>
    			</div>
    			<textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.(!empty($class) ? ' class="'.$class.'"' : null).(!empty($style) ? ' style="'.$style.'"' : null).' id="'.$id.'">'.(!empty($value) ? $value : null).'</textarea>';
    		}
    		else
    		{
    			return '[<a href="/help/codes">'.Lang::get('bb_codes').'</a> | <a href="/help/smiles">'.Lang::get('smiles').'</a> | <a href="/help/rules">'.Lang::get('rules').'</a> | <a href="/help/">'.Lang::get('help').'</a>]<br/>
    			<textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.(!empty($class) ? ' class="'.$class.'"' : null).(!empty($style) ? ' style="'.$style.'"' : null).' id="'.$id.'">'.(!empty($value) ? $value : null).'</textarea>';
    		}
    	}
    
    
    }

    Весь класс https://gist.github.com/eskrano/bb8fe1bc1e6b22456d68cf3e56bf752b

    eskrano, 30 Июля 2016

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

    +5

    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
    static public function Current()
    {
    	return mktime(date('H', time()),date('i', time()), 0, date('m', time()), date('d', time()), date('Y', time()));	
    }
    	
    static public function CurrentDate()
    {
    	return mktime(0, 0, 0, date('m', time()), date('d', time()), date('Y', time()));
    }
    	
    static public function YesterdayDate()
    {
    	$time = time()-86400;
    	return mktime(0, 0, 0, date('m', $time), date('d', $time), date('Y', $time));
    }

    Класс для работы с датой. Тяжелый случай...

    alexey6630, 29 Июля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $exceptionClass = '\yii\db\Exception';
    foreach ($this->exceptionMap as $error => $class) {
        if (strpos($e->getMessage(), $error) !== false) {
            $exceptionClass = $class;
        }
    }
    ...
    return new $exceptionClass($message, $errorInfo, (int) $e->getCode(), $e);

    Yii <3

    https://github.com/yiisoft/yii2/blob/master/framework/db/Schema.php#L625-L633

    Fike, 27 Июля 2016

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

    +3

    1. 1
    2. 2
    $arParams["SET_TITLE"] = $arParams["SET_TITLE"]!="N";
    $arParams["SET_LAST_MODIFIED"] = $arParams["SET_LAST_MODIFIED"]==="Y";

    news.detail - cтандартный компонент Битрикса

    pgood, 27 Июля 2016

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

    +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
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    static function saveoprosform_ajax()
    {
        global $DB, $USER;
        $task_id = $_REQUEST["task_id"];
        $qlist = $_REQUEST["qlist"];
    
        $sql = "DELETE FROM `tickets_qc_results` WHERE `task_id`=" . $DB->F($task_id) . ";";
        $DB->query($sql);
        $DB->free();
    
        if ($task_id && $qlist) {
            // другой говнокод
            $sql = "INSERT INTO `tickets_qc_results`...';
            $DB->query($sql);
        } else {
            $ret["error"] = "Недостаточно данных для выполнения операции!";
        }
        echo json_encode($ret);
        return false;
    }

    Сначала удаляем, потом проверяем by ©senior shaurma developer

    pahhan, 27 Июля 2016

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

    0

    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
    /**
         * Sets the user in the token.
         *
         * The user can be a UserInterface instance, or an object implementing
         * a __toString method or the username as a regular string.
         *
         * @param string|object $user The user
         *
         * @throws \InvalidArgumentException
         */
        public function setUser($user)
        {
            if (!($user instanceof UserInterface || (is_object($user) && method_exists($user, '__toString')) || is_string($user))) {
                throw new \InvalidArgumentException('$user must be an instanceof UserInterface, an object implementing a __toString method, or a primitive string.');
            }
            if (null === $this->user) {
                $changed = false;
            } elseif ($this->user instanceof UserInterface) {
                if (!$user instanceof UserInterface) {
                    $changed = true;
                } else {
                    $changed = $this->hasUserChanged($user);
                }
            } elseif ($user instanceof UserInterface) {
                $changed = true;
            } else {
                $changed = (string) $this->user !== (string) $user;
            }
            if ($changed) {
                $this->setAuthenticated(false);
            }
            $this->user = $user;
        }

    https://github.com/symfony/security-core/blob/master/Authentication/Token/AbstractToken.php#L93

    craaazy19, 26 Июля 2016

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