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 saveDBData() { $this->updatePost(); $modified = $this->post->isModified(); // save the post $this->post->save(); // save tags $tags = $this->getTags(); $result = $this->post->setTagsByShortName($tags); $tags_modified = $result['added'] > 0 || $result['removed'] > 0; $modified = $modified || $tags_modified; $instance_id = $this->app->getInstanceId(); // update files attached to the form to be attached to the post if ($this->id === null) { $form = $this->ui->getWidget('edit_form'); $unique_id = $form->getHiddenField('unique_id'); $sql = sprintf('update BlorgFile set post = %s, form_unique_id = null where form_unique_id = %s and post is null and instance %s %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($unique_id, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer')); $num = SwatDB::exec($this->app->db, $sql); $modified = $modified || $num > 0; } if ($modified) { // clear cache if (isset($this->app->memcache)) { $this->app->memcache->flushNs('posts'); $old_date = $this->original_publish_date; $new_date = $this->post->publish_date; if ($old_date instanceof SwatDate && $new_date instanceof SwatDate) { $date_modified = SwatDate::compare($old_date, $new_date) !== 0; } elseif ($old_date instanceof SwatDate && $new_date === null) { $date_modified = true; } elseif ($old_date === null && $new_date instanceof SwatDate) { $date_modified = true; } else { $date_modified = $old_date !== $new_date; } if ($this->original_enabled !== $this->post->enabled || $date_modified || $tags_modified) { $this->app->memcache->flushNs('tags'); } } $this->addToSearchQueue(); $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->post->getTitle())); // ping weblogs if ($this->post->enabled && $this->pingWeblogsDotCom()) { $message->secondary_content = Blorg::_('Weblogs.com has been notified of updated content.'); } $this->app->messages->add($message); } }
/** * Checks whether or not this date tag applies to a given photo * * @param PinholePhoto the photo to check. * * @return boolean true if this tag applies to the given photo and false if * this tag does not apply to the given photo. */ public function appliesToPhoto(PinholePhoto $photo) { switch ($this->name) { case 'date': $date = new SwatDate($this->value); // database content is always UTC $date->setTime(0, 0, 0); $date->toUTC(); $applies = SwatDate::compare($photo->photo_date, $date) == 0; break; case 'week': if (ctype_digit($this->value)) { // get date by week number $days = ($this->value - 1) * 7; $start_date = new SwatDate(); $start_date->setMonth(1); $start_date->setDay(1); $start_date->addDays($days); // beginning of next week $end_date = clone $start_date; $end_date->addDays(7 - $end_date->getDayOfWeek()); } else { // beginning of week $start_date = new SwatDate($this->value); $start_date->subtractDays($start_date->getDayOfWeek()); // beginning of next week $end_date = new SwatDate($this->value); $end_date->addDays(7 - $end_date->getDayOfWeek()); } // database content is always UTC $start_date->setTime(0, 0, 0); $end_date->setTime(0, 0, 0); $start_date->toUTC(); $end_date->toUTC(); $applies = SwatDate::compare($photo->photo_date, $start_date) >= 0 && SwatDate::compare($photo->photo_date, $end_date) <= 0; break; case 'year': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getYear() == $this->value; break; case 'month': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getMonth() == $this->value; break; case 'day': $local_photo_date = clone $photo->photo_date; $local_photo_date->convertTZById($photo->photo_time_zone); $applies = $local_photo_date->getDay() == $this->value; break; default: $applies = false; break; } return $applies; }