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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    there is a reason why opencart is the no.1 most used ecommerce solution in places like china and india, its the easiest code base to understand!
    
    --
    
    many apps servers! what does that mean? you mean different applications running from the same framework?
    you build each application starting from the index.php file and include what ever library classes you require.
    
    --
    
    "I agree with you that it's harder to write simple code, because REPEATING CODE IS HARD TO DEBUG HARD TO READ AND TO CORRECT. so it makes you waste a lot of time."
    
    this is what search and replace is for!

    Создатель опенкарта (Daniel Kerr) исходит на говно, много мякотки
    http://www.techchattr.com/never-use-opencart#comment-1151857248

    Fike, 22 Февраля 2015

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

    +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
    foreach (scandir(DIR.'app'.SLASH.'lib') as $filename) {
        $path = DIR.'app'.SLASH.'lib'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }
    foreach (scandir(DIR.'app'.SLASH.'models') as $filename) {
        $path = DIR.'app'.SLASH.'models'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }
    foreach (scandir(DIR.'app'.SLASH.'ext') as $filename) {
        $path = DIR.'app'.SLASH.'ext'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }

    Начался разбор проблемы со слов заказчика - "сайт долго грузится"

    Crawdaunt, 22 Февраля 2015

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function getMinQueueOrdering()
      {
        $sql="SELECT MAX(ordering)
              FROM priceloaddata_queue";
      .........
      }

    нет слов.

    Vasiliy, 19 Февраля 2015

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

    +168

    1. 1
    define("OUTPUT_DIR_CSV", "kokoko/kukarek/files" . DIRECTORY_SEPARATOR);

    Stallman, 19 Февраля 2015

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

    +161

    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
    public function set_debug($fparam) {
         $this->set_debug_mode($fparam);
    }
    
    protected function set_debug_mode($fparam) {
          $this->set_localization_debug_mode($fparam);
    }
    
    private function set_localization_debug_mode($fparam) {
          $this->set_localization_debug_mode_log_service($fparam);
    }
    
    private function set_localization_debug_mode_log_service($fparam) {
          $conf = //...тут уже что-то делает, наконец-то
    }

    Я понимаю, если бы они просто были алиасами... Но почему protected/private?

    Lowezar, 18 Февраля 2015

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

    +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
    if ($sub_sub_sub_sub_category_id !== null) {
    
    													if ($this->core->countUrl > 5) {
    														header('Location: /404/');
    													}
    
    													foreach ($categories[$category_id][$sub_category_id][$sub_sub_category_id][$sub_sub_sub_category_id][$sub_sub_sub_sub_category_id] as $k1 => $v1) {
    														if ($k1 !== 0) {
    															foreach ($v1 as $k2 => $v2) {
    																if ($k2 !== 0) {
    																	if ($this->core->translit($v2[0]) == $sub_sub_sub_category) {
    																		$sub_sub_sub_sub_sub_category_id = $k1;
    																		$sub_sub_sub_sub_sub_sub_category_id = $k2;
    																		break;
    																	}
    																}
    															}
    														}
    													}
    
    													$this->core->title($categories[$category_id][$sub_category_id][$sub_sub_category_id][$sub_sub_sub_category_id][$sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_sub_category_id][0]);
    													$bread_crumbs[] = array(
    														'text' => $categories[$category_id][$sub_category_id][$sub_sub_category_id][$sub_sub_sub_category_id][$sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_sub_category_id][0],
    														'url' => $location['alias'] . '/' . $this->core->translit($categories[$category_id][0]) . '/' . $this->core->translit($categories[$category_id][$sub_category_id][$sub_sub_category_id][0]) . '/' . $this->core->translit($categories[$category_id][$sub_category_id][$sub_sub_category_id][$sub_sub_sub_category_id][$sub_sub_sub_sub_category_id][0]) . '/' . $this->core->translit($categories[$category_id][$sub_category_id][$sub_sub_category_id][$sub_sub_sub_category_id][$sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_category_id][$sub_sub_sub_sub_sub_sub_category_id][0])
    													);
    
    													$query_add = "
    														AND (`market_item`.`category_key` = '" . $category_id . "')
    														AND  `market_item`.`param` REGEXP '(\"" . $sub_sub_sub_sub_category_id . "\")'
    													";
    													
    													$vip_query_add = "
    														AND `market_item`.`category_key` = '" . $category_id . "'
    													";
    
    												}

    qualitycode, 16 Февраля 2015

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

    +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
    if ( !defined ('BX_SKIP_INSTALL_CHECK') && file_exists( $dir['root'] . 'install' ) ) {
        $ret = <<<EOJ
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
        <title>Dolphin Installed</title>
        <link href="{$site['url']}install/general.css" rel="stylesheet" type="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body class="bx-def-font">
        <div class="adm-header">
            <div class="adm-header-content">
                <div class="adm-header-title bx-def-margin-sec-left">
                    <img class="adm-header-logo" src="{$site['url']}administration/templates/base/images/logo.png" />
                    <div class="adm-header-text bx-def-font-h1">Dolphin {$site['ver']}</div>
                    <div class="clear_both">&nbsp;</div>
                </div>
                <div class="clear_both">&nbsp;</div>
            </div>
        </div>
        <div id="bx-install-main" class="bx-def-border bx-def-round-corners bx-def-margin-top">
            <div id="bx-install-content" class="bx-def-padding">
                <div class="bx-install-header-caption bx-def-font-h1 bx-def-margin-bottom">
                    Well done, mate! Dolphin is now installed.
                </div>
                <div class="bx-install-header-text bx-def-font-large bx-def-font-grayed">
                    Remove directory called <b>"install"</b> from your server and <a href="{$site['url']}administration/modules.php">proceed to Admin Panel to install modules</a>.
                </div>
            </div>
        </div>
    </body>
    </html>
    EOJ;
        echo $ret;
        exit();
    }

    Какой веселый вывод HTML (Dolphin 7)

    jey-val-star, 15 Февраля 2015

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

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    namespace MultipleHashMapQueueMessageRetrieverCriterias\Domain\MultipleHashMapQueueMessageRetrieverCriterias\Adapters\Exceptions;
    use MultipleHashMapQueueMessageRetrieverCriterias\Domain\Exceptions\MultipleHashMapQueueMessageRetrieverCriteriaException;
    
    final class CannotConvertMultipleHashMapQueueMessageRetrieverCriteriaToMultipleQueueMessageRetrieverCriteriaException extends MultipleHashMapQueueMessageRetrieverCriteriaException {
        const CODE = 1;
        public function __construct($message, MultipleHashMapQueueMessageRetrieverCriteriaException $parentException = null) {
            parent::__construct($message, self::CODE, $parentException);
        }
    }

    http://www.reddit.com/r/lolphp/comments/2vrgr6/irestfulmultiplehashmapqueuemessageretri evercriter/
    https://github.com/irestful/MultipleHashMapQueueMessageRetrieverCrit erias/blob/master/MultipleHashMapQueueMessageRetrieverCrit erias/Domain/MultipleHashMapQueueMessageRetrieverCrit erias/Adapters/Exceptions/CannotConvertMultipleHashMapQueueMessage RetrieverCriteriaToMultipleQueueMessageR etrieverCriteriaException.php

    Алсо, обратите внимание на структуру гитхабовских репозиториев

    myaut, 15 Февраля 2015

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

    +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
    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
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    function display_form($value){
    		switch($value){
    			case "page_title":
    				return "<input type='text' id='page_title' name='settings[page_title]' value='".$this->values[$value]."'/>";
    			break;
    			case "admin_email":
    				return "<input type='text' id='admin_email' name='settings[admin_email]' value='".$this->values[$value]."'/>";
    			break;
    			case "max_rental":
    				return "<input type='text' id='max_rental' name='settings[max_rental]' value='".$this->values[$value]."'/>";
    			break;
    			case "offset":
    				return "<input type='text' id='offset' name='settings[offset]' value='".$this->values[$value]."'/>";
    			break;
    			case "launch_limit":
    				return "<input type='text' id='offset' name='settings[launch_limit]' value='".$this->values[$value]."'/>";
    			break;
    			
    			case "page_text":
    				return "<textarea id='page_text' class='ckeditor' name='settings[page_text]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "email_text":
    				return "<textarea id='page_text' class='ckeditor' name='settings[email_text]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "confirm_message":
    				return "<textarea id='page_text' class='ckeditor' name='settings[confirm_message]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "general_hours":
    				$hours = unserialize($this->values[$value]);
    				return "
    					<table id='hours'>
    					<tr><th></th>
    						<th>Sunday</th>
    						<th>Monday</th>
    						<th>Tuesday</th>
    						<th>Wednesday</th>
    						<th>Thursday</th>
    						<th>Friday</th>
    						<th>Saturday</th>
    					</tr>
    					<tr>
    						<th>Open</th>
    						<td>".$this->display_hour_options("Sunday","start",$hours['Sunday']['start'])."</td>
    						<td>".$this->display_hour_options("Monday","start",$hours['Monday']['start'])."</td>
    						<td>".$this->display_hour_options("Tuesday","start",$hours['Tuesday']['start'])."</td>
    						<td>".$this->display_hour_options("Wednesday","start",$hours['Wednesday']['start'])."</td>
    						<td>".$this->display_hour_options("Thursday","start",$hours['Thursday']['start'])."</td>
    						<td>".$this->display_hour_options("Friday","start",$hours['Friday']['start'])."</td>
    						<td>".$this->display_hour_options("Saturday","start",$hours['Sunday']['start'])."</td>
    					</tr>
    					<tr>
    						<th>Close</th>
    						<td>".$this->display_hour_options("Sunday","end",$hours['Sunday']['end'])."</td>
    						<td>".$this->display_hour_options("Monday","end",$hours['Monday']['end'])."</td>
    						<td>".$this->display_hour_options("Tuesday","end",$hours['Tuesday']['end'])."</td>
    						<td>".$this->display_hour_options("Wednesday","end",$hours['Wednesday']['end'])."</td>
    						<td>".$this->display_hour_options("Thursday","end",$hours['Thursday']['end'])."</td>
    						<td>".$this->display_hour_options("Friday","end",$hours['Friday']['end'])."</td>
    						<td>".$this->display_hour_options("Saturday","end",$hours['Saturday']['end'])."</td>
    					</tr>
    					</table>
    				";
    			break;
    			
    			case "interests":
    				$interests = unserialize($this->values[$value]);
    				return "<strong>Display:</strong> <br /><input type='text' name='settings[interests][display]' value='".$interests['display']."'/><br />
    						<strong>Options: </strong><small>(Seperated by \"|\")</small> <br /><textarea id='page_title' name='settings[interests][choices]'>".implode("|",$interests['choices'])."</textarea>";
    			break;
    			
    			case "occasions":
    				$occasions = unserialize($this->values[$value]);
    				return "<strong>Display:</strong> <br /><input type='text' name='settings[occasions][display]' value='".$occasions['display']."'/><br />
    						<strong>Options: </strong><small>(Seperated by \"|\")</small> <br /><textarea id='page_title' name='settings[occasions][choices]'>".implode("|",$occasions['choices'])."</textarea>";
    			break;
    		}
    	}

    ActiveForm на все случаи жизни

    dejust, 15 Февраля 2015

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

    +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
    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
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    function build_period($crews){
    	global $start_time, $end_time, $memc;
    	cache_smens();
    	//Добавление смен и исключений
    	foreach ($crews as $k => $v){
    		$re1 = @$memc->get($v['ID']);
    		if (is_array($re1)){
    			foreach ($re1 as $v1){
    				$crews[$k]['sm'][] = $v1;
    			}
    		}
    		$re2 = get_exception($v);
    		foreach ($re2 as $v2){
    			$crews[$k]['sm'][] = $v2;
    		}
    	}
    
    	$flags = array();
    	foreach ($crews as $v){//Если есть смена
    		if (isset($v['sm'])){
    			$flags[$v['ID']] = array();
    			//Генерируем флаги
    			//Есть смена - false, иначе если эту минуту надо замерять - true
    			for ($i = $start_time; $i <= $end_time; $i = $i + (60)){
    				if (!isset($flags[$v['ID']][$i])){
    					$flags[$v['ID']][$i] = true;
    				}
    				foreach ($v['sm'] as $v1){
    					if ($i >= $v1['begin'] && $i <= $v1['end']){
    						$flags[$v['ID']][$i] = false;
    					}
    				}
    			}
    		}
    		else{
    			//Если смены нет забъем массив труями.
    			for ($i = $start_time; $i <= $end_time; $i = $i + (60)){
    				if (!isset($flags[$v['ID']][$i])){
    					$flags[$v['ID']][$i] = true;
    				}
    			}
    		}
    	}
    
    
    	$xor_per = array();
    	foreach ($flags as $k => $v){
    		$l1 = 0;
    		$l2 = 0;
    		foreach ($flags[$k] as $k1 => $v1){
    			/**
    			 * На основе флагов генерируем ключи старта - конца замера.
    			 *
    			 * Если не установлен предыдущий флаг или предыдущий флаг - смена
    			 *  и текущий флаг - True, смены нет, ставим отметку начала периода
    			 */
    			if ((!isset($flags[$k][$k1 - 60]) || !$flags[$k][$k1 - 60]) && $v1){
    				$xor_per[$k][$l1]['begin'] = $k1;
    				$l1++;
    			}
    			/**
    			 * Если следующий флаг false или неустановлен и текущий true
    			 * ставим отметку конца смены.
    			 */
    			if ((!isset($flags[$k][$k1 + 60]) || !$flags[$k][$k1 + 60]) && $v1){
    				/**
    				 * Если время в итерации равно времени конца суток
    				 *  укажем концом периода замера конец суток
    				 *  иначе нахерато добавим минуту
    				 */
    				$xor_per[$k][$l2]['end'] = $k1 == $end_time ? $end_time : $k1 + 60;
    				$l2++;
    			}
    		}
    
    		#need вкурить что я тут написал
    		if (isset($xor_per[$k])){
    			$crews[$k]['ps'] = $xor_per[$k];
    		}else{
    			//Если целые сутки смена
    			unset($crews[$k]);
    		}
    		unset($flags[$k]);
    	}
    
    	return $crews;
    }

    "Вот жопой чую, можно было сделать проще"

    Rijen, 12 Февраля 2015

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