Example #1
0
 /**
  * Creates suggestions for correcting problems with orphaned folders
  *
  * @return  void
  * @since   1.5.5
  */
 public function createFolderSuggestions()
 {
     $query = $this->_db->getQuery(true);
     $query->select('COUNT(id)')->from(_JOOM_TABLE_ORPHANS)->where("type = 'folder'");
     $this->_db->setQuery($query);
     $total = $this->_db->loadResult();
     $start = false;
     if (!$this->_mainframe->getUserState('joom.maintenance.check.createfoldersuggestions')) {
         $start = true;
         $this->_mainframe->setUserState('joom.maintenance.check.index', 0);
         $this->_mainframe->setUserState('joom.maintenance.check.createfoldersuggestions', true);
     }
     $refresher = new JoomRefresher(array('name' => JText::_('COM_JOOMGALLERY_MAIMAN_CREATE_FOLDER_SUGGESTIONS'), 'remaining' => $total, 'start' => $start));
     $index = $this->_mainframe->getUserState('joom.maintenance.check.index');
     $query->clear('select')->select('id, type, fullpath');
     $this->_db->setQuery($query, $index, 1);
     while ($folder = $this->_db->loadObject()) {
         $folder_name_parts = explode('_', $folder->fullpath);
         $count_parts = count($folder_name_parts);
         if (!$count_parts) {
             $index++;
             $this->_db->setQuery($query, $index, 1);
             continue;
         }
         if (is_numeric($folder_name_parts[$count_parts - 1])) {
             $category_id = (int) $folder_name_parts[$count_parts - 1];
             if (strpos($folder->fullpath, JPath::clean($this->_ambit->get('thumb_path'), '/')) !== false) {
                 $type = 'thumb';
             } else {
                 if (strpos($folder->fullpath, JPath::clean($this->_ambit->get('img_path'), '/')) !== false) {
                     $type = 'img';
                 } else {
                     $type = 'orig';
                 }
             }
             $query->clear()->select('c.cid AS category_id')->select('m.id AS orphan_id')->select('c.name')->from(_JOOM_TABLE_CATEGORIES . ' AS c')->leftJoin(_JOOM_TABLE_MAINTENANCE . ' AS m ON c.cid = m.refid')->where('c.cid = ' . $category_id);
             $this->_db->setQuery($query);
             if ($suggestion = $this->_db->loadObject()) {
                 $query->clear()->update(_JOOM_TABLE_ORPHANS)->set('refid = ' . $suggestion->category_id)->set("title = '" . $suggestion->name . "'")->where('id = ' . $folder->id);
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 if ($suggestion->orphan_id) {
                     $query->clear()->update(_JOOM_TABLE_MAINTENANCE)->set($type . 'orphan = ' . $folder->id)->where('id = ' . $suggestion->orphan_id);
                     $this->_db->setQuery($query);
                     $this->_db->query();
                 }
             }
         }
         $index++;
         if (!$refresher->check()) {
             $this->_mainframe->setUserState('joom.maintenance.check.index', $index);
             $refresher->refresh($total - $index);
         }
         // Set query for next loop
         $query->clear()->select('id, type, fullpath')->from(_JOOM_TABLE_ORPHANS)->where("type = 'folder'");
         $this->_db->setQuery($query, $index, 1);
     }
     // Finished
     $this->_mainframe->setUserState('joom.maintenance.checked', time());
     $refresher->reset(null, null, JText::_('COM_JOOMGALLERY_MAIMAN_FINALIZING'));
     $refresher->refresh(0, 'display');
 }
Example #2
0
 /**
  * Recreates thumbnails of the selected images.
  * If original image is existent, detail image will be recreated, too.
  *
  * @return  array   An array of result information (thumbnail number, detail image number, array with information which image types have been recreated)
  * @since   1.5.5
  */
 public function recreate()
 {
     jimport('joomla.filesystem.file');
     $cids = $this->_mainframe->getUserStateFromRequest('joom.recreate.cids', 'cid', array(), 'array');
     $type = $this->_mainframe->getUserStateFromRequest('joom.recreate.type', 'type', '', 'cmd');
     $thumb_count = $this->_mainframe->getUserState('joom.recreate.thumbcount');
     $img_count = $this->_mainframe->getUserState('joom.recreate.imgcount');
     $recreated = $this->_mainframe->getUserState('joom.recreate.recreated');
     $row = $this->getTable('joomgalleryimages');
     // Before first loop check for selected images
     if (is_null($thumb_count) && !count($cids)) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_IMAGES_SELECTED'));
         return array(false);
     }
     if (is_null($recreated)) {
         $recreated = array();
     }
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher(array('controller' => 'images', 'task' => 'recreate', 'remaining' => count($cids), 'start' => JRequest::getBool('cid')));
     $debugoutput = '';
     // Loop through selected images
     foreach ($cids as $key => $cid) {
         $row->load($cid);
         $orig = $this->_ambit->getImg('orig_path', $row);
         $img = $this->_ambit->getImg('img_path', $row);
         $thumb = $this->_ambit->getImg('thumb_path', $row);
         // Check if there is an original image
         if (JFile::exists($orig)) {
             $orig_existent = true;
         } else {
             // If not, use detail image to create thumbnail
             $orig_existent = false;
             if (JFile::exists($img)) {
                 $orig = $img;
             } else {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_IMAGE_NOT_EXISTENT', $img));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
         }
         // Recreate thumbnail
         if (!$type || $type == 'thumb') {
             // TODO: Move image into a trash instead of deleting immediately for possible rollback
             if (JFile::exists($thumb)) {
                 JFile::delete($thumb);
             }
             $return = JoomFile::resizeImage($debugoutput, $orig, $thumb, $this->_config->get('jg_useforresizedirection'), $this->_config->get('jg_thumbwidth'), $this->_config->get('jg_thumbheight'), $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_thumbquality'), false, $this->_config->get('jg_cropposition'));
             if (!$return) {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_COULD_NOT_CREATE_THUMB', $thumb));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
             //$this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_SUCCESSFULLY_CREATED_THUMB', $row->id, $row->imgtitle));
             $recreated[$cid][] = 'thumb';
             $thumb_count++;
         }
         // Recreate detail image if original image is existent
         if ($orig_existent && (!$type || $type == 'img')) {
             // TODO: Move image into a trash instead of deleting immediately for possible rollback
             if (JFile::exists($img)) {
                 JFile::delete($img);
             }
             $return = JoomFile::resizeImage($debugoutput, $orig, $img, false, $this->_config->get('jg_maxwidth'), false, $this->_config->get('jg_thumbcreation'), $this->_config->get('jg_picturequality'), true, 0);
             if (!$return) {
                 JError::raiseWarning(100, JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_COULD_NOT_CREATE_IMG', $img));
                 $this->_mainframe->setUserState('joom.recreate.cids', array());
                 $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
                 $this->_mainframe->setUserState('joom.recreate.imgcount', null);
                 $this->_mainframe->setUserState('joom.recreate.recreated', null);
                 return false;
             }
             //$this->_mainframe->enqueueMessage(JText::sprintf('COM_JOOMGALLERY_IMGMAN_MSG_SUCCESSFULLY_CREATED_IMG', $row->id, $row->imgtitle));
             $recreated[$cid][] = 'img';
             $img_count++;
         }
         unset($cids[$key]);
         // Check remaining time
         if (!$refresher->check()) {
             $this->_mainframe->setUserState('joom.recreate.cids', $cids);
             $this->_mainframe->setUserState('joom.recreate.thumbcount', $thumb_count);
             $this->_mainframe->setUserState('joom.recreate.imgcount', $img_count);
             $this->_mainframe->setUserState('joom.recreate.recreated', $recreated);
             $refresher->refresh(count($cids));
         }
     }
     $this->_mainframe->setUserState('joom.recreate.cids', array());
     $this->_mainframe->setUserState('joom.recreate.type', null);
     $this->_mainframe->setUserState('joom.recreate.thumbcount', null);
     $this->_mainframe->setUserState('joom.recreate.imgcount', null);
     $this->_mainframe->setUserState('joom.recreate.recreated', null);
     return array($thumb_count, $img_count, $recreated);
 }
Example #3
0
 /**
  * Resets aliases of all images and categories
  *
  * @return  array An array of result information (image number, category number, result information about migrated dates)
  * @since   1.5.5
  */
 public function resetAliases()
 {
     $images = $this->_mainframe->getUserStateFromRequest('joom.setalias.images', 'images', array(), 'array');
     $categories = $this->_mainframe->getUserStateFromRequest('joom.setalias.categories', 'categories', array(), 'array');
     $img_count = $this->_mainframe->getUserState('joom.setalias.imgcount');
     $cat_count = $this->_mainframe->getUserState('joom.setalias.catcount');
     $start = JRequest::getBool('images') || JRequest::getBool('categories');
     // Before first loop check for selected images and categories
     if (isset($images[0]) && strpos(',', $images[0]) !== false) {
         $images = explode(',', $images[0]);
     }
     if (isset($categories[0]) && strpos(',', $categories[0]) !== false) {
         $categories = explode(',', $categories[0]);
     }
     if (is_null($img_count) && !count($images)) {
         $query = $this->_db->getQuery(true)->select('id')->from(_JOOM_TABLE_IMAGES);
         $this->_db->setQuery($query);
         if ($images = $this->_db->loadColumn()) {
             $start = true;
             $this->_mainframe->setUserState('joom.setalias.images', $images);
         }
     }
     if (is_null($cat_count) && !count($categories)) {
         $query = $this->_db->getQuery(true)->select('cid')->from(_JOOM_TABLE_CATEGORIES);
         $this->_db->setQuery($query);
         if ($categories = $this->_db->loadColumn()) {
             $start = true;
             $this->_mainframe->setUserState('joom.setalias.categories', $categories);
         }
     }
     if (!$images && !$categories) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_IMAGES_NO_CATEGORIES_SELECTED'));
         return array(false);
     }
     // Load refresher
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher(array('remaining' => count($images) + count($categories), 'start' => $start));
     $row = $this->getTable('joomgalleryimages');
     // Loop through selected images
     foreach ($images as $key => $id) {
         $row->load($id);
         $row->alias = '';
         $row->check();
         if (!$row->store()) {
             $this->setError($row->getError());
             $this->_mainframe->setUserState('joom.setalias.images', array());
             $this->_mainframe->setUserState('joom.setalias.categories', array());
             $this->_mainframe->setUserState('joom.setalias.imgcount', null);
             $this->_mainframe->setUserState('joom.setalias.catcount', null);
             return array(false);
         }
         $img_count++;
         unset($images[$key]);
         // Check remaining time
         if (!$refresher->check() && count($images)) {
             $this->_mainframe->setUserState('joom.setalias.images', $images);
             $this->_mainframe->setUserState('joom.setalias.imgcount', $img_count);
             $refresher->refresh(count($images) + count($categories));
         }
     }
     $row = $this->getTable('joomgallerycategories');
     //loop through selected categories
     foreach ($categories as $key => $id) {
         $row->load($id);
         // Trim slashes
         $row->catpath = trim($row->catpath, '/');
         $row->alias = '';
         $row->check();
         if (!$row->store()) {
             $this->setError($row->getError());
             $this->_mainframe->setUserState('joom.setalias.images', array());
             $this->_mainframe->setUserState('joom.setalias.categories', array());
             $this->_mainframe->setUserState('joom.setalias.imgcount', null);
             $this->_mainframe->setUserState('joom.setalias.catcount', null);
             return array(false);
         }
         $cat_count++;
         unset($categories[$key]);
         // Check remaining time
         if (!$refresher->check() && count($categories)) {
             $this->_mainframe->setUserState('joom.setalias.categories', $categories);
             $this->_mainframe->setUserState('joom.setalias.catcount', $cat_count);
             $refresher->refresh(count($categories));
         }
     }
     $this->_mainframe->setUserState('joom.setalias.images', array());
     $this->_mainframe->setUserState('joom.setalias.categories', array());
     $this->_mainframe->setUserState('joom.setalias.imgcount', null);
     $this->_mainframe->setUserState('joom.setalias.catcount', null);
     return array($img_count, $cat_count);
 }
Example #4
0
 /**
  * Removes one or more categories even though there
  * are still images or sub-categories in them.
  *
  * @access  public
  * @return  void
  * @since   1.5.5
  */
 function deletecompletely()
 {
     $mainframe = JFactory::getApplication('administrator');
     $categories = $mainframe->getUserState('joom.categories.delete.categories');
     $images = $mainframe->getUserState('joom.categories.delete.images');
     if (!$categories || !is_array($categories) || !count($categories)) {
         $this->setRedirect($this->_ambit->getRedirectUrl(), JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED'), 'notice');
         return;
     }
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher(array('msg' => true));
     $img_count = $mainframe->getUserState('joom.categories.delete.img_count');
     if (is_null($img_count)) {
         $img_count = 0;
     }
     $cat_count = $mainframe->getUserState('joom.categories.delete.cat_count');
     if (is_null($cat_count)) {
         $cat_count = 0;
     }
     $error = false;
     if ($images && is_array($images) && count($images)) {
         $model = $this->getModel('images');
         $row = $model->getTable('joomgalleryimages');
         foreach ($images as $key => $image) {
             // Check whether image still exists.
             // It may have been deleted before if categories were selected
             // to delete as well as their sub-categories.
             if ($row->load($image)) {
                 try {
                     $model->delete(array($image));
                 } catch (RuntimeException $e) {
                     JLog::add($e->getMessage(), JLog::ERROR, 'jerror');
                     $error = true;
                     break;
                 }
                 $img_count++;
             }
             unset($images[$key]);
             if (!$refresher->check()) {
                 $mainframe->setUserState('joom.categories.delete.images', $images);
                 $mainframe->setUserState('joom.categories.delete.img_count', $img_count);
                 $refresher->refresh();
             }
         }
     }
     $model = $this->getModel('categories');
     $row = $model->getTable('joomgallerycategories');
     $categories = $model->getOrderedCategories($categories, 'lft', 'DESC');
     if (!$error) {
         foreach ($categories as $key => $category) {
             // Check whether category still exists.
             // It may have been deleted before if categories were selected
             // to delete as well as their sub-categories.
             if ($row->load($category)) {
                 try {
                     $model->delete(array($category));
                 } catch (RuntimeException $e) {
                     JLog::add($e->getMessage(), JLog::ERROR, 'jerror');
                     break;
                 }
                 $cat_count++;
             }
             unset($categories[$key]);
             if (!$refresher->check() && count($categories)) {
                 $mainframe->setUserState('joom.categories.delete.images', $images);
                 $mainframe->setUserState('joom.categories.delete.categories', $categories);
                 $mainframe->setUserState('joom.categories.delete.img_count', $img_count);
                 $mainframe->setUserState('joom.categories.delete.cat_count', $cat_count);
                 $refresher->refresh();
             }
         }
     }
     if ($img_count) {
         if ($img_count == 1) {
             $msg = JText::_('COM_JOOMGALLERY_CATMAN_MSG_IMAGE_DELETED');
         } else {
             $msg = JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_IMAGES_DELETED', $img_count);
         }
         $mainframe->enqueueMessage($msg);
     }
     if ($cat_count == 1) {
         $msg = JText::_('COM_JOOMGALLERY_CATMAN_MSG_CATEGORY_DELETED');
     } else {
         $msg = JText::sprintf('COM_JOOMGALLERY_CATMAN_MSG_CATEGORIES_DELETED', $cat_count);
     }
     // Reset all user states of this task
     $mainframe->setUserState('joom.categories.delete', null);
     $this->setRedirect($this->_ambit->getRedirectUrl(), $msg);
 }
Example #5
0
 /**
  * FTP Upload
  * Several images uploaded via FTP before are moved to a category
  *
  * @return  void
  * @since   1.0.0
  */
 protected function uploadFTP()
 {
     // FTP upload is only available in backend at the moment
     if ($this->_site) {
         return false;
     }
     // Access check
     $category = $this->getCategory($this->catid);
     if (!$category || !$this->_user->authorise('joom.upload', _JOOM_OPTION . '.category.' . $this->catid) && (!$this->_user->authorise('joom.upload.inown', _JOOM_OPTION . '.category.' . $this->catid) || !$category->owner || $category->owner != $this->_user->get('id'))) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_YOU_ARE_NOT_ALLOWED_TO_UPLOAD_INTO_THIS_CATEGORY'));
         return false;
     }
     $subdirectory = $this->_db->escape($this->_mainframe->getUserStateFromRequest('joom.upload.ftp.subdirectory', 'subdirectory', '/', 'post', 'string'));
     $ftpfiles = $this->_mainframe->getUserStateFromRequest('joom.upload.ftp.files', 'ftpfiles', array(), 'array');
     if (!$ftpfiles && JRequest::getBool('ftpfiles')) {
         $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_IMAGES_SELECTED'));
         return false;
     }
     // Load the refresher
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher(array('remaining' => count($ftpfiles), 'start' => JRequest::getBool('ftpfiles')));
     $this->_debugoutput .= '<p></p>';
     foreach ($ftpfiles as $key => $origfilename) {
         // Check remaining time
         if (!$refresher->check()) {
             $this->_mainframe->setUserState('joom.upload.ftp.files', $ftpfiles);
             //$this->_mainframe->setUserState('joom.upload.debugoutput', $this->_debugoutput);
             $this->_mainframe->setUserState('joom.upload.debug', $this->debug);
             $refresher->refresh(count($ftpfiles));
         }
         // Get extension
         $tag = strtolower(JFile::getExt($origfilename));
         $this->_debugoutput .= '<hr />';
         $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_FILENAME', $origfilename) . '<br />';
         /*// Image size must not exceed the setting in backend if we are in frontend
           if($this->_site && $screenshot_filesize > $this->_config->get('jg_maxfilesize'))
           {
             $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_OUTPUT_MAX_ALLOWED_FILESIZE', $this->_config->get('jg_maxfilesize')).'<br />';
             $this->debug  = true;
             unset($ftpfiles[$key]);
             continue;
           }*/
         // Check for right format
         if ($tag != 'jpeg' && $tag != 'jpg' && $tag != 'jpe' && $tag != 'gif' && $tag != 'png' || strlen($origfilename) == 0) {
             $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_INVALID_IMAGE_TYPE') . '<br />';
             $this->debug = true;
             unset($ftpfiles[$key]);
             continue;
         }
         // Check filename for special characters if not allowed
         if ($this->_config->get('jg_filenamewithjs') == 0) {
             if ($this->_site && $this->_config->get('jg_useruseorigfilename') || !$this->_site && $this->_config->get('jg_useorigfilename')) {
                 $filename = $origfilename;
             } else {
                 $filename = $this->imgtitle;
             }
             if (JoomFile::checkValidFilename($filename, '', true) == false) {
                 $this->_debugoutput .= strip_tags(JText::_('COM_JOOMGALLERY_UPLOAD_ERROR_INVALIDSC_FILENAME'));
                 $this->debug = true;
                 unset($ftpfiles[$key]);
                 continue;
             }
         }
         $filecounter = null;
         if ($this->_site && $this->_config->get('jg_useruploadnumber') || !$this->_site && $this->_config->get('jg_filenamenumber')) {
             $filecounter = $this->_getSerial();
         }
         // Create new filename
         // If generic filename set in backend use them
         if ($this->_site && $this->_config->get('jg_useruseorigfilename') || !$this->_site && $this->_config->get('jg_useorigfilename')) {
             $oldfilename = $origfilename;
             $newfilename = JoomFile::fixFilename($origfilename);
         } else {
             $oldfilename = $this->imgtitle;
             $newfilename = JoomFile::fixFilename($this->imgtitle);
         }
         // Check the new filename
         if (JoomFile::checkValidFilename($oldfilename, $newfilename) == false) {
             $this->_debugoutput .= strip_tags(JText::sprintf('COM_JOOMGALLERY_UPLOAD_ERROR_INVALID_FILENAME', $newfilename, $oldfilename));
             $this->debug = true;
             unset($ftpfiles[$key]);
             continue;
         }
         $newfilename = $this->_genFilename($newfilename, $tag, $filecounter);
         // Resize image
         $delete_file = $this->_mainframe->getUserStateFromRequest('joom.upload.file_delete', 'file_delete', false, 'bool');
         if (!$this->resizeImage(JPath::clean($this->_ambit->get('ftp_path') . $subdirectory . $origfilename), $newfilename, false, $delete_file)) {
             $this->rollback($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), $this->_ambit->getImg('img_path', $newfilename, null, $this->catid), $this->_ambit->getImg('thumb_path', $newfilename, null, $this->catid));
             $this->debug = true;
             unset($ftpfiles[$key]);
             continue;
         }
         $row = JTable::getInstance('joomgalleryimages', 'Table');
         if (!$this->registerImage($row, $origfilename, $newfilename, $tag, $filecounter)) {
             $this->rollback($this->_ambit->getImg('orig_path', $newfilename, null, $this->catid), $this->_ambit->getImg('img_path', $newfilename, null, $this->catid), $this->_ambit->getImg('thumb_path', $newfilename, null, $this->catid));
             $this->debug = true;
             unset($ftpfiles[$key]);
             continue;
         }
         $this->_debugoutput .= JText::_('COM_JOOMGALLERY_UPLOAD_OUTPUT_IMAGE_SUCCESSFULLY_ADDED') . '<br />';
         $this->_debugoutput .= JText::sprintf('COM_JOOMGALLERY_UPLOAD_NEW_FILENAME', $newfilename) . '<br /><br />';
         $this->_mainframe->triggerEvent('onJoomAfterUpload', array($row));
         unset($ftpfiles[$key]);
     }
     $this->_debugoutput .= '<hr /><br />';
     // Reset file counter, delete original delete source file and
     // create special gif selection and debug information
     $this->_mainframe->setUserState('joom.upload.filecounter', 0);
     $this->_mainframe->setUserState('joom.upload.file_delete', false);
     $this->_mainframe->setUserState('joom.upload.delete_original', false);
     $this->_mainframe->setUserState('joom.upload.create_special_gif', false);
     $this->_mainframe->setUserState('joom.upload.debug', false);
     $this->_mainframe->setUserState('joom.upload.debugoutput', null);
     if ($this->debug) {
         echo $this->_debugoutput;
     }
     return !$this->debug;
 }
Example #6
0
 /**
  * Removes one or more categories even though there
  * are still images or sub-categories in them.
  *
  * @return  void
  * @since   1.5.5
  */
 public function deleteCompletely()
 {
     $mainframe = JFactory::getApplication('administrator');
     $categories = $mainframe->getUserState('joom.maintenance.delete.categories');
     $images = $mainframe->getUserState('joom.maintenance.delete.images');
     if (!$categories || !is_array($categories) || !count($categories)) {
         $this->setRedirect($this->_ambit->getRedirectUrl() . '&tab=categories', JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED'), 'notice');
         return;
     }
     require_once JPATH_COMPONENT . '/helpers/refresher.php';
     $refresher = new JoomRefresher();
     $img_count = $mainframe->getUserState('joom.maintenance.delete.img_count');
     if (is_null($img_count)) {
         $img_count = 0;
     }
     $cat_count = $mainframe->getUserState('joom.maintenance.delete.cat_count');
     if (is_null($cat_count)) {
         $cat_count = 0;
     }
     $model = $this->getModel('maintenance');
     if ($images && is_array($images) && count($images)) {
         $row = $model->getTable('joomgalleryimages');
         foreach ($images as $key => $image) {
             // Check whether image still exists.
             // It may have been deleted before if categories were selected
             // to delete as well as their sub-categories.
             if ($row->load($image)) {
                 JRequest::setVar('cid', array($image));
                 if ($model->delete(false)) {
                     $img_count++;
                 }
                 unset($images[$key]);
             }
             if (!$refresher->check()) {
                 $mainframe->setUserState('joom.maintenance.delete.images', $images);
                 $mainframe->setUserState('joom.maintenance.delete.img_count', $img_count);
                 $refresher->refresh();
             }
         }
     }
     $row = $model->getTable('joomgallerycategories');
     for ($i = count($categories) - 1; $i >= 0; $i--) {
         foreach ($categories[$i] as $key => $category) {
             // Check whether category still exists.
             // It may have been deleted before if categories were selected
             // to delete as well as their sub-categories.
             if ($row->load($category)) {
                 JRequest::setVar('cid', array($category));
                 if ($model->deletecategory(false, false)) {
                     $cat_count++;
                 }
                 unset($categories[$i][$key]);
             }
             if (!$refresher->check() && count($categories[0])) {
                 $mainframe->setUserState('joom.maintenance.delete.categories', $categories);
                 $mainframe->setUserState('joom.maintenance.delete.img_count', $img_count);
                 $mainframe->setUserState('joom.maintenance.delete.cat_count', $cat_count);
                 $refresher->refresh();
             }
         }
     }
     if ($img_count) {
         if ($img_count == 1) {
             $msg = JText::_('COM_JOOMGALLERY_MAIMAN_MSG_IMAGE_DELETED');
         } else {
             $msg = JText::sprintf('COM_JOOMGALLERY_MAIMAN_MSG_IMAGES_DELETED', $img_count);
         }
         $mainframe->enqueueMessage($msg);
     }
     if ($cat_count) {
         if ($cat_count == 1) {
             $msg = JText::_('COM_JOOMGALLERY_MAIMAN_MSG_CATEGORY_DELETED');
         } else {
             $msg = JText::sprintf('COM_JOOMGALLERY_MAIMAN_MSG_CATEGORIES_DELETED', $cat_count);
         }
         $mainframe->enqueueMessage($msg);
     }
     // Reset all user states of this task
     $mainframe->setUserState('joom.maintenance.delete', null);
     $this->setRedirect($this->_ambit->getRedirectUrl() . '&tab=categories');
 }