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.
- $nodes_ser = trim($_GET['nodes']);
- $nodes = explode("-",$nodes_ser);
- // print_r($nodes);
- $form = array();
- }
- 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) {
- $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);
- $nodes []= $value->nid;
- }
- fclose($ourFileHandle);
- compress("./sites/all/tempfolder");
- $nodes_ser = implode('-', $nodes);
- drupal_goto('translate/bulk', 'nodes='. $nodes_ser);
- }
- function recurse_zip($src,&$zip,$path_length) {
- $dir = opendir($src);
- while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . '/' . $file) ) {
- recurse_zip($src . '/' . $file,$zip,$path_length);
- }
- else {
- $zip->addFile($src . '/' . $file,substr($src . '/' . $file,$path_length));
- }
- }
- }
- closedir($dir);
- }
- //Call this function with argument = absolute path of file or directory name.
- function compress($src)
- {
- if(substr($src,-1)==='/')
- {$src=substr($src,0,-1);}
- $arr_src=explode('/',$src);
- $filename=end($src);
- unset($arr_src[count($arr_src)-1]);
- $path_length=strlen(implode('/',$arr_src).'/');
- $f=explode('.',$filename);
- $filename=$f[0];
- $filename=(($filename=='')? 'backup.zip' : $filename.'.zip');
- $zip = new ZipArchive;
- $res = $zip->open($filename, ZipArchive::CREATE);
- if($res !== TRUE){
- echo 'Error: Unable to create zip file';
- exit;}
- if(is_file($src)){
- $zip->addFile($src,substr($src,$path_length));
- }
- else{
- if(!is_dir($src)){
- $zip->close();
- @unlink($filename);
- echo 'Error: File not found';
- exit;}
- recurse_zip($src,$zip,$path_length);
- }
- $zip->close();
- header("Location: $filename");
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement