- 1
- 2
$dom = new DOMDocument;
$dom->loadHTML('<?xml encoding="UTF-8">' . $document);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+341
$dom = new DOMDocument;
$dom->loadHTML('<?xml encoding="UTF-8">' . $document);
Выжал самое интересное.
Кто угадает, зачем к документу прилепляется строка '<?xml encoding="UTF-8">', тому ничего. Но без неё не работает. Точнее, работает, но неправильно.
+4
// Change the color of the displayed status
if ($status == "active") {
$status_display = '<font color="white">' . $status . '</font>';
} elseif ($status == "sold") {
$status_display = '<font color="green">' . $status . '</font>';
} elseif ($status == "emis") {
$status_display = '<font color="orange">' . $status . '</font>';
} elseif ($status == "alert") {
//
} elseif ($status == "deleted") {
$status_display = '<font color="white">' . $status . '</font>';
//$style="text-decoration: line-through;";
} elseif ($status == "closed") {
$status_display = '<font color="closed">' . $status . '</font>';
} elseif ($status == "options_sent") {
$status_display = '<font color="yellow">' . $status . '</font>';
}
if ($trip_type == "one_way") {
$one_way = "SELECTED";
$round_trip = "";
$trip_type = '<font color="DarkBlue">One Way</font>';
} else {
$one_way = "";
$round_trip = "SELECTED";
$trip_type = '<font color="#348017">Round Trip</font>';
}
if ($cabin_class == "economy_class") {
$eco_class = "SELECTED";
$bus_class = "";
$ooo_class = "";
} elseif ($cabin_class == "business_class") {
$eco_class = "";
$bus_class = "SELECTED";
$ooo_class = "";
} elseif ($cabin_class == "o_class") {
$eco_class = "";
$bus_class = "";
$ooo_class = "SELECTED";
}
if ($num_pass == "1") {
$n1 = "SELECTED";
$n2 = "";
$n3 = "";
$n4 = "";
$n5 = "";
$n6 = "";
$n7 = "";
$n8 = "";
$n9 = "";
$n10 = "";
} elseif ($num_pass == "2") {
$n1 = "";
$n2 = "SELECTED";
$n3 = "";
$n4 = "";
$n5 = "";
$n6 = "";
$n7 = "";
$n8 = "";
$n9 = "";
$n10 = "";
} elseif ($num_pass == "3") {
$n1 = "";
$n2 = "";
$n3 = "SELECTED";
$n4 = "";
$n5 = "";
$n6 = "";
$n7 = "";
$n8 = "";
$n9 = "";
Вот почему не надо мелочиться. И нанимать нормальных программистов.
+4
var options = [<?php echo implode(',', range(App\Service\Service::CONSTANT_MIN, App\Service\Service::CONSTANT_MAX)); ?>];
+5
$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
}
Кандидат прислал тестовое задание
+5
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;
}
0
// 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);
Отправка письма
0
$result = call_user_func_array([ $brief, $value ? 'setOption' : 'deleteOption' ],
[ $option ] + ($value ? [ 1 => $value ] : []));
+2
<?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
+5
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));
}
Класс для работы с датой. Тяжелый случай...
+3
$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