Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media select all #8852

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions administrator/components/com_media/controllers/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public function delete()
{
JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));

$user = JFactory::getUser();

// Get some data from the request
$tmpl = $this->input->get('tmpl');
$paths = $this->input->get('rm', array(), 'array');
Expand All @@ -217,18 +219,25 @@ public function delete()

$this->setRedirect($redirect);

// Nothing to delete
// Just return if there's nothing to do
if (empty($paths))
{
$this->setMessage(JText::_('JERROR_NO_ITEMS_SELECTED'), 'error');

return true;
}

// Authorize the user
if (!$this->authoriseUser('delete'))
if (!$user->authorise('core.delete', 'com_media'))
{
// User is not authorised to delete
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'));

return false;
}

// Need this to enqueue messages.
$app = JFactory::getApplication();

// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');

Expand All @@ -237,17 +246,18 @@ public function delete()

$ret = true;

foreach ($paths as $path)
{
if ($path !== JFile::makeSafe($path))
{
// Filename is not safe
$filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE))));
$safePaths = array_intersect($paths, array_map(array('JFile', 'makeSafe'), $paths));
$unsafePaths = array_diff($paths, $safePaths);

continue;
}
foreach ($unsafePaths as $path)
{
$path = JPath::clean(implode(DIRECTORY_SEPARATOR, array($folder, $path)));
$path = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
$app->enqueueMessage(JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', $path), 'error');
}

foreach ($safePaths as $path)
{
$fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
$object_file = new JObject(array('filepath' => $fullPath));

Expand All @@ -269,12 +279,9 @@ public function delete()

// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file));
$this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));

continue;
$app->enqueueMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
}

if (is_dir($object_file->filepath))
elseif (is_dir($object_file->filepath))
{
$contents = JFolder::files($object_file->filepath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));

Expand All @@ -299,11 +306,11 @@ public function delete()
continue;
}

$ret &= JFolder::delete($object_file->filepath);
$ret &= !JFolder::delete($object_file->filepath);

// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file));
$this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
$app->enqueueMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
}
}

Expand Down
113 changes: 59 additions & 54 deletions administrator/components/com_media/controllers/folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,77 +63,82 @@ public function delete()
return false;
}

// Need this to enqueue messages.
$app = JFactory::getApplication();

// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');

$ret = true;

JPluginHelper::importPlugin('content');
$dispatcher = JEventDispatcher::getInstance();

if (count($paths))
$ret = true;

$safePaths = array_intersect($paths, array_map(array('JFile', 'makeSafe'), $paths));
$unsafePaths = array_diff($paths, $safePaths);

foreach ($unsafePaths as $path)
{
$path = JPath::clean(implode(DIRECTORY_SEPARATOR, array($folder, $path)));
$path = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
$app->enqueueMessage(JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', $path), 'error');
}

foreach ($safePaths as $path)
{
foreach ($paths as $path)
$fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
$object_file = new JObject(array('filepath' => $fullPath));

if (is_file($object_file->filepath))
{
if ($path !== JFile::makeSafe($path))
// Trigger the onContentBeforeDelete event.
$result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.file', &$object_file));

if (in_array(false, $result, true))
{
$dirname = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_WARNDIRNAME', substr($dirname, strlen(COM_MEDIA_BASE))));
// There are some errors in the plugins
$errors = $object_file->getErrors();
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors), implode('<br />', $errors)));

continue;
}

$fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
$object_file = new JObject(array('filepath' => $fullPath));
$ret &= JFile::delete($object_file->filepath);

if (is_file($object_file->filepath))
// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file));
$app->enqueueMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
}
elseif (is_dir($object_file->filepath))
{
$contents = JFolder::files($object_file->filepath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));

if (!empty($contents))
{
// Trigger the onContentBeforeDelete event.
$result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.file', &$object_file));

if (in_array(false, $result, true))
{
// There are some errors in the plugins
$errors = $object_file->getErrors();
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors), implode('<br />', $errors)));
continue;
}

$ret &= JFile::delete($object_file->filepath);

// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file));
$this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
// This makes no sense...
$folderPath = substr($object_file->filepath, strlen(COM_MEDIA_BASE));
JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', $folderPath));

continue;
}
elseif (is_dir($object_file->filepath))

// Trigger the onContentBeforeDelete event.
$result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.folder', &$object_file));

if (in_array(false, $result, true))
{
$contents = JFolder::files($object_file->filepath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));

if (empty($contents))
{
// Trigger the onContentBeforeDelete event.
$result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.folder', &$object_file));

if (in_array(false, $result, true))
{
// There are some errors in the plugins
$errors = $object_file->getErrors();
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors), implode('<br />', $errors)));
continue;
}

$ret &= !JFolder::delete($object_file->filepath);

// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file));
$this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
}
else
{
// This makes no sense...
$folderPath = substr($object_file->filepath, strlen(COM_MEDIA_BASE));
JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', $folderPath));
}
// There are some errors in the plugins
$errors = $object_file->getErrors();
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors), implode('<br />', $errors)));

continue;
}

$ret &= !JFolder::delete($object_file->filepath);

// Trigger the onContentAfterDelete event.
$dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file));
$app->enqueueMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
}
}

Expand Down
114 changes: 69 additions & 45 deletions administrator/components/com_media/views/medialist/tmpl/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,46 @@
*/

defined('_JEXEC') or die;
$user = JFactory::getUser();
$params = JComponentHelper::getParams('com_media');
$path = 'file_path';

JHtml::_('jquery.framework');
JHtml::_('behavior.core');

JFactory::getDocument()->addScriptDeclaration(
$doc = JFactory::getDocument();

// Need to override this core function because we use a different form id
$doc->addScriptDeclaration(
"
Joomla.isChecked = function( isitchecked, form ) {
if ( typeof form === 'undefined' ) {
form = document.getElementById( 'mediamanager-form' );
}

form.boxchecked.value += isitchecked ? 1 : -1;

// If we don't have a checkall-toggle, done.
if ( !form.elements[ 'checkall-toggle' ] ) return;

// Toggle main toggle checkbox depending on checkbox selection
var c = true,
i, e, n;

for ( i = 0, n = form.elements.length; i < n; i++ ) {
e = form.elements[ i ];

if ( e.type == 'checkbox' && e.name != 'checkall-toggle' && !e.checked ) {
c = false;
break;
}
}

form.elements[ 'checkall-toggle' ].checked = c;
};
"
);

$doc->addScriptDeclaration(
"
jQuery(document).ready(function($){
window.parent.document.updateUploader();
Expand Down Expand Up @@ -52,55 +85,46 @@
<div class="muted">
<p>
<span class="icon-folder"></span>
<?php if ($this->state->folder != '') : ?>
<?php echo JText::_('JGLOBAL_ROOT') . ': ' . $params->get($path, 'images') . '/' . $this->state->folder; ?>
<?php else : ?>
<?php echo JText::_('JGLOBAL_ROOT') . ': ' . $params->get($path, 'images'); ?>
<?php endif; ?>
<?php
echo JText::_('JGLOBAL_ROOT'), ': ',
$params->get($path, 'images'),
($this->state->folder != '') ? '/' . $this->state->folder : '';
?>
</p>
</div>

<div class="manager">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="1%"><?php echo JText::_('JGLOBAL_PREVIEW'); ?></th>
<th><?php echo JText::_('COM_MEDIA_NAME'); ?></th>
<th width="15%"><?php echo JText::_('COM_MEDIA_PIXEL_DIMENSIONS'); ?></th>
<th width="8%"><?php echo JText::_('COM_MEDIA_FILESIZE'); ?></th>
<?php if ($user->authorise('core.delete', 'com_media')):?>
<th width="8%"><?php echo JText::_('JACTION_DELETE'); ?></th>
<?php endif;?>
</tr>
</thead>
<tbody>
<?php echo $this->loadTemplate('up'); ?>

<?php for ($i = 0, $n = count($this->folders); $i < $n; $i++) :
$this->setFolder($i);
echo $this->loadTemplate('folder');
endfor; ?>

<?php for ($i = 0, $n = count($this->documents); $i < $n; $i++) :
$this->setDoc($i);
echo $this->loadTemplate('doc');
endfor; ?>

<?php for ($i = 0, $n = count($this->videos); $i < $n; $i++) :
$this->setVideo($i);
echo $this->loadTemplate('video');
endfor; ?>

<?php for ($i = 0, $n = count($this->images); $i < $n; $i++) :
$this->setImage($i);
echo $this->loadTemplate('img');
endfor; ?>

</tbody>
</table>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="1%"><?php echo JText::_('JGLOBAL_PREVIEW'); ?></th>
<th><?php echo JText::_('COM_MEDIA_NAME'); ?></th>
<th width="15%"><?php echo JText::_('COM_MEDIA_PIXEL_DIMENSIONS'); ?></th>
<th width="8%"><?php echo JText::_('COM_MEDIA_FILESIZE'); ?></th>

<?php if ($this->canDelete) : ?>
<th width="8%">
<?php echo JText::_('JACTION_DELETE'); ?>
<?php echo JHtml::_('grid.checkall'); ?>
</th>
<?php endif;?>
</tr>
</thead>
<tbody>
<?php
echo $this->loadTemplate('up'),
$this->loadTemplate('folders'),
$this->loadTemplate('docs'),
$this->loadTemplate('videos'),
$this->loadTemplate('imgs');
?>
</tbody>
</table>
</div>

<input type="hidden" name="task" value="list" />
<input type="hidden" name="username" value="" />
<input type="hidden" name="password" value="" />
<input type="hidden" name="boxchecked" value="" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
Loading