Esempio n. 1
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (!$url && !$file) {
         return $this->error(_("Both 'url' or 'file' parameters missing."));
     } elseif ($url && $file) {
         return $this->error(_("Choose only one of 'url' or 'file' parameters."));
     } elseif ($file) {
         // $url = SERVER_URL . getUploadDataPath() . '/' . $file;
         $url = getUploadDataPath() . '/' . $file;
     }
     if (string_ends_with($url, ".ogg")) {
         return HTML::video(array('autoplay' => 'true', 'controls' => 'true', 'src' => $url), _("Your browser does not understand the HTML 5 video tag."));
     }
     $html = HTML();
     if (isBrowserIE()) {
         $object = HTML::object(array('id' => 'flowplayer', 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', 'width' => $width, 'height' => $height));
         $param = HTML::param(array('name' => 'movie', 'value' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf')));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowfullscreen", 'value' => "true"));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowscriptaccess", 'value' => "false"));
         $object->pushContent($param);
         $flashvars = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
         $param = HTML::param(array('name' => 'flashvars', 'value' => $flashvars));
         $object->pushContent($param);
         $embed = HTML::embed(array('type' => 'application/x-shockwave-flash', 'width' => $width, 'height' => $height, 'src' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'), 'flashvars' => $flashvars));
         $object->pushContent($embed);
         $html->pushContent($object);
     } else {
         $object = HTML::object(array('data' => SERVER_URL . $WikiTheme->_findData('flowplayer-3.2.4.swf'), 'type' => "application/x-shockwave-flash", 'width' => $width, 'height' => $height));
         $param = HTML::param(array('name' => "allowfullscreen", 'value' => "true"));
         $object->pushContent($param);
         $param = HTML::param(array('name' => "allowscriptaccess", 'value' => "false"));
         $object->pushContent($param);
         $value = "config={'clip':{'url':'" . $url . "','autoPlay':" . $autoplay . "}}";
         $param = HTML::param(array('name' => "flashvars", 'value' => $value));
         $object->pushContent($param);
         $html->pushContent($object);
     }
     return $html;
 }
Esempio n. 2
0
 function _parseMap($text)
 {
     if (!preg_match_all("/^\\s*(\\S+)\\s+(.+)\$/m", $text, $matches, PREG_SET_ORDER)) {
         return false;
     }
     foreach ($matches as $m) {
         $map[$m[1]] = $m[2];
     }
     // Add virtual monikers Upload: Talk: User:
     // and expand special variables %u, %b, %d
     // Upload: Should be expanded later to user-specific upload dirs.
     // In the Upload plugin, not here: Upload:ReiniUrban/uploaded-file.png
     if (empty($map['Upload'])) {
         $map['Upload'] = getUploadDataPath();
     }
     // User:ReiniUrban => ReiniUrban or Users/ReiniUrban
     // Can be easily overriden by a customized InterWikiMap:
     //   User Users/%s
     if (empty($map["User"])) {
         $map["User"] = "******";
     }
     // Talk:PageName => PageName/Discussion as default, which might be overridden
     if (empty($map["Talk"])) {
         $pagename = $GLOBALS['request']->getArg('pagename');
         // against PageName/Discussion/Discussion
         if (string_ends_with($pagename, SUBPAGE_SEPARATOR . _("Discussion"))) {
             $map["Talk"] = "%s";
         } else {
             $map["Talk"] = "%s" . SUBPAGE_SEPARATOR . _("Discussion");
         }
     }
     foreach (array('Upload', 'User', 'Talk') as $special) {
         // Expand special variables:
         //   %u => username
         //   %b => wikibaseurl
         //   %d => iso8601 DateTime
         // %s is expanded later to the pagename
         if (strstr($map[$special], '%u')) {
             $map[$special] = str_replace($map[$special], '%u', $GLOBALS['request']->_user->_userid);
         }
         if (strstr($map[$special], '%b')) {
             $map[$special] = str_replace($map[$special], '%b', PHPWIKI_BASE_URL);
         }
         if (strstr($map[$special], '%d')) {
             $map[$special] = str_replace($map[$special], '%d', Iso8601DateTime());
         }
     }
     // Maybe add other monikers also - SemanticWeb link predicates
     // Should they be defined in a RDF? (strict mode)
     // Or should the SemanticWeb lib add it by itself?
     // (adding only a subset dependent on the context = model)
     return $map;
 }
Esempio n. 3
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     if (!$file) {
         return $this->error(sprintf(_("A required argument '%s' is missing."), 'file'));
     }
     if (!$display) {
         return $this->error(sprintf(_("A required argument '%s' is missing."), 'display'));
     }
     $dir = getcwd();
     chdir(PHPWIKI_DIR);
     // sanify $file name
     if (!file_exists($file)) {
         trigger_error("file \"{$file}\" not found", E_USER_WARNING);
     }
     $realfile = realpath($file);
     if (!string_starts_with($realfile, realpath(getUploadDataPath()))) {
         return $this->error("invalid path \"{$file}\"");
     } else {
         $isuploaded = 1;
     }
     $s = array();
     $modes = explode(",", $display);
     foreach ($modes as $mode) {
         switch ($mode) {
             case 'version':
                 $s[] = $this->exeversion($file);
                 break;
             case 'size':
                 $s[] = filesize($file);
                 break;
             case 'phonysize':
                 $s[] = $this->phonysize(filesize($file));
                 break;
             case 'date':
                 $s[] = strftime("%x %X", filemtime($file));
                 break;
             case 'mtime':
                 $s[] = filemtime($file);
                 break;
             case 'name':
                 $s[] = basename($file);
                 break;
             case 'path':
                 $s[] = $file;
                 break;
             case 'dirname':
                 $s[] = dirname($file);
                 break;
             case 'magic':
                 $s[] = $this->magic($file);
                 break;
             case 'mime-typ':
                 $s[] = $this->mime_type($file);
                 break;
             case 'link':
                 if ($isuploaded) {
                     $s[] = "[Upload:" . basename($file) . "]";
                 } else {
                     $s[] = "[" . basename($file) . "]";
                 }
                 break;
             default:
                 return $this->error(sprintf(_("Unsupported argument: %s=%s"), 'display', $mode));
                 break;
         }
     }
     chdir($dir);
     if (!$format) {
         $format = '';
         foreach ($s as $x) {
             $format .= " %s";
         }
     }
     array_unshift($s, $format);
     // $x, array($i,$j) => sprintf($x, $i, $j)
     $result = call_user_func_array("sprintf", $s);
     if (in_array('link', $modes)) {
         require_once "lib/InlineParser.php";
         return TransformInline($result);
     } else {
         return $result;
     }
 }
Esempio n. 4
0
 function markup($match)
 {
     $page = substr($match, 2, -2);
     // Check for predefined icons.
     $predefinedicons = array(":)" => "ic_smile.png", ":(" => "ic_sad.png", ":P" => "ic_tongue.png", ":D" => "ic_biggrin.png", ";)" => "ic_wink.png", "(y)" => "ic_handyes.png", "(n)" => "ic_handno.png", "(i)" => "ic_info.png", "(/)" => "ic_check.png", "(x)" => "ic_cross.png", "(!)" => "ic_danger.png", "(+)" => "ic_plus.png", "(-)" => "ic_minus.png", "(?)" => "ic_help.png", "(on)" => "ic_lighton.png", "(off)" => "ic_lightoff.png", "(*)" => "ic_yellowstar.png", "(*r)" => "ic_redstar.png", "(*g)" => "ic_greenstar.png", "(*b)" => "ic_bluestar.png", "(*y)" => "ic_yellowstar.png");
     foreach ($predefinedicons as $ascii => $icon) {
         if (trim($page) == $ascii) {
             return LinkImage(DATA_PATH . "/themes/default/images/{$icon}", $page);
         }
     }
     if (strpos($page, "|") === false) {
         $imagename = $page;
         $alt = "";
     } else {
         $imagename = substr($page, 0, strpos($page, "|"));
         $alt = ltrim(strstr($page, "|"), "|");
     }
     // It's not a Mediawiki template, it's a Wikicreole image
     if (is_image($imagename)) {
         if ($imagename[0] == '/') {
             return LinkImage(DATA_PATH . '/' . $imagename, $alt);
         } else {
             return LinkImage(getUploadDataPath() . $imagename, $alt);
         }
     }
     // It's a video
     if (is_video($imagename)) {
         $s = '<' . '?plugin Video file="' . $imagename . '" ?' . '>';
         return new Cached_PluginInvocation($s);
     }
     $page = str_replace("\n", "", $page);
     $vars = '';
     if (preg_match('/^(\\S+?)\\|(.*)$/', $page, $_m)) {
         $page = $_m[1];
         $vars = '"' . preg_replace('/\\|/', '" "', $_m[2]) . '"';
         $vars = preg_replace('/"(\\S+)=([^"]*)"/', '\\1="\\2"', $vars);
     }
     // page may contain a version number
     // {{foo?version=5}}
     // in that case, output is "page=foo rev=5"
     if (strstr($page, "?")) {
         $page = str_replace("?version=", "\" rev=\"", $page);
     }
     if ($vars) {
         $s = '<' . '?plugin Template page="' . $page . '" ' . $vars . ' ?' . '>';
     } else {
         $s = '<' . '?plugin Template page="' . $page . '" ?' . '>';
     }
     return new Cached_PluginInvocation($s);
 }
Esempio n. 5
0
 function text2png($args)
 {
     extract($args);
     /**
      * Basic image creation and caching
      *
      * You MUST delete the image cache yourself in /images if you
      * change the drawing routines!
      */
     $filename = urlencode($text) . ".png";
     // protect by urlencode!!!
     /**
      * FIXME: need something more elegant, and a way to gettext a
      *        different language depending on any individual
      *        user's locale preferences.
      */
     if ($l == "C") {
         $l = "en";
         //english=C
     } else {
         $l = urlencode($l);
         // who on earth forgot his?
     }
     $basedir = "text2png-image";
     $filepath = getUploadFilePath() . "{$basedir}/{$l}";
     if ($_force or !file_exists($filepath . $filename)) {
         if (!file_exists($filepath)) {
             $oldumask = umask(0);
             // permissions affected by user the www server is running as
             mkdir(getUploadFilePath() . $basedir, 0777);
             mkdir($filepath, 0777);
             umask($oldumask);
         }
         $filepath .= "/";
         /**
          * prepare a new image
          *
          * FIXME: needs a dynamic image size depending on text
          *        width and height
          */
         // got this logic from GraphViz
         if (defined('TTFONT')) {
             $ttfont = TTFONT;
         } elseif (PHP_OS == "Darwin") {
             // Mac OS X
             $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
         } elseif (isWindows()) {
             $ttfont = $_ENV['windir'] . '\\Fonts\\Arial.ttf';
         } else {
             $ttfont = 'luximr';
             // This is the only what sourceforge offered.
             //$ttfont = 'Helvetica';
         }
         /* http://download.php.net/manual/en/function.imagettftext.php
          * array imagettftext (int im, int size, int angle, int x, int y,
          *                      int col, string fontfile, string text)
          */
         // get ready to draw
         $s = ImageTTFBBox($fontsize, 0, $ttfont, $text);
         $im = @ImageCreate(abs($s[4]) + 20, abs($s[7]) + 10);
         if (empty($im)) {
             $error_html = _("PHP was unable to create a new GD image stream. Read 'lib/plugin/text2png.php' for details.");
             // FIXME: Error manager does not transform URLs passed
             //        through it.
             $link = "http://www.php.net/manual/en/function.imagecreate.php";
             $error_html .= sprintf(_("See %s"), $link) . ".";
             trigger_error($error_html, E_USER_NOTICE);
             return;
         }
         $rgb = $this->hexcolor($backcolor, array(255, 255, 255));
         $bg_color = ImageColorAllocate($im, $rgb[0], $rgb[1], $rgb[2]);
         if ($with_shadow) {
             $rgb = $this->hexcolor($shadowcolor, array(175, 175, 175));
             $text_color = ImageColorAllocate($im, $rgb[0], $rgb[1], $rgb[2]);
             // shadow is 1 pixel down and 2 pixels right
             ImageTTFText($im, $fontsize, 0, 12, abs($s[7]) + 6, $text_color, $ttfont, $text);
         }
         // draw text
         $rgb = $this->hexcolor($fontcolor, array(0, 0, 0));
         $text_color = ImageColorAllocate($im, $rgb[0], $rgb[1], $rgb[2]);
         ImageTTFText($im, $fontsize, 0, 10, abs($s[7]) + 5, $text_color, $ttfont, $text);
         /**
          * An alternate text drawing method in case ImageTTFText
          * doesn't work.
          **/
         //ImageString($im, 2, 10, 40, $text, $text_color);
         // To dump directly to browser:
         //header("Content-type: image/png");
         //ImagePng($im);
         // to save to file:
         $success = ImagePng($im, $filepath . $filename);
     } else {
         $filepath .= "/";
         $success = 2;
     }
     // create an <img src= tag to show the image!
     $html = HTML();
     if ($success > 0) {
         if (defined('text2png_debug')) {
             switch ($success) {
                 case 1:
                     trigger_error(sprintf(_("Image saved to cache file: %s"), $filepath . $filename), E_USER_NOTICE);
                 case 2:
                     trigger_error(sprintf(_("Image loaded from cache file: %s"), $filepath . $filename), E_USER_NOTICE);
             }
         }
         $url = getUploadDataPath() . "{$basedir}/" . urlencode($l) . "/" . urlencode($filename);
         $html->pushContent(HTML::img(array('src' => $url, 'alt' => $text, 'title' => '"' . $text . '"' . _(" produced by ") . $this->getName())));
     } else {
         trigger_error(sprintf(_("couldn't open file '%s' for writing"), $filepath . $filename), E_USER_NOTICE);
     }
     return $html;
 }
Esempio n. 6
0
/**
 * Inline Images
 *
 * Syntax: [image.png size=50% border=n align= hspace= vspace= width= height=]
 * Disallows sizes which are too small.
 * Spammers may use such (typically invisible) image attributes to raise their GoogleRank.
 *
 * Handle embeddable objects, like svg, class, vrml, swf, svgz, pdf, avi, wmv especially.
 */
function LinkImage($url, $alt = "")
{
    $force_img = "png|jpg|gif|jpeg|bmp|pl|cgi";
    // Disallow tags in img src urls. Typical CSS attacks.
    // FIXME: Is this needed (or sufficient?)
    // FIXED: This was broken for moniker:TP30 test/image.png => url="moniker:TP30" attr="test/image.png"
    $ori_url = $url;
    // support new syntax: [prefix/image.jpg size=50% border=n]
    if (empty($alt)) {
        $alt = "";
    }
    // Extract URL
    $arr = explode(' ', $url);
    if (!empty($arr)) {
        $url = $arr[0];
    }
    if (!IsSafeURL($url)) {
        $link = HTML::span(array('class' => 'error'), _("BAD URL -- remove all of <, >, \""));
        return $link;
    }
    // spaces in inline images must be %20 encoded!
    $link = HTML::img(array('src' => $url));
    // Extract attributes
    $arr = parse_attributes(strstr($ori_url, " "));
    foreach ($arr as $attr => $value) {
        // These attributes take strings: lang, id, title, alt
        if ($attr == "lang" || $attr == "id" || $attr == "title" || $attr == "alt") {
            $link->setAttr($attr, $value);
        } elseif ($attr == "align" && ($value == "bottom" || $value == "middle" || $value == "top" || $value == "left" || $value == "right")) {
            $link->setAttr($attr, $value);
        } elseif (($attr == "border" || $attr == "hspace" || $attr == "vspace") && is_numeric($value)) {
            $link->setAttr($attr, (int) $value);
        } elseif (($attr == "height" || $attr == "width") && preg_match('/\\d+[%p]?x?/', $value)) {
            $link->setAttr($attr, $value);
        } elseif ($attr == "size") {
            if (preg_match('/(\\d+%)/', $value, $m)) {
                $link->setAttr('width', $m[1]);
                $link->setAttr('height', $m[1]);
            } elseif (preg_match('/(\\d+)x(\\d+)/', $value, $m)) {
                $link->setAttr('width', $m[1]);
                $link->setAttr('height', $m[2]);
            }
        } else {
            $link = HTML::span(array('class' => 'error'), sprintf(_("Invalid image attribute \"%s\" %s=%s"), $url, $attr, $value));
            return $link;
        }
    }
    // Correct silently the most common error
    if ($url != $ori_url and empty($arr) and !preg_match("/^http/", $url)) {
        // space belongs to the path
        $file = NormalizeLocalFileName($ori_url);
        if (file_exists($file)) {
            $link = HTML::img(array('src' => $ori_url));
            trigger_error(sprintf(_("Invalid image link fixed %s => %s. Spaces must be quoted with %%20."), $url, $ori_url), E_USER_WARNING);
        } elseif (string_starts_with($ori_url, getUploadDataPath())) {
            $file = substr($file, strlen(getUploadDataPath()));
            $path = getUploadFilePath() . $file;
            if (file_exists($path)) {
                trigger_error(sprintf(_("Invalid image link fixed \"%s\" => \"%s\".\n Spaces must be quoted with %%20."), $url, $ori_url), E_USER_WARNING);
                $link->setAttr('src', getUploadDataPath() . $file);
                $url = $ori_url;
            }
        }
    }
    if (!$link->getAttr('alt')) {
        $link->setAttr('alt', $alt);
    }
    // Check width and height as spam countermeasure
    if ($width = $link->getAttr('width') and $height = $link->getAttr('height')) {
        //$width  = (int) $width; // px or % or other suffix
        //$height = (int) $height;
        if ($width < 3 and $height < 10 or $height < 3 and $width < 20 or $height < 7 and $width < 7) {
            $link = HTML::span(array('class' => 'error'), _("Invalid image size"));
            return $link;
        }
    } else {
        $size = 0;
        // Prepare for getimagesize($url)
        // $url only valid for external urls, otherwise local path
        if (DISABLE_GETIMAGESIZE) {
        } elseif (!preg_match("/\\.{$force_img}\$/i", $url)) {
        } elseif (preg_match("/^http/", $url)) {
            // external url
            $size = @getimagesize($url);
        } else {
            // local file
            if (file_exists($file = NormalizeLocalFileName($url))) {
                // here
                $size = @getimagesize($file);
            } elseif (file_exists(NormalizeLocalFileName(urldecode($url)))) {
                $size = @getimagesize($file);
                $link->setAttr('src', rawurldecode($url));
            } elseif (string_starts_with($url, getUploadDataPath())) {
                // there
                $file = substr($file, strlen(getUploadDataPath()));
                $path = getUploadFilePath() . rawurldecode($file);
                $size = @getimagesize($path);
                $link->setAttr('src', getUploadDataPath() . rawurldecode($file));
            } else {
                // elsewhere
                global $request;
                $size = @getimagesize($request->get('DOCUMENT_ROOT') . urldecode($url));
            }
        }
        if ($size) {
            $width = $size[0];
            $height = $size[1];
            if ($width < 3 and $height < 10 or $height < 3 and $width < 20 or $height < 7 and $width < 7) {
                $link = HTML::span(array('class' => 'error'), _("Invalid image size"));
                return $link;
            }
        }
    }
    $link->setAttr('class', 'inlineimage');
    /* Check for inlined objects. Everything allowed in INLINE_IMAGES besides
     * png|jpg|gif|jpeg|bmp|pl|cgi.  If no image it is an object to embed.
     * Note: Allow cgi's (pl,cgi) returning images.
     */
    if (!preg_match("/\\.(" . $force_img . ")/i", $url)) {
        // HTML::img(array('src' => $url, 'alt' => $alt, 'title' => $alt));
        // => HTML::object(array('src' => $url)) ...;
        return ImgObject($link, $ori_url);
    }
    return $link;
}
Esempio n. 7
0
 /**
  * static workaround on broken Cache or broken dot executable,
  * called only if debug=static.
  *
  * @access private
  * @param  url      string  url pointing to the image part of the map
  * @param  map      string  &lt;area&gt; tags defining active
  *                          regions in the map
  * @param  dbi      WikiDB  database abstraction class
  * @param  argarray array   complete (!) arguments to produce
  *                          image. It is not necessary to call
  *                          WikiPlugin->getArgs anymore.
  * @param  request  Request ???
  * @return          string  html output
  */
 function embedImg($url, &$dbi, $argarray, &$request)
 {
     if (!VISUALWIKI_ALLOWOPTIONS) {
         $argarray = $this->defaultarguments();
     }
     $this->checkArguments($argarray);
     //extract($argarray);
     if ($argarray['help']) {
         return array($this->helpImage(), ' ');
     }
     // FIXME
     $this->createColors();
     $this->extract_wikipages($dbi, $argarray);
     list($imagehandle, $content['html']) = $this->invokeDot($argarray);
     // write to uploads and produce static url
     $file_dir = getUploadFilePath();
     $upload_dir = getUploadDataPath();
     $tmpfile = tempnam($file_dir, "VisualWiki") . "." . $argarray['imgtype'];
     WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);
     ImageDestroy($imagehandle);
     return WikiPluginCached::embedMap(1, $upload_dir . basename($tmpfile), $content['html'], $dbi, $argarray, $request);
 }
Esempio n. 8
0
function _DumpHtmlToDir($target, $page_iter, $exclude = false)
{
    global $WikiTheme, $request, $ErrorManager;
    $silent = true;
    $zip = false;
    $directory = false;
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $directory = $target;
        $silent = false;
    } elseif ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        $directory = $target;
    } elseif (is_object($target)) {
        // $WikiTheme->DUMP_MODE == 'ZIPHTML'
        $zip = $target;
    }
    $request->_TemplatesProcessed = array();
    if ($exclude) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array('DebugAuthInfo', 'DebugGroupInfo', 'AuthInfo');
    }
    $WikiTheme->VALID_LINKS = array();
    if ($request->getArg('format')) {
        // pagelist
        $page_iter_sav = $page_iter;
        foreach ($page_iter_sav->asArray() as $handle) {
            $WikiTheme->VALID_LINKS[] = is_string($handle) ? $handle : $handle->getName();
        }
        $page_iter_sav->reset();
    }
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
    // check if the dumped file will be accessible from outside
    $doc_root = $request->get("DOCUMENT_ROOT");
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $ldir = NormalizeLocalFileName($directory);
        $wikiroot = NormalizeLocalFileName('');
        if (string_starts_with($ldir, $doc_root)) {
            $link_prefix = substr($directory, strlen($doc_root)) . "/";
        } elseif (string_starts_with($ldir, $wikiroot)) {
            $link_prefix = NormalizeWebFileName(substr($directory, strlen($wikiroot))) . "/";
        } else {
            $prefix = '';
            if (isWindows()) {
                $prefix = '/';
                // . substr($doc_root,0,2); // add drive where apache is installed
            }
            $link_prefix = "file://" . $prefix . $directory . "/";
        }
    } else {
        $link_prefix = "";
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 60 : 240;
    if ($directory) {
        if (isWindows()) {
            $directory = str_replace("\\", "/", $directory);
        }
        // no Win95 support.
        @mkdir("{$directory}/images");
    }
    $already = array();
    $outfiles = array();
    $already_images = array();
    while ($page = $page_iter->next()) {
        if (is_string($page)) {
            $pagename = $page;
            $page = $request->_dbi->getPage($pagename);
        } else {
            $pagename = $page->getName();
        }
        if (empty($firstpage)) {
            $firstpage = $pagename;
        }
        if (array_key_exists($pagename, $already)) {
            continue;
        }
        $already[$pagename] = 1;
        $current = $page->getCurrentRevision();
        //if ($current->getVersion() == 0)
        //    continue;
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        if ($zip) {
            $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1);
            if ($page->get('locked')) {
                $attrib['write_protected'] = 1;
            }
        } elseif (!$silent) {
            if (!isa($request, 'MockRequest')) {
                PrintXML(HTML::br(), $pagename, ' ... ');
                flush();
            }
        }
        if (in_array($pagename, $excludeList)) {
            if (!$silent and !isa($request, 'MockRequest')) {
                PrintXML(_("Skipped."));
                flush();
            }
            continue;
        }
        $relative_base = '';
        if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
            $request->setArg('action', 'pdf');
        }
        // to omit cache headers
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $args = array('revision' => $current, 'CONTENT' => $current->getTransformedContent(), 'relative_base' => $relative_base);
        // For every %2F will need to mkdir -p dirname($pagename)
        if (preg_match("/(%2F|\\/)/", $filename)) {
            // mkdir -p and set relative base for subdir pages
            $filename = preg_replace("/%2F/", "/", $filename);
            $count = substr_count($filename, "/");
            $dirname = dirname($filename);
            if ($directory) {
                mkdir_p($directory . "/" . $dirname);
            }
            // Fails with "XX / YY", "XX" is created, "XX / YY" cannot be written
            // if (isWindows()) // interesting Windows bug: cannot mkdir "bla "
            // Since dumps needs to be copied, we have to disallow this for all platforms.
            $filename = preg_replace("/ \\//", "/", $filename);
            $relative_base = "../";
            while ($count > 1) {
                $relative_base .= "../";
                $count--;
            }
            $args['relative_base'] = $relative_base;
        }
        $msg = HTML();
        $DUMP_MODE = $WikiTheme->DUMP_MODE;
        $data = GeneratePageasXML(new Template('browse', $request, $args), $pagename, $current, $args);
        $WikiTheme->DUMP_MODE = $DUMP_MODE;
        if (preg_match_all("/<img .*?src=\"(\\/.+?)\"/", $data, $m)) {
            // fix to local relative path for uploaded images, so that pdf will work
            foreach ($m[1] as $img_file) {
                $base = basename($img_file);
                $data = str_replace('src="' . $img_file . '"', 'src="images/' . $base . '"', $data);
                if (array_key_exists($img_file, $already_images)) {
                    continue;
                }
                $already_images[$img_file] = 1;
                // resolve src from webdata to file
                $src = $doc_root . $img_file;
                if (file_exists($src) and $base) {
                    if ($directory) {
                        $target = "{$directory}/images/{$base}";
                        if (copy($src, $target)) {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... copied to %s", $target));
                            }
                        } else {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... not copied to %s", $target));
                            }
                        }
                    } else {
                        $target = "images/{$base}";
                        $zip->addSrcFile($target, $src);
                    }
                }
            }
        }
        if ($directory) {
            $outfile = $directory . "/" . $filename;
            if (!($fd = fopen($outfile, "wb"))) {
                $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", $outfile)));
                $request->finish($msg);
            }
            $len = strlen($data);
            $num = fwrite($fd, $data, $len);
            if ($pagename != $filename) {
                $link = LinkURL($link_prefix . $filename, $filename);
                $msg->pushContent(HTML::small(_("saved as "), $link, " ... "));
            }
            $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n"));
            if (!$silent) {
                if (!isa($request, 'MockRequest')) {
                    PrintXML($msg);
                }
                flush();
                $request->chunkOutput();
            }
            assert($num == $len);
            fclose($fd);
            $outfiles[] = $outfile;
        } else {
            $zip->addRegularFile($filename, $data, $attrib);
        }
        if (USECACHE) {
            $request->_dbi->_cache->invalidate_cache($pagename);
            unset($request->_dbi->_cache->_pagedata_cache);
            unset($request->_dbi->_cache->_versiondata_cache);
            unset($request->_dbi->_cache->_glv_cache);
        }
        unset($request->_dbi->_cache->_backend->_page_data);
        unset($msg);
        unset($current->_transformedContent);
        unset($current);
        if (!empty($template)) {
            unset($template->_request);
            unset($template);
        }
        unset($data);
    }
    $page_iter->free();
    $attrib = false;
    //array('is_ascii' => 0);
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        // @mkdir("$directory/images");
        foreach ($WikiTheme->dumped_images as $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        // Buttons also
        if ($directory) {
            @mkdir("{$directory}/images/buttons");
        }
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/buttons/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/buttons/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if (array_key_exists($css_file, $already_images)) {
                continue;
            }
            $already_images[$css_file] = 1;
            if ($css_file and $from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                // TODO: fix @import url(main.css);
                if ($directory) {
                    $target = "{$directory}/" . basename($css_file);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    //$attrib = array('is_ascii' => 0);
                    $target = basename($css_file);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if ($zip) {
        $zip->finish();
    }
    if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        if (USE_EXTERNAL_HTML2PDF and $outfiles) {
            $cmd = EXTERNAL_HTML2PDF_PAGELIST . ' "' . join('" "', $outfiles) . '"';
            $filename = FilenameForPage($firstpage);
            if (DEBUG) {
                $tmpfile = $directory . "/createpdf.bat";
                $fp = fopen($tmpfile, "wb");
                fwrite($fp, $cmd . " > {$filename}.pdf");
                fclose($fp);
            }
            if (!headers_sent()) {
                Header('Content-Type: application/pdf');
                passthru($cmd);
            } else {
                $tmpdir = getUploadFilePath();
                $s = passthru($cmd . " > {$tmpdir}/{$filename}.pdf");
                $errormsg = "<br />\nGenerated <a href=\"" . getUploadDataPath() . "{$filename}.pdf\">Upload:{$filename}.pdf</a>\n";
                $errormsg .= $s;
                echo $errormsg;
            }
            if (!DEBUG) {
                foreach ($outfiles as $f) {
                    unlink($f);
                }
            }
        }
        if (!empty($errormsg)) {
            $request->discardOutput();
            $GLOBALS['ErrorManager']->_postponed_errors = array();
        }
    }
    $ErrorManager->popErrorHandler();
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
}
Esempio n. 9
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->disallowed_extensions = explode("\n", "ad[ep]\nasd\nba[st]\nchm\ncmd\ncom\ncgi\ncpl\ncrt\ndll\neml\nexe\nhlp\nhta\nin[fs]\nisp\njse?\nlnk\nmd[betw]\nms[cipt]\nnws\nocx\nops\npcd\np[ir]f\nphp\npl\npy\nreg\nsc[frt]\nsh[bsm]?\nswf\nurl\nvb[esx]?\nvxd\nws[cfh]");
     //removed "\{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}"
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $file_dir = getUploadFilePath();
     //$url_prefix = SERVER_NAME . DATA_PATH;
     $form = HTML::form(array('action' => $request->getPostURL(), 'enctype' => 'multipart/form-data', 'method' => 'post'));
     $contents = HTML::div(array('class' => 'wikiaction'));
     $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => MAX_UPLOAD_SIZE)));
     /// MV add pv
     /// @todo: have a generic method to transmit pv
     if (!empty($_REQUEST['pv'])) {
         $contents->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'pv', 'value' => $_REQUEST['pv'])));
     }
     $contents->pushContent(HTML::input(array('name' => 'userfile', 'type' => 'file', 'size' => '50')));
     $contents->pushContent(HTML::raw(" "));
     $contents->pushContent(HTML::input(array('value' => _("Upload"), 'type' => 'submit')));
     $form->pushContent($contents);
     $message = HTML();
     if ($request->isPost() and $this->only_authenticated) {
         // Make sure that the user is logged in.
         $user = $request->getUser();
         if (!$user->isAuthenticated()) {
             $message->pushContent(HTML::h2(_("ACCESS DENIED: You must log in to upload files.")), HTML::br(), HTML::br());
             $result = HTML();
             $result->pushContent($form);
             $result->pushContent($message);
             return $result;
         }
     }
     $userfile = $request->getUploadedFile('userfile');
     if ($userfile) {
         $userfile_name = $userfile->getName();
         $userfile_name = trim(basename($userfile_name));
         $userfile_tmpname = $userfile->getTmpName();
         $err_header = HTML::h2(fmt("ERROR uploading '%s': ", $userfile_name));
         /// MV add
         /// Wiki attachments
         $wa = new WikiAttachment(GROUP_ID);
         $rev = $wa->createRevision($userfile_name, $userfile->getSize(), $userfile->getType(), $userfile->getTmpName());
         if ($rev >= 0) {
             $prev = $rev + 1;
             $interwiki = new PageType_interwikimap();
             $link = $interwiki->link("Upload:{$prev}/{$userfile_name}");
             $message->pushContent(HTML::h2(_("File successfully uploaded.")));
             $message->pushContent(HTML::ul(HTML::li($link)));
             // the upload was a success and we need to mark this event in the "upload log"
             if ($logfile) {
                 $upload_log = $file_dir . basename($logfile);
                 $this->log($userfile, $upload_log, $message);
             }
             if ($autolink) {
                 require_once "lib/loadsave.php";
                 $pagehandle = $dbi->getPage($page);
                 if ($pagehandle->exists()) {
                     // don't replace default contents
                     $current = $pagehandle->getCurrentRevision();
                     $version = $current->getVersion();
                     $text = $current->getPackedContent();
                     $newtext = $text . "\n* [Upload:{$userfile_name}]";
                     $meta = $current->_data;
                     $meta['summary'] = sprintf(_("uploaded %s"), $userfile_name);
                     $pagehandle->save($newtext, $version + 1, $meta);
                 }
             }
         } else {
             $message->pushContent($err_header);
             $message->pushContent(HTML::br(), _("Uploading failed."), HTML::br());
         }
     } else {
         $message->pushContent(HTML::br(), HTML::br());
     }
     /// {{{ Codendi Specific
     // URL arguments
     if (array_key_exists('offset', $_REQUEST)) {
         $offset = $_REQUEST['offset'];
     } else {
         $offset = 0;
     }
     if (array_key_exists('limit', $_REQUEST)) {
         $limit = $_REQUEST['limit'];
     } else {
         $limit = 10;
     }
     $attchTab = HTML::table(array('border' => '1', 'width' => '100%'));
     $attchTab->pushContent(HTML::tr(HTML::th(_("Attachment")), HTML::th(_("Number of revision"))));
     $wai =& WikiAttachment::getListWithCounter(GROUP_ID, user_getid(), array('offset' => $offset, 'nb' => $limit));
     $wai->rewind();
     while ($wai->valid()) {
         $wa =& $wai->current();
         $filename = basename($wa->getFilename());
         $url = getUploadDataPath() . urlencode($filename);
         $line = HTML::tr();
         $line->pushContent(HTML::td(HTML::a(array('href' => $url), "Attach:" . $filename)));
         $line->pushContent(HTML::td($wa->count()));
         $attchTab->pushContent($line);
         $wai->next();
     }
     $attchList = HTML();
     $attchList->pushContent(HTML::hr(), HTML::h2(_("Attached files")));
     $attchList->pushContent($attchTab);
     $url = WikiURL("UpLoad");
     if (!empty($_REQUEST['pv'])) {
         $url .= '&pv=' . $_REQUEST['pv'];
     }
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset - $limit)), "<- Previous"));
     $attchList->pushContent(" - ");
     $attchList->pushContent(HTML::a(array('href' => $url . '&offset=' . ($offset + $limit)), "Next ->"));
     /// }}}
     //$result = HTML::div( array( 'class' => 'wikiaction' ) );
     $result = HTML();
     $result->pushContent($form);
     $result->pushContent($message);
     $result->pushContent($attchList);
     return $result;
 }
Esempio n. 10
0
 function staticUrl($tmpfile)
 {
     $content['file'] = $tmpfile;
     $content['url'] = getUploadDataPath() . basename($tmpfile);
     return $content;
 }
Esempio n. 11
0
 function _match(&$input, $m)
 {
     $pos = $input->getPos();
     $pi = $m->postmatch;
     if ($pi[0] == '{') {
         return false;
     }
     while (!preg_match('/(?<!' . ESCAPE_CHAR . ')}}\\s*$/', $pi)) {
         if (($line = $input->nextLine()) === false) {
             $input->setPos($pos);
             return false;
         }
         $pi .= "\n{$line}";
     }
     $input->advance();
     $pi = trim($pi);
     $pi = trim($pi, "}}");
     if (strpos($pi, "|") === false) {
         $imagename = $pi;
         $alt = "";
     } else {
         $imagename = substr($pi, 0, strpos($pi, "|"));
         $alt = ltrim(strstr($pi, "|"), "|");
     }
     // It's not a Mediawiki template, it's a Wikicreole image
     if (is_image($imagename)) {
         $this->_element = LinkImage(getUploadDataPath() . $imagename, $alt);
         return true;
     }
     // It's a video
     if (is_video($imagename)) {
         $pi = '<' . '?plugin Video file="' . $pi . '" ?>';
         $this->_element = new Cached_PluginInvocation($pi);
         return true;
     }
     $pi = str_replace("\n", "", $pi);
     $vars = '';
     if (preg_match('/^(\\S+?)\\|(.*)$/', $pi, $_m)) {
         $pi = $_m[1];
         $vars = '"' . preg_replace('/\\|/', '" "', $_m[2]) . '"';
         $vars = preg_replace('/"(\\S+)=([^"]*)"/', '\\1="\\2"', $vars);
     }
     // pi may contain a version number
     // {{foo?version=5}}
     // in that case, output is "page=foo rev=5"
     if (strstr($pi, "?")) {
         $pi = str_replace("?version=", "\" rev=\"", $page);
     }
     if ($vars) {
         $pi = '<' . '?plugin Template page="' . $pi . '" ' . $vars . ' ?>';
     } else {
         $pi = '<' . '?plugin Template page="' . $pi . '" ?>';
     }
     $this->_element = new Cached_PluginInvocation($pi);
     return true;
 }
Esempio n. 12
0
 /**
  * fromFile - read pictures & descriptions (separated by ;)
  *            from $src and return it in array $photos
  *
  * @param string $src path to dir or textfile (local or remote)
  * @param array $photos
  * @return string Error when bad url or file couldn't be opened
  */
 function fromFile($src, &$photos, $webpath = '')
 {
     $src_bak = $src;
     if (preg_match("/^Upload:(.*)\$/", $src, $m)) {
         $src = getUploadFilePath() . $m[1];
         $webpath = getUploadDataPath() . $m[1];
     }
     //there has a big security hole... as loading config/config.ini !
     if (!preg_match('/(\\.csv|\\.jpg|\\.jpeg|\\.png|\\.gif|\\/)$/', $src)) {
         return $this->error(_("File extension for csv file has to be '.csv'"));
     }
     if (!IsSafeURL($src)) {
         return $this->error(_("Bad url in src: remove all of <, >, \""));
     }
     if (preg_match('/^(http|ftp|https):\\/\\//i', $src)) {
         $contents = url_get_contents($src);
         $web_location = 1;
     } else {
         $web_location = 0;
         if (string_ends_with($src, "/")) {
             $src = substr($src, 0, -1);
         }
     }
     if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) {
         $src = PHPWIKI_DIR . "/{$src}";
     }
     // check if src is a directory
     if (file_exists($src) and filetype($src) == 'dir') {
         //all images
         $list = array();
         foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
             $fileset = new fileSet($src, "*.{$ext}");
             $list = array_merge($list, $fileset->getFiles());
         }
         // convert dirname($src) (local fs path) to web path
         natcasesort($list);
         if (!$webpath) {
             // assume relative src. default: "themes/Hawaiian/images/pictures"
             $webpath = DATA_PATH . '/' . $src_bak;
         }
         foreach ($list as $file) {
             // convert local path to webpath
             $photos[] = array("src" => $file, "name" => $webpath . "/{$file}", "name_tile" => $src . "/{$file}", "src" => $src . "/{$file}", "desc" => "");
         }
         return;
     }
     // check if $src is an image
     foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
         if (preg_match("/\\.{$ext}\$/", $src)) {
             if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/{$src}")) {
                 $src = PHPWIKI_DIR . "/{$src}";
             }
             if ($web_location == 1 and !empty($contents)) {
                 $photos[] = array("src" => $src, "name" => $src, "name_tile" => $src, "src" => $src, "desc" => "");
                 return;
             }
             if (!file_exists($src)) {
                 return $this->error(fmt("Unable to find src='%s'", $src));
             }
             $photos[] = array("src" => $src, "name" => "../" . $src, "name_tile" => $src, "src" => $src, "desc" => "");
             return;
         }
     }
     if ($web_location == 0) {
         $fp = @fopen($src, "r");
         if (!$fp) {
             return $this->error(fmt("Unable to read src='%s'", $src));
         }
         while ($data = fgetcsv($fp, 1024, ';')) {
             if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) {
                 continue;
             }
             if (empty($data[1])) {
                 $data[1] = '';
             }
             $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "location" => "../" . dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0]));
         }
         fclose($fp);
     } elseif ($web_location == 1) {
         //TODO: check if the file is an image
         $contents = preg_split('/\\n/', $contents);
         while (list($key, $value) = each($contents)) {
             $data = preg_split('/\\;/', $value);
             if (count($data) == 0 || empty($data[0]) || preg_match('/^#/', $data[0]) || preg_match('/^[[:space:]]*$/', $data[0])) {
                 continue;
             }
             if (empty($data[1])) {
                 $data[1] = '';
             }
             $photos[] = array("name" => dirname($src) . "/" . trim($data[0]), "src" => dirname($src) . "/" . trim($data[0]), "desc" => trim($data[1]), "name_tile" => dirname($src) . "/" . trim($data[0]));
         }
     }
 }
Esempio n. 13
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (!$file) {
         return $this->error(sprintf(_("A required argument '%s' is missing."), 'file'));
     }
     if (!$display) {
         return $this->error(sprintf(_("A required argument '%s' is missing."), 'display'));
     }
     if (string_starts_with($file, "Upload:")) {
         $file = preg_replace("/^Upload:(.*)\$/", getUploadFilePath() . "\\1", $file);
         $is_Upload = 1;
     }
     $dir = getcwd();
     if (defined('PHPWIKI_DIR')) {
         chdir(PHPWIKI_DIR);
     }
     if (!file_exists($file)) {
         if ($quiet) {
             return HTML::raw('');
         } else {
             return $this->error(sprintf(_("File '%s' not found."), $file));
         }
     }
     // sanify $file name
     $realfile = realpath($file);
     // Hmm, allow ADMIN to check a local file? Only if its locked
     if (string_starts_with($realfile, realpath(getUploadDataPath()))) {
         $isuploaded = 1;
     } else {
         $page = $dbi->getPage($basepage);
         $user = $request->getUser();
         if ($page->getOwner() != ADMIN_USER or !$page->get('locked')) {
             // For convenience we warn the admin
             if ($quiet and $user->isAdmin()) {
                 return HTML::span(array('title' => _("Output suppressed. FileInfoPlugin with local files require a locked page.")), HTML::em(_("page not locked")));
             } else {
                 return $this->error("Invalid path \"{$file}\". Only ADMIN can allow local paths, and the page must be locked.");
             }
         }
     }
     $s = array();
     $modes = explode(",", $display);
     foreach ($modes as $mode) {
         switch ($mode) {
             case 'version':
                 $s[] = $this->exeversion($file);
                 break;
             case 'size':
                 $s[] = filesize($file);
                 break;
             case 'phonysize':
                 $s[] = $this->phonysize(filesize($file));
                 break;
             case 'date':
                 $s[] = strftime("%x %X", filemtime($file));
                 break;
             case 'mtime':
                 $s[] = filemtime($file);
                 break;
             case 'owner':
                 $o = posix_getpwuid(fileowner($file));
                 $s[] = $o['name'];
                 break;
             case 'group':
                 $o = posix_getgrgid(filegroup($file));
                 $s[] = $o['name'];
                 break;
             case 'name':
                 $s[] = basename($file);
                 break;
             case 'path':
                 $s[] = $file;
                 break;
             case 'dirname':
                 $s[] = dirname($file);
                 break;
             case 'magic':
                 $s[] = $this->magic($file);
                 break;
             case 'mime-typ':
                 $s[] = $this->mime_type($file);
                 break;
             case 'link':
                 if ($is_Upload) {
                     $s[] = " [" . $args['file'] . "]";
                 } elseif ($isuploaded) {
                     // will fail with user uploads
                     $s[] = " [Upload:" . basename($file) . "]";
                 } else {
                     $s[] = " [" . basename($file) . "] ";
                 }
                 break;
             default:
                 if (!$quiet) {
                     return $this->error(sprintf(_("Unsupported argument: %s=%s"), 'display', $mode));
                 } else {
                     return HTML::raw('');
                 }
                 break;
         }
     }
     chdir($dir);
     if (!$format) {
         $format = '';
         foreach ($s as $x) {
             $format .= " %s";
         }
     }
     array_unshift($s, $format);
     // $x, array($i,$j) => sprintf($x, $i, $j)
     $result = call_user_func_array("sprintf", $s);
     if (in_array('link', $modes)) {
         require_once "lib/InlineParser.php";
         return TransformInline($result, 2, $basepage);
     } else {
         return HTML::raw($result);
     }
 }
Esempio n. 14
0
 function _tests()
 {
     $uplink = getUploadDataPath() . '/image.jpg';
     // last update: 1.3.13
     return array("[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ Upload:image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:' . strlen($uplink) . ':"' . $uplink . '";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ http://server/image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:3:"img";s:5:"_attr";a:4:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:11:"inlineimage";}s:8:"_content";a:0:{}s:11:"_properties";i:7;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ label | http://server/link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | Upload:link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "[ label | phpwiki:action=link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"Cached_PhpwikiURL":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', "Upload:image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"Cached_InterwikiLink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', "http://server/image.jpg" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', "http://server/link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', "[http:/server/~name/]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', "http:/server/~name/" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_ExternalLink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', "[label|:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":4:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[:link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:7:"_nolink";b:1;s:9:"_basepage";b:0;}i:2;s:0:"";}}', "relation::link" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":3:{s:4:"_url";s:14:"relation::link";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', "[label|relation::link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":4:{s:4:"_url";s:14:"relation::link";s:6:"_label";s:5:"label";s:9:"_relation";s:8:"relation";s:5:"_page";s:4:"link";}i:2;s:0:"";}}', "attribute:=1000" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:15:"attribute:=1000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:4:"1000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:0:"";}}', "attribute:=1,000km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:18:"attribute:=1,000km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:7:"1,000km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', "attribute:=1,000 km" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:16:"attribute:=1,000";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:5:"1,000";s:15:"_attribute_base";s:4:"1000";s:5:"_unit";s:0:"";}i:2;s:3:" km";}}', "[attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":5:{s:4:"_url";s:19:"attribute:=1,000 km";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', "[label|attribute:=1,000 km]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"Cached_SemanticLink":6:{s:4:"_url";s:19:"attribute:=1,000 km";s:6:"_label";s:5:"label";s:9:"_relation";s:9:"attribute";s:10:"_attribute";s:8:"1,000 km";s:15:"_attribute_base";s:9:"1000000 m";s:5:"_unit";s:1:"m";}i:2;s:0:"";}}', "This is a :PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:11:"This is a :";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "This is a ::PageLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a ::";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageLink";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "This is a :=PageAttr" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a :=";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageAttr";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "This is :~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:9:"This is :";i:1;s:6:"NoLink";i:2;s:0:"";}}', "This is ::~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is ::";i:1;s:6:"NoLink";i:2;s:0:"";}}', "This is :=~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is :=";i:1;s:6:"NoLink";i:2;s:0:"";}}');
 }
Esempio n. 15
0
$properties["ENABLE_MARKUP_COLOR"] = new boolean_define_optional('ENABLE_MARKUP_COLOR');
$properties["DISABLE_MARKUP_WIKIWORD"] = new boolean_define_optional('DISABLE_MARKUP_WIKIWORD');
$properties["ENABLE_MARKUP_DIVSPAN"] = new boolean_define_optional('ENABLE_MARKUP_DIVSPAN');
///////////////////
$properties["Part Six"] = new part('_part6', $SEPARATOR . "\n", "\n\nPart Six (optional):\nURL options -- you can probably skip this section.\n\nFor a pretty wiki (no index.php in the url) set a seperate DATA_PATH.");
$properties["Server Name"] = new _define_commented_optional('SERVER_NAME', $_SERVER['SERVER_NAME'], "\nCanonical name of the server on which this PhpWiki resides.");
$properties["Server Port"] = new numeric_define_commented('SERVER_PORT', $_SERVER['SERVER_PORT'], "\nCanonical httpd port of the server on which this PhpWiki resides.", "onchange=\"validate_ereg('Sorry, \\'%s\\' is no valid port number.', '^[0-9]+\$', 'SERVER_PORT', this);\"");
$properties["Server Protocol"] = new _define_selection_optional_commented('SERVER_PROTOCOL', array('http' => 'http', 'https' => 'https'));
$properties["Script Name"] = new _define_commented_optional('SCRIPT_NAME', $scriptname);
$properties["Data Path"] = new _define_commented_optional('DATA_PATH', dirname($scriptname));
$properties["PhpWiki Install Directory"] = new _define_commented_optional('PHPWIKI_DIR', dirname(__FILE__));
$properties["Use PATH_INFO"] = new _define_selection_optional_commented('USE_PATH_INFO', array('' => 'automatic', 'true' => 'use PATH_INFO', 'false' => 'do not use PATH_INFO'), "\nPhpWiki will try to use short urls to pages, eg \nhttp://www.example.com/index.php/HomePage\nIf you want to use urls like \nhttp://www.example.com/index.php?pagename=HomePage\nthen define 'USE_PATH_INFO' as false by uncommenting the line below.\nNB:  If you are using Apache >= 2.0.30, then you may need to to use\nthe directive \"AcceptPathInfo On\" in your Apache configuration file\n(or in an appropriate <.htaccess> file) for the short urls to work:  \nSee http://httpd.apache.org/docs-2.0/mod/core.html#acceptpathinfo\n\nSee also http://phpwiki.sourceforge.net/phpwiki/PrettyWiki for more ideas\non prettifying your urls.\n\nDefault: PhpWiki will try to divine whether use of PATH_INFO\nis supported in by your webserver/PHP configuration, and will\nuse PATH_INFO if it thinks that is possible.");
$properties["Virtual Path"] = new _define_commented_optional('VIRTUAL_PATH', '/SomeWiki', "\nVIRTUAL_PATH is the canonical URL path under which your your wiki\nappears. Normally this is the same as dirname(SCRIPT_NAME), however\nusing e.g. seperate starter scripts, apaches mod_actions (or mod_rewrite), \nyou can make it something different.\n\nIf you do this, you should set VIRTUAL_PATH here or in the starter scripts.\n\nE.g. your phpwiki might be installed at at /scripts/phpwiki/index.php,\nbut you've made it accessible through eg. /wiki/HomePage.\n\nOne way to do this is to create a directory named 'wiki' in your\nserver root. The directory contains only one file: an .htaccess\nfile which reads something like:\n<pre>\n    Action x-phpwiki-page /scripts/phpwiki/index.php\n    SetHandler x-phpwiki-page\n    DirectoryIndex /scripts/phpwiki/index.php\n</pre>\nIn that case you should set VIRTUAL_PATH to '/wiki'.\n\n(VIRTUAL_PATH is only used if USE_PATH_INFO is true.)\n");
$upload_file_path = defined('UPLOAD_FILE_PATH') ? UPLOAD_FILE_PATH : getUploadFilePath();
new _define_optional('UPLOAD_FILE_PATH', $temp);
$upload_data_path = defined('UPLOAD_DATA_PATH') ? UPLOAD_DATA_PATH : getUploadDataPath();
new _define_optional('UPLOAD_DATA_PATH', $temp);
$temp = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : "/tmp";
$properties["TEMP_DIR"] = new _define_optional('TEMP_DIR', $temp);
///////////////////
$properties["Part Seven"] = new part('_part7', $SEPARATOR . "\n", "\n\nPart Seven:\n\nMiscellaneous settings\n");
$properties["Strict Mailable Pagedumps"] = new boolean_define_optional('STRICT_MAILABLE_PAGEDUMPS', array('false' => "binary", 'true' => "quoted-printable"));
$properties["Default local Dump Directory"] = new _define_optional('DEFAULT_DUMP_DIR');
$properties["Default local HTML Dump Directory"] = new _define_optional('HTML_DUMP_DIR');
$properties["HTML Dump Filename Suffix"] = new _define_optional('HTML_DUMP_SUFFIX');
$properties["Pagename of Recent Changes"] = new _define_optional('RECENT_CHANGES', "RecentChanges");
$properties["Disable HTTP Redirects"] = new boolean_define_commented_optional('DISABLE_HTTP_REDIRECT');
$properties["Disable GETIMAGESIZE"] = new boolean_define_commented_optional('DISABLE_GETIMAGESIZE');
$properties["EDITING_POLICY"] = new _define_optional('EDITING_POLICY');
$properties["TOOLBAR_PAGELINK_PULLDOWN"] = new _define_commented_optional('TOOLBAR_PAGELINK_PULLDOWN');
$properties["TOOLBAR_TEMPLATE_PULLDOWN"] = new _define_commented_optional('TOOLBAR_TEMPLATE_PULLDOWN');