/** * Upload new photo, delete old photo * * @param string $delete_photo 'on': delete old photo * @return string filename of new photo (empty = no new photo) * */ function USER_handlePhotoUpload($uid, $delete_photo = '') { global $_CONF, $_TABLES, $LANG24; USES_class_upload(); $upload = new upload(); if (!empty($_CONF['image_lib'])) { $upload->setAutomaticResize(true); if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } } $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png')); if (!$upload->setPath($_CONF['path_images'] . 'userphotos')) { return ''; } $filename = ''; if (!empty($delete_photo) && $delete_photo == 1) { $delete_photo = true; } else { $delete_photo = false; } $curphoto = DB_getItem($_TABLES['users'], 'photo', "uid = " . (int) $uid); if (empty($curphoto)) { $delete_photo = false; } // see if user wants to upload a (new) photo $newphoto = $_FILES['photo']; if (!empty($newphoto['name'])) { $pos = strrpos($newphoto['name'], '.') + 1; $fextension = substr($newphoto['name'], $pos); $filename = $uid . '.' . $fextension; if (!empty($curphoto) && $filename != $curphoto) { $delete_photo = true; } else { $delete_photo = false; } } // delete old photo first if ($delete_photo) { USER_deletePhoto($curphoto); } // now do the upload if (!empty($filename)) { $upload->setFileNames($filename); $upload->setFieldName('photo'); $upload->setPerms('0644'); $upload->setMaxDimensions(1024000, 1024000); $upload->uploadFiles(); if ($upload->areErrors()) { return ''; } IMG_resizeImage($_CONF['path_images'] . 'userphotos/' . $filename, $_CONF['path_images'] . 'userphotos/' . $filename, $_CONF['max_photo_height'], $_CONF['max_photo_width']); } else { if (!$delete_photo && !empty($curphoto)) { $filename = $curphoto; } } return $filename; }
/** * Import events from a CSV file into the database. * * @return string Completion message */ function EVLIST_importEvents() { global $_CONF, $_TABLES, $LANG_EVLIST, $_USER; // Setting this to true will cause import to print processing status to // webpage and to the error.log file $verbose_import = true; $retval = ''; // First, upload the file USES_class_upload(); $upload = new upload(); $upload->setPath($_CONF['path_data']); $upload->setAllowedMimeTypes(array('text/plain' => '.txt, .csv', 'application/octet-stream' => '.txt, .csv')); $upload->setFileNames('evlist_import_file.txt'); $upload->setFieldName('importfile'); if ($upload->uploadFiles()) { // Good, file got uploaded, now install everything $filename = $_CONF['path_data'] . 'evlist_import_file.txt'; if (!file_exists($filename)) { // empty upload form $retval = $LANG_EVLIST['err_invalid_import']; return $retval; } } else { // A problem occurred, print debug information $retval .= $upload->printErrors(false); return $retval; } $fp = fopen($filename, 'r'); if (!$fp) { $retval = $LANG_EVLIST['err_invalid_import']; return $retval; } USES_evlist_class_event(); $success = 0; $failures = 0; // Set owner_id to the current user and group_id to the default $owner_id = (int) $_USER['uid']; if ($owner_id < 2) { $owner_id = 2; } // last resort, use Admin $group_id = (int) DB_getItem($_TABLES['groups'], 'grp_id', 'grp_name="evList Admin"'); if ($group_id < 2) { $group_id = 2; } // last resort, use Root while (($event = fgetcsv($fp)) !== false) { $Ev = new evEvent(); $Ev->isNew = true; $i = 0; $A = array('date_start1' => $event[$i++], 'date_end1' => $event[$i++], 'time_start1' => $event[$i++], 'time_end1' => $event[$i++], 'title' => $event[$i++], 'summary' => $event[$i++], 'full_description' => $event[$i++], 'url' => $event[$i++], 'location' => $event[$i++], 'street' => $event[$i++], 'city' => $event[$i++], 'province' => $event[$i++], 'country' => $event[$i++], 'postal' => $event[$i++], 'contact' => $event[$i++], 'email' => $event[$i++], 'phone' => $event[$i++], 'cal_id' => 1, 'status' => 1, 'hits' => 0, 'recurring' => 0, 'split' => 0, 'time_start2' => '00:00:00', 'time_end2' => '00:00:00', 'owner_id' => $owner_id, 'group_id' => $group_id); if ($_CONF['hour_mode'] == 12) { list($hour, $minute, $second) = explode(':', $A['time_start1']); if ($hour > 12) { $hour -= 12; $am = 'pm'; } elseif ($hour == 0) { $hour = 12; $am = 'am'; } else { $am = 'am'; } $A['start1_ampm'] = $am; $A['starthour1'] = $hour; $A['startminute1'] = $minute; list($hour, $minute, $second) = explode(':', $A['time_end1']); if ($hour > 12) { $hour -= 12; $am = 'pm'; } elseif ($hour == 0) { $hour = 12; $am = 'am'; } else { $am = 'am'; } $A['end1_ampm'] = $am; $A['endhour1'] = $hour; $A['endminute1'] = $minute; } if ($A['time_start1'] == '00:00:00' && $A['time_end1'] == '00:00:00') { $A['allday'] = 1; } else { $A['allday'] = 0; } $msg = $Ev->Save($A); if (empty($msg)) { $successes++; } else { $failures++; } } return "{$successes} Succeeded<br />{$failures} Failed"; }
<?php /** * Class to handle file uploads * * @author Lee Garner <*****@*****.**> * @copyright Copyright (c) 2009 Lee Garner <*****@*****.**> * @package paypal * @version 0.4.0 * @license http://opensource.org/licenses/gpl-2.0.php * GNU Public License v2 or later * @filesource */ // Import core glFusion upload functions USES_class_upload(); /** * Image-handling class * @package paypal */ class ppFile extends upload { //var $properties; var $filenames; /** Array of the names of successfully uploaded files * @var array */ var $goodfiles = array(); /** * Constructor * @param string $varname Optional form variable name */ function ppFile($varname = 'uploadfile')
function _ff_uploadfile($filename, &$upload_file, $allowablefiletypes, $use_filemgmt = 0) { global $_FILES, $_CONF, $_TABLES, $_FF_CONF, $LANG_GF00, $filemgmt_FileStore; USES_class_upload(); $upload = new upload(); if ($use_filemgmt == 1) { $upload->setPath($filemgmt_FileStore); } else { $upload->setPath($_FF_CONF['uploadpath']); } $upload->setLogging(true); $upload->setAllowedMimeTypes($allowablefiletypes); // Set max dimensions as well in case user is uploading a full size image $upload->setMaxDimensions($_FF_CONF['max_uploadimage_width'], $_FF_CONF['max_uploadimage_height']); if (!isset($_FF_CONF['max_uploadimage_size']) || $_FF_CONF['max_uploadimage_size'] == 0) { $upload->setMaxFileSize(100000000); } else { $upload->setMaxFileSize($_FF_CONF['max_uploadimage_size']); } $upload->setAutomaticResize(true); if (strlen($upload_file['name']) > 0) { $upload->setFileNames($filename); $upload->setPerms($_FF_CONF['fileperms']); $upload->_currentFile = $upload_file; // Verify file meets size limitations if (!$upload->_fileSizeOk()) { $upload->_addError('File, ' . $upload->_currentFile['name'] . ', is bigger than the ' . $upload->_maxFileSize . ' byte limit'); } // If all systems check, do the upload if ($upload->checkMimeType() and $upload->_imageSizeOK() and !$upload->areErrors()) { if ($upload->_copyFile()) { $upload->_uploadedFiles[] = $upload->_fileUploadDirectory . '/' . $upload->_getDestinationName(); } } $upload->_currentFile = array(); if ($upload->areErrors() and !$upload->_continueOnError) { $errmsg = "Forum Upload Attachment Error:" . $upload->printErrors(false); COM_errorlog($errmsg); $GLOBALS['ff_errmsg'] = $LANG_GF00['uploaderr'] . ':<br/>' . $upload->printErrors(false); return false; } return true; } else { return false; } return false; }