Returns the elements needed to display topics
428751
public function printTopics($forum_id, $sort_by, $start_from)
    {
        $forum_id = Container::get('hooks')
            ->fire('model.forum.print_topics_start', $forum_id, $sort_by, $start_from);

        // Get topic/forum tracking data
        if (!User::get()->is_guest) {
            $tracked_topics = Track::getTrackedTopics();
        }

        // Retrieve a list of topic IDs, LIMIT is (really) expensive so we only fetch the
        // IDs here then later fetch the remaining data
        $result = DB::forTable('topics')
                        ->select('id')
                        ->where('forum_id', $forum_id)
                        ->order_by_desc('sticky')
                        ->order_by_expr($sort_by)
                        ->order_by_desc('id')
                        ->limit(User::get()->disp_topics)
                        ->offset($start_from);
        $result = Container::get('hooks')->fire('model.forum.print_topics_ids_query', $result);
        $result = $result->find_many();

        $forum_data = [];

        // If there are topics in this forum
        if ($result) {
            $topic_ids = [];
            foreach ($result as $cur_topic_id) {
                $topic_ids[] = $cur_topic_id['id'];
            }

            // Fetch list of topics to display on this page
            if (User::get()->is_guest || ForumSettings::get('o_show_dot') == '0') {
                // Without "the dot"
                $result['select'] = [
                    'id',
                    'poster',
                    'subject',
                    'posted',
                    'last_post',
                    'last_post_id',
                    'last_poster',
                    'num_views',
                    'num_replies',
                    'closed',
                    'sticky',
                    'moved_to'
                ];

                $result = DB::forTable('topics')
                            ->select_many($result['select'])
                            ->where_in('id', $topic_ids)
                            ->order_by_desc('sticky')
                            ->order_by_expr($sort_by)
                            ->order_by_desc('id');
            } else {
                // With "the dot"
                $result['select'] = [
                    'has_posted' => 'p.poster_id',
                    't.id',
                    't.subject',
                    't.poster',
                    't.posted',
                    't.last_post',
                    't.last_post_id',
                    't.last_poster',
                    't.num_views',
                    't.num_replies',
                    't.closed',
                    't.sticky',
                    't.moved_to'
                ];

                $result = DB::forTable('topics')
                            ->table_alias('t')
                            ->select_many($result['select'])
//                            ->left_outer_join(DB::prefix().'posts',
// array('t.id', '=', 'p.topic_id'), 'p')
//                            ->left_outer_join(DB::prefix().'posts',
// array('p.poster_id', '=', User::get()->id), null, true)
                    ->left_outer_join(
                        DB::prefix().'posts',
                        '(t.id = p.topic_id AND p.poster_id = '.User::get()->id.')',
                        'p'
                    )
                            ->where_in('t.id', $topic_ids)
                            ->group_by('t.id')
                            ->order_by_desc('sticky')
                            ->order_by_expr($sort_by)
                            ->order_by_desc('id');
            }

            $result = Container::get('hooks')->fireDB('model.forum.print_topics_query', $result);
            $result = $result->find_many();

            $topic_count = 0;
            foreach ($result as $cur_topic) {
                ++$topic_count;
                $status_text = [];
                $cur_topic['item_status'] = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd';
                $cur_topic['icon_type'] = $cur_topic->sticky === '1' ? 'icon icon-sticky' :
                    ($cur_topic->closed === '1' ? 'icon icon-closed' : 'icon');
                $url_subject = Url::slug($cur_topic['subject']);

                if (is_null($cur_topic['moved_to'])) {
                    $cur_topic['last_post_formatted'] = '<a href="'.
                        Router::pathFor('viewPost', ['pid' => $cur_topic['last_post_id']]).'#p'.
                        $cur_topic['last_post_id'].'">'.Utils::timeFormat($cur_topic['last_post']).'</a><br />'.
                        '<span class="byuser">'.__('by').' '.Utils::escape($cur_topic['last_poster']).'</span>';
                } else {
                    $cur_topic['last_post_formatted'] = '- - -';
                }

                if (ForumSettings::get('o_censoring') == '1') { // TODO: correct ?
                    $cur_topic['subject'] = Utils::censor($cur_topic['subject']);
                }

                if ($cur_topic['sticky'] == '1') {
                    $cur_topic['item_status'] .= ' isticky';
                    $status_text[] = '<span class="stickytext">'.__('Sticky').'</span>';
                }

                if ($cur_topic['moved_to'] != 0) {
                    $cur_topic['subject_formatted'] = '<a href="'.
                        Router::pathFor('Topic', ['id' => $cur_topic['moved_to'], 'name' => $url_subject]).'">'.
                        Utils::escape($cur_topic['subject']).'</a> <span class="byuser">'.__('by').' '.
                        Utils::escape($cur_topic['poster']).'</span>';
                    $status_text[] = '<span class="movedtext">'.__('Moved').'</span>';
                    $cur_topic['item_status'] .= ' imoved';
                } elseif ($cur_topic['closed'] == '0') {
                    $cur_topic['subject_formatted'] = '<a href="'.
                        Router::pathFor('Topic', ['id' => $cur_topic['id'], 'name' => $url_subject]).'">'.
                        Utils::escape($cur_topic['subject']).'</a> <span class="byuser">'.__('by').' '.
                        Utils::escape($cur_topic['poster']).'</span>';
                } else {
                    $cur_topic['subject_formatted'] = '<a href="'.
                        Router::pathFor('Topic', ['id' => $cur_topic['id'], 'name' => $url_subject]).'">'.
                        Utils::escape($cur_topic['subject']).'</a> <span class="byuser">'.__('by').' '.
                        Utils::escape($cur_topic['poster']).'</span>';
                    $status_text[] = '<span class="closedtext">'.__('Closed').'</span>';
                    $cur_topic['item_status'] .= ' iclosed';
                }

                if (!User::get()->is_guest && $cur_topic['last_post'] > User::get()->last_visit &&
                    (!isset($tracked_topics['topics'][$cur_topic['id']]) ||
                        $tracked_topics['topics'][$cur_topic['id']] < $cur_topic['last_post']) &&
                    (!isset($tracked_topics['forums'][$forum_id]) ||
                        $tracked_topics['forums'][$forum_id] < $cur_topic['last_post']) &&
                    is_null($cur_topic['moved_to'])) {
                    $cur_topic['item_status'] .= ' inew';
                    $cur_topic['icon_type'] = 'icon icon-new';
                    $cur_topic['subject_formatted'] = '<strong>'.$cur_topic['subject_formatted'].'</strong>';
                    $subject_new_posts = '<span class="newtext">[ <a href="'.
                        Router::pathFor('topicAction', ['id' => $cur_topic['id'], 'action' => 'new']).
                        '" title="'.__('New posts info').'">'.__('New posts').'</a> ]</span>';
                } else {
                    $subject_new_posts = null;
                }

                // Insert the status text before the subject
                $cur_topic['subject_formatted'] = implode(' ', $status_text).' '.$cur_topic['subject_formatted'];

                // Should we display the dot or not? :)
                if (!User::get()->is_guest && ForumSettings::get('o_show_dot') == '1') {
                    if ($cur_topic['has_posted'] == User::get()->id) {
                        $cur_topic['subject_formatted'] = '<strong class="ipost">·&#160;</strong>'.
                            $cur_topic['subject_formatted'];
                        $cur_topic['item_status'] .= ' iposted';
                    }
                }

                $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / User::get()->disp_posts);

                if ($num_pages_topic > 1) {// FIXME rebuild url
                    $subject_multipage = '<span class="pagestext">[ '.
                        Url::paginate($num_pages_topic, -1, Init::$uri . '/topic/'.$cur_topic['id'].
                            '/'.$url_subject.'/#'). ' ]</span>';
                } else {
                    $subject_multipage = null;
                }

                // Should we show the "New posts" and/or the multipage links?
                if (!empty($subject_new_posts) || !empty($subject_multipage)) {
                    $cur_topic['subject_formatted'] .= !empty($subject_new_posts) ? ' '.$subject_new_posts : '';
                    $cur_topic['subject_formatted'] .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
                }

                $forum_data[] = $cur_topic;
            }
        }

        $forum_data = Container::get('hooks')->fire('model.forum.print_topics', $forum_data);

        return $forum_data;
    }
942560
def show_list(timeout_in_sec, out=sys.stdout, host=jps.env.get_master_host(), sub_port=jps.DEFAULT_SUB_PORT):
    '''
    '''
    class TopicNameStore(object):

        def __init__(self):
            self._topic_names = set()

        def callback(self, msg, topic):
            self._topic_names.add(topic)

        def get_topic_names(self):
            names = list(self._topic_names)
            names.sort()
            return names

    store = TopicNameStore()
    sub = jps.Subscriber('*', store.callback, host=host, sub_port=sub_port)
    sleep_sec = 0.01
    for i in range(int(timeout_in_sec / sleep_sec)):
        sub.spin_once(sleep_sec)
        time.sleep(0.001)  # for context switch
    for name in store.get_topic_names():
        out.write('{}\n'.format(name))
1046217
def list_topic(self, k, Nwords=10):
        

        return [(self.vocabulary[w], p) for w, p
                in self.phi.features[k].top(Nwords)]
860744
def topic_pages_inline_list(topic):
    
    data_dict = {
        'topic': topic,
    }

    pages_number = ((topic.posts_count - 1) // machina_settings.TOPIC_POSTS_NUMBER_PER_PAGE) + 1
    if pages_number > 5:
        data_dict['first_pages'] = range(1, 5)
        data_dict['last_page'] = pages_number
    elif pages_number > 1:
        data_dict['first_pages'] = range(1, pages_number + 1)

    return data_dict
624128
def features(self):
        
        features = []
        try:
            list_items = self._ad_page_content.select("#features li")
        except Exception as e:
            if self._debug:
                logging.error(
                    "Error getting features. Error message: " + e.args[0])
            return

        for li in list_items:
            features.append(li.text)
        return features
1090907
def _parse_topic(self, element):
        
        self._log.debug('Setting Trigger topic: {topic}'.format(topic=element.text))
        super(Trigger, self)._parse_topic(element)
751832
def topics(preload: Kazoo::Topic::DEFAULT_PRELOAD_METHODS)
      @topics_mutex.synchronize do
        @topics ||= begin
          topics = zk.get_children(path: "/brokers/topics")
          raise Kazoo::Error, "Failed to list topics. Error code: #{topics.fetch(:rc)}" unless topics.fetch(:rc) == Zookeeper::Constants::ZOK
          preload_topics_from_names(topics.fetch(:children), preload: preload)
        end
      end
    end
262921
function getCommandHelps() {
        const cmds = {},
            topics = {},
            result = ['Registered commands:'];
        let keys = {};
        Object.keys(handlers).map((key) => {
            keys[key] = 1;
        });
        Object.keys(helpTopics).map((key) => {
            keys[key] = 1;
        });
        Object.keys(keys).map((key) => {
            if (handlers[key]) {
                cmds[key] = handlers[key].help;
                if (helpTopics[key]) {
                    cmds[key] += ' *';
                }
            } else {
                topics[key] = 'Extended help topic';
            }
        });
        keys = Object.keys(cmds);
        keys.sort();
        keys.forEach((cmd) => result.push(`${cmd}: ${cmds[cmd]}`));
        keys = Object.keys(topics);
        if (keys.length) {
            result.push('');
            result.push('Help Topics:');
            keys.sort();
            keys.forEach((topic) => result.push(`${topic}: ${topics[topic]}`));
        }
        return result.join('\n');
    }
667767
def discussions_notifications(user):
    ''''''
    notifications = []

    # Only fetch required fields for notification serialization
    # Greatly improve performances and memory usage
    qs = discussions_for(user).only('id', 'created', 'title', 'subject')

    # Do not dereference subject (so it's a DBRef)
    # Also improve performances and memory usage
    for discussion in qs.no_dereference():
        notifications.append((discussion.created, {
            'id': discussion.id,
            'title': discussion.title,
            'subject': {
                'id': discussion.subject['_ref'].id,
                'type': discussion.subject['_cls'].lower(),
            }
        }))

    return notifications
795101
def trending_topics
      result = http_get("/services/data/v#{self.version}/chatter/topics/trending")
      result = JSON.parse(result.body)
      result["topics"].collect { |topic| topic["name"] }
    end
1242036
def print_topics(self, Nwords=10):
        
        print('Topic\tTop %i words' % Nwords)
        for k, words in self.list_topics(Nwords):
            print(unicode(k).ljust(3) + '\t' + ' '.join(list(zip(*words))[0]))
750761
def topics(self):
        
        from .topic import Topic

        for topic in self.soup.find_all('a', class_='zm-item-tag'):
            yield Topic(Zhihu_URL + topic['href'], topic.text.replace('\n', ''),
                        session=self._session)
361547
def list_user_topics(self, start=0):
        
        xml = self.api.xml(API_GROUP_LIST_USER_PUBLISHED_TOPICS % self.api.user_alias, params={'start': start})
        return build_list_result(self._parse_topic_table(xml, 'title,comment,created,group'), xml)
472712
def channels(self, topic):
        """"""
        nsq.assert_valid_topic_name(topic)
        return self._request('GET', '/channels', fields={'topic': topic})
906566
def topics_count(self):
        
        return self.obj.direct_topics_count + sum(n.topics_count for n in self.children)
95690
def questions(self):
        
        from .question import Question

        if self.url is None or self.question_num == 0:
            return
        for page_index in range(1, (self.question_num - 1) // 20 + 2):
            html = self._session.get(
                self.url + 'asks?page=' + str(page_index)).text
            soup = BeautifulSoup(html)
            question_links = soup.find_all('a', class_='question_link')
            question_datas = soup.find_all(
                'div', class_='zm-profile-section-main')
            for link, data in zip(question_links, question_datas):
                url = Zhihu_URL + link['href']
                title = link.text.strip()
                answer_num = int(
                    re_get_number.match(data.div.contents[4]).group(1))
                follower_num = int(
                    re_get_number.match(data.div.contents[6]).group(1))
                q = Question(url, title, follower_num, answer_num,
                             session=self._session)
                yield q
798499
def get_urlpatterns(self):
        
        return [
            path(
                _('topic/<str:slug>-<int:pk>/lock/'),
                self.topic_lock_view.as_view(),
                name='topic_lock',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/unlock/'),
                self.topic_unlock_view.as_view(),
                name='topic_unlock',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/delete/'),
                self.topic_delete_view.as_view(),
                name='topic_delete',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/move/'),
                self.topic_move_view.as_view(),
                name='topic_move',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/change/topic/'),
                self.topic_update_to_normal_topic_view.as_view(),
                name='topic_update_to_post',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/change/sticky/'),
                self.topic_update_to_sticky_topic_view.as_view(),
                name='topic_update_to_sticky',
            ),
            path(
                _('topic/<str:slug>-<int:pk>/change/announce/'),
                self.topic_update_to_announce_view.as_view(),
                name='topic_update_to_announce',
            ),
            path(_('queue/'), self.moderation_queue_list_view.as_view(), name='queue'),
            path(
                _('queue/<int:pk>/'),
                self.moderation_queue_detail_view.as_view(),
                name='queued_post',
            ),
            path(
                _('queue/<int:pk>/approve/'),
                self.post_approve_view.as_view(),
                name='approve_queued_post',
            ),
            path(
                _('queue/<int:pk>/disapprove/'),
                self.post_disapprove_view.as_view(),
                name='disapprove_queued_post',
            ),
        ]