Changeset - 3c5b498b2a1b
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2011-02-09 23:29:02
ohnobinki@ohnopublishing.net
Avoid using an anonymous function to support <php-5.3 (i.e., normaldotcom's old servers).
1 file changed with 10 insertions and 4 deletions:
0 comments (0 inline, 0 general)
inc/admin.inc
Show inline comments
 
@@ -132,28 +132,25 @@ function school_cache($schools)
 
	      if (!mkdir($cache_auto_school_dir_name, 0755, TRUE))
 
		error_log('Unable to create needed directory: `' . $cache_auto_dir_name . '\'');
 
	    }
 

	
 
	  $semesters = array();
 
	  $semester_weights = 0;
 
	  /*
 
	   * Try to presort the semesters into the proper order based
 
	   * on time_start/time_end. We want the older semesters to be
 
	   * nearer to the end of the list. This way, the crawler
 
	   * doesn't have to decide how to sort the semesters itself:
 
	   */
 
	  usort($semesters, function ($sem_a, $sem_b)
 
		{
 
		  return $sem_a->time_start_get() - $sem_b->time_start_get();
 
		});
 
	  usort($semesters, 'school_cache_semesters_sort');
 

	
 
	  foreach ($school['crawled_semesters'] as $semester)
 
	    {
 
	      $semesters[$semester->id()] = array(
 
						  'id' => $semester->id(),
 
						  'time_start' => $semester->time_start_get(),
 
						  'time_end' => $semester->time_end_get(),
 
						  'weight' => $semester_weights ++,
 
						  'name' => $semester->name_get(),
 
						  );
 

	
 
	      $cache_auto_school_semester_dir_name = $cache_auto_school_dir_name . $semester->id() . DIRECTORY_SEPARATOR;
 
@@ -208,24 +205,33 @@ function school_cache($schools)
 
      fprintf(STDERR, "Unable to open `%s' for writing\n",
 
	      $cache_file_name);
 
      return 1;
 
    }
 
  fwrite($cache_file, serialize($cache));
 
  fclose($cache_file);
 

	
 
  return 0;
 
}
 

	
 
/**
 
 * \brief
 
 *   To support usort() call in school_cache() to sort semesters.
 
 */
 
function school_cache_semesters_sort (Semester $sem_a, Semester $sem_b)
 
{
 
  return $sem_a->time_start_get() - $sem_b->time_start_get();
 
}
 

	
 
/**
 
 * \brief
 
 *   Invoke a school's registration data crawler.
 
 *
 
 * Each school may export registration data on publically accessible
 
 * websites. Thus, we populate some autocomplete information by
 
 * crawling these pages and storing the information in a special set
 
 * of caches.
 
 *
 
 * Because crawling code can be non-trivial, it should be separated
 
 * from a school's main .inc file. Thus, if a school supports
 
 * crawling, it will have a file called
 
 * schools.d/<school_id>.crawl.inc. In this file, a function called
 
 * <school_id>_crawl(array &$semesters, $verbosity = 1) must be
0 comments (0 inline, 0 general)