Advertisement
vishnu3006

Nov30Start

Nov 30th, 2011
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.52 KB | None | 0 0
  1. <?php
  2.  
  3. function formModifications_menu() {
  4.  
  5.   $items['translate/bulk'] = array(
  6.     'title' => t('Send Multiple Contents'),
  7.     'description' => t('Translate multiple nodes'),
  8.     'page callback' => 'drupal_get_form',
  9.     'page arguments' => array('formModifications_translate_bulk'),
  10.     'access arguments' => array('access translator'),
  11.   );
  12.    
  13.    return $items;
  14. }
  15.  
  16.  
  17. function formModifications_translate_bulk(){
  18.       // Get the nodes.
  19.       $chosenContents = "Contents Chosen :";
  20.       $nodes_ser = trim($_GET['nodes']);
  21.       $nodes = explode("-",$nodes_ser);
  22.       $form = array();
  23.      
  24.  
  25.          
  26.      foreach( $nodes as $key => $value){
  27.             $node = node_load($value); 
  28.             //print_r($node->title);
  29.             $chosenContents .= $node->title." , ";
  30.             }
  31.                        
  32.            
  33.     $form['content_information'] = array(
  34.         '#value' => variable_get('content_form_information', $chosenContents),
  35.         );
  36.  
  37.        
  38.   $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace"=>1));
  39.   $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace"=>1));
  40.  
  41.  
  42.               try{
  43.               $arrResponse = $LoginClient->Logon(array ('Username'=>'dmitry.testuser','Password'=>'I8it4lunch'));
  44.               $ticket = ($arrResponse->LogonResult);
  45.               $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket'=>$ticket));
  46.               $getDraftProjectIds = $ServicesLink->GetProjectSummariesList(array('Ticket'=>$ticket,'NumberOfProjects'=>100,'SortOrder'=>MostRecent,'ProjectStatusCode'=>'Draft'));
  47.                      
  48.                             $array = array();
  49.                             $forTarLang = array();
  50.                             $listOfProjects = array();
  51.                            
  52.                             foreach($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language)               
  53.                             {                                      
  54.                                 $array[$language->ID] = $language->Description;                            
  55.                                 $forTarLang[] = $language->ID;
  56.                             }
  57.                                                                                    
  58.                             for($i =0; $i <count($forTarLang);$i+=1)
  59.                             {
  60.                             print_r($forTarLang[i]);                           
  61.                             }
  62.                            
  63.                            
  64.                             foreach($getDraftProjectIds->GetProjectSummariesListResult->ProjectSummaries->ProjectSummary as $projectSummary)
  65.                             {
  66.                             $listOfProjects[$projectSummary->ID] = $projectSummary-> ID;
  67.                             }
  68.                            
  69.                         //$getTarLang = $AddFile->GetTargetLanguages(array('Ticket'=>$ticket,));   
  70.                        
  71.                             $tarLang = array();                    
  72.                            
  73.               }
  74.                   catch (SoapFault $exception){
  75.                   return $exception;
  76.                   }
  77.  
  78.  
  79. $form['folks_list']=array(
  80.         '#type'=>'select',
  81.         '#title' => t('Freeway Source Languages'),
  82.         //'#default_value' => array('1'=>'Joe'),
  83.         '#options' => $array,
  84.         //'#multiple' => false,
  85.         //'#attributes'=>array('size'=>4, 'class' => 'select_folks_list'),
  86.         '#weight'=>7,
  87.     );
  88.    
  89.  
  90. // listbox for target language.
  91.    
  92.     $form['targetLang_list']=array(
  93.         '#type'=>'select',
  94.         '#title' => t('Freeway Target Languages'),
  95.         '#options' => $array,
  96.         '#multiple' => false,
  97.         '#attributes'=>array('size'=>4, 'class' => 'select_folks_list'),
  98.         '#weight'=>8,
  99.     );
  100.    
  101.    
  102.  
  103.   $form['projectId'] = array(
  104.   '#type' => 'select',
  105.   '#title' => t('List of Draft projects created by you.'),
  106.    '#weight'=>9,
  107.   '#options' => $listOfProjects,
  108. ); 
  109.        
  110.        
  111.        
  112.        
  113.            
  114.  return $form;
  115.    
  116. }
  117.  
  118.  
  119.  
  120. function formModifications_form_alter(&$form,&$form_state,$form_id){
  121.  
  122.                 if ($form_id == 'node_admin_content') {
  123.                     $form['admin']['options']['operation']['#options']['send_for_translation'] = t('Send For Translation');
  124.                     $form['admin']['options']['submit']['#submit'][] = 'custom_send_for_translation_submit_admin';
  125.                 }
  126. }
  127.  
  128. function custom_send_for_translation_submit_admin($form, &$form_state) {
  129. $zipName = "Content";  
  130. $nodes = array();                                                                                                                                            
  131.               foreach ($form_state['values']['nodes'] as $key => $value)
  132.               {
  133.                      if ($value != 0) {
  134.                               $selected[] = node_load($key);
  135.                        }
  136.               }
  137.              
  138.  
  139.                  
  140.        foreach ($selected as $key => $value ){
  141.              $structure = './sites/all/tempfolder/';
  142.                                                                        
  143.                                                                                    
  144.               if(!is_dir($structure))
  145.               {
  146.                  mkdir($structure, 0, true);
  147.             }
  148.                                                                                                                                                                      
  149.           $fileName = $value->title;                                          
  150.           $sPattern = '/\s*/m';
  151.           $sReplace = '';
  152.           $refinedFileName = preg_replace( $sPattern, $sReplace, $fileName ).".xml";
  153.           $finalRefinedFileName = $structure.$refinedFileName;                                                                                    
  154.           $ourFileHandle = fopen($finalRefinedFileName, 'w') or die("can't open file");
  155.           $stringXmlHead = '<?xml version="1.0"?>'."\r\n";
  156.           fwrite($ourFileHandle, $stringXmlHead);
  157.           $rootNode = "<DrupalConnector>"."\r\n";  
  158.           fwrite($ourFileHandle, $rootNode);
  159.           $nodeIdTagStart = "<NodeId>";
  160.           fwrite($ourFileHandle, $nodeIdTagStart);
  161.           $nodeId = $value->nid;
  162.           fwrite($ourFileHandle, $nodeId);
  163.           $nodeIdTagEnd = "</NodeId>"."\r\n";
  164.           fwrite($ourFileHandle, $nodeIdTagEnd);
  165.           $nodeTitleTagStart = "<NodeTitle>";
  166.           fwrite($ourFileHandle, $nodeTitleTagStart);
  167.           $nodeTitle = "<![CDATA[".$value->title."]]>";
  168.           fwrite($ourFileHandle, $nodeTitle);
  169.           $nodeTitleTagEnd = "</NodeTitle>"."\r\n";
  170.           fwrite($ourFileHandle, $nodeTitleTagEnd);
  171.           $nodeBodyTagStart = "<NodeBody>";
  172.           fwrite($ourFileHandle, $nodeBodyTagStart);
  173.           $nodeBody = "<![CDATA[".$value->body."]]>";
  174.           fwrite($ourFileHandle, $nodeBody);
  175.           $nodeBodyTagEnd = "</NodeBody>"."\r\n";
  176.           fwrite($ourFileHandle, $nodeBodyTagEnd);
  177.           $rootNodeEnd = "</DrupalConnector>"."\r\n";
  178.           fwrite($ourFileHandle, $rootNodeEnd);
  179.          
  180.           $zipName.= "_".$nodeId;
  181.          
  182.          
  183.           $nodes []= $value->nid;
  184.    }
  185.    fclose($ourFileHandle);
  186.    
  187.   $finalZipName = $zipName.".zip";
  188.    
  189.    Zip('./sites/all/tempfolder','./'.$finalZipName);
  190.     //zipping done
  191.     $nodes_ser = implode('-', $nodes); 
  192.     drupal_goto('translate/bulk', 'nodes='. $nodes_ser);
  193.  
  194. }
  195.  
  196.  
  197. function Zip($source, $destination)
  198.  {  
  199.  if (!extension_loaded('zip') || !file_exists($source))
  200.      {      
  201.      return false;  
  202.      }  
  203.  
  204.  $zip = new ZipArchive();  
  205.  if (!$zip->open($destination, ZIPARCHIVE::CREATE))
  206.      {      
  207.      return false;
  208.      }    
  209.  
  210.  $source = str_replace('\\', '/', realpath($source));  
  211.  if (is_dir($source) === true)  
  212.  {    
  213.          $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
  214.          foreach ($files as $file)
  215.          {          
  216.              $file = str_replace('\\', '/', realpath($file));
  217.              if (is_dir($file) === true)  
  218.              {              
  219.              $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));  
  220.              }          
  221.              else if (is_file($file) === true)    
  222.              {        
  223.              $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));  
  224.              }  
  225.          }    
  226.  }
  227.  
  228.  else if (is_file($source) === true)  
  229.          {    
  230.          $zip->addFromString(basename($source), file_get_contents($source));
  231.          }  
  232.  return $zip->close();
  233.  }
  234.  
  235.  
  236.  
  237.  
  238.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement