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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    changeFace($arr) {
            switch ($arr['custtype']) {
                    case 2: $facetype = 'Ф'; break; //Физическое
                    case 1: $facetype = 'Ю'; break; //Юридическое лицо
                    default: $facetype = ' '; break;
            }
            return $facetype;
    }

    В этом смысле лицо - "person"

    DIX315, 06 Июня 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    PUBLIC STATIC FUNCTION /* ЭТО Я НЕ КАПСОМ ПИШУ, ЭТО Я ШИФТ ДЕРЖУ */ selectFor_confirm($delivery_mode, PtrCustomSelector $order_sel)
        {
            /* ... */
        }

    Последствия пятничного deadline-кодинга ^_^

    AntonioK, 06 Июня 2013

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

    +152

    1. 1
    2. 2
    // maybe even strtolower($value)?
    $bool = ($value && ($value !== 'false') && ($value !== 'null'));

    А разгадка одна — безблагодатность^w кривой JSON.

    AntonioK, 06 Июня 2013

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $currurl = str_replace(" ", '', $this->helper('core/url')->getCurrentUrl());
    if (strpos($currurl, 'index.php/')) {
        $currurl = str_replace('index.php/', '', $currurl);
    } else if (strpos($currurl, '/index.php')) {
        $currurl = str_replace('index.php', '', $currurl);
    }
    $url_suffix = (substr($currurl, strlen(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB))));
    <?php if (strlen($url_suffix) <= 0) : #not homepage ?>
    ...

    Magento. Увидел в template, код одной английской компании.

    crook, 06 Июня 2013

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $startYear = date('Y', $programs[$i][1]);
                    $startMounth = date('m', $programs[$i][1]);
                    $startDay = date('d', $programs[$i][1]);
                    $startHour = date('H', $programs[$i][1]);
                    $startMinute = date('i', $programs[$i][1]);
                    $startSecond = date('s', $programs[$i][1]);
                    $startDate = mktime($startHour + $timeoffset, $startMinute, $startSecond, $startMounth, $startDay, $startYear);

    Поправка на часовой пояс

    stsaranchin, 06 Июня 2013

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

    +150

    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
    <?php
    class Router {
        private $available_pages = array('index',
                                         'contacts',
                                         'about',
                                         'clients' => array('index',
                                                           'howto',
                                                           'register',
                                                           'faq'),
                                         'experts' => array('index',
                                                              'why',
                                                              'howto',
                                                              'register',
                                                              'faq')
                                         );
        
        function __construct()
        {
            if(!isset($_GET['act'])) $act = "index";
            else $act=$_GET['act'];
            $path = pathinfo($act);
            if($path["filename"] == "experts" || $path["filename"] == "clients")
            {
                $path['dirname'] = $path["filename"];
                $path['filename'] = "index";
            }
            if($this->isAvailablePage($path))
            {
                $controllerPath = FRONT_TPL.$path['dirname'].'/'.$path['filename'].'.php';
                $controllerName = $path['filename'];
                if(file_exists($controllerPath))
                {
                    include(FRONT_TPL."header.php");
                    include($controllerPath);
                    include(FRONT_TPL."footer.php");
                }
                else $this->error404();
            }
            else $this->error404();
        }
        
        function error404()
        {
            include(FRONT_TPL."header.php");
            include(FRONT_TPL."404.php");
            include(FRONT_TPL."footer.php");
        }
        
        function isAvailablePage($path)
        {
            
            if($path["dirname"] == ".")
            {
                reset($this->available_pages);
                if(in_array($path['filename'], $this->available_pages)) return true;
            }
            else if($path["dirname"] == "experts" || $path["dirname"] == "clients")
            {
                reset($this->available_pages);
                if(in_array($path['filename'], $this->available_pages[$path["dirname"]])) return true;
            }
            else return false;
        }
    }

    Небольшой роутинг

    varg242, 04 Июня 2013

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

    +152

    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
    88. 88
    89. 89
    90. 90
    function CreatePriceListArray($result_array)//TODO:Формирует древовидную форму прайс листа
    {
    		//print_r($result_array);
        $price_list=array();//Жилая недвижимость
        $current_object_name="";
        $current_section_name="none";
        $current_section_id=0;
        $current_object_array=null;
        $current_section_array=null;
        $current_kvartira_type=null;
        $current_kvartira_type_name="";
        $current_kvartira=null;
        $current_kvartira_area="";
        
        foreach($result_array as $value)
        {
            if($current_object_name != $value['object'])
            {
                if($current_object_array !=null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                    $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
                }
                $current_object_array=array();
                $current_object_name=$value['object'];
                $current_section_name="none";
                $current_section_id=0;
                $current_section_array=null;
            }
    
            if($current_section_name != $value['section_name'])
            {
                   // echo $current_kvartira_type['name']; echo ' | ';
                //if($current_kvartira_type['name'] != '') 
                {
                    
                    foreach ($current_kvartira_type as $value)
                    
                    //print_r($current_kvartira_type);
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);                
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                }
                $current_section_array=array();
                $current_section_name = $value['section_name'];
                $current_section_id=$value['section_id'];
               // $current_kvartira_type=null;
                $current_kvartira_type_name="";
            }
    
            if($current_kvartira_type_name != $value['kvartira_name'])
            {
               // if($current_kvartira_type != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                }
                $current_kvartira_type=array();
                $current_kvartira_type_name = $value['kvartira_name'];
                $current_kvartira=null;
                $current_kvartira_area="";
            }
    
            if($current_kvartira_area != $value['area'])
            {
               // if($current_kvartira != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                }
                $current_kvartira=array();
                $current_kvartira_area = $value['area'];
            }
            
            $current_kvartira[]=$value['floor'];
        }
    		
    			
           $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
           $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
           $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
    //echo $current_object_name;        
    if($current_object_name!='') $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
    
    echo '<!--';
    print_r($price_list);
    echo '-->';
        return $price_list;    
    }

    Пытаюсь тут что-то найти... Идет второй час.

    ghz, 04 Июня 2013

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function addDots($str)
    {
    	$str	= str_replace('В кадре', 'В кадре. ', $str);
    	$str	= str_replace('За кадром', 'За кадром. ', $str);
    	$str	= str_replace('Цитаты', 'Цитаты. ', $str);
    	$str	= str_replace('Код для блога', '', $str);
    	return $str;
    }

    В следующем выпуске вас ожидают addSlashes, addSpaces, addColons…

    stsaranchin, 04 Июня 2013

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

    +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
    // delete all directories, not used by database(middleware)
    	deleteToucanNpvrNotUsedDirectories($objDB, $ftp);
    	
    	// delete npvr records, not exist in bd, but exist on toucan
    	deleteToucanRecordsNotUsedButExistOnToucan($objDB);
    	
    	// delete npvr records on toucan db, but not found directory on toucan file system.
    	///deleteToucanRecordsExistButNotRecorded($objDB,$ftp);
    	
    	// delete npvr records not recorded founded in db, but not found on toucan db.
    	///deleteDbRecordsExistButNotRecordedAndNotFoundedOnToucan($objDB);	
    	
    	ftpToucanNpvrDisconnect($ftp);

    deleteDbRecordsExistButNotRecordedAndNot FoundedOnToucanAndIWantToKillAnybodyAfte rReadingThis

    stsaranchin, 04 Июня 2013

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

    +151

    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 getNextDay($_arr_date, $day)
    {
        $_arr_result = array();
        $str_result = '';
    
        $str_result = substr($_arr_date[0], 0, 2);
        $str_result .= '-';
        $str_result .= substr($_arr_date[0], 2, 2);
        $str_result .= '-';
        $str_result .= substr($_arr_date[0], 4, 4);
    
        $arrDate = explode('-', $str_result);
    
        $_arr_result[0] = date('d-m-Y', mktime(0, 0, 0, $arrDate[1], $arrDate[0] + $day, $arrDate[2]));
        $_arr_result[1] = date('d-m-Y', mktime(0, 0, 0, $arrDate[1], ($arrDate[0] + $day + 1), $arrDate[2]));
        $_arr_result[2] = date('Y-m-d', mktime(0, 0, 0, $arrDate[1], $arrDate[0] + $day, $arrDate[2])); //for BD
        $_arr_result[3] = date('Y-m-d', mktime(0, 0, 0, $arrDate[1], ($arrDate[0] + $day + 1), $arrDate[2])); //for BD
    
        return $_arr_result;
    }

    Получаем дату следующего дня

    stsaranchin, 04 Июня 2013

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