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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <ul>
        {foreach $сity as $c}
            {if Core::model()->getValue($c,'name') === $form->city_name}
                {assign $form->city_id $c['id']}
            {/if}
            <li data-value="{$c['id']}" class="{if $c['id']===$form->city_id}active{/if}"><span>{Core::model()->getValue($c,'name')}</span></li>
        {/foreach}
    </ul>

    Типичный шаблон на фреймворках PHP, в данном случае Yii 1.1

    M-A-X, 01 Июня 2016

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

    −3

    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
    [Wed Jun 01 10:13:25.866953 2016] [autoindex:error] [pid 30710] [client 77.222.112.203:24108] AH01276: Cannot serve directory /home/u325415/test.alpina-nerud.ru/www/: No matching DirectoryIndex (index.html,index.htm,index.php,index.php3,index.phtml,index.cgi,index.pl,index.shtml,default.htm,default.html) found, and server-generated directory index forbidden by Options directive
    [Wed Jun 01 10:21:28.044222 2016] [autoindex:error] [pid 4437] [client 77.222.112.203:30432] AH01276: Cannot serve directory /home/u325415/test.alpina-nerud.ru/www/: No matching DirectoryIndex (index.html,index.htm,index.php,index.php3,index.phtml,index.cgi,index.pl,index.shtml,default.htm,default.html) found, and server-generated directory index forbidden by Options directive
    [Wed Jun 01 10:28:39.825066 2016] [autoindex:error] [pid 10534] [client 77.222.112.203:36957] AH01276: Cannot serve directory /home/u325415/test.alpina-nerud.ru/www/: No matching DirectoryIndex (index.html,index.htm,index.php,index.php3,index.phtml,index.cgi,index.pl,index.shtml,default.htm,default.html) found, and server-generated directory index forbidden by Options directive
    [Wed Jun 01 12:11:48.394301 2016] [:error] [pid 6058] [client 77.222.112.203:37192] PHP Warning:  require(typo3/sysext/core/Classes/Core/Bootstrap.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/u325415/test.alpina-nerud.ru/www/index.php on line 48
    [Wed Jun 01 12:11:48.394400 2016] [:error] [pid 6058] [client 77.222.112.203:37192] PHP Warning:  require(typo3/sysext/core/Classes/Core/Bootstrap.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/u325415/test.alpina-nerud.ru/www/index.php on line 48
    [Wed Jun 01 12:11:48.394426 2016] [:error] [pid 6058] [client 77.222.112.203:37192] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required 'typo3/sysext/core/Classes/Core/Bootstrap.php' (include_path='.:/usr/share/php53:/usr/share/pear53') in /home/u325415/test.alpina-nerud.ru/www/index.php on line 48
    [Wed Jun 01 12:18:39.840563 2016] [:error] [pid 12269] [client 77.222.112.203:15356] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1, referer: http://test.alpina-nerud.ru/typo3/
    [Wed Jun 01 12:18:42.839703 2016] [:error] [pid 12319] [client 77.222.112.203:15413] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:18:45.376653 2016] [:error] [pid 12333] [client 77.222.112.203:15456] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:19:02.624195 2016] [:error] [pid 12557] [client 77.222.112.203:15794] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:19:04.446064 2016] [:error] [pid 12573] [client 77.222.112.203:15826] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:20:25.263810 2016] [:error] [pid 13455] [client 77.222.112.203:17281] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:21:43.511456 2016] [:error] [pid 14762] [client 77.222.112.203:18648] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:21:54.006698 2016] [:error] [pid 14760] [client 77.222.112.203:18644] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:21:56.294966 2016] [:error] [pid 14894] [client 77.222.112.203:18855] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:22:11.178438 2016] [:error] [pid 15124] [client 77.222.112.203:19238] PHP Parse error:  syntax error, unexpected T_CLASS in /home/u325415/test.alpina-nerud.ru/www/typo3conf/ext/chgallery/lib/class.tx_chgallery_tca.php on line 1
    [Wed Jun 01 12:23:17.882880 2016] [:error] [pid 15798] [client 77.222.112.203:20386] PHP Warning:  require(sysext/core/Classes/Core/Bootstrap.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/u325415/test.alpina-nerud.ru/www/typo3/init.php on line 55
    [Wed Jun 01 12:23:17.882976 2016] [:error] [pid 15798] [client 77.222.112.203:20386] PHP Warning:  require(sysext/core/Classes/Core/Bootstrap.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/u325415/test.alpina-nerud.ru/www/typo3/init.php on line 55
    [Wed Jun 01 12:23:17.883003 2016] [:error] [pid 15798] [client 77.222.112.203:20386] PHP Fatal error:  require() [<a href='function.require'>function.require</a>]: Failed opening required 'sysext/core/Classes/Core/Bootstrap.php' (include_path='.:/usr/share/php53:/usr/share/pear53') in /home/u325415/test.alpina-nerud.ru/www/typo3/init.php on line 55

    Ошибка в логах

    ponoroshca, 01 Июня 2016

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

    −3

    1. 1
    { "destination_addresses" : [ "Seattle, Washington, USA" ], "origin_addresses" : [ "Vancouver, Britisch-Kolumbien, Kanada" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "229 km", "value" : 229112 }, "duration" : { "text" : "2 Stunden, 35 Minuten", "value" : 9311 }, "status" : "OK" } ] } ], "status" : "OK" }

    viromax, 01 Июня 2016

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC&destinations=Seattle&mode=driving&language=de");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    $response = curl_exec($ch);
    echo $response;
    $array = json_decode($response, true);
    echo $array["destination_addresses"];
    ?>

    viromax, 01 Июня 2016

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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
       * Detects if the current device is using a mac OS
       */
      function DetectMacOSX() {
        if (stripos($this->userAgent, $this->macOSX) !== FALSE) {
          return TRUE;
        }
        else {
          return FALSE;
        }
      }

    vigasin, 01 Июня 2016

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

    +1

    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
    public function timeDiff( $time, $now = null ) {
    		if ( ! is_int( $time ) )
    			$time = strtotime( (string) $time ) + ( get_option( 'gmt_offset' ) * 3600 - 10800 );
    		if ( is_null( $now ) )
    			$now = time();
    		if ( $now == $time )
    			return __( 'right now', Challonge_Plugin::TEXT_DOMAIN );
    		if ( $now < $time )
    			/* translators:
    				%s is an approximate relative amount of time (eg. "2 days")
    			*/
    			return sprintf( __( 'in %s', Challonge_Plugin::TEXT_DOMAIN ), human_time_diff( $time, $now ) );
    		/* translators:
    			%s is an approximate relative amount of time (eg. "2 days")
    		*/
    		return sprintf( __( '%s ago', Challonge_Plugin::TEXT_DOMAIN ), human_time_diff( $time, $now ) );
    	}

    -10800
    починил блять!

    pstnkv, 30 Мая 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <script>
      var x = [];
      var y = [];
      x = [<?php foreach ($chart as $word => $f) echo "'$word', " ?>];
      y = [<?php foreach ($chart as $f) echo "$f, " ?>];
    </script>

    JS

    Stefan, 25 Мая 2016

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

    +4

    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
    if ($_REQUEST["date_type"] == 1) {
                    $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($doneStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($doneStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                } else {
                    if ($_REQUEST["date_type"] == 2) {
                        $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE `status_id` AND (DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])))."))";
                     } else  {                 
                        if ($_REQUEST["date_type"] == 3) {
                            $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE ((`status_id`=".$DB->F($doneStatus["id"])." OR `status_id`=".$DB->F($failStatus["id"])." OR `status_id`=".$DB->F($failOpStatus["id"]).") AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE ((`status_id`=".$DB->F($doneStatus["id"])." OR `status_id`=".$DB->F($failStatus["id"])." OR `status_id`=".$DB->F($failOpStatus["id"]).") AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";                
                        } else {
                            if ($_REQUEST["date_type"] == 4) {
                                // am
                                $filter .= "AND tick.inmoney=1  AND DATE_FORMAT(tick.inmoneydate, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom']))) . " AND DATE_FORMAT(tick.inmoneydate, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])));
                            } else {
                                if ($_REQUEST["date_type"] == 5) {
                                    //cl_date
                                    $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($closedStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($closedStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                } else {
                                    if ($_REQUEST["date_type"] == 6) {
                                        //rep_date
                                        $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($reportStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                    } else {
                                        if ($_REQUEST["date_type"] == 7) {
                                            //rep_date
                                            $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($accStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                        } else {
                                            $filter .= " AND DATE_FORMAT(t.date_reg, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom']))) . " AND DATE_FORMAT(t.date_reg, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])));
                                        }
                                    }
                                }  
                            }
                            
                        }
                     }
                }

    Запрос для какого-то отчета by ©senior shaurma developer

    pahhan, 22 Мая 2016

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

    −3

    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
    98. 98
    99. 99
    <?php
    namespace AppBundle\Command;
    
    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class InterpolationLabsCommand extends ContainerAwareCommand
    {
    
        /**
         * nodes for interpolation polynomial
         */
        protected $_nodes;
    
    
        protected function configure()
        {
            $this
                ->setName('app:interpolation:labs')
                ->setDescription('interpolation')
                ->addOption('nodes-count', null, InputOption::VALUE_REQUIRED, 
                    'Sets the number of nodes for interpolation.', null);
        }
    
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $intervalStart = -3;
            $intervalEnd  = 3;
    
            $nodesCount = $input->getOption('nodes-count');
            
            $this->generateSeries($nodesCount, $intervalStart, $intervalEnd, function($x) {
                return sin($x);
            });
    
            foreach (range($intervalStart, $intervalEnd, 0.1) as $value) {
    
                $result = $this->getLagrangeValue($value);
                $output->writeln("$value $result");
            }
        }
    
        /**
         * Find value for lagrange interpolation polynomial at n nodes
         * @throw \Exception
         * 
         * @return 
         */
        protected function getLagrangeValue($x)
        {
    
            $w = function($nodeKey) use ($x) {
    
                if (!array_key_exists($nodeKey, $this->_nodes)) {
                    throw new \Exception("The key is not exists to the array nodes");
                }
    
                $return = 1;
                foreach ($this->_nodes as $key => $node) {
                    if ($key == $nodeKey) {
                        continue;
                    }
    
                    $return *= ($x - $node->x)/($this->getNode($nodeKey)->x - $node->x);
                }
                return $return;
            };
    
            $result = 0;
            foreach ($this->_nodes as $nodeKey => $node) {
                $a = $w($nodeKey);
    
                $result += $w($nodeKey) * $node->fx;
            }
    
            return $result;
    
        }
    
        protected function getNode($i)
        {
            return $this->_nodes[$i];
        }
    
    
        private function generateSeries($num,  $intervalStart, $intervalEnd,  $fun)
        {
            for ($i=0; $i < $num; $i++) { 
    
                $x  = $intervalStart + ($intervalEnd - $intervalStart)/($num-1) * $i;
                $this->_nodes[] = (object) array('x' => $x, 
                    'fx' => $fun($x)); 
            }
        }
    }

    Лаба по методам численного анализа

    konmado, 19 Мая 2016

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

    0

    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
    require_once ('./main/config.php');
    class user 
    {
        /* 
        private login;
        private password;
        private username;
        private about;
        */
        
        function registerUser($login, $password, $username, $about)
        {
            $db = MysqliDb::getInstance();
            $data = Array ("login" => $login,
                   "password" => $password,
                   "username" => $username,
                   "about" => $about,
            );
            $id = $db->insert ('users', $data);
            if($id)
                echo 'user was created. Id=' . $id;
        }
        
        function authorizeUser($login, $password)
        {
            $db->where ("id", 1);
            $user = $db->getOne ("users");
            echo $user['id'];
            /*
            $logins = $db->getValue ("users", "login", null);
            // select login from users
            // select login from users limit 5
            foreach ($logins as $login)
            echo $login;
            */
        }
        
        
    }

    Ну как вам? Класс юзера для регистрации и авторизации (недоделан)

    Folsky, 18 Мая 2016

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