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

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function AdminMain()
    {
    	global $config, $user, $site, $db; // $user, $site и $db используются в подпрограммах.
    
    	if(isset($_GET['exe']) && $_GET['exe'] == 'exit'){
    		$user->UnsetCookie('admin');
    		GO(Ufu('index.php'));
    	}elseif(!isset($_GET['exe'])){
    		$exe = 'adminpanel';
    	}else{
    ...
    }

    из LinkorCMS...

    invision70, 06 Июля 2011

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

    +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
    $y=date("Y"); $m=date("n"); $d=date("d");
    if($d>1) {$d1=$d-1; $m1=$m; $y1=$y;}
    if($d==1 && $m>1) {$d1=date('t',mktime(0, 0, 0, $m-1, 1, $y)); $m1=$m-1; $y1=$y;}
    if($d==1 && $m==1) {$d1=date('t',mktime(0, 0, 0, 12, 1, $y)); $m1=12; $y1=$y-1;}
    
    echo "Вчера - $d1.$m1.$y1";
    
    if($d>2) {$d2=$d-2; $m2=$m; $y2=$y;}
    if($d==2 && $m>1) {$d2=date('t',mktime(0, 0, 0, $m-1, 1, $y)); $m2=$m-1; $y2=$y;}
    if($d==2 && $m==1) {$d2=31; $m2=12; $y2=$y-1;}
    if($d==1 && $m>1) {$d2=date('t',mktime(0, 0, 0, $m-1, 1, $y))-1; $m2=$m-1; $y2=$y;}
    if($d==1 && $m==1) {$d2=30; $m2=12; $y2=$y-1;}
    
    echo "Позавчера - $d2.$m2.$y2";

    Решение в лоб - зато полностью рабочее. Обнаружил в собственном проекте (вполне действующем).

    Spryt, 06 Июля 2011

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

    +160

    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
    /*
    		* Быстрая навигация
    		*/
    		if(isset($url[1]))
    		{
    			if(isset($component_array[$url[1]]))
    			{
    				if(isset($component_array[$url[1]]['subAct']))
    				{
    					foreach($component_array[$url[1]]['subAct'] as $comAct => $comActLink)
    					{
    						$subNav .= '<span' . ((isset($url[2]) && $url[2] == $comActLink OR !isset($url[2]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/' . $url[1] . '/' . $comActLink . '">' . $comAct . '</a></span>';
    					}
    				}
    				
    				$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/' . $url[1] . '">' . $component_array[$url[1]]['name'] . '</a></span>';
    			}
    			elseif(isset($url[2]) && isset($module_array[$url[2]]))
    			{
    				if(isset($module_array[$url[2]]['subAct']))
    				{
    					foreach($module_array[$url[2]]['subAct'] as $comAct => $comActLink)
    					{
    						$subNav .= '<span' . ((isset($url[3]) && $url[3] == $comActLink OR !isset($url[3]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/module/' . $url[2] . '/' . $comActLink . '">' . $comAct . '</a></span>';
    					}
    				}
    				
    				$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/module/' . $url[2] . '">' . $module_array[$url[2]]['name'] . '</a></span>';
    			}
    			elseif(isset($services_array[$url[1]]))
    			{
    				if(isset($services_array[$url[1]]['subAct']))
    				{
    					foreach($services_array[$url[1]]['subAct'] as $comAct => $comActLink)
    					{
    						$subNav .= '<span' . ((isset($url[2]) && $url[2] == $comActLink OR !isset($url[2]) && $comActLink == '') ? ' class="navMainActive"' : '') . '><a href="' . ADMIN . '/' . $url[1] . '/' . $comActLink . '">' . $comAct . '</a></span>';
    					}
    				}
    				
    				$noSub = '<span class="navMainActive"><a href="' . ADMIN . '/' . $url[1] . '">' . $services_array[$url[1]]['name'] . '</a></span>';
    			}
    		}

    Кусок из Toogle CMS.
    facepalm.

    invision70, 05 Июля 2011

    Комментарии (5)
  5. Куча / Говнокод #7159

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    .gaia.sub.el { font-family: arial, sans-serif; font-size: smaller; font-weight: bold;}
      .gaia.sub.pl { font-family: arial, sans-serif; font-size: smaller; font-weight: bold; }
      .gaia.sub.rpl { font-family: arial, sans-serif; font-size: smaller; font-weight: bold; }
      .gaia.sub.es { font-family: arial, sans-serif; font-size: smaller; font-style: italic; }
      .gaia.sub.seex { font-family: arial, sans-serif; font-size: smaller; color: #6f6f6f; }
      .gaia.sub.pc { font-family: arial,sans-serif; font-size: smaller; color: #6f6f6f; }

    Аккаунты Google. Запятые? Не, не слышал.

    stuffort, 05 Июля 2011

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

    +163

    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
    $res=mysql_query("SELECT * FROM `admin` ");
       $nam=mysql_result($res, 0, "name");
       $psw=mysql_result($res, 0, "pass");
       $snm=mysql_result($res, 0, "sitename");
       $ops=mysql_result($res, 0, "opis");
       $key=mysql_result($res, 0, "keyw");
       $rul=mysql_result($res, 0, "rules");
       $mls=mysql_result($res, 0, "lst");
       $mnm=mysql_result($res, 0, "mxnm");
       $mur=mysql_result($res, 0, "mxur");
       $mop=mysql_result($res, 0, "mxop");
       $mky=mysql_result($res, 0, "mxky");
       $mem=mysql_result($res, 0, "mxem");
       $mps=mysql_result($res, 0, "mxps");
       $mil=mysql_result($res, 0, "mail");
       $adr=mysql_result($res, 0, "adres");
       $logo=mysql_result($res, 0, "logo");
       $txlogo=mysql_result($res, 0, "txlogo");
       $copir=mysql_result($res, 0, "copirat");
       $blokrekl=mysql_result($res, 0, "blokrekl");

    Rinat, 04 Июля 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    <title><?php getSiteName();echo ' - ';getTitle();?></title>
    // Еще
                  if(isset($errors['sitename']))  echo '<span class="error"><li>'.$errors['sitename'].'</li></span>';
                    if(isset($errors['siteurl']))   echo '<span class="error"><li>'.$errors['siteurl'].'</li></span>';
                    if(isset($errors['login']))     echo '<span class="error"><li>'.$errors['login'].'</li></span>';
                    if(isset($errors['password']))  echo '<span class="error"><li>'.$errors['password'].'</li></span>';
                    if(isset($errors['email']))     echo '<span class="error"><li>'.$errors['email'].'</li></span>'

    Пример из template cms =)

    invision70, 04 Июля 2011

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

    +147

    1. 1
    2. 2
    3. 3
    if ($this->alias === null) {
    			$this->alias = (isset($alias) ? $alias : $this->name);
    		}

    Это cakePHP. Вот так вот в нём модель узнаёт свой alias.

    zabuhailo, 28 Июня 2011

    Комментарии (5)
  9. ActionScript / Говнокод #7087

    −113

    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
    private function formatResponse( map:Dictionary ):String
    		{
    // В этой функции было больше строчек, я оставил только те, где используется map
    			ha1_1.writeUTFBytes( map.username + ":" + map.realm + ":" + password );
    			ha1_2.writeUTFBytes( ":" + map.nonce + ":" + map.cnonce );
    			ha2.writeUTFBytes( "AUTHENTICATE:" + map[ "digest-uri" ] );
    			b.writeUTFBytes( sha1 + ":" + map.nonce + ":" + map.nc + ":" + map.cnonce + ":" + map.qop + ":" + sha2 );
    			return Hex.fromArray( b );
    		}
    
    		override public function handleChallenge( stage:int, challenge:XML ):XML
    		{
    			var decodedChallenge:String = Base64.decode( challenge );
    			var challengeKeyValuePairs:Array = decodedChallenge.replace( /\"/g, "").split( "," );
    			var challengeMap:Dictionary = new Dictionary();
    			for each( var keyValuePair:String in challengeKeyValuePairs )
    			{
    				var keyValue:Array = keyValuePair.split( "=" );
    				challengeMap[ keyValue[ 0 ] ] = keyValue[ 1 ];
    			}
    
    			var resp:XML = new XML( response );
    			resp.setNamespace( DigestMD5.NS );
    
    			if( !challengeMap.rspauth )
    			{
    				var responseMap:Dictionary = new Dictionary();
    				responseMap.username = connection.username;
    				responseMap.realm = challengeMap.realm ? challengeMap.realm : "";
    				responseMap.nonce = challengeMap.nonce;
    				responseMap.cnonce = new Date().time;
    				responseMap.nc = "00000001";
    				responseMap.qop = challengeMap.qop ? challengeMap.qop : "auth";
    				responseMap[ "digest-uri" ] = "xmpp/" + ( challengeMap.realm ? challengeMap.realm : connection.domain );
    				responseMap.charset = challengeMap.charset;
    				responseMap.response = formatResponse( responseMap );
    
    				var challengeResponse:String = "username=\"" + responseMap.username + "\"";
    				if( challengeMap.realm ) challengeResponse += ",realm=\"" + responseMap.realm + "\"";
    				challengeResponse += ",nonce=\"" + responseMap.nonce + "\"";
    				challengeResponse += ",cnonce=\"" + responseMap.cnonce + "\"";
    				challengeResponse += ",nc=" + responseMap.nc;
    				challengeResponse += ",qop=" + responseMap.qop;
    				challengeResponse += ",digest-uri=\"" + responseMap[ "digest-uri" ] + "\"";
    				challengeResponse += ",response=" + responseMap.response;
    				challengeResponse += ",charset=" + responseMap.charset;
    				challengeResponse = Base64.encode( challengeResponse );
    
    				resp.setChildren( challengeResponse );
    			}
    
    			return resp;
    		}

    Тут довольно много читать, но если вы не побоитесь и все же осилите, то откроете для себя еще один уголок прекрасного. Часть кода из первой функции вырезана т.как приниципиального значения не имела. Код явно переписан с чего-то похожего на Java человеком который ни разу не открыл маны по AS3.
    Целиком обозреть бессмертное творение можно тут: http://fisheye.igniterealtime.org/browse/~raw,r=12385/sparkweb/trunk/SparkWeb2/src/org/igniterealtime/xiff/auth/DigestMD5.as

    wvxvw, 27 Июня 2011

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

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function check() {
    
    if (document.login.user.value == "user" &&
    document.login.password.value == "correct_password")
        window.location.href = 'http://this.site/login.html';
    else
        window.location.href = 'http://this.site/loginfehler.html';
    
    return false;
    }

    yasosiska, 27 Июня 2011

    Комментарии (5)
  11. JavaScript / Говнокод #7072

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function nyak_nyak(el) {
        if (confirm("Вы уверены в своих действиях?")) {
            document.location = el.href;
    	}
        return false;
    }

    yasosiska, 27 Июня 2011

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