protected function saveDBData() { $values = $this->ui->getValues(array('name', 'shortname', 'visible', 'description', 'bodytext', 'openid_server', 'openid_delegate', 'email')); $this->author->name = $values['name']; $this->author->shortname = $values['shortname']; $this->author->visible = $values['visible']; $this->author->description = $values['description']; $this->author->bodytext = $values['bodytext']; $this->author->openid_server = $values['openid_server']; $this->author->openid_delegate = $values['openid_delegate']; $this->author->email = $values['email']; if ($this->id === null) { $this->author->instance = $this->app->getInstanceId(); } if ($this->author->isModified()) { $this->author->save(); if (isset($this->app->memcache)) { $this->app->memcache->flushNs('authors'); // only clear the posts when editing an existing author if ($this->id !== null) { $this->app->memcache->flushNs('posts'); } } $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->author->name)); $this->app->messages->add($message); } }
protected function initAuthor($shortname) { $this->author = false; if (isset($this->app->memcache)) { $key = 'author_' . $shortname; $this->author = $this->app->memcache->getNs('authors', $key); } if ($this->author === false) { $class_name = SwatDBClassMap::get('BlorgAuthor'); $this->author = new $class_name(); $this->author->setDatabase($this->app->db); if (!$this->author->loadByShortname($shortname, $this->app->getInstance())) { throw new SiteNotFoundException('Author not found.'); } if (!$this->author->visible) { throw new SiteNotFoundException('Author not found.'); } if (isset($this->app->memcache)) { $this->app->memcache->setNs('authors', $key, $this->author); } } else { $this->author->setDatabase($this->app->db); } }
/** * 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; } }