function getContent() { $hp = Codendi_HTMLPurifier::instance(); $content = ''; if ($this->rss_url) { require_once 'common/rss/libs/SimplePie/simplepie.inc'; if (!is_dir($GLOBALS['codendi_cache_dir'] . '/rss')) { mkdir($GLOBALS['codendi_cache_dir'] . '/rss'); } $rss = new SimplePie($this->rss_url, $GLOBALS['codendi_cache_dir'] . '/rss', null, $GLOBALS['sys_proxy']); $max_items = 10; $items = array_slice($rss->get_items(), 0, $max_items); $content .= '<table width="100%">'; $i = 0; foreach ($items as $item) { $content .= '<tr class="' . util_get_alt_row_color($i++) . '"><td WIDTH="99%">'; if ($image = $item->get_link(0, 'image')) { //hack to display twitter avatar $content .= '<img src="' . $hp->purify($image, CODENDI_PURIFIER_CONVERT_HTML) . '" width="48" height="48" style="float:left; margin-right:1em;" />'; } $content .= '<a href="' . $item->get_link() . '">' . $hp->purify($item->get_title(), CODENDI_PURIFIER_STRIP_HTML) . '</a>'; if ($item->get_date()) { $content .= '<span style="color:#999;" title="' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $item->get_date('U')) . '"> - ' . DateHelper::timeAgoInWords($item->get_date('U')) . '</span>'; } $content .= '</td></tr>'; } $content .= '</table>'; } return $content; }
private function getRemoteRepositoryInfoError() { $date = DateHelper::timeAgoInWords($this->project_creator_status->getEventDate($this->repository), false, true); $url = GIT_BASE_URL . '/?action=repo_management&group_id=' . $this->repository->getProjectId() . '&repo_id=' . $this->repository->getId() . '&pane=gerrit'; $html = ''; $html .= '<div class="alert alert-error gerrit_url">'; $html .= $GLOBALS['Language']->getText('plugin_git', 'delegated_to_gerrit_error', array($date, $url), CODENDI_PURIFIER_DISABLED); $html .= '</div>'; return $html; }
function getContent() { $hp = Codendi_HTMLPurifier::instance(); $content = ''; if ($this->twitterfollow_user) { require_once 'common/rss/libs/SimplePie/simplepie.inc'; if (!is_dir($GLOBALS['codendi_cache_dir'] . '/rss')) { mkdir($GLOBALS['codendi_cache_dir'] . '/rss'); } $twitterfollow = new SimplePie($this->getFeedUrl($this->twitterfollow_user), $GLOBALS['codendi_cache_dir'] . '/rss', null, $GLOBALS['sys_proxy']); $max_items = 10; $items = array_slice($twitterfollow->get_items(), 0, $max_items); $content .= '<table width="100%">'; $i = 0; foreach ($items as $i => $item) { $content .= '<tr class="' . util_get_alt_row_color($i++) . '"><td WIDTH="99%">'; $content .= '<div style="float:right;">'; $content .= '<a title="Reply" href="' . $this->getReplyToUrl($this->twitterfollow_user, basename($item->get_link())) . '">'; $content .= $GLOBALS['HTML']->getImage('ic/twitter_reply.gif'); $content .= '</a>'; $content .= '</div>'; $content .= '<span'; if ($i == 1) { $content .= ' style="font-size:1.5em">'; if ($image = $item->get_link(0, 'image')) { //hack to display twitter avatar $image = preg_replace('/_normal\\.(jpg|png|gif)$/i', '_bigger.$1', $image); $content .= '<a href="http://twitter.com/' . urlencode($this->twitterfollow_user) . '">'; $content .= '<img src="' . $hp->purify($image, CODENDI_PURIFIER_CONVERT_HTML) . '" width="48" height="48" style="float:left; margin-right:1em;" />'; $content .= '</a>'; } } else { $content .= '>'; //end of <span } $content .= $item->get_title(); //Trust SimplePie for purifying if ($item->get_date()) { $content .= ' <span style="color:#999; white-space:nowrap;" title="' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $item->get_date('U')) . '">- ' . DateHelper::timeAgoInWords($item->get_date('U')) . '</span>'; } $content .= '</span>'; $content .= '</td></tr>'; } $content .= '</table>'; } return $content; }
/** * @return string html */ public function getDateSubmittedOn() { return DateHelper::timeAgoInWords($this->submitted_on, false, true); }
/** * Compute the content of the widget * * @return String */ public function getContent() { $dao = new Git_LogDao(); $um = UserManager::instance(); $user = $um->getCurrentUser(); $date = $_SERVER['REQUEST_TIME'] - $this->pastDays * 24 * 60 * 60; $result = $dao->getLastPushesRepositories($user->getId(), $date); $content = ''; $project = ''; $dh = new DateHelper(); if ($result && !$result->isError()) { foreach ($result as $entry) { if (!empty($entry['repository_namespace'])) { $namespace = $entry['repository_namespace'] . "/"; } else { $namespace = ''; } $dar = $dao->getLastPushesByUser($user->getId(), $entry['repository_id'], $this->offset, $date); if ($dar && !$dar->isError() && $dar->rowCount() > 0) { if ($project != $entry['group_name']) { if (!empty($project)) { $content .= '</fieldset>'; } $project = $entry['group_name']; $content .= '<fieldset> <legend id="plugin_git_user_pushes_widget_project_' . $project . '" class="' . Toggler::getClassname('plugin_git_user_pushes_widget_project_' . $project) . '"> <span title="' . $GLOBALS['Language']->getText('plugin_git', 'tree_view_project') . '"> <b>' . $project . '</b> </span> </legend> <a href="' . $this->pluginPath . '/index.php?group_id=' . $entry['group_id'] . '">[ ' . $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_details') . ' ]</a>'; } $content .= '<fieldset> <legend id="plugin_git_user_pushes_widget_repo_' . $project . $namespace . $entry['repository_name'] . '" class="' . Toggler::getClassname('plugin_git_user_pushes_widget_repo_' . $project . $namespace . $entry['repository_name']) . '"> <span title="' . $GLOBALS['Language']->getText('plugin_git', 'tree_view_repository') . '"> ' . $namespace . $entry['repository_name'] . ' </span> </legend> ' . html_build_list_table_top(array($GLOBALS['Language']->getText('plugin_git', 'tree_view_date'), $GLOBALS['Language']->getText('plugin_git', 'tree_view_commits'))); $i = 0; $hp = Codendi_HTMLPurifier::instance(); foreach ($dar as $row) { $content .= '<tr class="' . html_get_alt_row_color(++$i) . '"> <td><span title="' . $dh->timeAgoInWords($row['push_date'], true) . '">' . $hp->purify(format_date($GLOBALS['Language']->getText('system', 'datefmt'), $row['push_date'])) . '</span></td> <td> <a href="' . $this->pluginPath . '/index.php/' . $entry['group_id'] . '/view/' . $entry['repository_id'] . '/"> ' . $hp->purify($row['commits_number']) . ' </a> </td> </tr>'; } $content .= "</table>\n </fieldset>"; } else { $content .= $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_no_content'); } } } else { $content = $GLOBALS['Language']->getText('plugin_git', 'widget_user_pushes_no_content'); } return $content; }
public function testDateInFuture() { expect($GLOBALS['Language'])->getText()->count(2); expect($GLOBALS['Language'])->getText('include_utils', 'time_in_future', '*')->at(1); DateHelper::timeAgoInWords($_SERVER['REQUEST_TIME'] + 500); }
/** * Returns the HTML code of this comment * * @return string the HTML code of this comment */ public function fetchFollowUp() { if ($this->hasEmptyBody()) { return null; } $uh = UserHelper::instance(); $html = '<div class="tracker_artifact_followup_comment_edited_by">'; if ($this->parent_id) { $html .= $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'last_edited'); $html .= ' ' . $uh->getLinkOnUserFromUserId($this->submitted_by) . ' '; $html .= DateHelper::timeAgoInWords($this->submitted_on, false, true); } $html .= '</div>'; if (!empty($this->body)) { $html .= '<input type="hidden" id="tracker_artifact_followup_comment_body_format_' . $this->changeset->getId() . '" name="tracker_artifact_followup_comment_body_format_' . $this->changeset->getId() . '" value="' . $this->bodyFormat . '" />'; $html .= '<div class="tracker_artifact_followup_comment_body">'; if ($this->parent_id && !trim($this->body)) { $html .= '<em>' . $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'comment_cleared') . '</em>'; } else { $html .= $this->getPurifiedBodyForHTML(); } $html .= '</div>'; } return $html; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_Date $value The changeset value for this field * @return string */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if (!$value) { // TODO use $changeset instead of $artifact->getLastChangeset() // see @todo in the comment $value = $this->getChangesetValue($artifact->getLastChangeset(), null, false); } $value = $value->getTimestamp(); $value = $value ? DateHelper::timeAgoInWords($value) : ''; $html .= $value; return $html; }
/** * Fetch some statistics about this tracker to display on trackers home page * * @return string html */ public function fetchStats() { $html = ''; if ($row = $this->getStats()) { $html .= '<div class="tracker_statistics" style="font-size:0.9em; color:#666;">'; $html .= '<div style="text-align:right;font-size:0.825em;">#' . $this->id . '</div>'; if ($row['nb_total'] && $this->hasSemanticsStatus()) { $html .= $GLOBALS['Language']->getText('plugin_tracker_stat', 'number_open_artifacts') . ' ' . $row['nb_open'] . '<br />'; } $html .= $GLOBALS['Language']->getText('plugin_tracker_stat', 'total_number_artifacts') . ' ' . $row['nb_total'] . '<br />'; if ($row['last_creation'] && $row['last_update']) { $html .= $GLOBALS['Language']->getText('plugin_tracker_stat', 'recent_activity'); $html .= '<ul>'; if ($row['last_update']) { $html .= '<li>' . $GLOBALS['Language']->getText('plugin_tracker_stat', 'last_update') . ' '; $html .= DateHelper::timeAgoInWords($row['last_update'], true, true); $html .= '</li>'; } if ($row['last_creation']) { $html .= '<li>' . $GLOBALS['Language']->getText('plugin_tracker_stat', 'last_artifact_created') . ' '; $html .= DateHelper::timeAgoInWords($row['last_creation'], true, true); $html .= '</li>'; } $html .= '</ul>'; } $html .= '</div>'; } return $html; }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_Date $value The changeset value for this field * @return string */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if (!$value) { $value = new Tracker_Artifact_ChangesetValue_Date(null, $this, false, $artifact->getSubmittedOn()); } $value = $value->getTimestamp(); $value = $value ? DateHelper::timeAgoInWords($value) : ''; $html .= $value; return $html; }
public function time() { return DateHelper::timeAgoInWords($this->changeset->getSubmittedOn()); }
/** * Fetch the html code to display the field value in tooltip * * @param Tracker_Artifact $artifact * @param Tracker_Artifact_ChangesetValue_Date $value The changeset value for this field * @return string */ protected function fetchTooltipValue(Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $value = null) { $html = ''; if ($value) { $html .= DateHelper::timeAgoInWords($value->getTimestamp()); } return $html; }
/** * fetch followup * * @param Tracker_Artifact_Changeset $previous_changeset The previous changeset * * @return string */ public function fetchFollowUp($previous_changeset) { $html = ''; $html .= '<div class="tracker_artifact_followup_header">'; $html .= '<div class="tracker_artifact_followup_title">'; //The permalink $html .= '<a href="#followup_' . $this->id . '">'; $html .= $GLOBALS['HTML']->getImage('ic/comment.png', array('border' => 0, 'alt' => 'permalink', 'class' => 'tracker_artifact_followup_permalink', 'style' => 'vertical-align:middle', 'title' => 'Link to this followup - #' . (int) $this->id)); $html .= '</a> '; //The submitter if ($this->submitted_by) { $uh = UserHelper::instance(); $submitter = $uh->getLinkOnUserFromUserId($this->submitted_by); } else { $hp = Codendi_HTMLPurifier::instance(); $submitter = $hp->purify($this->email, CODENDI_PURIFIER_BASIC); } $html .= '<span class="tracker_artifact_followup_title_user">' . $submitter . '</span>'; $html .= '</div>'; //The date $html .= '<div class="tracker_artifact_followup_date">'; $html .= DateHelper::timeAgoInWords($this->submitted_on, false, true); $html .= '</div>'; $html .= '</div>'; if (Config::get('sys_enable_avatars')) { if ($this->submitted_by) { $submitter = UserManager::instance()->getUserById($this->submitted_by); } else { $submitter = UserManager::instance()->getUserAnonymous(); $submitter->setEmail($this->email); } $html .= '<div class="tracker_artifact_followup_avatar">'; $html .= $submitter->fetchHtmlAvatar(); $html .= '</div>'; } // The content $html .= '<div class="tracker_artifact_followup_content">'; //The comment if ($comment = $this->getComment()) { if ($this->userCanEdit() || $this->userCanDelete()) { $html .= '<div class="tracker_artifact_followup_comment_controls">'; //edit if ($this->userCanEdit()) { $html .= '<a href="#" class="tracker_artifact_followup_comment_controls_edit">'; $html .= $GLOBALS['HTML']->getImage('ic/edit.png', array('border' => 0, 'alt' => $GLOBALS['Language']->getText('plugin_tracker_fieldeditor', 'edit'))); $html .= '</a>'; } //delete // We can't delete a snapshot since there is too many repercusion on subsequent changesets // If the deletion is for combatting spam, then edit and empty the comment // What would be nice is to make userCanDelete() return true only if the user has rights and the snapshot doesn't contain any changes //if ($this->userCanDelete()) { // $html .= '<a href="?'. http_build_query( // array( // 'aid' => $this->artifact->id, // 'func' => 'artifact-delete-changeset', // 'changeset' => $this->id, // ) // ).'" class="tracker_artifact_followup_comment_controls_close">'; // $html .= $GLOBALS['HTML']->getImage('ic/bin_closed.png', array('border' => 0, 'alt' => $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'del'))); // $html .= '</a>'; //} $html .= '</div>'; } $html .= '<div class="tracker_artifact_followup_comment">'; $html .= $comment->fetchFollowUp(); $html .= '</div>'; } //The changes if ($changes = $this->diffToPrevious()) { $html .= '<hr size="1" />'; $html .= '<ul class="tracker_artifact_followup_changes">'; $html .= $changes; $html .= '</ul>'; } $html .= '</div>'; $html .= '<div style="clear:both;"></div>'; return $html; }
public function getTimeAgo() { return DateHelper::timeAgoInWords($this->getFollowUpDate(), false, true); }
/** * Returns the HTML code of this comment * * @param String $format Format of the output * @param Boolean $forMail If the output is intended for mail notification then value should be true * @param Boolean $ignoreEmptyBody If true then display the user and the time even if the body is empty * * @return string the HTML code of this comment */ public function fetchFollowUp($format = 'html', $forMail = false, $ignoreEmptyBody = false) { if ($ignoreEmptyBody || !empty($this->body)) { $uh = UserHelper::instance(); $hp = Codendi_HTMLPurifier::instance(); switch ($format) { case 'html': $html = ''; if ($forMail) { $html .= '<div class="tracker_artifact_followup_title">'; $html .= '<span class="tracker_artifact_followup_title_user">'; $user = UserManager::instance()->getUserById($this->submitted_by); if ($user && !$user->isAnonymous()) { $html .= '<a href="mailto:' . $hp->purify($user->getEmail()) . '">' . $hp->purify($user->getRealName()) . ' (' . $hp->purify($user->getUserName()) . ')</a>'; } else { $user = UserManager::instance()->getUserAnonymous(); $user->setEmail($this->changeset->getEmail()); $html .= $GLOBALS['Language']->getText('tracker_include_artifact', 'anon_user'); } $html .= '</span></div>'; $timezone = ''; if ($user->getId() != 0) { $timezone = ' (' . $user->getTimezone() . ')'; } $html .= '<div class="tracker_artifact_followup_date">' . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $this->submitted_on) . $timezone . '</div>'; $html .= '</div>'; if (Config::get('sys_enable_avatars')) { $html .= '<div class="tracker_artifact_followup_avatar">'; $html .= $user->fetchHtmlAvatar(); $html .= '</div>'; } $html .= '<div class="tracker_artifact_followup_content">'; $html .= '<div class="tracker_artifact_followup_comment">'; } else { $html .= '<div class="tracker_artifact_followup_comment_edited_by">'; if ($this->parent_id) { $html .= $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'last_edited'); $html .= ' ' . $uh->getLinkOnUserFromUserId($this->submitted_by) . ' '; $html .= DateHelper::timeAgoInWords($this->submitted_on, false, true); } $html .= '</div>'; } if (!$forMail || !empty($this->body)) { $html .= '<input type="hidden" id="tracker_artifact_followup_comment_body_format_' . $this->changeset->getId() . '" name="tracker_artifact_followup_comment_body_format_' . $this->changeset->getId() . '" value="' . $this->bodyFormat . '" >'; $html .= '<div class="tracker_artifact_followup_comment_body">'; if ($this->parent_id && !trim($this->body)) { $html .= '<em>' . $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'comment_cleared') . '</em>'; } else { $html .= $this->getPurifiedBodyForHTML(); } $html .= '</div>'; } if ($forMail) { $html .= '</div>'; } return $html; break; default: $output = ''; //if ($this->parent_id) { //$output .= $GLOBALS['Language']->getText('plugin_tracker_include_artifact', 'last_edited'); //$output .= ' '.$uh->getDisplayNameFromUserId($this->submitted_by); //$output .= ' '.DateHelper::timeAgoInWords($this->submitted_on).PHP_EOL; //} if (!empty($this->body)) { $body = $this->getPurifiedBodyForText(); $output .= PHP_EOL . PHP_EOL . $body . PHP_EOL . PHP_EOL; } return $output; break; } } else { return null; } }
private function getMigratedToGerritError(Git_Driver_Gerrit_ProjectCreatorStatus $status) { $date = DateHelper::timeAgoInWords($status->getEventDate($this->repository), false, true); return '<div class="alert alert-error">' . $GLOBALS['Language']->getText('plugin_git', 'gerrit_server_migration_error', array($date)) . '</div>' . '<pre class="pre-scrollable">' . $status->getLog($this->repository) . '</pre>'; }