template_bak.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_class('admin', 'admin', 0);
  4. class template_bak extends admin {
  5. private $db, $style, $dir, $filename, $filepath, $fileid;
  6. public function __construct() {
  7. parent::__construct();
  8. $this->style = isset($_GET['style']) && trim($_GET['style']) ? str_replace(array('..\\', '../', './', '.\\', '/', '\\'), '', trim($_GET['style'])) : showmessage(L('illegal_operation'));
  9. $this->dir = isset($_GET['dir']) && trim($_GET['dir']) ? trim(urldecode($_GET['dir'])) : showmessage(L('illegal_operation'));
  10. $this->dir = safe_replace($this->dir);
  11. $this->filename = isset($_GET['filename']) && trim($_GET['filename']) ? trim($_GET['filename']) : showmessage(L('illegal_operation'));
  12. if (empty($this->style) || empty($this->dir) || empty($this->filename)) {
  13. showmessage(L('illegal_operation'), HTTP_REFERER);
  14. }
  15. $this->filepath = PC_PATH.'templates'.DIRECTORY_SEPARATOR.$this->style.DIRECTORY_SEPARATOR.$this->dir.DIRECTORY_SEPARATOR.$this->filename;
  16. $this->fileid = $this->style.'_'.$this->dir.'_'.$this->filename;
  17. $this->tpl_edit = pc_base::load_config('system', 'tpl_edit');
  18. $this->db = pc_base::load_model('template_bak_model');
  19. }
  20. public function init() {
  21. if($this->tpl_edit == '0'){
  22. showmessage(L('tpl_edit'), HTTP_REFERER);
  23. }
  24. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  25. $list = $this->db->listinfo(array('fileid'=>$this->fileid), 'creat_at desc', $page, 20);
  26. if (!$list) {
  27. showmessage(L('not_exist_versioning'), 'blank');
  28. }
  29. $pages = $this->db->pages;
  30. $show_header = true;
  31. pc_base::load_sys_class('format', '', 0);
  32. include $this->admin_tpl('template_bak_list');
  33. }
  34. public function restore() {
  35. $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_operation'), HTTP_REFERER);
  36. if ($data = $this->db->get_one(array('id'=>$id))) {
  37. if (!is_writable($this->filepath)) {
  38. showmessage(L("file_does_not_writable"), HTTP_REFERER);
  39. }
  40. if (@file_put_contents($this->filepath, $data['template'])) {
  41. showmessage(L('operation_success'), HTTP_REFERER, '', 'history');
  42. } else {
  43. showmessage(L('operation_success'), HTTP_REFERER, '', 'history');
  44. }
  45. } else {
  46. showmessage(L('notfound'), HTTP_REFERER);
  47. }
  48. }
  49. public function del() {
  50. $id = isset($_GET['id']) && intval($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_operation'), HTTP_REFERER);
  51. if ($data = $this->db->get_one(array('id'=>$id))) {
  52. $this->db->delete(array('id'=>$id));
  53. showmessage(L('operation_success'), HTTP_REFERER);
  54. } else {
  55. showmessage(L('notfound'), HTTP_REFERER);
  56. }
  57. }
  58. }
  59. ?>