Ejemplo n.º 1
0
/**
 * Printing wiki editor.
 * Depending on where it is called , action will go to different destinations.
 * If it is called from comments section, the return will be in comments section
 *  in any other case it will be in edit view section.
 * @param $pageid. Current pageid
 * @param $content. Content to be edited.
 * @param $section. Current section, default null
 * @param $comesfrom. Information about where the function call is made
 * @param commentid. id comment of comment that will be edited.
 */
function wiki_print_editor_wiki($pageid, $content, $editor, $version = -1, $section = null, $upload = false, $deleteuploads = array(), $comesfrom = 'editorview', $commentid = 0)
{
    global $CFG, $OUTPUT, $PAGE;
    if ($comesfrom == 'editcomments') {
        $action = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $pageid . '&id=' . $commentid . '&action=edit';
    } else {
        if ($comesfrom == 'addcomments') {
            $action = $CFG->wwwroot . '/mod/wiki/instancecomments.php?pageid=' . $pageid . '&id=' . $commentid . '&action=add';
        } else {
            $action = $CFG->wwwroot . '/mod/wiki/edit.php?pageid=' . $pageid;
        }
    }
    if (!empty($section)) {
        $action .= "&section=" . urlencode($section);
    }
    ///Get tags for every element we are displaying
    $tag = wiki_parser_get_token($editor, 'bold');
    $wiki_editor['bold'] = array('ed_bold.gif', get_string('wikiboldtext', 'wiki'), $tag[0], $tag[1], get_string('wikiboldtext', 'wiki'));
    $tag = wiki_parser_get_token($editor, 'italic');
    $wiki_editor['italic'] = array('ed_italic.gif', get_string('wikiitalictext', 'wiki'), $tag[0], $tag[1], get_string('wikiitalictext', 'wiki'));
    $tag = wiki_parser_get_token($editor, 'link');
    $wiki_editor['internal'] = array('ed_internal.gif', get_string('wikiinternalurl', 'wiki'), $tag[0], $tag[1], get_string('wikiinternalurl', 'wiki'));
    $tag = wiki_parser_get_token($editor, 'url');
    $wiki_editor['external'] = array('ed_external.gif', get_string('wikiexternalurl', 'wiki'), $tag[0], $tag[1], get_string('wikiexternalurl', 'wiki'));
    $tag = wiki_parser_get_token($editor, 'list');
    $wiki_editor['u_list'] = array('ed_ul.gif', get_string('wikiunorderedlist', 'wiki'), '\\n' . $tag[0], '', '');
    $wiki_editor['o_list'] = array('ed_ol.gif', get_string('wikiorderedlist', 'wiki'), '\\n' . $tag[1], '', '');
    $tag = wiki_parser_get_token($editor, 'image');
    $wiki_editor['image'] = array('ed_img.gif', get_string('wikiimage', 'wiki'), $tag[0], $tag[1], get_string('wikiimage', 'wiki'));
    $tag = wiki_parser_get_token($editor, 'header');
    $wiki_editor['h1'] = array('ed_h1.gif', get_string('wikiheader', 'wiki', 1), '\\n' . $tag . ' ', ' ' . $tag . '\\n', get_string('wikiheader', 'wiki', 1));
    $wiki_editor['h2'] = array('ed_h2.gif', get_string('wikiheader', 'wiki', 2), '\\n' . $tag . $tag . ' ', ' ' . $tag . $tag . '\\n', get_string('wikiheader', 'wiki', 2));
    $wiki_editor['h3'] = array('ed_h3.gif', get_string('wikiheader', 'wiki', 3), '\\n' . $tag . $tag . $tag . ' ', ' ' . $tag . $tag . $tag . '\\n', get_string('wikiheader', 'wiki', 3));
    $tag = wiki_parser_get_token($editor, 'line_break');
    $wiki_editor['hr'] = array('ed_hr.gif', get_string('wikihr', 'wiki'), '\\n' . $tag . '\\n', '', '');
    $tag = wiki_parser_get_token($editor, 'nowiki');
    $wiki_editor['nowiki'] = array('ed_nowiki.gif', get_string('wikinowikitext', 'wiki'), $tag[0], $tag[1], get_string('wikinowikitext', 'wiki'));
    $OUTPUT->heading(strtoupper(get_string('format' . $editor, 'wiki')));
    $PAGE->requires->js('/mod/wiki/editors/wiki/buttons.js');
    echo $OUTPUT->container_start('mdl-align');
    foreach ($wiki_editor as $button) {
        echo "<a href=\"javascript:insertTags";
        echo "('" . $button[2] . "','" . $button[3] . "','" . $button[4] . "');\">";
        echo "<img width=\"23\" height=\"22\" src=\"{$CFG->wwwroot}/mod/wiki/editors/wiki/images/{$button['0']}\" alt=\"" . $button[1] . "\" title=\"" . $button[1] . "\" />";
        echo "</a>";
    }
    echo $OUTPUT->container_end();
    echo $OUTPUT->container_start('mdl-align');
    echo '<form method="post" id="wikiform" action="' . $action . '">';
    echo $OUTPUT->container(print_textarea(false, 20, 60, 0, 0, "newcontent", $content, 0, true), false, 'wiki_editor');
    echo $OUTPUT->container_start();
    wiki_print_edit_form_default_fields($editor, $pageid, $version, $upload, $deleteuploads);
    echo $OUTPUT->container_end();
    echo '</form>';
    echo $OUTPUT->container_end();
}
Ejemplo n.º 2
0
 function toHtml()
 {
     global $CFG, $OUTPUT;
     $htmltable = new html_table();
     $htmltable->head = array(get_string('deleteupload', 'wiki'), get_string('uploadname', 'wiki'), get_string('uploadactions', 'wiki'));
     $fs = get_file_storage();
     $files = $fs->get_area_files($this->_fileinfo['contextid'], 'mod_wiki', 'attachments', $this->_fileinfo['itemid']);
     //TODO: verify where this is coming from, all params must be validated (skodak)
     if (count($files) < 2) {
         return get_string('noattachments', 'wiki');
     }
     //get tags
     foreach (array('image', 'attach', 'link') as $tag) {
         $tags[$tag] = wiki_parser_get_token($this->_format, $tag);
     }
     foreach ($files as $file) {
         if (!$file->is_directory()) {
             $checkbox = '<input type="checkbox" name="' . $this->_attributes['name'] . '[]" value="' . $file->get_pathnamehash() . '"';
             if (in_array($file->get_pathnamehash(), $this->_value)) {
                 $checkbox .= ' checked="checked"';
             }
             $checkbox .= " />";
             //actions
             $icon = file_file_icon($file);
             $file_url = file_encode_url($CFG->wwwroot . '/pluginfile.php', "/{$this->_contextid}/mod_wiki/attachments/{$this->_fileareaitemid}/" . $file->get_filename());
             $action_icons = "";
             if (!empty($tags['attach'])) {
                 $action_icons .= "<a href=\"javascript:void(0)\" class=\"wiki-attachment-attach\" " . $this->printInsertTags($tags['attach'], $file->get_filename()) . " title=\"" . get_string('attachmentattach', 'wiki') . "\">" . $OUTPUT->pix_icon($icon, "Attach") . "</a>";
                 //TODO: localize
             }
             $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-link\" " . $this->printInsertTags($tags['link'], $file_url) . " title=\"" . get_string('attachmentlink', 'wiki') . "\">" . $OUTPUT->pix_icon($icon, "Link") . "</a>";
             if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
                 $action_icons .= "&nbsp;&nbsp;<a href=\"javascript:void(0)\" class=\"wiki-attachment-image\" " . $this->printInsertTags($tags['image'], $file->get_filename()) . " title=\"" . get_string('attachmentimage', 'wiki') . "\">" . $OUTPUT->pix_icon($icon, "Image") . "</a>";
                 //TODO: localize
             }
             $htmltable->data[] = array($checkbox, '<a href="' . $file_url . '">' . $file->get_filename() . '</a>', $action_icons);
         }
     }
     return html_writer::table($htmltable);
 }
Ejemplo n.º 3
0
/**
 * Returns escaped token used by a wiki language to represent a given tag or "object" (bold -> **)
 *
 * @param string $format format of page
 * @param array|string $token format tokens which needs to be escaped
 * @return array|string
 */
function getTokens($format, $token)
{
    $tokens = wiki_parser_get_token($format, $token);
    if (is_array($tokens)) {
        foreach ($tokens as $key => $value) {
            $tokens[$key] = urlencode(str_replace("'", "\\'", $value));
        }
    } else {
        urlencode(str_replace("'", "\\'", $token));
    }
    return $tokens;
}
Ejemplo n.º 4
0
 private function getTokens($format, $token)
 {
     $tokens = wiki_parser_get_token($format, $token);
     if (is_array($tokens)) {
         foreach ($tokens as &$t) {
             $this->escapeToken($t);
         }
     } else {
         $this->escapeToken($tokens);
     }
     return $tokens;
 }