protected function displayContent() { $path = $this->app->config->blorg->path . 'tag'; $tags = $this->getTags(); if (count($tags) > 0) { $ul_tag = new SwatHtmlTag('ul'); if ($this->getValue('cloud_view')) { $ul_tag->class = 'blorg-tag-cloud'; } $ul_tag->open(); $max = 0; foreach ($tags as $tag) { if ($tag->post_count > $max) { $max = $tag->post_count; } } $locale = SwatI18NLocale::get(); foreach ($tags as $tag) { if ($tag->post_count > 0 || $this->getValue('show_empty')) { $popularity = $tag->post_count / $max; $li_tag = new SwatHtmlTag('li'); $li_tag->open(); $tag_span_tag = new SwatHtmlTag('span'); $tag_span_tag->class = $this->getTagClass($popularity); $tag_span_tag->open(); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = $path . '/' . $tag->shortname; $anchor_tag->setContent($tag->title); $anchor_tag->display(); if ($this->getValue('show_post_counts')) { echo ' '; $span_tag = new SwatHtmlTag('span'); $span_tag->setContent(sprintf(Blorg::ngettext('(%s post)', '(%s posts)', $tag->post_count), $locale->formatNumber($tag->post_count))); $span_tag->display(); } if ($this->getValue('show_feed_links')) { echo ' '; $span_tag = new SwatHtmlTag('span'); $span_tag->class = 'feed'; $span_tag->open(); echo '('; $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->class = 'feed'; $anchor_tag->href = $path . '/' . $tag->shortname . '/feed'; $anchor_tag->setContent('Feed'); $anchor_tag->display(); echo ')'; $span_tag->close(); } $tag_span_tag->close(); // breaking space for inline list items in cloud view if ($this->getValue('cloud_view')) { echo ' '; } $li_tag->close(); } } $ul_tag->close(); } }
protected function displayArchive() { $path = $this->app->config->blorg->path . 'tag'; $locale = SwatI18NLocale::get(); $ul_tag = new SwatHtmLTag('ul'); $ul_tag->class = 'blorg-archive-tags'; $ul_tag->open(); foreach ($this->tags as $tag) { $li_tag = new SwatHtmlTag('li'); $li_tag->open(); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = sprintf('%s/%s', $path, $tag->shortname); $anchor_tag->setContent($tag->title); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $tag->post_count), $locale->formatNumber($tag->post_count))); $heading_tag = new SwatHtmlTag('h4'); $heading_tag->class = 'blorg-archive-tag-title'; $heading_tag->open(); $anchor_tag->display(); $post_count_span->display(); $heading_tag->close(); $li_tag->close(); } $ul_tag->close(); }
protected function buildInternal() { parent::buildInternal(); $locale = SwatI18NLocale::get(); $item_list = $this->getItemList('integer'); $dep = new AdminListDependency(); $dep->setTitle(CME::_('CME front matter'), CME::_('CME front matters')); $sql = sprintf('select CMEFrontMatter.id, sum(CMECredit.hours) as hours from CMEFrontMatter left outer join CMECredit on CMECredit.front_matter = CMEFrontMatter.id where CMEFrontMatter.id in (%s) group by CMEFrontMatter.id', $item_list); $rs = SwatDB::query($this->app->db, $sql); $class_name = SwatDBClassMap::get('CMEFrontMatter'); foreach ($rs as $row) { $front_matter = new $class_name($row); $front_matter->setDatabase($this->app->db); $row->status_level = AdminDependency::DELETE; $row->parent = null; // not using ngettext because hours is a float $row->title = sprintf($row->hours == 1 ? CME::_('%s (1 hour)') : CME::_('%s (%s hours)'), $front_matter->getProviderTitleList(), $locale->formatNumber($row->hours)); $dep->entries[] = new AdminDependencyEntry($row); } $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) { $this->switchToCancelButton(); } }
protected function displayContent() { $stats = $this->getPhotoStats(); if ($stats->last_date === null) { echo Pinhole::_('No photos have been added.'); } else { $locale = SwatI18NLocale::get(); $first_date = new SwatDate($stats->first_date); $last_date = new SwatDate($stats->last_date); echo '<ul>'; $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Pinhole::_('%s photos have been uploaded since ' . '<a href="%stag?date.date=%s">%s</a>'), $locale->formatNumber($stats->photo_count), $this->app->config->pinhole->path, $first_date->formatLikeIntl('yyyy-MM-dd'), $first_date->formatLikeIntl(SwatDate::DF_DATE)), 'text/xml'); $li_tag->display(); $days = $last_date->diff($first_date)->days; $avg = round((double) $stats->photo_count / (double) $days, 2); $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Pinhole::_('Approximately %s photos have been uploaded ' . 'per day'), $locale->formatNumber($avg))); $li_tag->display(); $li_tag->setContent(sprintf(Pinhole::_('Last photo uploaded on ' . '<a href="%stag?date=%s">%s</a>'), $this->app->config->pinhole->path, $last_date->formatLikeIntl('yyyy-MM-dd'), $last_date->formatLikeIntl(SwatDate::DF_DATE)), 'text/xml'); $li_tag->display(); $tag_stats = $this->getTagStats(); if ($tag_stats->tag_count > 0) { $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Pinhole::_('<a href="%s/tags/alphabetical">%s tags</a> ' . 'have been added'), $this->app->config->pinhole->path, $locale->formatNumber($tag_stats->tag_count)), 'text/xml'); $li_tag->display(); $a_tag = new SwatHtmlTag('a'); $a_tag->setContent($tag_stats->popular_tag_title); $a_tag->href = $this->app->config->pinhole->path . 'tag?' . SwatString::minimizeEntities($tag_stats->popular_tag_name); $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Pinhole::_('The most popular tag “%s” has %s photos'), (string) $a_tag, $locale->formatNumber($tag_stats->popular_tag_count)), 'text/xml'); $li_tag->display(); } echo '</ul>'; } }
protected function buildInternal() { parent::buildInternal(); $locale = SwatI18NLocale::get(); $item_list = $this->getItemList('integer'); $dep = new AdminListDependency(); $dep->setTitle(CME::_('CME credit'), CME::_('CME credits')); $sql = sprintf('select CMECredit.* from CMECredit where CMECredit.id in (%s)', $item_list); $credits = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMECreditWrapper')); foreach ($credits as $credit) { $data = new stdClass(); $data->id = $credit->id; $data->status_level = AdminDependency::DELETE; $data->parent = null; $data->title = $credit->getTitle(); $dep->entries[] = new AdminDependencyEntry($data); } $message = $this->ui->getWidget('confirmation_message'); $message->content = $dep->getMessage(); $message->content_type = 'text/xml'; if ($dep->getStatusLevelCount(AdminDependency::DELETE) === 0) { $this->switchToCancelButton(); } }
protected function displayContent() { $comments = $this->getComments(); if (count($comments) == 0) { echo Pinhole::_('No comments have been made.'); } else { $locale = SwatI18NLocale::get(); echo '<ul>'; foreach ($comments as $comment) { echo '<li>'; $date = new SwatDate($comment->createdate); $date->convertTZById($this->app->config->date->time_zone); $date_diff = $date->getHumanReadableDateDiff(); $author = $comment->photographer === null ? $comment->fullname : $comment->photographer->fullname; $a_tag = new SwatHtmlTag('a'); $a_tag->href = sprintf('photo/%s#comment%s', $comment->getInternalValue('photo'), $comment->id); $a_tag->setContent(sprintf('%s ago by %s', $date_diff, $author)); $a_tag->display(); $div_tag = new SwatHtmlTag('div'); $div_tag->setContent(SwatString::ellipsizeRight(SwatString::condense($comment->bodytext), 100)); $div_tag->display(); echo '</li>'; } echo '</ul>'; } }
protected function processDBData() { parent::processDBData(); $locale = SwatI18NLocale::get(); $relocate = true; $message = null; $delete_count = 0; $error_count = 0; $newsletters = $this->getNewsletters(); foreach ($newsletters as $newsletter) { // only allow deleting unsent newsletters. There is nothing // technically stopping us from deleting ones that have been sent, // but do this for the sake of stats until deleting sent newsletters // is required. if ($newsletter->isSent() == false) { $list = $this->getList($newsletter); $campaign_type = $newsletter->instance instanceof SiteInstance ? $newsletter->instance->shortname : null; $campaign = $newsletter->getCampaign($this->app, $campaign_type); $transaction = new SwatDBTransaction($this->app->db); try { // If not a draft, remove the resources. Don't delete draft // newsletter resources as they are shared across all // drafts. if ($newsletter->isScheduled()) { DeliveranceCampaign::removeResources($this->app, $campaign); } $list->deleteCampaign($campaign); $sql = 'delete from Newsletter where id = %s'; $sql = sprintf($sql, $this->app->db->quote($newsletter->id, 'integer')); $delete_count += SwatDB::exec($this->app->db, $sql); $transaction->commit(); } catch (DeliveranceAPIConnectionException $e) { $transaction->rollback(); $e->processAndContinue(); $error_count++; $relocate = false; } catch (Exception $e) { $transaction->rollback(); $e = new DeliveranceException($e); $e->processAndContinue(); $error_count++; $relocate = false; } } } if ($delete_count > 0) { $message = new SwatMessage(sprintf(Deliverance::ngettext('One newsletter has been deleted.', '%s newsletters have been deleted.', $delete_count), $locale->formatNumber($delete_count)), 'notice'); $this->app->messages->add($message); } if ($error_count > 0) { $message = new SwatMessage(Deliverance::_('There was an issue connecting to the email service ' . 'provider.'), 'error'); $message->content_type = 'text/xml'; $message->secondary_content = sprintf('<strong>%s</strong><br />%s', sprintf(Deliverance::ngettext('One newsletter has not been deleted.', '%s newsletters have not been deleted.', $error_count), $locale->formatNumber($error_count)), Deliverance::ngettext('Connection issues are typically short-lived and ' . 'attempting to delete the newsletter again after a ' . 'delay will usually be successful.', 'Connection issues are typically short-lived and ' . 'attempting to delete the newsletters again after a ' . 'delay will usually be successful.', $error_count)); } return $relocate; }
protected function displayTitle() { $list = $this->tag_list; if ($list->getGeoTaggedPhotoCount() == $list->getPhotoCount()) { $message = Pinhole::_('View all of these photos on a map.'); } else { $locale = SwatI18NLocale::get(); $message = sprintf(Pinhole::_('View %s of these photos on a map.'), $locale->formatNumber($list->getGeoTaggedPhotoCount())); } echo SwatString::minimizeEntities($message); }
public static function formatCreditHours($hours) { $locale = SwatI18NLocale::get(); // When displaying credit hours round to single place except when there // are quarter hours, aka two digits past the decimal, where the last // digit is not zero. // Examples: // 4 -> 4.0 // 4.5 -> 4.5 // 4.50 -> 4.5 // 4.25 -> 4.25 $decimal_places = strlen(substr(strrchr($hours, "."), 1)) === 2 && substr($hours, -1) !== '0' ? 2 : 1; return $locale->formatNumber($hours, $decimal_places); }
public static function displayCalendarBody(SiteWebApplication $app, SwatDate $date) { if (isset($app->memcache)) { $cache_key = sprintf('PinholeCalendarGadget.%s.%s.%s', 'displayCalendarBody', $date->getISO8601(), $app->session->isLoggedIn() ? 'private' : 'public'); $body = $app->memcache->getNs('photos', $cache_key); if ($body !== false) { echo $body; return; } } ob_start(); $day_count = self::getPhotoCountPerDay($app, $date); echo '<table>'; $wd = new SwatDate(); $wd->setDate(1995, 1, 1); echo '<tr class="days-of-week">'; for ($i = 1; $i <= 7; $i++) { echo '<td>' . $wd->formatLikeIntl('EEE') . '</td>'; $wd->setDay($i + 1); } echo '</tr>'; $locale = SwatI18NLocale::get(); $start = -1 * $date->getDayOfWeek() + 1; $current_date = clone $date; for ($i = 0; $i <= 41; $i++) { $day = $i + $start; if ($i == 0) { echo '<tr>'; } elseif ($i % 7 == 0) { echo '</tr><tr>'; } if ($day > 0 && $day <= $date->getDaysInMonth()) { $current_date->setDay($day); if (array_key_exists($day, $day_count)) { printf('<td class="has-photos">' . '<a href="%stag?date.date=%s" ' . 'title="%s %s">%s</a></td>', $app->config->pinhole->path, $current_date->formatLikeIntl('yyyy-MM-dd'), $locale->formatNumber($day_count[$day]), Pinhole::ngettext('Photo', 'Photos', $day_count[$day]), $day); } else { echo '<td>' . $day . '</td>'; } } else { echo '<td> </td>'; } } echo '</tr></table>'; $body = ob_get_clean(); if (isset($app->memcache)) { $app->memcache->setNs('photos', $cache_key, $body); } echo $body; }
protected function displayArchive() { $years = $this->getYears(); if (count($years) === 0) { return; } $current_year = date('Y'); $path = $this->app->config->blorg->path . 'archive'; $locale = SwatI18NLocale::get(); $year_ul_tag = new SwatHtmLTag('ul'); $year_ul_tag->class = 'blorg-archive-years'; $year_ul_tag->open(); foreach ($years as $year => $values) { $year_li_tag = new SwatHtmlTag('li'); $year_li_tag->open(); $year_anchor_tag = new SwatHtmlTag('a'); $year_anchor_tag->href = sprintf('%s/%s', $path, $year); $year_anchor_tag->setContent($year); $year_anchor_tag->display(); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $values['post_count']), $locale->formatNumber($values['post_count']))); $post_count_span->display(); // show month links for current year if ($year == $current_year) { $month_ul_tag = new SwatHtmlTag('ul'); $month_ul_tag->open(); foreach ($values['months'] as $month => $post_count) { $date = new SwatDate(); $date->setMonth($month); $month_li_tag = new SwatHtmlTag('li'); $month_li_tag->open(); $month_anchor_tag = new SwatHtmlTag('a'); $month_anchor_tag->href = sprintf('%s/%s/%s', $path, $year, BlorgPageFactory::$month_names[$month]); $month_anchor_tag->setContent($date->formatLikeIntl('MMMM')); $month_anchor_tag->display(); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $post_count), $locale->formatNumber($post_count))); $post_count_span->display(); $month_li_tag->close(); } $month_ul_tag->close(); } $year_li_tag->close(); } $year_ul_tag->close(); }
protected function displayContent() { $conversations = $this->getActiveConversations(); if (count($conversations) > 0) { // get last visited date based on cookie value if ($this->app->hasModule('SiteCookieModule')) { $cookie = $this->app->getModule('SiteCookieModule'); try { if (isset($cookie->last_visit_date)) { $last_visit_date = new SwatDate($cookie->last_visit_date); } else { $last_visit_date = new SwatDate(); } } catch (SiteCookieException $e) { $last_visit_date = new SwatDate(); } } else { $last_visit_date = new SwatDate(); } echo '<ul>'; $locale = SwatI18NLocale::get(); $class_name = SwatDBClassMap::get('BlorgPost'); foreach ($conversations as $conversation) { $post = new $class_name($conversation); $last_comment_date = new SwatDate($conversation->last_comment_date); $last_comment_date->setTZById('UTC'); $li_tag = new SwatHtmlTag('li'); // is last comment is later than last visit date, mark as new if (SwatDate::compare($last_comment_date, $last_visit_date) > 0) { $li_tag->class = 'new'; } $li_tag->open(); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = $this->getPostRelativeUri($post); $anchor_tag->setContent($post->getTitle()); $span_tag = new SwatHtmlTag('span'); $span_tag->setContent(sprintf(Blorg::ngettext('(%s comment)', '(%s comments)', $post->getVisibleCommentCount()), $locale->formatNumber($post->getVisibleCommentCount()))); $anchor_tag->display(); echo ' '; $span_tag->display(); $li_tag->close(); } echo '</ul>'; } }
protected function displayContent() { $cache_module = isset($this->app->memcache) ? $this->app->memcache : null; $tag_list = new PinholeTagList($this->app, null, $this->app->session->isLoggedIn()); if ($tag_list->getGeoTaggedPhotoCount() == 0) { echo Pinhole::_('There are no tags with geo-tagged data.'); } else { $locale = SwatI18NLocale::get(); echo sprintf(Pinhole::_('%s photos can be %sviewed on a map%s.'), $locale->formatNumber($tag_list->getGeoTaggedPhotoCount()), '<a href="' . $this->app->config->pinhole->path . 'map' . '">', '</a>'); $map = new PinholeStaticMapView(); $map->setTagList($tag_list); $map->api_key = $this->app->config->pinhole->google_maps_api_key; $map->width = 250; $map->height = 150; $map->base = $this->app->config->pinhole->path . 'map'; $map->display(); } }
protected function displayArchive() { $path = $this->app->config->blorg->path . 'archive'; $locale = SwatI18NLocale::get(); $year_ul_tag = new SwatHtmLTag('ul'); $year_ul_tag->class = 'blorg-archive-years'; $year_ul_tag->open(); foreach ($this->years as $year => $values) { $year_li_tag = new SwatHtmlTag('li'); $year_li_tag->open(); $year_anchor_tag = new SwatHtmlTag('a'); $year_anchor_tag->href = sprintf('%s/%s', $path, $year); $year_anchor_tag->setContent($year); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $values['post_count']), $locale->formatNumber($values['post_count']))); $year_heading_tag = new SwatHtmlTag('h4'); $year_heading_tag->class = 'blorg-archive-year-title'; $year_heading_tag->open(); $year_anchor_tag->display(); $post_count_span->display(); $year_heading_tag->close(); $month_ul_tag = new SwatHtmlTag('ul'); $month_ul_tag->open(); foreach ($values['months'] as $month => $post_count) { $date = new SwatDate(); // Set year and day so we're sure it's a valid date, otherwise // the month may not be set. $date->setDate(2010, $month, 1); $month_li_tag = new SwatHtmlTag('li'); $month_li_tag->open(); $month_anchor_tag = new SwatHtmlTag('a'); $month_anchor_tag->href = sprintf('%s/%s/%s', $path, $year, BlorgPageFactory::$month_names[$month]); $month_anchor_tag->setContent($date->getMonthName()); $month_anchor_tag->display(); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $post_count), $locale->formatNumber($post_count))); $post_count_span->display(); $month_li_tag->close(); } $month_ul_tag->close(); $year_li_tag->close(); } $year_ul_tag->close(); }
protected function getContainer() { if (isset($this->app->memcache)) { $cache_key = sprintf('PinholeMetaDataGadget.getContainer.%s', $this->app->session->isLoggedIn() ? 'private' : 'public'); $container = $this->app->memcache->getNs('photos', $cache_key); if ($container !== false) { return $container; } } $sections = $this->getMetaDataSections(); $values = $this->getMetaDataValues(); $locale = SwatI18NLocale::get(); $container = new SwatContainer(); foreach ($sections as $section) { $disclosure = new SwatDisclosure(); $disclosure->title = $section->title; $disclosure->open = false; ob_start(); echo '<ul>'; foreach ($values as $value) { if ($value->meta_data == $section->id) { echo '<li class="clearfix"><div>'; $a_tag = new SwatHtmlTag('a'); $a_tag->href = sprintf('%stag?meta.%s=%s', $this->app->config->pinhole->path, $section->shortname, PinholePhotoMetaDataBinding::escapeValue($value->value)); $a_tag->setContent(PinholePhotoMetaDataBinding::getFormattedValue($section->shortname, $value->value)); $a_tag->display(); echo ' <span>' . $locale->formatNumber($value->photo_count) . '</span>'; echo '</div></li>'; } } echo '</ul>'; $content = new SwatContentBlock(); $content->content_type = 'text/xml'; $content->content = ob_get_clean(); $disclosure->add($content); $container->add($disclosure); } if (isset($this->app->memcache)) { $this->app->memcache->setNs('photos', $cache_key, $container); } return $container; }
protected function displayContent() { $articles = $this->getArticles(); if (count($articles) > 0) { echo '<ul>'; $locale = SwatI18NLocale::get(); foreach ($articles as $article) { echo '<li>'; $title_div = new SwatHtmlTag('div'); $title_div->open(); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = $this->getArticleRelativeUri($article); $anchor_tag->setContent($article->title); $anchor_tag->display(); $title_div->close(); $content_div = new SwatHtmlTag('div'); $content_div->setContent($article->description, 'text/xml'); $content_div->display(); echo '</li>'; } echo '</ul>'; } }
protected function updateSegment(DeliveranceList $list, DeliveranceCampaignSegment $segment) { if ($list->isAvailable()) { $this->debug(sprintf(Deliverance::_('Updating ‘%s’... '), $segment->title)); try { $size = $list->getSegmentSize($segment->getSegmentOptions()); $segment->cached_segment_size = $size; $segment->save(); $locale = SwatI18NLocale::get(); $this->debug(sprintf(Deliverance::_('found %s subscribers.') . "\n", $locale->formatNumber($size))); } catch (DeliveranceApiConnectionException $e) { // ignore these exceptions. segment sizes will be updated next // time around. $this->debug(sprintf(Deliverance::_('list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } catch (Exception $e) { $e = new DeliveranceException($e); $e->processAndContinue(); $this->debug(sprintf(Deliverance::_('Update error. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } } else { $this->debug(sprintf(Deliverance::_('Mailing list unavailable. Segment ‘%s’ was not updated.') . "\n", $segment->title)); } }
protected function getReplacementMarkerText($marker_id) { $locale = SwatI18NLocale::get(); switch ($marker_id) { case 'account-full-name': return $this->account->getFullName(); case 'cme-certificate-link': return $this->getCertificateLinkURI(); case 'quiz-passing-grade': return $locale->formatNumber($this->front_matter->passing_grade * 100) . '%'; case 'quiz-grade': $grade = $this->response->getGrade(); return $locale->formatNumber(round($grade * 1000) / 10) . '%'; default: return parent::getReplacementMarkerText($marker_id); } }
protected function getContainer() { $date = new SwatDate(); if (isset($this->app->memcache)) { $cache_key = sprintf('PinholeDateBrowserGadget.getContent.%s.%s', $date->formatLikeIntl('MM/yyyy'), $this->app->session->isLoggedIn() ? 'private' : 'public'); $container = $this->app->memcache->getNs('photos', $cache_key); if ($container !== false) { return $container; } } $container = new SwatContainer(); $months = $this->getMonths(); if (count($months) == 0) { $content = new SwatContentBlock(); $content->content = Pinhole::_('No photos have been uploaded yet.'); $container->add($content); return $container; } $months_array = array(); foreach ($months as $month) { $date = new SwatDate($month->photo_date); $key = $date->getYear() . '/' . $date->getMonth(); $months_array[$key] = $month; } $locale = SwatI18NLocale::get(); $start_date = new SwatDate($months->getFirst()->photo_date); $start_year = $start_date->getYear(); $index = count($months) - 1; $end_date = new SwatDate($months->getByIndex($index)->photo_date); $end_year = $end_date->getYear(); $date = new SwatDate(); $date->clearTime(); for ($year = $start_year; $year >= $end_year; $year--) { $year_count = 0; $disclosure = new SwatDisclosure(); $disclosure->title = $year; $disclosure->open = false; ob_start(); echo '<ul>'; for ($i = 1; $i <= 12; $i++) { echo '<li class="clearfix"><div>'; $date->setDate($year, $i, 1); if (isset($months_array[$year . '/' . $i])) { $a_tag = new SwatHtmlTag('a'); $a_tag->setContent($date->getMonthName()); $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year . '/date.month=' . $i; $a_tag->display(); $photo_count = $months_array[$year . '/' . $i]->photo_count; echo '<span>' . $locale->formatNumber($photo_count) . '</span>'; $year_count += $photo_count; } else { $div_tag = new SwatHtmlTag('div'); $div_tag->setContent($date->getMonthName()); $div_tag->display(); } echo '</div></li>'; if ($i == 12 && $year_count > 0) { echo '<li class="clearfix"><div>'; $a_tag = new SwatHtmlTag('a'); $a_tag->setContent(sprintf(Pinhole::_('View all photos from %s'), $year)); $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year; $a_tag->display(); echo '<span>' . $locale->formatNumber($year_count) . '</span>'; echo '</div></li>'; } } echo '</ul>'; $content = new SwatContentBlock(); $content->content_type = 'text/xml'; $content->content = ob_get_clean(); $disclosure->add($content); $container->add($disclosure); } if (isset($this->app->memcache)) { $this->app->memcache->setNs('photos', $cache_key, $container); } return $container; }
public function getCreditTitle($hours, $credit_count = 1, $is_free = false) { $locale = SwatI18NLocale::get(); return sprintf(SwatString::minimizeEntities($is_free ? CME::_('%s Free %s%s%s certified by %s') : CME::_('%s %s%s%s certified by %s')), SwatString::minimizeEntities($locale->formatNumber($hours)), '<em>', abs($hours - 1.0) < 0.01 ? SwatString::minimizeEntities($this->credit_title) : SwatString::minimizeEntities($this->credit_title_plural), '</em>', SwatString::minimizeEntities($this->title)); }
private function displayPhotoGrid(PinholePhotoWrapper $photos, $tag_list, array $box) { $ui = new SwatUI(); $ui->loadFromXml(dirname(__FILE__) . '/map-tile.xml'); $store = new SwatTableStore(); foreach ($photos as $photo) { $ds = new SwatDetailsStore(); $ds->photo = $photo; $ds->root_path = $this->app->config->pinhole->path; $ds->path = 'photo/' . $photo->id; if ($tag_list !== null) { $ds->path .= '?' . $tag_list; } $ds->display_title = $this->app->config->pinhole->browser_index_titles; $store->add($ds); } $ui->getWidget('photo_view')->model = $store; $locale = SwatI18NLocale::get(); $h3_tag = new SwatHtmlTag('h3'); $h3_tag->setContent(sprintf(Pinhole::_('%s Photos, Displaying %s to %s'), $locale->formatNumber($this->photo_count), $locale->formatNumber(1), $locale->formatNumber(count($photos)))); $h3_tag->display(); if (count($photos) > 3) { echo '<div class="fixed-width-marker">'; $ui->display(); echo '</div>'; } else { $ui->display(); } if (count($photos) < $this->photo_count) { $a_tag = new SwatHtmlTag('a'); $a_tag->class = 'more-photos-link'; $a_tag->setContent(sprintf(Pinhole::_('View All %s Photos'), $locale->formatNumber($this->photo_count))); if ($box['min_latitude'] == $box['max_latitude'] && $box['min_longitude'] == $box['max_longitude']) { $a_tag->href = sprintf('tag?gps.latitude=%s/gps.longitude=%s', $box['min_latitude'], $box['min_longitude']); } else { $a_tag->href = sprintf('tag?gps.box=%sx%s|%sx%s', $box['max_latitude'], $box['min_longitude'], $box['min_latitude'], $box['max_longitude']); } if ($tag_list !== null) { $a_tag->href .= '/' . $tag_list; } $a_tag->display(); } }
/** * Displays the number of comments for a weblog post */ protected function displayCommentCount(BlorgPost $post) { if ($this->getMode('comment_count') > SiteView::MODE_NONE) { $link = $this->getLink('comment_count'); $count = $post->getVisibleCommentCount(); if ($link === false) { $comment_count_tag = new SwatHtmlTag('span'); } else { $comment_count_tag = new SwatHtmlTag('a'); if (is_string($link)) { $comment_count_tag->href = $link; } else { $comment_count_tag->href = $this->getRelativeUri($post) . '#comments'; } switch ($post->comment_status) { case SiteCommentStatus::LOCKED: $comment_count_tag->title = sprintf(Blorg::_('View comments for %s'), $post->getTitle()); break; case SiteCommentStatus::OPEN: case SiteCommentStatus::MODERATED: $comment_count_tag->title = sprintf(Blorg::_('Comment on %s'), $post->getTitle()); break; } } $comment_count_tag->class = 'comment-count'; if ($count == 0) { $comment_count_tag->setContent(Blorg::_('leave a comment')); } else { $locale = SwatI18NLocale::get(); $comment_count_tag->setContent(sprintf(Blorg::ngettext('%s comment', '%s comments', $count), $locale->formatNumber($count))); } $comment_count_tag->display(); } }
protected function buildInfo() { $locale = SwatI18NLocale::get(); $info = $this->getInfo(); ob_start(); echo '<ul>'; $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Blorg::_('%s posts tagged %s times'), $locale->formatNumber($info['post_count'], 0), $locale->formatNumber($info['tag_count'], 0))); $li_tag->display(); $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Blorg::_('%s posts / month'), $locale->formatNumber($info['posts_per_month'], 2))); $li_tag->display(); echo '</ul><ul>'; $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Blorg::_('%s comments'), $locale->formatNumber($info['comment_count'], 0))); $li_tag->display(); $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf(Blorg::_('%s comments / day'), $locale->formatNumber($info['comments_per_day'], 2))); $li_tag->display(); echo '</ul>'; // author warning if ($this->getVisibleAuthorCount() === 0) { $this->ui->getWidget('new_post')->visible = false; $this->ui->getWidget('manage_authors')->visible = true; echo '<p><strong>', Blorg::_('Warning:'), '</strong> '; echo Blorg::_('At least one author must be set to “show on site” in ' . 'order to create new posts.'); echo '</p>'; } $this->ui->getWidget('info')->content = ob_get_clean(); $this->ui->getWidget('info')->content_type = 'text/xml'; }
protected function displayQuizDetailsIncomplete() { $locale = SwatI18NLocale::get(); // quiz description $description = $this->getQuizDescription(); if ($description != '') { echo '<div class="quiz-description">'; echo $description; echo '</div>'; } // passing grade echo '<div class="quiz-passing-grade">'; $grade_span = new SwatHtmlTag('span'); $grade_span->setContent($locale->formatNumber($this->front_matter->passing_grade * 100) . '%'); printf(CME::_('A grade of %s is required'), $grade_span); echo '</div>'; // number of questions and time estimate echo '<div class="quiz-intro-status">'; $total_questions = count($this->quiz->question_bindings); if ($total_questions > 30) { $time_estimate = round($total_questions * 2 / 30) / 2; $time_estimate = sprintf(CME::ngettext('one hour', '%s hours', $time_estimate), $locale->formatNumber($time_estimate)); } else { $time_estimate = ceil($total_questions * 2 / 10) * 10; $time_estimate = sprintf(CME::_('%s minutes'), $locale->formatNumber($time_estimate)); } printf(CME::_('%s questions, about %s.'), $locale->formatNumber($total_questions), $time_estimate); echo '</div>'; }
protected function displayRadioEntryQuestion(InquisitionQuestion $question, array $response_values) { $locale = SwatI18NLocale::get(); echo $this->convertText($question->bodytext); echo '<ul>'; $option_counts = array(); $option_values = array(); $total_count = 0; if (count($response_values) > 0) { foreach ($response_values as $value) { // Optional questions that are unanswered can have rows in the // db with no question options set, so ignore those rows. if ($value->question_option instanceof InquisitionQuestionOption) { $option_text = $value->question_option->title; if (!isset($option_counts[$option_text])) { $option_counts[$option_text] = 0; } $option_counts[$option_text]++; if ($value->text_value != '') { if (!isset($option_values[$option_text])) { $option_values[$option_text] = array(); } $option_values[$option_text][] = $value->text_value; } $total_count++; } } foreach ($question->options as $option) { if (isset($option_counts[$option->title])) { $percent = $option_counts[$option->title] / $total_count; $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(sprintf('%s - %s%% (%s)', $this->convertText($option->title), $locale->formatNumber(round($percent * 1000) / 10), $locale->formatNumber($option_counts[$option->title]))); $li_tag->open(); $li_tag->displayContent(); $this->displayBar($percent); if (isset($option_values[$option->title])) { echo '<ul>'; foreach ($option_values[$option->title] as $text) { $li_tag = new SwatHtmlTag('li'); $li_tag->setContent($this->convertText($text)); $li_tag->display(); } echo '</ul>'; } $li_tag->close(); } } } else { $li_tag = new SwatHtmlTag('li'); $li_tag->setContent(CME::_('There were no responses for this question.')); $li_tag->display(); } echo '</ul>'; }
/** * Displays the number of posts for a weblog author */ protected function displayPostCount(BlorgAuthor $author) { switch ($this->getMode('post_count')) { case SiteView::MODE_ALL: $link = $this->getLink('post_count'); $count = count($author->getVisiblePosts()); if ($link === false) { $post_count_tag = new SwatHtmlTag('span'); } else { $post_count_tag = new SwatHtmlTag('a'); if (is_string($link)) { $post_count_tag->href = $link; } else { $post_count_tag->href = $this->getRelativeUri($author) . '#posts'; } } $post_count_tag->class = 'post-count'; if ($count == 0) { $post_count_tag->setContent(Blorg::_('no posts')); } else { $locale = SwatI18NLocale::get(); $post_count_tag->setContent(sprintf(Blorg::ngettext('%s post', '%s posts', $count), $locale->formatNumber($count))); } $post_count_tag->display(); break; case SiteView::MODE_SUMMARY: $count = count($author->getVisiblePosts()); if ($count > 0) { $link = $this->getLink('post_count'); if ($link === false) { $post_count_tag = new SwatHtmlTag('span'); } else { $post_count_tag = new SwatHtmlTag('a'); if (is_string($link)) { $post_count_tag->href = $link; } else { $post_count_tag->href = $this->getRelativeUri($author) . '#posts'; } } $post_count_tag->class = 'author-post-count'; $locale = SwatI18NLocale::get(); $post_count_tag->setContent(sprintf(Blorg::ngettext('(%s post)', '(%s posts)', $count), $locale->formatNumber($count))); $post_count_tag->display(); } break; } }
protected function getListOptionTitle(CMEFrontMatter $front_matter) { $account = $this->app->session->account; $hours = $account->getEarnedCMECreditHoursByFrontMatter($front_matter); $locale = SwatI18NLocale::get(); ob_start(); $this->displayTitle($front_matter); $field = abs($hours - 1.0) < 0.01 ? 'credit_title' : 'credit_title_plural'; $titles = array(); foreach ($front_matter->providers as $provider) { $em_tag = new SwatHtmlTag('em'); $em_tag->setContent($provider->{$field}); $titles[] = $em_tag->__toString(); } $formatted_provider_credit_title = SwatString::toList($titles); $hours_span = new SwatHtmlTag('span'); $hours_span->class = 'hours'; $hours_span->setContent(sprintf(CME::_('%s %s from %s'), SwatString::minimizeEntities($locale->formatNumber($hours)), $formatted_provider_credit_title, SwatString::minimizeEntities($front_matter->getProviderTitleList())), 'text/xml'); $hours_span->display(); $details = $this->getFrontMatterDetails($front_matter); if ($details != '') { $details_span = new SwatHtmlTag('span'); $details_span->class = 'details'; $details_span->setContent($details); $details_span->display(); } return ob_get_clean(); }
protected function buildSegments() { if (count($this->segments) > 0) { $segment_widget = $this->ui->getWidget('campaign_segment'); $segment_widget->parent->visible = true; $locale = SwatI18NLocale::get(); $last_instance_title = null; foreach ($this->segments as $segment) { if ($this->app->isMultipleInstanceAdmin() && $segment->instance instanceof SiteInstance && $last_instance_title != $segment->instance->title) { $last_instance_title = $segment->instance->title; $segment_widget->addDivider(sprintf('<span class="instance-header">%s</span>', $last_instance_title), 'text/xml'); } if ($segment->cached_segment_size > 0) { $subscribers = sprintf(Deliverance::ngettext('One subscriber', '%s subscribers', $segment->cached_segment_size), $locale->formatNumber($segment->cached_segment_size)); } else { $subscribers = Deliverance::_('No subscribers'); } $title = sprintf('%s <span class="swat-note">(%s)</span>', $segment->title, $subscribers); if ($segment->cached_segment_size > 0) { $segment_widget->addOption($segment->id, $title, 'text/xml'); } else { // TODO, use a real option and disable it. $segment_widget->addDivider($title, 'text/xml'); } } } }
protected function getConfirmationMessage() { $locale = SwatI18NLocale::get(); ob_start(); printf('<p>%s</p><p>%s</p>', sprintf(Deliverance::ngettext('The newsletter “%s” will be sent to one subscriber.', 'The newsletter “%s” will be sent to %s subscribers.', $this->send_count), $this->newsletter->subject, $locale->formatNumber($this->send_count)), Deliverance::_('Subscriber counts are estimates. Full statistics ' . 'will be available once the newsletter has been sent.')); return ob_get_clean(); }
/** * Gets a formatted value * * @return string The formatted value. */ private static function formatExposureTime($value) { $values = explode('/', $value); if (count($values) == 2 && $values[1] > 0) { $seconds = (double) $values[0] / (double) $values[1]; } else { $seconds = (double) $value; } $locale = SwatI18NLocale::get(); $output = sprintf(Pinhole::ngettext('%s second', '%s seconds', $seconds == 1 ? 1 : 0), $locale->formatNumber(round($seconds, 6))); $fraction = self::formatAsFraction($value); if ($fraction !== null) { $output = $fraction . ' (' . $output . ')'; } return $output; }