PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/www/devel/plugin.php

https://bitbucket.org/valmy/openx
PHP | 154 lines | 111 code | 14 blank | 29 comment | 11 complexity | 70b368515991c949d9acdfe516804240 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. /**
  25. * OpenX Developer Toolbox
  26. *
  27. * @author Monique Szpak <monique.szpak@openx.org>
  28. * $Id$
  29. *
  30. */
  31. require_once './init.php';
  32. if (array_key_exists('btn_create',$_POST) && array_key_exists('name',$_POST))
  33. {
  34. global $pathPluginsTmp;
  35. $pathPluginsTmp = MAX_PATH.'/var/tmp'.$GLOBALS['_MAX']['CONF']['pluginPaths']['packages'];
  36. if (_fileMissing($pathPluginsTmp))
  37. {
  38. return false;
  39. }
  40. $aPluginValues = $_POST;
  41. $aPluginValues['date'] = date('Y-d-m');
  42. $aPluginValues['oxversion'] = OA_VERSION;
  43. $aGroupValues = $aPluginValues['group'];
  44. unset($aPluginValues['group']);
  45. if ($aGroupValues)
  46. {
  47. foreach ($aGroupValues as $name => $aVal)
  48. {
  49. $aVals = $aPluginValues;
  50. $aVals['extension'] = $name;
  51. $aVals['component'] = $aVal['componentname'];
  52. $aVals['group'] = $aVal['groupname'];
  53. $aPluginValues['grouporder'][] = $aVals['group'];
  54. putGroup($aVals);
  55. }
  56. }
  57. putPlugin($aPluginValues);
  58. }
  59. function putPlugin($aVals)
  60. {
  61. global $pathPluginsTmp;
  62. $target = $pathPluginsTmp.$aVals['name'].'.xml';
  63. $source = 'templates/plugins/plugin.xml';
  64. if (_fileExists($target) ||
  65. (!_putFile($source, $target, $aVals)) ||
  66. _fileMissing($target))
  67. {
  68. exit(1);
  69. }
  70. $target = MAX_PATH.'/var'.$GLOBALS['_MAX']['CONF']['pluginPaths']['packages'].$aVals['name'].'.readme.txt';
  71. if ($fp = fopen($target, 'w'))
  72. {
  73. fclose($fp);
  74. }
  75. $data = file_get_contents($target);
  76. foreach ($aVals['grouporder'] AS $i => $group)
  77. {
  78. $data = str_replace('{GROUP'.$i.'}', $group, $data);
  79. }
  80. $i = file_put_contents($target, $data);
  81. }
  82. function putGroup($aVals)
  83. {
  84. global $pathPluginsTmp;
  85. $path = $pathPluginsTmp.$aVals['group'];
  86. $source = 'templates/plugins/group'.ucfirst($aVals['extension']).'/group'.ucfirst($aVals['extension']).'.xml';
  87. $target = $path.'/'.$aVals['group'].'.xml';
  88. if (_fileExists($path) ||
  89. _fileExists($target) ||
  90. (!_makeDir($path)) ||
  91. (!_putFile($source, $target, $aVals)) ||
  92. _fileMissing($target))
  93. {
  94. exit(1);
  95. }
  96. }
  97. function _putFile($source, $target, $aVals)
  98. {
  99. $data = file_get_contents($source);
  100. foreach ($aVals AS $k => $v)
  101. {
  102. $data = str_replace('{'.strtoupper($k).'}', $v, $data);
  103. }
  104. $i = file_put_contents($target, $data);
  105. if (!$i)
  106. {
  107. echo 'Error writing file '.$target;
  108. return false;
  109. }
  110. return true;
  111. }
  112. function _makeDir($path)
  113. {
  114. if (!mkdir($path))
  115. {
  116. echo 'Failed to create path '.$path;
  117. return false;
  118. }
  119. return true;
  120. }
  121. function _fileExists($file)
  122. {
  123. if (file_exists($file))
  124. {
  125. echo 'File exists '.$file;
  126. return true;
  127. }
  128. return false;
  129. }
  130. function _fileMissing($file)
  131. {
  132. if (!file_exists($file))
  133. {
  134. echo 'File not found '.$file;
  135. return true;
  136. }
  137. return false;
  138. }
  139. include 'templates/plugin.html';
  140. ?>