function handle_uploaded_avatar_pic() { if (isset($_POST['user_filename'])) { $_POST['user_filename'] = Storage::validateFileId($_POST['user_filename']); } if (!empty($_FILES['userfile']['name'])) { // process uploaded image file $myUploadobj = new FileUploader(); $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, 'image'); if (!$file) { throw new PAException(FILE_NOT_UPLOADED, $myUploadobj->error); } } else { // download given image url $avatar_url = trim(@$_REQUEST['avatar_url']); if (!empty($avatar_url) && preg_match("|http://(.*?)/(.*)|", $avatar_url, $m)) { list(, $uf_server, $uf_path) = $m; $file = Storage::save($avatar_url, basename($uf_path), "critical", "image"); if (!$file) { throw new PAException(FILE_NOT_UPLOADED, sprintf(__("Could not retrieve file from URL: %s"), $avatar_url)); } } } if (@$file) { $_POST['user_filename'] = $file; $_POST['avatar_url'] = ''; } }
function header_image() { $header_image_action = $_POST['header_image_option']; $display_header_image = $_POST['desktop_image_display']; if (!empty($_FILES['headerphoto']['name']) && empty($_POST['restore_default'])) { $uploadfile = PA::$upload_path . basename($_FILES['headerphoto']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'headerphoto', true, true, $image_type); if ($file == false) { throw new PAException(GROUP_PARAMETER_ERROR, "File upload error: " . $myUploadobj->error); } $header_image = $file; $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action, 'header_image' => $header_image); return $header_img; } if (isset($_POST['restore_default'])) { $header_image = NULL; $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action, 'header_image' => $header_image); return $header_img; } $header_img = array('display_header_image' => $display_header_image, 'header_image_action' => $header_image_action); return $header_img; }
function handle_uploaded_avatar_pic() { if (!empty($_FILES['userfile']['name'])) { $uploadfile = PA::$upload_path . basename($_FILES['userfile']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type); if ($file == false) { $this->reg_user->msg = $myUploadobj->error; $this->reg_user->error = TRUE; } else { $_POST['user_filename'] = $file; } } else { // IF THE UPLOAD FIELD WAS EMPTY CHECK FOR THE URL FIELD $avatar_url = trim(@$_REQUEST['avatar_url']); if (!empty($avatar_url) && preg_match("|http://(.*?)/(.*)|", $avatar_url, $m)) { //TODO: change to use FileUploader or new storage code. list(, $uf_server, $uf_path) = $m; $uf_basename = preg_replace("[^A-Za-z0-9\\-_\\.]", "_", basename($uf_path)); //FETCH THE IMAGE VIA HTTP AND WRITE IT WHERE AN UPLOADED FILE WOULD GO $uploadfile = PA::$upload_path . $uf_basename; if ($this->reg_user->download($avatar_url, $uploadfile)) { $_POST['user_filename'] = $uf_basename; $_POST['avatar_url'] = ''; } else { $this->reg_user->msg = "Could not retrieve file from URL:" . $avatar_url; $this->reg_user->error = TRUE; } } } }
function do_file_upload() { $uploadfile = PA::$upload_path . basename($_FILES['network_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'network_image', true, true, $image_type); if ($file == false) { $r = array('error' => TRUE, 'error_msg' => $myUploadobj->error); } else { $r = array('error' => FALSE, 'file' => $file); } return $r; }
require_once "api/Tag/Tag.php"; require_once "web/includes/network.inc.php"; require_once "api/ModuleData/ModuleData.php"; include_once "web/languages/english/MessagesHandler.php"; $authorization_required = TRUE; $error = FALSE; $msg = NULL; if (@$_POST['submit'] == 'Submit') { $data = array(); // for ($i = 0; $i < count($_FILES); $i++) { if (!empty($_FILES['userfile_' . $i]['name'])) { $file_name = $_FILES['userfile_' . $i]['name']; $myUploadobj = new FileUploader(); //creating instance of file. $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile_' . $i, TRUE); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $error_file = FALSE; $msg = 'successfully updated'; } } if ($_POST["userfile_url_{$i}"]) { $data[$i]['url'] = $_POST["userfile_url_{$i}"]; } if ($_POST['caption'][$i]) { $data[$i]['title'] = $_POST['caption'][$i]; } if (!empty($_FILES['userfile_' . $i]['name'])) {
$skip_check = array('address'); } $error_post = check_error($skip_check); //validation check if ($error_post['error'] == TRUE) { $error = TRUE; $error_msg = $error_post['error_msg']; } if (!$error_post) { //code to upload the icon image if (!empty($_FILES['inner_logo_image']['name'])) { $uploadfile = PA::$upload_path . basename($_FILES['inner_logo_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $new_inner_logo_image = $myUploadobj->upload_file(PA::$upload_path, 'inner_logo_image', true, true, $image_type); if ($file == false) { $error = TRUE; $error_msg = $file_upload_result['error_msg']; unset($data_icon_image); } else { $data_icon_image = array('inner_logo_image' => $file); } } else { unset($data_icon_image); } //...code to upload the icon image $network_basic_controls = $extra; $network_basic_controls['network_group_title'] = $_POST['network_group_title']; if (!empty($_POST['reciprocated_relationship'])) { $network_basic_controls['reciprocated_relationship'] = NET_YES;
array('caption'=>'Stretch to fit', 'value'=>DESKTOP_IMAGE_ACTION_STRETCH); $image_actions[1] = array('caption'=>'Crop', 'value'=>DESKTOP_IMAGE_ACTION_CROP); $image_actions[2] = array('caption'=>'Tile', 'value'=>DESKTOP_IMAGE_ACTION_TILE); $image_actions[3] = array('caption'=>'Leave it alone', 'value'=>DESKTOP_IMAGE_ACTION_LEAVE); $profile = &$data_var['user_data_general']; if (!empty($_FILES['user_caption_image']['name'])) { $uploadfile = $uploaddir.basename($_FILES['user_caption_image']['name']); $myUploadobj = new FileUploader; //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file($uploaddir,'user_caption_image',true,true,$image_type); if($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $user_caption_image = $file; } } else { $user_caption_image = @$profile['user_caption_image']; } if (@$_POST['profile_type'] == 'general') { $user = get_login_user(); if (isset($_POST['submit'])) {
function create_new_network($_form) { // function checks initial settings for network creation $can_network_be_created = Network::can_network_be_created(); if ($can_network_be_created['error'] == TRUE) { $config_error = TRUE; $error = TRUE; $error_msg = $can_network_be_created['error_msg']; } else { if (!PA::$login_uid) { $config_error = TRUE; } } //form_data is array used for form fields // its initialized by $_form $temp_data['action'] = 'add'; $vartoset = array('address', 'name', 'tagline', 'category', 'desc', 'header_image', 'header_image_option', 'action', 'type', 'network_group_title', 'network_content_moderation'); for ($i = 0; $i < count($vartoset); $i += 1) { $var = $vartoset[$i]; if (!empty($_form[$var])) { $temp_data[$var] = trim($_form[$var]); } if ($var == 'type') { if (isset($_form[$var])) { $temp_data[$var] = $_form[$var]; } } } if (empty($config_error)) { filter_all_post($_form); //filters all data of html $error_post = check_error(); //validation check if ($error_post['error'] == TRUE) { $error = TRUE; $error_msg = $error_post['error_msg']; } if (!$error_post) { //upload file if (!empty($_FILES['network_image']['name'])) { $file_upload_result = do_file_upload(); if ($file_upload_result['error']) { $error = TRUE; $error_msg = $file_upload_result['error_msg']; } else { $header_image = $network_image = $file_upload_result['file']; } } else { //image hidden $header_image = $network_image = @$temp_data['header_image']; } //code to upload the icon image if (!empty($_FILES['inner_logo_image']['name'])) { $uploadfile = PA::$upload_path . basename($_FILES['inner_logo_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'inner_logo_image', true, true, $image_type); if ($file == false) { $error = TRUE; $error_msg = $file_upload_result['error_msg']; unset($data_icon_image); } else { $data_icon_image = array('inner_logo_image' => $file); } } else { unset($data_icon_image); } //...code to upload the icon image $network_basic_controls = PA::$network_defaults; $network_basic_controls['basic']['header_image']['name'] = $header_image; $network_basic_controls['basic']['header_image']['option'] = @$_form['header_image_option'] ? $_form['header_image_option'] : DESKTOP_IMAGE_ACTION_STRETCH; // for title of network group $network_basic_controls['network_group_title'] = ''; $network_basic_controls['network_group_title'] = $_form['network_group_title']; $network_basic_controls['network_content_moderation'] = @$_form['network_content_moderation']; $temp_data['address'] = strtolower($temp_data['address']); $data = array('user_id' => $_SESSION['user']['id'], 'name' => strip_tags($temp_data['name']), 'address' => $temp_data['address'], 'tagline' => strip_tags($temp_data['tagline']), 'category_id' => $temp_data['category'], 'type' => $temp_data['type'], 'description' => $temp_data['desc'], 'extra' => serialize($network_basic_controls), 'created' => time(), 'changed' => time()); //add icon image if (!empty($data_icon_image['inner_logo_image'])) { $data = array_merge($data, $data_icon_image); $temp_data['inner_logo_image'] = $data_icon_image['inner_logo_image']; } $network = new Network(); $network->set_params($data); try { $nid = $network->save(); //default_page_setting($network->address); // populate page_default setting } catch (PAException $e) { $error = TRUE; $error_msg = "{$e->message}"; } if (!empty($nid)) { $_extra = serialize(array('user' => true, 'network' => true, 'groups' => array())); Roles::set_user_role_for_network($network->user_id, ADMINISTRATOR_ROLE, $network->address, $_extra); $location = "http://" . $temp_data['address'] . '.' . PA::$domain_suffix . BASE_URL_REL . PA_ROUTE_CONFIGURE_NETWORK; } } $msg_array = array(); $msg_array['failure_msg'] = @$error_msg; $msg_array['success_msg'] = 7006; $return_array = @array('msg' => $msg_array, 'redirection_url' => $location, 'query_str' => $query_str); } return $return_array; }
$skip_check = array('address'); } $error_post = check_error($skip_check); //validation check if ($error_post['error'] == TRUE) { $error = TRUE; $error_msg = $error_post['error_msg']; } if (!$error_post) { //code to upload the icon image if (!empty($_FILES['inner_logo_image']['name'])) { $uploadfile = $uploaddir . basename($_FILES['inner_logo_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file($uploaddir, 'inner_logo_image', true, true, $image_type); if ($file == false) { $error = TRUE; $error_msg = $file_upload_result['error_msg']; unset($data_icon_image); } else { $data_icon_image = array('inner_logo_image' => $file); } } else { unset($data_icon_image); } //...code to upload the icon image $network_basic_controls = $extra; $network_basic_controls['network_group_title'] = $_POST['network_group_title']; if (!empty($_POST['reciprocated_relationship'])) { $network_basic_controls['reciprocated_relationship'] = NET_YES;
$image_type = 'image'; $file = $myUploadobj->upload_file($uploaddir, 'groupphoto', true, true, $image_type); if ($file == false) { throw new PAException(GROUP_PARAMETER_ERROR, "File upload error: " . $myUploadobj->error); } $upfile = $file; } if (empty($_form['deafult_headerphoto'])) { if (empty($_FILES['headerphoto']['name'])) { $header_image = $_form['header_file']; } else { $uploadfile = $uploaddir . basename($_FILES['headerphoto']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file($uploaddir, 'headerphoto', true, true, $image_type); if ($file == false) { throw new PAException(GROUP_PARAMETER_ERROR, "File upload error: " . $myUploadobj->error); } $header_image = $file; } } else { $header_image = null; } $result = Group::save_new_group($collection_id, $_SESSION['user']['id'], $groupname, $body, $upfile, $group_tags, $group_category, $access, $reg_type, $is_moderated, $header_image, $header_image_action, $display_header_image); $ccid = $result; if (!is_numeric($result)) { throw new PAException(GROUP_CREATION_FAILED, "Group creation failed: " . $result); } else { if (!$_REQUEST['gid']) { //auto email is sent, when a new group is created
private function handleEdit($request_data) { $this->err = ''; $data = $this->filter($request_data); // handle photo upload if (!empty($_FILES)) { foreach ($_FILES as $field_name => $file_info) { if (!empty($file_info['name'])) { $uploadfile = PA::$upload_path . basename($_FILES[$field_name]['name']); $myUploadobj = new FileUploader(); $file = $myUploadobj->upload_file(PA::$upload_path, $field_name, true, true, 'image'); if ($file == false) { $msg = $myUploadobj->error; $this->err .= sprintf(__('Please upload a valid Game Image in %s'), ucfirst($field_name)) . "<br/>"; continue; } else { Storage::link($file, array("role" => "game_image", "user" => PA::$login_user->user_id)); $data[$field_name] = $file; } } else { if (!empty($this->entity->attributes[$field_name])) { $data[$field_name] = $this->entity->attributes[$field_name]; } } } } if (empty($data['name'])) { $this->err .= __("Please supply a name.") . "<br/>"; } if (empty($this->err)) { // sync it TypedGroupEntity::sync($data); } }
function image_uploaded() { if (empty($_FILES['userfile']['name'])) { return false; } else { $uploadfile = PA::$upload_path . basename($_FILES['userfile']['name']); $myUploadobj = new FileUploader(); // creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type); if ($file == false) { throw new CNException(INVALID_ID, "Error uploading image " . $myUploadobj->error); } else { Storage::link($file, array("role" => "event_banner", "user" => PA::$login_user->user_id)); return $file; } } }
/********/ $error = FALSE; if (!$configure_permission) { $error = TRUE; $permission_denied_msg = "Sorry! you are not authorized to view content of this page"; } if (@$_GET['msg_id']) { $error_msg = MessagesHandler::get_message($_GET['msg_id']); } if (@$_POST['submit'] == 'Submit') { if (!empty($_FILES['userfile_0']['name'])) { $file_name = $_FILES['userfile_0']['name']; $uploadfile = $uploaddir . basename($file_name); $myUploadobj = new FileUploader(); //creating instance of file. $file = $myUploadobj->upload_file($uploaddir, 'userfile_0' . $i, TRUE); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $error_file = FALSE; $msg = 'successfully updated'; } } $data = array(); if ($_POST["userfile_url_0"]) { $data[0]['url'] = $_POST["userfile_url_0"]; } if ($_POST['caption'][0]) { $data[0]['title'] = $_POST['caption'][0]; }
private function handlePOST_addChild($request_data) { global $error_msg; $error = FALSE; $login_name = trim($_POST['login_name']); $first_name = stripslashes(trim($_POST['first_name'])); $last_name = stripslashes(trim($_POST['last_name'])); $email = trim($_POST['email']); $password = trim($_POST['password']); $use_parent_email = $_POST['use_parent_email']; //echo "<pre>".print_r($_POST, 1)."</pre>"; die(); if (!isset($_POST['state'])) { if (isset($_POST['stateOther'])) { $_POST['state'] = $_POST['stateOther']; } } if (isset($_POST['stateOther'])) { unset($_POST['stateOther']); } $msg = NULL; if (!Validation::validate_email($email) && !empty($_POST['email'])) { $email_invalid = TRUE; $error = TRUE; $msg .= '<br> Email address is not valid'; } if (User::user_exist($login_name)) { $msg = "Username {$login_name} is already taken"; $error = TRUE; } if ($error == FALSE) { $newuser = new User(); $newuser->login_name = $login_name; $newuser->password = $password; $newuser->first_name = $first_name; $newuser->last_name = $last_name; $newuser->email = $email; $newuser->is_active = ACTIVE; if (!empty($_FILES['userfile']['name'])) { $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $newuser->picture = $file; } } if ($error == FALSE) { try { if ($use_parent_email) { $newuser->save($check_unique_email = false); } else { $newuser->save($check_unique_email = true); } if (!empty($file)) { Storage::link($file, array("role" => "avatar", "user" => $newuser->user_id)); } // creating message basic folders Message::create_basic_folders($newuser->user_id); // adding default relation if ($newuser->user_id != SUPER_USER_ID) { User_Registration::add_default_relation($newuser->user_id, PA::$network_info); } // adding default media as well as album User_Registration::add_default_media($newuser->user_id, '', PA::$network_info); User_Registration::add_default_media($newuser->user_id, '_audio', PA::$network_info); User_Registration::add_default_media($newuser->user_id, '_video', PA::$network_info); User_Registration::add_default_blog($newuser->user_id); //adding default link categories & links User_Registration::add_default_links($newuser->user_id); // code for adding default desktop image for user $desk_img = uihelper_add_default_desktopimage($newuser->user_id); if (empty($desk_img)) { $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg'); $rand_key = array_rand($desktop_images); $desk_img = $desktop_images[$rand_key]; } $states = array_values(PA::getStatesList()); $countries = array_values(PA::getCountryList()); $profile_keys = array('dob_day', 'dob_month', 'dob_year', 'homeAddress1', 'homeAddress2', 'city', 'state', 'country', 'postal_code', 'phone', 'use_parent_email'); $profile_data = array(); filter_all_post($_POST); //filters all data of html foreach ($profile_keys as $k => $pkey) { if (!empty($_POST[$pkey])) { if ($pkey == 'state' && $_POST[$pkey] >= 0) { $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $states[$_POST[$pkey]], 'type' => GENERAL, 'perm' => 1); } else { if ($pkey == 'country' && $_POST[$pkey] >= 0) { $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $countries[$_POST[$pkey]], 'type' => GENERAL, 'perm' => 1); } else { $prof_rec = array('uid' => $newuser->user_id, 'name' => $pkey, 'value' => $_POST[$pkey], 'type' => GENERAL, 'perm' => 1); } } $profile_data[] = $prof_rec; } } $profile_data[] = array('uid' => $newuser->user_id, 'name' => 'user_caption_image', 'value' => $desk_img, 'type' => GENERAL, 'perm' => 1); // echo "<pre>".print_r($profile_data,1)."</pre>"; $newuser->save_user_profile($profile_data, GENERAL); //if new user is created in a network then he must set as a joined user if (!empty(PA::$network_info)) { $by_admin = true; Network::join(PA::$network_info->network_id, $newuser->user_id, NETWORK_MEMBER, $by_admin); // $by_admin = true overrides the // user_waiting status if it would get set // this is an admin action, so we want it to happen in any case } $user_joined = $this->family->join((int) $newuser->user_id, $newuser->email, null); if ($user_joined) { // deal with TypedGroup Relations require_once "api/Entity/TypedGroupEntityRelation.php"; $type = 'child'; TypedGroupEntityRelation::set_relation($newuser->user_id, $this->family->collection_id, $type); if ($type == 'child') { // if user type == child remove LoginUser and GroupMember roles $newuser->delete_user_role(); // then assign 'Child' role only $_extra = serialize(array('user' => false, 'network' => false, 'groups' => array($this->family->collection_id))); $user_roles[] = array('role_id' => CHILD_MEMBER_ROLE, 'extra' => $_extra); $newuser->set_user_role($user_roles); } } $msg = __("Child's account was successfully created"); } catch (PAException $e) { $msg = $e->message; } } // end if } //end if $error_msg = $msg; }
/** !! ************************************************************************ * The following methods take the request data, validate it, parse it, * and store it if there were no previous errors. ************************************************************************ */ public function basicProfileSave($request_data) { global $error_msg; $this->isError = TRUE; if (empty($request_data['first_name'])) { $this->message = __('Fields marked with * can not be empty, First name can not be empty.'); } else { if (empty($request_data['email_address'])) { $this->message = __('Fields marked with * can not be empty, Email field is mandatory.'); } else { if (!empty($request_data['pass']) || !empty($request_data['conpass'])) { $set_new_password = true; $new_password_ok = false; if ($request_data['pass'] != $request_data['conpass']) { $this->message = __('Password and confirm password should match.'); } else { if (strlen($request_data['pass']) < PA::$password_min_length) { $this->message = sprintf(__('Password should be of %s characters or more.'), PA::$password_min_length); } else { if (strlen($request_data['pass']) > PA::$password_max_length) { $this->message = sprintf(__('Password should be less than %s charcaters.'), PA::$password_max_length); } else { // all is good $new_password_ok = true; } } } } } } if ($request_data['deletepicture'] == "true") { $this->handleDeleteUserPic($request_data); } if (empty($this->message) && !empty($_FILES['userfile']['name'])) { $uploadfile = PA::$upload_path . basename($_FILES['userfile']['name']); $myUploadobj = new FileUploader(); $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, 'image'); if ($file == false) { $this->message = $myUploadobj->error; $error = TRUE; } else { $this->user_info->picture = $file; Storage::link($file, array("role" => "avatar", "user" => $user->user_id)); } } if (empty($this->message)) { //If there is no error message then try saving the user information. $this->user_info->first_name = $request_data['first_name']; $this->user_info->last_name = $request_data['last_name']; $this->user_info->email = $request_data['email_address']; if (!empty($request_data['pass'])) { $this->user_info->password = md5($request_data['pass']); } try { $this->user_info->save(); $dynProf = new DynamicProfile(PA::$login_user); $dynProf->processPOST('basic'); $dynProf->save('basic'); $this->message = __('Profile updated successfully.'); // $this->redirect2 = PA_ROUTE_EDIT_PROFILE; // $this->queryString = '?type='.$this->profile_type; $this->isError = FALSE; } catch (PAException $e) { $this->message = $e->message; } } $error_msg = $this->message; }
} $form_data['extra']['user_defaults']['user_friends'] = $comma_separated; } else { $form_data['extra']['user_defaults']['user_friends'] = $related; } } //.. end of $_POST['user_friends'] // if nothing is supplied if (empty($_POST['relate_me']) && empty($_POST['user_friends'])) { $form_data['extra']['user_defaults']['user_friends'] = ''; } //user's default desktop image start if (!empty($_FILES['desktop_image']['name'])) { $myUploadobj = new FileUploader(); //creating instance of file. $file = $myUploadobj->upload_file(PA::$upload_path, 'desktop_image', true, true, 'image'); if (!$file) { $error_msg = $myUploadobj->error; $error = TRUE; } else { $form_data['extra']['user_defaults']['desktop_image']['name'] = $file; } } //image options stretch, crop or tile $form_data['extra']['user_defaults']['desktop_image']['option'] = $_POST['header_image_option'] ? $_POST['header_image_option'] : DESKTOP_IMAGE_ACTION_STRETCH; $form_data['extra']['user_defaults']['desktop_image']['display'] = $_POST['desktop_image_display']; //image album if (isset($_POST['multiple_images'])) { $image_albums[] = $_POST['multiple_images']; foreach ($image_albums as $image) { $comma_separated_image = implode(',', $image);
function uihelper_upload_gallery_for_group($uid, $type, $k = 0) { require_once "api/User/User.php"; require_once "api/Tag/Tag.php"; require_once "api/Album/Album.php"; require_once "api/Image/Image.php"; require_once "api/Audio/Audio.php"; require_once "api/Video/Video.php"; require_once "web/includes/classes/CNFileUploader.php"; $logged_in_user = get_login_user(); $user = new User(); $media_count_no = $k; $error_file = NULL; $uploaded = False; if ($type == '') { $file_type = "image"; $alb_type = IMAGE_ALBUM; $new_img = new Image(); $new_img->file_perm = @$_POST['image_perm']; } elseif ($type == '_audio') { $file_type = "audio"; $alb_type = AUDIO_ALBUM; $new_img = new Audio(); $new_img->file_perm = @$_POST['audio_perm']; } elseif ($type == '_video') { $file_type = "video"; $alb_type = VIDEO_ALBUM; $new_img = new Video(); $new_img->file_perm = @$_POST['video_perm']; } //file uploading start $file_name_dynamic = "userfile{$type}" . "_" . "{$k}"; $file_name_dynamic_type = $file_name_dynamic; //"$file_name_dynamic"."$type"; $newname = $_FILES[$file_name_dynamic_type]['name']; $uploadfile = PA::$upload_path . basename($_FILES[$file_name_dynamic_type]['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = "{$file_type}"; $value = $file_name_dynamic_type; $file = $myUploadobj->upload_file(PA::$upload_path, $value, true, true, $image_type); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $new_img->file_name = "{$file}"; $error_file = FALSE; } // file uploading end if (empty($error)) { try { $user->load((int) $uid); $action = !empty($_GET['action']) ? $_GET['action'] : 'upload'; $colls = Album::load_all($uid, $alb_type); if (isset($_POST['submit' . $type]) && $action != 'delete' && $error_file == FALSE) { $new_img->author_id = $uid; if ($type == '_audio') { $new_img->type = AUDIO; } elseif ($type == '_video') { $new_img->type = VIDEO; } else { $new_img->type = IMAGE; } if (empty($_POST['caption' . $type][$k])) { $ext = explode(".", $newname); $_POST['caption' . $type][$k] = $ext[0]; } $new_img->title = stripslashes(trim($_POST['caption' . $type][$k])); $new_img->title = strip_tags($new_img->title); $new_img->file_perm = ANYONE; $new_img->excerpt = stripslashes(trim($_POST['caption' . $type][$k])); $new_img->excerpt = strip_tags($new_img->excerpt); if (empty($_POST['body' . $type][$k])) { $new_img->body = ''; $new_img->body = strip_tags($new_img->body); } else { $new_img->body = stripslashes(trim($_POST['body' . $type][$k])); $new_img->body = strip_tags($new_img->body); } $new_img->allow_comments = 1; $new_img->parent_collection_id = $_POST['group_id']; $new_img->save(); if (!empty($_POST['tags' . $type][$media_count_no])) { $tag_array = Tag::split_tags($_POST['tags' . $type][$media_count_no]); Tag::add_tags_to_content($new_img->content_id, $tag_array); } } else { throw new CNException(USER_NOT_FOUND, 'unable to upload file.'); } if (!empty($msg)) { $uploaded = FALSE; } else { $uploaded = TRUE; if (isset($_REQUEST['gid'])) { $mail_type = "group_media_uploaded"; $new_img->group_id = $_REQUEST['gid']; } else { $mail_type = "media_uploaded"; } PANotify::send($mail_type, PA::$network_info, PA::$login_user, $new_img); } } catch (CNException $e) { $msg = "{$e->message}"; $error = TRUE; } } $array_of_error_message = array(@$error, @$msg, @$error_file, @$uploaded, 'collection_id' => $new_img->parent_collection_id, 'content_id' => $new_img->content_id); return $array_of_error_message; }
function initializeModule($request_method, $request_data) { global $error_msg; $error = false; $msg = array(); $form_data = NULL; $edit = false; $message = NULL; // check permissions! $user_may = false; $user_may = PermissionsHandler::can_user(PA::$login_uid, array('permissions' => 'manage_ads')); // check for manageads of group permissions if (!empty($_REQUEST['gid']) && !$user_may) { // we do this checl only if the user is not already permitted to manage ads $gp_access = PermissionsHandler::can_group_user(PA::$login_uid, $_REQUEST['gid'], array('permissions' => 'manage_ads')); $user_may = $gp_access; } if (!$user_may) { $error_msg = __("You do not have permission to manage Ads."); return "skip"; } // paging if (!empty($request_data['page'])) { $this->Paging["page"] = (int) $request_data['page']; } if (!empty($request_data['action']) && $request_data['action'] == 'edit' && !empty($request_data['ad_id'])) { $edit = TRUE; $res = Advertisement::get($params = NULL, $condition = array('ad_id' => (int) $request_data['ad_id'])); if (!empty($res)) { $form_data['ad_id'] = $res[0]->ad_id; $form_data['ad_image'] = $res[0]->ad_image; $form_data['ad_script'] = $res[0]->ad_script; $form_data['ad_url'] = $res[0]->url; $form_data['ad_title'] = $res[0]->title; $form_data['ad_description'] = $res[0]->description; $form_data['ad_page_id'] = $res[0]->page_id; $form_data['orientation'] = $res[0]->orientation; $form_data['created'] = $res[0]->created; } } else { if (!empty($request_data['action']) && $request_data['action'] == 'delete' && !empty($request_data['ad_id'])) { if (!empty($request_data['ad_id'])) { try { Advertisement::delete((int) $request_data['ad_id']); $error_msg = 19013; } catch (CNException $e) { $msg[] = $e->message; } } } else { if (!empty($request_data['action']) && !empty($request_data['ad_id'])) { $update = false; switch ($request_data['action']) { case 'disable': $field_value = DELETED; $msg_id = 19010; $update = true; break; case 'enable': $field_value = ACTIVE; $msg_id = 19011; $update = true; break; } if ($update) { $update_fields = array('is_active' => $field_value); $condition = array('ad_id' => $request_data['ad_id']); try { Advertisement::update($update_fields, $condition); $error_msg = $msg_id; } catch (CNException $e) { $msg[] = $e->message; } } } } } $advertisement = new Advertisement(); if (!$error && $request_method == 'POST' && $request_data['btn_apply_name']) { // if page is submitted if (!empty($request_data['ad_id'])) { $advertisement->ad_id = $request_data['ad_id']; $advertisement->created = $request_data['created']; $msg_id = 19007; } else { $msg_id = 19008; $advertisement->created = time(); } if (!empty($_FILES['ad_image']['name'])) { $filename = $_FILES['ad_image']['name']; $uploadfile = PA::$upload_path . basename($filename); $myUploadobj = new FileUploader(); $file = $myUploadobj->upload_file(PA::$upload_path, 'ad_image', TRUE, TRUE, 'image'); $advertisement->ad_image = $form_data['ad_image'] = $file; if ($file == FALSE) { $error = TRUE; $msg[] = $myUploadobj->error; } } else { if (!empty($request_data['ad_id'])) { $advertisement->ad_image = $request_data['edit_image']; } } if (empty($request_data['ad_url']) && empty($request_data['ad_script'])) { $error = TRUE; $msg[] = MessagesHandler::get_message(19012); } if (!empty($request_data['ad_url'])) { // if url is given then validate $request_data['ad_url'] = Validation::validate_url($request_data['ad_url']); if (!Validation::isValidURL($request_data['ad_url'])) { $error = TRUE; $msg[] = MessagesHandler::get_message(19009); } } $advertisement->user_id = PA::$login_uid; $advertisement->url = $form_data['ad_url'] = $request_data['ad_url']; $advertisement->ad_script = $form_data['ad_script'] = $request_data['ad_script']; $advertisement->title = $form_data['ad_title'] = $request_data['ad_title']; $advertisement->description = $form_data['ad_description'] = $request_data['ad_description']; $advertisement->page_id = $form_data['ad_page_id'] = $request_data['ad_page_id']; $advertisement->orientation = $form_data['orientation'] = $request_data['x_loc'] . ',' . $request_data['y_loc']; $advertisement->changed = time(); $advertisement->is_active = ACTIVE; if (!empty($_REQUEST['gid'])) { $advertisement->group_id = (int) $_REQUEST['gid']; } if (!$error) { try { $ad_id = $advertisement->save(); if (!empty($file)) { Storage::link($file, array("role" => "ad", "ad" => $ad_id)); } $error_msg = $msg_id; } catch (CNException $e) { $error_msg = $e->message; } } else { $error_msg = implode("<br/>", $msg); } } $this->form_data = $form_data; $this->edit = $edit; $this->message = $message; }
$advertisement = new Advertisement(); if (!$error && !empty($_POST) && $_POST['btn_apply_name']) { // if page is submitted if (!empty($_POST['ad_id'])) { $advertisement->ad_id = $_POST['ad_id']; $advertisement->created = $_POST['created']; $msg_id = 19007; } else { $msg_id = 19008; $advertisement->created = time(); } if (!empty($_FILES['ad_image']['name'])) { $filename = $_FILES['ad_image']['name']; $uploadfile = $uploaddir . basename($file_name); $myUploadobj = new FileUploader(); $file = $myUploadobj->upload_file($uploaddir, 'ad_image', TRUE, TRUE, 'image'); $advertisement->ad_image = $form_data['ad_image'] = $file; if ($file == FALSE) { $error = TRUE; $msg[] = $myUploadobj->error; } } else { if (!empty($_POST['ad_id'])) { $advertisement->ad_image = $_POST['edit_image']; } } if (empty($_POST['ad_url']) && empty($_POST['ad_script'])) { $error = TRUE; $msg[] = MessagesHandler::get_message(19012); } if (!empty($_POST['ad_url'])) {
} } } //code for fields which are common to some sections like description, image if ($section == 'video_tours' || $section == 'register_today' || $section == 'network_of_moment' || $section == 'server_announcement' || $section == 'showcase') { if (empty($_POST['description'])) { $message[] = __('No description provided for network of moment'); } else { $networks_data['description'] = $_POST['description']; } $image_file = 'network_image'; if (!empty($_FILES[$image_file]['name'])) { //validating and then uploading the network image. $uploader = new FileUploader(); //creating instance of file. $file = $uploader->upload_file(PA::$upload_path, $image_file, true, true, 'image'); if ($file == false) { $message[] = __(' For network of moment, ') . $uploader->error; $networks_data['network_image'] = null; } else { $networks_data['network_image'] = $file; } } else { if (!empty($_POST['current_network_image'])) { //getting the previously added image from the hidden form field. $networks_data['network_image'] = $_POST['current_network_image']; } else { //setting the image to null. $networks_data['network_image'] = null; } }
} else { $form_data['extra']['user_defaults']['user_friends'] = $related; } } //.. end of $_POST['user_friends'] // if nothing is supplied if ($_POST['relate_me'] != 1 && $_POST['user_friends'] == '') { $form_data['extra']['user_defaults']['user_friends'] = ''; } //user's default desktop image start if (!empty($_FILES['desktop_image']['name'])) { $uploadfile = $uploaddir . basename($_FILES['desktop_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $file_type = 'image'; $file = $myUploadobj->upload_file($uploaddir, 'desktop_image', true, true, $file_type); if ($file == false) { $msg_pro = $myUploadobj->error; $error = TRUE; } else { $form_data['extra']['user_defaults']['desktop_image']['name'] = $file; } } //image options stretch, crop or tile $form_data['extra']['user_defaults']['desktop_image']['option'] = $_POST['header_image_option'] ? $_POST['header_image_option'] : DESKTOP_IMAGE_ACTION_STRETCH; $form_data['extra']['user_defaults']['desktop_image']['display'] = $_POST['desktop_image_display']; //image album if ($_POST['multiple_images']) { $image_albums[] = $_POST['multiple_images']; foreach ($image_albums as $image) { $comma_separated_image = implode(',', $image);
case '7': $error = 'Failed to write file to disk'; break; case '8': $error = 'File upload stopped by extension'; break; case '999': default: $error = 'No error code avaiable'; } } elseif (empty($_FILES['userfile']['tmp_name']) || $_FILES['userfile']['tmp_name'] == 'none') { $error = 'No file was uploaded..'; } else { try { $myUploadobj = new FileUploader(); $image_file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, 'image'); if (!$image_file) { $error = $myUploadobj->error; } } catch (Exception $e) { $error = $e->getMessage(); } $img_resized = uihelper_resize_mk_img($image_file, 200, 200, NULL, 'style="margin-left: 10px"'); } echo "{"; echo "error: '" . $error . "',\n"; echo "image: '" . htmlspecialchars($img_resized) . "',\n"; echo "image_file: '" . $image_file . "'\n"; echo "}"; } else { if (preg_match("|http://(.*?)/(.*)|", $img_url, $m)) {
$form_data[$var] = $_POST[$var]; } } if ($error == FALSE) { $newuser->login_name = $login_name; $newuser->password = $password; $newuser->first_name = $first_name; $newuser->last_name = $last_name; $newuser->email = $email; $newuser->is_active = ACTIVE; if (!empty($_FILES['userfile']['name'])) { $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file($uploaddir, 'userfile', true, true, $image_type); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $newuser->picture = $file; } } if ($error == FALSE) { try { $newuser->save(); // saving data in user profile data also -- for searching making more easier $data_array = array(0 => array('uid' => $newuser->user_id, 'name' => 'first_name', 'value' => "{$newuser->first_name}", 'type' => BASIC, 'perm' => 1), 1 => array('uid' => $newuser->user_id, 'name' => 'last_name', 'value' => "{$newuser->last_name}", 'type' => BASIC, 'perm' => 1)); $newuser->save_user_profile($data_array, BASIC); // creating message basic folders Message::create_basic_folders($newuser->user_id);
if (!empty($_POST[$var])) { $form_data[$var] = $_POST[$var]; } } if ($error == FALSE) { $newuser->login_name = $login_name; $newuser->password = $password; $newuser->first_name = $first_name; $newuser->last_name = $last_name; $newuser->email = $email; $newuser->is_active = ACTIVE; if (!empty($_FILES['userfile']['name'])) { $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'userfile', true, true, $image_type); if ($file == false) { $msg = $myUploadobj->error; $error = TRUE; } else { $newuser->picture = $file; } } if ($error == FALSE) { try { $newuser->save(); if (!empty($file)) { Storage::link($file, array("role" => "avatar", "user" => $newuser->user_id)); } // creating message basic folders Message::create_basic_folders($newuser->user_id);
/** !! * Get the uploaded image, giving an error if it is empty. The switch * statement is left empty for user and group as background image is a * feature of neither. Redirect to the same url at the end to refresh * the page. * Finally redirct the page to the same url to refresh it with the changes. * @param string $request_data contains the from with the image information */ private function handlePOST_applyBackgroundImage($request_data) { global $error, $error_msg; $form_data = $request_data['form_data']; if (!empty($_FILES['network_image']['name'])) { $uploadfile = PA::$upload_path . basename($_FILES['network_image']['name']); $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'network_image', true, true, $image_type); if ($file == false) { $error_msg = $myUploadobj->error; $error = TRUE; } else { $backgr_image = $file; // Storage::link($header_image, array("role" => "header", "user" => PA::$login_user->user_id)); } } else { $backgr_image = isset($form_data['backgr_image_name']) ? $form_data['backgr_image_name'] : null; } switch ($this->settings_type) { case 'user': break; case 'group': break; case 'network': $network =& $this->shared_data['network_info']; $extra =& $this->shared_data['extra']; $extra['basic']['background_image']['name'] = $backgr_image; $data = array('extra' => serialize($extra), 'network_id' => $network->network_id, 'changed' => time()); $network->set_params($data); try { $nid = $network->save(); $network = get_network_info(); // refreshing the network info } catch (PAException $e) { $error_msg = "{$e->message}"; } $this->setupCustomizeBackgroundImage($request_data); break; } unset($_FILES); unset($request_data['form_data']); $this->controller->redirect($this->url); }
/** !! * This handles the data that is POSTed back to the page upon * submission of the form. There is a lot happening in here, * but it basically looks at the submitted data, figures out * what it is supposed to do with it (based on if the group is * being created or modified), then creates a new group or * updates the current data using the {@link handle_entity() } method. * * @param array $request_data All of the data POSTed back to the form. */ public function handlePOST($request_data) { require_once "web/includes/classes/CNFileUploader.php"; require_once "api/CNActivities/CNActivities.php"; require_once "api/cnapi_constants.php"; if ($request_data['addgroup']) { filter_all_post($request_data); $groupname = trim($request_data['groupname']); $body = trim($request_data['groupdesc']); $tag_entry = trim($request_data['group_tags']); $group_category = $request_data['group_category']; $header_image = NULL; $header_image_action = @$request_data['header_image_action']; $display_header_image = @$request_data['display_header_image']; $collection_id = NULL; $this->extra = NULL; if ($request_data['ccid']) { $collection_id = (int) $request_data['ccid']; $group = new Group(); $group->load($collection_id); // preserve group info we are not editing in this module // load group extra $extra = $group->extra; if (!empty($extra)) { $this->extra = unserialize($extra); } $header_image = $group->header_image; $header_image_action = $group->header_image_action; $display_header_image = $group->display_header_image; } $access = 0; // default access is 0 means public $reg_type = $request_data['reg_type']; if ($reg_type == REG_INVITE) { // if reg. type = "Invite" access is PRIVATE $access = ACCESS_PRIVATE; } $is_moderated = 0; // is moderated is 0 means contents appear immediately $group_tags = $request_data['group_tags']; if (empty($request_data['groupname'])) { $error_msg = 90222; } else { if (empty($group_category) && empty($error_msg)) { $error_msg = 90224; } else { if (empty($error_msg)) { try { if (empty($_FILES['groupphoto']['name'])) { $upfile = $request_data['file']; } else { $myUploadobj = new FileUploader(); //creating instance of file. $image_type = 'image'; $file = $myUploadobj->upload_file(PA::$upload_path, 'groupphoto', true, true, $image_type); if ($file == false) { throw new CNException(GROUP_PARAMETER_ERROR, __("File upload error: ") . $myUploadobj->error); } $upfile = $file; $avatar_uploaded = TRUE; } $exception_message = NULL; $result = Group::save_new_group($collection_id, $_SESSION['user']['id'], $groupname, $body, $upfile, $group_tags, $group_category, $access, $reg_type, $is_moderated, $header_image, $header_image_action, $display_header_image, $this->extra); $ccid = $result; $exception_message = 'Group creation failed: ' . $result; if (!is_numeric($result)) { throw new CNException(GROUP_CREATION_FAILED, $exception_message); } else { if (@$avatar_uploaded) { Storage::link($upfile, array("role" => "avatar", "group" => (int) $result)); } if (@$header_uploaded) { Storage::link($header_image, array("role" => "header", "group" => (int) $result)); } $this->gid = $this->id = $result; if (empty($request_data['gid'])) { $mail_type = $activity = 'group_created'; $act_text = ' created a new group'; } else { $mail_type = $activity = 'group_settings_updated'; $act_text = ' changed group settings '; } $group = new Group(); $group->load((int) $this->gid); PANotify::send($mail_type, PA::$network_info, PA::$login_user, $group); // notify network onwer $_group_url = PA::$url . PA_ROUTE_GROUP . '/gid=' . $result; $group_owner = new User(); $group_owner->load((int) $_SESSION['user']['id']); $activity_extra['info'] = $group_owner->first_name . $act_text; $activity_extra['group_name'] = $groupname; $activity_extra['group_id'] = $result; $activity_extra['group_url'] = $_group_url; $extra = serialize($activity_extra); $object = $result; if ($reg_type != REG_INVITE) { Activities::save($group_owner->user_id, $activity, $object, $extra); } // if we reached here than the group is created if (empty($request_data['gid'])) { // when a new group is created // so, we need to assign group admin role to group owner now: $role_extra = array('user' => false, 'network' => false, 'groups' => array($this->gid)); $user_roles[] = array('role_id' => GROUP_ADMIN_ROLE, 'extra' => serialize($role_extra)); $group_owner->set_user_role($user_roles); } if (!empty(PA::$config->useTypedGroups) && !empty($request_data['type'])) { $this->gid = $this->id; switch ($request_data['op']) { case 'create_entity': case 'edit_entity': $this->handleEntity($request_data); break; } } } } catch (CNException $e) { if ($e->code == GROUP_PARAMETER_ERROR) { $error_msg = $e->message; if (empty($groupname)) { $error_msg = 90222; } else { if (empty($group_category)) { $error_msg = 90224; } } } else { $error_msg = $e->message; } } } } } } //if form is posted $msg_array = array(); $msg_array['failure_msg'] = @$error_msg; $msg_array['success_msg'] = !empty($this->id) ? 90231 : 90221; $redirect_url = PA::$url . PA_ROUTE_GROUP; $query_str = "?gid=" . @$result; set_web_variables($msg_array, $redirect_url, $query_str); }
} } } //code for fields which are common to some sections like description, image if ($section == 'video_tours' || $section == 'register_today' || $section == 'network_of_moment' || $section == 'server_announcement') { if (empty($_POST['description'])) { $message[] = 'No description provided for network of moment'; } else { $networks_data['description'] = $_POST['description']; } $image_file = 'network_image'; if (!empty($_FILES[$image_file]['name'])) { //validating and then uploading the network image. $uploader = new FileUploader(); //creating instance of file. $file = $uploader->upload_file($uploaddir, $image_file, true, true, 'image'); if ($file == false) { $message[] = ' For network of moment, ' . $uploader->error; $networks_data['network_image'] = null; } else { $networks_data['network_image'] = $file; } } else { if (!empty($_POST['current_network_image'])) { //getting the previously added image from the hidden form field. $networks_data['network_image'] = $_POST['current_network_image']; } else { //setting the image to null. $networks_data['network_image'] = null; } }