コード例 #1
0
 public function massiveImport()
 {
     $jinput = JFactory::getApplication()->input;
     $files = $jinput->get('item', array(), 'ARRAY');
     $param = JComponentHelper::getParams('com_simplefilemanager');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.utilities.date');
     define("DS", DIRECTORY_SEPARATOR);
     $uploadedSuccessfullCount = 0;
     foreach ($files as $file) {
         $src = JPATH_ROOT . DS . "sfmimporter" . DS . $file;
         // Check file extension.
         if (SimplefilemanagerHelper::hasSafeExtension($file)) {
             // File upload.
             $upload = SimplefilemanagerHelper::moveFile($src, $file);
             if ($upload) {
                 $file_name = $upload;
                 $md5hash = md5_file($file);
                 $file_size = filesize($file);
                 $title = JFile::stripExt($file);
                 $author = JFactory::getUser()->id;
                 $date =& JFactory::getDate('now');
                 // Save to db.
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $columns = array('state', 'title', 'author', 'file_created', 'file_name', 'file_size', md5hash);
                 $values = array(0, $db->quote($title), $db->quote($author), $db->quote($date->format('Y-m-d H:m:s', false)), $db->quote($file_name), $db->quote($file_size), $db->quote($md5hash));
                 $query->insert($db->quoteName('#__simplefilemanager'))->columns($db->quoteName($columns))->values(implode(',', $values));
                 $db->setQuery($query);
                 $db->execute();
                 $uploadedSuccessfullCount++;
             }
         }
     }
     if ($uploadedSuccessfullCount > 0) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_UPLOADED_SUCCESSFULLY_MSG', $uploadedSuccessfullCount), 'message');
     }
     return $this->display();
 }
コード例 #2
0
 protected function addToolbar()
 {
     $state = $this->get('State');
     $canDo = SimplefilemanagerHelper::getActions($state->get('filter.category_id'));
     $user = JFactory::getUser();
     $bar = JToolBar::getInstance('toolbar');
     JToolbarHelper::title(JText::_('COM_SIMPLEFILEMANAGER_MANAGER_SIMPLEFILEMANAGERS'), 'file-2');
     // User should be authorized to publish at least in a category
     if ($canDo->get('core.create') && count($user->getAuthorisedCategories('com_simplefilemanager', 'core.create')) > 0) {
         JToolbarHelper::addNew('simplefilemanager.add');
     }
     if ($canDo->get('core.edit')) {
         JToolbarHelper::editList('simplefilemanager.edit');
     }
     if ($canDo->get('core.edit.state')) {
         JToolbarHelper::publish('simplefilemanagers.publish', 'JTOOLBAR_PUBLISH', true);
         JToolbarHelper::unpublish('simplefilemanagers.unpublish', 'JTOOLBAR_UNPUBLISH', true);
         JToolbarHelper::archiveList('simplefilemanagers.archive');
         JToolbarHelper::checkin('simplefilemanagers.checkin');
     }
     $state = $this->get('State');
     if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
         JToolbarHelper::deleteList('', 'simplefilemanagers.delete', 'JTOOLBAR_EMPTY_TRASH');
     } elseif ($canDo->get('core.edit.state')) {
         JToolbarHelper::trash('simplefilemanagers.trash');
     }
     if ($canDo->get('core.admin')) {
         JToolbarHelper::preferences('com_simplefilemanager');
     }
     JToolBarHelper::help('COM_SIMPLEFILEMANAGER_HELP_VIEW_SIMPLEFILEMANANGERS', false, 'http://www.simplefilemanager.eu/support');
     JHtmlSidebar::setAction('index.php?option=com_simplefilemanager&view=simplefilemanagers');
     JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'filter_state', JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.state'), true));
     $this->category = JFormHelper::loadFieldType('catid', false);
     $this->categoryOptions = $this->category->getOptions();
     JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_CATEGORY'), 'filter_category', JHtml::_('select.options', $this->categoryOptions, 'value', 'text', $this->state->get('filter.category')));
     $this->visibilityOptions = array(1 => JText::_('COM_SIMPLEFILEMANAGER_VISIBILITY_PUBLIC'), 2 => JText::_('COM_SIMPLEFILEMANAGER_VISIBILITY_REGISTRED'), 3 => JText::_('COM_SIMPLEFILEMANAGER_VISIBILITY_USER'), 4 => JText::_('COM_SIMPLEFILEMANAGER_VISIBILITY_GROUP'), 5 => JText::_('COM_SIMPLEFILEMANAGER_VISIBILITY_AUTHOR'));
     JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_VISIBILITY'), 'filter_visibility', JHtml::_('select.options', $this->visibilityOptions, 'value', 'text', $this->state->get('filter.visibility')));
 }
コード例 #3
0
 protected function addToolbar()
 {
     $input = JFactory::getApplication()->input;
     $input->set('hidemainmenu', true);
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $isNew = $this->item->id == 0;
     $canDo = SimplefilemanagerHelper::getActions($this->item->catid, 0);
     if ($isNew) {
         JToolBarHelper::title(JText::_('COM_simplefilemanager_new_simplefilemanager'));
     } else {
         JToolBarHelper::title(JText::_('COM_simplefilemanager_edit_simplefilemanager'));
     }
     if ($canDo->get('core.edit') || count($user->getAuthorisedCategories('com_simplefilemanager', 'core.create'))) {
         JToolbarHelper::apply('simplefilemanager.apply');
         JToolbarHelper::save('simplefilemanager.save');
         if (!$isNew) {
             JToolbarHelper::save2new('simplefilemanager.save2new');
             JToolbarHelper::save2copy('simplefilemanager.save2copy');
         }
     }
     JToolBarHelper::cancel('simplefilemanager.cancel', $isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
 }
コード例 #4
0
 /**
  * Prepare data before executing controller save function
  * @param mixed $data Form data (passed by reference)
  * @param unknown $files File to upload
  */
 protected function prepareDataBeforeSave(&$data, $files)
 {
     $user = JFactory::getUser();
     $param = JComponentHelper::getParams('com_simplefilemanager');
     // Check if it's a new item
     $isNew = $data["file_name"] == "" ? 1 : 0;
     // Check if no file has been selected
     if ($isNew and $files['test'][0]["size"] <= 0) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_NOFILE_ERROR'), 'error');
         return;
     }
     // Import Joomla!'s file library
     jimport('joomla.filesystem.file');
     // Check if item already have an old file and delete it
     if (!$isNew and $data["file_size"] > 0) {
         if (SimplefilemanagerHelper::deleteFile($data["file_name"])) {
             $path_parts = pathinfo($data["file_name"]);
             rmdir($path_parts['dirname']);
         }
     }
     // Check if item needs a file upload
     if ($files['test'][0]["size"]) {
         // Set up the source and destination of the file
         $src = $files['test'][0]['tmp_name'];
         // Check file extension
         if (!SimplefilemanagerHelper::hasSafeExtension($files['test'][0]["name"])) {
             JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_DANGEROUS_FILE_ERROR'), 'error');
             return;
         }
         // File upload
         $upload = SimplefilemanagerHelper::uploadFile($files['test'][0]["tmp_name"], $files['test'][0]["name"]);
         if (!$upload) {
             JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_UPLOAD_ERROR'), 'error');
             return;
         }
         $data["file_name"] = $upload;
         // Set MD5 Hash
         $data["md5hash"] = md5_file($data["file_name"]);
         $data["file_size"] = $files['test'][0]["size"];
         // Send email
         if ($param->get('sendmail') == 1 and $isNew == 1 and $data["reserved_user"] > 0 and $data["visibility"] == 3) {
             $send = SimplefilemanagerHelper::sendMail($data["reserved_user"]);
             if (!send) {
                 JFactory::getApplication()->enqueueMessage(JText::_('JERROR') . ": " . $send->__toString(), 'error');
             }
         }
     }
     if ($data["title"] == "") {
         $data["title"] = JFile::stripExt($files['test'][0]["name"]);
     }
     if (!$data["author"]) {
         $data["author"] = JFactory::getUser()->id;
     }
     // Suspend publication if user not authorized to edit state
     if (!$user->authorise('core.manage', 'com_simplefilemanager')) {
         $data["state"] = 0;
     }
     // Updating dates
     if ($isNew) {
         jimport('joomla.utilities.date');
         $date =& JFactory::getDate('now');
         $data["file_created"] = $date->format('Y-m-d H:m:s', false);
     }
     if (!$data["md5hash"]) {
         $data["md5hash"] = md5_file($data["file_name"]);
     }
     return;
 }
コード例 #5
0
ファイル: edit.php プロジェクト: gmansillo/simplefilemanager
<?php

/**
 *
 * @package     Simple File Manager
 * @author       Giovanni Mansillo
 *
 * @copyright   Copyright (C) 2005 - 2014 Giovanni Mansillo. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
defined('_JEXEC') or die;
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('behavior.formvalidation');
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/simplefilemanager.php';
$isNew = $this->item->id == 0;
$maxFileSize = SimplefilemanagerHelper::getMaxFileUploadSize();
?>

<script type="text/javascript">
    jQuery(function () {
        jQuery('#jform1_uploader').change(function () {
            var f = this.files[0];
            var s = (f.size || f.fileSize);
            if (<?php 
echo $maxFileSize;
?>
 < s )
            alert("<?php 
echo JText::sprintf('COM_SIMPLEFILEMANAGER_UPLOAD_MAX_SIZE_EXCEEDED_ERROR', $maxFileSize / 1048576);
?>
");
コード例 #6
0
 public static function getMaxFileUploadSize()
 {
     return min(SimplefilemanagerHelper::return_bytes(ini_get('post_max_size')), SimplefilemanagerHelper::return_bytes(ini_get('upload_max_filesize')));
 }
コード例 #7
0
 public function save($key = null, $urlVar = null)
 {
     // Load libraries
     jimport('joomla.filesystem.file');
     jimport('joomla.utilities.date');
     // Load data
     $this->form = JFactory::getApplication()->input->post->get('jform', null, 'RAW');
     $this->files = JFactory::getApplication()->input->files->get('jform1');
     $this->params = JComponentHelper::getParams('com_simplefilemanager');
     // Check if user is creating a new file
     $isNew = $this->form["file_name"] ? false : true;
     // Checking file selection
     if ($this->files['test'][0]["size"]) {
         // Checking file extension
         if (!SimplefilemanagerHelper::hasSafeExtension($this->files['test'][0]["name"])) {
             JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_DANGEROUS_FILE_ERROR'), 'error');
             parent::save($key, $urlVar);
             return;
         }
         // Deleting previous file
         if ($this->form["file_name"]) {
             SimplefilemanagerHelper::deleteFile($this->form["file_name"]);
         }
         // File upload
         $upload = SimplefilemanagerHelper::uploadFile($this->files['test'][0]["tmp_name"], $this->files['test'][0]["name"]);
         if (!$upload or $this->form["file_name"] == $upload) {
             JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_UPLOAD_ERROR'), 'error');
             parent::save($key, $urlVar);
             return;
         }
         $this->form["file_name"] = $upload;
         $this->form["file_size"] = $this->files['test'][0]["size"];
         $this->form["md5hash"] = md5_file($this->form["file_name"]);
         if (!$this->form["file_created"] or !$this->form["author"]) {
             $this->form["file_created"] =& JFactory::getDate('now')->format('Y-m-d H:m:s', false);
             $this->form["author"] = JFactory::getUser()->id;
         }
     } elseif ($isNew) {
         JFactory::getApplication()->enqueueMessage(JText::_('COM_SIMPLEFILEMANAGER_FIELD_NOFILE_ERROR'), 'error');
         parent::save($key, $urlVar);
         return;
     } else {
         if ($this->task == "save2copy") {
             // File copy
             $copy = SimplefilemanagerHelper::copyFile($this->form["file_name"]);
             if ($copy === false) {
                 throw new Exception(JText::sprintf('COM_SIMPLEFILEMANAGER_FIELD_COPY_ERROR', $this->form["file_name"]), 500);
             }
             $this->form["file_name"] = $copy;
             $this->form["file_created"] = JFactory::getDate('now')->format('Y-m-d H:m:s', false);
             $this->form["author"] = JFactory::getUser()->id;
         }
     }
     // If save2copy, controller will automatically change items's id but won't change its publish state
     if ($this->task == "save2copy") {
         $this->form["state"] = 0;
     }
     // Send notify email
     if ($isNew and $this->params->get('sendmail') or isset($this->form["fl_send_mail"])) {
         SimplefilemanagerHelper::sendMail($this->form);
     }
     // Save data back to the $_POST global variable
     JFactory::getApplication()->input->post->set('jform', $this->form);
     parent::save($key, $urlVar);
 }