- 1
- 2
if (isset($_GET['oneway']))
$_SESSION['oneway'] = intval($_GET['oneway']) == 1 ? 1 : 0;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+37
if (isset($_GET['oneway']))
$_SESSION['oneway'] = intval($_GET['oneway']) == 1 ? 1 : 0;
Уточню : надо именно int, а не bool для API сервиса.
На ум приходят 2 других более красивых способа нормализации. Может и ещё что-то есть.
+46
for($i=0;$i<=100;$i++)echo(!$i?$i:($i%3==0&&$i%5==0?'FizzBuzz':($i%3==0?'Fizz':($i%5==0?'Buzz':$i)))).'<br>';
FizzBuzz - мое решение.
+46
public function custom_result_object($class_name)
{
if (array_key_exists($class_name, $this->custom_result_object))
{
return $this->custom_result_object[$class_name];
}
if ($this->result_id === FALSE OR $this->num_rows() == 0)
{
return array();
}
// add the data to the object
$this->_data_seek(0);
$result_object = array();
while ($row = $this->_fetch_object())
{
$object = new $class_name();
foreach ($row as $key => $value)
{
$object->$key = $value;
}
$result_object[] = $object;
}
// return the array
return $this->custom_result_object[$class_name] = $result_object;
}
// --------------------------------------------------------------------
/**
* Query result. "object" version.
*
* @access public
* @return object
*/
public function result_object()
{
if (count($this->result_object) > 0)
{
return $this->result_object;
}
// In the event that query caching is on the result_id variable
// will return FALSE since there isn't a valid SQL resource so
// we'll simply return an empty array.
if ($this->result_id === FALSE OR $this->num_rows() == 0)
{
return array();
}
$this->_data_seek(0);
while ($row = $this->_fetch_object())
{
$this->result_object[] = $row;
}
return $this->result_object;
}
+39
<?php
session_start();
include ("system/db.config.php");
if (empty($_SESSION['login']) or empty($_SESSION['id']))
{
header("Location: index.php");
}
else
{
//Выясняем, кто зашел сюда, если админ, удаляем юзера, если нет - перекидываем в список пользователей
$fResult = mysql_query("SELECT user_level FROM users WHERE id=".$_SESSION['id'], $db);
$fRow = mysql_fetch_array($fResult);
if($fRow['user_level'] == 1)
{
$DelTenderId = $_GET['id'];
$DellFiled = mysql_query("SELECT file_link FROM tenders WHERE id=".$DelTenderId);
$isdLnk = mysql_fetch_array($DellFiled);
$delPater = "uploads/".$isdLnk['file_link'];
unlink($delPater);
mysql_query("DELETE FROM tenders WHERE id =".$DelTenderId);
header("Location: tenders_list.php");
}
else
{
header("Location: home.php");
}
}
?>
Ну как то так....
+141
C:\>php -r "echo mb_convert_encoding('хуй', 'cp866', 'windows-1251') . chr(7);"
+43
if(!empty($_POST['word'])) {
$sql = "SELECT `sysname` FROM `__" . $this->tables[0] . "` WHERE `title`='".$_POST['word']."'";
$model = $conn->fetchAll($sql);
if(!sizeof($model)) {
header("Location: " . $_SERVER['HTTP_REFERER']);
exit;
}
header("Location: /catalog/brands/" . $model[0]['sysname'] . ".html");
exit;
}
Маленький кусок проекта на Symfony 2.
+54
$postitle = str_replace (' ', '-', $title);
$postitle = str_replace ('/', '', $postitle);
$postitle = str_replace ('\\', '', $postitle);
$postitle = str_replace (':', '', $postitle);
$postitle = str_replace ('<', '', $postitle);
$postitle = str_replace ('>', '', $postitle);
$postitle = str_replace ('*', '', $postitle);
$postitle = str_replace ('?', '', $postitle);
$postitle = str_replace ('|', '', $postitle);
$postitle = str_replace ('"', '', $postitle);
$postitle = preg_replace ('#\[.*?\]#isu', '', $postitle);
+44
function db_connect($serverMySql, $db_log, $db_pass) //create connection
{
$r = mysql_connect($serverMySql, $db_log, $db_pass);
return $r;
}
//....
// страницы
if (empty($_GET["p"])) {
$_GET["p"] = "1";
}
$p = $_GET["p"];
// защита от ввода
if (preg_match("/[%a-z_@.,^=:;Р°-СЏ\"*()&$#в„–+\-!?<>\~`|[{}\]]/i", $p)) {
die(header("Location:sluch_list.php"));
}
http://hashcode.ru/questions/163555/php-%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4-%D1%84%D1%80%D0%B0%D0%B7-%D0%BF%D0%BE-%D1%80%D0%B5%D0%B9%D1%82%D0%B8%D0%BD%D0% B3%D1%83
+45
if (!isset($_POST['searchText'])) $_POST['searchText'] = $_GET['searchText'];
if (!isset($_POST['by'])) $_POST['by'] = $_GET['by'];
+65
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
Opencart, catalog/model/catalog/product.php
Они что издеваются? А я-то думаю что у меня ложит mysql сервер на колени...