1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #12496

    +49

    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
    /**
        * Used to show configurable product attributes in case when all elements are out-of-stock
        * 
        * "$_product->isSaleable() &&" should be commented out at line #100 (where "container2" block is outputted) in catalog/product/view.phtml
        * to make this work
        * 
        * @see Mage_Catalog_Model_Product::isSalable
        * @param object $observer
        */
        public function onCatalogProductIsSalableAfter($observer)
        {
            if (Mage::getStoreConfig('amstockstatus/general/outofstock'))
            {
                $salable = $observer->getSalable();
                $stack = debug_backtrace();
                foreach ($stack as $object)
                {
                    if (isset($object['file']))
                    {
                        if ($object['file'])
                        {
                            if ( isset($object['file']) && false !== strpos($object['file'], 'options' . DIRECTORY_SEPARATOR . 'configurable'))
                            {
                                $salable->setData('is_salable', true);
                            }
                        }
                    }
                }
            }
        }

    Вот такой вот веселый модуль для Magento, одна из возможностей которого - отобразить опции для всех out-of-stock вариантов конфигурируемого товара.

    vo1, 29 Января 2013

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    If($z["timeout"]==1 || $z['timeout']==3 || $z['timeout']==4 || $z['timeout']==5 || $z['timeout']==7 || $z['timeout']==10) { 
    }  else {
         $z['timeout'] = 3;
    }

    '<>' и 'or' ? неее, не слышали!

    RickMan, 17 Января 2013

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

    +49

    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
    function preDispatch() {
            
    		
    		
    		
    		// Validate and redirect
            try {
                $this->_DB = Zend_Db_Table::getDefaultAdapter();
                $time = $this->_DB->query('SELECT time FROM `CapturesList` WHERE InnerLink = \'' . $_SERVER['REQUEST_URI'] . '\' LIMIT 0,1;')->fetchAll();
    
    
    		@$this->view->time = $time[0]['time'];
    
    
                if ($time[0]['time'] != NULL) {
                    $times = split(', ', $time[0]['time']);
                    if (strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00") < (int) (mktime())) {
                        if (strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00") > 1347032555) {
                            $count = $this->_DB->query('SELECT *, COUNT(time) AS counts FROM `CapturesList` WHERE time IS NOT NULL;')->fetchAll();
                            $count = $count[0]['counts'];
                            @$newdate = strftime("%G, %m, %d, %H", strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00 +" . ((int)($count / 2) + 1) . " weeks"));
                            @$this->_DB->query('UPDATE `CapturesList` SET `time` = \'' . ($newdate) . '\' WHERE InnerLink = \'' . $_SERVER['REQUEST_URI'] . '\';');
                            @$this->view->time = $newdate;
                        }
                        else{@$this->view->time = $time[0]['time'];}
                    } else {
                        @$this->view->time = $time[0]['time'];
                    }
                } else {
                    @$this->view->time = "NULL";
                }
            } catch (Exception $exc) {
                echo $exc->getTraceAsString();
                @$this->view->time = "NULL";
            }
    
    
    
            header('Refer: ' . $this->view->linktofunnel);
            if (session_id() == '')
                session_start();
            if ($this->_getParam('action') != 'save') {
                $_SESSION["domain"] = $this->view->domain;
                $_SESSION["owner"] = $this->OwnerData;
            }
        }

    Более говнокодного я давно не писал. Кажется я схожу с ума

    Stud, 06 Декабря 2012

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

    +49

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if($model->validate(array('code')))
    {
    	$model->addError('code', 'Введен неверный код купона. Купон с таким кодом уже существует.');
    }
    else
    {
    	if($model->save())
    	{
    		$this->redirect(array('view','id'=>$model->id));
    	}
    }

    sleeper, 12 Ноября 2012

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    ob_start();
    require_once realpath('.').'/email-template.html';
    $messageWithEwlTrailer = ob_get_contents();
    ob_end_clean();

    no comments

    anycolor, 18 Октября 2012

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

    +49

    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
    wordpress:
    function __( $text, $domain = 'default' ) {
    	        return translate( $text, $domain );
    }
    
    function translate( $text, $domain = 'default' ) {
    	        $translations = &get_translations_for_domain( $domain );
    	        return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
    }
    
    PHP-manual:
    PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality. 
    
    wordpress:
    /*
    * Don't use translate() directly, use __()
    */

    xcont, 12 Сентября 2012

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

    +49

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $em = $this->getDoctrine()->getEntityManager();
    $user = $em->getRepository('AdminBundle:AdminUser')
            ->findOneById($id);
    if ($user == $this->get('security.context')->getToken()->getUser()) {
            $this->get('session')->setFlash('admin-delete', 'TODO:TRANSLATE: Suicide is not allowed. Thank you!');
    } else {
            $em->remove($user);
            $em->flush();
            $this->get('session')->setFlash('admin-delete', 'TODO:TRANSLATE: User ' . $user->getEmail(). ' was deleted.');
    }

    Текст ошибок просто супер!

    EugeneC, 05 Сентября 2012

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
      * Test for method importData()
      */
    public function testImportData()
    {
         $this->_model->expects($this->once())
             ->method('_importData');
         $this->_model->importData();
     }

    Ценное юнит-тестирование правильности работы метода

    InnerJoin, 30 Августа 2012

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

    +49

    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
    /* КОСТЫЛИ ВЫ МОИ КОСТЫЛИ... */
    function safesql( $source )
     {
    	return @mysql_real_escape_string ($source);
    }
    function get_row($query_id = '')
    {
    	if ($query_id == '') $query_id = $this->lastResult;
    	return mysql_fetch_assoc($query_id);
    }
    ///------------------------- Немного в другом месте ----------------------///
    if (!is_null(Registry::get('database')->fetchNextObject()) or $admin)
    {
    	Registry::get('database')->execFormatSafe("DELETE FROM `%scomment` WHERE `_id` = '%s'", $pref, $id, $message);
    }
    else
    	return $errmess = "что то не так";

    Стыдно. Второй кусок кода мой. Как же всё меняется. Меньше года прошло

    s1Paris, 01 Июня 2012

    Комментарии (14)
  11. PHP / Говнокод #218

    +48.7

    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
    <?php
        global
            $_REQUEST,
            $_SERVER,
            $_FILES,
            $PHP_SELF,
            $_GET_VARS,$_GET,
            $_POST_VARS,  
            $_POST,
            $_COOKIE,
            $HTTP_ENV_VARS,
            $HTTP_SERVER_VARS,
            $_page,
            $_text,
            $_user,
            $_cook_session,
            $_page_index,
            $_page_title,
            $parce_page;
    
        extract($_GET);
        extract($_POST);
        extract($_FILES);
    
        while (list($key123, $value123) = each($_GET))    ${$key123}=$value123;
        while (list($key123, $value123) = each($_POST))   ${$key123}=$value123;
        while (list($key123, $value123) = each($_FILES))  ${$key123}=$value123;
    
        foreach ($_POST as $key=>$value) {
    	    ${$key}=$value;
    	}
        foreach ($_GET as $key=>$value) {
    	    ${$key}=$value;
    	}
    ?>

    Цитирую весь файл, как есть

    guest, 18 Декабря 2008

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