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

    +165

    1. 1
    2. 2
    return $result_rows;
    mysql_close($external_db);

    Ring, 30 Мая 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    //This is an optimization. We assume than no step can take more than one year.
      if($time_limit > 0)
       $end_time = time() + $time_limit;
      else
       $end_time = time() + 365*24*3600; // One year

    Источник: исходники битрикса, (/bitrix/modules/iblock/classes/general/cml2.php). Код используется при импорте из 1с.

    leonard, 30 Мая 2011

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

    +165

    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
    function func($microsoft,$corn)
    {
    	$tomato=array();
    	if(!isset($corn[$microsoft])) return NULL;
    	foreach($corn[$microsoft] as $potato=>$pizza)
    	{
    		$tomato[]=$pizza;
    		$wine=$this->func($microsoft.$pizza['name'].'/',$corn);
    		if($wine)
    			foreach($wine as $anchouses)
    				$tomato[]=$anchouses;
    	}
    	return $tomato; //Где мой тамат СУКА!
    }

    Функция выполняет рекурсивную сортировку масива по ассоциативному индексу.

    dvduser, 30 Мая 2011

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

    +152

    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
    if (mysql_query("UPDATE `users` as u, `inventory` as i SET u.{$slot1} = {$id}, i.dressed = 1,
    			u.sila = u.sila + i.gsila,
    			u.lovk = u.lovk + i.glovk,
    			u.inta = u.inta + i.ginta,
    			u.intel = u.intel + i.gintel,
    			u.maxhp = u.maxhp + i.ghp,
    			u.maxmana = u.maxmana + i.gmana,
    			u.noj = u.noj + i.gnoj,
    			u.topor = u.topor + i.gtopor,
    			u.dubina = u.dubina + i.gdubina,
    			u.mec = u.mec + i.gmech,
    			u.mfire = u.mfire + i.gfire,
    			u.mwater = u.mwater + i.gwater,
    			u.mair = u.mair + i.gair,
    			u.mearth = u.mearth + i.gearth,
    			u.mlight = u.mlight + i.glight,
    			u.mgray = u.mgray + i.ggray,
    			u.mdark = u.mdark + i.gdark
    				WHERE
    			i.needident = 0 AND
    			i.id = {$id} AND
    			i.dressed = 0 AND
    			i.owner = {$user['id']} AND
    			u.sila >= i.nsila AND
    			u.lovk >= i.nlovk AND
    			u.inta >= i.ninta AND
    			u.vinos >= i.nvinos AND
    			u.intel >= i.nintel AND
    			u.mudra >= i.nmudra AND
    			u.level >= i.nlevel AND
    			((".(int)$user['align']." = i.nalign) or (i.nalign = 0)) AND
    			u.id = {$user['id']};")) {
    			$user[$slot1] = $item['id'];
    			return 	true;}
    		}

    все та же браузерка

    jQuery, 29 Мая 2011

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

    +171

    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
    if ($user['sex']) {
    		switch(@$_GET['obraz']) {
    			case 0:
    				mysql_query("UPDATE `users` SET `shadow` = 'm0.gif' WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;");
    				$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;"));
    			break;
    			case 1:
    				mysql_query("UPDATE `users` SET `shadow` = 'm1.gif' WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;");
    				$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;"));
    			break;
    			case 2:
    				mysql_query("UPDATE `users` SET `shadow` = 'm2.gif' WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;");
    				$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;"));
                            break;
    			/// не трудно догадаться, что здесь)
    			case 99:
    				mysql_query("UPDATE `users` SET `shadow` = 'm00.gif' WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;");
                                    $user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$_SESSION['uid']}' LIMIT 1;"));
                             break;
                       }
    }

    о как

    jQuery, 29 Мая 2011

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

    +152

    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
    $datetime=strtotime($new["date"]);
        $m=date("m", $datetime);
        if($m=='01') { $month="Янв"; }
        if($m=='02') {  $month="Фев"; }
        if($m=='03') {  $month="Март"; }
        if($m=='04') {  $month="Апр"; }
        if($m=='05') {  $month="Май"; }
        if($m=='06') {  $month="Июнь"; }
        if($m=='07') {  $month="Иль"; }
        if($m=='08') {  $month="Авг"; }
        if($m=='09') {  $month="Сен"; }
        if($m=='10') {  $month="Окт"; }
        if($m=='11') {  $month="Ноя"; }
        if($m=='12') {  $month="Дек"; }
        $date = date("d", $datetime);

    http://www.askdev.ru/php/6048/%D0%A0%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7%D0% B0%D1%86%D0%B8%D1%8F-%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD%D0% BE%D0%B2-%D0%BD%D0%B0-PHP/

    radioheaded, 27 Мая 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $str = $note['count'];
    
    $res = strpos($str, ',');
    
    if($res){echo substr($str,0,$res);}else{echo $str;}

    проверка на целое число

    sanya, 27 Мая 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class email_selector {
    
    private static $number_per_page = 30;//
    
    public function getNumberPerPage() {
        return self::$number_per_page;
    }
    
    }

    понятно, что это только кусок класса. увидев, просто не смог не запостить....

    CRRaD, 27 Мая 2011

    Комментарии (20)
  9. 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)
  10. PHP / Говнокод #6760

    +147

    1. 1
    2. 2
    3. 3
    <?php
    ///*********************************** PAYMENT MODULE START**************************//////
    ?>

    из шаблона CMS oscommerce. открываем режим php чтобы написать комментарий

    gorky, 26 Мая 2011

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