예제 #1
0
 function __construct($args = '')
 {
     global $bp;
     $defaults = bp_album_default_query_args();
     $r = apply_filters('bp_album_template_args', wp_parse_args($args, $defaults));
     extract($r, EXTR_SKIP);
     $this->pag_page = $page;
     $this->pag_per_page = $per_page;
     $this->owner_id = $owner_id;
     $this->privacy = $privacy;
     $total = bp_album_get_picture_count($r);
     $this->pictures = bp_album_get_pictures($r);
     if (!$max || $max >= $total) {
         $this->total_picture_count = $total;
     } else {
         $this->total_picture_count = $max;
     }
     if (!$max || $max >= count($this->pictures)) {
         $this->picture_count = count($this->pictures);
     } else {
         $this->picture_count = $max;
     }
     $this->pag_links_global = paginate_links(array('base' => get_permalink() . '%#%', 'format' => '?page=%#%', 'total' => ceil((int) $this->total_picture_count / (int) $this->pag_per_page), 'current' => (int) $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1));
     //$this->pag_links = paginate_links( array(
     //'base' => $bp->displayed_user->domain . $bp->album->slug .'/'. $bp->album->pictures_slug .'/%_%',
     //'format' => '%#%',
     //'total' => ceil( (int) $this->total_picture_count / (int) $this->pag_per_page ),
     //'current' => (int) $this->pag_page,
     //'prev_text' => '←',
     //'next_text' => '→',
     //'mid_size' => 1
     //));
     if ($this->picture_count) {
         $this->picture = $this->pictures[0];
     }
 }
예제 #2
0
/**
 * bp_album_limits_info()
 *
 * @version 0.1.8.12
 * @since 0.1.8.0
 */
function bp_album_limits_info()
{
    global $bp, $pictures_template;
    $owner_id = isset($pictures_template) ? $pictures_template->picture->owner_id : $bp->loggedin_user->id;
    $results = bp_album_get_picture_count(array('owner_id' => $owner_id, 'privacy' => 'all', 'priv_override' => true, 'groupby' => 'privacy'));
    $return = array();
    $tot_count = 0;
    $tot_remaining = false;
    foreach (array(0, 2, 4, 6, 10) as $i) {
        $return[$i]['count'] = 0;
        foreach ($results as $r) {
            if ($r->privacy == $i) {
                $return[$i]['count'] = $r->count;
                break;
            }
        }
        if (isset($pictures_template) && $i == $pictures_template->picture->privacy) {
            $return[$i]['current'] = true;
        } else {
            $return[$i]['current'] = false;
        }
        if ($i == 10) {
            $return[$i]['enabled'] = is_super_admin();
            $return[$i]['remaining'] = $return[$i]['enabled'];
        } else {
            switch ($i) {
                case "0":
                    $pic_limit = $bp->album->bp_album_max_priv0_pictures;
                    break;
                case "1":
                    $pic_limit = $bp->album->bp_album_max_priv1_pictures;
                    break;
                case "2":
                    $pic_limit = $bp->album->bp_album_max_priv2_pictures;
                    break;
                case "3":
                    $pic_limit = $bp->album->bp_album_max_priv3_pictures;
                    break;
                case "4":
                    $pic_limit = $bp->album->bp_album_max_priv4_pictures;
                    break;
                case "5":
                    $pic_limit = $bp->album->bp_album_max_priv5_pictures;
                    break;
                case "6":
                    $pic_limit = $bp->album->bp_album_max_priv6_pictures;
                    break;
                case "7":
                    $pic_limit = $bp->album->bp_album_max_priv7_pictures;
                    break;
                case "8":
                    $pic_limit = $bp->album->bp_album_max_priv8_pictures;
                    break;
                case "9":
                    $pic_limit = $bp->album->bp_album_max_priv9_pictures;
                    break;
                default:
                    $pic_limit = null;
            }
            $return[$i]['enabled'] = $pic_limit !== 0 ? true : false;
            $return[$i]['remaining'] = $pic_limit === false ? true : ($pic_limit > $return[$i]['count'] ? $pic_limit - $return[$i]['count'] : 0);
        }
        $tot_count += $return[$i]['count'];
        $tot_remaining = $tot_remaining || $return[$i]['remaining'];
    }
    $return['all']['count'] = $tot_count;
    $return['all']['remaining'] = $bp->album->bp_album_max_pictures === false ? true : ($bp->album->bp_album_max_pictures > $tot_count ? $bp->album->bp_album_max_pictures - $tot_count : 0);
    $return['all']['remaining'] = $tot_remaining ? $return['all']['remaining'] : 0;
    $return['all']['enabled'] = true;
    return $return;
}
/**
 * bp_album_action_edit()
 *
 * @version 0.1.8.12
 * @since 0.1.8.0
 */
function bp_album_action_edit()
{
    global $bp, $pictures_template;
    if ($bp->current_component == $bp->album->slug && $bp->album->single_slug == $bp->current_action && $pictures_template->picture_count && isset($bp->action_variables[1]) && $bp->album->edit_slug == $bp->action_variables[1] && isset($_POST['submit'])) {
        check_admin_referer('bp-album-edit');
        $error_flag = false;
        $feedback_message = array();
        $id = $pictures_template->pictures[0]->id;
        if (empty($_POST['title'])) {
            $error_flag = true;
            $feedback_message[] = __('Picture title cannot be blank.', 'bp-album');
        }
        if ($bp->album->bp_album_require_description && empty($_POST['description'])) {
            $error_flag = true;
            $feedback_message[] = __('Picture description cannot be blank.', 'bp-album');
        }
        if (!isset($_POST['privacy'])) {
            $error_flag = true;
            $feedback_message[] = __('Please select a privacy option.', 'bp-album');
        } else {
            $priv_lvl = intval($_POST['privacy']);
            switch ($priv_lvl) {
                case "0":
                    $pic_limit = $bp->album->bp_album_max_priv0_pictures;
                    break;
                case "1":
                    $pic_limit = $bp->album->bp_album_max_priv1_pictures;
                    break;
                case "2":
                    $pic_limit = $bp->album->bp_album_max_priv2_pictures;
                    break;
                case "3":
                    $pic_limit = $bp->album->bp_album_max_priv3_pictures;
                    break;
                case "4":
                    $pic_limit = $bp->album->bp_album_max_priv4_pictures;
                    break;
                case "5":
                    $pic_limit = $bp->album->bp_album_max_priv5_pictures;
                    break;
                case "6":
                    $pic_limit = $bp->album->bp_album_max_priv6_pictures;
                    break;
                case "7":
                    $pic_limit = $bp->album->bp_album_max_priv7_pictures;
                    break;
                case "8":
                    $pic_limit = $bp->album->bp_album_max_priv8_pictures;
                    break;
                case "9":
                    $pic_limit = $bp->album->bp_album_max_priv9_pictures;
                    break;
                default:
                    $pic_limit = null;
            }
            if ($priv_lvl == 10) {
                $pic_limit = is_super_admin() ? false : null;
            }
            if ($pic_limit === null) {
                $error_flag = true;
                $feedback_message[] = __('Privacy option is not correct.', 'bp-album');
            } elseif ($pic_limit !== false && $priv_lvl !== $pictures_template->pictures[0]->privacy && ($pic_limit === 0 || $pic_limit <= bp_album_get_picture_count(array('privacy' => $priv_lvl)))) {
                $error_flag = true;
                switch ($priv_lvl) {
                    case 0:
                        $feedback_message[] = __('You have reached the limit for public pictures.', 'bp-album') . ' ' . __('Please select another privacy option.', 'bp-album');
                        break;
                    case 2:
                        $feedback_message[] = __('You have reached the limit for pictures visible to community members.', 'bp-album') . ' ' . __('Please select another privacy option.', 'bp-album');
                        break;
                    case 4:
                        $feedback_message[] = __('You have reached the limit for pictures visible to friends.', 'bp-album') . ' ' . __('Please select another privacy option.', 'bp-album');
                        break;
                    case 6:
                        $feedback_message[] = __('You have reached the limit for private pictures.', 'bp-album') . ' ' . __('Please select another privacy option.', 'bp-album');
                        break;
                }
            }
        }
        if (bp_is_active('activity') && $bp->album->bp_album_enable_comments) {
            if (!isset($_POST['enable_comments']) || $_POST['enable_comments'] != 0 && $_POST['enable_comments'] != 1) {
                $error_flag = true;
                $feedback_message[] = __('Comments option is not correct.', 'bp-album');
            } else {
                $_POST['enable_comments'] == 0;
            }
        }
        if (!$error_flag) {
            // WordPress adds an escape character "\" to some special values in INPUT FIELDS (test's becomes test\'s), so we have to strip
            // the escape characters, and then run the data through *proper* filters to prevent SQL injection, XSS, and various other attacks.
            if (bp_album_edit_picture($id, stripslashes($_POST['title']), stripslashes($_POST['description']), $priv_lvl, $_POST['enable_comments'])) {
                $feedback_message[] = __('Picture details saved.', 'bp-album');
            } else {
                $error_flag = true;
                $feedback_message[] = __('There were problems saving picture details.', 'bp-album');
            }
        }
        if ($error_flag) {
            bp_core_add_message(implode('&nbsp;', $feedback_message), 'error');
        } else {
            bp_core_add_message(implode('&nbsp;', $feedback_message), 'success');
            bp_core_redirect($bp->displayed_user->domain . $bp->album->slug . '/' . $bp->album->single_slug . '/' . $id . '/');
            die;
        }
    }
}