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

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    {|if $message=="ok"|}
        <div style="text-align: center; padding:10px; margin:10px; color: white; font-weight: bold; background-color: green;">Your message has successfully been added.</div>
    {|/if|}
    {|if $message=="error"|}
        <div style="text-align: center; padding:10px; margin:10px; color: white; font-weight: bold; background-color: red;">Mistake. You filled out the wrong form.</div>
    {|/if|}

    Красивое использование CSS.

    max_wp, 03 Июня 2011

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

    +158

    1. 1
    2. 2
    3. 3
    {foreach from=$deal_data|array_slice:(($page_number - 1) * $deals_per_page):$deals_per_page item=deal name=deal_data}
    ...
    {/foreach}

    Зачем делать нормальный пейджинг когда и так работает? :)

    kovel, 02 Июня 2011

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

    +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
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    public function getRelatedDataProvider($relationName,$config=array(),$params=array()){
    		
    		$md = $this->getMetaData();
    		if(!isset($md->relations[$relationName])){
    			throw new CDbException(Yii::t('yii','{class} does not have relation "{name}".',
    				array('{class}'=>get_class($this), '{name}'=>$relationName)));
    		}
    		
    		$relation = $md->relations[$relationName];
    		if(!($relation instanceof CHasManyRelation || $relation instanceof CManyManyRelation)){
    			throw new CDbException(Yii::t('yii','Связь {class}.{name} имеет тип, отличный от Has_Many и Many_Many.',
    				array('{class}'=>get_class($this), '{name}'=>$relationName)));
    		}
    		
    		// return new CArrayDataProvider($this->getRelated($relationName,true,$params), $config);
    		
    		var_dump($relation);
    		
    		// копируем критерии из связи
    		$criteria = new CDbCriteria;
    		foreach(array('select', 'condition', 'params', 'limit', 'offset', 'order', 'group', 'join', 'having', 'with', 'alias', 'index', 'together') as $param){
    			$criteria->$param = $relation->$param;
    		}
    		
    		// склеиваем параметры с критерией
    		$criteria->mergeWith(
    			is_string($params)
    				? array('condition' => $params)
    				: $params
    		);
    		
    		// добавляем связь через fk
    		// ВОТ ТУТ Я НИЧЕГО НЕ ПОНИМАЮ :)
    		$thisTable = $this->getTableAlias();
    		$childModel = CActiveRecord::model($relation->className);
    		$childMd = $childModel->getMetaData();
    		$childTable = empty($relation->alias) ? $childModel->getTableAlias() : $relation->alias;
    		//$criteria->join .= " {$relation->joinType} {$thisTable} ON {$thisTable}.{$relation->foreignKey}={$childTable}.{$childMd->tableSchema->primaryKey}";
    		$criteria->params[':fkrel'] = $this->{$relation->foreignKey};
    		$criteria->addCondition("{$childTable}.{$relation->foreignKey}=:fkrel");
    		
    		
    		// собираем кофиг для CActiveDataProvider
    		$dpConfig = array(
    			'criteria' => $criteria,
    		) + $config;
    		
    		echo "CActiveDataProvider( {$relation->className} , criteria: ".var_export($dpConfig['criteria']->toArray(),true)." )";
    		
    		// 
    		$dataProvider = new CActiveDataProvider(
    			$relation->className,
    			$dpConfig
    		);
    		
    		return $dataProvider;
    	}
    	
    }

    res-nullis, 26 Мая 2011

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

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (условие)
     echo 'FILE TO DELETE '.$file;
    }
    
    // затем делается
    
    if(условие)
     echo 'FILE TO DELETE '.$file;
     unlink($file);
    }

    ...и после запуска заметить, что скобочка закрывает не этот иф.

    hdkeeper, 12 Мая 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
     * Returns the symbol the adapter uses for delimited identifiers.
     *
     * @return string
     */
    public function getQuoteIdentifierSymbol() {
        return '"';
    }

    zend :)

    rO_ot, 05 Мая 2011

    Комментарии (25)
  7. JavaScript / Говнокод #6514

    +158

    1. 1
    if(typeof n!="number"&&(k==Number||!(n instanceof Number))||p.round(n)!=n||n==NaN||n==Infinity)return!1;

    http://www.google-analytics.com/ga.js
    Инженеры в Гугле знают толк в JavaScript'e.

    wvxvw, 29 Апреля 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($result === false) {
                $result = $translated;
            }
    
            if ($result === false){
                $result = $translated;
            }

    Magento. Так работают переводы.

    vsushkov, 28 Апреля 2011

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

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    foreach ($firstQueryRes as $row)
    			{
    				$K = $this->ccnm;
    				$U = $this->getFncByCategory($row->category);  // compile material href //
    				$R = $row->category;
    				$W = $row->date;
    				$A = $row->huu_1;
    				$materialHref[$row->id_all] = site_url("$K/$U/$R/$W/$A");
    				$materialTitle[$row->id_all] = $row->name;
    			}

    Задание: расшифруйте какое польское плохое слово здесь инкапсулировано.

    increazon, 21 Апреля 2011

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

    +158

    1. 1
    {{capture assign=isSmtng}}1{{/capture}}

    Опять смарти. Кто-то обьяснит чем указанное решение лучше этого?
    {{assign var="isSmtng" value="1"}}

    govno, 19 Апреля 2011

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

    +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
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    <script type="text/javascript"> 
         jQuery('.container').cycle({
        fx:     'scrollHorz',
        prev:   '#prev2',
        next:   '#next2',
        timeout: 0});
        </script>
        <img id="prev2" src="<?=$this->getSkinUrl('images/leftarr.png')?>" alt="Left Arrow" /> 
    <?php     foreach ($_gallery as $_image)
            $__gallery[] = $_image;
    ?>    
        <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
        <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+1) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
            <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+2) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>
            <ul class="container">
        <?php
    
        for($i = 0;$i < count($__gallery);$i++):
            $_image = $__gallery[($i+3) % count($__gallery)];
        ?>
            <li>
                <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
            </li>         
        <?php endfor; ?>
        </ul>

    слайдер с прокруткой с помощью цайкла

    jjonghyo, 19 Апреля 2011

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