public function execute()
 {
     $count = 10;
     $offset = waRequest::post('offset', 0, waRequest::TYPE_INT);
     $comment_model = new photosCommentModel();
     $comments = $comment_model->getList(array('author' => true, 'crop' => true, 'reply_to' => true), $offset, $count);
     $this->view->assign('comments_author', photosCommentModel::getAuthorInfo(wa()->getUser()->getId()));
     $this->view->assign('comments', $comments);
     $this->view->assign('contact_rights', wa()->getUser()->getRights('contacts', 'backend'));
     // get and send to view sidebar counters for updating
     $plugin = wa()->getPlugin('comments');
     $plugin->sidebarCounters();
 }
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException("Can't change status of comment: unknown id");
     }
     $status = waRequest::post('status', '', waRequest::TYPE_STRING_TRIM);
     if ($status == photosCommentModel::STATUS_DELETED || $status == photosCommentModel::STATUS_PUBLISHED) {
         $comment_model = new photosCommentModel();
         $comment_model->updateById($id, array('status' => $status));
     } else {
         $this->errors['unknown_status'] = _w('Unknown status');
     }
 }
 protected function getReqiestData()
 {
     $photo_id = waRequest::post('photo_id', null, waRequest::TYPE_INT);
     $comment_id = waRequest::post('comment_id', 0, waRequest::TYPE_INT);
     // id of parent in tree
     $photo_comments_count_text = waRequest::post('photo_comments_count_text', '', waRequest::TYPE_STRING);
     if (!$photo_id && !$comment_id) {
         throw new waException("Can't add comment: unknown photo for comment or comment for reply");
     }
     if (!$photo_id) {
         $parent_comment = $this->comment_model->getById($comment_id);
         $photo_id = $parent_comment['photo_id'];
     }
     $text = waRequest::post('text', '', waRequest::TYPE_STRING_TRIM);
     return array('photo_id' => $photo_id, 'comment_id' => $comment_id, 'text' => $text, 'photo_comments_count_text' => $photo_comments_count_text);
 }
 protected function getResponseAuthorData()
 {
     if ($this->author->isAuth()) {
         return parent::getResponseAuthorData();
     } else {
         $author = array('name' => $this->added_comment['name'], 'email' => $this->added_comment['email'], 'site' => $this->added_comment['site']);
         if ($this->added_comment['auth_provider'] != 'guest') {
             $author['photo'] = photosCommentModel::getAuthProvoderIcon($this->added_comment['auth_provider']);
         } else {
             $author['photo'] = $this->author->getPhoto(photosCommentModel::SMALL_AUTHOR_PHOTO_SIZE);
         }
         return $author;
     }
 }
 public function frontendPhoto($photo)
 {
     $this->view = $this->view();
     $photo_model = new photosPhotoModel();
     $photo_id = $photo['id'];
     if ($parent_id = $photo_model->getStackParentId($photo)) {
         $photo_id = $parent_id;
     }
     $comments = $this->comment()->getFullTree($photo_id, array('author' => true));
     $storage = wa()->getStorage();
     $adapters = array();
     $current_auth = null;
     $current_auth_source = null;
     $user = wa()->getUser();
     if ($user->isAuth()) {
         $comment_author = photosCommentModel::getAuthorInfo($user->getId(), photosCommentModel::BIG_AUTHOR_PHOTO_SIZE);
         $storage->del('auth_user_data');
         $this->view->assign('comment_author', $comment_author);
     } else {
         $current_auth = $storage->read('auth_user_data');
         $adapters = wa()->getAuthAdapters();
         if (!$adapters && $current_auth) {
             $current_auth = null;
             $storage->del('auth_user_data');
         }
         $current_auth_source = $current_auth ? $current_auth['source'] : null;
         $this->view->assign('comment_author', null);
     }
     $app_url = wa()->getAppStaticUrl();
     $this->view->assign('current_auth_source', $current_auth_source);
     $this->view->assign('current_auth', $current_auth);
     $this->view->assign('auth_adapters', $adapters);
     $this->view->assign('require_authorization', $this->getSettings('require_authorization'));
     $this->view->assign('comments', $comments);
     $this->view->assign('photo_id', $photo_id);
     return array('bottom' => $this->view()->fetch($this->path . '/templates/FrontendPhoto.html'));
 }
 public function contactsDelete($contact_ids)
 {
     $c = new waContactsCollection('id/' . implode(',', $contact_ids));
     $contacts = $c->getContacts('name,phone,email');
     foreach ($contacts as &$contact) {
         if (is_array($contact['phone'])) {
             $phone = reset($contact['phone']);
             if (is_array($phone)) {
                 if (isset($phone['value'])) {
                     $phone = $phone['value'];
                 } else {
                     $phone = '';
                 }
             }
             $contact['phone'] = $phone;
         }
         if (is_array($contact['email'])) {
             $email = reset($contact['email']);
             $contact['email'] = $email;
         }
     }
     $comment_model = new photosCommentModel();
     foreach ($contacts as $contact) {
         // Insert contact name into their reviews
         $comment_model->updateByField('contact_id', $contact['id'], array('contact_id' => 0, 'name' => $contact['name'], 'email' => $contact['email'], 'auth_provider' => null));
     }
 }