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>'; } }
/** * Gets earned CME credits to include in the quarterly report * * Credits are included if and only if: * * - the credit is earned * - the provider is the specified provider * - the earned date is within the quarter * - the account is not deleted * * @return array */ protected function getEarnedCredits() { $sql = sprintf('select AccountEarnedCMECredit.* from AccountEarnedCMECredit inner join Account on AccountEarnedCMECredit.account = Account.id inner join CMECredit on AccountEarnedCMECredit.credit = CMECredit.id inner join CMEFrontMatter on CMECredit.front_matter = CMEFrontMatter.id where CMEFrontMatter.id in ( select CMEFrontMatterProviderBinding.front_matter from CMEFrontMatterProviderBinding where CMEFrontMatterProviderBinding.provider = %s ) and convertTZ(earned_date, %s) >= %s and convertTZ(earned_date, %s) < %s and Account.delete_date is null', $this->app->db->quote($this->provider->id, 'integer'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->start_date->getDate(), 'date'), $this->app->db->quote($this->app->config->date->time_zone, 'text'), $this->app->db->quote($this->end_date->getDate(), 'date')); $earned_credits = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper')); // efficiently load accounts $accounts = $this->loadAccounts($earned_credits); // load addresses $addresses = $this->loadAccountAddresses($accounts); // efficiently load credits $credits = $this->loadCredits($earned_credits); // sort earned credits (sorting is application specific) $earned_credits_array = $earned_credits->getArray(); usort($earned_credits_array, array($this, 'compareEarnedCredit')); return $earned_credits_array; }
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 initPost($year, $month_name, $shortname) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException('Post not found.'); } // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, BlorgPageFactory::$months_by_name[$month_name], 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $loader->addSelectField('title'); $loader->addSelectField('bodytext'); $loader->addSelectField('extended_bodytext'); $loader->addSelectField('shortname'); $loader->addSelectField('publish_date'); $loader->addSelectField('author'); $loader->addSelectField('comment_status'); $loader->addSelectField('visible_comment_count'); $loader->setLoadFiles(true); $loader->setLoadTags(true); $loader->setWhereClause(sprintf('enabled = %s', $this->app->db->quote(true, 'boolean'))); $this->post = $loader->getPostByDateAndShortname($date, $shortname); if ($this->post === null) { throw new SiteNotFoundException('Post not found.'); } }
public function getDate() { $unix_time = strtotime($this->campaign['send_time']); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
public function getDate() { $unix_time = strtotime($this->status->created_at); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
public function getDate() { $date_string = $this->xpath->evaluate("string(pubDate)", $this->element); $unix_time = strtotime($date_string); $date = new SwatDate(); $date->setTimestamp($unix_time); $date->toUTC(); return $date; }
public function convertData($data) { $data = parent::convertData($data); if ($data === null && !$this->convert_null_to_now) { return null; } $date = new SwatDate($data); $date->setTZbyID($this->src_tz_id); $date->convertTZbyID($this->dst_tz_id); $data = $date->getDate(); return $data; }
/** * Returns an XHTML calendar with photo counts * * @param integer $year The year to display * @param integer $month The month to display * * @return string an XHTML calendar. */ public function getCalendar($year, $month) { $date = new SwatDate(); $date->setDate($year, $month, 1); $date->setTime(0, 0, 0); ob_start(); PinholeCalendarGadget::displayCalendarMonth($this->app, $date); $response['calendar_month'] = ob_get_clean(); ob_start(); PinholeCalendarGadget::displayCalendarBody($this->app, $date); $response['calendar_body'] = ob_get_clean(); return $response; }
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(); }
/** * Gets translatable string resources for the JavaScript object for * this gadget * * @return string translatable JavaScript string resources for this gadget. */ protected function getInlineJavaScriptTranslations() { $throbber_text = Blorg::_('loading …'); $visit_text = Blorg::_('Visit the Last.fm page for this track'); $none_text = Blorg::_('‹none›'); $months = array(); $short_months = array(); $date = new SwatDate('2000-01-01T00:00:00Z'); for ($i = 1; $i <= 12; $i++) { $months[] = SwatString::quoteJavaScriptString($date->formatLikeIntl('MMMM')); $short_months[] = SwatString::quoteJavaScriptString($date->formatLikeIntl('MMM')); $date->setMonth($i + 1); } $months = implode(', ', $months); $short_months = implode(', ', $short_months); return sprintf("BlorgLastFmGadget.throbber_text = '%s';\n" . "BlorgLastFmGadget.visit_text = '%s';\n" . "BlorgLastFmGadget.none_text = '%s';\n" . "BlorgLastFmGadget.months = [%s];\n" . "BlorgLastFmGadget.short_months = [%s];\n", $throbber_text, $visit_text, $none_text, $months, $short_months); }
protected function initReport() { $quarter = SiteApplication::initVar('quarter', null, SiteApplication::VAR_GET); if ($quarter === null || preg_match('/^2[0-9]{3}-0[1-4]$/', $quarter) === 0) { throw new AdminNotFoundException('Invalid quarter.'); } list($year, $quarter) = explode('-', $quarter, 2); $start_month = (intval($quarter) - 1) * 3 + 1; $quarter = new SwatDate(); $quarter->setTime(0, 0, 0); $quarter->setDate($year, $start_month, 1); $quarter->setTZ($this->app->default_time_zone); $quarter->toUTC(); $type = SiteApplication::initVar('type', null, SiteApplication::VAR_GET); $provider = new CMEProvider(); $provider->setDatabase($this->app->db); if (!$provider->loadByShortname($type)) { throw new AdminNotFoundException('Invalid CME provider.'); } $sql = sprintf('select * from QuizReport where quarter = %s and provider = %s', $this->app->db->quote($quarter->getDate(), 'date'), $this->app->db->quote($provider->id, 'integer')); $this->report = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('CMEQuizReportWrapper'))->getFirst(); if (!$this->report instanceof CMEQuizReport) { throw new AdminNotFoundException(sprintf('Report not found for quarter %s.', $quarter->getDate())); } $this->report->setFileBase('../../system/quiz-report-updater'); if (!file_exists($this->report->getFilePath())) { throw new AdminNotFoundException(sprintf('Report file ‘%s’ not found', $this->report->getFilePath())); } }
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>'; } }
/** * Saves this object to the database * * Only modified properties are updated. */ protected function saveInternal() { if ($this->id === null) { $this->shortname = $this->generateShortname($this->title); $this->createdate = new SwatDate(); $this->createdate->toUTC(); } parent::saveInternal(); }
public function getCampaignShortname() { if ($this->send_date === null) { $shortname = Deliverance::_('DRAFT'); } else { $shortname = $this->send_date->formatLikeIntl('yy-MM-dd'); } return $shortname; }
protected function initComments($year, $month_name, $shortname, $page) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, BlorgPageFactory::$months_by_name[$month_name], 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $loader->addSelectField('title'); $loader->addSelectField('bodytext'); $loader->addSelectField('shortname'); $loader->addSelectField('publish_date'); $loader->addSelectField('author'); $loader->addSelectField('visible_comment_count'); $loader->setWhereClause(sprintf('enabled = %s', $this->app->db->quote(true, 'boolean'))); $this->post = $loader->getPostByDateAndShortname($date, $shortname); if ($this->post === null) { throw new SiteNotFoundException('Post not found.'); } $this->total_count = $this->post->getVisibleCommentCount(); $this->comments = false; if (isset($this->app->memcache)) { $key = $this->getCommentsCacheKey(); $this->comments = $this->app->memcache->getNs('posts', $key); } if ($this->comments === false) { $offset = ($page - 1) * $this->getPageSize(); $this->comments = $this->post->getVisibleComments($this->getPageSize(), $offset); if (isset($this->app->memcache)) { $this->app->memcache->setNs('posts', $key, $this->comments); } } else { $this->comments->setDatabase($this->app->db); } if ($page > 1 && count($this->comments) === 0) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } }
protected function saveDBData() { $values = $this->ui->getValues(array('title', 'name', 'event', 'archived')); $this->tag->title = $values['title']; $this->tag->name = $values['name']; $this->tag->event = $values['event']; $this->tag->archived = $values['archived']; if ($this->id === null) { $now = new SwatDate(); $this->tag->createdate = $now->getDate(); } $flush_cache = $this->tag->isModified() && $this->tag->id !== null; $this->tag->save(); $this->addToSearchQueue(); if (isset($this->app->memcache) && $flush_cache) { $this->app->memcache->flushNs('photos'); } $message = new SwatMessage(sprintf(Pinhole::_('“%s” has been saved.'), $this->tag->title)); $this->app->messages->add($message); }
protected function saveDBData() { $values = $this->ui->getValues(array('title', 'shortname')); $this->tag->title = $values['title']; -($this->tag->shortname = $values['shortname']); if ($this->id === null) { $now = new SwatDate(); $now->toUTC(); $this->tag->createdate = $now; $this->tag->instance = $this->app->getInstanceId(); } if ($this->tag->isModified()) { $this->tag->save(); if (isset($this->app->memcache)) { $this->app->memcache->flushNs('tags'); // only clear the posts when editing an existing tag if ($this->id !== null) { $this->app->memcache->flushNs('posts'); } } $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->tag->title)); $this->app->messages->add($message); } }
protected function displayByDateAdded(PinholeTagList $tag_list) { $now = new SwatDate(); $now->convertTZById($this->app->config->date->time_zone); $store = new SwatTableStore(); foreach ($tag_list as $tag) { $ds = new SwatDetailsStore(); $ds->tag = $tag; $tag_date = $tag->getDataObject()->first_modified; $tag_date->convertTZById($this->app->config->date->time_zone); $days_past = $now->diff($tag_date)->days; if ($days_past <= 1) { $ds->date_part = Pinhole::_('Today'); } elseif ($days_past <= $now->getDayOfWeek() + 1) { $ds->date_part = Pinhole::_('This Week'); } elseif ($days_past <= $now->getDay()) { $ds->date_part = Pinhole::_('This Month'); } elseif ($days_past <= $now->getDayOfYear()) { $ds->date_part = Pinhole::_('This Year'); } else { $ds->date_part = sprintf(Pinhole::_('%s'), $tag_date->getYear()); } $store->add($ds); } $ul_tag = new SwatHtmlTag('ul'); $li_tag = new SwatHtmlTag('li'); $ul_tag->open(); $part = null; foreach ($store as $ds) { if ($part !== $ds->date_part) { if ($part !== null) { $li_tag->close(); } $li_tag->open(); $h2_tag = new SwatHtmlTag('h2'); $h2_tag->class = 'pinhole-tag-entity'; $h2_tag->setContent($ds->date_part); $h2_tag->display(); } elseif ($part !== null) { echo ', '; } $this->displayTag($ds->tag); $part = $ds->date_part; } $li_tag->close(); $ul_tag->close(); }
protected function createBlorgFile(SwatFileEntry $file, $path) { $now = new SwatDate(); $now->toUTC(); $class_name = SwatDBClassMap::get('BlorgFile'); $blorg_file = new $class_name(); $blorg_file->setDatabase($this->app->db); $blorg_file->setFileBase($path); $blorg_file->createFileBase($path); $blorg_file->visible = false; $blorg_file->filename = $file->getUniqueFileName($path); $blorg_file->mime_type = $file->getMimeType(); $blorg_file->filesize = $file->getSize(); $blorg_file->createdate = $now; $blorg_file->instance = $this->app->getInstanceId(); $blorg_file->save(); $file->saveFile($path, $blorg_file->filename); return $blorg_file->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 static function isShortnameValid(SiteApplication $app, BlorgPost $post) { // get publish date in local time if ($post->publish_date === null) { $publish_date = new SwatDate(); $publish_date->convertTZ($app->default_time_zone); } else { $publish_date = clone $post->publish_date; $publish_date->setTZ($app->default_time_zone); } $instance_id = $app->getInstanceId(); $sql = 'select shortname from BlorgPost where shortname = %s and instance %s %s and id %s %s and date_trunc(\'month\', convertTZ(publish_date, %s)) = date_trunc(\'month\', timestamp %s)'; $sql = sprintf($sql, $app->db->quote($post->shortname, 'text'), SwatDB::equalityOperator($instance_id), $app->db->quote($instance_id, 'integer'), SwatDB::equalityOperator($post->id, true), $app->db->quote($post->id, 'integer'), $app->db->quote($publish_date->getTimezone()->getName(), 'text'), $app->db->quote($publish_date->getDate(), 'date')); $query = SwatDB::query($app->db, $sql); return count($query) == 0; }
protected function getInfo() { $instance_id = $this->app->getInstanceId(); $sql = sprintf('select count(1) as post_count, sum(visible_comment_count) as comment_count, min(publish_date) as start_date from BlorgPost left outer join BlorgPostVisibleCommentCountView as v on BlorgPost.id = v.post and BlorgPost.instance = v.instance where BlorgPost.instance %s %s and BlorgPost.enabled = %s and BlorgPost.publish_date is not null', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean')); $post_info = SwatDB::queryRow($this->app->db, $sql, array('integer', 'integer', 'date')); $sql = sprintf('select sum(post_count) as tag_count from BlorgTagVisiblePostCountView as v inner join BlorgTag on BlorgTag.id = v.tag where instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $tag_info = SwatDB::queryRow($this->app->db, $sql, array('integer')); $start_date = new SwatDate($post_info->start_date); $now = new SwatDate(); $start_month = $start_date->getMonth(); $end_month = $now->getMonth(); $start_year = $start_date->getYear(); $end_year = $now->getYear(); if ($start_month > $end_month) { $end_month += 12; $end_year--; } $months = $end_month - $start_month + ($end_year - $start_year) * 12; $days = $now->diff($start_date)->days; $posts_per_month = $months == 0 ? 0 : $post_info->post_count / $months; $comments_per_day = $days == 0 ? 0 : $post_info->comment_count / $days; return array('post_count' => $post_info->post_count, 'posts_per_month' => $posts_per_month, 'comment_count' => $post_info->comment_count, 'comments_per_day' => $comments_per_day, 'tag_count' => $tag_info->tag_count); }
protected function displayMonths() { $path = $this->app->config->blorg->path . 'archive'; $view = SiteViewFactory::get($this->app, 'post'); $view->setPartMode('title', SiteView::MODE_SUMMARY); $view->setPartMode('bodytext', SiteView::MODE_NONE); $view->setPartMode('extended_bodytext', SiteView::MODE_NONE); $view->setPartMode('tags', SiteView::MODE_NONE); $view->setPartMode('files', SiteView::MODE_NONE); $ul_tag = new SwatHtmlTag('ul'); $ul_tag->class = 'blorg-archive-months'; $ul_tag->open(); foreach ($this->months as $month => $posts) { $li_tag = new SwatHtmlTag('li'); $li_tag->open(); $heading_tag = new SwatHtmlTag('h4'); $heading_tag->class = 'blorg-archive-month-title'; $heading_tag->open(); $date = new SwatDate(); $date->setDate(2010, $month, 1); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = sprintf('%s/%s/%s', $path, $this->year, BlorgPageFactory::$month_names[$month]); $anchor_tag->setContent($date->getMonthName()); $anchor_tag->display(); $heading_tag->close(); $post_ul_tag = new SwatHtmlTag('ul'); $post_ul_tag->class = 'entries'; $post_ul_tag->open(); foreach ($posts as $post) { $post_li_tag = new SwatHtmlTag('li'); $post_li_tag->open(); $view->display($post); $post_li_tag->close(); } $post_ul_tag->close(); $li_tag->close(); } $ul_tag->close(); }
protected function loadDBData() { $this->ui->setValues(get_object_vars($this->post)); $this->bodytext_control->value = $this->post->bodytext; $this->extended_bodytext_control->value = $this->post->extended_bodytext; if ($this->post->publish_date !== null) { $publish_date = new SwatDate($this->post->publish_date); $publish_date->convertTZ($this->app->default_time_zone); $this->ui->getWidget('publish')->setPublishDate($publish_date, $this->post->enabled === false); } $this->ui->getWidget('author')->value = $this->post->author->id; $tags = array(); foreach ($this->post->tags as $tag) { $tags[$tag->shortname] = $tag->title; } $this->ui->getWidget('tags')->setSelectedTagArray($tags); }
public function getPostByDateAndShortname(SwatDate $date, $shortname) { $post = false; if ($this->memcache !== null) { $key = $date->formatLikeIntl('yyyyMMdd') . $shortname; $key = $this->getPostCacheKey($key); $post = $this->memcache->getNs('posts', $key); } if ($post === false) { $sql = $this->getSelectClause(); $sql .= $this->getWhereClause(); $sql .= sprintf(' and BlorgPost.shortname = %s and date_trunc(\'month\', convertTZ(publish_date, %s)) = date_trunc(\'month\', timestamp %s)', $this->db->quote($shortname, 'text'), $this->db->quote($date->getTimezone()->getName(), 'text'), $this->db->quote($date->getDate(), 'date')); $this->db->setLimit(1, 0); $post_wrapper = SwatDBClassMap::get('BlorgPostWrapper'); $posts = SwatDB::query($this->db, $sql, $post_wrapper); if (in_array('author', $this->fields)) { $this->loadPostAuthors($posts); } if ($this->load_files) { $this->loadPostFiles($posts); } if ($this->load_tags) { $this->loadPostTags($posts); } $post = $posts->getFirst(); if ($this->memcache !== null) { $this->memcache->setNs('posts', $key, $post); } } else { if ($post !== null) { $post->setDatabase($this->db); } } return $post; }
protected function getFilename(SwatDate $quarter, CMEProvider $provider) { // replace spaces with dashes $title = str_replace(' ', '-', $provider->title); // strip non-word or dash characters $title = preg_replace('/[^\\w-]/', '', $title); return sprintf($this->getFilenamePattern(), $title, $quarter->formatLikeIntl('QQQ-yyyy')); }
protected function saveEarnedCredits(CMEAccount $account, CMEFrontMatter $front_matter) { $wrapper = SwatDBClassMap::get('CMEAccountEarnedCMECreditWrapper'); $class_name = SwatDBClassMap::get('CMEAccountEarnedCMECredit'); $earned_credits = new $wrapper(); $earned_date = new SwatDate(); $earned_date->toUTC(); foreach ($front_matter->credits as $credit) { if ($credit->isEarned($account)) { // check for existing earned credit before saving $sql = sprintf('select count(1) from AccountEarnedCMECredit where credit = %s and account = %s', $this->app->db->quote($credit->id, 'integer'), $this->app->db->quote($account->id, 'integer')); if (SwatDB::queryOne($this->app->db, $sql) == 0) { $earned_credit = new $class_name(); $earned_credit->account = $account->id; $earned_credit->credit = $credit->id; $earned_credit->earned_date = $now; $earned_credits->add($earned_credit); } } } $earned_credits->setDatabase($this->app->db); $earned_credits->save(); }
/** * Gets a summary of the number of photos in this tag list indexed * and grouped by the specified date part * * @param string $date_part the date part with which to index and group * photo counts. * * @return array an array indexed by the relevant date part with values * indicating the number of photos in the tag list * for the date part index. If the tag list has no photos * on a specific date, the returned array does not contain * an index at that date. */ public function getPhotoCountByDate($date_part) { $args = func_get_args(); $cache_key = $this->getCacheKey(__FUNCTION__, $args); $value = $this->app->getCacheValue($cache_key, 'photos'); if ($value !== false) { return $value; } $group_by_parts = array(); switch ($date_part) { case 'day': $group_by_parts[] = 'day'; $group_by_parts[] = 'month'; $group_by_parts[] = 'year'; $date_format = 'yyyy-MM-dd'; break; case 'month': $group_by_parts[] = 'month'; $group_by_parts[] = 'year'; $date_format = 'yyyy-MM'; break; case 'year': $group_by_parts[] = 'year'; $date_format = 'yyyy'; break; } $group_by_clause = ''; $count = 0; foreach ($group_by_parts as $part) { if ($count > 0) { $group_by_clause .= ', '; } $group_by_clause .= sprintf('date_part(%s, convertTZ(PinholePhoto.photo_date, PinholePhoto.photo_time_zone))', $this->db->quote($part, 'text')); $count++; } $sql = 'select count(PinholePhoto.id) as photo_count, max(convertTZ(PinholePhoto.photo_date, PinholePhoto.photo_time_zone)) as photo_date from PinholePhoto inner join ImageSet on PinholePhoto.image_set = ImageSet.id'; $join_clauses = implode(' ', $this->getJoinClauses()); if ($join_clauses != '') { $sql .= ' ' . $join_clauses . ' '; } $where_clause = $this->getWhereClause(); if ($where_clause != '') { $sql .= ' where ' . $where_clause; } if ($group_by_clause != '') { $sql .= ' group by ' . $group_by_clause; } $rows = SwatDB::query($this->db, $sql, null); $dates = array(); while ($row = $rows->fetchRow(MDB2_FETCHMODE_OBJECT)) { if ($row->photo_date === null) { continue; } $date = new SwatDate($row->photo_date); $dates[$date->formatLikeIntl($date_format)] = $row->photo_count; } $this->app->addCacheValue($dates, $cache_key, 'photos'); return $dates; }
protected function selectSwatDateEntry($id, SwatDate $date) { static $month_map = array('January' => '01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'); $year = $date->getYear(); $month = $date->getMonth(); $day = $date->getDay(); $year_select = 'xpath=//select[@id=\'' . $id . '_year\']'; $month_select = 'xpath=//select[@id=\'' . $id . '_month\']'; $day_select = 'xpath=//select[@id=\'' . $id . '_day\']'; // get year info $year_options = $this->getSelectOptions($year_select); $start_year = $year_options[1]; $end_year = end($year_options); // get month info if ($this->isElementPresent($month_select)) { $month_options = $this->getSelectOptions($month_select); $start_month = preg_replace('/[^A-Za-z]/', '', $month_options[1]); $start_month = $month_map[$start_month]; $end_month = preg_replace('/[^A-Za-z]/', '', end($month_options)); $end_month = $month_map[$end_month]; } else { $start_month = '01'; $end_month = '01'; } // get day info if ($this->isElementPresent($day_select)) { $day_options = $this->getSelectOptions($day_select); $start_day = sprintf('%02d', $day_options[1]); $end_day = sprintf('%02d', end($day_options)); } else { $start_day = '01'; $end_day = '01'; } // validate ranges $start_date = new SwatDate($start_year . $start_month . $start_day); $end_date = new SwatDate($end_year . $end_month . $end_day); $this->assertFalse($date->before($start_date), 'Date specified in test (' . $date . ') is before the minimum ' . 'selectable date (' . $start_date . ').'); $this->assertFalse($date->after($end_date), 'Date specified in test (' . $date . ') is after the maximum ' . 'selectable date (' . $end_date . ').'); // select year $year_index = $year - intval($start_year) + 1; $this->select($year_select, 'index=' . $year_index); // select month if ($this->isElementPresent($month_select)) { $month_index = $month - intval($start_month) + 1; $this->select($month_select, 'index=' . $month_index); } // select day if ($this->isElementPresent($day_select)) { $day_index = $day - intval($start_day) + 1; $this->select($day_select, 'index=' . $day_index); } }