function ewiki_add_title_image(&$html, $id, &$data, $action) { if (!isset($data['meta']['pageimage']) || $data['meta']['pageimage'] == '') { return; } $imagename = $data['meta']['pageimage']; $image = ewiki_database('GET', $imagename); if (EWIKI_PROTECTED_MODE && !ewiki_auth($imagename, $image, "binary-get")) { return; } #-- height, width $x = $image['meta']["width"]; $y = $image['meta']["height"]; #-- print a/img tag $o .= '<img src="' . ewiki_script_binary("", $imagename) . '" border="0" width="' . $x . '" height="' . $y . '"' . ' />' . "\n"; $html = preg_replace('/<h2 class="page title">/', '<h2 class="page title">' . $o, $html, 1); }
function ewiki_link_regex_callback($uu, $force_noimg = 0) { #print "<pre>"; print_r($uu); print "</pre>"; global $ewiki_links, $ewiki_plugins, $ewiki_config, $ewiki_id; $str = trim($uu[0]); $type = array(); $states = array(); #-- link bracket '[' escaped with '!' or '~' if ($str[0] == "!" || $str[0] == "~") { return substr($str, 1); } if ($str[0] == "#") { $states["define"] = 1; $str = substr($str, 1); } if ($str[0] == "[") { $states["brackets"] = 1; $str = substr($str, 1, -1); } #-- explicit title given via [ title | WikiLink ] $href = $title = strtok($str, "|"); if ($uu = strtok("|")) { $href = $uu; $states["titled"] = 1; } #-- title and href swapped: swap back if (strpos("://", $title) || strpos($title, ":") && !strpos($href, ":")) { $uu = $title; $title = $href; $href = $uu; } #-- new entitling scheme [ url "title" ] if (($l = strpos($str, '"')) < ($r = strrpos($str, '"')) && $l !== false) { $title = substr($str, $l + 1, $r - $l - 1); $href = substr($str, 0, $l) . substr($str, $r + 1); $states["titled"] = 1; } #-- strip spaces $spaces_l = $href[0] == " " ? 1 : 0; $spaces_r = $href[strlen($href) - 1] == " " ? 1 : 0; $title = ltrim(trim($title), "^"); $href = ltrim(trim($href), "^"); #-- strip_htmlentities() if (1 && strpos($href, "&") !== false && strpos($href, ";")) { foreach (array("<" => "<", ">" => ">", "&" => "&") as $f => $t) { $href = str_replace($f, $t, $href); } } #-- anchors $href2 = ""; if (($p = strrpos($href, "#")) && $p && $href[$p - 1] != "&") { $href2 = trim(substr($href, $p)); $href = trim(substr($href, 0, $p)); } elseif ($p === 0) { $states["define"] = 1; } if ($href == ".") { $href = $ewiki_id; } #-- for case-insensitivines $href_i = EWIKI_CASE_INSENSITIVE ? strtolower($href) : $href; #-- injected URLs if (strpos($inj_url = $ewiki_links[$href_i], "://")) { if ($href == $title) { $href = $inj_url; } } #-- interwiki links if (strpos($href, ":") && ($uu = ewiki_interwiki($href, $type))) { $href = $uu; $str = "<a href=\"{$href}{$href2}\">{$title}</a>"; } elseif ($ewiki_plugins["action"][$a = strtolower(strtok($href, ":"))]) { $type = array($a, "action", "wikipage"); $str = '<a href="' . ewiki_script($a, strtok("")) . '">' . $title . '</a>'; } elseif (@$states["define"]) { $type = array("anchor"); if ($title == $href) { $title = " "; } $str = '<a name="' . s(ltrim($href, "#")) . '">' . ltrim($title, "#") . '</a>'; } elseif (strlen($href2) && $href == $ewiki_id || $href[0] == "#" && ($href2 =& $href)) { $type = array("jump"); $str = '<a href="' . s($href2) . '">' . $title . '</a>'; } elseif ($ewiki_links === true || @$ewiki_links[$href_i]) { $type = array("wikipage"); #### BEGIN MOODLE CHANGES global $ewiki_link_case; $href_realcase = array_key_exists($href_i, $ewiki_link_case) ? $ewiki_link_case[$href_i] : $href; $str = '<a href="' . ewiki_script("", $href_realcase) . s($href2) . '">' . $title . '</a>'; #### END MOODLE CHANGES } elseif (strpos($href, "@") && !strpos($href, ":")) { $type = array("email"); $href = "mailto:" . $href; } else { $str = ""; #-- a plugin may take care if ($pf_a = $ewiki_plugins["link_notfound"]) { foreach ($pf_a as $pf) { if ($str = $pf($title, $href, $href2, $type)) { break; } } } #-- (QuestionMarkLink to edit/ action) if (!$str) { $type = array("notfound"); $str = '<span class="NotFound"><b>' . $title . '</b><a href="' . ewiki_script("", $href) . '">?</a></span>'; } } #-- convert standard URLs foreach ($ewiki_config["idf"]["url"] as $find) { if (strpos($href, $find) === 0) { $type[-2] = "url"; $type[-1] = strtok($find, ":"); #-- URL plugins if ($pf_a = $ewiki_plugins["link_url"]) { foreach ($pf_a as $pf) { if ($str = $pf($href, $title)) { break 2; } } } $meta = @$ewiki_links[$href]; #-- check for image files $ext = substr($href, strrpos($href, ".")); $nocache = strpos($ext, "no"); $ext = strtok($ext, "?&#"); $obj = in_array($ext, $ewiki_config["idf"]["obj"]); $img = $obj || in_array($ext, $ewiki_config["idf"]["img"]); #-- internal:// references (binary files) if (EWIKI_SCRIPT_BINARY && (strpos($href, EWIKI_IDF_INTERNAL) === 0 || EWIKI_IMAGE_MAXSIZE && EWIKI_CACHE_IMAGES && $img && !$nocache)) { $type = array("binary"); $href = ewiki_script_binary("", $href); } #-- output html reference if (!$img || $force_noimg || !$states["brackets"] || strpos($href, EWIKI_IDF_INTERNAL) === 0) { $str = '<a href="' . $href . '">' . $title . '</a>'; } else { if (is_string($meta)) { $meta = unserialize($meta); } $type = array("image"); #-- uploaded images size $x = $meta["width"]; $y = $meta["height"]; if ($p = strpos('?', $href)) { #-- width/height given in url parse_str(str_replace("&", "&", substr($href, $p)), $meta); $uu = $meta["x"] . $meta["width"] and $x = $uu; $uu = $meta["y"] . $meta["height"] and $y = $uu; if ($scale = $meta["r"] . $meta["scale"]) { $p = strpos($scale, "%") and $scale = strpos($scale, 0, $p) / 100; $x *= $scale; $y *= $scale; } } $align = array('', ' align="right"', ' align="left"', ' align="center"'); $align = $align[$spaces_l + 2 * $spaces_r]; $str = ($obj ? '<embed width="70%"' : '<img') . ' src="' . $href . '"' . ' alt="' . $title . '"' . (@$states["titled"] ? ' title="' . $title . '"' : '') . ($x && $y ? " width=\"{$x}\" height=\"{$y}\"" : "") . $align . " />" . ($obj ? "</embed>" : ""); # htmlentities($title) } break; } } #-- icon/transform plugins ksort($type); if ($pf_a = @$ewiki_plugins["link_final"]) { foreach ($pf_a as $pf) { $pf($str, $type, $href, $title); } } return $str; }
function wiki_admin_remove_list($listall = "") { /// Table header $table = new Object(); $table->head = array(" ", get_string("pagename", "wiki"), get_string("errororreason", "wiki")); /// Get all pages $result = ewiki_database("GETALL", array("version")); $selected = array(); /// User wants to see all pages if ($listall) { while ($row = $result->get()) { $selected[$row["id"]] = get_string("listall", "wiki") . "<br />"; } } while ($page = $result->get()) { $id = $page["id"]; $page = ewiki_database("GET", array("id" => $id)); $flags = $page["flags"]; #print "$id ".strlen(trim(($page["content"])))."<br />"; if (!strlen(trim($page["content"])) && !($flags & EWIKI_DB_F_BINARY)) { @($selected[$id] .= get_string("emptypage", "wiki") . "<br />"); } // Check for orphaned pages $result2 = ewiki_database("SEARCH", array("content" => $id)); $orphanedpage = true; if ($result2 && $result2->count()) { while ($row = $result2->get()) { $checkcontent = ewiki_database("GET", array("id" => $row["id"])); $checkcontent = strtolower($checkcontent["content"]); if (strpos($checkcontent, strtolower($id)) !== false) { $orphanedpage = false; } #echo "rc({$row['id']})==>($id): $check2 <br />"; } } /// Some more reasons for Deletion... if ($orphanedpage && $id != EWIKI_PAGE_INDEX && !($flags & EWIKI_DB_F_BINARY)) { @($selected[$id] .= get_string("orphanedpage", "wiki") . "<br />"); } if ($flags & EWIKI_DB_F_DISABLED) { @($selected[$id] .= get_string("disabledpage", "wiki") . "<br />"); } if (($flags & 3) == 3) { @($selected[$id] .= get_string("errorbinandtxt", "wiki") . "<br />"); } if (!($flags & 3)) { @($selected[$id] .= get_string("errornotype", "wiki") . "<br />"); } if ($flags & EWIKI_DB_F_HTML) { @($selected[$id] .= get_string("errorhtml", "wiki") . "<br />"); } if ($flags & EWIKI_DB_F_READONLY && !($flags & EWIKI_DB_F_BINARY)) { @($selected[$id] .= get_string("readonly", "wiki") . "<br />"); } if ($flags & EWIKI_DB_F_READONLY && $flags & EWIKI_DB_F_WRITEABLE) { @($selected[$id] .= get_string("errorroandwr", "wiki") . "<br />"); } if (strlen($page["content"]) >= 65536) { @($selected[$id] .= get_string("errorsize", "wiki") . "<br />"); } if (strpos($page["refs"], "\n" . get_string("deletemewikiword", "wiki") . "\n") !== false) { @($selected[$id] .= get_string("deletemewikiwordfound", "wiki", get_string("deletemewikiword", "wiki")) . "<br />"); } } foreach ($selected as $id => $reason) { $table_checkbox = '<input type="checkbox" value="' . rawurlencode($id) . '" name="pagestodelete[]" />'; #-- link & id if (strpos($id, EWIKI_IDF_INTERNAL) === false) { $table_page = '<a href="' . ewiki_script("", $id) . '">'; } else { $table_page = '<a href="' . ewiki_script_binary("", $id) . '">'; } $table_page .= s($id) . '</a>'; #-- print reason $table_reason = $reason; $table->data[] = array($table_checkbox, $table_page, $table_reason); } return $table; }
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; }
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}&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; }
function ewiki_page_image_gallery($id, $data = 0, $action) { global $ewiki_config; $o = ewiki_make_title($id, $id, 2); $mwidth = 120; $mscale = 0.7; #-- fetch and asort images $sorted = array(); $pages = array(); $result = ewiki_db::GETALL(array("flags", "created", "meta", "refs")); while ($row = $result->get()) { if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_BINARY && strpos($row['meta']['Content-Type'], 'image/') === 0) { if (isset($ewiki_config['image-galleries'][$id])) { foreach ($ewiki_config['image-galleries'][$id] as $field => $value) { if ($row['meta'][$field] != $value) { continue 2; } } } if (!EWIKI_PROTECTED_MODE || EWIKI_PROTECTED_MODE_HIDING <= 0.5 || ewiki_auth($row["id"], $uu, "binary-get")) { $sorted[$row["id"]] = $row["created"]; $pages[$row["id"]] = $row; } } elseif (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) { $page_refs[$row["id"]] = $row["refs"]; } } arsort($sorted); #-- start table $o .= '<table border="0" cellpadding="10" cellspacing="4">' . "\n"; $n = 0; $num_per_row = EWIKI_GALLERY_WIDTH; foreach ($sorted as $image => $uu) { $row = $pages[$image]; $meta = $row["meta"]; #-- height, width $x = $x0 = $meta["width"]; $y = $y0 = $meta["height"]; if (!($x && $y)) { $x = $mwidth; $y = (int) ($mwidth * $mscale); } $r = 1; if ($y > $mwidth * $mscale) { $r = $mwidth * $mscale / $y; } if ($r > $mwidth / $x) { $r = $mwidth / $x; } $x = (int) ($x * $r); $y = (int) ($y * $r); #-- get image references $ref = array(); foreach ($page_refs as $pageid => $pageref) { if (strstr($pageref, $image)) { if (EWIKI_PROTECTED_MODE && EWIKI_PROTECTED_MODE_HIDING && !ewiki_auth($pageid, $str_null, "view")) { continue; } $ref[] = '<a href=?page=' . $pageid . '>' . $pageid . '</a>'; } if (count($ref) >= 5) { break; } } $ref = implode(", ", $ref); #-- table lines $n % $num_per_row == 0 && ($o .= "<tr>\n"); #-- print a/img tag $o .= '<td class="lighter" align="center">' . '<a href="' . ewiki_script_binary("", $image) . '">' . '<img src="' . ewiki_script_binary("", $image) . '" alt="' . $image . '" border="0"' . ($x && $y ? ' width="' . $x . '" height="' . $y . '"' : '') . ' />' . str_replace('/', '/ ', urldecode($meta["Content-Location"])) . '</a><br />' . ($x0 && $y0 ? "{$x0}x{$y0}<br />" : "") . $ref . '<div class="action-links">' . ewiki_control_links_list($image, $uuu, $ewiki_config["action_links"]["gallery"]) . "</div>\n" . "</td>\n"; #-- table lines $n++; $n % $num_per_row == 0 && ($o .= "</tr>\n"); } #-- empty table cells if ($n % $num_per_row) { while ($n % $num_per_row && $n++) { $o .= "<td class=\"lighter\"> </td>\n"; } $o .= "</tr>\n"; } $o .= "</table>\n"; return $o; }
} } } echo '<form action="t_remove.php" method="POST" enctype="multipart/form-data">'; echo '<input type="submit" name="listall" value="listall">'; echo '<table class="list" border="0" cellspacing="3" cellpadding="2" width="500">' . "\n"; echo "<tr><th>page name</th><th>error / reason</th></tr>\n"; foreach ($selected as $id => $reason) { echo '<tr><td>'; #-- checkbox echo '<input type="checkbox" value="1" name="remove[' . rawurlencode($id) . ']"> '; #-- link & id if (strpos($id, EWIKI_IDF_INTERNAL) === false) { echo '<a href="' . ewiki_script("", $id) . '">'; } else { echo '<a href="' . ewiki_script_binary("", $id) . '">'; } echo htmlentities($id) . '</a></td>'; #-- print reason echo '<td>' . $reason . "</td>"; echo "</tr>\n"; } echo '</table><br><input type="submit" value=" delete selected pages "></form>'; } else { echo "<ul>\n"; foreach ($_REQUEST["remove"] as $id => $uu) { $id = rawurldecode($id); echo "<li>purging »" . htmlentities($id) . "«...</li>"; $data = ewiki_db::GET($id); for ($version = 1; $version <= $data["version"]; $version++) { ewiki_db::delete($id, $version);
function wikiapi_listLinks($id, $ver = NULL) { global $ewiki_config; $iw =& $ewiki_config["interwiki"]; $data = ewiki_db::GET($id, $ver); if ($data) { $r = array(); $refs = explode("\n", trim($data["refs"])); foreach ($refs as $link) { #-- interwiki if (($m = strtok($link, ":")) && ($p = strtok(""))) { if ($url = ewiki_array($iw, $m)) { while (($uu = ewiki_array($iw, $url)) !== NULL) { $url = $uu; } $link = $url . $p; } } #-- absolute URLs if (strpos($link, "://")) { if (strpos($link, EWIKI_IDF_INTERNAL) === 0) { $link = ewiki_script_binary("", $link); # BAD NEWS: we can't get absolute URLs for # internal:// image links } $r[] = array("page" => $link, "type" => "external", "href" => $href); } else { $r[] = array("page" => $link, "type" => "local", "href" => ewiki_script("", $link)); } } return $r; } }
function ewiki_page_edit_form_final_imgupload(&$o, &$id, &$data, &$action) { if (EWIKI_SCRIPT_BINARY && EWIKI_UP_UPLOAD && EWIKI_IMAGE_MAXSIZE) { $o .= "\n<br />\n" . '<div class="image-upload">' . '<form action=' . '"' . ewiki_script_binary("", EWIKI_IDF_INTERNAL, "", "_UPLOAD=1") . '"' . ' method="post" enctype="multipart/form-data" target="_upload">' . '<fieldset class="invisiblefieldset">' . '<input type="hidden" name="MAX_FILE_SIZE" value="' . EWIKI_IMAGE_MAXSIZE . '" />' . '<input type="file" name="' . EWIKI_UP_UPLOAD . '"' . (defined("EWIKI_IMAGE_ACCEPT") ? ' accept="' . EWIKI_IMAGE_ACCEPT . '" />' : " />") . '<input type="hidden" name="' . EWIKI_UP_BINARY . '" value="' . EWIKI_IDF_INTERNAL . '" />' . ' ' . '<input type="submit" value="' . ewiki_t("UPLOAD_PICTURE_BUTTON") . '" />' . '</fieldset></form></div>' . "\n"; } }