Page 1 of 1

Feature suggestion: Internal commenting

Posted: Mon Jan 12, 2015 10:15 pm
by Stosh
Hi,

This is just a feature suggestion. Not something I need, but just something that would be nice to have.

In my glossary (example) I have a set of message editing tags ([comment] blah blah blah [/comment]) that denote that anything between them is a comment, which is stored in the database, but is never displayed when the message is displayed at the outside level.

It is implemented simply by parsing out the entire structure to an empty string when the message is being parsed for display.

Again, not a demand, just thought it would be cool to have (very helpful in the glossary).

-s

Re: Feature suggestion: Internal commenting

Posted: Tue Jan 13, 2015 11:27 am
by garvinhicking
Hi!

Not really sure if there is public demand, but a plugin could very simply do this:

Code: Select all

<?php
class serendipity_event_commenthide extends serendipity_event {
    var $title = 'Hide internal comments';
    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          $this->title);
        $propbag->add('event_hooks',   array('frontend_display' => true));
    }

    function commentify($string) {
        return preg_replace('@\[comment](.+)\[/comment\]@imsU', '', $string);
    }

    function event_hook($event, &$bag, &$eventData, $addData = null) {
        global $serendipity;
        $hooks = &$bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch($event) {
                case 'frontend_display':
                    $el = array('body', 'extended');
                    foreach ($el as $temp) {
                        if (isset($eventData[$temp['element']]) &&
                            !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
                            !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
                            $element = $temp['element'];
                            $eventData[$element] = $this->commentify($eventData[$element]);
                        }
                    }
                    return true;
                    break;
            }
        }

        return false;
    }
}
?>
HTH,
Garvin