Пример #1
0
/**
 * Removes prefix from start of string
 *
 * @param string $input
 * @param string $prefix
 *
 * @return string
 *
 * @author Lucantis Swann <*****@*****.**>
 */
function string_chomp_left($input, $prefix)
{
    if (string_starts_with($input, $prefix)) {
        return mb_substr($input, mb_strlen($prefix));
    }
    return $input;
}
Пример #2
0
 function _doautocomplete(&$form, $inputtype, &$input, &$values)
 {
     global $request;
     $input['class'] = "dropdown";
     $input['acdropdown'] = "true";
     //$input['autocomplete'] = "OFF";
     $input['autocomplete_complete'] = "true";
     // only match begin: autocomplete_matchbegin, or
     $input['autocomplete_matchsubstring'] = "true";
     if (empty($values)) {
         if ($input['method']) {
             if (empty($input['args'])) {
                 if (preg_match("/^(.*?) (.*)\$/", $input['method'], $m)) {
                     $input['method'] = $m[1];
                     $input['args'] = $m[2];
                 } else {
                     $input['args'] = null;
                 }
             }
             static $tmpArray = 'tmpArray00';
             // deferred remote xmlrpc call
             if (string_starts_with($input['method'], "dynxmlrpc:")) {
                 // how is server + method + args encoding parsed by acdropdown?
                 $input['autocomplete_list'] = substr($input['method'], 3);
                 if ($input['args']) {
                     $input['autocomplete_list'] .= " " . $input['args'];
                 }
                 // static xmlrpc call, local only
             } elseif (string_starts_with($input['method'], "xmlrpc:")) {
                 include_once "lib/XmlRpcClient.php";
                 $values = wiki_xmlrpc_post(substr($input['method'], 7), $input['args']);
             } elseif (string_starts_with($input['method'], "url:")) {
                 include_once "lib/HttpClient.php";
                 $html = HttpClient::quickGet(substr($input['method'], 4));
                 //TODO: how to parse the HTML result into a list?
             } elseif (string_starts_with($input['method'], "dynurl:")) {
                 $input['autocomplete_list'] = substr($input['method'], 3);
             } elseif (string_starts_with($input['method'], "plugin:")) {
                 $dbi = $request->getDbh();
                 $pluginName = substr($input['method'], 7);
                 $basepage = '';
                 require_once "lib/WikiPlugin.php";
                 $w = new WikiPluginLoader();
                 $p = $w->getPlugin($pluginName, false);
                 // second arg?
                 if (!is_object($p)) {
                     trigger_error("invalid input['method'] " . $input['method'], E_USER_WARNING);
                 }
                 $pagelist = $p->run($dbi, @$input['args'], $request, $basepage);
                 $values = array();
                 if (is_object($pagelist) and isa($pagelist, 'PageList')) {
                     foreach ($pagelist->_pages as $page) {
                         if (is_object($page)) {
                             $values[] = $page->getName();
                         } else {
                             $values[] = (string) $page;
                         }
                     }
                 }
             } elseif (string_starts_with($input['method'], "array:")) {
                 // some predefined values (e.g. in a template or themeinfo.php)
                 $input['autocomplete_list'] = $input['method'];
             } else {
                 trigger_error("invalid input['method'] " . $input['method'], E_USER_WARNING);
             }
             if (empty($input['autocomplete_list'])) {
                 $tmpArray++;
                 $input['autocomplete_list'] = "array:" . $tmpArray;
                 $svalues = empty($values) ? "" : join("','", $values);
                 $form->pushContent(JavaScript("var {$tmpArray} = new Array('" . $svalues . "')"));
             }
             if (count($values) == 1) {
                 $input['value'] = $values[0];
             } else {
                 $input['value'] = "";
             }
             unset($input['method']);
             unset($input['args']);
             //unset($input['autocomplete']);
         } elseif ($s = $request->getArg($input['name'])) {
             $input['value'] = $s;
         }
     }
     return true;
 }
 /**
  * Uses PHP reflection to figure out which traditional HTML tags
  * require special rendering that's handled by this implementation.
  * Most HTML tags are rendered as you'd expect--that is, and FBML
  * node surround most HTML tags get rendered as:
  *
  *    <[tag-name] [name-1]="[value-1]" [name-2]="[value-2]" >
  *
  * But some HTML nodes--those with links to external URLs, for example--
  * might have special rendering needs.  An FBML implementation can
  * override the traditional rendering functionality for a tag by providing
  * one-argument method called "tag_[tag-name]".  That's a statement that
  * the FBML implementation is prepared to execute these methods on behalf
  * of these special HTML nodes.
  *
  * As with get_all_fb_tag_names, we compile a full list of all the methods,
  * search for those beginning with "tag_", and then reverse engineer the
  * name of the HTML tag type that requires special rendering.
  *
  * @return an array of all of the HTML tags which this FBML handles.  All HTML
  *         tag types not included in this list are assumed to be traditional
  *         HTML tags that can be rendered in the traditional manner.
  */
 public function get_special_html_tags()
 {
     $all_methods = get_class_methods($this);
     $html_special = array();
     foreach ($all_methods as $name) {
         $n = strtolower($name);
         if (string_starts_with($n, 'tag_') || string_starts_with($n, 'open_')) {
             $start = strpos($n, '_');
             $tag = substr($n, $start + 1);
             $html_special[$tag] = $tag;
         }
     }
     return $html_special;
 }
Пример #4
0
 function findBlogs(&$dbi, $parent, $type = 'wikiblog')
 {
     $prefix = (empty($parent) ? "" : $parent . SUBPAGE_SEPARATOR) . $this->_blogPrefix($type);
     $pages = $dbi->titleSearch(new TextSearchQuery("^" . $prefix, true, 'posix'));
     $blogs = array();
     while ($page = $pages->next()) {
         if (!string_starts_with($page->getName(), $prefix)) {
             continue;
         }
         $current = $page->getCurrentRevision();
         if ($current->get('pagetype') == $type) {
             $blogs[] = $current;
         }
     }
     return $blogs;
 }
Пример #5
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if ($page) {
         // Expand relative page names.
         $page = new WikiPageName($page, $basepage);
         $page = $page->name;
     }
     if (!$page) {
         return $this->error(_("no page specified"));
     }
     // A page can include itself once (this is needed, e.g.,  when editing
     // TextFormattingRules).
     static $included_pages = array();
     if (in_array($page, $included_pages)) {
         return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page));
     }
     // Check if page exists
     if (!$dbi->isWikiPage($page)) {
         return $this->error(sprintf(_("Page '%s' does not exist"), $page));
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $page)) {
         return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $page));
     }
     $p = $dbi->getPage($page);
     if ($rev) {
         $r = $p->getRevision($rev);
         if (!$r) {
             return $this->error(sprintf(_("%s(%d): no such revision"), $page, $rev));
         }
     } else {
         $r = $p->getCurrentRevision();
     }
     $c = $r->getContent();
     // follow redirects
     if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $m)) {
         // Strip quotes (simple or double) from page name if any
         if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
             $m[1] = substr($m[1], 1, -1);
         }
         // trap recursive redirects
         if (in_array($m[1], $included_pages)) {
             return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page . ' => ' . $m[1]));
         }
         $page = $m[1];
         $p = $dbi->getPage($page);
         $r = $p->getCurrentRevision();
         $c = $r->getContent();
         // array of lines
     }
     $ct = $this->extractParts($c, $page, $args);
     // exclude from expansion
     if (preg_match('/<noinclude>.+<\\/noinclude>/s', $ct)) {
         $ct = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $ct);
     }
     // only in expansion
     $ct = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $ct);
     array_push($included_pages, $page);
     include_once 'lib/BlockParser.php';
     $content = TransformText($ct, $r->get('markup'), $page);
     array_pop($included_pages);
     if ($quiet) {
         return $content;
     }
     return HTML(HTML::p(array('class' => 'transclusion-title'), fmt("Included from %s", WikiLink($page))), HTML::div(array('class' => 'transclusion'), false, $content));
 }
Пример #6
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);
}
Пример #7
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;
     }
 }
Пример #8
0
/**
 * Compute cell in spreadsheet table
 * $table: two-dimensional table
 * $i and $j: indexes of cell to compute
 * $imax and $jmax: table dimensions
 */
function compute_tablecell($table, $i, $j, $imax, $jmax)
{
    // What is implemented:
    // @@=SUM(R)@@ : sum of cells in current row
    // @@=SUM(C)@@ : sum of cells in current column
    // @@=AVERAGE(R)@@ : average of cells in current row
    // @@=AVERAGE(C)@@ : average of cells in current column
    // @@=MAX(R)@@ : maximum value of cells in current row
    // @@=MAX(C)@@ : maximum value of cells in current column
    // @@=MIN(R)@@ : minimum value of cells in current row
    // @@=MIN(C)@@ : minimum value of cells in current column
    // @@=COUNT(R)@@ : number of cells in current row
    //                (numeric or not, excluding headers and current cell)
    // @@=COUNT(C)@@ : number of cells in current column
    //                (numeric or not, excluding headers and current cell)
    $result = 0;
    $counter = 0;
    $found = false;
    if (strpos($table[$i][$j], "@@=SUM(C)@@") !== false) {
        for ($index = 0; $index < $imax; $index++) {
            if (is_numeric($table[$index][$j])) {
                $result += $table[$index][$j];
            }
        }
        return str_replace("@@=SUM(C)@@", $result, $table[$i][$j]);
    } else {
        if (strpos($table[$i][$j], "@@=SUM(R)@@") !== false) {
            for ($index = 0; $index < $jmax; $index++) {
                if (is_numeric($table[$i][$index])) {
                    $result += $table[$i][$index];
                }
            }
            return str_replace("@@=SUM(R)@@", $result, $table[$i][$j]);
        } else {
            if (strpos($table[$i][$j], "@@=AVERAGE(C)@@") !== false) {
                for ($index = 0; $index < $imax; $index++) {
                    if (is_numeric($table[$index][$j])) {
                        $result += $table[$index][$j];
                        $counter++;
                    }
                }
                $result = $result / $counter;
                return str_replace("@@=AVERAGE(C)@@", $result, $table[$i][$j]);
            } else {
                if (strpos($table[$i][$j], "@@=AVERAGE(R)@@") !== false) {
                    for ($index = 0; $index < $jmax; $index++) {
                        if (is_numeric($table[$i][$index])) {
                            $result += $table[$i][$index];
                            $counter++;
                        }
                    }
                    $result = $result / $counter;
                    return str_replace("@@=AVERAGE(R)@@", $result, $table[$i][$j]);
                } else {
                    if (strpos($table[$i][$j], "@@=MAX(C)@@") !== false) {
                        for ($index = 0; $index < $imax; $index++) {
                            if (is_numeric($table[$index][$j])) {
                                if (!$found) {
                                    $found = true;
                                    $result = $table[$index][$j];
                                } else {
                                    $result = max($result, $table[$index][$j]);
                                }
                            }
                        }
                        if (!$found) {
                            $result = "";
                        }
                        return str_replace("@@=MAX(C)@@", $result, $table[$i][$j]);
                    } else {
                        if (strpos($table[$i][$j], "@@=MAX(R)@@") !== false) {
                            for ($index = 0; $index < $jmax; $index++) {
                                if (is_numeric($table[$i][$index])) {
                                    if (!$found) {
                                        $found = true;
                                        $result = $table[$i][$index];
                                    } else {
                                        $result = max($result, $table[$i][$index]);
                                    }
                                }
                            }
                            if (!$found) {
                                $result = "";
                            }
                            return str_replace("@@=MAX(R)@@", $result, $table[$i][$j]);
                        } else {
                            if (strpos($table[$i][$j], "@@=MIN(C)@@") !== false) {
                                for ($index = 0; $index < $imax; $index++) {
                                    if (is_numeric($table[$index][$j])) {
                                        if (!$found) {
                                            $found = true;
                                            $result = $table[$index][$j];
                                        } else {
                                            $result = min($result, $table[$index][$j]);
                                        }
                                    }
                                }
                                if (!$found) {
                                    $result = "";
                                }
                                return str_replace("@@=MIN(C)@@", $result, $table[$i][$j]);
                            } else {
                                if (strpos($table[$i][$j], "@@=MIN(R)@@") !== false) {
                                    for ($index = 0; $index < $jmax; $index++) {
                                        if (is_numeric($table[$i][$index])) {
                                            if (!$found) {
                                                $found = true;
                                                $result = $table[$i][$index];
                                            } else {
                                                $result = min($result, $table[$i][$index]);
                                            }
                                        }
                                    }
                                    if (!$found) {
                                        $result = "";
                                    }
                                    return str_replace("@@=MIN(R)@@", $result, $table[$i][$j]);
                                } else {
                                    if (strpos($table[$i][$j], "@@=COUNT(C)@@") !== false) {
                                        for ($index = 0; $index < $imax; $index++) {
                                            if (!string_starts_with(trim($table[$index][$j]), "=")) {
                                                // exclude header
                                                $counter++;
                                            }
                                        }
                                        $result = $counter - 1;
                                        // exclude self
                                        return str_replace("@@=COUNT(C)@@", $result, $table[$i][$j]);
                                    } else {
                                        if (strpos($table[$i][$j], "@@=COUNT(R)@@") !== false) {
                                            for ($index = 0; $index < $jmax; $index++) {
                                                if (!string_starts_with(trim($table[$i][$index]), "=")) {
                                                    // exclude header
                                                    $counter++;
                                                }
                                            }
                                            $result = $counter - 1;
                                            // exclude self
                                            return str_replace("@@=COUNT(R)@@", $result, $table[$i][$j]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $table[$i][$j];
}
Пример #9
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     static $included_pages = false;
     if (!$included_pages) {
         $included_pages = array($basepage);
     }
     $args = $this->getArgs($argstr, $request);
     extract($args);
     $query = new TextSearchQuery($pagename . SUBPAGE_SEPARATOR . '*', true, 'glob');
     $subpages = $dbi->titleSearch($query, $sortby, $limit, $exclude);
     //if ($sortby)
     //    $subpages = $subpages->applyFilters(array('sortby' => $sortby, 'limit' => $limit, 'exclude' => $exclude));
     //$subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*', false,
     //                            $sortby, $limit, $exclude);
     if (is_string($exclude) and !is_array($exclude)) {
         $exclude = PageList::explodePageList($exclude, false, false, $limit);
     }
     $content = HTML();
     include_once 'lib/BlockParser.php';
     $i = 0;
     while ($page = $subpages->next()) {
         $cpagename = $page->getName();
         if ($maxpages and $i++ > $maxpages) {
             return $content;
         }
         if (in_array($cpagename, $exclude)) {
             continue;
         }
         // A page cannot include itself. Avoid doublettes.
         if (in_array($cpagename, $included_pages)) {
             $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename)));
             continue;
         }
         // Check if user is allowed to get the Page.
         if (!mayAccessPage('view', $cpagename)) {
             return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename));
         }
         // trap any remaining nonexistant subpages
         if ($page->exists()) {
             $r = $page->getCurrentRevision();
             $c = $r->getContent();
             // array of lines
             // follow redirects
             if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $c), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $c), $m)) {
                 // Strip quotes (simple or double) from page name if any
                 if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
                     $m[1] = substr($m[1], 1, -1);
                 }
                 // trap recursive redirects
                 if (in_array($m[1], $included_pages)) {
                     if (!$quiet) {
                         $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"), $cpagename . ' => ' . $m[1])));
                     }
                     continue;
                 }
                 $cpagename = $m[1];
                 // Check if user is allowed to get the Page.
                 if (!mayAccessPage('view', $cpagename)) {
                     return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $cpagename));
                 }
                 $page = $dbi->getPage($cpagename);
                 $r = $page->getCurrentRevision();
                 $c = $r->getContent();
                 // array of lines
             }
             // moved to IncludePage
             $ct = $this->extractParts($c, $cpagename, $args);
             array_push($included_pages, $cpagename);
             if ($smalltitle) {
                 $pname = array_pop(explode(SUBPAGE_SEPARATOR, $cpagename));
                 // get last subpage name
                 // Use _("%s: %s") instead of .": ". for French punctuation
                 $ct = TransformText(sprintf(_("%s: %s"), "[{$pname}|{$cpagename}]", $ct), $r->get('markup'), $cpagename);
             } else {
                 $ct = TransformText($ct, $r->get('markup'), $cpagename);
             }
             array_pop($included_pages);
             if (!$smalltitle) {
                 $content->pushContent(HTML::p(array('class' => $quiet ? '' : 'transclusion-title'), fmt("Included from %s:", WikiLink($cpagename))));
             }
             $content->pushContent(HTML(HTML::div(array('class' => $quiet ? '' : 'transclusion'), false, $ct)));
         }
     }
     if (!isset($cpagename)) {
         return $this->error(sprintf(_("%s has no subpages defined."), $pagename));
     }
     return $content;
 }
Пример #10
0
function isExternalReferrer(&$request)
{
    if ($referrer = $request->get('HTTP_REFERER')) {
        $home = SERVER_URL;
        // SERVER_URL or SCRIPT_NAME, if we want to check sister wiki's also
        if (string_starts_with(strtolower($referrer), strtolower($home))) {
            return false;
        }
        require_once "lib/ExternalReferrer.php";
        $se = new SearchEngines();
        return $se->parseSearchQuery($referrer);
    }
    return false;
}
Пример #11
0
/**
 * @since 3.4
 */
function is_awpcp_admin_page()
{
    if (!is_admin() || empty($_REQUEST['page'])) {
        return false;
    }
    if (string_starts_with($_REQUEST['page'], 'awpcp')) {
        return true;
    }
    if (in_array($_REQUEST['page'], array('Configure4', 'Configure5'))) {
        return true;
    }
    return false;
}
Пример #12
0
 public function all_in_one_seo_pack_title($title)
 {
     global $aioseop_options;
     $title_format = awpcp_array_data('aiosp_page_title_format', '', $aioseop_options);
     if (string_starts_with($title_format, '%page_title%')) {
         $seplocation = 'right';
     } else {
         $seplocation = 'left';
     }
     return $this->title_builder->build_title($title, '', $seplocation);
 }
Пример #13
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $this->vars = array();
     $args = $this->getArgs($argstr, $request);
     $vars = $args['vars'] ? $args['vars'] : $this->vars;
     $page = $args['page'];
     if ($page) {
         // Expand relative page names.
         $page = new WikiPageName($page, $basepage);
         $page = $page->name;
     }
     if (!$page) {
         return $this->error(_("no page specified"));
     }
     // If "Template:$page" exists, use it
     // else if "Template/$page" exists, use it
     // else use "$page"
     if ($dbi->isWikiPage("Template:" . $page)) {
         $page = "Template:" . $page;
     } elseif ($dbi->isWikiPage("Template/" . $page)) {
         $page = "Template/" . $page;
     }
     // Protect from recursive inclusion. A page can include itself once
     static $included_pages = array();
     if (in_array($page, $included_pages)) {
         return $this->error(sprintf(_("recursive inclusion of page %s"), $page));
     }
     // Check if page exists
     if (!$dbi->isWikiPage($page)) {
         return $this->error(sprintf(_("Page '%s' does not exist"), $page));
     }
     // Check if user is allowed to get the Page.
     if (!mayAccessPage('view', $page)) {
         return $this->error(sprintf(_("Illegal inclusion of page %s: no read access"), $page));
     }
     $p = $dbi->getPage($page);
     if ($args['rev']) {
         $r = $p->getRevision($args['rev']);
         if (!$r) {
             return $this->error(sprintf(_("%s(%d): no such revision"), $page, $args['rev']));
         }
     } else {
         $r = $p->getCurrentRevision();
     }
     $initial_content = $r->getPackedContent();
     $content = $r->getContent();
     // follow redirects
     if (preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(\\S+)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<' . '\\?plugin\\s+RedirectTo\\s+page=(.*?)\\s*\\?' . '>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page=(\\S+)\\s*>>/', implode("\n", $content), $m) or preg_match('/<<\\s*RedirectTo\\s+page="(.*?)"\\s*>>/', implode("\n", $content), $m)) {
         // Strip quotes (simple or double) from page name if any
         if (string_starts_with($m[1], "'") or string_starts_with($m[1], "\"")) {
             $m[1] = substr($m[1], 1, -1);
         }
         // trap recursive redirects
         if (in_array($m[1], $included_pages)) {
             return $this->error(sprintf(_("recursive inclusion of page %s ignored"), $page . ' => ' . $m[1]));
         }
         $page = $m[1];
         $p = $dbi->getPage($page);
         $r = $p->getCurrentRevision();
         $initial_content = $r->getPackedContent();
     }
     if ($args['section']) {
         $c = explode("\n", $initial_content);
         $c = extractSection($args['section'], $c, $page, $quiet, $args['sectionhead']);
         $initial_content = implode("\n", $c);
     }
     // exclude from expansion
     if (preg_match('/<noinclude>.+<\\/noinclude>/s', $initial_content)) {
         $initial_content = preg_replace("/<noinclude>.+?<\\/noinclude>/s", "", $initial_content);
     }
     // only in expansion
     $initial_content = preg_replace("/<includeonly>(.+)<\\/includeonly>/s", "\\1", $initial_content);
     $this->doVariableExpansion($initial_content, $vars, $basepage, $request);
     array_push($included_pages, $page);
     // If content is single-line, call TransformInline, else call TransformText
     $initial_content = trim($initial_content, "\n");
     if (preg_match("/\n/", $initial_content)) {
         include_once 'lib/BlockParser.php';
         $content = TransformText($initial_content, $r->get('markup'), $page);
     } else {
         include_once 'lib/InlineParser.php';
         $content = TransformInline($initial_content, $r->get('markup'), $page);
     }
     array_pop($included_pages);
     return $content;
 }
function woocommerce_custom_surcharge()
{
    global $woocommerce;
    $wc_shipping_island = get_option('wc_shipping_island');
    if (isset($wc_shipping_island) && $wc_shipping_island["stato"] == 'on') {
        if (is_admin() && !defined('DOING_AJAX')) {
            return;
        }
        $cap = $woocommerce->customer->get_shipping_postcode();
        $cap_isole = $wc_shipping_island["cap"];
        if ($wc_shipping_island["tax_costo"] == 'false') {
            $class_tax = 'NO-IMPONIBILE';
        }
        foreach ($cap_isole as $cap_isola) {
            if (string_starts_with($cap, $cap_isola)) {
                $woocommerce->cart->add_fee($wc_shipping_island["title"], $wc_shipping_island["costo"], $wc_shipping_island["tax_costo"], $class_tax);
            }
        }
    }
}
Пример #15
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;
}
Пример #16
0
function create_mod_xml()
{
    global $context;
    $content = file_get_contents($context['mod_current_file']);
    $content = explode("\n", $content);
    $operations = array();
    $context['modifications'] = array();
    $counter = 0;
    $opCounter = 0;
    for ($i = 0; $i < count($content); $i++) {
        if (string_starts_with($content[$i], '--- a/')) {
            $directory = substr($content[$i], 6, strpos($content[$i], '/', 7) - 6);
            if ($directory == 'Sources') {
                $dir = '$sourcedir';
            } elseif (strpos($content[$i], 'languages') !== false) {
                $dir = '$languagedir';
            } elseif (strpos($content[$i], 'images') !== false) {
                $dir = '$imagesdir';
            } elseif (strpos($content[$i], 'default/scripts') !== false) {
                $dir = '$themedir/scripts';
            } elseif ($directory == 'Themes') {
                $dir = '$themedir';
            } else {
                $dir = '$boarddir';
            }
            $context['modifications'][$counter]['path'] = $dir . '/' . basename($content[$i]);
            while (!string_starts_with($content[$i], '@@')) {
                $i++;
            }
            continue;
        }
        // The block of code is finished, let's create an <operation>
        if ((string_starts_with($content[$i], '@@') || string_starts_with($content[$i], 'diff --git') || !isset($content[$i + 1])) && !empty($operations)) {
            $context['modifications'][$counter]['operations'][$opCounter]['search'] = str_replace(array('<![CDATA[', ']]>'), array('<![CDA\' . \'TA[', ']\' . \']>'), implode("\n", $operations['search']));
            $context['modifications'][$counter]['operations'][$opCounter]['replace'] = str_replace(array('<![CDATA[', ']]>'), array('<![CDA\' . \'TA[', ']\' . \']>'), implode("\n", $operations['replace']));
            // Reset things.
            $operations = array();
            $opCounter++;
            if (string_starts_with($content[$i], 'diff --git')) {
                $dir = '';
                $counter++;
            }
            continue;
        }
        if (!empty($dir)) {
            if (string_starts_with($content[$i], ' ')) {
                $operations['replace'][] = $operations['search'][] = substr($content[$i], 1);
            }
            if (string_starts_with($content[$i], '-')) {
                $operations['search'][] = substr($content[$i], 1);
            } elseif (string_starts_with($content[$i], '+')) {
                $operations['replace'][] = substr($content[$i], 1);
            }
        }
    }
    if (!empty($context['modifications'])) {
        write_mod_xml();
    }
}
Пример #17
0
function add_user($username, $isadmin = FALSE, $password = '')
{
    if (!$password) {
        $password = bin2hex(openssl_random_pseudo_bytes(32));
    }
    if (!string_starts_with($password, '$6$')) {
        $salt = bin2hex(openssl_random_pseudo_bytes(16));
        $password = crypt($password, '$6$' . $salt);
    }
    $db = get_db();
    $q = $db->prepare('INSERT INTO users (emailaddress, password, isadmin) VALUES (?, ?, ?)');
    $q->bindValue(1, $username, SQLITE3_TEXT);
    $q->bindValue(2, $password, SQLITE3_TEXT);
    $q->bindValue(3, (int) (bool) $isadmin, SQLITE3_INTEGER);
    $ret = $q->execute();
    $db->close();
    return $ret;
}
Пример #18
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;
 }
Пример #19
0
 function extractHeaders(&$content, &$markup, $backlink = 0, $counter = 0, $levels = false, $firstlevelstyle = 'number', $basepage = '')
 {
     if (!$levels) {
         $levels = array(1, 2);
     }
     $tocCounter = $this->_initTocCounter();
     reset($levels);
     sort($levels);
     $headers = array();
     $j = 0;
     $insidetable = false;
     for ($i = 0; $i < count($content); $i++) {
         if (preg_match('/^\\s*{\\|/', $content[$i])) {
             $insidetable = true;
             continue;
         }
         if (preg_match('/^\\s*\\|}/', $content[$i])) {
             $insidetable = false;
             continue;
         }
         if ($insidetable) {
             continue;
         }
         foreach ($levels as $level) {
             if ($level < 1 or $level > 5) {
                 continue;
             }
             $phpwikiclassiclevel = 4 - $level;
             $wikicreolelevel = $level + 1;
             $trim = trim($content[$i]);
             if (strpos($trim, '=') === 0 && preg_match('/^\\s*(={' . $wikicreolelevel . ',' . $wikicreolelevel . '})([^=].*)$/', $content[$i], $match) or strpos($trim, '!') === 0 && preg_match('/^\\s*(!{' . $phpwikiclassiclevel . ',' . $phpwikiclassiclevel . '})([^!].*)$/', $content[$i], $match)) {
                 $this->_tocCounter($tocCounter, $level);
                 if (!strstr($content[$i], '#[')) {
                     $s = trim($match[2]);
                     // If it is Wikicreole syntax, remove '='s at the end
                     if (string_starts_with($match[1], "=")) {
                         $s = trim($s, "=");
                         $s = trim($s);
                     }
                     $anchor = $this->_nextAnchor($s);
                     $manchor = MangleXmlIdentifier($anchor);
                     $texts = $s;
                     if ($counter) {
                         $texts = $this->_getCounter($tocCounter, $level, $firstlevelstyle) . ' ' . $s;
                     }
                     $headers[] = array('text' => $texts, 'anchor' => $anchor, 'level' => $level);
                     // Change original wikitext, but that is useless art...
                     $content[$i] = $match[1] . " #[|{$manchor}][{$s}|#TOC]";
                     // And now change the to be printed markup (XmlTree):
                     // Search <hn>$s</hn> line in markup
                     /* Url for backlink */
                     $url = WikiURL(new WikiPageName($basepage, false, "TOC"));
                     $j = $this->searchHeader($markup->_content, $j, $s, $match[1], $hstart, $hend, $markup->_basepage);
                     if ($j and isset($markup->_content[$j])) {
                         $x = $markup->_content[$j];
                         $qheading = $this->_quote($s);
                         if ($counter) {
                             $counterString = $this->_getCounter($tocCounter, $level, $firstlevelstyle);
                         }
                         if ($hstart === 0 && is_string($markup->_content[$j])) {
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "<a href=\"{$url}\" id=\"{$manchor}\">{$counterString}</a> - \$2";
                                 } else {
                                     $anchorString = "<a href=\"{$url}\" id=\"{$manchor}\">\$2</a>";
                                 }
                             } else {
                                 $anchorString = "<a id=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             if ($x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$2\$3", $x, 1)) {
                                 if ($backlink) {
                                     $x = preg_replace('/(<h\\d>)(' . $qheading . ')(<\\/h\\d>)/', "\$1{$anchorString}\$3", $markup->_content[$j], 1);
                                 }
                                 $markup->_content[$j] = $x;
                             }
                         } else {
                             $x = $markup->_content[$hstart];
                             $h = $this->_getHeader($match[1]);
                             if ($backlink) {
                                 if ($counter) {
                                     $anchorString = "\$1<a href=\"{$url}\" id=\"{$manchor}\">{$counterString}</a> - ";
                                 } else {
                                     /* Not possible to make a backlink on a
                                      * title with a WikiWord */
                                     $anchorString = "\$1<a id=\"{$manchor}\"></a>";
                                 }
                             } else {
                                 $anchorString = "\$1<a id=\"{$manchor}\"></a>";
                                 if ($counter) {
                                     $anchorString .= "{$counterString} - ";
                                 }
                             }
                             $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $x, 1);
                             if ($backlink) {
                                 $x = preg_replace("/(<{$h}>)(?!.*<\\/{$h}>)/", $anchorString, $markup->_content[$hstart], 1);
                             }
                             $markup->_content[$hstart] = $x;
                         }
                     }
                 }
             }
         }
     }
     return $headers;
 }
Пример #20
0
function LinkBracketLink($bracketlink)
{
    // $bracketlink will start and end with brackets; in between will
    // be either a page name, a URL or both separated by a pipe.
    $wikicreolesyntax = false;
    if (string_starts_with($bracketlink, "[[") or string_starts_with($bracketlink, "#[[")) {
        $wikicreolesyntax = true;
        $bracketlink = str_replace("[[", "[", $bracketlink);
        $bracketlink = str_replace("]]", "]", $bracketlink);
    }
    // Strip brackets and leading space
    // bug#1904088  Some brackets links on 2 lines cause the parser to crash
    preg_match('/(\\#?) \\[\\s* (?: (.*?) \\s* (?<!' . ESCAPE_CHAR . ')(\\|) )? \\s* (.+?) \\s*\\]/x', str_replace("\n", " ", $bracketlink), $matches);
    if (count($matches) < 4) {
        // "[ personal\ninformation manager | PhpWiki:PersonalWiki ]"
        trigger_error(_("Invalid [] syntax ignored") . ": " . $bracketlink, E_USER_WARNING);
        return new Cached_Link();
    }
    list(, $hash, $label, $bar, $rawlink) = $matches;
    if ($wikicreolesyntax and $label) {
        $temp = $label;
        $label = $rawlink;
        $rawlink = $temp;
    }
    // Mediawiki compatibility: allow "Image:" and "File:"
    // as synonyms of "Upload:"
    if (string_starts_with($rawlink, "Image:")) {
        $rawlink = str_replace("Image:", "Upload:", $rawlink);
    }
    if (string_starts_with($rawlink, "File:")) {
        $rawlink = str_replace("File:", "Upload:", $rawlink);
    }
    $label = UnWikiEscape($label);
    /*
     * Check if the user has typed a explicit URL. This solves the
     * problem where the URLs have a ~ character, which would be stripped away.
     *   "[http:/server/~name/]" will work as expected
     *   "http:/server/~name/"   will NOT work as expected, will remove the ~
     */
    if (string_starts_with($rawlink, "http://") or string_starts_with($rawlink, "https://")) {
        $link = $rawlink;
        // Mozilla Browser URI Obfuscation Weakness 2004-06-14
        //   http://www.securityfocus.com/bid/10532/
        //   goodurl+"%2F%20%20%20."+badurl
        if (preg_match("/%2F(%20)+\\./i", $rawlink)) {
            $rawlink = preg_replace("/%2F(%20)+\\./i", "%2F.", $rawlink);
        }
    } else {
        $link = UnWikiEscape($rawlink);
    }
    /* Relatives links by Joel Schaubert.
     * Recognize [../bla] or [/bla] as relative links, without needing http://
     * but [ /link ] only if SUBPAGE_SEPERATOR is not "/".
     * Normally /Page links to the subpage /Page.
     */
    if (SUBPAGE_SEPARATOR == '/') {
        if (preg_match('/^\\.\\.\\//', $link)) {
            return new Cached_ExternalLink($link, $label);
        }
    } else {
        if (preg_match('/^(\\.\\.\\/|\\/)/', $link)) {
            return new Cached_ExternalLink($link, $label);
        }
    }
    // Handle "[[SandBox|{{image.jpg}}]]" and "[[SandBox|{{image.jpg|alt text}}]]"
    if (string_starts_with($label, "{{")) {
        $imgurl = substr($label, 2, -2);
        // Remove "{{" and "}}"
        $pipe = strpos($imgurl, '|');
        if ($pipe === false) {
            $label = LinkImage(getUploadDataPath() . $imgurl, $link);
        } else {
            list($img, $alt) = explode("|", $imgurl);
            $label = LinkImage(getUploadDataPath() . $img, $alt);
        }
    } else {
        // [label|link]
        // If label looks like a url to an image or object, we want an image link.
        if (isImageLink($label)) {
            $imgurl = $label;
            $intermap = getInterwikiMap();
            if (preg_match("/^" . $intermap->getRegexp() . ":/", $label)) {
                $imgurl = $intermap->link($label);
                $imgurl = $imgurl->getAttr('href');
            } elseif (!preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $imgurl)) {
                // local theme linkname like 'images/next.gif'.
                global $WikiTheme;
                $imgurl = $WikiTheme->getImageURL($imgurl);
            }
            // for objects (non-images) the link is taken as alt tag,
            // which is in return taken as alternative img
            $label = LinkImage($imgurl, $link);
        }
    }
    if ($hash) {
        // It's an anchor, not a link...
        $id = MangleXmlIdentifier($link);
        return HTML::a(array('name' => $id, 'id' => $id), $bar ? $label : $link);
    }
    if (preg_match("#^(" . ALLOWED_PROTOCOLS . "):#", $link)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (isImageLink($link) and empty($label)) {
            // patch #1348996 by Robert Litwiniec
            return LinkImage($link, $label);
        } else {
            return new Cached_ExternalLink($link, $label);
        }
    } elseif (substr($link, 0, 8) == 'phpwiki:') {
        return new Cached_PhpwikiURL($link, $label);
    } elseif (preg_match("/^ (\\w+) (:[:=]) (.*) \$/x", $link) and !isImageLink($link)) {
        return new Cached_SemanticLink($link, $label);
    } elseif (substr($link, 0, 1) == ':') {
        return new Cached_WikiLink($link, $label);
    } elseif (strstr($link, ':') and $intermap = getInterwikiMap() and preg_match("/^" . $intermap->getRegexp() . ":/", $link)) {
        // trigger_error("label: $label link: $link", E_USER_WARNING);
        if (empty($label) and isImageLink($link)) {
            // if without label => inlined image [File:xx.gif]
            $imgurl = $intermap->link($link);
            return LinkImage($imgurl->getAttr('href'), $link);
        }
        return new Cached_InterwikiLink($link, $label);
    } else {
        // Split anchor off end of pagename.
        if (preg_match('/\\A(.*)(?<!' . ESCAPE_CHAR . ')#(.*?)\\Z/', $rawlink, $m)) {
            list(, $rawlink, $anchor) = $m;
            $pagename = UnWikiEscape($rawlink);
            $anchor = UnWikiEscape($anchor);
            if (!$label) {
                $label = $link;
            }
        } else {
            $pagename = $link;
            $anchor = false;
        }
        return new Cached_WikiLink($pagename, $label, $anchor);
    }
}
Пример #21
0
 function _findData($file, $missing_okay = false)
 {
     if (!string_starts_with($file, "themes")) {
         // common case
         $path = $this->_findFile($file, $missing_okay);
     } else {
         // _findButton only
         if (file_exists($file)) {
             $path = $file;
         } elseif (defined('DATA_PATH') and file_exists(DATA_PATH . "/{$file}")) {
             $path = $file;
         } else {
             // fallback for buttons in parent themes
             $path = $this->_findFile($file, $missing_okay);
         }
     }
     if (!$path) {
         return false;
     }
     if (!DEBUG) {
         $min = preg_replace("/\\.(css|js)\$/", "-min.\\1", $file);
         if ($min and $x = $this->_findFile($min, true)) {
             $path = $x;
         }
     }
     if (defined('DATA_PATH')) {
         return DATA_PATH . "/{$path}";
     }
     return $path;
 }
?>

        <?php 
echo awpcp_form_fields()->render_fields($form, $errors, isset($listing) ? $listing : null, array('category' => $form['ad_category'], 'action' => 'normal'));
?>

        <?php 
if ($ui['terms-of-service']) {
    ?>
        <p class="awpcp-form-spacer">
        <?php 
    $text = get_awpcp_option('tos');
    ?>

        <?php 
    if (string_starts_with($text, 'http://', false) || string_starts_with($text, 'https://', false)) {
        ?>
            <a href="<?php 
        echo esc_attr($text);
        ?>
" target="_blank"><?php 
        echo esc_html(_x("Read our Terms of Service", 'ad details form', "AWPCP"));
        ?>
</a>
        <?php 
    } else {
        ?>
            <label><?php 
        echo esc_html(_x('Terms of service:', 'ad details form', 'AWPCP'));
        echo $required['terms-of-service'] ? '*' : '';
        ?>
Пример #23
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);
     }
 }