- 1
- 2
- 3
- 4
- 5
- 6
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;}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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() люди не знали.
+154.8
final class Graph extends DefaultModule implements IModule {
..........
protected function getDataByDate() {
..........
Интересно, какой скрытый смысл protected-метода в final-классе...
+160.2
function UserIsFriends($u1,$u2)
{
$db=new DB();
$db->query("SELECT `status` FROM `friends` where `status`='friends'
AND (`first`='".$u1."' or `second`='".$u1."')
AND (`first`='".$u2."' or `second`='".$u2."')");
if ($db->num_rows()!=0)$row=$db->next_record();
if ($row["status"]=="friends") return true; else return false;
}
Функция проверки дружбы между двумя людьми... ***дец
+159.4
if (Auth_OpenID_noMathSupport()) {
$null = null;
return $null;
}
взято в PHP OpenID, модуль BigMath.php, function Auth_OpenID_getMathLib
+158.6
<script type="text/javascript">
var pointsH =
[
<?php
$aPointsH = JRequest::getVar('aPoint');
if(is_array($aPointsH) && count($aPointsH) > 0){
.........
}else{
?>
[
<?php echo 0 ?>,
<?php echo 0 ?>,
'<?php echo 0 ?>',
<?php echo 0 ?>,
'<?php echo 0 ?>',
'<?php echo 0 ?>',
'<?php echo 0 ?>'
],
<?php
}
.....................
?>
....................
</script>
+141
$query =
'SELECT * ' .
'FROM `requests` ' .
'WHERE `requests`.`uid` = \'' . mysql_escape_string($uid) . '\' ' .
'AND `requests`.`status` = 0 ' .
'';
$requests = $this->execQuery($query);
if ( !$requests) {
$this->lastError = 'Error getting user\'s data. ';
return false;
} else {
$questions = $this->findAllQuestions();
foreach ($requests as $n => $request) {
$requests[$n]['quiz'] = unserialize(
unserialize($request['quiz'])
);
foreach ($requests[$n]['quiz'] as $qid => $answer) {
$currentQuestion = &$requests[$n]['quiz'][$qid];
$currentQuestion = array();
$currentQuestion['qid'] = $qid;
if (is_array($questions[$qid]['answers'])) {
$currentQuestion['question'] = $questions[$qid]['question'];
$currentQuestion['aid'] = $answer;
$currentQuestion['answer'] = $questions[$qid]['answers'][$answer]['answer'];;
} else {
$currentQuestion['question'] = $questions[$qid]['question'];
$currentQuestion['aid'] = null;
$currentQuestion['answer'] = $answer;
}
}
}
}
return $requests;
}
Я, честно говоря, так и не разобрался что "это" делает...
+141.4
function findRequest($id) {
$query =
'SELECT * ' .
'FROM `requests` ' .
'WHERE `requests`.`id` = \'' . mysql_escape_string($id) . '\' ' .
'LIMIT 0,1 ' .
'';
$request = $this->execQuery($query);
if ( !$request) {
$this->lastError = 'Error getting user\'s data. ';
return false;
} else {
$request[0]['quiz'] = unserialize(
unserialize($request[0]['quiz'])
);
}
return $request;
}
Оригинальная пунктуация сохранена