root/afridex/plugins/Flutter/RCCWP_ExportModule.php @ 21

Revision 21, 4.3 kB (checked in by admin, 18 years ago)
RevLine 
[21]1<?php
2require( dirname(__FILE__) . '/../../../wp-config.php' );
3if (!(is_user_logged_in() && current_user_can(FLUTTER_CAPABILITY_MODULES)))
4        die("Athentication failed!");
5       
6require_once('RCCWP_CustomWriteModule.php');
7require_once('RCCWP_CustomWritePanel.php');
8require_once('RCCWP_Application.php');
9require_once('RCCWP_CustomWritePanel.php');
10
11$moduleID = (int)$_REQUEST['custom-write-module-id'];
12$module = RCCWP_CustomWriteModule::Get($moduleID);
13
14if (isset($_POST["write_panels"])){
15       
16        $write_panels = json_decode(stripslashes($_POST["write_panels"]));
17       
18        $modulePath = FLUTTER_MODULES_DIR.$module->name.DIRECTORY_SEPARATOR;
19        $tmpPath = sys_get_temp_dir().DIRECTORY_SEPARATOR;
20       
21       
22        // Copy dir to tmp folder
23        dircopy($modulePath, $tmpPath. $module->name);
24        $moduleTmpPath = "$tmpPath{$module->name}";
25        chmod_R($moduleTmpPath, 0777);
26       
27        // Export write panels
28        foreach($write_panels as $panelID){
29                $writePanel = RCCWP_CustomWritePanel::Get($panelID);
30                $exportedFilename = $moduleTmpPath.DIRECTORY_SEPARATOR. '_'.$writePanel->name . '.pnl';
31                RCCWP_CustomWritePanel::Export($panelID, $exportedFilename);
32        }
33       
34        // Export duplicates and description
35        $moduleInfoFilename = $moduleTmpPath.DIRECTORY_SEPARATOR.'module_info.exp';
36        $moduleInfo_exported_data['duplicates'] = RCCWP_ModuleDuplicate::GetCustomModulesDuplicates($moduleID);
37        $moduleInfo_exported_data['moduleinfo'] = RCCWP_CustomWriteModule::Get($moduleID); 
38        $handle = fopen($moduleInfoFilename, "w");
39        $result = @fwrite($handle, serialize($moduleInfo_exported_data));
40        @fclose($handle);
41       
42        // -- Create zip file
43        $zipFile = "$tmpPath{$module->name}.zip";
44        chdir($moduleTmpPath.DIRECTORY_SEPARATOR);
45        if (RCCWP_Application::CheckCompressionProgramZip()) 
46                $command = "zip -r $zipFile  ./*"; 
47        else{
48                echo "Cannot find zip program";
49                return;
50        }
51        exec($command, $out, $err);
52       
53       
54        // send file in header
55        header('Content-type: binary');
56        header('Content-Disposition: attachment; filename="'.$module->name.'.zip"');
57        readfile($zipFile);
58       
59        // Remove file and directory
60        unlink($zipFile);
61        advancedRmdir($moduleTmpPath);
62        exit();
63}
64
65$customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
66               
67?>
68
69<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-basic11.dtd" >
70<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
71<head>
72        <title>Export Module</title>
73        <link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/global.css' type='text/css' />
74        <link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/wp-admin.css' type='text/css' />
75        <link rel='stylesheet' href='<?php echo get_bloginfo('wpurl');?>/wp-admin/css/colors-fresh.css' type='text/css' />
76       
77        <script type="text/javascript">
78                function startExport(){
79               
80                        // Collect write panels
81                        var write_panels = [];
82                        var write_panels_elements = document.export_module_form.elements["write_panels[]"];
83                        if (write_panels_elements != undefined){
84                                if (write_panels_elements.length != undefined){
85                                        for(i=0;i<write_panels_elements.length;i++)
86                                        {
87                                                if (write_panels_elements[i].checked)
88                                                        write_panels.push(write_panels_elements[i].value);
89                                        }
90                                }
91                                else
92                                {
93                                        if (write_panels_elements.checked)
94                                                write_panels.push(write_panels_elements.value);
95                                }
96                        }
97                       
98                        // Submit data through a hidden form in the parent window
99                        var par = window.parent.document;
100                        par.forms['do_export'].elements["custom-write-module-id"].value= "<?php echo $moduleID ?>";
101                        par.forms['do_export'].elements["write_panels"].value= self.parent.Object.toJSON(write_panels);
102                        par.forms['do_export'].submit();
103                       
104                        self.parent.tb_remove();
105                        return true;
106                       
107                }
108               
109        </script>
110       
111</head>
112<body>
113
114<div class="wrap">
115
116<h2>Export <?php echo $module->name ?></h2>
117               
118<form action="" method="post" name="export_module_form" id="export-module-form" >
119        <strong> <?php _e('If you want to export Write Panels along with the module, check them below:')?> </strong>
120        <ul>
121        <?php
122        foreach ($customWritePanels as $panel) :
123        ?>
124                <li>
125                <input type="checkbox" name="write_panels[]" value="<?php echo $panel->id?>">&nbsp;<?php echo $panel->name;?></input>
126                </li>
127        <?php
128        endforeach;
129        ?>
130        </ul>
131        <p class="submit" >
132                <input type="button" name="submit-export-module" id="submit-export-module" value="<?php _e('Export'); ?>" onclick="startExport()" />
133        </p>
134       
135</form>
136
137
138</div>
139
140</body>
141</html>
142       
Note: See TracBrowser for help on using the browser.