/** * 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; }
function display($tpl = null) { global $jlistConfig; // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); $userId = $user->get('id'); $jd_user_settings = JDHelper::getUserRules(); // get jD User group settings and limitations $this->user_rules = JDHelper::getUserRules(); $dispatcher = JDispatcher::getInstance(); $this->item = $this->get('Item'); $this->state = $this->get('State'); $this->user = $user; // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } $this->ipad_user = false; // check whether we have an ipad/iphone user for flowplayer aso... if ((bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') || (bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { $this->ipad_user = true; } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); if ($jlistConfig['view.ratings']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/rating/js/ajaxvote.js'); } // loadscript for flowplayer if ($jlistConfig['flowplayer.use']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer-3.2.12.min.js'); // load also the ipad plugin when required if ($this->ipad_user) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer.ipad-3.2.12.min.js'); } } if ($jlistConfig['use.lightbox.function']) { JHtml::_('bootstrap.framework'); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/lightbox/lightbox.js'); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/lightbox/lightbox.css", 'text/css', null, array()); } $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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(); }'); if ($jlistConfig['use.css.buttons.instead.icons']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); } $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); if ($jlistConfig['view.ratings']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); } $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $this->jd_image_path = JPATH_ROOT . '/images/jdownloads'; // Create a shortcut for $item. $item = $this->item; $item->tagLayout = new JLayoutFile('joomla.content.tags'); // Add router helpers. $item->slug = $item->file_alias ? $item->file_id . ':' . $item->file_alias : $item->file_id; $item->catslug = $item->category_alias ? $item->cat_id . ':' . $item->category_alias : $item->cat_id; $item->parent_slug = $item->category_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // TODO: Change based on shownoauth //$item->readmore_link = JRoute::_(JdownloadsHelperRoute::getDownloadRoute($item->slug, $item->catslug)); // Merge download params. If this is single-download view, menu params override download params // Otherwise, download params override menu item params $this->params = $this->state->get('params'); $active = $app->getMenu()->getActive(); $temp = clone $this->params; // Check to see which parameters should take priority if ($active) { $currentLink = $active->link; // If the current view is the active item and an download view for this download, then the menu item params take priority if (strpos($currentLink, 'view=download') && strpos($currentLink, '&id=' . (string) $item->file_id)) { // $item->params are the download params, $temp are the menu item params // Merge so that the menu item params take priority $item->params->merge($temp); // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } } else { // Current view is not a single download, so the download params take priority here // Merge the menu item params with the download params so that the download params take priority $temp->merge($item->params); $item->params = $temp; } } else { // Merge so that download params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-download menu item) // Single-download menu item layout takes priority over alt layout for an download if ($layout = $item->params->get('download_layout')) { $this->setLayout($layout); } } $offset = $this->state->get('list.offset'); // Check the view access to the download (the model has already computed the values). if ($item->params->get('access-view') != true && ($item->params->get('show_noauth') != true && $user->get('guest'))) { JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return; } $item->tags = new JHelperTags(); $item->tags->getItemTags('com_jdownloads.download', $this->item->file_id); // required for some content plugins if ($item->description_long != '') { $item->text = $item->description_long; $long_used = true; } else { $item->text = $item->description; $long_used = false; } $item->id = $item->file_id; // Process the content plugins. JPluginHelper::importPlugin('content'); // this is the event to modify the download data. if ($jlistConfig['activate.general.plugin.support'] && !$jlistConfig['use.general.plugin.support.only.for.descriptions']) { $dispatcher->trigger('onContentPrepare', array('com_jdownloads.download', &$item, &$this->params, $offset)); } $item->event = new stdClass(); // This is a request for information that should be placed immediately before the generated content. $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_jdownloads.download', &$item, &$this->params, $offset)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); // This is a request for information that should be placed immediately after the generated content. $results = $dispatcher->trigger('onContentAfterDisplay', array('com_jdownloads.download', &$item, &$this->params, $offset)); $item->event->afterDisplayContent = trim(implode("\n", $results)); // we use a little trick to get always the changes from content plugins if ($long_used) { if ($item->text != $item->description_long) { $item->description_long = $item->text; } } else { if ($item->text != $item->description) { $item->description = $item->text; } } // Increment the views counter of the download $model = $this->getModel(); $model->view(); //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx')); $this->_prepareDocument(); parent::display($tpl); }
function jd_file_fill_downloadok($p_Template, $files, $p_Symbol_Off, $p_DownloadType, $download_allowed) { global $jlistConfigM, $jDFPsfolders, $jDFPrank, $jDFPlive_site, $jDFPplugin_live_site, $jDFPabsolute_path, $cat_link_itemidsPlg, $jDLayoutTitleExists, $root_itemid, $date_format; $db = JFactory::getDBO(); $user = JFactory::getUser(); $jd_user_settings = JDHelper::getUserRules(); $jdlink_author_text = ''; $createdbyname = ''; $modifiedbyname = ''; $l_Template = str_replace("{{{", "[[[", $p_Template); $jdpic_license = ''; $jdpic_date = ''; $jdpic_author = ''; $jdpic_website = ''; $jdpic_system = ''; $jdpic_language = ''; $jdpic_download = ''; $jdpic_hits = ''; $jdpic_size = ''; $jdpic_price = ''; $cat_itemid = 0; if ($p_Symbol_Off == 0) { $msize = $jlistConfigM['info.icons.size']; $jdpic_license = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'license.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_LICENCE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_LICENCE') . '" /> '; $jdpic_date = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'date.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DATE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DATE') . '" /> '; $jdpic_author = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'contact.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_AUTHOR') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_AUTHOR') . '" /> '; $jdpic_website = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'weblink.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_WEBSITE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_WEBSITE') . '" /> '; $jdpic_system = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'system.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_SYSTEM') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_SYSTEM') . '" /> '; $jdpic_language = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'language.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_LANGUAGE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_LANGUAGE') . '" /> '; $jdpic_download = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'download.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DOWNLOAD') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DOWNLOAD') . '" /> '; $jdpic_hits = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'download.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DOWNLOAD') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_DOWNLOAD_HITS') . '" /> '; $jdpic_size = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'stuff.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_FILESIZE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_FILESIZE') . '" /> '; $jdpic_price = '<img src="' . JURI::base() . $jDFPsfolders['mini'] . 'currency.png" style="vertical-align:middle;" width="' . $msize . '" height="' . $msize . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_PRICE') . '" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_PRICE') . '" /> '; } // Build a little pic for extern links $jdextern_url_pic = '<img src="' . $jDFPplugin_live_site . 'content/jdownloads/jdownloads/images/link_extern.gif" style="vertical-align:middle;" alt="" title="" />'; $jd_file_pic = '<img src="' . JURI::base() . $jDFPsfolders['file'] . $files->file_pic . '" style="vertical-align:middle;" border="0" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" alt="" title="" />'; // Pics for: new file / hot file /updated $hotpic = '<img src="' . JURI::base() . 'images/jdownloads/hotimages/' . $jlistConfigM['picname.is.file.hot'] . '" alt="" />'; $newpic = '<img src="' . JURI::base() . 'images/jdownloads/newimages/' . $jlistConfigM['picname.is.file.new'] . '" alt="" />'; $updatepic = '<img src="' . JURI::base() . 'images/jdownloads/updimages/' . $jlistConfigM['picname.is.file.updated'] . '" alt="" />'; // Alternate CSS buttons when selected in configuration $status_color_hot = $jlistConfigM['css.button.color.hot']; $status_color_new = $jlistConfigM['css.button.color.new']; $status_color_updated = $jlistConfigM['css.button.color.updated']; $download_color = $jlistConfigM['css.button.color.download']; $download_size = $jlistConfigM['css.button.size.download']; $download_size_mirror = $jlistConfigM['css.button.size.download.mirror']; $download_color_mirror1 = $jlistConfigM['css.button.color.mirror1']; $download_color_mirror2 = $jlistConfigM['css.button.color.mirror2']; $download_size_listings = $jlistConfigM['css.button.size.download.small']; $jd_cat_id = $files->cat_id; $jd_filename = $files->url_download; $jd_file_language = $files->file_language; $jd_system = $files->system; if ($files->category_cat_dir_parent) { $category_dir = $files->category_cat_dir_parent . '/' . $files->category_cat_dir; } else { $category_dir = $files->category_cat_dir; } // Has this Download really a file? if (!$files->url_download && !$files->other_file_id && !$files->extern_file) { // only a document without file $no_file_info = JText::_('COM_JDOWNLOADS_FRONTEND_ONLY_DOCUMENT_USER_INFO'); $download_has_a_file = false; } else { $download_has_a_file = true; $no_file_info = ''; } // Compute the download slugs $files->slug = $files->file_alias ? $files->file_id . ':' . $files->file_alias : $files->file_id; // create all file titles $l_Template = JDHelper::buildFieldTitles($l_Template, $files); // When we have a simple document, view only the info not any buttons. if (!$download_has_a_file) { if (strpos($l_Template, '{url_download}')) { $l_Template = str_replace('{url_download}', $no_file_info, $l_Template); } else { $l_Template = str_replace('{checkbox_list}', $no_file_info, $l_Template); } // Place the images $l_Template = JDHelper::placeThumbs($l_Template, $files->images); if ($jlistConfigM['view.detailsite']) { $title_link = JRoute::_(JDownloadsHelperRoute::getDownloadRoute($files->slug, $files->cat_id, $files->language)); $title_link_text = '<a href="' . $title_link . '">' . $db->escape($files->file_title) . '</a>'; $detail_link_text = '<a href="' . $title_link . '">' . JText::_('COM_JDOWNLOADS_FE_DETAILS_LINK_TEXT_TO_DETAILS') . '</a>'; // Build the file symbol (with link) if ($files->file_pic != '') { $filepic = '<a href="' . $title_link . '">' . '<img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" /></a> '; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); // link to details view at the end $l_Template = str_replace('{link_to_details}', $detail_link_text, $l_Template); $l_Template = str_replace('{file_title}', $title_link_text, $l_Template); } else { // no links if ($files->file_pic != '') { $filepic = '<img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" />'; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); // remove link to details view at the end $l_Template = str_replace('{link_to_details}', '', $l_Template); $l_Template = str_replace('{file_title}', $files->file_title, $l_Template); } $l_Template = str_replace('{checkbox_list}', '', $l_Template); $l_Template = str_replace('{mirror_1}', '', $l_Template); $l_Template = str_replace('{mirror_2}', '', $l_Template); $l_Template = str_replace('{hits_value}', '', $l_Template); $l_Template = str_replace('{filesize_value}', '', $l_Template); } // insert rating system if ($jlistConfigM['view.ratings']) { $rating_system = JDHelper::getRatings($files->file_id, $files->rating_count, $files->rating_sum); $l_Template = str_replace('{rating}', $rating_system, $l_Template); } else { $l_Template = str_replace('{rating}', '', $l_Template); } // Build the license info data and build link if ($files->license == '') { $files->license = 0; } $lic_data = ''; if ($files->license_url != '') { $lic_data = $jdpic_license . '<a href="' . $files->license_url . '" target="_blank" rel="nofollow" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_MINI_ICON_ALT_LICENCE') . '">' . $files->license_title . '</a> ' . $jdextern_url_pic; } else { if ($files->license_title != '') { if ($files->license_text != '') { $lic_data = $jdpic_license . $files->license_title; $lic_data .= JHtml::_('tooltip', $files->license_text, $files->license_title); } else { $lic_data = $files->license_title; } } else { $lic_data = ''; } } $l_Template = str_replace('{license_text}', $lic_data, $l_Template); $l_Template = str_replace('{license}', $lic_data, $l_Template); // old placeholder // Build the 'files language' data $file_lang_values = explode(',', JDHelper::getOnlyLanguageSubstring($jlistConfigM['language.list'])); if ($jd_file_language == 0) { $jd_showlanguage = ''; } else { $jd_showlanguage = $jdpic_language . $file_lang_values[$jd_file_language]; } $l_Template = str_replace("{language}", $jd_showlanguage, $l_Template); // old placeholder $l_Template = str_replace("{language_text}", $jd_showlanguage, $l_Template); // Build the 'System' data $file_sys_values = explode(',', $jlistConfigM['system.list']); if ($jd_system == 0) { $jd_showsystem = ''; } else { $jd_showsystem = $jdpic_system . $file_sys_values[$jd_system]; } $l_Template = str_replace("{system}", $jd_showsystem, $l_Template); // old placeholder $l_Template = str_replace("{system_text}", $jd_showsystem, $l_Template); // Build hits values $numbers_downloads = JDHelper::strToNumber((int) $files->downloads); $jd_showhits = $jdpic_hits . $numbers_downloads; $l_Template = str_replace("{hits_value}", $jd_showhits, $l_Template); // Build website url if (!$files->url_home == '') { if (strpos($files->url_home, 'http://') !== false) { $l_Template = str_replace('{url_home}', $jdpic_website . '<a href="' . $files->url_home . '" target="_blank" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '</a> ' . $jdextern_url_pic, $l_Template); $l_Template = str_replace('{author_url_text} ', $jdpic_website . '<a href="' . $files->url_home . '" target="_blank" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '</a> ' . $jdextern_url_pic, $l_Template); } else { $l_Template = str_replace('{url_home}', $jdpic_website . '<a href="http://' . $files->url_home . '" target="_blank" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '</a> ' . $jdextern_url_pic, $l_Template); $l_Template = str_replace('{author_url_text}', $jdpic_website . '<a href="http://' . $files->url_home . '" target="_blank" title="' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_HOMEPAGE') . '</a> ' . $jdextern_url_pic, $l_Template); } } else { $l_Template = str_replace('{url_home}', '', $l_Template); $l_Template = str_replace('{author_url_text}', '', $l_Template); } // Encode is link a mail if (strpos($files->url_author, '@') && $jlistConfigM['mail.cloaking']) { if (!$files->author) { $mail_encode = JHtml::_('email.cloak', $files->url_author); } else { $mail_encode = JHtml::_('email.cloak', $files->url_author, true, $files->author, false); } } // Build author link if ($files->author != '') { if ($files->url_author != '') { if ($mail_encode) { $link_author = $jdpic_author . $mail_encode; } else { if (strpos($files->url_author, 'http://') !== false) { $link_author = $jdpic_author . '<a href="' . $files->url_author . '" target="_blank">' . $files->author . '</a> ' . $extern_url_pic; } else { $link_author = $jdpic_author . '<a href="http://' . $files->url_author . '" target="_blank">' . $files->author . '</a> ' . $extern_url_pic; } } $l_Template = str_replace('{author}', $link_author, $l_Template); $l_Template = str_replace('{author_text}', $link_author, $l_Template); $l_Template = str_replace('{url_author}', '', $l_Template); } else { $link_author = $jdpic_author . $files->author; $l_Template = str_replace('{author}', $link_author, $l_Template); $l_Template = str_replace('{author_text}', $link_author, $l_Template); $l_Template = str_replace('{url_author}', '', $l_Template); } } else { $l_Template = str_replace('{url_author}', $jdpic_author . $files->url_author, $l_Template); $l_Template = str_replace('{author}', '', $l_Template); $l_Template = str_replace('{author_text}', '', $l_Template); } // Place the images $l_Template = JDHelper::placeThumbs($l_Template, $files->images, 'list'); // Compute for HOT symbol if ($jlistConfigM['loads.is.file.hot'] > 0 && $files->downloads >= $jlistConfigM['loads.is.file.hot']) { // Is the old button pic used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $l_Template = str_replace('{pic_is_hot}', $hotpic, $l_Template); } else { // CSS Button is selected $l_Template = str_replace('{pic_is_hot}', '<span class="jdbutton ' . $status_color_hot . ' jstatus">' . JText::_('COM_JDOWNLOADS_HOT') . '</span>', $l_Template); } } else { $l_Template = str_replace('{pic_is_hot}', '', $l_Template); } // Compute for NEW symbol $days_diff = JDHelper::computeDateDifference(date('Y-m-d H:i:s'), $files->date_added); if ($jlistConfigM['days.is.file.new'] > 0 && $days_diff <= $jlistConfigM['days.is.file.new']) { // Is the old button used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $l_Template = str_replace('{pic_is_new}', $newpic, $l_Template); } else { // CSS Button is selected $l_Template = str_replace('{pic_is_new}', '<span class="jdbutton ' . $status_color_new . ' jstatus">' . JText::_('COM_JDOWNLOADS_NEW') . '</span>', $l_Template); } } else { $l_Template = str_replace('{pic_is_new}', '', $l_Template); } // Compute for UPDATED symbol // View it only when in the download is activated the 'updated' option if ($files->update_active) { $days_diff = JDHelper::computeDateDifference(date('Y-m-d H:i:s'), $files->modified); if ($jlistConfigM['days.is.file.updated'] > 0 && $days_diff >= 0 && $days_diff <= $jlistConfigM['days.is.file.updated']) { if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $l_Template = str_replace('{pic_is_updated}', $updatepic, $l_Template); } else { // CSS Button is selected $l_Template = str_replace('{pic_is_updated}', '<span class="jdbutton ' . $status_color_updated . ' jstatus">' . JText::_('COM_JDOWNLOADS_UPDATED') . '</span>', $l_Template); } } else { $l_Template = str_replace('{pic_is_updated}', '', $l_Template); } } else { $l_Template = str_replace('{pic_is_updated}', '', $l_Template); } // file size if (!$files->size == '') { $l_Template = str_replace('{size}', $jdpic_size . $files->size, $l_Template); $l_Template = str_replace('{filesize_value}', $jdpic_size . $files->size, $l_Template); } else { $l_Template = str_replace('{size}', '', $l_Template); $l_Template = str_replace('{filesize_value}', '', $l_Template); } // price if ($files->price != '') { $l_Template = str_replace('{price_value}', $jdpic_price . $files->price, $l_Template); } else { $l_Template = str_replace('{price_value}', '', $l_Template); } // file_date if ($files->file_date != '0000-00-00 00:00:00') { if ($files->params->get('show_date') == 0) { $filedate_data = $jdpic_date . JHtml::_('date', $files->file_date, $date_format['long']); $filedate_data_title = JText::_('COM_JDOWNLOADS_EDIT_FILE_FILE_DATE_TITLE'); } else { $filedate_data = $jdpic_date . JHtml::_('date', $files->file_date, $date_format['short']); $filedate_data_title = ''; } } else { $filedate_data = ''; $filedate_data_title = ''; } $l_Template = str_replace('{file_date}', $filedate_data, $l_Template); // date_added if ($files->date_added != '0000-00-00 00:00:00') { if ($files->params->get('show_date') == 0) { // use 'normal' date-time format field $date_data = $jdpic_date . JHtml::_('date', $files->date_added, $date_format['long']); } else { // use 'short' date-time format field $date_data = $jdpic_date . JHtml::_('date', $files->date_added, $date_format['short']); } } else { $date_data = ''; } $l_Template = str_replace('{date_added}', $date_data, $l_Template); $l_Template = str_replace('{created_date_value}', $date_data, $l_Template); if ($files->creator) { $l_Template = str_replace('{created_by_value}', $files->creator, $l_Template); } else { $l_Template = str_replace('{created_by_value}', '', $l_Template); } if ($files->modifier) { $l_Template = str_replace('{modified_by_value}', $files->modifier, $l_Template); } else { $l_Template = str_replace('{modified_by_value}', '', $l_Template); } // modified_date if ($files->modified != '0000-00-00 00:00:00') { if ($files->params->get('show_date') == 0) { $modified_data = $jdpic_date . JHtml::_('date', $files->modified, $date_format['long']); } else { $modified_data = $jdpic_date . JHtml::_('date', $files->modified, $date_format['short']); } } else { $modified_data = ''; } $l_Template = str_replace('{modified_date_value}', $modified_data, $l_Template); if ($files->release == '') { $l_Template = str_replace('{release}', '', $l_Template); } else { $l_Template = str_replace('{release}', $files->release, $l_Template); // with versions text from language file // $l_Template = str_replace('{release}', JText::_('COM_JDOWNLOADS_FRONTEND_VERSION_TITLE').$files->release, $l_Template); } // Create an additional hint for the description footer when this download has a file but user has not the download permissions if ($download_has_a_file) { if ($user->guest) { // when CSS3 buttons are activate, we use it also for the message if ($jlistConfigM['use.css.buttons.instead.icons']) { $first_reg_msg = '<div class="' . $jlistConfigM['css.button.color.download'] . ' ' . $jlistConfigM['css.button.size.download'] . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_FILE_ACCESS_REGGED') . '</div>'; } else { $first_reg_msg = '<div class="jdpf_not_logged_in">' . JText::_('COM_JDOWNLOADS_FRONTEND_FILE_ACCESS_REGGED') . '</div>'; } } else { // when CSS3 buttons are activate, we use it also for the message if ($jlistConfigM['use.css.buttons.instead.icons']) { $first_reg_msg = '<div class="' . $jlistConfigM['css.button.color.download'] . ' ' . $jlistConfigM['css.button.size.download'] . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_FILE_ACCESS_REGGED2') . '</div>'; } else { $first_reg_msg = '<div class="jdpf_not_logged_in">' . JText::_('COM_JDOWNLOADS_FRONTEND_FILE_ACCESS_REGGED2') . '</div>'; } } } else { $first_reg_msg = ''; } // Check and build the description text if ($jlistConfigM['plugin.auto.file.short.description'] && $jlistConfigM['plugin.auto.file.short.description.value'] > 0) { if (strlen($files->description) > $jlistConfigM['plugin.auto.file.short.description.value']) { // Cut description text $shorted_text = preg_replace("/[^ ]*\$/", '..', substr($files->description, 0, $jlistConfigM['plugin.auto.file.short.description.value'])); if (!$download_allowed) { //$l_Template = str_replace('{description}', $shorted_text.$first_reg_msg, $l_Template); $l_Template = str_replace('{description}', $shorted_text, $l_Template); } else { $l_Template = str_replace('{description}', $shorted_text, $l_Template); } } else { if (!$download_allowed) { // $l_Template = str_replace('{description}', $files->description.$first_reg_msg, $l_Template); $l_Template = str_replace('{description}', $files->description, $l_Template); } else { $l_Template = str_replace('{description}', $files->description, $l_Template); } } } else { if (!$download_allowed) { //$l_Template = str_replace("{description}",$files->description.$first_reg_msg, $l_Template); $l_Template = str_replace("{description}", $files->description, $l_Template); } else { $l_Template = str_replace("{description}", $files->description, $l_Template); } } // create filename if ($files->url_download) { $l_Template = str_replace('{file_name}', JDHelper::getShorterFilename($files->url_download), $l_Template); } elseif (isset($files->filename_from_other_download) && $files->filename_from_other_download != '') { $l_Template = str_replace('{file_name}', JDHelper::getShorterFilename($files->filename_from_other_download), $l_Template); } else { $l_Template = str_replace('{file_name}', '', $l_Template); } // google adsense if ($jlistConfigM['google.adsense.active']) { $l_Template = str_replace('{google_adsense}', stripslashes($jlistConfigM['google.adsense.code']), $l_Template); } else { $l_Template = str_replace('{google_adsense}', '', $l_Template); } // report download link if ($jd_user_settings->view_report_form) { $report_link = '<a href="' . JRoute::_("index.php?option=com_jdownloads&view=report&id=" . $files->slug . "&catid=" . $files->cat_id . "&Itemid=" . $root_itemid) . '" rel="nofollow">' . JText::_('COM_JDOWNLOADS_FRONTEND_REPORT_FILE_LINK_TEXT') . '</a>'; $l_Template = str_replace('{report_link}', $report_link, $l_Template); } else { $l_Template = str_replace('{report_link}', '', $l_Template); } // media player if ($files->preview_filename) { // we use the preview file when exist $is_preview = true; $files->itemtype = JDHelper::getFileExtension($files->preview_filename); $is_playable = JDHelper::isPlayable($files->preview_filename); $extern_media = false; } else { $is_preview = false; if ($files->extern_file) { $extern_media = true; $files->itemtype = JDHelper::getFileExtension($files->extern_file); $is_playable = JDHelper::isPlayable($files->extern_file); } else { $files->itemtype = JDHelper::getFileExtension($files->url_download); $is_playable = JDHelper::isPlayable($files->url_download); $extern_media = false; } } if (!$jlistConfigM['flowplayer.use'] && $files->itemtype == 'mp3') { // we use only the 'OLD' mp3 player if ($extern_media) { $mp3_path = $files->extern_file; } else { if ($is_preview) { // we need the path to the "previews" folder $mp3_path = JUri::base() . basename($jlistConfigM['files.uploaddir']) . '/' . $jlistConfigM['preview.files.folder.name'] . '/' . $files->preview_filename; } else { // we use the normal download file for the player $mp3_path = JUri::base() . basename($jlistConfigM['files.uploaddir']) . '/' . $category_dir . '/' . $files->url_download; } } $mp3_config = trim($jlistConfigM['mp3.player.config']); $mp3_config = str_replace('', '', $mp3_config); $mp3_config = str_replace(';', '&', $mp3_config); $mp3_player = '<object type="application/x-shockwave-flash" data="components/com_jdownloads/assets/mp3_player_maxi.swf" width="200" height="20"> <param name="movie" value="components/com_jdownloads/assets/mp3_player_maxi.swf" /> <param name="wmode" value="transparent"/> <param name="FlashVars" value="mp3=' . $mp3_path . '&' . $mp3_config . '" /> </object>'; $l_Template = str_replace('{mp3_player}', $mp3_player, $l_Template); } if ($jlistConfigM['flowplayer.use'] && $is_playable) { // we will use the new flowplayer option if ($extern_media) { $media_path = $files->extern_file; } else { if ($is_preview) { // we need the relative path to the "previews" folder $media_path = basename($jlistConfigM['files.uploaddir']) . '/' . $jlistConfigM['preview.files.folder.name'] . '/' . $files->preview_filename; } else { // we use the normal download file for the player $media_path = basename($jlistConfigM['files.uploaddir']) . '/' . $category_dir . '/' . $files->url_download; } } $ipadcode = ''; if ($files->itemtype == 'mp3') { $fullscreen = 'false'; $autohide = 'false'; $playerheight = (int) $jlistConfigM['flowplayer.playerheight.audio']; // we must use also the ipad plugin identifier when required // see http://flowplayer.blacktrash.org/test/ipad-audio.html and http://flash.flowplayer.org/plugins/javascript/ipad.html if ($ipad_user) { $ipadcode = '.ipad();'; } } else { $fullscreen = 'true'; $autohide = 'true'; $playerheight = (int) $jlistConfigM['flowplayer.playerheight']; } $player = '<a href="' . $media_path . '" style="display:block;width:' . $jlistConfigM['flowplayer.playerwidth'] . 'px; height:' . $playerheight . 'px;" class="player" id="player' . $files->file_id . '"></a>'; $player .= '<script language="JavaScript"> // install flowplayer into container flowplayer("player' . $files->file_id . '", "' . JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer-3.2.16.swf", { plugins: { controls: { // insert at first the config settings ' . $jlistConfigM['flowplayer.control.settings'] . ' // and now the basics fullscreen: ' . $fullscreen . ', height: ' . (int) $jlistConfigM['flowplayer.playerheight.audio'] . ', autoHide: ' . $autohide . ', } }, clip: { autoPlay: false, // optional: when playback starts close the first audio playback onBeforeBegin: function() { $f("player' . $files->file_id . '").close(); } } })' . $ipadcode . '; </script>'; // the 'ipad code' above is only required for ipad/iphone users // We will replace at first the old placeholder when exist if (strpos($l_Template, '{mp3_player}')) { $l_Template = str_replace('{mp3_player}', $player, $l_Template); } else { $l_Template = str_replace('{preview_player}', $player, $l_Template); } } if ($jlistConfigM['mp3.view.id3.info'] && $files->itemtype == 'mp3' && !$extern_media) { // read mp3 infos if ($is_preview) { // get the path to the preview file $mp3_path_abs = $jlistConfigM['files.uploaddir'] . '/' . $jlistConfigM['preview.files.folder.name'] . '/' . $files->preview_filename; } else { // get the path to the downloads file $mp3_path_abs = $jlistConfigM['files.uploaddir'] . '/' . $category_dir . '/' . $files->url_download; } $info = JDHelper::getID3v2Tags($mp3_path_abs); if ($info) { // add it $mp3_info = stripslashes($jlistConfigM['mp3.info.layout']); $mp3_info = str_replace('{name_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_TITLE'), $mp3_info); if ($is_preview) { $mp3_info = str_replace('{name}', $files->preview_filename, $mp3_info); } else { $mp3_info = str_replace('{name}', $files->url_download, $mp3_info); } $mp3_info = str_replace('{album_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_ALBUM'), $mp3_info); if (isset($info['TALB'])) { $mp3_info = str_replace('{album}', $info['TALB'], $mp3_info); } else { $mp3_info = str_replace('{album}', '', $mp3_info); } $mp3_info = str_replace('{artist_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_ARTIST'), $mp3_info); if (isset($info['TPE1'])) { $mp3_info = str_replace('{artist}', $info['TPE1'], $mp3_info); } else { $mp3_info = str_replace('{artist}', '', $mp3_info); } $mp3_info = str_replace('{genre_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_GENRE'), $mp3_info); if (isset($info['TCON'])) { $mp3_info = str_replace('{genre}', $info['TCON'], $mp3_info); } else { $mp3_info = str_replace('{genre}', '', $mp3_info); } $mp3_info = str_replace('{year_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_YEAR'), $mp3_info); if (isset($info['TYER'])) { $mp3_info = str_replace('{year}', $info['TYER'], $mp3_info); } else { $mp3_info = str_replace('{year}', '', $mp3_info); } $mp3_info = str_replace('{length_title}', JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_LENGTH'), $mp3_info); if (isset($info['TLEN'])) { $mp3_info = str_replace('{length}', $info['TLEN'] . ' ' . JText::_('COM_JDOWNLOADS_FE_VIEW_ID3_MINS'), $mp3_info); } else { $mp3_info = str_replace('{length}', '', $mp3_info); } $l_Template = str_replace('{mp3_id3_tag}', $mp3_info, $l_Template); } } // replace the {preview_url} if ($files->preview_filename) { // we need the relative path to the "previews" folder $media_path = basename($jlistConfigM['files.uploaddir']) . '/' . $jlistConfigM['preview.files.folder.name'] . '/' . $files->preview_filename; $l_Template = str_replace('{preview_url}', $media_path, $l_Template); } else { $l_Template = str_replace('{preview_url}', '', $l_Template); } $user_can_see_download_url = false; // only view download link when user has correct access level if ($files->params->get('access-download') == true) { $user_can_see_download_url = true; $blank_window = ''; $blank_window1 = ''; $blank_window2 = ''; // get file extension $view_types = array(); $view_types = explode(',', $jlistConfigM['file.types.view']); $only_file_name = basename($files->url_download); $filesextension = JDHelper::getFileExtension($only_file_name); if (in_array($filesextension, $view_types)) { $blank_window = 'target="_blank"'; } // check is set link to a new window? if ($files->extern_file && $files->extern_site) { $blank_window = 'target="_blank"'; } // is 'direct download' activated? if ($jlistConfigM['direct.download'] == '0') { // when not, we must link to the summary page $url_task = 'summary'; $blank_window = ''; $download_link = JRoute::_(JDownloadsHelperRoute::getOtherRoute($files->slug, $files->cat_id, $files->language, $url_task)); } else { if ($files->license_agree || $files->password || $jd_user_settings->view_captcha) { // user must agree the license - fill out a password field - or fill out the captcha human check - so we must view the summary page! $url_task = 'summary'; $download_link = JRoute::_(JDownloadsHelperRoute::getOtherRoute($files->slug, $files->cat_id, $files->language, $url_task)); } else { // start the download promptly $url_task = 'download.send'; $download_link = JRoute::_('index.php?option=com_jdownloads&task=download.send&id=' . $files->file_id . '&catid=' . $files->cat_id . '&m=0'); } } if ($url_task == 'download.send') { // is the old button used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $download_link_text = '<a ' . $blank_window . ' href="' . $download_link . '" class="jd_download_url"><img src="' . JURI::base() . 'images/jdownloads/downloadimages/' . $jlistConfigM['download.pic.details'] . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" /></a>'; } else { // we use the new css button $download_link_text = '<a ' . $blank_window . ' href="' . $download_link . '" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" class="jdbutton ' . $download_color . ' ' . $download_size_listings . '">' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '</a>'; } } else { // is the old button used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $download_link_text = '<a href="' . $download_link . '" class="jd_download_url"><img src="' . JURI::base() . 'images/jdownloads/downloadimages/' . $jlistConfigM['download.pic.details'] . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" title="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" /></a>'; } else { // we use the new css button $download_link_text = '<a ' . $blank_window . ' href="' . $download_link . '" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" class="jdbutton ' . $download_color . ' ' . $download_size_listings . '">' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '</a>'; } } if (strpos($l_Template, '{url_download}')) { $l_Template = str_replace('{url_download}', $download_link_text, $l_Template); } else { $l_Template = str_replace('{checkbox_list}', $download_link_text, $l_Template); } // mirrors if ($files->mirror_1) { if ($files->extern_site_mirror_1 && $url_task == 'download.send') { $blank_window1 = 'target="_blank"'; } $mirror1_link_dum = JRoute::_('index.php?option=com_jdownloads&task=download.send&id=' . $files->file_id . '&catid=' . $files->cat_id . '&m=1'); //$mirror1_link_dum = JRoute::_(JDownloadsHelperRoute::getOtherRoute($files->slug, $files->cat_id, $files->language, $url_task, 1)); // is the old button used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $mirror1_link = '<a ' . $blank_window1 . ' href="' . $mirror1_link_dum . '" class="jd_download_url"><img src="' . JURI::base() . 'images/jdownloads/downloadimages/' . $jlistConfigM['download.pic.mirror_1'] . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MIRROR_URL_TITLE_1') . '" /></a>'; } else { // we use the new css button $mirror1_link = '<a ' . $blank_window1 . ' href="' . $mirror1_link_dum . '" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" class="jdbutton ' . $download_color_mirror1 . ' ' . $download_size_mirror . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_MIRROR_URL_TITLE_1') . '</a>'; } $l_Template = str_replace('{mirror_1}', $mirror1_link, $l_Template); } else { $l_Template = str_replace('{mirror_1}', '', $l_Template); } if ($files->mirror_2) { if ($files->extern_site_mirror_2 && $url_task == 'download.send') { $blank_window2 = 'target="_blank"'; } $mirror2_link_dum = JRoute::_('index.php?option=com_jdownloads&task=download.send&id=' . $files->file_id . '&catid=' . $files->cat_id . '&m=2'); //$mirror2_link_dum = JRoute::_(JDownloadsHelperRoute::getOtherRoute($files->slug, $files->cat_id, $files->language, $url_task, 2)); // is the old button used? if ($jlistConfigM['use.css.buttons.instead.icons'] == '0') { $mirror2_link = '<a ' . $blank_window2 . ' href="' . $mirror2_link_dum . '" class="jd_download_url"><img src="' . JURI::base() . 'images/jdownloads/downloadimages/' . $jlistConfigM['download.pic.mirror_2'] . '" border="0" alt="' . JText::_('COM_JDOWNLOADS_FRONTEND_MIRROR_URL_TITLE_2') . '" /></a>'; } else { // we use the new css button $mirror2_link = '<a ' . $blank_window2 . ' href="' . $mirror2_link_dum . '" alt="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" class="jdbutton ' . $download_color_mirror2 . ' ' . $download_size_mirror . '">' . JText::_('COM_JDOWNLOADS_FRONTEND_MIRROR_URL_TITLE_2') . '</a>'; } $l_Template = str_replace('{mirror_2}', $mirror2_link, $l_Template); } else { $l_Template = str_replace('{mirror_2}', '', $l_Template); } } else { // visitor has not access to download this item - so we will inform him if (strpos($l_Template, '{url_download}')) { $l_Template = str_replace('{url_download}', $first_reg_msg, $l_Template); } else { $l_Template = str_replace('{checkbox_list}', $first_reg_msg, $l_Template); } $l_Template = str_replace('{mirror_1}', '', $l_Template); $l_Template = str_replace('{mirror_2}', '', $l_Template); } if ($jlistConfigM['view.detailsite']) { $title_link = JRoute::_(JDownloadsHelperRoute::getDownloadRoute($files->slug, $files->cat_id, $files->language)); $title_link_text = '<a href="' . $title_link . '">' . $db->escape($files->file_title) . '</a>'; $detail_link_text = '<a href="' . $title_link . '">' . JText::_('COM_JDOWNLOADS_FE_DETAILS_LINK_TEXT_TO_DETAILS') . '</a>'; // Build the file symbol (with link) if ($files->file_pic != '') { $filepic = '<a href="' . $title_link . '">' . '<img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" /></a> '; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); // link to details view at the end $l_Template = str_replace('{link_to_details}', $detail_link_text, $l_Template); $l_Template = str_replace('{file_title}', $title_link_text, $l_Template); } elseif ($jlistConfigM['use.download.title.as.download.link']) { if ($user_can_see_download_url) { // build title link as download link if ($url_task == 'download.send') { $download_link_text = '<a ' . $blank_window . ' href="' . $download_link . '" title="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '" class="jd_download_url">' . $files->file_title . '</a>'; } else { $download_link_text = '<a href="' . $download_link . '" title="' . JText::_('COM_JDOWNLOADS_LINKTEXT_DOWNLOAD_URL') . '">' . $files->file_title . '</a>'; } // View file icon also with link if ($files->file_pic != '') { $filepic = '<a href="' . $download_link . '"><img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" /></a>'; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); $l_Template = str_replace('{link_to_details}', '', $l_Template); $l_Template = str_replace('{file_title}', $download_link_text, $l_Template); } else { // user may not use download link $l_Template = str_replace('{file_title}', $files->file_title, $l_Template); if ($files->file_pic != '') { $filepic = '<img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" />'; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); } } else { // no links if ($files->file_pic != '') { $filepic = '<img src="' . JURI::base() . 'images/jdownloads/fileimages/' . $files->file_pic . '" align="top" width="' . $jlistConfigM['file.pic.size'] . '" height="' . $jlistConfigM['file.pic.size.height'] . '" border="0" alt="" />'; } else { $filepic = ''; } $l_Template = str_replace('{file_pic}', $filepic, $l_Template); // remove link to details view at the end $l_Template = str_replace('{link_to_details}', '', $l_Template); $l_Template = str_replace('{file_title}', $files->file_title, $l_Template); } $l_Template = str_replace('{file_title_only}', $files->file_title, $l_Template); $l_Template = str_replace('{checkbox_list}', '', $l_Template); $l_Template = str_replace('{file_id}', $files->file_id, $l_Template); $l_Template = str_replace('{ordering}', $files->ordering, $l_Template); $l_Template = str_replace('{published}', $files->published, $l_Template); $l_Template = str_replace('{cat_id}', $files->cat_id, $l_Template); $l_Template = str_replace('{rank}', $jDFPrank, $l_Template); $l_Template = str_replace('{mp3_player}', '', $l_Template); $l_Template = str_replace('{mp3_id3_tag}', '', $l_Template); $l_Template = str_replace('{preview_player}', '', $l_Template); $l_Template = str_replace('{report_link}', '', $l_Template); $l_Template = str_replace('{sum_jcomments}', '', $l_Template); $l_Template = str_replace('{rating}', '', $l_Template); // custom fields $custom_fields_arr = existsCustomFieldsTitlesPlg(); $row_custom_values = array('dummy', $files->custom_field_1, $files->custom_field_2, $files->custom_field_3, $files->custom_field_4, $files->custom_field_5, $files->custom_field_6, $files->custom_field_7, $files->custom_field_8, $files->custom_field_9, $files->custom_field_10, $files->custom_field_11, $files->custom_field_12, $files->custom_field_13, $files->custom_field_14); for ($x = 1; $x < 15; $x++) { // replace placeholder with title and value if (in_array($x, $custom_fields_arr[0]) && $row_custom_values[$x] && $row_custom_values[$x] != '0000-00-00') { $l_Template = str_replace("{custom_title_{$x}}", $custom_fields_arr[1][$x - 1], $l_Template); if ($x > 5) { $l_Template = str_replace("{custom_value_{$x}}", stripslashes($row_custom_values[$x]), $l_Template); } else { $l_Template = str_replace("{custom_value_{$x}}", $custom_fields_arr[2][$x - 1][$row_custom_values[$x]], $l_Template); } } else { // remove placeholder if ($jlistConfigM['remove.field.title.when.empty']) { $l_Template = str_replace("{custom_title_{$x}}", '', $l_Template); } else { $l_Template = str_replace("{custom_title_{$x}}", $custom_fields_arr[1][$x - 1], $l_Template); } $l_Template = str_replace("{custom_value_{$x}}", '', $l_Template); } } // insert files title area if (!$jDLayoutTitleExists) { $l_Template = str_replace('{files_title_begin}', '', $l_Template); $l_Template = str_replace('{files_title_end}', '', $l_Template); $l_Template = str_replace('{files_title_text}', JText::_('COM_JDOWNLOADS_FE_FILELIST_TITLE_OVER_FILES_LIST'), $l_Template); $jDLayoutTitleExists = true; } else { if (strpos($l_Template, "{files_title_end}") > 0) { $pos_end = strpos($l_Template, '{files_title_end}'); $pos_beg = strpos($l_Template, '{files_title_begin}'); $l_Template = substr_replace($l_Template, '', $pos_beg, $pos_end - $pos_beg + 17); } } // support for other content plugins // $l_Template = JHTML::_('content.prepare', $l_Template); // remove empty html tags if ($jlistConfigM['remove.empty.tags']) { $l_Template = JDHelper::removeEmptyTags($l_Template); } return str_replace("[[[", "{", $l_Template); }
* 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'); setlocale(LC_ALL, 'C.UTF-8', 'C'); global $jlistConfig; JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); $db = JFactory::getDBO(); $document = JFactory::getDocument(); $jinput = JFactory::getApplication()->input; $app = JFactory::getApplication(); $user = JFactory::getUser(); $jdownloads_root_dir_name = basename($jlistConfig['files.uploaddir']); // get jD user limits and settings $jd_user_settings = JDHelper::getUserRules(); // for Tabs jimport('joomla.html.pane'); // for Tooltip JHtml::_('behavior.tooltip'); $listOrder = str_replace('a.', '', $this->escape($this->state->get('list.ordering'))); $listDirn = $this->escape($this->state->get('list.direction')); // Create shortcuts to some parameters. $params = $this->params; $files = $this->items; $html = ''; $body = ''; $footer_text = ''; $layout = ''; $is_admin = false; $date_format = JDHelper::getDateFormat();
/** * Display the view * @return mixed False on error, null otherwise. */ public function display($tpl = null) { global $jlistConfig; $app = JFactory::getApplication(); $user = JFactory::getUser(); $jd_user_settings = JDHelper::getUserRules(); // Initialise variables $state = $this->get('State'); $items = $this->get('Items'); $pagination = $this->get('Pagination'); // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } $this->ipad_user = false; // check whether we have an ipad/iphone user for flowplayer aso... if ((bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') || (bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { $this->ipad_user = true; } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } if ($items === false) { return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); if ($jlistConfig['view.ratings']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/rating/js/ajaxvote.js'); } // loadscript for flowplayer if ($jlistConfig['flowplayer.use']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer-3.2.12.min.js'); // load also the ipad plugin when required if ($this->ipad_user) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer.ipad-3.2.12.min.js'); } } if ($jlistConfig['use.lightbox.function']) { JHtml::_('bootstrap.framework'); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/lightbox/lightbox.js'); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/lightbox/lightbox.css", 'text/css', null, array()); } $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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(); }'); if ($jlistConfig['use.css.buttons.instead.icons']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); } $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); if ($jlistConfig['view.ratings']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); } $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $this->jd_image_path = JPATH_ROOT . '/images/jdownloads'; $params =& $state->params; // Compute the download slugs and prepare text (runs content plugins). for ($i = 0, $n = count($items); $i < $n; $i++) { $item =& $items[$i]; $item->tags = new JHelperTags(); $item->tags->getItemTags('com_jdownloads.download', $item->file_id); $item->slug = $item->file_alias ? $item->file_id . ':' . $item->file_alias : $item->file_id; // No link for ROOT category if ($item->parent_alias == 'root') { $item->parent_slug = null; } // required for some content plugins $item->text = $item->description; $item->id = $item->file_id; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentPrepare', array('com_jdownloads.downloads', &$item, &$this->params, 0)); $item->event = new stdClass(); $results = $dispatcher->trigger('onContentAfterTitle', array('com_jdownloads.downloads', &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_jdownloads.downloads', &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_jdownloads.downloads', &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); // we use a little trick to get always the changes from content plugins if ($item->text != $item->description) { $item->description = $item->text; } } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->maxLevelcat = $params->get('maxLevelcat', -1); $this->assignRef('state', $state); $this->assignRef('params', $params); $this->assignRef('items', $items); $this->assignRef('pagination', $pagination); $this->_prepareDocument(); parent::display($tpl); }
public function display($tpl = null) { //Load pane behavior in joomla 3 jimport('joomla.html.html.tabs'); // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $document->addStyleSheet('components/com_jdownloads/assets/css/jdownloads_fe.css'); $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); $document->addScriptDeclaration(' // dynamically add a new image file upload field when the prior generated fields is used function add_new_image_file(field) { // Get the number of files previously uploaded. var count = parseInt(document.getElementById(\'image_file_count\').value); var sum = parseInt(document.getElementById(\'sum_listed_images\').value); var max = parseInt(document.getElementById(\'max_sum_images\').value); // Get the name of the file that has just been uploaded. var file_name = document.getElementById("file_upload_thumb["+count+"]").value; // Hide the file upload control containing the information about the picture that was just uploaded. document.getElementById(\'new_file_row\').style.display = "none"; document.getElementById(\'new_file_row\').id = "new_file_row["+count+"]"; // Get a reference to the table containing the uploaded pictures. var table = document.getElementById(\'files_table\'); // Insert a new row with the file name and a delete button. var row = table.insertRow(table.rows.length); row.id = "inserted_file["+count+"]"; var cell0 = row.insertCell(0); cell0.innerHTML = \'<input type="text" disabled="disabled" name="inserted_file[\'+count+\']" value="\'+file_name+\'" size="40" /><input type="button" name="delete[\'+count+\']" value="' . JTEXT::_('COM_JDOWNLOADS_REMOVE') . '" onclick="delete_inserted_image_field(this)">\'; // Increment count of the number of files uploaded. ++count; if (count+sum < max){ // Insert a new file upload control in the table. var row = table.insertRow(table.rows.length); row.id = "new_file_row"; var cell0 = row.insertCell(0); cell0.innerHTML = \'<input type="file" name="file_upload_thumb[\'+count+\']" id="file_upload_thumb[\'+count+\']" size="40" accept="image/gif,image/jpeg,image/jpg,image/png" onchange="add_new_image_file(this)" />\'; } // Update the value of the file hidden input tag holding the count of files uploaded. document.getElementById(\'image_file_count\').value = count; } // user will remove the files they have previously added function delete_inserted_image_field(field) { // Get the field name. var name = field.name; // Extract the file id from the field name. var id = name.substr(name.indexOf(\'[\') + 1, name.indexOf(\']\') - name.indexOf(\'[\') - 1); // Hide the row displaying the uploaded file name. document.getElementById("inserted_file["+id+"]").style.display = "none"; // Get a reference to the uploaded file control. var control = document.getElementById("file_upload_thumb["+id+"]"); // Remove the new file control. control.parentNode.removeChild(control); // check that we have always a input field when we remove a other file var found = false; for (var i = 0; i <= 30; i++){ if (document.adminForm.elements["file_upload_thumb["+i+"]"]) { found = true; } } if (!found) add_new_image_file(field); }'); // Get model data. $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); // we must get all 'allowed' category IDs $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); $user_rules = JDHelper::getUserRules(); $user_limits = JDHelper::getUserLimits($user_rules, 0); // Here is the place to change field attributes - defined in user groups limits if (!$user_rules->uploads_use_editor) { $this->form->setFieldAttribute('description', 'type', 'textarea'); $this->form->setFieldAttribute('description', 'rows', '4'); $this->form->setFieldAttribute('description', 'cols', '60'); $this->form->setFieldAttribute('description_long', 'type', 'textarea'); $this->form->setFieldAttribute('description_long', 'rows', '6'); $this->form->setFieldAttribute('description_long', 'cols', '60'); $this->form->setFieldAttribute('changelog', 'type', 'textarea'); $this->form->setFieldAttribute('changelog', 'rows', '4'); $this->form->setFieldAttribute('changelog', 'cols', '60'); $this->form->setFieldAttribute('custom_field_13', 'type', 'textarea'); $this->form->setFieldAttribute('custom_field_13', 'rows', '4'); $this->form->setFieldAttribute('custom_field_13', 'cols', '60'); $this->form->setFieldAttribute('custom_field_14', 'type', 'textarea'); $this->form->setFieldAttribute('custom_field_14', 'rows', '4'); $this->form->setFieldAttribute('custom_field_14', 'cols', '60'); } // activate the 'required' state if ($user_rules->form_alias && $user_rules->form_alias_x) { $this->form->setFieldAttribute('file_alias', 'required', 'true'); } if ($user_rules->form_author_mail && $user_rules->form_author_mail_x) { $this->form->setFieldAttribute('url_author', 'required', 'true'); } if ($user_rules->form_author_name && $user_rules->form_author_name_x) { $this->form->setFieldAttribute('author', 'required', 'true'); } if ($user_rules->form_website && $user_rules->form_website_x) { $this->form->setFieldAttribute('url_home', 'required', 'true'); } if ($user_rules->form_changelog && $user_rules->form_changelog_x) { $this->form->setFieldAttribute('changelog', 'required', 'true'); } if ($user_rules->form_creation_date && $user_rules->form_creation_date_x) { $this->form->setFieldAttribute('date_added', 'required', 'true'); } if ($user_rules->form_external_file && $user_rules->form_external_file_x) { $this->form->setFieldAttribute('extern_file', 'required', 'true'); } if ($user_rules->form_license && $user_rules->form_license_x) { $this->form->setFieldAttribute('license', 'required', 'true'); } if ($user_rules->form_version && $user_rules->form_version_x) { $this->form->setFieldAttribute('release', 'required', 'true'); } if ($user_rules->form_file_date && $user_rules->form_file_date_x) { $this->form->setFieldAttribute('file_date', 'required', 'true'); } if ($user_rules->form_file_language && $user_rules->form_file_language_x) { $this->form->setFieldAttribute('file_language', 'required', 'true'); } if ($user_rules->form_file_pic && $user_rules->form_file_pic_x) { $this->form->setFieldAttribute('file_pic', 'required', 'true'); } if ($user_rules->form_file_system && $user_rules->form_file_system_x) { $this->form->setFieldAttribute('system', 'required', 'true'); } if ($user_rules->form_images && $user_rules->form_images_x) { $this->form->setFieldAttribute('images', 'required', 'true'); } if ($user_rules->form_language && $user_rules->form_language_x) { $this->form->setFieldAttribute('language', 'required', 'true'); } if ($user_rules->form_mirror_1 && $user_rules->form_mirror_1_x) { $this->form->setFieldAttribute('mirror_1', 'required', 'true'); } if ($user_rules->form_mirror_2 && $user_rules->form_mirror_2_x) { $this->form->setFieldAttribute('mirror_2', 'required', 'true'); } if ($user_rules->form_password && $user_rules->form_password_x) { $this->form->setFieldAttribute('password', 'required', 'true'); } if ($user_rules->form_price && $user_rules->form_price_x) { $this->form->setFieldAttribute('price', 'required', 'true'); } if ($user_rules->form_short_desc && $user_rules->form_short_desc_x) { $this->form->setFieldAttribute('description', 'required', 'true'); } if ($user_rules->form_long_desc && $user_rules->form_long_desc_x) { $this->form->setFieldAttribute('description_long', 'required', 'true'); } if ($user_rules->form_extra_select_box_1 && $user_rules->form_extra_select_box_1_x) { $this->form->setFieldAttribute('custom_field_1', 'required', 'true'); } if ($user_rules->form_extra_select_box_2 && $user_rules->form_extra_select_box_2_x) { $this->form->setFieldAttribute('custom_field_2', 'required', 'true'); } if ($user_rules->form_extra_select_box_3 && $user_rules->form_extra_select_box_3_x) { $this->form->setFieldAttribute('custom_field_3', 'required', 'true'); } if ($user_rules->form_extra_select_box_4 && $user_rules->form_extra_select_box_4_x) { $this->form->setFieldAttribute('custom_field_4', 'required', 'true'); } if ($user_rules->form_extra_select_box_5 && $user_rules->form_extra_select_box_5_x) { $this->form->setFieldAttribute('custom_field_5', 'required', 'true'); } if ($user_rules->form_extra_short_input_1 && $user_rules->form_extra_short_input_1_x) { $this->form->setFieldAttribute('custom_field_6', 'required', 'true'); } if ($user_rules->form_extra_short_input_2 && $user_rules->form_extra_short_input_2_x) { $this->form->setFieldAttribute('custom_field_7', 'required', 'true'); } if ($user_rules->form_extra_short_input_3 && $user_rules->form_extra_short_input_3_x) { $this->form->setFieldAttribute('custom_field_8', 'required', 'true'); } if ($user_rules->form_extra_short_input_4 && $user_rules->form_extra_short_input_4_x) { $this->form->setFieldAttribute('custom_field_9', 'required', 'true'); } if ($user_rules->form_extra_short_input_5 && $user_rules->form_extra_short_input_5_x) { $this->form->setFieldAttribute('custom_field_10', 'required', 'true'); } if ($user_rules->form_extra_date_1 && $user_rules->form_extra_date_1_x) { $this->form->setFieldAttribute('custom_field_11', 'required', 'true'); } if ($user_rules->form_extra_date_2 && $user_rules->form_extra_date_2_x) { $this->form->setFieldAttribute('custom_field_12', 'required', 'true'); } if ($user_rules->form_extra_large_input_1 && $user_rules->form_extra_large_input_1_x) { $this->form->setFieldAttribute('custom_field_13', 'required', 'true'); } if ($user_rules->form_extra_large_input_2 && $user_rules->form_extra_large_input_2_x) { $this->form->setFieldAttribute('custom_field_14', 'required', 'true'); } // check the possibility to create new custom tags if (!$user_rules->uploads_allow_custom_tags) { $this->form->setFieldAttribute('tags', 'custom', 'deny'); //$this->form->setFieldAttribute( 'tags', 'mode', 'nested' ); } if (!$this->item->file_id) { // new Download // set default value for access in form when exist - use otherwise 1 for public access if ($user_rules->uploads_default_access_level) { $this->form->setValue('access', null, (int) $user_rules->uploads_default_access_level); } // Use this options only for 'creation' page (...why?) if ($user_rules->form_select_main_file && $user_rules->form_select_main_file_x) { $this->form->setFieldAttribute('file_upload', 'required', 'true'); } if ($user_rules->form_select_preview_file && $user_rules->form_select_preview_file_x) { $this->form->setFieldAttribute('preview_file_upload', 'required', 'true'); } } // user will edit a exist download so we must check the category rule if ($this->item->file_id && !$user_rules->uploads_can_change_category) { // change category field to readonly $this->form->setFieldAttribute('cat_id', 'readonly', 'true'); } $this->return_page = $this->get('ReturnPage'); if (!$this->return_page) { // seems we will create a new download about 'Add' button, so we will use the current url for return page $current_url = $_SERVER['HTTP_REFERER']; if ($current_url) { $this->return_page = base64_encode(urlencode($current_url)); } else { $this->return_page = base64_encode(urlencode(JURI::current())); } } if (empty($this->item->file_id)) { $authorised = $user->authorise('core.create', 'com_jdownloads') || count($this->authorised_cats); } else { $authorised = $this->item->params->get('access-edit'); } if ($authorised !== true) { if (empty($this->item->file_id)) { JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_FRONTEND_CREATE_NO_PERMISSIONS')); } else { JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_FRONTEND_EDIT_NO_PERMISSIONS')); } return false; } else { $this->view_upload_button = true; } if (isset($user_limits['upload']->sumfiles) && $user_limits['upload']->sumfiles > 0) { $upload_limits_reached = $user_limits['upload_remaining'] == 0; } else { $upload_limits_reached = false; } if ($upload_limits_reached == true) { $text = JDHelper::getOnlyLanguageSubstring($user_rules->upload_limit_daily_msg); if ($text != '') { JError::raiseNotice(100, $text); } else { JError::raiseNotice(100, JText::_('COM_JDOWNLOADS_DAILY_UPLOAD_LIMITS_REACHED_TEXT')); } return false; } $this->user_rules = $user_rules; $this->user_limits = $user_limits; $this->item->tags = new JHelperTags(); if (!empty($this->item->file_id)) { $this->item->tags->getItemTags('com_jdownloads.download.', $this->item->file_id); } if (!empty($this->item) && isset($this->item->file_id)) { $tmp = new stdClass(); $tmp->images = $this->item->images; $this->form->bind($tmp); } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // Create a shortcut to the parameters. $params =& $this->state->params; //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->params = $params; $this->user = $user; // check whether it is in menu settings defined only a single category if ($params->get('enable_category') == 1) { $this->form->setFieldAttribute('cat_id', 'default', $params->get('catid', 1)); $this->form->setFieldAttribute('cat_id', 'readonly', 'true'); } $this->_prepareDocument(); parent::display($tpl); }
/** * Get the search result * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if the search it to be restricted to areas, null if search all */ function getSearchResults($text, $phrase = '', $ordering = '', $areas = null) { global $jlistConfig; $db = JFactory::getDbo(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $tag = JFactory::getLanguage()->getTag(); require_once JPATH_SITE . '/components/com_jdownloads/helpers/route.php'; require_once JPATH_SITE . '/components/com_jdownloads/helpers/search.php'; require_once JPATH_SITE . '/components/com_jdownloads/helpers/jdownloadshelper.php'; $user_rules = JDHelper::getUserRules(); $searchText = $text; $limit = $this->state->get('search_limit', 500); $nullDate = $db->getNullDate(); $date = JFactory::getDate(); $now = $date->toSql(); $text = trim($text); if ($text == '') { return array(); } $wheres = array(); switch ($phrase) { case 'exact': $text = $db->Quote('%' . $db->escape($text, true) . '%', false); $wheres2 = array(); if (!$areas || in_array('title', $areas)) { $wheres2[] = 'a.file_title LIKE ' . $text; } if (!$areas || in_array('description', $areas)) { $wheres2[] = 'a.description LIKE ' . $text; $wheres2[] = 'a.description_long LIKE ' . $text; } if (!$areas || in_array('changelog', $areas)) { $wheres2[] = 'a.changelog LIKE ' . $text; } if ($jlistConfig['custom.field.6.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_6 LIKE ' . $text; } } if ($jlistConfig['custom.field.7.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_7 LIKE ' . $text; } } if ($jlistConfig['custom.field.8.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_8 LIKE ' . $text; } } if ($jlistConfig['custom.field.9.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_9 LIKE ' . $text; } } if ($jlistConfig['custom.field.10.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_10 LIKE ' . $text; } } if ($jlistConfig['custom.field.13.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_13 LIKE ' . $text; } } if ($jlistConfig['custom.field.14.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_14 LIKE ' . $text; } } if (!$areas || in_array('author', $areas)) { $wheres2[] = 'a.author LIKE ' . $text; } if (!$areas || in_array('metatags', $areas)) { $wheres2[] = 'a.metakey LIKE ' . $text; $wheres2[] = 'a.metadesc LIKE ' . $text; } $where = '(' . implode(') OR (', $wheres2) . ')'; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $word = $db->Quote('%' . $db->escape($word, true) . '%', false); $wheres2 = array(); if (!$areas || in_array('title', $areas)) { $wheres2[] = 'a.file_title LIKE ' . $word; } if (!$areas || in_array('description', $areas)) { $wheres2[] = 'a.description LIKE ' . $word; $wheres2[] = 'a.description_long LIKE ' . $word; } if (!$areas || in_array('changelog', $areas)) { $wheres2[] = 'a.changelog LIKE ' . $word; } if ($jlistConfig['custom.field.6.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_6 LIKE ' . $word; } } if ($jlistConfig['custom.field.7.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_7 LIKE ' . $word; } } if ($jlistConfig['custom.field.8.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_8 LIKE ' . $word; } } if ($jlistConfig['custom.field.9.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_9 LIKE ' . $word; } } if ($jlistConfig['custom.field.10.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_10 LIKE ' . $word; } } if ($jlistConfig['custom.field.13.title'] != '') { if (!$areas || in_array('customtext1', $areas)) { $wheres2[] = 'a.custom_field_13 LIKE ' . $word; } } if ($jlistConfig['custom.field.14.title'] != '') { if (!$areas || in_array('customtext2', $areas)) { $wheres2[] = 'a.custom_field_14 LIKE ' . $word; } } if (!$areas || in_array('author', $areas)) { $wheres2[] = 'a.author LIKE ' . $word; } if (!$areas || in_array('metatags', $areas)) { $wheres2[] = 'a.metakey LIKE ' . $word; $wheres2[] = 'a.metadesc LIKE ' . $word; } $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } $morder = ''; switch ($ordering) { case 'oldest': $order = 'a.date_added ASC'; break; case 'popular': $order = 'a.downloads DESC'; break; case 'alpha': $order = 'a.file_title ASC'; break; case 'category': $order = 'c.title ASC, a.file_title ASC'; $morder = 'a.file_title ASC'; break; case 'newest': default: $order = 'a.date_added DESC'; break; } $uncategorised = JText::_('COM_JDOWNLOADS_SELECT_UNCATEGORISED'); $rows = array(); $query = $db->getQuery(true); // search downloads if ($limit > 0) { $query->clear(); //sqlsrv changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.file_alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.file_id'); $case_when .= $query->concatenate(array($a_id, 'a.file_alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id . ' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id . ' END as catslug'; $query->select('a.file_title AS title, a.metadesc, a.metakey, a.url_download, a.extern_file, a.other_file_id, a.license_agree, a.password, a.author, a.date_added AS created, a.language, a.custom_field_6, a.custom_field_7, a.custom_field_8, a.custom_field_9, a.custom_field_10'); $query->select($query->concatenate(array('a.description', 'a.description_long', 'a.changelog', 'a.custom_field_13', 'a.custom_field_14')) . ' AS text'); $query->select('CASE c.title WHEN \'root\' THEN ' . $db->Quote($uncategorised) . ' ELSE c.title END AS section, ' . $case_when . ',' . $case_when1 . ', ' . '\'2\' AS browsernav'); $query->from('#__jdownloads_files AS a'); $query->innerJoin('#__jdownloads_categories AS c ON c.id = a.cat_id'); $query->where('(' . $where . ')' . 'AND a.published = 1 AND c.published = 1 AND a.access IN (' . $groups . ') ' . 'AND c.access IN (' . $groups . ') ' . 'AND (a.publish_from = ' . $db->Quote($nullDate) . ' OR a.publish_from <= ' . $db->Quote($now) . ') ' . 'AND (a.publish_to = ' . $db->Quote($nullDate) . ' OR a.publish_to >= ' . $db->Quote($now) . ')'); $query->group('a.file_id, a.file_title, a.metadesc, a.metakey, a.author, a.date_added, a.description, a.description_long, a.changelog, a.custom_field_6, a.custom_field_7, a.custom_field_8, a.custom_field_9, a.custom_field_10, a.custom_field_13, a.custom_field_14, c.title, a.file_alias, c.alias, c.id'); $query->order($order); // Filter by language if ($app->isSite() && $app->getLanguageFilter()) { $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); } $db->setQuery($query, 0, $limit); $list = $db->loadObjectList(); $limit -= count($list); if (isset($list)) { foreach ($list as $key => $item) { $direct_download = $jlistConfig['direct.download']; if (!$item->url_download && !$item->extern_file && !$item->other_file_id || $item->password || $item->license_agree || $user_rules->view_captcha) { // this download is a simple document without a file so we can not use 'direct' download option // or we need the summary page for password, captcha or license agree $direct_download = 0; } if ($jlistConfig['view.detailsite']) { // we must link to the details page $list[$key]->href = JDownloadsHelperRoute::getDownloadRoute($item->slug, $item->catslug, $item->language); } else { if ($direct_download) { // we must start the download process directly $list[$key]->href = JRoute::_('index.php?option=com_jdownloads&task=download.send&id=' . (int) $item->slug . '&catid=' . (int) $item->catslug . '&m=0'); } else { if (!$item->url_download && !$item->extern_file && !$item->other_file_id) { // Download is only a simple document without a file so we must link to the details page $list[$key]->href = JDownloadsHelperRoute::getDownloadRoute($item->slug, $item->catslug, $item->language); } else { // we must link to the summary page $list[$key]->href = JRoute::_('index.php?option=com_jdownloads&view=summary&id=' . $item->slug . '&catid=' . (int) $item->catslug); } } } } } $rows[] = $list; } $results = array(); if (count($rows)) { foreach ($rows as $row) { $new_row = array(); foreach ($row as $key => $download) { if (JDSearchHelper::checkNoHTML($download, $searchText, array('text', 'title', 'author', 'metadesc', 'metakey', 'custom_field_6', 'custom_field_7', 'custom_field_8', 'custom_field_9', 'custom_field_10'))) { $new_row[] = $download; } } $results = array_merge($results, (array) $new_row); } } return $results; }
/** * Display the view * * @return mixed False on error, null otherwise. */ function display($tpl = null) { global $jlistConfig; $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = $this->getModel(); $jd_user_settings = JDHelper::getUserRules(); // Get some data from the models $state = $this->get('State'); $params = $state->params; $items = $this->get('Items'); jimport('joomla.html.pagination'); $pagination = new JPagination($model->getTotal(), $model->getState('list.start'), $model->getState('list.limit')); $parent = $this->get('Parent'); // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } if ($items == false) { // return JError::raiseError(404, JText::_('COM_JDOWNLOADS_CATEGORY_NOT_FOUND')); } if ($parent == false) { JError::raiseError(404, JText::_('COM_JDOWNLOADS_CATEGORY_PARENT_NOT_FOUND')); return false; } // Get the tags foreach ($items as $item) { $item->tags = new JHelperTags(); $item->tags->getItemTags('com_jdownloads.category', $item->id); } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); if ($jlistConfig['view.ratings']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/rating/js/ajaxvote.js'); } if ($jlistConfig['use.lightbox.function']) { JHtml::_('bootstrap.framework'); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/lightbox/lightbox.js'); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/lightbox/lightbox.css", 'text/css', null, array()); } $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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(); }'); if ($jlistConfig['use.css.buttons.instead.icons']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); } $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); if ($jlistConfig['view.ratings']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); } $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $this->jd_image_path = JPATH_ROOT . '/images/jdownloads'; // $items = array($parent->id => $items); //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->maxLevelcat = $params->get('maxLevelcat', -1); $this->assignRef('state', $state); $this->assignRef('params', $params); $this->assignRef('parent', $parent); $this->assignRef('items', $items); $this->assignRef('pagination', $pagination); $this->_prepareDocument(); parent::display($tpl); }
function display($tpl = null) { global $jlistConfig; $app = JFactory::getApplication(); $user = JFactory::getUser(); $jd_user_settings = JDHelper::getUserRules(); // Get some data from the models $state = $this->get('State'); $params = $state->params; $items = $this->get('Items'); // get the category downloads $category = $this->get('Category'); // get the selected category data $children = $this->get('Children'); // get the categories sub categories $parent = $this->get('Parent'); // get the categories parent categories $pagination = $this->get('Pagination'); // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } $this->ipad_user = false; // check whether we have an ipad/iphone user for flowplayer aso... if ((bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') || (bool) strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')) { $this->ipad_user = true; } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/rating/js/ajaxvote.js'); // loadscript for flowplayer if ($jlistConfig['flowplayer.use']) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer-3.2.12.min.js'); // load also the ipad plugin when required if ($this->ipad_user) { $document->addScript(JURI::base() . 'components/com_jdownloads/assets/flowplayer/flowplayer.ipad-3.2.12.min.js'); } } $document->addScriptDeclaration('live_site = "' . JURI::base() . '";'); $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(); }'); if ($jlistConfig['use.lightbox.function']) { JHtml::_('bootstrap.framework'); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/lightbox/lightbox.js'); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/lightbox/lightbox.css", 'text/css', null, array()); } // required only for subcategories pagination $document->addScript(JURI::base() . 'components/com_jdownloads/assets/pagination/jdpagination.js'); if ($jlistConfig['use.css.buttons.instead.icons']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); } $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $this->jd_image_path = JPATH_ROOT . '/images/jdownloads'; if ($category == false) { return JError::raiseError(404, JText::_('COM_JDOWNLOADS_CATEGORY_NOT_FOUND')); } if ($parent == false) { return JError::raiseError(404, JText::_('COM_JDOWNLOADS_CATEGORY_PARENT_NOT_FOUND')); } // Setup the category parameters. $cparams = $category->getParams(); $category->params = clone $params; $category->params->merge($cparams); $category->tags = new JHelperTags(); $category->tags->getItemTags('com_jdownloads.category', $category->id); // Check whether category access level allows access. $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if (!in_array($category->access, $groups)) { return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); } // Compute the download slugs and prepare introtext (runs content plugins). for ($i = 0, $n = count($items); $i < $n; $i++) { $item =& $items[$i]; $item->slug = $item->file_alias ? $item->file_id . ':' . $item->file_alias : $item->file_id; // No link for ROOT category if ($item->parent_alias == 'root') { $item->parent_slug = null; } // required for some content plugins $item->text = $item->description; $item->id = $item->file_id; $item->event = new stdClass(); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $results = $dispatcher->trigger('onContentPrepare', array('com_jdownloads.category', &$item, &$this->params, 0)); $results = $dispatcher->trigger('onContentAfterTitle', array('com_jdownloads.category', &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_jdownloads.category', &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_jdownloads.category', &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); // check the result from content plugins if ($item->text != $item->description) { $item->description = $item->text; } } // Check for layout override only if this is not the active menu item // If it is the active menu item, then the view and category id will match $active = $app->getMenu()->getActive(); if (!$active || (strpos($active->link, 'view=category') === false || strpos($active->link, '&catid=' . (string) $category->id) === false)) { // Get the layout from the merged category params if ($layout = $category->params->get('category_layout')) { $this->setLayout($layout); } } elseif (isset($active->query['layout'])) { // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout) $this->setLayout($active->query['layout']); } $children = array($category->id => $children); //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->maxLevel = $params->get('maxLevel', -1); $this->assignRef('state', $state); $this->assignRef('items', $items); $this->assignRef('category', $category); $this->assignRef('children', $children); $this->assignRef('params', $params); $this->assignRef('parent', $parent); $this->assignRef('pagination', $pagination); $this->assignRef('user', $user); $this->_prepareDocument(); parent::display($tpl); }
function display($tpl = null) { global $jlistConfig; // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); $userId = $user->get('id'); $jd_user_settings = JDHelper::getUserRules(); // get jD User group settings and limitations $this->user_rules = JDHelper::getUserRules(); $dispatcher = JDispatcher::getInstance(); $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->user = $user; // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); if ($jlistConfig['view.ratings']) { $document->addScript(JUri::base() . 'components/com_jdownloads/assets/rating/js/ajaxvote.js'); } $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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(); }'); if ($jlistConfig['use.css.buttons.instead.icons']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); } $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); if ($jlistConfig['view.ratings']) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); } $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $this->jd_image_path = JPATH_ROOT . '/images/jdownloads'; // Create a shortcut for $item. $items =& $this->items; foreach ($items as $item) { // Add router helpers. $item->slug = $item->file_alias ? $item->file_id . ':' . $item->file_alias : $item->file_id; $item->catslug = $item->category_alias ? $item->cat_id . ':' . $item->category_alias : $item->cat_id; $item->parent_slug = $item->category_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // Merge article params. If this is single-article view, menu params override article params // Otherwise, article params override menu item params $this->params = $this->state->get('params'); $active = $app->getMenu()->getActive(); $temp = clone $this->params; // Check to see which parameters should take priority if ($active) { $currentLink = $active->link; // If the current view is the active item and an download view for this download, then the menu item params take priority if (strpos($currentLink, 'view=download') && strpos($currentLink, '&id=' . (string) $item->file_id)) { // $item->params are the downloads params, $temp are the menu item params // Merge so that the menu item params take priority $item->params->merge($temp); // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } } else { // Current view is not a single article, so the article params take priority here // Merge the menu item params with the article params so that the article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article if ($layout = $item->params->get('download_layout')) { $this->setLayout($layout); } } } else { // Merge so that article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-download menu item) // Single-download menu item layout takes priority over alt layout for an download if ($layout = $item->params->get('download_layout')) { $this->setLayout($layout); } } // Check the view access to the download (the model has already computed the values). if ($item->params->get('access-view') != true && ($item->params->get('show_noauth') != true && $user->get('guest'))) { JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return; } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($item->params->get('pageclass_sfx')); } // Process the content plugins. JPluginHelper::importPlugin('content'); // $results = $dispatcher->trigger('onContentPrepare', array ('com_jdownloads.download', &$item, &$this->params, $offset)); $this->event = new stdClass(); //$item->event = new stdClass(); $results = $dispatcher->trigger('onContentAfterTitle', array('com_jdownloads.download', &$item, &$this->params, 0)); $this->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_jdownloads.download', &$item, &$this->params, 0)); $this->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_jdownloads.download', &$item, &$this->params, 0)); $this->event->afterDisplayContent = trim(implode("\n", $results)); $this->_prepareDocument(); parent::display($tpl); }
/** * Method to submit the downloads file to the browser. * * * @return null */ public function send() { global $jlistConfig; jimport('joomla.environment.uri'); $jinput = JFactory::getApplication()->input; $app = JFactory::getApplication(); $params = $app->getParams(); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $db = JFactory::getDBO(); $config = array('ignore_request' => true); $model = $this->getModel('send', 'jdownloadsModel', $config); $user_rules = JDHelper::getUserRules(); clearstatcache(); $active = $app->getMenu()->getActive(); if ($active) { $current_link = $active->link; } else { $current_link = JRoute::_(JUri::current() . '?option=com_jdownloads'); } // abort when downloads are offline if ($jlistConfig['offline']) { $msg = JDHelper::getOnlyLanguageSubstring($jlistConfig['offline.text']); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } $allow = false; $extern = false; $extern_site = false; $can_download = false; $aup_exist = false; $profile = ''; // Which file types shall be viewed in browser $view_types = array(); $view_types = explode(',', $jlistConfig['file.types.view']); // get request data $cat_id = $db->escape($jinput->get('catid', 0, 'int')); $file_id = $db->escape($jinput->get('id', 0, 'int')); $mirror = $db->escape($jinput->get('m', 0, 'int')); $files_list = $db->escape($jinput->get('list', '', 'string')); $zip_file = $db->escape($jinput->get('user', 0, 'cmd')); // get session data $stored_random_id = (int) JDHelper::getSessionDecoded('jd_random_id'); $stored_file_id = (int) JDHelper::getSessionDecoded('jd_fileid'); $stored_cat_id = (int) JDHelper::getSessionDecoded('jd_catid'); $stored_files_list = JDHelper::getSessionDecoded('jd_list'); // compare and check it if ($cat_id > 0 && $cat_id != $stored_cat_id || $file_id > 0 && $file_id != $stored_file_id || $zip_file > 0 && $zip_file != $stored_random_id || $files_list != '' && $files_list != $stored_files_list) { // perhaps use it a direct download option $this->items = $model->getItems($file_id); if ($this->items) { $this->state = $model->getState(); $sum_selected_files = $this->state->get('sum_selected_files'); $sum_selected_volume = $this->state->get('sum_selected_volume'); $sum_files_prices = $this->state->get('sum_files_prices'); $must_confirm_license = $this->state->get('must_confirm_license'); $directlink = $this->state->get('directlink_used'); $marked_files_id = $this->state->get('download.marked_files.id'); // check the permission access for direct download option $within_the_user_limits = JDHelper::checkDirectDownloadLimits($cat_id, $file_id, $files_list, $user_rules, $sum_selected_files, $sum_selected_volume); if ($within_the_user_limits !== true) { // user has his limits reached or not enough points $msg = JText::_($within_the_user_limits); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } } else { // invalid data found / url manipulations? $msg = JText::_('COM_JDOWNLOADS_INVALID_DOWNLOAD_DATA_MSG'); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } } // check leeching if ($is_leeching = JDHelper::useAntiLeeching()) { // download stopped - view hint $msg = JText::_('COM_JDOWNLOADS_ANTILEECH_MSG') . ' ' . JText::_('COM_JDOWNLOADS_ANTILEECH_MSG2'); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } if ($zip_file) { // user has selected more as a single file $zip_file = $jlistConfig['zipfile.prefix'] . $zip_file . '.zip'; $filename = $jlistConfig['files.uploaddir'] . '/' . $jlistConfig['tempzipfiles.folder.name'] . '/' . $zip_file; if (!file_exists($filename)) { // download stopped - zip file not found $msg = JText::_('COM_JDOWNLOADS_FILE_NOT_FOUND') . ': ' . basename($zip_file); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } } // download action check (not for uncategorized) if ($cat_id > 1) { // If the category has been passed in the data or URL check it. $allow = $user->authorise('download', 'com_jdownloads.category.' . $cat_id); if ($file_id && $allow) { // If the category has been passed in the data or URL check it. $allow = $user->authorise('download', 'com_jdownloads.download.' . $file_id); } } else { if ($file_id) { // If the category has been passed in the data or URL check it. $allow = $user->authorise('download', 'com_jdownloads.download.' . $file_id); } } if (!$allow) { // download stopped - user has not the right to download it $msg = JText::_('COM_JDOWNLOADS_DOWNLOAD_NOT_ALLOWED_MSG'); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } $transfer_speed = (int) $user_rules->transfer_speed_limit_kb; if ($jlistConfig['use.alphauserpoints']) { // get AUP user info $api_AUP = JPATH_SITE . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'helper.php'; if (file_exists($api_AUP) && !$user->guest) { require_once $api_AUP; $aup_exist = true; // get user profile data from AUP $profile = AlphaUserPointsHelper::getUserInfo('', $user->id); // get standard points value from AUP $db->setQuery("SELECT points FROM #__alpha_userpoints_rules WHERE published = 1 AND plugin_function = 'plgaup_jdownloads_user_download'"); $aup_fix_points = floatval($db->loadResult()); //$aup_fix_points = JDHelper::strToNumber($aup_fix_points); } } // build a array with IDs $files_arr = explode(',', $files_list); // get the files data for multi or single download $query = $db->getQuery(true); $query->select('a.*'); $query->from('#__jdownloads_files AS a'); // Join on category table. $query->select('c.title AS category_title, c.id AS category_id, c.cat_dir AS category_cat_dir, c.cat_dir_parent AS category_cat_dir_parent'); $query->join('LEFT', '#__jdownloads_categories AS c on c.id = a.cat_id'); // Join on license table. $query->select('l.title AS license_title'); $query->join('LEFT', '#__jdownloads_licenses AS l on l.id = a.license'); $query->where('(a.published = ' . $db->Quote('1') . ')'); if ($files_list) { $query->where('a.file_id IN (' . $files_list . ')'); } else { $query->where('a.file_id = ' . $db->Quote($file_id)); } // Filter by access level so when we get not a result this user has not the access to view it $query->where('a.access IN (' . $groups . ')'); $query->where('c.access IN (' . $groups . ')'); $db->setQuery($query); $files = $db->loadObjectList(); if (!$files) { // invalid data or user has not really the access $msg = JText::_('COM_JDOWNLOADS_DATA_NOT_FOUND'); $app->redirect(JRoute::_($current_link), $msg, 'error'); } // When we have a regged user, we must check whether he downloads the file in parts. // If so, we may only once write the download data in log and compute the AUP etc. $download_in_parts = JDHelper::getLastDownloadActivity($user->id, $files_list, $file_id, $user_rules->download_limit_after_this_time); if (count($files) > 1) { // mass download if (!$download_in_parts) { // add AUP points if ($jlistConfig['use.alphauserpoints'] && $aup_exist) { if ($jlistConfig['use.alphauserpoints.with.price.field']) { $db->setQuery("SELECT SUM(price) FROM #__jdownloads_files WHERE file_id IN ({$files_list})"); $sum_points = (int) $db->loadResult(); if ($profile->points >= $sum_points) { foreach ($files as $aup_data) { $db->setQuery("SELECT price FROM #__jdownloads_files WHERE file_id = '{$aup_data->file_id}'"); if ($price = floatval($db->loadResult())) { $can_download = JDHelper::setAUPPointsDownloads($user->id, $aup_data->file_title, $aup_data->file_id, $price, $profile); } } } } else { // use fix points $sum_points = $aup_fix_points * count($files_arr); if ($profile->points >= $sum_points) { foreach ($files as $aup_data) { $can_download = JDHelper::setAUPPointsDownloads($user->id, $aup_data->file_title, $aup_data->file_id, 0, $profile); } } else { $can_download = false; } } } else { // no AUP active $can_download = true; } if ($jlistConfig['user.can.download.file.when.zero.points'] && !$user->guest) { $can_download = true; } } else { $can_download = true; } } else { // single download // we must be ensure that the user cannot skiped special options or settings // check at first the password option if ($files[0]->password_md5 != '') { // captcha is activated for this user $session_result = (int) JDHelper::getSessionDecoded('jd_password_run'); if ($session_result < 2) { // Abort !!! $msg = JText::_('COM_JDOWNLOADS_ANTILEECH_MSG'); $app->redirect(JRoute::_($current_link), $msg, 'error'); } else { JDHelper::writeSessionEncoded('0', 'jd_password_run'); } } else { // when is not use a password, we must check captcha if ($user_rules->view_captcha) { // captcha is activated for this user $session_result = (int) JDHelper::getSessionDecoded('jd_captcha_run'); if ($session_result < 2) { // Abort !!! $msg = JText::_('COM_JDOWNLOADS_ANTILEECH_MSG'); $app->redirect(JRoute::_($current_link), $msg, 'error'); } else { JDHelper::writeSessionEncoded('0', 'jd_captcha_run'); } } } if (!$mirror) { if ($files[0]->url_download) { // build the complete category path if ($files[0]->cat_id > 1) { // Download has a category if ($files[0]->category_cat_dir_parent != '') { $cat_dir = $files[0]->category_cat_dir_parent . '/' . $files[0]->category_cat_dir; } else { $cat_dir = $files[0]->category_cat_dir; } $filename = $jlistConfig['files.uploaddir'] . '/' . $cat_dir . '/' . $files[0]->url_download; $filename_direct = $jlistConfig['files.uploaddir'] . '/' . $cat_dir . '/' . $files[0]->url_download; } else { // Download is 'uncategorized' $filename = $jlistConfig['files.uploaddir'] . '/' . $jlistConfig['uncategorised.files.folder.name'] . '/' . $files[0]->url_download; } } elseif ($files[0]->other_file_id) { // A file from another Download was assigned $query = $db->getQuery(true); $query->select('a.*'); $query->from('#__jdownloads_files AS a'); // Join on category table. $query->select('c.id AS category_id, c.cat_dir AS category_cat_dir, c.cat_dir_parent AS category_cat_dir_parent'); $query->join('LEFT', '#__jdownloads_categories AS c on c.id = a.cat_id'); $query->where('a.published = ' . $db->Quote('1')); $query->where('a.file_id = ' . $db->Quote($files[0]->other_file_id)); $query->where('a.access IN (' . $groups . ')'); $db->setQuery($query); $other_file_data = $db->loadObject(); if ($other_file_data->cat_id > 1) { // the assigned Download has a category if ($other_file_data->category_cat_dir_parent != '') { $cat_dir = $other_file_data->category_cat_dir_parent . '/' . $other_file_data->category_cat_dir; } else { $cat_dir = $other_file_data->category_cat_dir; } $filename = $jlistConfig['files.uploaddir'] . '/' . $cat_dir . '/' . $other_file_data->url_download; $filename_direct = $jlistConfig['files.uploaddir'] . '/' . $cat_dir . '/' . $other_file_data->url_download; } else { // Download is 'uncategorized' $filename = $jlistConfig['files.uploaddir'] . '/' . $jlistConfig['uncategorised.files.folder.name'] . '/' . $other_file_data->url_download; } } else { $filename = $files[0]->extern_file; if ($files[0]->extern_site) { $extern_site = true; } $extern = true; } } else { // is mirror if ($mirror == 1) { $filename = $files[0]->mirror_1; if ($files[0]->extern_site_mirror_1) { $extern_site = true; } } else { $filename = $files[0]->mirror_2; if ($files[0]->extern_site_mirror_2) { $extern_site = true; } } $extern = true; } $price = ''; // Is AUP rule or price option used - we need the price for it if ($aup_exist) { if ($jlistConfig['use.alphauserpoints.with.price.field']) { $price = floatval($files[0]->price); } else { $price = $aup_fix_points; } } if (!$download_in_parts) { $can_download = JDHelper::setAUPPointsDownload($user->id, $files[0]->file_title, $files[0]->file_id, $price, $profile); if ($jlistConfig['user.can.download.file.when.zero.points'] && $user->id) { $can_download = true; } } else { $can_download = true; } } // plugin support // load external plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('jdownloads'); $results = $dispatcher->trigger('onBeforeDownloadIsSendJD', array(&$files, &$can_download, $user_rules, $download_in_parts)); if (!$can_download) { $msg = JText::_('COM_JDOWNLOADS_BACKEND_SET_AUP_FE_MESSAGE_NO_DOWNLOAD'); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } else { // run download if (!$download_in_parts) { // send at first e-mail if ($jlistConfig['send.mailto.option'] == '1' && $files) { JDHelper::sendMailDownload($files); } // give uploader AUP points when is set on if ($jlistConfig['use.alphauserpoints']) { if ($jlistConfig['use.alphauserpoints.with.price.field']) { JDHelper::setAUPPointsDownloaderToUploaderPrice($files); } else { JDHelper::setAUPPointsDownloaderToUploader($files); } } // write data in log if ($jlistConfig['activate.download.log']) { JDHelper::updateLog($type = 1, $files, ''); } // update downloads hits if (count($files) > 1) { $db->setQuery('UPDATE #__jdownloads_files SET downloads=downloads+1 WHERE file_id IN (' . $files_list . ')'); $db->execute(); } else { $db->setQuery("UPDATE #__jdownloads_files SET downloads=downloads+1 WHERE file_id = '" . $files[0]->file_id . "'"); $db->execute(); } } // get filesize if (!$extern) { if (!file_exists($filename)) { $msg = JText::_('COM_JDOWNLOADS_FILE_NOT_FOUND') . ': ' . basename($filename); $app->redirect(JRoute::_($current_link), $msg, 'notice'); } else { $size = filesize($filename); } } else { $size = JDHelper::getUrlFilesize($filename); } // if url go to other website - open it in a new browser window if ($extern_site) { echo "<script>document.location.href='{$filename}';</script>\n"; exit; } // if set the option for direct link to the file if (!$jlistConfig['use.php.script.for.download']) { $root = str_replace('\\', '/', $_SERVER["DOCUMENT_ROOT"]); $root = rtrim($root, "/"); $host = $_SERVER["HTTP_HOST"] . '/'; $filename_direct = str_replace($root, $host, $filename_direct); $filename_direct = str_replace('//', '/', $filename_direct); if (strpos('http://', $filename_direct) === false && strpos('https://', $filename_direct) === false && strpos('ftp://', $filename_direct) === false) { $filename_direct = 'http://' . $filename_direct; } $app->redirect($filename_direct); } else { $only_filename = basename($filename); $extension = JDHelper::getFileExtension($only_filename); if ($extern) { $mime_type = JDHelper::getMimeTypeRemote($filename); } else { $mime_type = JDHelper::getMimeTyp($extension); } // Check for protocol and set the appropriate headers $use_ssl = false; $uri = JUri::getInstance(JUri::current()); $protocol = $uri->getScheme(); if ($protocol == 'https') { $use_ssl = true; } $open_in_browser = false; if (in_array($extension, $view_types)) { // view file in browser $open_in_browser = true; } clearstatcache(); if ($extern) { ob_end_clean(); // needed for MS IE - otherwise content disposition is not used? if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header("Cache-Control: public, must-revalidate"); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // header("Pragma: no-cache"); // Problems with MS IE header("Expires: 0"); header("Content-Description: File Transfer"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header("Content-Type: " . $mime_type); header("Content-Length: " . (string) $size); if (!$open_in_browser) { header('Content-Disposition: attachment; filename="' . $only_filename . '"'); } else { // view file in browser header('Content-Disposition: inline; filename="' . $only_filename . '"'); } header("Content-Transfer-Encoding: binary\n"); // redirect to category when it is set the time if (intval($jlistConfig['redirect.after.download']) > 0) { header("refresh:" . $jlistConfig['redirect.after.download'] . "; url=" . $current_link); } // set_time_limit doesn't work in safe mode if (!ini_get('safe_mode')) { @set_time_limit(0); } @readfile($filename); flush(); exit; } else { $download_class_file = JPATH_SITE . DS . 'components' . DS . 'com_jdownloads' . DS . 'helpers' . DS . 'downloader.php'; if (file_exists($download_class_file)) { require_once $download_class_file; $object = new downloader(); $object->set_byfile($filename); // Type: Download from a file $object->set_filename($only_filename); // Set the file basename $object->set_filesize($size); // Set the file basename $object->set_mime($mime_type); // Set the mime type $object->set_speed($transfer_speed); // Set download speed $object->set_refresh($current_link, (int) $jlistConfig['redirect.after.download']); // // redirect to category when it is set the time in configuration $object->use_resume = true; // Set the value for using Resume Mode $object->use_ssl = $use_ssl; // Set support for SSL $object->open_in_browser = $open_in_browser; // Set whether the file shall be opened in browser window $object->use_autoexit = true; // Set the value for auto exit ('false' worked not really with extern file?) $object->download(); // Run the download flush(); exit; } else { $msg = JText::_('COM_JDOWNLOADS_FILE_NOT_FOUND') . ': ' . $filename; $app->redirect(JRoute::_($current_link), $msg, 'notice'); } } } } }
function display($tpl = null) { global $jlistConfig; require_once JPATH_COMPONENT . '/helpers/search.php'; // Initialise some variables $app = JFactory::getApplication(); $user = JFactory::getUser(); $pathway = $app->getPathway(); $uri = JFactory::getURI(); $jd_user_settings = JDHelper::getUserRules(); $error = null; $rows = null; $results = null; $total = 0; // Get some data from the model $areas = $this->get('areas'); $state = $this->get('state'); $searchword = $state->get('keyword'); $params = $app->getParams(); $menus = $app->getMenu(); $menu = $menus->getActive(); // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_buttons.css", "text/css", null, array()); $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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(); }'); // because the application sets a default page title, we need to get it // right from the menu item itself if (is_object($menu)) { $menu_params = new JRegistry(); $menu_params->loadString($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', JText::_('COM_JDOWNLOADS_SEARCH')); } } else { $params->set('page_title', JText::_('COM_JDOWNLOADS_SEARCH')); } $title = $params->get('page_title'); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename')); } $this->document->setTitle($title); if ($params->get('menu-meta_description')) { $this->document->setDescription($params->get('menu-meta_description')); } if ($params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $params->get('menu-meta_keywords')); } if ($params->get('robots')) { $this->document->setMetadata('robots', $params->get('robots')); } // upload icon handling $this->view_upload_button = false; if ($jd_user_settings->uploads_view_upload_icon) { // we must here check whether the user has the permissions to create new downloads // this can be defined in the components permissions but also in any category // but the upload icon is only viewed when in the user groups settings is also activated the: 'display add/upload icon' option // 1. check the component permissions if (!$user->authorise('core.create', 'com_jdownloads')) { // 2. not global permissions so we must check now every category (for a lot of categories can this be very slow) $this->authorised_cats = JDHelper::getAuthorisedJDCategories('core.create', $user); if (count($this->authorised_cats) > 0) { $this->view_upload_button = true; } } else { $this->view_upload_button = true; } } // built select lists $orders = array(); $orders[] = JHtml::_('select.option', 'newest', JText::_('COM_JDOWNLOADS_SEARCH_NEWEST_FIRST')); $orders[] = JHtml::_('select.option', 'oldest', JText::_('COM_JDOWNLOADS_SEARCH_OLDEST_FIRST')); $orders[] = JHtml::_('select.option', 'popular', JText::_('COM_JDOWNLOADS_SEARCH_MOST_POPULAR')); $orders[] = JHtml::_('select.option', 'alpha', JText::_('COM_JDOWNLOADS_SEARCH_ALPHABETICAL')); $orders[] = JHtml::_('select.option', 'category', JText::_('COM_JDOWNLOADS_SEARCH_CATEGORY')); $lists = array(); $lists['ordering'] = JHtml::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering')); $searchphrases = array(); $searchphrases[] = JHtml::_('select.option', 'all', JText::_('COM_JDOWNLOADS_SEARCH_ALL_WORDS')); $searchphrases[] = JHtml::_('select.option', 'any', JText::_('COM_JDOWNLOADS_SEARCH_ANY_WORDS')); $searchphrases[] = JHtml::_('select.option', 'exact', JText::_('COM_JDOWNLOADS_SEARCH_EXACT_PHRASE')); $lists['searchphrase'] = JHtml::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match')); // log the search // not used currently // SearchHelper::logSearch($searchword); //limit searchword $lang = JFactory::getLanguage(); $upper_limit = $lang->getUpperLimitSearchWord(); $lower_limit = $lang->getLowerLimitSearchWord(); if (JDSearchHelper::limitSearchWord($searchword)) { $error = JText::sprintf('COM_JDOWNLOADS_ERROR_SEARCH_MESSAGE', $lower_limit, $upper_limit); } //sanatise searchword if (JDSearchHelper::santiseSearchWord($searchword, $state->get('match'))) { $error = JText::_('COM_JDOWNLOADS_ERROR_IGNOREKEYWORD'); } if (!$searchword && count(JRequest::get('post'))) { //$error = JText::_('COM_JDOWNLOADS_ERROR_ENTERKEYWORD'); } // put the filtered results back into the model // for next release, the checks should be done in the model perhaps... $state->set('keyword', $searchword); if ($error == null) { $results = $this->get('data'); $total = $this->get('total'); $pagination = $this->get('pagination'); // require_once JPATH_SITE . '/components/com_jdownloads/helpers/route.php'; for ($i = 0, $count = count($results); $i < $count; $i++) { $row =& $results[$i]->text; if ($state->get('match') == 'exact') { $searchwords = array($searchword); $needle = $searchword; } else { $searchworda = preg_replace('#\\xE3\\x80\\x80#s', ' ', $searchword); $searchwords = preg_split("/\\s+/u", $searchworda); $needle = $searchwords[0]; } $row = JDSearchHelper::prepareSearchContent($row, $needle); $searchwords = array_unique($searchwords); $searchRegex = '#('; $x = 0; foreach ($searchwords as $k => $hlword) { $searchRegex .= $x == 0 ? '' : '|'; $searchRegex .= preg_quote($hlword, '#'); $x++; } $searchRegex .= ')#iu'; $row = preg_replace($searchRegex, '<span class="highlight">\\0</span>', $row); $result =& $results[$i]; if ($result->created) { $created = JHtml::_('date', $result->created, JText::_('DATE_FORMAT_LC3')); } else { $created = ''; } $result->text = JHtml::_('content.prepare', $result->text, '', 'com_jdownloads.search'); $result->created = $created; $result->count = $i + 1; } } // Check for layout override $active = JFactory::getApplication()->getMenu()->getActive(); if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->assignRef('pagination', $pagination); $this->assignRef('results', $results); $this->assignRef('lists', $lists); $this->assignRef('params', $params); $this->ordering = $state->get('ordering'); $this->searchword = $searchword; $this->origkeyword = $state->get('origkeyword'); $this->searchphrase = $state->get('match'); $this->searchareas = $areas; $this->total = $total; $this->error = $error; $this->action = $uri; parent::display($tpl); }
function display($tpl = null) { global $jlistConfig; // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); $userId = $user->get('id'); // get jD User group settings and limitations $this->user_rules = JDHelper::getUserRules(); // $dispatcher = JDispatcher::getInstance(); // Get data from the model $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); if ($this->item) { if (!$user->guest) { $this->form->setFieldAttribute('name', 'default', htmlspecialchars($user->name, ENT_COMPAT, 'UTF-8')); $this->form->setFieldAttribute('name', 'readonly', 'true'); $this->form->setFieldAttribute('name', 'class', 'readonly'); $this->form->setFieldAttribute('email', 'default', htmlspecialchars($user->email, ENT_COMPAT, 'UTF-8')); $this->form->setFieldAttribute('email', 'readonly', 'true'); $this->form->setFieldAttribute('email', 'class', 'readonly'); } } else { JError::raiseWarning(100, JText::_('COM_JDOWNLOADS_DOWNLOAD_NOT_FOUND')); return false; } // Get the category title if ($this->item->cat_id == 1) { $this->item->category_title = JText::_('COM_JDOWNLOADS_SELECT_UNCATEGORISED'); } else { $cat = JDHelper::getSingleCategory($this->item->cat_id); $this->item->category_title = $cat->title; } // do it in the form $this->form->setFieldAttribute('cat_title', 'default', htmlspecialchars($this->item->category_title, ENT_COMPAT, 'UTF-8')); $this->state = $this->get('State'); $this->user = $user; // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // add all needed cripts and css files $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_jdownloads/assets/js/jdownloads.js'); $document->addScriptDeclaration('var live_site = "' . JURI::base() . '";'); $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->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_fe.css", "text/css", null, array()); $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/rating/css/ajaxvote.css", "text/css", null, array()); $custom_css_path = JPATH_ROOT . '/components/com_jdownloads/assets/css/jdownloads_custom.css'; if (JFile::exists($custom_css_path)) { $document->addStyleSheet(JURI::base() . "components/com_jdownloads/assets/css/jdownloads_custom.css", 'text/css', null, array()); } // Check the report view access. if (!$this->user_rules->view_report_form) { JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return; } $this->_prepareDocument(); parent::display($tpl); }