Add 'Flag' link for discussions.
196977
public function DiscussionController_AfterDiscussionMeta_Handler($Sender, $Args) {      
      // Signed in users only. No guest reporting!
      if (Gdn::Session()->UserID)
         $this->AddFlagButton($Sender, $Args, 'discussion');
   }
669988
def add_html_link(app, pagename, templatename, context, doctree):
    """"""
    base_url = app.config['html_theme_options'].get('base_url', '')
    if base_url:
        app.sitemap_links.append(base_url + pagename + ".html")
1145680
def set_flag(self, request, val, fld):
        """"""
        if val is not None:
            val = bool(val)
            request.set(fld, val)
956711
def connect_discussion_signals():
    
    post_save.connect(
        count_discussions_handler, sender=comment_model,
        dispatch_uid=COMMENT_PS_COUNT_DISCUSSIONS)
    post_delete.connect(
        count_discussions_handler, sender=comment_model,
        dispatch_uid=COMMENT_PD_COUNT_DISCUSSIONS)
    comment_was_flagged.connect(
        count_discussions_handler, sender=comment_model,
        dispatch_uid=COMMENT_WF_COUNT_DISCUSSIONS)
    comment_was_posted.connect(
        count_comments_handler, sender=comment_model,
        dispatch_uid=COMMENT_WP_COUNT_COMMENTS)
    pingback_was_posted.connect(
        count_pingbacks_handler, sender=comment_model,
        dispatch_uid=PINGBACK_WF_COUNT_PINGBACKS)
    trackback_was_posted.connect(
        count_trackbacks_handler, sender=comment_model,
        dispatch_uid=TRACKBACK_WF_COUNT_TRACKBACKS)
746242
def flag(request, comment_id, next=None):
    
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Flag on POST
    if request.method == 'POST':
        perform_flag(request, comment)
        return next_redirect(request, fallback=next or 'comments-flag-done',
            c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/flag.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
87611
def update
      @discussion = Discussion.includes(:posts => :user).find(params[:id])

      respond_with(@discussion.category, @discussion) do |format|
        if @discussion.update_attributes(params[:discussion])
          flash[:notice] = "Discussion was successfully updated."
          format.html {redirect_to category_discussion_path(@discussion.category, @discussion)}
        else
          @categories = Category.discussions
          format.html {render :edit}
        end
      end

    end
1252817
protected function AddFlagButton($Sender, $Args, $Context = 'comment') {
      $ElementID = ($Context == 'comment') ? $Args['Comment']->CommentID : $Args['Discussion']->DiscussionID;
      
      if (!is_object($Args['Author']) || !isset($Args['Author']->UserID)) {
         $ElementAuthorID = 0;
         $ElementAuthor = 'Unknown';
      } else {
         $ElementAuthorID = $Args['Author']->UserID;
         $ElementAuthor = $Args['Author']->Name;
      }
      switch ($Context) {
         case 'comment':
            $URL = "/discussion/comment/{$ElementID}/#Comment_{$ElementID}";
            break;
            
         case 'discussion':
            $URL = "/discussion/{$ElementID}/".Gdn_Format::Url($Args['Discussion']->Name);
            break;
            
         default:
            return;
      }
      $EncodedURL = str_replace('=','-',base64_encode($URL));
      $FlagLink = Anchor(T('Flag'), "discussion/flag/{$Context}/{$ElementID}/{$ElementAuthorID}/".Gdn_Format::Url($ElementAuthor)."/{$EncodedURL}", 'FlagContent Popup');
      echo Wrap($FlagLink, 'span', array('class' => 'MItem CommentFlag'));
   }
737731
def main():
    """"""
    mod_choices = ('banned', 'contributor', 'moderator')
    mod_choices_dsp = ', '.join(['`{}`'.format(x) for x in mod_choices])
    msg = {
        'add': ('Add users to one of the following categories: {}'
                .format(mod_choices_dsp)),
        'clear': 'Remove users who have no flair set.',
        'css': 'Ignore the CSS field when synchronizing flair.',
        'edit': 'When adding flair templates, mark them as editable.',
        'file': 'The file containing contents for --message',
        'flair': 'List flair for the subreddit.',
        'flair_stats': 'Display the number of users with each flair.',
        'json': 'Output the results as json. Applies to --flair',
        'limit': ('The minimum number of users that must have the specified '
                  'flair in order to add as a template. default: %default'),
        'list': ('List the users in one of the following categories: '
                 '{}. May be specified more than once.'
                 .format(mod_choices_dsp)),
        'msg': ('Send message to users of one of the following categories: '
                '{}. Message subject provided via --subject, content provided '
                'via --file or STDIN.').format(mod_choices_dsp),
        'sort': ('The order to add flair templates. Available options are '
                 '`alpha` to add alphabetically, and `size` to first add '
                 'flair that is shared by the most number of users. '
                 'default: %default'),
        'static': ('Add this template when syncing flair templates. When '
                   'syncing text and css use a comma to separate the two.'),
        'subject': 'The subject of the message to send for --message.',
        'sync': 'Synchronize flair templates with current user flair.',
        'text': 'Ignore the text field when synchronizing flair.'}

    usage = 'Usage: %prog [options] SUBREDDIT'
    parser = arg_parser(usage=usage)
    parser.add_option('-a', '--add', help=msg['add'])
    parser.add_option('-l', '--list', action='append', help=msg['list'],
                      choices=mod_choices, metavar='CATEGORY', default=[])
    parser.add_option('-c', '--clear-empty', action='store_true',
                      help=msg['clear'])
    parser.add_option('-F', '--file', help=msg['file'])
    parser.add_option('-f', '--flair', action='store_true', help=msg['flair'])
    parser.add_option('', '--flair-stats', action='store_true',
                      help=msg['flair_stats'])
    parser.add_option('-m', '--message', choices=mod_choices, help=msg['msg'])
    parser.add_option('', '--subject', help=msg['subject'])

    group = OptionGroup(parser, 'Format options')
    group.add_option('-j', '--json', action='store_true', help=msg['json'])
    parser.add_option_group(group)

    group = OptionGroup(parser, 'Sync options')
    group.add_option('', '--sync', action='store_true', help=msg['sync'])
    group.add_option('-s', '--static', action='append', help=msg['static'])
    group.add_option('', '--editable', action='store_true', help=msg['edit'])
    group.add_option('', '--ignore-css', action='store_true',
                     default=False, help=msg['css'])
    group.add_option('', '--ignore-text', action='store_true',
                     default=False, help=msg['text'])
    group.add_option('', '--limit', type='int', help=msg['limit'], default=2)
    group.add_option('', '--sort', action='store', choices=('alpha', 'size'),
                     default='alpha', help=msg['sort'])
    parser.add_option_group(group)

    options, args = parser.parse_args()
    if len(args) == 0:
        parser.error('Must provide subreddit name.')
    if options.message and not options.subject:
        parser.error('Must provide --subject when providing --message.')
    subreddit = args[0]

    check_for_updates(options)

    modutils = ModUtils(subreddit, options.site, options.verbose)

    if options.add:
        modutils.add_users(options.add)
    if options.clear_empty:
        modutils.clear_empty()
    for category in options.list:
        modutils.output_list(category)
    if options.flair:
        modutils.output_current_flair(as_json=options.json)
    if options.flair_stats:
        modutils.output_flair_stats()
    if options.sync:
        modutils.flair_template_sync(editable=options.editable,
                                     limit=options.limit,
                                     static=options.static, sort=options.sort,
                                     use_css=not options.ignore_css,
                                     use_text=not options.ignore_text)
    if options.message:
        modutils.message(options.message, options.subject, options.file)
313926
def Flags(*params)
      if params.size==1 && params.first.kind_of?(Flags)
        params.first
      else
        Flags.new(*params)
      end
    end
575606
def register_flag_by_module_id(self, module_id, flag):
    
    flags_by_module_id = self.flags_by_module_id_dict()
    flags_by_module_id.setdefault(module_id, []).append(flag)
1374789
def create
      @discussion = Discussion.new(params[:discussion])

      # assign user if signed in
      if current_cornerstone_user
        @discussion.user = current_cornerstone_user
        @discussion.posts.first.user = current_cornerstone_user
      end

      respond_with(@discussion.category, @discussion) do |format|
        if @discussion.save
          flash[:notice] = 'Discussion was successfully created.'
          format.html {redirect_to category_discussion_path(@discussion.category, @discussion)}
        else
          @categories = Category.discussions
          format.html {render :new}
        end
      end
    end
861051
def give_us_somethin_to_talk_about(self, message):
        """"""
        r = requests.get("http://www.chatoms.com/chatom.json?Normal=1&Fun=2&Philosophy=3&Out+There=4")
        data = r.json()
        self.set_topic(data["text"], message=message)
93761
def _add_or_remove_flag(self, flag, add):
        
        meth = self.add_flag if add else self.remove_flag
        meth(flag)
1001014
def topic(self, channel, topic=None):
        """"""
        if topic:
            channel += ' :' + topic
        self.send_line('TOPIC %s' % channel)
282855
public function flag() {
        global $DB;

        $this->ensure_fields_exist(array('name', 'userid', 'rawname', 'flag'), 'flag');

        // Update all the tags to flagged.
        $this->timemodified = time();
        $this->flag++;
        $DB->update_record('tag', array('timemodified' => $this->timemodified,
            'flag' => $this->flag, 'id' => $this->id));

        $event = \core\event\tag_flagged::create(array(
            'objectid' => $this->id,
            'relateduserid' => $this->userid,
            'context' => context_system::instance(),
            'other' => array(
                'name' => $this->name,
                'rawname' => $this->rawname
            )

        ));
        $event->trigger();
    }
1199943
def add_edge(u, v, flags = EDGE_NORMAL)
      u.join(v)
      u.set_flag(v, flags)
    end
208400
protected function add_discussion_header($discussion, $forum, $course) {
        global $CFG;

        $shortname = format_string($course->shortname, true, [
                'context' => \context_course::instance($course->id),
            ]);

        $strforums = get_string('forums', 'forum');

        $this->discussiontext .= "\n=====================================================================\n\n";
        $this->discussiontext .= "$shortname -> $strforums -> " . format_string($forum->name, true);
        if ($discussion->name != $forum->name) {
            $this->discussiontext  .= " -> " . format_string($discussion->name, true);
        }
        $this->discussiontext .= "\n";
        $this->discussiontext .= new \moodle_url('/mod/forum/discuss.php', [
                'd' => $discussion->id,
            ]);
        $this->discussiontext .= "\n";

        if ($this->allowhtml) {
            $this->discussionhtml .= "<p><font face=\"sans-serif\">".
                "<a target=\"_blank\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$shortname</a> -> ".
                "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/index.php?id=$course->id\">$strforums</a> -> ".
                "<a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/view.php?f=$forum->id\">" .
                        format_string($forum->name, true)."</a>";
            if ($discussion->name == $forum->name) {
                $this->discussionhtml .= "</font></p>";
            } else {
                $this->discussionhtml .=
                        " -> <a target=\"_blank\" href=\"$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id\">" .
                        format_string($discussion->name, true)."</a></font></p>";
            }
            $this->discussionhtml .= '<p>';
        }

    }