Use __DIR__ magic constant instead of environment variable
This commit is contained in:
		@@ -6,8 +6,6 @@ KEY=''
 | 
			
		||||
# Delivery address is the original email before the "@".  e.g. if delivering to "support_mt@mayfirst.org", set this to "support_mt"
 | 
			
		||||
DELIVERY_ADDRESS='support_mt'
 | 
			
		||||
CATCHALL_PROJECT_NAME='catch'
 | 
			
		||||
# The path to the root directory containing this file.
 | 
			
		||||
FILEPATH='/usr/local/bin/redirect_test'
 | 
			
		||||
# Leave these three blank for false.
 | 
			
		||||
DEBUG_MODE=
 | 
			
		||||
DRY_RUN=
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ $membershipMapping = getUserMemberships($userList, $client);
 | 
			
		||||
writeUsers($projectsById, $membershipMapping);
 | 
			
		||||
 | 
			
		||||
function writeDomains($projectsByDomain) {
 | 
			
		||||
  $domainHandle = fopen('./data/domainmap.csv', 'w');
 | 
			
		||||
  $domainHandle = fopen(__DIR__ . '/data/domainmap.csv', 'w');
 | 
			
		||||
  foreach ($projectsByDomain as $domain => $identifier) {
 | 
			
		||||
    fwrite ($domainHandle, "$domain,$identifier\n");
 | 
			
		||||
  }
 | 
			
		||||
@@ -28,7 +28,7 @@ function writeDomains($projectsByDomain) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function writeUsers($projectsById, $membershipMapping) {
 | 
			
		||||
  $userHandle = fopen('./data/usermap.csv', 'w');
 | 
			
		||||
  $userHandle = fopen(__DIR__ . '/data/usermap.csv', 'w');
 | 
			
		||||
  foreach ($membershipMapping as $email => $projectId) {
 | 
			
		||||
    fwrite ($userHandle, "$email,{$projectsById[$projectId]}\n");
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -155,12 +155,11 @@ function SendToMailHandler($input, $params) {
 | 
			
		||||
 | 
			
		||||
//See if this email address is associated with a particular project
 | 
			
		||||
function ParseSenderEmail($from) {
 | 
			
		||||
  $filePath = getenv('FILEPATH');
 | 
			
		||||
  $project = $email = NULL;
 | 
			
		||||
  if(preg_match("/\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b/i", $from, $matches)) {
 | 
			
		||||
    $email = $matches[1];
 | 
			
		||||
  }
 | 
			
		||||
  if (($handle = fopen($filePath . "/" . "data/usermap.csv", 'r')) !== FALSE) {
 | 
			
		||||
  if (($handle = fopen(__DIR__ . "/" . "data/usermap.csv", 'r')) !== FALSE) {
 | 
			
		||||
    while (($data = fgetcsv($handle, 1000)) !== FALSE) {
 | 
			
		||||
      $users[$data[0]] = $data[1];
 | 
			
		||||
    }
 | 
			
		||||
@@ -172,12 +171,11 @@ function ParseSenderEmail($from) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function ParseSenderDomain($email) {
 | 
			
		||||
  $filePath = getenv('FILEPATH');
 | 
			
		||||
  $domain = $project = NULL;
 | 
			
		||||
  if(preg_match("/@(.*)\b/", $email, $matches)) {
 | 
			
		||||
    $domain = $matches[1];
 | 
			
		||||
  }
 | 
			
		||||
  if (($handle = fopen($filePath . "/" . "data/domainmap.csv", 'r')) !== FALSE) {
 | 
			
		||||
  if (($handle = fopen(__DIR__ . "/" . "data/domainmap.csv", 'r')) !== FALSE) {
 | 
			
		||||
    while (($data = fgetcsv($handle, 1000)) !== FALSE) {
 | 
			
		||||
      $domains[$data[0]] = $data[1];
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user