index.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * VersionX
  4. *
  5. * Copyright 2011 by Mark Hamstra <hello@markhamstra.com>
  6. *
  7. * VersionX is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * VersionX is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * VersionX; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. * Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * @var modX $modx
  21. * @var modAction $action
  22. */
  23. require_once dirname(dirname(__FILE__)).'/model/versionx.class.php';
  24. $versionx = new VersionX($modx);
  25. $versionx->initialize('mgr');
  26. $scripts = array();
  27. $versionid = (isset($_REQUEST['vid'])) ? (int)$_REQUEST['vid'] : false;
  28. $compareid = (isset($_REQUEST['cmid'])) ? (int)$_REQUEST['cmid'] : false;
  29. if (!isset($_REQUEST['action'])) $_REQUEST['action'] = 'index';
  30. switch ($_REQUEST['action']) {
  31. case 'resource':
  32. /* If an ID was passed, fetch that version into a record array. */
  33. if ($versionid > 0) {
  34. $v = $versionx->getVersionDetails('vxResource',$versionid,true);
  35. if ($v !== false)
  36. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$v.'; </script>');
  37. }
  38. /* If an ID to compare to was passed, fetch that aswell. */
  39. if ($compareid > 0) {
  40. $v = $versionx->getVersionDetails('vxResource',$compareid,true);
  41. if ($v !== false)
  42. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$v.'; </script>');
  43. }
  44. $scripts[] = $versionx->config['js_url'].'mgr/action.resource.js';
  45. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  46. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  47. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.content.js';
  48. $scripts[] = $versionx->config['js_url'].'mgr/resources/detailpanel/panel.tvs.js';
  49. $scripts[] = $versionx->config['js_url'].'mgr/resources/detailpanel.v21.resources.js';
  50. $scripts[] = $versionx->config['js_url'].'mgr/resources/combo.versions.resources.js';
  51. break;
  52. case 'template':
  53. /* If an ID was passed, fetch that version into a record array. */
  54. if ($versionid > 0) {
  55. $v = $versionx->getVersionDetails('vxTemplate',$versionid);
  56. if ($v !== false) {
  57. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$modx->toJSON($v).'; </script>');
  58. }
  59. }
  60. /* If an ID to compare to was passed, fetch that aswell. */
  61. if ($compareid > 0) {
  62. $v = $versionx->getVersionDetails('vxTemplate',$compareid);
  63. if ($v !== false) {
  64. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$modx->toJSON($v).'; </script>');
  65. }
  66. }
  67. $scripts[] = $versionx->config['js_url'].'mgr/action.template.js';
  68. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  69. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  70. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.content.js';
  71. $scripts[] = $versionx->config['js_url'].'mgr/templates/detailpanel.templates.js';
  72. $scripts[] = $versionx->config['js_url'].'mgr/templates/combo.versions.templates.js';
  73. break;
  74. case 'templatevar':
  75. /* If an ID was passed, fetch that version into a record array. */
  76. if ($versionid > 0) {
  77. $v = $versionx->getVersionDetails('vxTemplateVar',$versionid);
  78. if ($v !== false) {
  79. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$modx->toJSON($v).'; </script>');
  80. }
  81. }
  82. /* If an ID to compare to was passed, fetch that aswell. */
  83. if ($compareid > 0) {
  84. $v = $versionx->getVersionDetails('vxTemplateVar',$compareid);
  85. if ($v !== false) {
  86. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$modx->toJSON($v).'; </script>');
  87. }
  88. }
  89. $scripts[] = $versionx->config['js_url'].'mgr/action.templatevar.js';
  90. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  91. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  92. $scripts[] = $versionx->config['js_url'].'mgr/templatevars/detailpanel.templatevars.js';
  93. $scripts[] = $versionx->config['js_url'].'mgr/templatevars/combo.versions.templatevars.js';
  94. break;
  95. case 'chunk':
  96. /* If an ID was passed, fetch that version into a record array. */
  97. if ($versionid > 0) {
  98. $v = $versionx->getVersionDetails('vxChunk',$versionid);
  99. if ($v !== false) {
  100. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$modx->toJSON($v).'; </script>');
  101. }
  102. }
  103. /* If an ID to compare to was passed, fetch that aswell. */
  104. if ($compareid > 0) {
  105. $v = $versionx->getVersionDetails('vxChunk',$compareid);
  106. if ($v !== false) {
  107. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$modx->toJSON($v).'; </script>');
  108. }
  109. }
  110. $scripts[] = $versionx->config['js_url'].'mgr/action.chunk.js';
  111. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  112. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  113. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.content.js';
  114. $scripts[] = $versionx->config['js_url'].'mgr/chunks/detailpanel.chunks.js';
  115. $scripts[] = $versionx->config['js_url'].'mgr/chunks/combo.versions.chunks.js';
  116. break;
  117. case 'snippet':
  118. /* If an ID was passed, fetch that version into a record array. */
  119. if ($versionid > 0) {
  120. $v = $versionx->getVersionDetails('vxSnippet',$versionid);
  121. if ($v !== false) {
  122. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$modx->toJSON($v).'; </script>');
  123. }
  124. }
  125. /* If an ID to compare to was passed, fetch that aswell. */
  126. if ($compareid > 0) {
  127. $v = $versionx->getVersionDetails('vxSnippet',$compareid);
  128. if ($v !== false) {
  129. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$modx->toJSON($v).'; </script>');
  130. }
  131. }
  132. $scripts[] = $versionx->config['js_url'].'mgr/action.snippet.js';
  133. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  134. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  135. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.content.js';
  136. $scripts[] = $versionx->config['js_url'].'mgr/snippets/detailpanel.snippets.js';
  137. $scripts[] = $versionx->config['js_url'].'mgr/snippets/combo.versions.snippets.js';
  138. break;
  139. case 'plugin':
  140. /* If an ID was passed, fetch that version into a record array. */
  141. if ($versionid > 0) {
  142. $v = $versionx->getVersionDetails('vxPlugin',$versionid);
  143. if ($v !== false) {
  144. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.record = '.$modx->toJSON($v).'; </script>');
  145. }
  146. }
  147. /* If an ID to compare to was passed, fetch that aswell. */
  148. if ($compareid > 0) {
  149. $v = $versionx->getVersionDetails('vxPlugin',$compareid);
  150. if ($v !== false) {
  151. $modx->regClientStartupHTMLBlock('<script type="text/javascript">VersionX.cmrecord = '.$modx->toJSON($v).'; </script>');
  152. }
  153. }
  154. $scripts[] = $versionx->config['js_url'].'mgr/action.plugin.js';
  155. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.common.js';
  156. $scripts[] = $versionx->config['js_url'].'mgr/common/grid.common.js';
  157. $scripts[] = $versionx->config['js_url'].'mgr/common/panel.content.js';
  158. $scripts[] = $versionx->config['js_url'].'mgr/plugins/detailpanel.plugins.js';
  159. $scripts[] = $versionx->config['js_url'].'mgr/plugins/combo.versions.plugins.js';
  160. break;
  161. case 'index':
  162. default:
  163. $scripts[] = $versionx->config['js_url'].'mgr/resources/panel.resources.js';
  164. $scripts[] = $versionx->config['js_url'].'mgr/resources/grid.resources.js';
  165. $scripts[] = $versionx->config['js_url'].'mgr/templates/panel.templates.js';
  166. $scripts[] = $versionx->config['js_url'].'mgr/templates/grid.templates.js';
  167. $scripts[] = $versionx->config['js_url'].'mgr/templatevars/panel.templatevars.js';
  168. $scripts[] = $versionx->config['js_url'].'mgr/templatevars/grid.templatevars.js';
  169. $scripts[] = $versionx->config['js_url'].'mgr/chunks/panel.chunks.js';
  170. $scripts[] = $versionx->config['js_url'].'mgr/chunks/grid.chunks.js';
  171. $scripts[] = $versionx->config['js_url'].'mgr/snippets/panel.snippets.js';
  172. $scripts[] = $versionx->config['js_url'].'mgr/snippets/grid.snippets.js';
  173. $scripts[] = $versionx->config['js_url'].'mgr/plugins/panel.plugins.js';
  174. $scripts[] = $versionx->config['js_url'].'mgr/plugins/grid.plugins.js';
  175. $scripts[] = $versionx->config['js_url'].'mgr/action.index.js';
  176. break;
  177. }
  178. $scriptTags = '';
  179. foreach ($scripts as $url) {
  180. $scriptTags .= '<script type="text/javascript" src="'.$url.'?vxv='.urlencode($versionx->config['version']).'"></script>';
  181. }
  182. $modx->regClientStartupHTMLBlock($scriptTags);
  183. return '<div id="versionx"></div>';