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

    +159

    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
    <?php
    	if($showCapcha != 'showCapcha_0') {
    		echo 'Решите пример: ';
    		$secretCode_1 = rand(1 , 9);
    		$secretCode_2 = rand(1 , 9);
    		$secretCode = $secretCode_1 + $secretCode_2;
    		echo "<strong>" . $secretCode_1 . "</strong> + <strong>" . $secretCode_2 . "</strong> = ";
    		echo '
    			<input id="button_form_contact" type="text" name="secretCode" value="" />
    			<input type="hidden" name="secretCodeHide" value="'.$secretCode.'" />
    		';
    	}
    ?>
    <input id="button_form_contact" type="submit" value=" <?php echo MOD_CON_AM_GO_GO__; ?> ">

    Всё хватит придумывать капчи! Всё уже придумано xDDDD

    nethak, 11 Февраля 2011

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

    +163

    1. 1
    2. 2
    3. 3
    function isInt($val) {
        return is_int($val) || (string)(int)$val === (string)$val;
    }

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

    govnomes, 11 Февраля 2011

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # Преоброзование расширения в MIME тип
    function replace_type_in_mime($type) {
    	$type = strtolower($type);
    	$res = array("323" => "text/h323", "acx" => "application/internet-property-stream", "ai" => "application/postscript", "aif" => "audio/x-aiff", "aifc" => "audio/x-aiff", "aiff" => "audio/x-aiff", "asf" => "video/x-ms-asf", "asr" => "video/x-ms-asf", "asx" => "video/x-ms-asf", "au" => "audio/basic", "avi" => "video/x-msvideo", "axs" => "application/olescript", "bas" => "text/plain", "bcpio" => "application/x-bcpio", "bin" => "application/octet-stream", "bmp" => "image/bmp", "c" => "text/plain", "cat" => "application/vnd.ms-pkiseccat", "cdf" => "application/x-cdf", "cer" => "application/x-x509-ca-cert", "class" => "application/octet-stream", "clp" => "application/x-msclip", "cmx" => "image/x-cmx", "cod" => "image/cis-cod", "cpio" => "application/x-cpio", "crd" => "application/x-mscardfile", "crl" => "application/pkix-crl", "crt" => "application/x-x509-ca-cert", "csh" => "application/x-csh", "css" => "text/css", "dcr" => "application/x-director", "der" => "application/x-x509-ca-cert", "dir" => "application/x-director", "dll" => "application/x-msdownload", "dms" => "application/octet-stream", "doc" => "application/msword", "dot" => "application/msword", "dvi" => "application/x-dvi", "dxr" => "application/x-director", "eps" => "application/postscript", "etx" => "text/x-setext", "evy" => "application/envoy", "exe" => "application/octet-stream", "fif" => "application/fractals", "flr" => "x-world/x-vrml", "gif" => "image/gif", "gtar" => "application/x-gtar", "gz" => "application/x-gzip", "h" => "text/plain", "hdf" => "application/x-hdf", "hlp" => "application/winhlp", "hqx" => "application/mac-binhex40", "hta" => "application/hta", "htc" => "text/x-component", "htm" => "text/html", "html" => "text/html", "htt" => "text/webviewhtml", "ico" => "image/x-icon", "ief" => "image/ief", "iii" => "application/x-iphone", "ins" => "application/x-internet-signup", "isp" => "application/x-internet-signup", "jfif" => "image/pipeg", "jpe" => "image/jpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "js" => "application/x-javascript", "latex" => "application/x-latex", "lha" => "application/octet-stream", "lsf" => "video/x-la-asf", "lsx" => "video/x-la-asf", "lzh" => "application/octet-stream", "m13" => "application/x-msmediaview", "m14" => "application/x-msmediaview", "m3u" => "audio/x-mpegurl", "man" => "application/x-troff-man", "mdb" => "application/x-msaccess", "me" => "application/x-troff-me", "mht" => "message/rfc822", "mhtml" => "message/rfc822", "mid" => "audio/mid", "mny" => "application/x-msmoney", "mov" => "video/quicktime", "movie" => "video/x-sgi-movie", "mp2" => "video/mpeg", "mp3" => "audio/mpeg", "mpa" => "video/mpeg", "mpe" => "video/mpeg", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpp" => "application/vnd.ms-project", "mpv2" => "video/mpeg", "ms" => "application/x-troff-ms", "mvb" => "application/x-msmediaview", "nws" => "message/rfc822", "oda" => "application/oda", "p10" => "application/pkcs10", "p12" => "application/x-pkcs12", "p7b" => "application/x-pkcs7-certificates", "p7c" => "application/x-pkcs7-mime", "p7m" => "application/x-pkcs7-mime", "p7r" => "application/x-pkcs7-certreqresp", "p7s" => "application/x-pkcs7-signature", "pbm" => "image/x-portable-bitmap", "pdf" => "application/pdf", "pfx" => "application/x-pkcs12", "pgm" => "image/x-portable-graymap", "pko" => "application/ynd.ms-pkipko", "pma" => "application/x-perfmon", "pmc" => "application/x-perfmon", "pml" => "application/x-perfmon", "pmr" => "application/x-perfmon", "pmw" => "application/x-perfmon", "pnm" => "image/x-portable-anymap");
    	if($ret == null) {
    		$ret = "application/x-unknown-content-type";
    	} else {
    		$ret = $res[$type];
    	}
    	return $ret;
    }

    Не знаю смешно ли это или нет, но разобраться в одной километровой строке будет ооочень интересно))))
    Я вас огорчу, пришлось урезать на несколько тысяч символов эту дистанцию))

    nethak, 11 Февраля 2011

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

    +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
    function getAvailablePrivileges(Workset_Model_Object_Interface $resource, $where = null, $order = null, $limit = null, $offset = null, $offsetByPage = false) {
    
            if (true == $offsetByPage) {
                $offset = $this->getPageOffset($limit, $offset);
            }
    
    	$table = $this->_getTable();
    	$select = $table->prepareSelect($where, $order, $limit, $offset);
    
            $iselect = $this->_getTable()->select();
    
            $iselect->from(
                array('m' => $this->_getTable()->info(Zend_Db_Table_Abstract::NAME)),
                array('id')
            )
           ->join(
                array('i' => $this->_getTable($this->_linkedObjectTableClass)->info(Zend_Db_Table_Abstract::NAME)),
                "i.privilege_id = m.id",
                array()
            )
            ->where(
                'i.resource_id = ?', $resource->getId()
            );
    
            $select->where("id not in(?)", new Zend_Db_Expr($iselect->assemble()));
    
            $rowset = $table->fetchAll($select);
    
            return $this->getIterator($rowset, array(
                'countRows' => $this->_countAllRecords,
                'filter' => $select
            ));
    
        }

    Из проекта на Zend

    govnomes, 11 Февраля 2011

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

    +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
    if($amount > 0) :
    	if (is_dir($directory)) {
    		if ($open_dir = opendir($directory)) {
    			$a = 0; $b = 0;
    			while (false !== ($file = readdir($open_dir))) {
    				if ($file != "." && $file != ".." && !is_dir($directory."/".$file)) {
    					$a++;
    					if($a > $min) {
    						$b++;
    						echo "<tr id=\"am-list-input\" valign=\"center\" height: 20px;><td align=\"left\" width=\"10%\">";
    						echo " <a href=\"index.php?am=mod[uploader]&delete=$file\"><img src=\"../images/mini_icons/del.png\" /></a> ";
    						if(in_array(strtolower(getExtension($file)), $gud_types)) echo "<span OnClick=\"CaricaFoto('".$directory."/".$file."')\" OnMouseOver=\"Tip('<img style="max-width: 400px" src="".$directory."/".$file."" >')\"><img style=\"cursor: help\" src=\"../images/mini_icons/display.png\" /></span>";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram")))) echo "<img src=\"modules/mod[uploader]/assets/type/sound.png\" />";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv")))) echo "<img src=\"modules/mod[uploader]/assets/type/video.png\" />";
    						if(!in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv,mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram,jpg,jpeg,png,gif")))) echo "<img src=\"modules/mod[uploader]/assets/type/all.png\" />";
    						echo "</td><td width=\"70%\"><span style=\"display: block; cursor: pointer; color: #446eb8; font-weight: bold; line-height: 16px;\" onClick=\"document.getElementById('onclick').value='".str_replace("..", $conf_global["base_url"], $directory)."/".$file."'\" />".substr($file, 0, 100)."</span></td><td width=\"20%\">".formatsize(filesize($directory.DS.$file))."</td></tr>";
    						if($b == $max) : break; endif;
    					}
    				}
    			}
    		closedir($open_dir);
    		}
    	}
    endif;

    Грех не посмеятся над своими старыми проектами =)))

    nethak, 11 Февраля 2011

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

    +172

    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
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    /* Теперь задаём сами функции перекодировки translita в кириллицу и обратно. Вот код: */
    
    function ruslat ($string) # Задаём функцию перекодировки кириллицы в транслит.
    {
    $string = ereg_replace("ж","zh",$string);
    $string = ereg_replace("ё","yo",$string);
    $string = ereg_replace("й","i",$string);
    $string = ereg_replace("ю","yu",$string);
    $string = ereg_replace("ь","'",$string);
    $string = ereg_replace("ч","ch",$string);
    $string = ereg_replace("щ","sh",$string);
    $string = ereg_replace("ц","c",$string);
    $string = ereg_replace("у","u",$string);
    $string = ereg_replace("к","k",$string);
    $string = ereg_replace("е","e",$string);
    $string = ereg_replace("н","n",$string);
    $string = ereg_replace("г","g",$string);
    $string = ereg_replace("ш","sh",$string);
    $string = ereg_replace("з","z",$string);
    $string = ereg_replace("х","h",$string);
    $string = ereg_replace("ъ","''",$string);
    $string = ereg_replace("ф","f",$string);
    $string = ereg_replace("ы","y",$string);
    $string = ereg_replace("в","v",$string);
    $string = ereg_replace("а","a",$string);
    $string = ereg_replace("п","p",$string);
    $string = ereg_replace("р","r",$string);
    $string = ereg_replace("о","o",$string);
    $string = ereg_replace("л","l",$string);
    $string = ereg_replace("д","d",$string);
    $string = ereg_replace("э","yе",$string);
    $string = ereg_replace("я","jа",$string);
    $string = ereg_replace("с","s",$string);
    $string = ereg_replace("м","m",$string);
    $string = ereg_replace("и","i",$string);
    $string = ereg_replace("т","t",$string);
    $string = ereg_replace("б","b",$string);
    $string = ereg_replace("Ё","yo",$string);
    $string = ereg_replace("Й","I",$string);
    $string = ereg_replace("Ю","YU",$string);
    $string = ereg_replace("Ч","CH",$string);
    $string = ereg_replace("Ь","'",$string);
    $string = ereg_replace("Щ","SH'",$string);
    $string = ereg_replace("Ц","C",$string);
    $string = ereg_replace("У","U",$string);
    $string = ereg_replace("К","K",$string);
    $string = ereg_replace("Е","E",$string);
    $string = ereg_replace("Н","N",$string);
    $string = ereg_replace("Г","G",$string);
    $string = ereg_replace("Ш","SH",$string);
    $string = ereg_replace("З","Z",$string);
    $string = ereg_replace("Х","H",$string);
    $string = ereg_replace("Ъ","''",$string);
    $string = ereg_replace("Ф","F",$string);
    $string = ereg_replace("Ы","Y",$string);
    $string = ereg_replace("В","V",$string);
    $string = ereg_replace("А","A",$string);
    $string = ereg_replace("П","P",$string);
    $string = ereg_replace("Р","R",$string);
    $string = ereg_replace("О","O",$string);
    $string = ereg_replace("Л","L",$string);
    $string = ereg_replace("Д","D",$string);
    $string = ereg_replace("Ж","Zh",$string);
    $string = ereg_replace("Э","Ye",$string);
    $string = ereg_replace("Я","Ja",$string);
    $string = ereg_replace("С","S",$string);
    $string = ereg_replace("М","M",$string);
    $string = ereg_replace("И","I",$string);
    $string = ereg_replace("Т","T",$string);
    $string = ereg_replace("Б","B",$string);
    return $string;
    }

    Нашел сие чудо на: http://protoplex.ru/lib/?showid=89

    code_master, 10 Февраля 2011

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

    +166

    1. 1
    2. 2
    $pif=explode('?',$_SERVER['REQUEST_URI']);
    $tym=explode('=',$pif[1]);

    Вот такой вот способ получить значение переменной из GET запроса вида:
    http://127.0.0.1/component/index.php?name=r37.edoc

    isergey, 10 Февраля 2011

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    $p = array(1,0,0,0,0,0,0,0,0,0); // вероятность 1/10
    $a = array();
    for($i=0; $i<100; $i++) 
    	$a[] = $p[mt_rand(0, count($p)-1)];

    Это — заполнение массива случайными значениями с заданной вероятностью 1 к 10. =)

    Kevin, 10 Февраля 2011

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

    +164

    1. 1
    2. 2
    RewriteRule ^tn_([0-9]*)x([0-9]*)_([a-z]+)_([0-9]*)_([0-9]+)_(.*)_([c]*)_([f]*)_([0-9]*).[a-z]*$ перенос
    /index.php?exception=imageModification&width=$1&height=$2&module=$3&id=$4&time=$5&name=$6&crop=$7&force=$8&query=$9&file_name=%{REQUEST_URI} [L]

    В .htaccess:
    Победа над ресайзом картинок. Чуваки еще не успели ощутить на себе всю мощь ананимуса

    ifeya, 10 Февраля 2011

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?php if ( $row->type ){ ?>
    <?php if ( $row->type==1 ){ ?><?php echo _EZREALTY_TYPE_SALE;?><?php } ?>
    <?php if ( $row->type==2 ){ ?><?php echo _EZREALTY_TYPE_RENTAL;?><?php } ?>
    <?php if ( $row->type==3 ){ ?><?php echo _EZREALTY_TYPE_LEASE;?><?php } ?>
    <?php if ( $row->type==4 ){ ?><?php echo _EZREALTY_TYPE_AUCTION;?><?php } ?>
    <?php if ( $row->type==5 ){ ?><?php echo _EZREALTY_TYPE_SWAP;?><?php } ?>
    <?php if ( $row->type==6 ){ ?><?php echo _EZREALTY_TYPE_TENDER;?><?php } ?>
    <?php } ?>

    Компонент joomla ezrealty)

    antongorodezkiy, 10 Февраля 2011

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