function markup($match, $body) { if (substr($match, 1, 4) == 'abbr') { $tag = 'abbr'; } else { $tag = 'acronym'; } $rest = substr($match, 1 + strlen($tag), -1); $attrs = parse_attributes($rest); // Remove attributes other than title and lang $allowedargs = array(); foreach ($attrs as $key => $value) { if (in_array($key, array("title", "lang"))) { $allowedargs[$key] = $value; } } return new HtmlElement($tag, $allowedargs, $body); }
function run($dbi, $argstr, &$request, $basepage) { include_once "lib/BlockParser.php"; // MediawikiTablePlugin markup is new. $markup = 2.0; // We allow the compact Mediawiki syntax with: // - multiple cells on the same line (separated by "||"), // - multiple header cells on the same line (separated by "!!"). $argstr = str_replace("||", "\n| ", $argstr); $argstr = str_replace("!!", "\n! ", $argstr); $lines = preg_split('/\\n/', $argstr); $table = HTML::table(); // We always generate an Id for the table. // This is convenient for tables of class "sortable". // If user provides an Id, the generated Id will be overwritten below. $table->setAttr("id", GenerateId("MediawikiTable")); if (substr($lines[0], 0, 2) == "{|") { // Start of table $lines[0] = substr($lines[0], 2); } if ($lines[0][0] != '|' and $lines[0][0] != '!') { $line = array_shift($lines); $attrs = parse_attributes($line); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } if (count($lines) == 1) { // empty table, we only have closing "|}" line return HTML::raw(''); } foreach ($lines as $line) { if (substr($line, 0, 2) == "|}") { // End of table continue; } if (substr($line, 0, 2) == "|-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); unset($cell); } if (isset($thead)) { $thead->pushContent($row); $table->pushContent($thead); unset($thead); $tbody = HTML::tbody(); } else { $tbody->pushContent($row); } } $row = HTML::tr(); $attrs = parse_attributes(substr($line, 2)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } // Table summary if (substr($line, 0, 2) == "|=") { $line = substr($line, 2); $table->setAttr("summary", trim($line)); } // Table caption if (substr($line, 0, 2) == "|+") { $caption = HTML::caption(); $line = substr($line, 2); $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe)) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "align", "lang"))) { $caption->setAttr($key, $value); } } $line = substr($line, $pospipe + 1); } $caption->pushContent(trim($line)); $table->pushContent($caption); } if ((substr($line, 0, 1) == "|" or substr($line, 0, 1) == "!") and isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } unset($content); } $row->pushContent($cell); } if (substr($line, 0, 1) == "!") { $cell = HTML::th(); // Header $thead = HTML::thead(); } else { $cell = HTML::td(); if (!isset($tbody)) { $tbody = HTML::tbody(); } } $line = substr($line, 1); // If there is a "|" in the line, the start of line // (before the "|") is made of attributes. // The end of the line (after the "|") is the cell content // This is not true if the pipe is inside [], {{}} or {{{}}} // | [foo|bar] // The following cases must work: // | foo // | [foo|bar] // | class="xxx" | foo // | class="xxx" | [foo|bar] // | {{tmpl|arg=val}} // | {{image.png|alt}} // | {{{ xxx | yyy }}} $pospipe = strpos($line, "|"); $posbracket = strpos($line, "["); $poscurly = strpos($line, "{"); if ($pospipe !== false && ($posbracket === false || $posbracket > $pospipe) && ($poscurly === false || $poscurly > $pospipe)) { $attrs = parse_attributes(substr($line, 0, $pospipe)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } $line = substr($line, $pospipe + 1); if (is_numeric(trim($line))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($line))); } else { $cell->pushContent(TransformText(trim($line), $markup, $basepage)); } continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\\>", "?>", $line); $line = str_replace("\\~", "~", $line); if (empty($content)) { $content = ''; } $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText(trim($content), $markup, $basepage)); } } $row->pushContent($cell); } $tbody->pushContent($row); $table->pushContent($tbody); } return $table; }
/** * Creates a valid attribute array from either a string or an array * * @param string|array $attributes Array of attributes or HTML attribute string * * @return array An associative array of attributes * * @deprecated Don't use. */ function prepare_attributes($attributes) { $prepared = array(); if (is_string($attributes)) { return parse_attributes($attributes); } elseif (is_array($attributes)) { foreach ($attributes as $key => $value) { if (is_int($key)) { $key = strtolower($value); $prepared[$key] = $key; } else { $prepared[strtolower($key)] = (string) $value; } } } return $prepared; }
/** * Take a string and return an array of pairs (attribute name, attribute value) * * We allow attributes with or without double quotes (") * Attribute-value pairs may be separated by space or comma * Space is normal HTML attributes, comma is for RichTable compatibility * border=1, cellpadding="5" * border=1 cellpadding="5" * style="font-family: sans-serif; border-top:1px solid #dddddd;" * style="font-family: Verdana, Arial, Helvetica, sans-serif" */ function parse_attributes($line) { $options = array(); if (empty($line)) { return $options; } $line = trim($line); if (empty($line)) { return $options; } $line = trim($line, ","); if (empty($line)) { return $options; } // First we have an attribute name. $attribute = ""; $value = ""; $i = 0; while ($i < strlen($line) && $line[$i] != '=') { $i++; } $attribute = substr($line, 0, $i); $attribute = strtolower($attribute); $line = substr($line, $i + 1); $line = trim($line); $line = trim($line, "="); $line = trim($line); if (empty($line)) { return $options; } // Then we have the attribute value. $i = 0; // Attribute value might be between double quotes // In that case we have to find the closing double quote if ($line[0] == '"') { $i++; // skip first '"' while ($i < strlen($line) && $line[$i] != '"') { $i++; } $value = substr($line, 0, $i); $value = trim($value, '"'); $value = trim($value); // If there are no double quotes, we have to find the next space or comma } else { while ($i < strlen($line) && ($line[$i] != ' ' && $line[$i] != ',')) { $i++; } $value = substr($line, 0, $i); $value = trim($value); $value = trim($value, ","); $value = trim($value); } $options[$attribute] = $value; $line = substr($line, $i + 1); $line = trim($line); $line = trim($line, ","); $line = trim($line); return $options + parse_attributes($line); }
function wakka2callback($things) { $thing = $things[0]; $result = ''; $valid_filename = ''; static $oldIndentLevel = 0; static $oldIndentLength = 0; static $indentClosers = array(); static $newIndentSpace = array(); static $br = 1; static $trigger_table = 0; static $trigger_rowgroup = 0; static $trigger_colgroup = 0; static $trigger_bold = 0; static $trigger_italic = 0; static $trigger_underline = 0; static $trigger_monospace = 0; static $trigger_notes = 0; static $trigger_strike = 0; static $trigger_inserted = 0; static $trigger_deleted = 0; static $trigger_floatl = 0; static $trigger_floatr = 0; static $trigger_keys = 0; static $trigger_strike = 0; static $trigger_center = 0; static $trigger_l = array(-1, 0, 0, 0, 0, 0); static $output = ''; static $invalid = ''; static $curIndentType; global $wakka; // @@@ inline elements should be closed before block-level elements // (see ImprovedFormatter solution again) // TEST: are indents closed at end of page now??? (see... again) // @@@ <kbd> is missing if (!is_array($things) && $things == 'closetags') { $result = ''; if (3 < $trigger_table) { $result .= '</caption>'; } elseif (2 < $trigger_table) { $result .= '</th></tr>'; } elseif (1 < $trigger_table) { $result .= '</td></tr>'; } if (2 < $trigger_rowgroup) { $result .= '</tbody>'; } elseif (1 < $trigger_rowgroup) { $result .= '</tfoot>'; } elseif (0 < $trigger_rowgroup) { $result .= '</thead>'; } if (0 < $trigger_table) { $result .= '</table>'; } if ($trigger_strike % 2) { $result .= '</span>'; } if ($trigger_notes % 2) { $result .= '</span>'; } if ($trigger_inserted % 2) { $result .= '</ins>'; } if ($trigger_deleted % 2) { $result .= '</del>'; } if ($trigger_underline % 2) { $result .= '</span>'; } if ($trigger_floatl % 2) { $result .= '</div>'; } if ($trigger_floatr % 2) { $result .= '</div>'; } if ($trigger_center % 2) { $result .= '</div>'; } if ($trigger_italic % 2) { $result .= '</em>'; } if ($trigger_monospace % 2) { $result .= '</tt>'; } if ($trigger_bold % 2) { $result .= '</strong>'; } for ($i = 1; $i <= 5; $i++) { if ($trigger_l[$i] % 2) { $result .= "</h{$i}>"; } } $trigger_bold = $trigger_center = $trigger_floatl = $trigger_floatr = $trigger_inserted = $trigger_deleted = $trigger_italic = $trigger_keys = $trigger_table = 0; $trigger_l = array(-1, 0, 0, 0, 0, 0); $trigger_monospace = $trigger_notes = $trigger_strike = $trigger_underline = 0; return $result; } elseif (preg_match("/^\\|\\|\n\$/", $thing, $matches) && $trigger_table == 1) { return ''; } elseif (preg_match("/^\\|([^\\|])?\\|(\\(.*?\\))?(\\{.*?\\})?(\n)?\$/", $thing, $matches)) { for ($i = 1; $i < 5; $i++) { if (!isset($matches[$i])) { $matches[$i] = ''; } } //Set up the variables that will aggregate the html markup $close_part = ''; $open_part = ''; $linebreak_after_open = ''; $selfclose = ''; // $trigger_table == 0 means no table, 1 means in table but no cell, 2 is in datacell, 3 is in headercell, 4 is in caption. //If we have parsed the caption, close it, set trigger = 1 and return. if ($trigger_table == 4) { $close_part = '</caption>' . "\n"; $trigger_table = 1; return $close_part; } //If we have parsed a cell - close it, go on to open new. if ($trigger_table == 3) { $close_part = '</th>'; } elseif ($trigger_table == 2) { $close_part = '</td>'; } elseif ($trigger_table == 1 || $matches[1] == '!') { $close_part = ''; } else { //This is actually opening the table (i.e. nothing at all to close). Go on to open a cell. $trigger_table = 1; $close_part = '<table class="data">' . "\n"; } //If we are in a cell and there is a linebreak - then it is end of row. if ($trigger_table > 1 && $matches[4] == "\n") { $trigger_table = 1; return $close_part .= '</tr>' . "\n"; //Can return here, it is closed- } //If we were in a colgroup and there is a linebreak, then it is the end. if ($trigger_colgroup == 1 && $matches[4] == "\n") { $trigger_colgroup = 0; return $close_part .= '</colgroup>' . "\n"; //Can return here, it is closed- } //We want to start a new table, and most likely have attributes to parse. //TODO: Need to find out if class="data" should be auto added, and if so - put it in the attribute list to add up. if ($matches[1] == '!') { $trigger_table = 1; $open_part = '<table class="data"'; $linebreak_after_open = "\n"; } elseif ($matches[1] == '?') { $trigger_table = 4; $open_part = '<caption'; } elseif ($matches[1] == '#' || $matches[1] == '[' || $matches[1] == ']') { //If we're here, we want to close any open rowgroup. if (2 < $trigger_rowgroup) { $close_part .= '</tbody>' . "\n"; } elseif (1 < $trigger_rowgroup) { $close_part .= '</tfoot>' . "\n"; } elseif (0 < $trigger_rowgroup) { $close_part .= '</thead>' . "\n"; } //Then open the appropriate rowgroup. if ($matches[1] == '[') { $open_part .= '<thead'; $trigger_rowgroup = 1; } elseif ($matches[1] == ']') { $open_part .= '<tfoot'; $trigger_rowgroup = 2; } else { $open_part .= '<tbody'; $trigger_rowgroup = 3; } $linebreak_after_open = "\n"; } elseif ($matches[1] == '_') { //close any open colgroup if ($trigger_colgroup == 1) { $close_part .= '</colgroup>' . "\n"; } $trigger_colgroup = 1; $open_part .= '<colgroup'; } elseif ($matches[1] == '-') { $open_part .= '<col'; $selfclose = ' /'; if ($matches[4]) { $linebreak_after_open = "\n"; } } else { $open_part = ''; //Need a tbody if no other rowgroup open. if ($trigger_rowgroup == 0) { $open_part .= '<tbody>' . "\n"; $trigger_rowgroup = 3; } //If no row, open a new one. if ($trigger_table == 1) { $open_part .= '<tr>'; } //Header cell. if ($matches[1] == '=') { $trigger_table = 3; $open_part .= '<th'; } else { $trigger_table = 2; $open_part .= '<td'; } } //If attributes... if (preg_match("/\\((.*)\\)/", $matches[2], $attribs)) { // $hints = array('core' => 'core', 'i18n' => 'i18n'); $hints = array(); //allow / disallow different attribute keys. (ie. data/header cell only. if ($trigger_table == 2 || $trigger_table == 3) { $hints['cell'] = 'cell'; } else { $hints['other_table'] = 'other_table'; } $open_part .= parse_attributes($attribs[1], $hints); } //If styles, just make attribute of it and parse again. if (preg_match("/\\{(.*)\\}/", $matches[3], $attribs)) { $attribs = "s:" . $attribs[1]; $open_part .= parse_attributes($attribs, array()); } //the variable $selfclose is "/" if this is a <col/> element. $open_part .= $selfclose . '>'; return $close_part . $open_part . $linebreak_after_open; } else { if ($trigger_table == 1) { $close_part = ''; if (2 < $trigger_rowgroup) { $close_part .= '</tbody>' . "\n"; } elseif (1 < $trigger_rowgroup) { $close_part .= '</tfoot>' . "\n"; } elseif (0 < $trigger_rowgroup) { $close_part .= '</thead>' . "\n"; } $close_part .= '</table>' . "\n"; $trigger_table = $trigger_rowgroup = 0; //And remember to parse what we got. return $close_part . wakka2callback($things); } } // convert HTML thingies if ($thing == "<") { return "<"; } elseif ($thing == ">") { return ">"; } elseif ($thing == "<<") { return ++$trigger_floatl % 2 ? '<div class="floatl">' : '</div>'; } elseif ($thing == ">>") { return ++$trigger_floatr % 2 ? '<div class="floatr">' : '</div>'; } elseif ($thing == "::c::") { return "<div class=\"clear\"> </div>\n"; } elseif ($thing == "#%") { return ++$trigger_keys % 2 ? "<kbd class=\"keys\">" : "</kbd>"; } elseif ($thing == "**") { return ++$trigger_bold % 2 ? "<strong>" : "</strong>"; } elseif ($thing == "//") { return ++$trigger_italic % 2 ? "<em>" : "</em>"; } elseif ($thing == "__") { return ++$trigger_underline % 2 ? "<span class=\"underline\">" : "</span>"; } elseif ($thing == "##") { return ++$trigger_monospace % 2 ? "<tt>" : "</tt>"; } elseif ($thing == "''") { return ++$trigger_notes % 2 ? "<span class=\"notes\">" : "</span>"; } elseif ($thing == "++") { return ++$trigger_strike % 2 ? "<span class=\"strikethrough\">" : "</span>"; } elseif ($thing == "££") { return ++$trigger_inserted % 2 ? "<ins>" : "</ins>"; } elseif ($thing == "¥¥") { return ++$trigger_deleted % 2 ? "<del>" : "</del>"; } elseif ($thing == "@@") { return ++$trigger_center % 2 ? "<div class=\"center\">\n" : "\n</div>\n"; } elseif (preg_match("/^([a-z]+:\\/\\/[[:alnum:]\\/?;:@&=\\.]+[[:alnum:]\\/])(.*)\$/", $thing, $matches)) { $url = $matches[1]; /* Inline images are disabled for security reason, use {{image action}} #142 But if you still need this functionality, update this file like below if (preg_match("/\.(gif|jpg|png|svg)$/si", $url)) { return '<img src="'.$wakka->Link($url).'" alt="image" />'.$wakka->htmlspecialchars_ent($matches[2]); } else */ // Mind Mapping Mod if (preg_match("/\\.(mm)\$/si", $url)) { #145 return $wakka->Action("mindmap " . $url); } else { return $wakka->Link($url) . (isset($matches[2]) ? $matches[2] : ''); } #38 } elseif ($thing == "==") { $br = 0; return ++$trigger_l[5] % 2 ? "<h5>" : "</h5>\n"; } elseif ($thing == "===") { $br = 0; return ++$trigger_l[4] % 2 ? "<h4>" : "</h4>\n"; } elseif ($thing == "====") { $br = 0; return ++$trigger_l[3] % 2 ? "<h3>" : "</h3>\n"; } elseif ($thing == "=====") { $br = 0; return ++$trigger_l[2] % 2 ? "<h2>" : "</h2>\n"; } elseif ($thing == "======") { $br = 0; return ++$trigger_l[1] % 2 ? "<h1>" : "</h1>\n"; } elseif ($thing == "---") { return "<br />"; } elseif (preg_match("/^\"\"(.*)\"\"\$/s", $thing, $matches)) { $ddquotes_policy = $wakka->GetConfigValue("double_doublequote_html"); $embedded = $matches[1]; if ($ddquotes_policy == 'safe' || $ddquotes_policy == 'raw') { // get tags with id attributes # use backref to match both single and double quotes $patTagWithId = '((<[a-z][^>]*)((?<=\\s)id=("|\')(.*?)\\4)(.*?>))'; // @@@ #34 // with PREG_SET_ORDER we get an array for each match: easy to use with list()! // we do the match case-insensitive so we catch uppercase HTML as well; // SafeHTML will treat this but 'raw' may end up with invalid code! $tags2 = preg_match_all('/' . $patTagWithId . '/i', $embedded, $matches2, PREG_SET_ORDER); // step through code, replacing tags with ids with tags with new ('repaired') ids $tmpembedded = $embedded; $newembedded = ''; for ($i = 0; $i < $tags2; $i++) { list(, $tag, $tagstart, $attrid, $quote, $id, $tagend) = $matches2[$i]; # $attrid not needed, just for clarity $parts = explode($tag, $tmpembedded, 2); # split in two at matched tag if ($id != ($newid = $wakka->makeId('embed', $id))) { $tag = $tagstart . 'id=' . $quote . $newid . $quote . $tagend; } $newembedded .= $parts[0] . $tag; # append (replacement) tag to first part $tmpembedded = $parts[1]; # after tag: next bit to handle } $newembedded .= $tmpembedded; # add last part } switch ($ddquotes_policy) { case 'safe': return $wakka->ReturnSafeHTML($newembedded); case 'raw': return $newembedded; # may still be invalid code - 'raw' will not be corrected! # may still be invalid code - 'raw' will not be corrected! default: return $wakka->htmlspecialchars_ent($embedded); # display only } } elseif (preg_match("/^%%(.*?)%%\$/s", $thing, $matches)) { /* * Note: this routine is rewritten such that (new) language formatters * will automatically be found, whether they are GeSHi language config files * or "internal" Wikka formatters. * Path to GeSHi language files and Wikka formatters MUST be defined in config. * For line numbering (GeSHi only) a starting line can be specified after the language * code, separated by a ; e.g., %%(php;27)....%%. * Specifying >= 1 turns on line numbering if this is enabled in the configuration. * An optional filename can be specified as well, e.g. %%(php;27;myfile.php)....%% * This filename will be used by the grabcode handler. */ $output = ''; //reinitialize variables $filename = ''; $valid_filename = ''; $code = $matches[1]; // if configuration path isn't set, make sure we'll get an invalid path so we // don't match anything in the home directory $geshi_hi_path = isset($wakka->config['geshi_languages_path']) ? $wakka->config['geshi_languages_path'] : '/:/'; $wikka_hi_path = isset($wakka->config['wikka_highlighters_path']) ? $wakka->config['wikka_highlighters_path'] : '/:/'; // check if a language (and an optional starting line or filename) has been specified if (preg_match('/^' . PATTERN_OPEN_BRACKET . PATTERN_FORMATTER . PATTERN_LINE_NUMBER . PATTERN_FILENAME . PATTERN_CLOSE_BRACKET . PATTERN_CODE . '$/s', $code, $matches)) { list(, $language, , $start, , $filename, $invalid, $code) = $matches; } // get rid of newlines at start and end (and preceding/following whitespace) // Note: unlike trim(), this preserves any tabs at the start of the first "real" line $code = preg_replace('/^\\s*\\n+|\\n+\\s*$/', '', $code); // check if GeSHi path is set and we have a GeSHi highlighter for this language if (isset($language) && isset($wakka->config['geshi_path']) && file_exists($geshi_hi_path . DIRECTORY_SEPARATOR . $language . '.php')) { // check if specified filename is valid and generate code block header if (isset($filename) && strlen($filename) > 0 && strlen($invalid) == 0) { $valid_filename = $filename; // create code block header $output .= '<div class="code_header">'; // display filename and start line, if specified $output .= $filename; if (strlen($start) > 0) { $output .= ' (line ' . $start . ')'; } $output .= '</div>' . "\n"; } // use GeSHi for highlighting $output .= $wakka->GeSHi_Highlight($code, $language, $start); } elseif (isset($language) && isset($wakka->config['wikka_formatter_path']) && file_exists($wikka_hi_path . DIRECTORY_SEPARATOR . $language . '.php') && 'wakka' != $language) { // use internal Wikka highlighter $output = '<div class="code">' . "\n"; $output .= $wakka->Format($code, $language); $output .= "</div>\n"; } else { $output = '<div class="code">' . "\n"; $output .= $wakka->Format($code, 'code'); $output .= "</div>\n"; } // display grab button if option is set in the config file if ($wakka->GetConfigValue('grabcode_button') == '1') { $output .= $wakka->FormOpen("grabcode"); // build form $output .= '<input type="submit" class="grabcode" name="save" value="' . GRABCODE_BUTTON . '" title="' . rtrim(sprintf(GRABCODE_BUTTON_TITLE, $valid_filename)) . '" />'; $output .= '<input type="hidden" name="filename" value="' . urlencode($valid_filename) . '" />'; $output .= '<input type="hidden" name="code" value="' . urlencode($code) . '" />'; $output .= $wakka->FormClose(); } // output return $output; } else { if (preg_match("/^\\[\\[([\\S|\\.|\\/]*)(\\s+(.+))?\\]\\]\$/s", $thing, $matches)) { if (!isset($matches[1])) { $matches[1] = ''; } #38 if (!isset($matches[3])) { $matches[3] = ''; } #38 list(, $url, , $text) = $matches; if ($url) { //if ($url!=($url=(preg_replace("/@@|££||\[\[/","",$url))))$result="</span>"; $link = $wakka->Link($url, "", $text); // Hack to handle relative URIs (i.e., links to files // in the same directory) if (strstr($link, "http://.") || strstr($link, "http:///")) { $link = preg_replace("/^(.*)http:\\/\\/(.*)\$/", "\${1}\${2}", $link); } return $result . $link; } else { return ""; } } elseif (preg_match("/(^|\n)([\t~]+)(-|&|([0-9a-zA-Z]+)\\))?(\n|\$)/s", $thing, $matches)) { // new line $result .= $br ? "<br />\n" : "\n"; // we definitely want no line break in this one. $br = 0; // find out which indent type we want $newIndentType = $matches[3]; if (!$newIndentType) { $opener = "<div class=\"indent\">"; $closer = "</div>"; $br = 1; } elseif ($newIndentType == "-") { $opener = "<ul><li>"; $closer = "</li></ul>"; $li = 1; } elseif ($newIndentType == "&") { $opener = "<ul class=\"thread\"><li>"; $closer = "</li></ul>"; $li = 1; } else { if (preg_match('[0-9]', $newIndentType[0])) { $newIndentType = '1'; } elseif (preg_match('[IVX]', $newIndentType[0])) { $newIndentType = 'I'; } elseif (preg_match('[ivx]', $newIndentType[0])) { $newIndentType = 'i'; } elseif (preg_match('[A-Z]', $newIndentType[0])) { $newIndentType = 'A'; } elseif (preg_match('[a-z]', $newIndentType[0])) { $newIndentType = 'a'; } $opener = '<ol type="' . $newIndentType . '"><li>'; $closer = '</li></ol>'; $li = 1; } // get new indent level $newIndentLevel = strlen($matches[2]); if ($newIndentType != $curIndentType && $oldIndentLevel > 0) { for (; $oldIndentLevel > 0; $oldIndentLevel--) { $result .= array_pop($indentClosers); } } if ($newIndentLevel > $oldIndentLevel) { for ($i = 0; $i < $newIndentLevel - $oldIndentLevel; $i++) { $result .= $opener; array_push($indentClosers, $closer); } } elseif ($newIndentLevel < $oldIndentLevel) { for ($i = 0; $i < $oldIndentLevel - $newIndentLevel; $i++) { $result .= array_pop($indentClosers); } } $oldIndentLevel = $newIndentLevel; if (isset($li) && !preg_match("/" . str_replace(")", "\\)", $opener) . "\$/", $result)) { $result .= "</li><li>"; } $curIndentType = $newIndentType; return $result; } else { if ($thing == "\n") { // if we got here, there was no tab in the next line; this means that we can close all open indents. $c = count($indentClosers); for ($i = 0; $i < $c; $i++) { $result .= array_pop($indentClosers); $br = 0; } $oldIndentLevel = 0; $oldIndentLength = 0; $newIndentSpace = array(); $result .= $br ? "<br />\n" : "\n"; $br = 1; return $result; } elseif (preg_match("/^\\{\\{(.*?)\\}\\}\$/s", $thing, $matches)) { if ($matches[1]) { return $wakka->Action($matches[1]); } else { return "{{}}"; } } elseif (preg_match("/^[A-Zִײ�][A-Za-zִײ��הצ�]+[:]\\S*\$/s", $thing)) { return $wakka->Link($thing); } elseif (preg_match("/^[A-Zִײ�]+[a-z�הצ�]+[A-Z0-9ִײ�][A-Za-z0-9ִײ��הצ�]*\$/s", $thing)) { return $wakka->Link($thing); } elseif (preg_match("/-{4,}/", $thing, $matches)) { // TODO: This could probably be improved for situations where someone puts text on the same line as a separator. // Which is a stupid thing to do anyway! HAW HAW! Ahem. $br = 0; return "<hr />\n"; } elseif (preg_match("/^<map.*<\\/map>\$/s", $thing)) { return $wakka->Action("mindmap " . $wakka->Href() . "/mindmap.mm"); } elseif ($thing[0] == '&') { return $wakka->htmlspecialchars_ent($thing); } } } // if we reach this point, it must have been an accident. return $thing; }
function is_card_enabled($uuid, $delivery_time) { $now = time(); $filename = SimpleSAML_Utilities::getTempDir() . "/{$uuid}"; //File check if (!file_exists($filename)) { return false; } //File doesn't exist //Time check $handle = fopen($filename, 'r'); if ($handle) { $data = fread($handle, filesize($filename)); fclose($handle); $parsed_data = parse_attributes($data, 3); $parsed_data[2] = substr($parsed_data[2], 1); //Extracting numeric value $time = $parsed_data[2]; $endtime = $time + $delivery_time; if ($now <= $time || $now > $endtime) { return false; } //Incorrect time return $parsed_data; } else { return false; //Could not read the file } }
function run($dbi, $argstr, &$request, $basepage) { global $WikiTheme; include_once "lib/BlockParser.php"; // RichTablePlugin markup is new. $markup = 2.0; $lines = preg_split('/\\n/', $argstr); $table = HTML::table(); if ($lines[0][0] == '*') { $line = substr(array_shift($lines), 1); $attrs = parse_attributes($line); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "frame", "rules", "border", "cellspacing", "cellpadding", "summary", "align", "width"))) { $table->setAttr($key, $value); } } } foreach ($lines as $line) { if (substr($line, 0, 1) == "-") { if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText($content, $markup, $basepage)); } unset($content); } $row->pushContent($cell); unset($cell); } $table->pushContent($row); } $row = HTML::tr(); $attrs = parse_attributes(substr($line, 1)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "bgcolor", "align", "valign"))) { $row->setAttr($key, $value); } } continue; } if (substr($line, 0, 1) == "|" and isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText($content, $markup, $basepage)); } unset($content); } $row->pushContent($cell); } $cell = HTML::td(); $line = substr($line, 1); if ($line[0] == "*") { $attrs = parse_attributes(substr($line, 1)); foreach ($attrs as $key => $value) { if (in_array($key, array("id", "class", "title", "style", "colspan", "rowspan", "width", "height", "bgcolor", "align", "valign"))) { $cell->setAttr($key, $value); } } continue; } } if (isset($row) and isset($cell)) { $line = str_replace("?\\>", "?>", $line); $line = str_replace("\\~", "~", $line); if (empty($content)) { $content = ''; } $content .= $line . "\n"; } } if (isset($row)) { if (isset($cell)) { if (isset($content)) { if (is_numeric(trim($content))) { $cell->pushContent(HTML::p(array('style' => "text-align:right"), trim($content))); } else { $cell->pushContent(TransformText($content, $markup, $basepage)); } } $row->pushContent($cell); } $table->pushContent($row); } return $table; }