Пример #1
0
 /**
  * Gets user data for a forum reply or article comment
  */
 function get_data($group_id)
 {
     // Get the meta from cache
     $allmeta = wp_cache_get('bp_groups_allmeta_' . $group_id, 'bp');
     // Otherwise query the groupmeta table
     if (false === $allmeta) {
         global $bp, $wpdb;
         $allmeta = array();
         $rawmeta = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d", $group_id));
         foreach ($rawmeta as $meta) {
             $allmeta[$meta->meta_key] = $meta->meta_value;
         }
         wp_cache_set('bp_groups_allmeta_' . $group_id, $allmeta, 'bp');
     }
     // Add data to the class object
     $this->id = $group_id;
     $this->fullname = bp_get_group_name();
     $this->domain = bp_get_group_permalink();
     $this->slug = bp_get_group_slug();
     $this->guild = isset($allmeta['is_guild']) ? $allmeta['is_guild'] : 0;
     $this->members = bp_get_group_member_count();
     $this->alliance = isset($allmeta['group_faction']) ? $allmeta['group_faction'] : 'neutral';
     $this->server = isset($allmeta['group_server']) ? $allmeta['group_server'] : NULL;
     $this->style = isset($allmeta['group_style']) ? $allmeta['group_style'] : NULL;
     $this->interests = isset($allmeta['group_interests']) ? unserialize($allmeta['group_interests']) : array();
     $this->website = isset($allmeta['group_website']) ? $allmeta['group_website'] : NULL;
     // Get some derived data
     $this->type = $this->type();
     $this->faction = $this->allegiance();
     $this->servname = $this->server_name($this->server);
     $this->tooltip = $this->tooltip();
     // Get some extra stuff on user profiles
     if ($this->context == 'profile') {
         $this->byline = $this->byline();
         $this->admins = $this->admins();
         $this->mods = $this->mods();
     }
 }
function bp_group_slug($group = false)
{
    echo bp_get_group_slug($group);
}
Пример #3
0
function bp_group_slug()
{
    echo bp_get_group_slug();
}
Пример #4
0
 /**
  * Create the hub overview CSV when requested.
  *
  * @since    1.0.0
  */
 public function run_stat_hub_csv()
 {
     global $wpdb;
     $bp = buddypress();
     // Output headers so that the file is downloaded rather than displayed.
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename=cc-hubs-overview.csv');
     // Create a file pointer connected to the output stream.
     $output = fopen('php://output', 'w');
     // Write a header row.
     $row = array('Hub ID', 'Name', 'Slug', 'Status', 'Date Created', 'Last Activity', 'Parent Hub ID', 'Total Members', 'Creator ID', 'Creator Email', 'Forum', 'BP Docs', 'CC Hub Home Page', 'CC Hub Pages', 'CC Hub Narratives', 'Custom Plugins');
     fputcsv($output, $row);
     // Groups Loop
     if (bp_has_groups(array('order' => 'ASC', 'orderby' => 'date_created', 'page' => null, 'per_page' => null, 'max' => false, 'show_hidden' => true, 'user_id' => null, 'meta_query' => false, 'include' => false, 'exclude' => false, 'populate_extras' => false, 'update_meta_cache' => false))) {
         while (bp_groups()) {
             bp_the_group();
             $group_id = bp_get_group_id();
             $group_object = groups_get_group(array('group_id' => (int) $group_id, 'populate_extras' => true));
             // Hub ID
             $row = array($group_id);
             // Name
             $row[] = bp_get_group_name();
             // Slug
             $row[] = bp_get_group_slug();
             // Status
             $row[] = bp_get_group_status();
             // Date Created
             $row[] = $group_object->date_created;
             // Date of last activity
             $row[] = $group_object->last_activity;
             // Parent Hub ID
             $row[] = $wpdb->get_var($wpdb->prepare("SELECT g.parent_id FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id));
             // Total Members
             $row[] = groups_get_total_member_count($group_id);
             // Creator ID
             $creator_id = $group_object->creator_id;
             $row[] = $creator_id;
             // Creator Email
             $creator = get_user_by('id', $creator_id);
             $row[] = $creator->user_email;
             // Forum
             $row[] = $group_object->enable_forum;
             // BP Docs
             if (function_exists('bp_docs_is_docs_enabled_for_group')) {
                 $row[] = bp_docs_is_docs_enabled_for_group($group_id);
             } else {
                 $row[] = '';
             }
             // CC Hub Home Page
             if (function_exists('cc_get_group_home_page_post') && cc_get_group_home_page_post($group_id)->have_posts()) {
                 $row[] = 1;
             } else {
                 $row[] = 0;
             }
             // CC Hub Pages
             $row[] = (bool) groups_get_groupmeta($group_id, "ccgp_is_enabled");
             // CC Hub Narratives
             $row[] = (bool) groups_get_groupmeta($group_id, "ccgn_is_enabled");
             // Custom Plugins
             // To make your group-specific plugin be counted, so something like this:
             /*	add_filter( 'cc_stats_custom_plugins', 'prefix_report_custom_plugin', 10, 2 );
              *	function prefix_report_custom_plugin( $custom_plugins, $group_id ) {
              *		if ( $group_id == sa_get_group_id() ) {
              *			$custom_plugins[] = "CC Salud America";
              *		}
              *		return $custom_plugins;
              *	}
              */
             $custom_plugins = apply_filters('cc_stats_custom_plugins', array(), $group_id);
             $custom_plugins = implode(' ', $custom_plugins);
             $row[] = $custom_plugins;
             // Write the row.
             fputcsv($output, $row);
         }
     }
     fclose($output);
     exit;
 }
/**
 * Prints the box content.
 * 
 * @param WP_Post $post The object for the current post/page.
 */
function bpgroups_meta_box_callback($post)
{
    // Add an nonce field so we can check for it later.
    wp_nonce_field('bpgroups_meta_box', 'bpgroups_meta_box_nonce');
    // to store the groups this user is member of
    $buddypressgroups = array();
    $checkgroups = array();
    // Get real Buddypress Groups
    if (function_exists('bp_groups')) {
        if (bp_has_groups()) {
            while (bp_groups()) {
                bp_the_group();
                $groupname = bp_get_group_name();
                $groupslug = bp_get_group_slug();
                // Set group as taxonomy term if not already done
                $termexists = term_exists($groupname, 'buddypress_groups');
                if (empty($termexists)) {
                    wp_insert_term($groupname, 'buddypress_groups', array('slug' => strtolower($groupname)));
                }
                // Get only groups the current user is member of
                if (groups_is_user_member(get_current_user_id(), bp_get_group_id())) {
                    $buddypressgroups[] = array('name' => $groupname, 'slug' => $groupslug);
                    $checkgroups[] = strtolower($groupslug);
                }
            }
        }
    }
    // Remove tax terms that have no buddypress group counterpart anymore in case of changes
    $allgroupterms = get_terms('buddypress_groups', array('hide_empty' => false));
    foreach ($allgroupterms as $groupterm) {
        if (!in_array($groupterm->slug, $checkgroups) && $groupterm->slug != 'keine') {
            // just keep non assignment term
            $term = get_term_by('slug', $groupterm->name, 'buddypress_groups');
            if ($term) {
                wp_delete_term($term->term_id, 'buddypress_groups');
            }
        }
    }
    //get the group assigned to this post if any
    $assignedgroups = wp_get_object_terms(array($post->ID), array('buddypress_groups'));
    $assignedgroup = 'keine';
    // posts without assignments
    if ($assignedgroups) {
        $assignedgroup = $assignedgroups[0]->slug;
        // technically more than one but we use only one
    }
    ?>
	<p>
		<select name="bpgroups_groupselector" id="bpgroups_groupselector" size="1">
			<option value="keine" <?php 
    selected($assignedgroup, 'keine', true);
    ?>
>Keine</option>
			<?php 
    foreach ($buddypressgroups as $bpgroup) {
        $name = $bpgroup['name'];
        $slug = $bpgroup['slug'];
        ?>
				<option value="<?php 
        echo esc_html($slug);
        ?>
" <?php 
        selected($assignedgroup, $slug, true);
        ?>
><?php 
        echo esc_html($name);
        ?>
</option>
	<?php 
    }
    ?>
		</select>
	</p>
	<?php 
}