Advertisement
vishnu3006

zip

Nov 28th, 2011
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.25 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.   $nodes_ser = trim($_GET['nodes']);
  20.   $nodes = explode("-",$nodes_ser);
  21.  
  22.  // print_r($nodes);
  23.     $form = array();
  24.  
  25. }
  26.  
  27.  
  28.  
  29. function formModifications_form_alter(&$form,&$form_state,$form_id){
  30.  
  31.                 if ($form_id == 'node_admin_content') {
  32.                     $form['admin']['options']['operation']['#options']['send_for_translation'] = t('Send For Translation');
  33.                     $form['admin']['options']['submit']['#submit'][] = 'custom_send_for_translation_submit_admin';
  34.                 }
  35. }
  36.  
  37. function custom_send_for_translation_submit_admin($form, &$form_state) {  
  38. $nodes = array();                                                                                                                                            
  39.               foreach ($form_state['values']['nodes'] as $key => $value)
  40.               {
  41.                      if ($value != 0) {
  42.                               $selected[] = node_load($key);
  43.                        }
  44.               }
  45.              
  46.  
  47.                  
  48.        foreach ($selected as $key => $value ){
  49.              $structure = './sites/all/tempfolder/';
  50.                                                                        
  51.                                                                                    
  52.               if(!is_dir($structure))
  53.               {
  54.                  mkdir($structure, 0, true);
  55.             }
  56.                                                                                                                                                                      
  57.           $fileName = $value->title;                                          
  58.           $sPattern = '/\s*/m';
  59.           $sReplace = '';
  60.           $refinedFileName = preg_replace( $sPattern, $sReplace, $fileName ).".xml";
  61.           $finalRefinedFileName = $structure.$refinedFileName;                                                                                    
  62.           $ourFileHandle = fopen($finalRefinedFileName, 'w') or die("can't open file");
  63.           $stringXmlHead = '<?xml version="1.0"?>'."\r\n";
  64.           fwrite($ourFileHandle, $stringXmlHead);
  65.           $rootNode = "<DrupalConnector>"."\r\n";  
  66.           fwrite($ourFileHandle, $rootNode);
  67.           $nodeIdTagStart = "<NodeId>";
  68.           fwrite($ourFileHandle, $nodeIdTagStart);
  69.           $nodeId = $value->nid;
  70.           fwrite($ourFileHandle, $nodeId);
  71.           $nodeIdTagEnd = "</NodeId>"."\r\n";
  72.           fwrite($ourFileHandle, $nodeIdTagEnd);
  73.           $nodeTitleTagStart = "<NodeTitle>";
  74.           fwrite($ourFileHandle, $nodeTitleTagStart);
  75.           $nodeTitle = "<![CDATA[".$value->title."]]>";
  76.           fwrite($ourFileHandle, $nodeTitle);
  77.           $nodeTitleTagEnd = "</NodeTitle>"."\r\n";
  78.           fwrite($ourFileHandle, $nodeTitleTagEnd);
  79.           $nodeBodyTagStart = "<NodeBody>";
  80.           fwrite($ourFileHandle, $nodeBodyTagStart);
  81.           $nodeBody = "<![CDATA[".$value->body."]]>";
  82.           fwrite($ourFileHandle, $nodeBody);
  83.           $nodeBodyTagEnd = "</NodeBody>"."\r\n";
  84.           fwrite($ourFileHandle, $nodeBodyTagEnd);
  85.           $rootNodeEnd = "</DrupalConnector>"."\r\n";
  86.           fwrite($ourFileHandle, $rootNodeEnd);
  87.          
  88.          
  89.          
  90.          
  91.           $nodes []= $value->nid;
  92.    }
  93.    fclose($ourFileHandle);
  94.    
  95.    
  96.    compress("./sites/all/tempfolder");
  97.    
  98.     $nodes_ser = implode('-', $nodes); 
  99.     drupal_goto('translate/bulk', 'nodes='. $nodes_ser);
  100.  
  101. }
  102.  
  103.  
  104.  
  105. function recurse_zip($src,&$zip,$path_length) {
  106.         $dir = opendir($src);
  107.         while(false !== ( $file = readdir($dir)) ) {
  108.             if (( $file != '.' ) && ( $file != '..' )) {
  109.                 if ( is_dir($src . '/' . $file) ) {
  110.                     recurse_zip($src . '/' . $file,$zip,$path_length);
  111.                 }
  112.                 else {
  113.                     $zip->addFile($src . '/' . $file,substr($src . '/' . $file,$path_length));
  114.                 }
  115.             }
  116.         }
  117.         closedir($dir);
  118. }
  119.  
  120.  
  121. //Call this function with argument = absolute path of file or directory name.
  122. function compress($src)
  123. {
  124.         if(substr($src,-1)==='/')
  125.         {$src=substr($src,0,-1);}
  126.         $arr_src=explode('/',$src);
  127.         $filename=end($src);
  128.         unset($arr_src[count($arr_src)-1]);
  129.         $path_length=strlen(implode('/',$arr_src).'/');
  130.         $f=explode('.',$filename);
  131.         $filename=$f[0];
  132.         $filename=(($filename=='')? 'backup.zip' : $filename.'.zip');
  133.         $zip = new ZipArchive;
  134.         $res = $zip->open($filename, ZipArchive::CREATE);
  135.         if($res !== TRUE){
  136.                 echo 'Error: Unable to create zip file';
  137.                 exit;}
  138.         if(is_file($src)){
  139.         $zip->addFile($src,substr($src,$path_length));
  140.         }
  141.         else{
  142.                 if(!is_dir($src)){
  143.                      $zip->close();
  144.                      @unlink($filename);
  145.                      echo 'Error: File not found';
  146.                      exit;}
  147.         recurse_zip($src,$zip,$path_length);
  148.         }
  149.         $zip->close();
  150.         header("Location: $filename");
  151.         exit;
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement