- 1
<a href="#" class="lalalalalala" onclick="$('#frm').submit()">Добавить</a>
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+150.5
<a href="#" class="lalalalalala" onclick="$('#frm').submit()">Добавить</a>
обычный сабмит для веб 2.0 не катит а ни разу ))
+169.8
function query($sql)
{
//DEBUG echo $sql."<br />";
db::$count++;
$r = mysql_query($sql);
if(($this->error = mysql_error()) != "")
return false;
else
{
$this->error = "";
return mysql_query($sql);
}
}
Человек долго удивлялся, почему у него в mysql две записи валится при INSERT, а не одна
+144.8
$uploaddir = '../images/';
$uploadfile1 = $uploaddir . basename($_FILES['img']['name']);
все те же индусы
+151
public function __construct()
{
$this->post = $_POST;
unset($_POST);
}
public function get($var_name)
{
return $this->post[$var_name];
}
ещё бы сделали ф-ю
public function post($var_name)
{
return $this->get[$var_name];
}
+159.7
<?php
echo test;
?>
Денвер отвечает:
Notice: Use of undefined constant test - assumed 'test' in file.php on line 2
[Денвер: показать возможную причину ошибки]
Смотрим причину ошибки:
"Это предупреждение, вероятнее всего, возникает вследствие высокого уровня контроля ошибок в PHP, по умолчанию установленного в Денвере (E_ALL)"
Скрыл вывод ошибок и профит ;)
Денвер выращивает быдлоКОТЕРОВ!
+156
$db = JFactory::getDBO();
$records = $db->Execute(
'SELECT DISTINCT(MONTH(publication_date)) ' .
' FROM miel_news' .
' WHERE `news_type` != \'analytics\' and YEAR(publication_date) = ' . $year .
' AND publish=1'.
' AND publication_date < \''.date('Y-m-d H:i:s').'\''.
' ORDER BY publication_date DESC');
if ($records->data){
$mm = array('Январь', 'Февраль', 'Март' , 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь');
$m_array = array_map('array_shift', $records->data);
foreach ($m_array as $key => $value){
$value--;
$month[] = array('name' => $mm[$value], "id" =>$value+1) ;
}
return $month;
}
+161.7
function read_file($path)
{if(!is_file($path))return false;
elseif(!filesize($path))return array();
elseif($array=file($path))return $array;
else while(!$array=file($path))sleep(1);
return $array;}
интересный способ чтения файла в WR-Counter )))
+157
<?php
public function run()
{
$db = Registry::get('Db');
$db->transaction(Db_Database::START);
$success = $db->query()->update()
->table('forum_topics')
->set('PostsCount = PostsCount - 1')
->set('LastPostID = ('
. $db->query()
->select()->fields('ID')
->table('forum_posts')->order('ID', 1) // DESC
->where('TopicID = %d', $this->post->topic->id)
->limit(1)->compile()->getQuery()
. ')')
->set('FirstPostID = ('
. $db->query()
->select()->fields('ID')
->table('forum_posts')->order('ID')
->where('TopicID = %d', $this->post->topic->id)
->limit(1)->compile()->getQuery()
. ')')
->where('ID = %d', $this->post->topic->id)
->compile()->run()->success()
&& $db->query()->update()
->table('forum_cats')
->set('PostsCount = PostsCount - 1')
->set('LastTopicID = ('
. $db->query()
->select()->fields('ID')
->table('forum_topics')->order('LastPostID', 1) // DESC
->where('CatID = %d', $this->post->topic->category->id)
->limit(1)->compile()->getQuery()
. ')')
->where('ID = %d', $this->post->topic->category->id)
->compile()->run()->success()
&& $db->query()->update()
->table('forum_posts')
->set('Deleted = 1')
->where('ID = %d', $this->post->id)
->compile()->run()->success();
$db->transaction($success ? Db_Database::COMMIT : Db_Database::ROLLBACK);
return $success;
}
Вот такая вот жесть бывает. Изменение счетчиков на форуме (денормализация) с использованием альфа-версии кверибилдера. по-моему — устрашающе)
+165.2
function nik_slashes(&$value) {
return (stripslashes($value));
}
Коллега сделал свою функцию для удаления слэшей с блек джеком и всем прочим.
+158
<?php
/**
* хелпер подсчитывает кол-во дней между двух дат
*/
class ********_View_Helper_DateDiff
{
/**
* из дня, месяца и года формирует время в формате кол-ва дней
* @return integer
*/
protected function dateToDays($day, $month, $year)
{
if ($month > 2) {
// March = 0, April = 1, ..., December = 9,
// January = 10, February = 11
$month -= 3;
} else {
$month += 9;
--$year;
}
$hb_negativeyear = $year < 0;
$century = intval($year / 100);
$year = $year % 100;
if ($hb_negativeyear) {
return intval((14609700 * $century + ($year == 0 ? 1 : 0)) / 400) +
intval((1461 * $year + 1) / 4) +
intval((153 * $month + 2) / 5) +
$day + 1721118;
} else {
return intval(146097 * $century / 4) +
intval(1461 * $year / 4) +
intval((153 * $month + 2) / 5) +
$day + 1721119;
}
}
/**
* высчитывает разницу между двух дат
* @return integer
*/
public function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) {
$days1 = $this->dateToDays($day1,$month1,$year1);
$days2 = $this->dateToDays($day2,$month2,$year2);
return ($days1-$days2);
}
}
кусок самописного расширения ZF.
про gregoriantojd() люди не знали.