/**
 * Handle on_new_revision event
 *
 * @param Page $page
 * @param PageVersion $version
 * @param User $by
 * @return null
 */
function pages_handle_on_new_revision($page, $version, $by)
{
    if (instance_of($page, 'Page')) {
        $page->sendToSubscribers('pages/new_revision', array('created_by_url' => $by->getViewUrl(), 'created_by_name' => $by->getDisplayName(), 'revision_num' => $page->getRevisionNum(), 'old_url' => $version->getViewUrl(), 'old_name' => $version->getName(), 'old_body' => $version->getFormattedBody(), 'new_url' => $page->getViewUrl(), 'new_name' => $page->getName(), 'new_body' => $page->getFormattedBody()), $by->getId());
    }
    // if
}
/**
 * Handle on_new_revision event
 *
 * @param File $new
 * @param Attachment $old
 * @param User $by
 * @return null
 */
function files_handle_on_new_revision($new, $old, $by)
{
    if (instance_of($new, 'File')) {
        $new->sendToSubscribers('files/new_revision', array('created_by_url' => $by->getViewUrl(), 'created_by_name' => $by->getDisplayName()), $by->getId());
    }
    // if
}
 /**
  * Send welcome message
  *
  * @param void
  * @return null
  */
 function send_welcome_message()
 {
     if ($this->active_user->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_user->canSendWelcomeMessage($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->skip_layout = $this->request->isAsyncCall();
     $welcome_message_data = $this->request->post('welcome_message');
     if (!is_array($welcome_message_data)) {
         $welcome_message_data = array('message' => UserConfigOptions::getValue('welcome_message', $this->active_user));
     }
     // if
     $this->smarty->assign('welcome_message_data', $welcome_message_data);
     if ($this->request->isSubmitted()) {
         $welcome_message = trim(array_var($welcome_message_data, 'message'));
         if ($welcome_message) {
             UserConfigOptions::setValue('welcome_message', $welcome_message, $this->active_user);
         } else {
             UserConfigOptions::removeValue('welcome_message', $this->active_user);
         }
         // if
         $password = make_password(11);
         $this->active_user->setPassword($password);
         $save = $this->active_user->save();
         if ($save && !is_error($save)) {
             $welcome_message_sent = ApplicationMailer::send(array($this->active_user), 'system/new_user', array('created_by_id' => $this->logged_user->getId(), 'created_by_name' => $this->logged_user->getDisplayName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'email' => $this->active_user->getEmail(), 'password' => $password, 'login_url' => assemble_url('login'), 'welcome_body' => $welcome_message ? nl2br(clean($welcome_message)) : ''));
             if ($welcome_message_sent) {
                 $message = lang('Welcome message has been sent to :name', array('name' => $this->active_user->getDisplayName()));
             } else {
                 $message = lang('Failed to send welcome message to :name. Please try again later', array('name' => $this->active_user->getDisplayName()));
             }
             // if
             if ($this->request->isAsyncCall()) {
                 die($message);
             } else {
                 flash_success($message);
                 $this->redirectToUrl($this->active_user->getViewUrl());
             }
             // if
         } else {
             if ($this->request->isAsyncCall()) {
                 $this->httpError(HTTP_ERR_OPERATION_FAILED);
             } else {
                 flash_error($message);
                 $this->redirectToUrl($this->active_user->getViewUrl());
             }
             // if
         }
         // if
     }
     // if
 }
 /**
  * Log new view
  *
  * @param ProjectObject $object
  * @param User $user
  * @return boolean
  */
 function log($object, $user)
 {
     if (!isset($_SESSION['project_object_views'][$object->getId()])) {
         $_SESSION['project_object_views'][$object->getId()] = array();
     }
     // if
     if (!isset($_SESSION['project_object_views'][$object->getId()][$user->getId()])) {
         $_SESSION['project_object_views'][$object->getId()][$user->getId()] = array('name' => $user->getDisplayName(), 'email' => $user->getEmail());
     }
     // if
     //return db_execute('INSERT INTO ' . TABLE_PREFIX . 'project_object_views (object_id, created_by_id, created_by_name, created_by_email, created_on) VALUES (?, ?, ?, ?, ?)', $object->getId(), $user->getId(), $user->getDisplayName(), $user->getEmail(), date(DATETIME_MYSQL));
 }
 /**
  * Return the name of who completed this task
  *
  * @access public
  * @param void
  * @return User
  */
 function getCompletedByName()
 {
     if ($this->isCompleted()) {
         if (!$this->completed_by instanceof User) {
             $this->completed_by = Users::findById($this->getCompletedById());
         }
         // if
         if ($this->completed_by instanceof User) {
             return $this->completed_by->getDisplayName();
         } else {
             return '';
         }
     } else {
         return '';
     }
 }
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     $db = $Registry->Mongo->getDb();
     $map = new \MongoCode("function() { emit(this.t, 1); }");
     $reduce = new \MongoCode("function(k, vals) { " . "var sum = 0;" . "for (var i in vals) {" . "sum += vals[i];" . "}" . "return sum; }");
     $votes = $db->command(array("mapreduce" => "VOTES", "map" => $map, "reduce" => $reduce, "query" => array("i_uid" => $uid)));
     if (empty($votes) || empty($votes['result'])) {
         return '';
     }
     $counter = $db->selectCollection($votes['result'])->find();
     $total = 0;
     $s = '';
     foreach ($counter as $vote) {
         $vars = array('type' => $vote['_id'], 'count' => $vote['value']);
         $total += $vote['value'];
         $s .= \tplVoteCount::parse($vars, false);
     }
     $ret = \tplUserVotes::parse(array('count' => $total, 'stats' => $s, 'username' => $User->getDisplayName()));
     return $ret;
 }
 /**
  *
  * Get block with links to tags that User is following
  * and also possibly a block on tags that both Viewer and User
  * are following
  *
  * @param Registry $Registry
  * @param User $User
  *
  * @return string html
  */
 public static function get(Registry $Registry, User $User)
 {
     $aUserTags = $User['a_f_t'];
     if (empty($aUserTags)) {
         return '';
     }
     if (count($aUserTags) > self::MAX_TO_SHOW) {
         $aUserTags = \array_slice($aUserTags, 0, self::MAX_TO_SHOW);
     }
     /**
      * @todo Translate string
      */
     $blockTitle = $User->getDisplayName() . ' is following these tags';
     $tags = $commonTags = '';
     $tags = \tplTagLink::loop($aUserTags, false);
     /**
      * If Viewer is not the same user as user whose profile
      * being viewer then attempt to get the 'common' tags
      * that both viewer and user are following
      */
     if ($User->getUid() !== $Registry->Viewer->getUid()) {
         $commonTags = self::getCommonTags($aUserTags, $Registry->Viewer['a_f_t']);
     }
     $vals = array('count' => $blockTitle, 'label' => 'tag', 'tags' => $tags);
     $ret = \tplUserTags::parse($vals);
     return $ret . $commonTags;
 }
 /**
  * Sets value of lp_u : a link to Last Poster profile
  * and lp_t a time of last post
  *
  * @todo should make the last answerer an array
  * and then just push the value there
  * This way if answer is deleted we can just delete
  * that one element from array!
  *
  * @param User $User object of type User who made the last
  * Answer or Comment to this question
  *
  * @return object $this
  */
 public function setLatestAnswer(User $User, Answer $Answer)
 {
     $aLatest = $this->offsetGet('a_latest');
     $a = array('u' => '<a href="' . $User->getProfileUrl() . '">' . $User->getDisplayName() . '</a>', 't' => date('F j, Y g:i a T', $Answer->getLastModified()), 'id' => $Answer->getResourceId());
     /**
      * Latest answer data goes
      * to top of array
      */
     \array_unshift($aLatest, $a);
     $this->offsetSet('a_latest', $aLatest);
     return $this;
 }
Example #9
0
 /**
  * Send ticket notification to the list of users ($people)
  *
  * @param ProjectTicket $ticket New ticket
  * @param array $people
  * @param string $template template to send notification
  * @param User $user user who send the notification
  * @return boolean
  * @throws NotifierConnectionError
  */
 static function ticket(ProjectTicket $ticket, $people, $template, $user)
 {
     if (!is_array($people) || !count($people)) {
         return;
         // nothing here...
     }
     // if
     $recipients = array();
     foreach ($people as $subscriber) {
         if ($subscriber->getId() == $user->getId()) {
             continue;
             // skip comment author
         }
         // if
         $recipients[] = self::prepareEmailAddress($subscriber->getEmail(), $subscriber->getDisplayName());
     }
     // foreach
     if (!count($recipients)) {
         return true;
         // no recipients
     }
     // if
     tpl_assign('ticket', $ticket);
     return self::sendEmail($recipients, self::prepareEmailAddress($user->getEmail(), $user->getDisplayName()), $ticket->getProject()->getName() . ' - ' . $ticket->getSummary(), tpl_fetch(get_template_path($template, 'notifier')));
     // send
 }
Example #10
0
 /**
  *
  * Adds a_edited array of data to Question
  *
  * @param User $user
  * @param string $reason reason for editing
  *
  * @return object $this
  */
 public function setEdited(User $user, $reason = '')
 {
     if (!empty($reason)) {
         $reason = \strip_tags((string) $reason);
     }
     $aEdited = $this->offsetGet('a_edited');
     if (empty($aEdited) || !is_array($aEdited)) {
         $aEdited = array();
     }
     $aEdited[] = array('username' => $user->getDisplayName(), 'i_uid' => $user->getUid(), 'av' => $user->getAvatarSrc(), 'reason' => $reason, 'hts' => date('F j, Y g:i a T'));
     parent::offsetSet('a_edited', $aEdited);
     return $this;
 }
 /**
  * Mark this object as completed
  *
  * @param User $by
  * @param boolean $canceled
  * @param boolean $save
  * @return boolean
  */
 function complete($by, $canceled = false, $save = true)
 {
     $status = $canceled ? PROJECT_STATUS_CANCELED : PROJECT_STATUS_COMPLETED;
     $old_status = $this->getStatus();
     if ($status == $old_status) {
         return true;
     }
     // if
     $this->setStatus($status);
     $this->setCompletedOn(new DateTimeValue());
     $this->setCompletedById($by->getId());
     $this->setCompletedByName($by->getDisplayName());
     $this->setCompletedByEmail($by->getEmail());
     if ($save) {
         if ($old_status == PROJECT_STATUS_ACTIVE || $old_status == PROJECT_STATUS_PAUSED) {
             PinnedProjects::deleteByProject($this);
             ActivityLogs::deleteByProject($this);
             event_trigger('on_project_completed', array($this, $by, $status));
         }
         // if
         return $this->save();
     }
     // if
     return true;
 }
 function register_assignees_flag($assignees_flag = array(), $is_new_object = false)
 {
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME);
     if (!$is_new_object) {
         $query = "delete from healingcrystals_assignments_flag_fyi_actionrequest where object_id='" . $this->getId() . "'";
         mysql_query($query, $link);
     }
     $users = array();
     foreach ($assignees_flag['flag_fyi'] as $user_id) {
         if (!array_key_exists((string) $user_id, $users)) {
             $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0');
         }
         $users[(string) $user_id]['flag_fyi'] = '1';
     }
     foreach ($assignees_flag['flag_actionrequest'] as $user_id) {
         if (!array_key_exists((string) $user_id, $users)) {
             $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0');
         }
         $users[(string) $user_id]['flag_actionrequest'] = '1';
     }
     foreach ($assignees_flag['priority_actionrequest'] as $entry) {
         $vals = explode('_', $entry);
         list($temp_user_id, $priority) = $vals;
         if (array_key_exists((string) $temp_user_id, $users) && $users[(string) $temp_user_id]['flag_actionrequest'] == '1') {
             $users[(string) $temp_user_id]['priority_actionrequest'] = $priority;
         }
     }
     foreach ($assignees_flag['flag_email'] as $user_id) {
         if (!array_key_exists((string) $user_id, $users)) {
             $users[(string) $user_id] = array('flag_fyi' => '0', 'flag_actionrequest' => '0', 'priority_actionrequest' => '0', 'flag_email' => '0');
         }
         $users[(string) $user_id]['flag_email'] = '1';
     }
     foreach ($users as $user_id => $flags) {
         $query = "insert into healingcrystals_assignments_flag_fyi_actionrequest (user_id, object_id, flag_fyi, flag_actionrequest, priority_actionrequest, email_flag) values ('" . $user_id . "', '" . $this->getId() . "', '" . $flags['flag_fyi'] . "', '" . $flags['flag_actionrequest'] . "', '" . $flags['priority_actionrequest'] . "', '" . $flags['flag_email'] . "')";
         //mysql_query("insert into testing (date_added, content)  values (now(), '" . mysql_real_escape_string($query) . "')");
         mysql_query($query, $link);
     }
     //BOF:mod 20111011 #449
     if ($is_new_object) {
         $query = "select user_id from healingcrystals_assignments_flag_fyi_actionrequest where object_id='" . $this->getId() . "' and email_flag='1'";
         $result = mysql_query($query);
         $email_to = array();
         if (mysql_num_rows($result)) {
             while ($entry = mysql_fetch_assoc($result)) {
                 $email_to[] = new User($entry['user_id']);
             }
         }
         if (count($email_to)) {
             $owner_company = get_owner_company();
             $project = $this->getProject();
             // Prepare object type translations
             if (is_foreachable($languages)) {
                 $object_type = array();
                 foreach ($languages as $language) {
                     $object_type[$language->getLocale()] = $this->getVerboseType(false, $language);
                 }
                 // foreach
             } else {
                 $object_type = $this->getVerboseType();
             }
             // if
             $created_by_id = $this->getCreatedById();
             $created_by = new User($created_by_id);
             $variables = array('details_body' => EmailTemplates::renderProjectObjectDetails($this, $languages), 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'object_type' => $object_type, 'object_name' => $this->getName(), 'object_body' => $this->getFormattedBody(), 'object_url' => $this->getViewUrl(), 'owner_company_name' => $owner_company->getName(), 'created_by_name' => $created_by->getDisplayName(), 'created_by_url' => $created_by->getViewUrl());
             if ($context === null) {
                 $context = $this->getNotificationContext();
             }
             // if
             ApplicationMailer::send($email_to, 'resources/task_assigned', $variables, $context);
         }
     }
     //EOF:mod 20111011 #449
     mysql_close($link);
 }
Example #13
0
 protected function get_feed(appbox $appbox, User $user, $pub_restrict, $homelink, Application $app)
 {
     $user_key = 'user_' . $user->getId();
     if ($homelink == '1') {
         $feed_key = 'feed_homelink';
     } elseif ($pub_restrict == '1') {
         $feed_key = 'feed_restricted';
     } else {
         $feed_key = 'feed_public';
     }
     if (!array_key_exists($user_key, self::$feeds) || !isset(self::$feeds[$user_key][$feed_key])) {
         if ($homelink == '1') {
             $title = $user->getDisplayName() . ' - ' . 'homelink Feed';
         } elseif ($pub_restrict == '1') {
             $title = $user->getDisplayName() . ' - ' . 'private Feed';
         } else {
             $title = $user->getDisplayName() . ' - ' . 'public Feed';
         }
         $feed = new Feed();
         $publisher = new FeedPublisher();
         $feed->setTitle('title');
         $feed->setSubtitle('');
         $feed->addPublisher($publisher);
         $publisher->setFeed($feed);
         $publisher->setOwner(true);
         $publisher->setUser($user);
         if ($homelink) {
             $feed->setPublic(true);
             $app['EM']->persist($feed);
             $app['EM']->persist($user);
             $app['EM']->flush();
         } elseif ($pub_restrict == 1) {
             $collections = $app['acl']->get($user)->get_granted_base();
             $collection = array_shift($collections);
             if (!$collection instanceof collection) {
                 foreach ($appbox->get_databoxes() as $databox) {
                     foreach ($databox->get_collections() as $coll) {
                         $collection = $coll;
                         break;
                     }
                     if ($collection instanceof collection) {
                         break;
                     }
                 }
             }
             if (!$collection instanceof collection) {
                 return false;
             }
             $feed->setCollection($collection);
         }
         self::$feeds[$user_key][$feed_key] = $feed;
     } else {
         $feed = self::$feeds[$user_key][$feed_key];
     }
     return $feed;
 }