Changeset 26359


Ignore:
Timestamp:
06/13/10 23:05:01 (7 years ago)
Author:
indeyets
Message:

config-option for showing comments on index (listing of blog-articles) using ajax-requests

Location:
branches/ragnaroek/midcom/net.nehmer.blog
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midcom/net.nehmer.blog/config/config.inc

    r25466 r26359  
     1//<?php//hack for syntax highlighters
     2
    13// Schema database to use
    24'schemadb' => 'file:/net/nehmer/blog/config/schemadb_default.inc',
     
    4143
    4244'comments_enable' => false,
     45'ajax_comments_enable' => false,
    4346'comments_topic' => '',
    4447
  • branches/ragnaroek/midcom/net.nehmer.blog/config/schemadb_config.inc

    r25254 r26359  
     1//<?php array(//hack for syntax highlighters
    12'config' => array
    23(
     
    243244                'widget' => 'select',
    244245            ),
     246            'ajax_comments_enable' => array
     247            (
     248                'title' => 'ajax_comments_enable',
     249                'storage' => array
     250                (
     251                    'location' => 'configuration',
     252                    'domain' => 'net.nehmer.blog',
     253                    'name' => 'ajax_comments_enable',
     254                ),
     255                'type' => 'select',
     256                'type_config' => array
     257                (
     258                    'options' => array
     259                    (
     260                        '' => 'default setting',
     261                        '1' => 'yes',
     262                        '0' => 'no',
     263                    ),
     264                ),
     265                'widget' => 'select',
     266            ),
    245267            'ajax_enable' => array
    246268            (
  • branches/ragnaroek/midcom/net.nehmer.blog/handler/index.php

    r26069 r26359  
    214214        $data['index_fulltext'] = $this->_config->get('index_fulltext');
    215215
     216        if ($this->_config->get('ajax_comments_enable'))
     217        {
     218            $_MIDCOM->componentloader->load('net.nehmer.comments');
     219
     220            $comments_node = $this->_seek_comments();
     221
     222            if ($comments_node)
     223            {
     224                $this->_request_data['ajax_comments_enable'] = true;
     225                $this->_request_data['base_ajax_comments_url'] = $comments_node[MIDCOM_NAV_RELATIVEURL] . "comment/";
     226            }
     227        }
     228
    216229        midcom_show_style('index-start');
    217230
     
    284297        return true;
    285298    }
     299
     300    // helpers follow
     301    /**
     302     * Try to find a comments node (cache results)
     303     *
     304     * @access private
     305     */
     306    private function _seek_comments()
     307    {
     308        if ($this->_config->get('comments_topic'))
     309        {
     310            // We have a specified photostream here
     311            $comments_topic = new midcom_db_topic($this->_config->get('comments_topic'));
     312            if (   !is_object($comments_topic)
     313                || !isset($comments_topic->guid)
     314                || empty($comments_topic->guid))
     315            {
     316                return false;
     317            }
     318
     319            // We got a topic. Make it a NAP node
     320            $nap = new midcom_helper_nav();
     321            $comments_node = $nap->get_node($comments_topic->id);
     322
     323            return $comments_node;
     324        }
     325
     326        // No comments topic specified, autoprobe
     327        $comments_node = midcom_helper_find_node_by_component('net.nehmer.comments');
     328
     329        // Cache the data
     330        if ($_MIDCOM->auth->request_sudo('net.nehmer.blog'))
     331        {
     332            $this->_topic->parameter('net.nehmer.blog', 'comments_topic', $comments_node[MIDCOM_NAV_GUID]);
     333            $_MIDCOM->auth->drop_sudo();
     334        }
     335
     336        return $comments_node;
     337    }
    286338}
    287339?>
  • branches/ragnaroek/midcom/net.nehmer.blog/locale/default.en.txt

    r25280 r26359  
    8080---STRINGEND
    8181
     82---STRING ajax_comments_enable
     83Show comments in listing (using AJAX, requires the net.nehmer.comments component)
     84---STRINGEND
     85
    8286---STRING content
    8387Content
  • branches/ragnaroek/midcom/net.nehmer.blog/style/index-item.php

    r26069 r26359  
    1616$published = sprintf($data['l10n']->get('posted on %s.'), "<abbr title=\"" . strftime('%Y-%m-%dT%H:%M:%S%z', $data['article']->metadata->published) . "\">" . strftime('%x %X', $data['article']->metadata->published) . "</abbr>");
    1717
    18 if (array_key_exists('comments_enable', $data))
     18if (array_key_exists('ajax_comments_enable', $data))
    1919{
    20     $published .= " <a href=\"{$data['local_view_url']}#net_nehmer_comments_{$data['article']->guid}\">" . sprintf($data['l10n']->get('%s comments'), net_nehmer_comments_comment::count_by_objectguid($data['article']->guid)) . "</a>.";
     20    $published .= ' <a href="#switch_comments" onClick="showAjaxComments(this, \''.$data['article']->guid.'\'); return false;">'
     21                    .sprintf($data['l10n']->get('%s comments'), net_nehmer_comments_comment::count_by_objectguid($data['article']->guid))
     22                    ."</a>.";
     23}
     24elseif (array_key_exists('comments_enable', $data))
     25{
     26    $published .= " <a href=\"{$data['local_view_url']}#net_nehmer_comments_{$data['article']->guid}\">"
     27                    .sprintf($data['l10n']->get('%s comments'), net_nehmer_comments_comment::count_by_objectguid($data['article']->guid))
     28                    ."</a>.";
    2129}
    2230?>
     
    5159        <?php
    5260    }
     61
     62    if ($data['ajax_comments_enable'])
     63    {
     64        echo '<div class="ajax_comments_container" style="display: none;"></div>';
     65    }
    5366    ?>
    5467</div>
  • branches/ragnaroek/midcom/net.nehmer.blog/style/index-start.php

    r5048 r26359  
    44//$data =& $_MIDCOM->get_custom_context_data('request_data');
    55?>
     6<?php if (array_key_exists('ajax_comments_enable', $data)): ?>
     7<script type="text/javascript" charset="utf-8">
     8var base_ajax_comments_url = MIDCOM_PAGE_PREFIX + '<?php echo $data['base_ajax_comments_url']; ?>';
     9function showAjaxComments(element, guid)
     10{
     11    var container = $(element).parent().siblings('.ajax_comments_container');
     12    if (container.text().length) {
     13        container.slideUp(function(){ $(this).text(''); });
     14    } else {
     15        container.load(base_ajax_comments_url + guid, function(){ $(this).slideDown(); });
     16    }
     17}
     18</script>
     19<?php endif; ?>
    620
    721<h1><?php echo $data['page_title']; ?></h1>
Note: See TracChangeset for help on using the changeset viewer.