- 1
- 2
- 3
- 4
- 5
if($_REQUEST['filter2'] == 'my' OR $_REQUEST['filter2'] == 'all' OR $_REQUEST['filter2'] == 'delegated'){
$filter2 = htmlspecialchars( $_REQUEST['filter2'], ENT_QUOTES );
}else{
$filter2 = 'all';
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+50
if($_REQUEST['filter2'] == 'my' OR $_REQUEST['filter2'] == 'all' OR $_REQUEST['filter2'] == 'delegated'){
$filter2 = htmlspecialchars( $_REQUEST['filter2'], ENT_QUOTES );
}else{
$filter2 = 'all';
}
Может тогда уж $filter2 = htmlspecialchars( 'all', ENT_QUOTES ); для полного счастья?
+50
<?php
$confs = array();
$q = new WP_Query(array('post_type' => 'conference',
'posts_per_page' => -1,
'meta_key' => 'cd-conference-date-start',
'orderby' => 'meta_value_num',
'order' => 'DESC'
));
while($q->have_posts()): $q->the_post();
$confs[date("Y", get_post_meta($post->ID, 'cd-conference-date-start', true))][] = array('conf_title' => get_the_title(),
'conf_date_start' => get_post_meta($post->ID, 'cd-conference-date-start', true),
'conf_date_end' => get_post_meta($post->ID, 'cd-conference-date-end', true),
'conf_link' => get_permalink(),
'conf_city' => '', /* Город */
'conf_icon' => '' /* Иконка */
);
endwhile;
wp_reset_postdata();
foreach($confs as $key => $value)
{
?>
<h1 class="year"><?=$key;?></h1>
<?php
//print_r($value);
?>
<div class="conferences">
<?php foreach($value as $val)
{
//print_r($val);
?>
<div class="conf">
<div class="leftcol">
<a href="<?=$val["conf_link"];?>"><img src="<?=$val["conf_icon"];?>"></a>
</div>
<div class="rightcol">
<a href="<?=$val["conf_link"];?>"><h2><?=$val["conf_title"];?></h2></a>
<span class="date-place">
<?php
//setlocale(LC_TIME, "ru_RU");
if(date("m", $val["conf_date_start"]) == date("m", $val["conf_date_end"])) $confdays = date("j", $val["conf_date_start"])."-".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]));
else
{
$confdays = date("j", $val["conf_date_start"])." ".mb_strtolower(strftime("%B", $val["conf_date_start"]))." - ".date("j", $val["conf_date_end"])." ".mb_strtolower(strftime("%B", $val["conf_date_end"]));
}
?>
<?=$confdays;?>, <?=$val["conf_city"];?>
</span>
</div>
</div>
<?php
}
?>
</div>
<?php } ?>
+50
<?php
require('url_to_absolute.php');
ini_set('display_errors','On');
error_reporting('E_ALL');
$ext=array(
'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
'docs'=>array('rtf','doc','docx','pdf','txt'),
'html'=>array('shtml','html','xml','css','htm','xhtml'),
'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
'pack'=>array('deb','rpm','jar'),
'scripts'=>array('sh','pl','py','php','js')
);
$murl="";
$sext="";
$routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
foreach($ext as $sk=>$sval){
foreach($sval as $exts){
$routh.='(?!'.$exts.'")';
}
}
$routh.='[a-z0-9]{1,5}(?=[" ]))|i';
echo $routh."<br\ >";
if(isset($_GET['url'])){
$url=$_GET['url'];echo $url."<br>";
preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
$html=file_get_contents($url);
foreach($ext as $key=>$val){
echo "<h2>$key</h2><br\>";
foreach($val as $mext){
echo "$mext<br>";
preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
}
}
preg_match_all($routh,$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
echo "<br><h2>Other documents</h2><br>";
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
}
}
}
} else { printf("No url\n");}
?>
Вытягивает ссылки на картинки с html файла
+50
// $conn - mysqli_object
$query = "insert into orders values
('0', '".$customerid."', '".$_SESSION['total_price']."',
'".$date."', '".PARTIAL."', '".$ship_name."',
'".$ship_address."', '".$ship_city."',
'".$ship_state."', '".$ship_zip."',
'".$ship_phone."', '".$ship_mail."')";
$result = $conn->query($query) ;
if (!$result) {
return false;
}
//amount - float
$query = "select orderid from orders where
customerid = '".$customerid."' and
amount > (".$_SESSION['total_price']."-.001) and
amount < (".$_SESSION['total_price']."+.001) and
date = '".$date."' and
order_status = 'PARTIAL' and
ship_name = '".$ship_name."' and
ship_address = '".$ship_address."' and
ship_city = '".$ship_city."' and
ship_state = '".$ship_state."' and
ship_zip = '".$ship_zip."' and
ship_country = '".$ship_country."'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$order = $result->fetch_object();
$orderid = $order->orderid;
} else {
return false;
}
Источник: Люк Веллинг и Лора Томсон: Разработка веб-приложений с помощью PHP и MySQL(4 издание стр 594)
Как выдрать last_insert_id? Очень просто: нужно составить запрос на select вставленного orderid с указанием всех вставленных значений в поля, а для флоата указать на всякий случай интервал, и только тогда можно из выборки извлечь вставленный id
ps: констатна PARTIAL нигде не задаётся=)
+50
int i, j;
for (i = j = 0; i < 4; i++)
if (frame & (0x8 >> i))
{
if (i < 2 && p.value < double(frames1[j]) && !(i && j) ||
i > 1 && p.value > double(frames1[j]))
p.value.attr = 1 + i;
j++;
}
Как вам цикл до 4 с тремя проверками на значение счётчика? :)
+49.9
bool __fastcall TForm1::ImportFile(AnsiString FName, int Direction)
{
bool StatusUpload;
StatusUpload = true;
TStringList *Inside;
Inside = new TStringList;
Inside->LoadFromFile(FName);
if (Direction == 1)
{
// ...
date_made = StrToSqlDate(Inside->Strings[1]);
ops = Inside->Strings[0];
Inside->Delete(0);
Inside->Delete(0);
Inside->Delete(0);
int Iterations = (Inside->Count/5);
for (int i=0; i<Iterations; i++)
{
AnsiString A, B, C, D, E;
A = Inside->Strings[0].Trim();
B = Inside->Strings[1].Trim();
C = Inside->Strings[2].Trim();
D = Inside->Strings[3].Trim();
E = Inside->Strings[4].Trim();
for (int j=0; j<5;j++)
Inside->Delete(0);
if (A == "1.1.2")
E='1';
if (A == "4.13" || A == "4.13" || A == "4.13")
E='20';
C = RemoveZPT(C);
ADOQuery1->SQL->Text = "INSERT INTO dnevnik_inside (row_id, ops, date_made, code, sign, val, val_init, direction, type) VALUES ("
+ row_id + ", '" + ops + "', '" + date_made + "', '" + A + "', '"
+ B + "', " + C + ", " + C + ", '" + D +"', '"+E+"')";
ADOQuery1->ExecSQL();
}
Trans->CommitRetaining();
}
Собсно, название функции говорит само за себя :)
П.С. Коллега, не обижайся!
+49.8
bool ok;
double d;
QLocale c(QLocale::C);
d = c.toDouble( "1234.56", &ok ); // ok == true, d == 1234.56
Ссылка на bool!
+49.6
/*
* ToDo: дописать, что нужно сделать.
*/
+49.5
if (gettype($x/2) == 'int') {
$rowspan = $x - $i;
} else {
$rowspan = ($x - $i) + 1;
}
Проверка на остаток от деления на 2 одним начинающим знакомым ПХП программистом
+49.2
if (strlen(tmpStr) > 250)
strncpy(fields[i].info.fieldName, tmpStr, 250);
else
strcpy(fields[i].info.fieldName, tmpStr);
А пох - все равно скопируем. =)