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

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function timesec($str) 
    { 
    $h = date("H", strtotime($str)); 
    $i = date("i", strtotime($str)); 
    $s = date("s", strtotime($str)); 
    $m = date("m", strtotime($str)); 
    $d = date("d", strtotime($str)); 
    $y = date("Y", strtotime($str)); 
    return mktime($h, $i, $s, $m, $d, $y); 
    }

    GoodTalkBot, 10 Июня 2011

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

    +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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    class Template{
    	var $result,$template_dir="templates";
    	function ParseTemplate($template,$var_name,$value){
    		$out=preg_replace("/$var_name/i","$value",$template);
    		return $out;
    	}
    	function ClearTemplate($var){
    		$var=str_replace("\n","",$var);
    		$var=str_replace("\t","",$var);
    		$var=str_replace("\r","",$var);
    		$var=str_replace("   "," ",$var);
    		$var=str_replace(">  <","><",$var);
    		return $var;
    	}
    	function Template ($values=array(),$template_name="body.html",$body="",$dir="") {
    		$this->template_dir=PATH_TO_TEMPLATES;
    		if (!$body) $body=file_get_contents($this->template_dir."/".$template_name);
    		if ($values) foreach ($values as $name => $value) {
    			$body=$this->ParseTemplate($body,$name, $value);
    		}
    		$this->result=$body;
    	}
    }

    Пришел к нам сайт на обслуживание... Как-бы шаблонизатор... )))

    nethak, 10 Июня 2011

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $count = count($xml_array["TITLE"])-1; //считаем число проходов цикла.     
    for ($i=0; $i < $count; $i++) {
            echo $element[$xml_array["TITLE"][$i+1]]["value"];     //выводим название книги
            echo $element[$xml_array["AUTHOR"][$i+1]]["value"];  //выводим автора книги
            echo $element[$xml_array["YEAR"][$i+1]]["value"];     //выводим год
    }

    http://www.3mind.ru/programming/53-xml-i-php-parsing-dlya-chaynikov.html
    Из примера про парсинг XML... я один вижу индусский код ?

    Arris, 10 Июня 2011

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    foreach($nodes as $xm){
        $arr[count($arr)] = new StdClass();
        $arr[count($arr)-1]->id = $xm->title;
        $arr[count($arr)-1]->nid = $xm->id;
    }

    Lowezar, 10 Июня 2011

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

    +156

    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
    class sqlinj
    {
    ...
    public $liste=array("=","\'","\"","*","\-","declare","char","set","cast","convert","drop","exec","meta","script","select","truncate","insert","delete","union","update","create","where","join","information_schema","table_schema","into");
    ...
    private function tumsorgular($yapilacak){ 
                switch ($yapilacak){ 
                case "post": 
                $this->islet=array("POST"); 
                break; 
                case "get": 
                $this->islet=array("GET"); 
                break; 
                case "request": 
                $this->islet=array("REQUEST"); 
                break; 
                case "aio": 
                $this->islet=array("POST","GET","REQUEST"); 
                break; 
            }     
            foreach($this->islet as $islem){ 
            eval('foreach($_'.$islem.' as $ad=>$deger){ 
                $_'.$islem.'[$ad]=$deger; 
                foreach($this->liste as $bul){ 
                $_'.$islem.'[$ad]=str_replace($bul,"\\\".$bul."\\\",$_'.$islem.'[$ad]); 
                } 
            } 
    ...
    }

    [url=http://www.phpclasses.org/browse/file/35305.html]Basic SQL Injection Protection[/url]
    Cleanup harmful text from request parameters

    Взято с phpclasses.org.
    Новый тип говнокода- турецкий(описание: расходится по швам при первой носке)

    А чё, ... не попортим так хакнем ;D

    AlexanderC, 10 Июня 2011

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

    +162

    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
    <?php
    
     if ($stranica == "ГЛАВНАЯ") 
    
    { 
    
    echo "<p>ГЛАВНАЯ</p>"; 
    
    } 
    
    else
    
     { 
    
    echo "<p><a href='index.php'>ГЛАВНАЯ</a></p>";
    
     } 
    
    ?>

    http://www.master-live.ru/php_links.html
    Очередной сеошник учит детей похапе.

    7ion, 09 Июня 2011

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

    +155

    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
    <script type="text/php">
    
    $color_op = Style::munge_colour( "#565656" );
    
    $font_op = Font_Metrics::get_font("arial", "normal");
    $font_op2 = Font_Metrics::get_font("arial", "bold");
    
    {literal}
    #	$pdf->text($left_op, $top_op, $text00, $font_op, 16, $color_op);
    #	$pdf->text($left_op, $top_op + 20, $text22, $font_op, 16, $color_op);
    #	$pdf->text($left_op, $top_op + 40, $text33, $font_op, 16, $color_op);	
    
    	$pdf->text($left_op, $top_op, $text00, $font_op2, 16, $color_op);
    	$pdf->text($left_op+87, $top_op, $text01, $font_op2, 16, $color_op2);
    	$pdf->text($left_op+87+15, $top_op, $text02, font_op, 16, $color_op);
    	
    {/literal}
    </script>

    Кусок из шаблона Smarty.

    _tL, 09 Июня 2011

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

    +166

    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
    //Класс для генерации кнопок перелистывания страниц
    
    class Pages {
    
        //Если пользователь на англ версии сайта и он на первой странице, генерируем кнопку "Next page"
        public function GeneratePage1En() {
            $this->NextPageHTML = "<a id=\"pg-next\" class=\"pg-next\" href=\"{$this->Se}.php?Page=2&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Next page</a>";
        }
    
        //Если пользователь на рус версии сайта и он на первой странице, генерируем кнопку "Следующая страница"
        public function GeneratePage1Ru() {
            $this->NextPageHTML = "<a id=\"pg-next\" href=\"{$this->Se}.php?Page=2&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Следущая страница</a>";
        }
    
        //Если пользователь на англ версии сайта и он на >2 странице генерируем кнопку "Next Page" и "Previous Page"
        public function GeneratePagesEn($Page) {
            $this->PrevPageHTML = "<a id=\"pg-prev\" class=\"pg-prev\" href=\"{$this->Se}.php?Page={$this->PrevPage}&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Previous page</a>";
            $this->NextPageHTML = "<a id=\"pg-next\"  class=\"pg-next\"  href=\"{$this->Se}.php?Page={$this->NextPage}&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Next page</a>";
        }
    
        //Если пользователь на рус версии сайта и он на >2 странице генерируем кнопку "Следующая страница" и "Предыдущая страница"
        public function GeneratePagesRu($Page) {
            $this->PrevPageHTML = "<a id=\"pg-prev\" class=\"pg-prev\" href=\"{$this->Se}.php?Page={$this->PrevPage}&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Предыдущая страница</a>";
            $this->NextPageHTML = "<a id=\"pg-next\"  class=\"pg-next\"  href=\"{$this->Se}.php?Page={$this->NextPage}&Q={$this->Question}&D={$this->Domain}&Td={$this->Typedate}\">Следующая страница</a>";
        }
    }

    Недавно увидел такую вот реализацию "листания" страниц в блоге.
    Применение довольно простое. Сначала идет несколько проверок (на какой пользователь странице и какая у него версия сайта - рус или англ), и уже исходя от этого, генерируются нужные кнопки (вызывается нужная функция).
    Из особенностей - максимально кривое использование возможностей ООП))

    MyNameIsWinner, 09 Июня 2011

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

    +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
    elseif (intval($countryID)>0 && intval($regionID)>0){
                    $SQL = "SELECT DISTINCT ".TABLE_PREFIX."hotels".LANG_PREFIX.".stars FROM  ".TABLE_PREFIX."hotels".LANG_PREFIX.", ".TABLE_PREFIX."regions".LANG_PREFIX."
                    WHERE   ".TABLE_PREFIX."regions".LANG_PREFIX.".id=".TABLE_PREFIX."hotels".LANG_PREFIX.".region_id
                    AND ".TABLE_PREFIX."regions".LANG_PREFIX.".id =".$regionID."";                               
                    $qRS = mysql_query ($SQL) or die ("<hr size=\"1\"><b>Не удалось выполнить: </b> \"" . $SQL . "\"<br>" . mysql_error());
                    if (mysql_num_rows($qRS)) {
                            while ($row = mysql_fetch_object($qRS)) {
                                    $stars[$row->stars]++;
                            }
                    }
                    krsort($stars);
                    foreach ($stars as $key=> $value) {
                            $ret .= get_hotels($key, 100, $regionID, $countryID);        
                    }

    Washington, 09 Июня 2011

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

    +168

    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
    function ($param)
    {
    	$cnt = 0;
    
    	$result = mysql_query("SELECT * FROM `table` WHERE `table_field` = ".$param);
    
    	if ($result) 
    	{
    		while($row_s = mysql_fetch_assoc($result))
    		{
    			$cnt++;
    		}
    	}
    	else 
    	{
    		$cnt = 0;
    	}
    
    	return $cnt;
    }

    Шедевр неизвестного программиста.

    devl, 08 Июня 2011

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