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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function buildUpdateTimestampTrigger($tableName) {
    		return 
    			sprintf(
    				file_get_contents(SQL_FILES_PATH . 'updateTimestamp_PlPg.sql'),
    				strtolower($tableName) . '_updated'
    			) .
    			sprintf(
    				file_get_contents(SQL_FILES_PATH . 'updateTimestampTrigger.sql'),
    				$tableName
    			);
    	}

    artembegood, 14 Мая 2015

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

    +144

    1. 1
    $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];

    https://github.com/uisky/notabenoid/blob/6edfee9f33b8466be9164cd3ba6be90b8f3a5770/protected/controllers/MyCommentsController.php#L123

    Stallman, 14 Мая 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?php
    class ModelCheckoutOrder extends Model {
    	public function addOrder($data) {
    		$this->event->trigger('pre.order.add', $data);
    		$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? serialize($data['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_custom_field = '" . $this->db->escape(isset($data['payment_custom_field']) ? serialize($data['payment_custom_field']) : '') . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_custom_field = '" . $this->db->escape(isset($data['shipping_custom_field']) ? serialize($data['shipping_custom_field']) : '') . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', marketing_id = '" . (int)$data['marketing_id'] . "', tracking = '" . $this->db->escape($data['tracking']) . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" .  $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "', date_added = NOW(), date_modified = NOW()");

    Я вас еще немного помучаю, хорошо?
    3978 символов, считая отступы

    https://github.com/opencart/opencart/blob/d5f66b0d75a5adf35815e333e45598bbc38750d0/upload/catalog/model/checkout/order.php#L6

    Fike, 14 Мая 2015

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(isset($_GET['go']))
    	$go = htmlspecialchars(strip_tags(stripslashes(trim(urldecode(mysql_escape_string($_GET['go']))))));
    else
    	$go = "main";
    
    // ....
    
    switch($go){

    "Тыыыыыыы не пройдеееешь!". Зафильтровали (да ещё и криво) бедную переменную только для того, чтобы потом использовать её в switch-case блоке. Индусы-паникеры.

    bSun0000, 13 Мая 2015

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

    +143

    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
    if(!$user['email']) {
         $err = $this->system_message->getLang('empty_email');
    } elseif(strlen($user['email']) < self::MIN_USER_NAME) {
          $err = $this->system_message->getLang('small_email');
    } elseif(strlen($user['email']) > self::MAX_USER_NAME) {
          $err = $this->system_message->getLang('long_email');
    } elseif(!filter_var($user['email'], FILTER_VALIDATE_EMAIL)) {
          $err = $this->system_message->getLang('incorrect_name');
    } 
    
    if(!$user['passw']) {
          $err = $this->system_message->getLang('empty_passw');
    } elseif(strlen($user['passw']) < self::MIN_PASSWORD_NAME) {
          $err = $this->system_message->getLang('small_passw');
    } elseif(strlen($user['passw']) > self::MAX_PASSWORD_NAME) {
          $err = $this->system_message->getLang('long_passw');
    }
    if($err) {
       //!TODO add a exeption
    		
    } else {
          $find_email = $this->db_users->prepare("SELECT * FROM `users` WHERE `email` = :email");
          $find_email->execute(array(':email' => $user['email']));

    Мдэээ...

    Dev_18, 12 Мая 2015

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

    +140

    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
    <?php
    /**
      * @desc Локализация сайта
      *
      **/
    class System_Message{
      private function openLangFail($lang){
        $path = '/../message/'.$lang.'.php';
        if (file_exists($path)) {
          return 'File with languages not found';
        } else {
          return include $path; 
        }
      } 
      
      public function getLang($value, $lang='ru'){
        $lang = self::openLangFail($lang);
        if($lang[$value] != '') {
          return $lang[$value];
        } else {
    	  return false;
    	}
      }
    }

    Ну как?

    Dev_18, 12 Мая 2015

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

    +165

    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
    // Whoever introduced xml to shipping companies should be flogged
    $xml  = '<?xml version="1.0"?>';
    $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v10">';
    $xml .= '	<SOAP-ENV:Body>';
    $xml .= '		<ns1:RateRequest>';
    $xml .= '			<ns1:WebAuthenticationDetail>';
    
    // почти сотня строк
    
    $xml .= '</SOAP-ENV:Envelope>';
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    Смотри-ка, оно еще и ругается

    https://github.com/opencart/opencart/blob/58eeb544e2eddbe18b00224e10d2761259e8ce7b/upload/catalog/model/shipping/fedex.php#L48

    Fike, 12 Мая 2015

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

    +142

    1. 1
    Как-то долго на PHP говнокода не появляется, все научились писать что ли?

    proweber1, 12 Мая 2015

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

    +142

    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
    public function api() {
    	...
    	if ($this->validate()) {
    		if ($store_info) {
    			$url = $store_info['ssl'];
    		} else {
    			$url = HTTPS_CATALOG;
    		}
    		if (isset($this->session->data['cookie']) && isset($this->request->get['api'])) {
    			...
    			$curl = curl_init();
    			// Set SSL if required
    			if (substr($url, 0, 5) == 'https') {
    				curl_setopt($curl, CURLOPT_PORT, 443);
    			}
    			curl_setopt($curl, CURLOPT_HEADER, false);
    			curl_setopt($curl, CURLINFO_HEADER_OUT, true);
    			curl_setopt($curl, CURLOPT_USERAGENT, $this->request->server['HTTP_USER_AGENT']);
    			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    			curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
    			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    			curl_setopt($curl, CURLOPT_URL, $url . 'index.php?route=' . $this->request->get['api'] . ($url_data ? '&' . http_build_query($url_data) : ''));
    			if ($this->request->post) {
    				curl_setopt($curl, CURLOPT_POST, true);
    				curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->request->post));
    			}
    			curl_setopt($curl, CURLOPT_COOKIE, session_name() . '=' . $this->session->data['cookie'] . ';');
    			$json = curl_exec($curl);
    			curl_close($curl);

    API в опенкарте. Ну, короч, приходит пользователь, дергает АПИ, а я сам в контроллере дергаю свое АПИ. Такая практика.

    https://github.com/opencart/opencart/blob/4a151334efc702729071bd8d45a7e4af4e07b3ef/upload/admin/controller/sale/order.php#L2152

    Fike, 12 Мая 2015

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

    +142

    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
    <?php
    
    /* 
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    session_start();
    require "db.php";
    $id = $_GET["id"];
    pagedel($id);
    header ("location: index.php");
    
    function pagedel($id){    // функция удаления страниц
        $sql = "DELETE FROM mesage WHERE id=$id";
        mysql_query($sql) or die (mysql_error());
    }
    
    ?>

    не работает фукция удаления строки

    radiomonter, 11 Мая 2015

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