public function __construct()
 {
     $this->ROOT = realpath(dirname(__FILE__) . '/../../../');
     //imports
     require_once $this->ROOT . '/inc/config.inc.php';
     INIT::obtain();
     $this->db = Database::obtain(INIT::$DB_SERVER, INIT::$DB_USER, INIT::$DB_PASS, INIT::$DB_DATABASE);
     $this->db->connect();
     //init params
     $this->path = $this->ROOT . '/lib/Utils/converter_checker';
     $resultSet = $this->db->fetch_array(self::selectAllNotOffline);
     if (empty($resultSet)) {
         self::_prettyEcho("------------------------------------");
         self::_prettyEcho("************* WARNING **************");
         self::_prettyEcho("------------------------------------");
         $this->alertForEmptyPool();
         die(1);
     }
     foreach ($resultSet as $conv) {
         //            self::$ipLog = $conv[ 'ip_converter' ];
         $this->resultSet[$conv['ip_converter']] = $conv;
         $this->host_machine_map[$conv['ip_converter']] = array('ip_machine_host' => $conv['ip_machine_host'], 'machine_host_user' => $conv['machine_host_user'], 'machine_host_pass' => $conv['machine_host_pass'], 'instance_name' => $conv['instance_name']);
         //            self::_prettyEcho( "Retrieving Processes Info on " . $conv[ 'ip_converter' ] );
         //            $converter_json_top = self::getNodeProcessInfo( $conv[ 'ip_converter' ] );
         //            if ( !empty( $converter_json_top ) ) {
         //                $this->convertersTop[ $conv[ 'ip_converter' ] ] = array(
         //                    'converter_load'     => $converter_json_top[ 0 ],
         //                    'converter_json_top' => $converter_json_top[ 1 ]
         //                );
         //            }
     }
     $this->converterFactory = new FileFormatConverter();
 }
Example #2
0
 public function testEmptyConfiguration()
 {
     INIT::$MEMCACHE_SERVERS = array();
     MemcacheHandler::close();
     $this->setExpectedException('LogicException');
     /**
      * without INIT configuration
      */
     $x = MemcacheHandler::getInstance();
 }
Example #3
0
 /**
  * Class constructor
  *
  * There will be defined the callback urls for success or failure on login system
  *
  */
 public function __construct()
 {
     //SESSION ENABLED
     INIT::sessionStart();
     $this->currency = "EUR";
     $this->change_rate = 1;
     /**
      * @see OutsourceTo_AbstractProvider::$_outsource_login_url_ok
      */
     $this->_outsource_login_url_ok = INIT::$HTTPHOST . INIT::$BASEURL . "index.php?action=OutsourceTo_TranslatedSuccess";
     $this->_outsource_login_url_ko = INIT::$HTTPHOST . INIT::$BASEURL . "index.php?action=OutsourceTo_TranslatedError";
 }
Example #4
0
 public function setUp()
 {
     \INIT::$DEBUG = false;
     $this->_TMInstance = TaskManager::getInstance(null, __DIR__ . DIRECTORY_SEPARATOR . 'tm_config.ini');
     $this->_redisClient = new \RedisHandler();
     $this->_redisClient->getConnection()->set(RedisKeys::VOLUME_ANALYSIS_PID, 1224);
     for ($i = 0; $i < 30; $i++) {
         $this->_redisClient->getConnection()->sadd('ch_pid_set_p1', mt_rand(15, 20000));
         $this->_redisClient->getConnection()->sadd('ch_pid_set_p2', mt_rand(20001, 40000));
         $this->_redisClient->getConnection()->sadd('ch_pid_set_p3', mt_rand(40001, 65535));
     }
 }
 private function __construct()
 {
     // Read general config from INI file
     global $_INI_FILE;
     $root = realpath(dirname(__FILE__) . '/../');
     self::$ROOT = $root;
     // Accesible by Apache/PHP
     self::$BASE_URL = "/";
     set_include_path(get_include_path() . PATH_SEPARATOR . $root);
     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';
     self::$UPLOAD_ROOT = self::$ROOT . "/" . $_INI_FILE['ui']['uploads'];
     self::$ENABLED_BROWSERS = array('chrome', 'firefox', 'safari');
     self::$BUILD_NUMBER = '0.0.1';
 }
 public function __construct()
 {
     if (!class_exists("INIT")) {
         include_once "../../inc/config.inc.php";
         INIT::obtain();
     }
     $this->opt['httpheader'] = array("Content-Type:multipart/form-data;charset=UTF-8");
     $this->lang_handler = Langs_Languages::getInstance();
     $this->conversionObject = new ArrayObject(array('ip_machine' => null, 'ip_client' => null, 'path_name' => null, 'file_name' => null, 'path_backup' => null, 'file_size' => 0, 'direction' => null, 'error_message' => null, 'src_lang' => null, 'trg_lang' => null, 'status' => 'ok', 'conversion_time' => 0), ArrayObject::ARRAY_AS_PROPS);
     $db = Database::obtain();
     $converters = $db->fetch_array("SELECT ip_converter, cpu_weight, ip_storage, segmentation_rule FROM converters WHERE status_active = 1 AND status_offline = 0");
     foreach ($converters as $converter_storage) {
         self::$converters[$converter_storage['ip_converter']] = $converter_storage['cpu_weight'];
         self::$Storage_Lookup_IP_Map[$converter_storage['ip_converter']] = $converter_storage['ip_storage'];
         self::$converter2segmRule[$converter_storage['ip_converter']] = $converter_storage['segmentation_rule'];
     }
     //        self::$converters = array('10.11.0.98' => 1);//for debugging purposes
     //        self::$Storage_Lookup_IP_Map = array('10.11.0.98' => '10.11.0.99');//for debugging purposes
     $this->storage_lookup_map = self::$Storage_Lookup_IP_Map;
 }
Example #7
0
<?php

/**
 * User: domenico
 * Date: 09/10/13
 * Time: 15.21
 * 
 */
if (!class_exists('INIT', false)) {
    $root = realpath(dirname(__FILE__) . '/../../inc/');
    include $root . '/config.inc.php';
    INIT::obtain();
    set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../'));
}
abstract class Tests_AbstractTest extends PHPUnit_Framework_TestCase
{
    protected $thisTest;
    protected $reflectedClass;
    protected $reflectedMethod;
    public function setUp()
    {
        parent::setUp();
        $this->thisTest = microtime(true);
    }
    public function tearDown()
    {
        parent::tearDown();
        $resultTime = microtime(true) - $this->thisTest;
        echo " " . str_pad($this->getName(false), 35, " ", STR_PAD_RIGHT) . " - Did in " . $resultTime . " seconds.\n";
    }
}
 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 #9
0
 public function doAction()
 {
     $this->file_name = html_entity_decode($this->file_name, ENT_QUOTES);
     $file_path = $this->intDir . DIRECTORY_SEPARATOR . $this->file_name;
     if (!file_exists($file_path)) {
         $this->result['code'] = -6;
         // No Good, Default
         $this->result['errors'][] = array("code" => -6, "message" => "Error during upload. Please retry.", 'debug' => FilesStorage::basename_fix($this->file_name));
         return -1;
     }
     //XLIFF Conversion management
     //cyclomatic complexity 9999999 ..... but it works, for now.
     try {
         $fileType = DetectProprietaryXliff::getInfo($file_path);
         if (DetectProprietaryXliff::isXliffExtension() || DetectProprietaryXliff::getMemoryFileType()) {
             if (INIT::$CONVERSION_ENABLED) {
                 //conversion enforce
                 if (!INIT::$FORCE_XLIFF_CONVERSION) {
                     //if file is not proprietary AND Enforce is disabled
                     //we take it as is
                     if (!$fileType['proprietary'] || DetectProprietaryXliff::getMemoryFileType()) {
                         $this->result['code'] = 1;
                         // OK for client
                         //This file has to be linked to cache!
                         return 0;
                         //ok don't convert a standard sdlxliff
                     }
                 } else {
                     // if conversion enforce is active
                     // we force all xliff files but not files produced by
                     // SDL Studio or by the MateCAT converters, because we
                     // can handle them
                     if ($fileType['proprietary_short_name'] == 'matecat_converter' || $fileType['proprietary_short_name'] == 'trados' || DetectProprietaryXliff::getMemoryFileType()) {
                         $this->result['code'] = 1;
                         // OK for client
                         $this->result['errors'][] = array("code" => 0, "message" => "OK");
                         return 0;
                         //ok don't convert a standard sdlxliff
                     }
                 }
             } elseif ($fileType['proprietary']) {
                 unlink($file_path);
                 $this->result['code'] = -7;
                 // No Good, Default
                 $this->result['errors'][] = array("code" => -7, "message" => 'Matecat Open-Source does not support ' . ucwords($fileType['proprietary_name']) . '. Use MatecatPro.', 'debug' => FilesStorage::basename_fix($this->file_name));
                 return -1;
             } elseif (!$fileType['proprietary']) {
                 $this->result['code'] = 1;
                 // OK for client
                 $this->result['errors'][] = array("code" => 0, "message" => "OK");
                 return 0;
                 //ok don't convert a standard sdlxliff
             }
         }
     } catch (Exception $e) {
         //try catch not used because of exception no more raised
         $this->result['code'] = -8;
         // No Good, Default
         $this->result['errors'][] = array("code" => -8, "message" => $e->getMessage());
         Log::doLog($e->getMessage());
         return -1;
     }
     //compute hash to locate the file in the cache
     $sha1 = sha1_file($file_path);
     //initialize path variable
     $cachedXliffPath = false;
     //get storage object
     $fs = new FilesStorage();
     //TODO: REMOVE SET ENVIRONMENT FOR LEGACY CONVERSION INSTANCES
     if (INIT::$LEGACY_CONVERSION !== false) {
         INIT::$SAVE_SHASUM_FOR_FILES_LOADED = false;
     }
     //if already present in database cache get the converted without convert it again
     if (INIT::$SAVE_SHASUM_FOR_FILES_LOADED) {
         //move the file in the right directory from the packages to the file dir
         $cachedXliffPath = $fs->getXliffFromCache($sha1, $this->source_lang);
         if (!$cachedXliffPath) {
             Log::doLog("Failed to fetch xliff for {$sha1} from disk cache (is file there?)");
         }
     }
     //if invalid or no cached version
     if (!isset($cachedXliffPath) or empty($cachedXliffPath)) {
         //we have to convert it
         // By default, use always the new converters...
         $converterVersion = Constants_ConvertersVersions::LATEST;
         if ($this->segmentation_rule !== null) {
             // ...but new converters don't support custom segmentation rules.
             // if $this->segmentation_rule is set use the old ones.
             $converterVersion = Constants_ConvertersVersions::LEGACY;
         }
         //TODO: REMOVE SET ENVIRONMENT FOR LEGACY CONVERSION INSTANCES
         if (INIT::$LEGACY_CONVERSION !== false) {
             $converterVersion = Constants_ConvertersVersions::LEGACY;
         }
         $converter = new FileFormatConverter($converterVersion);
         if (strpos($this->target_lang, ',') !== false) {
             $single_language = explode(',', $this->target_lang);
             $single_language = $single_language[0];
         } else {
             $single_language = $this->target_lang;
         }
         $convertResult = $converter->convertToSdlxliff($file_path, $this->source_lang, $single_language, false, $this->segmentation_rule);
         if ($convertResult['isSuccess'] == 1) {
             /* try to back convert the file */
             $output_content = array();
             $output_content['out_xliff_name'] = $file_path . '.out.sdlxliff';
             $output_content['source'] = $this->source_lang;
             $output_content['target'] = $single_language;
             $output_content['content'] = $convertResult['xliffContent'];
             $output_content['filename'] = $this->file_name;
             $back_convertResult = $converter->convertToOriginal($output_content);
             /* try to back convert the file */
             if ($back_convertResult['isSuccess'] == false) {
                 //custom error message passed directly to javascript client and displayed as is
                 $convertResult['errorMessage'] = "Error: there is a problem with this file, it cannot be converted back to the original one.";
                 $this->result['code'] = -110;
                 $this->result['errors'][] = array("code" => -110, "message" => $convertResult['errorMessage'], 'debug' => FilesStorage::basename_fix($this->file_name));
                 return false;
             }
             //store converted content on a temporary path on disk (and off RAM)
             $cachedXliffPath = tempnam("/tmp", "MAT_XLF");
             file_put_contents($cachedXliffPath, $convertResult['xliffContent']);
             unset($convertResult['xliffContent']);
             /*
               store the converted file in the cache
               put a reference in the upload dir to the cache dir, so that from the UUID we can reach the converted file in the cache
               (this is independent by the "save xliff for caching" options, since we always end up storing original and xliff on disk)
             */
             //save in cache
             $res_insert = $fs->makeCachePackage($sha1, $this->source_lang, $file_path, $cachedXliffPath);
             if (!$res_insert) {
                 //custom error message passed directly to javascript client and displayed as is
                 $convertResult['errorMessage'] = "Error: File upload failed because you have MateCat running in multiple tabs. Please close all other MateCat tabs in your browser.";
                 $this->result['code'] = -103;
                 $this->result['errors'][] = array("code" => -103, "message" => $convertResult['errorMessage'], 'debug' => FilesStorage::basename_fix($this->file_name));
                 unset($cachedXliffPath);
                 return false;
             }
         } else {
             $file = FilesStorage::pathinfo_fix($this->file_name);
             switch ($file['extension']) {
                 case 'docx':
                     $defaultError = "Importing error. Try opening and saving the document with a new name. If this does not work, try converting to DOC.";
                     break;
                 case 'doc':
                 case 'rtf':
                     $defaultError = "Importing error. Try opening and saving the document with a new name. If this does not work, try converting to DOCX.";
                     break;
                 case 'inx':
                     $defaultError = "Importing Error. Try to commit changes in InDesign before importing.";
                     break;
                 case 'idml':
                     $defaultError = "Importing Error. MateCat does not support this version of InDesign, try converting it to a previous one.";
                     break;
                 default:
                     $defaultError = "Importing error. Try opening and saving the document with a new name.";
                     break;
             }
             if (stripos($convertResult['errorMessage'], "failed to create SDLXLIFF.") !== false || stripos($convertResult['errorMessage'], "COM target does not implement IDispatch") !== false) {
                 $convertResult['errorMessage'] = "Error: failed importing file.";
             } elseif (stripos($convertResult['errorMessage'], "Unable to open Excel file - it may be password protected") !== false) {
                 $convertResult['errorMessage'] = $convertResult['errorMessage'] . " Try to remove protection using the Unprotect Sheet command on Windows Excel.";
             } elseif (stripos($convertResult['errorMessage'], "The document contains unaccepted changes") !== false) {
                 $convertResult['errorMessage'] = "The document contains track changes. Accept all changes before uploading it.";
             } elseif (stripos($convertResult['errorMessage'], "Error: Could not find file") !== false || stripos($convertResult['errorMessage'], "tw4winMark") !== false) {
                 $convertResult['errorMessage'] = $defaultError;
             } elseif (stripos($convertResult['errorMessage'], "Attempted to read or write protected memory") !== false) {
                 $convertResult['errorMessage'] = $defaultError;
             } elseif (stripos($convertResult['errorMessage'], "The document was created in Microsoft Word 97 or earlier")) {
                 $convertResult['errorMessage'] = $defaultError;
             } elseif ($file['extension'] == 'csv' && empty($convertResult['errorMessage'])) {
                 $convertResult['errorMessage'] = "This CSV file is not eligible to be imported due internal wrong format. Try to convert in TXT using UTF8 encoding";
             } elseif (empty($convertResult['errorMessage'])) {
                 $convertResult['errorMessage'] = "Failed to convert file. Internal error. Please Try again.";
             } elseif (stripos($convertResult['errorMessage'], "DocumentFormat.OpenXml.dll") !== false) {
                 //this error is triggered on DOCX when converter's parser can't decode some regions of the file
                 $convertResult['errorMessage'] = "Conversion error. Try opening and saving the document with a new name. If this does not work, try converting to DOC.";
             } elseif ($file['extension'] == 'idml') {
                 $convertResult['errorMessage'] = $defaultError;
             } elseif (stripos($convertResult['errorMessage'], "Error: The source language of the file") !== false) {
                 //Error: The source language of the file (English (United States)) is different from the project source language.
                 //we take the error, is good
             } else {
                 $convertResult['errorMessage'] = "Import error. Try converting it to a compatible file format (e.g. doc > docx, xlsx > xls)";
             }
             //custom error message passed directly to javascript client and displayed as is
             $this->result['code'] = -100;
             $this->result['errors'][] = array("code" => -100, "message" => $convertResult['errorMessage'], "debug" => $file['basename']);
         }
     }
     //if everything went well and we've obtained a path toward a valid package (original+xliff), either via cache or conversion
     if (isset($cachedXliffPath) and !empty($cachedXliffPath)) {
         //FILE Found in cache, destroy the already present shasum for other languages ( if user swapped languages )
         $uploadDir = INIT::$UPLOAD_REPOSITORY . DIRECTORY_SEPARATOR . $this->cookieDir;
         $fs->deleteHashFromUploadDir($uploadDir, $sha1 . "|" . $this->source_lang);
         //put reference to cache in upload dir to link cache to session
         $fs->linkSessionToCache($sha1, $this->source_lang, $this->cookieDir, FilesStorage::basename_fix($file_path));
         //a usable package is available, give positive feedback
         $this->result['code'] = 1;
     }
     return 0;
 }
Example #10
0
 /**
  * This function is meant to check for a wrong configuration of the filesystems either
  * in development and production environment.
  *
  * We use this function in that phase of development, planning to remove it in the future.
  *
  * If you don't need this check set the defined CHECK_FS to false
  *
  */
 public static function getEnvConfig()
 {
     $env = self::$CONFIG[self::$CONFIG['ENV']];
     INIT::$BUILD_NUMBER = self::$CONFIG['BUILD_NUMBER'];
     foreach ($env as $KEY => $value) {
         if (property_exists('INIT', $KEY)) {
             INIT::${$KEY} = $value;
         }
     }
     $fileSystem = trim(shell_exec("df -T " . escapeshellcmd(INIT::$STORAGE_DIR) . "/files_storage/ | awk '{print \$2 }' | sed -n 2p"));
     if (self::$CONFIG['ENV'] == 'production') {
         if (stripos($fileSystem, 'nfs') === false && self::$CONFIG['CHECK_FS']) {
             die('Wrong Configuration! You must mount your remote filesystem to the production or change the storage directory.');
         }
     } else {
         if (stripos($fileSystem, 'nfs') !== false && self::$CONFIG['CHECK_FS']) {
             die('Wrong Configuration! You must un-mount your remote filesystem or change the local directory.');
         }
     }
 }
 public function setTemplateVars()
 {
     INIT::$CONVERSION_ENABLED = false;
     $this->template->basepath = "/";
     parent::setTemplateVars();
 }
Example #12
0
 public function __construct()
 {
     self::$OAUTH_CLIENT_ID = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_ID'];
     self::$OAUTH_CLIENT_SECRET = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_SECRET'];
     self::$OAUTH_CLIENT_APP_NAME = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_APP_NAME'];
     self::$OAUTH_REDIRECT_URL = INIT::$HTTPHOST . "/oauth/response";
     self::$OAUTH_SCOPES = array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile');
 }
Example #13
0
 public function __construct()
 {
     self::$OAUTH_CLIENT_ID = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_ID'];
     self::$OAUTH_CLIENT_SECRET = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_SECRET'];
     self::$OAUTH_CLIENT_APP_NAME = INIT::$OAUTH_CONFIG['OAUTH_CLIENT_APP_NAME'];
     self::$OAUTH_REDIRECT_URL = INIT::$HTTPHOST . "/oauth/response";
     self::$OAUTH_SCOPES = array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile');
     //TODO: REMOVE SET ENVIRONMENT FOR LEGACY CONVERSION INSTANCES
     if (getenv('LEGACY_CONVERSION') !== false) {
         self::$LEGACY_CONVERSION = true;
     }
     if (getenv('UNLOCKABLE_TAGS') !== false) {
         self::$UNLOCKABLE_TAGS = true;
     }
 }
Example #14
0
 /**
  * Explicitly disable sessions for ajax call
  *
  * Sessions enabled on INIT Class
  *
  */
 public function disableSessions()
 {
     INIT::sessionClose();
 }
Example #15
0
 private function __construct()
 {
     // Read general config from INI file
     global $_INI_FILE;
     $root = realpath(dirname(__FILE__) . '/../');
     self::$ROOT = $root;
     // Accesible by Apache/PHP
     self::$BASE_URL = $_INI_FILE['ui']['baseurl'];
     // Accesible by the browser
     set_include_path(get_include_path() . PATH_SEPARATOR . $root);
     self::$TIME_TO_EDIT_ENABLED = self::getConfigBool('timetoedit', 'ui');
     self::$DEFAULT_NUM_RESULTS_FROM_TM = $_INI_FILE['mymemory']['numresults'];
     self::$THRESHOLD_MATCH_TM_NOT_TO_SHOW = $_INI_FILE['mymemory']['matchthreshold'];
     self::$DB_SERVER = $_INI_FILE['db']['hostname'];
     self::$DB_DATABASE = $_INI_FILE['db']['database'];
     self::$DB_USER = $_INI_FILE['db']['username'];
     self::$DB_PASS = $_INI_FILE['db']['password'];
     self::$LOG_ENABLED = self::getConfigBool('logenabled', 'ui');
     self::$LOG_MAXCHUNKSIZE = isset($_INI_FILE['ui']['logmaxchunksize']) ? $_INI_FILE['ui']['logmaxchunksize'] : 3000;
     self::$LOG_REPOSITORY = self::$ROOT . "/" . $_INI_FILE['log']['directory'];
     self::$LOG_FILENAME = $_INI_FILE['log']['filename'];
     //log download
     self::$LOG_DOWNLOAD = self::$ROOT . "/" . $_INI_FILE['download_temp']['directory'];
     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';
     self::$UPLOAD_ROOT = self::$ROOT . "/" . $_INI_FILE['ui']['uploads'];
     self::$ENABLED_BROWSERS = array('chrome', 'firefox', 'safari');
     self::$BUILD_NUMBER = '0.3.0';
     // Casmacat customizations
     self::$ITP_SERVER = self::getConfig('itpserver');
     self::$HTR_SERVER = self::getConfig('htrserver');
     self::$BICONCOR_SERVER = self::getConfig('biconcorserver');
     self::$SOURCE_LANGUAGE = self::getConfig('sourcelanguage');
     self::$TARGET_LANGUAGE = self::getConfig('targetlanguage');
     self::$ITP_ENABLED = self::getConfigBool('itpenabled');
     self::$PEN_ENABLED = self::getConfigBool('penenabled');
     self::$ET_ENABLED = self::getConfigBool('etenabled');
     self::$SR_ENABLED = self::getConfigBool('srenabled');
     self::$BICONCOR_ENABLED = self::getConfigBool('biconcorenabled');
     self::$HIDE_CONTRIBUTIONS = self::getConfigBool('hidecontributions');
     self::$FLOAT_PREDICTIONS = self::getConfigBool('floatpredictions');
     self::$TRANSLATION_OPTIONS = self::getConfigBool('translationoptions');
     self::$ALLOW_CHANGE_VISUALIZATION_OPTIONS = self::getConfigBool('allowchangevisualizationoptions');
     self::$ITP_DRAFT_ONLY = self::getConfigBool('itpdraftonly');
     self::$ET_TYPE = self::getConfig('ettype', "casmacat", 0);
     self::$DEBUG = self::getConfigBool('debug', "debug");
 }