示例#1
0
 public function subscribe()
 {
     $required = array('club_id' => false, 'user_id' => false);
     $params = $this->controller->getParams($required);
     if (isset($params['club_id'])) {
         \UserClubSubscription::toggle($params['club_id']);
     } else {
         if (isset($params['user_id'])) {
             \UserBlogSubscription::toggle($params['user_id']);
         } else {
             throw new InvalidParamsApiException();
         }
     }
     $this->controller->setMessage('Success');
 }
示例#2
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);
 }