function route2groups() { global $user, $is_edit; $extra = unserialize(PA::$network_info->extra); $tags = preg_split('/\\s*,\\s*/', strtolower($_POST['tags'])); $tags = array_unique($tags); $net_owner = new User(); $net_owner->load((int) PA::$network_info->owner_id); $valid_post_types = array('BlogPost', 'Contribution', 'Suggestion'); $type = isset($_POST) && isset($_POST['blog_type']) && in_array($_POST['blog_type'], $valid_post_types) ? $_POST['blog_type'] : 'BlogPost'; //find tag entry $terms = array(); foreach ($tags as $term) { $tr = trim($term); if ($tr) { $terms[] = $tr; } } if (!empty($_POST['route_to_pa_home']) && $_POST['route_to_pa_home'] == 1) { $display_on_homepage = DISPLAY_ON_HOMEPAGE; //its zero } else { $display_on_homepage = NO_DISPLAY_ON_HOMEPAGE; //This will not show up on homepage - flag has opposite values } if (is_array($_POST['route_targets_group'])) { if (in_array(-2, $_POST['route_targets_group'])) { //-2 means Select none of group // no need to post in any group } elseif (in_array(-1, $_POST['route_targets_group'])) { //-1 means select all the groups // post in all the groups $group_array = explode(',', $_POST['Allgroups']); foreach ($group_array as $gid) { // post to all the groups $_group = Group::load_group_by_id((int) $gid); $login_required_str = null; if ($_group->access_type == ACCESS_PRIVATE) { $login_required_str = '&login_required=true'; } switch ($type) { case 'BlogPost': default: $res = BlogPost::save_blogpost(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; case 'Contribution': $res = Contribution::save_contribution(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; case 'Suggestion': $res = Suggetion::save_suggestion(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; } $permalink_cid = $res['cid']; // NOTE: would this notification message be sent for each group ??? $content_obj = Content::load_content((int) $permalink_cid); PANotify::send("content_posted", PA::$network_info, $user, $content_obj); // notify network owner (maybe group owner would be better?) if ($display_on_homepage == DISPLAY_ON_HOMEPAGE) { PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj); } //------- //for rivers of people $activity = 'group_post_a_blog'; $activity_extra['info'] = $user->first_name . 'posted a new blog'; $activity_extra['blog_name'] = $_POST["blog_title"]; $activity_extra['blog_id'] = $permalink_cid; $activity_extra['blog_url'] = PA::$url . PA_ROUTE_CONTENT . '/cid=' . $permalink_cid . $login_required_str; $extra = serialize($activity_extra); $object = $gid; // update status to unverified $group = ContentCollection::load_collection((int) $gid, PA::$login_uid); if ($group->reg_type == REG_MODERATED) { Network::moderate_network_content((int) $gid, $permalink_cid); } else { if ($extra['network_content_moderation'] == NET_YES && $is_edit == 0 && PA::$network_info->owner_id != $user->user_id) { Network::moderate_network_content($gid, $permalink_cid); } } if (!PA::is_moderated_content() && $group->reg_type != REG_MODERATED) { //Write to activity log only when moderation is off Activities::save($user->user_id, $activity, $object, $extra); } } } else { // post in selected groups foreach ($_POST['route_targets_group'] as $gid) { //only send to selected groups $_group = Group::load_group_by_id((int) $gid); $login_required_str = null; if ($_group->access_type == ACCESS_PRIVATE) { $login_required_str = '&login_required=true'; } switch ($type) { case 'BlogPost': default: $res = BlogPost::save_blogpost(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; case 'Contribution': $res = Contribution::save_contribution(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; case 'Suggestion': $res = Suggestion::save_suggestion(0, PA::$login_uid, $_POST['blog_title'], $_POST['description'], NULL, $terms, $gid, $is_active = 1, $display_on_homepage); break; } $permalink_cid = $res['cid']; $content_obj = Content::load_content((int) $permalink_cid); PANotify::send("content_posted", PA::$network_info, $user, $content_obj); // notify network owner (maybe group owner would be better?) if ($display_on_homepage == DISPLAY_ON_HOMEPAGE) { PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj); } //for rivers of people $activity = 'group_post_a_blog'; $activity_extra['info'] = $user->first_name . 'posted a new blog'; $activity_extra['blog_name'] = $_POST["blog_title"]; $activity_extra['blog_id'] = $permalink_cid; $activity_extra['blog_url'] = PA::$url . PA_ROUTE_CONTENT . '/cid=' . $permalink_cid . $login_required_str; $extra = serialize($activity_extra); $object = $gid; // update status to unverified $group = ContentCollection::load_collection((int) $gid, PA::$login_uid); if ($group->reg_type == REG_MODERATED) { Network::moderate_network_content((int) $gid, $permalink_cid); } else { if ($extra['network_content_moderation'] == NET_YES && $is_edit == 0 && PA::$network_info->owner_id != $user->user_id) { Network::moderate_network_content($gid, $permalink_cid); } } if (!PA::is_moderated_content() && $group->reg_type != REG_MODERATED) { //Write to activity log only when moderation is off Activities::save($user->user_id, $activity, $object, $extra); } } } } return TRUE; }
} else { if ($group->reg_type == REG_MODERATED || PA::$extra['network_content_moderation'] == NET_YES) { $msg = "&msg_id=1004"; } else { $msg = "&msg_id=7027"; } } // it means user is coming from group's page then redirect it to group //load group to see if group is if it is moderated $location = PA::$url . PA_ROUTE_GROUP . "/gid=" . $_REQUEST['ccid'] . $msg; $location = isset($redirect) && $redirect != '' ? $redirect : $location; header("location:{$location}"); exit; } else { //just redirect it to permalink page if (PA::is_moderated_content()) { $error_msg = "&msg_id=1004"; } else { $error_msg = "&msg_id=7027"; } // header("location:".PA::$url . PA_ROUTE_CONTENT . "/cid=".$permalink_cid.$error_msg);exit; $location = PA::$url . PA_ROUTE_USER_PRIVATE . "?cid=" . $permalink_cid . $error_msg; $location = isset($redirect) && $redirect != '' ? $redirect : $location; header("location:{$location}"); exit; } } else { //..end of !$error $post_err = 'Post could not be saved due to following errors:<br>' . $post_err; } }