Esempio n. 1
0
 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();
     }
 }
Esempio n. 2
0
    protected function processDBData()
    {
        parent::processDBData();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        // delete attached files using their dataobjects to remove the actual
        // files
        $sql = sprintf('select * from BlorgFile
			inner join BlorgPost on BlorgPost.id = BlorgFile.post
			where BlorgPost.instance %s %s and BlorgFile.post in (%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $files = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgFileWrapper'));
        foreach ($files as $file) {
            $file->setFileBase('../');
            $file->delete();
        }
        // delete the posts
        $sql = sprintf('delete from BlorgPost
			where instance %s %s and id in (%s)', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $num = SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNS('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One post has been deleted.', '%s posts have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 3
0
    public function processActions(SwatTableView $view, SwatActions $actions)
    {
        $num = count($view->getSelection());
        $message = null;
        $items = SwatDB::implodeSelection($this->app->db, $view->getSelection(), 'integer');
        switch ($actions->selected->id) {
            case 'delete':
                $this->app->replacePage($this->getComponentName() . '/Delete');
                $this->app->getPage()->setItems($view->getSelection());
                break;
            case 'enable':
                $instance_id = $this->app->getInstanceId();
                $num = SwatDB::exec($this->app->db, sprintf('update BlorgAuthor set visible = %s
				where instance %s %s and id in (%s)', $this->app->db->quote(true, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $items));
                if ($num > 0 && isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('authors');
                }
                $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been shown on site.', '%s authors have been shown on site.', $num), SwatString::numberFormat($num)));
                break;
            case 'disable':
                $instance_id = $this->app->getInstanceId();
                $num = SwatDB::exec($this->app->db, sprintf('update BlorgAuthor set visible = %s
				where instance %s %s and id in (%s)', $this->app->db->quote(false, 'boolean'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $items));
                if ($num > 0 && isset($this->app->memcache)) {
                    $this->app->memcache->flushNs('authors');
                }
                $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been hidden on site.', '%s authors have been hidden on site.', $num), SwatString::numberFormat($num)));
                break;
        }
        if ($message !== null) {
            $this->app->messages->add($message);
        }
    }
Esempio n. 4
0
 protected function processDBData()
 {
     parent::processDBData();
     $item_list = $this->getItemList('integer');
     $sql = sprintf('delete from BlorgTag where id in (%s)', $item_list);
     $num = SwatDB::exec($this->app->db, $sql);
     if (isset($this->app->memcache)) {
         $this->app->memcache->flushNs('tags');
         $this->app->memcache->flushNs('posts');
     }
     $message = new SwatMessage(sprintf(Blorg::ngettext('One tag has been deleted.', '%s tags have been deleted.', $num), SwatString::numberFormat($num)));
     $this->app->messages->add($message);
 }
Esempio n. 5
0
    protected function processDBData()
    {
        parent::processDBData();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('delete from BlorgAuthor where id in (%s)
			and instance %s %s', $item_list, SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $num = SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNs('authors');
            $this->app->memcache->flushNs('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One author has been deleted.', '%s authors have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
 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>';
     }
 }
Esempio n. 7
0
    protected function processDBData()
    {
        parent::processDBData();
        $item_list = $this->getItemList('integer');
        $instance_id = $this->app->getInstanceId();
        $this->addToSearchQueue($item_list);
        $sql = sprintf('delete from BlorgComment
			where id in
				(select BlorgComment.id from BlorgComment
					inner join BlorgPost on BlorgPost.id = BlorgComment.post
				where instance %s %s and BlorgComment.id in (%s))', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $item_list);
        $num = SwatDB::exec($this->app->db, $sql);
        if (isset($this->app->memcache)) {
            $this->app->memcache->flushNS('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One comment has been deleted.', '%s comments have been deleted.', $num), SwatString::numberFormat($num)));
        $this->app->messages->add($message);
    }
Esempio n. 8
0
 /**
  * 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();
     }
 }
Esempio n. 9
0
 /**
  * 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;
     }
 }
Esempio n. 10
0
    protected function publishPosts(SwatViewSelection $post_ids)
    {
        $num = 0;
        $transaction = new SwatDBTransaction($this->app->db);
        try {
            $instance_id = $this->app->getInstanceId();
            $post_ids = SwatDB::implodeSelection($this->app->db, $post_ids);
            $sql = sprintf('select id, shortname, title, bodytext from BlorgPost
				where instance %s %s and id in (%s) and enabled = %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $post_ids, $this->app->db->quote(false, 'boolean'));
            $posts = SwatDB::query($this->app->db, $sql, SwatDBClassMap::get('BlorgPostWrapper'));
            foreach ($posts as $post) {
                if ($post->shortname === null) {
                    $post->shortname = $this->getPostShortname($post);
                }
                $post->enabled = true;
                $post->save();
                $num++;
            }
            $transaction->commit();
        } catch (Exception $e) {
            $transaction->rollback();
            throw $e;
        }
        if ($num > 0 && isset($this->app->memcache)) {
            $this->app->memcache->flushNs('posts');
        }
        $message = new SwatMessage(sprintf(Blorg::ngettext('One post has been shown on site.', '%s posts have been shown on site.', $num), SwatString::numberFormat($num)));
    }
Esempio n. 11
0
 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();
 }
Esempio n. 12
0
 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();
 }
Esempio n. 13
0
 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();
 }