/** * 转换编码 */ public function actionIconv() { $request = Yii::app()->request; if (!$request->isPostRequest) { throw new CHttpException(400, "Invalid request type"); } $pageName = $request->getParam('pageName'); $from = $request->getParam('from'); $to = $request->getParam('to'); if (!$pageName || !$from || !$to) { throw new CHttpException(404, "Invalid params"); } $user = User::getCurrentLoginUser(); $page = $user->repository->getPageByName($pageName); if (!$page) { throw new CHttpException(404, "Page not found"); } ob_start(); $cmd = sprintf('iconv -f "%s" -t "%s" "%s"', $from, $to, $page->path); system($cmd, $return); $converted = ob_get_contents(); ob_end_clean(); if ($return != 0) { throw new CHttpException(500, "Iconv failed: " . $return); } file_put_contents($page->path, $converted); echo 'OK'; }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $user = User::getCurrentLoginUser(); if ($user) { $this->redirect(['/wiki/view', 'pageName' => 'index.org']); } else { $this->redirect(['/site/login']); } }