Example #1
0
 function link($link, $linktext = false)
 {
     global $WikiTheme;
     list($moniker, $page) = explode(":", $link, 2);
     if (!isset($this->_map[$moniker])) {
         return HTML::span(array('class' => 'bad-interwiki'), $linktext ? $linktext : $link);
     }
     $url = $this->_map[$moniker];
     // localize Upload:links for WIKIDUMP
     if (!empty($WikiTheme->DUMP_MODE) and $moniker == 'Upload') {
         global $request;
         include_once "lib/config.php";
         $url = getUploadFilePath();
         // calculate to a relative local path to /uploads for pdf images.
         $doc_root = $request->get("DOCUMENT_ROOT");
         $ldir = NormalizeLocalFileName($url);
         $wikiroot = NormalizeLocalFileName('');
         if (isWindows()) {
             $ldir = strtolower($ldir);
             $doc_root = strtolower($doc_root);
             $wikiroot = strtolower($wikiroot);
         }
         if (string_starts_with($ldir, $doc_root)) {
             $link_prefix = substr($url, strlen($doc_root));
         } elseif (string_starts_with($ldir, $wikiroot)) {
             $link_prefix = NormalizeWebFileName(substr($url, strlen($wikiroot)));
         }
     }
     // Urlencode page only if it's a query arg.
     // FIXME: this is a somewhat broken heuristic.
     if ($moniker == 'Upload') {
         $page_enc = $page;
         $page = rawurldecode($page);
     } else {
         $page_enc = strstr($url, '?') ? rawurlencode($page) : $page;
     }
     if (strstr($url, '%s')) {
         $url = sprintf($url, $page_enc);
     } else {
         $url .= $page_enc;
     }
     $link = HTML::a(array('href' => $url));
     if (!$linktext) {
         $link->pushContent(PossiblyGlueIconToText('interwiki', "{$moniker}:"), HTML::span(array('class' => 'wikipage'), $page));
         $link->setAttr('class', 'interwiki');
     } else {
         $link->pushContent(PossiblyGlueIconToText('interwiki', $linktext));
         $link->setAttr('class', 'named-interwiki');
     }
     return $link;
 }
Example #2
0
/**
 * Dump all pages as XHTML to a directory, as pagename.html.
 * Copies all used css files to the directory, all used images to a 
 * "images" subdirectory, and all used buttons to a "images/buttons" subdirectory.
 * The webserver must have write permissions to these directories. 
 *   chown httpd HTML_DUMP_DIR; chmod u+rwx HTML_DUMP_DIR 
 * should be enough.
 *
 * @param string directory (optional) path to dump to. Default: HTML_DUMP_DIR
 * @param string pages     (optional) Comma-seperated of glob-style pagenames to dump
 * @param string exclude   (optional) Comma-seperated of glob-style pagenames to exclude
 */
function DumpHtmlToDir(&$request)
{
    $directory = $request->getArg('directory');
    if (empty($directory)) {
        $directory = HTML_DUMP_DIR;
    }
    // See lib/plugin/WikiForm.php:87
    if (empty($directory)) {
        $request->finish(_("You must specify a directory to dump to"));
    }
    // see if we can access the directory the user wants us to use
    if (!file_exists($directory)) {
        if (!mkdir($directory, 0755)) {
            $request->finish(fmt("Cannot create directory '%s'", $directory));
        } else {
            $html = HTML::p(fmt("Created directory '%s' for the page dump...", $directory));
        }
    } else {
        $html = HTML::p(fmt("Using directory '%s'", $directory));
    }
    $request->_TemplatesProcessed = array();
    StartLoadDump($request, _("Dumping Pages"), $html);
    $thispage = $request->getArg('pagename');
    // for "Return to ..."
    $dbi =& $request->_dbi;
    if ($exclude = $request->getArg('exclude')) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array();
    }
    if ($pages = $request->getArg('pages')) {
        // which pagenames
        if ($pages == '[]') {
            // current page
            $pages = $thispage;
        }
        $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages));
        // not at admin page: dump only the current page
    } elseif ($thispage != _("PhpWikiAdministration")) {
        $page_iter = new WikiDB_Array_PageIterator(array($thispage));
    } else {
        $page_iter = $dbi->getAllPages(false, false, false, $excludeList);
    }
    global $WikiTheme;
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $WikiTheme->DUMP_MODE = 'HTML';
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    // check if the dumped file will be accessible from outside
    $doc_root = $request->get("DOCUMENT_ROOT");
    $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 . "/";
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 20 : 240;
    while ($page = $page_iter->next()) {
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        $pagename = $page->getName();
        if (!isa($request, 'MockRequest')) {
            PrintXML(HTML::br(), $pagename, ' ... ');
            flush();
        }
        if (in_array($pagename, $excludeList)) {
            if (!isa($request, 'MockRequest')) {
                PrintXML(_("Skipped."));
                flush();
            }
            continue;
        }
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $msg = HTML();
        $revision = $page->getCurrentRevision();
        $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $revision->getTransformedContent()));
        $data = GeneratePageasXML($template, $pagename);
        if (!($fd = fopen($directory . "/" . $filename, "wb"))) {
            $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", "{$directory}/{$filename}")));
            $request->finish($msg);
        }
        $num = fwrite($fd, $data, strlen($data));
        if ($page->getName() != $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 (!isa($request, 'MockRequest')) {
            PrintXML($msg);
        }
        flush();
        $request->chunkOutput();
        assert($num == strlen($data));
        fclose($fd);
        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($revision->_transformedContent);
        unset($revision);
        unset($template->_request);
        unset($template);
        unset($data);
    }
    $page_iter->free();
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        @mkdir("{$directory}/images");
        foreach ($WikiTheme->dumped_images as $img_file) {
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "{$directory}/images/" . basename($img_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        // Buttons also
        @mkdir("{$directory}/images/buttons");
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "{$directory}/images/buttons/" . basename($img_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if ($css_file and $from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                $target = "{$directory}/" . basename($css_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
    $request->setArg('pagename', $thispage);
    // Template::_basepage fix
    EndLoadDump($request);
}
Example #3
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;
}
Example #4
0
 function Theme($theme_name = 'default')
 {
     $this->_name = $theme_name;
     $this->_themes_dir = NormalizeLocalFileName("themes");
     $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
     $this->_theme = "themes/{$theme_name}";
     if ($theme_name != 'default') {
         $this->_default_theme = new Theme();
     }
     // by pixels
     if (is_object($GLOBALS['request']) and $GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT) {
         $this->initDoubleClickEdit();
     }
     // will be replaced by acDropDown
     if (ENABLE_LIVESEARCH) {
         // by bitflux.ch
         $this->initLiveSearch();
     }
     $this->_css = array();
 }
Example #5
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;
}
Example #6
0
 /**
  * noinit: Do not initialize unnecessary items in default_theme fallback twice.
  */
 function WikiTheme($theme_name = 'default', $noinit = false)
 {
     $this->_name = $theme_name;
     $this->_themes_dir = NormalizeLocalFileName("themes");
     $this->_path = defined('PHPWIKI_DIR') ? NormalizeLocalFileName("") : "";
     $this->_theme = "themes/{$theme_name}";
     $this->_parents = array();
     if ($theme_name != 'default') {
         $parent = $this;
         /* derived classes should search all parent classes */
         while ($parent = get_parent_class($parent)) {
             if (strtolower($parent) == 'wikitheme') {
                 $this->_default_theme = new WikiTheme('default', true);
                 $this->_parents[] = $this->_default_theme;
             } elseif ($parent) {
                 $this->_parents[] = new WikiTheme(preg_replace("/^WikiTheme_/i", "", $parent), true);
             }
         }
     }
     if ($noinit) {
         return;
     }
     $this->_css = array();
     // on derived classes do not add headers twice
     if (count($this->_parents) > 1) {
         return;
     }
     $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("wikicommon.js"))));
     if (!FUSIONFORGE) {
         // FusionForge already loads this
         $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("sortable.js"))));
     }
     // by pixels
     if (is_object($GLOBALS['request']) and $GLOBALS['request']->getPref('doubleClickEdit') or ENABLE_DOUBLECLICKEDIT) {
         $this->initDoubleClickEdit();
     }
     // will be replaced by acDropDown
     if (ENABLE_LIVESEARCH) {
         // by bitflux.ch
         $this->initLiveSearch();
     }
     // replaces external LiveSearch
     // enable ENABLE_AJAX for DynamicIncludePage
     if (ENABLE_ACDROPDOWN or ENABLE_AJAX) {
         $this->initMoAcDropDown();
         if (ENABLE_AJAX and DEBUG) {
             // minified all together
             $this->addMoreHeaders(JavaScript('', array('src' => $this->_findData("ajax.js"))));
         }
     }
 }
Example #7
0
 function fixThemeTemplate($match, $new, $template)
 {
     // for all custom themes
     $ourthemes = explode(":", "blog:Crao:default:Hawaiian:MacOSX:MonoBook:Portland:shamino_com:SpaceWiki:wikilens:Wordpress");
     $themedir = NormalizeLocalFileName("themes");
     $dh = opendir($themedir);
     while ($r = readdir($dh)) {
         if (filetype($r) == 'dir' and $r[0] != '.' and !is_array($r, $ourthemes)) {
             $customthemes[] = $r;
         }
     }
     $success = true;
     $errors = '';
     foreach ($customthemes as $customtheme) {
         $template = FindFile("themes/{$customtheme}/templates/{$template}");
         $do = $this->parent->fixLocalFile($match, $new, template);
         if (!$do[0]) {
             $success = false;
             $errors .= $do[1] . " ";
             echo $do[1];
         }
     }
     return array($success, $errors);
 }