You are here

function hacked_find_local_project_directory in Hacked! 5

Same name and namespace in other branches
  1. 6 hacked.module \hacked_find_local_project_directory()

Return the location of the installed project.

As drupal modules do not need to be named the same as the projects they are part of we need to be a little smarter about how we find the project directory to start hashing in.

5 calls to hacked_find_local_project_directory()
drush_hacked_diff in ./hacked.drush.inc
Drush command callback that shows the list of changes/unchanged files in a project.
hacked_calculate_project_data in ./hacked.module
hacked_hash_local in ./hacked.module
hacked_reports_hacked_diff in ./hacked.diff.inc
theme_hacked_detailed_report in ./hacked.details.inc
Theme project status report.

File

./hacked.module, line 298
The Hacked! module, shows which project have been changed since download.

Code

function hacked_find_local_project_directory($project) {

  // Do we have at least some modules to check for:
  if (!is_array($project['modules']) || !count($project['modules'])) {
    return FALSE;
  }

  // If this project is drupal it, we need to handle it specially
  if ($project['project_type'] != 'core') {
    $include = array_shift(array_keys($project['modules']));
    $include_type = $project['project_type'];
  }
  else {

    // Just use the system module to find where we've installed drupal
    $include = 'system';
    $include_type = 'module';
  }
  $path = drupal_get_path($include_type, $include);

  // Now we need to find the path of the info file in the downloaded package:
  // TODO: Can replace this with using the info file stuff we put there earlier:
  $temp = '';
  foreach ($project['clean_hashes'] as $file => $hash) {
    if (strpos($file, "{$include}.info") !== FALSE) {

      // TODO: Replace this with a regular expression
      $temp = str_replace("{$include}.info", '', $file);
      break;
    }
  }

  // How many '/' were in that path:
  $slash_count = substr_count($temp, '/');
  $back_track = str_repeat('/..', $slash_count);
  return realpath($path . $back_track);
}