예제 #1
0
function ewiki_edit_helptext($id, &$data, &$hpost)
{
    global $ewiki_t;
    if ($help = ewiki_db::GET("EditingHelp")) {
        $help = ewiki_format($help["content"]);
        if ($l = strpos($help, "<hr")) {
            $ewiki_t["en"]["EDIT_FORM_1"] = substr($help, 0, $l);
            $l = strpos($help, ">", $l);
            $help = substr($help, $l + 1);
        }
        $ewiki_t["en"]["EDIT_FORM_2"] = $help;
    }
}
예제 #2
0
파일: posts.php 프로젝트: gpuenteallott/rox
function ewiki_add_post($id, $data, $action)
{
    global $ewiki_plugins, $ewiki_config;
    $postNum = getPostCount($id) + 1;
    $postNum = str_pad($postNum, 3, "0", STR_PAD_LEFT);
    if ($postNum > 999) {
        $o = ewiki_format(ewiki_t("TOO_MANY_POSTS", array("id" => $id)));
    } else {
        $id = $id . EWIKI_POST_SEPARATOR . $postNum;
        $ewiki_config["create"] = $id;
        //echo("Calling edit function $id");
        $o = $ewiki_plugins["action"]["edit"]($id, array("id" => $id), $action);
    }
    return $o;
}
예제 #3
0
function ewiki_format_pre_code($wsrc, $sl = 1, $hl = EWIKI_ALLOW_HTML, $sh = 0)
{
    $html = "";
    $loop = 20;
    while (preg_match("#^(.*?\n)?<(code>|php>|\\?php|\\?)(.+?)\n(</code|</php|\\?)>#s", $wsrc, $uu) && $loop--) {
        $rend =& $uu[1];
        $code =& $uu[3];
        $wsrc = substr($wsrc, strlen($uu[0]));
        $html .= ewiki_format($rend, $sl, $hl, $sh);
        $html .= "<pre>" . ewiki_format_pre_code_escape($code, $uu[2] != "code>") . "\n</pre>";
    }
    if (strlen($wsrc)) {
        $html .= ewiki_format($wsrc, $sl, $hl, $sh);
    }
    return $html;
}
예제 #4
0
파일: tour.php 프로젝트: gpuenteallott/rox
function ewiki_tour($id, &$data, $action)
{
    $o = "\n";
    $page_lists = array(array($id), explode("\n", trim($data["refs"])), ewiki_get_backlinks($id));
    foreach ($page_lists as $pages) {
        foreach ($pages as $page) {
            $row = ewiki_db::GET($page);
            if (EWIKI_DB_F_TEXT == $row["flags"] & EWIKI_DB_F_TYPE) {
                $add = substr($row["content"], 0, 333);
                $add = substr($add, 0, strrpos($add, " "));
                $add = preg_replace("/^[!*#-:;>]+/m", "", $add);
                $add = strtr($add, "\n\t", "  ");
                $o .= "!!! [tour:{$row[id]}]\n" . "@@tour-page-fragment {$add} ...\n\n";
            }
        }
    }
    $o = ewiki_format($o);
    $o .= ewiki_control_links($id, $data, $action);
    return $o;
}
예제 #5
0
파일: lib.php 프로젝트: vuchannguyen/web
function wiki_ewiki_2_html($oldentry, $oldpage, $oldwiki)
{
    global $CFG, $wiki_entry, $moodle_disable_camel_case, $ewiki_plugins, $ewiki_config, $moodle_format;
    $wiki_entry = $oldentry;
    $moodle_disable_camel_case = $oldwiki->disablecamelcase == 1;
    // Block of dinamic ewiki defines
    wiki_set_define("EWIKI_NAME", $wiki_entry->pagename);
    wiki_set_define("EWIKI_DEFAULT_LANG", current_language());
    if ($moodle_disable_camel_case) {
        wiki_set_define("EWIKI_CHARS_L", "");
        wiki_set_define("EWIKI_CHARS_U", "");
    } else {
        wiki_set_define("EWIKI_CHARS_L", "a-z_µ¤\$ß-ÿ");
        wiki_set_define("EWIKI_CHARS_U", "A-Z0-9À-Þ");
    }
    wiki_set_define("EWIKI_CHARS", wiki_get_define('EWIKI_CHARS_L') . wiki_get_define('EWIKI_CHARS_U'));
    require_once $CFG->dirroot . '/mod/wiki/db/migration/wiki/ewikimoodlelib.php';
    require_once $CFG->dirroot . '/mod/wiki/db/migration/wiki/ewiki/ewiki.php';
    if ($oldwiki->htmlmode == 0) {
        # No HTML
        $ewiki_config["htmlentities"] = array();
        // HTML is managed by moodle
        $moodle_format = FORMAT_TEXT;
    }
    if ($oldwiki->htmlmode == 1) {
        # Safe HTML
        include_once $CFG->dirroot . "/mod/wiki/db/migration/wiki/ewiki/plugins/moodle/moodle_rescue_html.php";
        $moodle_format = FORMAT_HTML;
    }
    if ($oldwiki->htmlmode == 2) {
        # HTML Only
        $moodle_format = FORMAT_HTML;
        $ewiki_use_editor = 1;
        $ewiki_config["htmlentities"] = array();
        // HTML is allowed
        $ewiki_config["wiki_link_regex"] = " [!~]?(\n                    \\#?\\[[^<>\\[\\]\n]+\\] |\n                    \\^[-" . wiki_get_define('EWIKI_CHARS_U') . wiki_get_define('EWIKI_CHARS_L') . "]{3,} |\n                    \\b([\\w]{3,}:)*([" . wiki_get_define('EWIKI_CHARS_U') . "]+[" . wiki_get_define('EWIKI_CHARS_L') . "]+){2,}\\#?[\\w\\d]* |\n                    \\w[-_.+\\w]+@(\\w[-_\\w]+[.])+\\w{2,}   ) x";
    }
    $content = ewiki_format($oldpage->content);
    return format_text($content, $moodle_format);
}
예제 #6
0
function ewiki_page_wiki_dump_send($imgs = 1, $fullhtml = 0, $virtual = 0, $rootid, $depth = 1, $arctype = EWIKI_WIKIDUMP_DEFAULTTYPE, $complevel = 1)
{
    global $ewiki_config, $ewiki_plugins;
    #-- disable protected email
    foreach ($ewiki_plugins["link_url"] as $key => $linkplugin) {
        if ($linkplugin == "ewiki_email_protect_link") {
            unset($ewiki_plugins["link_url"][$key]);
        }
    }
    #-- set uservars
    $a_uservars = ewiki_get_uservar("WikiDump", array());
    if (!is_array($a_uservars)) {
        $a_uservars = unserialize($a_uservars);
    }
    $a_uservars[$rootid] = $depth;
    ewiki_set_uservar("WikiDump", $a_uservars);
    #-- if $fullhtml
    $HTML_TEMPLATE = '<html>
    <head>' . ewiki_t("EWIKIDUMPCSS") . '
    <title>$title</title>
    </head>
    <body bgcolor="#ffffff";>
    <div id="PageText">
    <h2>$title</h2>
    $content
    </div>
    </body>
    </html>
    ';
    #-- reconfigure ewiki_format() to generate offline pages and files
    $html_ext = ".htm";
    if ($fullhtml) {
        $html_ext = ".html";
    }
    $ewiki_config["script"] = "%s{$html_ext}";
    $ewiki_config["script_binary"] = "%s";
    #-- fetch also dynamic pages
    $a_virtual = array_keys($ewiki_plugins["page"]);
    #-- get all pages / binary files
    $a_validpages = ewiki_valid_pages(1, $virtual);
    $a_pagelist = ewiki_sitemap_create($rootid, $a_validpages, $depth, 1);
    foreach ($a_pagelist as $key => $value) {
        if (is_array($a_validpages[$value]["refs"])) {
            foreach ($a_validpages[$value]["refs"] as $refs) {
                if ($a_validpages[$refs]["type"] == "image") {
                    $a_pagelist[] = $refs;
                }
            }
        }
    }
    foreach ($a_pagelist as $key => $value) {
        if ($a_validpages[$value]["type"] == "image") {
            $a_images[] = urlencode($value);
            $a_rimages[] = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $value));
            unset($a_validpages[$value]);
        }
    }
    $a_sitemap = ewiki_sitemap_create($rootid, $a_validpages, $depth, 0);
    if ($a_pagelist) {
        #-- create new zip file
        if ($arctype == "ZIP") {
            $archivename = EWIKI_WIKIDUMP_ARCNAME . "{$rootid}.zip";
            $archive = new ewiki_virtual_zip();
        } elseif ($arctype == "TAR") {
            $archivename = EWIKI_WIKIDUMP_ARCNAME . "{$rootid}.tar";
            $archive = new ewiki_virtual_tarball();
        } else {
            die;
        }
        $a_pagelist = array_unique($a_pagelist);
        #-- convert all pages
        foreach ($a_pagelist as $pagename) {
            if (!in_array($pagename, $a_virtual)) {
                $id = $pagename;
                #-- not a virtual page
                $row = ewiki_db::GET($pagename);
                $content = "";
            } elseif ($virtual) {
                $id = $pagename;
                #-- is a virtual page
                $pf = $ewiki_plugins["page"][$id];
                $content = $pf($id, $content, "view");
                if ($fullhtml) {
                    $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE));
                }
                $fn = urlencode($id);
                $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $fn);
                $fn = $fn . $html_ext;
            } else {
                continue;
            }
            if (empty($content)) {
                switch ($row["flags"] & EWIKI_DB_F_TYPE) {
                    case EWIKI_DB_F_TEXT:
                        $content = ewiki_format($row["content"]);
                        $content = str_replace($a_images, $a_rimages, $content);
                        $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", urlencode($id));
                        $fn = $fn . $html_ext;
                        if ($fullhtml) {
                            $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE));
                        }
                        break;
                    case EWIKI_DB_F_BINARY:
                        if ($row["meta"]["class"] == "image" && $imgs) {
                            $fn = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $id));
                            $content =& $row["content"];
                        } else {
                            #-- php considers switch statements as loops so continue 2 is needed to
                            #-- hit the end of the for loop
                            continue 2;
                        }
                        break;
                    default:
                        # don't want it
                        continue 2;
                }
            }
            $content = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $content);
            #-- add file
            $archive->add($content, $fn, array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)), $complevel);
        }
        #-- create index page
        $timer = array();
        $level = -1;
        $fordump = 1;
        $str_formatted = "<ul>\n<li><a href=\"" . $rootid . $html_ext . "\">" . $rootid . "</a></li>";
        $fin_level = format_sitemap($a_sitemap, $rootid, $str_formatted, $level, $timer, $fordump);
        $str_formatted .= "</ul>" . str_pad("", $fin_level * 6, "</ul>\n");
        $str_formatted = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $str_formatted);
        #-- add index page
        $archive->add($str_formatted, "Index_{$rootid}" . $html_ext, array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)), $complevel);
        #-- Headers
        Header("Content-type: application/octet-stream");
        Header("Content-disposition: attachment; filename=\"{$archivename}\"");
        Header("Cache-control: private");
        Header("Original-Filename: {$archivename}");
        Header("X-Content-Type: application/octet-stream");
        Header("Content-Location: {$archivename}");
        #-- end output
        echo $archive->close();
    }
    #-- fin
    die;
}
예제 #7
0
function ewiki_entry_downloads($row, $show_section = 0)
{
    global $ewiki_binary_icons, $ewiki_upload_sections, $ewiki_config;
    $meta =& $row["meta"];
    $id = $row["id"];
    $p_title = basename($meta["Content-Location"]);
    $p_time = strftime("%c", $row["created"]);
    $p_hits = $uu = $row["hits"] ? $uu : "0";
    $p_size = $meta["size"];
    $p_size = isset($p_size) ? ", " . ($p_size >= 4096 ? round($p_size / 1024) . "K" : $p_size . " bytes") : "";
    $p_ct1 = $meta["Content-Type"];
    $p_ct2 = $meta["X-Content-Type"];
    if ($p_ct1 == $p_ct2) {
        unset($p_ct2);
    }
    if ($p_ct1 && !$p_ct2) {
        $p_ct = "<tt>{$p_ct1}</tt>";
    } elseif (!$p_ct1 && $p_ct2) {
        $p_ct = "<tt>{$p_ct2}</tt>";
    } elseif ($p_ct1 && $p_ct2) {
        $p_ct = "<tt>{$p_ct1}</tt>, <tt>{$p_ct2}</tt>";
    } else {
        $p_ct = "<tt>application/octet-stream</tt>";
    }
    $p_section = $ewiki_upload_sections[$meta["section"]];
    $p_section = $p_section ? $p_section : $meta["section"];
    $p_comment = strlen($meta["comment"]) ? '<table border="1" cellpadding="2" cellspacing="0"><tr><td class="lighter">' . str_replace('</p>', '', str_replace('<p>', '', ewiki_format($meta["comment"]))) . '</td></tr></table>' : "<br />";
    $p_icon = "";
    foreach ($ewiki_binary_icons as $str => $i) {
        if (empty($str) || strstr($row["Content-Location"], $str) || strstr($p_ct, $str) || strstr($p_ct2, $str)) {
            $p_icon = $i;
            $p_icon_t = $str;
        }
    }
    $o .= ewiki_t("DWNL_ENTRY_FORMAT", array("id" => $id, "size" => $p_size, "icon" => $p_icon ? '<img src="' . $p_icon . '" alt="[' . $p_icon_t . ']" align="left" width="14" height="14" border="0" /> ' : '', "time" => $p_time, "hits" => $p_hits, "section" => $show_section ? ewiki_t('dwnl_section') . ": {$p_section}<br />" : '', "type" => $p_ct, "url" => ewiki_script_binary("", $row["id"]), "title" => $p_title, 'comment' => $p_comment, 'control_links' => ewiki_control_links_list($id, &$data, $ewiki_config["action_links"]["binary_get"], $data["version"])));
    return $o;
}
예제 #8
0
function ewiki_page_README($id, $data, $action)
{
    $UNDERLINE = "¯¯¯";
    $SECTIONSEP = "--------------------------------------------------------------";
    #-- open "README" text file
    if ($r = fopen("{$id}", "r") or $r = fopen("doc/{$id}", "r")) {
        #-- received request for a specific entry
        if (($para = $_REQUEST["paragraph"]) || ($goto = $_REQUEST["goto"])) {
            $str_next = $str_prev = "???";
            #-- exact "title" pattern given
            $n = 0;
            if ($para) {
                while (!feof($r) && trim($line) != $para) {
                    $line = fgets($r, 4096);
                    if (strstr($line, $UNDERLINE)) {
                        $n++;
                        $str_prev = $last;
                    }
                    $last = $line;
                }
                $n++;
            } elseif ($goto) {
                while (!feof($r) && $n < $goto) {
                    $para = $line;
                    $line = fgets($r, 4096);
                    if (strstr($line, $UNDERLINE)) {
                        $n++;
                        $str_prev = $last;
                    }
                    $last = $line;
                }
            }
            if ($goto && $n == $goto || strstr(fgets($r, 4096), $UNDERLINE)) {
                $hl = str_replace("[", "![", "\n!! {$para}\n\n<pre>");
                $line = "";
                $lines = array();
                $strip_n = -1;
                while (!feof($r) && !strstr($line, $UNDERLINE)) {
                    $last = $line;
                    $line = fgets($r, 4096);
                    if ($strip_n == -1) {
                        preg_match("/^([ ]+)/", $line, $uu);
                        $strip_n = strlen($uu[1]);
                    }
                    if ($strip_n) {
                        $line = preg_replace("/^[ ]{{$strip_n}}/", "", $line);
                    }
                    $lines[] = $line;
                }
                $str_next = $last;
                array_pop($lines);
                array_pop($lines);
                $src = rtrim(implode("", $lines));
                $lines = "";
                #-- transformation
                #            $src =  str_replace("[", "![", $src);
                if (preg_match_all('/^\\s+(EWIKI_[^\\s]+)/m', $src, $uu) && count($uu[1]) > 10 || preg_match_all('/^[ ]+([^\\n]+)\\n\\s\\s\\s------+/m', $src, $uu) && count($uu[1]) > 7) {
                    $src = preg_replace('/^[ ]+(EWIKI_[^\\s]+)/m', ' $1#[$1":"]', $src);
                    $src = preg_replace('/^[ ]+([^\\n]+)\\n\\s\\s\\s(------+)/m', "\n   \$1#[\$1\"\"]\n   \$2", $src);
                    foreach ($uu[1] as $anchor) {
                        $pre .= "- [#{$anchor} \"{$anchor}\"]\n";
                    }
                    $src = $pre . "\n" . $src;
                }
                $end = "\n</pre>\n";
                $o .= ewiki_format($hl . $src . $end);
            }
        } else {
            $o .= "\n<h2>{$id} overview</h2>\n";
            $ol_level = 0;
            $first = 0;
            $last = "";
            $o .= "<ol>\n";
            while (!feof($r)) {
                $line = fgets($r, 4096);
                if (strstr($line, $SECTIONSEP)) {
                    while ($ol_level) {
                        $o .= "</ol>\n";
                        $ol_level--;
                    }
                    $first = 1;
                }
                if (strstr($line, $UNDERLINE) && $lastline !== "{$id}") {
                    $new_ol_level = 1 - $first + (strpos($line, $UNDERLINE) > 2 ? 1 : 0);
                    while ($ol_level > $new_ol_level) {
                        $o .= "</ol>\n";
                        $ol_level--;
                    }
                    while ($ol_level < $new_ol_level) {
                        $o .= "<ol>\n";
                        $ol_level++;
                    }
                    $first = 0;
                    $o .= '<li><a href="' . ewiki_script("", "{$id}", array("paragraph" => $lastline)) . '">' . $lastline . '</a><br /></li>' . "\n";
                    $section = 1;
                }
                $lastline = trim($line);
            }
            while ($ol_level--) {
                $o .= "</ol>\n";
            }
            $o .= "</ol>\n";
        }
    }
    if ($n) {
        $o .= '<a href="' . ewiki_script("", "{$id}", "goto=" . ($n - 1)) . '">' . 'prev &lt;&lt; "' . trim($str_prev) . '"</a><br />';
        $o .= '<a href="' . ewiki_script("", "{$id}", "goto=" . ($n + 1)) . '">' . 'next &gt;&gt; "' . trim($str_next) . '"</a><br />';
    }
    $br = ewiki_script("", "BugReports");
    $us = ewiki_script("", "UserSuggestions");
    $dc = ewiki_script("", "{$id}.Discussion");
    $o .= "\n<br />\n<hr>\nYou cannot modify the {$id} file, but anyhow any ideas or suggestion should\nas usually get filed on <a href=\"{$br}\">BugReports</a>,\n<a href=\"{$us}\">UserSuggestions</a> or even better the\n<a href=\"{$dc}\">{$id}.Discussion</a>.\n<br />\n";
    return $o;
}
예제 #9
0
function ewiki_entry_downloads($row, $show_section = 0, $fullinfo = false)
{
    global $ewiki_binary_icons, $ewiki_upload_sections;
    $meta =& $row["meta"];
    $id = $row["id"];
    $p_title = basename($meta["Content-Location"]);
    $p_time = userdate($row["created"]);
    $p_hits = $row["hits"] ? $row["hits"] : "0";
    $p_size = $meta["size"];
    $p_size = isset($p_size) ? ", " . ($p_size >= 4096 ? round($p_size / 1024) . "K" : $p_size . " bytes") : "";
    $p_ct1 = $meta["Content-Type"];
    $p_ct2 = $meta["X-Content-Type"];
    if ($p_ct1 == $p_ct2) {
        unset($p_ct2);
    }
    if ($p_ct1 && !$p_ct2) {
        $p_ct = "<tt>{$p_ct1}</tt>";
    } elseif (!$p_ct1 && $p_ct2) {
        $p_ct = "<tt>{$p_ct2}</tt>";
    } elseif ($p_ct1 && $p_ct2) {
        $p_ct = "<tt>{$p_ct1}</tt>, <tt>{$p_ct2}</tt>";
    } else {
        $p_ct = "<tt>application/octet-stream</tt>";
    }
    $p_section = $ewiki_upload_sections[$meta["section"]];
    $p_section = $p_section ? $p_section : $meta["section"];
    $p_comment = strlen($meta["comment"]) ? '<table border="1" cellpadding="2" cellspacing="0"><tr><td class="lighter">' . str_replace('</p>', '', str_replace('<p>', '', ewiki_format($meta["comment"]))) . '</td></tr></table>' : "<br />";
    $p_icon = "";
    /*foreach ($ewiki_binary_icons as $str => $i) {
         if (empty($str) || strstr($row["Content-Location"], $str) || strstr($p_ct, $str) || strstr($p_ct2, $str)) { 
            $p_icon = $i;
            $p_icon_t = $str;
         }
      }*/
    /// Moodle Icon Handling
    global $CFG;
    $icon = mimeinfo("icon", $id);
    $p_icon = "{$CFG->pixpath}/f/{$icon}";
    $p_icon_t = "";
    $info->id = $id;
    $info->size = $p_size;
    $info->icon = $p_icon ? '<img src="' . $p_icon . '" alt="[' . $p_icon_t . ']" class="icon" /> ' : '';
    $info->time = $p_time;
    $info->hits = $p_hits;
    $info->section = $show_section ? ewiki_t('dwnl_section') . ": {$p_section}<br />" : '';
    $info->type = $p_ct;
    $info->url = ewiki_script_binary("", $row["id"]);
    $info->title = $p_title;
    $info->comment = format_text($p_comment);
    if ($fullinfo) {
        if ($user = get_record('user', 'id', $row['userid'])) {
            if (!isset($course->id)) {
                $course->id = 1;
            }
            $picture = print_user_picture($user->id, $course->id, $user->picture, false, true, true);
            $value = $picture . " <a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$course->id}\">" . fullname($user) . "</a>";
        }
        $o .= '<a href="' . $info->url . '">' . $info->icon . $info->title . '</a>' . $info->size . '<br />' . $info->comment . $info->section . " " . get_string("fileisoftype", "wiki") . ": " . $info->type . '<br />' . get_string("uploadedon", "wiki") . ": " . $info->time . ", " . ' by ' . $value . '<br />' . get_string("downloadtimes", "wiki", $info->hits) . "<br />" . '<br /><br />';
    } else {
        //       global $moodle_format;   // from wiki/view.php
        $o .= '<a href="' . $info->url . '">' . $info->icon . $info->title . '</a>' . $info->size . '<br />' . $info->comment . '<br /><br />';
        //        $o = format_text($o, $moodle_format);
    }
    ewiki_t("DWNL_ENTRY_FORMAT", $info);
    return $o;
}
예제 #10
0
파일: news.php 프로젝트: gpuenteallott/rox
   (or just customize the defaults below)
*/
if (true) {
    global $ewiki_plugins, $ewiki_config;
    #-- conf
    ($n_get = $ewiki_config["newsblock_links"]) || ($n_get = "News");
    ($n_num = $ewiki_config["newsblock_num"]) || ($n_num = 10);
    ($n_len = $ewiki_config["newsblock_len"]) || ($n_len = 196);
    #-- fetch all page entries from DB, for sorting on creation time
    $links = ewiki_db::GET($n_get);
    $links = explode("\n", trim($links["refs"]));
    #-- cut
    $links = array_slice($links, 0, $n_num);
    #-- gen output
    $o = "";
    foreach ($links as $uu => $id) {
        if ($row = ewiki_db::GET($id)) {
            $text = substr($row["content"], 0, $n_len);
            $text = trim(strip_tags(strtr($text, "\r\n\t", "   ")));
            $text = str_replace("[internal://", "[  internal://", $text);
            $text .= "\n";
            #         $text .= " [...[read more | $id]]\n";
            $o .= "__[{$id}]__\n" . "{$text}\n" . "%%%\n";
        }
    }
    #-- pass thru renderer
    if ($o) {
        $o = ewiki_format($o);
        echo '<div class="block-news">' . $o . '</div>';
    }
}
예제 #11
0
function ewiki_page_wiki_dump_send($imgs = 1, $fullhtml = 0, $virtual = 0, $linksto = 0)
{
    global $ewiki_config, $ewiki_plugins;
    #-- reconfigure ewiki_format() to generate offline pages and files
    $html_ext = ".htm";
    if ($fullhtml) {
        $html_ext = ".html";
    }
    $ewiki_config["script"] = "%s{$html_ext}";
    $ewiki_config["script_binary"] = "%s";
    $ewiki_config["print_title"] = 0;
    #-- fetch also dynamic pages
    if ($virtual) {
        $virtual = array_keys($ewiki_plugins["page"]);
    } else {
        $virtual = array();
    }
    #-- get all pages / binary files
    $result = ewiki_db::GETALL(array("id", "version", "flags"));
    if ($result) {
        #-- HTTP headers
        header("Content-Type: application/x-tar");
        header("Content-Disposition: attachment; filename=\"WikiDump.tar.gz\"");
        #-- start tar file
        $tarball = new ewiki_virtual_tarball();
        $tarball->open(0);
        #-- convert all pages
        while (($row = $result->get()) || count($virtual)) {
            $content = "";
            #-- fetch page from database
            if ($id = $row["id"]) {
                $row = ewiki_db::GET($id);
            } elseif ($id = array_pop($virtual)) {
                $pf = $ewiki_plugins["page"][$id];
                $content = $pf($id, $content, "view");
                $row = array("flags" => EWIKI_DB_F_TEXT | EWIKI_DB_F_HTML, "lastmodified" => time());
            } else {
                break;
            }
            #-- file name
            $fn = $id;
            $fn = urlencode($fn);
            #-- post process for ordinary pages / binary data
            if (empty($content)) {
                switch ($row["flags"] & EWIKI_DB_F_TYPE) {
                    case EWIKI_DB_F_TEXT:
                        $content = ewiki_format($row["content"]);
                        break;
                    case EWIKI_DB_F_BINARY:
                        if ($row["meta"]["class"] == "image" && $imgs) {
                            $content =& $row["content"];
                        } else {
                            return;
                        }
                        break;
                    default:
                        # don't want it
                        continue;
                }
            }
            #-- size check
            if (empty($content)) {
                continue;
            }
            #-- for tarball
            $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00));
            #-- html post process
            if (!($row["flags"] & EWIKI_DB_F_BINARY)) {
                #-- use page template
                if ($fullhtml) {
                    $content = ewiki_dump_template($id, $content, $linksto);
                }
                #-- add links/ page
                if ($linksto) {
                    $tarball->add("{$fn}.links{$html_ext}", ewiki_dump_template($id, ewiki_page_links($id, $row, "links"), $lto = -1), $perms);
                }
                $fn .= $html_ext;
            }
            #-- add file
            $tarball->add($fn, $content, $perms);
        }
        #-- end output
        $tarball->close();
    }
    #-- fin
    die;
}
예제 #12
0
<?php

/*
   Loads the page named "UsageHints" and randomly selects a
   paragraph to output.
*/
if (true) {
    if ($data = ewiki_db::GET("UsageHints")) {
        $hints = preg_split("/\n+(---+\\s*)?\n+/", trim($data["content"]));
        $n = rand(0, count($hints) - 1);
        $text = $hints[$n];
        if ($text) {
            echo ewiki_format($text);
        }
    }
}
예제 #13
0
<?php

/*
   Gets the first list of links from the page "MainMenu" and outputs
   it. (verything else on that page gets stripped)
*/
if (true) {
    $mm = ewiki_db::GET("MainMenu");
    if ($mm = $mm["content"]) {
        $mm = preg_replace("/^([^*]+[^\n]+)?\n/m", "", $mm);
        $mm = ewiki_format($mm);
        echo '<div class="MainMenu">' . "\n" . $mm . "\n</div>\n";
    }
}
예제 #14
0
<?php

#-- like in the ZendWiki example
if ($data = ewiki_db::GET($editbar = "EditableSideText")) {
    echo ewiki_format($data["content"]);
    echo '<br>';
}
echo '<br><small><a href="' . ewiki_script("edit", $editbar) . '">Add some text here...</a><br></small>' . "\n\n";
예제 #15
0
function ewiki_linkdatabase($id, &$data, $action)
{
    if ($_REQUEST["action"] == "links" && $id == "action=links" && empty($_REQUEST["id"])) {
        $o = array("editlink" => 0, "empty" => 0, "names" => 1, "unique" => 1, "sort" => 1, "exists" => 2, "url" => 0, "inter" => 0, "search" => "");
        $o = array_merge($o, $_REQUEST);
        #-- first read in all pages
        $res = ewiki_db::GETALL(array("flags", "version", "refs"));
        $all = array();
        while ($row = $res->get()) {
            if (($row["version"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
                $refs = trim($row["refs"]);
                if (!$o["empty"] && empty($refs)) {
                    continue;
                }
                $all[$row["id"]] = $refs;
            }
        }
        #-- sort
        ksort($all);
        #-- output
        $out = "";
        foreach ($all as $i => $refs) {
            $refs = explode("\n", $refs);
            if ($refs) {
                $refs = ewiki_db::FIND($refs);
            }
            foreach ($refs as $ri => $rv) {
                if ($o["exists"] != 2) {
                    if ($rv != $o["exists"]) {
                        unset($refs[$ri]);
                    }
                }
                if ($o["url"] != 1) {
                    if ($o["url"] xor strpos($ri, "://")) {
                        unset($refs[$ri]);
                    }
                }
                if ($o["inter"] != 1) {
                    if ($o["inter"] xor strpos($ri, ":") && !strpos($ri, "://")) {
                        unset($refs[$ri]);
                    }
                }
                if ($o["search"] && strpos($ri, $o["search"]) === false) {
                    unset($refs[$ri]);
                }
            }
            if (!$o["empty"] && empty($refs)) {
                continue;
            }
            if ($o["sort"]) {
                asort($refs);
            }
            $out .= "<a href=\"" . ewiki_script("", $i) . "\">{$i}</a>  ";
            foreach ($refs as $i => $rv) {
                $title = $o[names] ? $i : " ";
                if ($rv) {
                    $out .= " <a href=\"" . ewiki_script("", $i) . "\">{$title}</a>";
                } else {
                    $out .= " {$title}";
                    if ($o["editlink"]) {
                        $out .= "<a href=\"" . ewiki_script("", $i) . "\">?</a>";
                    }
                }
            }
            $out .= "\n";
        }
        return "\n<pre>\n\n\n\n{$out}</pre>\n";
    } elseif ($id == "LinkDatabase") {
        $url = "url:?";
        #      $url = "ErfurtWiki:";
        return ewiki_format(<<<EOT
!!! LinkDatabase

The LinkDatabase provides a list of all internal pages together with the
links outgoing from each.

* [{$url}action=links] list pages and links, using default options
* [{$url}action=links&editlink=1] add the "?" link for not existent pages
* [{$url}action=links&empty=1] allowes listing of pages without forward links
* [{$url}action=links&names=0] no link title, just the <a href="...">
* [{$url}action=links&sort=0] order pages and their links
* [{$url}action=links&exists=0] only links to not existing pages
* [{$url}action=links&exists=1] only existing page links
* [{$url}action=links&url=1] add URLs
* [{$url}action=links&url=2] __only__ URLs
* [{$url}action=links&inter=1] add ~InterWiki:Links
* [{$url}action=links&inter=2] __only__ ~InterWiki:Links
* [{$url}action=links&search=google] apply search pattern to page links

handy combinations
* [{$url}action=links&inter=1&editlink=1&empty=1&url=1&sort=0&names=1] show all links
* [{$url}action=links&search=sourceforge&url=2] only URL links to sourceforge
* [{$url}action=links&sort=0&exists=0] unsorted missing pages

Only [{$url}action=links&unique=0] has not been implemented.

EOT
);
    }
}
예제 #16
0
function ewiki_page_edit_form(&$id, &$data, &$hidden_postdata)
{
    global $ewiki_plugins, $ewiki_config, $moodle_format;
    $content = optional_param('content', '');
    $version = optional_param('version', '');
    $o = '';
    #-- previously edited, or db fetched content
    if ($content || $version) {
        $data = array("version" => $version, "content" => $content);
    } else {
        if (empty($data["version"])) {
            $data["version"] = 1;
        }
        @($data["content"] .= "");
    }
    #-- normalize to DOS newlines
    $data["content"] = str_replace("\r\n", "\n", $data["content"]);
    $data["content"] = str_replace("\r", "\n", $data["content"]);
    $data["content"] = str_replace("\n", "\r\n", $data["content"]);
    $hidden_postdata["version"] =& $data["version"];
    #-- edit textarea/form
    // deleted name="ewiki", can not find the reference, and it's breaking xhtml
    $o .= ewiki_t("EDIT_FORM_1") . '<form method="post" enctype="multipart/form-data" action="' . ewiki_script("edit", $id) . '" ' . ' accept-charset="' . EWIKI_CHARSET . '">' . "\n";
    $o .= '<div>';
    #-- additional POST vars
    foreach ($hidden_postdata as $name => $value) {
        $o .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />' . "\n";
    }
    ($cols = strtok($ewiki_config["edit_box_size"], "x*/,;:")) && ($rows = strtok("x, ")) || ($cols = 70) && ($rows = 15);
    global $ewiki_use_editor, $ewiki_editor_content;
    $ewiki_editor_content = 1;
    if ($ewiki_use_editor) {
        ob_start();
        $usehtmleditor = can_use_html_editor();
        echo '<table><tr><td>';
        if ($usehtmleditor) {
            //clean and convert before editing
            $options = new object();
            $options->smiley = false;
            $options->filter = false;
            $oldtext = format_text(ewiki_format($data["content"]), $moodle_format, $options);
        } else {
            $oldtext = ewiki_format($data["content"]);
        }
        print_textarea($usehtmleditor, $rows, $cols, 680, 400, "content", $oldtext);
        echo '</td></tr></table>';
        $o .= ob_get_contents();
        ob_end_clean();
    } else {
        ##### END MOODLE ADDITION #####
        $o .= '<textarea wrap="soft" id="ewiki_content" name="content" rows="' . $rows . '" cols="' . $cols . '">' . s($data["content"]) . "</textarea>" . $GLOBALS["ewiki_t"]["C"]["EDIT_TEXTAREA_RESIZE_JS"];
        ##### BEGIN MOODLE ADDITION #####
    }
    ##### END MOODLE ADDITION #####
    #-- more <input> elements before the submit button
    if ($pf_a = $ewiki_plugins["edit_form_insert"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    ##### BEGIN MOODLE ADDITION (Cancel Editing into Button) #####
    $o .= "\n<br />\n" . '<input type="submit" name="save" value="' . ewiki_t("SAVE") . '" />' . "\n" . '<input type="submit" name="preview" value="' . ewiki_t("PREVIEW") . '" />' . "\n" . '<input type="submit" name="canceledit" value="' . ewiki_t("CANCEL_EDIT") . '" />' . "\n";
    #      . ' &nbsp; <a href="'. ewiki_script("", $id) . '">' . ewiki_t("CANCEL_EDIT") . '</a>';
    ##### END MOODLE ADDITION #####
    #-- additional form elements
    if ($pf_a = $ewiki_plugins["edit_form_append"]) {
        foreach ($pf_a as $pf) {
            $o .= $pf($id, $data, $action);
        }
    }
    $o .= "\n</div></form>\n";
    //   . ewiki_t("EDIT_FORM_2");  // MOODLE DELETION
    return '<div class="edit-box">' . $o . '</div>';
}
예제 #17
0
function ewiki_page_wiki_dump_send($exportbinaries = 0, $exportformats = 0, $withvirtualpages = 0, $exportdestinations = 0)
{
    global $ewiki_config, $wiki, $ewiki_plugins, $wiki_entry, $course, $CFG, $ewiki_t, $userid, $groupid;
    $filestozip = array();
    #-- disable protected email
    if (is_array($ewiki_plugins["link_url"])) {
        foreach ($ewiki_plugins["link_url"] as $key => $linkplugin) {
            if ($linkplugin == "ewiki_email_protect_link") {
                unset($ewiki_plugins["link_url"][$key]);
            }
        }
    }
    /// HTML-Export
    if ($exportformats == 1) {
        #-- if exportformats is html
        $HTML_TEMPLATE = '<html>
      <head>' . $ewiki_t["c"]["EWIKIDUMPCSS"] . '
      <title>$title</title>
      </head>
      <body bgcolor="#ffffff";>
      <div id="PageText">
      <h2>$title</h2>
      $content
      </div>
      </body>
      </html>';
        #-- reconfigure ewiki_format() to generate offline pages and files
        $html_ext = ".html";
        $ewiki_config["script"] = "%s{$html_ext}";
        $ewiki_config["script_binary"] = "%s";
    }
    // Export Virtual pages special
    $a_virtual = array_keys($ewiki_plugins["page"]);
    #-- get all pages / binary files
    $a_validpages = ewiki_valid_pages(1, $withvirtualpages);
    $a_pagelist = ewiki_sitemap_create($wiki_entry->pagename, $a_validpages, 100, 1);
    # Add linked binary files to pagelist
    foreach ($a_pagelist as $key => $value) {
        if (is_array($a_validpages[$value]["refs"])) {
            foreach ($a_validpages[$value]["refs"] as $refs) {
                if ($a_validpages[$refs]["type"] == "image" || $a_validpages[$refs]["type"] == "file") {
                    $a_pagelist[] = $refs;
                }
            }
        }
    }
    # Adjust links to binary files
    foreach ($a_pagelist as $key => $value) {
        if ($a_validpages[$value]["type"] == "image") {
            $a_images[] = urlencode($value);
            $a_rimages[] = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $value));
            unset($a_validpages[$value]);
        }
        if ($a_validpages[$value]["type"] == "file") {
            $a_images[] = urlencode($value);
            $a_rimages[] = clean_filename(substr($value, strlen(EWIKI_IDF_INTERNAL)));
            $a_images[] = $value;
            $a_rimages[] = clean_filename(substr($value, strlen(EWIKI_IDF_INTERNAL)));
            unset($a_validpages[$value]);
        }
    }
    # Remove binaries from a_validpages and add to a_pagelist
    foreach ($a_validpages as $key => $value) {
        if ($a_validpages[$key]["type"] == "image" || $a_validpages[$key]["type"] == "file") {
            $a_pagelist[] = $key;
            unset($a_validpages[$key]);
        }
    }
    #print "<pre>"; print_r($a_validpages); print "</pre>";
    #print "<hr /><pre>"; print_r($a_pagelist); print "</pre>";
    $a_sitemap = ewiki_sitemap_create($wiki_entry->pagename, $a_validpages, 99, 0);
    if ($a_pagelist) {
        #-- create new zip file
        #if($arctype == "ZIP"){
        #  $archivename=EWIKI_WIKIDUMP_ARCNAME."$rootid.zip";
        #  $archive = new ewiki_virtual_zip();
        #} elseif ($arctype == "TAR") {
        #  $archivename=EWIKI_WIKIDUMP_ARCNAME."$rootid.tar";
        #  $archive = new ewiki_virtual_tarball();
        #} else {
        #  die();
        #}
        /// Create/Set Directory
        $wname = clean_filename(strip_tags(format_string($wiki->name, true)));
        if ($exportdestinations) {
            if (wiki_is_teacher($wiki)) {
                $exportdir = $CFG->dataroot . "/" . $course->id . "/" . $exportdestinations;
            } else {
                add_to_log($course->id, "wiki", "hack", "", format_string($wiki->name, true) . ": Tried to export a wiki as non-teacher into {$exportdestinations}.");
                error("You are not a teacher !");
            }
        } else {
            $exportbasedir = tempnam("/tmp", "WIKIEXPORT");
            @unlink($exportbasedir);
            @mkdir($exportbasedir);
            /// maybe we need to check the name here...?
            $exportdir = $exportbasedir . "/" . $wname;
            @mkdir($exportdir);
            if (!is_dir($exportdir)) {
                error("Cannot create temporary directory {$exportdir} !");
            }
        }
        $a_pagelist = array_unique($a_pagelist);
        #-- convert all pages
        foreach ($a_pagelist as $pagename) {
            if (!in_array($pagename, $a_virtual)) {
                $id = $pagename;
                #-- not a virtual page
                $row = ewiki_database("GET", array("id" => $pagename));
                $content = "";
            } elseif ($withvirtualpages) {
                $id = $pagename;
                #-- is a virtual page
                $pf = $ewiki_plugins["page"][$id];
                $content = $pf($id, $content, "view");
                if ($exportformats == 1) {
                    $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE));
                }
                $fn = urlencode($id);
                $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $fn);
                $fn = $fn . $html_ext;
            } else {
                continue;
            }
            if (empty($content)) {
                switch ($row["flags"] & EWIKI_DB_F_TYPE) {
                    // Text Page
                    case EWIKI_DB_F_TEXT:
                        #print "<pre>"; print_r($row[content]); print "\n-------------</pre>";
                        if ($exportformats == 1) {
                            /// HTML-Export
                            $content = ewiki_format($row["content"]);
                        } else {
                            $content = $row["content"];
                        }
                        # Binary files link adjustment when html
                        if ($exportformats == 1) {
                            $content = str_replace($a_images, $a_rimages, $content);
                        }
                        $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", urlencode($id));
                        $fn = $fn . $html_ext;
                        if ($exportformats == 1) {
                            /// HTML-Export
                            $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE));
                        }
                        break;
                    case EWIKI_DB_F_BINARY:
                        #print "Binary: $row[id]<br />";
                        if (($row["meta"]["class"] == "image" || $row["meta"]["class"] == "file") && $exportbinaries) {
                            # Copy files to the appropriate directory
                            $fn = moodle_binary_get_path($id, $row["meta"], $course, $wiki, $userid, $groupid);
                            $destfn = clean_filename(substr($id, strlen(EWIKI_IDF_INTERNAL)));
                            $dest = "{$exportdir}/" . $destfn;
                            if (!copy($fn, $dest)) {
                                notify("Cannot copy {$fn} to {$dest}.");
                            }
                            #$fn = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $id));
                            #$content = &$row["content"];
                            $filestozip[] = $exportdir . "/" . $destfn;
                            continue 2;
                        } else {
                            #-- php considers switch statements as loops so continue 2 is needed to
                            #-- hit the end of the for loop
                            continue 2;
                        }
                        break;
                    default:
                        # don't want it
                        continue 2;
                }
            }
            # Do not translate links when wiki already in pure html - mode
            if ($wiki->htmlmode != 2) {
                $content = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $content);
            }
            #-- add file
            // Let's make sure the file exists and is writable first.
            if (!($handle = fopen($exportdir . "/" . $fn, 'w'))) {
                error("Cannot open file ({$exportdir}/{$fn})");
            }
            // Write $content to our opened file.
            if (fwrite($handle, $content) === FALSE) {
                error("Cannot write to file ({$exportdir}/{$fn})");
            }
            fclose($handle);
            $filestozip[] = $exportdir . "/" . $fn;
            #$archive->add($content, $fn, array(
            #  "mtime" => $row["lastmodified"],
            #  "uname" => "ewiki",
            #  "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000),
            #  ), $complevel);
        }
        #-- create index page
        /// HTML-Export
        if ($exportformats == 1) {
            $timer = array();
            $level = -1;
            $fordump = 1;
            $str_formatted = "<ul>\n<li><a href=\"" . $wiki_entry->pagename . $html_ext . "\">" . $wiki_entry->pagename . "</a></li>";
            $fin_level = format_sitemap($a_sitemap, $wiki_entry->pagename, $str_formatted, $level, $timer, $fordump);
            $str_formatted .= "</ul>" . str_pad("", $fin_level * 6, "</ul>\n");
            $str_formatted = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $str_formatted);
            $str_formatted = str_replace('$content', $str_formatted, str_replace('$title', get_string("index", "wiki"), $HTML_TEMPLATE));
            #-- add file
            // Let's make sure the file exists and is writable first.
            $indexname = "index" . $html_ext;
            if (!($handle = fopen($exportdir . "/" . $indexname, 'w'))) {
                error("Cannot open file ({$exportdir}/{$indexname})");
            }
            // Write $somecontent to our opened file.
            if (fwrite($handle, $str_formatted) === FALSE) {
                error("Cannot write to file ({$exportdir}/{$indexname})");
            }
            fclose($handle);
            $filestozip[] = $exportdir . "/" . $indexname;
            #-- add index page
            #    $archive->add($str_formatted, "Index_$rootid".$html_ext, array(
            #      "mtime" => $row["lastmodified"],
            #      "uname" => "ewiki",
            #      "mode" => 0664 | (($row["flags"]&EWIKI_DB_F_WRITEABLE)?0002:0000),
            #      ), $complevel);
        }
        if (!$exportdestinations) {
            $archivename = $wname . ".zip";
            zip_files($filestozip, "{$exportbasedir}/{$archivename}");
            #-- Headers
            Header("Content-type: application/zip");
            Header("Content-disposition: attachment; filename=\"{$archivename}\"");
            Header("Cache-control: private");
            Header("Original-Filename: {$archivename}");
            Header("X-Content-Type: application/zip");
            Header("Content-Location: {$archivename}");
            if (!@readfile("{$exportbasedir}/{$archivename}")) {
                error("Cannot read {$exportbasedir}/{$archivename}");
            }
            if (!deldir($exportbasedir)) {
                error("Cannot delete {$exportbasedir}");
            }
            #exit();
            return false;
        } else {
            return get_string("exportsuccessful", "wiki") . "<br />";
        }
    }
}
예제 #18
0
function wikiapi_getPageHtml($id, $ver = NULL)
{
    $data = ewiki_db::GET($id, $ver);
    if ($data) {
        $render_args = array("scan_links" => 1, "html" => EWIKI_ALLOW_HTML || @$data["flags"] & EWIKI_DB_F_HTML);
        $res = ewiki_format($data["content"], $render_args);
        return $res;
        #wikiapi_b64encode()
    }
}