/** * Render page, query string 's' indicates that get page record regardless of published status */ public function actionPage($id = '') { $isPreview = \Yii::$app->request->get('s', 0); if (!empty($id)) { $id = new \MongoId($id); $page = Page::getPage($id, !!$isPreview); if (empty($page) || empty($page->url)) { $this->redirect(self::NOT_FOUND_PAGE_PATH); } if (empty($page['color'])) { $page['color'] = \Yii::$app->params['micrositeDefaultColor']; } if (empty($page->cpts) || $isPreview) { $cpts = PageComponent::getAllComponents($id); $page->cpts = ArrayHelper::toArray($cpts); } $sdk = Yii::$app->wechatSdk; $sdk->refererUrl = $sdk->refererDomain . 'msite/page/' . $id; $signPackage = $sdk->getSignPackage(); $actionView = $this->getView(); $actionView->registerJsFile('https://res.wx.qq.com/open/js/jweixin-1.0.0.js'); $this->view->params['page'] = $page; $this->view->params['pageRGBColor'] = join(',', StringUtil::hex2rgb($page['color'])); $this->layout = self::PAGE_PATH; $this->registerPageResource($isPreview); $params = ['signPackage' => $signPackage, 'components' => $page->cpts, 'page' => ['title' => $page->title, 'desc' => $page->description, 'url' => $page->url, 'isCover' => $page->type === Page::TYPE_COVER]]; if (BrowserUtil::isWeiboBrower() || BrowserUtil::isWeixinBrowser()) { $params['hideTitle'] = true; } return $this->render(self::PAGE_PATH, $params); } else { return $this->render(self::NOT_FOUND_PAGE_PATH); } }
/** * View a page with statistics data * @param string $id page id */ public function actionPublish($id) { $pageId = new \MongoId($id); $page = Page::findByPk($pageId); if (empty($page)) { throw new ServerErrorHttpException(Yii::t('microSite', 'page_not_exist')); } $cpts = PageComponent::getAllComponents($pageId); $page->cpts = ArrayHelper::toArray($cpts); $page->isFinished = true; if ($page->validate()) { // all inputs are valid if ($page->save()) { return ['message' => 'ok']; } else { throw new ServerErrorHttpException(Yii::t('common', 'save_fail')); } } else { // valid fail, return errors return $page->errors; } }
/** * Query page component list * * <b>Request Type: </b>GET<br/> * <b>Request Endpoint: </b>http://{server-domain}/api/microsite/page-components * <b>Summary: </b>This api is for query page component list * * <b>Request Params</b>:<br/> * pageId: string<br/> * <br/><br/> * * <b>Response Example: </b> * <pre> * [ * { * "id": "54f05829e9c2fbfa038b4585", * "parentId": "54f05829e9c2fbfa038b4585", * "pageId": "54f05829e9c2fbfa038b4585", * "name": "articles", * "jsonConfig": [], * "color": "#6ab3f7", * "order": 0, * "tabIndex": null, * "tabs": null * }, * { * "id": "54f0581fe9c2fbc3168b4586", * "parentId": "54f0581fe9c2fbc3168b4586", * "pageId": "54f0581fe9c2fbc3168b4586", * "name": "tab", * "jsonConfig": [ * "tabs": [ * { * "name": "Tab1", * "cpts": [ * { * "id": "54f05831e9c2fbad3d8b457e", * "parentId": "54f05831e9c2fbad3d8b457e", * "pageId": "54f05831e9c2fbad3d8b457e", * "name": "title", * "jsonConfig": [], * "color": "#6ab3f7", * "order": 0, * "tabIndex": 0, * "tabs": null * } * ], * "active": true * }, * { * "name": "Tab2", * "cpts": [ * { * "id": "54f05b73e9c2fbad3d8b457f", * "parentId": "54f05b73e9c2fbad3d8b457f", * "pageId": "54f05b73e9c2fbad3d8b457f", * "name": "album", * "jsonConfig": [], * "color": "#6ab3f7", * "order": 0, * "tabIndex": 1, * "tabs": null * } * ], * "active": false * } * ] * ], * "color": "#6ab3f7", * "order": 1, * "tabIndex": null * } * ] * </pre> */ public function actionIndex() { $pageId = $this->getQuery('pageId'); if (empty($pageId)) { throw new BadRequestHttpException(\Yii::t('common', 'parameters_missing')); } $pageComponents = PageComponent::getAllComponents(new \MongoId($pageId)); return $pageComponents; }