80 lines
2.7 KiB
PHP
Executable File
80 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace WMarkDown\Modules;
|
|
|
|
class Checks extends \WMarkDown\Abstracts\Modules{
|
|
|
|
public function get_next_position($string){
|
|
if(!$this->more || $this->from >= 0)
|
|
return;
|
|
|
|
$pattern = '/';
|
|
|
|
foreach([
|
|
["(", ")"],
|
|
["[", "]"],
|
|
["{", "}"],
|
|
["<", ">"]
|
|
] as $delimiter)
|
|
$pattern .= ($pattern != '/' ? '|' : '') . '(\\' . $delimiter[0] . ')([\-\*\+x\\\\\/\=\#\|· v\?,yn])\\' . $delimiter[1];
|
|
$pattern .= '/i';
|
|
|
|
if($this->more = preg_match($pattern, $string, $this->matches, PREG_OFFSET_CAPTURE))
|
|
$this->from = $this->matches[0][1];
|
|
|
|
}
|
|
|
|
public function process($string, $modules, $level){
|
|
|
|
$character;
|
|
$value;
|
|
$hash = $this->wmarkdown->get_hash();
|
|
$type = "checkbox";
|
|
$icon = "checkbox";
|
|
$checked = false;
|
|
$disabled = false;
|
|
|
|
for($i = 1; $i < 8; $i += 2)
|
|
if(isset($this->matches[$i])){
|
|
$value = strtolower($this->content = $this->matches[$i + 1][0]);
|
|
$character = $this->matches[$i][0];
|
|
};
|
|
|
|
switch($value){
|
|
case "v":
|
|
$icon = "tick";
|
|
$checked = true;
|
|
break;
|
|
default:
|
|
$checked = strpos("x*#·vy", $value) !== false;
|
|
$disabled = strpos("-=?\\/|", $value) !== false;
|
|
switch($character){
|
|
case "(":
|
|
$type = "radio";
|
|
$icon = "radio";
|
|
break;
|
|
case "[":
|
|
$type = "checkbox";
|
|
$icon = "checkbox";
|
|
break;
|
|
case "{":
|
|
case "<":
|
|
$type = "checkbox";
|
|
$icon = "tick";
|
|
break;
|
|
};
|
|
break;
|
|
};
|
|
|
|
$this->length = strlen($this->matches[0][0]);
|
|
$this->to = $this->from + $this->length;
|
|
$this->html = ('
|
|
<label class="' . $icon . '" for="' . $hash . '">
|
|
<input type="' . $type . '" id="' . $hash . '" readonly onclick="return false;"' . ($checked ? ' checked' : '') . ($disabled ? ' disabled' : '') . ' />
|
|
<span data-icon="' . $icon . '"></span>
|
|
</label>
|
|
');
|
|
}
|
|
|
|
};
|