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

    +48

    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
    $title = get_the_title();
    if ( $title == "Portfolio")  $data['sl_portfolio_style'] = "2 Columns Portfolio";
    if ( $title == "3 Columns Portfolio")  $data['sl_portfolio_style'] = "3 Columns Portfolio";
    if ( $title == "4 Columns Portfolio")  $data['sl_portfolio_style'] = "4 Columns Portfolio";
    if ( $title == "6 Columns Portfolio")  $data['sl_portfolio_style'] = "6 Columns Portfolio";
    if ( $title == "Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=4&paged=' . $paged );
    if ( $title == "4 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=8&paged=' . $paged );
    if ( $title == "6 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "3 Columns Portfolio")  query_posts( '&post_type=portfolio-type&posts_per_page=6&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Right Sidebar")  $data['portfolio_sidebar_position'] = "Right Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['sl_portfolio_style'] = "Portfolio with Sidebar";
    if ( $title == "Portfolio Left Sidebar")  $data['portfolio_sidebar_position'] = "Left Sidebar";
    
    if ( $title == "Portfolio Left Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );
    if ( $title == "Portfolio Right Sidebar")  query_posts( '&post_type=portfolio-type&posts_per_page=12&paged=' . $paged );

    "switch - case" - Не не слышал!
    И это в покупной теме для wordpress на тимфоресте.
    Стоимость темы - 45 уе...

    tsybulskyserg, 22 Января 2013

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

    +67

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class IntegerUtils
    {
        public static function isInteger($value)
        {
            return preg_match('/[0-9]+/', $value);
        }
    }

    Must have класс, который должен быть у каждого в его библиотеке "велоприседов". Поистине краткий, лаконичный, гениальный. Даешь 100% говнокод!

    SunnyMagadan, 22 Января 2013

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

    +57

    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
    for($i=0;$i<count($data_cor);$i++)
      {
        if(($data_cor[$i]['status'] == 1) && (($data_cor[$i]['number_packet'] == "9999998") || ($data_cor[$i]['number_packet'] == $iNumber)))
        { $_MY_LOG_counter_2 ++;
          foreach($data_cor[$i] as $key=>$value)
            $data_cor[$i][$key] = str_replace(";","",str_replace("\n","",str_replace("\r\n","",$value)));
    
          $d .= "\$Заявка\r\n";
          $d .= $data_cor[$i]['guid'].             ";".$data_cor[$i]['number_1c'].     ";".$data_cor[$i]['date_request'].      ";".$data_cor[$i]['number_request'].";"
                .$data_cor[$i]['contractor'].      ";".$data_cor[$i]['contractor_doc'].";".$data_cor[$i]['general_request_id'].";".$data_cor[$i]['date_dispatch'].";"
                .$data_cor[$i]['type_dispatch'].   ";".$data_cor[$i]['g_contactor_id'].";".$data_cor[$i]['address'].           ";"
                .$data_cor[$i]['station_name'].    ";".$data_cor[$i]['station_code'].  ";".$data_cor[$i]['status'].            ";"
                .$data_cor[$i]['transport_id'].    ";".$data_cor[$i]['contact_person'].";".$data_cor[$i]['phone_number'].      ";"
                .$data_cor[$i]['station_guid'].    ";".$data_cor[$i]['guid_cont_4'].   ";".$data_cor[$i]['transport_type'].    ";"
                .$data_cor[$i]['trailer'].         ";".$data_cor[$i]['driver'].        ";".$data_cor[$i]['driver_reserve'].    ";"
    			.$data_cor[$i]['address_delivery'].";".$data_cor[$i]['comment'];
    
    
    			$d .= "\r\n";
              
          if(count($data_cor['products']>0))
          {
            $d .= "#Товары\r\n";
            foreach($data_cor[$i]['products'] as $p)
              $d .= $p['guid'].";".$p['ob'].";".$p['get'].";".$p['doc_guid']."\r\n";
            
            $d .= "#Состояния\r\n";
            foreach($data_cor[$i]['statuses'] as $s)
              $d .= $s['status'].";".$s['date'].";".$s['user'].";".$s['type'].";".$s['guid']."\r\n";
          }
        }
      }

    CSV заказывали?
    Ах да, выгружаться могут разные данные, поэтому рядом лежат еще 4 говнофункции, отличающихся от этой только ключами массива.

    clauclauclau, 22 Января 2013

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

    +50

    1. 1
    if(!empty($filter['features']) && !empty($filter['features'])) ...

    Simpla CMS /api/Products.php

    Andretti, 21 Января 2013

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

    +47

    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 executeNewsRightRelated(sfWebRequest $request)
      {
        $siteId = $request->getParameter('site')->id;
        $tNewsList = $this->object->News;
    
        $newsList = array();
        foreach ($tNewsList as $news) {
    
          $ids = array();
          foreach ($news->Sites as $idModel) {
            $ids[] = $idModel->id;
          }
    
          if (in_array($siteId, $ids)) {
            $newsList[] = $news;
          }
        }
    
        $this->newsList = $newsList;
      }

    Skiv, 18 Января 2013

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

    +54

    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
    73. 73
    <?php
    
        class ArrObj implements ArrayAccess, Countable, Iterator
        {
    
            protected $_data = array();
            protected $_indexes = array();
            protected $_pos = 0;
    
            public function __construct($data = array())
            {
                $this->_data = $data;
            }
    
            public function offsetGet($name)
            {
                if($isset = isset($this->_data[$name])) return $this->_data[$name];
                $this->_data[$name] = new self();
                return $isset ? $this->_data[$name] : null;
            }
    
            public function offsetSet($name, $value)
            {
                if(is_array($value)) $value = new self($value);
                $this->_data[$name] = $value;
                $this->_indexes[] = $name;
                return $value;
            }
    
            public function offsetUnset($name)
            {
                unset($this->_data[$name]);
                $this->_indexes = array_merge(array_diff($this->_indexes, array($name)));
            }
    
            public function offsetExists($name)
            {
                return isset($this->_data[$name]);
            }
    
            public function count()
            {
                return count($this->_data);
            }
    
            public function rewind()
            {
                $this->_pos = 0;
            }
    
            public function current()
            {
                return $this->_data[$this->_indexes[$this->_pos]];
            }
    
            public function key()
            {
                return $this->_indexes[$this->_pos];
            }
    
            public function next()
            {
                ++$this->_pos;
            }
    
            public function valid()
            {
                return isset($this->_indexes[$this->_pos]);
            }
    
        }
    
    ?>

    Sarkian, 18 Января 2013

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    If($z["timeout"]==1 || $z['timeout']==3 || $z['timeout']==4 || $z['timeout']==5 || $z['timeout']==7 || $z['timeout']==10) { 
    }  else {
         $z['timeout'] = 3;
    }

    '<>' и 'or' ? неее, не слышали!

    RickMan, 17 Января 2013

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

    +42

    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
    function test($method)
    {
      $picfile = 'pic1.png';
      $bgfile = 'output.png';
      $background = 'pic2.png';
      $foreground = 'pic3.png';
    
      if ($method == 'Imagick') {
        $img = new Imagick($picfile);
    
        $mask = new Imagick($background);
        $img->compositeImage($mask, imagick::COMPOSITE_COPYOPACITY, 0, 0);
        $mask->destroy();
    
        $overlay = new Imagick($foreground);
        $img->compositeImage($overlay, imagick::COMPOSITE_OVER, 0, 0);
        $overlay->destroy();
    
        $img->setImageFormat('png');
        file_put_contents($bgfile, $img->getImageBlob()); // $img->writeImage($bgfile) работает медленнее
        $img->destroy();
      } else if ($method == 'Wand') {
        $img = NewMagickWand();
        MagickReadImage($img, $picfile);
    
        $mask = NewMagickWand();
        MagickReadImage($mask, $background);
        MagickCompositeImage($img, $mask, MW_CopyOpacityCompositeOp, 0, 0);
        DestroyMagickWand($mask);
    
        $overlay = NewMagickWand();
        MagickReadImage($overlay, $foreground);
        MagickCompositeImage($img, $overlay, MW_OverlayCompositeOp , 0, 0);
        DestroyMagickWand($overlay);
    
        MagickSetImageFormat($img, 'png');
        file_put_contents($bgfile, MagickGetImagesBlob($img)); // ditto
        DestroyMagickWand($img);
      } else {
        $cmdline = 'convert -compose copy-opacity ' . $picfile . ' ' . $background . ' -composite';
        $cmdline .= ' -compose src-over ' . $foreground . ' -composite ' . $bgfile;
        exec($cmdline);
      }
    }
    
    $methods = array('Imagick', 'Wand', 'Command line');
    foreach ($methods as $m) {
      $start_time = microtime(true);
      for ($i = 0; $i < 4; $i++) {
        test($m);
      }
      $elapsed_time = microtime(true) - $start_time;
      echo 'Method: ' . $m . '; elapsed ' . strval($elapsed_time) . PHP_EOL;
    }

    Результаты выполнения на локальной машине:
    Method: Imagick; elapsed 0.45...
    Method: Wand; elapsed 0.82...
    Method: Command line; elapsed 0.87...
    Результаты выполнения на VPS:
    Method: Imagick; elapsed 79.64...
    Method: Wand; elapsed 151.64...
    Method: Command line; elapsed 46.49...

    Что-то тут не так...

    inkanus-gray, 17 Января 2013

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // sys
    if ($flag==1) {
            $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2);
    } elseif ($flag==2) {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    } else {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    }

    Это нашел в движке одной онлайн игры... Три проверки, но 1 и то же действие... Логика, мать её...

    RickMan, 16 Января 2013

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

    +55

    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
    <?php
    
    // ... много строк до этого
    
    echo "<table width=100% border=0>";
    if ($row = mysql_fetch_array($result))
    	for ($i = 0; $i < mysql_num_fields($result); $i++):	
    		if (mysql_field_name($result, $i) == "ID" || (mysql_field_name($result, $i) == "info") ||
    				mysql_field_name($result, $i) == "state" || (mysql_field_name($result, $i) == "date_st") ||
    				mysql_field_name($result, $i) == "date" || (mysql_field_name($result, $i) == "email") ||
    				mysql_field_name($result, $i) == "flag" || (mysql_field_name($result, $i) == "limit_time") ||
    				mysql_field_name($result, $i) == "cr_time" || mysql_field_name($result, $i) == "cr_money" ||
    				mysql_field_name($result, $i) == "flag" || (mysql_field_name($result, $i) == "info") ||
    				mysql_field_name($result, $i) == "attention" || mysql_field_name($result, $i) == "location" ||
    				mysql_field_name($result, $i) == "mailflag" || (mysql_field_name($result, $i) == "radio") ||
    				mysql_field_name($result, $i) == "radio30" || (mysql_field_name($result, $i) == "date_num") ||
    				mysql_field_name($result, $i) == "number" || mysql_field_name($result, $i) == "login_i"
    				|| mysql_field_name($result, $i) == "is_juridical")
    		{
    			if (mysql_field_name($result, $i) == "state")
    			{
    				echo "<select name=state style=\"background-color:red;color:white\"><option value=OPEN";
    				if ($row[$i] == "OPEN")
    					echo " selected ";
    				echo ">" . trans("OPEN") . "</option>\n";
    				echo "<option value=CLOSE";
    				if ($row[$i] == "CLOSE")
    					echo " selected ";
    				echo ">" . trans("CLOSE") . "</option></select\n";
    			}
    			elseif (mysql_field_name($result, $i) == "location")
    			{
    				genLeased($row[$i]);
    			}
    			elseif (mysql_field_name($result, $i) == "radio30" || mysql_field_name($result, $i) == "radio" || 
    				 mysql_field_name($result, $i) == "mailflag" )
    			
    			{
    			}
    			elseif (mysql_field_name($result, $i) == "date_st")
    			{
    				$ar = explode("-", $row[$i]);
    				echo "<b id=red>" . $ar[2] . "." . $ar[1] . "." . $ar[0] . "</b></td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "date_num")
    			{
    				$ar = explode("-", $row[$i]);
    				$dnum = $ar[2] . "." . $ar[1] . "." . $ar[0];
    				
    				echo "<b>" . $dnum . "</b></td></tr><tr><td><a href=\"contracts/index.php?user_id=" . $row['ID'] . "\">контракти</a></td></tr><tr><td colspan=2><hr noshade></td></tr>\n";
    			}
    
    			elseif (mysql_field_name($result, $i) == "date")
    			{
    				$ar = explode("-", $row[$i]);
    				$row[$i] = $ar[2] . "." . $ar[1] . "." . $ar[0];
    				echo "<input type=text name=date value=\"" . $row[$i] . "\"</td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "info")
    			{
    				echo "<textarea  rows=3 name=" . mysql_field_name($result, $i) . " >" . $row[$i] . "</textarea></td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "attention")
    			{
    				echo "<textarea id=warn rows=3 name=" . mysql_field_name($result, $i) . " >" . $row[$i] . "</textarea></td></tr>\n";
    			}
    // ... и так обрабатываем далее все поля

    Разработчик сначала запросил результат с помощью mysql_fetch_array,
    потом ищет название каждого поля с помощью mysql_field_name, функцией trans()
    читает файлик со словарем и переводит название каждого поле.

    Писалось не индусами, вариант "для количества" не прокатывает.
    Поэтому я не могу даже предположить, что сподвигло автора на создание сего творения.
    Файл содержит около 1400 строчек.

    rsvasilyev, 16 Января 2013

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