public function __construct() { parent::__construct(false); parent::makeTemplate("upload.html"); $this->guid = Utils::create_guid(); $this->lang_handler = Langs_Languages::getInstance(); $this->subject_handler = Langs_LanguageDomains::getInstance(); $this->subjectArray = $this->subject_handler->getEnabledDomains(); }
public function __construct() { parent::__construct(false); parent::makeTemplate("upload.html"); $filterArgs = array('project_name' => array('filter' => FILTER_SANITIZE_STRING), 'private_tm_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH)); $__postInput = filter_input_array(INPUT_GET, $filterArgs); $this->project_name = $__postInput["project_name"]; $this->private_tm_key = $__postInput["private_tm_key"]; $this->guid = Utils::create_guid(); $this->lang_handler = Langs_Languages::getInstance(); $this->subject_handler = Langs_LanguageDomains::getInstance(); $this->subjectArray = $this->subject_handler->getEnabledDomains(); }
private function __construct() { //get languages file // // SDL supported language codes // http://kb.sdl.com/kb/?ArticleId=2993&source=Article&c=12&cid=23#tab:homeTab:crumb:7:artId:4878 $file = INIT::$UTILS_ROOT . '/Langs/languageDomains.json'; if (!file_exists($file)) { log::doLog("no subject defs found in {$file}"); exit; } $string = file_get_contents($file); //parse to associative array $subjects = json_decode($string, true); Utils::raiseJsonExceptionError(); self::$subjectMap = $subjects; }
public function setTemplateVars() { $this->template->jobs = $this->jobs; $this->template->fast_analysis_wc = $this->fast_analysis_wc; $this->template->fast_analysis_wc_print = $this->fast_analysis_wc_print; $this->template->tm_analysis_wc = $this->tm_analysis_wc; $this->template->tm_analysis_wc_print = $this->tm_analysis_wc_print; $this->template->standard_analysis_wc = $this->standard_analysis_wc; $this->template->standard_analysis_wc_print = $this->standard_analysis_wc_print; $this->template->total_raw_word_count = $this->total_raw_word_count; $this->template->total_raw_word_count_print = $this->total_raw_word_count_print; $this->template->pname = $this->pname; $this->template->pid = $this->pid; $this->template->project_password = $this->ppassword; $this->template->project_not_found = $this->project_not_found; $this->template->fast_wc_time = $this->fast_wc_time; $this->template->tm_wc_time = $this->tm_wc_time; $this->template->tm_wc_unit = $this->tm_wc_unit; $this->template->fast_wc_unit = $this->fast_wc_unit; $this->template->standard_wc_unit = $this->standard_wc_unit; $this->template->raw_wc_time = $this->raw_wc_time; $this->template->standard_wc_time = $this->standard_wc_time; $this->template->raw_wc_unit = $this->raw_wc_unit; $this->template->project_status = $this->project_status; $this->template->num_segments = $this->num_segments; $this->template->num_segments_analyzed = $this->num_segments_analyzed; $this->template->logged_user = $this->logged_user !== false ? $this->logged_user->shortName() : ""; $this->template->extended_user = $this->logged_user !== false ? trim($this->logged_user->fullName()) : ""; $this->template->build_number = INIT::$BUILD_NUMBER; $this->template->enable_outsource = INIT::$ENABLE_OUTSOURCE; $this->template->outsource_service_login = $this->_outsource_login_API; $this->template->support_mail = INIT::$SUPPORT_MAIL; $langDomains = Langs_LanguageDomains::getInstance(); $this->subject = $langDomains::getDisplayDomain($this->subject); $this->template->subject = $this->subject; $this->template->isLoggedIn = $this->isLoggedIn(); if (isset($_SESSION['_anonym_pid']) && !empty($_SESSION['_anonym_pid'])) { $_SESSION['incomingUrl'] = INIT::$HTTPHOST . $_SERVER['REQUEST_URI']; $_SESSION['_newProject'] = 1; $this->template->showModalBoxLogin = true; } else { $this->template->showModalBoxLogin = false; } //url to which to send data in case of login $client = OauthClient::getInstance()->getClient(); $this->template->oauthFormUrl = $client->createAuthUrl(); $this->template->incomingUrl = '/login?incomingUrl=' . $_SERVER['REQUEST_URI']; //perform check on running daemons and send a mail randomly $misconfiguration = Analysis_Manager::thereIsAMisconfiguration(); if ($misconfiguration && mt_rand(1, 3) == 1) { $msg = "<strong>The analysis daemons seem not to be running despite server configuration.</strong><br />Change the application configuration or start analysis daemons."; Utils::sendErrMailReport($msg, "Matecat Misconfiguration"); } $this->template->daemon_misconfiguration = var_export($misconfiguration, true); }
public function __construct() { //limit execution time to 300 seconds set_time_limit(300); parent::__construct(); //force client to close connection, avoid UPLOAD_ERR_PARTIAL for keep-alive connections header("Connection: close"); $filterArgs = array('project_name' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW), 'source_lang' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW), 'target_lang' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW), 'tms_engine' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_SCALAR, 'options' => array('default' => 1, 'min_range' => 0)), 'mt_engine' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_SCALAR, 'options' => array('default' => 1, 'min_range' => 0)), 'private_tm_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW), 'subject' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'segmentation_rule' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'owner_email' => array('filter' => FILTER_VALIDATE_EMAIL)); $__postInput = filter_input_array(INPUT_POST, $filterArgs); if (!isset($__postInput['tms_engine']) || is_null($__postInput['tms_engine'])) { $__postInput['tms_engine'] = 1; } if (!isset($__postInput['mt_engine']) || is_null($__postInput['mt_engine'])) { $__postInput['mt_engine'] = 1; } foreach ($__postInput as $key => $val) { $__postInput[$key] = urldecode($val); } //NOTE: This is for debug purpose only, //NOTE: Global $_POST Overriding from CLI //$__postInput = filter_var_array( $_POST, $filterArgs ); $this->project_name = $__postInput['project_name']; $this->source_lang = $__postInput['source_lang']; $this->target_lang = $__postInput['target_lang']; $this->tms_engine = $__postInput['tms_engine']; // Default 1 MyMemory $this->mt_engine = $__postInput['mt_engine']; // Default 1 MyMemory $this->seg_rule = !empty($__postInput['segmentation_rule']) ? $__postInput['segmentation_rule'] : ''; $this->subject = !empty($__postInput['subject']) ? $__postInput['subject'] : 'general'; $this->owner = $__postInput['owner_email']; try { $this->private_tm_key = array_map('self::parseTmKeyInput', explode(",", $__postInput['private_tm_key'])); } catch (Exception $e) { $this->api_output['message'] = $e->getMessage(); $this->api_output['debug'] = $e->getMessage(); Log::doLog($e->getMessage()); return -6; } if ($this->owner === false) { $this->api_output['message'] = "Project Creation Failure"; $this->api_output['debug'] = "Email is not valid"; Log::doLog("Email is not valid"); return -5; } else { if (!is_null($this->owner) && !empty($this->owner)) { $domain = explode("@", $this->owner); $domain = $domain[1]; if (!checkdnsrr($domain)) { $this->api_output['message'] = "Project Creation Failure"; $this->api_output['debug'] = "Email is not valid"; Log::doLog("Email is not valid"); return -5; } } } try { $this->validateEngines(); } catch (Exception $ex) { $this->api_output['message'] = $ex->getMessage(); Log::doLog($ex->getMessage()); return -1; } if (count($this->private_tm_key) > self::MAX_NUM_KEYS) { $this->api_output['message'] = "Project Creation Failure"; $this->api_output['debug'] = "Too much keys provided. Max number of keys is " . self::MAX_NUM_KEYS; Log::doLog("Too much keys provided. Max number of keys is " . self::MAX_NUM_KEYS); return -2; } $langDomains = Langs_LanguageDomains::getInstance(); $subjectList = $langDomains::getEnabledDomains(); // In this list there is an item whose key is "----". // It is useful for UI purposes, but not here. So we unset it foreach ($subjectList as $idx => $subject) { if ($subject['key'] == '----') { unset($subjectList[$idx]); break; } } //Array_column() is not supported on PHP 5.4, so i'll rewrite it if (!function_exists('array_column')) { $subjectList = Utils::array_column($subjectList, 'key'); } else { $subjectList = array_column($subjectList, 'key'); } if (!in_array($this->subject, $subjectList)) { $this->api_output['message'] = "Project Creation Failure"; $this->api_output['debug'] = "Subject not allowed: " . $this->subject; Log::doLog("Subject not allowed: " . $this->subject); return -3; } if (!in_array($this->seg_rule, self::$allowed_seg_rules)) { $this->api_output['message'] = "Project Creation Failure"; $this->api_output['debug'] = "Segmentation rule not allowed: " . $this->seg_rule; Log::doLog("Segmentation rule not allowed: " . $this->seg_rule); return -4; } //normalize segmentation rule to what it's used internally if ($this->seg_rule == 'standard' || $this->seg_rule == '') { $this->seg_rule = null; } if (empty($_FILES)) { $this->result['errors'][] = array("code" => -1, "message" => "Missing file. Not Sent."); return -1; } $this->private_tm_key = array_values(array_filter($this->private_tm_key)); //If a TMX file has been uploaded and no key was provided, create a new key. if (empty($this->private_tm_key)) { foreach ($_FILES as $_fileinfo) { $pathinfo = FilesStorage::pathinfo_fix($_fileinfo['name']); if ($pathinfo['extension'] == 'tmx') { $this->private_tm_key[] = 'new'; break; } } } //remove all empty entries foreach ($this->private_tm_key as $__key_idx => $tm_key) { //from api a key is sent and the value is 'new' if ($tm_key['key'] == 'new') { try { $APIKeySrv = new TMSService(); $newUser = $APIKeySrv->createMyMemoryKey(); //TODO: i need to store an array of these $this->private_tm_user = $newUser->id; $this->private_tm_pass = $newUser->pass; $this->private_tm_key[$__key_idx] = array('key' => $newUser->key, 'name' => null, 'r' => $tm_key['r'], 'w' => $tm_key['w']); $this->new_keys[] = $newUser->key; } catch (Exception $e) { $this->api_output['message'] = 'Project Creation Failure'; $this->api_output['debug'] = array("code" => $e->getCode(), "message" => $e->getMessage()); return -1; } } else { if (!empty($tm_key)) { $this->private_tm_key[$__key_idx] = array('key' => $tm_key['key'], 'name' => null, 'r' => $tm_key['r'], 'w' => $tm_key['w']); } } $this->private_tm_key[$__key_idx] = array_filter($this->private_tm_key[$__key_idx], array("self", "sanitizeTmKeyArr")); } }