admincp_templates.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_templates.php 29301 2012-04-01 02:55:08Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. cpheader();
  12. if(!isfounder()) cpmsg('noaccess_isfounder', '', 'error');
  13. $operation = empty($operation) ? 'admin' : $operation;
  14. if($operation == 'admin') {
  15. if(!submitcheck('tplsubmit')) {
  16. $templates = '';
  17. foreach(C::t('common_template')->fetch_all_data() as $tpl) {
  18. $basedir = basename($tpl['directory']);
  19. $templates .= showtablerow('', array('class="td25"', '', 'class="td29"'), array(
  20. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" ".($tpl['templateid'] == 1 ? 'disabled ' : '')."value=\"$tpl[templateid]\">",
  21. "<input type=\"text\" class=\"txt\" size=\"8\" name=\"namenew[$tpl[templateid]]\" value=\"$tpl[name]\">".
  22. ($basedir != 'default' ? '<a href="'.ADMINSCRIPT.'?action=cloudaddons&id='.urlencode($basedir).'.template" target="_blank" title="'.$lang['cloudaddons_linkto'].'">'.$lang['view'].'</a>' : ''),
  23. "<input type=\"text\" class=\"txt\" size=\"20\" name=\"directorynew[$tpl[templateid]]\" value=\"$tpl[directory]\">",
  24. !empty($tpl['copyright']) ?
  25. $tpl['copyright'] :
  26. "<input type=\"text\" class=\"txt\" size=\"8\" name=\"copyrightnew[$tpl[templateid]]\" value=>"
  27. ), TRUE);
  28. }
  29. shownav('style', 'templates_admin');
  30. showsubmenu('templates_admin');
  31. showformheader('templates');
  32. showtableheader();
  33. showsubtitle(array('', 'templates_admin_name', 'dir', 'copyright'));
  34. echo $templates;
  35. echo '<tr><td>'.$lang['add_new'].'</td><td><input type="text" class="txt" size="8" name="newname"></td><td class="td29"><input type="text" class="txt" size="20" name="newdirectory"></td><td><input type="text" class="txt" size="25" name="newcopyright"></td><td>&nbsp;</td></tr>';
  36. showsubmit('tplsubmit', 'submit', 'del');
  37. showtablefooter();
  38. showformfooter();
  39. } else {
  40. if($_GET['newname']) {
  41. if(!$_GET['newdirectory']) {
  42. cpmsg('tpl_new_directory_invalid', '', 'error');
  43. } elseif(!istpldir($_GET['newdirectory'])) {
  44. $directory = $_GET['newdirectory'];
  45. cpmsg('tpl_directory_invalid', '', 'error', array('directory' => $directory));
  46. }
  47. C::t('common_template')->insert(array('name' => $_GET['newname'], 'directory' => $_GET['newdirectory'], 'copyright' => $_GET['newcopyright']));
  48. }
  49. foreach($_GET['directorynew'] as $id => $directory) {
  50. if(!$_GET['delete'] || ($_GET['delete'] && !in_array($id, $_GET['delete']))) {
  51. if(!istpldir($directory)) {
  52. cpmsg('tpl_directory_invalid', '', 'error', array('directory' => $directory));
  53. } elseif($id == 1 && $directory != './template/default') {
  54. cpmsg('tpl_default_directory_invalid', '', 'error');
  55. }
  56. C::t('common_template')->update($id, array('name' => $_GET['namenew'][$id], 'directory' => $_GET['directorynew'][$id]));
  57. if(!empty($_GET['copyrightnew'][$id])) {
  58. $template = C::t('common_template')->fetch($id);
  59. if(!$template['copyright']) {
  60. C::t('common_template')->update($id, array('copyright' => $_GET['copyrightnew'][$id]));
  61. }
  62. }
  63. }
  64. }
  65. if(is_array($_GET['delete'])) {
  66. if(in_array('1', $_GET['delete'])) {
  67. cpmsg('tpl_delete_invalid', '', 'error');
  68. }
  69. if($_GET['delete']) {
  70. C::t('common_template')->delete($_GET['delete']);
  71. C::t('common_style')->update($_GET['delete'], array('templateid' => 1));
  72. }
  73. }
  74. updatecache('styles');
  75. cpmsg('tpl_update_succeed', 'action=templates', 'succeed');
  76. }
  77. }
  78. ?>