setup-options.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Script to interact with user during backupmodx package install
  4. *
  5. * Copyright 2018 by Jan Dähne <https://www.quadro-system.de>
  6. * Created on 10-19-2018
  7. *
  8. * backupmodx is free software; you can redistribute it and/or modify it under the
  9. * terms of the GNU General Public License as published by the Free Software
  10. * Foundation; either version 2 of the License, or (at your option) any later
  11. * version.
  12. *
  13. * backupmodx is distributed in the hope that it will be useful, but WITHOUT ANY
  14. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  15. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * backupmodx; if not, write to the Free Software Foundation, Inc., 59 Temple
  19. * Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * @package backupmodx
  22. */
  23. /**
  24. * Description: Script to interact with user during backupmodx package install
  25. * @package backupmodx
  26. * @subpackage build
  27. */
  28. /* The return value from this script should be an HTML form (minus the
  29. * <form> tags and submit button) in a single string.
  30. *
  31. * The form will be shown to the user during install
  32. *
  33. * This example presents an HTML form to the user with two input fields
  34. * (you can have as many as you like).
  35. *
  36. * The user's entries in the form's input field(s) will be available
  37. * in any php resolvers with $modx->getOption('field_name', $options, 'default_value').
  38. *
  39. * You can use the value(s) to set system settings, snippet properties,
  40. * chunk content, etc. based on the user's preferences.
  41. *
  42. * One common use is to use a checkbox and ask the
  43. * user if they would like to install a resource for your
  44. * component (usually used only on install, not upgrade).
  45. */
  46. /* This is an example. Modify it to meet your needs.
  47. * The user's input would be available in a resolver like this:
  48. *
  49. * $changeSiteName = (! empty($modx->getOption('change_sitename', $options, ''));
  50. * $siteName = $modx->getOption('sitename', $options, '').
  51. *
  52. * */
  53. $setting = $modx->getObject('modSystemSetting',array('key' => 'backupmodx.cronKey'));
  54. if ($setting != null) {
  55. $values['cronKey'] = $setting->get('value');
  56. }else {
  57. $values['cronKey'] = substr(md5(openssl_random_pseudo_bytes(20)),-12);
  58. }
  59. unset($setting);
  60. $setting = $modx->getObject('modSystemSetting',array('key' => 'backupmodx.targetPath'));
  61. if ($setting != null) {
  62. $values['targetPath'] = $setting->get('value');
  63. }else {
  64. $values['targetPath'] = '{core_path}components/backupmodx/backups/';
  65. }
  66. unset($setting);
  67. $output = '<style>.field_desc { color: #A0A0A0; font-size: 11px; font-style: italic; }</style>
  68. <div style="padding-bottom: 1rem;">
  69. <label for="apikey-server">Backup Target Path:</label>
  70. <input type="text" name="targetPath" id="targetpath" value="'.$values['targetPath'].'" align="left" size="40" maxlength="60" />
  71. <div class="field_desc">The path to the folder to store the backups. "{core_path} & {assets_path}" Placeholders are available.</div>
  72. </div>
  73. <div style="padding-bottom: 1rem;">
  74. <label for="apikey-server">Cron Security Key:</label>
  75. <input type="text" name="cronKey" id="cronkey" value="'.$values['cronKey'].'" align="left" size="40" />
  76. <div class="field_desc">Security-Key for cron scheduled Backups. Can be any string.</div>
  77. </div>';
  78. return $output;