protected function composeEditor($o) { $o = self::composeReader($o); if (!empty($o->is_binary)) { unset($o->is_binary, $o->is_auth_edit); $o = $this->composeReader($o); } else { $this->editorTemplate && ($this->template = $this->editorTemplate); $f = new pForm($o); $f->add('textarea', 'code', array('default' => $o->text)); $send = $f->add('submit', 'save'); $send->attach('code', '', ''); if ($send->isOn()) { $code = $send->getData(); $code = $code['code']; if ('' !== $code && "\n" !== substr($code, -1)) { $code .= "\n"; } file_put_contents($this->realpath, $code); pStudio::syncCache($this->path, $this->depth); Patchwork::redirect(); } unset($o->text); } return $o; }
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); } @$db->queryExec($sql, $o->error_msg); $o->write_sql = pStudio_highlighter::highlight($sql, 'sql', false); } } return $this->composeReader($o); }
function control() { Patchwork::redirect('pStudio/explorer'); }
function compose($o) { $o->low = $this->get->low; $o->high = $this->get->high; $o->appname = pStudio::getAppname($this->depth); $o->is_file = '' !== $this->path && '/' !== substr($this->path, -1); $o->is_auth_edit = $this->is_auth_edit; $o->topname = '' !== $this->path ? basename($o->is_file ? $this->path : substr($this->path, 0, -1)) : $o->appname; $o->dirname = $o->is_file ? dirname($this->path) . '/' : $this->path; './' === $o->dirname && ($o->dirname = ''); $o->paths = new loop_array(explode('/', rtrim($this->path, '/'))); $o->subpaths = new loop_array($this->getSubpaths($o->dirname, $o->low, $o->high), 'filter_rawArray'); if ($o->is_auth_edit) { $f = new pForm($o); if ($o->is_file) { $f->add('file', 'file'); $send = $f->add('submit', 'send'); $send->attach('file', 'Please select a file', ''); if ($send->isOn()) { $file = $f->getElement('file')->getValue(); unlink($this->realpath); move_uploaded_file($file['tmp_name'], $this->realpath); pStudio::syncCache($this->path, $this->depth); Patchwork::redirect(); } } else { $filename = $f->add('text', 'filename', array('valid' => 'c', '^[^\\x00-\\x1F\\/:*?"<>|\\x7F]+$', 'validmsg' => T('Special characters are forbidden:') . ' \\ / : * ? " < > |')); if ($filename->getStatus()) { $newfile = $filename->getValue(); pStudio::isAuthEdit($this->path . $newfile) || $filename->setError(T('You are not allowed to create a ressource with this name')); $filename = $newfile; } $newfile = $f->add('submit', 'newfile'); $newfile->attach('filename', 'Please fill in the file name', ''); $newdir = $f->add('submit', 'newdir'); $newdir->attach('filename', 'Please fill in the directory name', ''); if ($newfile->isOn()) { file_put_contents($this->realpath . '/' . $filename, "\n"); } else { if ($newdir->isOn()) { mkdir($this->realpath . '/' . $filename); } else { $filename = false; } } if (false !== $filename) { pStudio::resetCache(); Patchwork::redirect("pStudio/explorer/{$this->path}{$filename}/?low={$this->get->low}&high={$this->get->high}"); } } if ('' !== $this->path && ($o->is_file || !$o->subpaths->getLength()) && $f->add('submit', 'del')->isOn()) { if ($o->is_file) { rename($this->realpath, $this->realpath . '~trashed'); } else { rmdir($this->realpath); } pStudio::resetCache(); Patchwork::redirect('pStudio/explorer/' . dirname($this->path) . "/?low={$this->get->low}&high={$this->get->high}"); } } return $o; }