/** * 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 build() { $jinput = new JInput(); //Initialize default form $keys = array('option' => $this->getExtension(), 'view' => $this->getView(), 'layout' => $jinput->get('layout', null, 'CMD'), 'task' => ""); //For item layout if (isset($this->dataObject)) { $keys['id'] = isset($this->dataObject->id) ? $this->dataObject->id : 0; //Deprecated $keys['cid[]'] = isset($this->dataObject->id) ? $this->dataObject->id : 0; } //Specifics values or overrides if (isset($this->values)) { foreach ($this->values as $key => $value) { $keys[$key] = $value; } } //Reproduce current query in the form $followers = array('lang', 'Itemid', 'tmpl'); //Cmd types only for the moment foreach ($followers as $follower) { $val = $jinput->get($follower, null, 'CMD'); if ($val) { $keys[$follower] = $val; } } $html = ""; foreach ($keys as $key => $value) { $html .= JDom::_('html.form.input.hidden', array('dataKey' => $key, 'dataValue' => $value)); } //Token $html .= JHTML::_('form.token'); return $html; }
/** * Example before save content method * * Method is called right before content is saved into the database. * Article object is passed by reference, so any changes will be saved! * NOTE: Returning false will abort the save with an error. *You can set the error by calling $article->setError($message) * * @param string The context of the content passed to the plugin. * @param object A JTableContent object * @param bool If the content is just about to be created * @return bool If false, abort the save * @since 1.6 */ public function onContentBeforeSave($context, $article, $isNew) { //error_log("plgContentArticlesubmit::onContentBeforeSave") ; $app = JFactory::getApplication(); // run this plugin only for com_content $parts = explode(".", $context); if ($parts[0] != 'com_content') { return true; } // dont do anything is it is not frontend if (!$app->isSite()) { return true; } $jinput = $app->input; $formData = new JInput($jinput->get('jform', '', 'array')); //error_log("jinput == " . print_r($jinput,true)); $introtext = $formData->get('article_introtext', '', 'html'); //error_log("introtext == " . $introtext); $fulltext = $formData->get('article_fulltext', '', 'raw'); //error_log("fulltext == " . $fulltext); $article->introtext = $introtext; $article->fulltext = $fulltext; $savedImage = $this->saveImage($article); if ($savedImage) { $images = array(); $images['image_fulltext'] = $savedImage; $images['image_intro'] = $savedImage; $article->images = json_encode($images); return true; } else { $article->setError("Could not process the uploaded image. Please try again with a different (smaller) image."); return false; } return true; }
/** * {@inheritdoc} */ protected function _get($name, $default = null, $isArray = false) { if ($isArray) { return $this->_input->get($name, $default, 'array'); } // Yeap, HTML is not RAW, but it safes your website return $this->_input->get($name, $default, 'html'); }
/** * upload * * @param \JInput $input */ public static function upload(\JInput $input) { try { $editorPlugin = \JPluginHelper::getPlugin('editors', 'akmarkdown'); if (!$editorPlugin) { throw new \Exception('Editor Akmarkdown not exists'); } $params = new Registry($editorPlugin->params); $files = $input->files; $field = $input->get('field', 'file'); $type = $input->get('type', 'post'); $allows = $params->get('Upload_AllowExtension', ''); $allows = array_map('strtolower', array_map('trim', explode(',', $allows))); $file = $files->getVar($field); $src = $file['tmp_name']; $name = $file['name']; $tmp = new \SplFileInfo(JPATH_ROOT . '/tmp/ak-upload/' . $name); if (empty($file['tmp_name'])) { throw new \Exception('File not upload'); } $ext = pathinfo($name, PATHINFO_EXTENSION); if (!in_array($ext, $allows)) { throw new \Exception('File extension now allowed.'); } // Move file to tmp if (!is_dir($tmp->getPath())) { \JFolder::create($tmp->getPath()); } if (is_file($tmp->getPathname())) { \JFile::delete($tmp->getPathname()); } \JFile::upload($src, $tmp->getPathname()); $src = $tmp; $dest = static::getDest($name, $params->get('Upload_S3_Subfolder', 'ak-upload')); $s3 = new \S3($params->get('Upload_S3_Key'), $params->get('Upload_S3_SecretKey')); $bucket = $params->get('Upload_S3_Bucket'); $result = $s3::putObject(\S3::inputFile($src->getPathname(), false), $bucket, $dest, \S3::ACL_PUBLIC_READ); if (is_file($tmp->getPathname())) { \JFile::delete($tmp->getPathname()); } if (!$result) { throw new \Exception('Upload fail.'); } } catch (\Exception $e) { $response = new Response(); $response->setBody(json_encode(['error' => $e->getMessage()])); $response->setMimeType('text/json'); $response->respond(); exit; } $return = new \JRegistry(); $return['filename'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest; $return['file'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest; $response = new Response(); $response->setBody((string) $return); $response->setMimeType('text/json'); $response->respond(); }
/** * Test the JInput::get method. * * @return void * * @since 11.1 */ public function testGet() { $_REQUEST['foo'] = 'bar'; // Test the get method. $this->assertThat($this->class->get('foo'), $this->equalTo('bar'), 'Line: ' . __LINE__ . '.'); $_GET['foo'] = 'bar2'; // Test the get method. $this->assertThat($this->class->get->get('foo'), $this->equalTo('bar2'), 'Line: ' . __LINE__ . '.'); // Test the get method. $this->assertThat($this->class->get('default_value', 'default'), $this->equalTo('default'), 'Line: ' . __LINE__ . '.'); }
/** * parseTask * * @param string $controller * @param \JInput $input * * @return void */ public static function parseUserTask($controller, $input) { $task = $input->get('task'); if (is_numeric($task)) { $id = $task; $input->set('id', $id); $input->set('task', null); } else { $input->set('task', 'user.' . $input->get('task')); } }
/** * @param array $data * @return Renderer */ public function createView(array $data = array()) { $renderer = new Renderer($data); $name = $this->getName(); // Add the default view path $renderer->addIncludePath(COMPONENT_ROOT . '/src/views/' . $this->getName()); $template = $this->app->getTemplate(); $option = $this->input->get('option'); // Prepend the template path $renderer->addIncludePath(JPATH_ROOT . '/templates/' . $template . '/html/' . $option . '/' . $this->getName(), true); return $renderer; }
/** * Starts the session * * @return boolean True if started * * @since 3.5 * @throws RuntimeException If something goes wrong starting the session. */ public function start() { $session_name = $this->getName(); // Get the JInputCookie object $cookie = $this->input->cookie; if (is_null($cookie->get($session_name))) { $session_clean = $this->input->get($session_name, false, 'string'); if ($session_clean) { $this->setId($session_clean); $cookie->set($session_name, '', time() - 3600); } } return parent::start(); }
/** * Start a session. * * Creates a session (or resumes the current one based on the state of the session) * * @return boolean true on success * * @since 11.1 */ protected function _start() { // Start session if not started if ($this->_state === 'restart') { session_regenerate_id(true); } else { $session_name = session_name(); // Get the JInputCookie object $cookie = $this->_input->cookie; if (is_null($cookie->get($session_name))) { $session_clean = $this->_input->get($session_name, false, 'string'); if ($session_clean) { session_id($session_clean); $cookie->set($session_name, '', time() - 3600); } } } /** * Write and Close handlers are called after destructing objects since PHP 5.0.5. * Thus destructors can use sessions but session handler can't use objects. * So we are moving session closure before destructing objects. * * Replace with session_register_shutdown() when dropping compatibility with PHP 5.3 */ register_shutdown_function('session_write_close'); session_cache_limiter('none'); session_start(); return true; }
/** * Build route. * * @param string $name Route resource name. * @param array &$queries Http queries. * * @return array */ public function build($name, &$queries) { if (empty($this->resources[$name])) { return array(); } if (is_callable($this->buildHandler[$name])) { call_user_func_array($this->buildHandler[$name], array($queries)); } $replace = array(); $pattern = $this->resources[$name]; foreach ($this->maps[$name]['vars'] as $key) { $var = isset($queries[$key]) ? $queries[$key] : $this->input->get($key, 'null'); if (is_array($var) || is_object($var)) { $var = implode('/', (array) $var); $key2 = '*' . $key; $replace[$key2] = $var; } else { $key2 = ':' . $key; $replace[$key2] = $var; } if (strpos($pattern, $key2) !== false) { unset($queries[$key]); } } $pattern = strtr($pattern, $replace); return explode('/', $pattern); }
/** * getContext * * @return string */ public function getContext() { $option = $this->input->get('option'); $view = $this->input->get('view'); $context = "{$option}.{$view}"; return $context; }
/** * Init this component. * * @return void */ public function init() { $dispatcher = $this->container->get('event.dispatcher'); // Event $dispatcher->trigger('onComponentBeforeInit', array($this->name, $this, $this->input)); // We build component path constant, helpe us get path easily. $this->path['self'] = JPATH_BASE . '/components/' . strtolower($this->option); $this->path['site'] = JPATH_ROOT . '/components/' . strtolower($this->option); $this->path['administrator'] = JPATH_ROOT . '/administrator/components/' . strtolower($this->option); define(strtoupper($this->name) . '_SELF', $this->path['self']); define(strtoupper($this->name) . '_SITE', $this->path['site']); define(strtoupper($this->name) . '_ADMIN', $this->path['administrator']); // Register some useful object for this component. $this->container->registerServiceProvider(new ComponentProvider($this->name, $this)); $task = $this->input->getWord('task'); $controller = $this->input->getWord('controller'); // Prepare default controller if (!$task && !$controller) { // If we got view, set it to display controller. $view = $this->input->get('view'); $task = $view ? $view . '.display' : $this->defaultController; $this->input->set('task', $task); $this->input->set('controller', $task); } // Register form and fields \JForm::addFieldPath(WINDWALKER_SOURCE . '/Form/Fields'); \JForm::addFormPath(WINDWALKER_SOURCE . '/Form/Forms'); $this->registerEventListener(); // Register elFinder controllers // @TODO: Should use event listener $this->registerTask('finder.elfinder.display', '\\Windwalker\\Elfinder\\Controller\\DisplayController'); $this->registerTask('finder.elfinder.connect', '\\Windwalker\\Elfinder\\Controller\\ConnectController'); // Event $dispatcher->trigger('onComponentAfterInit', array($this->name, $this, $this->input)); }
/** * This method checks if a value for remote user is present inside * the $_SERVER array. If so then replace any domain related stuff * to get the username and return it. * * @return mixed Username of detected user or False. * * @since 1.0 */ public function detectRemoteUser() { /* * When legacy flag is true, it ensures compatibility with JSSOMySite 1.x by * only returning a string username or false can be returned. This also means * keeping compatibility with Joomla 1.6. * When it is set to False, it can return an array and compatible with Joomla 2.5. */ $legacy = $this->params->get('use_legacy', false); // Get the array key of $_SERVER where the user can be located $serverKey = strtoupper($this->params->get('userkey', 'REMOTE_USER')); // Get the $_SERVER key and ensure its lowercase and doesn't filter if ($legacy) { // Get the $_SERVER value which should contain the SSO username $remoteUser = JRequest::getVar($serverKey, null, 'server', 'string', JREQUEST_ALLOWRAW); } else { // Get the $_SERVER value which should contain the SSO username $input = new JInput($_SERVER); $remoteUser = $input->get($serverKey, null, 'USERNAME'); unset($input); } // Ensures the returned user is lowercased $remoteUser = strtolower($remoteUser); // Get a username replacement parameter in lowercase and split by semi-colons $replace_set = explode(';', strtolower($this->params->get('username_replacement', ''))); foreach ($replace_set as $replacement) { $remoteUser = str_replace(trim($replacement), '', $remoteUser); } // Returns the username return $remoteUser; }
/** * Gets the IP address of the client machine, translates it to a compatiable * eDirectory netadress and queries it against the LDAP server using a filter. * * @return mixed Username of detected user or False. * * @since 1.0 */ public function detectRemoteUser() { // Import languages for frontend errors $this->loadLanguage(); /* * When legacy flag is true, it ensures compatibility with JSSOMySite 1.x by * only returning a string username or false can be returned. This also means * keeping compatibility with Joomla 1.6. * When it is set to False, it can return an array and compatible with Joomla 2.5. */ $legacy = $this->params->get('use_legacy', false); if ($legacy) { // Use legacy way of getting paramters $authParams = new JRegistry(); $authName = $this->params->get('auth_plugin', 'jmapmyldap'); $authPlugin = JPluginHelper::getPlugin('authentication', $authName); $authParams->loadString($authPlugin->params); $ldapUid = $authParams->get('ldap_uid', 'uid'); // Attempt to load up a LDAP instance using the legacy method jimport('shmanic.jldap2'); $ldap = new JLDAP2($authParams); // Lets try to bind using proxy user if (!$ldap->connect() || !$ldap->bind($ldap->connect_username, $ldap->connect_password)) { JError::raiseWarning('SOME_ERROR_CODE', JText::_('PLG_EDIR_ERROR_LDAP_BIND')); return; } // Get IP of client machine $myip = JRequest::getVar('REMOTE_ADDR', 0, 'server'); // Convert this to some net address thing that edir likes $na = JLDAPHelper::ipToNetAddress($myip); // Find the network address and return the uid for it $filter = "(networkAddress={$na})"; $dn = $authParams->get('base_dn'); // Do the LDAP filter search now $result = new JLDAPResult($ldap->search($dn, $filter, array($ldapUid))); $ldap->close(); } else { try { // We will only check the first LDAP config $ldap = SHLdap::getInstance(); $ldap->proxyBind(); $ldapUid = $ldap->getUid; // Get the IP address of this client and convert to netaddress for LDAP searching $input = new JInput($_SERVER); $myIp = $input->get('REMOTE_ADDR', false, 'string'); $na = SHLdapHelper::ipToNetAddress($myIp); $result = $ldap->search(null, "(networkAddress={$na})", array($ldapUid)); } catch (Exception $e) { SHLog::add($e, 16010, JLog::ERROR, 'sso'); return; } } if ($value = $result->getValue(0, $ldapuid, 0)) { // Username was found logged in on this client machine return $value; } }
/** * Method to display a view. * * @param boolean $cachable If true, the view output will be cached * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. * @since 1.5 */ public function display($cachable = false, $urlparams = false) { // TemplateckHelper::addSubmenu(JRequest::getCmd('view', 'templates')); $input = new JInput(); $view = $input->get('view', 'Modulesmanagerck'); $input->set('view', $view); parent::display(); return $this; }
/** * Start a session. * * Creates a session (or resumes the current one based on the state of the session) * * @return boolean true on success * * @since 11.1 */ protected function _start() { // Start session if not started if ($this->_state === 'restart') { session_regenerate_id(true); } else { $session_name = session_name(); // Get the JInputCookie object $cookie = $this->_input->cookie; if (is_null($cookie->get($session_name))) { $session_clean = $this->_input->get($session_name, false, 'string'); if ($session_clean) { session_id($session_clean); $cookie->set($session_name, '', time() - 3600); } } } /** * Write and Close handlers are called after destructing objects since PHP 5.0.5. * Thus destructors can use sessions but session handler can't use objects. * So we are moving session closure before destructing objects. */ register_shutdown_function(array($this, 'close')); session_cache_limiter('none'); session_start(); // Ok let's unserialize the whole thing // Try loading data from the session if (isset($_SESSION['joomla']) && !empty($_SESSION['joomla'])) { $data = $_SESSION['joomla']; $data = base64_decode($data); $this->data = unserialize($data); } // Temporary, PARTIAL, data migration of existing session data to avoid logout on update from J < 3.4.7 if (isset($_SESSION['__default']) && !empty($_SESSION['__default'])) { $migratableKeys = array("user", "session.token", "session.counter", "session.timer.start", "session.timer.last", "session.timer.now"); foreach ($migratableKeys as $migratableKey) { if (!empty($_SESSION['__default'][$migratableKey])) { // Don't overwrite existing session data if (!is_null($this->data->get('__default.' . $migratableKey, null))) { continue; } $this->data->set('__default.' . $migratableKey, $_SESSION['__default'][$migratableKey]); unset($_SESSION['__default'][$migratableKey]); } } /** * Finally, empty the __default key since we no longer need it. Don't unset it completely, we need this * for the administrator/components/com_admin/script.php to detect upgraded sessions and perform a full * session cleanup. */ $_SESSION['__default'] = array(); } return true; }
/** * Gets a value from the input data. * * @param string $name Name of the value to get. * @param mixed $default Default value to return if variable does not exist. * @param string $filter Filter to apply to the value. * * @return mixed The filtered input value. * * @since 11.1 */ public function get($name, $default = null, $filter = 'cmd') { // No filtering in RAW format if (strtoupper($filter) == 'RAW') { if (isset($this->data[$name])) { return $this->data[$name]; } return $default; } return parent::get($name, $default, $filter); }
/** * @param $name * @param null $default * @param string $hash * @param string $type * * @return mixed */ protected function getVar($name, $default = null, $hash = 'request', $type = 'none') { // If we are not in embedded mode, get variable from request if (!$this->embedded) { if ($hash == 'request') { return $this->input->get($name, $default, $type); } else { return $this->input->{$hash}->get($name, $default, $type); } } return $this->filter->clean($this->params->get($name, $default), $type); }
/** * Start a session. * * Creates a session (or resumes the current one based on the state of the session) * * @return boolean true on success * * @since 11.1 */ protected function _start() { // Start session if not started if ($this->_state === 'restart') { session_regenerate_id(true); } else { $session_name = session_name(); // Get the JInputCookie object $cookie = $this->_input->cookie; if (is_null($cookie->get($session_name))) { $session_clean = $this->_input->get($session_name, false, 'string'); if ($session_clean) { session_id($session_clean); $cookie->set($session_name, '', time() - 3600); } } } /** * Write and Close handlers are called after destructing objects since PHP 5.0.5. * Thus destructors can use sessions but session handler can't use objects. * So we are moving session closure before destructing objects. * * Replace with session_register_shutdown() when dropping compatibility with PHP 5.3 */ register_shutdown_function(array($this, 'close')); session_cache_limiter('none'); session_start(); // Ok let's unserialize the whole thing $this->data = new \Joomla\Registry\Registry(); // Try loading data from the session if (isset($_SESSION['joomla']) && !empty($_SESSION['joomla'])) { $data = $_SESSION['joomla']; $data = base64_decode($data); $this->data = unserialize($data); } // Migrate existing session data to avoid logout on update from J < 3.4.7 if (isset($_SESSION['__default'])) { $migratableKeys = array("user", "session.token", "session.counter", "session.timer.start", "session.timer.last", "session.timer.now"); foreach ($migratableKeys as $migratableKey) { if (!empty($_SESSION['__default'][$migratableKey])) { // Don't overwrite existing session data if (!is_null($this->data->get('__default.' . $migratableKey, null))) { continue; } $this->data->set('__default.' . $migratableKey, $_SESSION['__default'][$migratableKey]); unset($_SESSION['__default'][$migratableKey]); } } } return true; }
public function confirmDelivered($post) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $delivered = array(); if (!empty($post['delivered'])) { $delivered = $post['delivered']; } foreach ($delivered as $d) { $query->clear(); $query->update('#__hp_order_items')->set('delivered = 1')->where('id = ' . $d)->where('business_id = ' . JFactory::getUser()->id); $db->setQuery($query); $db->query(); if ($db->getErrorMsg()) { die($db->getErrorMsg()); } } // Upload file $jFileInput = new JInput($_FILES); $file = $jFileInput->get('jform', array(), 'array'); $filepath = JPATH_ROOT . DS . 'upload' . DS . 'orders' . DS . $post['order_id'] . DS; @mkdir($filepath, 0777, true); $uploadResult = false; if (!empty($file['name']['file_upload'])) { $uploadResult = JFile::upload($file['tmp_name']['file_upload'], $filepath . $file['name']['file_upload']); } if ($uploadResult) { // Update to files $fileName = $file['name']['file_upload']; $query->clear()->insert('#__files')->columns('item_id, item_type, file_upload, description, created')->values($post['order_id'] . ', "order", ' . $db->quote($fileName) . ', ' . $db->quote($post['description']) . ', ' . $db->quote(date('Y-m-d H:i:s'))); $db->setQuery($query); $db->query(); if ($db->getErrorMsg()) { die($db->getErrorMsg()); } } // Update note $note = trim($post['business_note']); if (!empty($note)) { $query->clear()->insert('#__hp_order_notes')->columns('order_id, business_id, note, created')->values($post['order_id'] . ',' . JFactory::getUser()->id . ',' . $db->quote($note) . ',' . $db->quote(date('Y-m-d H:i:s'))); $db->setQuery($query); $db->query(); if ($db->getErrorMsg()) { die($db->getErrorMsg()); } } return true; }
public function getOrderId() { $user = JFactory::getUser(); $user_id = $user->id; $jinput = new JInput(); $post = $jinput->get('jform', '', 'array'); $order_sum = $post['order_sum']; $row = array(); $row['user_id'] = $user_id; $row['sum'] = $order_sum; $payments =& JTable::getInstance('payments', 'VideoTranslationTable'); if (!$payments->bind($row)) { return JError::raiseWarning(500, $row->getError()); } if (!$payments->store()) { JError::raiseError(500, $row->getError()); } return $payments->id; }
protected function getLabel() { $input = new JInput(); $imgpath = JUri::root(true) . '/modules/mod_maximenuck/elements/images/'; // check if the maximenu params component is installed $com_params_text = ''; if (file_exists(JPATH_ROOT . '/administrator/components/com_maximenuck/maximenuck.php')) { $com_params_text = '<img src="' . $imgpath . 'accept.png" />' . JText::_('MOD_MAXIMENUCK_COMPONENT_PARAMS_INSTALLED'); $button = '<input name="' . $this->name . '_button" id="' . $this->name . '_button" class="ckpopupwizardmanager_button" style="background-image:url(' . $imgpath . 'pencil.png);width:100%;" type="button" value="' . JText::_('MAXIMENUCK_STYLES_WIZARD') . '" onclick="SqueezeBox.fromElement(this, {handler:\'iframe\', size: {x: 800, y: 500}, url:\'' . JUri::root(true) . '/administrator/index.php?option=com_maximenuck&view=modules&view=styles&&layout=modal&id=' . $input->get('id', 0, 'int') . '\'})"/>'; } else { $com_params_text = '<img src="' . $imgpath . 'cross.png" />' . JText::_('MOD_MAXIMENUCK_COMPONENT_PARAMS_NOT_INSTALLED'); $button = ''; } $html = ''; // css styles already loaded into the ckmaximenuchecking field $html .= $com_params_text ? '<div class="maximenuckchecking">' . $com_params_text . '</div>' : ''; $html .= '<div class="clr"></div>'; $html .= $button; return $html; }
/** * Display the view */ public function display($tpl = null) { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $app = JFactory::getApplication(); $input = new JInput(); // load the module params $controller = new MaximenuckController(); $this->params_string = $controller->load_param($input->get('id', 0, 'int'), '', false, true, true); $this->params = new JRegistry($this->params_string); $this->imagespath = JUri::root(true) . '/administrator/components/com_maximenuck'; $this->colorpicker_class = 'color {required:false,pickerPosition:\'top\',pickerBorder:2,pickerInset:3,hash:true}'; // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } parent::display($tpl); die; }
* @package com_maximenuck * @copyright Copyright (C) 2014. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr */ defined('_JEXEC') or die; $input = new JInput(); $document = JFactory::getDocument(); // get the language direction $langdirection = $document->getDirection(); $menubgcolor = ''; $logoimage = false; // generate the menu items $items = array((object) array('ftitle' => 'Lorem', 'id' => 1, 'level' => 1, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item1 parent first', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => true, 'shallower' => false, 'level_diff' => -1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Curabitur', 'id' => 2, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item2 parent', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => true, 'shallower' => false, 'level_diff' => -1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Elementum', 'id' => 3, 'level' => 3, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item2', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Lobortis nec', 'id' => 4, 'level' => 3, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item2', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => true, 'level_diff' => 1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Dictum nisi', 'id' => 5, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item3', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Semper orci', 'id' => 6, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item4', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => true, 'level_diff' => 1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Ipsum', 'id' => 7, 'level' => 1, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item5', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Dolor sit', 'id' => 8, 'level' => 1, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item6 parent', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => true, 'shallower' => false, 'level_diff' => -1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => '', 'submenuswidth' => 400, 'nextcolumnwidth' => '50%'), (object) array('ftitle' => 'Column 1', 'id' => 9, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item7 headingck', 'liclass' => '', 'type' => 'separator', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => '', 'columnwidth' => '50%', 'colonne' => true), (object) array('ftitle' => 'Cras massa', 'id' => 10, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item8', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Faucibus', 'id' => 11, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item9', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Dapibus ligula', 'id' => 12, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item10', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Column 2', 'id' => 13, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item11 headingck', 'liclass' => '', 'type' => 'separator', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => '', 'columnwidth' => '50%', 'colonne' => true), (object) array('ftitle' => 'Eu placerat', 'id' => 14, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item12', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Felis posuere', 'id' => 15, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item13', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Adipiscing', 'id' => 16, 'level' => 2, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item14', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => true, 'level_diff' => 1, 'is_end' => false, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => ''), (object) array('ftitle' => 'Consectetur', 'id' => 17, 'level' => 1, 'anchor_title' => '', 'desc' => '', 'params' => new JRegistry(), 'menu_image' => '', 'classe' => ' item15 active current', 'liclass' => '', 'type' => '', 'anchor_css' => '', 'flink' => 'javascript:void(0)', 'rel' => '', 'deeper' => false, 'shallower' => false, 'level_diff' => 0, 'is_end' => true, 'leftmargin' => '', 'topmargin' => '', 'colbgcolor' => '', 'submenucontainerheight' => '')); // get the params from the module $modulelayout = trim($input->get('modulelayout', $this->params->get('layout', 'default'), 'string'), '_:'); $orientation = $input->get('orientation', $this->params->get('orientation', 'horizontal'), 'string'); // set the params of the demo module $params = new JRegistry(); $params->set('startLevel', '1'); $params->set('orientation', $orientation); $params->set('menuid', 'maximenuck_previewmodule'); if (($modulelayout == 'pushdown' || $modulelayout == 'megatabs') && $orientation == 'vertical') { echo '<p style="color:red;font-weight:bold;">MAXIMENU MESSAGE : You can not use this layout for a Vertical menu</p>'; die; } // load the module helper if (file_exists(JPATH_ROOT . '/modules/mod_maximenuck/helper.php')) { require_once JPATH_ROOT . '/modules/mod_maximenuck/helper.php'; } else { echo JText::_('CK_MODULE_MAXIMENUCK_NOT_INSTALLED');
* The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 * More info at https://www.jomsocial.com/license-agreement */ defined('_JEXEC') or die; $input = new JInput(); ?> <div class="joms-page"> <h3 class="joms-page__title"><?php echo JText::_('COM_COMMUNITY_GROUPS_GROUP_DISCUSSION'); ?> </h3> <?php if ($canCreate) { ?> <button class="joms-button--add-on-page joms-button--primary joms-button--small" onclick="window.location='<?php echo CRoute::_('index.php?option=com_community&view=groups&groupid=' . $input->get('groupid') . '&task=adddiscussion'); ?> ';"><?php echo JText::_('COM_COMMUNITY_CREATE_GROUP_DISCUSSION'); ?> </button> <?php } if ($discussions) { foreach ($discussions as $row) { ?> <div class="joms-stream__container joms-stream--discussion"> <div class="joms-stream__header"> <div class="joms-avatar--stream"> <a href="<?php echo CUrlHelper::userLink($row->user->id);
static function uploadImages($field, $item, $delImage = 0, $itemType = 'albums', $width = 0, $height = 0) { $jFileInput = new JInput($_FILES); $file = $jFileInput->get('jform', array(), 'array'); // If there is no uploaded file, we have a problem... if (!is_array($file)) { // JError::raiseWarning('', 'No file was selected.'); return ''; } // Build the paths for our file to move to the components 'upload' directory $fileName = $file['name'][$field]; $tmp_src = $file['tmp_name'][$field]; $image = ''; $oldImage = ''; $flagDelete = false; // $item = $this->getItem(); // if delete old image checked or upload new file if ($delImage || $fileName) { $oldImage = JPATH_ROOT . DS . str_replace('/', DS, $item->images); // unlink file if (is_file($oldImage)) { @unlink($oldImage); } $flagDelete = true; $image = ''; } $date = date('Y') . DS . date('m') . DS . date('d'); $dest = JPATH_ROOT . DS . 'images' . DS . $itemType . DS . $date . DS . $item->id . DS; // Make directory @mkdir($dest, 0777, true); if (isset($fileName) && $fileName) { $filepath = JPath::clean($dest . $fileName); /* if (JFile::exists($filepath)) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS')); // File exists } */ // Move uploaded file jimport('joomla.filesystem.file'); if (!JFile::upload($tmp_src, $filepath)) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE')); // Error in upload return ''; } // if upload success, resize image if ($width) { require_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpthumb.class.php'; // create phpThumb object $phpThumb = new phpThumb(); if (include_once JPATH_ROOT . DS . 'jelibs/phpthumb/phpThumb.config.php') { foreach ($PHPTHUMB_CONFIG as $key => $value) { $keyname = 'config_' . $key; $phpThumb->setParameter($keyname, $value); } } // this is very important when using a single object to process multiple images $phpThumb->resetObject(); $phpThumb->setSourceFilename($filepath); // set parameters (see "URL Parameters" in phpthumb.readme.txt) $phpThumb->setParameter('w', $width); if ($height) { $phpThumb->setParameter('h', $height); } $phpThumb->setParameter('config_output_format', 'jpeg'); // set value to return $image = 'images/' . $itemType . '/' . str_replace(DS, '/', $date) . '/' . $item->id . '/' . $fileName; if ($phpThumb->GenerateThumbnail()) { if ($image) { if (!$phpThumb->RenderToFile($filepath)) { // do something on failed die('Failed (size=' . $width . '):<pre>' . implode("\n\n", $phpThumb->debugmessages) . '</pre>'); } $phpThumb->purgeTempFiles(); } } else { // do something with debug/error messages echo 'Failed (size=' . $width . ').<br>'; echo '<div style="background-color:#FFEEDD; font-weight: bold; padding: 10px;">' . $phpThumb->fatalerror . '</div>'; echo '<form><textarea rows="100" cols="300" wrap="off">' . htmlentities(implode("\n* ", $phpThumb->debugmessages)) . '</textarea></form><hr>'; die; } } else { // set value to return $image = 'images/' . $itemType . '/' . str_replace(DS, '/', $date) . '/' . $item->id . '/' . $fileName; } } else { if (!$flagDelete) { $image = $item->images; } } return $image; }
/** * Called when the user uploaded a new photo and process avatar upload & resize * @return type */ public function changeAvatar() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; /* get variables */ $type = $jinput->get('type', null, 'NONE'); $id = $jinput->get('id', null, 'INT'); $saveAction = $jinput->get('repeattype', null, 'STRING'); $filter = JFilterInput::getInstance(); $type = $filter->clean($type, 'string'); $id = $filter->clean($id, 'integer'); $params = new JRegistry(); $cTable = JTable::getInstance(ucfirst($type), 'CTable'); $cTable->load($id); if ($type == "profile") { $my = CFactory::getUser($id); } else { $my = CFactory::getUser(); } $config = CFactory::getConfig(); $userid = $my->id; $fileFilter = new JInput($_FILES); $file = $fileFilter->get('filedata', '', 'array'); if (!CImageHelper::checkImageSize(filesize($file['tmp_name']))) { $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_VIDEOS_IMAGE_FILE_SIZE_EXCEEDED_MB', CFactory::getConfig()->get('maxuploadsize'))); return; } //check if file is allwoed if (!CImageHelper::isValidType($file['type'])) { $this->_showUploadError(true, JText::_('COM_COMMUNITY_IMAGE_FILE_NOT_SUPPORTED')); return; } CImageHelper::autoRotate($file['tmp_name']); $album = JTable::getInstance('Album', 'CTable'); //create the avatar default album if it does not exists if (!($albumId = $album->isAvatarAlbumExists($id, $type))) { $albumId = $album->addAvatarAlbum($id, $type); } //start image processing // Get a hash for the file name. $fileName = JApplication::getHash($file['tmp_name'] . time()); $hashFileName = JString::substr($fileName, 0, 24); $avatarFolder = $type != 'profile' && $type != '' ? $type . '/' : ''; //avatar store path $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar' . '/' . $avatarFolder; if (!JFolder::exists($storage)) { JFolder::create($storage); } $storageImage = $storage . '/' . $hashFileName . CImageHelper::getExtension($file['type']); $image = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . $hashFileName . CImageHelper::getExtension($file['type']); /** * reverse image use for cropping feature * @uses <type>-<hashFileName>.<ext> */ $storageReserve = $storage . '/' . $type . '-' . $hashFileName . CImageHelper::getExtension($file['type']); // filename for stream attachment $imageAttachment = $config->getString('imagefolder') . '/avatar/' . $hashFileName . '_stream_' . CImageHelper::getExtension($file['type']); //avatar thumbnail path $storageThumbnail = $storage . '/thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); $thumbnail = $config->getString('imagefolder') . '/avatar/' . $avatarFolder . 'thumb_' . $hashFileName . CImageHelper::getExtension($file['type']); //Minimum height/width checking for Avatar uploads list($currentWidth, $currentHeight) = getimagesize($file['tmp_name']); if ($currentWidth < COMMUNITY_AVATAR_PROFILE_WIDTH || $currentHeight < COMMUNITY_AVATAR_PROFILE_HEIGHT) { $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MINIMUM_AVATAR_DIMENSION', COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)); return; } /** * Generate square avatar */ if (!CImageHelper::createThumb($file['tmp_name'], $storageImage, $file['type'], COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)) { $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage)); return; } // Generate thumbnail if (!CImageHelper::createThumb($file['tmp_name'], $storageThumbnail, $file['type'])) { $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage)); return; } /** * Generate large image use for avatar thumb cropping * It must be larget than profile avatar size because we'll use it for profile avatar recrop also */ $newWidth = 0; $newHeight = 0; if ($currentWidth >= $currentHeight) { if ($this->testResize($currentWidth, $currentHeight, COMMUNITY_AVATAR_RESERVE_WIDTH, 0, COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_RESERVE_WIDTH)) { $newWidth = COMMUNITY_AVATAR_RESERVE_WIDTH; $newHeight = 0; } else { $newWidth = 0; $newHeight = COMMUNITY_AVATAR_RESERVE_HEIGHT; } } else { if ($this->testResize($currentWidth, $currentHeight, 0, COMMUNITY_AVATAR_RESERVE_HEIGHT, COMMUNITY_AVATAR_PROFILE_HEIGHT, COMMUNITY_AVATAR_RESERVE_HEIGHT)) { $newWidth = 0; $newHeight = COMMUNITY_AVATAR_RESERVE_HEIGHT; } else { $newWidth = COMMUNITY_AVATAR_RESERVE_WIDTH; $newHeight = 0; } } if (!CImageHelper::resizeProportional($file['tmp_name'], $storageReserve, $file['type'], $newWidth, $newHeight)) { $this->_showUploadError(true, JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageReserve)); return; } /* * Generate photo to be stored in default avatar album * notes: just in case this need to be used in registration, just get the code below. */ $originalPath = $storage . 'original_' . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']); $fullImagePath = $storage . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']); $thumbPath = $storage . 'thumb_' . md5($my->id . '_avatar' . time()) . CImageHelper::getExtension($file['type']); // Generate full image if (!CImageHelper::resizeProportional($file['tmp_name'], $fullImagePath, $file['type'], 1024)) { $msg['error'] = JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $file['tmp_name']); echo json_encode($msg); exit; } CPhotos::generateThumbnail($file['tmp_name'], $thumbPath, $file['type']); if (!JFile::copy($file['tmp_name'], $originalPath)) { exit; } //store this picture into default avatar album $now = new JDate(); $photo = JTable::getInstance('Photo', 'CTable'); $photo->albumid = $albumId; $photo->image = str_replace(JPATH_ROOT . '/', '', $fullImagePath); $photo->caption = $file['name']; $photo->filesize = $file['size']; $photo->creator = $my->id; $photo->created = $now->toSql(); $photo->published = 1; $photo->thumbnail = str_replace(JPATH_ROOT . '/', '', $thumbPath); $photo->original = str_replace(JPATH_ROOT . '/', '', $originalPath); if ($photo->store()) { $album->load($albumId); $album->photoid = $photo->id; $album->setParam('thumbnail', $photo->thumbnail); $album->store(); } //end storing user avatar in avatar album if ($type == 'profile') { $profileType = $my->getProfileType(); $multiprofile = JTable::getInstance('MultiProfile', 'CTable'); $multiprofile->load($profileType); $useWatermark = $profileType != COMMUNITY_DEFAULT_PROFILE && $config->get('profile_multiprofile') && !empty($multiprofile->watermark) ? true : false; if ($useWatermark && $multiprofile->watermark) { JFile::copy($storageImage, JPATH_ROOT . '/images/watermarks/original' . '/' . md5($my->id . '_avatar') . CImageHelper::getExtension($file['type'])); JFile::copy($storageThumbnail, JPATH_ROOT . '/images/watermarks/original' . '/' . md5($my->id . '_thumb') . CImageHelper::getExtension($file['type'])); $watermarkPath = JPATH_ROOT . '/' . CString::str_ireplace('/', '/', $multiprofile->watermark); list($watermarkWidth, $watermarkHeight) = getimagesize($watermarkPath); list($avatarWidth, $avatarHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); $watermarkImage = $storageImage; $watermarkThumbnail = $storageThumbnail; // Avatar Properties $avatarPosition = CImageHelper::getPositions($multiprofile->watermark_location, $avatarWidth, $avatarHeight, $watermarkWidth, $watermarkHeight); // The original image file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageImage, $watermarkImage, $file['type'], $watermarkPath, $avatarPosition->x, $avatarPosition->y); //Thumbnail Properties $thumbPosition = CImageHelper::getPositions($multiprofile->watermark_location, $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight); // The original thumbnail file will be removed from the system once it generates a new watermark image. CImageHelper::addWatermark($storageThumbnail, $watermarkThumbnail, $file['type'], $watermarkPath, $thumbPosition->x, $thumbPosition->y); $my->set('_watermark_hash', $multiprofile->watermark_hash); } // We need to make a copy of current avatar and set it as stream 'attachement' // which will only gets deleted once teh stream is deleted $my->_cparams->set('avatar_photo_id', $photo->id); //we also set the id of the avatar photo $my->save(); JFile::copy($image, $imageAttachment); $params->set('attachment', $imageAttachment); } //end of storing this picture into default avatar album if (empty($saveAction)) { $cTable->setImage($image, 'avatar'); $cTable->setImage($thumbnail, 'thumb'); } else { // This is for event recurring save option ( current / future event ) $cTable->setImage($image, 'avatar', $saveAction); $cTable->setImage($thumbnail, 'thumb', $saveAction); } // add points & activity stream switch ($type) { case 'profile': /** * Generate activity stream * @todo Should we use CApiActivities::add */ // do not have to generate a stream if the user is not the user itself (eg admin change user avatar) if (CUserPoints::assignPoint('profile.avatar.upload') && $my->id == CFactory::getUser()->id) { $act = new stdClass(); $act->cmd = 'profile.avatar.upload'; $act->actor = $userid; $act->target = 0; $act->title = ''; $act->content = ''; $act->access = $my->_cparams->get("privacyPhotoView", 0); $act->app = 'profile.avatar.upload'; /* Profile app */ $act->cid = isset($photo->id) && $photo->id ? $photo->id : 0; $act->verb = 'upload'; /* We uploaded new avatar - NOT change avatar */ $act->params = $params; $params->set('photo_id', $photo->id); $params->set('album_id', $photo->albumid); $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'profile.avatar.upload'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'profile.avatar.upload'; } break; case 'group': CUserPoints::assignPoint('group.avatar.upload'); /** * Generate activity stream * @todo Should we use CApiActivities::add */ $act = new stdClass(); $act->cmd = 'groups.avatar.upload'; $act->actor = $userid; $act->target = 0; $act->title = ''; $act->content = ''; $act->app = 'groups.avatar.upload'; /* Groups app */ $act->cid = $id; $act->groupid = $id; $act->verb = 'update'; /* We do update */ $params->set('photo_id', $photo->id); $params->set('album_id', $photo->albumid); $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'groups.avatar.upload'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'groups.avatar.upload'; break; case 'event': //CUserPoints::assignPoint('events.avatar.upload'); @disabled since 4.0 /** * Generate activity stream * @todo Should we use CApiActivities::add */ $act = new stdClass(); $act->cmd = 'events.avatar.upload'; $act->actor = $userid; $act->target = 0; $act->title = ''; $act->content = ''; $act->app = 'events.avatar.upload'; /* Events app */ $act->cid = $id; $act->eventid = $id; $act->verb = 'update'; /* We do update */ $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'events.avatar.upload'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'events.avatar.upload'; break; } //we only generate stream if the uploader is the user himself, not admin or anyone else if (isset($act) && $my->id == $id || $type != 'profile') { // $return = CApiActivities::add($act); /** * use internal Stream instead use for 3rd part API */ $return = CActivityStream::add($act, $params->toString()); //add the reference to the activity so that we can do something when someone update the avatar if ($type == 'profile') { // overwrite the params because some of the param might be updated through $my object above $cTableParams = $my->_cparams; } else { $cTableParams = new JRegistry($cTable->params); } $cTableParams->set('avatar_activity_id', $return->id); $cTable->params = $cTableParams->toString(); $cTable->store(); } if (method_exists($cTable, 'getLargeAvatar')) { $this->_showUploadError(false, $cTable->getLargeAvatar(), CUrlHelper::avatarURI($thumbnail, 'user_thumb.png')); } else { $this->_showUploadError(false, $cTable->getAvatar(), CUrlHelper::avatarURI($thumbnail, 'user_thumb.png')); } }
private function parsePost() { $input = new JInput(); $apikey_param = $input->get('api_key', '', 'post'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!$apikey_param) { JFactory::getApplication()->enqueueMessage(JText::_('COM_GETRESPONSE_EMPTY_APIKEY'), 'error'); $url = JUri::getInstance(); $app = JFactory::getApplication(); $app->redirect($url->toString()); } else { $api = new GetResponse($apikey_param); $ping = $api->accounts(); if (!empty($ping) && !isset($ping->accountId)) { JFactory::getApplication()->enqueueMessage(JText::_('COM_GETRESPONSE_INVALID_APIKEY'), 'error'); $url = JUri::getInstance(); $app = JFactory::getApplication(); $app->redirect($url->toString()); } } $success_info = 'COM_GETRESPONSE_SUCCESS'; if ($this->apikey != $apikey_param) { $this->apikey = $apikey_param; $this->setApiKey($apikey_param); $success_info = 'COM_GETRESPONSE_SUCCESS_APIKEY'; } $is_active = $input->get('is_active', '', 'post'); $this->setActiveStatus($is_active); $css_style = $input->get('css_style', '', 'post'); $this->setCssStyle($css_style); $campaign_id = $input->get('campaign_id', '', 'post'); if (!empty($campaign_id)) { $this->setCampaignId($campaign_id); } $active_on_registration = $input->get('active_on_registration', '', 'post'); if (empty($active_on_registration)) { $active_on_registration = 0; } $this->setActiveOnRegistration($active_on_registration); $webform_id = $input->get('webform_id', '', 'post'); if ($webform_id) { $webform = $api->getWebform($webform_id); $generation = $this->web_form_generation_second; if (!empty($webform->webformId)) { $generation = $this->web_form_generation_first; } $this->setWebformId($webform_id); $this->setWebformGeneration($generation); } JFactory::getApplication()->enqueueMessage(JText::_($success_info)); $url = JUri::getInstance(); $app = JFactory::getApplication(); $app->redirect($url->toString()); } else { if ($input->get('disconnect', 0) == 1) { JFactory::getApplication()->enqueueMessage(JText::_('COM_GETRESPONSE_DISCONNECTED')); $this->disconnectIntegration(); $url = JUri::getInstance(); $url->delVar('disconnect'); $app = JFactory::getApplication(); $app->redirect($url->toString()); } } }
public function renderVersionsForClipboard() { if (!JEVHelper::isAdminUser()) { return; } jimport("joomla.filesystem.folder"); $apps = array(); // Joomla $app = new stdClass(); $app->name = "Joomla"; $version = new JVersion(); $app->version = $version->getShortVersion(); $apps[$app->name] = $app; // TODO : Can we do this from the database??? // components (including JEvents) $xmlfiles3 = array_merge(JFolder::files(JPATH_ADMINISTRATOR . "/components", "manifest\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "sh404sef\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "virtuemart\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "jce\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "jmailalerts\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "hikashop\\.xml", true, true), JFolder::files(JPATH_ADMINISTRATOR . "/components", "jev_latestevents\\.xml", true, true)); foreach ($xmlfiles3 as $manifest) { if (!($manifestdata = $this->getValidManifestFile($manifest))) { continue; } $app = new stdClass(); $app->name = $manifestdata["name"]; $app->version = $manifestdata["version"]; // is sh404sef disabled ? if (basename(dirname($manifest)) == "com_sh404sef") { if (is_callable("Sh404sefFactory::getConfig")) { $sefConfig = Sh404sefFactory::getConfig(); if (!$sefConfig->Enabled) { $app->version = $manifestdata["version"] . " (Disabled in SH404 settings)"; } } else { $app->version = $manifestdata["version"] . " (sh404sef system plugins not enabled)"; } } $name = "component_" . basename(dirname($manifest)); $apps[$name] = $app; } // modules if (JFolder::exists(JPATH_SITE . "/modules")) { $xmlfiles4 = JFolder::files(JPATH_SITE . "/modules", "\\.xml", true, true); } else { $xmlfiles4 = array(); } foreach ($xmlfiles4 as $manifest) { if (strpos($manifest, "mod_") === false) { continue; } if (!($manifestdata = $this->getValidManifestFile($manifest))) { continue; } $app = new stdClass(); $app->name = $manifestdata["name"]; $app->version = $manifestdata["version"]; $app->criticalversion = ""; $name = "module_" . str_replace(".xml", "", basename($manifest)); $apps[$name] = $app; } // club layouts $xmlfiles1 = JFolder::files(JEV_PATH . "views", "manifest\\.xml", true, true); foreach ($xmlfiles1 as $manifest) { if (realpath($manifest) != $manifest) { continue; } if (!($manifestdata = $this->getValidManifestFile($manifest))) { continue; } $app = new stdClass(); $app->name = $manifestdata["name"]; $app->version = $manifestdata["version"]; $apps["layout_" . basename(dirname($manifest))] = $app; } $xmlfiles1 = JFolder::files(JPATH_ADMINISTRATOR . "/manifests/files", "\\.xml", true, true); foreach ($xmlfiles1 as $manifest) { if (realpath($manifest) != $manifest) { continue; } if (!($manifestdata = $this->getValidManifestFile($manifest))) { continue; } $app = new stdClass(); $app->name = $manifestdata["name"]; $app->version = $manifestdata["version"]; $apps[str_replace(".xml", "", "layout_" . basename($manifest))] = $app; } // plugins if (JFolder::exists(JPATH_SITE . "/plugins")) { $xmlfiles2 = JFolder::files(JPATH_SITE . "/plugins", "\\.xml", true, true); } else { $xmlfiles2 = array(); } foreach ($xmlfiles2 as $manifest) { if (strpos($manifest, "Zend") > 0) { continue; } if (!($manifestdata = $this->getValidManifestFile($manifest))) { continue; } $app = new stdClass(); $app->name = $manifestdata["name"]; $app->version = $manifestdata["version"]; $name = str_replace(".xml", "", basename($manifest)); $group = basename(dirname(dirname($manifest))); $plugin = JPluginHelper::getPlugin($group, $name); if (!$plugin) { $app->version .= " (not enabled)"; } $name = "plugin_" . $group . "_" . $name; $apps[$name] = $app; } $output = "<textarea rows='40' cols='80' class='versionsinfo'>[code]\n"; $output .= "PHP Version : " . phpversion() . "\n"; $output .= "MySQL Version : " . JFactory::getDbo()->getVersion() . "\n"; $output .= "Server Information : " . php_uname() . "\n"; $params = JComponentHelper::getParams(JEV_COM_COMPONENT); if ($params->get("fixjquery", -1) == -1) { $output .= "*** CONFIG NOT SAVED*** \n"; } $output .= "Fix jQuery? : " . ($params->get("fixjquery", 1) ? "Yes" : "No") . "\n"; $output .= "Load JEvents Bootstrap CSS? : " . ($params->get("bootstrapcss", 1) ? "Yes" : "No") . "\n"; $output .= "Load JEvents Bootstrap JS? : " . ($params->get("bootstrapjs", 1) ? "Yes" : "No") . "\n"; if (ini_get("max_input_vars") > 0 && ini_get("max_input_vars") <= 10000) { $output .= "Max Input Vars ? : " . ini_get("max_input_vars") . "\n"; } $output .= "Club code set? : " . ($params->get("clubcode", false) ? "Yes" : "No") . " \n"; $server = new JInput($_SERVER); $useragent = $server->get('HTTP_USER_AGENT', false, "string"); $output .= $useragent ? "User Agent : " . $useragent . " \n" : ""; foreach ($apps as $appname => $app) { $output .= "{$appname} : {$app->version}\n"; } $output .= "[/code]</textarea>"; return $output; }