Example #1
0
 protected function _createJobs(ArrayObject $projectStructure, $owner)
 {
     foreach ($projectStructure['target_language'] as $target) {
         //shorten languages and get payable rates
         $shortSourceLang = substr($projectStructure['source_language'], 0, 2);
         $shortTargetLang = substr($target, 0, 2);
         //get payable rates
         $projectStructure['payable_rates'] = Analysis_PayableRates::getPayableRates($shortSourceLang, $shortTargetLang);
         $query_min_max = "SELECT MIN( id ) AS job_first_segment , MAX( id ) AS job_last_segment\n                FROM segments WHERE id_file IN ( %s )";
         $string_file_list = implode(",", $projectStructure['file_id_list']->getArrayCopy());
         $last_segments_query = sprintf($query_min_max, $string_file_list);
         $rows = $this->dbHandler->fetch_array($last_segments_query);
         if (!$rows || count($rows) == 0) {
             Log::doLog("Segment Search: Failed Retrieve min_segment/max_segment for files ( {$string_file_list} ) - DB Error: " . var_export($this->dbHandler->get_error(), true) . " - \n");
             throw new Exception("Segment import - DB Error: " . var_export($this->dbHandler->get_error(), true), -5);
         }
         //IT IS EVERY TIME ONLY A LINE!! don't worry about a cycle
         $job_segments = $rows[0];
         $password = $this->_generatePassword();
         $tm_key = array();
         if (!empty($projectStructure['private_tm_key'])) {
             foreach ($projectStructure['private_tm_key'] as $tmKeyObj) {
                 $newTmKey = TmKeyManagement_TmKeyManagement::getTmKeyStructure();
                 $newTmKey->tm = true;
                 $newTmKey->glos = true;
                 $newTmKey->owner = true;
                 $newTmKey->name = $tmKeyObj['name'];
                 $newTmKey->key = $tmKeyObj['key'];
                 $newTmKey->r = $tmKeyObj['r'];
                 $newTmKey->w = $tmKeyObj['w'];
                 $tm_key[] = $newTmKey;
             }
             //TODO: change this: private tm key field should not be used
             //set private tm key string to the first tm_key for retro-compatibility
             Log::doLog($projectStructure['private_tm_key']);
             //                $projectStructure[ 'private_tm_key' ] = $projectStructure[ 'private_tm_key' ][ 0 ][ 'key' ];
         }
         $projectStructure['tm_keys'] = json_encode($tm_key);
         $jid = insertJob($projectStructure, $password, $target, $job_segments, $owner);
         $projectStructure['array_jobs']['job_list']->append($jid);
         $projectStructure['array_jobs']['job_pass']->append($password);
         $projectStructure['array_jobs']['job_segments']->offsetSet($jid . "-" . $password, $job_segments);
         foreach ($projectStructure['file_id_list'] as $fid) {
             try {
                 //prepare pre-translated segments queries
                 if (!empty($projectStructure['translations'])) {
                     $this->_insertPreTranslations($jid);
                 }
             } catch (Exception $e) {
                 $msg = "\n\n Error, pre-translations lost, project should be re-created. \n\n " . var_export($e->getMessage(), true);
                 Utils::sendErrMailReport($msg);
             }
             insertFilesJob($jid, $fid);
         }
     }
 }
 public function doAction()
 {
     if (empty($this->file_name)) {
         $this->result['errors'][] = array("code" => -1, "message" => "Missing file name.");
         return false;
     }
     $arFiles = explode(',', $this->file_name);
     $default_project_name = $arFiles[0];
     if (count($arFiles) > 1 && empty($this->project_name)) {
         $default_project_name = "MATECAT_PROJ-" . date("Ymdhi");
     }
     $intDir = INIT::$UPLOAD_ROOT . '/' . $_COOKIE['upload_session'];
     if (count($arFiles) > 0) {
         $xliff = simplexml_load_file($intDir . '/' . $arFiles[0]);
         $src_lang = (string) $xliff->file['source-language'];
         if (!empty($src_lang) && empty($this->source_language)) {
             $this->source_language = $src_lang;
         }
         $tgt_lang = (string) $xliff->file['target-language'];
         if (!empty($tgt_lang) && empty($this->target_language)) {
             $this->target_language = $tgt_lang;
         }
     }
     if (empty($this->project_name)) {
         $this->project_name = $default_project_name;
         //'NO_NAME'.$this->create_project_name();
     }
     if (empty($this->source_language)) {
         $this->result['errors'][] = array("code" => -3, "message" => "Missing source language.");
         return false;
     }
     if (empty($this->target_language)) {
         $this->result['errors'][] = array("code" => -4, "message" => "Missing target language.");
         return false;
     }
     if (empty($this->tms_engine)) {
         $this->tms_engine = 1;
         // default MyMemory
     }
     // add her the cookie mangement for remembere the last 3 choosed languages
     // project name sanitize
     $this->project_name = preg_replace('/["\' \\(\\)\\[\\]\\{\\}\\+\\*]/', "_", $this->project_name);
     $this->project_name = preg_replace('/[_]{2,}/', "_", $this->project_name);
     $this->project_name = STR_replace('_.', ".", $this->project_name);
     //echo $this->project_name;
     // project name validation
     $pattern = "/^[\\p{L}\\ 0-9a-zA-Z_\\.\\-]+\$/";
     if (!preg_match($pattern, $this->project_name)) {
         $this->result['errors'][] = array("code" => -5, "message" => "Invalid Project Name {$this->project_name}: it should only contain numbers and letters!");
         //	        $this->result['project_name_error'] = $this->project_name;
         return false;
     }
     // create project
     $pid = insertProject('translated_user', $this->project_name);
     //create job
     $password = $this->create_password();
     $jid = insertJob($password, $pid, '', $this->source_language, $this->target_language, $this->mt_engine, $this->tms_engine);
     foreach ($arFiles as $file) {
         $filename = $intDir . '/' . $file;
         if (file_exists($filename)) {
         } else {
             $this->result['errors'][] = array("code" => -6, "message" => "File not found on server after upload.");
         }
         $handle = fopen($filename, "r");
         $contents = fread($handle, filesize($filename));
         fclose($handle);
         $fileSplit = explode('.', $file);
         $mimeType = $fileSplit[count($fileSplit) - 1];
         $fid = insertFile($pid, $file, $this->source_language, $mimeType, $contents);
         insertFilesJob($jid, $fid);
         $insertSegments = extractSegments($intDir, $file, $pid, $fid, $jid);
     }
     $this->deleteDir($intDir);
     if ($insertSegments) {
         $this->result['code'] = 1;
         $this->result['data'] = "OK";
         $this->result['password'] = $password;
         $this->result['id_job'] = $jid;
         $this->result['project_name'] = $this->project_name;
         $this->result['source_language'] = $this->source_language;
         $this->result['target_language'] = $this->target_language;
     } else {
         $this->result['errors'][] = array("code" => -7, "message" => "Not able to import this XLIFF file. ({$file})");
     }
     setcookie("upload_session", "", time() - 10000);
 }
Example #3
0
        $request = "http://api.indeed.com/ads/apisearch?publisher=3412350861593575&q=&l=" . $city . "%2C+va&sort=&radius=0&st=&jt=&start=" . $start . "&limit=&fromage=&filter=&latlong=&co=us&chnl=&userip=1.2.3.4&useragent=Mozilla/%2F4.0%28Firefox%29&v=2";
        $curl = curl_init($request);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $xml = new SimpleXMLElement(curl_exec($curl));
        curl_close($curl);
        for ($i = 0; $i < $xml->end - $xml->start + 1; $i++) {
            /**
             * Prevents processes listings for places like 'Fort Belvoir' when we are
             * actually looking for 'Belvoir'
             */
            if ($xml->results->result[$i]->city == $city) {
                /**
                 * Individual listing processing
                 */
                $city_id = $id;
                insertJob($stmt, $xml, $i, $title, $company, $description, $city_id, $county_id, $state_id, $date_posted);
            }
        }
        $start += 10;
        /**
         * Indeed only returns 10 listings per requests so this makes the script
         * retrieve the next 10 listings for the same city until all of them have
         * been processed
         */
    } while (intval($xml->totalresults) > intval($xml->end));
}
$stmt->close();
$conn->close();
function insertJob($stmt, $xml, $i, &$title, &$company, &$description, $city_id, $county_id, $state_id, &$date_posted)
{
    $title = $xml->results->result[$i]->jobtitle;
Example #4
0
 print "src_language: " . $src_lang . "\n";
 //create project
 $pid = insertProject('translated_user', "uploadFile");
 print "project: " . $pid . "\n";
 //create pass
 $length = 8;
 // Random
 $pool = "abcdefghkmnpqrstuvwxyz23456789";
 // skipping iljo01 because not easy to distinguish
 $pool_lenght = strlen($pool);
 $pwd = "";
 for ($index = 0; $index < $length; $index++) {
     $pwd .= substr($pool, rand() % $pool_lenght, 1);
 }
 //create job and file
 $jid = insertJob($pwd, $pid, '', $xml->Languages->attributes()->source, $xml->Languages->attributes()->target, '', '');
 $fid = insertFile($pid, $fileName, $xml->Languages->attributes()->source, 'xml', 'uploaded');
 insertFilesJob($jid, $fid);
 print "job_id: " . $jid . "\n";
 print "file_id: " . $fid . "\n";
 //get translations
 $initials = [];
 $count = 0;
 //initial translations
 for ($i = 0; $i < count($xml->initialTargetText->children()); $i++) {
     $id = $xml->initialTargetText->segment[$i]->attributes()->id;
     $suggestion = $xml->initialTargetText->segment[$i];
     $initials[$count] = [$id, $suggestion];
     $count = $count + 1;
 }
 $translations = [];