public function getLastLoginTime($app = true)
 {
     $expire_interval = $this->getOption('expire_interval');
     $expire_interval = $expire_interval === null ? 180 : max(0, intval($expire_interval));
     if (!$this->last_activity_time || !$app) {
         $storage = wa()->getStorage();
         $now = time();
         if ($activity = $storage->get('photos_last_activity_time')) {
             list($datetime, $timestamp) = $activity;
             if ($app && $now - $timestamp > $expire_interval) {
                 $datetime = $now - $expire_interval;
                 $storage->set('photos_last_activity_time', array($datetime, $now));
                 if ($contact_id = wa()->getUser()->getId()) {
                     $contact_settings = new waContactSettingsModel();
                     $contact_settings->set($contact_id, 'photos', 'last_login_time', date("Y-m-d H:i:s", $now));
                 }
             }
         } else {
             if ($contact_id = wa()->getUser()->getId()) {
                 $contact_settings = new waContactSettingsModel();
                 if ($last_login_time = $contact_settings->getOne($contact_id, 'photos', 'last_login_time')) {
                     if ($datetime = strtotime($last_login_time)) {
                         $datetime = max($datetime, $now - $expire_interval);
                     } else {
                         $datetime = $now - $expire_interval;
                     }
                 } else {
                     $datetime = $now - $expire_interval;
                 }
                 if ($app) {
                     $contact_settings->set($contact_id, 'photos', 'last_login_time', date("Y-m-d H:i:s", $now));
                 }
             } else {
                 $datetime = $now - $expire_interval;
             }
             if ($app) {
                 $storage->set('photos_last_activity_time', array($datetime, $now));
             }
         }
         if ($app) {
             $storage->set('photos_last_attend_time', $now);
             $this->last_activity_time = date("Y-m-d H:i:s", $datetime);
         } else {
             $datetime = max($datetime, $storage->get('photos_last_attend_time'));
             return date("Y-m-d H:i:s", $datetime);
         }
     }
     return $this->last_activity_time;
 }
 protected function getHash($contact_id, $set_new = false)
 {
     $contact_settings_model = new waContactSettingsModel();
     if ($set_new) {
         $hash = md5(uniqid(null, true));
         $contact_settings_model->set($contact_id, 'webasyst', 'forgot_password_hash', $hash);
         return substr($hash, 0, 16) . $contact_id . substr($hash, -16);
     } else {
         $hash = $contact_settings_model->getOne($contact_id, 'webasyst', 'forgot_password_hash');
         return substr($hash, 0, 16) . $contact_id . substr($hash, -16);
     }
 }
Example #3
0
 public function execute()
 {
     $user = $this->getUser();
     $filter = waRequest::get('filter');
     $contact_settings = new waContactSettingsModel();
     if (!$filter) {
         $filter = $contact_settings->getOne($user->getId(), $this->getAppId(), 'comments_filter');
         if (!$filter) {
             $filter = 'myposts';
         }
     } else {
         $contact_settings->set($user->getId(), $this->getAppId(), 'comments_filter', $filter);
     }
     $contact_photo_size = 20;
     $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page')));
     $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
     $blogs = blogHelper::getAvailable();
     $offset = $comments_per_page * ($page - 1);
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $data = $this->getComments(array('offset' => $offset, 'limit' => $comments_per_page, 'blog_id' => $blog_ids, 'filter' => $filter), $fields, $prepare_options);
     $comments = $data['comments'];
     $comments_all_count = $data['comments_all_count'];
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     $comments_count = ($page - 1) * $comments_per_page + count($comments);
     if ($page == 1) {
         $this->setLayout(new blogDefaultLayout());
         $this->getResponse()->setTitle(_w('Comments'));
     }
     /**
      * Backend comments view page
      * UI hook allow extends backend comments view page
      * @event backend_comments
      * @param array[int][string]mixed $comments
      * @param array[int][string]int $comments[%id%][id] comment id
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html
      */
     $this->view->assign('backend_comments', wa()->event('backend_comments', $comments, array('toolbar')));
     $this->view->assign('comments', $comments);
     $this->view->assign('comments_count', $comments_count);
     $this->view->assign('comments_total_count', $comments_all_count);
     $this->view->assign('comments_per_page', $comments_per_page);
     $this->view->assign('pages', ceil($comments_all_count / $comments_per_page));
     $this->view->assign('page', $page);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     $this->view->assign('current_contact_id', $user->getId());
     $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size)));
     $this->view->assign('filter', $filter);
     $yet_authors_exist = false;
     if ($blogs) {
         $yet_authors_exist = !!$post_model->select('contact_id')->where('blog_id IN (' . implode(',', $blog_ids) . ') AND contact_id != ' . $user->getId())->limit(1)->fetchField();
     }
     $this->view->assign('blogs', $blogs);
     $this->view->assign('yet_authors_exist', $yet_authors_exist);
 }
Example #4
0
 public function getSidebarWidth()
 {
     $settings_model = new waContactSettingsModel();
     $width = (int) $settings_model->getOne(wa()->getUser()->getId(), 'shop', 'sidebar_width');
     if (!$width) {
         return 250;
     }
     return max(min($width, 400), 200);
 }