/** * 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; }
public function getLabel() { global $jlistConfig; $app = JFactory::getApplication(); JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers'); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); $label = ''; $replace = ''; // Get the label text from the XML element, defaulting to the element name. if ($app->isAdmin()) { $text = $this->element['label'] ? (string) $this->element['label'] : (string) JDownloadsHelper::getOnlyLanguageSubstring($jlistConfig['custom.field.11.title']); } else { $text = $this->element['label'] ? (string) $this->element['label'] : (string) JDHelper::getOnlyLanguageSubstring($jlistConfig['custom.field.11.title']); } // Build the class for the label. $class = !empty($this->description) ? 'hasTip' : ''; $class = $this->required == true ? $class . ' required' : $class; $req = $this->required == true ? '<span class="star"> *</span>' : ''; // Add the opening label tag and main attributes attributes. $label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"'; // If a description is specified, use it to build a tooltip. if (!empty($this->description)) { $label .= ' title="' . htmlspecialchars(trim(JText::_($text), ':') . '::' . JText::_($this->description), ENT_COMPAT, 'UTF-8') . '"'; } // Add the label text and closing tag. $label .= '>' . JText::_($text) . $req . '</label>'; return $label; }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('licenses'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_LICENSES'), 'jdlicenses'); if ($canDo->get('core.create')) { JToolBarHelper::addNew('license.add'); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('license.edit'); JToolBarHelper::divider(); JToolBarHelper::checkin('licenses.checkin'); } if ($canDo->get('core.edit.state')) { JToolBarHelper::divider(); JToolBarHelper::publish('licenses.publish', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::unpublish('licenses.unpublish', 'JTOOLBAR_UNPUBLISH', true); } if ($canDo->get('core.delete')) { JToolBarHelper::deleteList(JText::_('COM_JDOWNLOADS_DELETE_LIST_ITEM_CONFIRMATION'), 'licenses.delete', 'COM_JDOWNLOADS_TOOLBAR_REMOVE'); } JToolBarHelper::divider(); JToolBarHelper::help('help.licenses', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; JRequest::setVar('hidemainmenu', true); $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'); $title = $isNew ? JText::_('COM_JDOWNLOADS_LICEDIT_ADD') : JText::_('COM_JDOWNLOADS_LICEDIT_EDIT'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . $title, 'jdlicenses'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { JToolBarHelper::apply('license.apply'); JToolBarHelper::save('license.save'); } if (!$checkedOut && $canDo->get('core.create')) { JToolBarHelper::save2new('license.save2new'); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::save2copy('license.save2copy'); } if (empty($this->item->id)) { JToolBarHelper::cancel('license.cancel'); } else { JToolBarHelper::cancel('license.cancel', 'JTOOLBAR_CLOSE'); } JToolBarHelper::divider(); JToolBarHelper::help('help.license', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('templates'); // set the correct text in title for every layout type switch ($this->jd_tmpl_type) { case '1': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP1'); break; case '2': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP2'); break; case '3': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP3'); break; case '4': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP4'); break; case '5': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP5'); break; case '6': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP6'); break; case '7': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP7'); break; default: $layout_type = ''; } JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_BACKEND_CPANEL_TEMPLATES_NAME') . ': ' . $layout_type, 'jdlayouts'); JToolBarHelper::custom('templates.cancel', 'list.png', 'list.png', JText::_('COM_JDOWNLOADS_LAYOUTS'), false, false); JToolBarHelper::divider(); if ($canDo->get('core.create')) { JToolBarHelper::addNew('template.add'); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('template.edit'); } if ($canDo->get('core.delete')) { JToolBarHelper::deleteList(JText::_('COM_JDOWNLOADS_DELETE_LIST_ITEM_CONFIRMATION'), 'templates.delete', 'COM_JDOWNLOADS_TOOLBAR_REMOVE'); } if ($canDo->get('core.edit')) { JToolBarHelper::divider(); JToolBarHelper::custom('templates.activate', 'publish', 'publish', JText::_('COM_JDOWNLOADS_BACKEND_TEMPLIST_MENU_TEXT_ACTIVE'), true, false); JToolBarHelper::checkin('templates.checkin'); } if ($canDo->get('core.edit')) { JToolBarHelper::custom('layouts.install', 'upload.png', 'upload.png', JText::_('COM_JDOWNLOADS_LAYOUTS_IMPORT_LABEL'), false, false); JToolBarHelper::custom('templates.export', 'download.png', 'download.png', JText::_('COM_JDOWNLOADS_LAYOUTS_EXPORT_LABEL'), true, false); } JToolBarHelper::divider(); JToolBarHelper::help('help.templates', true); }
/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getInput() { $cat_dir = $this->form->getValue('cat_dir', '', ''); $cat_dir_path = JDownloadsHelper::getSplittedCategoryDirectoryPath($cat_dir); if ($cat_dir_path->current) { return $cat_dir_path->current; } return; }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; JRequest::setVar('hidemainmenu', true); $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'); // set the correct text in title for every layout type switch ($this->jd_tmpl_type) { case '1': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP1'); break; case '2': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP2'); break; case '3': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP3'); break; case '4': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP4'); break; case '5': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP5'); break; case '6': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP6'); break; case '7': $layout_type = JText::_('COM_JDOWNLOADS_BACKEND_TEMP_TYP7'); break; } $title = $isNew ? JText::_('COM_JDOWNLOADS_BACKEND_TEMPEDIT_ADD') . ': ' . $layout_type : JText::_('COM_JDOWNLOADS_BACKEND_TEMPEDIT_EDIT') . ': ' . $layout_type; JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . $title, 'jdlayouts'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create'))) { JToolBarHelper::apply('template.apply'); JToolBarHelper::save('template.save'); } if (!$checkedOut && $canDo->get('core.create')) { JToolBarHelper::save2new('template.save2new'); } // If an existing item, can save to a copy. if (!$isNew && $canDo->get('core.create')) { JToolBarHelper::save2copy('template.save2copy'); } if (empty($this->item->id)) { JToolBarHelper::cancel('template.cancel'); } else { JToolBarHelper::cancel('template.cancel', 'JTOOLBAR_CLOSE'); } JToolBarHelper::divider(); JToolBarHelper::help('help.template', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('info'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_TERMS_OF_USE'), 'jdinfo'); JToolBarHelper::divider(); JToolBarHelper::help('help.jdownloads', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('layouts'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_BACKEND_CPANEL_TEMPLATES_NAME'), 'jdlogo'); JToolBarHelper::divider(); JToolBarHelper::help('help.layouts', true); }
/** * Setting the toolbar */ protected function addToolBar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('files'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_FILESLIST_TITLE_FILES_UPLOAD'), 'jdupload'); JToolBarHelper::custom('uploads.files', 'files32.png', 'files32.png', JText::_('COM_JDOWNLOADS_FILES'), false, true); JToolBarHelper::custom('uploads.downloads', 'downloads32.png', 'downloads32.png', JText::_('COM_JDOWNLOADS_DOWNLOADS'), false, false); JToolBarHelper::divider(); JToolBarHelper::help('help.uploads', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('restore'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_RESTORATION'), 'jdrestore'); if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_jdownloads'); JToolBarHelper::divider(); } JToolBarHelper::help('help.restore', true); }
/** * Add the page title and toolbar. */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('backup'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_BACKUP'), 'jdbackup'); if ($canDo->get('core.admin')) { JToolBarHelper::custom('backup.runbackup', 'new', 'new', JText::_('COM_JDOWNLOADS_BACKUP_CREATE_LINK_LABEL'), false, false); JToolBarHelper::divider(); JToolBarHelper::preferences('com_jdownloads'); JToolBarHelper::divider(); } JToolBarHelper::help('help.backup', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('files'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_FILES'), 'jdfiles'); JToolBarHelper::custom('files.uploads', 'upload32.png', 'upload32.png', JText::_('COM_JDOWNLOADS_FILESLIST_TITLE_FILES_UPLOAD'), false, true); JToolBarHelper::custom('files.downloads', 'downloads32.png', 'downloads32.png', JText::_('COM_JDOWNLOADS_DOWNLOADS'), false, false); if ($canDo->get('core.delete')) { JToolBarHelper::deleteList(JText::_('COM_JDOWNLOADS_DELETE_LIST_ITEM_CONFIRMATION'), 'files.delete', 'COM_JDOWNLOADS_TOOLBAR_REMOVE'); JToolBarHelper::divider(); } JToolBarHelper::divider(); JToolBarHelper::help('help.files', true); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); JDownloadsHelper::addSubmenu('categories'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_CATEGORIES'), 'jdcategories'); if ($canDo->get('core.create')) { JToolBarHelper::addNew('category.add'); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('category.edit'); } if ($canDo->get('core.edit.state')) { JToolBarHelper::divider(); JToolBarHelper::publish('categories.publish', 'COM_JDOWNLOADS_PUBLISH', true); JToolBarHelper::unpublish('categories.unpublish', 'COM_JDOWNLOADS_UNPUBLISH', true); JToolBarHelper::divider(); JToolBarHelper::checkin('categories.checkin'); } if ($canDo->get('core.delete')) { JToolBarHelper::deleteList(JText::_('COM_JDOWNLOADS_DELETE_LIST_ITEM_CONFIRMATION'), 'categories.delete', 'COM_JDOWNLOADS_TOOLBAR_REMOVE'); JToolBarHelper::divider(); } // Add a batch button if ($canDo->get('core.create') && $canDo->get('core.edit') && $canDo->get('core.edit.state')) { JHtml::_('bootstrap.modal', 'collapseModal'); $title = JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button $layout = new JLayoutFile('joomla.toolbar.batch'); $dhtml = $layout->render(array('title' => $title)); $bar->appendButton('Custom', $dhtml, 'batch'); } if ($canDo->get('core.admin')) { JToolBarHelper::custom('categories.rebuild', 'refresh.png', 'refresh_f2.png', 'COM_JDOWNLOADS_REBUILD', false); JToolBarHelper::divider(); } JToolBarHelper::help('help.categories', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; JRequest::setVar('hidemainmenu', true); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); //JDownloadsHelper::addSubmenu('templates'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_BACKEND_EDIT_LANG_TITLE_EDIT'), 'jdlogo'); if ($canDo->get('core.admin')) { JToolBarHelper::save('languageedit.save'); JToolBarHelper::cancel('languageedit.cancel'); JToolBarHelper::divider(); JToolBarHelper::preferences('com_jdownloads'); JToolBarHelper::divider(); } JToolBarHelper::help('help.languageedit', true); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); JDownloadsHelper::addSubmenu('logs'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_LOGS_TITLE_HEAD'), 'jdlogs'); if ($canDo->get('core.edit')) { JToolBarHelper::custom('logs.blockip', 'cancel.png', 'cancel.png', JText::_('COM_JDOWNLOADS_BACKEND_LOG_LIST_BLOCK_IP'), true); } if ($canDo->get('core.delete')) { JToolBarHelper::deleteList(JText::_('COM_JDOWNLOADS_DELETE_LIST_ITEM_CONFIRMATION'), 'logs.delete', 'COM_JDOWNLOADS_TOOLBAR_REMOVE'); JToolBarHelper::divider(); } JToolBarHelper::divider(); JToolBarHelper::help('help.logs', true); }
/** * Downloads list view method * @return void **/ function display($tpl = null) { // set a switch so we can build later a valid: db query $app = JFactory::getApplication(); if ($this->getLayout() == 'modal' || $this->getLayout() == 'modallist') { $app->setUserState('jd_modal', true); // Load the backend helper require_once JPATH_ADMINISTRATOR . '/components/com_jdownloads/helpers/jdownloadshelper.php'; // we must load the admin language here explicit $lang = JFactory::getLanguage(); $locale = JDownloadsHelper::getLangKey(); $lang->load('com_jdownloads', JPATH_ADMINISTRATOR, $locale, true); } else { $app->setUserState('jd_modal', false); } $this->state = $this->get('State'); $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // create 'delete also file' option $filters = array(); $filters[] = JHtml::_('select.option', '0', JText::_('NO')); $filters[] = JHtml::_('select.option', '1', JText::_('YES')); $this->delete_file_option = $filters; // build categories list box $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_SELECT_UNCATEGORISED')); // get the categories data $categories = $this->getCategoriesList($config); $this->categories = @array_merge($select, $categories); parent::display($tpl); }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('../components/com_jdownloads/assets/css/jdownloads_buttons.css'); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); $document->addScriptDeclaration('function openWindow (url) { fenster = window.open(url, "_blank", "width=550, height=480, STATUS=YES, DIRECTORIES=NO, MENUBAR=NO, SCROLLBARS=YES, RESIZABLE=NO"); fenster.focus(); }'); $document->addScriptDeclaration('function getSelectedText( frmName, srcListName ) { var form = eval( \'document.\' + frmName ); var srcList = eval( \'form.\' + srcListName ); i = srcList.selectedIndex; if (i != null && i > -1) { return srcList.options[i].text; } else { return null; } }'); JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_BACKEND_CPANEL_SETTINGS'), 'jdconfig'); if ($canDo->get('edit.config')) { JToolBarHelper::apply('config.apply'); JToolBarHelper::save('config.save'); JToolBarHelper::cancel('config.cancel'); JToolBarHelper::divider(); } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_jdownloads'); JToolBarHelper::divider(); } if ($canDo->get('edit.config')) { JToolBarHelper::help('help.config', true); } }
/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { global $jlistConfig; $app = JFactory::getApplication(); JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers'); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); $custom_field_list = array(); $values = array(); $x = 0; if ($jlistConfig['custom.field.1.title'] != '') { if ($app->isAdmin()) { $values = explode(',', JDownloadsHelper::getOnlyLanguageSubstring($jlistConfig['custom.field.1.values'])); } else { $values = explode(',', JDHelper::getOnlyLanguageSubstring($jlistConfig['custom.field.1.values'])); } } $custom_field_list[] = JHtml::_('select.option', $x, JText::_('COM_JDOWNLOADS_SELECT')); foreach ($values as $value) { $x++; $custom_field_list[] = JHtml::_('select.option', $x, $value); } return $custom_field_list; }
/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { global $jlistConfig; $app = JFactory::getApplication(); if ($app->isAdmin()) { JHtml::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/helpers'); } else { JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); } // Initialise variables. $options = array(); $file_lang_values = ''; // build file language listbox if ($app->isAdmin()) { $file_lang_values = explode(',', JDownloadsHelper::getOnlyLanguageSubstring($jlistConfig['language.list'])); } else { $file_lang_values = explode(',', JDHelper::getOnlyLanguageSubstring($jlistConfig['language.list'])); } for ($i = 0; $i < count($file_lang_values); $i++) { $options[] = JHtml::_('select.option', $i, $file_lang_values[$i]); } return $options; }
/** * Add the page title and toolbar. * * */ protected function addToolbar() { global $jlistConfig; require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; $state = $this->get('State'); $canDo = JDownloadsHelper::getActions(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/style.css'); $document->addScriptDeclaration('function openWindow (url) { fenster = window.open(url, "_blank", "width=550, height=480, STATUS=YES, DIRECTORIES=NO, MENUBAR=NO, SCROLLBARS=YES, RESIZABLE=NO"); fenster.focus(); }'); // view menu only when we have not to work with an update if (!$jlistConfig['old.jd.release.found']) { JDownloadsHelper::addSubmenu('jdownloads'); } JToolBarHelper::title(JText::_('COM_JDOWNLOADS') . ': ' . JText::_('COM_JDOWNLOADS_CPANEL'), 'jdlogo'); if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_jdownloads'); JToolBarHelper::divider(); } JToolBarHelper::help('help.jdownloads', true); }
/** * 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); } }
</td> </tr> <tr> <th class="adminheading"><?php echo JText::_('COM_JDOWNLOADS_BACKEND_PANEL_STATUS_DOWNLOADS_HEADER') . " "; ?> </th> </tr> <tr> <td> <?php if ($jlistConfig['files.autodetect']) { // start the auto monitoring JDownloadsHelper::runMonitoring(); } else { echo '<b><font color="#FF6600">' . JText::_('COM_JDOWNLOADS_BACKEND_PANEL_STATUS_DOWNLOADS_OFF_DESC') . '</font></b><br />'; } // get the secret key then we need it as link param // so nobody else outside can run the script (or he know the key value - e.g. to start it via a cronjob) $config = JFactory::getConfig(); $key = $config->get('secret'); ?> <br /> <div><a href="<?php echo JURI::base(); ?> components/com_jdownloads/helpers/scan.php?key=<?php echo $key; ?>
<?php /** * @package jDownloads * @version 2.5 * @copyright (C) 2007 - 2013 - Arno Betz - www.jdownloads.com * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt * * jDownloads is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ defined('_JEXEC') or die; global $jlistConfig; $ini_upload_max_filesize = JDownloadsHelper::return_bytes(ini_get('upload_max_filesize')); JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); JHtml::_('behavior.tooltip'); JHTML::_('behavior.formvalidation'); // JHtml::_('behavior.formvalidator'); Joomla >= 3.4 JHtml::_('behavior.keepalive'); $admin_images_folder = JURI::root() . 'administrator/components/com_jdownloads/assets/images/'; ?> <script type="text/javascript"> Joomla.submitbutton = function(task) { if (task == 'download.cancel' || document.formvalidator.isValid(document.id('download-form'))) { Joomla.submitform(task, document.getElementById('download-form')); } else {
* @package jDownloads * @version 2.5 * @copyright (C) 2007 - 2013 - Arno Betz - www.jdownloads.com * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt * * jDownloads is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ defined('_JEXEC') or die('Restricted access'); if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } // Access check. if (!JFactory::getUser()->authorise('core.manage', 'com_jdownloads')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } // Require the base controller require_once JPATH_COMPONENT . DS . 'controller.php'; require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'jdownloadshelper.php'; global $jlistConfig; $GLOBALS['jlistConfig'] = JDownloadsHelper::buildjlistConfig(); jimport('joomla.application.component.controller'); // Get an instance of the controller $controller = JControllerLegacy::getInstance('jdownloads'); // Perform the Request task $jinput = JFactory::getApplication()->input; $controller->execute($jinput->get('task')); // Redirect if set by the controller $controller->redirect();
public function delete() { $jinput = JFactory::getApplication()->input; $id = $jinput->get('id', 0, 'integer'); $type = $jinput->get('type', '', 'string'); $result = false; $msg = ''; if ($id) { if ($type == 'prev') { $result = JDownloadsHelper::deletePreviewFile($id); } else { $result = JDownloadsHelper::deleteFile($id); } if ($result) { $msg = JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_REMOVE_OK'); } else { $msg = JText::_('COM_JDOWNLOADS_BACKEND_FILESEDIT_REMOVE_ERROR'); } } // set redirect $this->setRedirect('index.php?option=com_jdownloads&task=download.edit&file_id=' . $id, $msg); }
?> </td> <td align="center"><?php echo JDownloadsHelper::strToNumber((int) $item->downloads); ?> </td> <td class="center"> <?php echo JHtml::_('jgrid.published', $item->published, $i, 'downloads.', $canChange, 'cb', $item->publish_from, $item->publish_to); ?> </td> <td class="center"> <?php echo JDownloadsHelper::getFeatureHTML($item->featured, $i, $canChange); ?> </td> <td class="order"> <?php if ($canChange) { ?> <?php if ($saveOrder) { ?> <?php if ($listDirn == 'asc') { ?> <span><?php
/** * logic to save the config data * * @access public * @return void */ public function save() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $jinput = JFactory::getApplication()->input; $config = JFactory::getConfig(); $secret = $config->get('secret'); $config_data = $jinput->get('jlistConfig', array(), 'array'); // clean text data //$config_data['google.adsense.code'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['google.adsense.code'], 'HTML'); // adsense code use also javascript... $config_data['user.message.when.zero.points'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['user.message.when.zero.points'], 'HTML'); $config_data['fileplugin.offline_title'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['fileplugin.offline_title'], 'HTML'); $config_data['fileplugin.offline_descr'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['fileplugin.offline_descr'], 'HTML'); $config_data['send.mailto.template.download'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['send.mailto.template.download'], 'HTML'); $config_data['send.mailto.template.upload'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['send.mailto.template.upload'], 'HTML'); $config_data['report.mail.layout'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['report.mail.layout'], 'HTML'); $config_data['offline.text'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['offline.text'], 'HTML'); $config_data['downloads.titletext'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['downloads.titletext'], 'HTML'); $config_data['downloads.footer.text'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['downloads.footer.text'], 'HTML'); $config_data['blocking.list'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['blocking.list'], 'STRING'); $config_data['allowed.leeching.sites'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['allowed.leeching.sites'], 'STRING'); $config_data['mp3.player.config'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['mp3.player.config'], 'STRING'); $config_data['mp3.info.layout'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['mp3.info.layout'], 'HTML'); $config_data['language.list'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['language.list'], 'STRING'); $config_data['system.list'] = JFilterInput::getInstance(null, null, 1, 1)->clean($config_data['system.list'], 'STRING'); $org_upload_path = $jinput->get('root_dir', '', 'string'); $org_uncat_dir = $jinput->get('uncat_dir', '', 'string'); $org_preview_dir = $jinput->get('preview_dir', '', 'string'); $org_private_dir = $jinput->get('private_dir', '', 'string'); $org_temp_dir = $jinput->get('temp_dir', '', 'string'); $new_cat_pic = $jinput->get('cat_pic', '', 'string'); $config_data['cat.pic.default.filename'] = $new_cat_pic; $new_file_pic = $jinput->get('file_pic', '', 'string'); $config_data['file.pic.default.filename'] = $new_file_pic; $new_featured_pic = $jinput->get('featured_pic', '', 'string'); $config_data['featured.pic.filename'] = $new_featured_pic; $new_new_pic = $jinput->get('new_pic', '', 'string'); $config_data['picname.is.file.new'] = $new_new_pic; $new_hot_pic = $jinput->get('hot_pic', '', 'string'); $config_data['picname.is.file.hot'] = $new_hot_pic; $new_upd_pic = $jinput->get('upd_pic', '', 'string'); $config_data['picname.is.file.updated'] = $new_upd_pic; $new_down_pic = $jinput->get('down_pic', '', 'string'); $config_data['download.pic.details'] = $new_down_pic; $new_down_pic2 = $jinput->get('down_pic2', '', 'string'); $config_data['download.pic.files'] = $new_down_pic2; $new_mirror_pic = $jinput->get('mirror_1_pic', '', 'string'); $config_data['download.pic.mirror_1'] = $new_mirror_pic; $new_mirror_pic2 = $jinput->get('mirror_2_pic', '', 'string'); $config_data['download.pic.mirror_2'] = $new_mirror_pic2; $new_pic_plg = $jinput->get('down_pic_plg', '', 'string'); $config_data['download.pic.plugin'] = $new_pic_plg; $resize_thumbnails = $jinput->get('resize_thumbs', 0, 'integer'); $com = $jinput->get('com', '', 'string'); $task = $jinput->get('task'); $result = true; // remove slash on the end from path $config_data['files.uploaddir'] = rtrim($config_data['files.uploaddir'], "/"); $config_data['files.uploaddir'] = rtrim($config_data['files.uploaddir'], "\\"); // replacing backslashes with slashes $config_data['files.uploaddir'] = str_replace('\\', '/', $config_data['files.uploaddir']); if (!JFolder::exists($config_data['files.uploaddir'])) { JError::raiseWarning(100, 'Error Upload root folder not found!'); } // is upload folder changed? /*if ($org_upload_path != $new_upload_path && $new_upload_path != ''){ if (JFolder::exists($org_upload_path)){ // rename the folder $result_root = JFolder::move($org_upload_path, $new_upload_path); if ($result_root === true){ $config_data['files.uploaddir'] = $new_upload_path; } else { $config_data['files.uploaddir'] = $org_upload_path; JError::raiseWarning( 100, 'Error! Can not rename or copy the root folder: '.$org_upload_path.' to: '.$new_upload_path ); $result = false; } } else { $config_data['files.uploaddir'] = $org_upload_path; JError::raiseWarning( 100, 'Error Upload root folder not found!' ); $result = false; } } */ // remove slash on the end from folder name $config_data['uncategorised.files.folder.name'] = rtrim($config_data['uncategorised.files.folder.name'], "/"); $config_data['uncategorised.files.folder.name'] = rtrim($config_data['uncategorised.files.folder.name'], "\\"); // is sub folder name changed for uncategorised downloads? if ($org_uncat_dir != $config_data['uncategorised.files.folder.name'] && $config_data['uncategorised.files.folder.name'] != '') { // rename the folder $result_uncat = JFolder::move($config_data['files.uploaddir'] . DS . $org_uncat_dir, $config_data['files.uploaddir'] . DS . $config_data['uncategorised.files.folder.name']); if ($result_uncat !== true) { JError::raiseWarning(100, 'Error! Can not rename folder: ' . $config_data['files.uploaddir'] . DS . $org_uncat_dir); $result = false; } } // remove slash on the end from folder name $config_data['preview.files.folder.name'] = rtrim($config_data['preview.files.folder.name'], "/"); $config_data['preview.files.folder.name'] = rtrim($config_data['preview.files.folder.name'], "\\"); // is sub folder name changed for preview files folder? if ($org_preview_dir != $config_data['preview.files.folder.name'] && $config_data['preview.files.folder.name'] != '') { // rename the folder $result_preview = JFolder::move($config_data['files.uploaddir'] . DS . $org_preview_dir, $config_data['files.uploaddir'] . DS . $config_data['preview.files.folder.name']); if ($result_preview !== true) { JError::raiseWarning(100, 'Error! Can not rename folder: ' . $config_data['files.uploaddir'] . DS . $org_preview_dir); $result = false; } } // remove slash on the end from folder name $config_data['private.area.folder.name'] = rtrim($config_data['private.area.folder.name'], "/"); $config_data['private.area.folder.name'] = rtrim($config_data['private.area.folder.name'], "\\"); // is sub folder name changed for private user area? if ($org_private_dir != $config_data['private.area.folder.name'] && $config_data['private.area.folder.name'] != '') { // rename the folder $result_private = JFolder::move($config_data['files.uploaddir'] . DS . $org_private_dir, $config_data['files.uploaddir'] . DS . $config_data['private.area.folder.name']); if ($result_private !== true) { JError::raiseWarning(100, 'Error! Can not rename folder: ' . $config_data['files.uploaddir'] . DS . $org_private_dir); $result = false; } } // remove slash on the end from folder name $config_data['tempzipfiles.folder.name'] = rtrim($config_data['tempzipfiles.folder.name'], "/"); $config_data['tempzipfiles.folder.name'] = rtrim($config_data['tempzipfiles.folder.name'], "\\"); // is sub folder name changed for temporary files folder? if ($org_temp_dir != $config_data['tempzipfiles.folder.name'] && $config_data['tempzipfiles.folder.name'] != '') { // rename the folder $result_temp = JFolder::move($config_data['files.uploaddir'] . DS . $org_temp_dir, $config_data['files.uploaddir'] . DS . $config_data['tempzipfiles.folder.name']); if ($result_temp !== true) { JError::raiseWarning(100, 'Error! Can not rename folder: ' . $config_data['files.uploaddir'] . DS . $org_temp_dir); $result = false; } } // shall we resize all thumbnails? if ($resize_thumbnails == 1 && $config_data['thumbnail.size.height'] > 0 && $config_data['thumbnail.size.width'] > 0) { $msg = JDownloadsHelper::resizeAllThumbs($config_data['thumbnail.size.height'], $config_data['thumbnail.size.width']); JError::raiseNotice(100, $msg); } // check folder protection situation $source = JPATH_SITE . '/administrator/components/com_jdownloads/htaccess.txt'; $dest = $config_data['files.uploaddir'] . '/.htaccess'; if ($config_data['anti.leech'] && !is_file($dest)) { // if activated - copy and rename the htaccess if (JFile::exists($source)) { JFile::copy($source, $dest); $msg .= ' - ' . JText::_('COM_JDOWNLOADS_ACTIVE_ANTILEECH_OK'); } else { $msg .= ' - ' . JText::_('COM_JDOWNLOADS_ACTIVE_ANTILEECH_ERROR'); } } else { // anti leech off? then delete the htaccess if (!$config_data['anti.leech']) { if (JFile::exists($dest)) { if (JFile::delete($dest)) { $msg .= ' - ' . JText::_('COM_JDOWNLOADS_ACTIVE_ANTILEECH_OFF_OK'); } else { $msg .= ' - ' . JText::_('COM_JDOWNLOADS_ACTIVE_ANTILEECH_OFF_ERROR'); } } } } // clean the flowplayer config settings string, before we can save it if ($config_data['flowplayer.control.settings'] != '') { $config_data['flowplayer.control.settings'] = trim(str_replace("'", '"', $config_data['flowplayer.control.settings'])); } // remove spaces from lists $config_data['file.types.view'] = str_replace(' ', '', $config_data['file.types.view']); $config_data['file.types.autodetect'] = str_replace(' ', '', $config_data['file.types.autodetect']); $config_data['allowed.upload.file.types'] = str_replace(' ', '', $config_data['allowed.upload.file.types']); $config_data['allowed.leeching.sites'] = str_replace(' ', '', $config_data['allowed.leeching.sites']); // check the given upload size and correct it $max_upload_php_ini = (int) ini_get('upload_max_filesize') * 1024; if ($config_data['allowed.upload.file.size'] > $max_upload_php_ini) { $config_data['allowed.upload.file.size'] = $max_upload_php_ini; } if ($com != '') { if ($com == $secret) { $config_data['com'] = strrev($secret); } } // make sure that all AUP options are set back to default, when the main option is set off. if (!$config_data['use.alphauserpoints']) { $config_data['use.alphauserpoints.with.price.field'] = '0'; $config_data['user.can.download.file.when.zero.points'] = '1'; } // installed imagick is needed if ($config_data['create.pdf.thumbs']) { if (!extension_loaded('imagick')) { $config_data['create.pdf.thumbs'] = '0'; } } // try now to save the data if ($result === true) { $model = $this->getModel('config'); if ($model->save($config_data)) { $msg = JText::_('COM_JDOWNLOADS_BACKEND_SETTINGS_SAVED'); } else { JFactory::getApplication()->enqueueMessage(JText::_('COM_JDOWNLOADS_BACKEND_SETTINGS_NOT_SAVED'), 'error'); } } if ($task == 'apply') { $this->setRedirect('index.php?option=com_jdownloads&view=config', $msg); } else { $this->setRedirect('index.php?option=com_jdownloads', $msg); } }
/** * Method to load files data in array * * @access public * @return array An array of results. */ public function getItems() { global $jlistConfig; jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); require_once JPATH_COMPONENT . '/helpers/jdownloadshelper.php'; jimport('joomla.html.pagination'); $app = JFactory::getApplication('administrator'); $mainframe = JFactory::getApplication(); $option = 'com_jdownloads'; // Lets load the file data if it doesn't already exist if (empty($this->_data)) { // get all file names from upload root dir $files_dir = $jlistConfig['files.uploaddir'] . DS; $filenames = JFolder::files($jlistConfig['files.uploaddir'], $filter = '.', $recurse = false, $fullpath = false, $exclude = array('index.htm', 'index.html', '.htaccess')); $files_info = array(); // build data array for files list for ($i = 0; $i < count($filenames); $i++) { $files_info[$i]['id'] = $i + 1; $files_info[$i]['name'] = $filenames[$i]; $date_format = JDownloadsHelper::getDateFormat(); $files_info[$i]['date'] = date($date_format['long'], filemtime($files_dir . $filenames[$i])); $files_info[$i]['size'] = JDownloadsHelper::fsize($files_dir . $filenames[$i]); } // search in file names $search = $this->getState('filter.search'); if ($search) { $search_result = JDownloadsHelper::arrayRegexSearch('/' . $search . '/i', $files_info, TRUE, TRUE); foreach ($search_result as $result) { $files_info_result[] = $files_info[$result]; } $files_info = $files_info_result; } // build pagination data $limitstart = $this->getState('list.start'); $limit = $this->getState('list.limit'); $pageNav = new JPagination(count($files_info), $limitstart, $limit); $this->_pagination = $pageNav; $items = array_splice($files_info, $limitstart, $limit); $this->_data = $items; } return $this->_data; }
public function installSampleData() { global $jlistConfig; jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $db = JFactory::getDBO(); $query = $db->getQuery(true); $user = JFactory::getUser(); $error = false; $model = $this->getModel('category', '', array()); $model_download = $this->getModel('download', '', array()); // check user access right if (JFactory::getUser()->authorise('edit.config', 'com_jdownloads')) { $root_dir = $jlistConfig['files.uploaddir']; if (JFolder::exists($root_dir)) { if (is_writable($root_dir)) { // create it only when the folder for the sample category still not exists if (!JFolder::exists($root_dir . '/' . JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CAT_NAME_ROOT'))) { // create root cat $create_result = $model->createCategory(JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CAT_NAME_ROOT'), '1', '', JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CAT_NAME_TEXT'), 1); if (!$create_result) { // error message: can not rebuild tree in DB $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_REBUILD_ERROR')); } else { // create sub category $create_result_sub = $model->createCategory(JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CAT_NAME_SUB'), $create_result->id, '', JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CAT_NAME_TEXT')); if (!$create_result_sub) { // error message: can not rebuild tree in DB $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_REBUILD_ERROR')); } else { // create download example $filename = 'example_data_file.zip'; // copy first the file to the target folder $source_path = JPATH_COMPONENT_ADMINISTRATOR . '/assets/example_data_file.zip'; $dest_path = $root_dir . '/' . $create_result_sub->cat_dir_parent . '/' . $create_result_sub->cat_dir . '/example_data_file.zip'; $filesize = JDownloadsHelper::fsize($source_path); $result = JFile::copy($source_path, $dest_path); $new_download = $model_download->createDownload(JText::_('COM_JDOWNLOADS_SAMPLE_DATA_FILE_NAME'), $create_result_sub->id, '', JText::_('COM_JDOWNLOADS_SAMPLE_DATA_FILE_NAME_TEXT'), $filename, $filesize); if (!$new_download) { $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_REBUILD_ERROR')); } } } } else { // error message: upload folder not writeable $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_EXISTS')); } } else { // error message: upload folder not writeable $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CREATE_ERROR')); } } else { // error message: upload folder not found $error = true; JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_SAMPLE_DATA_CREATE_ERROR')); } if (!$error) { // result successful JFactory::getApplication()->enqueueMessage(JText::_('COM_JDOWNLOADS_TOOLS_RESET_RESULT_OKAY_MSG')); } } $this->setRedirect(JRoute::_('index.php?option=com_jdownloads&view=tools', false)); }