pag_page = isset( $_GET['ipage'] ) ? intval( $_GET['ipage'] ) : 1; $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; $_taxonomies = oci_get_query_var(OCI_TAXONOMY); $_terms = oci_get_query_var(OCI_TERM); $_type = oci_get_query_var(OCI_TYPE); $this->taxonomies = !empty($_taxonomies) ? $_taxonomies : $taxonomies; $this->terms = !empty($_terms) ? $_terms : $terms; $this->type = !empty($_type) ? $_type : $type; if ($this->terms && $this->taxonomies) $this->items = OCI_Item::get_items_in_terms($this->terms, $this->taxonomies, $this->type, $this->pag_num, $this->pag_page); if ( !$max || $max >= (int)$this->items['total'] ) $this->total_item_count = (int)$this->items['total']; else $this->total_item_count = (int)$max; $this->items = $this->items['items']; if ( $max ) { if ( $max >= count($this->items) ) $this->item_count = count($this->items); else $this->item_count = (int)$max; } else { $this->item_count = count($this->items); } $this->pag_links = paginate_links( array( 'base' => add_query_arg( 'ipage', '%#%' ), 'format' => '', 'total' => ceil( (int) $this->total_item_count / (int) $this->pag_num ), // tot num pages possible 'current' => (int) $this->pag_page, 'prev_text' => '«', 'next_text' => '»', 'mid_size' => 1 )); } function has_items() { if ( $this->item_count ) return true; return false; } function next_item() { $this->current_item++; $this->item = $this->items[$this->current_item]; return $this->item; } function rewind_items() { $this->current_item = -1; if ( $this->item_count > 0 ) { $this->item = $this->items[0]; } } function items() { if ( $this->current_item + 1 < $this->item_count ) { return true; } elseif ( $this->current_item + 1 == $this->item_count ) { do_action('loop_end'); // Do some cleaning up after the loop $this->rewind_items(); } $this->in_the_loop = false; return false; } function the_item() { global $bp; $this->in_the_loop = true; $this->item = $this->next_item(); if ( !$item = wp_cache_get( 'oci_item_' . $this->item->id, 'oci' ) ) { $item = OCI_Item::get_source_object($this->item->item_id, $this->item->item_type, $this->item->item_source); wp_cache_set( 'oci_item_' . $item->id, $item, 'oci' ); } if ($item) $this->item = $item; if ( 0 == $this->current_item ) // loop has just started do_action('loop_start'); } } function oci_rewind_items() { global $oci_items_template; return $oci_items_template->rewind_items(); } function oci_has_items( $args = '' ) { global $bp, $oci_items_template; $defaults = array( 'taxonomy' => OCI_DEFAULT_TAG_TAXONOMY, 'type' => 'all', 'per_page' => 10, 'max' => false ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( $max ) { if ( $per_page > $max ) $per_page = $max; } $oci_items_template = new OCI_Items_Template( $taxonomy, $type, $per_page, $max ); return $oci_items_template->has_items(); } function oci_the_item() { global $oci_items_template; return $oci_items_template->the_item(); } function oci_the_items() { global $oci_items_template; return $oci_items_template->items(); } function oci_items_pagination() { echo oci_get_items_pagination(); } function oci_get_items_pagination() { global $oci_items_template; return apply_filters( 'oci_get_items_pagination', $oci_items_template->pag_links ); } function oci_the_items_pagination_count(){ echo oci_get_the_items_pagination_count(); } function oci_get_the_items_pagination_count() { global $bp, $oci_items_template; $from_num = intval( ( $oci_items_template->pag_page - 1 ) * $oci_items_template->pag_num ) + 1; $to_num = ( $from_num + ( $oci_items_template->pag_num - 1 ) > $oci_items_template->total_item_count ) ? $oci_items_template->total_item_count : $from_num + ( $oci_items_template->pag_num - 1) ; return sprintf( __( 'Viewing item %d to %d (of %d items)', 'bpcontents' ), $from_num, $to_num, $oci_items_template->total_item_count ); } function oci_the_items_term_and_taxonomy(){ echo oci_get_the_items_term_and_taxonomy(); } function oci_get_the_items_term_and_taxonomy() { global $bp, $oci_items_template; $pretty_tax = apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy' , $bp->contents->taxonomy->{$oci_items_template->taxonomies}->label); $term = apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy_term' , oci_get_term_by('slug', $oci_items_template->terms, $oci_items_template->taxonomies)); return apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy' , sprintf( __(' for %s in %s', 'bpcontents'), $term->name, $pretty_tax)); } function oci_bpc_nav_item(){ ?> class="selected"> contents->taxonomy->{$tax}->hierarchical; else $h = false; // default is sitewide tags in oci_the_taxonomy_select(); return $h; } function oci_the_taxonomy_tag_cloud($args = ''){ $tax = oci_get_query_var(OCI_TAXONOMY); if (!$tax) $tax = OCI_DEFAULT_TAG_TAXONOMY; $type = oci_get_query_var(OCI_TYPE); if (!$type) $type = 'all'; $args[OCI_TAXONOMY] = $tax; $args[OCI_TYPE] = $type; echo oci_get_tag_cloud($args); } function oci_the_taxonomy_category_list($args = ''){ $tax = oci_get_query_var(OCI_TAXONOMY); if (!$tax) $tax = OCI_DEFAULT_CATEGORY_TAXONOMY; $type = oci_get_query_var(OCI_TYPE); if (!$type) $type = 'all'; $defaults = array('taxonomy' => $tax, 'type' => $type, 'hide_empty' => true); $args = wp_parse_args($args, $defaults); echo oci_list_categories($args); } function oci_the_items_action(){ echo oci_get_the_items_action(); } function oci_get_the_items_action(){ global $bp; $path = $bp->root_domain . '/' . $bp->contents->slug; return apply_filters('oci_get_the_items_action', $path); } function oci_the_taxonomy_select($args = ''){ $defaults = array( 'name' => 'taxonomy_select', 'class' => '', 'taxonomy' => OCI_DEFAULT_TAG_TAXONOMY, 'tab_index' => 0, 'domain' => '', // from register taxonomy params 'instance' => '', // from register taxonomy params 'hierarchical' => '', // false = OCI_TAG, true = OCI_CATEGORY from register taxonomy params 'type' => '' // content type from register taxonomy params ); $args = wp_parse_args($args, $defaults); // allow template override if it is set $args['selected'] = oci_get_query_var(OCI_TAXONOMY); echo oci_get_dropdown_taxonomies($args); } /* * Template functions */ function oci_the_content_type_select($args = ''){ $defaults = array( 'name' => 'content_type_select', 'class' => '', 'type' => 'all' ); $args = wp_parse_args($args, $defaults); // allow template override if it is set $qv = oci_get_query_var(OCI_TYPE); $args['selected'] = !empty($qv) ? $qv : $args['type']; echo oci_get_dropdown_content_type($args); } function oci_get_dropdown_content_type( $args = '' ) { global $bp; $defaults = array( 'name' => 'content_type', 'class' => '', 'tab_index' => 0, 'type' => 'all' ); $args = wp_parse_args( $args, $defaults ); extract( $args ); $tab_index_attribute = ''; if ( (int) $tab_index > 0 ) $tab_index_attribute = " tabindex=\"$tab_index\""; /* $bp->contents->content_types->{$slug}->slug = $slug; $bp->contents->content_types->{$slug}->id = $id; $bp->contents->content_types->{$slug}->title = $title; $bp->contents->content_types->{$slug}->multi_source = $multi_source; */ $types = $bp->contents->content_types; $types->all->slug = 'all'; $types->all->title = 'All'; $output = ''; $output = "\n"; $output = apply_filters( 'oci_dropdown_content_types', $output ); return $output; } function oci_the_item_edit_link(){ } function oci_get_the_item_edit_link(){ } function oci_the_item_link($id = false){ echo oci_get_the_item_link($id); } function oci_get_the_item_link($id = false){ global $oci_items_template; if ($id){ $src_item = oci_source_get_item($id); $link = $src_item->item_link; } else{ $link = $oci_items_template->item->item_link; } return apply_filters('oci_get_the_item_link', $link); } function oci_the_item_title($id = false){ echo oci_get_the_item_title($id); } function oci_get_the_item_title($id = false){ global $oci_items_template; if ($id){ $src_item = oci_source_get_item($id); $title = $src_item->item_title; } else{ $title = $oci_items_template->item->item_title; } return apply_filters('oci_get_the_item_title', $title); } function oci_the_item_type($id = false){ echo oci_get_the_item_type($id); } function oci_get_the_item_type($id = false){ global $oci_items_template, $bp; if ($id){ $src_item = oci_source_get_item($id); $type = $bp->contents->content_types->{$src_item->item_type}->title; } else{ $type = $bp->contents->content_types->{$oci_items_template->item->item_type}->title; } return apply_filters('oci_get_the_item_type', $type); } // items template fn function oci_the_item_tags($id = false, $args = ''){ echo oci_get_the_item_tags($id, $args); } function oci_get_the_item_tags($id = false, $args = ''){ global $bp, $oci_items_template; $defaults = array('taxonomy' => OCI_DEFAULT_TAG_TAXONOMY, 'url' => OCI_DEFAULT_URL, 'before' => '', 'sep' => ' ', 'after' => '' ); $args = wp_parse_args($args, $defaults); extract($args); $before = apply_filters('oci_the_item_tags_before', $bp->contents->taxonomy->{$taxonomy}->label . ': ', $taxonomy); if ($id) $item = oci_source_get_item($id); else $item = $oci_items_template->item; return oci_the_term_list( $item->id, $taxonomy, $url, $before, $sep, $after); } function oci_the_item_categories($id = false, $args = ''){ echo oci_get_the_item_categories($id, $args); } function oci_get_the_item_categories($id = false, $args = ''){ global $bp, $oci_items_template; $defaults = array('taxonomy' => OCI_DEFAULT_CATEGORY_TAXONOMY, 'url' => OCI_DEFAULT_URL, 'before' => '', 'sep' => ' ', 'after' => '' ); $args = wp_parse_args($args, $defaults); extract($args); $before = apply_filters('oci_the_item_tags_before', $bp->contents->taxonomy->{$taxonomy}->label . ': ', $taxonomy); if ($id) $item = oci_source_get_item($id); else $item = $oci_items_template->item; return oci_the_term_list( $item->id, $taxonomy, $url, $before, $sep, $after); } function oci_the_item_description($id = false){ echo oci_get_the_item_description($id); } function oci_get_the_item_description($id = false){ global $oci_items_template; if ($id){ $src_item = oci_source_get_item($id); $desc = $src_item->item_description; } else{ $desc = $oci_items_template->item->item_description; } return apply_filters('oci_get_the_item_description', $desc); } function oci_the_item_author($id = false){ echo oci_get_the_item_author($id); } function oci_get_the_item_author($id = false){ global $oci_items_template; if ($id){ $src_item = oci_source_get_item($id); $author = $src_item->item_author; } else{ $author = $oci_items_template->item->item_author; } return apply_filters('oci_get_the_item_author', $author); } function oci_the_item_avatar($id = false){ echo oci_get_the_item_avatar($id); } function oci_get_the_item_avatar($id = false){ global $oci_items_template; if ($id){ $src_item = oci_source_get_item($id); $av = $src_item->item_avatar; } else{ $av = $oci_items_template->item->item_avatar; } return apply_filters('oci_get_the_item_avatar', $av); } /** * oci_objects_get_properties() * * Utility function to return the values of an object's properties. * Passed an array of objects, it will return an array of the property for each object's $prop_name. * * Example: passed an array of term objs the call oci_objects_get_properties($tags, 'name') will return an * array of 'name' properties for all the $tags objects. * * @param array $arr_of_objs array of stdClass objects * @param string $prop_name the property of the objects to return * @return array $props array of property values for the property $prop_name for each obj */ function oci_objects_get_properties($arr_of_objs, $prop_name){ $props = array(); foreach((array)$arr_of_objs as $obj){ $props[] = $obj->{$prop_name}; } return $props; } /** * oci_get_query_var() * * If a query var of the type http://mysite.org/members/?name=thisvalue&othername=thatvalue exists and the * $var == 'name' exists, returns the value 'thisvalue' * * @param string $var query var to return * @return string value of the $var argument */ function oci_get_query_var($var){ if (isset($_GET[$var])) return $_GET[$var]; else return ''; } function oci_no_items_message(){ global $oci_items_template; if (!$oci_items_template->has_items() && '' == oci_get_query_var(OCI_TERM)){ $no_items = apply_filters('oci_no_items_no_query', __('Select a tag or category.', 'bpcontents')); } else{ $no_items = apply_filters('oci_no_items_empty_query', __('No items found', 'bpcontents') . oci_get_the_items_term_and_taxonomy()); } echo $no_items; } ?>