1. PHP / Говнокод #1978

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    $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;
    		}

    kovel, 14 Октября 2009

    Комментарии (4)
  2. PHP / Говнокод #1974

    +161.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 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;}

    интересный способ чтения файла в WR-Counter )))

    inso, 14 Октября 2009

    Комментарии (1)
  3. PHP / Говнокод #1973

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    <?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;
        }

    Вот такая вот жесть бывает. Изменение счетчиков на форуме (денормализация) с использованием альфа-версии кверибилдера. по-моему — устрашающе)

    Shock, 13 Октября 2009

    Комментарии (7)
  4. PHP / Говнокод #1970

    +165.2

    1. 1
    2. 2
    3. 3
    function nik_slashes(&$value)     {
         return (stripslashes($value));
    }

    Коллега сделал свою функцию для удаления слэшей с блек джеком и всем прочим.

    Acid Beast, 13 Октября 2009

    Комментарии (13)
  5. PHP / Говнокод #1968

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    <?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() люди не знали.

    fatlazyanimal, 12 Октября 2009

    Комментарии (3)
  6. PHP / Говнокод #1960

    +154.8

    1. 1
    2. 2
    3. 3
    4. 4
    final class Graph extends DefaultModule implements IModule {
    ..........
    	protected function getDataByDate() {
    ..........

    Интересно, какой скрытый смысл protected-метода в final-классе...

    darkmyan, 12 Октября 2009

    Комментарии (7)
  7. PHP / Говнокод #1953

    +160.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    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;
    }

    Функция проверки дружбы между двумя людьми... ***дец

    getrix, 11 Октября 2009

    Комментарии (12)
  8. PHP / Говнокод #1952

    +159.4

    1. 1
    2. 2
    3. 3
    4. 4
    if (Auth_OpenID_noMathSupport()) {
            $null = null;
            return $null;
        }

    взято в PHP OpenID, модуль BigMath.php, function Auth_OpenID_getMathLib

    scanterkk, 09 Октября 2009

    Комментарии (3)
  9. PHP / Говнокод #1949

    +158.6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    <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>

    kovel, 09 Октября 2009

    Комментарии (4)
  10. PHP / Говнокод #1948

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    $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;
        }

    Я, честно говоря, так и не разобрался что "это" делает...

    Bartelby, 07 Октября 2009

    Комментарии (6)