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

    +145

    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
    <?php
    
    /* {{{ index */
    function creative_stat_default()
    {
        $dtime = urldecode(get_param('dtime', date('d.m.Y-d.m.Y')));
    
        list($begin_t, $end_t) = convert_date_calendar($dtime);
    
        $user = User::get_instance();
        $DB = DbSimple::getDb();
    
        $creatives_ids = $user->get_users_ids_by_roles(array('creative'));
    
        // user names
        $sql = " 
            SELECT user_id AS ARRAY_KEY, {$user->sql_case_names} as name
            FROM users
            WHERE user_id IN (?a)";
    
        $user_names = $DB->select($sql, $creatives_ids);
    
        // tasks all
        $sql = "
            SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_all
            FROM creative_tasks 
            WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d
            GROUP BY to_user_id
            ";
    
        $tasks = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
    
        // tasks done
        $sql = "
            SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_done
            FROM creative_tasks
            WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d AND status_id = ?d
            GROUP BY to_user_id
            ";
    
        $tasks_done = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
    
        // goods all
        $sql = "
            SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_all
            FROM goods
            WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d
            GROUP BY creatives_id
            ";
    
        $goods_all = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
    
        // goods active
        $sql = "
            SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_active
            FROM goods
            WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d AND status_id = ?d
            GROUP BY creatives_id
            ";
    
        $goods_active = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
    
        foreach($creatives_ids as $id) {
            $stat[$id] = array_merge(
                $user_names[$id], 
                isset($tasks[$id]) ? $tasks[$id] : array('tasks_all' => 0),
                isset($tasks_done[$id]) ? $tasks_done[$id] : array('tasks_done' => 0),
                array(
                    'tasks_not_ready' => (isset($tasks[$id]['tasks_all']) ? $tasks[$id]['tasks_all'] : 0) - 
                        (isset($tasks_done[$id]['tasks_done']) ? $tasks_done[$id]['tasks_done'] : 0)),
                isset($goods_all[$id]) ? $goods_all[$id] : array('goods_all' => 0),
                isset($goods_active[$id]) ? $goods_active[$id] : array('goods_active' => 0)
            );
        }
    
        render_tpl('creative/stat/index', array(
            'header'    => 'Статистика креатива',
            'dtime'     => $dtime,
            'stat'      => $stat
        ), 'creative#stat');
    }
    /* }}} */

    Собираю статистику. Каждый запрос возвращает массив с ключем = id пользователя, дальше это все клеится в один массив для отображения в табличке.

    Nicklasos, 30 Июня 2011

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

    +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
    $json = "";
    $json .= "{\n";
    $json .= "page: $page,\n";
    $json .= "total: $total,\n";
    $json .= "rows: [";
    $rc = false;
    
    while ($row = mysql_fetch_array($result)) {
    		if ($rc) $json .= ",";
    		$json .= "\n{";
    		$json .= "id:'".$row['id']."',";
    		$json .= "cltr: 'fo',";
    		$json .= "cell:['";
    		$json .= $row['secid'];
    
    		$json .="','".$row['blasttradedate'];
    
    		$json .="','".round($row['bid'],$row['decimals']);
    
    		$json .="','".round($row['offer'],$row['decimals']);
    
    		$json .="','".round($row['price'],$row['decimals']);
    
    		if(round($row['last'],$row['decimals'])) $json .="','".round($row['last'],$row['decimals']);
    		else $json .="', '";
    
                   // и еще много строк в том же духе
    }
    
    $json .= "]\n";
    $json .= "}";

    Сборка JSON по-джедайски

    maximum, 30 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
     * GetResponse
     * For common activation code length must be only 4 or 5 or 7 or 8 chars
     *
     * From XXX ... or 10
     * From YYY ... or 11
     *
     * @return string
     */

    эволюция

    elw00d, 30 Июня 2011

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

    +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
    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
    <?
    if(!defined('Hacking')) { die('Hacking attempt!'); exit;}
    
    $database_user_name="demo";
    $database_password="demo";
    $database_name="demo";
    $display_errors = false;
    $AdminEmail="[email protected]";
    $bpref="demo";
    $domenname="demo";
    function connect_db()
    {
    global $database_user_name, $database_password;
    $db=mysql_connect("localhost",$database_user_name,$database_password) or die ("Could not connect");
    mysql_query("SET NAMES cp1251") or die("Invalid query: " .mysql_error());
    return $db;
    }
    function db_name()
    {
    global $database_name;
    $db_name=$database_name;
    return $db_name;
    }
    function get_now()
    {
    $db=connect_db();
    $db_name=db_name();
    mysql_select_db($db_name,$db);
    $sql="select now() as now";
    $result=mysql_query($sql,$db);
    $myrow=mysql_fetch_array($result);
    $now=$myrow["now"];
    return $now;
    }
    function puterror($message)
    {
    echo("<p>$message</p>");
    exit();
    }
    foreach($_GET as $chexss) {
    if((eregi("<[^>]*script[^>]*>", $chexss)) || (eregi("<[^>]*object[^>]*>", $chexss)) ||
    (eregi("<[^>]*iframe[^>]*>", $chexss)) || (eregi("<[^>]*applet[^>]*>", $chexss)) ||
    (eregi("<[^>]*meta[^>]*>", $chexss)) || (eregi("<[^>]*style[^>]*>", $chexss)) ||
    (eregi("<[^>]*form[^>]*>", $chexss)) || (eregi("\([^>][^)]*\)", $chexss)) ||
    (eregi("<[^>]*frameset[^>]*>", $chexss)) || (eregi("<[^>]*onmouseover[^>]*>", $chexss)) ||
    (eregi("<[^>]*img[^>]*>", $chexss)) || (eregi("\"", $chexss)) || (eregi("'", $chexss))){
    die("Попытка ХАКА !");
    }
    } 
    $zzzz = html_entity_decode(urldecode($_SERVER['QUERY_STRING']));
    if ($zzzz) {
    if ((strpos($zzzz, '<') !== false) ||
    (strpos($zzzz, '>') !== false) ||
    (strpos($zzzz, '"') !== false) ||
    (strpos($zzzz, './') !== false) ||
    (strpos($zzzz, '../') !== false) ||
    (strpos($zzzz, '\'') !== false) ||
    (strpos($zzzz, '.pl') !== false) ||
    (strpos($zzzz, '.php') !== false)) 
    {
    die("Попытка ХАКА !");
    }
    }
    $zamena_b = array( "\x27", "\x22", "\x60", "\t",'\n','\r', '\\', "'","¬","#",";","~","[","]","{","}","=","-","+",")","(","*","&","^","%","$","<",">","?","!",".pl", ".php",'"' );
    $_GET = str_replace($zamena_b, '', $_GET);
    $_POST = str_replace($zamena_b, '', $_POST);
    $_SESSION = str_replace($zamena_b, '', $_SESSION);
    $_COOKIE = str_replace($zamena_b, '', $_COOKIE);
    $_ENV = str_replace($zamena_b, '', $_ENV);
    $_FILES = str_replace($zamena_b, '', $_FILES);
    $_REQUEST = str_replace($zamena_b, '', $_REQUEST);
    $_SERVER = str_replace($zamena_b, '', $_SERVER);
    ?>

    Просторы интернета богаты... Так вот люди работают с СУБД

    nethak, 30 Июня 2011

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $search_string = str_replace('"', '', $search_string);
    $search_string = str_replace('+', '%20', $search_string);
    
    //$search_string = preg_replace( '#([[:punct:]])#e', '( isset($punct[\'\1\']) ? $punct[\'\1\'] : \'\')', $search_string );
    $search_string = trim($search_string);
    $search_string = addslashes(stripslashes(htmlspecialchars(strip_tags(rawurldecode($search_string)))));

    Борямся с XSS

    yamaha252, 30 Июня 2011

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

    +154

    1. 1
    setcookie("password",$password,time()+94555556)

    Супер!

    substr, 29 Июня 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    //...
    	$fileinattachments = $root_directory.$filepath.$fileid.'_'.$filename;
    	if(!file($fileinattachments)) $fileinattachments = $root_directory.$filepath.$fileid."_".$filename
    //...
    ?>

    Много думал. Код из незабвенной vTiger CRM.

    mr.The, 29 Июня 2011

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

    +147

    1. 1
    date('d ', time()+3600*4);

    vdmodule, 28 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private function _fileExists($file)
    {
        if(file_exists(self::FILE_PATH . $file)) {
            return true;
        }
        return false;
    }

    Нашел в одном из проектов.

    cartman, 28 Июня 2011

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

    +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
    $get = dbcom('SELECT * FROM downloads ORDER BY views DESC;');
    			$i = 1;
    			while($row = mysql_fetch_array($get))
    			{
    				if($i == 1)
    				{
    					$p['v'] = $row['views'];
    				}
    				if($row['reports'] != 0)
    				{
    					$t['rep']++;
    				}
    				$t['dl'] += $row['views'];
    				$i = 0;
    			}

    DDLCMS is a COMMERCIAL grade content management system for DDL site owners.
    при 400к записях в downloads немножно все в ОЗУ не помещалось.

    peinguin, 28 Июня 2011

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