극단적인 드루팔 메시지 숨김법

* 이 방법은 극단적인 메시지 숨김법입니다.
에러 메시지의 근본적인 문제를 해결하기를 바라며 본 방법은 급할 때 이외에 추천하지 않습니다.

드루팔 drupal_set_message는 온갖 에러/경고 메시지를 다 뿌려대다 보니
드루지기처럼 게으른 자들에게는 악몽과 같다 (왠만하면 표시하지 말고 몰래 알려줘!)

PHP의 버전변경이나 각종 모듈의 업그레이드로 예상못한 에러가 생기면
시스템의 패스마져 공개되는 경우가 있어 꽤나 신경쓰인다. (물론 잘 정비하면 문제 없지만)

그래서 관리자 권한자인 경우에만 메시지를 표시토록
includes/bootstrap.inc 를 아래와 같이 수정하면 당분간 편하다.
게으른 관리자를 위한 극단적인 수정이다.

                                                                                           
function is_admin()                                                                                  
{                                                                                                    
  global $user;                                                                                      
  if ($user->roles) {                                                                                
    $roles = implode("','", array_keys($user->roles));                                               
    $is_admin = db_result(db_query("SELECT COUNT(rid) FROM {permission} WHERE rid IN ('$roles') AND perm LIKE '%access administration pages%'"));                                                          
  }                                                                                                  
  return $is_admin;                                                                                  
}                                                                                                    
                                                                                                     
function drupal_set_message($message = NULL, $type = 'status', $repeat = TRUE) {                     
  if (!is_admin()) { return NULL; }                                                                  
  if ($message) {                                                                                    
    if (!isset($_SESSION['messages'])) {                                                             
      $_SESSION['messages'] = array();                                                               
    }                                                                                                
                                                                                                     
    if (!isset($_SESSION['messages'][$type])) {                                                      
      $_SESSION['messages'][$type] = array();                                                        
    }                                                                                                
                                                                                                     
    if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {                              
      $_SESSION['messages'][$type][] = $message;                                                     
    }                                                                                                
  }                                                                                                  
                                                                                                     
  // messages not set when DB connection fails                                                       
  return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL;                                
}         
No votes yet