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

    +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
    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
    common.php:
    ....
    class Page { 
    	var $title;
    	var $style;
    	var $header;
    	var $content;
    	var $footer;
    
    	function setTitle($v) { 
    		$this->title=$v; 	
    	} 
    
    	function setStyle($v) { 
    		$this->style=$v; 
    	} 
    
    	function setHeader($v) { 
    		$this->header=$v; 
    	} 
    
    	function setContent($v) { 
    		$this->content=$v; 
    	} 
    
    	function setFooter($v) { 
    		$this->footer=$v; 
    	} 
    	
    	function getTitle() {
    		echo $this->title; 
    	}
    
    	function getStyle() {
    		echo $this->style; 
    	}
    	
    	function getHeader() {
    		echo $this->header; 
    	
    	}
    	
    	function getContent() {
    		echo $this->content; 
    	}
    
    	function getFooter() {
    		echo $this->footer; 
    	}
             ...
    }
    ...
    site.php:
      ...
       require('../../app/common.php');
       ....
       $p = new Page;
       $header ='<div id="title"><h2><a href="http://debtangel.mobi/bankruptcy/" >Divorce</a></h2></div>'.$location.'<p>Call Today <a  href="tel:8777328134">1-877-732-8134</a></p>';
       $p->setHeader($header); 
       $style = <<<EOT
    	body { background-color:white; color: black; font-family:Arial, Helvetica, sans-serif; }
    	a {	text-decoration: none;}
    	img { border:none; }...
           .....
       EOT;
       $p->setStyle($style); 
       $footer = <<<EOT
                        <p>Call <a href="tel:8777328134">1-877-732-8134</a></p><hr />
                        .....EOT;
      $p->setFooter($footer); 
       .......
    
    index.php:
         require_once ('site.php');
         $p->getTitle();
         $p->getStyle();
         $p->getHeader()
       и т.д.

    продолжение Говнокод #4313.....из тогоже "фреймворка"

    belial_y, 08 Октября 2010

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

    +157

    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
    function getFields () {
      global $requiredFields;
      global $alert;
      $formfields = "";
    
      foreach ($requiredFields as $name) {    
        if (isset($_SESSION[$name])) {
        // do nothing
        } elseif (isset($_POST[$name])) {
          if(verifyField($name)) {
            $_SESSION[$name] = $_POST[$name];
          } else {
            // display field again
            $formfields .= createField($name);
          }
        } else {
          // request field from user
          $formfields .= createField($name);
        }
      }
      return $formfields;
    }
    function getSessionValue($name) {
      if (isset($_SESSION[$name])) {
        return $_SESSION[$name];
      }  
      return NULL;
    }
    function getPostValue($name) {
      if (isset($_POST[$name])) {
        return $_POST[$name];
      }
      return NULL;
    }
    ...
     if (isset($labels[$name])) {
        return $labels[$name];
      } else {
        return $name;
      }
    }
    ....
    function createField($name) {
      if (isset($_POST[$name])) {
        $value = $_POST[$name];
      } else {
        $value = '';
      }
      $output = '';
      $label = getFieldLabel($name);
      switch ($name) {
        case 'firstname':
        case 'lastname':
        case 'name':
        case 'email':
        case 'confirm_email':
        case 'address':
        case 'expenses':
        case 'employer':
        case 'occupation':
        case 'MonthlyPayment':
        case 'nombre':
        case 'apellido':
        case 'correo':
          $output = "$label:<br/>
    			<input type=\"text\" name=\"$name\" value=\"$value\"/><br/>";
          break;
        case 'gender' :
          $output = $label . ':<br />
    	<select name="gender">
    	<option value="">-Select-</option>
    	<option value="m">Male</option>
    	<option value="f">Female</option>
    	</select><br />';
          break;
        case 'dob_month':
          $output = <<<EOT
    		$label:<br/>
    		<input type="text" name="$name" size="2" maxlength="2" value="$value" style="-wap-input-format: *N"/><br/>
    EOT;
          break;
        case 'dob_year':
          $output = <<<EOT
    		$label:<br/>
    		19<input type="text" name="$name" size="2" maxlength="2" value="$value" style="-wap-input-format: *N"/><br/>
    EOT;
          break;
        case 'dob_day':
          $output = <<<EOT
    		$label:<br/>
    		<input type="text" name="$name" size="2" maxlength="2" value="$value" style="-wap-input-format: *N"/><br/>
    EOT;
    ... 
      error_log($message);
          global $alert;
          $alert .= $message . '<br/>';
          break;
      }  return $output;
    }

    кусок из чудо "фреймворка" кем-то написанным. файл forms.php ."формирует" html поля для формы. такое там везде.

    belial_y, 08 Октября 2010

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

    +155

    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 printTree($array){
        global $db;
        for($i=0;$i<(count($array));$i++){
            #print $array[$i]['id'].'='.$array[$i]['title'];
            if($array[$i]['pid']==0){
                print '<li>'.$array[$i]['title']."</li>";
                $child=array();
                for($j=0;$j<count($db);$j++){
                    if($db[$j]['pid']!=0 && $db[$j]['pid']==$array[$i]['id']){
                        $child[]=array('id'=>$db[$j]['id'],'pid'=>0,'title'=>$db[$j]['title']);
                    }
                }
                print '<ul>';
                print printTree($child);
                print '</ul>';
            }
        }
    }

    Отрисовка дерева на PHP...

    nikelin, 08 Октября 2010

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

    +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
    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
    function checkUserPermission($module,$act){
            #return true;
            $this->temp=array();
            $this->temp['_result']=0;
            $this->temp['_uid']=explode('::',$_COOKIE['site_hash']);
            $this->temp['_uid']=$this->temp['_uid'][0];
            $this->temp['_gid']=$this->getUserSecurityAccess($this->temp['_uid']);
            $this->temp['_conn_id']=mysql_connect('host','user','passwd');
            mysql_select_db('database');
            $this->temp['_q1']=mysql_query('SELECT perms'
                            .'FROM `secure_groups`' 
                            .'WHERE id='.$this->temp['_gid']);    
            $this->temp['_access_stamp']=mysql_fetch_assoc($this->temp['_q1']);
            $this->temp['_access_stamp']=$this->temp['_access_stamp']['perms'];
            $this->temp['_access_stamp']=explode(';',$this->temp['_access_stamp']);
            $this->temp['_access_stamp']=array_slice($this->temp['_access_stamp'],0,-1);
            foreach($this->temp['_access_stamp'] as $this->temp['v']){
                $this->temp['_mod_access']=explode(':',$this->temp['v']);
                $this->temp['_mod_indefier']=$this->temp['_mod_access'][0];
                if($this->temp['_mod_indefier']==$module){
                    $this->temp['_perms']=explode(',',$this->temp['_mod_access'][1]);
                    switch($act){
                        case 'r':
                            $this->temp['_result']=($this->temp['_perms'][0]==1)? 1:0;
                            break;
                        case 'w':
                            $this->temp['_result']=($this->temp['_perms'][1]==1)? 1:0;
                            break;
                    }
                    break;
                }
            }
            mysql_close($conn_id);
            return $this->temp['_result'];
        }

    Такой вот занятный Acl :-D

    nikelin, 08 Октября 2010

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

    +162

    1. 1
    2. 2
    3. 3
    if ((int)$id == '') {
            throw new Engine_Exception('Нверный идентификатор организации', 403);
    }

    O_o а это когда-нибудь сработает :)

    lstaticl, 08 Октября 2010

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

    +172

    1. 1
    preg_match_all('/([h][t][t][p][:][\/][\/]([^\/]+)[\/][^\s">]+)[\s">]/is',$subject,$matches);

    Каждому знаку по домику!
    Регулярные премудрости или президентская программа в действии.

    Да, и с возвращением всех!!!

    Uchkuma, 07 Октября 2010

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $PUT_H = 'pay_history'; // это типа костанты
    $TAK_H = 'use_history';
    $PUT   = 'pay';
    
        $r = ($act === $PUT)
          ? $this->putMoney($_POST['payMethod'], $_POST['amount'])
          : ((!in_array($act, array($PUT_H, $TAK_H)))
    	 ? url_goto('cabinet/bill')
    	 : $this->showHistory($act != $TAK_H));

    такой-вот ахуенчик

    Holden, 21 Сентября 2010

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

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // seen in real project
    
    class SomeClass extends AnotherClass {
        protected $_AnotherClass = null;
        
        public function __construct() {
            $this->_AnotherClass = new AnotherClass();
        }
    }

    Сочная вырезка из структуры классов.

    shizzard, 20 Сентября 2010

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

    +152

    1. 1
    $this->Справочники = null;

    А вроде серьезная система...

    shizzard, 20 Сентября 2010

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

    +174

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    //коллаж картинок
    $total = 7;
    $i = 1;
    while ($i <= $total)
     {				
    	echo '<div><img src="'.$path.'picture/collage/'.$i.'.jpg" alt="Промышленное оборудование: трубогибы, пресс механический" title="Промышленное оборудование: трубогибы, пресс механический" /></div>'."\n";
    	$i++;
    	if($i > $total) break;
    }

    по моему простенько, но со вкусом :)

    t0xy, 20 Сентября 2010

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