Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function formModifications_menu() {
- $items['translate/bulk'] = array(
- 'title' => t('Send Multiple Contents'),
- 'description' => t('Translate multiple nodes'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('formModifications_translate_bulk'),
- 'access arguments' => array('access translator'),
- );
- return $items;
- }
- function formModifications_translate_bulk(){
- // Get the nodes.
- $chosenContents = "Contents Chosen :";
- $nodes_ser = trim($_GET['nodes']);
- $nodes = explode("-",$nodes_ser);
- $form = array();
- foreach( $nodes as $key => $value){
- $node = node_load($value);
- //print_r($node->title);
- $chosenContents .= $node->title." , ";
- }
- $form['content_information'] = array(
- '#value' => variable_get('content_form_information', $chosenContents),
- );
- $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace"=>1));
- $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace"=>1));
- try{
- $arrResponse = $LoginClient->Logon(array ('Username'=>'dmitry.testuser','Password'=>'I8it4lunch'));
- $ticket = ($arrResponse->LogonResult);
- $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket'=>$ticket));
- $getDraftProjectIds = $ServicesLink->GetProjectSummariesList(array('Ticket'=>$ticket,'NumberOfProjects'=>100,'SortOrder'=>MostRecent,'ProjectStatusCode'=>'Draft'));
- $array = array();
- $forTarLang = array();
- $listOfProjects = array();
- foreach($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language)
- {
- $array[$language->ID] = $language->Description;
- $forTarLang[] = $language->ID;
- }
- for($i =0; $i <count($forTarLang);$i+=1)
- {
- print_r($forTarLang[i]);
- }
- foreach($getDraftProjectIds->GetProjectSummariesListResult->ProjectSummaries->ProjectSummary as $projectSummary)
- {
- $listOfProjects[$projectSummary->ID] = $projectSummary-> ID;
- }
- //$getTarLang = $AddFile->GetTargetLanguages(array('Ticket'=>$ticket,));
- $tarLang = array();
- }
- catch (SoapFault $exception){
- return $exception;
- }
- $form['folks_list']=array(
- '#type'=>'select',
- '#title' => t('Freeway Source Languages'),
- //'#default_value' => array('1'=>'Joe'),
- '#options' => $array,
- //'#multiple' => false,
- //'#attributes'=>array('size'=>4, 'class' => 'select_folks_list'),
- '#weight'=>7,
- );
- // listbox for target language.
- $form['targetLang_list']=array(
- '#type'=>'select',
- '#title' => t('Freeway Target Languages'),
- '#options' => $array,
- '#multiple' => false,
- '#attributes'=>array('size'=>4, 'class' => 'select_folks_list'),
- '#weight'=>8,
- );
- $form['projectId'] = array(
- '#type' => 'select',
- '#title' => t('List of Draft projects created by you.'),
- '#weight'=>9,
- '#options' => $listOfProjects,
- );
- return $form;
- }
- function formModifications_form_alter(&$form,&$form_state,$form_id){
- if ($form_id == 'node_admin_content') {
- $form['admin']['options']['operation']['#options']['send_for_translation'] = t('Send For Translation');
- $form['admin']['options']['submit']['#submit'][] = 'custom_send_for_translation_submit_admin';
- }
- }
- function custom_send_for_translation_submit_admin($form, &$form_state) {
- $zipName = "Content";
- $nodes = array();
- foreach ($form_state['values']['nodes'] as $key => $value)
- {
- if ($value != 0) {
- $selected[] = node_load($key);
- }
- }
- foreach ($selected as $key => $value ){
- $structure = './sites/all/tempfolder/';
- if(!is_dir($structure))
- {
- mkdir($structure, 0, true);
- }
- $fileName = $value->title;
- $sPattern = '/\s*/m';
- $sReplace = '';
- $refinedFileName = preg_replace( $sPattern, $sReplace, $fileName ).".xml";
- $finalRefinedFileName = $structure.$refinedFileName;
- $ourFileHandle = fopen($finalRefinedFileName, 'w') or die("can't open file");
- $stringXmlHead = '<?xml version="1.0"?>'."\r\n";
- fwrite($ourFileHandle, $stringXmlHead);
- $rootNode = "<DrupalConnector>"."\r\n";
- fwrite($ourFileHandle, $rootNode);
- $nodeIdTagStart = "<NodeId>";
- fwrite($ourFileHandle, $nodeIdTagStart);
- $nodeId = $value->nid;
- fwrite($ourFileHandle, $nodeId);
- $nodeIdTagEnd = "</NodeId>"."\r\n";
- fwrite($ourFileHandle, $nodeIdTagEnd);
- $nodeTitleTagStart = "<NodeTitle>";
- fwrite($ourFileHandle, $nodeTitleTagStart);
- $nodeTitle = "<![CDATA[".$value->title."]]>";
- fwrite($ourFileHandle, $nodeTitle);
- $nodeTitleTagEnd = "</NodeTitle>"."\r\n";
- fwrite($ourFileHandle, $nodeTitleTagEnd);
- $nodeBodyTagStart = "<NodeBody>";
- fwrite($ourFileHandle, $nodeBodyTagStart);
- $nodeBody = "<![CDATA[".$value->body."]]>";
- fwrite($ourFileHandle, $nodeBody);
- $nodeBodyTagEnd = "</NodeBody>"."\r\n";
- fwrite($ourFileHandle, $nodeBodyTagEnd);
- $rootNodeEnd = "</DrupalConnector>"."\r\n";
- fwrite($ourFileHandle, $rootNodeEnd);
- $zipName.= "_".$nodeId;
- $nodes []= $value->nid;
- }
- fclose($ourFileHandle);
- $finalZipName = $zipName.".zip";
- Zip('./sites/all/tempfolder','./'.$finalZipName);
- //zipping done
- $nodes_ser = implode('-', $nodes);
- drupal_goto('translate/bulk', 'nodes='. $nodes_ser);
- }
- function Zip($source, $destination)
- {
- if (!extension_loaded('zip') || !file_exists($source))
- {
- return false;
- }
- $zip = new ZipArchive();
- if (!$zip->open($destination, ZIPARCHIVE::CREATE))
- {
- return false;
- }
- $source = str_replace('\\', '/', realpath($source));
- if (is_dir($source) === true)
- {
- $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
- foreach ($files as $file)
- {
- $file = str_replace('\\', '/', realpath($file));
- if (is_dir($file) === true)
- {
- $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
- }
- else if (is_file($file) === true)
- {
- $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
- }
- }
- }
- else if (is_file($source) === true)
- {
- $zip->addFromString(basename($source), file_get_contents($source));
- }
- return $zip->close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement