Advertisement
vishnu3006

formmod

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