PageRenderTime 44ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/workflow/engine/methods/setup/skinsExport.php

https://bitbucket.org/ferOnti/processmaker
PHP | 187 lines | 120 code | 29 blank | 38 comment | 19 complexity | 048f0f0c26dfef8f7d52f10e13f0cb2d MD5 | raw file
  1. <?php
  2. /**
  3. * skinsExport.php
  4. *
  5. * ProcessMaker Open Source Edition
  6. * Copyright (C) 2004 - 2008 Colosa Inc.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  22. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  23. */
  24. function copyFile ($input, $output)
  25. {
  26. $content = file_get_contents( $input );
  27. $filename = $output . PATH_SEP . basename( $input );
  28. return file_put_contents( $filename, $content );
  29. }
  30. function savePluginFile ($tplName, $fileName, $fields)
  31. {
  32. $pluginTpl = PATH_GULLIVER_HOME . 'bin' . PATH_SEP . 'tasks' . PATH_SEP . 'templates' . PATH_SEP . $tplName . '.tpl';
  33. $template = new TemplatePower( $pluginTpl );
  34. $template->prepare();
  35. if (is_array( $fields )) {
  36. foreach ($fields as $block => $data) {
  37. $template->gotoBlock( "_ROOT" );
  38. if (is_array( $data ))
  39. foreach ($data as $rowId => $row) {
  40. $template->newBlock( $block );
  41. foreach ($row as $key => $val)
  42. $template->assign( $key, $val );
  43. }
  44. else
  45. $template->assign( $block, $data );
  46. }
  47. }
  48. $content = $template->getOutputContent();
  49. $iSize = file_put_contents( $fileName, $content );
  50. return $iSize;
  51. }
  52. function addTarFolder ($tar, $pathBase, $pluginHome)
  53. {
  54. $aux = explode( PATH_SEP, $pathBase );
  55. if ($aux[count( $aux ) - 2] == '.svn')
  56. return;
  57. if ($handle = opendir( $pathBase )) {
  58. while (false !== ($file = readdir( $handle ))) {
  59. if (is_file( $pathBase . $file )) {
  60. //print "file $file \n";
  61. $tar->addModify( $pathBase . $file, '', $pluginHome );
  62. }
  63. if (is_dir( $pathBase . $file ) && $file != '..' && $file != '.') {
  64. //print "dir $pathBase$file \n";
  65. addTarFolder( $tar, $pathBase . $file . PATH_SEP, $pluginHome );
  66. }
  67. }
  68. closedir( $handle );
  69. }
  70. }
  71. function packPlugin ($pluginName, $version)
  72. {
  73. $pathBase = PATH_DATA . 'skins' . PATH_SEP . $pluginName . PATH_SEP;
  74. $pathHome = PATH_DATA . 'skins' . PATH_SEP . $pluginName;
  75. $fileTar = PATH_DATA . 'skins' . PATH_SEP . $pluginName . '-' . $version . '.tar';
  76. G::LoadSystem( 'templatePower' );
  77. /*
  78. $pluginDirectory = PATH_PLUGINS . $pluginName;
  79. $pluginOutDirectory = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $pluginName;
  80. $pluginHome = PATH_OUTTRUNK . 'plugins' . PATH_SEP . $pluginName;
  81. //verify if plugin exists,
  82. $pluginClassFilename = PATH_PLUGINS . $pluginName . PATH_SEP . 'class.' . $pluginName . '.php';
  83. if ( !is_file ( $pluginClassFilename ) ) {
  84. printf("The plugin %s doesn't exist in this file %s \n", pakeColor::colorize( $pluginName, 'ERROR'), pakeColor::colorize( $pluginClassFilename, 'INFO') );
  85. die ;
  86. }
  87. */
  88. G::LoadThirdParty( 'pear/Archive', 'Tar' );
  89. $tar = new Archive_Tar( $fileTar );
  90. $tar->_compress = false;
  91. //$tar->createModify( $pathHome . PATH_SEP . $pluginName . '.php' ,'', $pathHome);
  92. addTarFolder( $tar, $pathBase, $pathHome );
  93. $aFiles = $tar->listContent();
  94. return $fileTar;
  95. }
  96. global $RBAC;
  97. switch ($RBAC->userCanAccess( 'PM_SETUP' )) {
  98. case - 2:
  99. G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels' );
  100. G::header( 'location: ../login/login' );
  101. die();
  102. break;
  103. case - 1:
  104. G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels' );
  105. G::header( 'location: ../login/login' );
  106. die();
  107. break;
  108. }
  109. G::LoadClass( "system" );
  110. $id = $_GET['id'];
  111. $fileObj = PATH_SKINS . $id . '.cnf';
  112. if (! file_exists( $fileObj )) {
  113. $oConf = new stdClass();
  114. $oConf->name = $id;
  115. $oConf->description = "description of skin $id ";
  116. $oConf->version = 1;
  117. file_put_contents( $fileObj, serialize( $oConf ) );
  118. }
  119. $oConf = unserialize( file_get_contents( $fileObj ) );
  120. $oConf->version += 1;
  121. file_put_contents( $fileObj, serialize( $oConf ) );
  122. $pathHome = PATH_DATA . 'skins' . PATH_SEP . $id . PATH_SEP;
  123. $pathBase = PATH_DATA . 'skins' . PATH_SEP . $id . PATH_SEP . $id . PATH_SEP;
  124. $pathPublic = $pathBase . 'data' . PATH_SEP . 'public_html' . PATH_SEP;
  125. $pathImages = PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP . 'images' . PATH_SEP;
  126. G::mk_dir( $pathBase );
  127. G::mk_dir( $pathBase . 'data' );
  128. G::mk_dir( $pathPublic );
  129. G::mk_dir( $pathPublic . 'images' );
  130. // file_put_contents ( PATH_DATA . 'skins' . PATH_SEP . $id , "hello world" );
  131. $fields['className'] = $id;
  132. $fields['version'] = $oConf->version;
  133. $fields['description'] = $oConf->description;
  134. $fields['PMversion'] = System::getVersion();
  135. savePluginFile( 'skinPluginMainClass', $pathHome . $id . '.php', $fields );
  136. savePluginFile( 'skinPluginClass', $pathBase . 'class.' . $id . '.php', $fields );
  137. copyFile( PATH_SKINS . $id . '.php', $pathBase . 'data' );
  138. copyFile( PATH_SKINS . $id . '.html', $pathBase . 'data' );
  139. copyFile( PATH_SKINS . $id . '.cnf', $pathBase . 'data' );
  140. copyFile( PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP . 'iepngfix.htc', $pathPublic );
  141. copyFile( PATH_HTML . 'skins' . PATH_SEP . $id . PATH_SEP . 'style.css', $pathPublic );
  142. $aFiles = array ();
  143. if ($handle = opendir( $pathImages )) {
  144. while (false !== ($file = readdir( $handle ))) {
  145. if (substr( $file, 0, 1 ) != '.') {
  146. if (isset( $aFiles[$file] ))
  147. $aFiles[$file] = 0;
  148. copyFile( $pathImages . $file, $pathPublic . 'images' . PATH_SEP );
  149. }
  150. }
  151. closedir( $handle );
  152. }
  153. $fileTar = packPlugin( $id, $oConf->version );
  154. $bDownload = true;
  155. G::streamFile( $fileTar, $bDownload, basename( $fileTar ) );
  156. @G::rm_dir( $pathHome );
  157. @unlink( $fileTar );