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

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function generateGUID ()
      {
          $GUID = $this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter();
          return $GUID;
      }

    из класса для работы с paypal. (скачан с оффсайта)

    newmindcore, 16 Марта 2011

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

    +163

    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
    function price_filter_form()
    {
        // Хуярим неиибически сложную систему фильтрации по цене:
        $sql = "
    SELECT
    Max(c_good.price) AS `max`,
    Min(c_good.price) AS `min`,
    Count(c_good.price) AS `count`
    FROM
    c_good
    WHERE
    c_good.podcat_id =  '".mysql_real_escape_string($_GET['id'])."' AND
    c_good.onoff =  '1' AND c_good.`check` = '1'";
        $sql = mysql_query($sql) OR DIE (log_error('sql'));
        $price = mysql_fetch_assoc($sql);
        #echo ("<pre>");
        #print_r($price);
        #echo ("</pre>");
        if ($price['count'] < '10') // если товаров меньше 10, выводим 1 диапазон цен
        {
         $price_form = "<option value=\"".$price['min'].":".$price['max']."\">".$price['min']."-".$price['max']."руб.</option>";    
        }
        else
        {
            // Далее идёт непонятный говнокод, который к удивлению работает
            $step = (($price['max']-$price['min'])/11);
            $step = ceil($step);
            $step_len = strlen($step);
            $step = round($step, -($step_len-1));
            $first_step = ($price['min']+$step);
            $first_step_len = strlen($first_step);
            $first_step = (round($first_step, -($first_step_len-2))-1);
            #if ($first_step < $price['min']) $first_step = $price['min']+$step;
            $price_form = "<option value=\"".$price['min'].":".$first_step."\">".$price['min']."-".$first_step."руб.</option>";
            $price_form .= "<option value=\"".($first_step+1).":".($first_step+$step)."\">".($first_step+1)."-".($first_step+$step)."руб.</option>";
            
            #echo $step;
            for ($i=1;$i<8;$i++)
            {
             $price_form .= "<option value=\"".($first_step+($step*$i)+1).":".($first_step+($step*($i+1)))."\">
             ".($first_step+($step*$i)+1)."-".($first_step+($step*($i+1)))."руб.</option>";    
            }
            $price_form .= "<option value=\"".($first_step+($step*8)+1).":".$price['max']."\">
            ".($first_step+($step*8)+1)."-".$price['max']."руб.</option>";
        }
        $price_form = str_replace("\"".$defult_price['1']."\"", "\"".$defult_price['1']."\" selected", $price_form);
        return $price_form;
    }
    ?>

    вот с таким ГК пришлось столкнуться, после профилирования. Как Вам? Или - это нормально для PHP???
    P.S. комментарии сохранены авторские.

    ZeiZ, 16 Марта 2011

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

    +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
    16. 16
    17. 17
    18. 18
    elseif(isset($_GET['del']))
    {
        foreach($_POST as $id=>$a)
        {
            mysql_query("DELETE FROM `{$prefixbd}$table` WHERE `id`='".intval($id)."'")or die(mysql_error());
            @chmod(ret_img($file_path.$id),0777);
            @unlink(ret_img($file_path.$id));
            @chmod(ret_img($file_path.$id.'_big'),0777);
            @unlink(ret_img($file_path.$id.'_big'));
            $sql=mysql_query("SELECT FROM `{$prefixbd}{$table}_img` WHERE `prod`='".intval($id)."'")or die(mysql_error());
            while($data=mysql_fetch_assoc($sql)){
                @chmod(ret_img($file_path.$id.'_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_'.$data['id'].'_add'));
                @chmod(ret_img($file_path.$id.'_big_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_big_'.$data['id'].'_add'));
                mysql_query("DELETE FROM `{$prefixbd}{$table}_img` WHERE `id`='".$data['id']."'");
            }
        }

    Обратите внимание как удаляет файлы)) исходник из некого chrono CMS

    dobs2005, 16 Марта 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    ...
    $tlang->description = "Русский";
    $tlang->filename = "russian.php";
    $tlang->template_path = 'newtpl'; // Какой идиот придумал хранить настройки шаблонов в языках???
    ...

    Кусок из шоп скрипт... ивправду какого хрена так делать - загадка...

    dobs2005, 15 Марта 2011

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

    +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
    $properties_array = array_keys($this->values);
                array_unshift($properties_array, $properties_array[0]);
                unset($properties_array[0]);
                $properties_values_array = array_values($properties_array);
                $values_array = array_values($this->values);
                $properties = implode('` ,`', $properties_values_array);
                $values = implode(', ', array_fill(0, count($this->values), '?'));
                $result = self::$orm->db->prepare('INSERT INTO `' . $this->table . '`  (`' . $properties . '`) values (' . $values . ')');
                foreach ($values_array as $key => $value) {
                    $fieldinfo = $this->fields[$properties_values_array[$key]];
                    $result->bindParam($key + 1, $values_array[$key], $this->correctDataType($fieldinfo['native_type'], $fieldinfo['pdo_type']), $fieldinfo['len']);
                }
                $result->execute();

    Чувствую код плохо пахнет, надо разбирать)) Высоко нагруженный проект ;)

    PANACEA, 15 Марта 2011

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

    +164

    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
    function AuthorizeUser()
            {
                    global $USER;
                    if ( ( $USER->IsAuthorized() && $USER->GetID() == $this->GetUserID()) || $USER->IsAdmin())
                    {
                            return true;
                    }
                    else if ($this->AuthorizeByIP())
                    {
                            return true;
                    }
                    else if (1==2)
                    {
                            return true;
                    }
                    
                    return false;
            }

    А вдруг?

    elw00d, 14 Марта 2011

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

    +163

    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
    <?php
    set_time_limit(0);
    $d    = 0;
    $t    = 0;
    $link = mysql_connect('localhost', 'root', '123456'); // or die(mysql_error());
    //mysql_query('SET NAMES `cp1251`') or die(mysql_error());
    $dbr = mysql_query('SHOW DATABASES') or die(mysql_error());
    while ($dbd = mysql_fetch_assoc($dbr)) {
        if ($dbd['Database'] != 'information_schema') {
            mysql_select_db($dbd['Database'], $link); // or die(mysql_error());
            $tr  = mysql_query('SHOW  TABLES'); // or die(mysql_error());
            $sql = '';
            while ($td = mysql_fetch_assoc($tr)) {
                $sql .= '`' . $td['Tables_in_' . $dbd['Database']] . '`, ';
                ++$t;
            }
            $sql = substr($sql, 0, -2);
            mysql_query('REPAIR TABLE  ' . $sql . ''); // or die(mysql_error());
            ++$d;
        }
    }
    echo 'Востановил: ' . $d . ' баз(ы) данных, общие кол-во таблиц: ' . $t;
    mysql_close($link);

    Делает "REPAIR" всех баз данных.

    Unknown, 14 Марта 2011

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

    +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
    if (isset($_GET['frends'])) {
      $query = "SELECT `imail` FROM `frends` WHERE imail ='" .$_SESSION['user'] . "' AND status = '1'";
      $res = mysql_query($query) or die(mysql_error());
      
      while ($row = mysql_fetch_array($res)) {
           $imail = $row['imail_frend'];
     
     
           $query2 = "SELECT * FROM `users` WHERE imail ='$imail'";
           $res2 = mysql_query($query2) or die(mysql_error());
       
          $row2 = mysql_fetch_array($res2);
           echo $row2['surname'];
     
       }
    }

    qbasic, 13 Марта 2011

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

    +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
    public function get_settings($id,$name,$total,$limit)
    {    
        $config = array();
        $config['total_rows'] = $total;
        $config['per_page'] = $limit;    
        $config['first_link'] = '&laquo;Первая';
        $config['last_link'] = 'Последняя&raquo;';
        $config['next_link'] = '&raquo;';
        $config['prev_link'] = '&laquo;';
    
        switch($id)
        {
            // Если навигация для категорий
            case 'category':            
                
                $config['base_url'] = base_url().'/index/category/'.$name;      
                $config['uri_segment'] = 4;
                
                //количество "цифровых" ссылок по бокам от текущей
                $config['num_links'] = 5;             
                
                return $config;            
                break; 
                
        }
    }

    qbasic, 13 Марта 2011

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

    +161

    1. 1
    $type = isset($type) ? $type : '$type';

    govnozmey, 13 Марта 2011

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