PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/concrete/single_pages/dashboard/system/multilingual/copy.php

http://github.com/concrete5/concrete5
PHP | 162 lines | 146 code | 16 blank | 0 comment | 16 complexity | 3ab4c40f8da8e5930be1f81475b45897 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php defined('C5_EXECUTE') or die("Access Denied."); ?>
  2. <?php
  3. use Concrete\Core\Multilingual\Page\Section\Section as MultilingualSection;
  4. ?>
  5. <?php if (count($locales) > 1) {
  6. ?>
  7. <fieldset>
  8. <legend><?php echo t('Copy Locale Tree') ?></legend>
  9. <?php
  10. $u = Core::make(Concrete\Core\User\User::class);
  11. $copyLocales = array();
  12. foreach ($locales as $pc) {
  13. $copyLocales[$pc->getSiteTree()->getSiteHomePageID()] = tc(/*i18n: %1$s is a page name, %2$s is a language name, %3$s is a locale identifier (eg en_US)*/
  14. 'PageWithLocale', '%1$s (%2$s)', $pc->getLanguageText(), $pc->getLocale());
  15. }
  16. if ($u->isSuperUser()) { ?>
  17. <form method="post" id="ccm-internationalization-copy-tree" action="#">
  18. <?php if (count($locales) > 1) {
  19. $copyLocaleSelect1 = $form->select('copyTreeFrom', $copyLocales);
  20. $copyLocaleSelect2 = $form->select('copyTreeTo', $copyLocales);
  21. ?>
  22. <p><?php echo t('Copy all pages from a locale to another section. This will only copy pages that have not been associated. It will not replace or remove any pages from the destination section.') ?></p>
  23. <div class="form-group">
  24. <label class="control-label"><?php echo t('Copy From') ?></label>
  25. <?php echo $copyLocaleSelect1 ?>
  26. </div>
  27. <div class="form-group">
  28. <label class="control-label"><?php echo tc('Destination', 'To') ?></label>
  29. <?php echo $copyLocaleSelect2 ?>
  30. </div>
  31. <?php echo Loader::helper('validation/token')->output('copy_tree') ?>
  32. <button class="btn btn-default pull-left" type="submit" name="copy"><?= t('Copy Tree') ?></button>
  33. <?php
  34. } elseif (count($locales) == 1) {
  35. ?>
  36. <p><?php echo t("You must have more than one locale to use this tool.") ?></p>
  37. <?php
  38. } else {
  39. ?>
  40. <p><?php echo t('You have not created any multilingual content sections yet.') ?></p>
  41. <?php
  42. }
  43. ?>
  44. <script type="text/javascript">
  45. $(function () {
  46. $("#ccm-internationalization-copy-tree").on('submit', function () {
  47. var ctf = $('select[name=copyTreeFrom]').val();
  48. var ctt = $('select[name=copyTreeTo]').val();
  49. if (ctt > 0 && ctf > 0 && ctt != ctf) {
  50. ccm_triggerProgressiveOperation(
  51. CCM_DISPATCHER_FILENAME + '/ccm/system/dialogs/page/drag_request/copy_all',
  52. [
  53. {'name': 'origCID', 'value': ctf},
  54. {'name': 'destCID', 'value': ctt},
  55. {'name': 'copyChildrenOnly', 'value': true},
  56. {'name': 'multilingual', 'value': true},
  57. {name: <?= json_encode($token::DEFAULT_TOKEN_NAME) ?>, value: <?= json_encode($token->generate('/dialogs/page/drag_request'))?>}
  58. ],
  59. <?= json_encode(t('Copy Locale Tree')) ?>,
  60. function () {
  61. window.location.href = <?=json_encode((string) $this->action('tree_copied')) ?>;
  62. }
  63. );
  64. } else {
  65. alert(<?= json_encode(t('You must choose two separate multilingual sections to copy from/to')) ?>);
  66. }
  67. return false;
  68. });
  69. });
  70. </script>
  71. </form>
  72. <?php
  73. } elseif (!$u->isSuperUser()) {
  74. ?>
  75. <p><?= t('Only the super user may copy locale trees.') ?></p>
  76. <?php } ?>
  77. </fieldset>
  78. <hr/>
  79. <fieldset>
  80. <legend><?php echo t('Rescan Multilingual Tree') ?></legend>
  81. <?php
  82. if ($u->isSuperUser()) {
  83. ?>
  84. <form method="post" id="ccm-internationalization-rescan-tree" action="#">
  85. <?php if (count($locales) > 1) {
  86. ?>
  87. <p><?php echo t('Scans all blocks within the selected section. Any links to pages within another multilingual section will be updated to link to the pages within the selected tree. Any blocks within the scanned section that reference pages in another multilingual section will be updated to point to the page within the selected tree.') ?></p>
  88. <div class="form-group">
  89. <label class="control-label"><?php echo t('Rescan Locale') ?></label>
  90. <?php echo $form->select('rescanLocale', $copyLocales);
  91. ?>
  92. </div>
  93. <?php echo Loader::helper('validation/token')->output('rescan_locale') ?>
  94. <button class="btn btn-default pull-left" type="submit"
  95. name="rescan_locale"><?= t('Rescan Locale') ?></button>
  96. <?php
  97. } elseif (count($pages) == 1) {
  98. ?>
  99. <p><?php echo t("You must have more than one multilingual section to use this tool.") ?></p>
  100. <?php
  101. } else {
  102. ?>
  103. <p><?php echo t('You have not created any multilingual content sections yet.') ?></p>
  104. <?php
  105. }
  106. ?>
  107. <script type="text/javascript">
  108. $(function () {
  109. $("#ccm-internationalization-rescan-tree").on('submit', function () {
  110. var ctf = $('select[name=rescanLocale]').val();
  111. if (ctf > 0) {
  112. ccm_triggerProgressiveOperation(
  113. '<?=$view->action('rescan_locale')?>',
  114. [
  115. {'name': 'locale', 'value': ctf},
  116. {
  117. 'name': 'ccm_token',
  118. 'value': '<?=Core::make('token')->generate('rescan_locale')?>'
  119. }
  120. ],
  121. "<?=t('Rescan Links')?>",
  122. function () {
  123. window.location.href = "<?=$this->action('links_rescanned')?>";
  124. }
  125. );
  126. }
  127. return false;
  128. });
  129. });
  130. </script>
  131. </form>
  132. <?php
  133. } elseif (!$u->isSuperUser()) {
  134. ?>
  135. <p><?= t('Only the super user may rescan the links inside a multilingual tree.') ?></p>
  136. <?php
  137. }
  138. ?>
  139. </fieldset>
  140. <?php
  141. } else {
  142. ?>
  143. <p><?php echo t('You have not created any multilingual content sections yet.');
  144. ?></p>
  145. <?php
  146. } ?>