private function __construct()
 {
     $root = realpath(dirname(__FILE__) . '/../');
     $OAUTH_CONFIG = parse_ini_file(realpath(dirname(__FILE__) . '/oauth_config.ini'), true);
     self::$OAUTH_CONFIG = $OAUTH_CONFIG['OAUTH_CONFIG'];
     register_shutdown_function('INIT::fatalErrorHandler');
     if (stripos(PHP_SAPI, 'cli') === false) {
         register_shutdown_function('INIT::sessionClose');
         self::$PROTOCOL = isset($_SERVER['HTTPS']) ? "https" : "http";
         self::$HTTPHOST = self::$PROTOCOL . "://" . $_SERVER['HTTP_HOST'];
     } else {
         if (INIT::$DEBUG) {
             echo "\nPHP Running in CLI mode.\n\n";
         }
         //Possible CLI configurations. We definitly don't want sessions in our cron scripts
     }
     self::$ROOT = $root;
     // Accesible by Apache/PHP
     self::$BASEURL = "/";
     // Accesible by the browser
     self::$TIME_TO_EDIT_ENABLED = false;
     self::$DEFAULT_NUM_RESULTS_FROM_TM = 3;
     self::$THRESHOLD_MATCH_TM_NOT_TO_SHOW = 50;
     self::$DB_SERVER = "localhost";
     //database server
     self::$DB_DATABASE = "matecat";
     //database name
     self::$DB_USER = "******";
     //database login
     self::$DB_PASS = "******";
     //database password
     self::$MEMCACHE_SERVERS = array();
     //Not Used
     self::$REDIS_SERVERS = "tcp://localhost:6379";
     self::$QUEUE_BROKER_ADDRESS = "tcp://localhost:61613";
     self::$QUEUE_DQF_ADDRESS = "tcp://localhost:61613";
     self::$QUEUE_JMX_ADDRESS = "http://localhost:8161";
     self::$STORAGE_DIR = self::$ROOT . "/storage";
     self::$LOG_REPOSITORY = self::$STORAGE_DIR . "/log_archive";
     self::$UPLOAD_REPOSITORY = self::$STORAGE_DIR . "/upload";
     self::$CONVERSIONERRORS_REPOSITORY = self::$STORAGE_DIR . "/conversion_errors";
     self::$CONVERSIONERRORS_REPOSITORY_WEB = self::$BASEURL . "storage/conversion_errors";
     self::$TMP_DOWNLOAD = self::$STORAGE_DIR . "/tmp_download";
     self::$REFERENCE_REPOSITORY = self::$STORAGE_DIR . "/reference_files";
     self::$TEMPLATE_ROOT = self::$ROOT . "/lib/View";
     self::$MODEL_ROOT = self::$ROOT . '/lib/Model';
     self::$CONTROLLER_ROOT = self::$ROOT . '/lib/Controller';
     self::$UTILS_ROOT = self::$ROOT . '/lib/Utils';
     $this->_setIncludePath();
     spl_autoload_register('INIT::loadClass');
     require_once 'Predis/autoload.php';
     if (!is_dir(self::$STORAGE_DIR)) {
         mkdir(self::$STORAGE_DIR, 0755, true);
     }
     if (!is_dir(self::$LOG_REPOSITORY)) {
         mkdir(self::$LOG_REPOSITORY, 0755, true);
     }
     if (!is_dir(self::$UPLOAD_REPOSITORY)) {
         mkdir(self::$UPLOAD_REPOSITORY, 0755, true);
     }
     if (!is_dir(self::$CONVERSIONERRORS_REPOSITORY)) {
         mkdir(self::$CONVERSIONERRORS_REPOSITORY, 0755, true);
     }
     //auth sections
     self::$AUTHSECRET_PATH = self::$ROOT . '/inc/login_secret.dat';
     //if secret is set in file
     if (file_exists(self::$AUTHSECRET_PATH)) {
         //fetch it
         self::$AUTHSECRET = file_get_contents(self::$AUTHSECRET_PATH);
     } else {
         //try creating the file and the fetch it
         //generate pass
         $secret = self::generate_password(512);
         //put file
         file_put_contents(self::$AUTHSECRET_PATH, $secret);
         //if put succeed
         if (file_exists(self::$AUTHSECRET_PATH)) {
             //restrict permissions
             chmod(self::$AUTHSECRET_PATH, 0400);
         } else {
             //if couldn't create due to permissions, use default secret
             self::$AUTHSECRET = 'ScavengerOfHumanSorrow';
         }
     }
     self::$ENABLED_BROWSERS = array('applewebkit', 'chrome', 'safari');
     //, 'firefox');
     // sometimes the browser declare to be Mozilla but does not provide a valid Name (e.g. Safari).
     // This occurs especially in mobile environment. As an example, when you try to open a link from within
     // the GMail app, it redirect to an internal browser that does not declare a valid user agent
     // In this case we will show a notice on the top of the page instead of deny the access
     self::$UNTESTED_BROWSERS = array('mozillageneric');
     /**
      * Matecat open source by default only handles xliff files with a strong focus on sdlxliff
      * ( xliff produced by SDL Trados )
      *
      * We are not including the file converters into the Matecat code because we haven't find any open source
      * library that satisfy the required quality and licensing.
      *
      * Here you have two options
      *  a) Keep $CONVERSION_ENABLED to false, manually convert your files into xliff using SDL Trados, Okapi or similar
      *  b) Set $CONVERSION_ENABLED to true and implement your own converter
      *
      */
     self::$CONVERSION_ENABLED = false;
     self::$ANALYSIS_WORDS_PER_DAYS = 3000;
     self::$BUILD_NUMBER = '0.5.5';
     self::$VOLUME_ANALYSIS_ENABLED = true;
     self::$SUPPORT_MAIL = 'the owner of this Matecat instance';
     //default string is 'the owner of this Matecat instance'
     self::$AUTHCOOKIENAME = 'matecat_login_v2';
     self::$AUTHCOOKIEDURATION = 86400 * 60;
     self::$FORCE_XLIFF_CONVERSION = false;
     self::$WARNING_POLLING_INTERVAL = 20;
     //seconds
     self::$SEGMENT_QA_CHECK_INTERVAL = 1;
     //seconds
     self::$SPELL_CHECK_TRANSPORT_TYPE = 'shell';
     self::$SPELL_CHECK_ENABLED = false;
     self::$SAVE_SHASUM_FOR_FILES_LOADED = true;
     self::$MAX_UPLOAD_FILE_SIZE = 60 * 1024 * 1024;
     // bytes
     self::$MAX_UPLOAD_TMX_FILE_SIZE = 100 * 1024 * 1024;
     // bytes
     self::$MAX_NUM_FILES = 100;
     self::$SUPPORTED_FILE_TYPES = array('Office' => array('doc' => array('', '', 'extdoc'), 'dot' => array('', '', 'extdoc'), 'docx' => array('', '', 'extdoc'), 'dotx' => array('', '', 'extdoc'), 'docm' => array('', '', 'extdoc'), 'dotm' => array('', '', 'extdoc'), 'rtf' => array('', '', 'extdoc'), 'odt' => array('', '', 'extdoc'), 'sxw' => array('', '', 'extdoc'), 'txt' => array('', '', 'exttxt'), 'pdf' => array('', '', 'extpdf'), 'xls' => array('', '', 'extxls'), 'xlt' => array('', '', 'extxls'), 'xlsm' => array('', '', 'extxls'), 'xlsx' => array('', '', 'extxls'), 'xltx' => array('', '', 'extxls'), 'ods' => array('', '', 'extxls'), 'sxc' => array('', '', 'extxls'), 'csv' => array('', '', 'extxls'), 'pot' => array('', '', 'extppt'), 'pps' => array('', '', 'extppt'), 'ppt' => array('', '', 'extppt'), 'potm' => array('', '', 'extppt'), 'potx' => array('', '', 'extppt'), 'ppsm' => array('', '', 'extppt'), 'ppsx' => array('', '', 'extppt'), 'pptm' => array('', '', 'extppt'), 'pptx' => array('', '', 'extppt'), 'odp' => array('', '', 'extppt'), 'sxi' => array('', '', 'extppt'), 'xml' => array('', '', 'extxml')), 'Web' => array('htm' => array('', '', 'exthtm'), 'html' => array('', '', 'exthtm'), 'xhtml' => array('', '', 'exthtm'), 'xml' => array('', '', 'extxml')), "Interchange Formats" => array('xliff' => array('default', '', 'extxif'), 'sdlxliff' => array('default', '', 'extxif'), 'tmx' => array('', '', 'exttmx'), 'ttx' => array('', '', 'extttx'), 'itd' => array('', '', 'extitd'), 'xlf' => array('default', '', 'extxlf')), "Desktop Publishing" => array('mif' => array('', '', 'extmif'), 'inx' => array('', '', 'extidd'), 'idml' => array('', '', 'extidd'), 'icml' => array('', '', 'extidd'), 'xtg' => array('', '', 'extqxp'), 'tag' => array('', '', 'exttag'), 'xml' => array('', '', 'extxml'), 'dita' => array('', '', 'extdit')), "Localization" => array('properties' => array('', '', 'extpro'), 'rc' => array('', '', 'extrcc'), 'resx' => array('', '', 'extres'), 'xml' => array('', '', 'extxml'), 'dita' => array('', '', 'extdit'), 'sgm' => array('', '', 'extsgm'), 'sgml' => array('', '', 'extsgm'), 'Android xml' => array('', '', 'extxml'), 'strings' => array('', '', 'extstr')));
     self::$UNSUPPORTED_FILE_TYPES = array('fm' => array('', "Try converting to MIF"), 'indd' => array('', "Try converting to INX"));
     /**
      * If you don't have a client id and client secret, please visit
      * Google Developers Console (https://console.developers.google.com/)
      * and follow these instructions:
      * - click "Create Project" button and specify project name
      * - In the sidebar on the left, select APIs & auth.
      * - In the displayed list of APIs, make sure "Google+ API" show a status of ON. If it doesn't, enable it.
      * - In the sidebar on the left, select "Credentials" under "APIs & auth" menu.
      * - Click "Create new client ID" button
      * - under APPLICATION TYPE, select "web application" option
      * - under AUTHORIZED JAVASCRIPT ORIGINS, insert the domain on which you installed MateCat
      * - under REDIRECT URIs, insert "http://<domain>/oauth/response" , where <domain> is the same that you specified in the previous step
      * - click "Create client ID"
      * Your client ID and client secret are now available.
      *
      * Edit the file inc/oauth_config.ini.sample with the right parameters obtained in the previous step of this guide.
      * set:
      * OAUTH_CLIENT_ID with your client ID
      * OAUTH_CLIENT_SECRET with your client secret
      * OAUTH_CLIENT_APP_NAME with your custom app name, if you want, or leave Matecat
      *
      * save and rename to oauth_config.ini file.
      *
      * Done!
      */
     self::$OAUTH_CLIENT_ID = self::$OAUTH_CONFIG['OAUTH_CLIENT_ID'];
     self::$OAUTH_CLIENT_SECRET = self::$OAUTH_CONFIG['OAUTH_CLIENT_SECRET'];
     self::$OAUTH_CLIENT_APP_NAME = self::$OAUTH_CONFIG['OAUTH_CLIENT_APP_NAME'];
     self::$OAUTH_REDIRECT_URL = self::$HTTPHOST . "/oauth/response";
     self::$OAUTH_SCOPES = array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile');
     self::$CONFIG_VERSION_ERR_MESSAGE = "Your config.inc.php file is not up-to-date.";
 }
Example #2
0
 private function __construct()
 {
     self::$CONFIG = parse_ini_file('config.ini', true);
     self::$_ROOT = realpath(dirname(__FILE__) . '/../');
     $OAUTH_CONFIG = parse_ini_file(realpath(dirname(__FILE__) . '/oauth_config.ini'), true);
     register_shutdown_function('Bootstrap::fatalErrorHandler');
     $mv = parse_ini_file('version.ini');
     self::$_INI_VERSION = $mv['version'];
     $this->_setIncludePath();
     spl_autoload_register('Bootstrap::loadClass');
     require_once 'Predis/autoload.php';
     if (stripos(PHP_SAPI, 'cli') === false) {
         register_shutdown_function('Bootstrap::sessionClose');
         INIT::$PROTOCOL = isset($_SERVER['HTTPS']) ? "https" : "http";
         INIT::$HTTPHOST = INIT::$PROTOCOL . "://" . $_SERVER['HTTP_HOST'];
     } else {
         if (INIT::$DEBUG) {
             echo "\nPHP Running in CLI mode.\n\n";
         }
         //Possible CLI configurations. We definitly don't want sessions in our cron scripts
     }
     INIT::$OAUTH_CONFIG = $OAUTH_CONFIG['OAUTH_CONFIG'];
     INIT::obtain();
     INIT::$ROOT = self::$_ROOT;
     // Accesible by Apache/PHP
     INIT::$BASEURL = "/";
     // Accesible by the browser
     INIT::$TIME_TO_EDIT_ENABLED = false;
     INIT::$DEFAULT_NUM_RESULTS_FROM_TM = 3;
     INIT::$THRESHOLD_MATCH_TM_NOT_TO_SHOW = 50;
     //get the environment configuration
     self::getEnvConfig();
     INIT::$LOG_REPOSITORY = INIT::$STORAGE_DIR . "/log_archive";
     INIT::$UPLOAD_REPOSITORY = INIT::$STORAGE_DIR . "/upload";
     INIT::$FILES_REPOSITORY = INIT::$STORAGE_DIR . "/files_storage/files";
     INIT::$CACHE_REPOSITORY = INIT::$STORAGE_DIR . "/files_storage/cache";
     INIT::$CONVERSIONERRORS_REPOSITORY = INIT::$STORAGE_DIR . "/conversion_errors";
     INIT::$CONVERSIONERRORS_REPOSITORY_WEB = INIT::$BASEURL . "storage/conversion_errors";
     INIT::$TMP_DOWNLOAD = INIT::$STORAGE_DIR . "/tmp_download";
     INIT::$REFERENCE_REPOSITORY = INIT::$STORAGE_DIR . "/reference_files";
     INIT::$TEMPLATE_ROOT = INIT::$ROOT . "/lib/View";
     INIT::$MODEL_ROOT = INIT::$ROOT . '/lib/Model';
     INIT::$CONTROLLER_ROOT = INIT::$ROOT . '/lib/Controller';
     INIT::$UTILS_ROOT = INIT::$ROOT . '/lib/Utils';
     if (!is_dir(INIT::$STORAGE_DIR)) {
         mkdir(INIT::$STORAGE_DIR, 0755, true);
     }
     if (!is_dir(INIT::$LOG_REPOSITORY)) {
         mkdir(INIT::$LOG_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$UPLOAD_REPOSITORY)) {
         mkdir(INIT::$UPLOAD_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$FILES_REPOSITORY)) {
         mkdir(INIT::$FILES_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$CACHE_REPOSITORY)) {
         mkdir(INIT::$CACHE_REPOSITORY, 0755, true);
     }
     if (!is_dir(INIT::$CONVERSIONERRORS_REPOSITORY)) {
         mkdir(INIT::$CONVERSIONERRORS_REPOSITORY, 0755, true);
     }
     //auth sections
     INIT::$AUTHSECRET_PATH = INIT::$ROOT . '/inc/login_secret.dat';
     //if secret is set in file
     if (file_exists(INIT::$AUTHSECRET_PATH)) {
         //fetch it
         INIT::$AUTHSECRET = file_get_contents(INIT::$AUTHSECRET_PATH);
     } else {
         //try creating the file and the fetch it
         //generate pass
         $secret = self::generate_password(512);
         //put file
         file_put_contents(INIT::$AUTHSECRET_PATH, $secret);
         //if put succeed
         if (file_exists(INIT::$AUTHSECRET_PATH)) {
             //restrict permissions
             chmod(INIT::$AUTHSECRET_PATH, 0400);
         } else {
             //if couldn't create due to permissions, use default secret
             INIT::$AUTHSECRET = 'ScavengerOfHumanSorrow';
         }
     }
 }