Example #1
0
 public function file($file = '')
 {
     if (is_string($file)) {
         $this->manipulation['filename'] = STYLES_DIR . suffix($file, '.css');
         $this->manipulation['file'] = File::contents($this->manipulation['filename']);
     }
     return $this;
 }
Example #2
0
 public function sqlFile($sqlFile = '')
 {
     if (!is_string($sqlFile) || empty($sqlFile)) {
         return Error::set(lang('Error', 'stringParameter', 'sqlFile'));
     }
     $fileContents = File::contents(suffix($sqlFile, ".sql"));
     $fileContents = preg_replace("/SET (.*?);/", "", $fileContents);
     $fileContents = preg_replace("/\\/\\*(.*?)\\*\\//", "", $fileContents);
     $fileContents = preg_replace("/--(.*?)\n/", "", $fileContents);
     $fileContents = preg_replace("/\\/\\*!40101/", "", $fileContents);
     $queries = explode(";\n", $fileContents);
     $db = uselib('DB');
     foreach ($queries as $query) {
         if ($query !== '') {
             $db->execQuery(trim($query));
         }
     }
 }
 function view()
 {
     $this->Form->setAttribute('action', extension_filemanager::baseURL() . 'properties/?file=' . $_GET['file']);
     $file = new File(DOCROOT . $this->_FileManager->getStartLocation() . $_GET['file']);
     $FileManager =& $this->_Parent->ExtensionManager->create('filemanager');
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert('An error occurred while processing this form. <a href="#error">See below for details.</a>', AdministrationPage::PAGE_ALERT_ERROR);
     }
     if (isset($_GET['result'])) {
         switch ($_GET['result']) {
             case 'saved':
                 $this->pageAlert(__('%s updated successfully', array($file->isDir() ? 'Folder' : 'File')), Alert::SUCCESS);
                 break;
         }
     }
     $this->setPageType('form');
     $path = extension_filemanager::baseURL() . 'browse/';
     $breadcrumb = '';
     $pathelements = explode('/', $_GET['file']);
     foreach ($pathelements as $element) {
         if ($element != '') {
             $path .= $element . '/';
             $breadcrumb .= ' / ' . ($element == end($pathelements) ? $element : Widget::Anchor($element, $path)->generate());
         }
     }
     $this->appendSubheading(trim($FileManager->getStartLocationLink(), '/') . $breadcrumb);
     $fields = array();
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'settings');
     $fieldset->appendChild(new XMLElement('legend', 'Essentials'));
     $div = new XMLElement('div');
     $div->setAttribute('class', 'group');
     $label = Widget::Label('Name');
     $label->appendChild(Widget::Input('fields[name]', General::sanitize($file->name())));
     if (isset($this->_errors['name'])) {
         $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name']));
     } else {
         $div->appendChild($label);
     }
     $label = Widget::Label('Permissions');
     $label->appendChild(Widget::Input('fields[permissions]', General::sanitize($file->permissions())));
     if (isset($this->_errors['permissions'])) {
         $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['permissions']));
     } else {
         $div->appendChild($label);
     }
     $fieldset->appendChild($div);
     $this->Form->appendChild($fieldset);
     if (!$file->isDir() && in_array(File::fileType($file->name()), array(File::CODE, File::DOC))) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', 'Editor'));
         $label = Widget::Label('Contents');
         $label->appendChild(Widget::Textarea('fields[contents]', '25', '50', General::sanitize($file->contents()), array('class' => 'code')));
         if (isset($this->_errors['contents'])) {
             $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['contents']));
         } else {
             $fieldset->appendChild($label);
         }
         $this->Form->appendChild($fieldset);
     }
     if (!$file->isDir() && File::fileType($file->name()) == File::IMAGE) {
         $fieldset = new XMLElement('fieldset');
         $fieldset->setAttribute('class', 'settings');
         $fieldset->appendChild(new XMLElement('legend', 'Preview'));
         $img = new XMLElement('img');
         $img->setAttribute('src', URL . $FileManager->getStartLocation() . $_GET['file']);
         $img->setAttribute('alt', $file->name());
         $fieldset->appendChild($img);
         $this->Form->appendChild($fieldset);
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     if (is_writeable(DOCROOT . $this->_FileManager->getStartLocation() . $_GET['file'])) {
         $div->appendChild(Widget::Input('action[save]', 'Save Changes', 'submit', array('accesskey' => 's')));
         $button = new XMLElement('button', 'Delete');
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => 'Delete this ' . ($file->isDir() ? 'Folder' : 'File')));
         $div->appendChild($button);
     } else {
         $notice = new XMLElement('p', 'The server does not have permission to edit this file.');
         $notice->setAttribute('class', 'inactive');
         $div->appendChild($notice);
     }
     $this->Form->appendChild($div);
 }
Example #4
0
 /**
  * Build the request body.
  */
 protected function buildBody()
 {
     // If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads
     // will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off
     // and use CurlFile.
     if (count($this->files())) {
         $body = [];
         foreach ($this->params as $key => $value) {
             $body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"", "", $value]);
         }
         foreach ($this->files as $key => $path) {
             $file = new File($path);
             $body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"", "Content-Type: application/octet-stream", "", $file->contents()]);
         }
         do {
             $boundary = "---------------------" . md5(mt_rand() . microtime());
         } while (preg_grep("/{$boundary}/", $body));
         foreach ($body as $i => $part) {
             $body[$i] = "--{$boundary}\r\n" . $part;
         }
         $body[] = "--{$boundary}--";
         $body[] = "";
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, implode("\r\n", $body));
         $this->header('Content-Type', 'multipart/form-data; boundary=' . $boundary);
     } else {
         curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($this->params));
         $this->header('Content-Type', 'application/x-www-form-urlencoded');
     }
 }