OSDN Git Service

バージョン記載追加
[trpgtools-onweb/cake-frame.git] / app / controllers / site_configs_controller.php
1 <?php
2 /**
3  * PHP version 5
4  *
5  * @category Controller
6  * @package  Chara-Shee!
7  * @version  beta
8  * @author   Cake <cake_67@users.sourceforge.jp>
9  * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
10  * @link     http://trpgtools-onweb.sourceforge.jp/
11  */
12 class SiteConfigsController extends AppController {
13
14         var $name = 'SiteConfigs';
15         var $helpers = array(
16         );
17
18         var $disableTokenActions = array(
19         );
20
21         function beforeRender()
22         {
23                 parent::beforeRender();
24         }
25
26         function admin_edit() {
27                 if (!empty($this->data) && !empty($this->data['SiteConfig'])) {
28                         $error_flg = false;
29                         foreach($this->data['SiteConfig'] as $k => $v) {
30                                 if ($k == '__Token') {
31                                         continue;
32                                 }
33
34                                 if (CorePlus::is_valid($v, 'id')) {
35                                         $this->SiteConfig->id = $v['id'];
36                                         $fields = $this->SiteConfig->fields['edit'];
37                                 } else {
38                                         $v['key_name'] = $k;
39                                         $this->SiteConfig->create();
40                                         $fields = $this->SiteConfig->fields['add'];
41                                 }
42
43                                 if (
44                                         $k == 'Upload.imagefile.FileSizeMax' || 
45                                         $k == 'Upload.imagefile.WidthMax' || 
46                                         $k == 'Upload.imagefile.HeightMax'
47                                 ) {
48                                         $v['value'] = intval($v['value']);
49                                         if ($v['value'] < 0) {
50                                                 $v['value'] = NULL;
51                                         }
52                                 }
53
54                                 $data['SiteConfig'] = $v;
55
56                                 if (isset($this->data['design_submit'])) {
57                                         $this->SiteConfig->fields['escape']['value']['all'] = false;
58                                 }
59
60                                 if (!$this->SiteConfig->save($data, true, $fields)) {
61                                         $error_flg = true;
62                                         break;
63                                 }
64                         }
65
66                         if ($error_flg === true) {
67                                 $this->Session->setFlash(__('The data could not be saved. Please, try again.', true));
68                         } else {
69                                 $this->Session->setFlash(__('The SiteConfig has been saved', true));
70
71                                 if (isset($this->data['basic_submit'])) {
72                                         $sharp = 'basic';
73                                 } elseif (isset($this->data['upload_submit'])) {
74                                         $sharp = 'upload';
75                                 } elseif (isset($this->data['character_submit'])) {
76                                         $sharp = 'character';
77                                 } elseif (isset($this->data['system_submit'])) {
78                                         $sharp = 'system';
79                                 } elseif (isset($this->data['design_submit'])) {
80                                         $this->redirect(array('action'=>'edit_customcss'));
81                                 } else {
82                                         $sharp = null;
83                                 }
84
85                                 $this->redirect(array('action'=>'edit', '#' => $sharp));
86                         }
87                         unset($this->data['SiteConfig']['__Token']);
88                 }
89
90                 if (empty($this->data)) {
91                         $site_config = $this->site_configs;
92                         foreach($site_config as $k => $v) {
93                                 $site_config[$k] = $this->_restore_html_site_config($v);
94                         }
95
96                         $this->data['SiteConfig'] = $site_config;
97                 }
98
99                 $this->pageTitle .= " - ". __('Site Settings', true);
100         }
101
102         function admin_edit_customcss() {
103                 $site_config = $this->site_configs;
104                 foreach($site_config as $k => $v) {
105                         if ($k == 'Design.customCss') {
106                                 $this->data['SiteConfig'][$k] = $this->_restore_html_site_config($v, true);
107                                 break;
108                         }
109                 }
110
111                 $this->pageTitle .= " - ". __('Custom CSS', true);
112         }
113
114         function admin_delete_allcache() {
115                 if (isset($this->data['Cache']['DelConfirm']) && $this->data['Cache']['DelConfirm'] == 'yes') {
116                         $this->SiteConfig->deleteCacheAll();
117                         
118
119                         $this->Session->setFlash(__('All Cache has been deleted.', true));
120                         $this->redirect(array('controller' => 'site_configs', 'action'=>'edit_customcss'));
121                 }
122         }
123
124
125         /* restore_html */
126         function _restore_html_site_config($data, $nl2br = false) {
127                 $data['value'] = $this->{$this->modelClass}->restore_html($data['value'], false, false, false);
128                 if ($nl2br) {
129                         $data['value'] = str_replace('<br />', "\n", $data['value']);
130                 }
131
132                 return $data;
133         }
134
135 }
136 ?>