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

    +150

    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
    <?php
    
    function test_menu() {
      $menu['test'] = array(
        'page callback' => 'test_page',
        'access callback' => TRUE,
      );
    
      $menu['test/%user'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }

    vectoroc, 25 Марта 2011

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

    +150

    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
    <?php
    
    function test_menu() {
      $menu['test'] = array(
        'page callback' => 'test_page',
        'access callback' => TRUE,
      );
    
      $menu['test/%user'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }

    vectoroc, 25 Марта 2011

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

    +167

    1. 1
    2. 2
    <?php
    $nidPage_storage = 64578; // нид страницы "Магазины и склады" - хранится отдельно, потому что контент-менеджеры удаляют страницу "Магазинов" и нид всё время меняется

    Изначально это это был drupal.

    turdman, 25 Марта 2011

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

    +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
    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
    <?php
    $z=0;
    $ti=0;
    $ti2=0;
    
    $res=array();
    $txt="";
    $res=array();
    if($argc<2)exit(0);
    $fn=$argv[1];
    $pt='/(^|\b|\s)((\w|[а-я]|\d)+(?:\.|\,)?)(\b|\.|,|-)/i';
    if(isset($fn)){
    $fc=file($fn);
    foreach($fc as $nl=>$str){
    preg_match_all($pt,$str,$res,PREG_PATTERN_ORDER);
    foreach($res[0] as $key=>$per){
     # $per=trim($per);
    $sz=iconv_strlen($per);
    $tz=iconv_strlen($per);
    echo "Per $per key $key sz $sz\n";
    
    while($sz>=2){ 
     $eb = substr($per,0,$sz-1);
    echo "eb $eb\n";
    $res=system("cat -b dict.txt | grep ' ".$eb." ' | head -n1 | gawk '{ print $1 }'");
    #echo "$res\n";
    if($res!=""){
    echo "res $res\n";
    $oc=substr($per,$sz-1,$tz); 
    $fd=fopen("$argv[1].txt","a");
    if($fd<0){echo "fopen";exit(0);};
      fseek($fd,SEEK_END,0);
    fwrite($fd,"$res$oc ");
    
    fclose($fd);
    $sz=1;
    sleep(3);
    };
      $sz--;
    };
    if($sz==1){
    
    $fd=fopen("$argv[1].txt","a");
    if($fd<0){echo "fopen";exit(0);};
      fseek($fd,SEEK_END,0);
      fwrite($fd,"$per ");
      fclose($fd);
    };
    
    };
    };
    $str="";
    $res="";
    }
    ?>

    Замена слова кодом из словаря, по номеру слова в словаре.

    AliceGoth, 25 Марта 2011

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

    +173

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if ($mail->send($mailTo)) { 
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    			$fname = $fmail = $ftext = "";
    		} else { 
    			$fname = $fmail = $ftext = "";
    			$aSuccMess[] = "Спасибо. Ваш сообщение отправлено. Администрация сайта рассмотрит его в ближайшее время.";
    		}

    Взято с сайта, сделанным моим коллегой)

    sleeper, 24 Марта 2011

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

    +167

    1. 1
    2. 2
    $handle = fopen($filename, "a+");
    fwrite($handle, '');

    В цикле таким образом измененяли дату модификации файлов. Существование touch() похоже было неизвестно.

    tkf, 24 Марта 2011

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

    +158

    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
    class Query {
      protected $baseTable;
      protected $baseTableAlias;
      protected $whereGroup;
    
      protected $joins = array();
      protected $fields = array();
    
      protected $executed = FALSE;
      protected $resource = NULL;
    
    
      function __construct($base_table = 'node', $alias = 'n') {
        $this->whereGroup = new QueryWhereGroup();
        $this->baseTable = $base_table;
        $this->baseTableAlias = empty($alias) ? $base_table : $alias;
      }
    
      function select($fields) {
        settype($fields, 'array');
        foreach ($fields as $alias => $field) {
          if (is_numeric($alias)) {
            $this->fields[] = $field;
          }
          else {
            $this->fields[$alias] = "$field as $alias";
          }
        }
    
        return $this;
      }
    
      /**
       * @param QueryWhereGroup $whereGroup
       * @return Query
       */
      function where($whereGroup) {
        call_user_func_array(array($this->whereGroup, 'cond'), func_get_args());
        return $this;
      }
    
      function createWhereGroup() {
        return new QueryWhereGroup();
      }
    
      function join($table, $alias = NULL, $condition, $join_type = 'INNER') {
        if (!$alias) {
          $alias = $table;
        }
    
        if (is_array($condition)) {
          $condition = 'USING ('. join(', ', $condition) .')';
        }
        if (!preg_match('/^ON|USING/i', $condition)) {
          $condition = 'ON '. $condition;
        }
    
        $this->joins[$alias] = "$join_type JOIN $table $alias $condition";
        return $this;
      }
    
      function compile() {
        $select_fields = join(', ', array_unique($this->fields));
        $joins_list = join("\n", $this->joins);
        $where_conditions = $this->whereGroup->compile();
    
        if (!empty($where_conditions)) {
          $where_conditions = 'WHERE '. $where_conditions;
        }
    
        return "SELECT $select_fields FROM {{$this->baseTable}} {$this->baseTableAlias} \n $joins_list $where_conditions";
      }
    
      function args() {
        return $this->whereGroup->args;
      }
    
      function execute() {
        return db_query($this->compile(), $this->args());
      }
    
      function fetchAll() {
        $res = $this->execute();
        while($row = db_fetch_object($res)) {
          $rows[] = $row;
        }
        return $rows;
      }
    }

    построитель запросов (drupal 6)
    wheregroup здесь http://govnokod.ru/6076

    vectoroc, 23 Марта 2011

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

    +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
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    class QueryWhereGroup {
      public $groupOp = 'AND';
      public $args = array();
      public $conditions = array();
    
      function cond($field, $value = NULL, $op = '=') {
        if ($value === NULL) {
          $this->conditions[] = $field;
          if (is_object($field) && isset($field->args)) {
            $this->args = array_merge($this->args, $field->args);
          }
        }
        else {
          if (is_numeric($value)) {
            $this->conditions[] = "$field $op %d";
            $this->args[]  = $value;
          }
          elseif (is_array($value)) {
            $placeholders  = db_placeholders($value, is_numeric(current($value)) ? 'int' : 'text');
            $this->conditions[] = "$field  IN ($placeholders)";
            $this->args = array_merge($this->args, $value);
          }
          else {
            $this->conditions[] = "$field $op '%s'";
            $this->args[]  = $value;
          }
        }
    
        return $this;
      }
    
      function compile($wrap = FALSE) {
        $result = join(" $this->groupOp ", $this->conditions);
        if ($wrap && !empty($result)) {
          $result = "(\n$result\n)";
        }
    
        return $result;
      }
    
      function __toString() {
        return $this->compile();
      }
    }

    см. след говнокод

    vectoroc, 23 Марта 2011

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

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if ( $arOrderProps['CODE'] == 'BIRTHDATE_MONTH'
    	  || $arOrderProps['CODE'] == 'DOCEXPIRATION_MONTH'
    	  || $arOrderProps['CODE'] == 'BIRTHDATE_DAY'
    	  || $arOrderProps['CODE'] == 'DOCEXPIRATION_DAY' )
    {
    	if ( $curVal[0] == '0' )
    	{
    	$curVal = $curVal[1];
    	}
    }

    Преобразование месяца или дня, например 05 => 5. var_dump( $curVal ) => string(2) "20"

    wwwguru, 23 Марта 2011

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

    +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
    <?php
    $str=$argv[1];
    $sz=sizeof($str);
    $c=1;
    while($c){
    for($i=0;$i<=10;$i++){
    $str = strtolower($str);
    $per = str_shuffle($str);
    #echo "$per\n";
    $res=system("egrep ' ".$per." ' ./dict.txt | gawk '{ print $1 }'");
    if($res!="" && $sz=sizeof($res)){echo "Success $res\n";};
    };
    };
    ?>

    Поиск слов в словаре

    AliceGoth, 23 Марта 2011

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