public function run()
 {
     $app_settings_model = new waAppSettingsModel();
     $contact_settings_model = new waContactSettingsModel();
     $app_settings_model->set('blog', 'last_reminder_cron_time', time());
     // remider settings for all users
     $reminders = $contact_settings_model->select('contact_id, value')->where("app_id='blog' AND name='reminder'")->fetchAll('contact_id', true);
     if (!$reminders) {
         return;
     }
     $time = time();
     // do job no more one time in 24 hours
     $last_cron_times = $contact_settings_model->select('contact_id')->where("app_id='blog' AND name='last_reminder_cron_time' AND value <= " . ($time - 86400))->fetchAll('contact_id', true);
     $reminders_allowed = array_keys($last_cron_times);
     if (!$reminders_allowed) {
         return;
     }
     $post_model = new blogPostModel();
     $backend_url = $app_settings_model->get('blog', 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
     $message_count = 0;
     foreach ($reminders_allowed as $contact_id) {
         $days = $reminders[$contact_id];
         // get all deadline posts for this contact
         $posts = $post_model->select("id, title, datetime")->where("status='" . blogPostModel::STATUS_DEADLINE . "' AND contact_id=" . $contact_id . " AND datetime < '" . date('Y-m-d H:i:s', $time + $days * 86400) . "'")->order('datetime')->fetchAll();
         if ($posts) {
             $contact = new waContact($contact_id);
             $email = $contact->get('email', 'default');
             $message = new waMailMessage(_w('Scheduled blog posts'), $this->getMessage($posts, $time, $backend_url));
             try {
                 $message->setTo($email);
                 if ($message->send()) {
                     $message_count++;
                 }
             } catch (Exception $e) {
             }
         }
         $contact_settings_model->set($contact_id, 'blog', 'last_reminder_cron_time', $time);
     }
     /**
      * Notify plugins about sending reminder
      * @event followup_send
      * @return void
      */
     wa()->event('reminder_send', $message_count);
 }
Example #2
0
 /**
  * Update timestamp of user activity at application
  * @param null $id
  * @param bool $force
  * @return bool|null|string
  */
 public static function setUserActivity($id = null, $force = true)
 {
     if (is_null($id)) {
         $id = wa()->getUser()->getId();
     }
     $t = null;
     $storage = wa()->getStorage();
     if ($id) {
         if (!$force && (!($app_last_datetime = $storage->get(self::$app_id . "_last_datetime")) || time() - strtotime($app_last_datetime) > 120)) {
             $force = 1;
         }
         if ($force) {
             $t = date("Y-m-d H:i:s", time() + 1);
             $contact = new waContactSettingsModel();
             $contact->set($id, self::$app_id, self::$app_id . "_last_datetime", $t);
             $storage->write(self::$app_id . "_last_datetime", $t);
             if ($force === true) {
                 $storage->write(self::$app_id . "_badge_datetime", $t);
             }
         } elseif ($force === false) {
             $storage->write(self::$app_id . "_badge_datetime", $s = date("Y-m-d H:i:s", time() + 1));
         }
     } elseif ($force) {
         $storage->set(self::$app_id . "_session_datetime", $t = date("Y-m-d H:i:s", time() + 1));
     }
     return $t;
 }
 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 #4
0
 /**
  * Saves properties of specified contact to database.
  *
  * @param string $app_id Id of the app for which a value of a contact property must be set
  * @param string $name Contact property id
  * @param mixed $value Contact property value
  * @return bool Whether saved successfully
  */
 public function setSettings($app_id, $name, $value = null)
 {
     $setting_model = new waContactSettingsModel();
     if (is_array($value)) {
         $value = implode(",", $value);
     }
     return $setting_model->set($this->id, $app_id, $name, $value);
 }
Example #5
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);
 }
 public function setLastLoginTime($datetime)
 {
     $contact_id = wa()->getUser()->getId();
     $contact_settings = new waContactSettingsModel();
     $contact_settings->set($contact_id, 'photos', 'last_login_time', $datetime);
     return $datetime;
 }
Example #7
0
 public function setSidebarWidth($width)
 {
     $width = max(min((int) $width, 400), 200);
     $settings_model = new waContactSettingsModel();
     $settings_model->set(wa()->getUser()->getId(), 'shop', 'sidebar_width', $width);
 }