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

    Всего: 10

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

    +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
    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
    <?php
    
    function test_menu() {
    //  $menu['test'] = array(
    //    'page callback' => 'test_page',
    //    'access callback' => TRUE,
    //  );
    
      $menu['test/%user_uid_optional'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }
    
    function test_access($account) {
      dpm($account);
      return TRUE;
    }

    vectoroc, 25 Марта 2011

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

    +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
    <?php
    
    function test_menu() {
      $menu['test'] = array(
        'page callback' => 'test_page',
        'access callback' => TRUE,
      );
    
      $menu['test/%user'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }

    vectoroc, 25 Марта 2011

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

    +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
    <?php
    
    function test_menu() {
      $menu['test'] = array(
        'page callback' => 'test_page',
        'access callback' => TRUE,
      );
    
      $menu['test/%user'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }

    vectoroc, 25 Марта 2011

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

    +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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    class Query {
      protected $baseTable;
      protected $baseTableAlias;
      protected $whereGroup;
    
      protected $joins = array();
      protected $fields = array();
    
      protected $executed = FALSE;
      protected $resource = NULL;
    
    
      function __construct($base_table = 'node', $alias = 'n') {
        $this->whereGroup = new QueryWhereGroup();
        $this->baseTable = $base_table;
        $this->baseTableAlias = empty($alias) ? $base_table : $alias;
      }
    
      function select($fields) {
        settype($fields, 'array');
        foreach ($fields as $alias => $field) {
          if (is_numeric($alias)) {
            $this->fields[] = $field;
          }
          else {
            $this->fields[$alias] = "$field as $alias";
          }
        }
    
        return $this;
      }
    
      /**
       * @param QueryWhereGroup $whereGroup
       * @return Query
       */
      function where($whereGroup) {
        call_user_func_array(array($this->whereGroup, 'cond'), func_get_args());
        return $this;
      }
    
      function createWhereGroup() {
        return new QueryWhereGroup();
      }
    
      function join($table, $alias = NULL, $condition, $join_type = 'INNER') {
        if (!$alias) {
          $alias = $table;
        }
    
        if (is_array($condition)) {
          $condition = 'USING ('. join(', ', $condition) .')';
        }
        if (!preg_match('/^ON|USING/i', $condition)) {
          $condition = 'ON '. $condition;
        }
    
        $this->joins[$alias] = "$join_type JOIN $table $alias $condition";
        return $this;
      }
    
      function compile() {
        $select_fields = join(', ', array_unique($this->fields));
        $joins_list = join("\n", $this->joins);
        $where_conditions = $this->whereGroup->compile();
    
        if (!empty($where_conditions)) {
          $where_conditions = 'WHERE '. $where_conditions;
        }
    
        return "SELECT $select_fields FROM {{$this->baseTable}} {$this->baseTableAlias} \n $joins_list $where_conditions";
      }
    
      function args() {
        return $this->whereGroup->args;
      }
    
      function execute() {
        return db_query($this->compile(), $this->args());
      }
    
      function fetchAll() {
        $res = $this->execute();
        while($row = db_fetch_object($res)) {
          $rows[] = $row;
        }
        return $rows;
      }
    }

    построитель запросов (drupal 6)
    wheregroup здесь http://govnokod.ru/6076

    vectoroc, 23 Марта 2011

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

    +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
    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
    class QueryWhereGroup {
      public $groupOp = 'AND';
      public $args = array();
      public $conditions = array();
    
      function cond($field, $value = NULL, $op = '=') {
        if ($value === NULL) {
          $this->conditions[] = $field;
          if (is_object($field) && isset($field->args)) {
            $this->args = array_merge($this->args, $field->args);
          }
        }
        else {
          if (is_numeric($value)) {
            $this->conditions[] = "$field $op %d";
            $this->args[]  = $value;
          }
          elseif (is_array($value)) {
            $placeholders  = db_placeholders($value, is_numeric(current($value)) ? 'int' : 'text');
            $this->conditions[] = "$field  IN ($placeholders)";
            $this->args = array_merge($this->args, $value);
          }
          else {
            $this->conditions[] = "$field $op '%s'";
            $this->args[]  = $value;
          }
        }
    
        return $this;
      }
    
      function compile($wrap = FALSE) {
        $result = join(" $this->groupOp ", $this->conditions);
        if ($wrap && !empty($result)) {
          $result = "(\n$result\n)";
        }
    
        return $result;
      }
    
      function __toString() {
        return $this->compile();
      }
    }

    см. след говнокод

    vectoroc, 23 Марта 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function &_extract(&$array, $path) {
      $element = &$array;
      while(count($path)) {
        $key = array_shift($path);
        $element = &$element[$key];
      }
    
      return $element;
    }

    vectoroc, 05 Марта 2011

    Комментарии (12)
  8. JavaScript / Говнокод #5531

    +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
    var keyCodes = {
        'ENTER': 13,
        'TAB': 9
      };
    
      var validate_element = function(el) {
        return el.name && !el.disabled && !el.readOnly &&
                (/select|textarea/i.test(el.nodeName) || /text|password/i.test(el.type));
      }
    
      jQuery('form', context).keypress(function(event) {
        var target = event.originalTarget || event.srcElement;
    
        if (target.nodeName.toLowerCase() == 'textarea') {
          // do nothing on textarea fields
          return;
        }
    
        if (event.keyCode == keyCodes['ENTER'] && validate_element(target)) { // pressed Enter
          if (jQuery('#autocomplete').size()) {
            // let do autocomplete.js its own job
            return;
          }
          
          var inputs = jQuery.makeArray(this.elements).filter(validate_element);
          for (var i=0; i<inputs.length; i++) {
            var element = jQuery(inputs[i]);
            if (!element.val()) {
              element.focus();
              return false;
            }
          }
        }
      })

    vectoroc, 04 Февраля 2011

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

    +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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    class Relay {
      protected $_data = array();
      protected $_devices;
      static protected $_db_fields = array();
    
      function getId() {
        return $this->_data['id'];
      }
      static function load($id) {
        if ($id) {
          $select = db_select('relay', 'r');
          $select->fields('r');
          $select->condition('r.id', $id);
          $relay = $select->execute()->fetchObject(__CLASS__);
          return $relay;
        }
      }
      function save() {
        foreach (array_diff(array_keys($this->_data), self::_getPureDbFields('relay')) as $field) {
          $this->_data['data'] = $this->_data[$field];
        }
    
        if ($this->getId()) {
          drupal_write_record('relay', $this->_data, array('id'));
        }
        else {
          drupal_write_record('relay', $this->_data);
        }
        $this->_saveDevices();
      }
      protected function _saveDevices() {
        if ($this->getId()) {
          $delete = db_delete('relay_devices');
          $delete->condition('relay_id', $this->getId());
          $delete->execute();
    
          foreach ((array)$this->_devices as $device) {
            $device = (array) $device;
            foreach (array_diff(array_keys($device), self::_getPureDbFields('relay_devices')) as $field) {
              $device['data'] = $device[$field];
            }
    
            drupal_write_record('relay_devices', $device);
          }
        }
      }
      function getDateFrom() {
        return $this->_data['date_from'];
      }
      function getDateDuration(){
        return $this->_data['date_duration'];
      }
      function getDateTo(){
        return $this->getDateFrom() + $this->getDateDuration();
      }
      function getDevices(){
        $this->_ensureDevicesLoaded();
        return $this->_devices;
      }
      protected function _ensureDevicesLoaded() {
        if (!is_array($this->_devices)) {
          $select = db_select('relay_devices', 'rd');
          $select->fields('rd');
          $select->condition('rd.relay_id', $this->getId());
          $query = $select->execute();
    
          $this->_devices = array_map('drupal_unpack', $query->fetchAll());
        }
        return is_array($this->_devices);
      }
      function __construct($data = NULL) {
        if (is_array($data)) {
          foreach ($data as $key => $value) {
            $this->_data[$key] = $value;
          }
        }
        elseif (is_string($this->_data['data']) && !empty($this->_data['data'])) {
          drupal_unpack($this);
        }
      }
      function __set($name, $value) {
        return $this->_data[$name] = $value;
      }
      function __get($name) {
        return $this->_data[$name];
      }
      static protected function _getPureDbFields($table) {
        if (!isset(self::$_db_fields[$table])) {
          $schema = drupal_get_schema($table);
          $fields = $schema['fields'];
          unset($fields['data']);
          self::$_db_fields[$table] = array_keys($fields);
        }
    
        return self::$_db_fields[$table];
      }
    }

    vectoroc, 26 Января 2011

    Комментарии (10)
  10. SQL / Говнокод #5278

    −860

    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
    SELECT
        node.nid AS nid,
        location.latitude AS location_latitude,
        location.longitude AS location_longitude,
        node.title AS node_title,
        node.language AS node_language,
        location.lid AS location_lid,
        (IFNULL(ACOS(0.501284223863*COS(RADIANS(location.latitude))*(0.863228195442*COS(RADIANS(location.longitude)) + 0.504813908876*SIN(RADIANS(location.longitude))) + 0.865282686124*SIN(RADIANS(location.latitude))), 0.00000)*6362105.74365) AS location_distance,
        node_data_field_rate_prior.field_rate_prior_amount AS node_data_field_rate_prior_field_rate_prior_amount,
        node_data_field_rate_prior.field_rate_prior_currency AS node_data_field_rate_prior_field_rate_prior_currency,
        node.type AS node_type, node.vid AS node_vid,
        node_data_field_rate_prior.field_rate_reg_amount AS node_data_field_rate_prior_field_rate_reg_amount,
        node_data_field_rate_prior.field_rate_reg_currency AS node_data_field_rate_prior_field_rate_reg_currency,
        node_data_field_rate_prior.field_rate_vip_amount AS node_data_field_rate_prior_field_rate_vip_amount,
        node_data_field_rate_prior.field_rate_vip_currency AS node_data_field_rate_prior_field_rate_vip_currency
      FROM node node
      LEFT JOIN location_instance location_instance ON node.vid = location_instance.vid
      LEFT JOIN location location ON location_instance.lid = location.lid
      LEFT JOIN content_type_dta_kiosk node_data_field_rate_prior ON node.vid = node_data_field_rate_prior.vid
      WHERE node.type in ('dta_kiosk')
        AND (location.latitude > 40.9991009563 
          AND location.latitude < 59.0008990437 
          AND location.longitude > 5.91311892539 
          AND location.longitude < 34.0868810746
        )
      ORDER BY location_distance ASC

    vectoroc, 14 Января 2011

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

    +153.2

    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 event_form_alter($form_id, &$form) {
      global $user;
    
      $node = isset($form['#node']) ? $form['#node'] : NULL;
    
      switch ($form_id) {
        // node settings form
        case 'node_type_form':
          $type = (isset($form['old_type']) && isset($form['old_type']['#value'])) ? $form['old_type']['#value'] : NULL;
          $form['workflow']['event_nodeapi'] = array(
            '#type' => 'radios',
            '#title' => t('Show in event calendar'),
            '#default_value' => variable_get('event_nodeapi_'. $type, 'never'),
            '#options' => array('all' => t('All views'), 'solo' => t('Only in views for this type'), 'never' => t('Never')),
            '#description' => t('All views: This content type will be available for display on all calendar views, including with other events.<br />Only in views for this type: This content type will only appear in calendar views specific to this type and never with other events.<br />Never: This content type will not be associated with the events calendar.')
          );
          break;
    #...
     }
    }

    vectoroc, 09 Января 2010

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