| Conditions | 12 |
| Paths | 98 |
| Total Lines | 63 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 43 | function CheckAuthentication($drupal_path) |
||
| 44 | { |
||
| 45 | static $authenticated; |
||
| 46 | |||
| 47 | if (!isset($authenticated)) { |
||
| 48 | if (!isset($bootstrap_file_found) || $bootstrap_file_found) { |
||
| 49 | $current_cwd = getcwd(); |
||
| 50 | if (!defined('DRUPAL_ROOT')) { |
||
| 51 | define('DRUPAL_ROOT', $drupal_path); |
||
| 52 | } |
||
| 53 | |||
| 54 | // Simulate being in the drupal root folder so we can share the session |
||
| 55 | chdir(DRUPAL_ROOT); |
||
| 56 | |||
| 57 | global $base_url; |
||
| 58 | $base_root = (isset($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) ? 'https' : 'http'; |
||
| 59 | $base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']); |
||
| 60 | |||
| 61 | if ($dir = trim(dirname($_SERVER['SCRIPT_NAME']), '\,/')) { |
||
| 62 | $base_path = "/$dir"; |
||
| 63 | $base_url .= $base_path; |
||
| 64 | } |
||
| 65 | |||
| 66 | // correct base_url so it points to Drupal root |
||
| 67 | $pos = strpos($base_url, '/sites/'); |
||
| 68 | $base_url = substr($base_url, 0, $pos); // drupal root absolute url |
||
| 69 | |||
| 70 | // If we aren't in a Drupal installation, or if Drupal path hasn't been properly found, die |
||
| 71 | if (!file_exists(DRUPAL_ROOT . '/includes/bootstrap.inc')) { |
||
| 72 | die('The CMS integration service for -drupal- requires KCFinder to be properly placed inside your Drupal installation.'); |
||
| 73 | } |
||
| 74 | |||
| 75 | // bootstrap |
||
| 76 | require_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); |
||
| 77 | drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); |
||
| 78 | |||
| 79 | // if user has access permission... |
||
| 80 | if (user_access('access kcfinder')) { |
||
| 81 | if (!isset($_SESSION['KCFINDER'])) { |
||
| 82 | $_SESSION['KCFINDER'] = []; |
||
| 83 | $_SESSION['KCFINDER']['disabled'] = false; |
||
| 84 | } |
||
| 85 | |||
| 86 | // User has permission, so make sure KCFinder is not disabled! |
||
| 87 | if (!isset($_SESSION['KCFINDER']['disabled'])) { |
||
| 88 | $_SESSION['KCFINDER']['disabled'] = false; |
||
| 89 | } |
||
| 90 | |||
| 91 | global $user; |
||
| 92 | $_SESSION['KCFINDER']['uploadURL'] = strtr(variable_get('kcfinder_upload_url', 'sites/default/files/kcfinder'), ['%u' => $user->uid, '%n' => $user->name]); |
||
| 93 | $_SESSION['KCFINDER']['uploadDir'] = strtr(variable_get('kcfinder_upload_dir', ''), ['%u' => $user->uid, '%n' => $user->name]); |
||
| 94 | $_SESSION['KCFINDER']['theme'] = variable_get('kcfinder_theme', 'default'); |
||
| 95 | |||
| 96 | //echo '<br />uploadURL: ' . $_SESSION['KCFINDER']['uploadURL']<br />; |
||
| 97 | //echo '<br />uploadDir: ' . $_SESSION['KCFINDER']['uploadDir']<br />; |
||
| 98 | |||
| 99 | chdir($current_cwd); |
||
| 100 | |||
| 101 | return true; |
||
| 102 | } |
||
| 103 | |||
| 104 | chdir($current_cwd); |
||
| 105 | return false; |
||
| 106 | } |
||
| 111 |