Skip to content

Instantly share code, notes, and snippets.

@aaroneaton
Created August 12, 2011 20:00
Show Gist options
  • Save aaroneaton/1142869 to your computer and use it in GitHub Desktop.
Save aaroneaton/1142869 to your computer and use it in GitHub Desktop.
<?php
/*
Section: People
Author: J. Aaron Eaton
Description: Enables the creation of people and how to display the posts
Version: 1.0.0
*/
class BasePeople extends PageLinesSection {
function __construct( $registered_settings = array() ) {
$name = __('People', 'pagelines');
$id = 'people';
// SETTINGS
// Setup description of the seciton, tell pagelines what areas the seciton works with, locate the icon,
// and declare the version.
$default_settings = array(
'description' => 'Create people, organize them by group, field, and research.',
'workswith' => array('main','content'),
'icon' => PL_ADMIN_ICONS . '/boxes.png',
'version' => 'pro',
);
// OPS
// Draw section using the section API - DON'T TOUCH THIS!
$settings = wp_parse_args( $registered_settings, $default_settings );
parent::__construct($name, $id, $settings);
}
/*
Loads php that will run on every page load (admin and site)
Used for creating administrative information, like post types
*/
function section_persistent(){
/*
Create Custom Post Type 'People'
*/
$args = array(
'label' => __('People', 'pagelines'),
'singular_label' => __('Person', 'pagelines'),
'description' => 'For creating faculty, staff, and student entries.',
'capability_type' => 'post',
);
$taxonomies = array(
"groups" => array(
"label" => __('Groups', 'pagelines'),
"singular_label" => __('Group', 'pagelines'),
'hierarchical' => true,
),
"field" => array(
'label' => __('Field','pagelines'),
'singular_label' => __('Field','pagelines'),
'hierarchical' => true,
),
"research" => array(
'label' => __('Research','pagelines'),
'singular_label' => __('Research','pagelines'),
'hierarchical' => false,
),
);
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Display Name",
"lastname" => "Last Name",
"firstname" => "First Name",
"group" => "Group",
"field" => "Field",
"research" => "Research",
"portrait" => "Portrait",
);
$column_value_function = 'people_column_display';
$this->post_type = new PageLinesPostType($this->id, $args, $taxonomies, $columns, $column_value_function);
/* Set default posts if none are present */
//$this->post_type->set_default_posts('pagelines_default_people');
/*
Meta Options
*/
/*
Create meta fields for the post type
*/
$type_meta_array = array(
'lastname' => array(
'version' => 'pro',
'type' => 'text',
'title' => 'Last Name',
'desc' => 'Person Last Name',
),
'firstname' => array(
'version' => 'pro',
'type' => 'text',
'title' => 'First Name',
'desc' => 'Person First Name',
),
'email' => array(
'version' => 'pro',
'type' => 'text',
'title' => 'Email Address',
'desc' => 'Person email address',
),
'phone' => array(
'version' => 'pro',
'type' => 'text',
'title' => 'Phone Number',
'desc' => '(xxx)xxx-xxxx',
),
'building' => array(
'version' => 'pro',
'type' => 'select',
'title' => 'Building',
'desc' => 'Which building?',
'selectvalues' => array(
'acad' => 'Academic Building',
'bloc' => 'Blocker Building',
'reed' => 'Reed McDonald',
),
),
'room' => array(
'version' => 'pro',
'type' => 'text',
'title' => 'Room Number',
'desc' => 'What is the office number?',
),
'the_person_icon' => array(
'version' => 'pro',
'type' => 'image_upload',
'title' => 'Upload Portrait',
'desc' => 'Upload an image for this person.'
),
);
$post_types = array($this->id);
$type_metapanel_settings = array(
'id' => 'people-metapanel',
'name' => THEMENAME." People Options",
'posttype' => $post_types,
);
global $people_meta_panel;
$people_meta_panel = new PageLinesMetaPanel( $type_metapanel_settings );
$type_metatab_settings = array(
'id' => 'people-type-metatab',
'name' => "People Setup Options",
'icon' => $this->icon,
);
$people_meta_panel->register_tab( $type_metatab_settings, $type_meta_array );
/*
Build Ind. Page and Post Options
*/
$metatab_array = array(
'group' => array(
'version' => 'pro',
'type' => 'select_taxonomy',
'taxonomy_id' => 'groups',
'title' => 'Select Group to Show',
'desc' => 'Select which group you would like to show on this page (faculty, staff, students).'
),
'people_items' => array(
'version' => 'pro',
'type' => 'text',
'size' => 'small',
'inputlabel' => 'Maximum Number of People To Show On Page',
'title' => 'Max Number of People',
'desc' => "Select the max number of people to show on this page (overrides default).",
),
);
$metatab_settings = array(
'id' => 'fpeople_meta',
'name' => "People Section",
'icon' => $this->icon
);
register_metatab($metatab_settings, $metatab_array);
}
function section_template() {
$p = $this->pagelines_people_set();
$this->draw_people($p, $this->set);
}
function pagelines_people_set(){
global $post;
global $pagelines_ID;
if( get_pagelines_meta('groups', $pagelines_ID) )
$this->set = get_post_meta($pagelines_ID, 'groups', true);
else
$this->set = null;
$limit = (pagelines_option('people_items', $pagelines_ID)) ? pagelines_option('people_items', $pagelines_ID) : null;
$p = $this->load_pagelines_people($this->set, $limit);
return $p;
}
function load_pagelines_people($set = null, $limit = null){
$query = array();
$query['orderby'] = 'ID';
$query['post_type'] = 'people';
if(isset($set))
$query['groups'] = $set;
if(isset($limit))
$query['showposts'] = $limit;
$q = new WP_Query($query);
if(is_array($q->posts))
return $q->posts;
else
return array();
}
function draw_people($p){
global $post;
global $pagelines_layout;
$current_page_post = $post;
?>
<div id="people" class="<?php echo $class; ?> fix">
<div id="people-area">
<?php
if(!empty($p)):
foreach($p as $post) :
// Setup for Standard WP Functions
setup_postdata($post);
// Get the person's portrait
$person_portrait = get_post_meta($post->ID, 'the_person_icon', true);
?>
<div id="<?php echo 'person_' . $post->ID; ?>" class="pcontainer">
<?php pagelines_register_hook('pagelines_pcontent_before', $this->id); // Hook ?>
<div class="pheading">
<h3 class="ptitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div><!-- End class="pheading" -->
<div class="ptext">
<div class="pemail">
<?php
if(get_post_meta($post->ID, 'email', true)){
echo '<p>' . get_post_meta($post->ID, 'email', true) . '</p>';
} else {
echo '<p>No Email Provided</p>';
}
?>
</div><!-- End class="pemail" -->
<div>
<?php if(isset($person_portrait)): ?>
<img src="<?php echo $person_portrait; ?>" />
<?php else: ?>
<p>No Image Found!</p>
<?php endif; ?>
</div>
</div><!-- End class="ptext" -->
</div><!-- End id="person_###" -->
<?php endforeach; ?>
<?php else: ?>
<h4 style="padding: 50px; text-align: center"><?php echo $p; ?></h4>
<?php endif; ?>
<?php $post = $current_page_post; ?>
</div><!-- End id="people-area" -->
</div><!-- End id="people" -->
<?php }
function section_options($optionset = null, $location = null) {
if($optionset == 'new' && $location == 'bottom'){
}
}
// End of Section Class //
}
function people_column_display($column){
global $post;
switch ($column){
case "lastname":
if(get_post_meta($post->ID, 'lastname', true)){
$lname = get_post_meta($post->ID, 'lastname');
echo $lname[0];
}
break;
case "firstname":
if(get_post_meta($post->ID, 'firstname', true)){
$fname = get_post_meta($post->ID, 'firstname');
echo $fname[0];
}
break;
case "group":
echo get_the_term_list($post->ID, 'groups', '', ', ','');
break;
case "field":
echo get_the_term_list($post->ID, 'field', '', ', ','');
break;
case "research":
echo get_the_term_list($post->ID, 'research', '', ', ','');
break;
case "portrait":
if(m_pagelines($oid, $post->ID )){
$portrait = m_pagelines($oid, $post->ID);
echo '<img src="' . $portrait['the_person_icon'][0] . '" style="max-width: 80px; margin: 10px; border: 1px solid #ccc; padding: 5px; background: #fff" />';
//echo $portrait[the_person_icon][0];
}
break;
}
}
//function pagelines_default_people($post_type){
//$d = array_reverse(get_default_fpeople());
//foreach($d as $dp){
//// Create post object
//$default_post = array();
//$default_post['post_title'] = $dp['title'];
//$default_post['post_content'] = $dp['text'];
//$default_post['post_type'] = $post_type;
//$default_post['post_status'] = 'publish';
//$newPostID = wp_insert_post( $default_post );
//if(isset($dp['media']))
//update_post_meta($newPostID, 'the_people_icon', $dp['media']);
//wp_set_object_terms($newPostID, 'default-people', 'group');
//// Add other default sets, if applicable.
//if(isset($dp['set']))
//wp_set_object_terms($newPostID, $dp['set'], 'group', true);
//}
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment