Source for file export.act.php

Documentation is available at export.act.php

  1. <?php
  2. /**
  3. * @since 9/27/05
  4. * @package polyphony.basket
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: export.act.php,v 1.11 2007/09/19 14:04:54 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13. require_once(POLYPHONY."/main/library/Exporter/XMLAssetExporter.class.php");
  14.  
  15. /**
  16. * This is the export action for an asset
  17. *
  18. * @since 9/27/05
  19. * @package polyphony.basket
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: export.act.php,v 1.11 2007/09/19 14:04:54 adamfranco Exp $
  25. */
  26. class exportAction
  27. extends MainWindowAction
  28. {
  29. /**
  30. * Check Authorizations
  31. *
  32. * @return boolean
  33. * @access public
  34. * @since 9/27/05
  35. */
  36. function isAuthorizedToExecute () {
  37. $harmoni = Harmoni::instance();
  38. $authZ = Services::getService("AuthZ");
  39. $idManager = Services::getService("Id");
  40.  
  41. $basket = Basket::instance();
  42. $basket->reset();
  43. $view =$idManager->getId("edu.middlebury.authorization.view");
  44. $this->_exportList = array();
  45.  
  46. while ($basket->hasNext()) {
  47. $id =$basket->next();
  48. if ($authZ->isUserAuthorized($view, $id))
  49. $this->_exportList[] = $id;
  50. }
  51.  
  52. if (count($this->_exportList) > 0)
  53. return true;
  54. else
  55. return false;
  56. }
  57. /**
  58. * Return the "unauthorized" string to pring
  59. *
  60. * @return string
  61. * @access public
  62. * @since 9/27/05
  63. */
  64. function getUnauthorizedMessage () {
  65. return dgettext("polyphony", "You are not authorized to export ANY of these <em>Assets</em>.");
  66. }
  67. /**
  68. * Return the heading text for this action, or an empty string.
  69. *
  70. * @return string
  71. * @access public
  72. * @since 9/28/05
  73. */
  74. function getHeadingText () {
  75. $harmoni = Harmoni::Instance();
  76. $idManager = Services::getService("Id");
  77.  
  78. return dgettext("polyphony", "Export the <em>Assets</em> in the Selection");
  79. }
  80.  
  81. /**
  82. * Build the content for this action
  83. *
  84. * @return void
  85. * @access public
  86. * @since 9/27/05
  87. */
  88. function buildContent () {
  89. $harmoni = Harmoni::Instance();
  90.  
  91. $centerPane =$this->getActionRows();
  92.  
  93. $authN = Services::getService("AuthN");
  94. $authTypes =$authN->getAuthenticationTypes();
  95. $uniqueString = "";
  96. while($authTypes->hasNext()) {
  97. $authType =$authTypes->next();
  98. $uniqueString .= "_".$authN->getUserId($authType);
  99. }
  100.  
  101. $cacheName = 'export_asset_wizard'.$uniqueString;
  102. $this->runWizard ( $cacheName, $centerPane );
  103. }
  104. /**
  105. * Create a new Wizard for this action. Caching of this Wizard is handled by
  106. * {@link getWizard()} and does not need to be implemented here.
  107. *
  108. * @return object Wizard
  109. * @access public
  110. * @since 9/28/05
  111. */
  112. function createWizard () {
  113. // Instantiate the wizard, then add our steps.
  114. $wizard = SimpleWizard::withText(
  115. "\n<h3>"._("Click <em>Export</em> to Export the Selection")."</h3>".
  116. "\n<br/>"._("The current content of the Selection will be exported and presented as an archive for download. Once the archive is downloaded click <em>Cancel</em> to go back.").
  117. "\n<br/><h3>"._("Archive:")."</h3>".
  118. "<table border='0' style='margin-top:20px' >\n" .
  119. "\n<tr><td>"._("Archive Name: ")."</td>".
  120. "<td>[[filepath]]</td></tr>".
  121. "\n<tr><td>"._("Compression: ")."</td>".
  122. "<td>[[compression]]</td></tr>".
  123. "<tr>\n" .
  124. "<td align='left'>\n" .
  125. "[[_cancel]]".
  126. "</td>\n" .
  127. "<td align='right'>\n" .
  128. "[[_save]]".
  129. "</td></tr></table>");
  130. // Create the properties.
  131. $fileNameProp =$wizard->addComponent("filepath", new WTextField());
  132.  
  133. // $datefield =$wizard->addComponent("effective_date", new WTextField());
  134. // $date = DateAndTime::Now();
  135. // $datefield->setValue($date->asString());
  136. //
  137. // $date2field =$wizard->addComponent("expiration_date", new WTextField());
  138. //
  139. // if (is_object($date2))
  140. // $date2field->setValue($date->asString());
  141. $type =$wizard->addComponent("compression", new WSelectList());
  142. $type->setValue(".tar.gz");
  143. $type->addOption(".tar.gz", dgettext("polyphony", "gzip"));
  144. // $type->addOption(".zip", _("zip"));
  145. // $type->addOption(".bz2", _("bz2"));
  146.  
  147. $save =$wizard->addComponent("_save",
  148. WSaveButton::withLabel("Export"));
  149. $cancel =$wizard->addComponent("_cancel", new WCancelButton());
  150.  
  151. return $wizard;
  152. }
  153. /**
  154. * Save our results. Tearing down and unsetting the Wizard is handled by
  155. * in {@link runWizard()} and does not need to be implemented here.
  156. *
  157. * @param string $cacheName
  158. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  159. * Wizard should ensue.
  160. * @access public
  161. * @since 4/28/05
  162. */
  163. function saveWizard ( $cacheName ) {
  164. $wizard =$this->getWizard($cacheName);
  165. $properties = $wizard->getAllValues();
  166. // instantiate new exporter
  167. $exporter = XMLAssetExporter::withCompression(
  168. $properties['compression']);
  169. $dir = $exporter->exportList($this->_exportList);
  170. $this->_archiveFile = $exporter->compressWithStatus();
  171. $this->_archiveFileKey = str_replace('.', '', basename($this->_archiveFile, $properties['compression']));
  172. // printpre($this->_archiveFile);
  173. // For security, only files listed in the following array will be allowed
  174. // to be downloaded.
  175. if (!isset($_SESSION['EXPORTED_FILES']))
  176. $_SESSION['EXPORTED_FILES'] = array();
  177. $_SESSION['EXPORTED_FILES'][$this->_archiveFileKey] = array(
  178. 'file' => $this->_archiveFile,
  179. 'name' => basename($properties['filepath'].$properties['compression']),
  180. 'mime' => 'application/x-gzip');
  181.  
  182. return TRUE;
  183. }
  184. /**
  185. * Return the URL that this action should return to when completed.
  186. *
  187. * @return string
  188. * @access public
  189. * @since 4/28/05
  190. */
  191. function getReturnUrl () {
  192. $harmoni = Harmoni::instance();
  193. $return = $harmoni->request->quickURL("basket", "view");
  194. if ($this->_archiveFile) {
  195. $harmoni->request->startNamespace('export');
  196. $downloadUrl = $harmoni->request->quickURL("export", "getFile",
  197. array('file' => urlencode($this->_archiveFileKey)));
  198. $harmoni->request->endNamespace();
  199. print "<div>"._("Your download should begin momentarily. If it does not, please click the download link below.")."</div>";
  200. print "<div style='margin: 10px; margin-left: 20px;'><a href='".$downloadUrl."'>"._("Download")."</a></div>";
  201. print "<div style=''><a href='".$return."'>"._("&lt;-- Return")."</a></div>";
  202. while(ob_get_level())
  203. ob_end_flush();
  204. flush();
  205. $harmoni->request->sendTo($downloadUrl);
  206. exit;
  207. } else
  208. return $return;
  209. }
  210. }
  211.  
  212. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:06 -0400 by phpDocumentor 1.3.0RC3