Exemple #1
0
 public function postComment()
 {
     $controller = $this->controller;
     $this->controller->getActionProperties()->setModel(Comment::model())->setRequire(array('text' => true, 'entity_id' => true, 'response_id' => false))->setAccess(array('createComment'));
     $this->controller->getActionEvents()->setBeforeSave(function ($instance, $params) {
         /**
          * @var Comment $instance
          */
         $instance->detachBehavior('duplicate');
         $instance->detachBehavior('antispam');
         $instance->new_entity_id = $params['entity_id'];
         if (isset($params['response_id'])) {
             $instance->response_id = $params['response_id'];
         }
         /**
          * @var Content $content
          */
         $content = Content::model()->findByPk($params['entity_id']);
         $instance->entity_id = $content->originEntityId;
         $instance->entity = $content->originService == 'oldBlog' ? 'BlogContent' : $content->originEntity;
     })->setAfterSave(function ($instance, $params) use($controller) {
         /**
          * @var Comment $instance
          */
         $controller->pushData = $instance->toJSON();
         $controller->push(get_class($instance), \CometModel::COMMENTS_NEW);
     });
     $this->controller->post();
 }
Exemple #2
0
 private function afterCommentCreate()
 {
     $post = Content::model()->findByPk($this->owner->new_entity_id);
     if (!$post) {
         return;
     }
     $apps = Application::model()->byChannel('user_channel')->findAll();
     /**
      * @var Application $app;
      */
     foreach ($apps as $app) {
         $gcm = new GcmSender($post->authorId, $app->gcm_conf);
         $gcm->setType(Types::NEW_COMMENT)->setId((int) $this->owner->new_entity_id)->setAppId($app->_id);
         if (!($post->authorId == $this->owner->author_id)) {
             $topic = new GcmTopic();
             $topic->setChannel(Channels::USER)->setId($post->authorId);
             $gcm->sendToTopic($topic);
         }
     }
     $this->commentInPost($post);
     if ($this->owner->response_id) {
         $root = Comment::model()->findByPk($this->owner->response_id);
         if (!$root || $root->author_id == $this->owner->author_id) {
             return;
         }
         foreach ($apps as $app) {
             $gcm = new GcmSender($root->author_id, $app->gcm_conf);
             $gcm->setType(Types::NEW_COMMENT_ANSWER)->setId((int) $this->owner->new_entity_id)->setAppId($app->_id);
             $topic = new GcmTopic();
             $topic->setChannel(Channels::USER)->setId($root->author_id);
             $gcm->sendToTopic($topic);
         }
     }
 }
Exemple #3
0
 private function getPosts()
 {
     $required = array('type' => true, 'user_id' => true);
     $params = $this->controller->getParams($required);
     $model = null;
     if ($params['type'] == 'community') {
         /**
          * @var CommentatorsContestParticipant $participant
          */
         $participant = CommentatorsContestParticipant::model()->byContest(ContestManager::getCurrentActive()->id)->byUser($params['user_id'])->find();
         $model = Content::model()->byService(Content::COMMUNITY_SERVICE)->withoutUserComments($params['user_id']);
         if (($settings = $participant->getSettingArray()) && isset($settings['community_filter'])) {
             $model->byClubs(explode(',', $settings['community_filter']));
         }
     } else {
         if ($params['type'] == 'blog') {
             $model = Content::model()->byService(Content::BLOG_SERVICE)->withoutUserComments($params['user_id']);
         } else {
             throw new InvalidParamsApiException();
         }
     }
     $this->controller->setBeforeToArray(function ($models) use($params) {
         foreach ($models as $model) {
             QuestsManager::addQuest($params['user_id'], QuestTypes::COMMENT_POST, $model, array(), null, '', '');
         }
     });
     $this->controller->get($model, $this);
 }
 public function convert()
 {
     $scenario = 'oldPost';
     $oldPost = $this->owner;
     $this->owner->purified->clearCache();
     $service = 'oldBlog';
     $entity = get_class($this->owner);
     $id = $this->owner->id;
     $tags = array();
     $rubric = $this->owner->rubric;
     while ($rubric) {
         $tags[] = 'Рубрика: ' . $rubric->title;
         $rubric = $rubric->parent;
     }
     if ($this->owner->rubric->community) {
         $tags[] = 'Форум: ' . $this->owner->rubric->community->title;
         if ($oldPost->rubric->community->club) {
             $tags[] = 'Клуб: ' . $this->owner->rubric->community->club->title;
         }
         if ($oldPost->rubric->community->club && $oldPost->rubric->community->club->section) {
             $tags[] = 'Секция: ' . $this->owner->rubric->community->club->section->title;
         }
     }
     $tags[] = Label::LABEL_BLOG;
     $newPost = Content::model()->resetScope()->findByAttributes(array('originService' => $service, 'originEntity' => $entity, 'originEntityId' => $id));
     if (!$newPost) {
         $newPost = new Content($scenario);
     }
     $newPost->scenario = $scenario;
     $newPost->labelsArray = array_reverse($tags);
     $newPost->url = $this->owner->getUrl(false, true);
     $newPost->originService = $service;
     $newPost->originEntity = $entity;
     $newPost->originEntityId = $id;
     $newPost->authorId = $oldPost->author_id;
     //something wrong here.
     $newPost->dtimeCreate = strtotime($this->owner->created);
     $newPost->dtimeUpdate = max($newPost->dtimeCreate, strtotime($this->owner->updated), strtotime($this->owner->last_updated));
     $newPost->dtimePublication = $newPost->dtimeCreate;
     $newPost->uniqueIndex = $this->owner->uniqueness;
     $newPost->isNoindex = is_numeric($this->owner->uniqueness) && $this->owner->uniqueness < 50;
     $newPost->isNofollow = false;
     $newPost->isRemoved = $this->owner->removed;
     $newPost->isDraft = 0;
     $newPost->title = trim($this->owner->title);
     $newPost->templateObject->layout = 'newBlogPost';
     $newPost->originManageInfoObject->link = array('url' => '/' . 'blogs/edit/post', 'get' => array('id' => $id));
     $newPost->isAutoMeta = $oldPost->meta_description ? false : true;
     $newPost->metaObject->description = $newPost->isAutoMeta ? $this->owner->meta_description_auto : $this->owner->meta_description;
     $newPost->metaObject->title = trim($this->owner->title);
     $newPost->socialObject->description = $newPost->metaObject->description;
     $newPost->isAutoSocial = true;
     if ($this->owner->rubric->community_id == ContractubexHelper::getForum()->id) {
         $newPost->templateObject->data['hideAdsense'] = true;
     }
     $this->secondStep($newPost);
 }
Exemple #5
0
 public function postProcessing(&$data)
 {
     for ($i = 0; $i < count($data); $i++) {
         if (in_array('blogPostsCount', $this->controller->getWithParameters(\User::model(), true))) {
             $count = count(Content::model()->findAllByAttributes(array('authorId' => $data[$i]['id'], 'originService' => 'oldBlog')));
             $data[$i]['blogPostsCount'] = $count;
         }
         $favourite = Favourite::model()->byUser($this->controller->identity->getId())->byModel(get_class(\User::model()), $data[$i]['id'])->find();
         $data[$i]['is_my_favourite'] = $favourite == null ? false : true;
         Formatter::addStatusToUser($data[$i]);
     }
 }
 public function getPostsContent()
 {
     $this->controller->get(Content::model(), $this);
 }
Exemple #7
0
 /**
  * HTML Format, Views Counter Increment
  *
  * @param $data
  */
 public function postProcessing(&$data)
 {
     //\Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM');
     include_once \Yii::getPathOfAlias('site.frontend.vendor.simplehtmldom_1_5') . DIRECTORY_SEPARATOR . 'simple_html_dom.php';
     $lastText = '';
     $indexes = array();
     //В форматер и отрефакторить.
     for ($i = 0; $i < count($data); $i++) {
         if ($data[$i]['originService'] == 'oldCommunity') {
             $data[$i]['subscribers'] = \UserClubSubscription::model()->getSubscribersCount(Content::model()->findByPk($data[$i]['id'])->club->id);
         } else {
             if ($data[$i]['originService'] == 'oldBlog') {
                 $data[$i]['subscribers'] = (int) \UserBlogSubscription::model()->subscribersCount($data[$i]['authorId']);
             } else {
                 $data[$i]['subscribers'] = 0;
             }
         }
         $temp = $data[$i]['html'];
         if ($i != 0) {
             //ApiLog::i($lastText . ' -------- ' . $temp);
             if ($lastText == $temp) {
                 //ApiLog::i('DELETED');
                 //$data[$i] = null;
                 $indexes[] = $i;
                 continue;
             }
         }
         if (!$this->isOriginHtml) {
             $data[$i]['html'] = HtmlParser::handleHtml($data[$i]['html'], $data[$i])->outertext;
             if ($data[$i]['preview'] != '') {
                 $data[$i]['preview'] = HtmlParser::handleHtml($data[$i]['preview'])->outertext;
             }
             $url = preg_replace("/http:\\/\\/www.*\\.ru/", "", $data[$i]['url']);
             $pageView = PageView::getModel($url);
             $data[$i]['views'] = $pageView->visits;
             if (isset($data[$i]['photoCollection'])) {
                 $array = \CJSON::decode($data[$i]['photoCollection']);
                 $collection = PhotoCollection::model()->findByPk($array['id']);
                 if ($collection) {
                     $data[$i]['photoCollection'] = $collection->getAttributes();
                     $attaches = PhotoAttach::model()->findAll(array('condition' => 'collection_id=' . $data[$i]['photoCollection']['id'], 'with' => array('photo')));
                     foreach ($attaches as $attach) {
                         $temp = $attach->getAttributes();
                         $temp['photo'] = $attach->photo->getAttributes();
                         $temp['photo']['originalUrl'] = \Yii::app()->fs->getUrl($attach->photo->getFile()->getKey());
                         $data[$i]['photoCollection']['attaches'][] = $temp;
                     }
                 }
             }
         }
         //crutch for adding status info for.
         if ($data[$i]['originService'] == 'status') {
             $status = Status::model()->with('moodModel')->findByPk($data[$i]['originEntityId']);
             Formatter::formatCommon($status);
             $data[$i]['status'] = $status->getAttributes();
             if ($status->moodModel) {
                 Formatter::formatCommon($status->moodModel);
                 $data[$i]['status']['moodModel'] = $status->moodModel->getAttributes();
             }
         }
         $lastText = $temp;
     }
     for ($i = 0; $i < count($indexes); $i++) {
         unset($data[$indexes[$i]]);
     }
     $data = array_values($data);
 }