Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new FileForm();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['FileForm'])) {
         $file = new File();
         $file->name = $_POST['FileForm']['name'];
         $slug = $file->generateRandomString();
         while (true) {
             $invalidSlug = File::model()->findByAttributes(array('slug' => $slug));
             if (!$invalidSlug) {
                 break;
             }
         }
         $file->slug = $slug;
         if ($file->save()) {
             $fileFormTypeArray = $file->fileType();
             foreach ($fileFormTypeArray as $fileType) {
                 if (trim($_POST['FileForm'][$fileType]) != "") {
                     $url = new Url();
                     $url->type = $fileType;
                     $url->file_id = $file->id;
                     $url->day_update = date('d');
                     $url->month_update = date('m');
                     $url->url = $_POST['FileForm'][$fileType];
                     $url->save();
                 }
             }
             $statistic = new Statistic();
             $statistic->file_id = $file->id;
             $statistic->date = date('dmY');
             $statistic->save();
         }
         $this->redirect(array('admin'));
     }
     $this->render('create', array('model' => $model));
 }
 public function buildTableRow(DirectoryIterator $file, $includeParentDirectoryDots = true)
 {
     if (!$file->isDot() && substr($file->getFilename(), 0, 1) == '.' && Administration::instance()->Configuration->get('show-hidden', 'filemanager') != 'yes') {
         return;
     } elseif ($file->isDot() && !$includeParentDirectoryDots && $file->getFilename() == '..') {
         return;
     } elseif ($file->getFilename() == '.') {
         return;
     }
     $relpath = str_replace($this->getStartLocation() == '' ? DOCROOT : DOCROOT . $this->getStartLocation(), NULL, $file->getPathname());
     if (!$file->isDir()) {
         //if(File::fileType($file->getFilename()) == self::CODE)
         //	$download_uri = self::baseURL() . 'edit/?file=' . urlencode($relpath);
         //else
         $download_uri = self::baseURL() . 'download/?file=' . urlencode($relpath);
     } else {
         $download_uri = self::baseURL() . 'properties/?file=' . urlencode($relpath) . '/';
     }
     if (!$file->isDot()) {
         $td1 = Widget::TableData(Widget::Anchor($file->getFilename(), self::baseURL() . ($file->isDir() ? 'browse' . $relpath . '/' : 'properties/?file=' . urlencode($relpath)), NULL, 'file-type ' . ($file->isDir() ? 'folder' : File::fileType($file->getFilename()))));
         //$group = (function_exists('posix_getgrgid') ? posix_getgrgid($file->getGroup()) : $file->getGroup());
         //$owner = (function_exists('posix_getpwuid') ? posix_getpwuid($file->getOwner()) : $file->getOwner());
         $group = $file->getGroup();
         $owner = $file->getOwner();
         $td3 = Widget::TableData(File::getOctalPermission($file->getPerms()) . ' <span class="inactive">' . File::getReadablePerm($file->getPerms()), NULL, NULL, NULL, array('title' => (isset($owner['name']) ? $owner['name'] : $owner) . ', ' . (isset($group['name']) ? $group['name'] : $group)) . '</span>');
         $td4 = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, $file->getMTime()));
         if ($file->isWritable()) {
             if ($file->isDir()) {
                 $td5 = Widget::TableData(Widget::Anchor('Edit', $download_uri));
             } else {
                 $td5 = Widget::TableData(Widget::Anchor('Download', $download_uri));
             }
         } else {
             $td5 = Widget::TableData('-', 'inactive');
         }
     } else {
         $td1 = Widget::TableData(Widget::Anchor('&crarr;', self::baseURL() . 'browse' . $relpath . '/'));
         $td3 = Widget::TableData('-', 'inactive');
         $td4 = Widget::TableData('-', 'inactive');
         $td5 = Widget::TableData('-', 'inactive');
     }
     $td2 = Widget::TableData($file->isDir() ? '-' : General::formatFilesize($file->getSize()), $file->isDir() ? 'inactive' : NULL);
     $startlocation = DOCROOT . $this->getStartLocation();
     if (!$file->isDot()) {
         $td5->appendChild(Widget::Input('items[' . str_replace($startlocation, '', $file->getPathname()) . ($file->isDir() ? '/' : NULL) . ']', NULL, 'checkbox'));
     }
     return Widget::TableRow(array($td1, $td2, $td3, $td4, $td5));
 }
 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);
 }