protected function composeReader($o) { if (is_file($this->realpath) && false !== ($a = file_get_contents($this->realpath))) { $a && false !== strpos($a, "\r") && ($a = strtr(str_replace("\r\n", "\n", $a), "\r", "\n")); u::isUtf8($a) || ($a = u::utf8_encode($a)); $o->code = pStudio_highlighter::highlight($a, $this->language, true); } return $o; }
protected static function highlight_php($a, $line_numbers) { $a = highlight_string($a, true); $a = substr($a, 6, -7); $a = str_replace(' ', ' ', $a); if ($line_numbers) { $a = str_replace("\n", '', $a); $b = array(); self::$pool = array(); foreach (explode('<br>', $a) as $a) { $b[] = implode('', self::$pool) . preg_replace_callback("'<(/?)span[^>]*>'", array(__CLASS__, 'pool_callback'), $a) . str_repeat('</span>', count(self::$pool)); } $a = implode("<br>\n", $b); } return self::finalize($a, $line_numbers); }
protected function composeEditor($o) { if (!$this->get->sql) { $f = new pForm($o); $f->setPrefix(''); $f->add('hidden', 'low'); $f->add('hidden', 'high'); $sql = $f->add('textarea', 'sql'); if ($sql->isOn()) { $sql = trim($sql->getValue()); $sql || Patchwork::redirect(); if (!($db = $this->getDb($o))) { return $o; } if (self::isReadOnlyQuery($db, $sql, $o->error_msg)) { $sql = urlencode($sql); $uri = Patchwork::__URI__(); $uri = $uri !== strtr($uri, '?&', '--') ? preg_replace("'([?&]sql=)[^&]*'", '$1' . $sql, $uri) : $uri . '?sql=' . $sql; Patchwork::redirect($uri); } try { $db->exec($sql); } catch (Exception $e) { $o->error_msg = $e->getMessage(); } $o->write_sql = pStudio_highlighter::highlight($sql, 'sql', false); } } return $this->composeReader($o); }