6 App::import('Vendor', 'pear_ini');
7 App::import('Vendor', 'Net_UserAgent_Mobile', array('file' => 'Net' . DS . 'UserAgent' . DS . 'Mobile.php'));
12 $this->agent = &Net_UserAgent_Mobile::factory();
13 if (!$this->agent->isNonMobile()) {
14 Configure::write('mobileUserAgent', true);
17 class AppController extends Controller
19 var $user = array('User' => array(
24 var $isAdministrator = false;
26 var $isMobile = false;
28 var $site_configs = array();
30 var $components = array(
32 'Cakeplus.HtmlEscape',
53 var $conditions = array(
54 'Character.public_flag' => 'public',
55 'Character.deleted' => 0
59 'Character.system_id',
62 'Character.main_picture',
63 'Character.sort_order',
65 'Character.public_flag',
68 var $contain = array();
71 'Character.modified' => 'DESC',
73 var $paginate = array(
76 'conditions' => array(
77 'Character.public_flag' => 'public',
78 'Character.deleted' => 0
82 'Character.modified' => 'DESC',
87 var $cacheAction = array();
89 // POSTのTokenチェックをしないアクション
90 var $disableTokenActions = array();
92 function __construct() {
93 if (Configure::read('mobileUserAgent')) {
94 Configure::write('Session.save', 'sessino_m_custom');
97 parent::__construct();
100 function beforeFilter()
102 $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' .' beforeFilterStart');
104 parent::beforeFilter();
106 $this->user['User']['name'] = __('Guest', true);
109 $this->disableCache();
111 if (isset($this->params['prefix'])) {
112 if ($this->params['prefix'] == Configure::read('Routing.admin')) {
113 $this->isAdmin = true;
114 $this->layout = 'admin_'.$this->layout;
115 } elseif ($this->params['prefix'] == 'm') {
116 $this->isMobile = true;
119 $this->set('admin', $this->isAdmin);
122 $this->site_configs = CorePlus::set_db_settings();
123 $this->set('site_configs', $this->site_configs);
125 if ($this->AuthPlus) {
127 // $this->AuthPlus->actionPath = 'controllers/';
128 // $this->AuthPlus->authorize = 'crud';
129 $this->AuthPlus->authorize = 'orig';
131 $this->user_id = $this->AuthPlus->user('id');
132 $user = $this->getUser($this->user_id);
137 if (in_array($this->AuthPlus->user('group_id'), array(1,2,3))) {
138 $this->isAdministrator = true;
142 $this->Token->checkToken();
145 if (Configure::read('mobileUserAgent')) {
146 $this->AuthPlus->loginAction = '/m/users/login';
147 $this->AuthPlus->loginRedirect = '/m/users/index';
148 $this->AuthPlus->logoutRedirect = '/m/users/index';
150 $this->AuthPlus->loginAction = '/users/login';
151 $this->AuthPlus->loginRedirect = '/users/index';
152 $this->AuthPlus->logoutRedirect = '/users/index';
154 if ($this->isAdmin) {
155 $this->AuthPlus->loginRedirect = '/admin/users/index';
158 $this->set('user', $this->user);
159 $this->set('isAdministrator', $this->isAdministrator);
161 $this->pageTitle = $this->site_configs['Site.siteName']['value'];
164 function beforeRender()
166 $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' . ' beforeRenderStart');
167 parent::beforeRender();
170 function afterFilter()
172 $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' . ' afterFilterStart');
173 parent::afterFilter();
177 /* public_flag設定をview用にセット */
178 function set_public_flag4view()
180 $model_public_flags = $this->get_public_flag();
182 $this->set('public_flags', $model_public_flags);
184 function get_public_flag()
186 return $this->{$this->modelClass}->public_flag;
188 function check_public_flag($data, $key = null)
190 return CorePlus::check_public_flag($data, $key);
192 function check_public_flag2($data, $key = null)
194 return CorePlus::check_public_flag2($data, $key);
197 /* status設定をview用にセット */
198 function set_status4view()
200 $model_status = $this->get_status();
202 $this->set('status', $model_status);
204 function get_status()
206 if (isset($this->Character)) {
207 return $this->Character->status;
208 } elseif (isset($this->CharacterProfileArchive)) {
209 return $this->CharacterProfileArchive->Character->status;
216 function isOwner($data, $user_id)
218 return CorePlus::isOwner($data, $user_id);
222 function getUser($id, $isAdmin=false, $isDelete=false) {
227 if (!isset($this->User)) {
228 $this->User = CorePlus::set_model('User');
234 if ($isAdmin === true) {
235 $conditions['User.group_id'] = array(
236 Configure::read('Group.admin'),
237 Configure::read('Group.subadmin'),
238 Configure::read('Group.watcher'),
239 Configure::read('Group.member'),
240 Configure::read('Group.locked'),
241 Configure::read('Group.pre'),
244 $conditions['User.group_id'] = array(
245 Configure::read('Group.admin'),
246 Configure::read('Group.subadmin'),
247 Configure::read('Group.watcher'),
248 Configure::read('Group.member'),
249 Configure::read('Group.locked'),
263 if ($isAdmin === true) {
264 $fields = array_merge($fields, array(
275 if ($isAdmin === true || $isDelete === true) {
276 $contain = array_merge($contain, array(
280 unset($this->User->hasMany['Character']['conditions']['Character.public_flag']);
281 unset($this->User->hasMany['Character']['limit']);
284 if (empty($contain)) {
287 $recursive = Set::countDim($contain);
290 $user = $this->User->find('first', array(
291 'conditions' => $conditions,
293 'recursive' => $recursive,
294 'contain' => $contain,
301 function _check_demo()
303 if (Configure::read('Mode.Demo')) {
304 if ($_SESSION['Auth']['User']['username'] == 'guest') {
305 $this->Session->setFlash(__('NO AVAILABLE NOW.', true));
306 $this->redirect(array('action'=>'index'));
312 function _restore_html_system($data) {
313 if (isset($data['System']['name']) && !empty($data['System']['name'])) {
314 $data['System']['name'] = $this->{$this->modelClass}->restore_html($data['System']['name'], false, false, false);
316 if (isset($data['System']['copyright']) && !empty($data['System']['copyright'])) {
317 $data['System']['copyright'] = $this->{$this->modelClass}->restore_html($data['System']['copyright'], false, false, false);
319 if (isset($data['System']['url']) && !empty($data['System']['url'])) {
320 $data['System']['url'] = $this->{$this->modelClass}->restore_html($data['System']['url'], false, false, false);
322 if (isset($data['System']['detail']) && !empty($data['System']['detail'])) {
323 $data['System']['detail'] = $this->{$this->modelClass}->restore_html($data['System']['detail'], false, false, false);
326 if (isset($data['Profile']) && !empty($data['Profile'])) {
327 $data = $this->_restore_html_profile($data);
333 function _get_systems($public_flag = 'public')
335 $conditions = array();
336 if (!empty($public_flag)) {
337 $conditions['System.public_flag'] = $public_flag;
340 if (!isset($this->System)) {
341 $this->System = CorePlus::set_model('System');
344 $systems = $this->System->find('list', array(
345 'conditions' => $conditions,
348 if (!empty($systems)) {
349 foreach ($systems as $k => $v) {
350 $systems[$k] = $this->{$this->modelClass}->restore_html($v);
359 function _set_conditions_characters4user_id($user_id = null, $conditions = array(), $fields = array(), $contain = array(), $order = array())
361 if (!empty($user_id)) {
362 $conditions = array_merge((array)$conditions,
364 'Character.user_id' => $user_id,
369 $conditions = array_merge($this->conditions, (array)$conditions);
371 if ((isset($conditions['isAdmin']))|| (!empty($user_id) && ($user_id == $this->user_id))) {
372 unset($conditions['Character.public_flag']);
373 unset($conditions['isAdmin']);
376 $fields = array_merge($this->fields, (array)$fields);
379 $contain = array_merge($this->contain, (array)$contain);
380 if (empty($contain)) {
383 $recursive = Set::countDim($contain);
386 $order = array_merge($this->order, (array)$order);
388 return array($conditions, $fields, $contain, $recursive, $order);
391 function _get_characters_list4user_id($user_id = null, $conditions = array(), $limit = 5, $fields = array(), $contain = array(), $order = array())
393 list($conditions, $fields, $contain, $recursive, $order) = $this->_set_conditions_characters4user_id($user_id, $conditions, $fields, $contain, $order);
395 if (!isset($this->Character)) {
396 $this->Character = CorePlus::set_model('Character');
399 return $this->Character->find('all', array(
400 'conditions' => $conditions,
403 'recursive' => $recursive,
404 'contain' => $contain,
409 function _get_characters_page4user_id($user_id = null, $conditions = array(), $limit = 20, $fields = array(), $contain = array(), $order = array(), $page = 1)
411 list($conditions, $fields, $contain, $recursive, $order) = $this->_set_conditions_characters4user_id($user_id, $conditions, $fields, $contain, $order);
413 if (!isset($this->Character)) {
414 $this->Character = CorePlus::set_model('Character');
417 $this->paginate['Character'] = array(
419 'conditions' => $conditions,
421 'contain' => $contain,
422 'recursive' => $recursive,
427 return $this->paginate('Character');
432 function _get_character4character_id($character_id, $user_id = null, $public_flag = null, $is_deleted = 0)
434 if (!isset($this->Character)) {
435 $this->Character = CorePlus::set_model('Character');
439 'Character.id' => $character_id,
440 'Character.deleted' => $is_deleted,
443 $conditions['Character.user_id'] = $user_id;
446 unset($this->Character->hasMany['CharacterPicture']['conditions']['CharacterPicture.public_flag']);
448 $conditions['Character.public_flag'] = $public_flag;
449 $this->Character->hasMany['CharacterPicture']['conditions']['CharacterPicture.public_flag'] = $public_flag;
452 $character = $this->Character->find('first', array(
453 'conditions' => $conditions,
455 'CharacterPicture' => array(
461 if (empty($character)) {
462 $this->Session->setFlash(__('Invalid Character.', true));
463 $this->redirect(array('controller' => 'characters', 'action'=>'index'));
468 function check_character_picture_max($character_pictures_num)
470 if (!$max_num = intval($this->site_configs['Character.maxPictures']['value'])) {
474 if ($max_num <= $character_pictures_num) {
482 function _restore_html_user($data, $nl2br = false) {
483 $data['name'] = $this->{$this->modelClass}->restore_html($data['name'], false, false, false);
485 if (isset($data['notes']) && !empty($data['notes'])) {
486 $data['notes'] = $this->{$this->modelClass}->restore_html($data['notes'], false, false, false);
488 $data['notes'] = str_replace('<br />', "\n", $data['notes']);
493 $data = $this->decrypt_mail($data);
498 function decrypt_mail($data)
500 if (isset($data['pcmail']) && !empty($data['pcmail'])) {
501 $data['pcmail'] = $this->Crypt->decrypt($data['pcmail']);
506 /* Profile系 htmlRestore */
507 function _restore_html_profile($data) {
508 if (isset($data['Profile']['name']) && !empty($data['Profile']['name'])) {
509 $data['Profile']['name'] = $this->{$this->modelClass}->restore_html($data['Profile']['name'], false, false, false);
512 if (isset($data['Profile'][0]['ProfileSelect'])) {
513 foreach ($data['Profile'] as $k => $v) {
514 $data['Profile'][$k] = $this->__restore_html_profile($v);
516 $data['Profile'] = $this->_restore_html_profiles($data['Profile']);
518 } elseif($data['Profile']['ProfileSelect']) {
519 $data['Profile'] = $this->__restore_html_profile($data['Profile']);
524 function __restore_html_profile($data) {
525 if (isset($data['ProfileSelect']) && !empty($data['ProfileSelect'])) {
526 $data['ProfileSelect'] = $this->_restore_html_profile_select($data['ProfileSelect']);
528 if (isset($data['ProfileTable']) && !empty($data['ProfileTable'])) {
529 $data['ProfileTable'] = $this->_restore_html_profile_table($data['ProfileTable']);
531 if (isset($data['ProfileTableStatic']) && !empty($data['ProfileTableStatic'])) {
532 $data['ProfileTableStatic'] = $this->_restore_html_profile_table_static($data['ProfileTableStatic']);
537 function _restore_html_profiles($data) {
538 $sort_order = array();
539 foreach ($data as $k => $v) {
540 if (isset($v['value']) && !empty($v['value'])) {
541 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
544 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
545 $sort_order[$k] = $v['sort_order'];
551 $data = $this->sort4sort_order($data, $sort_order);
555 function _restore_html_profile_select($data) {
556 $sort_order = array();
557 foreach ($data as $k => $v) {
558 if (isset($v['value']) && !empty($v['value'])) {
559 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
562 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
563 $sort_order[$k] = $v['sort_order'];
569 $data = $this->sort4sort_order($data, $sort_order);
573 function _restore_html_profile_table($data) {
574 foreach ($data as $k => $v) {
575 if (isset($v['value']) && !empty($v['value'])) {
576 $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
579 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
580 $sort_order[$k] = $v['sort_order'];
586 $data = $this->sort4sort_order($data, $sort_order);
590 function _restore_html_profile_table_static($data) {
591 foreach ($data as $k => $v) {
592 if (isset($v['title']) && !empty($v['title'])) {
593 $data['ProfileTableStatic'][$k]['title'] = $this->{$this->modelClass}->restore_html($v['title'], false, false, false);
596 if (isset($v['sort_order']) && !empty($v['sort_order'])) {
597 $sort_order[$k] = $v['sort_order'];
603 $data = $this->sort4sort_order($data, $sort_order);
608 function sort4sort_order($data, $sort_order)
610 if (empty($data) || empty($sort_order)) {
613 array_multisort($sort_order, SORT_ASC, $data);
620 // AppControllerを携帯とPCで振り分け
621 if (Configure::read('mobileUserAgent')) {
622 class ModuleController extends MobileAppController
626 class ModuleController extends PcAppController
634 class MobileAppController extends AppController
636 function beforeFilter()
638 parent::beforeFilter();
641 if (!Configure::read('Mode.Mobile')) {
642 exit("Mobile View is inavailable.");
646 if (!isset($this->params["prefix"])) {
648 if ($this->params["url"]["url"] == "/") {
649 $this->redirect("/m/");
651 $this->cakeError("errorPcView");
655 @array_walk_recursive($this->data, "convertEncodeSjis2Utf8");
658 function beforeRender()
660 parent::beforeRender();
662 $this->layout = 'mobile_'.$this->layout;
665 function afterFilter()
667 parent::afterFilter();
670 $this->output = mb_convert_kana($this->output, "rak", Configure::read('App.encoding'));
672 $this->output = mb_convert_encoding($this->output, "SJIS", Configure::read('App.encoding'));
680 class PcAppController extends AppController
682 function beforeFilter()
684 parent::beforeFilter();
686 // 携帯用アクションへのアクセスはPC用に変更
687 if (isset($this->params["prefix"]) && $this->params["prefix"] == "mobile") {
688 $pc_url = substr_replace($this->params["url"]["url"], "", 0, 2+strlen($this->params["controller"])+1);
691 $pc_url = substr_replace($this->params['action'], "", 0, strlen($this->params["prefix"])+1);
694 $this->redirect($pc_url);
698 function beforeRender()
700 parent::beforeRender();
712 * 文字コード変換 SJISWin->UTF-8
714 function convertEncodeSjis2Utf8(&$str, $key)
716 $str = mb_convert_encoding($str, 'UTF-8', 'SJIS-Win');