PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/files/edit.php

http://acp3.googlecode.com/
PHP | 145 lines | 112 code | 22 blank | 11 comment | 42 complexity | dafa3d11d048547a2b09f8d1b6a37c1d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Files
  4. *
  5. * @author Goratsch Webdesign
  6. * @package ACP3
  7. * @subpackage Modules
  8. */
  9. if (defined('IN_ADM') === false)
  10. exit;
  11. if (ACP3_Validate::isNumber($uri->id) === true && $db->countRows('*', 'files', 'id = \'' . $uri->id . '\'') == 1) {
  12. require_once MODULES_DIR . 'categories/functions.php';
  13. $settings = ACP3_Config::getModuleSettings('files');
  14. if (isset($_POST['submit']) === true) {
  15. if (isset($_POST['external'])) {
  16. $file = $_POST['file_external'];
  17. } elseif (!empty($_FILES['file_internal']['name'])) {
  18. $file['tmp_name'] = $_FILES['file_internal']['tmp_name'];
  19. $file['name'] = $_FILES['file_internal']['name'];
  20. $file['size'] = $_FILES['file_internal']['size'];
  21. }
  22. if (ACP3_Validate::date($_POST['start'], $_POST['end']) === false)
  23. $errors[] = $lang->t('common', 'select_date');
  24. if (strlen($_POST['link_title']) < 3)
  25. $errors['link-title'] = $lang->t('files', 'type_in_link_title');
  26. if (isset($_POST['external']) && (empty($file) || empty($_POST['filesize']) || empty($_POST['unit'])))
  27. $errors['external'] = $lang->t('files', 'type_in_external_resource');
  28. if (!isset($_POST['external']) && isset($file) && is_array($file) &&
  29. (empty($file['tmp_name']) || empty($file['size']) || $_FILES['file_internal']['error'] !== UPLOAD_ERR_OK))
  30. $errors['file-internal'] = $lang->t('files', 'select_internal_resource');
  31. if (strlen($_POST['text']) < 3)
  32. $errors['text'] = $lang->t('files', 'description_to_short');
  33. if (strlen($_POST['cat_create']) < 3 && categoriesCheck($_POST['cat']) === false)
  34. $errors['cat'] = $lang->t('files', 'select_category');
  35. if (strlen($_POST['cat_create']) >= 3 && categoriesCheckDuplicate($_POST['cat_create'], 'files') === true)
  36. $errors['cat-create'] = $lang->t('categories', 'category_already_exists');
  37. if (CONFIG_SEO_ALIASES === true && !empty($_POST['alias']) &&
  38. (ACP3_Validate::isUriSafe($_POST['alias']) === false || ACP3_Validate::uriAliasExists($_POST['alias'], 'files/details/id_' . $uri->id) === true))
  39. $errors['alias'] = $lang->t('common', 'uri_alias_unallowed_characters_or_exists');
  40. if (isset($errors) === true) {
  41. $tpl->assign('error_msg', errorBox($errors));
  42. } elseif (ACP3_Validate::formToken() === false) {
  43. ACP3_View::setContent(errorBox($lang->t('common', 'form_already_submitted')));
  44. } else {
  45. $new_file_sql = null;
  46. // Falls eine neue Datei angegeben wurde, Änderungen durchführen
  47. if (isset($file)) {
  48. if (is_array($file) === true) {
  49. $result = moveFile($file['tmp_name'], $file['name'], 'files');
  50. $new_file = $result['name'];
  51. $filesize = $result['size'];
  52. } else {
  53. $_POST['filesize'] = (float) $_POST['filesize'];
  54. $new_file = $file;
  55. $filesize = $_POST['filesize'] . ' ' . $db->escape($_POST['unit']);
  56. }
  57. // SQL Query für die Änderungen
  58. $new_file_sql = array(
  59. 'file' => $new_file,
  60. 'size' => $filesize,
  61. );
  62. }
  63. $update_values = array(
  64. 'start' => $date->timestamp($_POST['start']),
  65. 'end' => $date->timestamp($_POST['end']),
  66. 'category_id' => strlen($_POST['cat_create']) >= 3 ? categoriesCreate($_POST['cat_create'], 'files') : $_POST['cat'],
  67. 'link_title' => $db->escape($_POST['link_title']),
  68. 'text' => $db->escape($_POST['text'], 2),
  69. 'comments' => $settings['comments'] == 1 && isset($_POST['comments']) ? 1 : 0,
  70. 'user_id' => $auth->getUserId(),
  71. );
  72. if (is_array($new_file_sql) === true) {
  73. $old_file = $db->select('file', 'files', 'id = \'' . $uri->id . '\'');
  74. removeUploadedFile('files', $old_file[0]['file']);
  75. $update_values = array_merge($update_values, $new_file_sql);
  76. }
  77. $bool = $db->update('files', $update_values, 'id = \'' . $uri->id . '\'');
  78. if (CONFIG_SEO_ALIASES === true && !empty($_POST['alias']))
  79. ACP3_SEO::insertUriAlias('files/details/id_' . $uri->id, $_POST['alias'], $db->escape($_POST['seo_keywords']), $db->escape($_POST['seo_description']), (int) $_POST['seo_robots']);
  80. require_once MODULES_DIR . 'files/functions.php';
  81. setFilesCache($uri->id);
  82. $session->unsetFormToken();
  83. setRedirectMessage($bool !== false ? $lang->t('common', 'edit_success') : $lang->t('common', 'edit_error'), 'acp/files');
  84. }
  85. }
  86. if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
  87. $dl = $db->select('start, end, category_id, file, size, link_title, text, comments', 'files', 'id = \'' . $uri->id . '\'');
  88. $dl[0]['text'] = $db->escape($dl[0]['text'], 3);
  89. // Datumsauswahl
  90. $tpl->assign('publication_period', $date->datepicker(array('start', 'end'), array($dl[0]['start'], $dl[0]['end'])));
  91. $unit = trim(strrchr($dl[0]['size'], ' '));
  92. $units = array();
  93. $units[0]['value'] = 'Byte';
  94. $units[0]['selected'] = selectEntry('unit', 'Byte', $unit);
  95. $units[1]['value'] = 'KiB';
  96. $units[1]['selected'] = selectEntry('unit', 'KiB', $unit);
  97. $units[2]['value'] = 'MiB';
  98. $units[2]['selected'] = selectEntry('unit', 'MiB', $unit);
  99. $units[3]['value'] = 'GiB';
  100. $units[3]['selected'] = selectEntry('unit', 'GiB', $unit);
  101. $units[4]['value'] = 'TiB';
  102. $units[4]['selected'] = selectEntry('unit', 'TiB', $unit);
  103. $tpl->assign('units', $units);
  104. $dl[0]['filesize'] = substr($dl[0]['size'], 0, strpos($dl[0]['size'], ' '));
  105. // Formularelemente
  106. $tpl->assign('categories', categoriesList('files', $dl[0]['category_id'], true));
  107. if (ACP3_Modules::check('comments', 'functions') === true && $settings['comments'] == 1) {
  108. $options = array();
  109. $options[0]['name'] = 'comments';
  110. $options[0]['checked'] = selectEntry('comments', '1', $dl[0]['comments'], 'checked');
  111. $options[0]['lang'] = $lang->t('common', 'allow_comments');
  112. $tpl->assign('options', $options);
  113. }
  114. $tpl->assign('checked_external', isset($_POST['external']) ? ' checked="checked"' : '');
  115. $tpl->assign('current_file', $dl[0]['file']);
  116. $tpl->assign('SEO_FORM_FIELDS', ACP3_SEO::formFields('files/details/id_' . $uri->id));
  117. $tpl->assign('form', isset($_POST['submit']) ? $_POST : $dl[0]);
  118. $session->generateFormToken();
  119. ACP3_View::setContent(ACP3_View::fetchTemplate('files/edit.tpl'));
  120. }
  121. } else {
  122. $uri->redirect('errors/403');
  123. }