Ejemplo n.º 1
1
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return    boolean    True on success.
  */
 public function checkData($isNew, $auto_added = false)
 {
     global $jlistConfig;
     jimport('joomla.filesystem.file ');
     jimport('joomla.filesystem.folder');
     jimport('joomla.html.html');
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     // we neeed the jform data
     $jinput = JFactory::getApplication()->input;
     $formdata = $jinput->get('jform', array(), 'array');
     // we neeed also the jform files data
     $jFileInput = new JInput($_FILES);
     $files = $jFileInput->get('jform', array(), 'array');
     $default_access_value_used = false;
     // doing the next part only when we have a new download creation or an editing in frontend
     if ($app->isSite() && !$auto_added) {
         $user_rules = JDHelper::getUserRules();
         // we must check some from the required fields manually, which are not checked with javascript
         if ($this->cat_id == 0) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CATEGORY'));
         }
         if ($user_rules->form_changelog && $user_rules->form_changelog_x && $this->changelog == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CHANGELOG'));
         }
         if ($user_rules->form_short_desc && $user_rules->form_short_desc_x && $this->description == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_SHORT_DESC'));
         }
         if ($user_rules->form_long_desc && $user_rules->form_long_desc_x && $this->description_long == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_LONG_DESC'));
         }
         if ($user_rules->form_extra_large_input_1 && $user_rules->form_extra_large_input_1_x && $this->custom_field_13 == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_TEXT'));
         }
         if ($user_rules->form_extra_large_input_2 && $user_rules->form_extra_large_input_2_x && $this->custom_field_14 == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_TEXT'));
         }
         if ($user_rules->form_license && $user_rules->form_license_x && !$this->license) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_LICENSE'));
         }
         if ($user_rules->form_creation_date && $user_rules->form_creation_date_x && $this->date_added == '0000-00-00 00:00:00') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_DATE_ADDED'));
         }
         if ($user_rules->form_file_date && $user_rules->form_file_date_x && $this->file_date == '0000-00-00 00:00:00') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_DATE_FILE'));
         }
         if ($user_rules->form_file_language && $user_rules->form_file_language_x && !$this->file_language) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_LANGUAGE_FILE'));
         }
         if ($user_rules->form_file_system && $user_rules->form_file_system_x && !$this->system) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_SYSTEM_FILE'));
         }
         if ($user_rules->form_file_pic && $user_rules->form_file_pic_x && !$this->file_pic) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_PIC_FILE'));
         }
         // we need the total amount of selected image files
         $thumb_image_files = $jFileInput->get('file_upload_thumb', array(), 'array');
         $amount_selected_thumbs_files = count($thumb_image_files['name']);
         foreach ($thumb_image_files['name'] as $name) {
             if (!$name) {
                 $amount_selected_thumbs_files--;
             }
         }
         if ($user_rules->form_images && $user_rules->form_images_x && !$amount_selected_thumbs_files) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_IMAGES'));
         }
         if ($user_rules->form_extra_select_box_1 && $user_rules->form_extra_select_box_1_x && !$this->custom_field_1) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_SELECT'));
         }
         if ($user_rules->form_extra_select_box_2 && $user_rules->form_extra_select_box_2_x && !$this->custom_field_2) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_SELECT'));
         }
         if ($user_rules->form_extra_select_box_3 && $user_rules->form_extra_select_box_3_x && !$this->custom_field_3) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_SELECT'));
         }
         if ($user_rules->form_extra_select_box_4 && $user_rules->form_extra_select_box_4_x && !$this->custom_field_4) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_SELECT'));
         }
         if ($user_rules->form_extra_select_box_5 && $user_rules->form_extra_select_box_5_x && !$this->custom_field_5) {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_SELECT'));
         }
         if ($user_rules->form_extra_date_1 && $user_rules->form_extra_extra_date_1_x && $this->custom_field_11 == '0000-00-00 00:00:00') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_DATE'));
         }
         if ($user_rules->form_extra_date_2 && $user_rules->form_extra_extra_date_2_x && $this->custom_field_12 == '0000-00-00 00:00:00') {
             $this->setError(JText::_('COM_JDOWNLOADS_REQUIRED_CUSTOM_DATE'));
         }
         // break when we have before found a invalid data field
         if ($this->getErrors()) {
             return false;
         }
         // check the file extension when frontend upload
         if ($files['tmp_name']['file_upload'] != '' || $files['name']['file_upload'] != '') {
             $file_extension = JFile::getExt($files['name']['file_upload']);
             $user_file_types = explode(',', strtolower($user_rules->uploads_allowed_types));
             if (!in_array(strtolower($file_extension), $user_file_types)) {
                 // error - user have tried to upload a not allowed file type
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_FILE_TYPE'));
                 return false;
             }
             // check allowed file size
             if ($files['size']['file_upload'] > $user_rules->uploads_maxfilesize_kb * 1024 || $files['name']['file_upload'] != '' && $files['size']['file_upload'] == 0) {
                 // error - user have tried to upload a to big file
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_FILE_SIZE'));
                 return false;
             }
         }
         // check the file extension when frontend preview file upload
         if ($files['tmp_name']['preview_file_upload'] != '' || $files['name']['preview_file_upload'] != '') {
             $file_prev_extension = JFile::getExt($files['name']['preview_file_upload']);
             $user_preview_file_types = explode(',', $user_rules->uploads_allowed_preview_types);
             if (!in_array($file_prev_extension, $user_preview_file_types)) {
                 // error - user have tried to upload a not allowed file type
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_PREVIEW_FILE_TYPE'));
                 return false;
             }
             // check allowed file size
             if ($files['size']['preview_file_upload'] > $user_rules->uploads_maxfilesize_kb * 1024 || $files['name']['preview_file_upload'] != '' && $files['size']['preview_file_upload'] == 0) {
                 // error - user have tried to upload a to big file
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_FILE_SIZE'));
                 return false;
             }
         }
         // check the access handling
         if ($user_rules->form_access == 0) {
             // the access select field was not viewed so we use the default value when exist
             if ($user_rules->uploads_default_access_level) {
                 $this->access = (int) $user_rules->uploads_default_access_level;
                 $default_access_value_used = true;
             }
         } else {
             // the access select field was viewed
             if ($this->access > 1) {
                 // user has selected a special access level so we do not use the access value from parent category
                 $default_access_value_used = true;
             }
         }
     }
     // this part is always used
     if ($this->cat_id > 1) {
         if ($isNew && !$default_access_value_used) {
             // set access level value from parent
             $query = "SELECT * FROM #__jdownloads_categories WHERE id = '{$this->cat_id}'";
             $db->setQuery($query);
             $parent_cat = $db->loadObject();
             $this->access = $parent_cat->access;
         }
     }
     // we need the rest only when the new item is not added by monitoring !!!
     if (!$auto_added) {
         // get the uploaded image files
         $imagefiles = $jFileInput->get('file_upload_thumb', array(), 'array');
         $movedmsg = '';
         $errormsg = '';
         $cat_dir_org = '';
         $filename_org = '';
         $marked_cat_id = '';
         $file_cat_changed = false;
         $invalid_filename = false;
         $thumb_created = false;
         $image_created = false;
         $image_thumb_name = '';
         $filename_renamed = false;
         $filename_new_name = '';
         $filename_old_name = '';
         $use_xml_for_file_info = 0;
         $selected_updatefile = 0;
         // use xml install file to fill the file informations
         if (isset($formdata['use_xml'])) {
             $use_xml_for_file_info = (int) $formdata['use_xml'];
         }
         // marked cat id
         if (isset($formdata['cat_id'])) {
             $marked_cat_id = (int) $formdata['cat_id'];
         } else {
             // is download added about jdownloadsModeldownload::createDownload() ?
             if ($this->cat_id > 0) {
                 $marked_cat_id = (int) $this->cat_id;
             }
         }
         // prior marked cat id
         $cat_dir_org = $jinput->get('cat_dir_org', 0, 'integer');
         // original filename changed?
         $filename_org = $jinput->get('filename_org', '', 'string');
         if (!$isNew && $filename_org != '' && $formdata['url_download'] != '' && $filename_org != $formdata['url_download']) {
             $filename_renamed = true;
             $filename_new_name = $formdata['url_download'];
             $filename_old_name = $filename_org;
         }
         // original preview filename changed?
         $preview_filename_org = $jinput->get('preview_filename_org', '', 'string');
         if (!$isNew && $preview_filename_org != '' && $formdata['preview_filename'] != '' && $preview_filename_org != $formdata['preview_filename']) {
             $preview_filename_renamed = true;
             $preview_filename_new_name = $formdata['preview_filename'];
             $preview_filename_old_name = $preview_filename_org;
         }
         // get selected file from server for update download?
         if (isset($formdata['update_file'])) {
             $selected_updatefile = $formdata['update_file'];
         }
         // When download is new created in frontend, we must do some other things...
         if ($app->isSite() && !$auto_added) {
             if ($isNew) {
                 $this->submitted_by = $user->id;
                 if ($user_rules->uploads_auto_publish == 1) {
                     $this->published = 1;
                 }
                 if ($jlistConfig['use.alphauserpoints'] && $this->published == 1) {
                     // add the AUP points
                     JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                 }
             } else {
                 if ($jlistConfig['use.alphauserpoints'] && $this->published == 1) {
                     // add the AUP points when an older download is published (maybe the first time)
                     JDHelper::setAUPPointsUploads($this->submitted_by, $this->file_title);
                 }
             }
         } else {
             $this->set_aup_points = $jinput->get('set_aup_points', 0, 'integer');
             $this->submitted_by = $jinput->get('submitted_by', 0, 'integer');
         }
         $this->extern_file = $formdata['extern_file'];
         $this->url_home = $formdata['url_home'];
         $this->url_author = $formdata['url_author'];
         $this->author = $formdata['author'];
         $this->mirror_1 = $formdata['mirror_1'];
         $this->mirror_2 = $formdata['mirror_2'];
         $this->extern_site = (int) $formdata['extern_site'];
         $this->extern_site_mirror_1 = (int) $formdata['extern_site_mirror_1'];
         $this->extern_site_mirror_2 = (int) $formdata['extern_site_mirror_2'];
         // check for valid name
         if (trim($this->file_title) == '') {
             $this->setError(JText::_('COM_JDOWNLOADS_TITLE_NOT_SET'));
             return false;
         }
         // check date, user id fields and cat_id
         if (!$isNew) {
             // old download changed
             // set user id in modified field
             $this->modified_id = $user->id;
             // fill out modified date field
             // get first the old date and compare it with the current value from the form
             // when user has self changed the date value - so we do not change it here
             // otherwise use we the current date and time
             $modified_date_old = $jinput->get('modified_date_old', '', 'string');
             if ($modified_date_old == $this->modified_date) {
                 $this->modified_date = JFactory::getDate()->toSql();
             }
             if ($cat_dir_org != $marked_cat_id) {
                 $file_cat_changed = true;
                 $this->cat_id = $marked_cat_id;
             }
         } else {
             // fill out created date field
             $this->date_added = JFactory::getDate()->toSql();
             // $this->date_added = JHtml::_('date', '','Y-m-d H:i:s');
             if (!$this->created_id) {
                 $this->created_id = $user->id;
             }
         }
         // get the selected categories folder name, when it is not uncategorised selected
         if ($marked_cat_id > 1) {
             $db->SetQuery("SELECT cat_dir, cat_dir_parent FROM #__jdownloads_categories WHERE id = {$marked_cat_id}");
             $stored_catdir = $db->loadObject();
             if (!$stored_catdir) {
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_CAT_DIR_NOT_EXIST'));
                 return false;
             } else {
                 // build the complete stored category path
                 if ($stored_catdir->cat_dir_parent != '') {
                     $mark_catdir = $stored_catdir->cat_dir_parent . DS . $stored_catdir->cat_dir;
                 } else {
                     $mark_catdir = $stored_catdir->cat_dir;
                 }
             }
         } else {
             if ($marked_cat_id == 1) {
                 // 'uncategorised' is selected
                 $mark_catdir = $jlistConfig['uncategorised.files.folder.name'];
             }
         }
         // when we will use a file from a other download, we must delete first the old file when it exist
         // the same, when we will use a file from the server
         if ($this->other_file_id > 0 && $this->url_download != '' || $selected_updatefile > 0 && $this->url_download != '') {
             $path = $jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download;
             if (JFile::exists($path)) {
                 JFile::delete($path);
             }
             $this->url_download = '';
         }
         $this->description = rtrim(stripslashes($this->description));
         $this->description_long = rtrim(stripslashes($this->description_long));
         if ($this->file_id) {
             // get filesize and date if no value set
             if ($formdata['size'] != '' && $formdata['size'] != $this->size && $files['tmp_name']['file_upload'] == '' && !$file_cat_changed) {
                 // user had changed the size manually
                 $this->size = JFilterInput::getInstance(null, null, 1, 1)->clean($formdata['size'], 'STRING');
             }
             if (!(int) $this->size > 0 && $files['tmp_name']['file_upload'] == '' && !$file_cat_changed) {
                 if ($this->url_download) {
                     $filepath = $jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download;
                     if (JFile::exists($filepath)) {
                         $this->size = jdownloadsHelper::fsize($filepath);
                     }
                 } elseif ($this->extern_file != '') {
                     // get extern file size
                     $this->size = jdownloadsHelper::urlfilesize($this->extern_file, 'b');
                 } elseif ($this->other_file_id > 0) {
                     // use file from other download - get the size from it
                     $this->size = jdownloadsHelper::getFieldDataFromDownload($this->other_file_id, 'size');
                 }
             }
             // is date empty get filedate - only for intern linked files
             if ($this->url_download) {
                 if (empty($this->date_added) and $files['tmp_name']['file_upload'] == '' and !$file_cat_changed) {
                     $this->date_added = date("Y-m-d H:i:s", filemtime($jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download));
                 }
             } elseif ($this->extern_file != '') {
                 // is extern file - try to get the data
                 if (empty($this->date_added) and $files['tmp_name']['file_upload'] == '' and !$file_cat_changed) {
                     $this->date_added = jdownloadsHelper::urlfiledate($this->extern_file);
                     $this->size = jdownloadsHelper::urlfilesize($this->extern_file, 'b');
                 }
             } elseif ($this->other_file_id > 0) {
                 // use file from other download - get the date from it
                 $this->file_date = jdownloadsHelper::getFieldDataFromDownload($this->other_file_id, 'file_date');
             }
         } else {
             if (!(int) $this->size > 0 && $files['tmp_name']['file_upload'] == '' && !$file_cat_changed) {
                 if ($this->url_download) {
                     $filepath = $jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download;
                     if (JFile::exists($filepath)) {
                         $this->size = jdownloadsHelper::fsize($filepath);
                     }
                 } elseif ($this->extern_file != '') {
                     // get extern file file
                     $this->size = jdownloadsHelper::urlfilesize($this->extern_file, 'b');
                 } elseif ($this->other_file_id > 0) {
                     // use file from other download - get the size from it
                     $this->size = jdownloadsHelper::getFieldDataFromDownload($this->other_file_id, 'size');
                 }
             }
         }
         //handle now the basic file upload for this download
         if ($files['tmp_name']['file_upload'] != '') {
             // clear the other fields
             $this->other_file_id = '';
             // delete first old assigned file if exist - so we can use for a update a file with the same filename!
             // we must delete it, otherwise found the auto monitoring it as new file and will add it as new founded file!
             if ($this->url_download) {
                 if (JFile::exists($jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download)) {
                     JFile::delete($jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/' . $this->url_download);
                     $this->size = '';
                 }
             }
             $upload_dir = $jlistConfig['files.uploaddir'] . '/' . $mark_catdir . '/';
             $only_name = JFile::stripExt($files['name']['file_upload']);
             $file_extension = JFile::getExt($files['name']['file_upload']);
             // check filename
             $filename_new = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
             $only_name = JFile::stripExt($filename_new);
             $file_extension = JFile::getExt($filename_new);
             if ($only_name != '') {
                 // filename is valid
                 $num = 0;
                 // rename new file when it exists in this folder
                 while (JFile::exists($upload_dir . $filename_new)) {
                     $filename_new = $only_name . $num++ . '.' . $file_extension;
                     if ($num > 5000) {
                         break;
                     }
                 }
                 $files['name']['file_upload'] = $filename_new;
                 $target_path = $upload_dir . $files['name']['file_upload'];
                 // When file mime is an image type, make sure that we have not a fake pic
                 $file_is_image = JDownloadsHelper::fileIsImage($files['type']['file_upload']);
                 if ($file_is_image && !JDownloadsHelper::imageFileIsValid($files['tmp_name']['file_upload'])) {
                     $files['tmp_name']['file_upload'] = '';
                     // error - user have tried to upload a not valid image file
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_IMAGE_FILE'));
                     return false;
                 }
                 if (JFile::upload($files['tmp_name']['file_upload'], $target_path, false, true)) {
                     $this->sha1_value = sha1_file($target_path);
                     $this->md5_value = md5_file($target_path);
                     $this->url_download = basename($target_path);
                     $this->extern_file = '';
                     $this->extern_site = '';
                     // set file extension pic
                     $filepfad = JPATH_SITE . '/images/jdownloads/fileimages/' . strtolower($file_extension) . '.png';
                     if (JFile::exists(JPATH_SITE . '/images/jdownloads/fileimages/' . strtolower($file_extension) . '.png')) {
                         $this->file_pic = strtolower($file_extension) . '.png';
                     } else {
                         $this->file_pic = $jlistConfig['file.pic.default.filename'];
                     }
                     // get filesize and date if no value set from user after upload
                     $this->size = jdownloadsHelper::fsize($target_path);
                     // is date empty get filedate
                     if (empty($this->date_added)) {
                         $this->date_added = JHtml::_('date', 'now', 'Y-m-d H:i:s');
                     }
                     // is file creation date empty - set filedate to now
                     if (empty($this->file_date)) {
                         $this->file_date = JHtml::_('date', 'now', 'Y-m-d H:i:s');
                     }
                     // create thumbs form pdf
                     if ($jlistConfig['create.pdf.thumbs'] && strtolower($file_extension) == 'pdf') {
                         $thumb_path = JPATH_SITE . '/images/jdownloads/screenshots/thumbnails/';
                         $screenshot_path = JPATH_SITE . '/images/jdownloads/screenshots/';
                         $pdf_thumb_name = jdownloadsHelper::create_new_pdf_thumb($target_path, $only_name, $thumb_path, $screenshot_path);
                         if ($pdf_thumb_name) {
                             $image_thumb_name = $pdf_thumb_name;
                             $thumb_created = TRUE;
                         }
                     }
                     // create auto thumb when extension is a pic
                     if ($jlistConfig['create.auto.thumbs.from.pics'] && $file_is_image) {
                         $thumb_created = jdownloadsHelper::create_new_thumb($target_path);
                         if ($thumb_created) {
                             $image_thumb_name = $filename_new;
                             // create new big image for full view
                             $image_created = jdownloadsHelper::create_new_image($target_path);
                         }
                     }
                     // use xml to read file info (works with joomla install packages (also others?)
                     if ($use_xml_for_file_info) {
                         $xml_tags = jdownloadsHelper::getXMLdata($target_path, $this->url_download);
                         if ($xml_tags[name] != '') {
                             $row = $this;
                             $row_file_title = jdownloadsHelper::fillFileDateFromXML($row, $xml_tags);
                             if (!$row_file_title) {
                                 $this->setError(JText::_('COM_JDOWNLOADS_BE_EDIT_FILES_USE_XML_RESULT_NO_DATA'));
                                 return false;
                             }
                             $movedmsg .= JText::_('COM_JDOWNLOADS_BE_EDIT_FILES_USE_XML_RESULT_OK');
                         } else {
                             // no xml data found
                             $this->file_title = $this->url_download;
                             $errormsg .= JText::_('COM_JDOWNLOADS_BE_EDIT_FILES_USE_XML_RESULT_NO_FILE');
                         }
                     }
                 } else {
                     // error - can not write on server folder - wrong permissions set?
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_CHECK_PERMISSIONS'));
                     return false;
                 }
             } else {
                 // filename is after clearing empty - invalid filename
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_FILENAME'));
             }
         } else {
             // no new file seletcted for upload
             // check now whether assigned category has changed - if so, then move the file
             if ($file_cat_changed && $this->url_download != '') {
                 // move file
                 // get the folder name from the old category folder - so we can build the path
                 if ($cat_dir_org != 1) {
                     // it is NOT a 'uncategorised' download!
                     $db->SetQuery("SELECT cat_dir, cat_dir_parent FROM #__jdownloads_categories WHERE id = '{$cat_dir_org}'");
                     $old_stored_catdir = $db->loadObject();
                 } else {
                     // get the uncategorised folder name from configuration
                     $old_stored_catdir->cat_dir = $jlistConfig['uncategorised.files.folder.name'];
                 }
                 // build the complete stored cat path
                 if ($old_stored_catdir->cat_dir_parent != '') {
                     $old_catdir = $old_stored_catdir->cat_dir_parent . DS . $old_stored_catdir->cat_dir;
                 } else {
                     $old_catdir = $old_stored_catdir->cat_dir;
                 }
                 // move it now to the new folder place
                 if (jFile::move($old_catdir . DS . $this->url_download, $mark_catdir . DS . $this->url_download, $jlistConfig['files.uploaddir'] . DS)) {
                     $movedmsg .= JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_SAVE_MOVEFILE_OK');
                 } else {
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_SAVE_MOVEFILE_ERROR'));
                     return false;
                 }
             }
             // is alternate a file from the server selected to update the download?
             if ($selected_updatefile) {
                 // clear the other field
                 $this->other_file_id = '';
                 // okay, then we will use it
                 $update_dir = $jlistConfig['files.uploaddir'] . DS;
                 // todo: we must use here the new methode for this in next release
                 $only_name = JFile::stripExt($selected_updatefile);
                 $file_extension = JFile::getExt($selected_updatefile);
                 $update_filename = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
                 if ($update_filename != $selected_updatefile) {
                     // rename file
                     jFile::move($update_dir . $selected_updatefile, $update_dir . $update_filename);
                 }
                 // delete first old assigned file
                 if ($this->cat_id > 1) {
                     $db->setQuery("SELECT cat_dir, cat_dir_parent FROM #__jdownloads_categories WHERE id = '{$this->cat_id}'");
                     $cat_dirs = $db->loadObject();
                     if ($cat_dirs->cat_dir_parent != '') {
                         $cat_dir = $cat_dirs->cat_dir_parent . '/' . $cat_dirs->cat_dir;
                     } else {
                         $cat_dir = $cat_dirs->cat_dir;
                     }
                 } else {
                     // the used category is 'uncategorised'
                     $cat_dir = $jlistConfig['uncategorised.files.folder.name'];
                 }
                 if (JFile::exists($jlistConfig['files.uploaddir'] . DS . $cat_dir . DS . $this->url_download)) {
                     JFile::delete($jlistConfig['files.uploaddir'] . DS . $cat_dir . DS . $this->url_download);
                 }
                 // set new url_download value
                 $this->url_download = $update_filename;
                 // move the file from the upload root folder to the new target folder
                 $target_path = $jlistConfig['files.uploaddir'] . DS . $cat_dir . DS . $update_filename;
                 if (jFile::move($update_dir . $update_filename, $target_path)) {
                     $this->size = jdownloadsHelper::fsize($target_path);
                     $movedmsg .= JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_SAVE_MOVEFILE_OK');
                     $this->sha1_value = sha1_file($target_path);
                     $this->md5_value = md5_file($target_path);
                 }
                 if (JFile::exists($update_dir . $update_filename)) {
                     JFile::delete($update_dir . $update_filename);
                 }
                 // use xml to read file info (works with joomla install packages (also others?)
                 if ($use_xml_for_file_info) {
                     $xml_tags = jdownloadsHelper::getXMLdata($target_path, $this->url_download);
                     if ($xml_tags[name] != '') {
                         $row = $this;
                         $row_file_title = jdownloadsHelper::fillFileDateFromXML($row, $xml_tags);
                         if (!$row_file_title) {
                             $this->setError(JText::_('COM_JDOWNLOADS_BE_EDIT_FILES_USE_XML_RESULT_NO_DATA'));
                             return false;
                         }
                     } else {
                         // no xml data found
                         $this->file_title = $this->url_download;
                         $this->setError(JText::_('COM_JDOWNLOADS_BE_EDIT_FILES_USE_XML_RESULT_NO_FILE'));
                     }
                 }
                 // create thumbs form pdf
                 if ($jlistConfig['create.pdf.thumbs'] && strtolower($file_extension) == 'pdf') {
                     $thumb_path = JPATH_SITE . '/images/jdownloads/screenshots/thumbnails/';
                     $screenshot_path = JPATH_SITE . '/images/jdownloads/screenshots/';
                     $pdf_thumb_name = jdownloadsHelper::create_new_pdf_thumb($target_path, JFile::stripExt($update_filename), $thumb_path, $screenshot_path);
                     if ($pdf_thumb_name) {
                         $image_thumb_name = $pdf_thumb_name;
                         $thumb_created = TRUE;
                     }
                 }
                 // When file mime is an image type, make sure that we have not a fake pic
                 $file_is_image = JDownloadsHelper::fileIsPicture($update_filename);
                 if ($file_is_image && !JDownloadsHelper::imageFileIsValid($target_path)) {
                     $this->images = '';
                     // error - user have tried to upload a not valid image file
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_IMAGE_FILE'));
                     return false;
                 }
                 // create auto thumb when extension is a pic
                 if ($jlistConfig['create.auto.thumbs.from.pics'] && $file_is_image) {
                     $thumb_created = jdownloadsHelper::create_new_thumb($target_path);
                     if ($thumb_created) {
                         $image_thumb_name = $update_filename;
                         // create new big image for full view
                         $image_created = jdownloadsHelper::create_new_image($target_path);
                     }
                 }
             } elseif ($this->other_file_id > 0) {
                 // file from an other download is selected
                 // get mdh5 and sha1
                 $this->md5_value = jdownloadsHelper::getFieldDataFromDownload($this->other_file_id, 'md5_value');
                 $this->sha1_value = jdownloadsHelper::getFieldDataFromDownload($this->other_file_id, 'sha1_value');
             } else {
                 // has user the filename manually renamed? Then do it now.
                 if ($filename_renamed) {
                     $only_name = JFile::stripExt($filename_new_name);
                     $file_extension = JFile::getExt($filename_new_name);
                     // check new filename
                     $filename_new = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
                     $only_name = JFile::stripExt($filename_new);
                     if ($only_name != '') {
                         if (JFile::move($jlistConfig['files.uploaddir'] . DS . $mark_catdir . DS . $filename_old_name, $jlistConfig['files.uploaddir'] . DS . $mark_catdir . DS . $filename_new)) {
                             // change now value in table field
                             $this->url_download = $filename_new;
                             JError::raiseNotice(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_RENAMED'));
                         } else {
                             // error - can not rename
                             JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_ERROR'));
                         }
                     } else {
                         // filename is after clearing empty - invalid filename
                         JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_ERROR'));
                     }
                 }
                 // has user the preview filename manually renamed? Then do it now.
                 if ($preview_filename_renamed) {
                     $only_name = JFile::stripExt($preview_filename_new_name);
                     $file_extension = JFile::getExt($preview_filename_new_name);
                     // check new filename
                     $preview_filename_new = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
                     $only_name = JFile::stripExt($preview_filename_new);
                     if ($only_name != '') {
                         if (JFile::move($jlistConfig['files.uploaddir'] . DS . $jlistConfig['preview.files.folder.name'] . DS . $preview_filename_old_name, $jlistConfig['files.uploaddir'] . DS . $jlistConfig['preview.files.folder.name'] . DS . $preview_filename_new)) {
                             // change now value in table field
                             $this->preview_filename = $preview_filename_new;
                             JError::raiseNotice(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_RENAMED'));
                         } else {
                             // error - can not rename
                             JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_ERROR'));
                         }
                     } else {
                         // filename is after clearing empty - invalid filename
                         JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_FILENAME_ERROR'));
                     }
                 }
             }
         }
         //handle now the preview file upload for this download
         if ($files['tmp_name']['preview_file_upload'] != '') {
             $upload_dir = $jlistConfig['files.uploaddir'] . '/' . $jlistConfig['preview.files.folder.name'] . '/';
             // delete first old assigned file if exist - so we can use for a update a file with the same filename!
             if ($this->preview_filename) {
                 if (JFile::exists($upload_dir . $this->preview_filename)) {
                     JFile::delete($upload_dir . $this->preview_filename);
                 }
             }
             $only_name = JFile::stripExt($files['name']['preview_file_upload']);
             $file_extension = JFile::getExt($files['name']['preview_file_upload']);
             // check filename
             $filename_new = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
             $only_name = JFile::stripExt($filename_new);
             $file_extension = JFile::getExt($filename_new);
             if ($only_name != '') {
                 // filename is valid
                 $files['name']['preview_file_upload'] = $filename_new;
                 $target_path = $upload_dir . $files['name']['preview_file_upload'];
                 // When file mime is an image type, make sure that we have not a fake pic
                 $file_is_image = JDownloadsHelper::fileIsImage($files['type']['preview_file_upload']);
                 if ($file_is_image && !JDownloadsHelper::imageFileIsValid($files['tmp_name']['preview_file_upload'])) {
                     $files['tmp_name']['preview_file_upload'] = '';
                     // error - user have tried to upload a not valid image file
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_IMAGE_FILE'));
                     return false;
                 }
                 if (JFile::upload($files['tmp_name']['preview_file_upload'], $target_path)) {
                     $this->preview_filename = basename($target_path);
                 } else {
                     // error - can not write on server folder - wrong permissions set?
                     $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_CHECK_PERMISSIONS'));
                     return false;
                 }
             } else {
                 // filename is after clearing empty - invalid filename
                 $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_FILENAME'));
             }
         }
         /**
          * @desc  Remove all not marked images from image folders and DB  
          */
         if ($this->images != '') {
             $post = JRequest::get('post');
             if (isset($post['keep_image'])) {
                 $keep_image_ids = $post['keep_image'];
             } else {
                 $keep_image_ids = array();
             }
             // build an array so we can compare it
             $org_image_ids = explode('|', $this->images);
             $results = array_diff($org_image_ids, $keep_image_ids);
             if ($results) {
                 $images_dir = JPATH_SITE . '/images/jdownloads/screenshots/';
                 $thumb_dir = JPATH_SITE . '/images/jdownloads/screenshots/thumbnails/';
                 foreach ($results as $result) {
                     // remove the unchecked images
                     if (JFile::exists($images_dir . $result)) {
                         JFile::delete($images_dir . $result);
                     }
                     if (JFile::exists($thumb_dir . $result)) {
                         JFile::delete($thumb_dir . $result);
                     }
                 }
                 // update the image field in the db table
                 $this->images = implode('|', $keep_image_ids);
             }
         }
         // only now can we add the above created thumbs for assigned image or pdf files
         if ($image_thumb_name) {
             if ($this->images != '') {
                 $this->images = $this->images . '|' . $image_thumb_name;
             } else {
                 $this->images = $image_thumb_name;
             }
             $this->images = rtrim($this->images, "|");
         }
         /**
          * @desc  check icon upload field
          *           if pic selected for upload:
          *           - check image typ
          *           - check whether filename exists. If so, rename the new file. 
          *           - move new file to catimages
          */
         $file = JArrayHelper::getValue($_FILES, 'picnew', array('tmp_name' => ''));
         if ($file['tmp_name'] != '' && JDownloadsHelper::fileIsPicture($file['name'])) {
             $upload_dir = JPATH_SITE . '/images/jdownloads/fileimages/';
             $file['name'] = JFile::makeSafe($file['name']);
             if (!JFile::upload($file['tmp_name'], $upload_dir . $file['name'])) {
                 $this->setError(JText::_('COM_JDOWNLOADS_ERROR_CAN_NOT_MOVE_UPLOADED_IMAGE'));
                 return false;
             } else {
                 // move ok - set new file name as selected
                 $this->file_pic = $file['name'];
             }
         } else {
             // check now whether it is selected manually a other icon from server
             $selected_file_icon = $jinput->get('file_pic', '', 'string');
             if ($selected_file_icon != '' && $selected_file_icon != $this->file_pic) {
                 $this->file_pic = $selected_file_icon;
             }
         }
         /**
          * @desc  check thumbnail upload field
          *           if image selected for upload:
          *           - check image typ
          *           - check whether filename exists. If so, rename the new file. 
          *           - move new files to /screenshots and /screenshots/thumbnail folder 
          */
         $filename = '';
         $tempname = '';
         $images = array();
         $upload_dir = JPATH_SITE . '/images/jdownloads/screenshots/';
         $sum = count($imagefiles['name']);
         if ($sum > 0) {
             // new images are uploaded
             for ($i = 0; $i < $sum; $i++) {
                 $filename = $imagefiles['name'][$i];
                 $tempname = $imagefiles['tmp_name'][$i];
                 $temptype = $imagefiles['type'][$i];
                 if ($filename != '' && JDownloadsHelper::fileIsImage($temptype)) {
                     // replace special chars in filename
                     $only_name = JFile::stripExt($filename);
                     $file_extension = JFile::getExt($filename);
                     $filename = JDownloadsHelper::getCleanFolderFileName($only_name) . '.' . $file_extension;
                     $only_name = JFile::stripExt($filename);
                     $num = 0;
                     while (JFile::exists($upload_dir . $filename)) {
                         $filename = $only_name . $num++ . '.' . $file_extension;
                         if ($num > 5000) {
                             break;
                         }
                     }
                     // make sure that we have not a fake image file
                     if (!JDownloadsHelper::imageFileIsValid($tempname)) {
                         $imagefiles['tmp_name'][$i] = '';
                         // error - user have tried to upload a not valid image file
                         // but we do not break the upload process
                         // $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_INVALID_IMAGE_FILE'));
                         // return false;
                     } else {
                         if (!JFile::upload($tempname, $upload_dir . $filename)) {
                             //$this->setError(JText::_('COM_JDOWNLOADS_ERROR_CAN_NOT_MOVE_UPLOADED_IMAGE'));
                             //return false;
                         } else {
                             // move okay - create now thumbnail
                             $x = JDownloadsHelper::create_new_thumb($upload_dir . $filename);
                             // set correct chmod
                             @chmod($upload_dir . $filename, 0655);
                             // move ok - set new file name as selected
                             $images[] = $filename;
                         }
                     }
                 } else {
                     // not a file with image mime selected
                     if ($filename != '' && !JDownloadsHelper::fileIsImage($imagefiles['type'][$i])) {
                         // add a error message? Or do better nothing then we have always files stored above!
                         // $this->setError(JText::_('COM_JDOWNLOADS_BACKEND_CATSEDIT_ERROR_FILE_TITLE'));
                     }
                 }
             }
             // add all uploaded or selected image files to the new images field
             if ($this->images != '') {
                 $this->images = $this->images . '|' . implode('|', $images);
             } else {
                 $this->images = implode('|', $images);
             }
             $this->images = rtrim($this->images, "|");
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Display the view
  * 
  * 
  */
 public function display($tpl = null)
 {
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     // What Access Permissions does this user have? What can (s)he do?
     $this->canDo = jdownloadsHelper::getActions();
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->addToolbar();
     parent::display($tpl);
 }
Ejemplo n.º 3
0
 /**
  * Add the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', 1);
     $user = JFactory::getUser();
     $isNew = $this->item->id == 0;
     $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
     $canDo = jdownloadsHelper::getActions();
     $document = JFactory::getDocument();
     $document->addStyleSheet('components/com_jdownloads/assets/css/style.css');
     JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_USERGROUP_EDIT_TITLE'), 'jdgroups');
     if ($canDo->get('edit.user.limits')) {
         JToolBarHelper::apply('group.apply');
         JToolBarHelper::save('group.save');
     }
     JToolBarHelper::cancel('group.cancel', 'JTOOLBAR_CLOSE');
     JToolBarHelper::divider();
     JToolBarHelper::help('help.group', true);
 }
Ejemplo n.º 4
0
 /**
  * uploads display method
  * @return void
  **/
 function display($tpl = null)
 {
     global $jlistConfig;
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     // What Access Permissions does this user have? What can (s)he do?
     $this->canDo = jdownloadsHelper::getActions();
     $language = JFactory::getLanguage();
     $lang = $language->getTag();
     $langfiles = JPATH_COMPONENT_ADMINISTRATOR . '/assets/plupload/js/i18n/';
     $PLdataDir = JURI::root() . "administrator/components/com_jdownloads/assets/plupload/";
     $document = JFactory::getDocument();
     $PLuploadScript = new PLuploadScript($PLdataDir);
     $runtimeScript = $PLuploadScript->runtimeScript;
     $runtime = $PLuploadScript->runtime;
     //add default PL css
     $document->addStyleSheet($PLdataDir . 'css/plupload.css');
     //add PL styles and scripts
     $document->addStyleSheet($PLdataDir . 'js/jquery.plupload.queue/css/jquery.plupload.queue.css', 'text/css', 'screen');
     $document->addScript($PLdataDir . 'js/jquery.min.js');
     $document->addScript($PLdataDir . 'js/plupload.full.min.js');
     // load plupload language file
     if ($lang) {
         if (JFile::exists($langfiles . $lang . '.js')) {
             $document->addScript($PLdataDir . 'js/i18n/' . $lang . '.js');
         } else {
             $document->addScript($PLdataDir . 'js/i18n/en-GB.js');
         }
     }
     $document->addScript($PLdataDir . 'js/jquery.plupload.queue/jquery.plupload.queue.js');
     $document->addScriptDeclaration($PLuploadScript->getScript());
     //set variables for the template
     $this->enableLog = $jlistConfig['plupload.enable.uploader.log'];
     $this->runtime = $runtime;
     $this->currentDir = $jlistConfig['files.uploaddir'] . '/';
     //set toolbar
     $this->addToolBar();
     $this->sidebar = JHtmlSidebar::render();
     // Display the template
     parent::display($tpl);
 }
Ejemplo n.º 5
0
 /**
  * Display the view
  * 
  * 
  */
 public function display($tpl = null)
 {
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     // What Access Permissions does this user have? What can (s)he do?
     $this->canDo = jdownloadsHelper::getActions();
     // get filename when selected in files list
     $session = JFactory::getSession();
     $filename = $session->get('jd_filename');
     if ($filename) {
         $this->selected_filename = JFilterOutput::cleanText($filename);
     }
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->addToolbar();
     parent::display($tpl);
 }
Ejemplo n.º 6
0
 /**
  * categories view display method
  * @return void
  **/
 function display($tpl = null)
 {
     $this->state = $this->get('State');
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     // What Access Permissions does this user have? What can (s)he do?
     $this->canDo = jdownloadsHelper::getActions();
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     // Preprocess the list of items to find ordering divisions.
     foreach ($this->items as &$item) {
         $this->ordering[$item->parent_id][] = $item->id;
     }
     //$params     = JComponentHelper::getParams('com_jdownloads');
     // Levels filter.
     $options = array();
     $options[] = JHtml::_('select.option', '1', JText::_('J1'));
     $options[] = JHtml::_('select.option', '2', JText::_('J2'));
     $options[] = JHtml::_('select.option', '3', JText::_('J3'));
     $options[] = JHtml::_('select.option', '4', JText::_('J4'));
     $options[] = JHtml::_('select.option', '5', JText::_('J5'));
     $this->assign('levels', $options);
     // build categories list box for batch operations
     $lists = array();
     $config = array('filter.published' => array(0, 1));
     $select[] = JHtml::_('select.option', 0, JText::_('COM_JDOWNLOADS_SELECT_CATEGORY'));
     $select[] = JHtml::_('select.option', 1, JText::_('COM_JDOWNLOADS_BATCH_ROOT_CAT'));
     // get the categories data
     $categories = $this->getCategoriesList($config);
     $this->categories = @array_merge($select, $categories);
     $this->addToolbar();
     $this->sidebar = JHtmlSidebar::render();
     parent::display($tpl);
 }
Ejemplo n.º 7
0
 /**
  * Add the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php';
     $document = JFactory::getDocument();
     $document->addStyleSheet('components/com_jdownloads/assets/css/style.css');
     JDownloadsHelper::addSubmenu('groups');
     JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_USER_GROUPS'), 'jdgroups');
     $canDo = jdownloadsHelper::getActions();
     if ($canDo->get('edit.config')) {
         JToolBarHelper::editList('group.edit', 'COM_JDOWNLOADS_USERGROUPS_CHANGE_LIMITS_TITLE');
         JToolBarHelper::divider();
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::custom('groups.resetLimits', 'reset', 'reset', JText::_('COM_JDOWNLOADS_USERGROUPS_RESET_LIMITS_TITLE'), true, false);
         JToolBarHelper::divider();
     }
     if ($canDo->get('core.admin')) {
         JToolBarHelper::preferences('com_jdownloads');
         JToolBarHelper::divider();
     }
     if ($canDo->get('edit.config')) {
         JToolBarHelper::help('help.groups', true);
     }
 }
Ejemplo n.º 8
0
// JHtml::_('behavior.formvalidator'); Joomla >= 3.4
JHtml::_('jquery.framework');
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery("SELECT `rules` FROM #__assets WHERE `name` = 'com_jdownloads' AND `title` = 'com_jdownloads' AND `level` = '1'");
$component_rules = $db->loadResult();
// get download stats
$stats_data = jdownloadsHelper::getDownloadStatsData();
$sum_downloads = jdownloadsHelper::getSumDownloads();
$user_rules = jdownloadsHelper::getUserRules();
$canDo = jdownloadsHelper::getActions();
$option = 'com_jdownloads';
// check that we have valid user rules
// when not, create it from joomla users
if (!$user_rules) {
    $user_result = jdownloadsHelper::setUserRules();
}
// view not the control panel when we must move the data from old release (< 2.5)
if (!$jlistConfig['old.jd.release.found']) {
    ?>
    
    <form action="index.php" method="post" name="adminForm">
        
    <div id="j-main-container" class="span10">
        <div class="adminform">
            <div class="jd-cpanel-left">
                <div id="cpanel">        
                    <?php 
    // are global permissions defined?
    if ($component_rules == '{}') {
        echo '<div class="jdlists-header-info" style="margin-bottom:10px; padding-bottom: 10px; width: 96%; font-size: 12px; text-align: yustify;">' . '<img src="' . JURI::base() . 'components/com_jdownloads/assets/images/warning.png' . '" border="0" alt="warning" style="float:left;" />' . JText::_('COM_JDOWNLOADS_PERMISSIONS_NOT_FOUND_INFO') . ' ' . JText::_('COM_JDOWNLOADS_SET_PERMISSIONS_INFO_HINT') . '<br /><small>' . JText::_('COM_JDOWNLOADS_ACCESS_ONLY_FOR_SUPER_USERS') . '</small></div>';
Ejemplo n.º 9
0
 /**
  * Method to handle the category folder actions (create/move/rename)
  *
  * @param   string   $isNew                 true when used
  * @param   string   $catChanged            true when used
  * @param   string   $titleChanged          true when used 
  * @param   string   $checked_cat_title     the new/changed and checked category folder name  
  *
  * @return  boolean  $result True on success
  */
 public function checkCategoryFolder($isNew, $catChanged, $titleChanged, $checked_cat_title, $cat_dir_changed_manually)
 {
     global $jlistConfig;
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     $jinput = JFactory::getApplication()->input;
     $root_dir_path = $jlistConfig['files.uploaddir'];
     if (!$isNew && !$catChanged && !$titleChanged && !$cat_dir_changed_manually) {
         // nothing to do
         return true;
     }
     if ($isNew) {
         // get parent dir when selected
         if ($this->parent_id > 1) {
             $this->cat_dir_parent = $this->getParentCategoryPath($this->parent_id);
         }
         if ($this->cat_dir_parent != '') {
             $cat_dir_path = $root_dir_path . DS . $this->cat_dir_parent . DS . $this->cat_dir;
         } else {
             $cat_dir_path = $root_dir_path . DS . $this->cat_dir;
         }
         // create the new folder when he not exists
         if (!JFolder::exists($cat_dir_path)) {
             $result = JFolder::create($cat_dir_path);
             // copy also a empty index.html
             JFile::copy(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jdownloads' . DS . 'index.html', $cat_dir_path . DS . 'index.html');
         } else {
             // new category but the given cat_dir exists always...
             // TODO: problem, we have stored the new category in DB but can not create the new folder - so we have now two categories with the same folder path?
             $result = false;
         }
     } else {
         // build the new folder path to move or rename the folder when needed
         if ($this->parent_id > 1) {
             $this->cat_dir_parent = $this->getParentCategoryPath($this->parent_id);
         } else {
             $this->cat_dir_parent = '';
         }
         if ($this->cat_dir_parent != '') {
             $new_cat_dir_path = $root_dir_path . DS . $this->cat_dir_parent . DS . $this->cat_dir;
         } else {
             $new_cat_dir_path = $root_dir_path . DS . $this->cat_dir;
         }
         // we need also the old folder path
         $old_parent = $jinput->get('cat_dir_parent_org', '', 'string');
         $old_dir = $jinput->get('cat_dir_org', '', 'string');
         if ($old_parent != '') {
             $old_cat_dir_path = $root_dir_path . DS . $old_parent . DS . $old_dir;
         } else {
             $old_cat_dir_path = $root_dir_path . DS . $old_dir;
         }
         // category is not new - so we must at first check, whether the title is changed.
         if ($titleChanged || $cat_dir_changed_manually) {
             // get the old and new cat dir and rename it
             if (JFolder::exists($old_cat_dir_path)) {
                 $result = JFolder::move($old_cat_dir_path, $new_cat_dir_path);
             } else {
                 JError::raiseWarning(100, JText::sprintf('COM_JDOWNLOADS_CATSEDIT_ERROR_CHECK_FOLDER', $old_cat_dir_path));
                 $result = false;
             }
         }
         // we must only check this, when the user have not changed the category title
         // if so, we must move the category folder complete to the new position
         if ($catChanged && !$titleChanged) {
             // move it to the new location when exists
             if (JFolder::exists($old_cat_dir_path)) {
                 $result = jdownloadsHelper::moveDirs($old_cat_dir_path . DS, $new_cat_dir_path . '/', true, $msg, true, false, false);
                 if ($result !== true) {
                     // $result has a error message from file/folder operations
                     JError::raiseWarning(100, $result);
                     $result = false;
                 }
             } else {
                 $result = false;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 10
0
<!--  modified cam 2014-05-20  circa line 152 with <ul> addition
    changed fltlft to jdfltlft and fltrt to jdfltrt-->
<?php 
defined('_JEXEC') or die;
global $jlistConfig;
// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHTML::_('behavior.formvalidation');
// JHtml::_('behavior.formvalidator'); Joomla >= 3.4
$canDo = jdownloadsHelper::getActions();
jimport('joomla.form.form');
$star = '<span class="star">*</span>';
?>

    <script type="text/javascript">
	    Joomla.submitbutton = function(task)
	    {
		    if (task == 'group.cancel' || document.formvalidator.isValid(document.id('group-form'))) {
			    Joomla.submitform(task, document.getElementById('group-form'));
		    }
	    }
    </script>

<?php 
if ($canDo->get('edit.user.limits')) {
    ?>

<form action="<?php 
    echo JRoute::_('index.php?option=com_jdownloads&layout=edit&id=' . (int) $this->item->id);
    ?>
" method="post" name="adminForm" id="group-form" class="form-validate">
Ejemplo n.º 11
0
function checkFiles($task)
{
    global $jlistConfig, $lang;
    $limits = remove_server_limits();
    if (!$limits) {
        echo '<p>';
        echo '*******************************************************';
        echo '<br />Note: The time limit on the server could not be changed/increased!<br />';
        echo '*******************************************************';
        echo '</p>';
    }
    ignore_user_abort(true);
    // ob_flush();
    flush();
    $model_category = JModelLegacy::getInstance('Category', 'jdownloadsModel');
    $model_download = JModelLegacy::getInstance('Download', 'jdownloadsModel');
    jimport('joomla.filesystem.folder');
    jimport('joomla.filesystem.file');
    $db = JFactory::getDBO();
    $lang = JFactory::getLanguage();
    $lang->load('com_jdownloads', JPATH_SITE . DS);
    //check if all files and dirs in the uploaddir directory are listed
    if ($jlistConfig['files.autodetect'] || $task == 'restore.run' || $task == 'scan.files') {
        if (file_exists($jlistConfig['files.uploaddir']) && $jlistConfig['files.uploaddir'] != '') {
            $startdir = $jlistConfig['files.uploaddir'] . '/';
            $dir_len = strlen($startdir);
            // define the params for scan_dir() results
            $dir = $startdir;
            $only = FALSE;
            $type = array();
            if ($jlistConfig['all.files.autodetect']) {
                $allFiles = true;
            } else {
                $allFiles = FALSE;
                $type = explode(',', $jlistConfig['file.types.autodetect']);
            }
            $recursive = TRUE;
            $onlyDir = TRUE;
            $files = array();
            $file = array();
            $dirlist = array();
            $new_files = 0;
            $new_dirs_found = 0;
            $new_dirs_create = 0;
            $new_dirs_errors = 0;
            $new_dirs_exists = 0;
            $new_cats_create = 0;
            $log_message = '';
            $success = FALSE;
            $log_array = array();
            // ********************************************
            // first search new categories
            // ********************************************
            clearstatcache();
            $jd_root = $jlistConfig['files.uploaddir'] . '/';
            $temp_dir = $jd_root . $jlistConfig['tempzipfiles.folder.name'] . '/';
            $uncat_dir = $jd_root . $jlistConfig['uncategorised.files.folder.name'] . '/';
            $preview_dir = $jd_root . $jlistConfig['preview.files.folder.name'] . '/';
            $private_dir = $jd_root . $jlistConfig['private.area.folder.name'] . '/';
            $except_folders = array($temp_dir, $uncat_dir, $preview_dir, $private_dir);
            $searchdirs = array();
            $dirlist = JDownloadsHelper::searchdir($jd_root, -1, 'DIRS', 0, $except_folders);
            $no_writable = 0;
            for ($i = 0; $i < count($dirlist); $i++) {
                // no tempzifiles directory
                if (strpos($dirlist[$i], $jlistConfig['private.area.folder.name'] . '/') === FALSE) {
                    if (!is_writable($dirlist[$i])) {
                        $no_writable++;
                    }
                    $dirlist[$i] = str_replace($jd_root, '', $dirlist[$i]);
                    // delete last slash /
                    if ($pos = strrpos($dirlist[$i], '/')) {
                        $searchdirs[] = substr($dirlist[$i], 0, $pos);
                    }
                }
            }
            unset($dirlist);
            $count_cats = count($searchdirs);
            // first progressbar for cats
            $title1 = JText::_('COM_JDOWNLOADS_RUN_MONITORING_INFO3');
            $bar = new ProgressBar();
            $bar->setMessage($title1);
            $bar->setAutohide(false);
            $bar->setSleepOnFinish(0);
            $bar->setPrecision(100);
            $bar->setForegroundColor('#990000');
            $bar->setBackgroundColor('#CCCCCC');
            $bar->setBarLength(300);
            $bar->initialize($count_cats - 1);
            // print the empty bar
            for ($i = 0; $i < count($searchdirs); $i++) {
                $dirs = explode('/', $searchdirs[$i]);
                $sum = count($dirs);
                // check that folder exist
                if ($sum == 1) {
                    $db->setQuery("SELECT COUNT(*) FROM #__jdownloads_categories WHERE cat_dir = '{$searchdirs[$i]}'");
                    $cat_dir_parent_value = '';
                    $cat_dir_value = $dirs[0];
                } else {
                    $pos = strrpos($searchdirs[$i], '/');
                    $cat_dir_parent_value = substr($searchdirs[$i], 0, $pos);
                    $cat_dir_value = substr($searchdirs[$i], $pos + 1);
                    $db->setQuery("SELECT COUNT(*) FROM #__jdownloads_categories WHERE cat_dir = '{$cat_dir_value}' AND cat_dir_parent = '{$cat_dir_parent_value}'");
                }
                $cat_exist = $db->loadResult();
                // when not exist - add it
                if (!$cat_exist) {
                    $new_dirs_found++;
                    $parent_cat = '';
                    // get the right parent_id value
                    if ($sum == 1) {
                        // we have a new root cat
                        $parent_id = 1;
                    } else {
                        // find the parent category and get the cat ID
                        $pos = strrpos($cat_dir_parent_value, '/');
                        if ($pos) {
                            // we have NOT a first level sub category
                            $cat_dir_parent_value2 = substr($cat_dir_parent_value, 0, $pos);
                            $cat_dir_value2 = substr($cat_dir_parent_value, $pos + 1);
                            $db->setQuery("SELECT * FROM #__jdownloads_categories WHERE cat_dir = '{$cat_dir_value2}' AND cat_dir_parent = '{$cat_dir_parent_value2}'");
                        } else {
                            // we have a first level sub category
                            $cat_dir_parent_value2 = $cat_dir_parent_value;
                            $cat_dir_value2 = $cat_dir_value;
                            $db->setQuery("SELECT * FROM #__jdownloads_categories WHERE cat_dir = '{$cat_dir_parent_value2}' AND cat_dir_parent = ''");
                        }
                        $parent_cat = $db->loadObject();
                        if ($parent_cat) {
                            $parent_id = $parent_cat->id;
                        } else {
                            // can not found the parents category for the new child
                            $log_array[] = JText::_('Abort. Can not find parents category for the new folder: ') . ' <b>' . $searchdirs[$i] . '</b><br />';
                            break;
                        }
                    }
                    $cat_dir_value = utf8_encode($cat_dir_value);
                    // we need the original folder title as category title
                    $original_folder_name = $cat_dir_value;
                    // check the founded folder name
                    $checked_cat_dir = JDownloadsHelper::getCleanFolderFileName($cat_dir_value, true);
                    // check the folder name result
                    if ($cat_dir_value != $checked_cat_dir) {
                        // build path
                        if ($parent_cat) {
                            if ($parent_cat->cat_dir_parent) {
                                $cat_dir_path = $jd_root . $parent_cat->cat_dir_parent . '/' . $parent_cat->cat_dir . '/' . $checked_cat_dir;
                                $new_cat_dir_name = $parent_cat->cat_dir_parent . '/' . $parent_cat->cat_dir . '/' . $checked_cat_dir;
                            } else {
                                $cat_dir_path = $jd_root . $parent_cat->cat_dir . '/' . $checked_cat_dir;
                                $new_cat_dir_name = $parent_cat->cat_dir . '/' . $checked_cat_dir;
                            }
                        } else {
                            $cat_dir_path = $jd_root . $checked_cat_dir;
                            $new_cat_dir_name = $checked_cat_dir;
                        }
                        // rename the folder - when he already exist: make it unique!
                        $num = 1;
                        while (JFolder::exists($cat_dir_path)) {
                            $cat_dir_path = $cat_dir_path . $num;
                            $checked_cat_dir = $checked_cat_dir . $num;
                            $num++;
                        }
                        if (!JFolder::exists($cat_dir_path)) {
                            $copied = JFolder::move($jd_root . $searchdirs[$i], $cat_dir_path);
                            if ($copied !== true) {
                                $log_array[] = JText::_('Error! Can not change folder name: ') . ' <b>' . $searchdirs[$i] . '</b><br />';
                            }
                        } else {
                            $log_array[] = JText::_('Error! A folder with the same (cleaned) name exist already: ') . ' <b>' . $searchdirs[$i] . '</b><br />';
                        }
                        $cat_dir_value = $checked_cat_dir;
                        // update the name in the folder list
                        $searchdirs[$i] = $new_cat_dir_name;
                    }
                    // set access
                    if ($parent_cat) {
                        $access = $parent_cat->access;
                    } else {
                        $access = 1;
                    }
                    // set alias
                    $alias = JApplication::stringURLSafe($cat_dir_value);
                    // set note hint
                    $note = JText::_('COM_JDOWNLOADS_RUN_MONITORING_NOTE_TEXT');
                    // build table array
                    $data = array('id' => 0, 'parent_id' => $parent_id, 'title' => $original_folder_name, 'alias' => $alias, 'notes' => $note, 'description' => '', 'cat_dir' => $cat_dir_value, 'cat_dir_parent' => $cat_dir_parent_value, 'pic' => $jlistConfig['cat.pic.default.filename'], 'published' => (int) $jlistConfig['autopublish.founded.files'], 'access' => $access, 'metadesc' => '', 'metakey' => '', 'created_user_id' => '0', 'language' => '*', 'rules' => array('core.create' => array(), 'core.delete' => array(), 'core.edit' => array(), 'core.edit.state' => array(), 'core.edit.own' => array(), 'download' => array()), 'params' => array());
                    // create new cat in table
                    $create_result = $model_category->createAutoCategory($data);
                    if (!$create_result) {
                        // error message
                        $log_array[] = JText::_('Error! Can not create new category for: ') . ' <b>' . $searchdirs[$i] . '</b><br />';
                    }
                    $new_cats_create++;
                    // copy index.html to the new folder
                    $index_copied = JFile::copy(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_jdownloads' . DS . 'index.html', $jlistConfig['files.uploaddir'] . DS . $searchdirs[$i] . DS . 'index.html');
                    $log_array[] = JText::_('COM_JDOWNLOADS_AUTO_CAT_CHECK_ADDED') . ' <b>' . $searchdirs[$i] . '</b><br />';
                }
                $bar->increase();
                // calls the bar with every processed element
            }
            echo '<small><br />' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_SUM_FOLDERS') . ' ' . count($searchdirs) . '<br /><br /></small>';
            ob_flush();
            flush();
            unset($dirs);
            unset($searchdirs);
            // ********************************************
            // Exists all published category folders?
            // ********************************************
            $mis_cats = 0;
            // get all published categories but not the root
            $db->setQuery("SELECT * FROM #__jdownloads_categories WHERE published = 1 AND id > 1");
            $cats = $db->loadObjectList();
            $count_cats = count($cats);
            // first progressbar for cats
            $bar = new ProgressBar();
            $title2 = JText::_('COM_JDOWNLOADS_RUN_MONITORING_INFO4');
            $bar->setMessage($title2);
            $bar->setAutohide(false);
            $bar->setSleepOnFinish(0);
            $bar->setPrecision(100);
            $bar->setForegroundColor('#990000');
            $bar->setBarLength(300);
            $bar->initialize($count_cats);
            // print the empty bar
            foreach ($cats as $cat) {
                if ($cat->cat_dir_parent != '') {
                    $cat_dir = $jd_root . $cat->cat_dir_parent . '/' . $cat->cat_dir;
                } else {
                    $cat_dir = $jd_root . $cat->cat_dir;
                }
                // when it not exist, we must unpublish the category
                if (!JFolder::exists($cat_dir)) {
                    $db->setQuery("UPDATE #__jdownloads_categories SET published = 0 WHERE id = '{$cat->id}'");
                    $db->execute();
                    $mis_cats++;
                    $log_array[] = '<font color="red">' . JText::_('COM_JDOWNLOADS_AUTO_CAT_CHECK_DISABLED') . ' <b>' . $cat->cat_dir . '</b></font><br />';
                }
                $bar->increase();
                // calls the bar with every processed element
            }
            echo '<br /><br />';
            unset($cats);
            // *********************************************************
            //  Check all files and create for new founded new Downloads
            // *********************************************************
            unset($except_folders[1]);
            $all_dirs = JDownloadsHelper::scan_dir($dir, $type, $only, $allFiles, $recursive, $onlyDir, $except_folders, $jd_root, $files);
            if ($all_dirs != FALSE) {
                $count_files = count($files);
                // first progressbar for cats
                $bar = new ProgressBar();
                $title3 = JText::_('COM_JDOWNLOADS_RUN_MONITORING_INFO5');
                $bar->setMessage($title3);
                $bar->setAutohide(false);
                $bar->setSleepOnFinish(0);
                $bar->setPrecision(100);
                $bar->setForegroundColor('#990000');
                $bar->setBarLength(300);
                $bar->initialize($count_files);
                // print the empty bar
                reset($files);
                $new_files = 0;
                foreach ($files as $key3 => $array2) {
                    $filename = $files[$key3]['file'];
                    if ($filename != '') {
                        $dir_path_total = $files[$key3]['path'];
                        $restpath = substr($files[$key3]['path'], $dir_len);
                        $only_dirs = substr($restpath, 0, strlen($restpath) - 1);
                        $upload_dir = $jlistConfig['files.uploaddir'] . '/' . $only_dirs . '/';
                        $pos = strrpos($only_dirs, '/');
                        if ($pos) {
                            $cat_dir_parent_value = substr($only_dirs, 0, $pos);
                            $cat_dir_value = substr($only_dirs, $pos + 1);
                        } else {
                            $cat_dir_parent_value = '';
                            $cat_dir_value = $only_dirs;
                        }
                        // exist still a Download with this filename?
                        $exist_file = false;
                        $db->setQuery("SELECT cat_id FROM #__jdownloads_files WHERE url_download = '" . $filename . "'");
                        $row_file_exists = $db->loadObjectList();
                        // when exist, get the category from the Download, when we have really assigned a category (ID > 1)
                        if ($row_file_exists && $row_file_exists[0]->cat_id > 1) {
                            foreach ($row_file_exists as $row_file_exist) {
                                if (!$exist_file) {
                                    $db->setQuery("SELECT COUNT(*) FROM #__jdownloads_categories WHERE id = '{$row_file_exist->cat_id}' AND cat_dir = '{$cat_dir_value}' AND cat_dir_parent = '{$cat_dir_parent_value}'");
                                    $row_cat_find = $db->loadResult();
                                    if ($row_cat_find) {
                                        $exist_file = true;
                                    }
                                }
                            }
                        } else {
                            // it can be an 'uncategorised'
                            if ($row_file_exists && $row_file_exists[0]->cat_id == 1) {
                                $exist_file = true;
                            } else {
                                $exist_file = false;
                            }
                        }
                        // Add the file here in a new Download
                        if (!$exist_file) {
                            // not check the filename when restore backup file
                            if ($task != 'restore.run') {
                                // reset images var
                                $images = '';
                                $only_name = utf8_encode(JFile::stripExt($filename));
                                $file_extension = JFile::getExt($filename);
                                // $title =  JFilterInput::clean($only_name);
                                $title = JFilterInput::getInstance(null, null, 1, 1)->clean($only_name, 'STRING');
                                // check filename
                                $filename_new = JDownloadsHelper::getCleanFolderFileName($only_name, true) . '.' . $file_extension;
                                if ($only_name == '') {
                                    echo "<script> alert('Error: Filename empty after cleaning: " . $dir_path_total . "'); </script>\n";
                                    continue;
                                    // go to next foreach item
                                }
                                if ($filename_new != $filename) {
                                    $source = $startdir . $only_dirs . '/' . $filename;
                                    $target = $startdir . $only_dirs . '/' . $filename_new;
                                    $success = @rename($source, $target);
                                    if ($success === true) {
                                        $filename = $filename_new;
                                    } else {
                                        // could not rename filename
                                        echo "<script> alert('Error: Could not rename {$filename}'); </script>\n";
                                        continue;
                                        // go to next foreach item
                                    }
                                }
                            }
                            $target_path = $upload_dir . $filename;
                            // find the category for the new founded file in this folder
                            $db->setQuery("SELECT * FROM #__jdownloads_categories WHERE cat_dir = '{$cat_dir_value}' AND cat_dir_parent = '{$cat_dir_parent_value}'");
                            $cat = $db->loadObject();
                            if ($cat) {
                                $id = $cat->id;
                                $access = $cat->access;
                            } else {
                                // it seems that we have a new file in 'uncategorised' folder found
                                $id = 1;
                                $access = 1;
                            }
                            $date = JFactory::getDate();
                            $tz = JFactory::getConfig()->get('offset');
                            $date->setTimezone(new DateTimeZone($tz));
                            $file_extension = JFile::getExt($filename);
                            // set file size
                            $file_size = $files[$key3]['size'];
                            // set note hint
                            $note = JText::_('COM_JDOWNLOADS_RUN_MONITORING_NOTE_TEXT');
                            // set creation date
                            $creation_date = JFactory::getDate()->toSql();
                            // set file mime pic
                            $picpath = strtolower(JPATH_SITE . '/images/jdownloads/fileimages/' . $file_extension . '.png');
                            if (file_exists($picpath)) {
                                $file_pic = $file_extension . '.png';
                            } else {
                                $file_pic = $jlistConfig['file.pic.default.filename'];
                            }
                            // create thumbs form pdf
                            if ($jlistConfig['create.pdf.thumbs'] && $jlistConfig['create.pdf.thumbs.by.scan'] && $file_extension == 'pdf') {
                                $thumb_path = JPATH_SITE . '/images/jdownloads/screenshots/thumbnails/';
                                $screenshot_path = JPATH_SITE . '/images/jdownloads/screenshots/';
                                $pdf_thumb_name = jdownloadsHelper::create_new_pdf_thumb($target_path, $only_name, $thumb_path, $screenshot_path);
                                if ($pdf_thumb_name) {
                                    $images = $pdf_thumb_name;
                                }
                            }
                            // create auto thumb when founded file is an image
                            if ($jlistConfig['create.auto.thumbs.from.pics'] && $jlistConfig['create.auto.thumbs.from.pics.by.scan']) {
                                if ($file_is_image = JDownloadsHelper::fileIsPicture($filename)) {
                                    $thumb_created = jdownloadsHelper::create_new_thumb($target_path);
                                    if ($thumb_created) {
                                        $images = $filename;
                                        // create new big image for full view
                                        $image_created = jdownloadsHelper::create_new_image($target_path);
                                    }
                                }
                            }
                            $sha1_value = sha1_file($target_path);
                            $md5_value = md5_file($target_path);
                            // build data array
                            $data = array('file_id' => 0, 'cat_id' => $id, 'file_title' => $title, 'file_alias' => '', 'notes' => $note, 'url_download' => $filename, 'size' => $file_size, 'description' => JDownloadsHelper::getOnlyLanguageSubstring($jlistConfig['autopublish.default.description']), 'file_pic' => $file_pic, 'images' => $images, 'date_added' => $creation_date, 'sha1_value' => $sha1_value, 'md5_value' => $md5_value, 'published' => (int) $jlistConfig['autopublish.founded.files'], 'access' => $access, 'metadesc' => '', 'metakey' => '', 'created_user_id' => '0', 'language' => '*', 'rules' => array('core.create' => array(), 'core.delete' => array(), 'core.edit' => array(), 'core.edit.state' => array(), 'core.edit.own' => array(), 'download' => array()), 'params' => array());
                            // create new download in table
                            $create_result = $model_download->createAutoDownload($data);
                            if (!$create_result) {
                                // error message
                                echo "<script> alert('Error: Could not add download for: {$filename}'); window.history.go(-1); </script>\n";
                                exit;
                            }
                            $new_files++;
                            $log_array[] = JText::_('COM_JDOWNLOADS_AUTO_FILE_CHECK_ADDED') . ' <b>' . $only_dirs . '/' . $filename . '</b><br />';
                        }
                    }
                    $bar->increase();
                    // calls the bar with every processed element
                }
            }
            echo '<small><br />' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_SUM_FILES') . ' ' . count($files) . '<br /><br /></small>';
            unset($files);
            flush();
            // ****************************************************
            // Check whether the assigned files from all published downloads exists
            // - otherwise unpublish this downloads
            // ****************************************************
            $mis_files = 0;
            $db->setQuery("SELECT * FROM #__jdownloads_files WHERE published = 1");
            $files = $db->loadObjectList();
            $count_files = count($files);
            // first progressbar for cats
            $bar = new ProgressBar();
            $title4 = JText::_('COM_JDOWNLOADS_RUN_MONITORING_INFO6');
            $bar->setMessage($title4);
            $bar->setAutohide(false);
            $bar->setSleepOnFinish(0);
            $bar->setPrecision(100);
            $bar->setForegroundColor('#990000');
            $bar->setBarLength(300);
            $bar->initialize($count_files);
            // print the empty bar
            foreach ($files as $file) {
                // we checked only intern stored files
                if ($file->url_download != '') {
                    // get the category path only, when we have not an 'uncategorised' Download
                    if ($file->cat_id > 1) {
                        $db->setQuery("SELECT cat_dir, cat_dir_parent FROM #__jdownloads_categories WHERE id = '{$file->cat_id}'");
                        $cat = $db->loadObject();
                        if ($cat->cat_dir_parent != '') {
                            $cat_dir_path = $cat->cat_dir_parent . '/' . $cat->cat_dir;
                        } else {
                            $cat_dir_path = $cat->cat_dir;
                        }
                        $file_path = $jd_root . $cat_dir_path . '/' . $file->url_download;
                        $cat_dir = $cat->cat_dir . '/' . $file->url_download;
                    } else {
                        // file in 'uncategorised' folder
                        $file_path = $uncat_dir . $file->url_download;
                        $cat_dir = $file_path;
                    }
                    if (!file_exists($file_path)) {
                        $db->setQuery("UPDATE #__jdownloads_files SET published = 0 WHERE file_id = '{$file->file_id}'");
                        $db->execute();
                        $mis_files++;
                        $log_array[] = '<font color="red">' . JText::_('COM_JDOWNLOADS_AUTO_FILE_CHECK_DISABLED') . ' <b>' . $cat_dir . '</b></font><br />';
                    }
                }
                $bar->increase();
                // calls the bar with every processed element
            }
            echo '<br /><br />';
            echo '<div style="font-family:Verdana; font-size:10"><b>' . JText::_('COM_JDOWNLOADS_RUN_MONITORING_INFO7') . '</b><br /><br /></div>';
            flush();
            // build log message
            if (count($log_array) > 0) {
                array_unshift($log_array, date(JText::_('DATE_FORMAT_LC2')) . ':<br />');
            }
            foreach ($log_array as $log) {
                $log_message .= $log;
            }
            // when we have changed anything, we store it in the config
            if ($log_message != '') {
                $db->setQuery("UPDATE #__jdownloads_config SET setting_value = '{$log_message}' WHERE setting_name = 'last.log.message'");
                $db->execute();
            }
            if ($task == 'scan.files') {
                echo '<table width="100%"><tr><td><font size="1" face="Verdana">' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_TITLE') . '</font><br />';
                if ($new_cats_create > 0) {
                    echo '<font color="#FF6600" size="1" face="Verdana"><b>' . $new_cats_create . ' ' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NEW_CATS') . '</b></font><br />';
                } else {
                    echo '<font color="green" size="1" face="Verdana"><b>' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NO_NEW_CATS') . '</b></font><br />';
                }
                if ($new_files > 0) {
                    echo '<font color="#FF6600" size="1" face="Verdana"><b>' . $new_files . ' ' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NEW_FILES') . '</b></font><br />';
                } else {
                    echo '<font color="green" size="1" face="Verdana"><b>' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NO_NEW_FILES') . '</b></font><br />';
                }
                if ($mis_cats > 0) {
                    echo '<font color="#990000" size="1" face="Verdana"><b>' . $mis_cats . ' ' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_MISSING_CATS') . '</b></font><br />';
                } else {
                    echo '<font color="green" size="1" face="Verdana"><b>' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NO_MISSING_CATS') . '</b></font><br />';
                }
                if ($mis_files > 0) {
                    echo '<font color="#990000"  size="1" face="Verdana"><b>' . $mis_files . ' ' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_MISSING_FILES') . '</b><br /></td></tr></table>';
                } else {
                    echo '<font color="green" size="1" face="Verdana"><b>' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_NO_MISSING_FILES') . '</b><br /></td></tr></table>';
                }
                if ($log_message) {
                    echo '<table width="100%"><tr><td><font size="1" face="Verdana">' . JText::_('COM_JDOWNLOADS_BACKEND_AUTOCHECK_LOG_TITLE') . '<br />' . $log_message . '</font></td></tr></table>';
                }
            }
        } else {
            // error upload dir not exists
            echo '<font color="red"><b>' . JText::sprintf('COM_JDOWNLOADS_AUTOCHECK_DIR_NOT_EXIST', $jlistConfig['files.uploaddir']) . '<br /><br />' . JText::_('COM_JDOWNLOADS_AUTOCHECK_DIR_NOT_EXIST_2') . '</b></font>';
        }
    }
}