예제 #1
0
 public function likeAction()
 {
     $request = $this->getRequest();
     $pin_id = $request->getRequest('pin_id');
     $pin = Model_Pins::getPin($pin_id, Model_Users::$allowed_fields);
     if (!$pin) {
         $this->forward('error', 'error404');
     }
     if ($request->isXmlHttpRequest()) {
         if (!(int) JO_Session::get('user[user_id]')) {
             $this->view->location = WM_Router::create($request->getBaseUrl() . '?controller=landing');
         } else {
             if (Model_Pins::pinIsLiked($pin_id)) {
                 $result = Model_Pins::unlikePin($pin_id);
                 $this->view = JO_View::getInstance()->reset();
                 if ($result) {
                     Model_History::addHistory($pin['user_id'], Model_History::UNLIKEPIN, $pin_id);
                     $this->view->pin = self::getPinStat($pin_id);
                     $this->view->ok = $this->translate('Like');
                     $this->view->classs = 'remove';
                 } else {
                     $this->view->error = true;
                 }
             } else {
                 $result = Model_Pins::likePin($pin_id);
                 $this->view = JO_View::getInstance()->reset();
                 if ($result) {
                     Model_History::addHistory($pin['user_id'], Model_History::LIKEPIN, $pin_id);
                     if ($pin['user']['email_interval'] == 1 && $pin['user']['likes_email']) {
                         $this->view->user_info = $pin['user'];
                         $this->view->profile_href = WM_Router::create($request->getBaseUrl() . '?controller=users&action=profile&user_id=' . JO_Session::get('user[user_id]'));
                         $this->view->full_name = JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]');
                         $this->view->text_email = $this->translate('like your');
                         $this->view->pin_href = WM_Router::create($request->getBaseUrl() . '?controller=pin&pin_id=' . $pin_id);
                         $result = Model_Email::send($pin['user']['email'], JO_Registry::get('noreply_mail'), JO_Session::get('user[firstname]') . ' ' . JO_Session::get('user[lastname]') . ' ' . $this->translate('like your pin'), $this->view->render('like_pin', 'mail'));
                     }
                     $this->view->pin = self::getPinStat($pin_id);
                     $this->view->ok = $this->translate('Unlike');
                     $this->view->classs = 'add';
                 } else {
                     $this->view->error = true;
                 }
             }
         }
         echo $this->renderScript('json');
     } else {
         if (!(int) JO_Session::get('user[user_id]')) {
             $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=landing'));
         }
     }
 }