Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php final class PhutilRemarkupListBlockRule extends PhutilRemarkupBlockRule { public fu..

Decoded Output download

<?php
 final class PhutilRemarkupListBlockRule extends PhutilRemarkupBlockRule { public function getPriority() { return 400; } public function getMatchingLineCount(array $lines, $cursor) { $num_lines = 0; $first_line = $cursor; $is_one_line = false; while (isset($lines[$cursor])) { if (!$num_lines) { if (preg_match(self::START_BLOCK_PATTERN, $lines[$cursor])) { $num_lines++; $cursor++; $is_one_line = true; continue; } } else { if (preg_match(self::CONT_BLOCK_PATTERN, $lines[$cursor])) { $num_lines++; $cursor++; $is_one_line = false; continue; } $this_empty = !strlen(trim($lines[$cursor])); $this_indented = preg_match("/^ /", $lines[$cursor]); $next_empty = true; $next_indented = false; if (isset($lines[$cursor + 1])) { $next_empty = !strlen(trim($lines[$cursor + 1])); $next_indented = preg_match("/^ /", $lines[$cursor + 1]); } if ($this_empty || $this_indented) { if ($this_indented && !$this_empty || $next_indented && !$next_empty) { $num_lines++; $cursor++; continue; } } if ($this_empty) { $num_lines++; } } break; } if ($is_one_line) { if ($first_line + $num_lines < count($lines)) { if (strncmp($lines[$first_line], "#", 1) === 0) { return 0; } } } return $num_lines; } const MAXIMUM_LIST_NESTING_DEPTH = 12; const START_BLOCK_PATTERN = "@^\s*(?:[-*#]+|([1-9][0-9]*)[.)]|\[\D?\])\s+@"; const CONT_BLOCK_PATTERN = "@^\s*(?:[-*#]+|[0-9]+[.)]|\[\D?\])\s+@"; const STRIP_BLOCK_PATTERN = "@^\s*(?:[-*#]+|[0-9]+[.)])\s*@"; public function markupText($text, $children) { $items = array(); $lines = explode("
", $text); $regex = self::START_BLOCK_PATTERN; $min_space = PHP_INT_MAX; foreach ($lines as $ii => $line) { $matches = null; if (preg_match($regex, $line)) { $regex = self::CONT_BLOCK_PATTERN; if (preg_match("/^(\s+)/", $line, $matches)) { $space = strlen($matches[1]); } else { $space = 0; } $min_space = min($min_space, $space); } } $regex = self::START_BLOCK_PATTERN; if ($min_space) { foreach ($lines as $key => $line) { if (preg_match($regex, $line)) { $regex = self::CONT_BLOCK_PATTERN; $lines[$key] = substr($line, $min_space); } } } $item = array(); $starts_at = null; $regex = self::START_BLOCK_PATTERN; foreach ($lines as $line) { $match = null; if (preg_match($regex, $line, $match)) { if (!$starts_at && !empty($match[1])) { $starts_at = $match[1]; } $regex = self::CONT_BLOCK_PATTERN; if ($item) { $items[] = $item; $item = array(); } } $item[] = $line; } if ($item) { $items[] = $item; } if (!$starts_at) { $starts_at = 1; } $has_marks = false; foreach ($items as $key => $item) { $item = preg_replace("/ *(\n+) */", "\1", implode("
", $item)); $item = preg_replace("/(?<!\n)\n(?!\n)/", " ", $item); $item = rtrim($item); if (!strlen($item)) { unset($items[$key]); continue; } $matches = null; if (preg_match("/^\s*([-*#]{2,})/", $item, $matches)) { $depth = strlen($matches[1]) - 1; } else { if (preg_match("/^(\s+)/", $item, $matches)) { $depth = strlen($matches[1]); } else { $depth = 0; } } if (preg_match("/^\s*(?:#|[0-9])/", $item)) { $style = "#"; } else { $style = "-"; } $text = preg_replace(self::STRIP_BLOCK_PATTERN, '', $item); $mark = null; $matches = null; if (preg_match("/^\s*\[(\D?)\]\s*/", $text, $matches)) { if (strlen(trim($matches[1]))) { $mark = true; } else { $mark = false; } $has_marks = true; $text = substr($text, strlen($matches[0])); } $items[$key] = array("text" => $text, "depth" => $depth, "style" => $style, "mark" => $mark); } $items = array_values($items); $l = 0; $r = count($items); $tree = $this->buildTree($items, $l, $r, $cur_level = 0); $this->adjustTreeStyleInformation($tree); $out = $this->renderTree($tree, 0, $has_marks, $starts_at); if ($this->getEngine()->isTextMode()) { $out = implode('', $out); $out = rtrim($out, "
"); $out = preg_replace("/ +$/m", '', $out); return $out; } return phutil_implode_html('', $out); } private function buildTree(array $items, $l, $r, $cur_level) { if ($l == $r) { return array(); } if ($cur_level > self::MAXIMUM_LIST_NESTING_DEPTH) { $nodes = array(); for ($ii = $l; $ii < $r; $ii++) { $nodes[] = array("level" => $cur_level, "items" => array()) + $items[$ii]; } return $nodes; } $min = $l; for ($ii = $r - 1; $ii >= $l; $ii--) { if ($items[$ii]["depth"] <= $items[$min]["depth"]) { $min = $ii; } } $min_depth = $items[$min]["depth"]; $nodes = array(); if ($min != $l) { $nodes[] = array("text" => null, "level" => $cur_level, "style" => null, "mark" => null, "items" => $this->buildTree($items, $l, $min, $cur_level + 1)); } $last = $min; for ($ii = $last + 1; $ii < $r; $ii++) { if ($items[$ii]["depth"] == $min_depth) { $nodes[] = array("level" => $cur_level, "items" => $this->buildTree($items, $last + 1, $ii, $cur_level + 1)) + $items[$last]; $last = $ii; } } $nodes[] = array("level" => $cur_level, "items" => $this->buildTree($items, $last + 1, $r, $cur_level + 1)) + $items[$last]; return $nodes; } private function adjustTreeStyleInformation(array &$tree) { $style = "-"; for ($ii = count($tree) - 1; $ii >= 0; $ii--) { if ($tree[$ii]["style"] !== null) { $style = $tree[$ii]["style"]; } else { $tree[$ii]["style"] = $style; } if ($tree[$ii]["items"]) { $this->adjustTreeStyleInformation($tree[$ii]["items"]); } } } private function renderTree(array $tree, $level, $has_marks, $starts_at = 1) { $style = idx(head($tree), "style"); $out = array(); if (!$this->getEngine()->isTextMode()) { switch ($style) { case "#": $tag = "ol"; break; case "-": $tag = "ul"; break; } $start_attr = null; if (ctype_digit(phutil_string_cast($starts_at)) && $starts_at > 1) { $start_attr = hsprintf(" start="%d"", $starts_at); } if ($has_marks) { $out[] = hsprintf("<%s class="remarkup-list remarkup-list-with-checkmarks"%s>", $tag, $start_attr); } else { $out[] = hsprintf("<%s class="remarkup-list"%s>", $tag, $start_attr); } $out[] = "
"; } $number = $starts_at; foreach ($tree as $item) { if ($this->getEngine()->isTextMode()) { if ($item["text"] === null) { } else { $indent = str_repeat(" ", 2 * $level); $out[] = $indent; if ($item["mark"] !== null) { if ($item["mark"]) { $out[] = "[X] "; } else { $out[] = "[ ] "; } } else { switch ($style) { case "#": $out[] = $number . ". "; $number++; break; case "-": $out[] = "- "; break; } } $parts = preg_split("/\n{2,}/", $item["text"]); foreach ($parts as $key => $part) { if ($key != 0) { $out[] = "\xa
  " . $indent; } $out[] = $this->applyRules($part); } $out[] = "
"; } } else { if ($item["text"] === null) { $out[] = hsprintf("<li class="remarkup-list-item phantom-item">"); } else { if ($item["mark"] !== null) { if ($item["mark"] == true) { $out[] = hsprintf("<li class="remarkup-list-item remarkup-checked-item">"); } else { $out[] = hsprintf("<li class="remarkup-list-item remarkup-unchecked-item">"); } $out[] = phutil_tag("input", array("type" => "checkbox", "checked" => $item["mark"] ? "checked" : null, "disabled" => "disabled")); $out[] = " "; } else { $out[] = hsprintf("<li class="remarkup-list-item">"); } $parts = preg_split("/\n{2,}/", $item["text"]); foreach ($parts as $key => $part) { if ($key != 0) { $out[] = array("\xa", phutil_tag("br"), phutil_tag("br"), "\xa"); } $out[] = $this->applyRules($part); } } } if ($item["items"]) { $subitems = $this->renderTree($item["items"], $level + 1, $has_marks); foreach ($subitems as $i) { $out[] = $i; } } if (!$this->getEngine()->isTextMode()) { $out[] = hsprintf("</li>\xa"); } } if (!$this->getEngine()->isTextMode()) { switch ($style) { case "#": $out[] = hsprintf("</ol>"); break; case "-": $out[] = hsprintf("</ul>"); break; } } return $out; } } ?>

Did this file decode correctly?

Original Code

<?php
 final class PhutilRemarkupListBlockRule extends PhutilRemarkupBlockRule { public function getPriority() { return 400; } public function getMatchingLineCount(array $lines, $cursor) { $num_lines = 0; $first_line = $cursor; $is_one_line = false; while (isset($lines[$cursor])) { if (!$num_lines) { if (preg_match(self::START_BLOCK_PATTERN, $lines[$cursor])) { $num_lines++; $cursor++; $is_one_line = true; continue; } } else { if (preg_match(self::CONT_BLOCK_PATTERN, $lines[$cursor])) { $num_lines++; $cursor++; $is_one_line = false; continue; } $this_empty = !strlen(trim($lines[$cursor])); $this_indented = preg_match("\57\136\40\57", $lines[$cursor]); $next_empty = true; $next_indented = false; if (isset($lines[$cursor + 1])) { $next_empty = !strlen(trim($lines[$cursor + 1])); $next_indented = preg_match("\x2f\x5e\x20\x2f", $lines[$cursor + 1]); } if ($this_empty || $this_indented) { if ($this_indented && !$this_empty || $next_indented && !$next_empty) { $num_lines++; $cursor++; continue; } } if ($this_empty) { $num_lines++; } } break; } if ($is_one_line) { if ($first_line + $num_lines < count($lines)) { if (strncmp($lines[$first_line], "\43", 1) === 0) { return 0; } } } return $num_lines; } const MAXIMUM_LIST_NESTING_DEPTH = 12; const START_BLOCK_PATTERN = "\x40\x5e\134\163\52\x28\x3f\x3a\133\55\52\x23\x5d\x2b\x7c\x28\133\x31\55\x39\x5d\x5b\60\x2d\71\x5d\52\51\x5b\x2e\51\x5d\174\134\133\134\104\77\134\135\x29\x5c\x73\53\100"; const CONT_BLOCK_PATTERN = "\x40\x5e\134\x73\52\50\77\72\x5b\55\x2a\x23\x5d\x2b\174\133\60\x2d\71\135\53\x5b\x2e\51\135\x7c\134\133\x5c\x44\x3f\x5c\135\x29\134\163\53\100"; const STRIP_BLOCK_PATTERN = "\100\136\134\x73\x2a\50\x3f\72\x5b\55\52\x23\x5d\53\x7c\133\x30\x2d\71\135\53\x5b\56\x29\x5d\x29\134\163\x2a\x40"; public function markupText($text, $children) { $items = array(); $lines = explode("\12", $text); $regex = self::START_BLOCK_PATTERN; $min_space = PHP_INT_MAX; foreach ($lines as $ii => $line) { $matches = null; if (preg_match($regex, $line)) { $regex = self::CONT_BLOCK_PATTERN; if (preg_match("\57\136\50\x5c\x73\x2b\51\57", $line, $matches)) { $space = strlen($matches[1]); } else { $space = 0; } $min_space = min($min_space, $space); } } $regex = self::START_BLOCK_PATTERN; if ($min_space) { foreach ($lines as $key => $line) { if (preg_match($regex, $line)) { $regex = self::CONT_BLOCK_PATTERN; $lines[$key] = substr($line, $min_space); } } } $item = array(); $starts_at = null; $regex = self::START_BLOCK_PATTERN; foreach ($lines as $line) { $match = null; if (preg_match($regex, $line, $match)) { if (!$starts_at && !empty($match[1])) { $starts_at = $match[1]; } $regex = self::CONT_BLOCK_PATTERN; if ($item) { $items[] = $item; $item = array(); } } $item[] = $line; } if ($item) { $items[] = $item; } if (!$starts_at) { $starts_at = 1; } $has_marks = false; foreach ($items as $key => $item) { $item = preg_replace("\57\40\52\x28\134\x6e\x2b\x29\x20\52\x2f", "\x5c\x31", implode("\12", $item)); $item = preg_replace("\x2f\x28\77\x3c\41\134\156\x29\x5c\156\x28\77\41\134\x6e\x29\57", "\x20", $item); $item = rtrim($item); if (!strlen($item)) { unset($items[$key]); continue; } $matches = null; if (preg_match("\57\136\134\163\52\50\x5b\x2d\52\x23\135\173\x32\54\175\x29\x2f", $item, $matches)) { $depth = strlen($matches[1]) - 1; } else { if (preg_match("\57\136\50\x5c\x73\53\51\57", $item, $matches)) { $depth = strlen($matches[1]); } else { $depth = 0; } } if (preg_match("\57\x5e\134\163\52\50\77\72\43\x7c\133\60\55\71\135\x29\x2f", $item)) { $style = "\x23"; } else { $style = "\55"; } $text = preg_replace(self::STRIP_BLOCK_PATTERN, '', $item); $mark = null; $matches = null; if (preg_match("\x2f\136\134\x73\x2a\x5c\133\50\134\x44\77\x29\x5c\135\134\x73\52\x2f", $text, $matches)) { if (strlen(trim($matches[1]))) { $mark = true; } else { $mark = false; } $has_marks = true; $text = substr($text, strlen($matches[0])); } $items[$key] = array("\x74\145\170\164" => $text, "\x64\145\x70\x74\x68" => $depth, "\163\x74\x79\154\145" => $style, "\x6d\x61\x72\153" => $mark); } $items = array_values($items); $l = 0; $r = count($items); $tree = $this->buildTree($items, $l, $r, $cur_level = 0); $this->adjustTreeStyleInformation($tree); $out = $this->renderTree($tree, 0, $has_marks, $starts_at); if ($this->getEngine()->isTextMode()) { $out = implode('', $out); $out = rtrim($out, "\12"); $out = preg_replace("\x2f\40\x2b\44\57\x6d", '', $out); return $out; } return phutil_implode_html('', $out); } private function buildTree(array $items, $l, $r, $cur_level) { if ($l == $r) { return array(); } if ($cur_level > self::MAXIMUM_LIST_NESTING_DEPTH) { $nodes = array(); for ($ii = $l; $ii < $r; $ii++) { $nodes[] = array("\154\145\166\145\154" => $cur_level, "\151\164\145\x6d\163" => array()) + $items[$ii]; } return $nodes; } $min = $l; for ($ii = $r - 1; $ii >= $l; $ii--) { if ($items[$ii]["\x64\x65\160\x74\150"] <= $items[$min]["\x64\x65\160\164\150"]) { $min = $ii; } } $min_depth = $items[$min]["\x64\145\x70\x74\150"]; $nodes = array(); if ($min != $l) { $nodes[] = array("\x74\x65\x78\164" => null, "\x6c\x65\166\145\x6c" => $cur_level, "\x73\x74\171\x6c\x65" => null, "\x6d\141\162\153" => null, "\151\164\x65\155\163" => $this->buildTree($items, $l, $min, $cur_level + 1)); } $last = $min; for ($ii = $last + 1; $ii < $r; $ii++) { if ($items[$ii]["\144\145\160\164\150"] == $min_depth) { $nodes[] = array("\x6c\x65\166\145\154" => $cur_level, "\151\x74\x65\155\163" => $this->buildTree($items, $last + 1, $ii, $cur_level + 1)) + $items[$last]; $last = $ii; } } $nodes[] = array("\x6c\x65\166\x65\154" => $cur_level, "\151\x74\x65\x6d\x73" => $this->buildTree($items, $last + 1, $r, $cur_level + 1)) + $items[$last]; return $nodes; } private function adjustTreeStyleInformation(array &$tree) { $style = "\55"; for ($ii = count($tree) - 1; $ii >= 0; $ii--) { if ($tree[$ii]["\x73\164\171\x6c\x65"] !== null) { $style = $tree[$ii]["\x73\164\x79\154\x65"]; } else { $tree[$ii]["\x73\164\171\154\145"] = $style; } if ($tree[$ii]["\x69\164\x65\x6d\x73"]) { $this->adjustTreeStyleInformation($tree[$ii]["\x69\x74\x65\155\x73"]); } } } private function renderTree(array $tree, $level, $has_marks, $starts_at = 1) { $style = idx(head($tree), "\163\164\x79\154\145"); $out = array(); if (!$this->getEngine()->isTextMode()) { switch ($style) { case "\43": $tag = "\x6f\154"; break; case "\55": $tag = "\165\x6c"; break; } $start_attr = null; if (ctype_digit(phutil_string_cast($starts_at)) && $starts_at > 1) { $start_attr = hsprintf("\40\163\164\x61\162\164\x3d\x22\x25\x64\42", $starts_at); } if ($has_marks) { $out[] = hsprintf("\x3c\45\x73\x20\x63\x6c\x61\x73\163\75\42\162\145\155\x61\162\x6b\x75\160\55\154\x69\x73\x74\x20\x72\145\x6d\x61\162\153\165\160\x2d\x6c\x69\x73\x74\55\x77\x69\x74\x68\55\143\x68\x65\143\x6b\x6d\x61\x72\x6b\163\42\45\163\76", $tag, $start_attr); } else { $out[] = hsprintf("\x3c\45\x73\x20\143\154\141\163\x73\75\42\162\x65\155\141\162\x6b\x75\x70\55\154\x69\163\164\x22\x25\163\x3e", $tag, $start_attr); } $out[] = "\12"; } $number = $starts_at; foreach ($tree as $item) { if ($this->getEngine()->isTextMode()) { if ($item["\x74\145\170\x74"] === null) { } else { $indent = str_repeat("\40", 2 * $level); $out[] = $indent; if ($item["\155\x61\x72\153"] !== null) { if ($item["\x6d\141\x72\x6b"]) { $out[] = "\133\x58\x5d\40"; } else { $out[] = "\133\x20\135\40"; } } else { switch ($style) { case "\x23": $out[] = $number . "\x2e\x20"; $number++; break; case "\x2d": $out[] = "\55\x20"; break; } } $parts = preg_split("\x2f\134\156\173\x32\x2c\x7d\57", $item["\x74\145\170\164"]); foreach ($parts as $key => $part) { if ($key != 0) { $out[] = "\xa\12\40\x20" . $indent; } $out[] = $this->applyRules($part); } $out[] = "\12"; } } else { if ($item["\164\x65\170\164"] === null) { $out[] = hsprintf("\x3c\x6c\x69\40\x63\154\141\x73\x73\75\x22\x72\145\x6d\141\x72\153\x75\x70\55\154\x69\x73\x74\x2d\x69\x74\x65\x6d\x20\160\150\141\156\x74\x6f\x6d\55\151\164\145\155\42\x3e"); } else { if ($item["\x6d\141\x72\x6b"] !== null) { if ($item["\155\141\162\153"] == true) { $out[] = hsprintf("\74\x6c\151\x20\x63\154\141\x73\x73\75\42\162\145\x6d\141\x72\153\x75\160\55\154\x69\163\x74\x2d\x69\x74\145\155\x20\162\x65\x6d\x61\x72\x6b\165\160\55\143\x68\x65\143\153\x65\144\55\x69\164\x65\x6d\42\76"); } else { $out[] = hsprintf("\x3c\154\151\40\x63\154\x61\163\163\75\42\x72\145\x6d\141\x72\153\x75\160\x2d\x6c\151\163\164\55\151\164\x65\x6d\40\162\145\155\x61\x72\153\x75\160\x2d\x75\x6e\143\x68\145\143\153\x65\144\x2d\x69\164\x65\x6d\42\76"); } $out[] = phutil_tag("\151\x6e\x70\x75\x74", array("\x74\171\160\x65" => "\x63\150\145\x63\x6b\x62\157\x78", "\x63\150\x65\143\x6b\x65\144" => $item["\155\141\x72\153"] ? "\x63\x68\145\x63\153\145\144" : null, "\x64\151\x73\x61\142\154\x65\144" => "\x64\x69\x73\141\142\154\145\x64")); $out[] = "\40"; } else { $out[] = hsprintf("\74\154\151\40\x63\154\141\x73\x73\75\x22\x72\145\155\x61\162\x6b\165\x70\55\x6c\151\x73\164\55\x69\x74\x65\x6d\42\x3e"); } $parts = preg_split("\57\x5c\156\x7b\x32\54\x7d\57", $item["\x74\x65\x78\x74"]); foreach ($parts as $key => $part) { if ($key != 0) { $out[] = array("\xa", phutil_tag("\x62\162"), phutil_tag("\142\x72"), "\xa"); } $out[] = $this->applyRules($part); } } } if ($item["\151\164\145\x6d\163"]) { $subitems = $this->renderTree($item["\x69\x74\x65\155\x73"], $level + 1, $has_marks); foreach ($subitems as $i) { $out[] = $i; } } if (!$this->getEngine()->isTextMode()) { $out[] = hsprintf("\74\57\x6c\x69\76\xa"); } } if (!$this->getEngine()->isTextMode()) { switch ($style) { case "\43": $out[] = hsprintf("\74\x2f\157\154\76"); break; case "\x2d": $out[] = hsprintf("\x3c\x2f\x75\154\x3e"); break; } } return $out; } }

Function Calls

None

Variables

None

Stats

MD5 f294eacb646fe966a0d20760458c854f
Eval Count 0
Decode Time 102 ms