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

    Всего: 11

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

    +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
    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
    class/View.php
    
    <?php
    
    class View {
    
    ...
    
      public function compile() {
        $view_src = file_get_contents(VIEW_SRC_PATH . $this->full_name . EXT);
        // echo
        $view_src = preg_replace("/\{\{(\w+)\}\}/", "<?php echo \$$1; ?>", $view_src);
        $view_src = preg_replace("/\{\{(\w+)\|(\w+)\}\}/", "<?php echo \$$1['$2']; ?>", $view_src);
        $view_src = preg_replace("/\{\{(\w+)\.(\w+)\}\}/", "<?php echo \$$1->$2; ?>", $view_src);
        // foreach
        $view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)-->/", "<?php foreach(\$$2 as \$$1): ?>", $view_src);
        $view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)\|(\w+)-->/", "<?php foreach(\$$2['$3'] as \$$1): ?>", $view_src);
        $view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)\.(\w+)-->/", "<?php foreach(\$$2->$3 as \$$1): ?>", $view_src);
        $view_src = preg_replace("/<!--each\s+(\w+)\s+(\w+)\s+in\s+(\w+)\.(\w+)-->/", "<?php foreach(\$$3->$4 as \$$1 => \$$2): ?>", $view_src);
        $view_src = preg_replace("/<!--each\s+(\w+)\s+(\w+)\s+in\s+(\w+)-->/", "<?php foreach(\$$3 as \$$1 => \$$2): ?>", $view_src);
        $view_src = preg_replace("/<!--each-->/", "<?php endforeach; ?>", $view_src);
        // switch
        $view_src = preg_replace("/<!--select\s+(\w+)\.(\w+)-->\s*<!--when\s+(.+)-->/", "<?php switch(\$$1->$2): case $3: ?>", $view_src);
        $view_src = preg_replace("/<!--when\s+(.+)-->/", "<?php break; ?><?php case $1: ?>", $view_src);
        $view_src = preg_replace("/<!--otherwise-->/", "<?php break; ?><?php default: ?>", $view_src);
        $view_src = preg_replace("/<!--select-->/", "<?php endswitch; ?>", $view_src);
        if (!file_exists(VIEW_PATH . $this->path)) mkdir(VIEW_PATH . $this->path, 0777, true);
        $fp = fopen(VIEW_PATH . $this->full_name . EXT, 'w');
        fwrite($fp, $view_src);
        fclose($fp);
      }
    
    ...
    
    ?>
    
    view-src/ShadeType.php
    
    {{type.name}}
    <!--each k d in type.diameters-->
    <h1>{{k}}</h1>
      <!--each s in d-->
      <div>
        {{s.bottom}} × {{s.top}} × {{s.height}}
        <div>
          <!--select s.mode-->
          <!--when 'u'-->(на ушках)
          <!--when 'p'-->(только подвес)
          <!--otherwise--> 
          <!--select-->
        </div>
      </div>
      <!--each-->
    <!--each-->
    
    view/ShadeType.php
    
    <?php echo $type->name; ?>
    <?php foreach($type->diameters as $k => $d): ?>
    <h1><?php echo $k; ?></h1>
      <?php foreach($d as $s): ?>
      <div>
        <?php echo $s->bottom; ?> × <?php echo $s->top; ?> × <?php echo $s->height; ?>
        <div>
          <?php switch($s->mode): case 'u': ?>(на ушках)
          <?php break; ?><?php case 'p': ?>(только подвес)
          <?php break; ?><?php default: ?> 
          <?php endswitch; ?>
        </div>
      </div>
      <?php endforeach; ?>
    <?php endforeach; ?>

    На хостинге PHP 5.2, а старые версии фреймворков не хочется. Решил запилить свой.

    kgm-rj, 13 Ноября 2015

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