CMSimple_XH 開発者ドキュメント
TextFileEdit.php
1 <?php
2 
16 namespace XH;
17 
28 abstract class TextFileEdit extends FileEdit
29 {
35  protected $textareaName = null;
36 
42  protected $text = null;
43 
47  public function __construct()
48  {
49  $contents = XH_readFile($this->filename);
50  if ($contents !== false) {
51  $this->text = $contents;
52  } else {
53  e('cntopen', 'file', $this->filename);
54  $this->text = '';
55  }
56  }
57 
68  public function form()
69  {
71 
72  $title = $this->caption;
73  $action = isset($this->plugin) ? $sn . '?&amp;' . $this->plugin : $sn;
74  $value = utf8_ucfirst($tx['action']['save']);
75  if (isset($_GET['xh_success'])) {
76  $filetype = utf8_ucfirst($tx['filetype'][stsl($_GET['xh_success'])]);
77  $message = XH_message('success', $tx['message']['saved'], $filetype);
78  } else {
79  $message = '';
80  }
81  $button = '<input type="submit" class="submit" value="' . $value . '">';
82  $o = '<h1>' . $this->caption . '</h1>' . $message
83  . '<form action="' . $action . '" method="post">'
84  . '<textarea rows="25" cols="80" name="' . $this->textareaName
85  . '" class="xh_file_edit">'
86  . XH_hsc($this->text)
87  . '</textarea>';
88  foreach ($this->params as $param => $value) {
89  $o .= '<input type="hidden" name="' . $param . '" value="'
90  . $value . '">';
91  }
92  $o .= $_XH_csrfProtection->tokenInput()
93  . $button . '</form>';
94  return $o;
95  }
96 
107  public function submit()
108  {
109  global $_XH_csrfProtection;
110 
111  $_XH_csrfProtection->check();
112  $this->text = stsl($_POST[$this->textareaName]);
113  if ($this->save() !== false) {
114  header('Location: ' . CMSIMPLE_URL . $this->redir, true, 303);
115  XH_exit();
116  } else {
117  e('cntsave', 'file', $this->filename);
118  return $this->form();
119  }
120  }
121 
127  protected function asString()
128  {
129  return $this->text;
130  }
131 }
$action
Definition: cms.php:460
XH_readFile($filename)
Definition: functions.php:1601
const CMSIMPLE_URL
Definition: cms.php:761
utf8_ucfirst($string)
Definition: utf8.php:118
$title
Definition: cms.php:100
XH_exit($status=0)
Definition: functions.php:2401
$o
Definition: cms.php:113
e($et, $ft, $fn)
Definition: functions.php:655
$sn
Definition: cms.php:434
foreach(XH_plugins() as $plugin) $_XH_csrfProtection
Definition: cms.php:879
$tx
Definition: cms.php:363
stsl($t)
Definition: functions.php:606
$text
Definition: cms.php:698
XH_hsc($string)
Definition: functions.php:2204
XH_message($type, $message)
Definition: functions.php:1806