1. Список говнокодов пользователя nergal

    Всего: 3

  2. PHP / Говнокод #4110

    +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
    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
    /**
     * Получить список NEW5
     * 
     * @return array список событий
     */
    public function getLastForBlockNew($cat_tc_id = NULL)
    {
    
        $max_name_len = 41;
    
        $sql = "SELECT
                    a.d_id,
                    CONCAT(a.d_sname, ' ', a.d_name, ' ', a.d_fname) as d_name,
                    SUBSTR(a.d_description, 0, 30) as d_description,
                    a.d_rating,
                    c.c_name_url,
                    b.rg_name_url,
                    '".Application_Url_Maker::makeUrl(array(), 'sub-domain1')."' as domain
                FROM customers a
                    LEFT JOIN cities c ON c.c_id=a.d_c_id
                    LEFT JOIN regions b ON b.rg_id=c.c_rg_id
                WHERE a.d_rating is not NULL
                ORDER BY RAND()
                LIMIT 5
        ";
        $query[-1] = $this->querycached($sql);
    
        $sql = "SELECT
                    a.h_id,
                    a.h_name_ru,
                    SUBSTR(a.h_description, 0, 30) as h_description,
                    a.h_rating,
                    c.c_name_url,
                    b.rg_name_url,
                    '".Application_Url_Maker::makeUrl(array(), 'sub-domain2')."' as domain,
                    h_lat,
                    h_lon,
                    h_address,
                    h_phones,
                    d.hs_name_url
                FROM hospitals a
                    LEFT JOIN cities c ON c.c_id=a.h_c_id
                    LEFT JOIN regions b ON b.rg_id=c.c_rg_id
                    LEFT JOIN item_specializations d ON d.hs_id=a.h_hs_id
                WHERE a.h_rating is not NULL
                ORDER BY RAND()
                LIMIT 5
        ";
        $query[1] = $this->querycached($sql);
    
        $tc_ids = $this->db->fetchAll("select tc_id, tc_name_subdomain from type_catalogs where tc_id<>1");
        foreach($tc_ids as $v){
            $sql = "SELECT
                        a.cat_id,
                        a.cat_name_ru,
                        SUBSTR(a.cat_description, 0, 30) as cat_description,
                        a.cat_rating,
                        c.c_name_url,
                        b.rg_name_url,
                        '".Application_Url_Maker::makeUrl(array(), $v['tc_name_subdomain'])."' as domain,
                        cat_lat,
                        cat_lon,
                        cat_address,
                        cat_phones
            FROM catalogs a
                LEFT JOIN cities c ON c.c_id=a.cat_c_id
                LEFT JOIN regions b ON b.rg_id=c.c_rg_id
            WHERE a.cat_tc_id=? and a.cat_rating is not NULL
            ORDER BY RAND()
            LIMIT 5
            ";
            $query[$v['tc_id']] = $this->querycached($sql, array($v['tc_id']));
        }
    
        foreach($query as $k=>$v){
            foreach($v as $k1=>$v1){
                if(isset($v1['cat_name_ru']) && mb_strlen($v1['cat_name_ru']) > $max_name_len){
                    $query[$k][$k1]['cat_name_ru'] = mb_substr($v1['cat_name_ru'], 0, $max_name_len).'...';
                }
                elseif(isset($v1['h_name_ru']) && mb_strlen($v1['h_name_ru']) > $max_name_len){
                    $query[$k][$k1]['h_name_ru'] = mb_substr($v1['h_name_ru'], 0, $max_name_len).'...';
                }
            }
        }
        return $query;
    }

    nergal, 26 Августа 2010

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

    +144

    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
    <?php
    
    class Event {
        private static $_instance = NULL;
        protected $_events_pool = array();
    
        public static function getInstance() {
            if (self::$_instance === NULL) {
                $class = __CLASS__;
                self::$_instance = new $class;
            }
            
            return self::$_instance;
        }
    
        private function __construct() { }
    
        public function connect($event, $callback, array $params = null) {
            $this->_events_pool[$event] = array(
                'callback'	=>	$callback,
                'params'	=>	$params,
            );
            
            return $this;
        }
    
        public function clear($event = NULL) {
            if ($event === NULL) {
                $this->_events_pool = array();
            } else {
                foreach ($this->_events_pool as $id => $_event) {
                     if ($_event['event'] === $event) {
                        $this->_events_pool[$id] = NULL;
                     }
                }
            }
        }
    
        public function emit($events = NULL) {
            if ($events === NULL) {
                $events = array_keys($this->_events_pool);
            } else {
                $events = (is_array($events)) ? $events : array($events);
            }
            
            foreach ($events as $event) {
                foreach ($this->_events_pool as $id => $item) {
                     if ($id === $event) {
                        $this->call($this->_events_pool[$id]['callback']);
                     }
                }
            }
        }
    
        protected function call($class_name, $method_name = NULL, array $params = array(), array $class_params = array()) {	
            $_method = ($method_name === NULL) ? $class_name : array($class_name, $method_name);
            call_user_func_array($_method, $params);
        }
    }

    nergal, 26 Августа 2010

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

    +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
    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
    /**
         * Обновление информации о пользователе
         *
         * @param integer $user_id
         * @param array $data
         * @return Zend_Db_Statement_Pdo
         */
        public function updateProfile($user_id, $data)
        {
            // TODO: сделать человеческую валидацию
            $params = $keys = array();
    
            if ($data['login'] !== NULL) {
                $keys[] = 'u_login = ?';
                $params[] = $data['login'];
            }
    
            if (Zend_Validate::is($data['email'], 'EmailAddress')) {
                $keys[] = 'u_email = ?';
                $params[] = $data['email'];
            }
    
            if ($data['sname'] !== NULL) {
                $keys[] = 'u_sname = ?';
                $params[] = $data['sname'];
            }
    
            if ($data['name'] !== NULL) {
                $keys[] = 'u_name = ?';
                $params[] = $data['name'];
            }
    
            if ($data['fname'] !== NULL) {
                $keys[] = 'u_fname = ?';
                $params[] = $data['fname'];
            }
    
            if ($data['birthdate'] !== NULL) {
                $keys[] = 'u_birthdate = ?';
                $params[] = $data['birthdate'];
            } else {
                $keys[] = 'u_birthdate = NULL';
            }
    
            if ($data['city'] !== NULL) {
                $keys[] = 'u_c_id = ?';
                $params[] = (int) $data['city'];
            }
    
            if ($data['info'] !== NULL) {
                $keys[] = 'u_info = ?';
                $params[] = $data['info'];
            }
    
            if ($data['sign'] !== NULL) {
                $keys[] = 'u_sign = ?';
                $params[] = $data['sign'];
            }
    
            if ($data['sex'] === 'M' OR $data['sex'] === 'F') {
                $keys[] = 'u_sex = ?';
                $params[] = $data['sex'];
            }
    
            if ($data['subscribe'] === 'on' AND ($data['subtype'] === 'T' OR $data['subtype'] === 'H')) {
                $keys[] = 'u_subscribed = ?';
                $params[] = $data['subtype'] === 'T' ? 1 : 2;
            } else {
                $keys[] = 'u_subscribed = ?';
                $params[] = 0;
            }
    
            $sql = 'UPDATE users SET ' . implode(', ', $keys) . ' WHERE u_id = ' . (int) $user_id;
            $query = $this->db->query($sql, $params);
    
            $this->clearUserCache($user_id);
    
            return $query;
        }

    nergal, 26 Августа 2010

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