Ejemplo n.º 1
0
 /**
  * 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Create default page cover
  * @param \MongoId $accountId
  * @throws ServerErrorHttpException
  */
 private function _createDefaultPageCover(\MongoId $accountId)
 {
     $page = new Page(['scenario' => 'createBasic']);
     $defaultCoverPage = Yii::$app->params['default_cover_page'];
     $page->load($defaultCoverPage, '');
     $page->_id = new \MongoId();
     $page->accountId = $accountId;
     $page->url = Yii::$app->request->hostinfo . '/msite/page/' . $page->_id;
     $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
     $page->shortUrl = $shortUrl['Short'];
     if ($page->save()) {
         $pageComponent = new PageComponent(['scenario' => PageComponent::SCENARIO_CREATE]);
         $defaultCoverPageCompnent = Yii::$app->params['default_cover_pagecomponent'];
         $pageComponent->load($defaultCoverPageCompnent, '');
         $pageComponent->pageId = $page->_id;
         $pageComponent->parentId = $page->_id;
         $pageComponent->accountId = $accountId;
         $pageComponent->jsonConfig = Yii::$app->params['micrositeDefaultConfig'][$pageComponent->name];
         $pageComponent->save();
     } else {
         throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
     }
 }
Ejemplo n.º 3
0
 public function actionTitle()
 {
     $url = $this->getQuery('url');
     if (empty($url)) {
         throw BadRequestHttpException('common', 'parameters_missing');
     }
     $url = urldecode($url);
     $page = Page::getByShortUrl($url);
     if (!empty($page->title)) {
         return ['title' => $page->title];
     }
     $article = Article::getByUrl($url);
     return ['title' => empty($article->name) ? '' : $article->name];
 }
Ejemplo n.º 4
0
 public function actionPage()
 {
     $allPages = Page::findAll([]);
     if ($allPages) {
         foreach ($allPages as $page) {
             if (isset($page->url) && !empty($page->url)) {
                 $url = $page->url;
                 $newUrl = ereg_replace('microsite', 'msite', $url);
                 $shortenResult = Yii::$app->urlService->shortenUrl($newUrl);
                 $shortUrl = $shortenResult['Short'];
                 $page->url = $newUrl;
                 $page->shortUrl = $shortUrl;
                 if (!$page->update()) {
                     Yii::error('Update page ' . (string) $page->_id . ' fail', 'application');
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * 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;
     }
 }
Ejemplo n.º 6
0
 private function _createDefaultPageCover($accountId, $hostinfo)
 {
     $defaultCoverPage = ['title' => '默认首页', 'description' => '默认首页', 'type' => 'cover', 'isFinished' => true, 'deletable' => false];
     $defaultCoverPageCompnent = ['name' => 'cover1', 'color' => '#6AB3F7', 'order' => 0];
     $page = Page::findOne(array_merge($defaultCoverPage, ['accountId' => $accountId]));
     if (empty($page)) {
         $page = new Page(['scenario' => 'createBasic']);
         $page->load($defaultCoverPage, '');
         $page->_id = new MongoId();
         $page->accountId = $accountId;
         $page->url = $hostinfo . '/msite/page/' . $page->_id;
         $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
         $page->shortUrl = $shortUrl['Short'];
         if ($page->save()) {
             $pageComponent = new PageComponent(['scenario' => PageComponent::SCENARIO_CREATE]);
             $pageComponent->load($defaultCoverPageCompnent, '');
             $pageComponent->pageId = $page->_id;
             $pageComponent->parentId = $page->_id;
             $pageComponent->accountId = $accountId;
             $pageComponent->jsonConfig = Yii::$app->params['micrositeDefaultConfig'][$pageComponent->name];
             $pageComponent->save();
         } else {
             echo $page->getErrors() . PHP_EOL;
             exit;
         }
     } else {
         echo $accountId . 'data is exists' . PHP_EOL;
     }
 }
Ejemplo n.º 7
0
 /**
  * Update page creator name.
  * @param  \MongoId $userId
  * @param  string $name
  */
 public function updatePageCreator(\MongoId $userId, $name)
 {
     Page::updateAll(['$set' => ['creator.name' => $name]], ['creator.id' => $userId]);
 }