Example #1
0
/*
 * Prior to PHP v5.3.6, the PDO does not pass along to MySQL the DSN charset configuration option,
 * and it must be done manually.
 */
if (version_compare(PHP_VERSION, '5.3.6', '<')) {
    $db->exec("SET NAMES utf8");
}
/*
 * We're going to need access to the database connection throughout the site.
 */
global $db;
/*
 * Include Solarium's autoloader, for queries to Solr.
 */
require 'Solarium/Autoloader.php';
Solarium_Autoloader::register();
/*
 * Include the custom functions file.
 */
require CUSTOM_FUNCTIONS;
/*
 * If Memcached or Redis is installed, instantiate a connection to it.
 */
if (defined('CACHE_HOST') && defined('CACHE_PORT')) {
    $cache = new Cache();
}
/*
 * Establish routes
 */
require 'routes.inc.php';
/*
 /**
  * Test whether the server environment is configured properly.
  *
  * Run a series of tests to determine whether the correct software is installed, permissions
  * are correct, and settings are enabled.
  *
  * @throws Exception if the environment test fails
  */
 function test_environment()
 {
     /*
      * Make sure that the PHP Data Objects extension is enabled.
      */
     if (!defined('PDO::ATTR_DRIVER_NAME')) {
         $this->logger->message('PHP Data Objects (PDO) must be enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that PDO MySQL support exists.
      */
     if (!in_array('mysql', PDO::getAvailableDrivers())) {
         $this->logger->message('PHP Data Objects (PDO) must have a MySQL driver enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that HTML Tidy is available within PHP or, failing that, at the command line.
      */
     if (class_exists('tidy', FALSE) == FALSE) {
         /*
          * A non-zero return status from a program called via exec() indicates an error.
          */
         exec('which tidy', $result, $status);
         if ($status != 0) {
             $this->logger->message('HTML Tidy must be installed.', 10);
             $error = TRUE;
         }
     }
     /*
      * Make sure that php-xml is installed.
      */
     if (extension_loaded('xml') == FALSE) {
         $this->logger->message('PHP’s XML extension must be installed and enabled.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that xmllint is installed.
      */
     exec('which xmllint', $result, $status);
     if ($status != 0) {
         $this->logger->message('xmllint must be installed.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that zip is installed.
      */
     exec('which zip', $result, $status);
     if ($status != 0) {
         $this->logger->message('zip must be installed.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that the configuration file is writable.
      */
     if (is_writable(INCLUDE_PATH . '/config.inc.php') !== TRUE) {
         $this->logger->message('config.inc.php must be writable by the server.', 10);
         $error = TRUE;
     }
     /*
      * Make sure that sitemap.xml is writable.
      */
     if (is_writable(WEB_ROOT . '/sitemap.xml') !== TRUE) {
         $this->logger->message('sitemap.xml must be writable by the server', 3);
         $error = TRUE;
     }
     /*
      * Make sure that .htaccess is writable.
      */
     if (is_writable(WEB_ROOT . '/.htaccess') !== TRUE) {
         $this->logger->message('.htaccess must be writable by the server', 3);
         $error = TRUE;
     }
     /*
      * If the Downloads directory exists, make sure that it's writable.
      */
     if (is_writable(WEB_ROOT . '/downloads') !== TRUE) {
         $this->logger->message('The downloads directory (' . WEB_ROOT . '/downloads/' . ') must be writable by the server.', 10);
         $error = TRUE;
     }
     if (defined('SOLR_URL')) {
         /*
          * Make sure that Solr is responsive.
          */
         Solarium_Autoloader::register();
         $client = new Solarium_Client($GLOBALS['solr_config']);
         $ping = $client->createPing();
         try {
             $result = $client->ping($ping);
         } catch (Solarium_Exception $e) {
             $this->logger->message('Solr must be installed, configured in config.inc.php, and running.', 10);
             $error = TRUE;
         }
     }
     if (isset($error)) {
         return FALSE;
     }
     return TRUE;
 }