Forums | Mahara Community

Support /
Mahara word count for page


Wullie's profile picture
Posts: 252

08 March 2013, 3:14

Hi,

Similar to the request for counting characters in a blog, as per here, is there anyway to have Mahara count how many words have been included on a page (in all text boxes), or does anyone want to throw suggestions at me where to start with something like this?

Thanks

Aaron Wells's profile picture
Posts: 896

08 March 2013, 11:11

Hi Wullie,

To count all the words in all the text boxes on a Page, you'd probably need to do some coding in the Page view script, view/index.php, and its associated template theme/raw/templates/view/index.tpl

If you just want to show the character count in a rich text field as you're typing in it, the version of TinyMCE that ships with Mahara actually includes a "word count" plugin, which is disabled by default. To activate it you'd need to go to lib/web.php and look for the section in the smarty() function where it determines the tinymce configuration, and add a couple of lines to it (I've bolded the lines in question):

                    if ($check[$key] == 'tinymce') {
                        $spellchecker_rpc = $jsroot.'tinymce/plugins/spellchecker/rpc.php';
                        $tinymce_config = <<<EOF
    mode: "none",
    theme: "advanced",
    plugins: "table,emotions,spellchecker,inlinepopups,paste,fullscreen,wordcount",
    theme_advanced_buttons1 : "{$adv_buttons[1]}",
    theme_advanced_buttons2 : "{$adv_buttons[2]}",
    theme_advanced_buttons3 : "{$adv_buttons[3]}",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    theme_advanced_statusbar_location : "bottom",
    fix_list_elements: true,
    spellchecker_rpc_url : "{$spellchecker_rpc}",
    //width: '512',
EOF;
                    }
                    else {
                        $tinymce_config = <<<EOF
    mode: "textareas",
    editor_selector: 'tinywysiwyg',
    theme: "advanced",
    plugins: "fullscreen,inlinepopups,autoresize,wordcount",
    theme_advanced_buttons1 : "{$adv_buttons[0]}",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "{$toolbar_align}",
    theme_advanced_statusbar_location : "bottom",
    fullscreen_new_window: true,
    fullscreen_settings: {
        theme: "advanced",
        plugins: "table,emotions,iespell,inlinepopups,paste,fullscreen,wordcount",
        theme_advanced_buttons1 : "{$adv_buttons[1]}",
        theme_advanced_buttons2 : "{$adv_buttons[2]}",
        theme_advanced_buttons3 : "{$adv_buttons[3]}",
        theme_advanced_statusbar_location: "bottom"
    },

EOF;
                    }

That adds a word count box to TinyMCE as you're typing, which updates whenever you press enter, or after you press backspace.

I hope this helps!

Cheers,
Aaron

2 results