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 render() { $pic = $aud = $vid = NULL; switch ($this->page) { case 'homepage': $pic = CNImage::load_recent_media_image(0, $this->subject); $aud = CNAudio::load_recent_media_audio(0, $this->subject); $vid = CNVideo::load_recent_media_video(0, $this->subject); break; case 'grouppage': $pic = CNImage::load_images_for_collection_id((int) $this->gid); $aud = CNAudio::load_audios_for_collection_id((int) $this->gid); $vid = CNVideo::load_videos_for_collection_id((int) $this->gid); break; case 'userpage': $pic = CNImage::load_user_gallery_images($this->uid, 10, PA::$login_uid); $aud = CNAudio::load_user_gallery_audio($this->uid, 10, PA::$login_uid); $vid = CNVideo::load_user_gallery_video($this->uid, 10, PA::$login_uid); break; } //even if we got more media, we can display only 6 $pictures = array(); $max = count($pic) < 6 ? count($pic) : ($max = 6); for ($i = 0; $i < $max; $i++) { $pictures[$i] = $pic[$i]; } $audios = array(); $max = count($aud) < 6 ? count($aud) : ($max = 6); for ($i = 0; $i < $max; $i++) { $audios[$i] = $aud[$i]; } $videos = array(); $max = count($vid) < 6 ? count($vid) : ($max = 6); for ($i = 0; $i < $max; $i++) { $videos[$i] = $vid[$i]; } if (!empty($this->group_details) && (!empty($pictures) || !empty($audios) || !empty($videos))) { $this->view_all_url = PA::$url . PA_ROUTE_MEDIA_GALLEY_IMAGES . "/view=groups_media&gid=" . (int) $this->group_details->collection_id; } $gallery = array('images' => $pictures, 'audios' => $audios, 'videos' => $videos); $this->links = $gallery; $this->inner_HTML = $this->generate_inner_html($this->links); if (empty($gallery['images']) && empty($gallery['audios']) && empty($gallery['videos'])) { $this->height = 70; $this->view_all_url = ''; } else { $this->height = 260; } $content = parent::render(); return $content; }