public static function save_suggestion($cid, $uid, $title, $body, $track, $tags, $ccid = 0, $is_active = 1, $display_on = 0, $is_default_content = FALSE) { // global var $path_prefix has been removed - please, use PA::$path static variable $errors = array(); // ensure integers here $cid = (int) $cid; $uid = (int) $uid; $ccid = (int) $ccid; // if a new post, make one, otherwise load the existing one if ($cid) { $post = Content::load_content($cid, $uid); // ignore $ccid passed to function if the post already exists // - we don't allow users to move posts between // ContentCollections. $ccid = (int) $post->parent_collection_id; } else { $post = new Suggestion(); $post->author_id = $uid; if ($ccid) { $post->parent_collection_id = $ccid; } } if ($ccid && $ccid != -1) { $g = ContentCollection::load_collection($ccid, $uid); $g->assert_user_access($uid); } else { $g = NULL; } $post->title = $title; $post->body = $body; $post->allow_comments = 1; $post->is_active = $is_active; $post->display_on = $display_on; $post->trackbacks = ''; if ($track) { $post->trackbacks = implode(",", $track); } $post->is_default_content = $is_default_content; $post->save(); //if ($tags) { Tag::add_tags_to_content($post->content_id, $tags); //} if ($track) { foreach ($track as $t) { if (!$post->send_trackback($t)) { $errors[] = array("code" => "trackback_failed", "msg" => "Failed to send trackback", "url" => $t); } } } if ($g && !$cid) { // new post - post it to the group as well $g->post_content($post->content_id, $uid); } if (!$cid) { // add to suggestion queue automatically if not editing ModerationQueue::moderate_suggestion($post->content_id); } return array("cid" => (int) $post->content_id, "moderation_required" => $g ? $g->is_moderated == 1 && $g->author_id != $uid : FALSE, "errors" => $errors); }
$new_save->parent_collection_id = $_POST['album']; } if (!$error) { $condition = array('content_id' => $new_save->content_id); $is_active = ACTIVE; if ($extra['network_content_moderation'] == NET_YES) { $content = Content::load_all_content_for_moderation(NULL, $condition); if (!empty($content)) { $is_active = $content[0]['is_active']; } } $new_save->is_active = $is_active; $new_save->save(); if (!empty($_POST['tags'])) { $tag_array = Tag::split_tags($_POST['tags']); Tag::add_tags_to_content($new_save->content_id, $tag_array); } $album_id = $_POST['album']; $album = "&album_id=" . $album_id; header("Location: media_gallery.php?msg_id=2007&uid=" . $_SESSION['user']['id'] . "&type=" . $module . $album); } } } $user = new User(); $user->load((int) $uid); function setup_module($column, $moduleName, $obj) { global $show_media, $users, $uid, $cc_info, $user, $_REQUEST; switch ($column) { case 'left': $obj->mode = PUB;
public static function add_default_media($user_id, $type = '', $network_info = NULL) { // global var $path_prefix has been removed - please, use PA::$path static variable require_once "api/CNUser/CNUser.php"; require_once "api/CNAlbum/CNAlbum.php"; require_once "api/CNImage/CNImage.php"; require_once "api/CNAudio/CNAudio.php"; require_once "api/CNVideo/CNVideo.php"; require_once "api/CNContentCollection/CNContentCollection.php"; //$extra contains networks extra information $extra = unserialize($network_info->extra); /** setting common variables according to media type */ if ($type == '') { $net_extra_ccid_str = $extra['user_defaults']['default_image_gallery']; $alb_type = IMAGE_ALBUM; $new_img = new CNImage(); } elseif ($type == '_audio') { $net_extra_ccid_str = $extra['user_defaults']['default_audio_gallery']; $alb_type = AUDIO_ALBUM; $new_img = new CNAudio(); } elseif ($type == '_video') { $net_extra_ccid_str = $extra['user_defaults']['default_video_gallery']; $alb_type = VIDEO_ALBUM; $new_img = new CNVideo(); } /** getting array of content collection from comma separated string */ if (!empty($net_extra_ccid_str)) { $net_extra_ccid = explode(',', $net_extra_ccid_str); /** setting all content collection variables */ if (count($net_extra_ccid) >= 1) { for ($i = 0; $i < count($net_extra_ccid); $i++) { $new_im_al = new Album($alb_type); $new_im_al_default = new Album($alb_type); $new_im_al->load((int) $net_extra_ccid[$i]); $content_collection_obj = new ContentCollection(); $content_collection_obj->collection_id = $new_im_al->collection_id; $contents = $content_collection_obj->get_contents_for_collection(); $new_im_al_default->title = $new_im_al->title; $new_im_al_default->description = $new_im_al->description; $new_im_al_default->author_id = $user_id; $new_im_al_default->type = 2; // FOR ALBUM, type is 2 $new_im_al_default->save(); /** Setting content variable */ for ($j = 0; $j < count($contents); $j++) { if ($contents[$j]['type'] != 7) { // If content is not a SB content if ($alb_type == IMAGE_ALBUM) { $new_img_default = new CNImage(); $new_img_default->type = IMAGE; } elseif ($alb_type == AUDIO_ALBUM) { $new_img_default = new CNAudio(); $new_img_default->type = AUDIO; } elseif ($alb_type == VIDEO_ALBUM) { $new_img_default = new CNVideo(); $new_img_default->type = VIDEO; } $new_img->load((int) $contents[$j]['content_id']); $new_img_default->file_name = $new_img->file_name; $new_img_default->file_perm = $new_img->file_perm; $new_img_default->title = $contents[$j]['title']; $new_img_default->body = $contents[$j]['body']; $tags = Tag::load_tags_for_content($contents[$j]['content_id']); $new_img_default->allow_comments = 1; $new_img_default->author_id = $user_id; $new_img_default->parent_collection_id = $new_im_al_default->collection_id; $new_img_default->save(); if (!empty($tags)) { $tag_array = array(); if (is_array($tags)) { for ($i = 0; $i < count($tags); $i++) { $tag_array[] = $tags[$i]['name']; } } Tag::add_tags_to_content($new_img_default->content_id, $tag_array); } } else { // If content is a SB content //TODO: handling of SB content if it is in media gallery. } } } } } }
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 add_tags_to_content($cid, $tag_string) { if (!empty($tag_string)) { $tag_array = Tag::split_tags($tag_string); Tag::add_tags_to_content($cid, $tag_array); } return; }
function peopleaggregator_newFile($args) { $user = User::from_auth_token($args['authToken']); $title = strip_tags($args['title']); $body = strip_tags($args['content']); $file_type = $args['type']; $tags = $args['tags']; $access = $args['access']; $context = $args['context']; // URL or file? if (!empty($args['url'])) { $upload_type = 'url'; $url = $args['url']; } else { $upload_type = 'file'; $filename = api_sanitize_filename($args['filename']); // strip attempts to ascend the directory tree $data = $args['data']; } $alb_type = API::$album_type_to_id[$file_type]; switch ($alb_type) { case IMAGE_ALBUM: $new_img = new Image(); $new_img->type = IMAGE; break; case AUDIO_ALBUM: $new_img = new Audio(); $new_img->type = AUDIO; break; case VIDEO_ALBUM: $new_img = new Video(); $new_img->type = VIDEO; break; default: throw new PAException(INVALID_ID, "file type must be 'image', 'audio' or 'video' (not {$file_type})"); } // When uploading a file, we can use the special 'default album' context: 'user:123:album:default' if (preg_match("/^user:\\d+:album:default:([a-z]+)\$/", $context, $m)) { $default_alb_type = API::$album_type_to_id[$m[1]]; $collection = Album::get_or_create_default($user->user_id, $default_alb_type); $collection_id = $collection->collection_id; } else { list($collection_id, $collection) = api_validate_album_context($context, $user, "write"); } if ($collection instanceof Album) { $album_file_type = API::$album_type_from_id[(int) $collection->album_type]; if ($album_file_type != $file_type) { throw new PAException(OPERATION_NOT_PERMITTED, "Attempting to upload a file of type '{$file_type}' into an album that can only contain '{$album_file_type}' files"); } } try { switch ($upload_type) { case 'url': // just supplying a URL; no upload to handle $new_img->file_name = $url; break; case 'file': // we're uploading a file - figure out where to put it $upload_path = realpath(PA::$upload_path); // make a filename that isn't already used $fn_munge = ""; $munge_serial = 0; while (1) { $fn = "{$upload_path}/" . $user->user_id . "_" . $fn_munge . $filename; if (!file_exists($fn)) { break; } // we have our filename! $fn_munge = ++$munge_serial . "_"; } // and try to save the file, then put it in the database, // removing the file if an exception occurs at any point. if (file_put_contents($fn, $data) != strlen($data)) { global $php_errormsg; throw new PAException(FILE_NOT_UPLOADED, "An error occurred when saving the file: {$php_errormsg}"); } $new_img->file_name = basename($fn); break; } $access_map = array('nobody' => 0, 'everybody' => 1, 'relations' => 2); $new_img->file_perm = $access_map[$access]; $new_img->author_id = $user->user_id; $new_img->title = $new_img->excerpt = $title; $new_img->body = $body; $new_img->allow_comments = 1; $new_img->parent_collection_id = $collection_id; $new_img->save(); if ($tags) { Tag::add_tags_to_content($new_img->content_id, Tag::split_tags($tags)); } } catch (PAException $e) { if ($upload_type == 'file') { // delete file @unlink($fn); } throw $e; } return array('success' => TRUE, 'id' => "file:{$new_img->content_id}", 'url' => api_get_url_of_file($new_img->file_name)); }
/** * Function used to save some information into our system * @access public */ public function save() { Logger::log("Enter: TekVideo::save()"); $this->video_id = $this->file_name; // so that this content will not display on the recent post module $this->is_default_content = FALSE; $this->type = TEK_VIDEO; parent::save(); if (empty($this->status)) { $this->status = -1; Tag::add_tags_to_content($this->content_id, $this->tags); $sql = 'INSERT INTO {media_videos} (content_id, video_id, email_id, views, author_id, status, video_perm) values (?, ?, ?, ?, ?, ?, ?)'; Dal::query($sql, array($this->content_id, $this->video_id, $this->email_id, 0, $this->author_id, $this->status, $this->video_perm)); } else { $params['key_value'] = array('video_perm' => $this->video_perm); $this->update($this->content_id, $params); } Logger::log("Exit: TekVideo::save()"); return; }
$new_video->parent_collection_id = $new_im_al->collection_id; } else { $new_video->parent_collection_id = $_GET['album_video']; } $new_video->allow_comments = 1; if (!empty($_GET['group_id'])) { $perm = 1; } else { $perm = !empty($_GET['video_perm']) ? $_GET['video_perm'] : 1; } $new_video->video_perm = $new_video->file_perm = $perm; $new_video->save(); $tag_array = NULL; if (!empty($_GET['tag'])) { $tag_array = Tag::split_tags($_GET['tag']); Tag::add_tags_to_content($new_video->content_id, $tag_array); } global $config_site_name; $uploaded = TRUE; $media_owner_image = uihelper_resize_mk_user_img(PA::$user->picture, 80, 80, 'alt="' . PA::$user->first_name . '" align="left" style="padding: 0px 12px 12px 0px;"'); $params['first_name'] = PA::$user->first_name; $params['user_id'] = PA::$login_uid; $params['user_image'] = $media_owner_image; $params['cid'] = $new_video->content_id; $params['media_title'] = $new_video->title; $params['content_url'] = $redirect_url . '/' . FILE_CONTENT . '?cid=' . $new_video->content_id; $params['config_site_name'] = $config_site_name; $params['media_full_view_url'] = $redirect_url . '/' . FILE_MEDIA_FULL_VIEW . '?cid=' . $new_video->content_id; $params['content_moderation_url'] = $redirect_url . '/' . FILE_NETWORK_MANAGE_CONTENT; $params['network_name'] = PA::$network_info->name; // auto_email_notification('media_uploaded', $params, $network_details);