public function doEditOption() { try { // 检查权限 if (!$this->CurrentUser->isAdmin()) { throw new PermissionDeniedException('无权修改'); } if (Input::has('site-name')) { $val = Input::get('site-name'); $validator = Validator::make(array('站点名' => $val), array('站点名' => 'required|alpha_dash|min:3|max:20')); if ($validator->fails()) { throw new InvalidArgumentException($validator->messages()->first()); } $option = AmaotoOption::getOptionByKey('site-name'); $option->value = $val; $option->save(); } if (Input::has('copyright-name')) { $val = Input::get('copyright-name'); $validator = Validator::make(array('版权名' => $val), array('版权名' => 'required|alpha_dash|min:3|max:20')); if ($validator->fails()) { throw new InvalidArgumentException($validator->messages()->first()); } $option = AmaotoOption::getOptionByKey('copyright-name'); $option->value = $val; $option->save(); } if (Input::has('copyright-first-year')) { $val = Input::get('copyright-first-year'); $validator = Validator::make(array('建站年份' => $val), array('建站年份' => 'required|integer|min:1000|max:9999')); if ($validator->fails()) { throw new InvalidArgumentException($validator->messages()->first()); } $option = AmaotoOption::getOptionByKey('copyright-first-year'); $option->value = $val; $option->save(); } return Response::json(array('type' => 'success', 'message' => '修改成功')); } catch (InvalidArgumentException $e) { return Response::json(array('type' => 'warning', 'message' => $e->getMessage())); } catch (Exception $e) { return Response::json(array('type' => 'error', 'message' => $e->getMessage())); } }
<?php function _c(array $p = array()) { if (is_array($p)) { foreach ($p as $t) { if ($t) { return $t; } } } return NULL; } $array = array(); $array['installed'] = AmaotoOption::getValueByKey('installed'); $array['site-name'] = _c(array(AmaotoOption::getValueByKey('site-name'), 'Amaoto System')); $array['version'] = '0.8.141024'; $array['copyright-first-year'] = _c(array(AmaotoOption::getValueByKey('copyright-first-year'), date('Y'))); $array['copyright-year'] = $array['copyright-first-year'] == date('Y') ? $array['copyright-first-year'] : $array['copyright-first-year'] . '-' . date('Y'); $array['copyright-name'] = _c(array(AmaotoOption::getValueByKey('copyright-name'), 'Amaoto System')); return $array;