base.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. */
  21. require_once dirname(__DIR__).'/model/versionx.class.php';
  22. abstract class VersionXBaseManagerController extends modExtraManagerController {
  23. /** @var VersionX */
  24. protected $versionx;
  25. public $targetClass = null;
  26. public function initialize()
  27. {
  28. $this->versionx = new VersionX($this->modx);
  29. $this->addHtml('
  30. <script type="text/javascript">
  31. Ext.onReady(function() {
  32. VersionX.config = '.$this->modx->toJSON($this->versionx->config).';
  33. });
  34. </script>
  35. <style type="text/css">
  36. .vx-added {
  37. color: #007500;
  38. font-weight: bold !important;
  39. }
  40. .vx-removed {
  41. color: #750300;
  42. font-weight: bold !important;
  43. }
  44. .vx-error-panel {
  45. background: #ffdbdb;
  46. padding: 1em;
  47. border: 1px solid #830000;
  48. border-radius: 3px;
  49. color: #5a2a2a;
  50. }
  51. </style>');
  52. $this->addJavascript($this->versionx->config['js_url'].'mgr/versionx.class.js');
  53. $this->addJavascript($this->versionx->config['js_url'].'mgr/common/json2.js');
  54. $this->addJavascript($this->versionx->config['assets_url'].'node_modules/diff/dist/diff.js');
  55. $versionid = isset($_REQUEST['vid']) ? (int)$_REQUEST['vid'] : false;
  56. $compareid = isset($_REQUEST['cmid']) ? (int)$_REQUEST['cmid'] : false;
  57. /* If an ID was passed, fetch that version into a record array. */
  58. if ($versionid > 0) {
  59. $v = $this->versionx->getVersionDetails($this->targetClass, $versionid, true);
  60. if ($v !== false) {
  61. $this->addHtml('<script type="text/javascript">VersionX.record = ' . $v . '; </script>');
  62. }
  63. }
  64. /* If an ID to compare to was passed, fetch that aswell. */
  65. if ($compareid > 0) {
  66. $v = $this->versionx->getVersionDetails($this->targetClass, $compareid, true);
  67. if ($v !== false) {
  68. $this->addHtml('<script type="text/javascript">VersionX.cmrecord = ' . $v . '; </script>');
  69. }
  70. }
  71. }
  72. public function getLanguageTopics()
  73. {
  74. return [
  75. 'versionx:default'
  76. ];
  77. }
  78. public function getPageTitle()
  79. {
  80. return $this->modx->lexicon('versionx');
  81. }
  82. public function getTemplateFile()
  83. {
  84. return $this->versionx->config['core_path'] . 'templates/mgr/versionx.tpl';
  85. }
  86. }